@module-federation/node 2.1.5 → 2.1.6
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/dist/jest.config.d.ts +11 -0
- package/dist/jest.config.js +19 -0
- package/dist/jest.config.js.map +1 -0
- package/dist/package.json +95 -0
- package/dist/src/filesystem/stratagies.d.ts +18 -0
- package/dist/src/filesystem/stratagies.js +117 -0
- package/dist/src/filesystem/stratagies.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +17 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/plugins/AutomaticPublicPathPlugin.d.ts +9 -0
- package/dist/src/plugins/AutomaticPublicPathPlugin.js +38 -0
- package/dist/src/plugins/AutomaticPublicPathPlugin.js.map +1 -0
- package/dist/src/plugins/ChunkCorrelationPlugin.d.ts +61 -0
- package/dist/src/plugins/ChunkCorrelationPlugin.js +442 -0
- package/dist/src/plugins/ChunkCorrelationPlugin.js.map +1 -0
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.d.ts +17 -0
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.js +121 -0
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.js.map +1 -0
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.d.ts +39 -0
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js +119 -0
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js.map +1 -0
- package/dist/src/plugins/EntryChunkTrackerPlugin.d.ts +13 -0
- package/dist/src/plugins/EntryChunkTrackerPlugin.js +41 -0
- package/dist/src/plugins/EntryChunkTrackerPlugin.js.map +1 -0
- package/dist/src/plugins/NodeFederationPlugin.d.ts +46 -0
- package/dist/src/plugins/NodeFederationPlugin.js +81 -0
- package/dist/src/plugins/NodeFederationPlugin.js.map +1 -0
- package/dist/src/plugins/RemotePublicPathRuntimeModule.d.ts +10 -0
- package/dist/src/plugins/RemotePublicPathRuntimeModule.js +132 -0
- package/dist/src/plugins/RemotePublicPathRuntimeModule.js.map +1 -0
- package/dist/src/plugins/StreamingTargetPlugin.d.ts +28 -0
- package/dist/src/plugins/StreamingTargetPlugin.js +59 -0
- package/dist/src/plugins/StreamingTargetPlugin.js.map +1 -0
- package/dist/src/plugins/UniversalFederationPlugin.d.ts +43 -0
- package/dist/src/plugins/UniversalFederationPlugin.js +53 -0
- package/dist/src/plugins/UniversalFederationPlugin.js.map +1 -0
- package/dist/src/plugins/webpackChunkUtilities.d.ts +50 -0
- package/dist/src/plugins/webpackChunkUtilities.js +305 -0
- package/dist/src/plugins/webpackChunkUtilities.js.map +1 -0
- package/dist/src/types/index.d.ts +3 -0
- package/dist/src/types/index.js +3 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/utils/flush-chunks.d.ts +11 -0
- package/dist/src/utils/flush-chunks.js +172 -0
- package/dist/src/utils/flush-chunks.js.map +1 -0
- package/dist/src/utils/hot-reload.d.ts +7 -0
- package/dist/src/utils/hot-reload.js +184 -0
- package/dist/src/utils/hot-reload.js.map +1 -0
- package/dist/src/utils/index.d.ts +2 -0
- package/dist/src/utils/index.js +19 -0
- package/dist/src/utils/index.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
|
|
4
|
+
const { RuntimeGlobals, RuntimeModule } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
|
|
5
|
+
const { getUndoPath } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/util/identifier'));
|
|
6
|
+
const tapable_1 = require("tapable");
|
|
7
|
+
const compileBooleanMatcher = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/util/compileBooleanMatcher'));
|
|
8
|
+
const webpackChunkUtilities_1 = require("./webpackChunkUtilities");
|
|
9
|
+
const stratagies_1 = require("../filesystem/stratagies");
|
|
10
|
+
class DynamicFilesystemChunkLoadingRuntimeModule extends RuntimeModule {
|
|
11
|
+
constructor(runtimeRequirements, options, chunkLoadingContext) {
|
|
12
|
+
super('readFile chunk loading', RuntimeModule.STAGE_ATTACH + 1);
|
|
13
|
+
this.hooks = {
|
|
14
|
+
strategyCase: new tapable_1.SyncWaterfallHook(['source']),
|
|
15
|
+
};
|
|
16
|
+
this.runtimeRequirements = runtimeRequirements;
|
|
17
|
+
this.options = options;
|
|
18
|
+
this.chunkLoadingContext = chunkLoadingContext;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @private
|
|
22
|
+
* @param {Chunk} chunk chunk
|
|
23
|
+
* @param {string} rootOutputDir root output directory
|
|
24
|
+
* @returns {string} generated code
|
|
25
|
+
*/
|
|
26
|
+
_generateBaseUri(chunk, rootOutputDir) {
|
|
27
|
+
const options = chunk.getEntryOptions();
|
|
28
|
+
if (options && options.baseUri) {
|
|
29
|
+
return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
|
|
30
|
+
}
|
|
31
|
+
return `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${rootOutputDir
|
|
32
|
+
? `__dirname + ${JSON.stringify('/' + rootOutputDir)}`
|
|
33
|
+
: '__filename'});`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @private
|
|
37
|
+
* @param {unknown[]} items item to log
|
|
38
|
+
*/
|
|
39
|
+
_getLogger(...items) {
|
|
40
|
+
if (!this.options.debug) {
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
return `console.log(${items.join(',')});`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @returns {string} runtime code
|
|
47
|
+
*/
|
|
48
|
+
generate() {
|
|
49
|
+
const { remotes = {}, name } = this.options;
|
|
50
|
+
const { webpack } = this.chunkLoadingContext;
|
|
51
|
+
const { chunkGraph, chunk, compilation } = this;
|
|
52
|
+
const { Template } = webpack;
|
|
53
|
+
if (!chunkGraph || !chunk || !compilation) {
|
|
54
|
+
console.warn('Missing required properties. Returning empty string.');
|
|
55
|
+
return '';
|
|
56
|
+
}
|
|
57
|
+
const { runtimeTemplate } = compilation;
|
|
58
|
+
const jsModulePlugin = webpack?.javascript?.JavascriptModulesPlugin ||
|
|
59
|
+
require('webpack/lib/javascript/JavascriptModulesPlugin');
|
|
60
|
+
const { chunkHasJs } = jsModulePlugin;
|
|
61
|
+
const fn = RuntimeGlobals.ensureChunkHandlers;
|
|
62
|
+
const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
|
|
63
|
+
const hasJsMatcher = compileBooleanMatcher(conditionMap);
|
|
64
|
+
const initialChunkIds = (0, webpackChunkUtilities_1.getInitialChunkIds)(chunk, chunkGraph, chunkHasJs);
|
|
65
|
+
const outputName = compilation.getPath(jsModulePlugin.getChunkFilenameTemplate(chunk, compilation.outputOptions), { chunk, contentHashType: 'javascript' });
|
|
66
|
+
const rootOutputDir = getUndoPath(outputName, compilation.outputOptions.path || '', false);
|
|
67
|
+
const stateExpression = this.runtimeRequirements.has(RuntimeGlobals.hmrDownloadUpdateHandlers)
|
|
68
|
+
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_readFileVm`
|
|
69
|
+
: undefined;
|
|
70
|
+
const dynamicFilesystemChunkLoadingPluginCode = Template.asString([
|
|
71
|
+
stratagies_1.fileSystemRunInContextStrategy.toString(),
|
|
72
|
+
stratagies_1.httpEvalStrategy.toString(),
|
|
73
|
+
stratagies_1.httpVmStrategy.toString(),
|
|
74
|
+
'const loadChunkStrategy = async (strategyType,chunkId,rootOutputDir, remotes, callback) => {',
|
|
75
|
+
Template.indent([
|
|
76
|
+
'switch (strategyType) {',
|
|
77
|
+
Template.indent([
|
|
78
|
+
'case "filesystem": return await fileSystemRunInContextStrategy(chunkId,rootOutputDir, remotes, callback);',
|
|
79
|
+
'case "http-eval": return await httpEvalStrategy(chunkId,rootOutputDir, remotes, callback);',
|
|
80
|
+
'case "http-vm": return await httpVmStrategy(chunkId,rootOutputDir, remotes, callback);',
|
|
81
|
+
this.hooks.strategyCase.call('default: throw new Error("Invalid strategy type");'),
|
|
82
|
+
]),
|
|
83
|
+
'}',
|
|
84
|
+
]),
|
|
85
|
+
'};',
|
|
86
|
+
]);
|
|
87
|
+
return Template.asString([
|
|
88
|
+
dynamicFilesystemChunkLoadingPluginCode,
|
|
89
|
+
this.runtimeRequirements.has(RuntimeGlobals.baseURI)
|
|
90
|
+
? this._generateBaseUri(chunk, rootOutputDir)
|
|
91
|
+
: '// no baseURI',
|
|
92
|
+
'',
|
|
93
|
+
'// object to store loaded chunks',
|
|
94
|
+
'// "0" means "already loaded", Promise means loading',
|
|
95
|
+
`var installedChunks = ${stateExpression ? `${stateExpression} = ${stateExpression} || ` : ''}{`,
|
|
96
|
+
Template.indent(Array.from(initialChunkIds, (id) => `${JSON.stringify(id)}: 0`).join(',\n')),
|
|
97
|
+
'};',
|
|
98
|
+
'',
|
|
99
|
+
(0, webpackChunkUtilities_1.handleOnChunkLoad)(this.runtimeRequirements.has(RuntimeGlobals.onChunksLoaded), runtimeTemplate),
|
|
100
|
+
'',
|
|
101
|
+
(0, webpackChunkUtilities_1.generateInstallChunk)(runtimeTemplate, this.runtimeRequirements.has(RuntimeGlobals.onChunksLoaded)),
|
|
102
|
+
'',
|
|
103
|
+
this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers)
|
|
104
|
+
? (0, webpackChunkUtilities_1.generateLoadScript)(runtimeTemplate)
|
|
105
|
+
: '// no remote script loader needed',
|
|
106
|
+
this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers)
|
|
107
|
+
? (0, webpackChunkUtilities_1.generateLoadingCode)(this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers), fn, hasJsMatcher, rootOutputDir, remotes, name)
|
|
108
|
+
: '// no chunk loading',
|
|
109
|
+
'',
|
|
110
|
+
(0, webpackChunkUtilities_1.generateExternalInstallChunkCode)(this.runtimeRequirements.has(RuntimeGlobals.externalInstallChunk), this.options.debug),
|
|
111
|
+
'',
|
|
112
|
+
(0, webpackChunkUtilities_1.generateHmrCode)(this.runtimeRequirements.has(RuntimeGlobals.hmrDownloadUpdateHandlers), rootOutputDir),
|
|
113
|
+
'',
|
|
114
|
+
(0, webpackChunkUtilities_1.generateHmrManifestCode)(this.runtimeRequirements.has(RuntimeGlobals.hmrDownloadManifest), rootOutputDir),
|
|
115
|
+
]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.default = DynamicFilesystemChunkLoadingRuntimeModule;
|
|
119
|
+
//# sourceMappingURL=DynamicFilesystemChunkLoadingRuntimeModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DynamicFilesystemChunkLoadingRuntimeModule.js","sourceRoot":"","sources":["../../../src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.ts"],"names":[],"mappings":";;AAIA,0FAAqF;AACrF,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,GAAG,OAAO,CAC/C,IAAA,6CAAoB,EAAC,SAAS,CAAC,CACJ,CAAC;AAC9B,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAC7B,IAAA,6CAAoB,EAAC,6BAA6B,CAAC,CACJ,CAAC;AAClD,qCAA4C;AAC5C,MAAM,qBAAqB,GAAG,OAAO,CACnC,IAAA,6CAAoB,EAAC,wCAAwC,CAAC,CACJ,CAAC;AAC7D,mEASiC;AACjC,yDAIkC;AAmBlC,MAAM,0CAA2C,SAAQ,aAAa;IAQpE,YACE,mBAAgC,EAChC,OAA0D,EAC1D,mBAAwC;QAExC,KAAK,CAAC,wBAAwB,EAAE,aAAa,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;QATlE,UAAK,GAAG;YACN,YAAY,EAAE,IAAI,2BAAiB,CAAC,CAAC,QAAQ,CAAC,CAAC;SAChD,CAAC;QAQA,IAAI,CAAC,mBAAmB,GAA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CAAC,mBAAmB,CAAC,EAChE,EAAE,EACF,YAAY,EACZ,aAAa,EACb,OAAO,EACP,IAAI,CACL;gBACH,CAAC,CAAC,qBAAqB;YACzB,EAAE;YACF,IAAA,wDAAgC,EAC9B,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,cAAc,CAAC,oBAAoB,CAAC,EACjE,IAAI,CAAC,OAAO,CAAC,KAAK,CACnB;YACD,EAAE;YACF,IAAA,uCAAe,EACb,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,cAAc,CAAC,yBAAyB,CAAC,EACtE,aAAa,CACd;YACD,EAAE;YACF,IAAA,+CAAuB,EACrB,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,cAAc,CAAC,mBAAmB,CAAC,EAChE,aAAa,CACd;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAED,kBAAe,0CAA0C,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Compiler, Chunk, Module } from 'webpack';
|
|
2
|
+
export interface Options {
|
|
3
|
+
eager?: RegExp | ((module: Module) => boolean);
|
|
4
|
+
excludeChunk?: (chunk: Chunk) => boolean;
|
|
5
|
+
}
|
|
6
|
+
declare class EntryChunkTrackerPlugin {
|
|
7
|
+
private _options;
|
|
8
|
+
constructor(options?: Options);
|
|
9
|
+
apply(compiler: Compiler): void;
|
|
10
|
+
private _handleRenderStartup;
|
|
11
|
+
private _getTemplateString;
|
|
12
|
+
}
|
|
13
|
+
export default EntryChunkTrackerPlugin;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
|
|
4
|
+
const SortableSet = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/util/SortableSet'));
|
|
5
|
+
class EntryChunkTrackerPlugin {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this._options = options || {};
|
|
8
|
+
}
|
|
9
|
+
apply(compiler) {
|
|
10
|
+
compiler.hooks.thisCompilation.tap('EntryChunkTrackerPlugin', (compilation) => {
|
|
11
|
+
this._handleRenderStartup(compiler, compilation);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
_handleRenderStartup(compiler, compilation) {
|
|
15
|
+
compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation).renderStartup.tap('EntryChunkTrackerPlugin', (source, _renderContext, upperContext) => {
|
|
16
|
+
if (this._options.excludeChunk &&
|
|
17
|
+
this._options.excludeChunk(upperContext.chunk)) {
|
|
18
|
+
return source;
|
|
19
|
+
}
|
|
20
|
+
const templateString = this._getTemplateString(compiler, source);
|
|
21
|
+
return new compiler.webpack.sources.ConcatSource(templateString);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
_getTemplateString(compiler, source) {
|
|
25
|
+
const { Template } = compiler.webpack;
|
|
26
|
+
return Template.asString([
|
|
27
|
+
`if(typeof module !== 'undefined') {
|
|
28
|
+
globalThis.entryChunkCache = globalThis.entryChunkCache || new Set();
|
|
29
|
+
globalThis.entryChunkCache.add(module.filename);
|
|
30
|
+
if(module.children) {
|
|
31
|
+
module.children.forEach(function(c) {
|
|
32
|
+
globalThis.entryChunkCache.add(c.filename);
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
}`,
|
|
36
|
+
Template.indent(source.source().toString()),
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.default = EntryChunkTrackerPlugin;
|
|
41
|
+
//# sourceMappingURL=EntryChunkTrackerPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntryChunkTrackerPlugin.js","sourceRoot":"","sources":["../../../src/plugins/EntryChunkTrackerPlugin.ts"],"names":[],"mappings":";;AAAA,0FAAqF;AAYrF,MAAM,WAAW,GAAG,OAAO,CACzB,IAAA,6CAAoB,EAAC,8BAA8B,CAAC,C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
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Compiler, container } from 'webpack';
|
|
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
|
+
*/
|
|
9
|
+
interface NodeFederationOptions extends ModuleFederationPluginOptions {
|
|
10
|
+
experiments?: Record<string, unknown>;
|
|
11
|
+
debug?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Interface for Context
|
|
15
|
+
* @interface
|
|
16
|
+
* @property {typeof container.ModuleFederationPlugin} ModuleFederationPlugin - Optional ModuleFederationPlugin
|
|
17
|
+
*/
|
|
18
|
+
interface Context {
|
|
19
|
+
ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Class representing a NodeFederationPlugin.
|
|
23
|
+
* @class
|
|
24
|
+
*/
|
|
25
|
+
declare class NodeFederationPlugin {
|
|
26
|
+
private _options;
|
|
27
|
+
private context;
|
|
28
|
+
private experiments;
|
|
29
|
+
/**
|
|
30
|
+
* Create a NodeFederationPlugin.
|
|
31
|
+
* @constructor
|
|
32
|
+
* @param {NodeFederationOptions} options - The options for the NodeFederationPlugin
|
|
33
|
+
* @param {Context} context - The context for the NodeFederationPlugin
|
|
34
|
+
*/
|
|
35
|
+
constructor({ experiments, debug, ...options }: NodeFederationOptions, context: Context);
|
|
36
|
+
/**
|
|
37
|
+
* Apply method for the NodeFederationPlugin class.
|
|
38
|
+
* @method
|
|
39
|
+
* @param {Compiler} compiler - The webpack compiler.
|
|
40
|
+
*/
|
|
41
|
+
apply(compiler: Compiler): void;
|
|
42
|
+
private preparePluginOptions;
|
|
43
|
+
private updateCompilerOptions;
|
|
44
|
+
private getModuleFederationPlugin;
|
|
45
|
+
}
|
|
46
|
+
export default NodeFederationPlugin;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const EntryChunkTrackerPlugin_1 = __importDefault(require("./EntryChunkTrackerPlugin"));
|
|
7
|
+
/**
|
|
8
|
+
* Class representing a NodeFederationPlugin.
|
|
9
|
+
* @class
|
|
10
|
+
*/
|
|
11
|
+
class NodeFederationPlugin {
|
|
12
|
+
/**
|
|
13
|
+
* Create a NodeFederationPlugin.
|
|
14
|
+
* @constructor
|
|
15
|
+
* @param {NodeFederationOptions} options - The options for the NodeFederationPlugin
|
|
16
|
+
* @param {Context} context - The context for the NodeFederationPlugin
|
|
17
|
+
*/
|
|
18
|
+
constructor({ experiments, debug, ...options }, context) {
|
|
19
|
+
this._options = options || {};
|
|
20
|
+
this.context = context || {};
|
|
21
|
+
this.experiments = experiments || {};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Apply method for the NodeFederationPlugin class.
|
|
25
|
+
* @method
|
|
26
|
+
* @param {Compiler} compiler - The webpack compiler.
|
|
27
|
+
*/
|
|
28
|
+
apply(compiler) {
|
|
29
|
+
const { webpack } = compiler;
|
|
30
|
+
const pluginOptions = this.preparePluginOptions();
|
|
31
|
+
this.updateCompilerOptions(compiler);
|
|
32
|
+
const ModuleFederationPlugin = this.getModuleFederationPlugin(compiler, webpack);
|
|
33
|
+
new ModuleFederationPlugin(pluginOptions).apply(compiler);
|
|
34
|
+
new EntryChunkTrackerPlugin_1.default({}).apply(compiler);
|
|
35
|
+
}
|
|
36
|
+
preparePluginOptions() {
|
|
37
|
+
return {
|
|
38
|
+
...this._options,
|
|
39
|
+
remotes: this._options.remotes || {},
|
|
40
|
+
// enable dts in browser by default
|
|
41
|
+
dts: this._options.dts ?? false,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
updateCompilerOptions(compiler) {
|
|
45
|
+
if (compiler.options && compiler.options.output) {
|
|
46
|
+
//todo, need to change / remove
|
|
47
|
+
compiler.options.output.importMetaName = 'remoteContainerRegistry';
|
|
48
|
+
}
|
|
49
|
+
const chunkFileName = compiler.options?.output?.chunkFilename;
|
|
50
|
+
const uniqueName = compiler?.options?.output?.uniqueName || this._options.name;
|
|
51
|
+
if (typeof chunkFileName === 'string' &&
|
|
52
|
+
uniqueName &&
|
|
53
|
+
!chunkFileName.includes(uniqueName)) {
|
|
54
|
+
const suffix = `-[chunkhash].js`;
|
|
55
|
+
compiler.options.output.chunkFilename = chunkFileName.replace('.js', suffix);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
getModuleFederationPlugin(compiler, webpack) {
|
|
59
|
+
let ModuleFederationPlugin;
|
|
60
|
+
try {
|
|
61
|
+
return require('@module-federation/enhanced').ModuleFederationPlugin;
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
console.error("Can't find @module-federation/enhanced, falling back to webpack ModuleFederationPlugin, this may not work");
|
|
65
|
+
if (this.context.ModuleFederationPlugin) {
|
|
66
|
+
ModuleFederationPlugin = this.context.ModuleFederationPlugin;
|
|
67
|
+
}
|
|
68
|
+
else if (webpack &&
|
|
69
|
+
webpack.container &&
|
|
70
|
+
webpack.container.ModuleFederationPlugin) {
|
|
71
|
+
ModuleFederationPlugin = webpack.container.ModuleFederationPlugin;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
|
|
75
|
+
}
|
|
76
|
+
return ModuleFederationPlugin;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.default = NodeFederationPlugin;
|
|
81
|
+
//# sourceMappingURL=NodeFederationPlugin.js.map
|
|
@@ -0,0 +1 @@
|
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@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const RuntimeModule: typeof import("webpack").RuntimeModule;
|
|
2
|
+
declare class AutoPublicPathRuntimeModule extends RuntimeModule {
|
|
3
|
+
private options;
|
|
4
|
+
constructor(options: any);
|
|
5
|
+
/**
|
|
6
|
+
* @returns {string} runtime code
|
|
7
|
+
*/
|
|
8
|
+
generate(): string;
|
|
9
|
+
}
|
|
10
|
+
export default AutoPublicPathRuntimeModule;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
|
|
4
|
+
const { RuntimeGlobals, RuntimeModule, Template, javascript } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
|
|
5
|
+
const { getUndoPath } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack/lib/util/identifier'));
|
|
6
|
+
class AutoPublicPathRuntimeModule extends RuntimeModule {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super('publicPath', RuntimeModule.STAGE_BASIC + 1);
|
|
9
|
+
this.options = options;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @returns {string} runtime code
|
|
13
|
+
*/
|
|
14
|
+
generate() {
|
|
15
|
+
const { compilation } = this;
|
|
16
|
+
const { scriptType, path, publicPath, importMetaName, uniqueName, chunkLoading,
|
|
17
|
+
//@ts-ignore
|
|
18
|
+
} = compilation.outputOptions;
|
|
19
|
+
const getPath = () => compilation?.getPath(publicPath || '', {
|
|
20
|
+
hash: compilation?.hash || 'XXXX',
|
|
21
|
+
});
|
|
22
|
+
const chunkName = compilation?.getPath(javascript.JavascriptModulesPlugin.getChunkFilenameTemplate(this.chunk, compilation?.outputOptions), {
|
|
23
|
+
chunk: this.chunk,
|
|
24
|
+
contentHashType: 'javascript',
|
|
25
|
+
});
|
|
26
|
+
let undoPath = null;
|
|
27
|
+
if (chunkName && path) {
|
|
28
|
+
undoPath = getUndoPath(chunkName, path, false);
|
|
29
|
+
}
|
|
30
|
+
const getPathFromFederation = `
|
|
31
|
+
function getPathFromFederation() {
|
|
32
|
+
// Access the global federation manager or create a fallback object
|
|
33
|
+
var federationManager = globalThis.__FEDERATION__ || {};
|
|
34
|
+
// Access the current Webpack instance's federation details or create a fallback object
|
|
35
|
+
var instance = __webpack_require__.federation.instance || {};
|
|
36
|
+
|
|
37
|
+
// Function to aggregate all known remote module paths
|
|
38
|
+
var getAllKnownRemotes = function() {
|
|
39
|
+
var found = {};
|
|
40
|
+
// Iterate over all federation instances to collect module cache entries
|
|
41
|
+
(federationManager.__INSTANCES__ || []).forEach((instance) => {
|
|
42
|
+
instance.moduleCache.forEach((value, key) => {
|
|
43
|
+
found[key] = value;
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
return found;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// Retrieve the combined remote cache from all federation instances
|
|
50
|
+
const combinedRemoteCache = getAllKnownRemotes();
|
|
51
|
+
// Get the name of the current host from the instance
|
|
52
|
+
const hostName = instance.name;
|
|
53
|
+
// Find the path for the current host in the remote cache
|
|
54
|
+
const foundPath = combinedRemoteCache[hostName];
|
|
55
|
+
// If a path is not found, return undefined to indicate the absence of an entry path
|
|
56
|
+
if (!foundPath) { return undefined; }
|
|
57
|
+
// Return the entry path for the found remote module
|
|
58
|
+
const entryPath = foundPath.remoteInfo.entry;
|
|
59
|
+
return entryPath;
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
62
|
+
const definePropertyCode = `
|
|
63
|
+
Object.defineProperty(__webpack_require__, "p", {
|
|
64
|
+
get: function() {
|
|
65
|
+
var scriptUrl;
|
|
66
|
+
|
|
67
|
+
// Attempt to get the script URL based on the environment
|
|
68
|
+
var scriptType = ${JSON.stringify(scriptType)};
|
|
69
|
+
var chunkLoading = ${JSON.stringify(chunkLoading)};
|
|
70
|
+
var isModuleEnvironment = ['module', 'node', 'async-node', 'require'].includes(scriptType) || chunkLoading;
|
|
71
|
+
|
|
72
|
+
if (isModuleEnvironment) {
|
|
73
|
+
try {
|
|
74
|
+
// Use Function constructor to avoid direct reference to import.meta in environments that do not support it
|
|
75
|
+
scriptUrl = (new Function('return typeof ${importMetaName}.url === "string" ? ${importMetaName}.url : undefined;'))();
|
|
76
|
+
} catch (e) {
|
|
77
|
+
// Handle cases where import.meta is not available or other errors occur
|
|
78
|
+
var scriptPath = getPathFromFederation();
|
|
79
|
+
if (scriptPath) {
|
|
80
|
+
scriptUrl = scriptPath;
|
|
81
|
+
} else if (typeof __filename !== "undefined") {
|
|
82
|
+
scriptUrl = __filename;
|
|
83
|
+
} else {
|
|
84
|
+
scriptUrl = ${publicPath !== 'auto' ? JSON.stringify(getPath()) : 'undefined'};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
// Fallback for non-module environments, such as browsers
|
|
89
|
+
if (${RuntimeGlobals.global}.importScripts) {
|
|
90
|
+
scriptUrl = ${RuntimeGlobals.global}.location + "";
|
|
91
|
+
}
|
|
92
|
+
var document = ${RuntimeGlobals.global}.document;
|
|
93
|
+
if (!scriptUrl && document) {
|
|
94
|
+
if (document.currentScript) {
|
|
95
|
+
scriptUrl = document.currentScript.src;
|
|
96
|
+
} else {
|
|
97
|
+
var scripts = document.getElementsByTagName("script");
|
|
98
|
+
if (scripts.length) {
|
|
99
|
+
scriptUrl = scripts[scripts.length - 1].src;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (!scriptUrl) {
|
|
106
|
+
throw new Error("Unable to calculate automatic public path");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Clean up the script URL by removing any hash or query parameters
|
|
110
|
+
scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\\?.*$/, "").replace(/\\/[^\\/]+$/, "/");
|
|
111
|
+
|
|
112
|
+
// Apply any undo path that might be necessary for nested public paths
|
|
113
|
+
var finalScript = ${JSON.stringify(undoPath)} ? scriptUrl + ${JSON.stringify(undoPath)} : scriptUrl;
|
|
114
|
+
|
|
115
|
+
// Helper function to ensure the URL has a protocol if it starts with '//'
|
|
116
|
+
var addProtocol = function(url) {
|
|
117
|
+
return url.startsWith('//') ? 'https:' + url : url;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// Set the global variable for the public path
|
|
121
|
+
globalThis.currentVmokPublicPath = addProtocol(finalScript) || '/';
|
|
122
|
+
|
|
123
|
+
// Return the final public path
|
|
124
|
+
return finalScript
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
`;
|
|
128
|
+
return Template.asString([getPathFromFederation, definePropertyCode]);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.default = AutoPublicPathRuntimeModule;
|
|
132
|
+
//# sourceMappingURL=RemotePublicPathRuntimeModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemotePublicPathRuntimeModule.js","sourceRoot":"","sources":["../../../src/plugins/RemotePublicPathRuntimeModule.ts"],"names":[],"mappings":";;AAAA,0FAAqF;AACrF,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,OAAO,CACrE,IAAA,6CAAoB,EAAC,SAAS,CAAC,CACJ,CAAC;AAC9B,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAC7B,IAAA,6CAAoB,EAAC,6BAA6B,CAAC,CACJ,CAAC;AAElD,MAAM,2BAA4B,SAAQ,aAAa;IAGrD,YAAY,OAAY;QACtB,KAAK,CAAC,YAAY,EAAE,aAAa,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;QACnD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACM,QAAQ;QACf,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;QAC7B,MAAM,EACJ,UAAU,EACV,IAA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C,QAAQ,CAAC,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,CAAC,CAAC;IACxE,CAAC;CACF;AAED,kBAAe,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Compiler, WebpackPluginInstance } from 'webpack';
|
|
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
|
+
*/
|
|
8
|
+
interface StreamingTargetOptions extends ModuleFederationPluginOptions {
|
|
9
|
+
promiseBaseURI?: string;
|
|
10
|
+
debug?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Class representing a StreamingTargetPlugin
|
|
14
|
+
*/
|
|
15
|
+
declare class StreamingTargetPlugin implements WebpackPluginInstance {
|
|
16
|
+
private options;
|
|
17
|
+
/**
|
|
18
|
+
* Create a StreamingTargetPlugin
|
|
19
|
+
* @param {StreamingTargetOptions} options - The options for the plugin
|
|
20
|
+
*/
|
|
21
|
+
constructor(options: StreamingTargetOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Apply the plugin to the compiler
|
|
24
|
+
* @param {Compiler} compiler - The webpack compiler
|
|
25
|
+
*/
|
|
26
|
+
apply(compiler: Compiler): void;
|
|
27
|
+
}
|
|
28
|
+
export default StreamingTargetPlugin;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const CommonJsChunkLoadingPlugin_1 = __importDefault(require("./CommonJsChunkLoadingPlugin"));
|
|
7
|
+
/**
|
|
8
|
+
* Class representing a StreamingTargetPlugin
|
|
9
|
+
*/
|
|
10
|
+
class StreamingTargetPlugin {
|
|
11
|
+
/**
|
|
12
|
+
* Create a StreamingTargetPlugin
|
|
13
|
+
* @param {StreamingTargetOptions} options - The options for the plugin
|
|
14
|
+
*/
|
|
15
|
+
constructor(options) {
|
|
16
|
+
this.options = options || {};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Apply the plugin to the compiler
|
|
20
|
+
* @param {Compiler} compiler - The webpack compiler
|
|
21
|
+
*/
|
|
22
|
+
apply(compiler) {
|
|
23
|
+
// When used with Next.js, context is needed to use Next.js webpack
|
|
24
|
+
const { webpack } = compiler;
|
|
25
|
+
compiler.options.output.chunkFormat = 'commonjs';
|
|
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
|
+
}
|
|
32
|
+
compiler.options.output.chunkLoading = 'async-node';
|
|
33
|
+
// Disable default config
|
|
34
|
+
// FIXME: enabledChunkLoadingTypes is of type 'string[] | undefined'
|
|
35
|
+
// Can't use the 'false' value as it isn't the right format,
|
|
36
|
+
// Emptying it out ensures theres no other readFileVm added to webpack runtime
|
|
37
|
+
compiler.options.output.enabledChunkLoadingTypes = [];
|
|
38
|
+
compiler.options.output.environment = {
|
|
39
|
+
...compiler.options.output.environment,
|
|
40
|
+
dynamicImport: true,
|
|
41
|
+
};
|
|
42
|
+
new (webpack?.node?.NodeEnvironmentPlugin ||
|
|
43
|
+
require('webpack/lib/node/NodeEnvironmentPlugin'))({
|
|
44
|
+
infrastructureLogging: compiler.options.infrastructureLogging,
|
|
45
|
+
}).apply(compiler);
|
|
46
|
+
new (webpack?.node?.NodeTargetPlugin ||
|
|
47
|
+
require('webpack/lib/node/NodeTargetPlugin'))().apply(compiler);
|
|
48
|
+
new CommonJsChunkLoadingPlugin_1.default({
|
|
49
|
+
asyncChunkLoading: true,
|
|
50
|
+
name: this.options.name,
|
|
51
|
+
remotes: this.options.remotes,
|
|
52
|
+
baseURI: compiler.options.output.publicPath,
|
|
53
|
+
promiseBaseURI: this.options.promiseBaseURI,
|
|
54
|
+
debug: this.options.debug,
|
|
55
|
+
}).apply(compiler);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.default = StreamingTargetPlugin;
|
|
59
|
+
//# sourceMappingURL=StreamingTargetPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StreamingTargetPlugin.js","sourceRoot":"","sources":["../../../src/plugins/StreamingTargetPlugin.ts"],"names":[],"mappings":";;;;;AAGA,8FAAsE;AAkBtE;;GAEG;AACH,MAAM,qBAAqB;IAGzB;;;OAGG;IACH,YAAY,OAA+B;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAkB;QACtB,mEAAmE;QACnE,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;QAE7B,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,GAAG,UAAU,CAAC;QACjD,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,mBAAmB,KAAK,SAAS,EAAE,CAAC;YAC9D,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,mBAAmB,GAAG,CAAC,iBAAiB,CAAC,CAAC;QACpE,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACtE,CAAC;QAED,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;QAEpD,yBAAyB;QACzB,oEAAoE;QACpE,4DAA4D;QAC5D,8EAA8E;QAC9E,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,wBAAwB,GAAG,EAAE,CAAC;QACtD,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,GAAG;YACpC,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW;YACtC,aAAa,EAAE,IAAI;SACpB,CAAC;QAEF,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,qBAAqB;YACvC,OAAO,CAAC,wCAAwC,CAAC,CAAC,CAAC;YACnD,qBAAqB,EAAE,QAAQ,CAAC,OAAO,CAAC,qBAAqB;SAC9D,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEnB,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,gBAAgB;YAClC,OAAO,CAAC,mCAAmC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAClE,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"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ModuleFederationPluginOptions } from '../types';
|
|
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
|
+
*/
|
|
9
|
+
interface NodeFederationOptions extends ModuleFederationPluginOptions {
|
|
10
|
+
isServer: boolean;
|
|
11
|
+
promiseBaseURI?: string;
|
|
12
|
+
debug?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Interface for NodeFederationContext
|
|
16
|
+
* @property {typeof container.ModuleFederationPlugin} [ModuleFederationPlugin] - The ModuleFederationPlugin from webpack container
|
|
17
|
+
*/
|
|
18
|
+
interface NodeFederationContext {
|
|
19
|
+
ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Class representing a UniversalFederationPlugin
|
|
23
|
+
*/
|
|
24
|
+
declare class UniversalFederationPlugin {
|
|
25
|
+
private _options;
|
|
26
|
+
private context;
|
|
27
|
+
private name;
|
|
28
|
+
/**
|
|
29
|
+
* Create a UniversalFederationPlugin
|
|
30
|
+
* @param {NodeFederationOptions} options - The options for the plugin
|
|
31
|
+
* @param {NodeFederationContext} context - The context for the plugin
|
|
32
|
+
*/
|
|
33
|
+
constructor(options: NodeFederationOptions, context: NodeFederationContext);
|
|
34
|
+
/**
|
|
35
|
+
* Apply the plugin to the compiler
|
|
36
|
+
* @param {Compiler} compiler - The webpack compiler
|
|
37
|
+
*/
|
|
38
|
+
apply(compiler: Compiler): void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Exporting UniversalFederationPlugin as default
|
|
42
|
+
*/
|
|
43
|
+
export default UniversalFederationPlugin;
|