Skip to content

Commit

Permalink
feat: admin jsconfig when building plugin in javascript (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoward1994 authored Sep 2, 2024
1 parent 8be4f65 commit 845a3b0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-hairs-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@strapi/sdk-plugin': patch
---

add admin jsconfig when building plugin in javascript
7 changes: 7 additions & 0 deletions src/cli/commands/plugin/init/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
24 changes: 24 additions & 0 deletions src/cli/commands/plugin/init/files/javascript.ts
Original file line number Diff line number Diff line change
@@ -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 };

0 comments on commit 845a3b0

Please sign in to comment.