@nx/react 20.2.0-beta.2 → 20.2.0-beta.4
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 +20 -6
- package/src/generators/application/files/base-rspack/rspack.config.js__tmpl__ +53 -0
- package/src/generators/application/files/base-rspack/tsconfig.app.json__tmpl__ +21 -4
- package/src/generators/application/files/base-vite/tsconfig.app.json__tmpl__ +19 -2
- package/src/generators/application/files/base-webpack/tsconfig.app.json__tmpl__ +20 -3
- package/src/generators/application/files/style-css-module/src/app/__fileName__.tsx__tmpl__ +2 -2
- package/src/generators/application/lib/add-e2e.d.ts +1 -1
- package/src/generators/application/lib/add-e2e.js +45 -15
- package/src/generators/application/lib/add-jest.js +1 -0
- package/src/generators/application/lib/add-project.js +85 -3
- package/src/generators/application/lib/create-application-files.js +30 -1
- package/src/generators/application/lib/normalize-options.js +2 -0
- package/src/generators/application/lib/update-jest-config.js +5 -0
- package/src/generators/application/schema.d.ts +5 -0
- package/src/generators/application/schema.json +19 -15
- package/src/generators/component/component.js +3 -1
- package/src/generators/component/lib/normalize-options.js +2 -1
- package/src/generators/component/schema.d.ts +1 -1
- package/src/generators/component/schema.json +3 -5
- package/src/generators/hook/hook.js +10 -25
- package/src/generators/hook/schema.d.ts +0 -2
- package/src/generators/hook/schema.json +10 -18
- 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/host/host.js +3 -2
- package/src/generators/host/lib/update-module-federation-tsconfig.d.ts +3 -0
- package/src/generators/host/lib/update-module-federation-tsconfig.js +39 -0
- package/src/generators/init/init.js +0 -2
- package/src/generators/library/lib/create-files.d.ts +1 -1
- package/src/generators/library/lib/create-files.js +22 -2
- package/src/generators/library/lib/normalize-options.js +3 -0
- package/src/generators/library/library.js +46 -16
- package/src/generators/library/schema.d.ts +1 -0
- package/src/generators/library/schema.json +14 -11
- package/src/generators/redux/schema.json +13 -4
- 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/generators/remote/remote.js +1 -2
- 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 +66 -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 +12 -4
- package/src/utils/build-static.remotes.d.ts +1 -1
- package/src/utils/create-ts-config.js +57 -7
- 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 -3
- package/src/utils/versions.js +3 -5
- 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/generators/library/files/common/package.json__tmpl__ +0 -4
- package/src/generators/library/files/vite/package.json__tmpl__ +0 -12
- 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
@@ -4,7 +4,64 @@ exports.createTsConfig = createTsConfig;
|
|
4
4
|
exports.extractTsConfigBase = extractTsConfigBase;
|
5
5
|
const shared = require("@nx/js/src/utils/typescript/create-ts-config");
|
6
6
|
const json_1 = require("nx/src/generators/utils/json");
|
7
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
7
8
|
function createTsConfig(host, projectRoot, type, options, relativePathToRootTsConfig) {
|
9
|
+
if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)(host)) {
|
10
|
+
createTsConfigForTsSolution(host, projectRoot, type, options, relativePathToRootTsConfig);
|
11
|
+
}
|
12
|
+
else {
|
13
|
+
createTsConfigForNonTsSolution(host, projectRoot, type, options, relativePathToRootTsConfig);
|
14
|
+
}
|
15
|
+
}
|
16
|
+
function extractTsConfigBase(host) {
|
17
|
+
shared.extractTsConfigBase(host);
|
18
|
+
if (host.exists('vite.config.ts')) {
|
19
|
+
const vite = host.read('vite.config.ts').toString();
|
20
|
+
host.write('vite.config.ts', vite.replace(`projects: []`, `projects: ['tsconfig.base.json']`));
|
21
|
+
}
|
22
|
+
}
|
23
|
+
function createTsConfigForTsSolution(host, projectRoot, type, options, relativePathToRootTsConfig) {
|
24
|
+
const json = {
|
25
|
+
files: [],
|
26
|
+
include: [],
|
27
|
+
references: [
|
28
|
+
{
|
29
|
+
path: type === 'app' ? './tsconfig.app.json' : './tsconfig.lib.json',
|
30
|
+
},
|
31
|
+
],
|
32
|
+
};
|
33
|
+
// inline tsconfig.base.json into the project
|
34
|
+
if (options.rootProject) {
|
35
|
+
json.compileOnSave = false;
|
36
|
+
json.compilerOptions = {
|
37
|
+
...shared.tsConfigBaseOptions,
|
38
|
+
...json.compilerOptions,
|
39
|
+
};
|
40
|
+
json.exclude = ['node_modules', 'tmp'];
|
41
|
+
}
|
42
|
+
else {
|
43
|
+
json.extends = relativePathToRootTsConfig;
|
44
|
+
}
|
45
|
+
(0, json_1.writeJson)(host, `${projectRoot}/tsconfig.json`, json);
|
46
|
+
const tsconfigProjectPath = `${projectRoot}/tsconfig.${type}.json`;
|
47
|
+
if (host.exists(tsconfigProjectPath)) {
|
48
|
+
(0, json_1.updateJson)(host, tsconfigProjectPath, (json) => {
|
49
|
+
if (options.bundler === 'vite') {
|
50
|
+
json.compilerOptions ??= {};
|
51
|
+
const types = new Set(json.compilerOptions.types ?? []);
|
52
|
+
types.add('node');
|
53
|
+
types.add('vite/client');
|
54
|
+
json.compilerOptions.types = Array.from(types);
|
55
|
+
}
|
56
|
+
if (options.style === '@emotion/styled') {
|
57
|
+
json.compilerOptions ??= {};
|
58
|
+
json.compilerOptions.jsxImportSource = '@emotion/react';
|
59
|
+
}
|
60
|
+
return json;
|
61
|
+
});
|
62
|
+
}
|
63
|
+
}
|
64
|
+
function createTsConfigForNonTsSolution(host, projectRoot, type, options, relativePathToRootTsConfig) {
|
8
65
|
const json = {
|
9
66
|
compilerOptions: {
|
10
67
|
jsx: 'react-jsx',
|
@@ -55,10 +112,3 @@ function createTsConfig(host, projectRoot, type, options, relativePathToRootTsCo
|
|
55
112
|
});
|
56
113
|
}
|
57
114
|
}
|
58
|
-
function extractTsConfigBase(host) {
|
59
|
-
shared.extractTsConfigBase(host);
|
60
|
-
if (host.exists('vite.config.ts')) {
|
61
|
-
const vite = host.read('vite.config.ts').toString();
|
62
|
-
host.write('vite.config.ts', vite.replace(`projects: []`, `projects: ['tsconfig.base.json']`));
|
63
|
-
}
|
64
|
-
}
|
@@ -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
@@ -1,5 +1,4 @@
|
|
1
1
|
export declare const nxVersion: any;
|
2
|
-
export declare const nxRspackVersion = "*";
|
3
2
|
export declare const reactVersion = "18.3.1";
|
4
3
|
export declare const reactDomVersion = "18.3.1";
|
5
4
|
export declare const reactIsVersion = "18.3.1";
|
@@ -36,8 +35,8 @@ export declare const typesExpressVersion = "4.17.17";
|
|
36
35
|
export declare const isbotVersion = "^3.6.5";
|
37
36
|
export declare const corsVersion = "~2.8.5";
|
38
37
|
export declare const typesCorsVersion = "~2.8.12";
|
39
|
-
export declare const moduleFederationNodeVersion = "~2.
|
40
|
-
export declare const moduleFederationEnhancedVersion = "0.6
|
38
|
+
export declare const moduleFederationNodeVersion = "~2.6.11";
|
39
|
+
export declare const moduleFederationEnhancedVersion = "0.7.6";
|
41
40
|
export declare const lessVersion = "3.12.2";
|
42
41
|
export declare const sassVersion = "^1.55.0";
|
43
42
|
export declare const rollupPluginUrlVersion = "^8.0.2";
|
package/src/utils/versions.js
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.swcPluginStyledComponentsVersion = exports.swcPluginEmotionVersion = exports.swcPluginStyledJsxVersion = exports.svgrRollupVersion = exports.rollupPluginUrlVersion = exports.sassVersion = exports.lessVersion = exports.moduleFederationEnhancedVersion = exports.moduleFederationNodeVersion = exports.typesCorsVersion = exports.corsVersion = exports.isbotVersion = exports.typesExpressVersion = exports.expressVersion = exports.autoprefixerVersion = exports.tailwindcssVersion = exports.postcssVersion = exports.tsLibVersion = exports.babelPluginStyledComponentsVersion = exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.reactReduxVersion = exports.reduxjsToolkitVersion = exports.testingLibraryReactVersion = exports.reactRouterDomVersion = exports.styledJsxVersion = exports.emotionBabelPlugin = exports.emotionReactVersion = exports.emotionStyledVersion = exports.typesStyledComponentsVersion = exports.styledComponentsVersion = exports.babelCoreVersion = exports.babelPresetReactVersion = exports.typesNodeVersion = exports.reactViteVersion = exports.typesReactIsVersion = exports.typesReactDomVersion = exports.typesReactVersion = exports.babelLoaderVersion = exports.swcLoaderVersion = exports.reactIsVersion = exports.reactDomVersion = exports.reactVersion = exports.
|
3
|
+
exports.swcPluginStyledComponentsVersion = exports.swcPluginEmotionVersion = exports.swcPluginStyledJsxVersion = exports.svgrRollupVersion = exports.rollupPluginUrlVersion = exports.sassVersion = exports.lessVersion = exports.moduleFederationEnhancedVersion = exports.moduleFederationNodeVersion = exports.typesCorsVersion = exports.corsVersion = exports.isbotVersion = exports.typesExpressVersion = exports.expressVersion = exports.autoprefixerVersion = exports.tailwindcssVersion = exports.postcssVersion = exports.tsLibVersion = exports.babelPluginStyledComponentsVersion = exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.reactReduxVersion = exports.reduxjsToolkitVersion = exports.testingLibraryReactVersion = exports.reactRouterDomVersion = exports.styledJsxVersion = exports.emotionBabelPlugin = exports.emotionReactVersion = exports.emotionStyledVersion = exports.typesStyledComponentsVersion = exports.styledComponentsVersion = exports.babelCoreVersion = exports.babelPresetReactVersion = exports.typesNodeVersion = exports.reactViteVersion = exports.typesReactIsVersion = exports.typesReactDomVersion = exports.typesReactVersion = exports.babelLoaderVersion = exports.swcLoaderVersion = exports.reactIsVersion = exports.reactDomVersion = exports.reactVersion = exports.nxVersion = void 0;
|
4
4
|
exports.nxVersion = require('../../package.json').version;
|
5
|
-
// Always pull the latest version until we merge rspack plugin into the repo.
|
6
|
-
exports.nxRspackVersion = '*';
|
7
5
|
exports.reactVersion = '18.3.1';
|
8
6
|
exports.reactDomVersion = '18.3.1';
|
9
7
|
exports.reactIsVersion = '18.3.1';
|
@@ -42,8 +40,8 @@ exports.typesExpressVersion = '4.17.17';
|
|
42
40
|
exports.isbotVersion = '^3.6.5';
|
43
41
|
exports.corsVersion = '~2.8.5';
|
44
42
|
exports.typesCorsVersion = '~2.8.12';
|
45
|
-
exports.moduleFederationNodeVersion = '~2.
|
46
|
-
exports.moduleFederationEnhancedVersion = '0.6
|
43
|
+
exports.moduleFederationNodeVersion = '~2.6.11';
|
44
|
+
exports.moduleFederationEnhancedVersion = '0.7.6';
|
47
45
|
// style preprocessors
|
48
46
|
exports.lessVersion = '3.12.2';
|
49
47
|
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
|
-
}
|