@module-federation/node 0.0.0-chore-bump-node-22-20260710161714
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/LICENSE +21 -0
- package/README.md +235 -0
- 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 +21 -0
- package/dist/src/filesystem/stratagies.js +105 -0
- package/dist/src/filesystem/stratagies.js.map +1 -0
- 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 -0
- package/dist/src/index.js +16 -0
- package/dist/src/index.mjs +9 -0
- package/dist/src/plugins/AutomaticPublicPathPlugin.d.mts +12 -0
- package/dist/src/plugins/AutomaticPublicPathPlugin.d.ts +11 -0
- package/dist/src/plugins/AutomaticPublicPathPlugin.js +29 -0
- package/dist/src/plugins/AutomaticPublicPathPlugin.js.map +1 -0
- 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 -0
- package/dist/src/plugins/ChunkCorrelationPlugin.js +9 -0
- package/dist/src/plugins/ChunkCorrelationPlugin.js.map +1 -0
- 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 +20 -0
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.js +71 -0
- package/dist/src/plugins/CommonJsChunkLoadingPlugin.js.map +1 -0
- 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 +45 -0
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js +112 -0
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js.map +1 -0
- 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 +17 -0
- package/dist/src/plugins/EntryChunkTrackerPlugin.js +39 -0
- package/dist/src/plugins/EntryChunkTrackerPlugin.js.map +1 -0
- 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 +53 -0
- package/dist/src/plugins/NodeFederationPlugin.js +76 -0
- package/dist/src/plugins/NodeFederationPlugin.js.map +1 -0
- package/dist/src/plugins/NodeFederationPlugin.mjs +73 -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 +14 -0
- package/dist/src/plugins/RemotePublicPathRuntimeModule.js +133 -0
- package/dist/src/plugins/RemotePublicPathRuntimeModule.js.map +1 -0
- 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 +31 -0
- package/dist/src/plugins/StreamingTargetPlugin.js +46 -0
- package/dist/src/plugins/StreamingTargetPlugin.js.map +1 -0
- 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 +48 -0
- package/dist/src/plugins/UniversalFederationPlugin.js +66 -0
- package/dist/src/plugins/UniversalFederationPlugin.js.map +1 -0
- package/dist/src/plugins/UniversalFederationPlugin.mjs +65 -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 +8 -0
- package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.js +25 -0
- package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.js.map +1 -0
- package/dist/src/plugins/UniverseEntryChunkTrackerPlugin.mjs +23 -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 +55 -0
- package/dist/src/plugins/webpackChunkUtilities.js +242 -0
- package/dist/src/plugins/webpackChunkUtilities.js.map +1 -0
- 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 +6 -0
- package/dist/src/recordDynamicRemoteEntryHashPlugin.js +28 -0
- package/dist/src/recordDynamicRemoteEntryHashPlugin.js.map +1 -0
- 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 +27 -0
- package/dist/src/runtimePlugin.js +242 -0
- package/dist/src/runtimePlugin.js.map +1 -0
- package/dist/src/runtimePlugin.mjs +226 -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 -0
- package/dist/src/types/index.js +1 -0
- 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 +15 -0
- package/dist/src/utils/flush-chunks.js +106 -0
- package/dist/src/utils/flush-chunks.js.map +1 -0
- package/dist/src/utils/flush-chunks.mjs +102 -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 +16 -0
- package/dist/src/utils/hot-reload.js +206 -0
- package/dist/src/utils/hot-reload.js.map +1 -0
- package/dist/src/utils/hot-reload.mjs +195 -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 -0
- package/dist/src/utils/index.js +15 -0
- package/dist/src/utils/index.mjs +4 -0
- package/package.json +135 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DynamicFilesystemChunkLoadingRuntimeModule.js","names":["createInfrastructureLogger","createLogger","SyncWaterfallHook","getInitialChunkIds","fileSystemRunInContextStrategy","httpEvalStrategy","httpVmStrategy","handleOnChunkLoad","generateInstallChunk","generateLoadScript","generateLoadingCode","generateExternalInstallChunkCode","generateHmrCode","generateHmrManifestCode"],"sources":["../../../src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.ts"],"sourcesContent":["/*\n MIT License http://www.opensource.org/licenses/mit-license.php\n*/\nimport type { Chunk, Compiler } from 'webpack';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nconst { RuntimeGlobals, RuntimeModule } = 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');\nimport { SyncWaterfallHook } from 'tapable';\nconst compileBooleanMatcher = require(\n normalizeWebpackPath('webpack/lib/util/compileBooleanMatcher'),\n) as typeof import('webpack/lib/util/compileBooleanMatcher');\nimport {\n generateHmrCode,\n getInitialChunkIds,\n generateLoadingCode,\n generateHmrManifestCode,\n handleOnChunkLoad,\n generateLoadScript,\n generateInstallChunk,\n generateExternalInstallChunkCode,\n} from './webpackChunkUtilities';\nimport {\n createInfrastructureLogger,\n createLogger,\n} from '@module-federation/sdk';\nimport {\n fileSystemRunInContextStrategy,\n httpEvalStrategy,\n httpVmStrategy,\n} from '../filesystem/stratagies';\n\ninterface RemotesByType {\n functional: string[];\n normal: string[];\n}\n\ninterface DynamicFilesystemChunkLoadingRuntimeModuleOptions {\n baseURI: Compiler['options']['output']['publicPath'];\n promiseBaseURI?: string;\n remotes: Record<string, string>;\n name?: string;\n debug?: boolean;\n}\n\ninterface ChunkLoadingContext {\n webpack: Compiler['webpack'];\n}\n\nconst createBundlerLogger: typeof createLogger =\n typeof createInfrastructureLogger === 'function'\n ? (createInfrastructureLogger as unknown as typeof createLogger)\n : createLogger;\n\nclass DynamicFilesystemChunkLoadingRuntimeModule extends RuntimeModule {\n private runtimeRequirements: Set<string>;\n private options: DynamicFilesystemChunkLoadingRuntimeModuleOptions;\n private chunkLoadingContext: ChunkLoadingContext;\n hooks = {\n strategyCase: new SyncWaterfallHook(['source']),\n };\n private logger = createBundlerLogger(\n '[ DynamicFilesystemChunkLoadingRuntimeModule ]',\n );\n\n constructor(\n runtimeRequirements: Set<string>,\n options: DynamicFilesystemChunkLoadingRuntimeModuleOptions,\n chunkLoadingContext: ChunkLoadingContext,\n ) {\n super('readFile chunk loading', RuntimeModule.STAGE_ATTACH + 1);\n this.runtimeRequirements = runtimeRequirements;\n\n this.options = options;\n this.chunkLoadingContext = chunkLoadingContext;\n }\n\n /**\n * @private\n * @param {Chunk} chunk chunk\n * @param {string} rootOutputDir root output directory\n * @returns {string} generated code\n */\n _generateBaseUri(chunk: Chunk, rootOutputDir: string) {\n const options = chunk.getEntryOptions();\n if (options && options.baseUri) {\n return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;\n }\n\n return `${RuntimeGlobals.baseURI} = require(\"url\").pathToFileURL(${\n rootOutputDir\n ? `__dirname + ${JSON.stringify('/' + rootOutputDir)}`\n : '__filename'\n });`;\n }\n\n /**\n * @private\n * @param {unknown[]} items item to log\n */\n _getLogger(...items: unknown[]) {\n if (!this.options.debug) {\n return '';\n }\n\n return `console.log(${items.join(',')});`;\n }\n\n /**\n * @returns {string} runtime code\n */\n override generate() {\n const { remotes = {}, name } = this.options;\n const { webpack } = this.chunkLoadingContext;\n const { chunkGraph, chunk, compilation } = this;\n const { Template } = webpack;\n if (!chunkGraph || !chunk || !compilation) {\n this.logger.warn('Missing required properties. Returning empty string.');\n return '';\n }\n\n const infrastructureLogger = compilation.getLogger?.(\n 'DynamicFilesystemChunkLoadingRuntimeModule',\n );\n if (infrastructureLogger) {\n this.logger.setDelegate(infrastructureLogger as any);\n }\n\n const { runtimeTemplate } = compilation;\n const jsModulePlugin =\n webpack?.javascript?.JavascriptModulesPlugin ||\n require('webpack/lib/javascript/JavascriptModulesPlugin');\n const { chunkHasJs } = jsModulePlugin;\n const fn = RuntimeGlobals.ensureChunkHandlers;\n\n const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);\n const hasJsMatcher = compileBooleanMatcher(conditionMap);\n const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);\n\n const outputName = compilation.getPath(\n jsModulePlugin.getChunkFilenameTemplate(chunk, compilation.outputOptions),\n { chunk, contentHashType: 'javascript' },\n );\n const rootOutputDir = getUndoPath(\n outputName,\n compilation.outputOptions.path || '',\n false,\n );\n const stateExpression = this.runtimeRequirements.has(\n RuntimeGlobals.hmrDownloadUpdateHandlers,\n )\n ? `${RuntimeGlobals.hmrRuntimeStatePrefix}_readFileVm`\n : undefined;\n\n const dynamicFilesystemChunkLoadingPluginCode = Template.asString([\n fileSystemRunInContextStrategy.toString(),\n httpEvalStrategy.toString(),\n httpVmStrategy.toString(),\n 'const loadChunkStrategy = async (strategyType,chunkId,rootOutputDir, remotes, callback) => {',\n Template.indent([\n 'switch (strategyType) {',\n Template.indent([\n 'case \"filesystem\": return await fileSystemRunInContextStrategy(chunkId,rootOutputDir, remotes, callback);',\n 'case \"http-eval\": return await httpEvalStrategy(chunkId,rootOutputDir, remotes, callback);',\n 'case \"http-vm\": return await httpVmStrategy(chunkId,rootOutputDir, remotes, callback);',\n this.hooks.strategyCase.call(\n 'default: throw new Error(\"Invalid strategy type\");',\n ) as string,\n ]),\n '}',\n ]),\n '};',\n ]);\n\n return Template.asString([\n dynamicFilesystemChunkLoadingPluginCode,\n this.runtimeRequirements.has(RuntimeGlobals.baseURI)\n ? this._generateBaseUri(chunk, rootOutputDir)\n : '// no baseURI',\n '',\n '// object to store loaded chunks',\n '// \"0\" means \"already loaded\", Promise means loading',\n `var installedChunks = ${\n stateExpression ? `${stateExpression} = ${stateExpression} || ` : ''\n }{`,\n Template.indent(\n Array.from(initialChunkIds, (id) => `${JSON.stringify(id)}: 0`).join(\n ',\\n',\n ),\n ),\n '};',\n '',\n handleOnChunkLoad(\n this.runtimeRequirements.has(RuntimeGlobals.onChunksLoaded),\n runtimeTemplate,\n ),\n '',\n generateInstallChunk(\n runtimeTemplate,\n this.runtimeRequirements.has(RuntimeGlobals.onChunksLoaded),\n ),\n '',\n this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers)\n ? generateLoadScript(runtimeTemplate)\n : '// no remote script loader needed',\n this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers)\n ? generateLoadingCode(\n this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers),\n fn,\n hasJsMatcher,\n rootOutputDir,\n remotes,\n name,\n )\n : '// no chunk loading',\n '',\n generateExternalInstallChunkCode(\n this.runtimeRequirements.has(RuntimeGlobals.externalInstallChunk),\n this.options.debug,\n ),\n '',\n generateHmrCode(\n this.runtimeRequirements.has(RuntimeGlobals.hmrDownloadUpdateHandlers),\n rootOutputDir,\n ),\n '',\n generateHmrManifestCode(\n this.runtimeRequirements.has(RuntimeGlobals.hmrDownloadManifest),\n rootOutputDir,\n ),\n ]);\n }\n}\n\nexport default DynamicFilesystemChunkLoadingRuntimeModule;\n"],"mappings":"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"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { __require } from "../../_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
import { generateExternalInstallChunkCode, generateHmrCode, generateHmrManifestCode, generateInstallChunk, generateLoadScript, generateLoadingCode, getInitialChunkIds, handleOnChunkLoad } from "./webpackChunkUtilities.mjs";
|
|
3
|
+
import { fileSystemRunInContextStrategy, httpEvalStrategy, httpVmStrategy } from "../filesystem/stratagies.mjs";
|
|
4
|
+
import { normalizeWebpackPath } from "@module-federation/sdk/normalize-webpack-path";
|
|
5
|
+
import { SyncWaterfallHook } from "tapable";
|
|
6
|
+
import { createInfrastructureLogger, createLogger } from "@module-federation/sdk";
|
|
7
|
+
|
|
8
|
+
//#region src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.ts
|
|
9
|
+
const { RuntimeGlobals, RuntimeModule } = __require(normalizeWebpackPath("webpack"));
|
|
10
|
+
const { getUndoPath } = __require(normalizeWebpackPath("webpack/lib/util/identifier"));
|
|
11
|
+
const compileBooleanMatcher = __require(normalizeWebpackPath("webpack/lib/util/compileBooleanMatcher"));
|
|
12
|
+
const createBundlerLogger = typeof createInfrastructureLogger === "function" ? createInfrastructureLogger : createLogger;
|
|
13
|
+
var DynamicFilesystemChunkLoadingRuntimeModule = class extends RuntimeModule {
|
|
14
|
+
constructor(runtimeRequirements, options, chunkLoadingContext) {
|
|
15
|
+
super("readFile chunk loading", RuntimeModule.STAGE_ATTACH + 1);
|
|
16
|
+
this.hooks = { strategyCase: new SyncWaterfallHook(["source"]) };
|
|
17
|
+
this.logger = createBundlerLogger("[ DynamicFilesystemChunkLoadingRuntimeModule ]");
|
|
18
|
+
this.runtimeRequirements = runtimeRequirements;
|
|
19
|
+
this.options = options;
|
|
20
|
+
this.chunkLoadingContext = chunkLoadingContext;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @private
|
|
24
|
+
* @param {Chunk} chunk chunk
|
|
25
|
+
* @param {string} rootOutputDir root output directory
|
|
26
|
+
* @returns {string} generated code
|
|
27
|
+
*/
|
|
28
|
+
_generateBaseUri(chunk, rootOutputDir) {
|
|
29
|
+
const options = chunk.getEntryOptions();
|
|
30
|
+
if (options && options.baseUri) return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
|
|
31
|
+
return `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${rootOutputDir ? `__dirname + ${JSON.stringify("/" + rootOutputDir)}` : "__filename"});`;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @private
|
|
35
|
+
* @param {unknown[]} items item to log
|
|
36
|
+
*/
|
|
37
|
+
_getLogger(...items) {
|
|
38
|
+
if (!this.options.debug) return "";
|
|
39
|
+
return `console.log(${items.join(",")});`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @returns {string} runtime code
|
|
43
|
+
*/
|
|
44
|
+
generate() {
|
|
45
|
+
const { remotes = {}, name } = this.options;
|
|
46
|
+
const { webpack } = this.chunkLoadingContext;
|
|
47
|
+
const { chunkGraph, chunk, compilation } = this;
|
|
48
|
+
const { Template } = webpack;
|
|
49
|
+
if (!chunkGraph || !chunk || !compilation) {
|
|
50
|
+
this.logger.warn("Missing required properties. Returning empty string.");
|
|
51
|
+
return "";
|
|
52
|
+
}
|
|
53
|
+
const infrastructureLogger = compilation.getLogger?.("DynamicFilesystemChunkLoadingRuntimeModule");
|
|
54
|
+
if (infrastructureLogger) this.logger.setDelegate(infrastructureLogger);
|
|
55
|
+
const { runtimeTemplate } = compilation;
|
|
56
|
+
const jsModulePlugin = webpack?.javascript?.JavascriptModulesPlugin || __require("webpack/lib/javascript/JavascriptModulesPlugin");
|
|
57
|
+
const { chunkHasJs } = jsModulePlugin;
|
|
58
|
+
const fn = RuntimeGlobals.ensureChunkHandlers;
|
|
59
|
+
const hasJsMatcher = compileBooleanMatcher(chunkGraph.getChunkConditionMap(chunk, chunkHasJs));
|
|
60
|
+
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
|
|
61
|
+
const rootOutputDir = getUndoPath(compilation.getPath(jsModulePlugin.getChunkFilenameTemplate(chunk, compilation.outputOptions), {
|
|
62
|
+
chunk,
|
|
63
|
+
contentHashType: "javascript"
|
|
64
|
+
}), compilation.outputOptions.path || "", false);
|
|
65
|
+
const stateExpression = this.runtimeRequirements.has(RuntimeGlobals.hmrDownloadUpdateHandlers) ? `${RuntimeGlobals.hmrRuntimeStatePrefix}_readFileVm` : void 0;
|
|
66
|
+
const dynamicFilesystemChunkLoadingPluginCode = Template.asString([
|
|
67
|
+
fileSystemRunInContextStrategy.toString(),
|
|
68
|
+
httpEvalStrategy.toString(),
|
|
69
|
+
httpVmStrategy.toString(),
|
|
70
|
+
"const loadChunkStrategy = async (strategyType,chunkId,rootOutputDir, remotes, callback) => {",
|
|
71
|
+
Template.indent([
|
|
72
|
+
"switch (strategyType) {",
|
|
73
|
+
Template.indent([
|
|
74
|
+
"case \"filesystem\": return await fileSystemRunInContextStrategy(chunkId,rootOutputDir, remotes, callback);",
|
|
75
|
+
"case \"http-eval\": return await httpEvalStrategy(chunkId,rootOutputDir, remotes, callback);",
|
|
76
|
+
"case \"http-vm\": return await httpVmStrategy(chunkId,rootOutputDir, remotes, callback);",
|
|
77
|
+
this.hooks.strategyCase.call("default: throw new Error(\"Invalid strategy type\");")
|
|
78
|
+
]),
|
|
79
|
+
"}"
|
|
80
|
+
]),
|
|
81
|
+
"};"
|
|
82
|
+
]);
|
|
83
|
+
return Template.asString([
|
|
84
|
+
dynamicFilesystemChunkLoadingPluginCode,
|
|
85
|
+
this.runtimeRequirements.has(RuntimeGlobals.baseURI) ? this._generateBaseUri(chunk, rootOutputDir) : "// no baseURI",
|
|
86
|
+
"",
|
|
87
|
+
"// object to store loaded chunks",
|
|
88
|
+
"// \"0\" means \"already loaded\", Promise means loading",
|
|
89
|
+
`var installedChunks = ${stateExpression ? `${stateExpression} = ${stateExpression} || ` : ""}{`,
|
|
90
|
+
Template.indent(Array.from(initialChunkIds, (id) => `${JSON.stringify(id)}: 0`).join(",\n")),
|
|
91
|
+
"};",
|
|
92
|
+
"",
|
|
93
|
+
handleOnChunkLoad(this.runtimeRequirements.has(RuntimeGlobals.onChunksLoaded), runtimeTemplate),
|
|
94
|
+
"",
|
|
95
|
+
generateInstallChunk(runtimeTemplate, this.runtimeRequirements.has(RuntimeGlobals.onChunksLoaded)),
|
|
96
|
+
"",
|
|
97
|
+
this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers) ? generateLoadScript(runtimeTemplate) : "// no remote script loader needed",
|
|
98
|
+
this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers) ? generateLoadingCode(this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers), fn, hasJsMatcher, rootOutputDir, remotes, name) : "// no chunk loading",
|
|
99
|
+
"",
|
|
100
|
+
generateExternalInstallChunkCode(this.runtimeRequirements.has(RuntimeGlobals.externalInstallChunk), this.options.debug),
|
|
101
|
+
"",
|
|
102
|
+
generateHmrCode(this.runtimeRequirements.has(RuntimeGlobals.hmrDownloadUpdateHandlers), rootOutputDir),
|
|
103
|
+
"",
|
|
104
|
+
generateHmrManifestCode(this.runtimeRequirements.has(RuntimeGlobals.hmrDownloadManifest), rootOutputDir)
|
|
105
|
+
]);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
//#endregion
|
|
110
|
+
export { DynamicFilesystemChunkLoadingRuntimeModule as default };
|
|
111
|
+
//# sourceMappingURL=DynamicFilesystemChunkLoadingRuntimeModule.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DynamicFilesystemChunkLoadingRuntimeModule.mjs","names":[],"sources":["../../../src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.ts"],"sourcesContent":["/*\n MIT License http://www.opensource.org/licenses/mit-license.php\n*/\nimport type { Chunk, Compiler } from 'webpack';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nconst { RuntimeGlobals, RuntimeModule } = 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');\nimport { SyncWaterfallHook } from 'tapable';\nconst compileBooleanMatcher = require(\n normalizeWebpackPath('webpack/lib/util/compileBooleanMatcher'),\n) as typeof import('webpack/lib/util/compileBooleanMatcher');\nimport {\n generateHmrCode,\n getInitialChunkIds,\n generateLoadingCode,\n generateHmrManifestCode,\n handleOnChunkLoad,\n generateLoadScript,\n generateInstallChunk,\n generateExternalInstallChunkCode,\n} from './webpackChunkUtilities';\nimport {\n createInfrastructureLogger,\n createLogger,\n} from '@module-federation/sdk';\nimport {\n fileSystemRunInContextStrategy,\n httpEvalStrategy,\n httpVmStrategy,\n} from '../filesystem/stratagies';\n\ninterface RemotesByType {\n functional: string[];\n normal: string[];\n}\n\ninterface DynamicFilesystemChunkLoadingRuntimeModuleOptions {\n baseURI: Compiler['options']['output']['publicPath'];\n promiseBaseURI?: string;\n remotes: Record<string, string>;\n name?: string;\n debug?: boolean;\n}\n\ninterface ChunkLoadingContext {\n webpack: Compiler['webpack'];\n}\n\nconst createBundlerLogger: typeof createLogger =\n typeof createInfrastructureLogger === 'function'\n ? (createInfrastructureLogger as unknown as typeof createLogger)\n : createLogger;\n\nclass DynamicFilesystemChunkLoadingRuntimeModule extends RuntimeModule {\n private runtimeRequirements: Set<string>;\n private options: DynamicFilesystemChunkLoadingRuntimeModuleOptions;\n private chunkLoadingContext: ChunkLoadingContext;\n hooks = {\n strategyCase: new SyncWaterfallHook(['source']),\n };\n private logger = createBundlerLogger(\n '[ DynamicFilesystemChunkLoadingRuntimeModule ]',\n );\n\n constructor(\n runtimeRequirements: Set<string>,\n options: DynamicFilesystemChunkLoadingRuntimeModuleOptions,\n chunkLoadingContext: ChunkLoadingContext,\n ) {\n super('readFile chunk loading', RuntimeModule.STAGE_ATTACH + 1);\n this.runtimeRequirements = runtimeRequirements;\n\n this.options = options;\n this.chunkLoadingContext = chunkLoadingContext;\n }\n\n /**\n * @private\n * @param {Chunk} chunk chunk\n * @param {string} rootOutputDir root output directory\n * @returns {string} generated code\n */\n _generateBaseUri(chunk: Chunk, rootOutputDir: string) {\n const options = chunk.getEntryOptions();\n if (options && options.baseUri) {\n return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;\n }\n\n return `${RuntimeGlobals.baseURI} = require(\"url\").pathToFileURL(${\n rootOutputDir\n ? `__dirname + ${JSON.stringify('/' + rootOutputDir)}`\n : '__filename'\n });`;\n }\n\n /**\n * @private\n * @param {unknown[]} items item to log\n */\n _getLogger(...items: unknown[]) {\n if (!this.options.debug) {\n return '';\n }\n\n return `console.log(${items.join(',')});`;\n }\n\n /**\n * @returns {string} runtime code\n */\n override generate() {\n const { remotes = {}, name } = this.options;\n const { webpack } = this.chunkLoadingContext;\n const { chunkGraph, chunk, compilation } = this;\n const { Template } = webpack;\n if (!chunkGraph || !chunk || !compilation) {\n this.logger.warn('Missing required properties. Returning empty string.');\n return '';\n }\n\n const infrastructureLogger = compilation.getLogger?.(\n 'DynamicFilesystemChunkLoadingRuntimeModule',\n );\n if (infrastructureLogger) {\n this.logger.setDelegate(infrastructureLogger as any);\n }\n\n const { runtimeTemplate } = compilation;\n const jsModulePlugin =\n webpack?.javascript?.JavascriptModulesPlugin ||\n require('webpack/lib/javascript/JavascriptModulesPlugin');\n const { chunkHasJs } = jsModulePlugin;\n const fn = RuntimeGlobals.ensureChunkHandlers;\n\n const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);\n const hasJsMatcher = compileBooleanMatcher(conditionMap);\n const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);\n\n const outputName = compilation.getPath(\n jsModulePlugin.getChunkFilenameTemplate(chunk, compilation.outputOptions),\n { chunk, contentHashType: 'javascript' },\n );\n const rootOutputDir = getUndoPath(\n outputName,\n compilation.outputOptions.path || '',\n false,\n );\n const stateExpression = this.runtimeRequirements.has(\n RuntimeGlobals.hmrDownloadUpdateHandlers,\n )\n ? `${RuntimeGlobals.hmrRuntimeStatePrefix}_readFileVm`\n : undefined;\n\n const dynamicFilesystemChunkLoadingPluginCode = Template.asString([\n fileSystemRunInContextStrategy.toString(),\n httpEvalStrategy.toString(),\n httpVmStrategy.toString(),\n 'const loadChunkStrategy = async (strategyType,chunkId,rootOutputDir, remotes, callback) => {',\n Template.indent([\n 'switch (strategyType) {',\n Template.indent([\n 'case \"filesystem\": return await fileSystemRunInContextStrategy(chunkId,rootOutputDir, remotes, callback);',\n 'case \"http-eval\": return await httpEvalStrategy(chunkId,rootOutputDir, remotes, callback);',\n 'case \"http-vm\": return await httpVmStrategy(chunkId,rootOutputDir, remotes, callback);',\n this.hooks.strategyCase.call(\n 'default: throw new Error(\"Invalid strategy type\");',\n ) as string,\n ]),\n '}',\n ]),\n '};',\n ]);\n\n return Template.asString([\n dynamicFilesystemChunkLoadingPluginCode,\n this.runtimeRequirements.has(RuntimeGlobals.baseURI)\n ? this._generateBaseUri(chunk, rootOutputDir)\n : '// no baseURI',\n '',\n '// object to store loaded chunks',\n '// \"0\" means \"already loaded\", Promise means loading',\n `var installedChunks = ${\n stateExpression ? `${stateExpression} = ${stateExpression} || ` : ''\n }{`,\n Template.indent(\n Array.from(initialChunkIds, (id) => `${JSON.stringify(id)}: 0`).join(\n ',\\n',\n ),\n ),\n '};',\n '',\n handleOnChunkLoad(\n this.runtimeRequirements.has(RuntimeGlobals.onChunksLoaded),\n runtimeTemplate,\n ),\n '',\n generateInstallChunk(\n runtimeTemplate,\n this.runtimeRequirements.has(RuntimeGlobals.onChunksLoaded),\n ),\n '',\n this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers)\n ? generateLoadScript(runtimeTemplate)\n : '// no remote script loader needed',\n this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers)\n ? generateLoadingCode(\n this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers),\n fn,\n hasJsMatcher,\n rootOutputDir,\n remotes,\n name,\n )\n : '// no chunk loading',\n '',\n generateExternalInstallChunkCode(\n this.runtimeRequirements.has(RuntimeGlobals.externalInstallChunk),\n this.options.debug,\n ),\n '',\n generateHmrCode(\n this.runtimeRequirements.has(RuntimeGlobals.hmrDownloadUpdateHandlers),\n rootOutputDir,\n ),\n '',\n generateHmrManifestCode(\n this.runtimeRequirements.has(RuntimeGlobals.hmrDownloadManifest),\n rootOutputDir,\n ),\n ]);\n }\n}\n\nexport default DynamicFilesystemChunkLoadingRuntimeModule;\n"],"mappings":"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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Chunk, Compiler, Module } from "webpack";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/EntryChunkTrackerPlugin.d.ts
|
|
4
|
+
interface Options {
|
|
5
|
+
eager?: RegExp | ((module: Module) => boolean);
|
|
6
|
+
excludeChunk?: (chunk: Chunk) => boolean;
|
|
7
|
+
}
|
|
8
|
+
declare class EntryChunkTrackerPlugin {
|
|
9
|
+
private _options;
|
|
10
|
+
constructor(options?: Options);
|
|
11
|
+
apply(compiler: Compiler): void;
|
|
12
|
+
private _handleRenderStartup;
|
|
13
|
+
private _getTemplateString;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { Options, EntryChunkTrackerPlugin as default };
|
|
17
|
+
//# sourceMappingURL=EntryChunkTrackerPlugin.d.mts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Chunk, Compiler, Module } from "webpack";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/EntryChunkTrackerPlugin.d.ts
|
|
4
|
+
interface Options {
|
|
5
|
+
eager?: RegExp | ((module: Module) => boolean);
|
|
6
|
+
excludeChunk?: (chunk: Chunk) => boolean;
|
|
7
|
+
}
|
|
8
|
+
declare class EntryChunkTrackerPlugin {
|
|
9
|
+
private _options;
|
|
10
|
+
constructor(options?: Options);
|
|
11
|
+
apply(compiler: Compiler): void;
|
|
12
|
+
private _handleRenderStartup;
|
|
13
|
+
private _getTemplateString;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { Options, EntryChunkTrackerPlugin as default };
|
|
17
|
+
//# sourceMappingURL=EntryChunkTrackerPlugin.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
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/EntryChunkTrackerPlugin.ts
|
|
6
|
+
require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/SortableSet"));
|
|
7
|
+
var EntryChunkTrackerPlugin = class {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this._options = options || {};
|
|
10
|
+
}
|
|
11
|
+
apply(compiler) {
|
|
12
|
+
compiler.hooks.thisCompilation.tap("EntryChunkTrackerPlugin", (compilation) => {
|
|
13
|
+
this._handleRenderStartup(compiler, compilation);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
_handleRenderStartup(compiler, compilation) {
|
|
17
|
+
compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation).renderStartup.tap("EntryChunkTrackerPlugin", (source, _renderContext, upperContext) => {
|
|
18
|
+
if (this._options.excludeChunk && this._options.excludeChunk(upperContext.chunk)) return source;
|
|
19
|
+
const templateString = this._getTemplateString(compiler, source);
|
|
20
|
+
return new compiler.webpack.sources.ConcatSource(templateString);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_getTemplateString(compiler, source) {
|
|
24
|
+
const { Template } = compiler.webpack;
|
|
25
|
+
return Template.asString([`if(typeof module !== 'undefined') {
|
|
26
|
+
globalThis.entryChunkCache = globalThis.entryChunkCache || new Set();
|
|
27
|
+
module.filename && globalThis.entryChunkCache.add(module.filename);
|
|
28
|
+
if(module.children) {
|
|
29
|
+
module.children.forEach(function(c) {
|
|
30
|
+
c.filename && globalThis.entryChunkCache.add(c.filename);
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
}`, Template.indent(source.source().toString())]);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.default = EntryChunkTrackerPlugin;
|
|
39
|
+
//# sourceMappingURL=EntryChunkTrackerPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntryChunkTrackerPlugin.js","names":[],"sources":["../../../src/plugins/EntryChunkTrackerPlugin.ts"],"sourcesContent":["import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport type {\n Compiler,\n Compilation,\n Chunk,\n sources,\n Module,\n RuntimeGlobals,\n javascript,\n} from 'webpack';\nimport type { SyncWaterfallHook } from 'tapable';\n\nconst SortableSet = require(\n normalizeWebpackPath('webpack/lib/util/SortableSet'),\n) as typeof import('webpack/lib/util/SortableSet');\n\ntype CompilationHooksJavascriptModulesPlugin = ReturnType<\n typeof javascript.JavascriptModulesPlugin.getCompilationHooks\n>;\ntype RenderStartup = CompilationHooksJavascriptModulesPlugin['renderStartup'];\n\ntype InferStartupRenderContext<T> =\n T extends SyncWaterfallHook<\n [infer Source, infer Module, infer StartupRenderContext]\n >\n ? StartupRenderContext\n : never;\n\ntype StartupRenderContext = InferStartupRenderContext<RenderStartup>;\n\nexport interface Options {\n eager?: RegExp | ((module: Module) => boolean);\n excludeChunk?: (chunk: Chunk) => boolean;\n}\n\nclass EntryChunkTrackerPlugin {\n private _options: Options;\n\n constructor(options?: Options) {\n this._options = options || {};\n }\n\n apply(compiler: Compiler) {\n compiler.hooks.thisCompilation.tap(\n 'EntryChunkTrackerPlugin',\n (compilation: Compilation) => {\n this._handleRenderStartup(compiler, compilation);\n },\n );\n }\n private _handleRenderStartup(compiler: Compiler, compilation: Compilation) {\n compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(\n compilation,\n ).renderStartup.tap(\n 'EntryChunkTrackerPlugin',\n (\n source: sources.Source,\n _renderContext: Module,\n upperContext: StartupRenderContext,\n ) => {\n if (\n this._options.excludeChunk &&\n this._options.excludeChunk(upperContext.chunk)\n ) {\n return source;\n }\n\n const templateString = this._getTemplateString(compiler, source);\n\n return new compiler.webpack.sources.ConcatSource(templateString);\n },\n );\n }\n\n private _getTemplateString(compiler: Compiler, source: sources.Source) {\n const { Template } = compiler.webpack;\n return Template.asString([\n `if(typeof module !== 'undefined') {\n globalThis.entryChunkCache = globalThis.entryChunkCache || new Set();\n module.filename && globalThis.entryChunkCache.add(module.filename);\n if(module.children) {\n module.children.forEach(function(c) {\n c.filename && globalThis.entryChunkCache.add(c.filename);\n })\n}\n }`,\n Template.indent(source.source().toString()),\n ]);\n }\n}\n\nexport default EntryChunkTrackerPlugin;\n"],"mappings":";;;;;AAYoB,gFACG,+BAA+B,CACrD;AAqBD,IAAM,0BAAN,MAA8B;CAG5B,YAAY,SAAmB;AAC7B,OAAK,WAAW,WAAW,EAAE;;CAG/B,MAAM,UAAoB;AACxB,WAAS,MAAM,gBAAgB,IAC7B,4BACC,gBAA6B;AAC5B,QAAK,qBAAqB,UAAU,YAAY;IAEnD;;CAEH,AAAQ,qBAAqB,UAAoB,aAA0B;AACzE,WAAS,QAAQ,WAAW,wBAAwB,oBAClD,YACD,CAAC,cAAc,IACd,4BAEE,QACA,gBACA,iBACG;AACH,OACE,KAAK,SAAS,gBACd,KAAK,SAAS,aAAa,aAAa,MAAM,CAE9C,QAAO;GAGT,MAAM,iBAAiB,KAAK,mBAAmB,UAAU,OAAO;AAEhE,UAAO,IAAI,SAAS,QAAQ,QAAQ,aAAa,eAAe;IAEnE;;CAGH,AAAQ,mBAAmB,UAAoB,QAAwB;EACrE,MAAM,EAAE,aAAa,SAAS;AAC9B,SAAO,SAAS,SAAS,CACvB;;;;;;;;UASA,SAAS,OAAO,OAAO,QAAQ,CAAC,UAAU,CAAC,CAC5C,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { __require } from "../../_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
import { normalizeWebpackPath } from "@module-federation/sdk/normalize-webpack-path";
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/EntryChunkTrackerPlugin.ts
|
|
5
|
+
__require(normalizeWebpackPath("webpack/lib/util/SortableSet"));
|
|
6
|
+
var EntryChunkTrackerPlugin = class {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this._options = options || {};
|
|
9
|
+
}
|
|
10
|
+
apply(compiler) {
|
|
11
|
+
compiler.hooks.thisCompilation.tap("EntryChunkTrackerPlugin", (compilation) => {
|
|
12
|
+
this._handleRenderStartup(compiler, compilation);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
_handleRenderStartup(compiler, compilation) {
|
|
16
|
+
compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation).renderStartup.tap("EntryChunkTrackerPlugin", (source, _renderContext, upperContext) => {
|
|
17
|
+
if (this._options.excludeChunk && this._options.excludeChunk(upperContext.chunk)) return source;
|
|
18
|
+
const templateString = this._getTemplateString(compiler, source);
|
|
19
|
+
return new compiler.webpack.sources.ConcatSource(templateString);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
_getTemplateString(compiler, source) {
|
|
23
|
+
const { Template } = compiler.webpack;
|
|
24
|
+
return Template.asString([`if(typeof module !== 'undefined') {
|
|
25
|
+
globalThis.entryChunkCache = globalThis.entryChunkCache || new Set();
|
|
26
|
+
module.filename && globalThis.entryChunkCache.add(module.filename);
|
|
27
|
+
if(module.children) {
|
|
28
|
+
module.children.forEach(function(c) {
|
|
29
|
+
c.filename && globalThis.entryChunkCache.add(c.filename);
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
}`, Template.indent(source.source().toString())]);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { EntryChunkTrackerPlugin as default };
|
|
38
|
+
//# sourceMappingURL=EntryChunkTrackerPlugin.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntryChunkTrackerPlugin.mjs","names":[],"sources":["../../../src/plugins/EntryChunkTrackerPlugin.ts"],"sourcesContent":["import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport type {\n Compiler,\n Compilation,\n Chunk,\n sources,\n Module,\n RuntimeGlobals,\n javascript,\n} from 'webpack';\nimport type { SyncWaterfallHook } from 'tapable';\n\nconst SortableSet = require(\n normalizeWebpackPath('webpack/lib/util/SortableSet'),\n) as typeof import('webpack/lib/util/SortableSet');\n\ntype CompilationHooksJavascriptModulesPlugin = ReturnType<\n typeof javascript.JavascriptModulesPlugin.getCompilationHooks\n>;\ntype RenderStartup = CompilationHooksJavascriptModulesPlugin['renderStartup'];\n\ntype InferStartupRenderContext<T> =\n T extends SyncWaterfallHook<\n [infer Source, infer Module, infer StartupRenderContext]\n >\n ? StartupRenderContext\n : never;\n\ntype StartupRenderContext = InferStartupRenderContext<RenderStartup>;\n\nexport interface Options {\n eager?: RegExp | ((module: Module) => boolean);\n excludeChunk?: (chunk: Chunk) => boolean;\n}\n\nclass EntryChunkTrackerPlugin {\n private _options: Options;\n\n constructor(options?: Options) {\n this._options = options || {};\n }\n\n apply(compiler: Compiler) {\n compiler.hooks.thisCompilation.tap(\n 'EntryChunkTrackerPlugin',\n (compilation: Compilation) => {\n this._handleRenderStartup(compiler, compilation);\n },\n );\n }\n private _handleRenderStartup(compiler: Compiler, compilation: Compilation) {\n compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(\n compilation,\n ).renderStartup.tap(\n 'EntryChunkTrackerPlugin',\n (\n source: sources.Source,\n _renderContext: Module,\n upperContext: StartupRenderContext,\n ) => {\n if (\n this._options.excludeChunk &&\n this._options.excludeChunk(upperContext.chunk)\n ) {\n return source;\n }\n\n const templateString = this._getTemplateString(compiler, source);\n\n return new compiler.webpack.sources.ConcatSource(templateString);\n },\n );\n }\n\n private _getTemplateString(compiler: Compiler, source: sources.Source) {\n const { Template } = compiler.webpack;\n return Template.asString([\n `if(typeof module !== 'undefined') {\n globalThis.entryChunkCache = globalThis.entryChunkCache || new Set();\n module.filename && globalThis.entryChunkCache.add(module.filename);\n if(module.children) {\n module.children.forEach(function(c) {\n c.filename && globalThis.entryChunkCache.add(c.filename);\n })\n}\n }`,\n Template.indent(source.source().toString()),\n ]);\n }\n}\n\nexport default EntryChunkTrackerPlugin;\n"],"mappings":";;;;UAaE,qBAAqB,+BAA+B,CACrD;AAqBD,IAAM,0BAAN,MAA8B;CAG5B,YAAY,SAAmB;AAC7B,OAAK,WAAW,WAAW,EAAE;;CAG/B,MAAM,UAAoB;AACxB,WAAS,MAAM,gBAAgB,IAC7B,4BACC,gBAA6B;AAC5B,QAAK,qBAAqB,UAAU,YAAY;IAEnD;;CAEH,AAAQ,qBAAqB,UAAoB,aAA0B;AACzE,WAAS,QAAQ,WAAW,wBAAwB,oBAClD,YACD,CAAC,cAAc,IACd,4BAEE,QACA,gBACA,iBACG;AACH,OACE,KAAK,SAAS,gBACd,KAAK,SAAS,aAAa,aAAa,MAAM,CAE9C,QAAO;GAGT,MAAM,iBAAiB,KAAK,mBAAmB,UAAU,OAAO;AAEhE,UAAO,IAAI,SAAS,QAAQ,QAAQ,aAAa,eAAe;IAEnE;;CAGH,AAAQ,mBAAmB,UAAoB,QAAwB;EACrE,MAAM,EAAE,aAAa,SAAS;AAC9B,SAAO,SAAS,SAAS,CACvB;;;;;;;;UASA,SAAS,OAAO,OAAO,QAAQ,CAAC,UAAU,CAAC,CAC5C,CAAC"}
|
|
@@ -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
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ModuleFederationPluginOptions } from "../types/index.js";
|
|
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
|
+
export = NodeFederationPlugin;
|
|
53
|
+
//# sourceMappingURL=NodeFederationPlugin.d.ts.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
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;
|
|
10
|
+
function getRuntimePluginPath() {
|
|
11
|
+
return require.resolve("../runtimePlugin.js");
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Class representing a NodeFederationPlugin.
|
|
15
|
+
* @class
|
|
16
|
+
*/
|
|
17
|
+
var NodeFederationPlugin = class {
|
|
18
|
+
/**
|
|
19
|
+
* Create a NodeFederationPlugin.
|
|
20
|
+
* @constructor
|
|
21
|
+
* @param {NodeFederationOptions} options - The options for the NodeFederationPlugin
|
|
22
|
+
* @param {Context} context - The context for the NodeFederationPlugin
|
|
23
|
+
*/
|
|
24
|
+
constructor({ debug, useRuntimePlugin, ...options }, context) {
|
|
25
|
+
this.logger = createBundlerLogger("[ Node Federation Plugin ]");
|
|
26
|
+
this._options = options || {};
|
|
27
|
+
this.context = context || {};
|
|
28
|
+
this.useRuntimePlugin = useRuntimePlugin || false;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Apply method for the NodeFederationPlugin class.
|
|
32
|
+
* @method
|
|
33
|
+
* @param {Compiler} compiler - The webpack compiler.
|
|
34
|
+
*/
|
|
35
|
+
apply(compiler) {
|
|
36
|
+
(0, _module_federation_sdk.bindLoggerToCompiler)(this.logger, compiler, "NodeFederationPlugin");
|
|
37
|
+
const { webpack } = compiler;
|
|
38
|
+
const pluginOptions = this.preparePluginOptions();
|
|
39
|
+
this.updateCompilerOptions(compiler);
|
|
40
|
+
new (this.getModuleFederationPlugin(compiler, webpack))(pluginOptions).apply(compiler);
|
|
41
|
+
new require_src_plugins_EntryChunkTrackerPlugin.default({}).apply(compiler);
|
|
42
|
+
}
|
|
43
|
+
preparePluginOptions() {
|
|
44
|
+
this._options.runtimePlugins = [...this.useRuntimePlugin ? [getRuntimePluginPath()] : [], ...this._options.runtimePlugins || []];
|
|
45
|
+
return {
|
|
46
|
+
...this._options,
|
|
47
|
+
remotes: this._options.remotes || {},
|
|
48
|
+
runtimePlugins: this._options.runtimePlugins,
|
|
49
|
+
dts: this._options.dts ?? false
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
updateCompilerOptions(compiler) {
|
|
53
|
+
const chunkFileName = compiler.options?.output?.chunkFilename;
|
|
54
|
+
const uniqueName = compiler?.options?.output?.uniqueName || this._options.name;
|
|
55
|
+
if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
56
|
+
const suffix = `-[contenthash].js`;
|
|
57
|
+
compiler.options.output.chunkFilename = chunkFileName.replace(".js", suffix);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
getModuleFederationPlugin(compiler, webpack) {
|
|
61
|
+
let ModuleFederationPlugin;
|
|
62
|
+
try {
|
|
63
|
+
return require("@module-federation/enhanced").ModuleFederationPlugin;
|
|
64
|
+
} catch (e) {
|
|
65
|
+
this.logger.error("Can't find @module-federation/enhanced, falling back to webpack ModuleFederationPlugin, this may not work");
|
|
66
|
+
if (this.context.ModuleFederationPlugin) ModuleFederationPlugin = this.context.ModuleFederationPlugin;
|
|
67
|
+
else if (webpack && webpack.container && webpack.container.ModuleFederationPlugin) ModuleFederationPlugin = webpack.container.ModuleFederationPlugin;
|
|
68
|
+
else ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
|
|
69
|
+
return ModuleFederationPlugin;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
exports.default = NodeFederationPlugin;
|
|
76
|
+
//# sourceMappingURL=NodeFederationPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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\nfunction getRuntimePluginPath(): string {\n return require.resolve(\n process.env.IS_ESM_BUILD === 'true'\n ? '../runtimePlugin.mjs'\n : '../runtimePlugin.js',\n );\n}\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 ? [getRuntimePluginPath()] : []),\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;AAEN,SAAS,uBAA+B;AACtC,QAAO,QAAQ,QAGT,sBACL;;;;;;AAOH,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,sBAAsB,CAAC,GAAG,EAAE,EACzD,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,73 @@
|
|
|
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
|
+
function getRuntimePluginPath() {
|
|
8
|
+
return __require.resolve("../runtimePlugin.mjs");
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
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
|
+
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 EntryChunkTrackerPlugin({}).apply(compiler);
|
|
39
|
+
}
|
|
40
|
+
preparePluginOptions() {
|
|
41
|
+
this._options.runtimePlugins = [...this.useRuntimePlugin ? [getRuntimePluginPath()] : [], ...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
|
|
72
|
+
export { NodeFederationPlugin as default };
|
|
73
|
+
//# 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\nfunction getRuntimePluginPath(): string {\n return require.resolve(\n process.env.IS_ESM_BUILD === 'true'\n ? '../runtimePlugin.mjs'\n : '../runtimePlugin.js',\n );\n}\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 ? [getRuntimePluginPath()] : []),\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;AAEN,SAAS,uBAA+B;AACtC,kBAAe,QAET,uBAEL;;;;;;AAOH,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,CAAC,sBAAsB,CAAC,GAAG,EAAE,EACzD,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
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
export = AutoPublicPathRuntimeModule;
|
|
14
|
+
//# sourceMappingURL=RemotePublicPathRuntimeModule.d.ts.map
|