@nx/react 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.d.ts +6 -4
- package/module-federation.js +16 -7
- package/package.json +6 -6
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +5 -7
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +5 -7
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +1 -1
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +4 -5
- package/src/generators/application/application.js +9 -18
- package/src/generators/application/files/base-rspack/rspack.config.js__tmpl__ +53 -0
- package/src/generators/application/lib/add-e2e.js +2 -0
- package/src/generators/application/lib/add-project.js +66 -0
- package/src/generators/application/lib/create-application-files.js +28 -1
- package/src/generators/host/files/rspack-module-federation/rspack.config.js__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation/rspack.config.prod.js__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ts/rspack.config.prod.ts__tmpl__ +2 -1
- package/src/generators/host/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +2 -1
- package/src/generators/host/files/webpack-module-federation/webpack.config.js__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation/webpack.config.prod.js__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation-ssr/module-federation.server.config.js__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation-ts/webpack.config.prod.ts__tmpl__ +2 -2
- package/src/generators/host/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +3 -2
- package/src/generators/remote/files/rspack-module-federation/rspack.config.js__tmpl__ +1 -1
- package/src/generators/remote/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +1 -1
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation/webpack.config.js__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation-ts/webpack.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 +63 -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/rules/update-module-federation-project.js +6 -4
- package/src/utils/has-rspack-plugin.d.ts +2 -0
- package/src/utils/has-rspack-plugin.js +10 -0
- package/src/utils/versions.d.ts +2 -2
- package/src/utils/versions.js +2 -2
- package/src/generators/application/lib/add-project-root-to-rspack-plugin-excludes.d.ts +0 -2
- package/src/generators/application/lib/add-project-root-to-rspack-plugin-excludes.js +0 -31
- package/src/module-federation/load-config.d.ts +0 -3
- package/src/module-federation/load-config.js +0 -15
- package/src/module-federation/models.d.ts +0 -24
- package/src/module-federation/models.js +0 -2
- package/src/module-federation/package-json.d.ts +0 -8
- package/src/module-federation/package-json.js +0 -12
- package/src/module-federation/utils.d.ts +0 -12
- package/src/module-federation/utils.js +0 -75
- package/src/module-federation/with-module-federation-ssr.d.ts +0 -2
- package/src/module-federation/with-module-federation-ssr.js +0 -50
- package/src/module-federation/with-module-federation.d.ts +0 -7
- package/src/module-federation/with-module-federation.js +0 -63
package/src/generators/host/files/webpack-module-federation-ts/webpack.config.prod.ts__tmpl__
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { composePlugins, withNx } from '@nx/webpack';
|
2
2
|
import { withReact } from '@nx/react';
|
3
|
-
import { withModuleFederation } from '@nx/
|
4
|
-
import { ModuleFederationConfig } from '@nx/
|
3
|
+
import { withModuleFederation } from '@nx/module-federation/webpack';
|
4
|
+
import { ModuleFederationConfig } from '@nx/module-federation';
|
5
5
|
|
6
6
|
import baseConfig from './module-federation.config';
|
7
7
|
|
@@ -1,6 +1,7 @@
|
|
1
|
-
import {composePlugins, withNx
|
1
|
+
import {composePlugins, withNx} from '@nx/webpack';
|
2
2
|
import {withReact} from '@nx/react';
|
3
|
-
import {withModuleFederation} from '@nx/
|
3
|
+
import {withModuleFederation} from '@nx/module-federation/webpack';
|
4
|
+
import { ModuleFederationConfig } from '@nx/module-federation';
|
4
5
|
|
5
6
|
import baseConfig from './module-federation.config';
|
6
7
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
const { composePlugins, withNx, withReact } = require('@nx/rspack');
|
2
|
-
const { withModuleFederation } = require('@nx/
|
2
|
+
const { withModuleFederation } = require('@nx/module-federation/rspack');
|
3
3
|
|
4
4
|
const baseConfig = require('./module-federation.config');
|
5
5
|
|
package/src/generators/remote/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
const {composePlugins, withNx, withReact} = require('@nx/rspack');
|
2
|
-
const {withModuleFederationForSSR} = require('@nx/
|
2
|
+
const {withModuleFederationForSSR} = require('@nx/module-federation/rspack');
|
3
3
|
|
4
4
|
const baseConfig = require("./module-federation.server.config");
|
5
5
|
|
package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import {composePlugins, withNx, withReact} from '@nx/rspack';
|
2
|
-
import {withModuleFederationForSSR} from '@nx/
|
2
|
+
import {withModuleFederationForSSR} from '@nx/module-federation/rspack';
|
3
3
|
|
4
4
|
import baseConfig from "./module-federation.server.config";
|
5
5
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
const { composePlugins, withNx } = require('@nx/webpack');
|
2
2
|
const { withReact } = require('@nx/react');
|
3
|
-
const { withModuleFederation } = require('@nx/
|
3
|
+
const { withModuleFederation } = require('@nx/module-federation/webpack');
|
4
4
|
|
5
5
|
const baseConfig = require('./module-federation.config');
|
6
6
|
|
package/src/generators/remote/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
const {composePlugins, withNx} = require('@nx/webpack');
|
2
2
|
const {withReact} = require('@nx/react');
|
3
|
-
const {withModuleFederationForSSR} = require('@nx/
|
3
|
+
const {withModuleFederationForSSR} = require('@nx/module-federation/webpack');
|
4
4
|
|
5
5
|
const baseConfig = require("./module-federation.server.config");
|
6
6
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import {composePlugins, withNx} from '@nx/webpack';
|
2
2
|
import {withReact} from '@nx/react';
|
3
|
-
import {withModuleFederationForSSR} from '@nx/
|
3
|
+
import {withModuleFederationForSSR} from '@nx/module-federation/webpack';
|
4
4
|
|
5
5
|
import baseConfig from "./module-federation.server.config";
|
6
6
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import {composePlugins, withNx} from '@nx/webpack';
|
2
2
|
import {withReact} from '@nx/react';
|
3
|
-
import {withModuleFederation} from '@nx/
|
3
|
+
import {withModuleFederation} from '@nx/module-federation/webpack';
|
4
4
|
|
5
5
|
import baseConfig from './module-federation.config';
|
6
6
|
|
@@ -0,0 +1,63 @@
|
|
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]),ImportDeclaration:has(StringLiteral[value=@nx/rspack/module-federation]):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
|
+
const RSPACK_IMPORT_SELECTOR = `ImportDeclaration > StringLiteral[value=@nx/rspack/module-federation]`;
|
13
|
+
async function migrateMfImportsToNewPackage(tree) {
|
14
|
+
const rootsToCheck = new Set();
|
15
|
+
const graph = await (0, devkit_1.createProjectGraphAsync)();
|
16
|
+
for (const [project, dependencies] of Object.entries(graph.dependencies)) {
|
17
|
+
const usesNxWebpackOrRspack = dependencies.some((dep) => dep.target === 'npm:@nx/webpack' || dep.target === 'npm:@nx/rspack');
|
18
|
+
if (usesNxWebpackOrRspack) {
|
19
|
+
const root = graph.nodes[project].data.root;
|
20
|
+
rootsToCheck.add(root);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
for (const root of rootsToCheck) {
|
24
|
+
(0, devkit_2.visitNotIgnoredFiles)(tree, root, (filePath) => {
|
25
|
+
if (!filePath.endsWith('.ts') && !filePath.endsWith('.js')) {
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
let contents = tree.read(filePath, 'utf-8');
|
29
|
+
if (!contents.includes(MF_IMPORT_TO_UPDATE)) {
|
30
|
+
return;
|
31
|
+
}
|
32
|
+
const ast = tsquery_1.tsquery.ast(contents);
|
33
|
+
const importNodes = (0, tsquery_1.tsquery)(ast, MF_CONFIG_IMPORT_SELECTOR);
|
34
|
+
if (importNodes.length === 0) {
|
35
|
+
return;
|
36
|
+
}
|
37
|
+
const importNode = importNodes[0];
|
38
|
+
const importSpecifiers = (0, tsquery_1.tsquery)(importNode, IMPORT_TOKENS_SELECTOR);
|
39
|
+
if (importSpecifiers.length > 1) {
|
40
|
+
const mfConfigImportSpecifierNode = (0, tsquery_1.tsquery)(importNode, MF_CONFIG_IMPORT_SPECIFIER_SELECTOR)[0];
|
41
|
+
const end = contents.charAt(mfConfigImportSpecifierNode.getEnd()) === ','
|
42
|
+
? mfConfigImportSpecifierNode.getEnd() + 1
|
43
|
+
: mfConfigImportSpecifierNode.getEnd();
|
44
|
+
contents = `import { ${MF_IMPORT_TO_UPDATE} } from '@nx/module-federation';
|
45
|
+
${contents.slice(0, mfConfigImportSpecifierNode.getStart())}${contents.slice(end)}`;
|
46
|
+
}
|
47
|
+
else {
|
48
|
+
const nxWebpackImportStringNodes = (0, tsquery_1.tsquery)(importNode, WEBPACK_IMPORT_SELECTOR);
|
49
|
+
const nxRspackImportStringNodes = (0, tsquery_1.tsquery)(importNode, RSPACK_IMPORT_SELECTOR);
|
50
|
+
if (nxWebpackImportStringNodes.length === 0 &&
|
51
|
+
nxRspackImportStringNodes.length === 0) {
|
52
|
+
return;
|
53
|
+
}
|
54
|
+
const bundlerImportStringNode = nxWebpackImportStringNodes.length
|
55
|
+
? nxWebpackImportStringNodes[0]
|
56
|
+
: nxRspackImportStringNodes[0];
|
57
|
+
contents = `${contents.slice(0, bundlerImportStringNode.getStart())}'@nx/module-federation'${contents.slice(bundlerImportStringNode.getEnd())}`;
|
58
|
+
}
|
59
|
+
tree.write(filePath, contents);
|
60
|
+
});
|
61
|
+
}
|
62
|
+
await (0, devkit_2.formatFiles)(tree);
|
63
|
+
}
|
@@ -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_RSPACK_MODULE_FEDERATION_IMPORT_SELECTOR = 'ImportDeclaration > StringLiteral[value=@nx/react/module-federation], VariableStatement CallExpression:has(Identifier[name=require]) > StringLiteral[value=@nx/react/module-federation]';
|
8
|
+
const NEW_IMPORT_PATH = `'@nx/module-federation/webpack'`;
|
9
|
+
async function migrateWithMfImport(tree) {
|
10
|
+
const projects = new Set();
|
11
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/react:module-federation-dev-server', (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/react/module-federation')) {
|
22
|
+
return;
|
23
|
+
}
|
24
|
+
const ast = tsquery_1.tsquery.ast(contents);
|
25
|
+
const importNodes = (0, tsquery_1.tsquery)(ast, NX_RSPACK_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
|
+
}
|
@@ -8,24 +8,26 @@ function updateModuleFederationProject(host, options) {
|
|
8
8
|
if (options.bundler === 'rspack') {
|
9
9
|
projectConfig.targets.build.executor = '@nx/rspack:rspack';
|
10
10
|
projectConfig.targets.build.options = {
|
11
|
-
...projectConfig.targets.build.options,
|
11
|
+
...(projectConfig.targets.build.options ?? {}),
|
12
12
|
main: (0, maybe_js_1.maybeJs)({ js: options.js, useJsx: true }, `${options.appProjectRoot}/src/main.ts`),
|
13
13
|
rspackConfig: `${options.appProjectRoot}/rspack.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
|
14
14
|
target: 'web',
|
15
15
|
};
|
16
|
+
projectConfig.targets.build.configurations ??= {};
|
16
17
|
projectConfig.targets.build.configurations.production = {
|
17
|
-
...projectConfig.targets.build.configurations
|
18
|
+
...(projectConfig.targets.build.configurations?.production ?? {}),
|
18
19
|
rspackConfig: `${options.appProjectRoot}/rspack.config.prod.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
|
19
20
|
};
|
20
21
|
}
|
21
22
|
else {
|
22
23
|
projectConfig.targets.build.options = {
|
23
|
-
...projectConfig.targets.build.options,
|
24
|
+
...(projectConfig.targets.build.options ?? {}),
|
24
25
|
main: (0, maybe_js_1.maybeJs)(options, `${options.appProjectRoot}/src/main.ts`),
|
25
26
|
webpackConfig: `${options.appProjectRoot}/webpack.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
|
26
27
|
};
|
28
|
+
projectConfig.targets.build.configurations ??= {};
|
27
29
|
projectConfig.targets.build.configurations.production = {
|
28
|
-
...projectConfig.targets.build.configurations
|
30
|
+
...(projectConfig.targets.build.configurations?.production ?? {}),
|
29
31
|
webpackConfig: `${options.appProjectRoot}/webpack.config.prod.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
|
30
32
|
};
|
31
33
|
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.hasRspackPlugin = hasRspackPlugin;
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
5
|
+
function hasRspackPlugin(tree) {
|
6
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
7
|
+
return !!nxJson.plugins?.some((p) => typeof p === 'string'
|
8
|
+
? p === '@nx/rspack/plugin'
|
9
|
+
: p.plugin === '@nx/rspack/plugin');
|
10
|
+
}
|
package/src/utils/versions.d.ts
CHANGED
@@ -36,8 +36,8 @@ export declare const typesExpressVersion = "4.17.17";
|
|
36
36
|
export declare const isbotVersion = "^3.6.5";
|
37
37
|
export declare const corsVersion = "~2.8.5";
|
38
38
|
export declare const typesCorsVersion = "~2.8.12";
|
39
|
-
export declare const moduleFederationNodeVersion = "~2.
|
40
|
-
export declare const moduleFederationEnhancedVersion = "0.6
|
39
|
+
export declare const moduleFederationNodeVersion = "~2.6.11";
|
40
|
+
export declare const moduleFederationEnhancedVersion = "0.7.6";
|
41
41
|
export declare const lessVersion = "3.12.2";
|
42
42
|
export declare const sassVersion = "^1.55.0";
|
43
43
|
export declare const rollupPluginUrlVersion = "^8.0.2";
|
package/src/utils/versions.js
CHANGED
@@ -42,8 +42,8 @@ exports.typesExpressVersion = '4.17.17';
|
|
42
42
|
exports.isbotVersion = '^3.6.5';
|
43
43
|
exports.corsVersion = '~2.8.5';
|
44
44
|
exports.typesCorsVersion = '~2.8.12';
|
45
|
-
exports.moduleFederationNodeVersion = '~2.
|
46
|
-
exports.moduleFederationEnhancedVersion = '0.6
|
45
|
+
exports.moduleFederationNodeVersion = '~2.6.11';
|
46
|
+
exports.moduleFederationEnhancedVersion = '0.7.6';
|
47
47
|
// style preprocessors
|
48
48
|
exports.lessVersion = '3.12.2';
|
49
49
|
exports.sassVersion = '^1.55.0';
|
@@ -1,31 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.addProjectRootToRspackPluginExcludesIfExists = addProjectRootToRspackPluginExcludesIfExists;
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
5
|
-
const devkit_2 = require("@nx/devkit");
|
6
|
-
function addProjectRootToRspackPluginExcludesIfExists(tree, projectRoot) {
|
7
|
-
const excludeProjectGlob = (0, devkit_1.joinPathFragments)(projectRoot, '/**');
|
8
|
-
const nxJson = (0, devkit_2.readNxJson)(tree);
|
9
|
-
if (!nxJson.plugins?.length) {
|
10
|
-
return;
|
11
|
-
}
|
12
|
-
for (let i = 0; i < nxJson.plugins.length; i++) {
|
13
|
-
let plugin = nxJson.plugins[i];
|
14
|
-
const isRspackPlugin = typeof plugin === 'string'
|
15
|
-
? plugin === '@nx/rspack/plugin'
|
16
|
-
: plugin.plugin === '@nx/rspack/plugin';
|
17
|
-
if (isRspackPlugin) {
|
18
|
-
if (typeof plugin === 'string') {
|
19
|
-
plugin = {
|
20
|
-
plugin: plugin,
|
21
|
-
exclude: [excludeProjectGlob],
|
22
|
-
};
|
23
|
-
}
|
24
|
-
else {
|
25
|
-
plugin.exclude = [...(plugin.exclude ?? []), excludeProjectGlob];
|
26
|
-
}
|
27
|
-
nxJson.plugins[i] = plugin;
|
28
|
-
}
|
29
|
-
}
|
30
|
-
(0, devkit_1.updateNxJson)(tree, nxJson);
|
31
|
-
}
|
@@ -1,15 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.loadModuleFederationConfigFromContext = loadModuleFederationConfigFromContext;
|
4
|
-
const path_1 = require("path");
|
5
|
-
function loadModuleFederationConfigFromContext(context) {
|
6
|
-
const p = context.projectsConfigurations.projects[context.projectName];
|
7
|
-
const moduleFederationConfigPath = (0, path_1.join)(context.root, p.root, 'module-federation.config.js');
|
8
|
-
try {
|
9
|
-
return require(moduleFederationConfigPath);
|
10
|
-
}
|
11
|
-
catch {
|
12
|
-
// TODO(jack): Add a link to guide
|
13
|
-
throw new Error(`Could not load ${moduleFederationConfigPath}. Was this project generated with "@nx/react:host"?`);
|
14
|
-
}
|
15
|
-
}
|
@@ -1,24 +0,0 @@
|
|
1
|
-
export type ModuleFederationLibrary = {
|
2
|
-
type: string;
|
3
|
-
name: string;
|
4
|
-
};
|
5
|
-
export type Remotes = string[] | [remoteName: string, remoteUrl: string][];
|
6
|
-
export interface SharedLibraryConfig {
|
7
|
-
singleton?: boolean;
|
8
|
-
strictVersion?: boolean;
|
9
|
-
requiredVersion?: false | string;
|
10
|
-
eager?: boolean;
|
11
|
-
}
|
12
|
-
export type SharedFunction = (libraryName: string, sharedConfig: SharedLibraryConfig) => undefined | false | SharedLibraryConfig;
|
13
|
-
export type AdditionalSharedConfig = Array<string | [libraryName: string, sharedConfig: SharedLibraryConfig] | {
|
14
|
-
libraryName: string;
|
15
|
-
sharedConfig: SharedLibraryConfig;
|
16
|
-
}>;
|
17
|
-
export interface ModuleFederationConfig {
|
18
|
-
name: string;
|
19
|
-
remotes?: Remotes;
|
20
|
-
library?: ModuleFederationLibrary;
|
21
|
-
exposes?: Record<string, string>;
|
22
|
-
shared?: SharedFunction;
|
23
|
-
additionalShared?: AdditionalSharedConfig;
|
24
|
-
}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.readRootPackageJson = readRootPackageJson;
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
5
|
-
const fs_1 = require("fs");
|
6
|
-
function readRootPackageJson() {
|
7
|
-
const pkgJsonPath = (0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, 'package.json');
|
8
|
-
if (!(0, fs_1.existsSync)(pkgJsonPath)) {
|
9
|
-
throw new Error('NX MFE: Could not find root package.json to determine dependency versions.');
|
10
|
-
}
|
11
|
-
return (0, devkit_1.readJsonFile)(pkgJsonPath);
|
12
|
-
}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import { ModuleFederationConfig } from '@nx/webpack/src/utils/module-federation';
|
2
|
-
export declare function getFunctionDeterminateRemoteUrl(isServer?: boolean): (remote: string) => string;
|
3
|
-
export declare function getModuleFederationConfig(mfConfig: ModuleFederationConfig, options?: {
|
4
|
-
isServer: boolean;
|
5
|
-
determineRemoteUrl?: (remote: string) => string;
|
6
|
-
}): Promise<{
|
7
|
-
sharedLibraries: import("@nx/webpack/src/utils/module-federation").SharedWorkspaceLibraryConfig;
|
8
|
-
sharedDependencies: {
|
9
|
-
[x: string]: import("@nx/webpack/src/utils/module-federation").SharedLibraryConfig;
|
10
|
-
};
|
11
|
-
mappedRemotes: {};
|
12
|
-
}>;
|
@@ -1,75 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getFunctionDeterminateRemoteUrl = getFunctionDeterminateRemoteUrl;
|
4
|
-
exports.getModuleFederationConfig = getModuleFederationConfig;
|
5
|
-
const module_federation_1 = require("@nx/webpack/src/utils/module-federation");
|
6
|
-
const devkit_1 = require("@nx/devkit");
|
7
|
-
const project_graph_1 = require("nx/src/project-graph/project-graph");
|
8
|
-
function getFunctionDeterminateRemoteUrl(isServer = false) {
|
9
|
-
const target = 'serve';
|
10
|
-
const remoteEntry = isServer ? 'server/remoteEntry.js' : 'remoteEntry.js';
|
11
|
-
return function (remote) {
|
12
|
-
const mappedStaticRemotesFromEnv = process.env
|
13
|
-
.NX_MF_DEV_SERVER_STATIC_REMOTES
|
14
|
-
? JSON.parse(process.env.NX_MF_DEV_SERVER_STATIC_REMOTES)
|
15
|
-
: undefined;
|
16
|
-
if (mappedStaticRemotesFromEnv && mappedStaticRemotesFromEnv[remote]) {
|
17
|
-
return `${mappedStaticRemotesFromEnv[remote]}/${remoteEntry}`;
|
18
|
-
}
|
19
|
-
let remoteConfiguration = null;
|
20
|
-
try {
|
21
|
-
remoteConfiguration = (0, project_graph_1.readCachedProjectConfiguration)(remote);
|
22
|
-
}
|
23
|
-
catch (e) {
|
24
|
-
throw new Error(`Cannot find remote: "${remote}". Check that the remote name is correct in your module federation config file.\n`);
|
25
|
-
}
|
26
|
-
const serveTarget = remoteConfiguration?.targets?.[target];
|
27
|
-
if (!serveTarget) {
|
28
|
-
throw new Error(`Cannot automatically determine URL of remote (${remote}). Looked for property "host" in the project's "${serveTarget}" target.\n
|
29
|
-
You can also use the tuple syntax in your webpack config to configure your remotes. e.g. \`remotes: [['remote1', 'http://localhost:4201']]\``);
|
30
|
-
}
|
31
|
-
const host = serveTarget.options?.host ??
|
32
|
-
`http${serveTarget.options.ssl ? 's' : ''}://localhost`;
|
33
|
-
const port = serveTarget.options?.port ?? 4201;
|
34
|
-
return `${host.endsWith('/') ? host.slice(0, -1) : host}:${port}/${remoteEntry}`;
|
35
|
-
};
|
36
|
-
}
|
37
|
-
async function getModuleFederationConfig(mfConfig, options = { isServer: false }) {
|
38
|
-
let projectGraph;
|
39
|
-
try {
|
40
|
-
projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
41
|
-
}
|
42
|
-
catch (e) {
|
43
|
-
projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
44
|
-
}
|
45
|
-
const project = projectGraph.nodes[mfConfig.name]?.data;
|
46
|
-
if (!project) {
|
47
|
-
throw Error(`Cannot find project "${mfConfig.name}". Check that the name is correct in module-federation.config.js`);
|
48
|
-
}
|
49
|
-
const dependencies = (0, module_federation_1.getDependentPackagesForProject)(projectGraph, mfConfig.name);
|
50
|
-
if (mfConfig.shared) {
|
51
|
-
dependencies.workspaceLibraries = dependencies.workspaceLibraries.filter((lib) => mfConfig.shared(lib.importKey, {}) !== false);
|
52
|
-
dependencies.npmPackages = dependencies.npmPackages.filter((pkg) => mfConfig.shared(pkg, {}) !== false);
|
53
|
-
}
|
54
|
-
const sharedLibraries = (0, module_federation_1.shareWorkspaceLibraries)(dependencies.workspaceLibraries);
|
55
|
-
const npmPackages = (0, module_federation_1.sharePackages)(dependencies.npmPackages);
|
56
|
-
const sharedDependencies = {
|
57
|
-
...sharedLibraries.getLibraries(project.root),
|
58
|
-
...npmPackages,
|
59
|
-
};
|
60
|
-
(0, module_federation_1.applySharedFunction)(sharedDependencies, mfConfig.shared);
|
61
|
-
(0, module_federation_1.applyAdditionalShared)(sharedDependencies, mfConfig.additionalShared, projectGraph);
|
62
|
-
// Choose the correct mapRemotes function based on the server state.
|
63
|
-
const mapRemotesFunction = options.isServer ? module_federation_1.mapRemotesForSSR : module_federation_1.mapRemotes;
|
64
|
-
// Determine the URL function, either from provided options or by using a default.
|
65
|
-
const determineRemoteUrlFunction = options.determineRemoteUrl
|
66
|
-
? options.determineRemoteUrl
|
67
|
-
: getFunctionDeterminateRemoteUrl(options.isServer);
|
68
|
-
// Map the remotes if they exist, otherwise default to an empty object.
|
69
|
-
let mappedRemotes = {};
|
70
|
-
if (mfConfig.remotes && mfConfig.remotes.length > 0) {
|
71
|
-
const isLibraryTypeVar = mfConfig.library?.type === 'var';
|
72
|
-
mappedRemotes = mapRemotesFunction(mfConfig.remotes, 'js', determineRemoteUrlFunction, true);
|
73
|
-
}
|
74
|
-
return { sharedLibraries, sharedDependencies, mappedRemotes };
|
75
|
-
}
|
@@ -1,2 +0,0 @@
|
|
1
|
-
import { ModuleFederationConfig, NxModuleFederationConfigOverride } from '@nx/webpack/src/utils/module-federation';
|
2
|
-
export declare function withModuleFederationForSSR(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: any) => any>;
|
@@ -1,50 +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
|
-
config.target = 'async-node';
|
14
|
-
config.output.uniqueName = options.name;
|
15
|
-
config.optimization = {
|
16
|
-
...(config.optimization ?? {}),
|
17
|
-
runtimeChunk: false,
|
18
|
-
};
|
19
|
-
config.plugins.push(new (require('@module-federation/enhanced').ModuleFederationPlugin)({
|
20
|
-
name: options.name.replace(/-/g, '_'),
|
21
|
-
filename: 'remoteEntry.js',
|
22
|
-
exposes: options.exposes,
|
23
|
-
remotes: mappedRemotes,
|
24
|
-
shared: {
|
25
|
-
...sharedDependencies,
|
26
|
-
},
|
27
|
-
/**
|
28
|
-
* Apply user-defined config overrides
|
29
|
-
*/
|
30
|
-
...(configOverride ? configOverride : {}),
|
31
|
-
runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
|
32
|
-
!options.disableNxRuntimeLibraryControlPlugin
|
33
|
-
? [
|
34
|
-
...(configOverride?.runtimePlugins ?? []),
|
35
|
-
require.resolve('@nx/webpack/src/utils/module-federation/plugins/runtime-library-control.plugin.js'),
|
36
|
-
]
|
37
|
-
: [
|
38
|
-
...(configOverride?.runtimePlugins ?? []),
|
39
|
-
require.resolve('@module-federation/node/runtimePlugin'),
|
40
|
-
],
|
41
|
-
virtualRuntimeEntry: true,
|
42
|
-
}, {}), sharedLibraries.getReplacementPlugin());
|
43
|
-
// The env var is only set from the module-federation-dev-server
|
44
|
-
// Attach the runtime plugin
|
45
|
-
config.plugins.push(new (require('webpack').DefinePlugin)({
|
46
|
-
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
|
47
|
-
}));
|
48
|
-
return config;
|
49
|
-
};
|
50
|
-
}
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import { ModuleFederationConfig, NxModuleFederationConfigOverride } from '@nx/webpack/src/utils/module-federation';
|
2
|
-
import type { AsyncNxComposableWebpackPlugin } from '@nx/webpack';
|
3
|
-
/**
|
4
|
-
* @param {ModuleFederationConfig} options
|
5
|
-
* @return {Promise<AsyncNxComposableWebpackPlugin>}
|
6
|
-
*/
|
7
|
-
export declare function withModuleFederation(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<AsyncNxComposableWebpackPlugin>;
|
@@ -1,63 +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
|
-
/**
|
7
|
-
* @param {ModuleFederationConfig} options
|
8
|
-
* @return {Promise<AsyncNxComposableWebpackPlugin>}
|
9
|
-
*/
|
10
|
-
async function withModuleFederation(options, configOverride) {
|
11
|
-
if (global.NX_GRAPH_CREATION) {
|
12
|
-
return (config) => config;
|
13
|
-
}
|
14
|
-
const { sharedDependencies, sharedLibraries, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options);
|
15
|
-
return (config, ctx) => {
|
16
|
-
config.output.uniqueName = options.name;
|
17
|
-
config.output.publicPath = 'auto';
|
18
|
-
config.output.scriptType = 'text/javascript';
|
19
|
-
config.optimization = {
|
20
|
-
...(config.optimization ?? {}),
|
21
|
-
runtimeChunk: false,
|
22
|
-
};
|
23
|
-
if (config.mode === 'development' &&
|
24
|
-
Object.keys(mappedRemotes).length > 1 &&
|
25
|
-
!options.exposes) {
|
26
|
-
config.optimization.runtimeChunk = 'single';
|
27
|
-
}
|
28
|
-
config.plugins.push(new webpack_1.ModuleFederationPlugin({
|
29
|
-
name: options.name.replace(/-/g, '_'),
|
30
|
-
filename: 'remoteEntry.js',
|
31
|
-
exposes: options.exposes,
|
32
|
-
remotes: mappedRemotes,
|
33
|
-
shared: {
|
34
|
-
...sharedDependencies,
|
35
|
-
},
|
36
|
-
/**
|
37
|
-
* remoteType: 'script' is required for the remote to be loaded as a script tag.
|
38
|
-
* remotes will need to be defined as:
|
39
|
-
* { appX: 'appX@http://localhost:3001/remoteEntry.js' }
|
40
|
-
* { appY: 'appY@http://localhost:3002/remoteEntry.js' }
|
41
|
-
*/
|
42
|
-
remoteType: 'script',
|
43
|
-
/**
|
44
|
-
* Apply user-defined config overrides
|
45
|
-
*/
|
46
|
-
...(configOverride ? configOverride : {}),
|
47
|
-
runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
|
48
|
-
!options.disableNxRuntimeLibraryControlPlugin
|
49
|
-
? [
|
50
|
-
...(configOverride?.runtimePlugins ?? []),
|
51
|
-
require.resolve('@nx/webpack/src/utils/module-federation/plugins/runtime-library-control.plugin.js'),
|
52
|
-
]
|
53
|
-
: configOverride?.runtimePlugins,
|
54
|
-
virtualRuntimeEntry: true,
|
55
|
-
}), sharedLibraries.getReplacementPlugin());
|
56
|
-
// The env var is only set from the module-federation-dev-server
|
57
|
-
// Attach the runtime plugin
|
58
|
-
config.plugins.push(new (require('webpack').DefinePlugin)({
|
59
|
-
'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
|
60
|
-
}));
|
61
|
-
return config;
|
62
|
-
};
|
63
|
-
}
|