Browse Source

pluginkit biome configuration

Futa Arai 9 months ago
parent
commit
ae47ba4c70
26 changed files with 276 additions and 172 deletions
  1. 0 1
      biome.json
  2. 1 1
      packages/pluginkit/.eslintignore
  3. 0 5
      packages/pluginkit/.eslintrc.cjs
  4. 1 1
      packages/pluginkit/package.json
  5. 7 7
      packages/pluginkit/src/model/growi-plugin-package-data.ts
  6. 9 9
      packages/pluginkit/src/model/growi-plugin-validation-data.ts
  7. 4 4
      packages/pluginkit/src/model/growi-plugin-validation-error.ts
  8. 3 1
      packages/pluginkit/src/v4/client/utils/growi-facade/growi-react.spec.ts
  9. 1 2
      packages/pluginkit/src/v4/client/utils/growi-facade/growi-react.ts
  10. 18 16
      packages/pluginkit/src/v4/interfaces/template.ts
  11. 7 2
      packages/pluginkit/src/v4/server/utils/common/import-package-json.spec.ts
  12. 3 1
      packages/pluginkit/src/v4/server/utils/common/import-package-json.ts
  13. 36 17
      packages/pluginkit/src/v4/server/utils/common/validate-growi-plugin-directive.spec.ts
  14. 29 8
      packages/pluginkit/src/v4/server/utils/common/validate-growi-plugin-directive.ts
  15. 5 2
      packages/pluginkit/src/v4/server/utils/template/get-markdown.ts
  16. 6 6
      packages/pluginkit/src/v4/server/utils/template/get-status.ts
  17. 45 31
      packages/pluginkit/src/v4/server/utils/template/scan.ts
  18. 15 7
      packages/pluginkit/src/v4/server/utils/template/validate-all-locales.ts
  19. 15 10
      packages/pluginkit/src/v4/server/utils/template/validate-growi-plugin-directive.spec.ts
  20. 10 4
      packages/pluginkit/src/v4/server/utils/template/validate-growi-plugin-directive.ts
  21. 22 12
      packages/pluginkit/src/v4/server/utils/theme/validate-growi-plugin-directive.spec.ts
  22. 13 6
      packages/pluginkit/src/v4/server/utils/theme/validate-growi-plugin-directive.ts
  23. 13 5
      packages/pluginkit/src/v4/utils/template.spec.ts
  24. 9 4
      packages/pluginkit/src/v4/utils/template.ts
  25. 2 6
      packages/pluginkit/tsconfig.json
  26. 2 4
      packages/pluginkit/vitest.config.ts

+ 0 - 1
biome.json

@@ -24,7 +24,6 @@
       "./packages/custom-icons/**",
       "./packages/editor/**",
       "./packages/pdf-converter-client/**",
-      "./packages/pluginkit/**",
       "./packages/presentation/**",
       "./packages/remark-attachment-refs/**"
     ]

+ 1 - 1
packages/pluginkit/.eslintignore

@@ -1 +1 @@
-/dist/**
+*

+ 0 - 5
packages/pluginkit/.eslintrc.cjs

@@ -1,5 +0,0 @@
-module.exports = {
-  extends: [
-    'plugin:vitest/recommended',
-  ],
-};

+ 1 - 1
packages/pluginkit/package.json

@@ -15,7 +15,7 @@
     "clean": "shx rm -rf dist",
     "dev": "vite build --mode dev",
     "watch": "pnpm run dev -w --emptyOutDir=false",
-    "lint:js": "eslint **/*.{js,ts}",
+    "lint:js": "biome check",
     "lint:typecheck": "vue-tsc --noEmit",
     "lint": "npm-run-all -p lint:*",
     "test": "vitest run --coverage"

+ 7 - 7
packages/pluginkit/src/model/growi-plugin-package-data.ts

@@ -1,12 +1,12 @@
 import type { GrowiPluginType } from '@growi/core';
 
 export type GrowiPluginDirective = {
-  [key: string]: any,
-  schemaVersion: number,
-  types: GrowiPluginType[],
-}
+  [key: string]: any;
+  schemaVersion: number;
+  types: GrowiPluginType[];
+};
 
 export type GrowiPluginPackageData = {
-  [key: string]: any,
-  growiPlugin: GrowiPluginDirective,
-}
+  [key: string]: any;
+  growiPlugin: GrowiPluginDirective;
+};

+ 9 - 9
packages/pluginkit/src/model/growi-plugin-validation-data.ts

@@ -3,17 +3,17 @@ import type { GrowiPluginType, GrowiThemeMetadata } from '@growi/core';
 import type { GrowiPluginDirective } from './growi-plugin-package-data';
 
 export type GrowiPluginValidationData = {
-  projectDirRoot: string,
-  growiPlugin: GrowiPluginDirective,
-  schemaVersion: number,
-  expectedPluginType?: GrowiPluginType,
-  actualPluginTypes?: GrowiPluginType[],
+  projectDirRoot: string;
+  growiPlugin: GrowiPluginDirective;
+  schemaVersion: number;
+  expectedPluginType?: GrowiPluginType;
+  actualPluginTypes?: GrowiPluginType[];
 };
 
 export type GrowiTemplatePluginValidationData = GrowiPluginValidationData & {
-  supportingLocales: string[],
-}
+  supportingLocales: string[];
+};
 
 export type GrowiThemePluginValidationData = GrowiPluginValidationData & {
-  themes: GrowiThemeMetadata[],
-}
+  themes: GrowiThemeMetadata[];
+};

+ 4 - 4
packages/pluginkit/src/model/growi-plugin-validation-error.ts

@@ -2,14 +2,14 @@ import ExtensibleCustomError from 'extensible-custom-error';
 
 import type { GrowiPluginValidationData } from './growi-plugin-validation-data';
 
-
-export class GrowiPluginValidationError<E extends Partial<GrowiPluginValidationData> = Partial<GrowiPluginValidationData>> extends ExtensibleCustomError {
-
+export class GrowiPluginValidationError<
+  E extends
+    Partial<GrowiPluginValidationData> = Partial<GrowiPluginValidationData>,
+> extends ExtensibleCustomError {
   data?: E;
 
   constructor(message: string, data?: E) {
     super(message);
     this.data = data;
   }
-
 }

+ 3 - 1
packages/pluginkit/src/v4/client/utils/growi-facade/growi-react.spec.ts

@@ -14,7 +14,9 @@ describe('growiReact()', () => {
   it('returns window.growiFacade.react in production mode', () => {
     // given
     process.env.NODE_ENV = 'production';
-    const mockProductionReact = { useEffect: () => {} } as unknown as typeof React;
+    const mockProductionReact = {
+      useEffect: () => {},
+    } as unknown as typeof React;
 
     (global as any).window = {
       growiFacade: {

+ 1 - 2
packages/pluginkit/src/v4/client/utils/growi-facade/growi-react.ts

@@ -2,10 +2,9 @@ import type React from 'react';
 
 import type { GrowiFacade } from '@growi/core';
 
-
 declare global {
   interface Window {
-    growiFacade: GrowiFacade
+    growiFacade: GrowiFacade;
   }
 }
 

+ 18 - 16
packages/pluginkit/src/v4/interfaces/template.ts

@@ -1,25 +1,27 @@
 export type TemplateStatusBasis = {
-  id: string,
-  locale: string,
-  pluginId?: string,
-}
+  id: string;
+  locale: string;
+  pluginId?: string;
+};
 export type TemplateStatusValid = TemplateStatusBasis & {
-  isValid: true,
-  isDefault: boolean,
-  title: string,
-  desc?: string,
-}
+  isValid: true;
+  isDefault: boolean;
+  title: string;
+  desc?: string;
+};
 export type TemplateStatusInvalid = TemplateStatusBasis & {
-  isValid: false,
-  invalidReason: string,
-}
+  isValid: false;
+  invalidReason: string;
+};
 export type TemplateStatus = TemplateStatusValid | TemplateStatusInvalid;
 
-export function isTemplateStatusValid(status: TemplateStatus): status is TemplateStatusValid {
+export function isTemplateStatusValid(
+  status: TemplateStatus,
+): status is TemplateStatusValid {
   return status.isValid;
 }
 
 export type TemplateSummary = {
-  default: TemplateStatusValid,
-  [locale: string]: TemplateStatus,
-}
+  default: TemplateStatusValid;
+  [locale: string]: TemplateStatus;
+};

+ 7 - 2
packages/pluginkit/src/v4/server/utils/common/import-package-json.spec.ts

@@ -2,9 +2,14 @@ import path from 'path';
 
 import { importPackageJson } from './import-package-json';
 
-it('importPackageJson() returns an object', async() => {
+it('importPackageJson() returns an object', async () => {
   // when
-  const pkg = importPackageJson(path.resolve(__dirname, '../../../../../test/fixtures/example-package/template1'));
+  const pkg = importPackageJson(
+    path.resolve(
+      __dirname,
+      '../../../../../test/fixtures/example-package/template1',
+    ),
+  );
 
   // then
   expect(pkg).not.toBeNull();

+ 3 - 1
packages/pluginkit/src/v4/server/utils/common/import-package-json.ts

@@ -3,7 +3,9 @@ import path from 'path';
 
 import type { GrowiPluginPackageData } from '../../../../model';
 
-export const importPackageJson = (projectDirRoot: string): GrowiPluginPackageData => {
+export const importPackageJson = (
+  projectDirRoot: string,
+): GrowiPluginPackageData => {
   const packageJsonUrl = path.resolve(projectDirRoot, 'package.json');
   return JSON.parse(readFileSync(packageJsonUrl, 'utf-8'));
 };

+ 36 - 17
packages/pluginkit/src/v4/server/utils/common/validate-growi-plugin-directive.spec.ts

@@ -2,7 +2,6 @@ import { GrowiPluginType } from '@growi/core';
 
 import examplePkg from '../../../../../test/fixtures/example-package/template1/package.json';
 
-
 import { validateGrowiDirective } from './validate-growi-plugin-directive';
 
 const mocks = vi.hoisted(() => {
@@ -16,8 +15,7 @@ vi.mock('./import-package-json', () => {
 });
 
 describe('validateGrowiDirective()', () => {
-
-  it('returns a data object', async() => {
+  it('returns a data object', async () => {
     // setup
     mocks.importPackageJsonMock.mockReturnValue(examplePkg);
 
@@ -28,28 +26,34 @@ describe('validateGrowiDirective()', () => {
     expect(data).not.toBeNull();
   });
 
-  it("with the 'expectedPluginType' argument returns a data object", async() => {
+  it("with the 'expectedPluginType' argument returns a data object", async () => {
     // setup
     mocks.importPackageJsonMock.mockReturnValue(examplePkg);
 
     // when
-    const data = validateGrowiDirective('package.json', GrowiPluginType.Template);
+    const data = validateGrowiDirective(
+      'package.json',
+      GrowiPluginType.Template,
+    );
 
     // then
     expect(data).not.toBeNull();
   });
 
   describe('should throw an GrowiPluginValidationError', () => {
-
     it("when the pkg does not have 'growiPlugin' directive", () => {
       // setup
       mocks.importPackageJsonMock.mockReturnValue({});
 
       // when
-      const caller = () => { validateGrowiDirective('package.json') };
+      const caller = () => {
+        validateGrowiDirective('package.json');
+      };
 
       // then
-      expect(caller).toThrow("The package.json does not have 'growiPlugin' directive.");
+      expect(caller).toThrow(
+        "The package.json does not have 'growiPlugin' directive.",
+      );
     });
 
     it("when the 'schemaVersion' is NaN", () => {
@@ -61,10 +65,14 @@ describe('validateGrowiDirective()', () => {
       });
 
       // when
-      const caller = () => { validateGrowiDirective('package.json') };
+      const caller = () => {
+        validateGrowiDirective('package.json');
+      };
 
       // then
-      expect(caller).toThrow("The growiPlugin directive must have a valid 'schemaVersion' directive.");
+      expect(caller).toThrow(
+        "The growiPlugin directive must have a valid 'schemaVersion' directive.",
+      );
     });
 
     it("when the 'schemaVersion' is less than 4", () => {
@@ -76,10 +84,14 @@ describe('validateGrowiDirective()', () => {
       });
 
       // when
-      const caller = () => { validateGrowiDirective('package.json') };
+      const caller = () => {
+        validateGrowiDirective('package.json');
+      };
 
       // then
-      expect(caller).toThrow("The growiPlugin directive must have a valid 'schemaVersion' directive.");
+      expect(caller).toThrow(
+        "The growiPlugin directive must have a valid 'schemaVersion' directive.",
+      );
     });
 
     it("when the 'types' directive does not exist", () => {
@@ -91,10 +103,14 @@ describe('validateGrowiDirective()', () => {
       });
 
       // when
-      const caller = () => { validateGrowiDirective('package.json') };
+      const caller = () => {
+        validateGrowiDirective('package.json');
+      };
 
       // then
-      expect(caller).toThrow("The growiPlugin directive does not have 'types' directive.");
+      expect(caller).toThrow(
+        "The growiPlugin directive does not have 'types' directive.",
+      );
     });
 
     it("when the 'types' directive does not have expected plugin type", () => {
@@ -107,11 +123,14 @@ describe('validateGrowiDirective()', () => {
       });
 
       // when
-      const caller = () => { validateGrowiDirective('package.json', GrowiPluginType.Script) };
+      const caller = () => {
+        validateGrowiDirective('package.json', GrowiPluginType.Script);
+      };
 
       // then
-      expect(caller).toThrow("The growiPlugin directive does not have expected plugin type in 'types' directive.");
+      expect(caller).toThrow(
+        "The growiPlugin directive does not have expected plugin type in 'types' directive.",
+      );
     });
   });
-
 });

+ 29 - 8
packages/pluginkit/src/v4/server/utils/common/validate-growi-plugin-directive.ts

@@ -1,32 +1,50 @@
 import type { GrowiPluginType } from '@growi/core';
 
-import { type GrowiPluginValidationData, GrowiPluginValidationError } from '../../../../model';
+import {
+  type GrowiPluginValidationData,
+  GrowiPluginValidationError,
+} from '../../../../model';
 
 import { importPackageJson } from './import-package-json';
 
-
-export const validateGrowiDirective = (projectDirRoot: string, expectedPluginType?: GrowiPluginType): GrowiPluginValidationData => {
+export const validateGrowiDirective = (
+  projectDirRoot: string,
+  expectedPluginType?: GrowiPluginType,
+): GrowiPluginValidationData => {
   const pkg = importPackageJson(projectDirRoot);
 
   const { growiPlugin } = pkg;
 
-  const data: GrowiPluginValidationData = { projectDirRoot, schemaVersion: NaN, growiPlugin };
+  const data: GrowiPluginValidationData = {
+    projectDirRoot,
+    schemaVersion: Number.NaN,
+    growiPlugin,
+  };
 
   if (growiPlugin == null) {
-    throw new GrowiPluginValidationError("The package.json does not have 'growiPlugin' directive.", data);
+    throw new GrowiPluginValidationError(
+      "The package.json does not have 'growiPlugin' directive.",
+      data,
+    );
   }
 
   // schema version checking
   const schemaVersion = Number(growiPlugin.schemaVersion);
   data.schemaVersion = schemaVersion;
   if (Number.isNaN(schemaVersion) || schemaVersion < 4) {
-    throw new GrowiPluginValidationError("The growiPlugin directive must have a valid 'schemaVersion' directive.", data);
+    throw new GrowiPluginValidationError(
+      "The growiPlugin directive must have a valid 'schemaVersion' directive.",
+      data,
+    );
   }
 
   const types: GrowiPluginType[] = growiPlugin.types;
   data.actualPluginTypes = types;
   if (types == null) {
-    throw new GrowiPluginValidationError("The growiPlugin directive does not have 'types' directive.", data);
+    throw new GrowiPluginValidationError(
+      "The growiPlugin directive does not have 'types' directive.",
+      data,
+    );
   }
 
   // type checking
@@ -34,7 +52,10 @@ export const validateGrowiDirective = (projectDirRoot: string, expectedPluginTyp
     data.expectedPluginType = expectedPluginType;
 
     if (!types.includes(expectedPluginType)) {
-      throw new GrowiPluginValidationError("The growiPlugin directive does not have expected plugin type in 'types' directive.", data);
+      throw new GrowiPluginValidationError(
+        "The growiPlugin directive does not have expected plugin type in 'types' directive.",
+        data,
+      );
     }
   }
 

+ 5 - 2
packages/pluginkit/src/v4/server/utils/template/get-markdown.ts

@@ -3,8 +3,11 @@ import path from 'path';
 
 import { getStatus } from './get-status';
 
-
-export const getMarkdown = async(projectDirRoot: string, templateId: string, locale: string): Promise<string> => {
+export const getMarkdown = async (
+  projectDirRoot: string,
+  templateId: string,
+  locale: string,
+): Promise<string> => {
   const tplDir = path.resolve(projectDirRoot, 'dist', templateId, locale);
 
   const { isTemplateExists } = await getStatus(tplDir);

+ 6 - 6
packages/pluginkit/src/v4/server/utils/template/get-status.ts

@@ -2,14 +2,12 @@ import fs, { readFileSync } from 'fs';
 import path from 'path';
 import { promisify } from 'util';
 
-
 const statAsync = promisify(fs.stat);
 
-
 type TemplateDirStatus = {
-  isTemplateExists: boolean,
-  meta?: { [key: string]: string },
-}
+  isTemplateExists: boolean;
+  meta?: { [key: string]: string };
+};
 
 export async function getStatus(tplDir: string): Promise<TemplateDirStatus> {
   const markdownPath = path.resolve(tplDir, 'template.md');
@@ -22,7 +20,9 @@ export async function getStatus(tplDir: string): Promise<TemplateDirStatus> {
 
   const result: TemplateDirStatus = {
     isTemplateExists,
-    meta: isMetaDataFileExists ? JSON.parse(readFileSync(metaDataPath, 'utf-8')) : undefined,
+    meta: isMetaDataFileExists
+      ? JSON.parse(readFileSync(metaDataPath, 'utf-8'))
+      : undefined,
   };
 
   return result;

+ 45 - 31
packages/pluginkit/src/v4/server/utils/template/scan.ts

@@ -2,19 +2,22 @@ import fs from 'fs';
 import path from 'path';
 
 import type { GrowiTemplatePluginValidationData } from '../../../../model';
-import { isTemplateStatusValid, type TemplateStatus, type TemplateSummary } from '../../../interfaces';
+import {
+  type TemplateStatus,
+  type TemplateSummary,
+  isTemplateStatusValid,
+} from '../../../interfaces';
 
 import { getStatus } from './get-status';
 import { validateTemplatePluginGrowiDirective } from './validate-growi-plugin-directive';
 
-
-export const scanTemplate = async(
-    projectDirRoot: string,
-    templateId: string,
-    data: GrowiTemplatePluginValidationData,
-    opts?: {
-      pluginId?: string,
-    },
+export const scanTemplate = async (
+  projectDirRoot: string,
+  templateId: string,
+  data: GrowiTemplatePluginValidationData,
+  opts?: {
+    pluginId?: string;
+  },
 ): Promise<TemplateStatus[]> => {
   const status: TemplateStatus[] = [];
 
@@ -26,13 +29,12 @@ export const scanTemplate = async(
 
     try {
       const stats = await getStatus(tplDir);
-      const {
-        isTemplateExists, meta,
-      } = stats;
+      const { isTemplateExists, meta } = stats;
 
       if (!isTemplateExists) throw new Error("'template.md does not exist.");
       if (meta == null) throw new Error("'meta.md does not exist.");
-      if (meta?.title == null) throw new Error("'meta.md does not contain the title.");
+      if (meta?.title == null)
+        throw new Error("'meta.md does not contain the title.");
 
       const isDefault = !isDefaultPushed;
       status.push({
@@ -45,8 +47,7 @@ export const scanTemplate = async(
         desc: meta.desc,
       });
       isDefaultPushed = true;
-    }
-    catch (err) {
+    } catch (err) {
       status.push({
         pluginId: opts?.pluginId,
         id: templateId,
@@ -58,21 +59,23 @@ export const scanTemplate = async(
   }
 
   // eslint-disable-next-line no-console
-  console.debug(`Template directory (${projectDirRoot}) has scanned`, { status });
+  console.debug(`Template directory (${projectDirRoot}) has scanned`, {
+    status,
+  });
 
   return status;
 };
 
-export const scanAllTemplates = async(
-    projectDirRoot: string,
-    opts?: {
-      data?: GrowiTemplatePluginValidationData,
-      pluginId?: string,
-      returnsInvalidTemplates?: boolean,
-    },
+export const scanAllTemplates = async (
+  projectDirRoot: string,
+  opts?: {
+    data?: GrowiTemplatePluginValidationData;
+    pluginId?: string;
+    returnsInvalidTemplates?: boolean;
+  },
 ): Promise<TemplateSummary[]> => {
-
-  const data = opts?.data ?? validateTemplatePluginGrowiDirective(projectDirRoot);
+  const data =
+    opts?.data ?? validateTemplatePluginGrowiDirective(projectDirRoot);
 
   const summaries: TemplateSummary[] = [];
 
@@ -80,14 +83,23 @@ export const scanAllTemplates = async(
   const distDirFiles = fs.readdirSync(distDirPath);
 
   for await (const templateId of distDirFiles) {
-    const status = (await scanTemplate(projectDirRoot, templateId, data, { pluginId: opts?.pluginId }))
+    const status = (
+      await scanTemplate(projectDirRoot, templateId, data, {
+        pluginId: opts?.pluginId,
+      })
+    )
       // omit invalid templates if `returnsInvalidTemplates` is true
-      .filter(s => (opts?.returnsInvalidTemplates ? true : s.isValid));
+      .filter((s) => (opts?.returnsInvalidTemplates ? true : s.isValid));
 
     // determine default locale
-    const defaultTemplateStatus = status.find(s => 'isDefault' in s && s.isDefault);
-
-    if (defaultTemplateStatus == null || !isTemplateStatusValid(defaultTemplateStatus)) {
+    const defaultTemplateStatus = status.find(
+      (s) => 'isDefault' in s && s.isDefault,
+    );
+
+    if (
+      defaultTemplateStatus == null ||
+      !isTemplateStatusValid(defaultTemplateStatus)
+    ) {
       continue;
     }
 
@@ -95,7 +107,9 @@ export const scanAllTemplates = async(
       // for the 'default' key
       default: defaultTemplateStatus,
       // for each locale keys
-      ...Object.fromEntries(status.map(templateStatus => [templateStatus.locale, templateStatus])),
+      ...Object.fromEntries(
+        status.map((templateStatus) => [templateStatus.locale, templateStatus]),
+      ),
     });
   }
 

+ 15 - 7
packages/pluginkit/src/v4/server/utils/template/validate-all-locales.ts

@@ -1,11 +1,15 @@
 import { scanAllTemplates } from './scan';
 import { validateTemplatePluginGrowiDirective } from './validate-growi-plugin-directive';
 
-
-export const validateAllTemplateLocales = async(projectDirRoot: string): Promise<boolean> => {
+export const validateAllTemplateLocales = async (
+  projectDirRoot: string,
+): Promise<boolean> => {
   const data = validateTemplatePluginGrowiDirective(projectDirRoot);
 
-  const results = await scanAllTemplates(projectDirRoot, { data, returnsInvalidTemplates: true });
+  const results = await scanAllTemplates(projectDirRoot, {
+    data,
+    returnsInvalidTemplates: true,
+  });
 
   if (Object.keys(results).length === 0) {
     throw new Error('This plugin does not have any templates');
@@ -16,18 +20,22 @@ export const validateAllTemplateLocales = async(projectDirRoot: string): Promise
   // value: isValid properties
   const idValidMap: { [id: string]: boolean[] } = {};
   results.forEach((summary) => {
-    idValidMap[summary.default.id] = Object.values(summary).map(s => s?.isValid ?? false);
+    idValidMap[summary.default.id] = Object.values(summary).map(
+      (s) => s?.isValid ?? false,
+    );
   });
 
   for (const [id, validMap] of Object.entries(idValidMap)) {
     // warn
-    if (!validMap.every(bool => bool)) {
+    if (!validMap.every((bool) => bool)) {
       // eslint-disable-next-line no-console
-      console.warn(`[WARN] Template '${id}' has some locales that status is invalid`);
+      console.warn(
+        `[WARN] Template '${id}' has some locales that status is invalid`,
+      );
     }
 
     // This means the template directory does not have any valid template
-    if (!validMap.some(bool => bool)) {
+    if (!validMap.some((bool) => bool)) {
       return false;
     }
   }

+ 15 - 10
packages/pluginkit/src/v4/server/utils/template/validate-growi-plugin-directive.spec.ts

@@ -4,12 +4,13 @@ import { GrowiPluginType } from '@growi/core';
 
 import { validateTemplatePluginGrowiDirective } from './validate-growi-plugin-directive';
 
-
 describe('validateTemplatePluginGrowiDirective()', () => {
-
-  it('returns a data object', async() => {
+  it('returns a data object', async () => {
     // setup
-    const projectDirRoot = path.resolve(__dirname, '../../../../../test/fixtures/example-package/template1');
+    const projectDirRoot = path.resolve(
+      __dirname,
+      '../../../../../test/fixtures/example-package/template1',
+    );
 
     // when
     const data = validateTemplatePluginGrowiDirective(projectDirRoot);
@@ -22,18 +23,22 @@ describe('validateTemplatePluginGrowiDirective()', () => {
   });
 
   describe('should throw an GrowiPluginValidationError', () => {
-
     it("when the pkg does not have 'growiPlugin.locale' directive", () => {
       // setup
-      const projectDirRoot = path.resolve(__dirname, '../../../../../test/fixtures/example-package/invalid-template1');
+      const projectDirRoot = path.resolve(
+        __dirname,
+        '../../../../../test/fixtures/example-package/invalid-template1',
+      );
 
       // when
-      const caller = () => { validateTemplatePluginGrowiDirective(projectDirRoot) };
+      const caller = () => {
+        validateTemplatePluginGrowiDirective(projectDirRoot);
+      };
 
       // then
-      expect(caller).toThrow("Template plugin must have 'supportingLocales' and that must have one or more locales");
+      expect(caller).toThrow(
+        "Template plugin must have 'supportingLocales' and that must have one or more locales",
+      );
     });
-
   });
-
 });

+ 10 - 4
packages/pluginkit/src/v4/server/utils/template/validate-growi-plugin-directive.ts

@@ -1,15 +1,19 @@
 import { GrowiPluginType } from '@growi/core';
 
-import type { GrowiPluginValidationData, GrowiTemplatePluginValidationData } from '../../../../model';
+import type {
+  GrowiPluginValidationData,
+  GrowiTemplatePluginValidationData,
+} from '../../../../model';
 import { GrowiPluginValidationError } from '../../../../model';
 import { validateGrowiDirective } from '../common';
 
-
 /**
  * An utility for template plugin which wrap 'validateGrowiDirective' of './common' module
  * @param projectDirRoot
  */
-export const validateTemplatePluginGrowiDirective = (projectDirRoot: string): GrowiTemplatePluginValidationData => {
+export const validateTemplatePluginGrowiDirective = (
+  projectDirRoot: string,
+): GrowiTemplatePluginValidationData => {
   const data = validateGrowiDirective(projectDirRoot, GrowiPluginType.Template);
 
   const { growiPlugin } = data;
@@ -17,7 +21,9 @@ export const validateTemplatePluginGrowiDirective = (projectDirRoot: string): Gr
   // check supporting locales
   const supportingLocales: string[] | undefined = growiPlugin.locales;
   if (supportingLocales == null || supportingLocales.length === 0) {
-    throw new GrowiPluginValidationError<GrowiPluginValidationData & { supportingLocales?: string[] }>(
+    throw new GrowiPluginValidationError<
+      GrowiPluginValidationData & { supportingLocales?: string[] }
+    >(
       "Template plugin must have 'supportingLocales' and that must have one or more locales",
       {
         ...data,

+ 22 - 12
packages/pluginkit/src/v4/server/utils/theme/validate-growi-plugin-directive.spec.ts

@@ -4,12 +4,13 @@ import { isGrowiThemeMetadata } from '@growi/core';
 
 import { validateThemePluginGrowiDirective } from './validate-growi-plugin-directive';
 
-
 describe('validateThemePluginGrowiDirective()', () => {
-
-  it('returns a data object', async() => {
+  it('returns a data object', async () => {
     // setup
-    const projectDirRoot = path.resolve(__dirname, '../../../../../test/fixtures/example-package/theme1');
+    const projectDirRoot = path.resolve(
+      __dirname,
+      '../../../../../test/fixtures/example-package/theme1',
+    );
 
     // when
     const data = validateThemePluginGrowiDirective(projectDirRoot);
@@ -22,29 +23,38 @@ describe('validateThemePluginGrowiDirective()', () => {
   });
 
   describe('should throw an GrowiPluginValidationError', () => {
-
     it("when the pkg does not have 'growiPlugin.themes' directive", () => {
       // setup
-      const projectDirRoot = path.resolve(__dirname, '../../../../../test/fixtures/example-package/invalid-theme1');
+      const projectDirRoot = path.resolve(
+        __dirname,
+        '../../../../../test/fixtures/example-package/invalid-theme1',
+      );
 
       // when
-      const caller = () => { validateThemePluginGrowiDirective(projectDirRoot) };
+      const caller = () => {
+        validateThemePluginGrowiDirective(projectDirRoot);
+      };
 
       // then
-      expect(caller).toThrow("Theme plugin must have 'themes' array and that must have one or more theme metadata");
+      expect(caller).toThrow(
+        "Theme plugin must have 'themes' array and that must have one or more theme metadata",
+      );
     });
 
     it("when the pkg does not have 'growiPlugin.locale' directive", () => {
       // setup
-      const projectDirRoot = path.resolve(__dirname, '../../../../../test/fixtures/example-package/invalid-theme2');
+      const projectDirRoot = path.resolve(
+        __dirname,
+        '../../../../../test/fixtures/example-package/invalid-theme2',
+      );
 
       // when
-      const caller = () => { validateThemePluginGrowiDirective(projectDirRoot) };
+      const caller = () => {
+        validateThemePluginGrowiDirective(projectDirRoot);
+      };
 
       // then
       expect(caller).toThrow(/^Some of theme metadata are invalid:/);
     });
-
   });
-
 });

+ 13 - 6
packages/pluginkit/src/v4/server/utils/theme/validate-growi-plugin-directive.ts

@@ -1,22 +1,30 @@
 import type { GrowiThemeMetadata } from '@growi/core';
 import { GrowiPluginType, isGrowiThemeMetadata } from '@growi/core';
 
-import type { GrowiPluginValidationData, GrowiThemePluginValidationData } from '../../../../model';
+import type {
+  GrowiPluginValidationData,
+  GrowiThemePluginValidationData,
+} from '../../../../model';
 import { GrowiPluginValidationError } from '../../../../model';
 import { validateGrowiDirective } from '../common';
 
-
 /**
  * An utility for theme plugin which wrap 'validateGrowiDirective' of './common' module
  * @param projectDirRoot
  */
-export const validateThemePluginGrowiDirective = (projectDirRoot: string): GrowiThemePluginValidationData => {
+export const validateThemePluginGrowiDirective = (
+  projectDirRoot: string,
+): GrowiThemePluginValidationData => {
   const data = validateGrowiDirective(projectDirRoot, GrowiPluginType.Theme);
 
   const { growiPlugin } = data;
 
   // check themes
-  if (growiPlugin.themes == null || !Array.isArray(growiPlugin.themes) || growiPlugin.themes.length === 0) {
+  if (
+    growiPlugin.themes == null ||
+    !Array.isArray(growiPlugin.themes) ||
+    growiPlugin.themes.length === 0
+  ) {
     throw new GrowiPluginValidationError<GrowiPluginValidationData>(
       "Theme plugin must have 'themes' array and that must have one or more theme metadata",
     );
@@ -27,8 +35,7 @@ export const validateThemePluginGrowiDirective = (projectDirRoot: string): Growi
   growiPlugin.themes.forEach((theme: unknown) => {
     if (isGrowiThemeMetadata(theme)) {
       validMetadatas.push(theme);
-    }
-    else {
+    } else {
       invalidObjects.push(theme);
     }
   });

+ 13 - 5
packages/pluginkit/src/v4/utils/template.spec.ts

@@ -1,6 +1,6 @@
 import type { TemplateSummary } from '../interfaces';
 
-import { getLocalizedTemplate, extractSupportedLocales } from './template';
+import { extractSupportedLocales, getLocalizedTemplate } from './template';
 
 describe('getLocalizedTemplate', () => {
   it('should return undefined if templateSummary is undefined', () => {
@@ -17,7 +17,9 @@ describe('getLocalizedTemplate', () => {
         title: 'Default Title',
       },
     };
-    expect(getLocalizedTemplate(templateSummary)).toEqual(templateSummary.default);
+    expect(getLocalizedTemplate(templateSummary)).toEqual(
+      templateSummary.default,
+    );
   });
 
   it('should return the localized template if locale is provided and exists in templateSummary', () => {
@@ -37,7 +39,9 @@ describe('getLocalizedTemplate', () => {
         title: 'Japanese Title',
       },
     };
-    expect(getLocalizedTemplate(templateSummary, 'ja_JP')).toEqual(templateSummary.ja_JP);
+    expect(getLocalizedTemplate(templateSummary, 'ja_JP')).toEqual(
+      templateSummary.ja_JP,
+    );
   });
 
   it('should return the default template if locale is provided but does not exist in templateSummary', () => {
@@ -50,7 +54,9 @@ describe('getLocalizedTemplate', () => {
         title: 'Default Title',
       },
     };
-    expect(getLocalizedTemplate(templateSummary, 'fr')).toEqual(templateSummary.default);
+    expect(getLocalizedTemplate(templateSummary, 'fr')).toEqual(
+      templateSummary.default,
+    );
   });
 });
 
@@ -76,6 +82,8 @@ describe('extractSupportedLocales', () => {
         title: 'Japanese Title',
       },
     };
-    expect(extractSupportedLocales(templateSummary)).toEqual(new Set(['en_US', 'ja_JP']));
+    expect(extractSupportedLocales(templateSummary)).toEqual(
+      new Set(['en_US', 'ja_JP']),
+    );
   });
 });

+ 9 - 4
packages/pluginkit/src/v4/utils/template.ts

@@ -1,6 +1,9 @@
-import type { TemplateSummary, TemplateStatus } from '../interfaces';
+import type { TemplateStatus, TemplateSummary } from '../interfaces';
 
-export const getLocalizedTemplate = (templateSummary: TemplateSummary | undefined, locale?: string): TemplateStatus | undefined => {
+export const getLocalizedTemplate = (
+  templateSummary: TemplateSummary | undefined,
+  locale?: string,
+): TemplateStatus | undefined => {
   if (templateSummary == null) {
     return undefined;
   }
@@ -10,10 +13,12 @@ export const getLocalizedTemplate = (templateSummary: TemplateSummary | undefine
     : templateSummary.default;
 };
 
-export const extractSupportedLocales = (templateSummary: TemplateSummary | undefined): Set<string> | undefined => {
+export const extractSupportedLocales = (
+  templateSummary: TemplateSummary | undefined,
+): Set<string> | undefined => {
   if (templateSummary == null) {
     return undefined;
   }
 
-  return new Set(Object.values(templateSummary).map(s => s.locale));
+  return new Set(Object.values(templateSummary).map((s) => s.locale));
 };

+ 2 - 6
packages/pluginkit/tsconfig.json

@@ -2,11 +2,7 @@
   "$schema": "http://json.schemastore.org/tsconfig",
   "extends": "../../tsconfig.base.json",
   "compilerOptions": {
-    "types": [
-      "vitest/globals"
-    ]
+    "types": ["vitest/globals"]
   },
-  "include": [
-    "src"
-  ]
+  "include": ["src"]
 }

+ 2 - 4
packages/pluginkit/vitest.config.ts

@@ -1,10 +1,8 @@
 import tsconfigPaths from 'vite-tsconfig-paths';
-import { defineConfig, coverageConfigDefaults } from 'vitest/config';
+import { coverageConfigDefaults, defineConfig } from 'vitest/config';
 
 export default defineConfig({
-  plugins: [
-    tsconfigPaths(),
-  ],
+  plugins: [tsconfigPaths()],
   test: {
     environment: 'node',
     clearMocks: true,