@nx/angular 20.2.0-canary.20241116-8efad63 → 20.2.0-canary.20241120-09a01eb
Sign up to get free protection for your applications and to get access to all the features.
- package/migrations.json +6 -0
- package/package.json +8 -7
- package/src/executors/module-federation-dev-server/lib/build-static-remotes.d.ts +1 -1
- package/src/executors/module-federation-dev-server/lib/start-static-remotes-file-server.d.ts +1 -1
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +8 -10
- package/src/executors/module-federation-ssr-dev-server/lib/build-static-remotes.d.ts +1 -1
- package/src/executors/module-federation-ssr-dev-server/lib/start-static-remotes.d.ts +1 -1
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +5 -7
- package/src/generators/setup-mf/files/ts-webpack/module-federation.config.ts__tmpl__ +1 -1
- package/src/migrations/update-20-2-0/migrate-mf-imports-to-new-package.d.ts +2 -0
- package/src/migrations/update-20-2-0/migrate-mf-imports-to-new-package.js +58 -0
- package/src/utils/mf/utils.d.ts +2 -2
- package/src/utils/mf/utils.js +1 -1
- package/src/utils/mf/with-module-federation-ssr.d.ts +1 -1
- package/src/utils/mf/with-module-federation-ssr.js +1 -1
- package/src/utils/mf/with-module-federation.d.ts +1 -1
- package/src/utils/mf/with-module-federation.js +1 -1
package/migrations.json
CHANGED
@@ -266,6 +266,12 @@
|
|
266
266
|
"version": "19.6.1-beta.0",
|
267
267
|
"description": "Ensure Target Defaults are set correctly for Module Federation.",
|
268
268
|
"factory": "./src/migrations/update-19-6-1/ensure-depends-on-for-mf"
|
269
|
+
},
|
270
|
+
"update-20-2-0-update-module-federation-config-import": {
|
271
|
+
"cli": "nx",
|
272
|
+
"version": "20.2.0-beta.2",
|
273
|
+
"description": "Update the ModuleFederationConfig import use @nx/module-federation.",
|
274
|
+
"factory": "./src/migrations/update-20-2-0/migrate-mf-imports-to-new-package"
|
269
275
|
}
|
270
276
|
},
|
271
277
|
"packageJsonUpdates": {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/angular",
|
3
|
-
"version": "20.2.0-canary.
|
3
|
+
"version": "20.2.0-canary.20241120-09a01eb",
|
4
4
|
"private": false,
|
5
5
|
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Playwright and Cypress. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
6
6
|
"repository": {
|
@@ -80,12 +80,13 @@
|
|
80
80
|
"webpack-merge": "^5.8.0",
|
81
81
|
"webpack": "^5.88.0",
|
82
82
|
"@module-federation/enhanced": "0.6.9",
|
83
|
-
"@nx/devkit": "20.2.0-canary.
|
84
|
-
"@nx/js": "20.2.0-canary.
|
85
|
-
"@nx/eslint": "20.2.0-canary.
|
86
|
-
"@nx/webpack": "20.2.0-canary.
|
87
|
-
"@nx/
|
88
|
-
"@nx/
|
83
|
+
"@nx/devkit": "20.2.0-canary.20241120-09a01eb",
|
84
|
+
"@nx/js": "20.2.0-canary.20241120-09a01eb",
|
85
|
+
"@nx/eslint": "20.2.0-canary.20241120-09a01eb",
|
86
|
+
"@nx/webpack": "20.2.0-canary.20241120-09a01eb",
|
87
|
+
"@nx/module-federation": "20.2.0-canary.20241120-09a01eb",
|
88
|
+
"@nx/web": "20.2.0-canary.20241120-09a01eb",
|
89
|
+
"@nx/workspace": "20.2.0-canary.20241120-09a01eb",
|
89
90
|
"piscina": "^4.4.0"
|
90
91
|
},
|
91
92
|
"peerDependencies": {
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { type Schema } from '../schema';
|
2
2
|
import { type ExecutorContext } from '@nx/devkit';
|
3
|
-
import type { StaticRemotesConfig } from '@nx/
|
3
|
+
import type { StaticRemotesConfig } from '@nx/module-federation/src/utils';
|
4
4
|
export declare function buildStaticRemotes(staticRemotesConfig: StaticRemotesConfig, nxBin: any, context: ExecutorContext, options: Schema): Promise<Record<string, string>>;
|
package/src/executors/module-federation-dev-server/lib/start-static-remotes-file-server.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { type ExecutorContext } from '@nx/devkit';
|
2
2
|
import { type Schema } from '../schema';
|
3
|
-
import type { StaticRemotesConfig } from '@nx/
|
3
|
+
import type { StaticRemotesConfig } from '@nx/module-federation/src/utils';
|
4
4
|
export declare function startStaticRemotesFileServer(staticRemotesConfig: StaticRemotesConfig, context: ExecutorContext, options: Schema): AsyncGenerator<{
|
5
5
|
success: boolean;
|
6
6
|
baseUrl: string;
|
@@ -6,16 +6,14 @@ const devkit_1 = require("@nx/devkit");
|
|
6
6
|
const lib_1 = require("./lib");
|
7
7
|
const rxjs_for_await_1 = require("@nx/devkit/src/utils/rxjs-for-await");
|
8
8
|
const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
|
9
|
-
const
|
9
|
+
const utils_1 = require("@nx/module-federation/src/utils");
|
10
10
|
const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
|
11
11
|
const file_server_impl_1 = tslib_1.__importDefault(require("@nx/web/src/executors/file-server/file-server.impl"));
|
12
12
|
const ngcli_adapter_1 = require("nx/src/adapter/ngcli-adapter");
|
13
13
|
const dev_server_impl_1 = require("../../builders/dev-server/dev-server.impl");
|
14
|
-
const
|
14
|
+
const module_federation_1 = require("../../builders/utilities/module-federation");
|
15
15
|
const path_1 = require("path");
|
16
16
|
const fs_1 = require("fs");
|
17
|
-
const start_remote_proxies_1 = require("@nx/webpack/src/utils/module-federation/start-remote-proxies");
|
18
|
-
const parse_static_remotes_config_1 = require("@nx/webpack/src/utils/module-federation/parse-static-remotes-config");
|
19
17
|
async function* moduleFederationDevServerExecutor(schema, context) {
|
20
18
|
// Force Node to resolve to look for the nx binary that is inside node_modules
|
21
19
|
const nxBin = require.resolve('nx/bin/nx');
|
@@ -44,7 +42,7 @@ async function* moduleFederationDevServerExecutor(schema, context) {
|
|
44
42
|
}
|
45
43
|
let pathToManifestFile;
|
46
44
|
if (!options.pathToManifestFile) {
|
47
|
-
pathToManifestFile = (0,
|
45
|
+
pathToManifestFile = (0, module_federation_1.getDynamicMfManifestFile)(project, context.root);
|
48
46
|
}
|
49
47
|
else {
|
50
48
|
const userPathToManifestFile = (0, path_1.join)(context.root, options.pathToManifestFile);
|
@@ -56,10 +54,10 @@ async function* moduleFederationDevServerExecutor(schema, context) {
|
|
56
54
|
}
|
57
55
|
pathToManifestFile = userPathToManifestFile;
|
58
56
|
}
|
59
|
-
(0,
|
60
|
-
const moduleFederationConfig = (0,
|
57
|
+
(0, module_federation_1.validateDevRemotes)(options, workspaceProjects);
|
58
|
+
const moduleFederationConfig = (0, utils_1.getModuleFederationConfig)(project.targets.build.options.tsConfig, context.root, project.root, 'angular');
|
61
59
|
const remoteNames = options.devRemotes.map((r) => typeof r === 'string' ? r : r.remoteName);
|
62
|
-
const remotes = (0,
|
60
|
+
const remotes = (0, utils_1.getRemotes)(remoteNames, options.skipRemotes, moduleFederationConfig, {
|
63
61
|
projectName: project.name,
|
64
62
|
projectGraph: context.projectGraph,
|
65
63
|
root: context.root,
|
@@ -70,11 +68,11 @@ async function* moduleFederationDevServerExecutor(schema, context) {
|
|
70
68
|
...(remotes.devRemotes.map((r) => typeof r === 'string' ? r : r.remoteName) ?? []).map((r) => r.replace(/-/g, '_')),
|
71
69
|
project.name.replace(/-/g, '_'),
|
72
70
|
]);
|
73
|
-
const staticRemotesConfig = (0,
|
71
|
+
const staticRemotesConfig = (0, utils_1.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
|
74
72
|
const mappedLocationsOfStaticRemotes = await (0, lib_1.buildStaticRemotes)(staticRemotesConfig, nxBin, context, options);
|
75
73
|
const devRemoteIters = await (0, lib_1.startRemotes)(remotes.devRemotes, workspaceProjects, options, context, 'serve');
|
76
74
|
const staticRemotesIter = (0, lib_1.startStaticRemotesFileServer)(staticRemotesConfig, context, options);
|
77
|
-
(0,
|
75
|
+
(0, utils_1.startRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
|
78
76
|
? {
|
79
77
|
pathToCert: options.sslCert,
|
80
78
|
pathToKey: options.sslKey,
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import type { Schema } from '../schema';
|
2
2
|
import { type ExecutorContext } from '@nx/devkit';
|
3
|
-
import type { StaticRemotesConfig } from '@nx/
|
3
|
+
import type { StaticRemotesConfig } from '@nx/module-federation/src/utils';
|
4
4
|
export declare function buildStaticRemotes(staticRemotesConfig: StaticRemotesConfig, nxBin: any, context: ExecutorContext, options: Schema): Promise<Record<string, string>>;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { type ExecutorContext } from '@nx/devkit';
|
2
2
|
import { type Schema } from '../schema';
|
3
|
-
import type { StaticRemotesConfig } from '@nx/
|
3
|
+
import type { StaticRemotesConfig } from '@nx/module-federation/src/utils';
|
4
4
|
export declare function startStaticRemotes(ssrStaticRemotesConfig: StaticRemotesConfig, context: ExecutorContext, options: Schema): AsyncIterable<unknown>;
|
package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js
CHANGED
@@ -6,8 +6,7 @@ const fs_1 = require("fs");
|
|
6
6
|
const project_graph_1 = require("nx/src/project-graph/project-graph");
|
7
7
|
const path_1 = require("path");
|
8
8
|
const module_federation_1 = require("../../builders/utilities/module-federation");
|
9
|
-
const
|
10
|
-
const parse_static_remotes_config_1 = require("@nx/webpack/src/utils/module-federation/parse-static-remotes-config");
|
9
|
+
const utils_1 = require("@nx/module-federation/src/utils");
|
11
10
|
const build_static_remotes_1 = require("./lib/build-static-remotes");
|
12
11
|
const start_dev_remotes_1 = require("./lib/start-dev-remotes");
|
13
12
|
const start_static_remotes_1 = require("./lib/start-static-remotes");
|
@@ -16,7 +15,6 @@ const rxjs_for_await_1 = require("@nx/devkit/src/utils/rxjs-for-await");
|
|
16
15
|
const ngcli_adapter_1 = require("nx/src/adapter/ngcli-adapter");
|
17
16
|
const normalize_options_1 = require("./lib/normalize-options");
|
18
17
|
const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
|
19
|
-
const start_ssr_remote_proxies_1 = require("@nx/webpack/src/utils/module-federation/start-ssr-remote-proxies");
|
20
18
|
const angular_version_utils_1 = require("../utilities/angular-version-utils");
|
21
19
|
async function* moduleFederationSsrDevServerExecutor(schema, context) {
|
22
20
|
const nxBin = require.resolve('nx/bin/nx');
|
@@ -50,15 +48,15 @@ async function* moduleFederationSsrDevServerExecutor(schema, context) {
|
|
50
48
|
pathToManifestFile = (0, module_federation_1.getDynamicMfManifestFile)(project, context.root);
|
51
49
|
}
|
52
50
|
(0, module_federation_1.validateDevRemotes)({ devRemotes: options.devRemotes }, workspaceProjects);
|
53
|
-
const moduleFederationConfig = (0,
|
51
|
+
const moduleFederationConfig = (0, utils_1.getModuleFederationConfig)(project.targets.build.options.tsConfig, context.root, project.root, 'angular');
|
54
52
|
const remoteNames = options.devRemotes.map((r) => typeof r === 'string' ? r : r.remoteName);
|
55
|
-
const remotes = (0,
|
53
|
+
const remotes = (0, utils_1.getRemotes)(remoteNames, options.skipRemotes, moduleFederationConfig, {
|
56
54
|
projectName: project.name,
|
57
55
|
projectGraph: context.projectGraph,
|
58
56
|
root: context.root,
|
59
57
|
}, pathToManifestFile);
|
60
58
|
options.staticRemotesPort ??= remotes.staticRemotePort;
|
61
|
-
const staticRemotesConfig = (0,
|
59
|
+
const staticRemotesConfig = (0, utils_1.parseStaticSsrRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
|
62
60
|
const mappedLocationsOfStaticRemotes = await (0, build_static_remotes_1.buildStaticRemotes)(staticRemotesConfig, nxBin, context, options);
|
63
61
|
// Set NX_MF_DEV_REMOTES for the Nx Runtime Library Control Plugin
|
64
62
|
process.env.NX_MF_DEV_REMOTES = JSON.stringify([
|
@@ -67,7 +65,7 @@ async function* moduleFederationSsrDevServerExecutor(schema, context) {
|
|
67
65
|
]);
|
68
66
|
const devRemotes = await (0, start_dev_remotes_1.startRemotes)(remotes.devRemotes, workspaceProjects, options, context);
|
69
67
|
const staticRemotes = (0, start_static_remotes_1.startStaticRemotes)(staticRemotesConfig, context, options);
|
70
|
-
(0,
|
68
|
+
(0, utils_1.startSsrRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
|
71
69
|
? { pathToCert: options.sslCert, pathToKey: options.sslKey }
|
72
70
|
: undefined);
|
73
71
|
const removeBaseUrlEmission = (iter) => (0, async_iterable_1.mapAsyncIterable)(iter, (v) => ({
|
@@ -0,0 +1,58 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.default = migrateMfImportsToNewPackage;
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
5
|
+
const devkit_2 = require("@nx/devkit");
|
6
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
7
|
+
const MF_IMPORT_TO_UPDATE = 'ModuleFederationConfig';
|
8
|
+
const MF_CONFIG_IMPORT_SELECTOR = `ImportDeclaration:has(StringLiteral[value=@nx/webpack]):has(Identifier[name=ModuleFederationConfig])`;
|
9
|
+
const IMPORT_TOKENS_SELECTOR = `ImportClause ImportSpecifier`;
|
10
|
+
const MF_CONFIG_IMPORT_SPECIFIER_SELECTOR = `ImportClause ImportSpecifier > Identifier[name=ModuleFederationConfig]`;
|
11
|
+
const WEBPACK_IMPORT_SELECTOR = `ImportDeclaration > StringLiteral[value=@nx/webpack]`;
|
12
|
+
async function migrateMfImportsToNewPackage(tree) {
|
13
|
+
const rootsToCheck = new Set();
|
14
|
+
const graph = await (0, devkit_1.createProjectGraphAsync)();
|
15
|
+
for (const [project, dependencies] of Object.entries(graph.dependencies)) {
|
16
|
+
const usesNxWebpack = dependencies.some((dep) => dep.target === 'npm:@nx/webpack');
|
17
|
+
if (usesNxWebpack) {
|
18
|
+
const root = graph.nodes[project].data.root;
|
19
|
+
rootsToCheck.add(root);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
for (const root of rootsToCheck) {
|
23
|
+
(0, devkit_2.visitNotIgnoredFiles)(tree, root, (filePath) => {
|
24
|
+
if (!filePath.endsWith('.ts') && !filePath.endsWith('.js')) {
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
let contents = tree.read(filePath, 'utf-8');
|
28
|
+
if (!contents.includes(MF_IMPORT_TO_UPDATE)) {
|
29
|
+
return;
|
30
|
+
}
|
31
|
+
const ast = tsquery_1.tsquery.ast(contents);
|
32
|
+
const importNodes = (0, tsquery_1.tsquery)(ast, MF_CONFIG_IMPORT_SELECTOR);
|
33
|
+
if (importNodes.length === 0) {
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
const importNode = importNodes[0];
|
37
|
+
const importSpecifiers = (0, tsquery_1.tsquery)(importNode, IMPORT_TOKENS_SELECTOR);
|
38
|
+
if (importSpecifiers.length > 1) {
|
39
|
+
const mfConfigImportSpecifierNode = (0, tsquery_1.tsquery)(importNode, MF_CONFIG_IMPORT_SPECIFIER_SELECTOR)[0];
|
40
|
+
const end = contents.charAt(mfConfigImportSpecifierNode.getEnd()) === ','
|
41
|
+
? mfConfigImportSpecifierNode.getEnd() + 1
|
42
|
+
: mfConfigImportSpecifierNode.getEnd();
|
43
|
+
contents = `import { ${MF_IMPORT_TO_UPDATE} } from '@nx/module-federation';
|
44
|
+
${contents.slice(0, mfConfigImportSpecifierNode.getStart())}${contents.slice(end)}`;
|
45
|
+
}
|
46
|
+
else {
|
47
|
+
const nxWebpackImportStringNodes = (0, tsquery_1.tsquery)(ast, WEBPACK_IMPORT_SELECTOR);
|
48
|
+
if (nxWebpackImportStringNodes.length === 0) {
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
const nxWebpackImportStringNode = nxWebpackImportStringNodes[0];
|
52
|
+
contents = `${contents.slice(0, nxWebpackImportStringNode.getStart())}'@nx/module-federation'${contents.slice(nxWebpackImportStringNode.getEnd())}`;
|
53
|
+
}
|
54
|
+
tree.write(filePath, contents);
|
55
|
+
});
|
56
|
+
}
|
57
|
+
await (0, devkit_2.formatFiles)(tree);
|
58
|
+
}
|
package/src/utils/mf/utils.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ModuleFederationConfig, SharedLibraryConfig } from '@nx/
|
1
|
+
import { ModuleFederationConfig, SharedLibraryConfig } from '@nx/module-federation';
|
2
2
|
export declare function applyDefaultEagerPackages(sharedConfig: Record<string, SharedLibraryConfig>): void;
|
3
3
|
export declare const DEFAULT_NPM_PACKAGES_TO_AVOID: string[];
|
4
4
|
export declare const DEFAULT_ANGULAR_PACKAGES_TO_SHARE: string[];
|
@@ -7,7 +7,7 @@ export declare function getModuleFederationConfig(mfConfig: ModuleFederationConf
|
|
7
7
|
isServer: boolean;
|
8
8
|
determineRemoteUrl?: (remote: string) => string;
|
9
9
|
}): Promise<{
|
10
|
-
sharedLibraries: import("@nx/
|
10
|
+
sharedLibraries: import("@nx/module-federation").SharedWorkspaceLibraryConfig;
|
11
11
|
sharedDependencies: {
|
12
12
|
[x: string]: SharedLibraryConfig;
|
13
13
|
};
|
package/src/utils/mf/utils.js
CHANGED
@@ -4,7 +4,7 @@ exports.DEFAULT_ANGULAR_PACKAGES_TO_SHARE = exports.DEFAULT_NPM_PACKAGES_TO_AVOI
|
|
4
4
|
exports.applyDefaultEagerPackages = applyDefaultEagerPackages;
|
5
5
|
exports.getFunctionDeterminateRemoteUrl = getFunctionDeterminateRemoteUrl;
|
6
6
|
exports.getModuleFederationConfig = getModuleFederationConfig;
|
7
|
-
const module_federation_1 = require("@nx/
|
7
|
+
const module_federation_1 = require("@nx/module-federation");
|
8
8
|
const devkit_1 = require("@nx/devkit");
|
9
9
|
const project_graph_1 = require("nx/src/project-graph/project-graph");
|
10
10
|
function applyDefaultEagerPackages(sharedConfig) {
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import type { ModuleFederationConfig, NxModuleFederationConfigOverride } from '@nx/
|
1
|
+
import type { ModuleFederationConfig, NxModuleFederationConfigOverride } from '@nx/module-federation';
|
2
2
|
export declare function withModuleFederationForSSR(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: any) => any>;
|
@@ -47,7 +47,7 @@ async function withModuleFederationForSSR(options, configOverride) {
|
|
47
47
|
? [
|
48
48
|
...(configOverride?.runtimePlugins ?? []),
|
49
49
|
require.resolve('@module-federation/node/runtimePlugin'),
|
50
|
-
require.resolve('@nx/
|
50
|
+
require.resolve('@nx/module-federation/src/utils/plugins/runtime-library-control.plugin.js'),
|
51
51
|
]
|
52
52
|
: [
|
53
53
|
...(configOverride?.runtimePlugins ?? []),
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import type { ModuleFederationConfig, NxModuleFederationConfigOverride } from '@nx/
|
1
|
+
import type { ModuleFederationConfig, NxModuleFederationConfigOverride } from '@nx/module-federation';
|
2
2
|
export declare function withModuleFederation(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: any) => any>;
|
@@ -52,7 +52,7 @@ async function withModuleFederation(options, configOverride) {
|
|
52
52
|
!options.disableNxRuntimeLibraryControlPlugin
|
53
53
|
? [
|
54
54
|
...(configOverride?.runtimePlugins ?? []),
|
55
|
-
require.resolve('@nx/
|
55
|
+
require.resolve('@nx/module-federation/src/utils/plugins/runtime-library-control.plugin.js'),
|
56
56
|
]
|
57
57
|
: configOverride?.runtimePlugins,
|
58
58
|
virtualRuntimeEntry: true,
|