From 33d7e7bda161f14ab31f410c9f57f9d9f9e9149e Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Thu, 8 Aug 2024 16:52:10 +0200 Subject: [PATCH 01/12] feat: in strapi project create plugin in plugin path --- src/cli/commands/plugin/init/action.ts | 763 +++++++++++++------------ src/cli/commands/utils/helpers.ts | 45 +- 2 files changed, 444 insertions(+), 364 deletions(-) diff --git a/src/cli/commands/plugin/init/action.ts b/src/cli/commands/plugin/init/action.ts index 9fba1e4..6d76434 100644 --- a/src/cli/commands/plugin/init/action.ts +++ b/src/cli/commands/plugin/init/action.ts @@ -6,6 +6,8 @@ import gitUrlParse from 'git-url-parse'; import path from 'node:path'; import { outdent } from 'outdent'; +import { dirContainsStrapiProject, logInstructions } from '../../utils/helpers'; + import { gitIgnoreFile } from './files/gitIgnore'; import type { CLIContext } from '../../../../types'; @@ -21,24 +23,49 @@ const USE_RC_VERSIONS: string[] = [ '@strapi/typescript-utils', ] as const; +// Store results of prompt answers (run by pack-up init) +// This is a limitation of pack-up; we cannot run the prompt and pass the answers in +let promptAnswers: any = []; + export default async ( packagePath: string, { silent, debug }: ActionOptions, { logger, cwd }: CLIContext ) => { try { + const isStrapi = dirContainsStrapiProject(cwd); + + // If the user entered a path, we will try to parse the plugin name from it so we can provide it as a suggestion for consistency + const parsedPath = path.parse(packagePath); + const suggestedPackageName = parsedPath.base; + const isPathPackageName = !packagePath.includes('/'); + const pluginPath = isStrapi && isPathPackageName ? `./src/plugins/${packagePath}` : packagePath; + + // + const template = getPluginTemplate({ suggestedPackageName }); + /** * Create the package // plugin */ await init({ - path: packagePath, + path: pluginPath, cwd, silent, debug, - template: PLUGIN_TEMPLATE, + template, }); - logger.info("Don't forget to enable your plugin in your configuration files."); + if (isStrapi) { + const pkgName = promptAnswers.find((option: any) => option?.name === 'pkgName')?.answer; + + const language = promptAnswers.find((option: any) => option?.name === 'typescript')?.answer + ? 'ts' + : 'js'; + + logger.info(logInstructions(pkgName, { language, path: pluginPath })); + } + + logger.info('Plugin generated successfully.'); } catch (err) { logger.error( 'There seems to be an unexpected error, try again with --debug for more information \n' @@ -101,436 +128,448 @@ interface PluginPackageJson { }; } -const PLUGIN_TEMPLATE = defineTemplate(async ({ logger, gitConfig, packagePath }) => { - let repo: { - source?: string; - owner?: string; - name?: string; - }; - - const [packageFolder] = packagePath.split(path.sep).slice(-1); - - if (!packagePath?.length || !packageFolder) { - throw new Error('Missing package path'); - } - - return { - prompts: [ - definePackageOption({ - name: 'repo', - type: 'text', - message: 'git url', - validate(val: unknown) { - if (!val) { - return true; - } +type PluginTemplateOptions = { + suggestedPackageName?: string; +}; - try { - const result = gitUrlParse(val as any); +const getPluginTemplate = ({ suggestedPackageName }: PluginTemplateOptions) => { + return defineTemplate(async ({ logger, gitConfig, packagePath }) => { + let repo: { + source?: string; + owner?: string; + name?: string; + }; - repo = { source: result.source, owner: result.owner, name: result.name }; + const [packageFolder] = packagePath.split(path.sep).slice(-1); - return true; - } catch (err) { - return 'invalid git url'; - } - }, - }), - definePackageOption({ - name: 'pkgName', - type: 'text', - message: 'plugin name', - initial: () => repo?.name ?? '', - validate(val: unknown) { - if (!val || typeof val !== 'string') { - return 'package name is required'; - } + if (!packagePath?.length || !packageFolder) { + throw new Error('Missing package path'); + } - const match = PACKAGE_NAME_REGEXP.exec(val); + return { + prompts: [ + definePackageOption({ + name: 'repo', + type: 'text', + message: 'git url', + validate(val: unknown) { + if (!val) { + return true; + } - if (!match) { - return 'invalid package name'; - } + try { + const result = gitUrlParse(val as any); - return true; - }, - }), - definePackageOption({ - name: 'displayName', - type: 'text', - message: 'plugin display name', - }), - definePackageOption({ - name: 'description', - type: 'text', - message: 'plugin description', - }), - definePackageOption({ - name: 'authorName', - type: 'text', - message: 'plugin author name', - initial: gitConfig?.user?.name, - }), - definePackageOption({ - name: 'authorEmail', - type: 'text', - message: 'plugin author email', - initial: gitConfig?.user?.email, - }), - definePackageOption({ - name: 'license', - type: 'text', - message: 'plugin license', - initial: 'MIT', - validate(v) { - if (!v) { - return 'license is required'; - } + repo = { source: result.source, owner: result.owner, name: result.name }; - return true; - }, - }), - definePackageOption({ - name: 'client-code', - type: 'confirm', - message: 'register with the admin panel?', - initial: true, - }), - definePackageOption({ - name: 'server-code', - type: 'confirm', - message: 'register with the server?', - initial: true, - }), - definePackageFeature({ - name: 'editorconfig', - initial: true, - optional: true, - }), - definePackageFeature({ - name: 'eslint', - initial: true, - optional: true, - }), - definePackageFeature({ - name: 'prettier', - initial: true, - optional: true, - }), - definePackageFeature({ - name: 'typescript', - initial: true, - optional: true, - }), - ], - async getFiles(answers) { - const author: string[] = []; - - const files: TemplateFile[] = []; - - // package.json - const pkgJson: PluginPackageJson = { - version: '0.0.0', - keywords: [], - type: 'commonjs', - exports: { - './package.json': './package.json', - }, - files: ['dist'], - scripts: { - build: 'strapi-plugin build', - watch: 'strapi-plugin watch', - 'watch:link': 'strapi-plugin watch:link', - verify: 'strapi-plugin verify', - }, - dependencies: {}, - devDependencies: { - /** - * We set * as a default version, but further down - * we try to resolve each package to their latest - * version, failing that we leave the fallback of *. - */ - '@strapi/strapi': '*', - '@strapi/sdk-plugin': '*', - prettier: '*', - }, - peerDependencies: { - // TODO: set this to 5.0.0 when Strapi 5 is released - '@strapi/strapi': '^5.0.0-beta', - '@strapi/sdk-plugin': '^5.0.0', - }, - strapi: { - kind: 'plugin', - }, - }; - - if (Array.isArray(answers)) { - for (const ans of answers) { - const { name, answer } = ans; - - switch (name) { - case 'pkgName': { - pkgJson.name = String(answer); - pkgJson.strapi.name = String(answer); - break; + return true; + } catch (err) { + return 'invalid git url'; } - case 'description': { - pkgJson.description = String(answer) ?? undefined; - pkgJson.strapi.description = String(answer) ?? undefined; - break; + }, + }), + definePackageOption({ + name: 'pkgName', + type: 'text', + message: 'plugin name', + initial: () => suggestedPackageName ?? repo?.name ?? '', + validate(val: unknown) { + if (!val || typeof val !== 'string') { + return 'package name is required'; } - case 'displayName': { - pkgJson.strapi.displayName = String(answer) ?? undefined; - break; - } - case 'authorName': { - author.push(String(answer)); - break; - } - case 'authorEmail': { - if (answer) { - author.push(`<${answer}>`); - } - break; - } - case 'license': { - pkgJson.license = String(answer); - break; - } - case 'client-code': { - if (answer) { - pkgJson.exports['./strapi-admin'] = { - source: './admin/src/index.js', - import: './dist/admin/index.mjs', - require: './dist/admin/index.js', - default: './dist/admin/index.js', - }; - - pkgJson.dependencies = { - ...pkgJson.dependencies, - '@strapi/design-system': '*', - '@strapi/icons': '*', - 'react-intl': '*', - }; - - pkgJson.devDependencies = { - ...pkgJson.devDependencies, - react: '*', - 'react-dom': '*', - 'react-router-dom': '*', - 'styled-components': '*', - }; - - pkgJson.peerDependencies = { - ...pkgJson.peerDependencies, - react: '^17.0.0 || ^18.0.0', - 'react-dom': '^17.0.0 || ^18.0.0', - 'react-router-dom': '^6.0.0', - 'styled-components': '^6.0.0', - }; - } - break; + const match = PACKAGE_NAME_REGEXP.exec(val); + + if (!match) { + return 'invalid package name'; } - case 'server-code': { - if (answer) { - pkgJson.exports['./strapi-server'] = { - source: './server/src/index.js', - import: './dist/server/index.mjs', - require: './dist/server/index.js', - default: './dist/server/index.js', - }; - - pkgJson.files.push('./strapi-server.js'); - - files.push({ - name: 'strapi-server.js', - contents: outdent` - 'use strict'; - - module.exports = require('./dist/server'); - `, - }); - } - break; + return true; + }, + }), + definePackageOption({ + name: 'displayName', + type: 'text', + message: 'plugin display name', + }), + definePackageOption({ + name: 'description', + type: 'text', + message: 'plugin description', + }), + definePackageOption({ + name: 'authorName', + type: 'text', + message: 'plugin author name', + initial: gitConfig?.user?.name, + }), + definePackageOption({ + name: 'authorEmail', + type: 'text', + message: 'plugin author email', + initial: gitConfig?.user?.email, + }), + definePackageOption({ + name: 'license', + type: 'text', + message: 'plugin license', + initial: 'MIT', + validate(v) { + if (!v) { + return 'license is required'; } - case 'typescript': { - const isTypescript = Boolean(answer); - if (isTypescript) { - if (isRecord(pkgJson.exports['./strapi-admin'])) { - pkgJson.exports['./strapi-admin'].source = './admin/src/index.ts'; + return true; + }, + }), + definePackageOption({ + name: 'client-code', + type: 'confirm', + message: 'register with the admin panel?', + initial: true, + }), + definePackageOption({ + name: 'server-code', + type: 'confirm', + message: 'register with the server?', + initial: true, + }), + definePackageFeature({ + name: 'editorconfig', + initial: true, + optional: true, + }), + definePackageFeature({ + name: 'eslint', + initial: true, + optional: true, + }), + definePackageFeature({ + name: 'prettier', + initial: true, + optional: true, + }), + definePackageFeature({ + name: 'typescript', + initial: true, + optional: true, + }), + ], + async getFiles(answers) { + const author: string[] = []; + + const files: TemplateFile[] = []; + + // package.json + const pkgJson: PluginPackageJson = { + version: '0.0.0', + keywords: [], + type: 'commonjs', + exports: { + './package.json': './package.json', + }, + files: ['dist'], + scripts: { + build: 'strapi-plugin build', + watch: 'strapi-plugin watch', + 'watch:link': 'strapi-plugin watch:link', + verify: 'strapi-plugin verify', + }, + dependencies: {}, + devDependencies: { + /** + * We set * as a default version, but further down + * we try to resolve each package to their latest + * version, failing that we leave the fallback of *. + */ + '@strapi/strapi': '*', + '@strapi/sdk-plugin': '*', + prettier: '*', + }, + peerDependencies: { + // TODO: set this to 5.0.0 when Strapi 5 is released + '@strapi/strapi': '^5.0.0-beta', + '@strapi/sdk-plugin': '^5.0.0', + }, + strapi: { + kind: 'plugin', + }, + }; + + if (Array.isArray(answers)) { + for (const ans of answers) { + const { name, answer } = ans; + switch (name) { + case 'pkgName': { + pkgJson.name = String(answer); + pkgJson.strapi.name = String(answer); + break; + } + case 'description': { + pkgJson.description = String(answer) ?? undefined; + pkgJson.strapi.description = String(answer) ?? undefined; + break; + } + case 'displayName': { + pkgJson.strapi.displayName = String(answer) ?? undefined; + break; + } + case 'authorName': { + author.push(String(answer)); + break; + } + case 'authorEmail': { + if (answer) { + author.push(`<${answer}>`); + } + break; + } + case 'license': { + pkgJson.license = String(answer); + break; + } + case 'client-code': { + if (answer) { pkgJson.exports['./strapi-admin'] = { - types: './dist/admin/src/index.d.ts', - ...pkgJson.exports['./strapi-admin'], + source: './admin/src/index.js', + import: './dist/admin/index.mjs', + require: './dist/admin/index.js', + default: './dist/admin/index.js', }; - pkgJson.scripts = { - ...pkgJson.scripts, - 'test:ts:front': 'run -T tsc -p admin/tsconfig.json', + pkgJson.dependencies = { + ...pkgJson.dependencies, + '@strapi/design-system': '*', + '@strapi/icons': '*', + 'react-intl': '*', }; pkgJson.devDependencies = { ...pkgJson.devDependencies, - '@types/react': '*', - '@types/react-dom': '*', + react: '*', + 'react-dom': '*', + 'react-router-dom': '*', + 'styled-components': '*', }; - const { adminTsconfigFiles } = await import('./files/typescript'); - - files.push(adminTsconfigFiles.tsconfigBuildFile, adminTsconfigFiles.tsconfigFile); + pkgJson.peerDependencies = { + ...pkgJson.peerDependencies, + react: '^17.0.0 || ^18.0.0', + 'react-dom': '^17.0.0 || ^18.0.0', + 'react-router-dom': '^6.0.0', + 'styled-components': '^6.0.0', + }; } - if (isRecord(pkgJson.exports['./strapi-server'])) { - pkgJson.exports['./strapi-server'].source = './server/src/index.ts'; - + break; + } + case 'server-code': { + if (answer) { pkgJson.exports['./strapi-server'] = { - types: './dist/server/src/index.d.ts', - ...pkgJson.exports['./strapi-server'], - }; - - pkgJson.scripts = { - ...pkgJson.scripts, - 'test:ts:back': 'run -T tsc -p server/tsconfig.json', + source: './server/src/index.js', + import: './dist/server/index.mjs', + require: './dist/server/index.js', + default: './dist/server/index.js', }; - const { serverTsconfigFiles } = await import('./files/typescript'); + pkgJson.files.push('./strapi-server.js'); - files.push( - serverTsconfigFiles.tsconfigBuildFile, - serverTsconfigFiles.tsconfigFile - ); + files.push({ + name: 'strapi-server.js', + contents: outdent` + 'use strict'; + + module.exports = require('./dist/server'); + `, + }); } - pkgJson.devDependencies = { - ...pkgJson.devDependencies, - '@strapi/typescript-utils': '*', - typescript: '*', - }; + break; } + case 'typescript': { + const isTypescript = Boolean(answer); + + if (isTypescript) { + if (isRecord(pkgJson.exports['./strapi-admin'])) { + pkgJson.exports['./strapi-admin'].source = './admin/src/index.ts'; + + pkgJson.exports['./strapi-admin'] = { + types: './dist/admin/src/index.d.ts', + ...pkgJson.exports['./strapi-admin'], + }; + + pkgJson.scripts = { + ...pkgJson.scripts, + 'test:ts:front': 'run -T tsc -p admin/tsconfig.json', + }; + + pkgJson.devDependencies = { + ...pkgJson.devDependencies, + '@types/react': '*', + '@types/react-dom': '*', + }; + + const { adminTsconfigFiles } = await import('./files/typescript'); + + files.push( + adminTsconfigFiles.tsconfigBuildFile, + adminTsconfigFiles.tsconfigFile + ); + } + + if (isRecord(pkgJson.exports['./strapi-server'])) { + pkgJson.exports['./strapi-server'].source = './server/src/index.ts'; + + pkgJson.exports['./strapi-server'] = { + types: './dist/server/src/index.d.ts', + ...pkgJson.exports['./strapi-server'], + }; + + pkgJson.scripts = { + ...pkgJson.scripts, + 'test:ts:back': 'run -T tsc -p server/tsconfig.json', + }; + + const { serverTsconfigFiles } = await import('./files/typescript'); + + files.push( + serverTsconfigFiles.tsconfigBuildFile, + serverTsconfigFiles.tsconfigFile + ); + } + + pkgJson.devDependencies = { + ...pkgJson.devDependencies, + '@strapi/typescript-utils': '*', + typescript: '*', + }; + } - /** - * This is where we add all the source files regardless - * of whether they are typescript or javascript. - */ - if (isRecord(pkgJson.exports['./strapi-admin'])) { - files.push({ - name: isTypescript ? 'admin/src/pluginId.ts' : 'admin/src/pluginId.js', - contents: outdent` + /** + * This is where we add all the source files regardless + * of whether they are typescript or javascript. + */ + if (isRecord(pkgJson.exports['./strapi-admin'])) { + files.push({ + name: isTypescript ? 'admin/src/pluginId.ts' : 'admin/src/pluginId.js', + contents: outdent` export const PLUGIN_ID = '${pkgJson.name!.replace(/^strapi-plugin-/i, '')}'; `, - }); + }); - if (isTypescript) { - const { adminTypescriptFiles } = await import('./files/admin'); + if (isTypescript) { + const { adminTypescriptFiles } = await import('./files/admin'); - files.push(...adminTypescriptFiles); - } else { - const { adminJavascriptFiles } = await import('./files/admin'); + files.push(...adminTypescriptFiles); + } else { + const { adminJavascriptFiles } = await import('./files/admin'); - files.push(...adminJavascriptFiles); + files.push(...adminJavascriptFiles); + } } - } - if (isRecord(pkgJson.exports['./strapi-server'])) { - if (isTypescript) { - const { serverTypescriptFiles } = await import('./files/server'); + if (isRecord(pkgJson.exports['./strapi-server'])) { + if (isTypescript) { + const { serverTypescriptFiles } = await import('./files/server'); - files.push(...serverTypescriptFiles(packageFolder)); - } else { - const { serverJavascriptFiles } = await import('./files/server'); + files.push(...serverTypescriptFiles(packageFolder)); + } else { + const { serverJavascriptFiles } = await import('./files/server'); - files.push(...serverJavascriptFiles(packageFolder)); + files.push(...serverJavascriptFiles(packageFolder)); + } } + + break; } + case 'eslint': { + if (answer) { + const { eslintIgnoreFile } = await import('./files/eslint'); - break; - } - case 'eslint': { - if (answer) { - const { eslintIgnoreFile } = await import('./files/eslint'); + files.push(eslintIgnoreFile); + } - files.push(eslintIgnoreFile); + break; } + case 'prettier': { + if (answer) { + const { prettierFile, prettierIgnoreFile } = await import('./files/prettier'); - break; - } - case 'prettier': { - if (answer) { - const { prettierFile, prettierIgnoreFile } = await import('./files/prettier'); - - files.push(prettierFile, prettierIgnoreFile); + files.push(prettierFile, prettierIgnoreFile); + } + break; } - break; - } - case 'editorconfig': { - if (answer) { - const { editorConfigFile } = await import('./files/editorConfig'); + case 'editorconfig': { + if (answer) { + const { editorConfigFile } = await import('./files/editorConfig'); - files.push(editorConfigFile); + files.push(editorConfigFile); + } + break; } - break; + default: + break; } - default: - break; } } - } - if (repo) { - pkgJson.repository = { - type: 'git', - url: `git+ssh://git@${repo.source}/${repo.owner}/${repo.name}.git`, - }; - pkgJson.bugs = { - url: `https://${repo.source}/${repo.owner}/${repo.name}/issues`, - }; - pkgJson.homepage = `https://${repo.source}/${repo.owner}/${repo.name}#readme`; - } - - pkgJson.author = author.filter(Boolean).join(' ') ?? undefined; - - try { - pkgJson.devDependencies = await resolveLatestVerisonOfDeps(pkgJson.devDependencies); - pkgJson.dependencies = await resolveLatestVerisonOfDeps(pkgJson.dependencies); - pkgJson.peerDependencies = await resolveLatestVerisonOfDeps(pkgJson.peerDependencies); - } catch (err) { - if (err instanceof Error) { - logger.error(err.message); - } else { - logger.error(err); + if (repo) { + pkgJson.repository = { + type: 'git', + url: `git+ssh://git@${repo.source}/${repo.owner}/${repo.name}.git`, + }; + pkgJson.bugs = { + url: `https://${repo.source}/${repo.owner}/${repo.name}/issues`, + }; + pkgJson.homepage = `https://${repo.source}/${repo.owner}/${repo.name}#readme`; } - } - files.push({ - name: 'package.json', - contents: outdent` + pkgJson.author = author.filter(Boolean).join(' ') ?? undefined; + + try { + pkgJson.devDependencies = await resolveLatestVersionOfDeps(pkgJson.devDependencies); + pkgJson.dependencies = await resolveLatestVersionOfDeps(pkgJson.dependencies); + pkgJson.peerDependencies = await resolveLatestVersionOfDeps(pkgJson.peerDependencies); + } catch (err) { + if (err instanceof Error) { + logger.error(err.message); + } else { + logger.error(err); + } + } + + files.push({ + name: 'package.json', + contents: outdent` ${JSON.stringify(pkgJson, null, 2)} `, - }); + }); - files.push({ - name: 'README.md', - contents: outdent` + files.push({ + name: 'README.md', + contents: outdent` # ${pkgJson.name} ${pkgJson.description ?? ''} `, - }); + }); - files.push(gitIgnoreFile); + files.push(gitIgnoreFile); - return files; - }, - }; -}); + // Save prompt answers so we have access to them after init + promptAnswers = answers; + + return files; + }, + }; + }); +}; const isRecord = (value: unknown): value is Record => Boolean(value) && !Array.isArray(value) && typeof value === 'object'; -const resolveLatestVerisonOfDeps = async ( +const resolveLatestVersionOfDeps = async ( deps: Record ): Promise> => { const latestDeps: Record = {}; diff --git a/src/cli/commands/utils/helpers.ts b/src/cli/commands/utils/helpers.ts index 8138884..4a4704b 100644 --- a/src/cli/commands/utils/helpers.ts +++ b/src/cli/commands/utils/helpers.ts @@ -1,6 +1,10 @@ +import chalk from 'chalk'; +import fs from 'fs'; +import path from 'path'; + import type { CLIContext } from '../../../types'; -const runAction = +export const runAction = (name: string, action: (...args: any[]) => Promise) => (ctx: CLIContext, ...args: unknown[]) => { const { logger } = ctx; @@ -14,4 +18,41 @@ const runAction = }); }; -export { runAction }; +export const dirContainsStrapiProject = (dir: string) => { + try { + const packageJsonPath = path.join(dir, 'package.json'); + const pkgJSON = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); + return Boolean( + (pkgJSON.dependencies && pkgJSON.dependencies['@strapi/strapi']) || + (pkgJSON.devDependencies && pkgJSON.devDependencies['@strapi/strapi']) + ); + } catch (err) { + return false; + } +}; + +export const logInstructions = ( + pluginName: string, + { language, path: pluginPath }: { language: string; path?: string } +) => { + const maxLength = ` resolve: './src/plugins/${pluginName}'`.length; + const separator = Array(maxLength).fill('─').join(''); + + const exportInstruction = language === 'js' ? 'module.exports =' : 'export default'; + + return ` +You can now enable your plugin by adding the following in ${chalk.yellow( + `./config/plugins.${language}` + )} +${separator} +${exportInstruction} { + ${chalk.gray('// ...')} + ${chalk.green(`'${pluginName}'`)}: { + enabled: ${chalk.yellow(true)}, + resolve: ${chalk.yellow(pluginPath || `'./src/plugins/${pluginName}'`)} + }, + ${chalk.gray('// ...')} +} +${separator} +`; +}; From ddd9df574dea30c8e58f6122e557ad556a0d95c1 Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Thu, 8 Aug 2024 16:54:07 +0200 Subject: [PATCH 02/12] chore: changeset --- .changeset/wet-files-repeat.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/wet-files-repeat.md diff --git a/.changeset/wet-files-repeat.md b/.changeset/wet-files-repeat.md new file mode 100644 index 0000000..a48366c --- /dev/null +++ b/.changeset/wet-files-repeat.md @@ -0,0 +1,5 @@ +--- +'@strapi/sdk-plugin': minor +--- + +In Strapi projects, generate plugin in plugins path and log config info From 2e1ca56d4a4e9262bf909d7a2da55461663b291b Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Thu, 8 Aug 2024 17:01:49 +0200 Subject: [PATCH 03/12] enhancement: make path required --- src/cli/commands/plugin/init/command.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/commands/plugin/init/command.ts b/src/cli/commands/plugin/init/command.ts index b048500..725bf36 100644 --- a/src/cli/commands/plugin/init/command.ts +++ b/src/cli/commands/plugin/init/command.ts @@ -9,7 +9,7 @@ const command: StrapiCommand = ({ command: commanderCommand, ctx }) => { commanderCommand .command('init') .description('Create a new plugin at a given path') - .argument('[path]', 'path to the plugin', './src/plugins/my-plugin') + .argument('path', 'path to the plugin') .option('-d, --debug', 'Enable debugging mode with verbose logs', false) .option('--silent', "Don't log anything", false) .action((path, options) => { From 40b3f5039c1bda8ed29ba3fd1cd05a325f225fc7 Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Thu, 8 Aug 2024 17:18:05 +0200 Subject: [PATCH 04/12] chore: fix quotes --- src/cli/commands/utils/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/commands/utils/helpers.ts b/src/cli/commands/utils/helpers.ts index 4a4704b..1d6e51d 100644 --- a/src/cli/commands/utils/helpers.ts +++ b/src/cli/commands/utils/helpers.ts @@ -49,7 +49,7 @@ ${exportInstruction} { ${chalk.gray('// ...')} ${chalk.green(`'${pluginName}'`)}: { enabled: ${chalk.yellow(true)}, - resolve: ${chalk.yellow(pluginPath || `'./src/plugins/${pluginName}'`)} + resolve: '${chalk.yellow(pluginPath || `./src/plugins/${pluginName}`)}' }, ${chalk.gray('// ...')} } From ac47fe002e9e3a59838ef218ba95edca9c335203 Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Fri, 9 Aug 2024 13:25:58 +0200 Subject: [PATCH 05/12] fix: export in format expected by strapi --- src/cli/commands/plugin/init/files/server.ts | 45 ++++++++++++++------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/src/cli/commands/plugin/init/files/server.ts b/src/cli/commands/plugin/init/files/server.ts index bdfd103..32f7739 100644 --- a/src/cli/commands/plugin/init/files/server.ts +++ b/src/cli/commands/plugin/init/files/server.ts @@ -9,20 +9,33 @@ const TYPESCRIPT = (pluginName: string): TemplateFile[] => [ /** * Application methods */ - export * as bootstrap from './bootstrap'; - export * as destroy from './destroy'; - export * as register from './register'; + import bootstrap from './bootstrap'; + import destroy from './destroy'; + import register from './register'; /** * Plugin server methods */ - export * as config from './config'; - export * as contentTypes from './content-types'; - export * as controllers from './controllers'; - export * as middlewares from './middlewares'; - export * as policies from './policies'; - export * as routes from './routes'; - export * as services from './services'; + import config from './config'; + import contentTypes from './content-types'; + import controllers from './controllers'; + import middlewares from './middlewares'; + import policies from './policies'; + import routes from './routes'; + import services from './services'; + + export default { + register, + bootstrap, + destroy, + config, + controllers, + routes, + services, + contentTypes, + policies, + middlewares, + }; `, }, { @@ -79,7 +92,11 @@ const TYPESCRIPT = (pluginName: string): TemplateFile[] => [ { name: 'server/src/controllers/index.ts', contents: outdent` - export * as controller from './controller'; + import controller from './controller'; + + export default { + controller, + }; `, }, { @@ -131,7 +148,11 @@ const TYPESCRIPT = (pluginName: string): TemplateFile[] => [ { name: 'server/src/services/index.ts', contents: outdent` - export * as service from './service'; + import service from './service'; + + export default { + service, + }; `, }, { From ace6121f822ed84c2b5603a614d46c83bf0d8241 Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Fri, 9 Aug 2024 14:12:39 +0200 Subject: [PATCH 06/12] fix: strapi-server import paths --- src/cli/commands/plugin/init/action.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/cli/commands/plugin/init/action.ts b/src/cli/commands/plugin/init/action.ts index 6d76434..5412a4f 100644 --- a/src/cli/commands/plugin/init/action.ts +++ b/src/cli/commands/plugin/init/action.ts @@ -380,7 +380,7 @@ const getPluginTemplate = ({ suggestedPackageName }: PluginTemplateOptions) => { contents: outdent` 'use strict'; - module.exports = require('./dist/server'); + module.exports = require('./server/src'); `, }); } @@ -437,6 +437,19 @@ const getPluginTemplate = ({ suggestedPackageName }: PluginTemplateOptions) => { serverTsconfigFiles.tsconfigBuildFile, serverTsconfigFiles.tsconfigFile ); + + // Replace the strapi-server import to use the dist directory + const fileToUpdate = files.find((file) => file.name === 'strapi-server.js'); + if (fileToUpdate) { + fileToUpdate.contents = outdent` + 'use strict'; + + // New content goes here + module.exports = require('./dist/server'); + `; + } else { + logger.error('File with name strapi-server.js not found.'); + } } pkgJson.devDependencies = { From 3ecd542b98301e043ced7d5e4ed2060b16743a57 Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Fri, 9 Aug 2024 14:13:38 +0200 Subject: [PATCH 07/12] chore: remove comment --- src/cli/commands/plugin/init/action.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cli/commands/plugin/init/action.ts b/src/cli/commands/plugin/init/action.ts index 5412a4f..6138e2f 100644 --- a/src/cli/commands/plugin/init/action.ts +++ b/src/cli/commands/plugin/init/action.ts @@ -444,7 +444,6 @@ const getPluginTemplate = ({ suggestedPackageName }: PluginTemplateOptions) => { fileToUpdate.contents = outdent` 'use strict'; - // New content goes here module.exports = require('./dist/server'); `; } else { From 15e7e72c827cf616c5091248173ab0d444b968c3 Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Tue, 13 Aug 2024 16:18:56 +0200 Subject: [PATCH 08/12] revert: import path --- src/cli/commands/plugin/init/action.ts | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/cli/commands/plugin/init/action.ts b/src/cli/commands/plugin/init/action.ts index 6138e2f..6d76434 100644 --- a/src/cli/commands/plugin/init/action.ts +++ b/src/cli/commands/plugin/init/action.ts @@ -380,7 +380,7 @@ const getPluginTemplate = ({ suggestedPackageName }: PluginTemplateOptions) => { contents: outdent` 'use strict'; - module.exports = require('./server/src'); + module.exports = require('./dist/server'); `, }); } @@ -437,18 +437,6 @@ const getPluginTemplate = ({ suggestedPackageName }: PluginTemplateOptions) => { serverTsconfigFiles.tsconfigBuildFile, serverTsconfigFiles.tsconfigFile ); - - // Replace the strapi-server import to use the dist directory - const fileToUpdate = files.find((file) => file.name === 'strapi-server.js'); - if (fileToUpdate) { - fileToUpdate.contents = outdent` - 'use strict'; - - module.exports = require('./dist/server'); - `; - } else { - logger.error('File with name strapi-server.js not found.'); - } } pkgJson.devDependencies = { From cbfb8d93330b33dc487b39cd2c6a5d2b3477f6de Mon Sep 17 00:00:00 2001 From: Convly Date: Tue, 13 Aug 2024 16:53:37 +0200 Subject: [PATCH 09/12] fix: ensures compatibility with CommonJS modules during the build --- package.json | 1 + pnpm-lock.yaml | 170 +++++++++++++++++++++++++++++++ src/cli/commands/plugin/build.ts | 2 + 3 files changed, 173 insertions(+) diff --git a/package.json b/package.json index 8adf868..4fa6cdb 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "watch": "pack-up watch" }, "dependencies": { + "@rollup/plugin-commonjs": "^26.0.1", "@strapi/pack-up": ">=5.0.1-alpha.1 <6.0.0", "@types/prompts": "2.4.9", "boxen": "5.1.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cbd6830..5a21a78 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: dependencies: + '@rollup/plugin-commonjs': + specifier: ^26.0.1 + version: 26.0.1(rollup@4.14.1) '@strapi/pack-up': specifier: '>=5.0.1-alpha.1 <6.0.0' version: 5.0.1-alpha.1(@types/node@20.12.6) @@ -598,6 +601,10 @@ packages: '@humanwhocodes/object-schema@2.0.3': resolution: {integrity: sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==} + '@isaacs/cliui@8.0.2': + resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} + engines: {node: '>=12'} + '@istanbuljs/load-nyc-config@1.1.0': resolution: {integrity: sha512-VjeHSlIzpv/NyD3N0YuHfXOPDIixcA1q2ZV98wsMqcYlPmv2n3Yb2lYP9XMElnaFVXg5A7YLTeLu6V84uQDjmQ==} engines: {node: '>=8'} @@ -691,6 +698,9 @@ packages: '@jridgewell/sourcemap-codec@1.4.15': resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==} + '@jridgewell/sourcemap-codec@1.5.0': + resolution: {integrity: sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==} + '@jridgewell/trace-mapping@0.3.25': resolution: {integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==} @@ -715,6 +725,10 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} + '@pkgjs/parseargs@0.11.0': + resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} + engines: {node: '>=14'} + '@pkgr/core@0.1.1': resolution: {integrity: sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==} engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0} @@ -731,6 +745,24 @@ packages: resolution: {integrity: sha512-UA91GwWPhFExt3IizW6bOeY/pQ0BkuNwKjk9iQW9KqxluGCrg4VenZ0/L+2Y0+ZOtme72EVvg6v0zo3AMQRCeA==} engines: {node: '>=12'} + '@rollup/plugin-commonjs@26.0.1': + resolution: {integrity: sha512-UnsKoZK6/aGIH6AdkptXhNvhaqftcjq3zZdT+LY5Ftms6JR06nADcDsYp5hTU9E2lbJUEOhdlY5J4DNTneM+jQ==} + engines: {node: '>=16.0.0 || 14 >= 14.17'} + peerDependencies: + rollup: ^2.68.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + + '@rollup/pluginutils@5.1.0': + resolution: {integrity: sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + '@rollup/rollup-android-arm-eabi@4.14.1': resolution: {integrity: sha512-fH8/o8nSUek8ceQnT7K4EQbSiV7jgkHq81m9lWZFIXjJ7lJzpWXbQFpT/Zh6OZYnpFykvzC3fbEvEAFZu03dPA==} cpu: [arm] @@ -1470,6 +1502,9 @@ packages: resolution: {integrity: sha512-gk/Z852D2Wtb//0I+kRFNKKE9dIIVirjoqPoA1wJU+XePVXZfGeBpk45+A1rKO4Q43prqWBNY/MiIeRLbPWUaA==} engines: {node: '>=4.0.0'} + commondir@1.0.1: + resolution: {integrity: sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==} + compare-func@2.0.0: resolution: {integrity: sha512-zHig5N+tPWARooBnb0Zx1MFcdfpyJrfTJ3Y5L+IFvUm8rM74hHz66z0gw0x4tijh5CorKkKUCnW82R2vmpeCRA==} @@ -1688,6 +1723,9 @@ packages: resolution: {integrity: sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==} engines: {node: '>=10'} + eastasianwidth@0.2.0: + resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} + electron-to-chromium@1.4.730: resolution: {integrity: sha512-oJRPo82XEqtQAobHpJIR3zW5YO3sSRRkPz2an4yxi1UvqhsGm54vR/wzTFV74a3soDOJ8CKW7ajOOX5ESzddwg==} @@ -1981,6 +2019,9 @@ packages: resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==} engines: {node: '>=4.0'} + estree-walker@2.0.2: + resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} + esutils@2.0.3: resolution: {integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==} engines: {node: '>=0.10.0'} @@ -2079,6 +2120,10 @@ packages: for-each@0.3.3: resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==} + foreground-child@3.3.0: + resolution: {integrity: sha512-Ld2g8rrAyMYFXBhEqMz8ZAHBi4J4uS1i/CxGMDnjyFWddMXLVcDp051DZfu+t7+ab7Wv6SMqpWmyFIj5UbfFvg==} + engines: {node: '>=14'} + from2@2.3.0: resolution: {integrity: sha512-OMcX/4IC/uqEPVgGeyfN22LJk6AZrMkRZHxcHBMBvHScDGgwTm2GT2Wkgtocyd3JfZffjj2kYUDXXII0Fk9W0g==} @@ -2177,6 +2222,10 @@ packages: resolution: {integrity: sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==} engines: {node: '>=10.13.0'} + glob@10.4.5: + resolution: {integrity: sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==} + hasBin: true + glob@7.2.3: resolution: {integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==} @@ -2443,6 +2492,9 @@ packages: resolution: {integrity: sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==} engines: {node: '>=0.10.0'} + is-reference@1.2.1: + resolution: {integrity: sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==} + is-regex@1.1.4: resolution: {integrity: sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==} engines: {node: '>= 0.4'} @@ -2545,6 +2597,9 @@ packages: iterator.prototype@1.1.2: resolution: {integrity: sha512-DR33HMMr8EzwuRL8Y9D3u2BMj8+RqSE850jfGu59kS7tbmPLzGkZmVSfyCFSDxuZiEY6Rzt3T2NA/qU+NwVj1w==} + jackspeak@3.4.3: + resolution: {integrity: sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==} + jest-changed-files@29.7.0: resolution: {integrity: sha512-fEArFiwf1BpQ+4bXSprcDc3/x4HSzL4al2tozwVpDFpsxALjLYdyiIK4e5Vz66GQJIbXJ82+35PtysofptNX2w==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -2843,6 +2898,9 @@ packages: resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==} hasBin: true + lru-cache@10.4.3: + resolution: {integrity: sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==} + lru-cache@4.1.5: resolution: {integrity: sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==} @@ -2857,6 +2915,9 @@ packages: resolution: {integrity: sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==} hasBin: true + magic-string@0.30.11: + resolution: {integrity: sha512-+Wri9p0QHMy+545hKww7YAu5NyzF8iomPL/RQazugQ9+Ez4Ic3mERMd8ZTX5rfK944j+560ZJi8iAwgak1Ac7A==} + make-dir@4.0.0: resolution: {integrity: sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==} engines: {node: '>=10'} @@ -2921,6 +2982,10 @@ packages: minimist@1.2.8: resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} + minipass@7.1.2: + resolution: {integrity: sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==} + engines: {node: '>=16 || 14 >=14.17'} + mixme@0.5.10: resolution: {integrity: sha512-5H76ANWinB1H3twpJ6JY8uvAtpmFvHNArpilJAjXRKXSDDLPIMoZArw5SH0q9z+lLs8IrMw7Q2VWpWimFKFT1Q==} engines: {node: '>= 8.0.0'} @@ -3093,6 +3158,9 @@ packages: resolution: {integrity: sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==} engines: {node: '>=6'} + package-json-from-dist@1.0.0: + resolution: {integrity: sha512-dATvCeZN/8wQsGywez1mzHtTlP22H8OEfPrVMLNr4/eGa+ijtLn/6M5f0dY8UKNrC2O9UCU6SSoG3qRKnt7STw==} + parent-module@1.0.1: resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==} engines: {node: '>=6'} @@ -3137,6 +3205,10 @@ packages: path-parse@1.0.7: resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} + path-scurry@1.11.1: + resolution: {integrity: sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==} + engines: {node: '>=16 || 14 >=14.18'} + path-type@4.0.0: resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} engines: {node: '>=8'} @@ -3559,6 +3631,10 @@ packages: resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} engines: {node: '>=8'} + string-width@5.1.2: + resolution: {integrity: sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==} + engines: {node: '>=12'} + string-width@7.1.0: resolution: {integrity: sha512-SEIJCWiX7Kg4c129n48aDRwLbFb2LJmXXFrWBG4NGaRtMQ3myKPKbwrD1BKqQn74oCoNMBVrfDEr5M9YxCsrkw==} engines: {node: '>=18'} @@ -3902,6 +3978,10 @@ packages: resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} engines: {node: '>=10'} + wrap-ansi@8.1.0: + resolution: {integrity: sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==} + engines: {node: '>=12'} + wrap-ansi@9.0.0: resolution: {integrity: sha512-G8ura3S+3Z2G+mkgNRq8dqaFZAuxfsxpBB8OCTGRTCtp+l/v9nbFNmCUP1BZMts3G1142MsZfn6eeUKrr4PD1Q==} engines: {node: '>=18'} @@ -4571,6 +4651,15 @@ snapshots: '@humanwhocodes/object-schema@2.0.3': {} + '@isaacs/cliui@8.0.2': + dependencies: + string-width: 5.1.2 + string-width-cjs: string-width@4.2.3 + strip-ansi: 7.1.0 + strip-ansi-cjs: strip-ansi@6.0.1 + wrap-ansi: 8.1.0 + wrap-ansi-cjs: wrap-ansi@7.0.0 + '@istanbuljs/load-nyc-config@1.1.0': dependencies: camelcase: 5.3.1 @@ -4759,6 +4848,8 @@ snapshots: '@jridgewell/sourcemap-codec@1.4.15': {} + '@jridgewell/sourcemap-codec@1.5.0': {} + '@jridgewell/trace-mapping@0.3.25': dependencies: '@jridgewell/resolve-uri': 3.1.2 @@ -4796,6 +4887,9 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.17.1 + '@pkgjs/parseargs@0.11.0': + optional: true + '@pkgr/core@0.1.1': {} '@pnpm/config.env-replace@1.1.0': {} @@ -4810,6 +4904,25 @@ snapshots: '@pnpm/network.ca-file': 1.0.2 config-chain: 1.1.13 + '@rollup/plugin-commonjs@26.0.1(rollup@4.14.1)': + dependencies: + '@rollup/pluginutils': 5.1.0(rollup@4.14.1) + commondir: 1.0.1 + estree-walker: 2.0.2 + glob: 10.4.5 + is-reference: 1.2.1 + magic-string: 0.30.11 + optionalDependencies: + rollup: 4.14.1 + + '@rollup/pluginutils@5.1.0(rollup@4.14.1)': + dependencies: + '@types/estree': 1.0.5 + estree-walker: 2.0.2 + picomatch: 2.3.1 + optionalDependencies: + rollup: 4.14.1 + '@rollup/rollup-android-arm-eabi@4.14.1': optional: true @@ -5691,6 +5804,8 @@ snapshots: common-tags@1.8.2: {} + commondir@1.0.1: {} + compare-func@2.0.0: dependencies: array-ify: 1.0.0 @@ -5920,6 +6035,8 @@ snapshots: dotenv@8.6.0: {} + eastasianwidth@0.2.0: {} + electron-to-chromium@1.4.730: {} emittery@0.13.1: {} @@ -6438,6 +6555,8 @@ snapshots: estraverse@5.3.0: {} + estree-walker@2.0.2: {} + esutils@2.0.3: {} eventemitter3@5.0.1: {} @@ -6557,6 +6676,11 @@ snapshots: dependencies: is-callable: 1.2.7 + foreground-child@3.3.0: + dependencies: + cross-spawn: 7.0.3 + signal-exit: 4.1.0 + from2@2.3.0: dependencies: inherits: 2.0.4 @@ -6671,6 +6795,15 @@ snapshots: dependencies: is-glob: 4.0.3 + glob@10.4.5: + dependencies: + foreground-child: 3.3.0 + jackspeak: 3.4.3 + minimatch: 9.0.4 + minipass: 7.1.2 + package-json-from-dist: 1.0.0 + path-scurry: 1.11.1 + glob@7.2.3: dependencies: fs.realpath: 1.0.0 @@ -6896,6 +7029,10 @@ snapshots: is-plain-object@5.0.0: {} + is-reference@1.2.1: + dependencies: + '@types/estree': 1.0.5 + is-regex@1.1.4: dependencies: call-bind: 1.0.7 @@ -7007,6 +7144,12 @@ snapshots: reflect.getprototypeof: 1.0.6 set-function-name: 2.0.2 + jackspeak@3.4.3: + dependencies: + '@isaacs/cliui': 8.0.2 + optionalDependencies: + '@pkgjs/parseargs': 0.11.0 + jest-changed-files@29.7.0: dependencies: execa: 5.1.1 @@ -7475,6 +7618,8 @@ snapshots: dependencies: js-tokens: 4.0.0 + lru-cache@10.4.3: {} + lru-cache@4.1.5: dependencies: pseudomap: 1.0.2 @@ -7490,6 +7635,10 @@ snapshots: lz-string@1.5.0: {} + magic-string@0.30.11: + dependencies: + '@jridgewell/sourcemap-codec': 1.5.0 + make-dir@4.0.0: dependencies: semver: 7.6.0 @@ -7551,6 +7700,8 @@ snapshots: minimist@1.2.8: {} + minipass@7.1.2: {} + mixme@0.5.10: {} ms@2.1.2: {} @@ -7731,6 +7882,8 @@ snapshots: p-try@2.2.0: {} + package-json-from-dist@1.0.0: {} + parent-module@1.0.1: dependencies: callsites: 3.1.0 @@ -7766,6 +7919,11 @@ snapshots: path-parse@1.0.7: {} + path-scurry@1.11.1: + dependencies: + lru-cache: 10.4.3 + minipass: 7.1.2 + path-type@4.0.0: {} picocolors@1.0.0: {} @@ -8215,6 +8373,12 @@ snapshots: is-fullwidth-code-point: 3.0.0 strip-ansi: 6.0.1 + string-width@5.1.2: + dependencies: + eastasianwidth: 0.2.0 + emoji-regex: 9.2.2 + strip-ansi: 7.1.0 + string-width@7.1.0: dependencies: emoji-regex: 10.3.0 @@ -8573,6 +8737,12 @@ snapshots: string-width: 4.2.3 strip-ansi: 6.0.1 + wrap-ansi@8.1.0: + dependencies: + ansi-styles: 6.2.1 + string-width: 5.1.2 + strip-ansi: 7.1.0 + wrap-ansi@9.0.0: dependencies: ansi-styles: 6.2.1 diff --git a/src/cli/commands/plugin/build.ts b/src/cli/commands/plugin/build.ts index d911057..361cefd 100644 --- a/src/cli/commands/plugin/build.ts +++ b/src/cli/commands/plugin/build.ts @@ -1,3 +1,4 @@ +import commonjs from '@rollup/plugin-commonjs'; import { build } from '@strapi/pack-up'; import boxen from 'boxen'; import chalk from 'chalk'; @@ -70,6 +71,7 @@ const action = async ({ ...opts }: BuildCLIOptions, _cmd: unknown, { logger, cwd cwd, configFile: false, config: { + plugins: [commonjs()], bundles, dist: './dist', /** From 898cff1b2bf46dff238a228e022008992ae3721a Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Wed, 14 Aug 2024 10:54:32 +0200 Subject: [PATCH 10/12] revert: spacing --- src/cli/commands/plugin/init/action.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cli/commands/plugin/init/action.ts b/src/cli/commands/plugin/init/action.ts index 3c5aba2..750bd49 100644 --- a/src/cli/commands/plugin/init/action.ts +++ b/src/cli/commands/plugin/init/action.ts @@ -384,8 +384,9 @@ const getPluginTemplate = ({ suggestedPackageName }: PluginTemplateOptions) => { name: 'strapi-server.js', contents: outdent` 'use strict'; + module.exports = require('./dist/server'); - `, + `, }); } From 3a6154d3d4b09a92e8bfc32ac5c2ad4d6af6b6ab Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Wed, 14 Aug 2024 11:00:34 +0200 Subject: [PATCH 11/12] revert: spacing --- src/cli/commands/plugin/init/action.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/commands/plugin/init/action.ts b/src/cli/commands/plugin/init/action.ts index 750bd49..efa8fef 100644 --- a/src/cli/commands/plugin/init/action.ts +++ b/src/cli/commands/plugin/init/action.ts @@ -384,7 +384,7 @@ const getPluginTemplate = ({ suggestedPackageName }: PluginTemplateOptions) => { name: 'strapi-server.js', contents: outdent` 'use strict'; - + module.exports = require('./dist/server'); `, }); From edea3e7e801d0af750b0fb7b48a4fc068149dab1 Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Wed, 14 Aug 2024 11:22:28 +0200 Subject: [PATCH 12/12] chore: changeset --- .changeset/tricky-eyes-kneel.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tricky-eyes-kneel.md diff --git a/.changeset/tricky-eyes-kneel.md b/.changeset/tricky-eyes-kneel.md new file mode 100644 index 0000000..a7d08cf --- /dev/null +++ b/.changeset/tricky-eyes-kneel.md @@ -0,0 +1,5 @@ +--- +'@strapi/sdk-plugin': patch +--- + +Support commonjs plugins