From 205550d5d5a5104402b79fdfa254a2df5a9bfb65 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Wed, 21 Aug 2024 15:37:06 -0400 Subject: [PATCH] fix(node): generate webpack server apps with generatePackageJson:true by default (#27570) We already do this for esbuild apps (e.g. express, fastify, koa), but we don't do it for webpack (nest). ## Current Behavior ## Expected Behavior ## Related Issue(s) Fixes #27389 (cherry picked from commit ca8995092098e656002db7095857801662707a51) --- .../application/application.legacy.spec.ts | 1 + .../application/application.spec.ts | 24 +++++++++++++++++++ .../src/generators/application/application.ts | 1 + .../files/common/webpack.config.js__tmpl__ | 1 + 4 files changed, 27 insertions(+) diff --git a/packages/node/src/generators/application/application.legacy.spec.ts b/packages/node/src/generators/application/application.legacy.spec.ts index 9a56a513d9f22..21044e90c13f4 100644 --- a/packages/node/src/generators/application/application.legacy.spec.ts +++ b/packages/node/src/generators/application/application.legacy.spec.ts @@ -42,6 +42,7 @@ describe('node app generator (legacy)', () => { "my-node-app/src/assets", ], "compiler": "tsc", + "generatePackageJson": true, "main": "my-node-app/src/main.ts", "outputPath": "dist/my-node-app", "target": "node", diff --git a/packages/node/src/generators/application/application.spec.ts b/packages/node/src/generators/application/application.spec.ts index d41ede16d3084..50482703ca2c8 100644 --- a/packages/node/src/generators/application/application.spec.ts +++ b/packages/node/src/generators/application/application.spec.ts @@ -63,6 +63,30 @@ describe('app', () => { }, } `); + expect(tree.read(`my-node-app/webpack.config.js`, 'utf-8')) + .toMatchInlineSnapshot(` + "const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin'); + const { join } = require('path'); + + module.exports = { + output: { + path: join(__dirname, '../dist/my-node-app'), + }, + plugins: [ + new NxAppWebpackPlugin({ + target: 'node', + compiler: 'tsc', + main: './src/main.ts', + tsConfig: './tsconfig.app.json', + assets: ['./src/assets'], + optimization: false, + outputHashing: 'none', + generatePackageJson: true, + }), + ], + }; + " + `); expect(() => readProjectConfiguration(tree, 'my-node-app-e2e') ).not.toThrow(); diff --git a/packages/node/src/generators/application/application.ts b/packages/node/src/generators/application/application.ts index b889224c70d9f..541b1d8517c97 100644 --- a/packages/node/src/generators/application/application.ts +++ b/packages/node/src/generators/application/application.ts @@ -79,6 +79,7 @@ function getWebpackBuildConfig( options.appProjectRoot, 'webpack.config.js' ), + generatePackageJson: true, }, configurations: { development: {}, diff --git a/packages/node/src/generators/application/files/common/webpack.config.js__tmpl__ b/packages/node/src/generators/application/files/common/webpack.config.js__tmpl__ index e913fff9c264a..052c7a86d19ee 100644 --- a/packages/node/src/generators/application/files/common/webpack.config.js__tmpl__ +++ b/packages/node/src/generators/application/files/common/webpack.config.js__tmpl__ @@ -15,6 +15,7 @@ module.exports = { assets: <%- JSON.stringify(webpackPluginOptions.assets) %>, optimization: false, outputHashing: 'none', + generatePackageJson: true, }) ], };