@nx/angular 20.8.0 → 20.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/migrations.json CHANGED
@@ -1660,6 +1660,15 @@
1660
1660
  "alwaysAddToPackageJson": false
1661
1661
  }
1662
1662
  }
1663
+ },
1664
+ "20.8.1": {
1665
+ "version": "20.8.1-beta.0",
1666
+ "packages": {
1667
+ "@nx/angular-rspack": {
1668
+ "version": "^20.7.0",
1669
+ "alwaysAddToPackageJson": false
1670
+ }
1671
+ }
1663
1672
  }
1664
1673
  }
1665
1674
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/angular",
3
- "version": "20.8.0",
3
+ "version": "20.8.2",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Playwright and Cypress. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
6
6
  "repository": {
@@ -72,14 +72,14 @@
72
72
  "semver": "^7.5.3",
73
73
  "tslib": "^2.3.0",
74
74
  "webpack-merge": "^5.8.0",
75
- "@nx/devkit": "20.8.0",
76
- "@nx/js": "20.8.0",
77
- "@nx/eslint": "20.8.0",
78
- "@nx/webpack": "20.8.0",
79
- "@nx/rspack": "20.8.0",
80
- "@nx/module-federation": "20.8.0",
81
- "@nx/web": "20.8.0",
82
- "@nx/workspace": "20.8.0",
75
+ "@nx/devkit": "20.8.2",
76
+ "@nx/js": "20.8.2",
77
+ "@nx/eslint": "20.8.2",
78
+ "@nx/webpack": "20.8.2",
79
+ "@nx/rspack": "20.8.2",
80
+ "@nx/module-federation": "20.8.2",
81
+ "@nx/web": "20.8.2",
82
+ "@nx/workspace": "20.8.2",
83
83
  "piscina": "^4.4.0"
84
84
  },
85
85
  "peerDependencies": {
@@ -76,6 +76,12 @@ async function applicationGenerator(tree, schema) {
76
76
  skipInstall: options.skipPackageJson,
77
77
  skipFormat: true,
78
78
  });
79
+ if (options.ssr) {
80
+ (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, './files/rspack-ssr'), options.appProjectSourceRoot, {
81
+ pathToDistFolder: (0, devkit_1.joinPathFragments)((0, devkit_1.offsetFromRoot)(options.appProjectRoot), options.outputPath, 'browser'),
82
+ tmpl: '',
83
+ });
84
+ }
79
85
  }
80
86
  if (!options.skipFormat) {
81
87
  await (0, devkit_1.formatFiles)(tree);
@@ -0,0 +1,72 @@
1
+ import 'zone.js/node';
2
+
3
+ import { APP_BASE_HREF } from '@angular/common';
4
+ import { CommonEngine } from '@angular/ssr/node';
5
+ import * as express from 'express';
6
+ import { existsSync } from 'node:fs';
7
+ import { join } from 'node:path';
8
+ import bootstrap from './main.server';
9
+
10
+ // The Express app is exported so that it can be used by serverless Functions.
11
+ export function app(): express.Express {
12
+ const server = express();
13
+ const distFolder = join(process.cwd(), "<%= pathToDistFolder %>");
14
+ const indexHtml = existsSync(join(distFolder, 'index.original.html'))
15
+ ? join(distFolder, 'index.original.html')
16
+ : join(distFolder, 'index.html');
17
+
18
+ const commonEngine = new CommonEngine();
19
+
20
+ server.set('view engine', 'html');
21
+ server.set('views', distFolder);
22
+
23
+ // Example Express Rest API endpoints
24
+ // server.get('/api/**', (req, res) => { });
25
+ // Serve static files from /browser
26
+ server.get(
27
+ '*.*',
28
+ express.static(distFolder, {
29
+ maxAge: '1y',
30
+ })
31
+ );
32
+
33
+ // All regular routes use the Angular engine
34
+ server.get('*', (req, res, next) => {
35
+ const { protocol, originalUrl, baseUrl, headers } = req;
36
+
37
+ commonEngine
38
+ .render({
39
+ bootstrap,
40
+ documentFilePath: indexHtml,
41
+ url: `${protocol}://${headers.host}${originalUrl}`,
42
+ publicPath: distFolder,
43
+ providers: [{ provide: APP_BASE_HREF, useValue: baseUrl }],
44
+ })
45
+ .then((html) => res.send(html))
46
+ .catch((err) => next(err));
47
+ });
48
+
49
+ return server;
50
+ }
51
+
52
+ function run(): void {
53
+ const port = process.env['PORT'] || 4000;
54
+
55
+ // Start up the Node server
56
+ const server = app();
57
+ server.listen(port, () => {
58
+ console.log(`Node Express server listening on http://localhost:${port}`);
59
+ });
60
+ }
61
+
62
+ // Webpack will replace 'require' with '__webpack_require__'
63
+ // '__non_webpack_require__' is a proxy to Node 'require'
64
+ // The below code is to ensure that the server is run only when not requiring the bundle.
65
+ declare const __non_webpack_require__: NodeRequire;
66
+ const mainModule = __non_webpack_require__.main;
67
+ const moduleFilename = (mainModule && mainModule.filename) || '';
68
+ if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
69
+ run();
70
+ }
71
+
72
+ export default bootstrap;
@@ -20,7 +20,6 @@ export interface Schema {
20
20
  e2eTestRunner?: E2eTestRunner;
21
21
  backendProject?: string;
22
22
  strict?: boolean;
23
- standaloneConfig?: boolean;
24
23
  port?: number;
25
24
  setParserOptionsProject?: boolean;
26
25
  skipPackageJson?: boolean;
@@ -130,12 +130,6 @@
130
130
  "description": "Create an application with stricter type checking and build optimization options.",
131
131
  "default": true
132
132
  },
133
- "standaloneConfig": {
134
- "description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
135
- "type": "boolean",
136
- "default": true,
137
- "x-deprecated": "Nx only supports standaloneConfig"
138
- },
139
133
  "port": {
140
134
  "type": "number",
141
135
  "description": "The port at which the remote application should be served."
@@ -14,7 +14,9 @@ const enquirer_1 = require("enquirer");
14
14
  const SUPPORTED_EXECUTORS = [
15
15
  '@angular-devkit/build-angular:browser',
16
16
  '@angular-devkit/build-angular:dev-server',
17
+ '@angular-devkit/build-angular:server',
17
18
  '@nx/angular:webpack-browser',
19
+ '@nx/angular:webpack-server',
18
20
  '@nx/angular:dev-server',
19
21
  '@nx/angular:module-federation-dev-server',
20
22
  ];
@@ -22,20 +24,12 @@ const RENAMED_OPTIONS = {
22
24
  main: 'browser',
23
25
  ngswConfigPath: 'serviceWorker',
24
26
  };
27
+ const DEFAULT_PORT = 4200;
25
28
  const REMOVED_OPTIONS = [
26
- 'publicHost',
27
- 'disableHostCheck',
28
- 'resourcesOutputPath',
29
- 'routesFile',
30
- 'routes',
31
- 'discoverRoutes',
32
- 'appModuleBundle',
33
- 'inputIndexPath',
34
- 'outputIndexPath',
35
29
  'buildOptimizer',
36
- 'deployUrl',
37
30
  'buildTarget',
38
31
  'browserTarget',
32
+ 'publicHost',
39
33
  ];
40
34
  function normalizeFromProjectRoot(tree, path, projectRoot) {
41
35
  if (projectRoot === '.') {
@@ -256,6 +250,7 @@ async function convertToRspack(tree, schema) {
256
250
  const serveTargetNames = [];
257
251
  let customWebpackConfigPath;
258
252
  (0, validate_supported_executor_1.validateSupportedBuildExecutor)(Object.values(project.targets));
253
+ let projectServePort = DEFAULT_PORT;
259
254
  for (const [targetName, target] of Object.entries(project.targets)) {
260
255
  if (target.executor === '@angular-devkit/build-angular:browser' ||
261
256
  target.executor === '@nx/angular:webpack-browser') {
@@ -268,12 +263,22 @@ async function convertToRspack(tree, schema) {
268
263
  }
269
264
  buildTargetNames.push(targetName);
270
265
  }
266
+ else if (target.executor === '@angular-devkit/build-angular:server' ||
267
+ target.executor === '@nx/angular:webpack-server') {
268
+ createConfigOptions.ssr ??= {};
269
+ createConfigOptions.ssr.entry ??= normalizeFromProjectRoot(tree, target.options.main, project.root);
270
+ createConfigOptions.server = './src/main.server.ts';
271
+ buildTargetNames.push(targetName);
272
+ }
271
273
  else if (target.executor === '@angular-devkit/build-angular:dev-server' ||
272
274
  target.executor === '@nx/angular:dev-server' ||
273
275
  target.executor === '@nx/angular:module-federation-dev-server') {
274
276
  createConfigOptions.devServer = {};
275
277
  if (target.options) {
276
278
  handleDevServerTargetOptions(tree, target.options, createConfigOptions.devServer, project.root);
279
+ if (target.options.port !== DEFAULT_PORT) {
280
+ projectServePort = target.options.port;
281
+ }
277
282
  }
278
283
  if (target.configurations) {
279
284
  for (const [configurationName, configuration] of Object.entries(target.configurations)) {
@@ -293,6 +298,11 @@ async function convertToRspack(tree, schema) {
293
298
  for (const targetName of [...buildTargetNames, ...serveTargetNames]) {
294
299
  delete project.targets[targetName];
295
300
  }
301
+ if (projectServePort !== DEFAULT_PORT) {
302
+ project.targets.serve ??= {};
303
+ project.targets.serve.options ??= {};
304
+ project.targets.serve.options.port = projectServePort;
305
+ }
296
306
  (0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
297
307
  const { rspackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxVersion);
298
308
  await rspackInitGenerator(tree, {
@@ -9,7 +9,7 @@ function createConfig(tree, opts, configurationOptions = {}, existingWebpackConf
9
9
  ? Object.entries(configurationOptions)
10
10
  .map(([configurationName, configurationOptions]) => {
11
11
  return `
12
- ${configurationName}: {
12
+ "${configurationName}": {
13
13
  options: {
14
14
  ${JSON.stringify(configurationOptions, undefined, 2).slice(1, -1)}
15
15
  }
@@ -17,6 +17,12 @@ function createConfig(tree, opts, configurationOptions = {}, existingWebpackConf
17
17
  })
18
18
  .join(',\n')
19
19
  : '';
20
+ const createConfigContents = `createConfig({
21
+ options: {
22
+ root: __dirname,
23
+ ${JSON.stringify(createConfigOptions, undefined, 2).slice(1, -1)}
24
+ }
25
+ }${hasConfigurations ? `, {${expandedConfigurationOptions}}` : ''});`;
20
26
  const configContents = `
21
27
  import { createConfig }from '@nx/angular-rspack';
22
28
  ${existingWebpackConfigPath
@@ -26,23 +32,14 @@ function createConfig(tree, opts, configurationOptions = {}, existingWebpackConf
26
32
  : `import webpackMerge from 'webpack-merge';`}`
27
33
  : ''}
28
34
 
29
- ${existingWebpackConfigPath ? 'const baseConfig = ' : 'export default '}createConfig({
30
- options: {
31
- root: __dirname,
32
- ${JSON.stringify(createConfigOptions, undefined, 2).slice(1, -1)}
33
- }
34
- }${hasConfigurations ? `, {${expandedConfigurationOptions}}` : ''});
35
35
  ${existingWebpackConfigPath
36
- ? `
37
- export default ${isExistingWebpackConfigFunction
38
- ? `async function (env, argv) {
39
- const oldConfig = await baseWebpackConfig;
36
+ ? `export default async () => {
37
+ const baseConfig = await ${createConfigContents}
38
+ ${isExistingWebpackConfigFunction
39
+ ? `const oldConfig = await baseWebpackConfig;
40
40
  const browserConfig = baseConfig[0];
41
- return oldConfig(browserConfig);
42
- }`
43
- : 'webpackMerge(baseConfig[0], baseWebpackConfig);'}
44
- `
45
- : ''}
46
- `;
41
+ return oldConfig(browserConfig);`
42
+ : 'return webpackMerge(baseConfig[0], baseWebpackConfig);'}};`
43
+ : `export default ${createConfigContents}`}`;
47
44
  tree.write((0, devkit_1.joinPathFragments)(root, 'rspack.config.ts'), configContents);
48
45
  }
@@ -30,7 +30,7 @@ function convertWebpackConfigToUseNxModuleFederationPlugin(webpackConfigContents
30
30
  const withModuleFederationImportNodes = (0, tsquery_1.tsquery)(ast, 'ImportDeclaration:has(StringLiteral[value=@nx/module-federation/angular])');
31
31
  if (withModuleFederationImportNodes.length > 0) {
32
32
  const withModuleFederationImportNode = withModuleFederationImportNodes[0];
33
- newWebpackConfigContents = `${webpackConfigContents.slice(0, withModuleFederationImportNode.getStart())}import { NxModuleFederationPlugin } from '@nx/module-federation/rspack';${webpackConfigContents.slice(withModuleFederationImportNode.getEnd())}`;
33
+ newWebpackConfigContents = `${webpackConfigContents.slice(0, withModuleFederationImportNode.getStart())}import { NxModuleFederationPlugin, NxModuleFederationDevServerPlugin } from '@nx/module-federation/rspack';${webpackConfigContents.slice(withModuleFederationImportNode.getEnd())}`;
34
34
  ast = tsquery_1.tsquery.ast(newWebpackConfigContents);
35
35
  const exportedWithModuleFederationNodes = (0, tsquery_1.tsquery)(ast, 'ExportAssignment:has(CallExpression > Identifier[name=withModuleFederation])');
36
36
  if (exportedWithModuleFederationNodes.length > 0) {
@@ -38,9 +38,10 @@ function convertWebpackConfigToUseNxModuleFederationPlugin(webpackConfigContents
38
38
  newWebpackConfigContents = `${newWebpackConfigContents.slice(0, exportedWithModuleFederationNode.getStart())}${newWebpackConfigContents.slice(exportedWithModuleFederationNode.getEnd())}
39
39
  export default {
40
40
  plugins: [
41
- new NxModuleFederationPlugin(config, {
41
+ new NxModuleFederationPlugin({ config }, {
42
42
  dts: false,
43
43
  }),
44
+ new NxModuleFederationDevServerPlugin({ config }),
44
45
  ]
45
46
  }
46
47
  `;
@@ -52,7 +53,7 @@ function convertWebpackConfigToUseNxModuleFederationPlugin(webpackConfigContents
52
53
  const withModuleFederationRequireNodes = (0, tsquery_1.tsquery)(ast, 'VariableStatement:has(CallExpression > Identifier[name=withModuleFederation], StringLiteral[value=@nx/module-federation/angular])');
53
54
  if (withModuleFederationRequireNodes.length > 0) {
54
55
  const withModuleFederationRequireNode = withModuleFederationRequireNodes[0];
55
- newWebpackConfigContents = `${webpackConfigContents.slice(0, withModuleFederationRequireNode.getStart())}const { NxModuleFederationPlugin } = require('@nx/module-federation/rspack');${webpackConfigContents.slice(withModuleFederationRequireNode.getEnd())}`;
56
+ newWebpackConfigContents = `${webpackConfigContents.slice(0, withModuleFederationRequireNode.getStart())}const { NxModuleFederationPlugin, NxModuleFederationDevServerPlugin } = require('@nx/module-federation/rspack');${webpackConfigContents.slice(withModuleFederationRequireNode.getEnd())}`;
56
57
  ast = tsquery_1.tsquery.ast(newWebpackConfigContents);
57
58
  const exportedWithModuleFederationNodes = (0, tsquery_1.tsquery)(ast, 'ExpressionStatement:has(BinaryExpression > PropertyAccessExpression:has(Identifier[name=module], Identifier[name=exports]), CallExpression:has(Identifier[name=withModuleFederation]))');
58
59
  if (exportedWithModuleFederationNodes.length > 0) {
@@ -63,6 +64,7 @@ function convertWebpackConfigToUseNxModuleFederationPlugin(webpackConfigContents
63
64
  new NxModuleFederationPlugin({ config }, {
64
65
  dts: false,
65
66
  }),
67
+ new NxModuleFederationDevServerPlugin({ config }),
66
68
  ]
67
69
  }
68
70
  `;
@@ -20,7 +20,6 @@ export interface Schema {
20
20
  e2eTestRunner?: E2eTestRunner;
21
21
  backendProject?: string;
22
22
  strict?: boolean;
23
- standaloneConfig?: boolean;
24
23
  inlineStyle?: boolean;
25
24
  inlineTemplate?: boolean;
26
25
  viewEncapsulation?: 'Emulated' | 'Native' | 'None';
@@ -144,12 +144,6 @@
144
144
  "description": "Create an application with stricter type checking and build optimization options.",
145
145
  "default": true
146
146
  },
147
- "standaloneConfig": {
148
- "description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
149
- "type": "boolean",
150
- "default": true,
151
- "x-deprecated": "Nx only supports standaloneConfig"
152
- },
153
147
  "setParserOptionsProject": {
154
148
  "type": "boolean",
155
149
  "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
@@ -12,7 +12,6 @@ export interface NormalizedSchema {
12
12
  buildable?: boolean;
13
13
  publishable?: boolean;
14
14
  importPath?: string;
15
- standaloneConfig?: boolean;
16
15
  spec?: boolean;
17
16
  commonModule?: boolean;
18
17
  routing?: boolean;
@@ -12,7 +12,6 @@ export interface Schema {
12
12
  buildable?: boolean;
13
13
  publishable?: boolean;
14
14
  importPath?: string;
15
- standaloneConfig?: boolean;
16
15
  spec?: boolean;
17
16
  flat?: boolean;
18
17
  commonModule?: boolean;
@@ -108,12 +108,6 @@
108
108
  "enum": ["eslint", "none"],
109
109
  "default": "eslint"
110
110
  },
111
- "standaloneConfig": {
112
- "description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
113
- "type": "boolean",
114
- "default": true,
115
- "x-deprecated": "Nx only supports standaloneConfig"
116
- },
117
111
  "compilationMode": {
118
112
  "description": "Specifies the compilation mode to use. If not specified, it will default to `partial` for publishable libraries and to `full` for buildable libraries. The `full` value can not be used for publishable libraries.",
119
113
  "type": "string",
@@ -19,7 +19,6 @@ export interface Schema {
19
19
  e2eTestRunner?: E2eTestRunner;
20
20
  backendProject?: string;
21
21
  strict?: boolean;
22
- standaloneConfig?: boolean;
23
22
  inlineStyle?: boolean;
24
23
  inlineTemplate?: boolean;
25
24
  viewEncapsulation?: 'Emulated' | 'Native' | 'None';
@@ -138,12 +138,6 @@
138
138
  "description": "Create an application with stricter type checking and build optimization options.",
139
139
  "default": true
140
140
  },
141
- "standaloneConfig": {
142
- "description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
143
- "type": "boolean",
144
- "default": true,
145
- "x-deprecated": "Nx only supports standaloneConfig"
146
- },
147
141
  "setParserOptionsProject": {
148
142
  "type": "boolean",
149
143
  "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
@@ -2,7 +2,7 @@ export declare const nxVersion: any;
2
2
  export declare const angularVersion = "~19.2.0";
3
3
  export declare const angularDevkitVersion = "~19.2.0";
4
4
  export declare const ngPackagrVersion = "~19.2.0";
5
- export declare const angularRspackVersion = "~20.6.1";
5
+ export declare const angularRspackVersion = "^20.7.0";
6
6
  export declare const ngrxVersion = "^19.0.0";
7
7
  export declare const rxjsVersion = "~7.8.0";
8
8
  export declare const zoneJsVersion = "~0.15.0";
@@ -5,7 +5,7 @@ exports.nxVersion = require('../../package.json').version;
5
5
  exports.angularVersion = '~19.2.0';
6
6
  exports.angularDevkitVersion = '~19.2.0';
7
7
  exports.ngPackagrVersion = '~19.2.0';
8
- exports.angularRspackVersion = '~20.6.1';
8
+ exports.angularRspackVersion = '^20.7.0';
9
9
  exports.ngrxVersion = '^19.0.0';
10
10
  exports.rxjsVersion = '~7.8.0';
11
11
  exports.zoneJsVersion = '~0.15.0';