Skip to content

Commit

Permalink
Remove unecessary commonjs plugin (#53)
Browse files Browse the repository at this point in the history
* chore: remove extra commonjs plugin

* fix: nodemon setup
  • Loading branch information
alexandrebodin committed Sep 12, 2024
1 parent 374fd9a commit 4c9d898
Show file tree
Hide file tree
Showing 7 changed files with 1,224 additions and 1,794 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-cows-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@strapi/sdk-plugin': patch
---

Remove unecessary commonjs plugin
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@
"watch": "pack-up watch"
},
"dependencies": {
"@rollup/plugin-commonjs": "^26.0.1",
"@strapi/pack-up": ">=5.0.1-alpha.1 <6.0.0",
"@strapi/pack-up": "5.0.1-alpha.3",
"@types/prompts": "2.4.9",
"boxen": "5.1.2",
"chalk": "4.1.2",
Expand Down Expand Up @@ -88,7 +87,6 @@
"@types/git-url-parse": "9.0.3",
"@types/jest": "^29.5.12",
"@types/node": "^22.5.4",
"@types/nodemon": "^1.19.6",
"@types/prettier": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
Expand Down
2,897 changes: 1,154 additions & 1,743 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

14 changes: 2 additions & 12 deletions src/cli/commands/plugin/build.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import commonjs from '@rollup/plugin-commonjs';
import { build } from '@strapi/pack-up';
import boxen from 'boxen';
import chalk from 'chalk';
import { createCommand } from 'commander';

import { resolveConfig } from '../utils/config';
import { runAction } from '../utils/helpers';
import { loadPkg, validatePkg } from '../utils/pkg';

Expand Down Expand Up @@ -70,17 +70,7 @@ const action = async ({ ...opts }: BuildCLIOptions, _cmd: unknown, { logger, cwd
await build({
cwd,
configFile: false,
config: {
plugins: [commonjs()],
bundles,
dist: './dist',
/**
* ignore the exports map of a plugin, because we're streamlining the
* process and ensuring the server package and admin package are built
* with the correct runtime and their individual tsconfigs
*/
exports: {},
},
config: resolveConfig({ cwd, bundles }),
...opts,
});
} catch (err) {
Expand Down
55 changes: 31 additions & 24 deletions src/cli/commands/plugin/link-watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ const action = async (_opts: ActionOptions, _cmd: unknown, { cwd, logger }: CLIC
const outDir = './dist';
const extensions = 'ts,js,png,svg,gif,jpeg,css';

nodemon({
watch: [outDir],
ext: extensions,
exec: 'yalc push --changed',
});

const folder = path.join(cwd, outDir);

if (!(await pathExists(folder))) {
Expand All @@ -33,35 +27,48 @@ const action = async (_opts: ActionOptions, _cmd: unknown, { cwd, logger }: CLIC
const pkg = await loadPkg({ cwd, logger });
const pkgJson = await validatePkg({ pkg });

concurrently(['npm run watch']);
logger.info(
outdent`
Watching ${outDir} for changes to files with extensions: ${extensions}
nodemon
.on('start', () => {
logger.info(
outdent`
Watching ${outDir} for changes to files with extensions: ${extensions}
To use this package in Strapi, in a separate shell run:
cd /path/to/strapi/project
To use this package in Strapi, in a separate shell run:
cd /path/to/strapi/project
Then run one of the commands below based on the package manager used in that project:
Then run one of the commands below based on the package manager used in that project:
## yarn
${chalk.greenBright(`yarn dlx yalc add --link ${pkgJson.name} && yarn install`)}
## yarn
${chalk.greenBright(`yarn dlx yalc add --link ${pkgJson.name} && yarn install`)}
## npm
${chalk.greenBright(
`npx yalc add ${pkgJson.name} && npx yalc link ${pkgJson.name} && npm install`
)}
`.trimStart()
);

## npm
${chalk.greenBright(
`npx yalc add ${pkgJson.name} && npx yalc link ${pkgJson.name} && npm install`
)}
`.trimStart()
);
})
// @ts-expect-error - invalid types
nodemon({
watch: [outDir],
ext: extensions,
exec: 'yalc push --changed',
});

concurrently(['npm run watch']);

nodemon
.on('quit', () => {
process.exit();
})
.on('restart', (files: unknown) => {
logger.info('Found changes in files:', chalk.magentaBright(files));
logger.info('Pushing new yalc package...');
})
.on('crash', () => {
logger.error(
'An error occurred. Make sure yalc is installed globally on your system. Exiting...'
);

process.exit(1);
});
} catch (err) {
logger.error(
Expand Down
14 changes: 2 additions & 12 deletions src/cli/commands/plugin/watch.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import commonjs from '@rollup/plugin-commonjs';
import { watch } from '@strapi/pack-up';
import boxen from 'boxen';
import chalk from 'chalk';
import { createCommand } from 'commander';

import { resolveConfig } from '../utils/config';
import { runAction } from '../utils/helpers';
import { loadPkg, validatePkg } from '../utils/pkg';

Expand Down Expand Up @@ -67,17 +67,7 @@ const action = async (opts: ActionOptions, _cmd: unknown, { cwd, logger }: CLICo
await watch({
cwd,
configFile: false,
config: {
plugins: [commonjs()],
bundles,
dist: './dist',
/**
* ignore the exports map of a plugin, because we're streamlining the
* process and ensuring the server package and admin package are built
* with the correct runtime and their individual tsconfigs
*/
exports: {},
},
config: resolveConfig({ cwd, bundles }),
...opts,
});
} catch (err) {
Expand Down
29 changes: 29 additions & 0 deletions src/cli/commands/utils/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { ConfigBundle } from '@strapi/pack-up';

interface Options {
cwd: string;
bundles: ConfigBundle[];
}

export function resolveConfig(opts: Options) {
const { cwd, bundles } = opts;

return {
unstable_viteConfig: {
build: {
commonjsOptions: {
include: [/node_modules/, `${cwd}/**/*`],
extensions: ['.js', '.jsx', '.cjs'],
},
},
},
bundles,
dist: './dist',
/**
* ignore the exports map of a plugin, because we're streamlining the
* process and ensuring the server package and admin package are built
* with the correct runtime and their individual tsconfigs
*/
exports: {},
};
}

0 comments on commit 4c9d898

Please sign in to comment.