@nx/angular 18.0.2 → 18.0.4

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.
Files changed (21) hide show
  1. package/package.json +10 -10
  2. package/src/builders/dev-server/dev-server.impl.js +13 -10
  3. package/src/builders/dev-server/lib/index.d.ts +1 -0
  4. package/src/builders/dev-server/lib/index.js +1 -0
  5. package/src/builders/dev-server/lib/validate-options.d.ts +2 -0
  6. package/src/builders/dev-server/lib/validate-options.js +18 -0
  7. package/src/builders/dev-server/schema.d.ts +1 -0
  8. package/src/builders/dev-server/schema.json +5 -0
  9. package/src/executors/module-federation-dev-server/lib/build-static-remotes.d.ts +2 -5
  10. package/src/executors/module-federation-dev-server/lib/build-static-remotes.js +7 -8
  11. package/src/executors/module-federation-dev-server/lib/index.d.ts +1 -0
  12. package/src/executors/module-federation-dev-server/lib/index.js +1 -0
  13. package/src/executors/module-federation-dev-server/lib/parse-static-remotes-config.d.ts +11 -0
  14. package/src/executors/module-federation-dev-server/lib/parse-static-remotes-config.js +18 -0
  15. package/src/executors/module-federation-dev-server/lib/start-static-remotes-file-server.d.ts +2 -5
  16. package/src/executors/module-federation-dev-server/lib/start-static-remotes-file-server.js +9 -11
  17. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +3 -2
  18. package/src/generators/setup-ssr/files/ngmodule/base/src/__main__ +1 -1
  19. package/src/generators/setup-ssr/files/server/application-builder/__serverFileName__ +1 -1
  20. package/src/generators/setup-ssr/files/server/server-builder/pre-v17/__serverFileName__ +1 -1
  21. package/src/generators/setup-ssr/files/server/server-builder/v17+/__serverFileName__ +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/angular",
3
- "version": "18.0.2",
3
+ "version": "18.0.4",
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, 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- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
6
6
  "repository": {
@@ -78,16 +78,16 @@
78
78
  "tslib": "^2.3.0",
79
79
  "webpack": "^5.80.0",
80
80
  "webpack-merge": "^5.8.0",
81
- "@nx/devkit": "18.0.2",
82
- "@nx/cypress": "18.0.2",
83
- "@nx/jest": "18.0.2",
84
- "@nx/js": "18.0.2",
85
- "@nx/eslint": "18.0.2",
86
- "@nx/webpack": "18.0.2",
87
- "@nx/web": "18.0.2",
88
- "@nx/workspace": "18.0.2",
81
+ "@nx/devkit": "18.0.4",
82
+ "@nx/cypress": "18.0.4",
83
+ "@nx/jest": "18.0.4",
84
+ "@nx/js": "18.0.4",
85
+ "@nx/eslint": "18.0.4",
86
+ "@nx/webpack": "18.0.4",
87
+ "@nx/web": "18.0.4",
88
+ "@nx/workspace": "18.0.4",
89
89
  "piscina": "^4.2.1",
90
- "@nrwl/angular": "18.0.2"
90
+ "@nrwl/angular": "18.0.4"
91
91
  },
92
92
  "peerDependencies": {
93
93
  "@angular-devkit/build-angular": ">= 15.0.0 < 18.0.0",
@@ -16,13 +16,7 @@ const buildable_libs_1 = require("../utilities/buildable-libs");
16
16
  const webpack_1 = require("../utilities/webpack");
17
17
  const lib_1 = require("./lib");
18
18
  function executeDevServerBuilder(rawOptions, context) {
19
- if (rawOptions.esbuildMiddleware?.length > 0) {
20
- const { major: angularMajorVersion, version: angularVersion } = (0, angular_version_utils_1.getInstalledAngularVersionInfo)();
21
- if (angularMajorVersion < 17) {
22
- throw new Error((0, devkit_1.stripIndents) `The "esbuildMiddleware" option is only supported in Angular >= 17.0.0. You are currently using "${angularVersion}".
23
- You can resolve this error by removing the "esbuildMiddleware" option or by migrating to Angular 17.0.0.`);
24
- }
25
- }
19
+ (0, lib_1.validateOptions)(rawOptions);
26
20
  process.env.NX_TSCONFIG_PATH = (0, js_1.getRootTsConfigPath)();
27
21
  const options = (0, lib_1.normalizeOptions)(rawOptions);
28
22
  const parsedBuildTarget = (0, devkit_1.parseTargetString)(options.buildTarget, {
@@ -106,7 +100,8 @@ function executeDevServerBuilder(rawOptions, context) {
106
100
  (0, rxjs_1.from)(Promise.resolve().then(() => require('@angular-devkit/build-angular'))),
107
101
  (0, rxjs_1.from)((0, esbuild_extensions_1.loadPlugins)(buildTargetOptions.plugins, buildTargetOptions.tsConfig)),
108
102
  (0, rxjs_1.from)((0, esbuild_extensions_1.loadMiddleware)(options.esbuildMiddleware, buildTargetOptions.tsConfig)),
109
- ]).pipe((0, operators_2.switchMap)(([{ executeDevServerBuilder }, plugins, middleware]) => executeDevServerBuilder(delegateBuilderOptions, context, {
103
+ (0, rxjs_1.from)(loadIndexHtmlFileTransformer(pathToIndexFileTransformer, buildTargetOptions.tsConfig, context, isUsingWebpackBuilder)),
104
+ ]).pipe((0, operators_2.switchMap)(([{ executeDevServerBuilder }, plugins, middleware, indexHtmlTransformer,]) => executeDevServerBuilder(delegateBuilderOptions, context, {
110
105
  webpackConfiguration: isUsingWebpackBuilder
111
106
  ? async (baseWebpackConfig) => {
112
107
  if (!buildLibsFromSource) {
@@ -129,9 +124,9 @@ function executeDevServerBuilder(rawOptions, context) {
129
124
  return (0, webpack_1.mergeCustomWebpackConfig)(baseWebpackConfig, pathToWebpackConfig, buildTargetOptions, context.target);
130
125
  }
131
126
  : undefined,
132
- ...(pathToIndexFileTransformer
127
+ ...(indexHtmlTransformer
133
128
  ? {
134
- indexHtml: (0, webpack_1.resolveIndexHtmlTransformer)(pathToIndexFileTransformer, buildTargetOptions.tsConfig, context.target),
129
+ indexHtml: indexHtmlTransformer,
135
130
  }
136
131
  : {}),
137
132
  }, {
@@ -154,6 +149,14 @@ function getDelegateBuilderOptions(options) {
154
149
  delete delegateBuilderOptions.buildLibsFromSource;
155
150
  return delegateBuilderOptions;
156
151
  }
152
+ async function loadIndexHtmlFileTransformer(pathToIndexFileTransformer, tsConfig, context, isUsingWebpackBuilder) {
153
+ if (!pathToIndexFileTransformer) {
154
+ return undefined;
155
+ }
156
+ return isUsingWebpackBuilder
157
+ ? (0, webpack_1.resolveIndexHtmlTransformer)(pathToIndexFileTransformer, tsConfig, context.target)
158
+ : await (0, esbuild_extensions_1.loadIndexHtmlTransformer)(pathToIndexFileTransformer, tsConfig);
159
+ }
157
160
  const executorToBuilderMap = new Map([
158
161
  [
159
162
  '@nx/angular:browser-esbuild',
@@ -1 +1,2 @@
1
1
  export * from './normalize-options';
2
+ export * from './validate-options';
@@ -2,3 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./normalize-options"), exports);
5
+ tslib_1.__exportStar(require("./validate-options"), exports);
@@ -0,0 +1,2 @@
1
+ import type { Schema } from '../schema';
2
+ export declare function validateOptions(options: Schema): void;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateOptions = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const semver_1 = require("semver");
6
+ const angular_version_utils_1 = require("../../../executors/utilities/angular-version-utils");
7
+ function validateOptions(options) {
8
+ const { major: angularMajorVersion, version: angularVersion } = (0, angular_version_utils_1.getInstalledAngularVersionInfo)();
9
+ if ((0, semver_1.lt)(angularVersion, '16.1.0') && options.forceEsbuild !== undefined) {
10
+ throw new Error((0, devkit_1.stripIndents) `The "forceEsbuild" option is only supported in Angular >= 16.1.0. You are currently using "${angularVersion}".
11
+ You can resolve this error by removing the "forceEsbuild" option or by migrating to Angular 16.1.0.`);
12
+ }
13
+ if (angularMajorVersion < 17 && options.esbuildMiddleware?.length > 0) {
14
+ throw new Error((0, devkit_1.stripIndents) `The "esbuildMiddleware" option is only supported in Angular >= 17.0.0. You are currently using "${angularVersion}".
15
+ You can resolve this error by removing the "esbuildMiddleware" option or by migrating to Angular 17.0.0.`);
16
+ }
17
+ }
18
+ exports.validateOptions = validateOptions;
@@ -16,6 +16,7 @@ interface BaseSchema {
16
16
  hmr?: boolean;
17
17
  watch?: boolean;
18
18
  poll?: number;
19
+ forceEsbuild?: boolean;
19
20
  buildLibsFromSource?: boolean;
20
21
  esbuildMiddleware?: string[];
21
22
  }
@@ -111,6 +111,11 @@
111
111
  "type": "number",
112
112
  "description": "Enable and define the file watching poll time period in milliseconds."
113
113
  },
114
+ "forceEsbuild": {
115
+ "type": "boolean",
116
+ "description": "Force the development server to use the 'browser-esbuild' builder when building. This is a developer preview option for the esbuild-based build system. _Note: this is only supported in Angular versions >= 16.1.0_.",
117
+ "default": false
118
+ },
114
119
  "buildLibsFromSource": {
115
120
  "type": "boolean",
116
121
  "description": "Read buildable libraries from source instead of building them separately. If not set, it will take the value specified in the `browserTarget` options, or it will default to `true` if it's also not set in the `browserTarget` options.",
@@ -1,7 +1,4 @@
1
1
  import { type Schema } from '../schema';
2
2
  import { type ExecutorContext } from '@nx/devkit';
3
- export declare function buildStaticRemotes(remotes: {
4
- remotePorts: any[];
5
- staticRemotes: string[];
6
- devRemotes: string[];
7
- }, nxBin: any, context: ExecutorContext, options: Schema): Promise<void>;
3
+ import type { StaticRemotesConfig } from './parse-static-remotes-config';
4
+ export declare function buildStaticRemotes(staticRemotesConfig: StaticRemotesConfig, nxBin: any, context: ExecutorContext, options: Schema): Promise<void>;
@@ -3,22 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildStaticRemotes = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const child_process_1 = require("child_process");
6
- async function buildStaticRemotes(remotes, nxBin, context, options) {
7
- if (!remotes.staticRemotes ||
8
- (Array.isArray(remotes.staticRemotes) && !remotes.staticRemotes.length)) {
6
+ async function buildStaticRemotes(staticRemotesConfig, nxBin, context, options) {
7
+ if (!staticRemotesConfig.remotes.length) {
9
8
  return;
10
9
  }
11
10
  const mappedLocationOfRemotes = {};
12
- for (const app of remotes.staticRemotes) {
13
- mappedLocationOfRemotes[app] = `http${options.ssl ? 's' : ''}://${options.host}:${options.staticRemotesPort}/${app}`;
11
+ for (const app of staticRemotesConfig.remotes) {
12
+ mappedLocationOfRemotes[app] = `http${options.ssl ? 's' : ''}://${options.host}:${options.staticRemotesPort}/${staticRemotesConfig.config[app].urlSegment}`;
14
13
  }
15
14
  process.env.NX_MF_DEV_SERVER_STATIC_REMOTES = JSON.stringify(mappedLocationOfRemotes);
16
15
  await new Promise((res) => {
17
- devkit_1.logger.info(`NX Building ${remotes.staticRemotes.length} static remotes...`);
16
+ devkit_1.logger.info(`NX Building ${staticRemotesConfig.remotes.length} static remotes...`);
18
17
  const staticProcess = (0, child_process_1.fork)(nxBin, [
19
18
  'run-many',
20
19
  `--target=build`,
21
- `--projects=${remotes.staticRemotes.join(',')}`,
20
+ `--projects=${staticRemotesConfig.remotes.join(',')}`,
22
21
  ...(context.configurationName
23
22
  ? [`--configuration=${context.configurationName}`]
24
23
  : []),
@@ -32,7 +31,7 @@ async function buildStaticRemotes(remotes, nxBin, context, options) {
32
31
  const stdoutString = data.toString().replace(ANSII_CODE_REGEX, '');
33
32
  if (stdoutString.includes('Successfully ran target build')) {
34
33
  staticProcess.stdout.removeAllListeners('data');
35
- devkit_1.logger.info(`NX Built ${remotes.staticRemotes.length} static remotes`);
34
+ devkit_1.logger.info(`NX Built ${staticRemotesConfig.remotes.length} static remotes`);
36
35
  res();
37
36
  }
38
37
  });
@@ -1,4 +1,5 @@
1
1
  export * from './build-static-remotes';
2
2
  export * from './normalize-options';
3
+ export * from './parse-static-remotes-config';
3
4
  export * from './start-dev-remotes';
4
5
  export * from './start-static-remotes-file-server';
@@ -3,5 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./build-static-remotes"), exports);
5
5
  tslib_1.__exportStar(require("./normalize-options"), exports);
6
+ tslib_1.__exportStar(require("./parse-static-remotes-config"), exports);
6
7
  tslib_1.__exportStar(require("./start-dev-remotes"), exports);
7
8
  tslib_1.__exportStar(require("./start-static-remotes-file-server"), exports);
@@ -0,0 +1,11 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ export type StaticRemoteConfig = {
3
+ basePath: string;
4
+ outputPath: string;
5
+ urlSegment: string;
6
+ };
7
+ export type StaticRemotesConfig = {
8
+ remotes: string[];
9
+ config: Record<string, StaticRemoteConfig> | undefined;
10
+ };
11
+ export declare function parseStaticRemotesConfig(staticRemotes: string[] | undefined, context: ExecutorContext): StaticRemotesConfig;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseStaticRemotesConfig = void 0;
4
+ const path_1 = require("path");
5
+ function parseStaticRemotesConfig(staticRemotes, context) {
6
+ if (!staticRemotes?.length) {
7
+ return { remotes: [], config: undefined };
8
+ }
9
+ const config = {};
10
+ for (const app of staticRemotes) {
11
+ const outputPath = context.projectGraph.nodes[app].data.targets['build'].options.outputPath;
12
+ const basePath = (0, path_1.dirname)(outputPath);
13
+ const urlSegment = (0, path_1.basename)(outputPath);
14
+ config[app] = { basePath, outputPath, urlSegment };
15
+ }
16
+ return { remotes: staticRemotes, config };
17
+ }
18
+ exports.parseStaticRemotesConfig = parseStaticRemotesConfig;
@@ -1,10 +1,7 @@
1
1
  import { type ExecutorContext } from '@nx/devkit';
2
2
  import { type Schema } from '../schema';
3
- export declare function startStaticRemotesFileServer(remotes: {
4
- remotePorts: any[];
5
- staticRemotes: string[];
6
- devRemotes: string[];
7
- }, context: ExecutorContext, options: Schema): AsyncGenerator<{
3
+ import type { StaticRemotesConfig } from './parse-static-remotes-config';
4
+ export declare function startStaticRemotesFileServer(staticRemotesConfig: StaticRemotesConfig, context: ExecutorContext, options: Schema): AsyncGenerator<{
8
5
  success: boolean;
9
6
  baseUrl: string;
10
7
  }, {
@@ -5,26 +5,24 @@ const devkit_1 = require("@nx/devkit");
5
5
  const file_server_impl_1 = require("@nx/web/src/executors/file-server/file-server.impl");
6
6
  const path_1 = require("path");
7
7
  const fs_1 = require("fs");
8
- function startStaticRemotesFileServer(remotes, context, options) {
8
+ function startStaticRemotesFileServer(staticRemotesConfig, context, options) {
9
9
  let shouldMoveToCommonLocation = false;
10
10
  let commonOutputDirectory;
11
- for (const app of remotes.staticRemotes) {
12
- const outputPath = context.projectGraph.nodes[app].data.targets['build'].options.outputPath;
13
- const directoryOfOutputPath = (0, path_1.dirname)(outputPath);
11
+ for (const app of staticRemotesConfig.remotes) {
12
+ const remoteBasePath = staticRemotesConfig.config[app].basePath;
14
13
  if (!commonOutputDirectory) {
15
- commonOutputDirectory = directoryOfOutputPath;
14
+ commonOutputDirectory = remoteBasePath;
16
15
  }
17
- else if (commonOutputDirectory !== directoryOfOutputPath ||
18
- !outputPath.endsWith(app)) {
16
+ else if (commonOutputDirectory !== remoteBasePath) {
19
17
  shouldMoveToCommonLocation = true;
18
+ break;
20
19
  }
21
20
  }
22
21
  if (shouldMoveToCommonLocation) {
23
22
  commonOutputDirectory = (0, path_1.join)(devkit_1.workspaceRoot, 'tmp/static-remotes');
24
- for (const app of remotes.staticRemotes) {
25
- const outputPath = context.projectGraph.nodes[app].data.targets['build'].options
26
- .outputPath;
27
- (0, fs_1.cpSync)(outputPath, (0, path_1.join)(commonOutputDirectory, app), {
23
+ for (const app of staticRemotesConfig.remotes) {
24
+ const remoteConfig = staticRemotesConfig.config[app];
25
+ (0, fs_1.cpSync)(remoteConfig.outputPath, (0, path_1.join)(commonOutputDirectory, remoteConfig.urlSegment), {
28
26
  force: true,
29
27
  recursive: true,
30
28
  });
@@ -68,10 +68,11 @@ async function* moduleFederationDevServerExecutor(schema, context) {
68
68
  }
69
69
  }, options.staticRemotesPort);
70
70
  }
71
- await (0, lib_1.buildStaticRemotes)(remotes, nxBin, context, options);
71
+ const staticRemotesConfig = (0, lib_1.parseStaticRemotesConfig)(remotes.staticRemotes, context);
72
+ await (0, lib_1.buildStaticRemotes)(staticRemotesConfig, nxBin, context, options);
72
73
  const devRemoteIters = await (0, lib_1.startDevRemotes)(remotes, workspaceProjects, options, context);
73
74
  const staticRemotesIter = remotes.staticRemotes.length > 0
74
- ? (0, lib_1.startStaticRemotesFileServer)(remotes, context, options)
75
+ ? (0, lib_1.startStaticRemotesFileServer)(staticRemotesConfig, context, options)
75
76
  : undefined;
76
77
  const removeBaseUrlEmission = (iter) => (0, async_iterable_1.mapAsyncIterable)(iter, (v) => ({
77
78
  ...v,
@@ -1 +1 @@
1
- export { <%= rootModuleClassName %> } from './app/<%= rootModuleFileName.slice(0, -3) %>';
1
+ export { <%= rootModuleClassName %> as default } from './app/<%= rootModuleFileName.slice(0, -3) %>';
@@ -3,7 +3,7 @@ import { CommonEngine } from '@angular/ssr';
3
3
  import express from 'express';
4
4
  import { fileURLToPath } from 'node:url';
5
5
  import { dirname, join, resolve } from 'node:path';
6
- import <% if (standalone) { %>bootstrap<% } else { %>{ <%= rootModuleClassName %> }<% } %> from './src/<%= main.slice(0, -3) %>';
6
+ import <% if (standalone) { %>bootstrap<% } else { %><%= rootModuleClassName %><% } %> from './src/<%= main.slice(0, -3) %>';
7
7
 
8
8
  // The Express app is exported so that it can be used by serverless Functions.
9
9
  export function app(): express.Express {
@@ -5,7 +5,7 @@ import { ngExpressEngine } from '@nguniversal/express-engine';
5
5
  import * as express from 'express';
6
6
  import { existsSync } from 'fs';
7
7
  import { join } from 'path';
8
- import <% if (standalone) { %>bootstrap<% } else { %>{ <%= rootModuleClassName %> }<% } %> from './src/<%= main.slice(0, -3) %>';
8
+ import <% if (standalone) { %>bootstrap<% } else { %><%= rootModuleClassName %><% } %> from './src/<%= main.slice(0, -3) %>';
9
9
 
10
10
  // The Express app is exported so that it can be used by serverless Functions.
11
11
  export function app(): express.Express {
@@ -5,7 +5,7 @@ import { CommonEngine } from '@angular/ssr';
5
5
  import * as express from 'express';
6
6
  import { existsSync } from 'node:fs';
7
7
  import { join } from 'node:path';
8
- import <% if (standalone) { %>bootstrap<% } else { %>{ <%= rootModuleClassName %> }<% } %> from './src/<%= main.slice(0, -3) %>';
8
+ import <% if (standalone) { %>bootstrap<% } else { %><%= rootModuleClassName %><% } %> from './src/<%= main.slice(0, -3) %>';
9
9
 
10
10
  // The Express app is exported so that it can be used by serverless Functions.
11
11
  export function app(): express.Express {