diff --git a/.changeset/cold-hairs-yawn.md b/.changeset/cold-hairs-yawn.md new file mode 100644 index 0000000..ad36401 --- /dev/null +++ b/.changeset/cold-hairs-yawn.md @@ -0,0 +1,5 @@ +--- +'@strapi/sdk-plugin': patch +--- + +add admin jsconfig when building plugin in javascript diff --git a/src/cli/commands/plugin/init/action.ts b/src/cli/commands/plugin/init/action.ts index efa8fef..b4be398 100644 --- a/src/cli/commands/plugin/init/action.ts +++ b/src/cli/commands/plugin/init/action.ts @@ -449,6 +449,13 @@ const getPluginTemplate = ({ suggestedPackageName }: PluginTemplateOptions) => { '@strapi/typescript-utils': '*', typescript: '*', }; + } else if (isRecord(pkgJson.exports['./strapi-admin'])) { + // If the plugin is not typescript, we need to add a jsconfig.json file + // to the frontend code. This configuration ensures we have no + // build errors for the frontend javascript code. + const { adminJsConfigFile } = await import('./files/javascript'); + + files.push(adminJsConfigFile); } /** diff --git a/src/cli/commands/plugin/init/files/javascript.ts b/src/cli/commands/plugin/init/files/javascript.ts new file mode 100644 index 0000000..fd8aaea --- /dev/null +++ b/src/cli/commands/plugin/init/files/javascript.ts @@ -0,0 +1,24 @@ +import { outdent } from 'outdent'; + +import type { TemplateFile } from '@strapi/pack-up'; + +const ADMIN: TemplateFile = { + name: 'admin/jsconfig.json', + contents: outdent` + { + "compilerOptions": { + "target": "es6", + "jsx": "react", + "module": "esnext", + "allowSyntheticDefaultImports": true, + "esModuleInterop": true + }, + "include": [ + "./src/**/*.js", + "./src/**/*.jsx" + ] + } + `, +}; + +export { ADMIN as adminJsConfigFile };