@nx/angular 20.2.0-beta.2 → 20.2.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/migrations.json +33 -0
- package/module-federation/index.d.ts +5 -2
- package/module-federation/index.js +3 -4
- package/package.json +8 -9
- 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/host/files/js/webpack.server.config.js__tmpl__ +1 -1
- package/src/generators/host/files/ts/webpack.server.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/base/webpack.server.config.js__tmpl__ +1 -1
- package/src/generators/remote/files/base-ts/webpack.server.config.ts__tmpl__ +1 -1
- package/src/generators/scam-to-standalone/lib/replace-module-usages-with-component.js +3 -1
- package/src/generators/setup-mf/files/ts-webpack/module-federation.config.ts__tmpl__ +1 -1
- package/src/generators/setup-mf/files/ts-webpack/webpack.config.ts__tmpl__ +1 -1
- package/src/generators/setup-mf/files/ts-webpack/webpack.prod.config.ts__tmpl__ +1 -1
- package/src/generators/setup-mf/files/webpack/webpack.config.js__tmpl__ +1 -1
- package/src/generators/setup-mf/files/webpack/webpack.prod.config.js__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/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts +2 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +35 -0
- package/src/utils/versions.d.ts +2 -2
- package/src/utils/versions.js +2 -2
- package/src/utils/mf/utils.d.ts +0 -15
- package/src/utils/mf/utils.js +0 -101
- package/src/utils/mf/with-module-federation-ssr.d.ts +0 -2
- package/src/utils/mf/with-module-federation-ssr.js +0 -68
- package/src/utils/mf/with-module-federation.d.ts +0 -2
- package/src/utils/mf/with-module-federation.js +0 -70
package/migrations.json
CHANGED
|
@@ -266,6 +266,18 @@
|
|
|
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"
|
|
275
|
+
},
|
|
276
|
+
"update-20-2-0-update-with-module-federation-import": {
|
|
277
|
+
"cli": "nx",
|
|
278
|
+
"version": "20.2.0-beta.2",
|
|
279
|
+
"description": "Update the withModuleFederation import use @nx/module-federation/angular.",
|
|
280
|
+
"factory": "./src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package"
|
|
269
281
|
}
|
|
270
282
|
},
|
|
271
283
|
"packageJsonUpdates": {
|
|
@@ -1158,6 +1170,27 @@
|
|
|
1158
1170
|
"alwaysAddToPackageJson": false
|
|
1159
1171
|
}
|
|
1160
1172
|
}
|
|
1173
|
+
},
|
|
1174
|
+
"20.2.0": {
|
|
1175
|
+
"version": "20.2.0-beta.3",
|
|
1176
|
+
"packages": {
|
|
1177
|
+
"@module-federation/enhanced": {
|
|
1178
|
+
"version": "0.7.6",
|
|
1179
|
+
"alwaysAddToPackageJson": false
|
|
1180
|
+
},
|
|
1181
|
+
"@module-federation/runtime": {
|
|
1182
|
+
"version": "0.7.6",
|
|
1183
|
+
"alwaysAddToPackageJson": false
|
|
1184
|
+
},
|
|
1185
|
+
"@module-federation/sdk": {
|
|
1186
|
+
"version": "0.7.6",
|
|
1187
|
+
"alwaysAddToPackageJson": false
|
|
1188
|
+
},
|
|
1189
|
+
"@module-federation/node": {
|
|
1190
|
+
"version": "2.6.11",
|
|
1191
|
+
"alwaysAddToPackageJson": false
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1161
1194
|
}
|
|
1162
1195
|
}
|
|
1163
1196
|
}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { withModuleFederation, withModuleFederationForSSR } from '@nx/module-federation/angular';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Update the import path to `@nx/module-federation/angular` instead. This import path will be removed in Nx v22.
|
|
4
|
+
*/
|
|
5
|
+
export { withModuleFederation, withModuleFederationForSSR };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withModuleFederationForSSR = exports.withModuleFederation = void 0;
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "withModuleFederation", { enumerable: true, get: function () { return
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "withModuleFederationForSSR", { enumerable: true, get: function () { return with_module_federation_ssr_1.withModuleFederationForSSR; } });
|
|
4
|
+
const angular_1 = require("@nx/module-federation/angular");
|
|
5
|
+
Object.defineProperty(exports, "withModuleFederation", { enumerable: true, get: function () { return angular_1.withModuleFederation; } });
|
|
6
|
+
Object.defineProperty(exports, "withModuleFederationForSSR", { enumerable: true, get: function () { return angular_1.withModuleFederationForSSR; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/angular",
|
|
3
|
-
"version": "20.2.0-beta.
|
|
3
|
+
"version": "20.2.0-beta.3",
|
|
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": {
|
|
@@ -78,14 +78,13 @@
|
|
|
78
78
|
"semver": "^7.5.3",
|
|
79
79
|
"tslib": "^2.3.0",
|
|
80
80
|
"webpack-merge": "^5.8.0",
|
|
81
|
-
"
|
|
82
|
-
"@
|
|
83
|
-
"@nx/
|
|
84
|
-
"@nx/
|
|
85
|
-
"@nx/
|
|
86
|
-
"@nx/
|
|
87
|
-
"@nx/
|
|
88
|
-
"@nx/workspace": "20.2.0-beta.2",
|
|
81
|
+
"@nx/devkit": "20.2.0-beta.3",
|
|
82
|
+
"@nx/js": "20.2.0-beta.3",
|
|
83
|
+
"@nx/eslint": "20.2.0-beta.3",
|
|
84
|
+
"@nx/webpack": "20.2.0-beta.3",
|
|
85
|
+
"@nx/module-federation": "20.2.0-beta.3",
|
|
86
|
+
"@nx/web": "20.2.0-beta.3",
|
|
87
|
+
"@nx/workspace": "20.2.0-beta.3",
|
|
89
88
|
"piscina": "^4.4.0"
|
|
90
89
|
},
|
|
91
90
|
"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) => ({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { withModuleFederationForSSR } = require('@nx/
|
|
1
|
+
const { withModuleFederationForSSR } = require('@nx/module-federation/angular');
|
|
2
2
|
const config = require('./module-federation.config');
|
|
3
3
|
/**
|
|
4
4
|
* DTS Plugin is disabled in Nx Workspaces as Nx already provides Typing support for Module Federation
|
|
@@ -10,7 +10,9 @@ function replaceModuleUsagesWithComponent(tree, moduleName, componentName) {
|
|
|
10
10
|
}
|
|
11
11
|
const fileContents = tree.read(path, 'utf-8');
|
|
12
12
|
if (fileContents.includes(moduleName)) {
|
|
13
|
-
|
|
13
|
+
// Word boundary \b ensures that other modules won't be affected.
|
|
14
|
+
// E.g. "MapIconModule" would not be affected when "IconModule" is being migrated.
|
|
15
|
+
const moduleNameRegex = new RegExp(`\\b${moduleName}\\b`, 'g');
|
|
14
16
|
const newFileContents = fileContents.replace(moduleNameRegex, componentName);
|
|
15
17
|
tree.write(path, newFileContents);
|
|
16
18
|
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = migrateWithMfImport;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
6
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
7
|
+
const NX_ANGULAR_MODULE_FEDERATION_IMPORT_SELECTOR = 'ImportDeclaration > StringLiteral[value=@nx/angular/module-federation], VariableStatement CallExpression:has(Identifier[name=require]) > StringLiteral[value=@nx/angular/module-federation]';
|
|
8
|
+
const NEW_IMPORT_PATH = `'@nx/module-federation/angular'`;
|
|
9
|
+
async function migrateWithMfImport(tree) {
|
|
10
|
+
const projects = new Set();
|
|
11
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/angular:webpack-browser', (options, project, target) => {
|
|
12
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
13
|
+
projects.add(projectConfig.root);
|
|
14
|
+
});
|
|
15
|
+
for (const projectRoot of projects) {
|
|
16
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, projectRoot, (filePath) => {
|
|
17
|
+
if (!filePath.endsWith('.ts') && !filePath.endsWith('.js')) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
let contents = tree.read(filePath, 'utf-8');
|
|
21
|
+
if (!contents.includes('@nx/angular/module-federation')) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const ast = tsquery_1.tsquery.ast(contents);
|
|
25
|
+
const importNodes = (0, tsquery_1.tsquery)(ast, NX_ANGULAR_MODULE_FEDERATION_IMPORT_SELECTOR);
|
|
26
|
+
if (importNodes.length === 0) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const importPathNode = importNodes[0];
|
|
30
|
+
contents = `${contents.slice(0, importPathNode.getStart())}${NEW_IMPORT_PATH}${contents.slice(importPathNode.getEnd())}`;
|
|
31
|
+
tree.write(filePath, contents);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
35
|
+
}
|
package/src/utils/versions.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ export declare const typesCorsVersion = "~2.8.5";
|
|
|
12
12
|
export declare const expressVersion = "~4.18.2";
|
|
13
13
|
export declare const typesExpressVersion = "4.17.14";
|
|
14
14
|
export declare const browserSyncVersion = "^3.0.0";
|
|
15
|
-
export declare const moduleFederationNodeVersion = "~2.
|
|
16
|
-
export declare const moduleFederationEnhancedVersion = "0.6
|
|
15
|
+
export declare const moduleFederationNodeVersion = "~2.6.11";
|
|
16
|
+
export declare const moduleFederationEnhancedVersion = "0.7.6";
|
|
17
17
|
export declare const angularEslintVersion = "^18.3.0";
|
|
18
18
|
export declare const typescriptEslintVersion = "^7.16.0";
|
|
19
19
|
export declare const tailwindVersion = "^3.0.2";
|
package/src/utils/versions.js
CHANGED
|
@@ -15,8 +15,8 @@ exports.typesCorsVersion = '~2.8.5';
|
|
|
15
15
|
exports.expressVersion = '~4.18.2';
|
|
16
16
|
exports.typesExpressVersion = '4.17.14';
|
|
17
17
|
exports.browserSyncVersion = '^3.0.0';
|
|
18
|
-
exports.moduleFederationNodeVersion = '~2.
|
|
19
|
-
exports.moduleFederationEnhancedVersion = '0.6
|
|
18
|
+
exports.moduleFederationNodeVersion = '~2.6.11';
|
|
19
|
+
exports.moduleFederationEnhancedVersion = '0.7.6';
|
|
20
20
|
exports.angularEslintVersion = '^18.3.0';
|
|
21
21
|
exports.typescriptEslintVersion = '^7.16.0';
|
|
22
22
|
exports.tailwindVersion = '^3.0.2';
|
package/src/utils/mf/utils.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ModuleFederationConfig, SharedLibraryConfig } from '@nx/webpack/src/utils/module-federation';
|
|
2
|
-
export declare function applyDefaultEagerPackages(sharedConfig: Record<string, SharedLibraryConfig>): void;
|
|
3
|
-
export declare const DEFAULT_NPM_PACKAGES_TO_AVOID: string[];
|
|
4
|
-
export declare const DEFAULT_ANGULAR_PACKAGES_TO_SHARE: string[];
|
|
5
|
-
export declare function getFunctionDeterminateRemoteUrl(isServer?: boolean): (remote: string) => string;
|
|
6
|
-
export declare function getModuleFederationConfig(mfConfig: ModuleFederationConfig, options?: {
|
|
7
|
-
isServer: boolean;
|
|
8
|
-
determineRemoteUrl?: (remote: string) => string;
|
|
9
|
-
}): Promise<{
|
|
10
|
-
sharedLibraries: import("@nx/webpack/src/utils/module-federation").SharedWorkspaceLibraryConfig;
|
|
11
|
-
sharedDependencies: {
|
|
12
|
-
[x: string]: SharedLibraryConfig;
|
|
13
|
-
};
|
|
14
|
-
mappedRemotes: Record<string, string>;
|
|
15
|
-
}>;
|
package/src/utils/mf/utils.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_ANGULAR_PACKAGES_TO_SHARE = exports.DEFAULT_NPM_PACKAGES_TO_AVOID = void 0;
|
|
4
|
-
exports.applyDefaultEagerPackages = applyDefaultEagerPackages;
|
|
5
|
-
exports.getFunctionDeterminateRemoteUrl = getFunctionDeterminateRemoteUrl;
|
|
6
|
-
exports.getModuleFederationConfig = getModuleFederationConfig;
|
|
7
|
-
const module_federation_1 = require("@nx/webpack/src/utils/module-federation");
|
|
8
|
-
const devkit_1 = require("@nx/devkit");
|
|
9
|
-
const project_graph_1 = require("nx/src/project-graph/project-graph");
|
|
10
|
-
function applyDefaultEagerPackages(sharedConfig) {
|
|
11
|
-
const DEFAULT_PACKAGES_TO_LOAD_EAGERLY = [
|
|
12
|
-
'@angular/localize',
|
|
13
|
-
'@angular/localize/init',
|
|
14
|
-
];
|
|
15
|
-
for (const pkg of DEFAULT_PACKAGES_TO_LOAD_EAGERLY) {
|
|
16
|
-
if (!sharedConfig[pkg]) {
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
sharedConfig[pkg] = { ...sharedConfig[pkg], eager: true };
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.DEFAULT_NPM_PACKAGES_TO_AVOID = [
|
|
23
|
-
'zone.js',
|
|
24
|
-
'@nx/angular/mf',
|
|
25
|
-
'@nrwl/angular/mf',
|
|
26
|
-
];
|
|
27
|
-
exports.DEFAULT_ANGULAR_PACKAGES_TO_SHARE = [
|
|
28
|
-
'@angular/core',
|
|
29
|
-
'@angular/animations',
|
|
30
|
-
'@angular/common',
|
|
31
|
-
];
|
|
32
|
-
function getFunctionDeterminateRemoteUrl(isServer = false) {
|
|
33
|
-
const target = 'serve';
|
|
34
|
-
const remoteEntry = isServer ? 'server/remoteEntry.js' : 'remoteEntry.mjs';
|
|
35
|
-
return function (remote) {
|
|
36
|
-
const mappedStaticRemotesFromEnv = process.env
|
|
37
|
-
.NX_MF_DEV_SERVER_STATIC_REMOTES
|
|
38
|
-
? JSON.parse(process.env.NX_MF_DEV_SERVER_STATIC_REMOTES)
|
|
39
|
-
: undefined;
|
|
40
|
-
if (mappedStaticRemotesFromEnv && mappedStaticRemotesFromEnv[remote]) {
|
|
41
|
-
return `${mappedStaticRemotesFromEnv[remote]}/${remoteEntry}`;
|
|
42
|
-
}
|
|
43
|
-
let remoteConfiguration = null;
|
|
44
|
-
try {
|
|
45
|
-
remoteConfiguration = (0, project_graph_1.readCachedProjectConfiguration)(remote);
|
|
46
|
-
}
|
|
47
|
-
catch (e) {
|
|
48
|
-
throw new Error(`Cannot find remote "${remote}". Check that the remote name is correct in your module federation config file.\n`);
|
|
49
|
-
}
|
|
50
|
-
const serveTarget = remoteConfiguration?.targets?.[target];
|
|
51
|
-
if (!serveTarget) {
|
|
52
|
-
throw new Error(`Cannot automatically determine URL of remote (${remote}). Looked for property "host" in the project's "serve" target.\n
|
|
53
|
-
You can also use the tuple syntax in your webpack config to configure your remotes. e.g. \`remotes: [['remote1', 'http://localhost:4201']]\``);
|
|
54
|
-
}
|
|
55
|
-
const host = serveTarget.options?.host ??
|
|
56
|
-
`http${serveTarget.options.ssl ? 's' : ''}://localhost`;
|
|
57
|
-
const port = serveTarget.options?.port ?? 4201;
|
|
58
|
-
return `${host.endsWith('/') ? host.slice(0, -1) : host}:${port}/${remoteEntry}`;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
async function getModuleFederationConfig(mfConfig, options = { isServer: false }) {
|
|
62
|
-
let projectGraph;
|
|
63
|
-
try {
|
|
64
|
-
projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
65
|
-
}
|
|
66
|
-
catch (e) {
|
|
67
|
-
projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
68
|
-
}
|
|
69
|
-
if (!projectGraph.nodes[mfConfig.name]?.data) {
|
|
70
|
-
throw Error(`Cannot find project "${mfConfig.name}". Check that the name is correct in module-federation.config.js`);
|
|
71
|
-
}
|
|
72
|
-
const dependencies = (0, module_federation_1.getDependentPackagesForProject)(projectGraph, mfConfig.name);
|
|
73
|
-
if (mfConfig.shared) {
|
|
74
|
-
dependencies.workspaceLibraries = dependencies.workspaceLibraries.filter((lib) => mfConfig.shared(lib.importKey, {}) !== false);
|
|
75
|
-
dependencies.npmPackages = dependencies.npmPackages.filter((pkg) => mfConfig.shared(pkg, {}) !== false);
|
|
76
|
-
}
|
|
77
|
-
const sharedLibraries = (0, module_federation_1.shareWorkspaceLibraries)(dependencies.workspaceLibraries);
|
|
78
|
-
const npmPackages = (0, module_federation_1.sharePackages)(Array.from(new Set([
|
|
79
|
-
...exports.DEFAULT_ANGULAR_PACKAGES_TO_SHARE,
|
|
80
|
-
...dependencies.npmPackages.filter((pkg) => !exports.DEFAULT_NPM_PACKAGES_TO_AVOID.includes(pkg)),
|
|
81
|
-
])));
|
|
82
|
-
exports.DEFAULT_NPM_PACKAGES_TO_AVOID.forEach((pkgName) => {
|
|
83
|
-
if (pkgName in npmPackages) {
|
|
84
|
-
delete npmPackages[pkgName];
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
const sharedDependencies = {
|
|
88
|
-
...sharedLibraries.getLibraries(projectGraph.nodes[mfConfig.name].data.root),
|
|
89
|
-
...npmPackages,
|
|
90
|
-
};
|
|
91
|
-
applyDefaultEagerPackages(sharedDependencies);
|
|
92
|
-
(0, module_federation_1.applySharedFunction)(sharedDependencies, mfConfig.shared);
|
|
93
|
-
(0, module_federation_1.applyAdditionalShared)(sharedDependencies, mfConfig.additionalShared, projectGraph);
|
|
94
|
-
const determineRemoteUrlFn = options.determineRemoteUrl ||
|
|
95
|
-
getFunctionDeterminateRemoteUrl(options.isServer);
|
|
96
|
-
const mapRemotesFunction = options.isServer ? module_federation_1.mapRemotesForSSR : module_federation_1.mapRemotes;
|
|
97
|
-
const mappedRemotes = !mfConfig.remotes || mfConfig.remotes.length === 0
|
|
98
|
-
? {}
|
|
99
|
-
: mapRemotesFunction(mfConfig.remotes, 'mjs', determineRemoteUrlFn);
|
|
100
|
-
return { sharedLibraries, sharedDependencies, mappedRemotes };
|
|
101
|
-
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import type { ModuleFederationConfig, NxModuleFederationConfigOverride } from '@nx/webpack/src/utils/module-federation';
|
|
2
|
-
export declare function withModuleFederationForSSR(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: any) => any>;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withModuleFederationForSSR = withModuleFederationForSSR;
|
|
4
|
-
const utils_1 = require("./utils");
|
|
5
|
-
async function withModuleFederationForSSR(options, configOverride) {
|
|
6
|
-
if (global.NX_GRAPH_CREATION) {
|
|
7
|
-
return (config) => config;
|
|
8
|
-
}
|
|
9
|
-
const { sharedLibraries, sharedDependencies, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options, {
|
|
10
|
-
isServer: true,
|
|
11
|
-
});
|
|
12
|
-
return (config) => {
|
|
13
|
-
const updatedConfig = {
|
|
14
|
-
...(config ?? {}),
|
|
15
|
-
target: 'async-node',
|
|
16
|
-
output: {
|
|
17
|
-
...(config.output ?? {}),
|
|
18
|
-
uniqueName: options.name,
|
|
19
|
-
},
|
|
20
|
-
optimization: {
|
|
21
|
-
...(config.optimization ?? {}),
|
|
22
|
-
runtimeChunk: false,
|
|
23
|
-
},
|
|
24
|
-
resolve: {
|
|
25
|
-
...(config.resolve ?? {}),
|
|
26
|
-
alias: {
|
|
27
|
-
...(config.resolve?.alias ?? {}),
|
|
28
|
-
...sharedLibraries.getAliases(),
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
plugins: [
|
|
32
|
-
...(config.plugins ?? []),
|
|
33
|
-
new (require('@module-federation/enhanced').ModuleFederationPlugin)({
|
|
34
|
-
name: options.name.replace(/-/g, '_'),
|
|
35
|
-
filename: 'remoteEntry.js',
|
|
36
|
-
exposes: options.exposes,
|
|
37
|
-
remotes: mappedRemotes,
|
|
38
|
-
shared: {
|
|
39
|
-
...sharedDependencies,
|
|
40
|
-
},
|
|
41
|
-
/**
|
|
42
|
-
* Apply user-defined config override
|
|
43
|
-
*/
|
|
44
|
-
...(configOverride ? configOverride : {}),
|
|
45
|
-
runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
|
|
46
|
-
!options.disableNxRuntimeLibraryControlPlugin
|
|
47
|
-
? [
|
|
48
|
-
...(configOverride?.runtimePlugins ?? []),
|
|
49
|
-
require.resolve('@module-federation/node/runtimePlugin'),
|
|
50
|
-
require.resolve('@nx/webpack/src/utils/module-federation/plugins/runtime-library-control.plugin.js'),
|
|
51
|
-
]
|
|
52
|
-
: [
|
|
53
|
-
...(configOverride?.runtimePlugins ?? []),
|
|
54
|
-
require.resolve('@module-federation/node/runtimePlugin'),
|
|
55
|
-
],
|
|
56
|
-
virtualRuntimeEntry: true,
|
|
57
|
-
}, {}),
|
|
58
|
-
sharedLibraries.getReplacementPlugin(),
|
|
59
|
-
],
|
|
60
|
-
};
|
|
61
|
-
// The env var is only set from the module-federation-dev-server
|
|
62
|
-
// Attach the runtime plugin
|
|
63
|
-
updatedConfig.plugins.push(new (require('webpack').DefinePlugin)({
|
|
64
|
-
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
|
|
65
|
-
}));
|
|
66
|
-
return updatedConfig;
|
|
67
|
-
};
|
|
68
|
-
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import type { ModuleFederationConfig, NxModuleFederationConfigOverride } from '@nx/webpack/src/utils/module-federation';
|
|
2
|
-
export declare function withModuleFederation(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: any) => any>;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withModuleFederation = withModuleFederation;
|
|
4
|
-
const utils_1 = require("./utils");
|
|
5
|
-
const webpack_1 = require("@module-federation/enhanced/webpack");
|
|
6
|
-
async function withModuleFederation(options, configOverride) {
|
|
7
|
-
if (global.NX_GRAPH_CREATION) {
|
|
8
|
-
return (config) => config;
|
|
9
|
-
}
|
|
10
|
-
const { sharedLibraries, sharedDependencies, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options);
|
|
11
|
-
return (config) => {
|
|
12
|
-
const updatedConfig = {
|
|
13
|
-
...(config ?? {}),
|
|
14
|
-
output: {
|
|
15
|
-
...(config.output ?? {}),
|
|
16
|
-
uniqueName: options.name,
|
|
17
|
-
publicPath: 'auto',
|
|
18
|
-
},
|
|
19
|
-
optimization: {
|
|
20
|
-
...(config.optimization ?? {}),
|
|
21
|
-
runtimeChunk: false,
|
|
22
|
-
},
|
|
23
|
-
resolve: {
|
|
24
|
-
...(config.resolve ?? {}),
|
|
25
|
-
alias: {
|
|
26
|
-
...(config.resolve?.alias ?? {}),
|
|
27
|
-
...sharedLibraries.getAliases(),
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
experiments: {
|
|
31
|
-
...(config.experiments ?? {}),
|
|
32
|
-
outputModule: true,
|
|
33
|
-
},
|
|
34
|
-
plugins: [
|
|
35
|
-
...(config.plugins ?? []),
|
|
36
|
-
new webpack_1.ModuleFederationPlugin({
|
|
37
|
-
name: options.name.replace(/-/g, '_'),
|
|
38
|
-
filename: 'remoteEntry.mjs',
|
|
39
|
-
exposes: options.exposes,
|
|
40
|
-
remotes: mappedRemotes,
|
|
41
|
-
shared: {
|
|
42
|
-
...sharedDependencies,
|
|
43
|
-
},
|
|
44
|
-
library: {
|
|
45
|
-
type: 'module',
|
|
46
|
-
},
|
|
47
|
-
/**
|
|
48
|
-
* Apply user-defined config override
|
|
49
|
-
*/
|
|
50
|
-
...(configOverride ? configOverride : {}),
|
|
51
|
-
runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
|
|
52
|
-
!options.disableNxRuntimeLibraryControlPlugin
|
|
53
|
-
? [
|
|
54
|
-
...(configOverride?.runtimePlugins ?? []),
|
|
55
|
-
require.resolve('@nx/webpack/src/utils/module-federation/plugins/runtime-library-control.plugin.js'),
|
|
56
|
-
]
|
|
57
|
-
: configOverride?.runtimePlugins,
|
|
58
|
-
virtualRuntimeEntry: true,
|
|
59
|
-
}),
|
|
60
|
-
sharedLibraries.getReplacementPlugin(),
|
|
61
|
-
],
|
|
62
|
-
};
|
|
63
|
-
// The env var is only set from the module-federation-dev-server
|
|
64
|
-
// Attach the runtime plugin
|
|
65
|
-
updatedConfig.plugins.push(new (require('webpack').DefinePlugin)({
|
|
66
|
-
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
|
|
67
|
-
}));
|
|
68
|
-
return updatedConfig;
|
|
69
|
-
};
|
|
70
|
-
}
|