Skip to content

Commit

Permalink
Build: Use regular expressions to mark packages as external (#1589)
Browse files Browse the repository at this point in the history
## Motivation for the change, related issues

Follows up on
#1586

Extracting external packages names from the `package.json` files did not
work as expected due to `cwd` misconfiguration in CI. This PR replaces
that logic with a regexp matching the name of the packages from this
monorepo to avoid maintaining the paths entirely.

## Testing instructions

Run `nx build php-wasm-node` and confirm the
resulting`dist/packages/playground/client/index.js` file and other built
npm-published modules do not bundle any external modules. The only
exception should be the `cli` packages.
  • Loading branch information
adamziel authored Jul 9, 2024
1 parent 22390d6 commit a022e4c
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions packages/vite-extensions/vite-external-modules.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
import glob from 'glob';
import fs from 'fs';

const getPackageNames = (): string[] => {
const packageJsonPaths = glob
.sync('../php-wasm/*/package.json')
.concat(glob.sync('../playground/*/package.json'));
const packageNames: string[] = [];

packageJsonPaths.forEach((packageJsonPath) => {
const packageJson = JSON.parse(
fs.readFileSync(packageJsonPath, 'utf8')
);
packageNames.push(packageJson.name);
});

return packageNames;
};

// Usage
const packageNames = getPackageNames();

export const getExternalModules = () => {
return [
'yargs',
Expand All @@ -38,6 +16,7 @@ export const getExternalModules = () => {
'dns',
'ws',
/node_modules\//,
...packageNames,
/^@php-wasm\//,
/^@wp-playground\//,
];
};

0 comments on commit a022e4c

Please sign in to comment.