From 845a3b0facdcb47f5fdc2716eb8d1ae45109beaa Mon Sep 17 00:00:00 2001 From: Jamie Howard <48524071+jhoward1994@users.noreply.github.com> Date: Mon, 2 Sep 2024 13:01:52 +0100 Subject: [PATCH] feat: admin jsconfig when building plugin in javascript (#43) --- .changeset/cold-hairs-yawn.md | 5 ++++ src/cli/commands/plugin/init/action.ts | 7 ++++++ .../commands/plugin/init/files/javascript.ts | 24 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 .changeset/cold-hairs-yawn.md create mode 100644 src/cli/commands/plugin/init/files/javascript.ts 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 };