@module-federation/node 2.7.31 → 2.7.33
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/_virtual/_rolldown/runtime.js +31 -0
- package/dist/_virtual/_rolldown/runtime.mjs +8 -0
- package/dist/plugins/ChunkCorrelationPlugin.js +308 -0
- package/dist/plugins/ChunkCorrelationPlugin.js.map +1 -0
- package/dist/plugins/ChunkCorrelationPlugin.mjs +305 -0
- package/dist/plugins/ChunkCorrelationPlugin.mjs.map +1 -0
- package/dist/src/filesystem/stratagies.d.mts +21 -0
- package/dist/src/filesystem/stratagies.d.ts +10 -7
- package/dist/src/filesystem/stratagies.js +97 -116
- package/dist/src/filesystem/stratagies.js.map +1 -1
- package/dist/src/filesystem/stratagies.mjs +103 -0
- package/dist/src/filesystem/stratagies.mjs.map +1 -0
- package/dist/src/index.d.mts +8 -0
- package/dist/src/index.d.ts +8 -7
- package/dist/src/index.js +16 -22
- package/dist/src/index.mjs +9 -0
- package/dist/src/plugins/AutomaticPublicPathPlugin.d.mts +12 -0
- package/dist/src/plugins/AutomaticPublicPathPlugin.d.ts +9 -7
- package/dist/src/plugins/AutomaticPublicPathPlugin.js +26 -35
- package/dist/src/plugins/AutomaticPublicPathPlugin.js.map +1 -1
- package/dist/src/plugins/AutomaticPublicPathPlugin.mjs +28 -0
- package/dist/src/plugins/AutomaticPublicPathPlugin.mjs.map +1 -0
- package/dist/src/plugins/ChunkCorrelationPlugin.d.mts +5 -0
- package/dist/src/plugins/ChunkCorrelationPlugin.d.ts +4 -61
- package/dist/src/plugins/ChunkCorrelationPlugin.js +8 -440
- package/dist/src/plugins/ChunkCorrelationPlugin.js.map +1 -1
- package/dist/src/plugins/ChunkCorrelationPlugin.mjs +8 -0
- package/dist/src/plugins/ChunkCorrelationPlugin.mjs.map +1 -0
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.d.mts +21 -0
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.d.ts +16 -13
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.js +68 -118
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.js.map +1 -1
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.mjs +70 -0
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.mjs.map +1 -0
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.d.mts +46 -0
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.d.ts +39 -34
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js +110 -126
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js.map +1 -1
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.mjs +111 -0
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.mjs.map +1 -0
- package/dist/src/plugins/EntryChunkTrackerPlugin.d.mts +17 -0
- package/dist/src/plugins/EntryChunkTrackerPlugin.d.ts +14 -10
- package/dist/src/plugins/EntryChunkTrackerPlugin.js +30 -32
- package/dist/src/plugins/EntryChunkTrackerPlugin.js.map +1 -1
- package/dist/src/plugins/EntryChunkTrackerPlugin.mjs +38 -0
- package/dist/src/plugins/EntryChunkTrackerPlugin.mjs.map +1 -0
- package/dist/src/plugins/NodeFederationPlugin.d.mts +54 -0
- package/dist/src/plugins/NodeFederationPlugin.d.ts +33 -26
- package/dist/src/plugins/NodeFederationPlugin.js +69 -84
- package/dist/src/plugins/NodeFederationPlugin.js.map +1 -1
- package/dist/src/plugins/NodeFederationPlugin.mjs +70 -0
- package/dist/src/plugins/NodeFederationPlugin.mjs.map +1 -0
- package/dist/src/plugins/RemotePublicPathRuntimeModule.d.mts +15 -0
- package/dist/src/plugins/RemotePublicPathRuntimeModule.d.ts +12 -8
- package/dist/src/plugins/RemotePublicPathRuntimeModule.js +34 -35
- package/dist/src/plugins/RemotePublicPathRuntimeModule.js.map +1 -1
- package/dist/src/plugins/RemotePublicPathRuntimeModule.mjs +132 -0
- package/dist/src/plugins/RemotePublicPathRuntimeModule.mjs.map +1 -0
- package/dist/src/plugins/StreamingTargetPlugin.d.mts +32 -0
- package/dist/src/plugins/StreamingTargetPlugin.d.ts +19 -16
- package/dist/src/plugins/StreamingTargetPlugin.js +43 -56
- package/dist/src/plugins/StreamingTargetPlugin.js.map +1 -1
- package/dist/src/plugins/StreamingTargetPlugin.mjs +46 -0
- package/dist/src/plugins/StreamingTargetPlugin.mjs.map +1 -0
- package/dist/src/plugins/UniversalFederationPlugin.d.mts +49 -0
- package/dist/src/plugins/UniversalFederationPlugin.d.ts +26 -23
- package/dist/src/plugins/UniversalFederationPlugin.js +58 -81
- package/dist/src/plugins/UniversalFederationPlugin.js.map +1 -1
- package/dist/src/plugins/UniversalFederationPlugin.mjs +61 -0
- package/dist/src/plugins/UniversalFederationPlugin.mjs.map +1 -0
- package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.d.mts +9 -0
- package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.d.ts +6 -3
- package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.js +17 -17
- package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.js.map +1 -1
- package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.mjs +25 -0
- package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.mjs.map +1 -0
- package/dist/src/plugins/webpackChunkUtilities.d.mts +55 -0
- package/dist/src/plugins/webpackChunkUtilities.d.ts +14 -9
- package/dist/src/plugins/webpackChunkUtilities.js +195 -257
- package/dist/src/plugins/webpackChunkUtilities.js.map +1 -1
- package/dist/src/plugins/webpackChunkUtilities.mjs +234 -0
- package/dist/src/plugins/webpackChunkUtilities.mjs.map +1 -0
- package/dist/src/recordDynamicRemoteEntryHashPlugin.d.mts +7 -0
- package/dist/src/recordDynamicRemoteEntryHashPlugin.d.ts +5 -2
- package/dist/src/recordDynamicRemoteEntryHashPlugin.js +24 -61
- package/dist/src/recordDynamicRemoteEntryHashPlugin.js.map +1 -1
- package/dist/src/recordDynamicRemoteEntryHashPlugin.mjs +26 -0
- package/dist/src/recordDynamicRemoteEntryHashPlugin.mjs.map +1 -0
- package/dist/src/runtimePlugin.d.mts +27 -0
- package/dist/src/runtimePlugin.d.ts +24 -19
- package/dist/src/runtimePlugin.js +157 -252
- package/dist/src/runtimePlugin.js.map +1 -1
- package/dist/src/runtimePlugin.mjs +169 -0
- package/dist/src/runtimePlugin.mjs.map +1 -0
- package/dist/src/types/index.d.mts +8 -0
- package/dist/src/types/index.d.ts +8 -3
- package/dist/src/types/index.js +1 -3
- package/dist/src/types/index.mjs +1 -0
- package/dist/src/utils/flush-chunks.d.mts +15 -0
- package/dist/src/utils/flush-chunks.d.ts +7 -3
- package/dist/src/utils/flush-chunks.js +87 -161
- package/dist/src/utils/flush-chunks.js.map +1 -1
- package/dist/src/utils/flush-chunks.mjs +99 -0
- package/dist/src/utils/flush-chunks.mjs.map +1 -0
- package/dist/src/utils/hot-reload.d.mts +16 -0
- package/dist/src/utils/hot-reload.d.ts +14 -10
- package/dist/src/utils/hot-reload.js +177 -264
- package/dist/src/utils/hot-reload.js.map +1 -1
- package/dist/src/utils/hot-reload.mjs +194 -0
- package/dist/src/utils/hot-reload.mjs.map +1 -0
- package/dist/src/utils/index.d.mts +3 -0
- package/dist/src/utils/index.d.ts +3 -2
- package/dist/src/utils/index.js +15 -19
- package/dist/src/utils/index.mjs +4 -0
- package/package.json +59 -15
- package/dist/jest.config.d.ts +0 -11
- package/dist/jest.config.js +0 -19
- package/dist/jest.config.js.map +0 -1
- package/dist/package.json +0 -82
- package/dist/src/index.js.map +0 -1
- package/dist/src/types/index.js.map +0 -1
- package/dist/src/utils/index.js.map +0 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ModuleFederationPluginOptions } from "../types/index.mjs";
|
|
2
|
+
import { Compiler, container } from "webpack";
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/NodeFederationPlugin.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Interface for NodeFederationOptions which extends ModuleFederationPluginOptions
|
|
7
|
+
* @interface
|
|
8
|
+
* @property {boolean} debug - Optional debug flag
|
|
9
|
+
*/
|
|
10
|
+
interface NodeFederationOptions extends ModuleFederationPluginOptions {
|
|
11
|
+
debug?: boolean;
|
|
12
|
+
useRuntimePlugin?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Interface for Context
|
|
16
|
+
* @interface
|
|
17
|
+
* @property {typeof container.ModuleFederationPlugin} ModuleFederationPlugin - Optional ModuleFederationPlugin
|
|
18
|
+
*/
|
|
19
|
+
interface Context {
|
|
20
|
+
ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Class representing a NodeFederationPlugin.
|
|
24
|
+
* @class
|
|
25
|
+
*/
|
|
26
|
+
declare class NodeFederationPlugin {
|
|
27
|
+
private _options;
|
|
28
|
+
private context;
|
|
29
|
+
private useRuntimePlugin?;
|
|
30
|
+
private logger;
|
|
31
|
+
/**
|
|
32
|
+
* Create a NodeFederationPlugin.
|
|
33
|
+
* @constructor
|
|
34
|
+
* @param {NodeFederationOptions} options - The options for the NodeFederationPlugin
|
|
35
|
+
* @param {Context} context - The context for the NodeFederationPlugin
|
|
36
|
+
*/
|
|
37
|
+
constructor({
|
|
38
|
+
debug,
|
|
39
|
+
useRuntimePlugin,
|
|
40
|
+
...options
|
|
41
|
+
}: NodeFederationOptions, context: Context);
|
|
42
|
+
/**
|
|
43
|
+
* Apply method for the NodeFederationPlugin class.
|
|
44
|
+
* @method
|
|
45
|
+
* @param {Compiler} compiler - The webpack compiler.
|
|
46
|
+
*/
|
|
47
|
+
apply(compiler: Compiler): void;
|
|
48
|
+
private preparePluginOptions;
|
|
49
|
+
private updateCompilerOptions;
|
|
50
|
+
private getModuleFederationPlugin;
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { NodeFederationPlugin as default };
|
|
54
|
+
//# sourceMappingURL=NodeFederationPlugin.d.mts.map
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { ModuleFederationPluginOptions } from "../types/index.js";
|
|
2
|
+
import { Compiler, container } from "webpack";
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/NodeFederationPlugin.d.ts
|
|
3
5
|
/**
|
|
4
6
|
* Interface for NodeFederationOptions which extends ModuleFederationPluginOptions
|
|
5
7
|
* @interface
|
|
6
8
|
* @property {boolean} debug - Optional debug flag
|
|
7
9
|
*/
|
|
8
10
|
interface NodeFederationOptions extends ModuleFederationPluginOptions {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
debug?: boolean;
|
|
12
|
+
useRuntimePlugin?: boolean;
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
15
|
* Interface for Context
|
|
@@ -15,32 +17,37 @@ interface NodeFederationOptions extends ModuleFederationPluginOptions {
|
|
|
15
17
|
* @property {typeof container.ModuleFederationPlugin} ModuleFederationPlugin - Optional ModuleFederationPlugin
|
|
16
18
|
*/
|
|
17
19
|
interface Context {
|
|
18
|
-
|
|
20
|
+
ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
23
|
* Class representing a NodeFederationPlugin.
|
|
22
24
|
* @class
|
|
23
25
|
*/
|
|
24
26
|
declare class NodeFederationPlugin {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
27
|
+
private _options;
|
|
28
|
+
private context;
|
|
29
|
+
private useRuntimePlugin?;
|
|
30
|
+
private logger;
|
|
31
|
+
/**
|
|
32
|
+
* Create a NodeFederationPlugin.
|
|
33
|
+
* @constructor
|
|
34
|
+
* @param {NodeFederationOptions} options - The options for the NodeFederationPlugin
|
|
35
|
+
* @param {Context} context - The context for the NodeFederationPlugin
|
|
36
|
+
*/
|
|
37
|
+
constructor({
|
|
38
|
+
debug,
|
|
39
|
+
useRuntimePlugin,
|
|
40
|
+
...options
|
|
41
|
+
}: NodeFederationOptions, context: Context);
|
|
42
|
+
/**
|
|
43
|
+
* Apply method for the NodeFederationPlugin class.
|
|
44
|
+
* @method
|
|
45
|
+
* @param {Compiler} compiler - The webpack compiler.
|
|
46
|
+
*/
|
|
47
|
+
apply(compiler: Compiler): void;
|
|
48
|
+
private preparePluginOptions;
|
|
49
|
+
private updateCompilerOptions;
|
|
50
|
+
private getModuleFederationPlugin;
|
|
45
51
|
}
|
|
46
|
-
export
|
|
52
|
+
export = NodeFederationPlugin;
|
|
53
|
+
//# sourceMappingURL=NodeFederationPlugin.d.ts.map
|
|
@@ -1,88 +1,73 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
: sdk_1.createLogger;
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
5
|
+
const require_src_plugins_EntryChunkTrackerPlugin = require('./EntryChunkTrackerPlugin.js');
|
|
6
|
+
let _module_federation_sdk = require("@module-federation/sdk");
|
|
7
|
+
|
|
8
|
+
//#region src/plugins/NodeFederationPlugin.ts
|
|
9
|
+
const createBundlerLogger = typeof _module_federation_sdk.createInfrastructureLogger === "function" ? _module_federation_sdk.createInfrastructureLogger : _module_federation_sdk.createLogger;
|
|
11
10
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
ModuleFederationPlugin = this.context.ModuleFederationPlugin;
|
|
74
|
-
}
|
|
75
|
-
else if (webpack &&
|
|
76
|
-
webpack.container &&
|
|
77
|
-
webpack.container.ModuleFederationPlugin) {
|
|
78
|
-
ModuleFederationPlugin = webpack.container.ModuleFederationPlugin;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
|
|
82
|
-
}
|
|
83
|
-
return ModuleFederationPlugin;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
11
|
+
* Class representing a NodeFederationPlugin.
|
|
12
|
+
* @class
|
|
13
|
+
*/
|
|
14
|
+
var NodeFederationPlugin = class {
|
|
15
|
+
/**
|
|
16
|
+
* Create a NodeFederationPlugin.
|
|
17
|
+
* @constructor
|
|
18
|
+
* @param {NodeFederationOptions} options - The options for the NodeFederationPlugin
|
|
19
|
+
* @param {Context} context - The context for the NodeFederationPlugin
|
|
20
|
+
*/
|
|
21
|
+
constructor({ debug, useRuntimePlugin, ...options }, context) {
|
|
22
|
+
this.logger = createBundlerLogger("[ Node Federation Plugin ]");
|
|
23
|
+
this._options = options || {};
|
|
24
|
+
this.context = context || {};
|
|
25
|
+
this.useRuntimePlugin = useRuntimePlugin || false;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Apply method for the NodeFederationPlugin class.
|
|
29
|
+
* @method
|
|
30
|
+
* @param {Compiler} compiler - The webpack compiler.
|
|
31
|
+
*/
|
|
32
|
+
apply(compiler) {
|
|
33
|
+
(0, _module_federation_sdk.bindLoggerToCompiler)(this.logger, compiler, "NodeFederationPlugin");
|
|
34
|
+
const { webpack } = compiler;
|
|
35
|
+
const pluginOptions = this.preparePluginOptions();
|
|
36
|
+
this.updateCompilerOptions(compiler);
|
|
37
|
+
new (this.getModuleFederationPlugin(compiler, webpack))(pluginOptions).apply(compiler);
|
|
38
|
+
new require_src_plugins_EntryChunkTrackerPlugin.default({}).apply(compiler);
|
|
39
|
+
}
|
|
40
|
+
preparePluginOptions() {
|
|
41
|
+
this._options.runtimePlugins = [...this.useRuntimePlugin ? [require.resolve("../runtimePlugin")] : [], ...this._options.runtimePlugins || []];
|
|
42
|
+
return {
|
|
43
|
+
...this._options,
|
|
44
|
+
remotes: this._options.remotes || {},
|
|
45
|
+
runtimePlugins: this._options.runtimePlugins,
|
|
46
|
+
dts: this._options.dts ?? false
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
updateCompilerOptions(compiler) {
|
|
50
|
+
const chunkFileName = compiler.options?.output?.chunkFilename;
|
|
51
|
+
const uniqueName = compiler?.options?.output?.uniqueName || this._options.name;
|
|
52
|
+
if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
53
|
+
const suffix = `-[contenthash].js`;
|
|
54
|
+
compiler.options.output.chunkFilename = chunkFileName.replace(".js", suffix);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
getModuleFederationPlugin(compiler, webpack) {
|
|
58
|
+
let ModuleFederationPlugin;
|
|
59
|
+
try {
|
|
60
|
+
return require("@module-federation/enhanced").ModuleFederationPlugin;
|
|
61
|
+
} catch (e) {
|
|
62
|
+
this.logger.error("Can't find @module-federation/enhanced, falling back to webpack ModuleFederationPlugin, this may not work");
|
|
63
|
+
if (this.context.ModuleFederationPlugin) ModuleFederationPlugin = this.context.ModuleFederationPlugin;
|
|
64
|
+
else if (webpack && webpack.container && webpack.container.ModuleFederationPlugin) ModuleFederationPlugin = webpack.container.ModuleFederationPlugin;
|
|
65
|
+
else ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
|
|
66
|
+
return ModuleFederationPlugin;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
87
72
|
exports.default = NodeFederationPlugin;
|
|
88
73
|
//# sourceMappingURL=NodeFederationPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeFederationPlugin.js","
|
|
1
|
+
{"version":3,"file":"NodeFederationPlugin.js","names":["createInfrastructureLogger","createLogger","EntryChunkTrackerPlugin"],"sources":["../../../src/plugins/NodeFederationPlugin.ts"],"sourcesContent":["'use strict';\n\nimport type { Compiler, container } from 'webpack';\nimport type { ModuleFederationPluginOptions } from '../types';\nimport EntryChunkTrackerPlugin from './EntryChunkTrackerPlugin';\nimport {\n bindLoggerToCompiler,\n createInfrastructureLogger,\n createLogger,\n} from '@module-federation/sdk';\n/**\n * Interface for NodeFederationOptions which extends ModuleFederationPluginOptions\n * @interface\n * @property {boolean} debug - Optional debug flag\n */\ninterface NodeFederationOptions extends ModuleFederationPluginOptions {\n debug?: boolean;\n useRuntimePlugin?: boolean;\n}\n\n/**\n * Interface for Context\n * @interface\n * @property {typeof container.ModuleFederationPlugin} ModuleFederationPlugin - Optional ModuleFederationPlugin\n */\ninterface Context {\n ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;\n}\n\nconst createBundlerLogger: typeof createLogger =\n typeof createInfrastructureLogger === 'function'\n ? (createInfrastructureLogger as unknown as typeof createLogger)\n : createLogger;\n\n/**\n * Class representing a NodeFederationPlugin.\n * @class\n */\nclass NodeFederationPlugin {\n private _options: ModuleFederationPluginOptions;\n private context: Context;\n private useRuntimePlugin?: boolean;\n private logger = createBundlerLogger('[ Node Federation Plugin ]');\n\n /**\n * Create a NodeFederationPlugin.\n * @constructor\n * @param {NodeFederationOptions} options - The options for the NodeFederationPlugin\n * @param {Context} context - The context for the NodeFederationPlugin\n */\n constructor(\n { debug, useRuntimePlugin, ...options }: NodeFederationOptions,\n context: Context,\n ) {\n this._options = options || ({} as ModuleFederationPluginOptions);\n this.context = context || ({} as Context);\n this.useRuntimePlugin = useRuntimePlugin || false;\n }\n\n /**\n * Apply method for the NodeFederationPlugin class.\n * @method\n * @param {Compiler} compiler - The webpack compiler.\n */\n apply(compiler: Compiler) {\n bindLoggerToCompiler(this.logger, compiler, 'NodeFederationPlugin');\n const { webpack } = compiler;\n const pluginOptions = this.preparePluginOptions();\n this.updateCompilerOptions(compiler);\n const ModuleFederationPlugin = this.getModuleFederationPlugin(\n compiler,\n webpack,\n );\n new ModuleFederationPlugin(pluginOptions).apply(compiler);\n new EntryChunkTrackerPlugin({}).apply(compiler);\n }\n\n private preparePluginOptions(): ModuleFederationPluginOptions {\n this._options.runtimePlugins = [\n ...(this.useRuntimePlugin ? [require.resolve('../runtimePlugin')] : []),\n ...(this._options.runtimePlugins || []),\n ];\n\n return {\n ...this._options,\n remotes: this._options.remotes || {},\n runtimePlugins: this._options.runtimePlugins,\n // enable dts in browser by default\n dts: this._options.dts ?? false,\n };\n }\n\n private updateCompilerOptions(compiler: Compiler): void {\n const chunkFileName = compiler.options?.output?.chunkFilename;\n const uniqueName =\n compiler?.options?.output?.uniqueName || this._options.name;\n if (\n typeof chunkFileName === 'string' &&\n uniqueName &&\n !chunkFileName.includes(uniqueName)\n ) {\n const suffix = `-[contenthash].js`;\n compiler.options.output.chunkFilename = chunkFileName.replace(\n '.js',\n suffix,\n );\n }\n }\n\n private getModuleFederationPlugin(compiler: Compiler, webpack: any): any {\n let ModuleFederationPlugin;\n try {\n return require('@module-federation/enhanced').ModuleFederationPlugin;\n } catch (e) {\n this.logger.error(\n \"Can't find @module-federation/enhanced, falling back to webpack ModuleFederationPlugin, this may not work\",\n );\n if (this.context.ModuleFederationPlugin) {\n ModuleFederationPlugin = this.context.ModuleFederationPlugin;\n } else if (\n webpack &&\n webpack.container &&\n webpack.container.ModuleFederationPlugin\n ) {\n ModuleFederationPlugin = webpack.container.ModuleFederationPlugin;\n } else {\n ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');\n }\n return ModuleFederationPlugin;\n }\n }\n}\n\nexport default NodeFederationPlugin;\n"],"mappings":";;;;;;;;AA6BA,MAAM,sBACJ,OAAOA,sDAA+B,aACjCA,oDACDC;;;;;AAMN,IAAM,uBAAN,MAA2B;;;;;;;CAYzB,YACE,EAAE,OAAO,kBAAkB,GAAG,WAC9B,SACA;gBAXe,oBAAoB,6BAA6B;AAYhE,OAAK,WAAW,WAAY,EAAE;AAC9B,OAAK,UAAU,WAAY,EAAE;AAC7B,OAAK,mBAAmB,oBAAoB;;;;;;;CAQ9C,MAAM,UAAoB;AACxB,mDAAqB,KAAK,QAAQ,UAAU,uBAAuB;EACnE,MAAM,EAAE,YAAY;EACpB,MAAM,gBAAgB,KAAK,sBAAsB;AACjD,OAAK,sBAAsB,SAAS;AAKpC,OAJ+B,KAAK,0BAClC,UACA,QACD,EAC0B,cAAc,CAAC,MAAM,SAAS;AACzD,MAAIC,oDAAwB,EAAE,CAAC,CAAC,MAAM,SAAS;;CAGjD,AAAQ,uBAAsD;AAC5D,OAAK,SAAS,iBAAiB,CAC7B,GAAI,KAAK,mBAAmB,CAAC,QAAQ,QAAQ,mBAAmB,CAAC,GAAG,EAAE,EACtE,GAAI,KAAK,SAAS,kBAAkB,EAAE,CACvC;AAED,SAAO;GACL,GAAG,KAAK;GACR,SAAS,KAAK,SAAS,WAAW,EAAE;GACpC,gBAAgB,KAAK,SAAS;GAE9B,KAAK,KAAK,SAAS,OAAO;GAC3B;;CAGH,AAAQ,sBAAsB,UAA0B;EACtD,MAAM,gBAAgB,SAAS,SAAS,QAAQ;EAChD,MAAM,aACJ,UAAU,SAAS,QAAQ,cAAc,KAAK,SAAS;AACzD,MACE,OAAO,kBAAkB,YACzB,cACA,CAAC,cAAc,SAAS,WAAW,EACnC;GACA,MAAM,SAAS;AACf,YAAS,QAAQ,OAAO,gBAAgB,cAAc,QACpD,OACA,OACD;;;CAIL,AAAQ,0BAA0B,UAAoB,SAAmB;EACvE,IAAI;AACJ,MAAI;AACF,UAAO,QAAQ,8BAA8B,CAAC;WACvC,GAAG;AACV,QAAK,OAAO,MACV,4GACD;AACD,OAAI,KAAK,QAAQ,uBACf,0BAAyB,KAAK,QAAQ;YAEtC,WACA,QAAQ,aACR,QAAQ,UAAU,uBAElB,0BAAyB,QAAQ,UAAU;OAE3C,0BAAyB,QAAQ,+CAA+C;AAElF,UAAO"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { __require } from "../../_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
import EntryChunkTrackerPlugin from "./EntryChunkTrackerPlugin.mjs";
|
|
3
|
+
import { bindLoggerToCompiler, createInfrastructureLogger, createLogger } from "@module-federation/sdk";
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/NodeFederationPlugin.ts
|
|
6
|
+
const createBundlerLogger = typeof createInfrastructureLogger === "function" ? createInfrastructureLogger : createLogger;
|
|
7
|
+
/**
|
|
8
|
+
* Class representing a NodeFederationPlugin.
|
|
9
|
+
* @class
|
|
10
|
+
*/
|
|
11
|
+
var NodeFederationPlugin = class {
|
|
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({ debug, useRuntimePlugin, ...options }, context) {
|
|
19
|
+
this.logger = createBundlerLogger("[ Node Federation Plugin ]");
|
|
20
|
+
this._options = options || {};
|
|
21
|
+
this.context = context || {};
|
|
22
|
+
this.useRuntimePlugin = useRuntimePlugin || false;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Apply method for the NodeFederationPlugin class.
|
|
26
|
+
* @method
|
|
27
|
+
* @param {Compiler} compiler - The webpack compiler.
|
|
28
|
+
*/
|
|
29
|
+
apply(compiler) {
|
|
30
|
+
bindLoggerToCompiler(this.logger, compiler, "NodeFederationPlugin");
|
|
31
|
+
const { webpack } = compiler;
|
|
32
|
+
const pluginOptions = this.preparePluginOptions();
|
|
33
|
+
this.updateCompilerOptions(compiler);
|
|
34
|
+
new (this.getModuleFederationPlugin(compiler, webpack))(pluginOptions).apply(compiler);
|
|
35
|
+
new EntryChunkTrackerPlugin({}).apply(compiler);
|
|
36
|
+
}
|
|
37
|
+
preparePluginOptions() {
|
|
38
|
+
this._options.runtimePlugins = [...this.useRuntimePlugin ? [__require.resolve("../runtimePlugin")] : [], ...this._options.runtimePlugins || []];
|
|
39
|
+
return {
|
|
40
|
+
...this._options,
|
|
41
|
+
remotes: this._options.remotes || {},
|
|
42
|
+
runtimePlugins: this._options.runtimePlugins,
|
|
43
|
+
dts: this._options.dts ?? false
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
updateCompilerOptions(compiler) {
|
|
47
|
+
const chunkFileName = compiler.options?.output?.chunkFilename;
|
|
48
|
+
const uniqueName = compiler?.options?.output?.uniqueName || this._options.name;
|
|
49
|
+
if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
50
|
+
const suffix = `-[contenthash].js`;
|
|
51
|
+
compiler.options.output.chunkFilename = chunkFileName.replace(".js", suffix);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
getModuleFederationPlugin(compiler, webpack) {
|
|
55
|
+
let ModuleFederationPlugin;
|
|
56
|
+
try {
|
|
57
|
+
return __require("@module-federation/enhanced").ModuleFederationPlugin;
|
|
58
|
+
} catch (e) {
|
|
59
|
+
this.logger.error("Can't find @module-federation/enhanced, falling back to webpack ModuleFederationPlugin, this may not work");
|
|
60
|
+
if (this.context.ModuleFederationPlugin) ModuleFederationPlugin = this.context.ModuleFederationPlugin;
|
|
61
|
+
else if (webpack && webpack.container && webpack.container.ModuleFederationPlugin) ModuleFederationPlugin = webpack.container.ModuleFederationPlugin;
|
|
62
|
+
else ModuleFederationPlugin = __require("webpack/lib/container/ModuleFederationPlugin");
|
|
63
|
+
return ModuleFederationPlugin;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { NodeFederationPlugin as default };
|
|
70
|
+
//# sourceMappingURL=NodeFederationPlugin.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeFederationPlugin.mjs","names":[],"sources":["../../../src/plugins/NodeFederationPlugin.ts"],"sourcesContent":["'use strict';\n\nimport type { Compiler, container } from 'webpack';\nimport type { ModuleFederationPluginOptions } from '../types';\nimport EntryChunkTrackerPlugin from './EntryChunkTrackerPlugin';\nimport {\n bindLoggerToCompiler,\n createInfrastructureLogger,\n createLogger,\n} from '@module-federation/sdk';\n/**\n * Interface for NodeFederationOptions which extends ModuleFederationPluginOptions\n * @interface\n * @property {boolean} debug - Optional debug flag\n */\ninterface NodeFederationOptions extends ModuleFederationPluginOptions {\n debug?: boolean;\n useRuntimePlugin?: boolean;\n}\n\n/**\n * Interface for Context\n * @interface\n * @property {typeof container.ModuleFederationPlugin} ModuleFederationPlugin - Optional ModuleFederationPlugin\n */\ninterface Context {\n ModuleFederationPlugin?: typeof container.ModuleFederationPlugin;\n}\n\nconst createBundlerLogger: typeof createLogger =\n typeof createInfrastructureLogger === 'function'\n ? (createInfrastructureLogger as unknown as typeof createLogger)\n : createLogger;\n\n/**\n * Class representing a NodeFederationPlugin.\n * @class\n */\nclass NodeFederationPlugin {\n private _options: ModuleFederationPluginOptions;\n private context: Context;\n private useRuntimePlugin?: boolean;\n private logger = createBundlerLogger('[ Node Federation Plugin ]');\n\n /**\n * Create a NodeFederationPlugin.\n * @constructor\n * @param {NodeFederationOptions} options - The options for the NodeFederationPlugin\n * @param {Context} context - The context for the NodeFederationPlugin\n */\n constructor(\n { debug, useRuntimePlugin, ...options }: NodeFederationOptions,\n context: Context,\n ) {\n this._options = options || ({} as ModuleFederationPluginOptions);\n this.context = context || ({} as Context);\n this.useRuntimePlugin = useRuntimePlugin || false;\n }\n\n /**\n * Apply method for the NodeFederationPlugin class.\n * @method\n * @param {Compiler} compiler - The webpack compiler.\n */\n apply(compiler: Compiler) {\n bindLoggerToCompiler(this.logger, compiler, 'NodeFederationPlugin');\n const { webpack } = compiler;\n const pluginOptions = this.preparePluginOptions();\n this.updateCompilerOptions(compiler);\n const ModuleFederationPlugin = this.getModuleFederationPlugin(\n compiler,\n webpack,\n );\n new ModuleFederationPlugin(pluginOptions).apply(compiler);\n new EntryChunkTrackerPlugin({}).apply(compiler);\n }\n\n private preparePluginOptions(): ModuleFederationPluginOptions {\n this._options.runtimePlugins = [\n ...(this.useRuntimePlugin ? [require.resolve('../runtimePlugin')] : []),\n ...(this._options.runtimePlugins || []),\n ];\n\n return {\n ...this._options,\n remotes: this._options.remotes || {},\n runtimePlugins: this._options.runtimePlugins,\n // enable dts in browser by default\n dts: this._options.dts ?? false,\n };\n }\n\n private updateCompilerOptions(compiler: Compiler): void {\n const chunkFileName = compiler.options?.output?.chunkFilename;\n const uniqueName =\n compiler?.options?.output?.uniqueName || this._options.name;\n if (\n typeof chunkFileName === 'string' &&\n uniqueName &&\n !chunkFileName.includes(uniqueName)\n ) {\n const suffix = `-[contenthash].js`;\n compiler.options.output.chunkFilename = chunkFileName.replace(\n '.js',\n suffix,\n );\n }\n }\n\n private getModuleFederationPlugin(compiler: Compiler, webpack: any): any {\n let ModuleFederationPlugin;\n try {\n return require('@module-federation/enhanced').ModuleFederationPlugin;\n } catch (e) {\n this.logger.error(\n \"Can't find @module-federation/enhanced, falling back to webpack ModuleFederationPlugin, this may not work\",\n );\n if (this.context.ModuleFederationPlugin) {\n ModuleFederationPlugin = this.context.ModuleFederationPlugin;\n } else if (\n webpack &&\n webpack.container &&\n webpack.container.ModuleFederationPlugin\n ) {\n ModuleFederationPlugin = webpack.container.ModuleFederationPlugin;\n } else {\n ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');\n }\n return ModuleFederationPlugin;\n }\n }\n}\n\nexport default NodeFederationPlugin;\n"],"mappings":";;;;;AA6BA,MAAM,sBACJ,OAAO,+BAA+B,aACjC,6BACD;;;;;AAMN,IAAM,uBAAN,MAA2B;;;;;;;CAYzB,YACE,EAAE,OAAO,kBAAkB,GAAG,WAC9B,SACA;gBAXe,oBAAoB,6BAA6B;AAYhE,OAAK,WAAW,WAAY,EAAE;AAC9B,OAAK,UAAU,WAAY,EAAE;AAC7B,OAAK,mBAAmB,oBAAoB;;;;;;;CAQ9C,MAAM,UAAoB;AACxB,uBAAqB,KAAK,QAAQ,UAAU,uBAAuB;EACnE,MAAM,EAAE,YAAY;EACpB,MAAM,gBAAgB,KAAK,sBAAsB;AACjD,OAAK,sBAAsB,SAAS;AAKpC,OAJ+B,KAAK,0BAClC,UACA,QACD,EAC0B,cAAc,CAAC,MAAM,SAAS;AACzD,MAAI,wBAAwB,EAAE,CAAC,CAAC,MAAM,SAAS;;CAGjD,AAAQ,uBAAsD;AAC5D,OAAK,SAAS,iBAAiB,CAC7B,GAAI,KAAK,mBAAmB,WAAS,QAAQ,mBAAmB,CAAC,GAAG,EAAE,EACtE,GAAI,KAAK,SAAS,kBAAkB,EAAE,CACvC;AAED,SAAO;GACL,GAAG,KAAK;GACR,SAAS,KAAK,SAAS,WAAW,EAAE;GACpC,gBAAgB,KAAK,SAAS;GAE9B,KAAK,KAAK,SAAS,OAAO;GAC3B;;CAGH,AAAQ,sBAAsB,UAA0B;EACtD,MAAM,gBAAgB,SAAS,SAAS,QAAQ;EAChD,MAAM,aACJ,UAAU,SAAS,QAAQ,cAAc,KAAK,SAAS;AACzD,MACE,OAAO,kBAAkB,YACzB,cACA,CAAC,cAAc,SAAS,WAAW,EACnC;GACA,MAAM,SAAS;AACf,YAAS,QAAQ,OAAO,gBAAgB,cAAc,QACpD,OACA,OACD;;;CAIL,AAAQ,0BAA0B,UAAoB,SAAmB;EACvE,IAAI;AACJ,MAAI;AACF,oBAAe,8BAA8B,CAAC;WACvC,GAAG;AACV,QAAK,OAAO,MACV,4GACD;AACD,OAAI,KAAK,QAAQ,uBACf,0BAAyB,KAAK,QAAQ;YAEtC,WACA,QAAQ,aACR,QAAQ,UAAU,uBAElB,0BAAyB,QAAQ,UAAU;OAE3C,oCAAiC,+CAA+C;AAElF,UAAO"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as webpack from "webpack";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/RemotePublicPathRuntimeModule.d.ts
|
|
4
|
+
declare const RuntimeModule: typeof webpack.RuntimeModule;
|
|
5
|
+
declare class AutoPublicPathRuntimeModule extends RuntimeModule {
|
|
6
|
+
private options;
|
|
7
|
+
constructor(options: any);
|
|
8
|
+
/**
|
|
9
|
+
* @returns {string} runtime code
|
|
10
|
+
*/
|
|
11
|
+
generate(): string;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { AutoPublicPathRuntimeModule as default };
|
|
15
|
+
//# sourceMappingURL=RemotePublicPathRuntimeModule.d.mts.map
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import * as webpack from "webpack";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/RemotePublicPathRuntimeModule.d.ts
|
|
4
|
+
declare const RuntimeModule: typeof webpack.RuntimeModule;
|
|
2
5
|
declare class AutoPublicPathRuntimeModule extends RuntimeModule {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
private options;
|
|
7
|
+
constructor(options: any);
|
|
8
|
+
/**
|
|
9
|
+
* @returns {string} runtime code
|
|
10
|
+
*/
|
|
11
|
+
generate(): string;
|
|
9
12
|
}
|
|
10
|
-
export
|
|
13
|
+
export = AutoPublicPathRuntimeModule;
|
|
14
|
+
//# sourceMappingURL=RemotePublicPathRuntimeModule.d.ts.map
|
|
@@ -1,33 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
undoPath = getUndoPath(chunkName, path, false);
|
|
29
|
-
}
|
|
30
|
-
const getPathFromFederation = `
|
|
1
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
3
|
+
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/RemotePublicPathRuntimeModule.ts
|
|
6
|
+
const { RuntimeGlobals, RuntimeModule, Template, javascript } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
|
|
7
|
+
const { getUndoPath } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/identifier"));
|
|
8
|
+
var AutoPublicPathRuntimeModule = class extends RuntimeModule {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
super("publicPath", RuntimeModule.STAGE_BASIC + 1);
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @returns {string} runtime code
|
|
15
|
+
*/
|
|
16
|
+
generate() {
|
|
17
|
+
const { compilation } = this;
|
|
18
|
+
const { scriptType, path, publicPath, importMetaName, uniqueName, chunkLoading } = compilation.outputOptions;
|
|
19
|
+
const getPath = () => compilation?.getPath(publicPath || "", { hash: compilation?.hash || "XXXX" });
|
|
20
|
+
const currentChunk = this.chunk;
|
|
21
|
+
const chunkName = currentChunk && compilation?.getPath(javascript.JavascriptModulesPlugin.getChunkFilenameTemplate(currentChunk, compilation?.outputOptions), {
|
|
22
|
+
chunk: currentChunk,
|
|
23
|
+
contentHashType: "javascript"
|
|
24
|
+
});
|
|
25
|
+
let undoPath = null;
|
|
26
|
+
if (chunkName && path) undoPath = getUndoPath(chunkName, path, false);
|
|
27
|
+
const getPathFromFederation = `
|
|
31
28
|
function getPathFromFederation() {
|
|
32
29
|
// Access the global federation manager or create a fallback object
|
|
33
30
|
var federationManager = globalThis.__FEDERATION__ || {};
|
|
@@ -61,7 +58,7 @@ function getPathFromFederation() {
|
|
|
61
58
|
return entryPath;
|
|
62
59
|
}
|
|
63
60
|
`;
|
|
64
|
-
|
|
61
|
+
const definePropertyCode = `
|
|
65
62
|
Object.defineProperty(__webpack_require__, "p", {
|
|
66
63
|
get: function() {
|
|
67
64
|
var scriptUrl;
|
|
@@ -83,7 +80,7 @@ Object.defineProperty(__webpack_require__, "p", {
|
|
|
83
80
|
} else if (typeof __filename !== "undefined") {
|
|
84
81
|
scriptUrl = __filename;
|
|
85
82
|
} else {
|
|
86
|
-
scriptUrl = ${publicPath !==
|
|
83
|
+
scriptUrl = ${publicPath !== "auto" ? JSON.stringify(getPath()) : "undefined"};
|
|
87
84
|
}
|
|
88
85
|
}
|
|
89
86
|
} else {
|
|
@@ -127,8 +124,10 @@ Object.defineProperty(__webpack_require__, "p", {
|
|
|
127
124
|
}
|
|
128
125
|
});
|
|
129
126
|
`;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
127
|
+
return Template.asString([getPathFromFederation, definePropertyCode]);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
//#endregion
|
|
133
132
|
exports.default = AutoPublicPathRuntimeModule;
|
|
134
133
|
//# sourceMappingURL=RemotePublicPathRuntimeModule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemotePublicPathRuntimeModule.js","
|
|
1
|
+
{"version":3,"file":"RemotePublicPathRuntimeModule.js","names":[],"sources":["../../../src/plugins/RemotePublicPathRuntimeModule.ts"],"sourcesContent":["import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nconst { RuntimeGlobals, RuntimeModule, Template, javascript } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { getUndoPath } = require(\n normalizeWebpackPath('webpack/lib/util/identifier'),\n) as typeof import('webpack/lib/util/identifier');\n\nclass AutoPublicPathRuntimeModule extends RuntimeModule {\n private options: any;\n\n constructor(options: any) {\n super('publicPath', RuntimeModule.STAGE_BASIC + 1);\n this.options = options;\n }\n\n /**\n * @returns {string} runtime code\n */\n override generate() {\n const { compilation } = this;\n const {\n scriptType,\n path,\n publicPath,\n importMetaName,\n uniqueName,\n chunkLoading,\n //@ts-ignore\n } = compilation.outputOptions;\n\n const getPath = () =>\n compilation?.getPath(publicPath || '', {\n hash: compilation?.hash || 'XXXX',\n });\n\n const currentChunk = this.chunk;\n const chunkName =\n currentChunk &&\n compilation?.getPath(\n javascript.JavascriptModulesPlugin.getChunkFilenameTemplate(\n currentChunk,\n compilation?.outputOptions,\n ),\n {\n chunk: currentChunk,\n contentHashType: 'javascript',\n },\n );\n\n let undoPath: string | null = null;\n if (chunkName && path) {\n undoPath = getUndoPath(chunkName, path, false);\n }\n\n const getPathFromFederation = `\nfunction getPathFromFederation() {\n // Access the global federation manager or create a fallback object\n var federationManager = globalThis.__FEDERATION__ || {};\n // Access the current Webpack instance's federation details or create a fallback object\n var instance = __webpack_require__.federation.instance || {};\n\n // Function to aggregate all known remote module paths\n var getAllKnownRemotes = function() {\n var found = {};\n // Iterate over all federation instances to collect module cache entries\n (federationManager.__INSTANCES__ || []).forEach((instance) => {\n if(instance){\n instance.moduleCache.forEach((value, key) => {\n found[key] = value;\n });\n }\n });\n return found;\n };\n\n // Retrieve the combined remote cache from all federation instances\n const combinedRemoteCache = getAllKnownRemotes();\n // Get the name of the current host from the instance\n const hostName = instance.name;\n // Find the path for the current host in the remote cache\n const foundPath = combinedRemoteCache[hostName];\n // If a path is not found, return undefined to indicate the absence of an entry path\n if (!foundPath) { return undefined; }\n // Return the entry path for the found remote module\n const entryPath = foundPath.remoteInfo.entry;\n return entryPath;\n}\n`;\n const definePropertyCode = `\nObject.defineProperty(__webpack_require__, \"p\", {\n get: function() {\n var scriptUrl;\n\n // Attempt to get the script URL based on the environment\n var scriptType = ${JSON.stringify(scriptType)};\n var chunkLoading = ${JSON.stringify(chunkLoading)};\n var isModuleEnvironment = ['module', 'node', 'async-node', 'require'].includes(scriptType) || chunkLoading;\n\n if (isModuleEnvironment) {\n try {\n // Use Function constructor to avoid direct reference to import.meta in environments that do not support it\n scriptUrl = (new Function('return typeof ${importMetaName}.url === \"string\" ? ${importMetaName}.url : undefined;'))();\n } catch (e) {\n // Handle cases where import.meta is not available or other errors occur\n var scriptPath = getPathFromFederation();\n if (scriptPath) {\n scriptUrl = scriptPath;\n } else if (typeof __filename !== \"undefined\") {\n scriptUrl = __filename;\n } else {\n scriptUrl = ${\n publicPath !== 'auto' ? JSON.stringify(getPath()) : 'undefined'\n };\n }\n }\n } else {\n // Fallback for non-module environments, such as browsers\n if (${RuntimeGlobals.global}.importScripts) {\n scriptUrl = ${RuntimeGlobals.global}.location + \"\";\n }\n var document = ${RuntimeGlobals.global}.document;\n if (!scriptUrl && document) {\n if (document.currentScript) {\n scriptUrl = document.currentScript.src;\n } else {\n var scripts = document.getElementsByTagName(\"script\");\n if (scripts.length) {\n scriptUrl = scripts[scripts.length - 1].src;\n }\n }\n }\n }\n\n if (!scriptUrl) {\n throw new Error(\"Unable to calculate automatic public path\");\n }\n\n // Clean up the script URL by removing any hash or query parameters\n scriptUrl = scriptUrl.replace(/#.*$/, \"\").replace(/\\\\?.*$/, \"\").replace(/\\\\/[^\\\\/]+$/, \"/\");\n\n // Apply any undo path that might be necessary for nested public paths\n var finalScript = ${JSON.stringify(\n undoPath,\n )} ? scriptUrl + ${JSON.stringify(undoPath)} : scriptUrl;\n\n // Helper function to ensure the URL has a protocol if it starts with '//'\n var addProtocol = function(url) {\n return url.startsWith('//') ? 'https:' + url : url;\n };\n\n // Set the global variable for the public path\n globalThis.currentVmokPublicPath = addProtocol(finalScript) || '/';\n\n // Return the final public path\n return finalScript\n }\n});\n`;\n\n return Template.asString([getPathFromFederation, definePropertyCode]);\n }\n}\n\nexport default AutoPublicPathRuntimeModule;\n"],"mappings":";;;;;AACA,MAAM,EAAE,gBAAgB,eAAe,UAAU,eAAe,gFACzC,UAAU,CAChC;AACD,MAAM,EAAE,gBAAgB,gFACD,8BAA8B,CACpD;AAED,IAAM,8BAAN,cAA0C,cAAc;CAGtD,YAAY,SAAc;AACxB,QAAM,cAAc,cAAc,cAAc,EAAE;AAClD,OAAK,UAAU;;;;;CAMjB,AAAS,WAAW;EAClB,MAAM,EAAE,gBAAgB;EACxB,MAAM,EACJ,YACA,MACA,YACA,gBACA,YACA,iBAEE,YAAY;EAEhB,MAAM,gBACJ,aAAa,QAAQ,cAAc,IAAI,EACrC,MAAM,aAAa,QAAQ,QAC5B,CAAC;EAEJ,MAAM,eAAe,KAAK;EAC1B,MAAM,YACJ,gBACA,aAAa,QACX,WAAW,wBAAwB,yBACjC,cACA,aAAa,cACd,EACD;GACE,OAAO;GACP,iBAAiB;GAClB,CACF;EAEH,IAAI,WAA0B;AAC9B,MAAI,aAAa,KACf,YAAW,YAAY,WAAW,MAAM,MAAM;EAGhD,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkC9B,MAAM,qBAAqB;;;;;;uBAMR,KAAK,UAAU,WAAW,CAAC;yBACzB,KAAK,UAAU,aAAa,CAAC;;;;;;mDAMH,eAAe,sBAAsB,eAAe;;;;;;;;;wBAU3F,eAAe,SAAS,KAAK,UAAU,SAAS,CAAC,GAAG,YACrD;;;;;YAKC,eAAe,OAAO;sBACZ,eAAe,OAAO;;uBAErB,eAAe,OAAO;;;;;;;;;;;;;;;;;;;;;wBAqBrB,KAAK,UACvB,SACD,CAAC,iBAAiB,KAAK,UAAU,SAAS,CAAC;;;;;;;;;;;;;;;AAgB5C,SAAO,SAAS,SAAS,CAAC,uBAAuB,mBAAmB,CAAC"}
|