Skip to content

Commit

Permalink
feat(node): allow executing esm compiled scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
bulldog98 authored and jaysoo committed May 4, 2023
1 parent e49b3c5 commit 096f1b9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
48 changes: 25 additions & 23 deletions e2e/node/src/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,44 +232,46 @@ describe('Node Applications', () => {
}
}, 120000);

it('should be able to run es module applications', async () => {
it('should be able to run ESM applications', async () => {
const esmapp = uniq('esmapp');

runCLI(`generate @nrwl/node:app ${esmapp} --linter=eslint`);
runCLI(
`generate @nrwl/node:app ${esmapp} --linter=eslint --framework=none --bundler=webpack`
);
updateJson(`apps/${esmapp}/tsconfig.app.json`, (config) => {
config.module = 'esnext';
config.target = 'es2020';
return config;
});
updateProjectConfig(esmapp, (config) => {
config.targets.build.executor = '@nrwl/node:webpack';
config.targets.build.options.outputFileName = 'main.mjs';
config.targets.build.options.webpackConfig = `apps/${esmapp}/webpack.config.js`;
config.targets.serve.executor = '@nrwl/node:node';
config.targets.serve.options.watch = false;
config.targets.build.options.assets = [];
return config;
});
updateFile(
`apps/${esmapp}/webpack.config.js`,
`module.exports = (config, context) => ({
...config,
experiments: {
...config.experiments,
outputModule: true,
topLevelAwait: true,
},
output: {
path: config.output.path,
chunkFormat: 'module',
library: {
type: 'module',
},
},
})`
`
const { composePlugins, withNx } = require('@nx/webpack');
module.exports = composePlugins(withNx(), (config) => {
config.experiments = {
...config.experiments,
outputModule: true,
topLevelAwait: true,
};
config.output = {
path: config.output.path,
chunkFormat: 'module',
library: { type: 'module' }
}
return config;
});
`
);
await runCLIAsync(`build ${esmapp}`);
const { stdout } = await runCLIAsync(`serve ${esmapp}`);
expect(stdout).toBe('Hello World!');
const p = await runCommandUntil(`serve ${esmapp}`, (output) => {
return output.includes('Hello World');
});
p.kill();
}, 300000);
});

Expand Down
11 changes: 1 addition & 10 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
{
"packages": ["build/packages/*", "build/packages/nx/native-packages/*"],
"version": "16.1.0-rc.1",
"granularPathspec": false,
"command": {
"publish": {
"graphType": "all"
}
}
}
{"packages":["build/packages/*","build/packages/nx/native-packages/*"],"version":"16.1.0","granularPathspec":false,"command":{"publish":{"graphType":"all"}}}

0 comments on commit 096f1b9

Please sign in to comment.