@module-federation/node 2.0.0 → 2.0.2-beta.0
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 +37 -0
- package/README.md +27 -0
- package/jest.config.d.ts +11 -0
- package/jest.config.js +19 -0
- package/jest.config.js.map +1 -0
- package/package.json +3 -2
- package/src/filesystem/DynamicFilesystemRuntimeModule.d.ts +6 -0
- package/src/filesystem/DynamicFilesystemRuntimeModule.js +30 -0
- package/src/filesystem/DynamicFilesystemRuntimeModule.js.map +1 -0
- package/src/filesystem/stratagies.d.ts +11 -0
- package/src/filesystem/stratagies.js +105 -0
- package/src/filesystem/stratagies.js.map +1 -0
- package/src/plugins/ChunkCorrelationPlugin.js +1 -0
- package/src/plugins/ChunkCorrelationPlugin.js.map +1 -1
- package/src/plugins/CommonJsChunkLoadingPlugin.js +29 -2
- package/src/plugins/CommonJsChunkLoadingPlugin.js.map +1 -1
- package/src/plugins/{LoadFileChunkLoadingRuntimeModule.d.ts → DynamicFilesystemChunkLoadingRuntimeModule.d.ts} +8 -4
- package/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js +145 -0
- package/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js.map +1 -0
- package/src/plugins/FederationModuleInfoRuntimeModule.d.ts +9 -0
- package/src/plugins/FederationModuleInfoRuntimeModule.js +55 -0
- package/src/plugins/FederationModuleInfoRuntimeModule.js.map +1 -0
- package/src/plugins/NodeFederationPlugin.d.ts +45 -2
- package/src/plugins/NodeFederationPlugin.js +57 -93
- package/src/plugins/NodeFederationPlugin.js.map +1 -1
- package/src/plugins/RemotePublicPathRuntimeModule.d.ts +10 -0
- package/src/plugins/RemotePublicPathRuntimeModule.js +86 -0
- package/src/plugins/RemotePublicPathRuntimeModule.js.map +1 -0
- package/src/plugins/StreamingTargetPlugin.d.ts +16 -0
- package/src/plugins/StreamingTargetPlugin.js +17 -7
- package/src/plugins/StreamingTargetPlugin.js.map +1 -1
- package/src/plugins/UniversalFederationPlugin.d.ts +25 -0
- package/src/plugins/UniversalFederationPlugin.js +20 -1
- package/src/plugins/UniversalFederationPlugin.js.map +1 -1
- package/src/plugins/parts.d.ts +50 -0
- package/src/plugins/parts.js +316 -0
- package/src/plugins/parts.js.map +1 -0
- package/src/plugins/LoadFileChunkLoadingRuntimeModule.js +0 -434
- package/src/plugins/LoadFileChunkLoadingRuntimeModule.js.map +0 -1
- package/src/plugins/loadScript.d.ts +0 -7
- package/src/plugins/loadScript.js +0 -116
- package/src/plugins/loadScript.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DynamicFilesystemChunkLoadingRuntimeModule.js","sourceRoot":"","sources":["../../../../../packages/node/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.ts"],"names":[],"mappings":";;;;;AAIA,qCAAmE;AACnE,4DAA0D;AAC1D,qCAAyC;AACzC,mGAA2E;AAC3E,mCASiB;AACjB,yDAIkC;AAoBlC,yBAAyB;AACzB,mBAAmB;AACnB,gCAAgC;AAChC,qFAAqF;AACrF,qFAAqF;AACrF,8EAA8E;AAC9E,4EAA4E;AAC5E,oHAAoH;AACpH,gBAAgB;AAChB,YAAY;AACZ,YAAY;AACZ,UAAU;AACV,MAAM;AACN,IAAI;AACJ,MAAM,0CAA2C,SAAQ,uBAAa;IAQpE,YACE,mBAAgC,EAChC,OAA0D,EAC1D,mBAAwC;QAExC,KAAK,CAAC,wBAAwB,EAAE,uBAAa,CAAC,YAAY,CAAC,CAAC;QAT9D,UAAK,GAAG;YACN,YAAY,EAAE,IAAI,2BAAiB,CAAC,CAAC,QAAQ,CAAC,CAAC;SAChD,CAAC;QAQA,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAE/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;IACjD,CAAC;IAED;;;;;OAKG;IACH,gBAAgB,CAAC,KAAY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B,EAAC,eAAe,CAAC;gBACrC,CAAC,CAAC,mCAAmC;YACvC,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,wBAAc,CAAC,mBAAmB,CAAC;gBAC9D,CAAC,CAAC,IAAA,2BAAmB,EACjB,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,wBAAc,CAAC,mBAAmB,CAAC,EAChE,EAAE,EACF,YAAY,EACZ,aAAa,EACb,OAAO,EACP,IAAI,CACL;gBACH,CAAC,CAAC,qBAAqB;YACzB,EAAE;YACF,IAAA,wCAAgC,EAC9B,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,wBAAc,CAAC,oBAAoB,CAAC,EACjE,IAAI,CAAC,OAAO,CAAC,KAAK,CACnB;YACD,EAAE;YACF,IAAA,uBAAe,EACb,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,wBAAc,CAAC,yBAAyB,CAAC,EACtE,aAAa,CACd;YACD,EAAE;YACF,IAAA,+BAAuB,EACrB,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,wBAAc,CAAC,mBAAmB,CAAC,EAChE,aAAa,CACd;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAED,kBAAe,0CAA0C,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const webpack_1 = require("webpack");
|
|
4
|
+
const webpack_2 = require("webpack");
|
|
5
|
+
class FederationModuleInfoRuntimeModule extends webpack_1.RuntimeModule {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('federation module info runtime', webpack_1.RuntimeModule.STAGE_BASIC);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* @returns {string} runtime code
|
|
11
|
+
*/
|
|
12
|
+
generate() {
|
|
13
|
+
return webpack_2.Template.asString([
|
|
14
|
+
`${webpack_1.RuntimeGlobals.require}.federation = {`,
|
|
15
|
+
webpack_2.Template.indent([
|
|
16
|
+
`cache: {},`,
|
|
17
|
+
`remotes: {},`,
|
|
18
|
+
`moduleInfo: { },`,
|
|
19
|
+
]),
|
|
20
|
+
`};`,
|
|
21
|
+
// `if (!globalThis.__remote_scopes__) {`,
|
|
22
|
+
webpack_2.Template.indent([
|
|
23
|
+
'// backward compatible global proxy',
|
|
24
|
+
`globalThis.__remote_scope__ = globalThis.__remote_scope__ || new Proxy(${webpack_1.RuntimeGlobals.require}.federation, {`,
|
|
25
|
+
webpack_2.Template.indent([
|
|
26
|
+
`get: function(target, prop, receiver) {`,
|
|
27
|
+
'var result;',
|
|
28
|
+
webpack_2.Template.indent([
|
|
29
|
+
`if (prop === '_config') {`,
|
|
30
|
+
webpack_2.Template.indent([`result = ${webpack_1.RuntimeGlobals.require}.federation.remotes;`]),
|
|
31
|
+
`} else {`,
|
|
32
|
+
webpack_2.Template.indent([`result = ${webpack_1.RuntimeGlobals.require}.federation.cache[prop];`]),
|
|
33
|
+
`}`,
|
|
34
|
+
'return result;'
|
|
35
|
+
]),
|
|
36
|
+
`},`,
|
|
37
|
+
`set: function(target, prop, value) {`,
|
|
38
|
+
webpack_2.Template.indent([
|
|
39
|
+
`if (prop === '_config') {`,
|
|
40
|
+
webpack_2.Template.indent([`${webpack_1.RuntimeGlobals.require}.federation.remotes = value;`]),
|
|
41
|
+
`} else {`,
|
|
42
|
+
webpack_2.Template.indent([`${webpack_1.RuntimeGlobals.require}.federation.cache[prop] = value;`]),
|
|
43
|
+
`}`,
|
|
44
|
+
`return true;`,
|
|
45
|
+
]),
|
|
46
|
+
`}`,
|
|
47
|
+
]),
|
|
48
|
+
`});`,
|
|
49
|
+
]),
|
|
50
|
+
// `}`,
|
|
51
|
+
]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.default = FederationModuleInfoRuntimeModule;
|
|
55
|
+
//# sourceMappingURL=FederationModuleInfoRuntimeModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FederationModuleInfo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,CAAC;YACF,OAAO;SACR,CAAC,CAAC;IACL,CAAC;CACF;AAED,kBAAe,iCAAiC,CAAC"}
|
|
@@ -1,20 +1,63 @@
|
|
|
1
1
|
import type { Compiler, container } from 'webpack';
|
|
2
2
|
import type { ModuleFederationPluginOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for NodeFederationOptions which extends ModuleFederationPluginOptions
|
|
5
|
+
* @interface
|
|
6
|
+
* @property {Record<string, unknown>} experiments - Optional experiments configuration
|
|
7
|
+
* @property {boolean} debug - Optional debug flag
|
|
8
|
+
*/
|
|
3
9
|
interface NodeFederationOptions extends ModuleFederationPluginOptions {
|
|
4
10
|
experiments?: Record<string, unknown>;
|
|
5
11
|
debug?: boolean;
|
|
12
|
+
useRemoteSideloader?: boolean;
|
|
6
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Interface for Context
|
|
16
|
+
* @interface
|
|
17
|
+
* @property {typeof container.ModuleFederationPlugin} ModuleFederationPlugin - Optional ModuleFederationPlugin
|
|
18
|
+
*/
|
|
7
19
|
interface Context {
|
|
8
20
|
ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;
|
|
9
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* This function iterates over all remotes and checks if they
|
|
24
|
+
* are internal or not. If it's an internal remote then we add it to our new object
|
|
25
|
+
* with a key of the name of the remote and value as internal. If it's not an internal
|
|
26
|
+
* remote then we check if there is a '@' in that string which likely means it is a global @ url
|
|
27
|
+
*
|
|
28
|
+
* @param {Record<string, any>} remotes - The remotes to parse.
|
|
29
|
+
* @returns {Record<string, string>} - The parsed remotes.
|
|
30
|
+
* */
|
|
10
31
|
export declare const parseRemotes: (remotes: Record<string, any>) => Record<string, string>;
|
|
11
|
-
|
|
12
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Parses the remote syntax and returns a formatted string if the remote includes '@' and does not start with 'window', 'global', or 'globalThis'.
|
|
34
|
+
* Otherwise, it returns the original remote string.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} remote - The remote string to parse.
|
|
37
|
+
* @returns {string} - The parsed remote string or the original remote string.
|
|
38
|
+
* @throws {Error} - Throws an error if the remote is not a string.
|
|
39
|
+
*/
|
|
40
|
+
export declare const parseRemoteSyntax: (remote: any) => string;
|
|
41
|
+
/**
|
|
42
|
+
* Class representing a NodeFederationPlugin.
|
|
43
|
+
* @class
|
|
44
|
+
*/
|
|
13
45
|
declare class NodeFederationPlugin {
|
|
14
46
|
private _options;
|
|
15
47
|
private context;
|
|
16
48
|
private experiments;
|
|
49
|
+
/**
|
|
50
|
+
* Create a NodeFederationPlugin.
|
|
51
|
+
* @constructor
|
|
52
|
+
* @param {NodeFederationOptions} options - The options for the NodeFederationPlugin
|
|
53
|
+
* @param {Context} context - The context for the NodeFederationPlugin
|
|
54
|
+
*/
|
|
17
55
|
constructor({ experiments, debug, ...options }: NodeFederationOptions, context: Context);
|
|
56
|
+
/**
|
|
57
|
+
* Apply method for the NodeFederationPlugin class.
|
|
58
|
+
* @method
|
|
59
|
+
* @param {Compiler} compiler - The webpack compiler.
|
|
60
|
+
*/
|
|
18
61
|
apply(compiler: Compiler): void;
|
|
19
62
|
}
|
|
20
63
|
export default NodeFederationPlugin;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseRemoteSyntax = exports.
|
|
3
|
+
exports.parseRemoteSyntax = exports.parseRemotes = void 0;
|
|
4
4
|
const pure_1 = require("@module-federation/utilities/src/utils/pure");
|
|
5
5
|
// possible remote evaluators
|
|
6
6
|
// this depends on the chunk format selected.
|
|
@@ -10,121 +10,85 @@ const pure_1 = require("@module-federation/utilities/src/utils/pure");
|
|
|
10
10
|
// const remote = eval('let exports = {};' + scriptContent + 'exports');
|
|
11
11
|
// commonjs-module, ideal since it returns a commonjs module format
|
|
12
12
|
// const remote = eval(scriptContent + 'module.exports')
|
|
13
|
-
|
|
14
|
-
This
|
|
15
|
-
are internal or not If it
|
|
16
|
-
with a key of the name of the remote and value as internal If it
|
|
17
|
-
remote then we check if there is a in that string which means
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
/**
|
|
14
|
+
* This function iterates over all remotes and checks if they
|
|
15
|
+
* are internal or not. If it's an internal remote then we add it to our new object
|
|
16
|
+
* with a key of the name of the remote and value as internal. If it's not an internal
|
|
17
|
+
* remote then we check if there is a '@' in that string which likely means it is a global @ url
|
|
18
|
+
*
|
|
19
|
+
* @param {Record<string, any>} remotes - The remotes to parse.
|
|
20
|
+
* @returns {Record<string, string>} - The parsed remotes.
|
|
21
|
+
* */
|
|
22
|
+
const parseRemotes = (remotes) => {
|
|
23
|
+
if (!remotes || typeof remotes !== 'object') {
|
|
24
|
+
throw new Error('remotes must be an object');
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
return Object.entries(remotes).reduce((acc, [key, value]) => {
|
|
27
|
+
const isInternal = value.startsWith('internal ');
|
|
28
|
+
const isGlobal = value.includes('@') && !['window.', 'global.', 'globalThis.', 'self.'].some(prefix => value.startsWith(prefix));
|
|
29
|
+
acc[key] = isInternal || !isGlobal ? value : (0, exports.parseRemoteSyntax)(value);
|
|
27
30
|
return acc;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return acc;
|
|
31
|
-
}, {});
|
|
31
|
+
}, {});
|
|
32
|
+
};
|
|
32
33
|
exports.parseRemotes = parseRemotes;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (typeof globalThis.__remote_scope__[${JSON.stringify(global)}] !== 'undefined') return resolve(globalThis.__remote_scope__[${JSON.stringify(global)}]);
|
|
43
|
-
globalThis.__remote_scope__._config[${JSON.stringify(global)}] = ${JSON.stringify(url)};
|
|
44
|
-
var __webpack_error__ = new Error();
|
|
45
|
-
|
|
46
|
-
__webpack_require__.l(
|
|
47
|
-
${JSON.stringify(url)},
|
|
48
|
-
function (event) {
|
|
49
|
-
if (typeof globalThis.__remote_scope__[${JSON.stringify(global)}] !== 'undefined') return resolve(globalThis.__remote_scope__[${JSON.stringify(global)}]);
|
|
50
|
-
var realSrc = event && event.target && event.target.src;
|
|
51
|
-
__webpack_error__.message = 'Loading script failed.\\n(' + event.message + ': ' + realSrc + ')';
|
|
52
|
-
__webpack_error__.name = 'ScriptExternalLoadError';
|
|
53
|
-
__webpack_error__.stack = event.stack;
|
|
54
|
-
reject(__webpack_error__);
|
|
55
|
-
},
|
|
56
|
-
${JSON.stringify(global)},
|
|
57
|
-
);
|
|
58
|
-
}).catch((e)=> {
|
|
59
|
-
console.error(${JSON.stringify(global)}, 'is offline, returning fake remote');
|
|
60
|
-
console.error(e);
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
fake: true,
|
|
64
|
-
get: (arg) => {
|
|
65
|
-
console.warn('faking', arg, 'module on', ${JSON.stringify(global)});
|
|
66
|
-
|
|
67
|
-
return Promise.resolve(() => {
|
|
68
|
-
return () => null
|
|
69
|
-
});
|
|
70
|
-
},
|
|
71
|
-
init: () => {
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}).then(function (remote) {
|
|
75
|
-
if(remote.fake) {
|
|
76
|
-
return remote;
|
|
77
|
-
}
|
|
78
|
-
return remote;
|
|
79
|
-
})`;
|
|
80
|
-
exports.generateRemoteTemplate = generateRemoteTemplate;
|
|
81
|
-
/*
|
|
82
|
-
This code is taking the remote string and splitting it into two parts The first
|
|
83
|
-
part of the split is going to be a url which will be used in generate Remote Template
|
|
84
|
-
function The second part of the split is going to be a global variable name which
|
|
85
|
-
will also be used in generate Remote Template function If there\'s no global variable
|
|
86
|
-
name then we\'ll use default as default value for that parameter
|
|
87
|
-
*/
|
|
34
|
+
/**
|
|
35
|
+
* Parses the remote syntax and returns a formatted string if the remote includes '@' and does not start with 'window', 'global', or 'globalThis'.
|
|
36
|
+
* Otherwise, it returns the original remote string.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} remote - The remote string to parse.
|
|
39
|
+
* @returns {string} - The parsed remote string or the original remote string.
|
|
40
|
+
* @throws {Error} - Throws an error if the remote is not a string.
|
|
41
|
+
*/
|
|
88
42
|
const parseRemoteSyntax = (remote) => {
|
|
89
|
-
if (typeof remote
|
|
43
|
+
if (typeof remote !== 'string') {
|
|
44
|
+
throw new Error('remote must be a string');
|
|
45
|
+
}
|
|
46
|
+
if (remote.includes('@')) {
|
|
90
47
|
const [url, global] = (0, pure_1.extractUrlAndGlobal)(remote);
|
|
91
|
-
|
|
48
|
+
if (!['window.', 'global.', 'globalThis.'].some(prefix => global.startsWith(prefix))) {
|
|
49
|
+
return `globalThis.__remote_scope__.${global}@${url}`;
|
|
50
|
+
}
|
|
92
51
|
}
|
|
93
52
|
return remote;
|
|
94
53
|
};
|
|
95
54
|
exports.parseRemoteSyntax = parseRemoteSyntax;
|
|
55
|
+
/**
|
|
56
|
+
* Class representing a NodeFederationPlugin.
|
|
57
|
+
* @class
|
|
58
|
+
*/
|
|
96
59
|
class NodeFederationPlugin {
|
|
60
|
+
/**
|
|
61
|
+
* Create a NodeFederationPlugin.
|
|
62
|
+
* @constructor
|
|
63
|
+
* @param {NodeFederationOptions} options - The options for the NodeFederationPlugin
|
|
64
|
+
* @param {Context} context - The context for the NodeFederationPlugin
|
|
65
|
+
*/
|
|
97
66
|
constructor({ experiments, debug, ...options }, context) {
|
|
98
67
|
this._options = options || {};
|
|
99
68
|
this.context = context || {};
|
|
100
69
|
this.experiments = experiments || {};
|
|
101
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Apply method for the NodeFederationPlugin class.
|
|
73
|
+
* @method
|
|
74
|
+
* @param {Compiler} compiler - The webpack compiler.
|
|
75
|
+
*/
|
|
102
76
|
apply(compiler) {
|
|
103
77
|
// When used with Next.js, context is needed to use Next.js webpack
|
|
104
78
|
const { webpack } = compiler;
|
|
105
79
|
const pluginOptions = {
|
|
106
80
|
...this._options,
|
|
107
|
-
remotes: (0, exports.parseRemotes)(this._options.remotes
|
|
81
|
+
remotes: this._options.remotes ? (0, exports.parseRemotes)(this._options.remotes) : {},
|
|
108
82
|
};
|
|
83
|
+
//TODO can use import meta mock object but need to update data structure of remote_scope
|
|
84
|
+
if (compiler.options && compiler.options.output) {
|
|
85
|
+
compiler.options.output.importMetaName = 'remoteContainerRegistry';
|
|
86
|
+
}
|
|
109
87
|
const chunkFileName = compiler.options?.output?.chunkFilename;
|
|
110
88
|
const uniqueName = compiler?.options?.output?.uniqueName || this._options.name;
|
|
111
|
-
if (typeof chunkFileName === 'string') {
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
'[contenthash]',
|
|
115
|
-
'[fullHash]',
|
|
116
|
-
uniqueName,
|
|
117
|
-
];
|
|
118
|
-
if (
|
|
119
|
-
//@ts-ignore
|
|
120
|
-
!requiredSubstrings.some((substring) =>
|
|
121
|
-
//@ts-ignore
|
|
122
|
-
chunkFileName.includes(substring))) {
|
|
123
|
-
const suffix = compiler.options.mode === 'development'
|
|
124
|
-
? `.[chunkhash].js`
|
|
125
|
-
: `.[chunkhash].js`;
|
|
126
|
-
compiler.options.output.chunkFilename = chunkFileName.replace('.js', suffix);
|
|
127
|
-
}
|
|
89
|
+
if (typeof chunkFileName === 'string' && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
90
|
+
const suffix = `-[chunkhash].js`;
|
|
91
|
+
compiler.options.output.chunkFilename = chunkFileName.replace('.js', suffix);
|
|
128
92
|
}
|
|
129
93
|
new (this.context.ModuleFederationPlugin ||
|
|
130
94
|
(webpack && webpack.container.ModuleFederationPlugin) ||
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeFederationPlugin.js","sourceRoot":"","sources":["../../../../../packages/node/src/plugins/NodeFederationPlugin.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;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MAAM,CAAC,cAAc,GAAG,yBAAyB,CAAC;SACpE;QAED,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC;QAC9D,MAAM,UAAU,GACd,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QAE9D,IAAI,OAAO,aAAa,KAAK,QAAQ,IAAI,UAAU,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;YAC1F,MAAM,MAAM,GAAG,iBAAiB,CAAC;YACjC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,GAAG,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;SAC9E;QAED,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB;YACtC,CAAC,OAAO,IAAI,OAAO,CAAC,SAAS,CAAC,sBAAsB,CAAC;YACrD,OAAO,CAAC,8CAA8C,CAAC,CAAC,CACxD,aAAa,CACd,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;CACF;AAED,kBAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default AutoPublicPathRuntimeModule;
|
|
2
|
+
declare class AutoPublicPathRuntimeModule extends RuntimeModule {
|
|
3
|
+
constructor(options: any);
|
|
4
|
+
options: any;
|
|
5
|
+
/**
|
|
6
|
+
* @returns {string} runtime code
|
|
7
|
+
*/
|
|
8
|
+
generate(): string;
|
|
9
|
+
}
|
|
10
|
+
import { RuntimeModule } from "webpack";
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const webpack_1 = require("webpack");
|
|
4
|
+
const identifier_1 = require("webpack/lib/util/identifier");
|
|
5
|
+
class AutoPublicPathRuntimeModule extends webpack_1.RuntimeModule {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super("publicPath", webpack_1.RuntimeModule.STAGE_BASIC + 1);
|
|
8
|
+
this.options = options;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @returns {string} runtime code
|
|
12
|
+
*/
|
|
13
|
+
generate() {
|
|
14
|
+
const { compilation } = this;
|
|
15
|
+
const { scriptType, path, publicPath, importMetaName, uniqueName } = compilation.outputOptions;
|
|
16
|
+
const getPath = () => {
|
|
17
|
+
return compilation.getPath(publicPath || "", {
|
|
18
|
+
hash: compilation.hash || "XXXX"
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
// If publicPath is not "auto", return the static value
|
|
22
|
+
if (publicPath !== "auto") {
|
|
23
|
+
return `${webpack_1.RuntimeGlobals.publicPath} = ${JSON.stringify(getPath())};`;
|
|
24
|
+
}
|
|
25
|
+
const chunkName = compilation.getPath(webpack_1.javascript.JavascriptModulesPlugin.getChunkFilenameTemplate(this.chunk, compilation.outputOptions), {
|
|
26
|
+
chunk: this.chunk,
|
|
27
|
+
contentHashType: "javascript"
|
|
28
|
+
});
|
|
29
|
+
const undoPath = (0, identifier_1.getUndoPath)(chunkName, path, false);
|
|
30
|
+
const ident = webpack_1.Template.toIdentifier(uniqueName);
|
|
31
|
+
return webpack_1.Template.asString([
|
|
32
|
+
"var scriptUrl;",
|
|
33
|
+
// its an esproxy so nesting into _config directly is not possible
|
|
34
|
+
"var remoteReg = globalThis.__remote_scope__._config;",
|
|
35
|
+
`
|
|
36
|
+
let remoteContainerRegistry = {
|
|
37
|
+
get url() {
|
|
38
|
+
return remoteReg[${JSON.stringify(ident)}];
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
`,
|
|
42
|
+
scriptType === "module"
|
|
43
|
+
? webpack_1.Template.asString([
|
|
44
|
+
'try {',
|
|
45
|
+
webpack_1.Template.indent([
|
|
46
|
+
`scriptUrl = new Function('return typeof ${importMetaName}.url === "string" ? ${importMetaName}.url : undefined;')();`,
|
|
47
|
+
]),
|
|
48
|
+
'} catch (e) {',
|
|
49
|
+
webpack_1.Template.indent([
|
|
50
|
+
`if (typeof remoteContainerRegistry.url === "string") {`,
|
|
51
|
+
webpack_1.Template.indent('scriptUrl = remoteContainerRegistry.url;'),
|
|
52
|
+
'} else {',
|
|
53
|
+
webpack_1.Template.indent('scriptUrl = __filename;'),
|
|
54
|
+
'}',
|
|
55
|
+
]),
|
|
56
|
+
'}'
|
|
57
|
+
])
|
|
58
|
+
: webpack_1.Template.asString([
|
|
59
|
+
`if (${webpack_1.RuntimeGlobals.global}.importScripts) scriptUrl = ${webpack_1.RuntimeGlobals.global}.location + "";`,
|
|
60
|
+
`var document = ${webpack_1.RuntimeGlobals.global}.document;`,
|
|
61
|
+
"if (!scriptUrl && document) {",
|
|
62
|
+
webpack_1.Template.indent([
|
|
63
|
+
`if (document.currentScript)`,
|
|
64
|
+
webpack_1.Template.indent(`scriptUrl = document.currentScript.src`),
|
|
65
|
+
"if (!scriptUrl) {",
|
|
66
|
+
webpack_1.Template.indent([
|
|
67
|
+
'var scripts = document.getElementsByTagName("script");',
|
|
68
|
+
"if(scripts.length) scriptUrl = scripts[scripts.length - 1].src"
|
|
69
|
+
]),
|
|
70
|
+
"}"
|
|
71
|
+
]),
|
|
72
|
+
"}",
|
|
73
|
+
]),
|
|
74
|
+
"console.log('scriptUrl', scriptUrl);",
|
|
75
|
+
"// When supporting server environments where an automatic publicPath is not supported, you must specify an output.publicPath manually via configuration",
|
|
76
|
+
'// or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.',
|
|
77
|
+
'if (!scriptUrl) throw new Error("Unable to calculate automatic public path");',
|
|
78
|
+
'scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\\?.*$/, "").replace(/\\/[^\\/]+$/, "/");',
|
|
79
|
+
!undoPath
|
|
80
|
+
? `${webpack_1.RuntimeGlobals.publicPath} = scriptUrl;`
|
|
81
|
+
: `${webpack_1.RuntimeGlobals.publicPath} = scriptUrl + ${JSON.stringify(undoPath)};`
|
|
82
|
+
]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.default = AutoPublicPathRuntimeModule;
|
|
86
|
+
//# sourceMappingURL=RemotePublicPathRuntimeModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemotePublicPathRuntimeModule.js","sourceRoot":"","sources":["../../../../../packages/node/src/plugins/RemotePublicPathRuntimeModule.js"],"names":[],"mappings":";;AAAA,qCAA8E;AAC9E,4DAA0D;AAE1D,MAAM,2BAA4B,SAAQ,uBAAa;IACrD,YAAY,OAAO;QACjB,KAAK,CAAC,YAAY,EAAE,uBAAa,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;QACnD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;QAC7B,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,UAAU,EAAE,GAAG,WAAW,CAAC,aAAa,CAAC;QAC/F,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,OAAO,WAAW,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,EAAE;gBAC3C,IAAI,EAAE,WAAW,CAAC,IAAI,IAAI,MAAM;aACjC,CAAC,CAAC;QACL,CAAC,CAAC;QACF,uDAAuD;QACvD,IAAI,UAAU,KAAK,MAAM,EAAE;YACzB,OAAO,GAAG,wBAAc,CAAC,UAAU,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC;SACvE;QAED,MAAM,SAAS,GAAG,WAAW,CAAC,OAAO,CACnC,oBAAU,CAAC,uBAAuB,CAAC,wBAAwB,CACzD,IAAI,CAAC,KAAK,EACV,WAAW,CAAC,aAAa,CAC1B,EACD;YACE,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,eAAe,EAAE,YAAY;SAC9B,CACF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GAAG,wBAAc,CAAC,UAAU,eAAe;gBAC7C,CAAC,CAAC,GAAG,wBAAc,CAAC,UAAU,kBAAkB,IAAI,CAAC,SAAS,CAC5D,QAAQ,CACT,GAAG;SACP,CAAC,CAAC;IACL,CAAC;CACF;AAED,kBAAe,2BAA2B,CAAC"}
|
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import type { Compiler } from 'webpack';
|
|
2
2
|
import type { ModuleFederationPluginOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for StreamingTargetOptions which extends ModuleFederationPluginOptions
|
|
5
|
+
* @property {string} promiseBaseURI - The base URI for the promise
|
|
6
|
+
* @property {boolean} debug - Flag to enable/disable debug mode
|
|
7
|
+
*/
|
|
3
8
|
interface StreamingTargetOptions extends ModuleFederationPluginOptions {
|
|
4
9
|
promiseBaseURI?: string;
|
|
5
10
|
debug?: boolean;
|
|
6
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Class representing a StreamingTargetPlugin
|
|
14
|
+
*/
|
|
7
15
|
declare class StreamingTargetPlugin {
|
|
8
16
|
private options;
|
|
17
|
+
/**
|
|
18
|
+
* Create a StreamingTargetPlugin
|
|
19
|
+
* @param {StreamingTargetOptions} options - The options for the plugin
|
|
20
|
+
*/
|
|
9
21
|
constructor(options: StreamingTargetOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Apply the plugin to the compiler
|
|
24
|
+
* @param {Compiler} compiler - The webpack compiler
|
|
25
|
+
*/
|
|
10
26
|
apply(compiler: Compiler): void;
|
|
11
27
|
}
|
|
12
28
|
export default StreamingTargetPlugin;
|
|
@@ -4,21 +4,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const CommonJsChunkLoadingPlugin_1 = __importDefault(require("./CommonJsChunkLoadingPlugin"));
|
|
7
|
+
/**
|
|
8
|
+
* Class representing a StreamingTargetPlugin
|
|
9
|
+
*/
|
|
7
10
|
class StreamingTargetPlugin {
|
|
11
|
+
/**
|
|
12
|
+
* Create a StreamingTargetPlugin
|
|
13
|
+
* @param {StreamingTargetOptions} options - The options for the plugin
|
|
14
|
+
*/
|
|
8
15
|
constructor(options) {
|
|
9
16
|
this.options = options || {};
|
|
10
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Apply the plugin to the compiler
|
|
20
|
+
* @param {Compiler} compiler - The webpack compiler
|
|
21
|
+
*/
|
|
11
22
|
apply(compiler) {
|
|
12
|
-
if (compiler.options.target) {
|
|
13
|
-
console.warn(`target should be set to false while using NodeSoftwareStreamRuntime plugin, actual target: ${compiler.options.target}`);
|
|
14
|
-
console.info('Setting target to false');
|
|
15
|
-
compiler.options.target = false;
|
|
16
|
-
}
|
|
17
23
|
// When used with Next.js, context is needed to use Next.js webpack
|
|
18
24
|
const { webpack } = compiler;
|
|
19
|
-
// This will enable CommonJsChunkFormatPlugin
|
|
20
25
|
compiler.options.output.chunkFormat = 'commonjs';
|
|
21
|
-
|
|
26
|
+
if (compiler.options.output.enabledLibraryTypes === undefined) {
|
|
27
|
+
compiler.options.output.enabledLibraryTypes = ['commonjs-module'];
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
compiler.options.output.enabledLibraryTypes.push('commonjs-module');
|
|
31
|
+
}
|
|
22
32
|
compiler.options.output.chunkLoading = 'async-node';
|
|
23
33
|
// Disable default config
|
|
24
34
|
// FIXME: enabledChunkLoadingTypes is of type 'string[] | undefined'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StreamingTargetPlugin.js","sourceRoot":"","sources":["../../../../../packages/node/src/plugins/StreamingTargetPlugin.ts"],"names":[],"mappings":";;;;;AAGA,8FAAsE;
|
|
1
|
+
{"version":3,"file":"StreamingTargetPlugin.js","sourceRoot":"","sources":["../../../../../packages/node/src/plugins/StreamingTargetPlugin.ts"],"names":[],"mappings":";;;;;AAGA,8FAAsE;AAkBtE;;GAEG;AACH,M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ClE,IAAI,oCAA0B,CAAC;YAC7B,iBAAiB,EAAE,IAAI;YACvB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;YACvB,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAiC;YACvD,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU;YAC3C,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc;YAC3C,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK;SAC1B,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC;CACF;AAED,kBAAe,qBAAqB,CAAC"}
|
|
@@ -1,17 +1,42 @@
|
|
|
1
1
|
import { ModuleFederationPluginOptions } from '../types';
|
|
2
2
|
import type { Compiler, container } from 'webpack';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for NodeFederationOptions
|
|
5
|
+
* @property {boolean} isServer - Indicates if the server is running
|
|
6
|
+
* @property {string} [promiseBaseURI] - The base URI for the promise
|
|
7
|
+
* @property {boolean} [debug] - Indicates if debug mode is enabled
|
|
8
|
+
*/
|
|
3
9
|
interface NodeFederationOptions extends ModuleFederationPluginOptions {
|
|
4
10
|
isServer: boolean;
|
|
5
11
|
promiseBaseURI?: string;
|
|
6
12
|
debug?: boolean;
|
|
7
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Interface for NodeFederationContext
|
|
16
|
+
* @property {typeof container.ModuleFederationPlugin} [ModuleFederationPlugin] - The ModuleFederationPlugin from webpack container
|
|
17
|
+
*/
|
|
8
18
|
interface NodeFederationContext {
|
|
9
19
|
ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;
|
|
10
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Class representing a UniversalFederationPlugin
|
|
23
|
+
*/
|
|
11
24
|
declare class UniversalFederationPlugin {
|
|
12
25
|
private _options;
|
|
13
26
|
private context;
|
|
27
|
+
/**
|
|
28
|
+
* Create a UniversalFederationPlugin
|
|
29
|
+
* @param {NodeFederationOptions} options - The options for the plugin
|
|
30
|
+
* @param {NodeFederationContext} context - The context for the plugin
|
|
31
|
+
*/
|
|
14
32
|
constructor(options: NodeFederationOptions, context: NodeFederationContext);
|
|
33
|
+
/**
|
|
34
|
+
* Apply the plugin to the compiler
|
|
35
|
+
* @param {Compiler} compiler - The webpack compiler
|
|
36
|
+
*/
|
|
15
37
|
apply(compiler: Compiler): void;
|
|
16
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Exporting UniversalFederationPlugin as default
|
|
41
|
+
*/
|
|
17
42
|
export default UniversalFederationPlugin;
|
|
@@ -3,19 +3,35 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/**
|
|
7
|
+
* Importing necessary plugins and types
|
|
8
|
+
*/
|
|
6
9
|
const StreamingTargetPlugin_1 = __importDefault(require("./StreamingTargetPlugin"));
|
|
7
10
|
const NodeFederationPlugin_1 = __importDefault(require("./NodeFederationPlugin"));
|
|
11
|
+
/**
|
|
12
|
+
* Class representing a UniversalFederationPlugin
|
|
13
|
+
*/
|
|
8
14
|
class UniversalFederationPlugin {
|
|
15
|
+
/**
|
|
16
|
+
* Create a UniversalFederationPlugin
|
|
17
|
+
* @param {NodeFederationOptions} options - The options for the plugin
|
|
18
|
+
* @param {NodeFederationContext} context - The context for the plugin
|
|
19
|
+
*/
|
|
9
20
|
constructor(options, context) {
|
|
10
21
|
this._options = options || {};
|
|
11
22
|
this.context = context || {};
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Apply the plugin to the compiler
|
|
26
|
+
* @param {Compiler} compiler - The webpack compiler
|
|
27
|
+
*/
|
|
13
28
|
apply(compiler) {
|
|
14
29
|
const { isServer, debug, ...options } = this._options;
|
|
15
30
|
const { webpack } = compiler;
|
|
16
31
|
if (isServer ||
|
|
17
32
|
compiler.options.name === 'server' ||
|
|
18
|
-
compiler.options.target === 'node'
|
|
33
|
+
compiler.options.target === 'node' ||
|
|
34
|
+
compiler.options.target === 'async-node') {
|
|
19
35
|
new NodeFederationPlugin_1.default(options, this.context).apply(compiler);
|
|
20
36
|
new StreamingTargetPlugin_1.default({ ...options, debug }).apply(compiler);
|
|
21
37
|
}
|
|
@@ -26,5 +42,8 @@ class UniversalFederationPlugin {
|
|
|
26
42
|
}
|
|
27
43
|
}
|
|
28
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Exporting UniversalFederationPlugin as default
|
|
47
|
+
*/
|
|
29
48
|
exports.default = UniversalFederationPlugin;
|
|
30
49
|
//# sourceMappingURL=UniversalFederationPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UniversalFederationPlugin.js","sourceRoot":"","sources":["../../../../../packages/node/src/plugins/UniversalFederationPlugin.ts"],"names":[],"mappings":";;;;;AAAA,oFAA4D;AAC5D,kFAA0D;
|
|
1
|
+
{"version":3,"file":"UniversalFederationPlugin.js","sourceRoot":"","sources":["../../../../../packages/node/src/plugins/UniversalFederationPlugin.ts"],"names":[],"mappings":";;;;;AAAA;;GAEG;AACH,oFAA4D;AAC5D,kFAA0D;AAwB1D;;GAEG;AACH,MAAM,yBAAyB;IAI7B;;;;OAIG;IACH,YAAY,OAA8B,EAAE,OAA8B;QACxE,IAAI,CAAC,QAAQ,GAAG,OAAO,IAAK,EAA4B,CAAC;QACzD,IAAI,CAAC,OAAO,GAAG,OAAO,IAAK,EAA4B,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAkB;QACtB,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC;QACtD,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;QAE7B,IACE,QAAQ;YACR,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,QAAQ;YAClC,QAAQ,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM;YAClC,QAAQ,CAAC,OAAO,CAAC,MAAM,KAAK,YAAY,EACxC;YACA,IAAI,8BAAoB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAChE,IAAI,+BAAqB,CAAC,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;SAClE;aAAM;YACL,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB;gBACtC,CAAC,OAAO,IAAI,OAAO,CAAC,SAAS,CAAC,sBAAsB,CAAC;gBACrD,OAAO,CAAC,8CAA8C,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,CACvE,QAAQ,CACT,CAAC;SACH;IACH,CAAC;CACF;AAED;;GAEG;AACH,kBAAe,yBAAyB,CAAC"}
|