@nx/module-federation 22.2.0-canary.20251208-300493e → 22.3.0-canary.20251209-6092031
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/package.json +5 -5
- package/src/utils/share.d.ts.map +1 -1
- package/src/utils/share.js +50 -29
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/module-federation",
|
|
3
3
|
"description": "The Nx Plugin for Module Federation contains executors and utilities that support building applications using Module Federation.",
|
|
4
|
-
"version": "22.
|
|
4
|
+
"version": "22.3.0-canary.20251209-6092031",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"@module-federation/enhanced": "^0.21.2",
|
|
28
28
|
"@module-federation/node": "^2.7.21",
|
|
29
29
|
"@module-federation/sdk": "^0.21.2",
|
|
30
|
-
"@nx/devkit": "22.
|
|
31
|
-
"@nx/js": "22.
|
|
32
|
-
"@nx/web": "22.
|
|
30
|
+
"@nx/devkit": "22.3.0-canary.20251209-6092031",
|
|
31
|
+
"@nx/js": "22.3.0-canary.20251209-6092031",
|
|
32
|
+
"@nx/web": "22.3.0-canary.20251209-6092031",
|
|
33
33
|
"@rspack/core": "^1.5.2",
|
|
34
34
|
"express": "^4.21.2",
|
|
35
35
|
"http-proxy-middleware": "^3.0.5",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"webpack": "^5.101.3"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"nx": "22.
|
|
41
|
+
"nx": "22.3.0-canary.20251209-6092031"
|
|
42
42
|
},
|
|
43
43
|
"nx-migrations": {
|
|
44
44
|
"migrations": "./migrations.json"
|
package/src/utils/share.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"share.d.ts","sourceRoot":"","sources":["../../../../../packages/module-federation/src/utils/share.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,4BAA4B,EAC5B,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAQlE,OAAO,EACL,KAAK,YAAY,EAMlB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"share.d.ts","sourceRoot":"","sources":["../../../../../packages/module-federation/src/utils/share.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,4BAA4B,EAC5B,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAQlE,OAAO,EACL,KAAK,YAAY,EAMlB,MAAM,YAAY,CAAC;AA0DpB;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,gBAAgB,EAAE,EACjC,YAAY,SAAwD,EACpE,OAAO,GAAE,QAAQ,GAAG,SAAoB,GACvC,4BAA4B,CA4L9B;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACd,mBAAmB,GAAG,SAAS,CAwBjC;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAAE,GACjB,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAqBrC;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,EACjD,QAAQ,EAAE,cAAc,GAAG,SAAS,GACnC,IAAI,CAgBN;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,EACjD,gBAAgB,EAAE,sBAAsB,GAAG,SAAS,EACpD,YAAY,EAAE,YAAY,GACzB,IAAI,CAcN"}
|
package/src/utils/share.js
CHANGED
|
@@ -12,6 +12,44 @@ const secondary_entry_points_1 = require("./secondary-entry-points");
|
|
|
12
12
|
const devkit_1 = require("@nx/devkit");
|
|
13
13
|
const fs_1 = require("fs");
|
|
14
14
|
const core_1 = require("@rspack/core");
|
|
15
|
+
/**
|
|
16
|
+
* Checks if a version string is a workspace protocol version that needs normalization.
|
|
17
|
+
* This includes pnpm workspace protocol (workspace:*), file: protocol, or bare *.
|
|
18
|
+
*/
|
|
19
|
+
function isWorkspaceProtocolVersion(version) {
|
|
20
|
+
if (!version)
|
|
21
|
+
return false;
|
|
22
|
+
return (version === '*' ||
|
|
23
|
+
version.startsWith('workspace:') ||
|
|
24
|
+
version.startsWith('file:'));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Normalizes workspace protocol versions (workspace:*, workspace:^, *, file:) to actual semver versions
|
|
28
|
+
* by looking up the version from the library's package.json.
|
|
29
|
+
*
|
|
30
|
+
* @param version - The version string that may contain workspace protocol
|
|
31
|
+
* @param libraryName - The name of the library to look up
|
|
32
|
+
* @param workspaceLibs - The workspace libraries to search in
|
|
33
|
+
* @returns The normalized version string, or null if it cannot be resolved
|
|
34
|
+
*/
|
|
35
|
+
function normalizeWorkspaceProtocolVersion(version, libraryName, workspaceLibs) {
|
|
36
|
+
if (!isWorkspaceProtocolVersion(version)) {
|
|
37
|
+
return version;
|
|
38
|
+
}
|
|
39
|
+
// Look up the actual version from the library's package.json
|
|
40
|
+
const workspaceLib = workspaceLibs.find((lib) => lib.importKey === libraryName);
|
|
41
|
+
if (workspaceLib) {
|
|
42
|
+
const libPackageJsonPath = (0, path_1.join)(devkit_1.workspaceRoot, workspaceLib.root, 'package.json');
|
|
43
|
+
if ((0, fs_1.existsSync)(libPackageJsonPath)) {
|
|
44
|
+
const libPkgJson = (0, devkit_1.readJsonFile)(libPackageJsonPath);
|
|
45
|
+
if (libPkgJson?.version) {
|
|
46
|
+
return libPkgJson.version;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Can't resolve the actual version, return null to indicate no version requirement
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
15
53
|
/**
|
|
16
54
|
* Build an object of functions to be used with the ModuleFederationPlugin to
|
|
17
55
|
* share Nx Workspace Libraries between Hosts and Remotes.
|
|
@@ -80,6 +118,8 @@ function shareWorkspaceLibraries(workspaceLibs, tsConfigPath = process.env.NX_TS
|
|
|
80
118
|
let version = pkgJson
|
|
81
119
|
? (0, devkit_1.getDependencyVersionFromPackageJson)(library.name, devkit_1.workspaceRoot, pkgJson)
|
|
82
120
|
: null;
|
|
121
|
+
// Normalize workspace protocol versions (workspace:*, workspace:^, *, file:)
|
|
122
|
+
version = normalizeWorkspaceProtocolVersion(version, library.name, workspaceLibs);
|
|
83
123
|
if (!version && workspaceLibs.length > 0) {
|
|
84
124
|
const workspaceLib = workspaceLibs.find((lib) => lib.importKey === library.name);
|
|
85
125
|
const libPackageJsonPath = workspaceLib
|
|
@@ -110,35 +150,8 @@ function shareWorkspaceLibraries(workspaceLibs, tsConfigPath = process.env.NX_TS
|
|
|
110
150
|
for (const libraryName of workspaceLibrariesAsDeps) {
|
|
111
151
|
let version = pkgJson?.dependencies?.[libraryName] ??
|
|
112
152
|
pkgJson?.devDependencies?.[libraryName];
|
|
113
|
-
// Normalize workspace protocol versions (workspace:*, workspace:^, *,
|
|
114
|
-
|
|
115
|
-
(version === '*' ||
|
|
116
|
-
version.startsWith('workspace:') ||
|
|
117
|
-
version.startsWith('file:'))) {
|
|
118
|
-
// Look up the actual version from the library's package.json
|
|
119
|
-
const workspaceLib = workspaceLibs.find((lib) => lib.importKey === libraryName);
|
|
120
|
-
if (workspaceLib) {
|
|
121
|
-
const libPackageJsonPath = (0, path_1.join)(devkit_1.workspaceRoot, workspaceLib.root, 'package.json');
|
|
122
|
-
if ((0, fs_1.existsSync)(libPackageJsonPath)) {
|
|
123
|
-
const libPkgJson = (0, devkit_1.readJsonFile)(libPackageJsonPath);
|
|
124
|
-
if (libPkgJson?.version) {
|
|
125
|
-
version = libPkgJson.version;
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
// Library has no version, treat as no version requirement
|
|
129
|
-
version = null;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
// Can't find library package.json, treat as no version requirement
|
|
134
|
-
version = null;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
// Can't find workspace library, treat as no version requirement
|
|
139
|
-
version = null;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
153
|
+
// Normalize workspace protocol versions (workspace:*, workspace:^, *, file:)
|
|
154
|
+
version = normalizeWorkspaceProtocolVersion(version, libraryName, workspaceLibs);
|
|
142
155
|
libraries[libraryName] = {
|
|
143
156
|
...(version
|
|
144
157
|
? { requiredVersion: version, singleton: true }
|
|
@@ -186,6 +199,14 @@ function getNpmPackageSharedConfig(pkgName, version) {
|
|
|
186
199
|
'The package will not be shared.');
|
|
187
200
|
return undefined;
|
|
188
201
|
}
|
|
202
|
+
// Warn if a workspace protocol version is passed - this indicates the package
|
|
203
|
+
// should be configured as a workspace library instead of using sharePackages
|
|
204
|
+
if (isWorkspaceProtocolVersion(version)) {
|
|
205
|
+
devkit_1.logger.warn(`Package "${pkgName}" has a workspace protocol version "${version}" which cannot be used ` +
|
|
206
|
+
'for Module Federation. For workspace libraries, use the workspace library configuration ' +
|
|
207
|
+
'instead of sharePackages. The package will not be shared.');
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
189
210
|
return { singleton: true, strictVersion: true, requiredVersion: version };
|
|
190
211
|
}
|
|
191
212
|
/**
|