@nrwl/react 15.0.13 → 15.1.0-beta.1
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/CHANGELOG.md +1 -1
- package/module-federation.d.ts +0 -2
- package/module-federation.js +0 -3
- package/module-federation.js.map +1 -1
- package/package.json +11 -11
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +1 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +4 -3
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js.map +1 -1
- package/src/executors/module-federation-dev-server/schema.json +7 -0
- package/src/generators/application/schema.d.ts +1 -0
- package/src/generators/application/schema.json +5 -0
- package/src/generators/host/files/module-federation/module-federation.config.js__tmpl__ +1 -1
- package/src/generators/host/files/module-federation/webpack.config.js__tmpl__ +1 -1
- package/src/generators/host/files/module-federation/webpack.config.prod.js__tmpl__ +1 -1
- package/src/generators/remote/files/module-federation/module-federation.config.js__tmpl__ +1 -1
- package/src/generators/remote/files/module-federation/webpack.config.js__tmpl__ +1 -1
- package/src/module-federation/with-module-federation.d.ts +1 -1
- package/src/module-federation/with-module-federation.js +9 -134
- package/src/module-federation/with-module-federation.js.map +1 -1
- package/src/module-federation/webpack-utils.d.ts +0 -9
- package/src/module-federation/webpack-utils.js +0 -76
- package/src/module-federation/webpack-utils.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
# [15.1.0-beta.1](https://github.com/nrwl/nx/compare/15.0.7...15.1.0-beta.1) (2022-11-11)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @nrwl/react
|
package/module-federation.d.ts
CHANGED
package/module-federation.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withModuleFederation = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const with_module_federation_1 = require("./src/module-federation/with-module-federation");
|
|
6
5
|
Object.defineProperty(exports, "withModuleFederation", { enumerable: true, get: function () { return with_module_federation_1.withModuleFederation; } });
|
|
7
|
-
tslib_1.__exportStar(require("./src/module-federation/models"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./src/module-federation/webpack-utils"), exports);
|
|
9
6
|
// Support for older generated code: `const withModuleFederation = require('@nrwl/react/module-federation')`
|
|
10
7
|
module.exports = with_module_federation_1.withModuleFederation;
|
|
11
8
|
// Allow newer generated code to work: `const { withModuleFederation } = require(...)`;
|
package/module-federation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-federation.js","sourceRoot":"","sources":["../../../packages/react/module-federation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"module-federation.js","sourceRoot":"","sources":["../../../packages/react/module-federation.ts"],"names":[],"mappings":";;;AAAA,2FAAsF;AAE7E,qGAFA,6CAAoB,OAEA;AAE7B,4GAA4G;AAC5G,MAAM,CAAC,OAAO,GAAG,6CAAoB,CAAC;AACtC,uFAAuF;AACvF,MAAM,CAAC,OAAO,CAAC,oBAAoB,GAAG,6CAAoB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nrwl/react",
|
|
3
|
-
"version": "15.0.
|
|
3
|
+
"version": "15.1.0-beta.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
|
|
6
6
|
"repository": {
|
|
@@ -33,15 +33,15 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/core": "^7.15.0",
|
|
35
35
|
"@babel/preset-react": "^7.14.5",
|
|
36
|
-
"@nrwl/cypress": "15.0.
|
|
37
|
-
"@nrwl/devkit": "15.0.
|
|
38
|
-
"@nrwl/jest": "15.0.
|
|
39
|
-
"@nrwl/js": "15.0.
|
|
40
|
-
"@nrwl/linter": "15.0.
|
|
41
|
-
"@nrwl/storybook": "15.0.
|
|
42
|
-
"@nrwl/web": "15.0.
|
|
43
|
-
"@nrwl/webpack": "15.0.
|
|
44
|
-
"@nrwl/workspace": "15.0.
|
|
36
|
+
"@nrwl/cypress": "15.1.0-beta.1",
|
|
37
|
+
"@nrwl/devkit": "15.1.0-beta.1",
|
|
38
|
+
"@nrwl/jest": "15.1.0-beta.1",
|
|
39
|
+
"@nrwl/js": "15.1.0-beta.1",
|
|
40
|
+
"@nrwl/linter": "15.1.0-beta.1",
|
|
41
|
+
"@nrwl/storybook": "15.1.0-beta.1",
|
|
42
|
+
"@nrwl/web": "15.1.0-beta.1",
|
|
43
|
+
"@nrwl/webpack": "15.1.0-beta.1",
|
|
44
|
+
"@nrwl/workspace": "15.1.0-beta.1",
|
|
45
45
|
"@phenomnomnominal/tsquery": "4.1.1",
|
|
46
46
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
|
|
47
47
|
"@svgr/webpack": "^6.1.2",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"access": "public"
|
|
62
62
|
},
|
|
63
63
|
"types": "./index.d.ts",
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "16c3a2eb20902a34eda53e9f6c0dcb301b9ea70d"
|
|
65
65
|
}
|
|
@@ -2,6 +2,7 @@ import { ExecutorContext } from '@nrwl/devkit';
|
|
|
2
2
|
import { WebDevServerOptions } from '@nrwl/webpack/src/executors/dev-server/schema';
|
|
3
3
|
declare type ModuleFederationDevServerOptions = WebDevServerOptions & {
|
|
4
4
|
devRemotes?: string | string[];
|
|
5
|
+
skipRemotes?: string[];
|
|
5
6
|
};
|
|
6
7
|
export default function moduleFederationDevServer(options: ModuleFederationDevServerOptions, context: ExecutorContext): AsyncGenerator<any, void, unknown>;
|
|
7
8
|
export {};
|
|
@@ -7,7 +7,7 @@ const path_1 = require("path");
|
|
|
7
7
|
const chalk = require("chalk");
|
|
8
8
|
const async_iterator_1 = require("../../utils/async-iterator");
|
|
9
9
|
function moduleFederationDevServer(options, context) {
|
|
10
|
-
var _a;
|
|
10
|
+
var _a, _b;
|
|
11
11
|
return tslib_1.__asyncGenerator(this, arguments, function* moduleFederationDevServer_1() {
|
|
12
12
|
let iter = (0, dev_server_impl_1.default)(options, context);
|
|
13
13
|
const p = context.workspace.projects[context.projectName];
|
|
@@ -16,11 +16,12 @@ function moduleFederationDevServer(options, context) {
|
|
|
16
16
|
try {
|
|
17
17
|
moduleFederationConfig = require(moduleFederationConfigPath);
|
|
18
18
|
}
|
|
19
|
-
catch (
|
|
19
|
+
catch (_c) {
|
|
20
20
|
// TODO(jack): Add a link to guide
|
|
21
21
|
throw new Error(`Could not load ${moduleFederationConfigPath}. Was this project generated with "@nrwl/react:host"?`);
|
|
22
22
|
}
|
|
23
|
-
const
|
|
23
|
+
const remotesToSkip = new Set((_a = options.skipRemotes) !== null && _a !== void 0 ? _a : []);
|
|
24
|
+
const knownRemotes = ((_b = moduleFederationConfig.remotes) !== null && _b !== void 0 ? _b : []).filter((r) => !remotesToSkip.has(r));
|
|
24
25
|
const devServeApps = !options.devRemotes
|
|
25
26
|
? []
|
|
26
27
|
: Array.isArray(options.devRemotes)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-federation-dev-server.impl.js","sourceRoot":"","sources":["../../../../../../packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts"],"names":[],"mappings":";;;AAAA,yCAAoE;AACpE,4FAAuF;AAEvF,+BAA4B;AAC5B,+BAA+B;AAC/B,+DAGoC;
|
|
1
|
+
{"version":3,"file":"module-federation-dev-server.impl.js","sourceRoot":"","sources":["../../../../../../packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts"],"names":[],"mappings":";;;AAAA,yCAAoE;AACpE,4FAAuF;AAEvF,+BAA4B;AAC5B,+BAA+B;AAC/B,+DAGoC;AAOpC,SAA+B,yBAAyB,CACtD,OAAyC,EACzC,OAAwB;;;QAExB,IAAI,IAAI,GAAG,IAAA,yBAAiB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC/C,MAAM,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAE1D,MAAM,0BAA0B,GAAG,IAAA,WAAI,EACrC,OAAO,CAAC,IAAI,EACZ,CAAC,CAAC,IAAI,EACN,6BAA6B,CAC9B,CAAC;QAEF,IAAI,sBAA2B,CAAC;QAChC,IAAI;YACF,sBAAsB,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;SAC9D;QAAC,WAAM;YACN,kCAAkC;YAClC,MAAM,IAAI,KAAK,CACb,kBAAkB,0BAA0B,uDAAuD,CACpG,CAAC;SACH;QAED,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,MAAA,OAAO,CAAC,WAAW,mCAAI,EAAE,CAAC,CAAC;QACzD,MAAM,YAAY,GAAG,CAAC,MAAA,sBAAsB,CAAC,OAAO,mCAAI,EAAE,CAAC,CAAC,MAAM,CAChE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAC7B,CAAC;QAEF,MAAM,YAAY,GAAG,CAAC,OAAO,CAAC,UAAU;YACtC,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC;gBACnC,CAAC,CAAC,OAAO,CAAC,UAAU;gBACpB,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAEzB,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE;YAC9B,MAAM,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACnD,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC7C,IAAI,GAAG,IAAA,sCAAqB,EAC1B,IAAI,EACJ,sBAAM,IAAA,oBAAW,EACf;gBACE,OAAO,EAAE,OAAO;gBAChB,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc;gBACxC,aAAa,EAAE,OAAO,CAAC,iBAAiB;aACzC,EACD;gBACE,KAAK,EAAE,KAAK;aACb,EACD,OAAO,CACR,CAAA,CACF,CAAC;SACH;QAED,IAAI,WAAW,GAAG,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,iBAAiB;QAC5D,6BAAO,sBAAA,KAAK,CAAC,CAAC,yBAAA,sBAAA,IAAA,iCAAgB,EAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE;;YACzC,WAAW,EAAE,CAAC;YACd,IAAI,WAAW,KAAK,CAAC,EAAE;gBACrB,eAAM,CAAC,IAAI,CACT,KAAK,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,MAAA,OAAO,CAAC,IAAI,mCAAI,WAAW,IAC/D,MAAA,OAAO,CAAC,IAAI,mCAAI,IAClB,EAAE,CACH,CAAC;aACH;QACH,CAAC,CAAC,CAAA,CAAA,CAAA,EAAC;;CACJ;AAhED,4CAgEC"}
|
|
@@ -13,6 +13,13 @@
|
|
|
13
13
|
},
|
|
14
14
|
"description": "List of remote applications to run in development mode (i.e. using serve target)."
|
|
15
15
|
},
|
|
16
|
+
"skipRemotes": {
|
|
17
|
+
"type": "array",
|
|
18
|
+
"items": {
|
|
19
|
+
"type": "string"
|
|
20
|
+
},
|
|
21
|
+
"description": "List of remote applications to not automatically serve, either statically or in development mode. This can be useful for multi-repository module federation setups where the host application uses a remote application from an external repository."
|
|
22
|
+
},
|
|
16
23
|
"buildTarget": {
|
|
17
24
|
"type": "string",
|
|
18
25
|
"description": "Target which builds the application."
|
|
@@ -164,6 +164,11 @@
|
|
|
164
164
|
"description": "Skip setting the project as the default project. When `false` (the default), the project is set as the default project only if there is no default project already set.",
|
|
165
165
|
"type": "boolean",
|
|
166
166
|
"default": false
|
|
167
|
+
},
|
|
168
|
+
"skipPackageJson": {
|
|
169
|
+
"description": "Do not add dependencies to `package.json`.",
|
|
170
|
+
"type": "boolean",
|
|
171
|
+
"default": false
|
|
167
172
|
}
|
|
168
173
|
},
|
|
169
174
|
"required": []
|
|
@@ -4,7 +4,7 @@ const { withModuleFederation } = require('@nrwl/react/module-federation');
|
|
|
4
4
|
const baseConfig = require('./module-federation.config');
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @type {import('@nrwl/
|
|
7
|
+
* @type {import('@nrwl/devkit').ModuleFederationConfig}
|
|
8
8
|
**/
|
|
9
9
|
const defaultConfig = {
|
|
10
10
|
...baseConfig,
|
|
@@ -4,7 +4,7 @@ const { withModuleFederation } = require('@nrwl/react/module-federation');
|
|
|
4
4
|
const baseConfig = require('./module-federation.config');
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @type {import('@nrwl/
|
|
7
|
+
* @type {import('@nrwl/devkit').ModuleFederationConfig}
|
|
8
8
|
**/
|
|
9
9
|
const prodConfig = {
|
|
10
10
|
...baseConfig,
|
|
@@ -4,7 +4,7 @@ const { withModuleFederation } = require('@nrwl/react/module-federation');
|
|
|
4
4
|
const baseConfig = require('./module-federation.config');
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @type {import('@nrwl/
|
|
7
|
+
* @type {import('@nrwl/devkit').ModuleFederationConfig}
|
|
8
8
|
**/
|
|
9
9
|
const defaultConfig = {
|
|
10
10
|
...baseConfig,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ModuleFederationConfig } from '
|
|
1
|
+
import { ModuleFederationConfig } from '@nrwl/devkit';
|
|
2
2
|
export declare function withModuleFederation(options: ModuleFederationConfig): Promise<(config: any) => any>;
|
|
@@ -2,69 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withModuleFederation = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const webpack_utils_1 = require("./webpack-utils");
|
|
6
5
|
const devkit_1 = require("@nrwl/devkit");
|
|
7
|
-
const
|
|
8
|
-
const package_json_1 = require("./package-json");
|
|
9
|
-
const path_1 = require("path");
|
|
6
|
+
const project_graph_1 = require("nx/src/project-graph/project-graph");
|
|
10
7
|
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
|
|
11
|
-
function
|
|
12
|
-
workspaceLibraries: new Set(),
|
|
13
|
-
npmPackages: new Set(),
|
|
14
|
-
}, seen = new Set()) {
|
|
15
|
-
var _a;
|
|
16
|
-
if (seen.has(name)) {
|
|
17
|
-
return dependencies;
|
|
18
|
-
}
|
|
19
|
-
seen.add(name);
|
|
20
|
-
((_a = projectGraph.dependencies[name]) !== null && _a !== void 0 ? _a : []).forEach((dependency) => {
|
|
21
|
-
if (dependency.target.startsWith('npm:')) {
|
|
22
|
-
dependencies.npmPackages.add(dependency.target.replace('npm:', ''));
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
dependencies.workspaceLibraries.add(dependency.target);
|
|
26
|
-
collectDependencies(projectGraph, dependency.target, dependencies, seen);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
return dependencies;
|
|
30
|
-
}
|
|
31
|
-
function mapWorkspaceLibrariesToTsConfigImport(workspaceLibraries, { nodes }) {
|
|
32
|
-
var _a, _b;
|
|
33
|
-
const tsConfigPath = (_a = process.env.NX_TSCONFIG_PATH) !== null && _a !== void 0 ? _a : (0, typescript_1.getRootTsConfigPath)();
|
|
34
|
-
const tsConfig = (0, typescript_1.readTsConfig)(tsConfigPath);
|
|
35
|
-
const tsconfigPathAliases = (_b = tsConfig.options) === null || _b === void 0 ? void 0 : _b.paths;
|
|
36
|
-
if (!tsconfigPathAliases) {
|
|
37
|
-
return workspaceLibraries;
|
|
38
|
-
}
|
|
39
|
-
const mappedLibraries = [];
|
|
40
|
-
for (const lib of workspaceLibraries) {
|
|
41
|
-
const sourceRoot = nodes[lib].data.sourceRoot;
|
|
42
|
-
let found = false;
|
|
43
|
-
for (const [key, value] of Object.entries(tsconfigPathAliases)) {
|
|
44
|
-
if (value.find((p) => p.startsWith(sourceRoot))) {
|
|
45
|
-
mappedLibraries.push(key);
|
|
46
|
-
found = true;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (!found) {
|
|
51
|
-
mappedLibraries.push(lib);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return mappedLibraries;
|
|
55
|
-
}
|
|
56
|
-
function getDependentPackagesForProject(projectGraph, name) {
|
|
57
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
const { npmPackages, workspaceLibraries } = collectDependencies(projectGraph, name);
|
|
59
|
-
return {
|
|
60
|
-
workspaceLibraries: mapWorkspaceLibrariesToTsConfigImport([...workspaceLibraries], projectGraph),
|
|
61
|
-
npmPackages: [...npmPackages],
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
function determineRemoteUrl(remote, projectGraph) {
|
|
8
|
+
function determineRemoteUrl(remote) {
|
|
66
9
|
var _a, _b, _c, _d, _e;
|
|
67
|
-
const remoteConfiguration =
|
|
10
|
+
const remoteConfiguration = (0, project_graph_1.readCachedProjectConfiguration)(remote);
|
|
68
11
|
const serveTarget = (_a = remoteConfiguration === null || remoteConfiguration === void 0 ? void 0 : remoteConfiguration.targets) === null || _a === void 0 ? void 0 : _a.serve;
|
|
69
12
|
if (!serveTarget) {
|
|
70
13
|
throw new Error(`Cannot automatically determine URL of remote (${remote}). Looked for property "host" in the project's "serve" target.\n
|
|
@@ -74,74 +17,6 @@ function determineRemoteUrl(remote, projectGraph) {
|
|
|
74
17
|
const port = (_e = (_d = serveTarget.options) === null || _d === void 0 ? void 0 : _d.port) !== null && _e !== void 0 ? _e : 4201;
|
|
75
18
|
return `${host.endsWith('/') ? host.slice(0, -1) : host}:${port}/remoteEntry.js`;
|
|
76
19
|
}
|
|
77
|
-
function mapRemotes(remotes, projectGraph) {
|
|
78
|
-
const mappedRemotes = {};
|
|
79
|
-
for (const remote of remotes) {
|
|
80
|
-
if (Array.isArray(remote)) {
|
|
81
|
-
let [remoteName, remoteLocation] = remote;
|
|
82
|
-
const remoteLocationExt = (0, path_1.extname)(remoteLocation);
|
|
83
|
-
mappedRemotes[remoteName] = ['.js', '.mjs'].includes(remoteLocationExt)
|
|
84
|
-
? remoteLocation
|
|
85
|
-
: `${remoteLocation.endsWith('/')
|
|
86
|
-
? remoteLocation.slice(0, -1)
|
|
87
|
-
: remoteLocation}/remoteEntry.js`;
|
|
88
|
-
}
|
|
89
|
-
else if (typeof remote === 'string') {
|
|
90
|
-
mappedRemotes[remote] = determineRemoteUrl(remote, projectGraph);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return mappedRemotes;
|
|
94
|
-
}
|
|
95
|
-
function applySharedFunction(sharedConfig, sharedFn) {
|
|
96
|
-
if (!sharedFn) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
for (const [libraryName, library] of Object.entries(sharedConfig)) {
|
|
100
|
-
const mappedDependency = sharedFn(libraryName, library);
|
|
101
|
-
if (mappedDependency === false) {
|
|
102
|
-
delete sharedConfig[libraryName];
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
else if (!mappedDependency) {
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
sharedConfig[libraryName] = mappedDependency;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
function addStringDependencyToSharedConfig(sharedConfig, dependency, projectGraph) {
|
|
112
|
-
var _a, _b, _c, _d;
|
|
113
|
-
if (projectGraph.nodes[dependency]) {
|
|
114
|
-
sharedConfig[dependency] = { requiredVersion: false };
|
|
115
|
-
}
|
|
116
|
-
else if ((_a = projectGraph.externalNodes) === null || _a === void 0 ? void 0 : _a[`npm:${dependency}`]) {
|
|
117
|
-
const pkgJson = (0, package_json_1.readRootPackageJson)();
|
|
118
|
-
const config = (0, webpack_utils_1.getNpmPackageSharedConfig)(dependency, (_c = (_b = pkgJson.dependencies) === null || _b === void 0 ? void 0 : _b[dependency]) !== null && _c !== void 0 ? _c : (_d = pkgJson.devDependencies) === null || _d === void 0 ? void 0 : _d[dependency]);
|
|
119
|
-
if (!config) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
sharedConfig[dependency] = config;
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
throw new Error(`The specified dependency "${dependency}" in the additionalShared configuration does not exist in the project graph. ` +
|
|
126
|
-
`Please check your additionalShared configuration and make sure you are including valid workspace projects or npm packages.`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
function applyAdditionalShared(sharedConfig, additionalShared, projectGraph) {
|
|
130
|
-
if (!additionalShared) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
for (const shared of additionalShared) {
|
|
134
|
-
if (typeof shared === 'string') {
|
|
135
|
-
addStringDependencyToSharedConfig(sharedConfig, shared, projectGraph);
|
|
136
|
-
}
|
|
137
|
-
else if (Array.isArray(shared)) {
|
|
138
|
-
sharedConfig[shared[0]] = shared[1];
|
|
139
|
-
}
|
|
140
|
-
else if (typeof shared === 'object') {
|
|
141
|
-
sharedConfig[shared.libraryName] = shared.sharedConfig;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
20
|
function withModuleFederation(options) {
|
|
146
21
|
var _a;
|
|
147
22
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -157,12 +32,12 @@ function withModuleFederation(options) {
|
|
|
157
32
|
if (!project) {
|
|
158
33
|
throw Error(`Cannot find project "${options.name}". Check that the name is correct in module-federation.config.js`);
|
|
159
34
|
}
|
|
160
|
-
const dependencies =
|
|
161
|
-
const sharedLibraries = (0,
|
|
162
|
-
const npmPackages = (0,
|
|
35
|
+
const dependencies = (0, devkit_1.getDependentPackagesForProject)(projectGraph, options.name);
|
|
36
|
+
const sharedLibraries = (0, devkit_1.shareWorkspaceLibraries)(dependencies.workspaceLibraries);
|
|
37
|
+
const npmPackages = (0, devkit_1.sharePackages)(dependencies.npmPackages);
|
|
163
38
|
const sharedDependencies = Object.assign(Object.assign({}, sharedLibraries.getLibraries()), npmPackages);
|
|
164
|
-
applySharedFunction(sharedDependencies, options.shared);
|
|
165
|
-
applyAdditionalShared(sharedDependencies, options.additionalShared, projectGraph);
|
|
39
|
+
(0, devkit_1.applySharedFunction)(sharedDependencies, options.shared);
|
|
40
|
+
(0, devkit_1.applyAdditionalShared)(sharedDependencies, options.additionalShared, projectGraph);
|
|
166
41
|
return (config) => {
|
|
167
42
|
config = reactWebpackConfig(config);
|
|
168
43
|
config.output.uniqueName = options.name;
|
|
@@ -173,7 +48,7 @@ function withModuleFederation(options) {
|
|
|
173
48
|
config.experiments = Object.assign(Object.assign({}, config.experiments), { outputModule: true });
|
|
174
49
|
const mappedRemotes = !options.remotes || options.remotes.length === 0
|
|
175
50
|
? {}
|
|
176
|
-
: mapRemotes(options.remotes,
|
|
51
|
+
: (0, devkit_1.mapRemotes)(options.remotes, 'js', determineRemoteUrl);
|
|
177
52
|
config.plugins.push(new ModuleFederationPlugin({
|
|
178
53
|
name: options.name,
|
|
179
54
|
library: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-module-federation.js","sourceRoot":"","sources":["../../../../../packages/react/src/module-federation/with-module-federation.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"with-module-federation.js","sour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,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,OAAO,EAAE,aAAa;gBACtB,MAAM,oBACD,kBAAkB,CACtB;aACF,CAAC,EACF,eAAe,CAAC,oBAAoB,EAAE,CACvC,CAAC;YAEF,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;;CACH;AA5ED,oDA4EC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { NormalModuleReplacementPlugin } from 'webpack';
|
|
2
|
-
import { SharedLibraryConfig } from './models';
|
|
3
|
-
export declare function shareWorkspaceLibraries(libraries: string[], tsConfigPath?: string): {
|
|
4
|
-
getAliases: () => {};
|
|
5
|
-
getLibraries: (eager?: boolean) => Record<string, SharedLibraryConfig>;
|
|
6
|
-
getReplacementPlugin: () => NormalModuleReplacementPlugin;
|
|
7
|
-
};
|
|
8
|
-
export declare function getNpmPackageSharedConfig(pkgName: string, version: string): SharedLibraryConfig | undefined;
|
|
9
|
-
export declare function sharePackages(packages: string[]): Record<string, SharedLibraryConfig>;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sharePackages = exports.getNpmPackageSharedConfig = exports.shareWorkspaceLibraries = void 0;
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
const webpack_1 = require("webpack");
|
|
6
|
-
const devkit_1 = require("@nrwl/devkit");
|
|
7
|
-
const path_1 = require("path");
|
|
8
|
-
const typescript_1 = require("@nrwl/workspace/src/utilities/typescript");
|
|
9
|
-
const package_json_1 = require("./package-json");
|
|
10
|
-
function shareWorkspaceLibraries(libraries, tsConfigPath) {
|
|
11
|
-
var _a, _b;
|
|
12
|
-
if (tsConfigPath === void 0) { tsConfigPath = (_a = process.env.NX_TSCONFIG_PATH) !== null && _a !== void 0 ? _a : (0, typescript_1.getRootTsConfigPath)(); }
|
|
13
|
-
if (!(0, fs_1.existsSync)(tsConfigPath)) {
|
|
14
|
-
throw new Error(`NX: TsConfig Path for workspace libraries does not exist! (${tsConfigPath})`);
|
|
15
|
-
}
|
|
16
|
-
const tsConfig = (0, typescript_1.readTsConfig)(tsConfigPath);
|
|
17
|
-
const tsconfigPathAliases = (_b = tsConfig.options) === null || _b === void 0 ? void 0 : _b.paths;
|
|
18
|
-
if (!tsconfigPathAliases) {
|
|
19
|
-
return {
|
|
20
|
-
getAliases: () => [],
|
|
21
|
-
getLibraries: () => ({}),
|
|
22
|
-
getReplacementPlugin: () => new webpack_1.NormalModuleReplacementPlugin(/./, () => { }),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
const pathMappings = [];
|
|
26
|
-
for (const [key, paths] of Object.entries(tsconfigPathAliases)) {
|
|
27
|
-
if (libraries && libraries.includes(key)) {
|
|
28
|
-
const pathToLib = (0, path_1.normalize)((0, path_1.join)(devkit_1.workspaceRoot, paths[0]));
|
|
29
|
-
pathMappings.push({
|
|
30
|
-
name: key,
|
|
31
|
-
path: pathToLib,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
getAliases: () => pathMappings.reduce((aliases, library) => (Object.assign(Object.assign({}, aliases), { [library.name]: library.path })), {}),
|
|
37
|
-
getLibraries: (eager) => pathMappings.reduce((libraries, library) => (Object.assign(Object.assign({}, libraries), { [library.name]: { requiredVersion: false, eager } })), {}),
|
|
38
|
-
getReplacementPlugin: () => new webpack_1.NormalModuleReplacementPlugin(/./, (req) => {
|
|
39
|
-
if (!req.request.startsWith('.')) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const from = req.context;
|
|
43
|
-
const to = (0, path_1.normalize)((0, path_1.join)(req.context, req.request));
|
|
44
|
-
for (const library of pathMappings) {
|
|
45
|
-
const libFolder = (0, path_1.normalize)((0, path_1.dirname)(library.path));
|
|
46
|
-
if (!from.startsWith(libFolder) && to.startsWith(libFolder)) {
|
|
47
|
-
req.request = library.name;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
exports.shareWorkspaceLibraries = shareWorkspaceLibraries;
|
|
54
|
-
function getNpmPackageSharedConfig(pkgName, version) {
|
|
55
|
-
if (!version) {
|
|
56
|
-
devkit_1.logger.warn(`Could not find a version for "${pkgName}" in the root "package.json" ` +
|
|
57
|
-
'when collecting shared packages for the Module Federation setup. ' +
|
|
58
|
-
'The package will not be shared.');
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
return { singleton: true, requiredVersion: version };
|
|
62
|
-
}
|
|
63
|
-
exports.getNpmPackageSharedConfig = getNpmPackageSharedConfig;
|
|
64
|
-
function sharePackages(packages) {
|
|
65
|
-
const pkgJson = (0, package_json_1.readRootPackageJson)();
|
|
66
|
-
return packages.reduce((shared, pkg) => {
|
|
67
|
-
var _a, _b, _c;
|
|
68
|
-
const config = getNpmPackageSharedConfig(pkg, (_b = (_a = pkgJson.dependencies) === null || _a === void 0 ? void 0 : _a[pkg]) !== null && _b !== void 0 ? _b : (_c = pkgJson.devDependencies) === null || _c === void 0 ? void 0 : _c[pkg]);
|
|
69
|
-
if (config) {
|
|
70
|
-
shared[pkg] = config;
|
|
71
|
-
}
|
|
72
|
-
return shared;
|
|
73
|
-
}, {});
|
|
74
|
-
}
|
|
75
|
-
exports.sharePackages = sharePackages;
|
|
76
|
-
//# sourceMappingURL=webpack-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"webpack-utils.js","sourceRoot":"","sources":["../../../../../packages/react/src/module-federation/webpack-utils.ts"],"names":[],"mappings":";;;AAAA,2BAAgC;AAChC,qCAAwD;AACxD,yCAAqD;AACrD,+BAAgD;AAEhD,yEAGkD;AAElD,iDAAqD;AAErD,SAAgB,uBAAuB,CACrC,SAAmB,EACnB,YAAoE;;iCAApE,EAAA,qBAAe,OAAO,CAAC,GAAG,CAAC,gBAAgB,mCAAI,IAAA,gCAAmB,GAAE;IAEpE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