@nx/angular 19.6.0-canary.20240813-c72ba9b → 19.6.0-canary.20240815-5410794

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. package/esm2022/src/runtime/nx/data-persistence.mjs +9 -4
  2. package/esm2022/testing/src/testing-utils.mjs +5 -3
  3. package/executors.d.ts +1 -1
  4. package/executors.js +1 -1
  5. package/executors.json +5 -5
  6. package/fesm2022/nx-angular-testing.mjs +4 -2
  7. package/fesm2022/nx-angular-testing.mjs.map +1 -1
  8. package/fesm2022/nx-angular.mjs +8 -3
  9. package/fesm2022/nx-angular.mjs.map +1 -1
  10. package/migrations.json +76 -0
  11. package/package.json +8 -8
  12. package/src/executors/module-federation-ssr-dev-server/lib/build-static-remotes.d.ts +4 -0
  13. package/src/executors/module-federation-ssr-dev-server/lib/build-static-remotes.js +65 -0
  14. package/src/executors/module-federation-ssr-dev-server/lib/normalize-options.d.ts +2 -0
  15. package/src/executors/module-federation-ssr-dev-server/lib/normalize-options.js +19 -0
  16. package/src/executors/module-federation-ssr-dev-server/lib/start-dev-remotes.d.ts +5 -0
  17. package/src/executors/module-federation-ssr-dev-server/lib/start-dev-remotes.js +30 -0
  18. package/src/executors/module-federation-ssr-dev-server/lib/start-static-remotes.d.ts +9 -0
  19. package/src/executors/module-federation-ssr-dev-server/lib/start-static-remotes.js +37 -0
  20. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts +4 -0
  21. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +101 -0
  22. package/src/{builders/module-federation-dev-ssr → executors/module-federation-ssr-dev-server}/schema.d.ts +7 -1
  23. package/src/{builders/module-federation-dev-ssr → executors/module-federation-ssr-dev-server}/schema.json +34 -2
  24. package/src/executors/utilities/esbuild-extensions.d.ts +2 -1
  25. package/src/generators/component-cypress-spec/schema.json +2 -1
  26. package/src/generators/host/files/js/webpack.server.config.js__tmpl__ +6 -1
  27. package/src/generators/host/files/ts/webpack.server.config.ts__tmpl__ +6 -1
  28. package/src/generators/ng-add/migrators/projects/e2e.migrator.js +1 -1
  29. package/src/generators/ng-add/migrators/projects/project.migrator.d.ts +2 -0
  30. package/src/generators/ng-add/migrators/projects/project.migrator.js +38 -1
  31. package/src/generators/remote/files/base/webpack.server.config.js__tmpl__ +7 -1
  32. package/src/generators/remote/files/base-ts/webpack.server.config.ts__tmpl__ +6 -1
  33. package/src/generators/setup-mf/files/ts-webpack/webpack.config.ts__tmpl__ +6 -1
  34. package/src/generators/setup-mf/files/ts-webpack/webpack.prod.config.ts__tmpl__ +6 -1
  35. package/src/generators/setup-mf/files/webpack/webpack.config.js__tmpl__ +7 -1
  36. package/src/generators/setup-mf/files/webpack/webpack.prod.config.js__tmpl__ +7 -1
  37. package/src/generators/stories/schema.json +4 -2
  38. package/src/migrations/update-19-6-0/turn-off-dts-by-default.d.ts +2 -0
  39. package/src/migrations/update-19-6-0/turn-off-dts-by-default.js +56 -0
  40. package/src/migrations/update-19-6-0/update-angular-cli.d.ts +3 -0
  41. package/src/migrations/update-19-6-0/update-angular-cli.js +23 -0
  42. package/src/runtime/nx/data-persistence.d.ts +8 -3
  43. package/src/utils/versions.d.ts +3 -3
  44. package/src/utils/versions.js +3 -3
  45. package/testing/src/testing-utils.d.ts +4 -2
  46. package/src/builders/module-federation-dev-ssr/module-federation-dev-ssr.impl.d.ts +0 -4
  47. package/src/builders/module-federation-dev-ssr/module-federation-dev-ssr.impl.js +0 -103
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const minimatch_1 = require("minimatch");
6
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
7
+ async function default_1(tree) {
8
+ (0, devkit_1.visitNotIgnoredFiles)(tree, '', (path) => {
9
+ const webpackConfigGlob = '**/webpack*.config*.{js,ts,mjs,cjs}';
10
+ const result = (0, minimatch_1.minimatch)(path, webpackConfigGlob);
11
+ if (!result) {
12
+ return;
13
+ }
14
+ let webpackConfigContents = tree.read(path, 'utf-8');
15
+ if (!/withModuleFederationSSR|withModuleFederation/.test(webpackConfigContents)) {
16
+ return;
17
+ }
18
+ const WITH_MODULE_FEDERATION_SELECTOR = 'CallExpression:has(Identifier[name=withModuleFederation]),CallExpression:has(Identifier[name=withModuleFederationForSSR])';
19
+ const EXISTING_MF_OVERRIDES_SELECTOR = 'ObjectLiteralExpression';
20
+ const ast = tsquery_1.tsquery.ast(webpackConfigContents);
21
+ const withModuleFederationNodes = (0, tsquery_1.tsquery)(ast, WITH_MODULE_FEDERATION_SELECTOR, { visitAllChildren: true });
22
+ if (!withModuleFederationNodes.length) {
23
+ return;
24
+ }
25
+ const withModuleFederationNode = withModuleFederationNodes[0];
26
+ const existingOverridesNodes = (0, tsquery_1.tsquery)(withModuleFederationNode, EXISTING_MF_OVERRIDES_SELECTOR, { visitAllChildren: true });
27
+ if (!existingOverridesNodes.length) {
28
+ // doesn't exist, add it
29
+ webpackConfigContents = `${webpackConfigContents.slice(0, withModuleFederationNode.getEnd() - 1)},${JSON.stringify({ dts: false })}${webpackConfigContents.slice(withModuleFederationNode.getEnd() - 1)}`;
30
+ }
31
+ else {
32
+ let existingOverrideNode;
33
+ for (const node of existingOverridesNodes) {
34
+ if (!existingOverrideNode) {
35
+ existingOverrideNode = node;
36
+ }
37
+ if (existingOverrideNode.getText().includes(node.getText())) {
38
+ continue;
39
+ }
40
+ existingOverrideNode = node;
41
+ }
42
+ const DTS_PROPERTY_SELECTOR = 'PropertyAssignment > Identifier[name=dts]';
43
+ const dtsPropertyNode = (0, tsquery_1.tsquery)(existingOverrideNode, DTS_PROPERTY_SELECTOR);
44
+ if (dtsPropertyNode.length) {
45
+ // dts already exists, do nothing
46
+ return;
47
+ }
48
+ const newOverrides = `{ dts: false, ${existingOverrideNode
49
+ .getText()
50
+ .slice(1)}`;
51
+ webpackConfigContents = `${webpackConfigContents.slice(0, existingOverrideNode.getStart())}${newOverrides}${webpackConfigContents.slice(existingOverrideNode.getEnd())}`;
52
+ }
53
+ tree.write(path, webpackConfigContents);
54
+ });
55
+ await (0, devkit_1.formatFiles)(tree);
56
+ }
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare const angularCliVersion = "~18.2.0";
3
+ export default function (tree: Tree): Promise<void>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.angularCliVersion = void 0;
4
+ exports.default = default_1;
5
+ const devkit_1 = require("@nx/devkit");
6
+ exports.angularCliVersion = '~18.2.0';
7
+ async function default_1(tree) {
8
+ let shouldFormat = false;
9
+ (0, devkit_1.updateJson)(tree, 'package.json', (json) => {
10
+ if (json.devDependencies?.['@angular/cli']) {
11
+ json.devDependencies['@angular/cli'] = exports.angularCliVersion;
12
+ shouldFormat = true;
13
+ }
14
+ else if (json.dependencies?.['@angular/cli']) {
15
+ json.dependencies['@angular/cli'] = exports.angularCliVersion;
16
+ shouldFormat = true;
17
+ }
18
+ return json;
19
+ });
20
+ if (shouldFormat) {
21
+ await (0, devkit_1.formatFiles)(tree);
22
+ }
23
+ }
@@ -24,7 +24,6 @@ export type ActionOrActionWithState<T, A> = ActionOrActionWithStates<[T], A>;
24
24
  export type ActionStatesStream<T extends Array<unknown>, A> = Observable<ActionOrActionWithStates<T, A>>;
25
25
  export type ActionStateStream<T, A> = Observable<ActionOrActionWithStates<[T], A>>;
26
26
  /**
27
- *
28
27
  * @whatItDoes Handles pessimistic updates (updating the server first).
29
28
  *
30
29
  * Updating the server, when implemented naively, suffers from race conditions and poor error handling.
@@ -79,10 +78,11 @@ export type ActionStateStream<T, A> = Observable<ActionOrActionWithStates<[T], A
79
78
  * ```
80
79
  *
81
80
  * @param opts
81
+ *
82
+ * @deprecated This will be removed in Nx v21. Import `pessimisticUpdate` from `@ngrx/router-store/data-persistence` instead.
82
83
  */
83
84
  export declare function pessimisticUpdate<T extends Array<unknown>, A extends Action>(opts: PessimisticUpdateOpts<T, A>): (source: ActionStatesStream<T, A>) => Observable<Action>;
84
85
  /**
85
- *
86
86
  * @whatItDoes Handles optimistic updates (updating the client first).
87
87
  *
88
88
  * It runs all fetches in order, which removes race conditions and forces the developer to handle errors.
@@ -138,10 +138,11 @@ export declare function pessimisticUpdate<T extends Array<unknown>, A extends Ac
138
138
  * ```
139
139
  *
140
140
  * @param opts
141
+ *
142
+ * @deprecated This will be removed in Nx v21. Import `optimisticUpdate` from `@ngrx/router-store/data-persistence` instead.
141
143
  */
142
144
  export declare function optimisticUpdate<T extends Array<unknown>, A extends Action>(opts: OptimisticUpdateOpts<T, A>): (source: ActionStatesStream<T, A>) => Observable<Action>;
143
145
  /**
144
- *
145
146
  * @whatItDoes Handles data fetching.
146
147
  *
147
148
  * Data fetching implemented naively suffers from race conditions and poor error handling.
@@ -217,6 +218,8 @@ export declare function optimisticUpdate<T extends Array<unknown>, A extends Act
217
218
  * In addition, if there are multiple requests for Todo 1 scheduled, it will only run the last one.
218
219
  *
219
220
  * @param opts
221
+ *
222
+ * @deprecated This will be removed in Nx v21. Import `fetch` from `@ngrx/router-store/data-persistence` instead.
220
223
  */
221
224
  export declare function fetch<T extends Array<unknown>, A extends Action>(opts: FetchOpts<T, A>): (source: ActionStatesStream<T, A>) => Observable<Action>;
222
225
  /**
@@ -267,5 +270,7 @@ export declare function fetch<T extends Array<unknown>, A extends Action>(opts:
267
270
  *
268
271
  * @param component
269
272
  * @param opts
273
+ *
274
+ * @deprecated This will be removed in Nx v21. Import `navigation` from `@ngrx/router-store/data-persistence` instead.
270
275
  */
271
276
  export declare function navigation<T extends Array<unknown>, A extends Action>(component: Type<any>, opts: HandleNavigationOpts<T>): (source: ActionStatesStream<T, A>) => Observable<Action<string>>;
@@ -1,7 +1,7 @@
1
1
  export declare const nxVersion: any;
2
- export declare const angularVersion = "~18.1.0";
3
- export declare const angularDevkitVersion = "~18.1.0";
4
- export declare const ngPackagrVersion = "~18.1.0";
2
+ export declare const angularVersion = "~18.2.0";
3
+ export declare const angularDevkitVersion = "~18.2.0";
4
+ export declare const ngPackagrVersion = "~18.2.0";
5
5
  export declare const ngrxVersion = "^18.0.1";
6
6
  export declare const rxjsVersion = "~7.8.0";
7
7
  export declare const zoneJsVersion = "~0.14.3";
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.jsoncEslintParserVersion = exports.jasmineMarblesVersion = exports.typesNodeVersion = exports.jestPresetAngularVersion = exports.tsNodeVersion = exports.autoprefixerVersion = exports.postcssUrlVersion = exports.postcssVersion = exports.tailwindVersion = exports.typescriptEslintVersion = exports.angularEslintVersion = exports.moduleFederationEnhancedVersion = exports.moduleFederationNodeVersion = exports.browserSyncVersion = exports.typesExpressVersion = exports.expressVersion = exports.typesCorsVersion = exports.corsVersion = exports.tsLibVersion = exports.angularJsVersion = exports.zoneJsVersion = exports.rxjsVersion = exports.ngrxVersion = exports.ngPackagrVersion = exports.angularDevkitVersion = exports.angularVersion = exports.nxVersion = void 0;
4
4
  exports.nxVersion = require('../../package.json').version;
5
- exports.angularVersion = '~18.1.0';
6
- exports.angularDevkitVersion = '~18.1.0';
7
- exports.ngPackagrVersion = '~18.1.0';
5
+ exports.angularVersion = '~18.2.0';
6
+ exports.angularDevkitVersion = '~18.2.0';
7
+ exports.ngPackagrVersion = '~18.2.0';
8
8
  exports.ngrxVersion = '^18.0.1';
9
9
  exports.rxjsVersion = '~7.8.0';
10
10
  exports.zoneJsVersion = '~0.14.3';
@@ -1,6 +1,7 @@
1
1
  import type { Observable } from 'rxjs';
2
2
  /**
3
- * @deprecated This will be removed in a later version of Nx. Since RxJS 7, use firstValueFrom(obs$.pipe(toArray())) or lastValueFrom(obs$.pipe(toArray())).
3
+ * @deprecated This will be removed in Nx v21. If using RxJS 7, use `firstValueFrom(obs$.pipe(toArray()))`
4
+ * or `lastValueFrom(obs$.pipe(toArray()))`. If using RxJS 6, use `obs$.pipe(toArray()).toPromise()`.
4
5
  *
5
6
  * @whatItDoes reads all the values from an observable and returns a promise
6
7
  * with an array of all values. This should be used in combination with async/await.
@@ -15,7 +16,8 @@ import type { Observable } from 'rxjs';
15
16
  */
16
17
  export declare function readAll<T>(o: Observable<T>): Promise<T[]>;
17
18
  /**
18
- * @deprecated This will be removed in a later version of Nx. Since RxJS 7, use firstValueFrom(obs$)
19
+ * @deprecated This will be removed in Nx v21. Since RxJS 7, use `firstValueFrom(obs$)`. If using RxJS 6,
20
+ * use `obs$.pipe(first()).toPromise()`.
19
21
  *
20
22
  * @whatItDoes reads the first value from an observable and returns a promise
21
23
  * with it. This should be used in combination with async/await.
@@ -1,4 +0,0 @@
1
- import type { Schema } from './schema';
2
- export declare function executeModuleFederationDevSSRBuilder(schema: Schema, context: import('@angular-devkit/architect').BuilderContext): import("rxjs").Observable<unknown>;
3
- declare const _default: any;
4
- export default _default;
@@ -1,103 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executeModuleFederationDevSSRBuilder = executeModuleFederationDevSSRBuilder;
4
- const devkit_1 = require("@nx/devkit");
5
- const child_process_1 = require("child_process");
6
- const fs_1 = require("fs");
7
- const ngcli_adapter_1 = require("nx/src/adapter/ngcli-adapter");
8
- const executor_utils_1 = require("nx/src/command-line/run/executor-utils");
9
- const project_graph_1 = require("nx/src/project-graph/project-graph");
10
- const path_1 = require("path");
11
- const rxjs_1 = require("rxjs");
12
- const operators_1 = require("rxjs/operators");
13
- const angular_version_utils_1 = require("../../executors/utilities/angular-version-utils");
14
- const module_federation_1 = require("../utilities/module-federation");
15
- function executeModuleFederationDevSSRBuilder(schema, context) {
16
- const { ...options } = schema;
17
- const projectGraph = (0, devkit_1.readCachedProjectGraph)();
18
- const { projects: workspaceProjects } = (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(projectGraph);
19
- const project = workspaceProjects[context.target.project];
20
- let pathToManifestFile;
21
- if (options.pathToManifestFile) {
22
- const userPathToManifestFile = (0, path_1.join)(context.workspaceRoot, options.pathToManifestFile);
23
- if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
24
- throw new Error(`The provided Module Federation manifest file path does not exist. Please check the file exists at "${userPathToManifestFile}".`);
25
- }
26
- else if ((0, path_1.extname)(options.pathToManifestFile) !== '.json') {
27
- throw new Error(`The Module Federation manifest file must be a JSON. Please ensure the file at ${userPathToManifestFile} is a JSON.`);
28
- }
29
- pathToManifestFile = userPathToManifestFile;
30
- }
31
- else {
32
- pathToManifestFile = (0, module_federation_1.getDynamicMfManifestFile)(project, context.workspaceRoot);
33
- }
34
- const devServeRemotes = !options.devRemotes
35
- ? []
36
- : Array.isArray(options.devRemotes)
37
- ? options.devRemotes
38
- : [options.devRemotes];
39
- // Set NX_MF_DEV_REMOTES for the Nx Runtime Library Control Plugin
40
- process.env.NX_MF_DEV_REMOTES = JSON.stringify(devServeRemotes);
41
- (0, module_federation_1.validateDevRemotes)({ devRemotes: devServeRemotes }, workspaceProjects);
42
- const remotesToSkip = new Set(options.skipRemotes ?? []);
43
- const staticRemotes = (0, module_federation_1.getStaticRemotes)(project, context, workspaceProjects, remotesToSkip);
44
- const dynamicRemotes = (0, module_federation_1.getDynamicRemotes)(project, context, workspaceProjects, remotesToSkip, pathToManifestFile);
45
- const remotes = [...staticRemotes, ...dynamicRemotes];
46
- const remoteProcessPromises = [];
47
- for (const remote of remotes) {
48
- const isDev = devServeRemotes.includes(remote);
49
- const target = isDev ? 'serve-ssr' : 'static-server';
50
- if (!workspaceProjects[remote].targets?.[target]) {
51
- throw new Error(`Could not find "${target}" target in "${remote}" project.`);
52
- }
53
- else if (!workspaceProjects[remote].targets?.[target].executor) {
54
- throw new Error(`Could not find executor for "${target}" target in "${remote}" project.`);
55
- }
56
- const runOptions = {};
57
- if (options.verbose) {
58
- const [collection, executor] = workspaceProjects[remote].targets[target].executor.split(':');
59
- const { schema } = (0, executor_utils_1.getExecutorInformation)(collection, executor, devkit_1.workspaceRoot, workspaceProjects);
60
- if (schema.additionalProperties || 'verbose' in schema.properties) {
61
- runOptions.verbose = options.verbose;
62
- }
63
- }
64
- const remotePromise = new Promise((res, rej) => {
65
- if (target === 'static-server') {
66
- const remoteProject = workspaceProjects[remote];
67
- const remoteServerOutput = (0, path_1.join)(devkit_1.workspaceRoot, remoteProject.targets.server.options.outputPath, 'main.js');
68
- const pm = (0, devkit_1.getPackageManagerCommand)();
69
- (0, child_process_1.execSync)(`${pm.exec} nx run ${remote}:server${context.target.configuration
70
- ? `:${context.target.configuration}`
71
- : ''}`, { stdio: 'inherit' });
72
- const child = (0, child_process_1.fork)(remoteServerOutput, {
73
- env: { PORT: remoteProject.targets['serve-ssr'].options.port },
74
- });
75
- child.on('message', (msg) => {
76
- if (msg === 'nx.server.ready') {
77
- res();
78
- }
79
- });
80
- }
81
- if (target === 'serve-ssr') {
82
- (0, ngcli_adapter_1.scheduleTarget)(context.workspaceRoot, {
83
- project: remote,
84
- target,
85
- configuration: context.target.configuration,
86
- runOptions,
87
- projects: workspaceProjects,
88
- }, options.verbose).then((obs) => obs
89
- .pipe((0, operators_1.tap)((result) => {
90
- result.success && res();
91
- }))
92
- .toPromise());
93
- }
94
- });
95
- remoteProcessPromises.push(remotePromise);
96
- }
97
- const { major: angularMajorVersion } = (0, angular_version_utils_1.getInstalledAngularVersionInfo)();
98
- const { executeSSRDevServerBuilder } = angularMajorVersion >= 17
99
- ? require('@angular-devkit/build-angular')
100
- : require('@nguniversal/builders');
101
- return (0, rxjs_1.from)(Promise.all(remoteProcessPromises)).pipe((0, operators_1.switchMap)(() => executeSSRDevServerBuilder(options, context)));
102
- }
103
- exports.default = require('@angular-devkit/architect').createBuilder(executeModuleFederationDevSSRBuilder);