@nx/angular 17.2.0-beta.1 → 17.2.0-beta.11

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 (46) hide show
  1. package/executors.d.ts +7 -2
  2. package/executors.js +5 -2
  3. package/executors.json +9 -9
  4. package/migrations.json +18 -0
  5. package/package.json +10 -10
  6. package/plugins/component-testing.js +1 -1
  7. package/src/builders/dev-server/dev-server.impl.d.ts +4 -0
  8. package/src/builders/{webpack-dev-server/webpack-dev-server.impl.js → dev-server/dev-server.impl.js} +62 -28
  9. package/src/builders/{webpack-dev-server → dev-server}/schema.json +2 -2
  10. package/src/builders/utilities/module-federation.js +1 -1
  11. package/src/builders/webpack-server/schema.json +1 -1
  12. package/src/executors/module-federation-dev-server/lib/build-static-remotes.d.ts +7 -0
  13. package/src/executors/module-federation-dev-server/lib/build-static-remotes.js +49 -0
  14. package/src/executors/module-federation-dev-server/lib/index.d.ts +4 -0
  15. package/src/executors/module-federation-dev-server/lib/index.js +7 -0
  16. package/src/executors/module-federation-dev-server/lib/normalize-options.d.ts +2 -0
  17. package/src/executors/module-federation-dev-server/lib/normalize-options.js +20 -0
  18. package/src/executors/module-federation-dev-server/lib/start-dev-remotes.d.ts +9 -0
  19. package/src/executors/module-federation-dev-server/lib/start-dev-remotes.js +29 -0
  20. package/src/executors/module-federation-dev-server/lib/start-static-remotes-file-server.d.ts +12 -0
  21. package/src/executors/module-federation-dev-server/lib/start-static-remotes-file-server.js +48 -0
  22. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +3 -0
  23. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +107 -0
  24. package/src/{builders → executors}/module-federation-dev-server/schema.json +9 -3
  25. package/src/generators/add-linting/add-linting.js +0 -5
  26. package/src/generators/application/lib/add-e2e.js +1 -0
  27. package/src/generators/library-secondary-entry-point/lib/index.d.ts +0 -1
  28. package/src/generators/library-secondary-entry-point/lib/index.js +0 -1
  29. package/src/generators/library-secondary-entry-point/library-secondary-entry-point.js +0 -1
  30. package/src/generators/ng-add/migrators/projects/e2e.migrator.js +1 -1
  31. package/src/generators/setup-mf/lib/setup-serve-target.js +1 -1
  32. package/src/migrations/update-17-2-0/rename-webpack-dev-server.d.ts +2 -0
  33. package/src/migrations/update-17-2-0/rename-webpack-dev-server.js +40 -0
  34. package/src/utils/versions.d.ts +1 -1
  35. package/src/utils/versions.js +1 -1
  36. package/src/builders/module-federation-dev-server/module-federation-dev-server.impl.d.ts +0 -5
  37. package/src/builders/module-federation-dev-server/module-federation-dev-server.impl.js +0 -229
  38. package/src/builders/webpack-dev-server/webpack-dev-server.impl.d.ts +0 -4
  39. package/src/generators/library-secondary-entry-point/lib/update-linting-file-patterns.d.ts +0 -3
  40. package/src/generators/library-secondary-entry-point/lib/update-linting-file-patterns.js +0 -15
  41. /package/src/builders/{webpack-dev-server → dev-server}/lib/index.d.ts +0 -0
  42. /package/src/builders/{webpack-dev-server → dev-server}/lib/index.js +0 -0
  43. /package/src/builders/{webpack-dev-server → dev-server}/lib/normalize-options.d.ts +0 -0
  44. /package/src/builders/{webpack-dev-server → dev-server}/lib/normalize-options.js +0 -0
  45. /package/src/builders/{webpack-dev-server → dev-server}/schema.d.ts +0 -0
  46. /package/src/{builders → executors}/module-federation-dev-server/schema.d.ts +0 -0
package/executors.d.ts CHANGED
@@ -1,9 +1,14 @@
1
- export * from './src/builders/module-federation-dev-server/module-federation-dev-server.impl';
2
1
  export * from './src/builders/module-federation-dev-ssr/module-federation-dev-ssr.impl';
3
2
  export * from './src/builders/webpack-browser/webpack-browser.impl';
4
- export * from './src/builders/webpack-dev-server/webpack-dev-server.impl';
5
3
  export * from './src/builders/webpack-server/webpack-server.impl';
4
+ export * from './src/executors/module-federation-dev-server/module-federation-dev-server.impl';
6
5
  export * from './src/executors/delegate-build/delegate-build.impl';
7
6
  export * from './src/executors/ng-packagr-lite/ng-packagr-lite.impl';
8
7
  export * from './src/executors/package/package.impl';
9
8
  export * from './src/executors/browser-esbuild/browser-esbuild.impl';
9
+ import { executeDevServerBuilder } from './src/builders/dev-server/dev-server.impl';
10
+ export {
11
+ /**
12
+ * @deprecated Use executeDevServerBuilder instead. It will be removed in Nx v18.
13
+ */
14
+ executeDevServerBuilder as executeWebpackDevServerBuilder, executeDevServerBuilder, };
package/executors.js CHANGED
@@ -1,12 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeDevServerBuilder = exports.executeWebpackDevServerBuilder = void 0;
3
4
  const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./src/builders/module-federation-dev-server/module-federation-dev-server.impl"), exports);
5
5
  tslib_1.__exportStar(require("./src/builders/module-federation-dev-ssr/module-federation-dev-ssr.impl"), exports);
6
6
  tslib_1.__exportStar(require("./src/builders/webpack-browser/webpack-browser.impl"), exports);
7
- tslib_1.__exportStar(require("./src/builders/webpack-dev-server/webpack-dev-server.impl"), exports);
8
7
  tslib_1.__exportStar(require("./src/builders/webpack-server/webpack-server.impl"), exports);
8
+ tslib_1.__exportStar(require("./src/executors/module-federation-dev-server/module-federation-dev-server.impl"), exports);
9
9
  tslib_1.__exportStar(require("./src/executors/delegate-build/delegate-build.impl"), exports);
10
10
  tslib_1.__exportStar(require("./src/executors/ng-packagr-lite/ng-packagr-lite.impl"), exports);
11
11
  tslib_1.__exportStar(require("./src/executors/package/package.impl"), exports);
12
12
  tslib_1.__exportStar(require("./src/executors/browser-esbuild/browser-esbuild.impl"), exports);
13
+ const dev_server_impl_1 = require("./src/builders/dev-server/dev-server.impl");
14
+ Object.defineProperty(exports, "executeWebpackDevServerBuilder", { enumerable: true, get: function () { return dev_server_impl_1.executeDevServerBuilder; } });
15
+ Object.defineProperty(exports, "executeDevServerBuilder", { enumerable: true, get: function () { return dev_server_impl_1.executeDevServerBuilder; } });
package/executors.json CHANGED
@@ -19,6 +19,11 @@
19
19
  "implementation": "./src/executors/browser-esbuild/browser-esbuild.impl",
20
20
  "schema": "./src/executors/browser-esbuild/schema.json",
21
21
  "description": "Builds your application with esbuild and adds support for incremental builds."
22
+ },
23
+ "module-federation-dev-server": {
24
+ "implementation": "./src/executors/module-federation-dev-server/module-federation-dev-server.impl",
25
+ "schema": "./src/executors/module-federation-dev-server/schema.json",
26
+ "description": "The module-federation-dev-server executor is reserved exclusively for use with host Module Federation applications. It allows the user to specify which remote applications should be served with the host."
22
27
  }
23
28
  },
24
29
  "builders": {
@@ -27,21 +32,16 @@
27
32
  "schema": "./src/builders/webpack-browser/schema.json",
28
33
  "description": "The `webpack-browser` executor is very similar to the standard `browser` builder provided by the Angular Devkit. It allows you to build your Angular application to a build artifact that can be hosted online. There are some key differences: \n- Supports Custom Webpack Configurations \n- Supports Incremental Building"
29
34
  },
30
- "webpack-dev-server": {
31
- "implementation": "./src/builders/webpack-dev-server/webpack-dev-server.impl",
32
- "schema": "./src/builders/webpack-dev-server/schema.json",
33
- "description": "The `webpack-dev-server` executor is very similar to the standard `dev-server` builder provided by the Angular Devkit. It is usually used in tandem with `@nrwl/angular:webpack-browser` when your Angular application uses a custom webpack configuration."
35
+ "dev-server": {
36
+ "implementation": "./src/builders/dev-server/dev-server.impl",
37
+ "schema": "./src/builders/dev-server/schema.json",
38
+ "description": "The `dev-server` executor is very similar to the standard `dev-server` builder provided by the Angular Devkit. It is usually used in tandem with `@nrwl/angular:webpack-browser` when your Angular application uses a custom webpack configuration."
34
39
  },
35
40
  "webpack-server": {
36
41
  "implementation": "./src/builders/webpack-server/webpack-server.impl",
37
42
  "schema": "./src/builders/webpack-server/schema.json",
38
43
  "description": "The `webpack-server` executor is very similar to the standard `server` builder provided by the Angular Devkit. It is usually used in tandem with `@nrwl/angular:webpack-browser` when your Angular application uses a custom webpack configuration and NgUniversal for SSR."
39
44
  },
40
- "module-federation-dev-server": {
41
- "implementation": "./src/builders/module-federation-dev-server/module-federation-dev-server.impl",
42
- "schema": "./src/builders/module-federation-dev-server/schema.json",
43
- "description": "The module-federation-dev-server executor is reserved exclusively for use with host Module Federation applications. It allows the user to specify which remote applications should be served with the host."
44
- },
45
45
  "module-federation-dev-ssr": {
46
46
  "implementation": "./src/builders/module-federation-dev-ssr/module-federation-dev-ssr.impl",
47
47
  "schema": "./src/builders/module-federation-dev-ssr/schema.json",
package/migrations.json CHANGED
@@ -323,6 +323,12 @@
323
323
  },
324
324
  "description": "Replace the deep imports from 'zone.js/dist/zone' and 'zone.js/dist/zone-testing' with 'zone.js' and 'zone.js/testing'.",
325
325
  "factory": "./src/migrations/update-17-1-0/update-zone-js-deep-import"
326
+ },
327
+ "rename-webpack-dev-server-executor": {
328
+ "cli": "nx",
329
+ "version": "17.2.0-beta.2",
330
+ "description": "Rename '@nx/angular:webpack-dev-server' executor to '@nx/angular:dev-server'",
331
+ "factory": "./src/migrations/update-17-2-0/rename-webpack-dev-server"
326
332
  }
327
333
  },
328
334
  "packageJsonUpdates": {
@@ -1505,6 +1511,18 @@
1505
1511
  "alwaysAddToPackageJson": false
1506
1512
  }
1507
1513
  }
1514
+ },
1515
+ "17.2.0-ngrx": {
1516
+ "version": "17.2.0-beta.3",
1517
+ "requires": {
1518
+ "@angular/core": "^17.0.0"
1519
+ },
1520
+ "packages": {
1521
+ "@ngrx/store": {
1522
+ "version": "~17.0.0",
1523
+ "alwaysAddToPackageJson": false
1524
+ }
1525
+ }
1508
1526
  }
1509
1527
  }
1510
1528
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/angular",
3
- "version": "17.2.0-beta.1",
3
+ "version": "17.2.0-beta.11",
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,15 +78,15 @@
78
78
  "tslib": "^2.3.0",
79
79
  "webpack": "^5.80.0",
80
80
  "webpack-merge": "^5.8.0",
81
- "@nx/devkit": "17.2.0-beta.1",
82
- "@nx/cypress": "17.2.0-beta.1",
83
- "@nx/jest": "17.2.0-beta.1",
84
- "@nx/js": "17.2.0-beta.1",
85
- "@nx/eslint": "17.2.0-beta.1",
86
- "@nx/webpack": "17.2.0-beta.1",
87
- "@nx/web": "17.2.0-beta.1",
88
- "@nx/workspace": "17.2.0-beta.1",
89
- "@nrwl/angular": "17.2.0-beta.1"
81
+ "@nx/devkit": "17.2.0-beta.11",
82
+ "@nx/cypress": "17.2.0-beta.11",
83
+ "@nx/jest": "17.2.0-beta.11",
84
+ "@nx/js": "17.2.0-beta.11",
85
+ "@nx/eslint": "17.2.0-beta.11",
86
+ "@nx/webpack": "17.2.0-beta.11",
87
+ "@nx/web": "17.2.0-beta.11",
88
+ "@nx/workspace": "17.2.0-beta.11",
89
+ "@nrwl/angular": "17.2.0-beta.11"
90
90
  },
91
91
  "peerDependencies": {
92
92
  "@angular-devkit/build-angular": ">= 15.0.0 < 18.0.0",
@@ -225,7 +225,7 @@ function withSchemaDefaults(options) {
225
225
  options.outputHashing ??= 'none';
226
226
  options.progress ??= true;
227
227
  options.scripts ??= [];
228
- options.main = options.main ??= options.browser;
228
+ options.main ??= options.browser;
229
229
  return options;
230
230
  }
231
231
  /**
@@ -0,0 +1,4 @@
1
+ import type { Schema } from './schema';
2
+ export declare function executeDevServerBuilder(rawOptions: Schema, context: import('@angular-devkit/architect').BuilderContext): import("rxjs").Observable<import("@angular-devkit/build-angular").DevServerBuilderOutput>;
3
+ declare const _default: any;
4
+ export default _default;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executeWebpackDevServerBuilder = void 0;
3
+ exports.executeDevServerBuilder = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const js_1 = require("@nx/js");
6
6
  const webpack_nx_build_coordination_plugin_1 = require("@nx/webpack/src/plugins/webpack-nx-build-coordination-plugin");
@@ -13,7 +13,7 @@ const angular_version_utils_1 = require("../../executors/utilities/angular-versi
13
13
  const buildable_libs_1 = require("../utilities/buildable-libs");
14
14
  const webpack_1 = require("../utilities/webpack");
15
15
  const lib_1 = require("./lib");
16
- function executeWebpackDevServerBuilder(rawOptions, context) {
16
+ function executeDevServerBuilder(rawOptions, context) {
17
17
  process.env.NX_TSCONFIG_PATH = (0, js_1.getRootTsConfigPath)();
18
18
  const options = (0, lib_1.normalizeOptions)(rawOptions);
19
19
  const parsedBuildTarget = (0, devkit_1.parseTargetString)(options.buildTarget, {
@@ -75,27 +75,41 @@ function executeWebpackDevServerBuilder(rawOptions, context) {
75
75
  buildTargetOptions.tsConfig = tsConfigPath;
76
76
  }
77
77
  const delegateBuilderOptions = getDelegateBuilderOptions(options);
78
+ const isUsingWebpackBuilder = ![
79
+ '@angular-devkit/build-angular:application',
80
+ '@angular-devkit/build-angular:browser-esbuild',
81
+ '@nx/angular:browser-esbuild',
82
+ ].includes(buildTarget.executor);
83
+ /**
84
+ * The Angular CLI dev-server builder make some decisions based on the build
85
+ * target builder but it only considers `@angular-devkit/build-angular:*`
86
+ * builders. Since we are using a custom builder, we patch the context to
87
+ * handle `@nx/angular:*` executors.
88
+ */
89
+ patchBuilderContext(context);
78
90
  return (0, rxjs_1.from)(Promise.resolve().then(() => require('@angular-devkit/build-angular'))).pipe((0, operators_2.switchMap)(({ executeDevServerBuilder }) => executeDevServerBuilder(delegateBuilderOptions, context, {
79
- webpackConfiguration: async (baseWebpackConfig) => {
80
- if (!buildLibsFromSource) {
81
- const workspaceDependencies = dependencies
82
- .filter((dep) => !(0, operators_1.isNpmProject)(dep.node))
83
- .map((dep) => dep.node.name);
84
- // default for `nx run-many` is --all projects
85
- // by passing an empty string for --projects, run-many will default to
86
- // run the target for all projects.
87
- // This will occur when workspaceDependencies = []
88
- if (workspaceDependencies.length > 0) {
89
- baseWebpackConfig.plugins.push(
90
- // @ts-expect-error - difference between angular and webpack plugin definitions bc of webpack versions
91
- new webpack_nx_build_coordination_plugin_1.WebpackNxBuildCoordinationPlugin(`nx run-many --target=${parsedBuildTarget.target} --projects=${workspaceDependencies.join(',')}`));
91
+ webpackConfiguration: isUsingWebpackBuilder
92
+ ? async (baseWebpackConfig) => {
93
+ if (!buildLibsFromSource) {
94
+ const workspaceDependencies = dependencies
95
+ .filter((dep) => !(0, operators_1.isNpmProject)(dep.node))
96
+ .map((dep) => dep.node.name);
97
+ // default for `nx run-many` is --all projects
98
+ // by passing an empty string for --projects, run-many will default to
99
+ // run the target for all projects.
100
+ // This will occur when workspaceDependencies = []
101
+ if (workspaceDependencies.length > 0) {
102
+ baseWebpackConfig.plugins.push(
103
+ // @ts-expect-error - difference between angular and webpack plugin definitions bc of webpack versions
104
+ new webpack_nx_build_coordination_plugin_1.WebpackNxBuildCoordinationPlugin(`nx run-many --target=${parsedBuildTarget.target} --projects=${workspaceDependencies.join(',')}`));
105
+ }
92
106
  }
107
+ if (!pathToWebpackConfig) {
108
+ return baseWebpackConfig;
109
+ }
110
+ return (0, webpack_1.mergeCustomWebpackConfig)(baseWebpackConfig, pathToWebpackConfig, buildTargetOptions, context.target);
93
111
  }
94
- if (!pathToWebpackConfig) {
95
- return baseWebpackConfig;
96
- }
97
- return (0, webpack_1.mergeCustomWebpackConfig)(baseWebpackConfig, pathToWebpackConfig, buildTargetOptions, context.target);
98
- },
112
+ : undefined,
99
113
  ...(pathToIndexFileTransformer
100
114
  ? {
101
115
  indexHtml: (0, webpack_1.resolveIndexHtmlTransformer)(pathToIndexFileTransformer, buildTargetOptions.tsConfig, context.target),
@@ -103,14 +117,34 @@ function executeWebpackDevServerBuilder(rawOptions, context) {
103
117
  : {}),
104
118
  })));
105
119
  }
106
- exports.executeWebpackDevServerBuilder = executeWebpackDevServerBuilder;
107
- exports.default = require('@angular-devkit/architect').createBuilder(executeWebpackDevServerBuilder);
120
+ exports.executeDevServerBuilder = executeDevServerBuilder;
121
+ exports.default = require('@angular-devkit/architect').createBuilder(executeDevServerBuilder);
108
122
  function getDelegateBuilderOptions(options) {
109
- const delegatedBuilderOptions = { ...options };
110
- const { major } = (0, angular_version_utils_1.getInstalledAngularVersionInfo)();
111
- if (major <= 17) {
112
- delegatedBuilderOptions.browserTarget = delegatedBuilderOptions.buildTarget;
113
- delete delegatedBuilderOptions.buildTarget;
123
+ const delegateBuilderOptions = {
124
+ ...options,
125
+ };
126
+ const { major: angularMajorVersion } = (0, angular_version_utils_1.getInstalledAngularVersionInfo)();
127
+ if (angularMajorVersion <= 17) {
128
+ delegateBuilderOptions.browserTarget = delegateBuilderOptions.buildTarget;
129
+ delete delegateBuilderOptions.buildTarget;
114
130
  }
115
- return delegatedBuilderOptions;
131
+ // delete extra option not supported by the delegate builder
132
+ delete delegateBuilderOptions.buildLibsFromSource;
133
+ return delegateBuilderOptions;
134
+ }
135
+ const executorToBuilderMap = new Map([
136
+ [
137
+ '@nx/angular:browser-esbuild',
138
+ '@angular-devkit/build-angular:browser-esbuild',
139
+ ],
140
+ ]);
141
+ function patchBuilderContext(context) {
142
+ const originalGetBuilderNameForTarget = context.getBuilderNameForTarget;
143
+ context.getBuilderNameForTarget = async (target) => {
144
+ const builderName = await originalGetBuilderNameForTarget(target);
145
+ if (executorToBuilderMap.has(builderName)) {
146
+ return executorToBuilderMap.get(builderName);
147
+ }
148
+ return builderName;
149
+ };
116
150
  }
@@ -3,8 +3,8 @@
3
3
  "outputCapture": "direct-nodejs",
4
4
  "$schema": "http://json-schema.org/draft-07/schema",
5
5
  "title": "Schema for Webpack Dev Server",
6
- "description": "The webpack-dev-server executor is very similar to the standard dev server builder provided by the Angular Devkit. It is usually used in tandem with `@nx/angular:webpack-browser` when your Angular application uses a custom webpack configuration.",
7
- "examplesFile": "../../../docs/webpack-dev-server-examples.md",
6
+ "description": "The dev-server executor is very similar to the standard dev server builder provided by the Angular Devkit. It is usually used in tandem with `@nx/angular:webpack-browser` when your Angular application uses a custom webpack configuration.",
7
+ "examplesFile": "../../../docs/dev-server-examples.md",
8
8
  "type": "object",
9
9
  "presets": [
10
10
  {
@@ -85,7 +85,7 @@ function getStaticRemotes(project, context, workspaceProjects, remotesToSkip) {
85
85
  }
86
86
  exports.getStaticRemotes = getStaticRemotes;
87
87
  function validateDevRemotes(options, workspaceProjects) {
88
- const invalidDevRemotes = options.devRemotes?.filter((remote) => !workspaceProjects[remote]);
88
+ const invalidDevRemotes = options.devRemotes?.filter((remote) => !workspaceProjects[remote]) ?? [];
89
89
  if (invalidDevRemotes.length) {
90
90
  throw new Error(invalidDevRemotes.length === 1
91
91
  ? `Invalid dev remote provided: ${invalidDevRemotes[0]}.`
@@ -3,7 +3,7 @@
3
3
  "outputCapture": "direct-nodejs",
4
4
  "$schema": "http://json-schema.org/draft-07/schema",
5
5
  "title": "Schema for Webpack Server",
6
- "description": "The webpack-dev-server executor is very similar to the standard server builder provided by the Angular Devkit. It is usually used in tandem with `@nx/angular:webpack-browser` when your Angular application uses a custom webpack configuration and NgUniversal for SSR.",
6
+ "description": "The webpack-server executor is very similar to the standard server builder provided by the Angular Devkit. It is usually used in tandem with `@nx/angular:webpack-browser` when your Angular application uses a custom webpack configuration and NgUniversal for SSR.",
7
7
  "type": "object",
8
8
  "properties": {
9
9
  "assets": {
@@ -0,0 +1,7 @@
1
+ import { type Schema } from '../schema';
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>;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildStaticRemotes = void 0;
4
+ const devkit_1 = require("@nx/devkit");
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)) {
9
+ return;
10
+ }
11
+ const mappedLocationOfRemotes = {};
12
+ for (const app of remotes.staticRemotes) {
13
+ mappedLocationOfRemotes[app] = `http${options.ssl ? 's' : ''}://${options.host}:${options.staticRemotesPort}/${app}`;
14
+ }
15
+ process.env.NX_MF_DEV_SERVER_STATIC_REMOTES = JSON.stringify(mappedLocationOfRemotes);
16
+ await new Promise((res) => {
17
+ devkit_1.logger.info(`NX Building ${remotes.staticRemotes.length} static remotes...`);
18
+ const staticProcess = (0, child_process_1.fork)(nxBin, [
19
+ 'run-many',
20
+ `--target=build`,
21
+ `--projects=${remotes.staticRemotes.join(',')}`,
22
+ ...(context.configurationName
23
+ ? [`--configuration=${context.configurationName}`]
24
+ : []),
25
+ ...(options.parallel ? [`--parallel=${options.parallel}`] : []),
26
+ ], {
27
+ cwd: context.root,
28
+ stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
29
+ });
30
+ staticProcess.stdout.on('data', (data) => {
31
+ const ANSII_CODE_REGEX = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
32
+ const stdoutString = data.toString().replace(ANSII_CODE_REGEX, '');
33
+ if (stdoutString.includes('Successfully ran target build')) {
34
+ staticProcess.stdout.removeAllListeners('data');
35
+ devkit_1.logger.info(`NX Built ${remotes.staticRemotes.length} static remotes`);
36
+ res();
37
+ }
38
+ });
39
+ staticProcess.stderr.on('data', (data) => devkit_1.logger.info(data.toString()));
40
+ staticProcess.on('exit', (code) => {
41
+ if (code !== 0) {
42
+ throw new Error(`Remotes failed to build. See above for errors.`);
43
+ }
44
+ });
45
+ process.on('SIGTERM', () => staticProcess.kill('SIGTERM'));
46
+ process.on('exit', () => staticProcess.kill('SIGTERM'));
47
+ });
48
+ }
49
+ exports.buildStaticRemotes = buildStaticRemotes;
@@ -0,0 +1,4 @@
1
+ export * from './build-static-remotes';
2
+ export * from './normalize-options';
3
+ export * from './start-dev-remotes';
4
+ export * from './start-static-remotes-file-server';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./build-static-remotes"), exports);
5
+ tslib_1.__exportStar(require("./normalize-options"), exports);
6
+ tslib_1.__exportStar(require("./start-dev-remotes"), exports);
7
+ tslib_1.__exportStar(require("./start-static-remotes-file-server"), exports);
@@ -0,0 +1,2 @@
1
+ import type { NormalizedSchema, Schema } from '../schema';
2
+ export declare function normalizeOptions(schema: Schema): NormalizedSchema;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeOptions = void 0;
4
+ function normalizeOptions(schema) {
5
+ let buildTarget = schema.buildTarget;
6
+ if (schema.browserTarget) {
7
+ buildTarget ??= schema.browserTarget;
8
+ delete schema.browserTarget;
9
+ }
10
+ return {
11
+ ...schema,
12
+ buildTarget,
13
+ host: schema.host ?? 'localhost',
14
+ port: schema.port ?? 4200,
15
+ liveReload: schema.liveReload ?? true,
16
+ open: schema.open ?? false,
17
+ ssl: schema.ssl ?? false,
18
+ };
19
+ }
20
+ exports.normalizeOptions = normalizeOptions;
@@ -0,0 +1,9 @@
1
+ import { type Schema } from '../schema';
2
+ import { type ExecutorContext, type ProjectConfiguration } from '@nx/devkit';
3
+ export declare function startDevRemotes(remotes: {
4
+ remotePorts: any[];
5
+ staticRemotes: string[];
6
+ devRemotes: string[];
7
+ }, workspaceProjects: Record<string, ProjectConfiguration>, options: Schema, context: ExecutorContext): Promise<AsyncIterable<{
8
+ success: boolean;
9
+ }>[]>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startDevRemotes = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ async function startDevRemotes(remotes, workspaceProjects, options, context) {
6
+ const devRemotesIters = [];
7
+ for (const app of remotes.devRemotes) {
8
+ if (!workspaceProjects[app].targets?.['serve']) {
9
+ throw new Error(`Could not find "serve" target in "${app}" project.`);
10
+ }
11
+ else if (!workspaceProjects[app].targets?.['serve'].executor) {
12
+ throw new Error(`Could not find executor for "serve" target in "${app}" project.`);
13
+ }
14
+ const [collection, executor] = workspaceProjects[app].targets['serve'].executor.split(':');
15
+ const isUsingModuleFederationDevServerExecutor = executor.includes('module-federation-dev-server');
16
+ devRemotesIters.push(await (0, devkit_1.runExecutor)({
17
+ project: app,
18
+ target: 'serve',
19
+ configuration: context.configurationName,
20
+ }, {
21
+ verbose: options.verbose ?? false,
22
+ ...(isUsingModuleFederationDevServerExecutor
23
+ ? { isInitialHost: false }
24
+ : {}),
25
+ }, context));
26
+ }
27
+ return devRemotesIters;
28
+ }
29
+ exports.startDevRemotes = startDevRemotes;
@@ -0,0 +1,12 @@
1
+ import { type ExecutorContext } from '@nx/devkit';
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<{
8
+ success: boolean;
9
+ baseUrl: string;
10
+ }, {
11
+ success: boolean;
12
+ }, unknown>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startStaticRemotesFileServer = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const file_server_impl_1 = require("@nx/web/src/executors/file-server/file-server.impl");
6
+ const path_1 = require("path");
7
+ const fs_1 = require("fs");
8
+ function startStaticRemotesFileServer(remotes, context, options) {
9
+ let shouldMoveToCommonLocation = false;
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);
14
+ if (!commonOutputDirectory) {
15
+ commonOutputDirectory = directoryOfOutputPath;
16
+ }
17
+ else if (commonOutputDirectory !== directoryOfOutputPath ||
18
+ !outputPath.endsWith(app)) {
19
+ shouldMoveToCommonLocation = true;
20
+ }
21
+ }
22
+ if (shouldMoveToCommonLocation) {
23
+ 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), {
28
+ force: true,
29
+ recursive: true,
30
+ });
31
+ }
32
+ }
33
+ const staticRemotesIter = (0, file_server_impl_1.default)({
34
+ cors: true,
35
+ watch: false,
36
+ staticFilePath: commonOutputDirectory,
37
+ parallel: false,
38
+ spa: false,
39
+ withDeps: false,
40
+ host: options.host,
41
+ port: options.staticRemotesPort,
42
+ ssl: options.ssl,
43
+ sslCert: options.sslCert,
44
+ sslKey: options.sslKey,
45
+ }, context);
46
+ return staticRemotesIter;
47
+ }
48
+ exports.startStaticRemotesFileServer = startStaticRemotesFileServer;
@@ -0,0 +1,3 @@
1
+ import { type ExecutorContext } from '@nx/devkit';
2
+ import { type Schema } from './schema';
3
+ export default function moduleFederationDevServerExecutor(schema: Schema, context: ExecutorContext): AsyncGenerator<any, any, undefined>;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const lib_1 = require("./lib");
5
+ const rxjs_for_await_1 = require("@nx/devkit/src/utils/rxjs-for-await");
6
+ const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
7
+ const module_federation_1 = require("@nx/webpack/src/utils/module-federation");
8
+ const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
9
+ const file_server_impl_1 = require("@nx/web/src/executors/file-server/file-server.impl");
10
+ const ngcli_adapter_1 = require("nx/src/adapter/ngcli-adapter");
11
+ const dev_server_impl_1 = require("../../builders/dev-server/dev-server.impl");
12
+ const module_federation_2 = require("../../builders/utilities/module-federation");
13
+ const path_1 = require("path");
14
+ const fs_1 = require("fs");
15
+ async function* moduleFederationDevServerExecutor(schema, context) {
16
+ // Force Node to resolve to look for the nx binary that is inside node_modules
17
+ const nxBin = require.resolve('nx/bin/nx');
18
+ const options = (0, lib_1.normalizeOptions)(schema);
19
+ options.staticRemotesPort ??= options.port + 1;
20
+ const { projects: workspaceProjects } = (0, devkit_1.readProjectsConfigurationFromProjectGraph)(context.projectGraph);
21
+ const project = workspaceProjects[context.projectName];
22
+ const currIter = options.static
23
+ ? (0, file_server_impl_1.default)({
24
+ port: options.port,
25
+ host: options.host,
26
+ ssl: options.ssl,
27
+ buildTarget: options.buildTarget,
28
+ parallel: false,
29
+ spa: false,
30
+ withDeps: false,
31
+ cors: true,
32
+ }, context)
33
+ : (0, rxjs_for_await_1.eachValueFrom)((0, dev_server_impl_1.executeDevServerBuilder)(options, await (0, ngcli_adapter_1.createBuilderContext)({
34
+ builderName: '@nx/angular:webpack-browser',
35
+ description: 'Build a browser application',
36
+ optionSchema: await Promise.resolve().then(() => require('../../builders/webpack-browser/schema.json')),
37
+ }, context)));
38
+ if (options.isInitialHost === false) {
39
+ return yield* currIter;
40
+ }
41
+ let pathToManifestFile = (0, path_1.join)(context.root, project.sourceRoot, 'assets/module-federation.manifest.json');
42
+ if (options.pathToManifestFile) {
43
+ const userPathToManifestFile = (0, path_1.join)(context.root, options.pathToManifestFile);
44
+ if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
45
+ throw new Error(`The provided Module Federation manifest file path does not exist. Please check the file exists at "${userPathToManifestFile}".`);
46
+ }
47
+ else if ((0, path_1.extname)(options.pathToManifestFile) !== '.json') {
48
+ throw new Error(`The Module Federation manifest file must be a JSON. Please ensure the file at ${userPathToManifestFile} is a JSON.`);
49
+ }
50
+ pathToManifestFile = userPathToManifestFile;
51
+ }
52
+ (0, module_federation_2.validateDevRemotes)(options, workspaceProjects);
53
+ const moduleFederationConfig = (0, module_federation_1.getModuleFederationConfig)(project.targets.build.options.tsConfig, context.root, project.root, 'angular');
54
+ const remotes = (0, module_federation_1.getRemotes)(options.devRemotes, options.skipRemotes, moduleFederationConfig, {
55
+ projectName: project.name,
56
+ projectGraph: context.projectGraph,
57
+ root: context.root,
58
+ }, pathToManifestFile);
59
+ if (remotes.devRemotes.length > 0 && !schema.staticRemotesPort) {
60
+ options.staticRemotesPort = options.devRemotes.reduce((portToUse, r) => {
61
+ const remotePort = context.projectGraph.nodes[r].data.targets['serve'].options.port;
62
+ if (remotePort >= portToUse) {
63
+ return remotePort + 1;
64
+ }
65
+ }, options.staticRemotesPort);
66
+ }
67
+ await (0, lib_1.buildStaticRemotes)(remotes, nxBin, context, options);
68
+ const devRemoteIters = await (0, lib_1.startDevRemotes)(remotes, workspaceProjects, options, context);
69
+ const staticRemotesIter = remotes.staticRemotes.length > 0
70
+ ? (0, lib_1.startStaticRemotesFileServer)(remotes, context, options)
71
+ : undefined;
72
+ const removeBaseUrlEmission = (iter) => (0, async_iterable_1.mapAsyncIterable)(iter, (v) => ({
73
+ ...v,
74
+ baseUrl: undefined,
75
+ }));
76
+ return yield* (0, async_iterable_1.combineAsyncIterables)(removeBaseUrlEmission(currIter), ...devRemoteIters.map(removeBaseUrlEmission), ...(staticRemotesIter ? [removeBaseUrlEmission(staticRemotesIter)] : []), (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
77
+ if (!options.isInitialHost) {
78
+ done();
79
+ return;
80
+ }
81
+ if (remotes.remotePorts.length === 0) {
82
+ devkit_1.logger.info(`NX All remotes started, server ready at http://localhost:${options.port}`);
83
+ next({ success: true, baseUrl: `http://localhost:${options.port}` });
84
+ done();
85
+ return;
86
+ }
87
+ try {
88
+ const portsToWaitFor = staticRemotesIter
89
+ ? [options.staticRemotesPort, ...remotes.remotePorts]
90
+ : [...remotes.remotePorts];
91
+ await Promise.all(portsToWaitFor.map((port) => (0, wait_for_port_open_1.waitForPortOpen)(port, {
92
+ retries: 480,
93
+ retryDelay: 2500,
94
+ host: 'localhost',
95
+ })));
96
+ devkit_1.logger.info(`NX All remotes started, server ready at http://localhost:${options.port}`);
97
+ next({ success: true, baseUrl: `http://localhost:${options.port}` });
98
+ }
99
+ catch {
100
+ throw new Error(`Timed out waiting for remote to start. Check above for any errors.`);
101
+ }
102
+ finally {
103
+ done();
104
+ }
105
+ }));
106
+ }
107
+ exports.default = moduleFederationDevServerExecutor;
@@ -1,8 +1,7 @@
1
1
  {
2
- "version": 2,
3
- "outputCapture": "direct-nodejs",
4
2
  "$schema": "http://json-schema.org/draft-07/schema",
5
3
  "title": "Schema for Module Federation Dev Server",
4
+ "outputCapture": "direct-nodejs",
6
5
  "description": "The module-federation-dev-server executor is reserved exclusively for use with host Module Federation applications. It allows the user to specify which remote applications should be served with the host.",
7
6
  "type": "object",
8
7
  "presets": [
@@ -149,6 +148,13 @@
149
148
  }
150
149
  },
151
150
  "additionalProperties": false,
152
- "anyOf": [{ "required": ["buildTarget"] }, { "required": ["browserTarget"] }],
151
+ "anyOf": [
152
+ {
153
+ "required": ["buildTarget"]
154
+ },
155
+ {
156
+ "required": ["browserTarget"]
157
+ }
158
+ ],
153
159
  "examplesFile": "../../../docs/module-federation-dev-server-examples.md"
154
160
  }
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addLintingGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const eslint_1 = require("@nx/eslint");
6
- const lint_project_1 = require("@nx/eslint/src/generators/lint-project/lint-project");
7
6
  const add_angular_eslint_dependencies_1 = require("./lib/add-angular-eslint-dependencies");
8
7
  const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
9
8
  const string_utils_1 = require("@nx/devkit/src/utils/string-utils");
@@ -17,10 +16,6 @@ async function addLintingGenerator(tree, options) {
17
16
  (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.app.json'),
18
17
  ],
19
18
  unitTestRunner: options.unitTestRunner,
20
- eslintFilePatterns: [
21
- (0, lint_project_1.mapLintPattern)(options.projectRoot, 'ts', rootProject),
22
- (0, lint_project_1.mapLintPattern)(options.projectRoot, 'html', rootProject),
23
- ],
24
19
  setParserOptionsProject: options.setParserOptionsProject,
25
20
  skipFormat: true,
26
21
  rootProject: rootProject,
@@ -24,6 +24,7 @@ async function addE2e(tree, options) {
24
24
  skipPackageJson: options.skipPackageJson,
25
25
  skipFormat: true,
26
26
  devServerTarget: `${options.name}:serve:development`,
27
+ baseUrl: 'http://localhost:4200',
27
28
  rootProject: options.rootProject,
28
29
  });
29
30
  }
@@ -1,5 +1,4 @@
1
1
  export * from './add-files';
2
2
  export * from './add-path-mapping';
3
3
  export * from './normalize-options';
4
- export * from './update-linting-file-patterns';
5
4
  export * from './update-tsconfig-included-files';
@@ -4,5 +4,4 @@ const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./add-files"), exports);
5
5
  tslib_1.__exportStar(require("./add-path-mapping"), exports);
6
6
  tslib_1.__exportStar(require("./normalize-options"), exports);
7
- tslib_1.__exportStar(require("./update-linting-file-patterns"), exports);
8
7
  tslib_1.__exportStar(require("./update-tsconfig-included-files"), exports);
@@ -8,7 +8,6 @@ async function librarySecondaryEntryPointGenerator(tree, rawOptions) {
8
8
  (0, lib_1.addFiles)(tree, options);
9
9
  (0, lib_1.addPathMapping)(tree, options);
10
10
  (0, lib_1.updateTsConfigIncludedFiles)(tree, options);
11
- (0, lib_1.updateLintingFilePatterns)(tree, options);
12
11
  await (0, devkit_1.formatFiles)(tree);
13
12
  }
14
13
  exports.librarySecondaryEntryPointGenerator = librarySecondaryEntryPointGenerator;
@@ -217,7 +217,6 @@ class E2eMigrator extends project_migrator_1.ProjectMigrator {
217
217
  await (0, eslint_1.lintProjectGenerator)(this.tree, {
218
218
  project: this.project.name,
219
219
  linter: eslint_1.Linter.EsLint,
220
- eslintFilePatterns: [`${this.project.newRoot}/**/*.{js,ts}`],
221
220
  unitTestRunner: this.options.unitTestRunner,
222
221
  tsConfigPaths: [
223
222
  (0, devkit_1.joinPathFragments)(this.project.newRoot, 'tsconfig.json'),
@@ -242,6 +241,7 @@ class E2eMigrator extends project_migrator_1.ProjectMigrator {
242
241
  skipFormat: true,
243
242
  // any target would do, we replace it later with the target existing in the project being migrated
244
243
  devServerTarget: `${this.appName}:serve`,
244
+ baseUrl: 'http://localhost:4200',
245
245
  });
246
246
  const cypressConfigFilePath = this.updateOrCreateCypressConfigFile(oldCypressConfigFilePath);
247
247
  this.updateCypressProjectConfiguration(cypressConfigFilePath);
@@ -8,7 +8,7 @@ function setupServeTarget(host, options) {
8
8
  ...appConfig.targets['serve'],
9
9
  executor: options.mfType === 'host'
10
10
  ? '@nx/angular:module-federation-dev-server'
11
- : '@nx/angular:webpack-dev-server',
11
+ : '@nx/angular:dev-server',
12
12
  options: {
13
13
  ...appConfig.targets['serve'].options,
14
14
  port: options.port ?? undefined,
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export default function (tree: Tree): Promise<void>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ async function default_1(tree) {
5
+ const projects = (0, devkit_1.getProjects)(tree);
6
+ for (const [, project] of projects) {
7
+ if (project.projectType !== 'application') {
8
+ continue;
9
+ }
10
+ for (const target of Object.values(project.targets ?? {})) {
11
+ if (target.executor === '@nx/angular:webpack-dev-server' ||
12
+ target.executor === '@nrwl/angular:webpack-dev-server') {
13
+ target.executor = '@nx/angular:dev-server';
14
+ }
15
+ }
16
+ (0, devkit_1.updateProjectConfiguration)(tree, project.name, project);
17
+ }
18
+ // update options from nx.json target defaults
19
+ const nxJson = (0, devkit_1.readNxJson)(tree);
20
+ if (!nxJson.targetDefaults) {
21
+ return;
22
+ }
23
+ for (const [targetOrExecutor, targetConfig] of Object.entries(nxJson.targetDefaults)) {
24
+ if (targetOrExecutor === '@nx/angular:webpack-dev-server') {
25
+ nxJson.targetDefaults['@nx/angular:dev-server'] = targetConfig;
26
+ delete nxJson.targetDefaults['@nx/angular:webpack-dev-server'];
27
+ }
28
+ else if (targetOrExecutor === '@nrwl/angular:webpack-dev-server') {
29
+ nxJson.targetDefaults['@nx/angular:dev-server'] = targetConfig;
30
+ delete nxJson.targetDefaults['@nrwl/angular:webpack-dev-server'];
31
+ }
32
+ else if (targetConfig.executor === '@nx/angular:webpack-dev-server' ||
33
+ targetConfig.executor === '@nrwl/angular:webpack-dev-server') {
34
+ targetConfig.executor = '@nx/angular:dev-server';
35
+ }
36
+ }
37
+ (0, devkit_1.updateNxJson)(tree, nxJson);
38
+ await (0, devkit_1.formatFiles)(tree);
39
+ }
40
+ exports.default = default_1;
@@ -2,7 +2,7 @@ export declare const nxVersion: any;
2
2
  export declare const angularVersion = "~17.0.0";
3
3
  export declare const angularDevkitVersion = "~17.0.0";
4
4
  export declare const ngPackagrVersion = "~17.0.0";
5
- export declare const ngrxVersion = "~16.0.0";
5
+ export declare const ngrxVersion = "~17.0.0";
6
6
  export declare const rxjsVersion = "~7.8.0";
7
7
  export declare const zoneJsVersion = "~0.14.0";
8
8
  export declare const angularJsVersion = "1.7.9";
@@ -5,7 +5,7 @@ exports.nxVersion = require('../../package.json').version;
5
5
  exports.angularVersion = '~17.0.0';
6
6
  exports.angularDevkitVersion = '~17.0.0';
7
7
  exports.ngPackagrVersion = '~17.0.0';
8
- exports.ngrxVersion = '~16.0.0';
8
+ exports.ngrxVersion = '~17.0.0';
9
9
  exports.rxjsVersion = '~7.8.0';
10
10
  exports.zoneJsVersion = '~0.14.0';
11
11
  exports.angularJsVersion = '1.7.9';
@@ -1,5 +0,0 @@
1
- import type { Schema } from './schema';
2
- import { executeWebpackDevServerBuilder } from '../webpack-dev-server/webpack-dev-server.impl';
3
- export declare function executeModuleFederationDevServerBuilder(schema: Schema, context: import('@angular-devkit/architect').BuilderContext): ReturnType<typeof executeWebpackDevServerBuilder | any>;
4
- declare const _default: any;
5
- export default _default;
@@ -1,229 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executeModuleFederationDevServerBuilder = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- const ngcli_adapter_1 = require("nx/src/adapter/ngcli-adapter");
6
- const webpack_dev_server_impl_1 = require("../webpack-dev-server/webpack-dev-server.impl");
7
- const project_graph_1 = require("nx/src/project-graph/project-graph");
8
- const executor_utils_1 = require("nx/src/command-line/run/executor-utils");
9
- const module_federation_1 = require("../utilities/module-federation");
10
- const fs_1 = require("fs");
11
- const path_1 = require("path");
12
- const module_federation_2 = require("@nx/webpack/src/utils/module-federation");
13
- const child_process_1 = require("child_process");
14
- const rxjs_1 = require("rxjs");
15
- const fs_2 = require("fs");
16
- function buildStaticRemotes(remotes, nxBin, context, options) {
17
- const mappedLocationOfRemotes = {};
18
- for (const app of remotes.staticRemotes) {
19
- mappedLocationOfRemotes[app] = `http${options.ssl ? 's' : ''}://${options.host}:${options.staticRemotesPort}/${app}`;
20
- }
21
- process.env.NX_MF_DEV_SERVER_STATIC_REMOTES = JSON.stringify(mappedLocationOfRemotes);
22
- const staticRemoteBuildPromise = new Promise((res) => {
23
- devkit_1.logger.info(`NX Building ${remotes.staticRemotes.length} static remotes...`);
24
- const staticProcess = (0, child_process_1.fork)(nxBin, [
25
- 'run-many',
26
- `--target=build`,
27
- `--projects=${remotes.staticRemotes.join(',')}`,
28
- ...(context.target.configuration
29
- ? [`--configuration=${context.target.configuration}`]
30
- : []),
31
- ...(options.parallel ? [`--parallel=${options.parallel}`] : []),
32
- ], {
33
- cwd: context.workspaceRoot,
34
- stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
35
- });
36
- staticProcess.stdout.on('data', (data) => {
37
- const ANSII_CODE_REGEX = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
38
- const stdoutString = data.toString().replace(ANSII_CODE_REGEX, '');
39
- if (stdoutString.includes('Successfully ran target build')) {
40
- staticProcess.stdout.removeAllListeners('data');
41
- devkit_1.logger.info(`NX Built ${remotes.staticRemotes.length} static remotes`);
42
- res();
43
- }
44
- });
45
- staticProcess.stderr.on('data', (data) => devkit_1.logger.info(data.toString()));
46
- staticProcess.on('exit', (code) => {
47
- if (code !== 0) {
48
- throw new Error(`Remotes failed to build. See above for errors.`);
49
- }
50
- });
51
- process.on('SIGTERM', () => staticProcess.kill('SIGTERM'));
52
- process.on('exit', () => staticProcess.kill('SIGTERM'));
53
- });
54
- return staticRemoteBuildPromise;
55
- }
56
- function startStaticRemotesFileServer(remotes, projectGraph, options, context) {
57
- let shouldMoveToCommonLocation = false;
58
- let commonOutputDirectory;
59
- for (const app of remotes.staticRemotes) {
60
- const outputPath = projectGraph.nodes[app].data.targets['build'].options.outputPath;
61
- const directoryOfOutputPath = (0, path_1.dirname)(outputPath);
62
- if (!commonOutputDirectory) {
63
- commonOutputDirectory = directoryOfOutputPath;
64
- }
65
- else if (commonOutputDirectory !== directoryOfOutputPath) {
66
- shouldMoveToCommonLocation = true;
67
- }
68
- }
69
- if (shouldMoveToCommonLocation) {
70
- commonOutputDirectory = (0, path_1.join)(devkit_1.workspaceRoot, 'tmp/static-remotes');
71
- for (const app of remotes.staticRemotes) {
72
- const outputPath = projectGraph.nodes[app].data.targets['build'].options.outputPath;
73
- const outputPathParts = outputPath.split('/');
74
- (0, fs_2.cpSync)(outputPath, (0, path_1.join)(commonOutputDirectory, outputPathParts[outputPathParts.length - 1]), {
75
- force: true,
76
- recursive: true,
77
- });
78
- }
79
- }
80
- const staticRemotesIter$ = (0, rxjs_1.from)(Promise.resolve().then(() => require('@nx/web/src/executors/file-server/file-server.impl'))).pipe((0, rxjs_1.switchMap)((fileServerExecutor) => fileServerExecutor.default({
81
- cors: true,
82
- watch: false,
83
- staticFilePath: commonOutputDirectory,
84
- parallel: false,
85
- spa: false,
86
- withDeps: false,
87
- host: options.host,
88
- port: options.staticRemotesPort,
89
- ssl: options.ssl,
90
- sslCert: options.sslCert,
91
- sslKey: options.sslKey,
92
- }, {
93
- projectGraph,
94
- root: context.workspaceRoot,
95
- target: projectGraph.nodes[context.target.project].data.targets[context.target.target],
96
- targetName: context.target.target,
97
- projectName: context.target.project,
98
- configurationName: context.target.configuration,
99
- cwd: context.currentDirectory,
100
- isVerbose: options.verbose,
101
- projectsConfigurations: (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(projectGraph),
102
- nxJsonConfiguration: (0, devkit_1.readNxJson)(),
103
- })));
104
- return staticRemotesIter$;
105
- }
106
- function startDevRemotes(remotes, workspaceProjects, options, context) {
107
- const devRemotes$ = [];
108
- for (const app of remotes.devRemotes) {
109
- if (!workspaceProjects[app].targets?.['serve']) {
110
- throw new Error(`Could not find "serve" target in "${app}" project.`);
111
- }
112
- else if (!workspaceProjects[app].targets?.['serve'].executor) {
113
- throw new Error(`Could not find executor for "serve" target in "${app}" project.`);
114
- }
115
- const runOptions = {};
116
- const [collection, executor] = workspaceProjects[app].targets['serve'].executor.split(':');
117
- const isUsingModuleFederationDevServerExecutor = executor.includes('module-federation-dev-server');
118
- const { schema } = (0, executor_utils_1.getExecutorInformation)(collection, executor, devkit_1.workspaceRoot, workspaceProjects);
119
- if ((options.verbose && schema.additionalProperties) ||
120
- 'verbose' in schema.properties) {
121
- runOptions.verbose = options.verbose;
122
- }
123
- if (isUsingModuleFederationDevServerExecutor) {
124
- runOptions.isInitialHost = false;
125
- }
126
- const serve$ = (0, ngcli_adapter_1.scheduleTarget)(context.workspaceRoot, {
127
- project: app,
128
- target: 'serve',
129
- configuration: context.target.configuration,
130
- runOptions,
131
- projects: workspaceProjects,
132
- }, options.verbose).then((obs) => {
133
- obs.toPromise().catch((err) => {
134
- throw new Error(`Remote '${app}' failed to serve correctly due to the following: \r\n${err.toString()}`);
135
- });
136
- });
137
- devRemotes$.push(serve$);
138
- }
139
- return devRemotes$;
140
- }
141
- function executeModuleFederationDevServerBuilder(schema, context) {
142
- // Force Node to resolve to look for the nx binary that is inside node_modules
143
- const nxBin = require.resolve('nx/bin/nx');
144
- const options = normalizeOptions(schema);
145
- options.staticRemotesPort ??= options.port + 1;
146
- const projectGraph = (0, devkit_1.readCachedProjectGraph)();
147
- const { projects: workspaceProjects } = (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(projectGraph);
148
- const project = workspaceProjects[context.target.project];
149
- const staticFileServer = (0, rxjs_1.from)(Promise.resolve().then(() => require('@nx/web/src/executors/file-server/file-server.impl'))).pipe((0, rxjs_1.switchMap)((fileServerExecutor) => fileServerExecutor.default({
150
- port: options.port,
151
- host: options.host,
152
- ssl: options.ssl,
153
- buildTarget: options.buildTarget,
154
- parallel: false,
155
- spa: false,
156
- withDeps: false,
157
- cors: true,
158
- }, {
159
- projectGraph,
160
- root: context.workspaceRoot,
161
- target: projectGraph.nodes[context.target.project].data.targets[context.target.target],
162
- targetName: context.target.target,
163
- projectName: context.target.project,
164
- configurationName: context.target.configuration,
165
- cwd: context.currentDirectory,
166
- isVerbose: options.verbose,
167
- projectsConfigurations: { projects: workspaceProjects, version: 2 },
168
- nxJsonConfiguration: (0, devkit_1.readNxJson)(),
169
- })));
170
- const webpackDevServer = (0, webpack_dev_server_impl_1.executeWebpackDevServerBuilder)(options, context);
171
- const currExecutor = options.static ? staticFileServer : webpackDevServer;
172
- if (options.isInitialHost === false) {
173
- return currExecutor;
174
- }
175
- let pathToManifestFile = (0, path_1.join)(context.workspaceRoot, project.sourceRoot, 'assets/module-federation.manifest.json');
176
- if (options.pathToManifestFile) {
177
- const userPathToManifestFile = (0, path_1.join)(context.workspaceRoot, options.pathToManifestFile);
178
- if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
179
- throw new Error(`The provided Module Federation manifest file path does not exist. Please check the file exists at "${userPathToManifestFile}".`);
180
- }
181
- else if ((0, path_1.extname)(options.pathToManifestFile) !== '.json') {
182
- throw new Error(`The Module Federation manifest file must be a JSON. Please ensure the file at ${userPathToManifestFile} is a JSON.`);
183
- }
184
- pathToManifestFile = userPathToManifestFile;
185
- }
186
- (0, module_federation_1.validateDevRemotes)(options, workspaceProjects);
187
- const moduleFederationConfig = (0, module_federation_2.getModuleFederationConfig)(project.targets.build.options.tsConfig, context.workspaceRoot, project.root, 'angular');
188
- const remotes = (0, module_federation_2.getRemotes)(options.devRemotes, options.skipRemotes, moduleFederationConfig, {
189
- projectName: project.name,
190
- projectGraph,
191
- root: context.workspaceRoot,
192
- }, pathToManifestFile);
193
- if (remotes.devRemotes.length > 0 && !schema.staticRemotesPort) {
194
- options.staticRemotesPort = options.devRemotes.reduce((portToUse, r) => {
195
- const remotePort = projectGraph.nodes[r].data.targets['serve'].options.port;
196
- if (remotePort >= portToUse) {
197
- return remotePort + 1;
198
- }
199
- }, options.staticRemotesPort);
200
- }
201
- const staticRemoteBuildPromise = buildStaticRemotes(remotes, nxBin, context, options);
202
- return (0, rxjs_1.from)(staticRemoteBuildPromise).pipe((0, rxjs_1.concatMap)(() => {
203
- const staticRemotesIter$ = remotes.staticRemotes.length > 0
204
- ? startStaticRemotesFileServer(remotes, projectGraph, options, context)
205
- : (0, rxjs_1.from)(Promise.resolve());
206
- const devRemotes$ = startDevRemotes(remotes, workspaceProjects, options, context);
207
- return devRemotes$.length > 0
208
- ? (0, rxjs_1.combineLatest)([...devRemotes$, staticRemotesIter$]).pipe((0, rxjs_1.concatMap)(() => currExecutor))
209
- : (0, rxjs_1.from)(staticRemotesIter$).pipe((0, rxjs_1.concatMap)(() => currExecutor));
210
- }));
211
- }
212
- exports.executeModuleFederationDevServerBuilder = executeModuleFederationDevServerBuilder;
213
- exports.default = require('@angular-devkit/architect').createBuilder(executeModuleFederationDevServerBuilder);
214
- function normalizeOptions(schema) {
215
- let buildTarget = schema.buildTarget;
216
- if (schema.browserTarget) {
217
- buildTarget ??= schema.browserTarget;
218
- delete schema.browserTarget;
219
- }
220
- return {
221
- ...schema,
222
- buildTarget,
223
- host: schema.host ?? 'localhost',
224
- port: schema.port ?? 4200,
225
- liveReload: schema.liveReload ?? true,
226
- open: schema.open ?? false,
227
- ssl: schema.ssl ?? false,
228
- };
229
- }
@@ -1,4 +0,0 @@
1
- import type { Schema } from './schema';
2
- export declare function executeWebpackDevServerBuilder(rawOptions: Schema, context: import('@angular-devkit/architect').BuilderContext): import("rxjs").Observable<import("@angular-devkit/build-angular").DevServerBuilderOutput>;
3
- declare const _default: any;
4
- export default _default;
@@ -1,3 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- import { NormalizedGeneratorOptions } from '../schema';
3
- export declare function updateLintingFilePatterns(tree: Tree, options: NormalizedGeneratorOptions): void;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateLintingFilePatterns = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- function updateLintingFilePatterns(tree, options) {
6
- const { libraryProject } = options;
7
- if (libraryProject.targets?.lint?.options?.lintFilePatterns) {
8
- libraryProject.targets.lint.options.lintFilePatterns.push(...[
9
- `${libraryProject.root}/${options.name}/**/*.ts`,
10
- `${libraryProject.root}/${options.name}/**/*.html`,
11
- ]);
12
- (0, devkit_1.updateProjectConfiguration)(tree, options.library, libraryProject);
13
- }
14
- }
15
- exports.updateLintingFilePatterns = updateLintingFilePatterns;