@module-federation/node 2.7.49 → 2.7.50
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/plugins/createBundlerLogger.js +9 -0
- package/dist/plugins/createBundlerLogger.js.map +1 -0
- package/dist/plugins/createBundlerLogger.mjs +8 -0
- package/dist/plugins/createBundlerLogger.mjs.map +1 -0
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js +2 -3
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.js.map +1 -1
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.mjs +1 -2
- package/dist/src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.mjs.map +1 -1
- package/dist/src/plugins/NodeFederationPlugin.js +2 -2
- package/dist/src/plugins/NodeFederationPlugin.js.map +1 -1
- package/dist/src/plugins/NodeFederationPlugin.mjs +2 -2
- package/dist/src/plugins/NodeFederationPlugin.mjs.map +1 -1
- package/dist/src/plugins/StreamingTargetPlugin.js.map +1 -1
- package/dist/src/plugins/StreamingTargetPlugin.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.js');
|
|
2
|
+
let _module_federation_sdk = require("@module-federation/sdk");
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/createBundlerLogger.ts
|
|
5
|
+
const createBundlerLogger = typeof _module_federation_sdk.createInfrastructureLogger === "function" ? _module_federation_sdk.createInfrastructureLogger : _module_federation_sdk.createLogger;
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
exports.createBundlerLogger = createBundlerLogger;
|
|
9
|
+
//# sourceMappingURL=createBundlerLogger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBundlerLogger.js","names":["createInfrastructureLogger","createLogger"],"sources":["../../src/plugins/createBundlerLogger.ts"],"sourcesContent":["import {\n createInfrastructureLogger,\n createLogger,\n} from '@module-federation/sdk';\n\nexport const createBundlerLogger: typeof createLogger =\n typeof createInfrastructureLogger === 'function'\n ? (createInfrastructureLogger as unknown as typeof createLogger)\n : createLogger;\n"],"mappings":";;;;AAKA,MAAa,sBACX,OAAOA,sDAA+B,aACjCA,oDACDC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createInfrastructureLogger, createLogger } from "@module-federation/sdk";
|
|
2
|
+
|
|
3
|
+
//#region src/plugins/createBundlerLogger.ts
|
|
4
|
+
const createBundlerLogger = typeof createInfrastructureLogger === "function" ? createInfrastructureLogger : createLogger;
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
export { createBundlerLogger };
|
|
8
|
+
//# sourceMappingURL=createBundlerLogger.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBundlerLogger.mjs","names":[],"sources":["../../src/plugins/createBundlerLogger.ts"],"sourcesContent":["import {\n createInfrastructureLogger,\n createLogger,\n} from '@module-federation/sdk';\n\nexport const createBundlerLogger: typeof createLogger =\n typeof createInfrastructureLogger === 'function'\n ? (createInfrastructureLogger as unknown as typeof createLogger)\n : createLogger;\n"],"mappings":";;;AAKA,MAAa,sBACX,OAAO,+BAA+B,aACjC,6BACD"}
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
2
|
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
3
3
|
const require_src_plugins_webpackChunkUtilities = require('./webpackChunkUtilities.js');
|
|
4
|
+
const require_createBundlerLogger = require('../../plugins/createBundlerLogger.js');
|
|
4
5
|
const require_src_filesystem_stratagies = require('../filesystem/stratagies.js');
|
|
5
6
|
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
6
7
|
let tapable = require("tapable");
|
|
7
|
-
let _module_federation_sdk = require("@module-federation/sdk");
|
|
8
8
|
|
|
9
9
|
//#region src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.ts
|
|
10
10
|
const { RuntimeGlobals, RuntimeModule } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
|
|
11
11
|
const { getUndoPath } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/identifier"));
|
|
12
12
|
const compileBooleanMatcher = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/compileBooleanMatcher"));
|
|
13
|
-
const createBundlerLogger = typeof _module_federation_sdk.createInfrastructureLogger === "function" ? _module_federation_sdk.createInfrastructureLogger : _module_federation_sdk.createLogger;
|
|
14
13
|
var DynamicFilesystemChunkLoadingRuntimeModule = class extends RuntimeModule {
|
|
15
14
|
constructor(runtimeRequirements, options, chunkLoadingContext) {
|
|
16
15
|
super("readFile chunk loading", RuntimeModule.STAGE_ATTACH + 1);
|
|
17
16
|
this.hooks = { strategyCase: new tapable.SyncWaterfallHook(["source"]) };
|
|
18
|
-
this.logger = createBundlerLogger("[ DynamicFilesystemChunkLoadingRuntimeModule ]");
|
|
17
|
+
this.logger = require_createBundlerLogger.createBundlerLogger("[ DynamicFilesystemChunkLoadingRuntimeModule ]");
|
|
19
18
|
this.runtimeRequirements = runtimeRequirements;
|
|
20
19
|
this.options = options;
|
|
21
20
|
this.chunkLoadingContext = chunkLoadingContext;
|
|
@@ -1 +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":";;;;;;;;;AAKA,MAAM,EAAE,gBAAgB,kBAAkB,gFACnB,UAAU,CAChC;AACD,MAAM,EAAE,gBAAgB,gFACD,8BAA8B,CACpD;AAED,MAAM,wBAAwB,gFACP,yCAAyC,CAC/D;AAsCD,MAAM,sBACJ,OAAOA,sDAA+B,aACjCA,oDACDC;AAEN,IAAM,6CAAN,cAAyD,cAAc;CAWrE,YACE,qBACA,SACA,qBACA;AACA,QAAM,0BAA0B,cAAc,eAAe,EAAE;eAZzD,EACN,cAAc,IAAIC,0BAAkB,CAAC,SAAS,CAAC,EAChD;gBACgB,oBACf,iDACD;AAQC,OAAK,sBAAsB;AAE3B,OAAK,UAAU;AACf,OAAK,sBAAsB;;;;;;;;CAS7B,iBAAiB,OAAc,eAAuB;EACpD,MAAM,UAAU,MAAM,iBAAiB;AACvC,MAAI,WAAW,QAAQ,QACrB,QAAO,GAAG,eAAe,QAAQ,KAAK,KAAK,UAAU,QAAQ,QAAQ,CAAC;AAGxE,SAAO,GAAG,eAAe,QAAQ,kCAC/B,gBACI,eAAe,KAAK,UAAU,MAAM,cAAc,KAClD,aACL;;;;;;CAOH,WAAW,GAAG,OAAkB;AAC9B,MAAI,CAAC,KAAK,QAAQ,MAChB,QAAO;AAGT,SAAO,eA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KAAK,gBAAgB,QAAQ,GACnE;GACD,SAAS,OACP,MAAM,KAAK,kBAAkB,OAAO,GAAG,KAAK,UAAU,GAAG,CAAC,KAAK,CAAC,KAC9D,MACD,CACF;GACD;GACA;GACAC,4DACE,KAAK,oBAAoB,IAAI,eAAe,eAAe,EAC3D,gBACD;GACD;GACAC,+DACE,iBACA,KAAK,oBAAoB,IAAI,eAAe,eAAe,CAC5D;GACD;GACA,KAAK,oBAAoB,IAAI,eAAe,oBAAoB,GAC5DC,6DAAmB,gBAAgB,GACnC;GACJ,KAAK,oBAAoB,IAAI,eAAe,oBAAoB,GAC5DC,8DACE,KAAK,oBAAoB,IAAI,eAAe,oBAAoB,EAChE,IACA,cACA,eACA,SACA,KACD,GACD;GACJ;GACAC,2EACE,KAAK,oBAAoB,IAAI,eAAe,qBAAqB,EACjE,KAAK,QAAQ,MACd;GACD;GACAC,0DACE,KAAK,oBAAoB,IAAI,eAAe,0BAA0B,EACtE,cACD;GACD;GACAC,kEACE,KAAK,oBAAoB,IAAI,eAAe,oBAAoB,EAChE,cACD;GACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"DynamicFilesystemChunkLoadingRuntimeModule.js","names":["SyncWaterfallHook","createBundlerLogger","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 { createBundlerLogger } from './createBundlerLogger';\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\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(R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AAoB,IAAI,eAAe,oBAAoB,EAChE,IACA,cACA,eACA,SACA,KACD,GACD;GACJ;GACAC,2EACE,KAAK,oBAAoB,IAAI,eAAe,qBAAqB,EACjE,KAAK,QAAQ,MACd;GACD;GACAC,0DACE,KAAK,oBAAoB,IAAI,eAAe,0BAA0B,EACtE,cACD;GACD;GACAC,kEACE,KAAK,oBAAoB,IAAI,eAAe,oBAAoB,EAChE,cACD;GACF,CAAC"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { __require } from "../../_virtual/_rolldown/runtime.mjs";
|
|
2
2
|
import { generateExternalInstallChunkCode, generateHmrCode, generateHmrManifestCode, generateInstallChunk, generateLoadScript, generateLoadingCode, getInitialChunkIds, handleOnChunkLoad } from "./webpackChunkUtilities.mjs";
|
|
3
|
+
import { createBundlerLogger } from "../../plugins/createBundlerLogger.mjs";
|
|
3
4
|
import { fileSystemRunInContextStrategy, httpEvalStrategy, httpVmStrategy } from "../filesystem/stratagies.mjs";
|
|
4
5
|
import { normalizeWebpackPath } from "@module-federation/sdk/normalize-webpack-path";
|
|
5
6
|
import { SyncWaterfallHook } from "tapable";
|
|
6
|
-
import { createInfrastructureLogger, createLogger } from "@module-federation/sdk";
|
|
7
7
|
|
|
8
8
|
//#region src/plugins/DynamicFilesystemChunkLoadingRuntimeModule.ts
|
|
9
9
|
const { RuntimeGlobals, RuntimeModule } = __require(normalizeWebpackPath("webpack"));
|
|
10
10
|
const { getUndoPath } = __require(normalizeWebpackPath("webpack/lib/util/identifier"));
|
|
11
11
|
const compileBooleanMatcher = __require(normalizeWebpackPath("webpack/lib/util/compileBooleanMatcher"));
|
|
12
|
-
const createBundlerLogger = typeof createInfrastructureLogger === "function" ? createInfrastructureLogger : createLogger;
|
|
13
12
|
var DynamicFilesystemChunkLoadingRuntimeModule = class extends RuntimeModule {
|
|
14
13
|
constructor(runtimeRequirements, options, chunkLoadingContext) {
|
|
15
14
|
super("readFile chunk loading", RuntimeModule.STAGE_ATTACH + 1);
|
|
@@ -1 +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":";;;;;;;;AAKA,MAAM,EAAE,gBAAgB,4BACtB,qBAAqB,UAAU,CAChC;AACD,MAAM,EAAE,0BACN,qBAAqB,8BAA8B,CACpD;AAED,MAAM,kCACJ,qBAAqB,yCAAyC,CAC/D;AAsCD,MAAM,sBACJ,OAAO,+BAA+B,aACjC,6BACD;AAEN,IAAM,6CAAN,cAAyD,cAAc;CAWrE,YACE,qBACA,SACA,qBACA;AACA,QAAM,0BAA0B,cAAc,eAAe,EAAE;eAZzD,EACN,cAAc,IAAI,kBAAkB,CAAC,SAAS,CAAC,EAChD;gBACgB,oBACf,iDACD;AAQC,OAAK,sBAAsB;AAE3B,OAAK,UAAU;AACf,OAAK,sBAAsB;;;;;;;;CAS7B,iBAAiB,OAAc,eAAuB;EACpD,MAAM,UAAU,MAAM,iBAAiB;AACvC,MAAI,WAAW,QAAQ,QACrB,QAAO,GAAG,eAAe,QAAQ,KAAK,KAAK,UAAU,QAAQ,QAAQ,CAAC;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CAAC;AAEF,SAAO,SAAS,SAAS;GACvB;GACA,KAAK,oBAAoB,IAAI,eAAe,QAAQ,GAChD,KAAK,iBAAiB,OAAO,cAAc,GAC3C;GACJ;GACA;GACA;GACA,yBACE,kBAAkB,GAAG,gBAAgB,KAAK,gBAAgB,QAAQ,GACnE;GACD,SAAS,OACP,MAAM,KAAK,kBAAkB,OAAO,GAAG,KAAK,UAAU,GAAG,CAAC,KAAK,CAAC,KAC9D,MACD,CACF;GACD;GACA;GACA,kBACE,KAAK,oBAAoB,IAAI,eAAe,eAAe,EAC3D,gBACD;GACD;GACA,qBACE,iBACA,KAAK,oBAAoB,IAAI,eAAe,eAAe,CAC5D;GACD;GACA,KAAK,oBAAoB,IAAI,eAAe,oBAAoB,GAC5D,mBAAmB,gBAAgB,GACnC;GACJ,KAAK,oBAAoB,IAAI,eAAe,oBAAoB,GAC5D,oBACE,KAAK,oBAAoB,IAAI,eAAe,oBAAoB,EAChE,IACA,cACA,eACA,SACA,KACD,GACD;GACJ;GACA,iCACE,KAAK,oBAAoB,IAAI,eAAe,qBAAqB,EACjE,KAAK,QAAQ,MACd;GACD;GACA,gBACE,KAAK,oBAAoB,IAAI,eAAe,0BAA0B,EACtE,cACD;GACD;GACA,wBACE,KAAK,oBAAoB,IAAI,eAAe,oBAAoB,EAChE,cACD;GACF,CAAC"}
|
|
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 { createBundlerLogger } from './createBundlerLogger';\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\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(Runtim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,EAChE,IACA,cACA,eACA,SACA,KACD,GACD;GACJ;GACA,iCACE,KAAK,oBAAoB,IAAI,eAAe,qBAAqB,EACjE,KAAK,QAAQ,MACd;GACD;GACA,gBACE,KAAK,oBAAoB,IAAI,eAAe,0BAA0B,EACtE,cACD;GACD;GACA,wBACE,KAAK,oBAAoB,IAAI,eAAe,oBAAoB,EAChE,cACD;GACF,CAAC"}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
4
|
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
5
|
+
const require_createBundlerLogger = require('../../plugins/createBundlerLogger.js');
|
|
5
6
|
const require_src_plugins_EntryChunkTrackerPlugin = require('./EntryChunkTrackerPlugin.js');
|
|
6
7
|
let _module_federation_sdk = require("@module-federation/sdk");
|
|
7
8
|
|
|
8
9
|
//#region src/plugins/NodeFederationPlugin.ts
|
|
9
|
-
const createBundlerLogger = typeof _module_federation_sdk.createInfrastructureLogger === "function" ? _module_federation_sdk.createInfrastructureLogger : _module_federation_sdk.createLogger;
|
|
10
10
|
function getRuntimePluginPath() {
|
|
11
11
|
return require.resolve("../runtimePlugin.js");
|
|
12
12
|
}
|
|
@@ -22,7 +22,7 @@ var NodeFederationPlugin = class {
|
|
|
22
22
|
* @param {Context} context - The context for the NodeFederationPlugin
|
|
23
23
|
*/
|
|
24
24
|
constructor({ debug, useRuntimePlugin, ...options }, context) {
|
|
25
|
-
this.logger = createBundlerLogger("[ Node Federation Plugin ]");
|
|
25
|
+
this.logger = require_createBundlerLogger.createBundlerLogger("[ Node Federation Plugin ]");
|
|
26
26
|
this._options = options || {};
|
|
27
27
|
this.context = context || {};
|
|
28
28
|
this.useRuntimePlugin = useRuntimePlugin || false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeFederationPlugin.js","names":["
|
|
1
|
+
{"version":3,"file":"NodeFederationPlugin.js","names":["createBundlerLogger","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 { bindLoggerToCompiler } from '@module-federation/sdk';\nimport { createBundlerLogger } from './createBundlerLogger';\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\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":";;;;;;;;;AA0BA,SAAS,uBAA+B;AACtC,QAAO,QAAQ,QAGT,sBACL;;;;;;AAOH,IAAM,uBAAN,MAA2B;;;;;;;CAYzB,YACE,EAAE,OAAO,kBAAkB,GAAG,WAC9B,SACA;gBAXeA,gDAAo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@ -1,9 +1,9 @@
|
|
|
1
1
|
import { __require } from "../../_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
import { createBundlerLogger } from "../../plugins/createBundlerLogger.mjs";
|
|
2
3
|
import EntryChunkTrackerPlugin from "./EntryChunkTrackerPlugin.mjs";
|
|
3
|
-
import { bindLoggerToCompiler
|
|
4
|
+
import { bindLoggerToCompiler } from "@module-federation/sdk";
|
|
4
5
|
|
|
5
6
|
//#region src/plugins/NodeFederationPlugin.ts
|
|
6
|
-
const createBundlerLogger = typeof createInfrastructureLogger === "function" ? createInfrastructureLogger : createLogger;
|
|
7
7
|
function getRuntimePluginPath() {
|
|
8
8
|
return __require.resolve("../runtimePlugin.mjs");
|
|
9
9
|
}
|
|
@@ -1 +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 {
|
|
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 { bindLoggerToCompiler } from '@module-federation/sdk';\nimport { createBundlerLogger } from './createBundlerLogger';\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\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":";;;;;;AA0BA,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StreamingTargetPlugin.js","names":["CommonJsChunkLoadingPlugin"],"sources":["../../../src/plugins/StreamingTargetPlugin.ts"],"sourcesContent":["import type { Compiler, WebpackPluginInstance } from 'webpack';\nimport type { ModuleFederationPluginOptions } from '../types';\n\nimport CommonJsChunkLoadingPlugin from './CommonJsChunkLoadingPlugin';\n\n/**\n * Interface for StreamingTargetOptions which extends ModuleFederationPluginOptions\n * @property {string} promiseBaseURI - The base URI for the promise\n * @property {boolean} debug - Flag to enable/disable debug mode\n */\ninterface StreamingTargetOptions extends ModuleFederationPluginOptions {\n promiseBaseURI?: string;\n debug?: boolean;\n}\n\n
|
|
1
|
+
{"version":3,"file":"StreamingTargetPlugin.js","names":["CommonJsChunkLoadingPlugin"],"sources":["../../../src/plugins/StreamingTargetPlugin.ts"],"sourcesContent":["import type { Compiler, WebpackPluginInstance } from 'webpack';\nimport type { ModuleFederationPluginOptions } from '../types';\n\nimport CommonJsChunkLoadingPlugin from './CommonJsChunkLoadingPlugin';\n\n/**\n * Interface for StreamingTargetOptions which extends ModuleFederationPluginOptions\n * @property {string} promiseBaseURI - The base URI for the promise\n * @property {boolean} debug - Flag to enable/disable debug mode\n */\ninterface StreamingTargetOptions extends ModuleFederationPluginOptions {\n promiseBaseURI?: string;\n debug?: boolean;\n}\n\n/**\n * Class representing a StreamingTargetPlugin\n */\nclass StreamingTargetPlugin implements WebpackPluginInstance {\n private options: StreamingTargetOptions;\n\n /**\n * Create a StreamingTargetPlugin\n * @param {StreamingTargetOptions} options - The options for the plugin\n */\n constructor(options: StreamingTargetOptions) {\n this.options = options || {};\n }\n\n /**\n * Apply the plugin to the compiler\n * @param {Compiler} compiler - The webpack compiler\n */\n apply(compiler: Compiler) {\n // When used with Next.js, context is needed to use Next.js webpack\n const { webpack } = compiler;\n\n compiler.options.output.chunkFormat = 'commonjs';\n if (compiler.options.output.enabledLibraryTypes === undefined) {\n compiler.options.output.enabledLibraryTypes = ['commonjs-module'];\n } else {\n compiler.options.output.enabledLibraryTypes.push('commonjs-module');\n }\n\n compiler.options.output.chunkLoading = 'async-node';\n\n // Disable default config\n // FIXME: enabledChunkLoadingTypes is of type 'string[] | undefined'\n // Can't use the 'false' value as it isn't the right format,\n // Emptying it out ensures theres no other readFileVm added to webpack runtime\n compiler.options.output.enabledChunkLoadingTypes = [];\n compiler.options.output.environment = {\n ...compiler.options.output.environment,\n dynamicImport: true,\n };\n\n new (\n webpack?.node?.NodeEnvironmentPlugin ||\n require('webpack/lib/node/NodeEnvironmentPlugin')\n )({\n infrastructureLogging: compiler.options.infrastructureLogging,\n }).apply(compiler);\n\n new (\n webpack?.node?.NodeTargetPlugin ||\n require('webpack/lib/node/NodeTargetPlugin')\n )().apply(compiler);\n new CommonJsChunkLoadingPlugin({\n asyncChunkLoading: true,\n name: this.options.name,\n remotes: this.options.remotes as Record<string, string>,\n baseURI: compiler.options.output.publicPath,\n promiseBaseURI: this.options.promiseBaseURI,\n debug: this.options.debug,\n }).apply(compiler);\n }\n}\n\nexport default StreamingTargetPlugin;\n"],"mappings":";;;;;;;AAkBA,IAAM,wBAAN,MAA6D;;;;;CAO3D,YAAY,SAAiC;AAC3C,OAAK,UAAU,WAAW,EAAE;;;;;;CAO9B,MAAM,UAAoB;EAExB,MAAM,EAAE,YAAY;AAEpB,WAAS,QAAQ,OAAO,cAAc;AACtC,MAAI,SAAS,QAAQ,OAAO,wBAAwB,OAClD,UAAS,QAAQ,OAAO,sBAAsB,CAAC,kBAAkB;MAEjE,UAAS,QAAQ,OAAO,oBAAoB,KAAK,kBAAkB;AAGrE,WAAS,QAAQ,OAAO,eAAe;AAMvC,WAAS,QAAQ,OAAO,2BAA2B,EAAE;AACrD,WAAS,QAAQ,OAAO,cAAc;GACpC,GAAG,SAAS,QAAQ,OAAO;GAC3B,eAAe;GAChB;AAED,OACE,SAAS,MAAM,0BACf,QAAQ,yCAAyC,GACjD,EACA,uBAAuB,SAAS,QAAQ,uBACzC,CAAC,CAAC,MAAM,SAAS;AAElB,OACE,SAAS,MAAM,qBACf,QAAQ,oCAAoC,IAC3C,CAAC,MAAM,SAAS;AACnB,MAAIA,uDAA2B;GAC7B,mBAAmB;GACnB,MAAM,KAAK,QAAQ;GACnB,SAAS,KAAK,QAAQ;GACtB,SAAS,SAAS,QAAQ,OAAO;GACjC,gBAAgB,KAAK,QAAQ;GAC7B,OAAO,KAAK,QAAQ;GACrB,CAAC,CAAC,MAAM,SAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StreamingTargetPlugin.mjs","names":["CommonJsChunkLoadingPlugin"],"sources":["../../../src/plugins/StreamingTargetPlugin.ts"],"sourcesContent":["import type { Compiler, WebpackPluginInstance } from 'webpack';\nimport type { ModuleFederationPluginOptions } from '../types';\n\nimport CommonJsChunkLoadingPlugin from './CommonJsChunkLoadingPlugin';\n\n/**\n * Interface for StreamingTargetOptions which extends ModuleFederationPluginOptions\n * @property {string} promiseBaseURI - The base URI for the promise\n * @property {boolean} debug - Flag to enable/disable debug mode\n */\ninterface StreamingTargetOptions extends ModuleFederationPluginOptions {\n promiseBaseURI?: string;\n debug?: boolean;\n}\n\n
|
|
1
|
+
{"version":3,"file":"StreamingTargetPlugin.mjs","names":["CommonJsChunkLoadingPlugin"],"sources":["../../../src/plugins/StreamingTargetPlugin.ts"],"sourcesContent":["import type { Compiler, WebpackPluginInstance } from 'webpack';\nimport type { ModuleFederationPluginOptions } from '../types';\n\nimport CommonJsChunkLoadingPlugin from './CommonJsChunkLoadingPlugin';\n\n/**\n * Interface for StreamingTargetOptions which extends ModuleFederationPluginOptions\n * @property {string} promiseBaseURI - The base URI for the promise\n * @property {boolean} debug - Flag to enable/disable debug mode\n */\ninterface StreamingTargetOptions extends ModuleFederationPluginOptions {\n promiseBaseURI?: string;\n debug?: boolean;\n}\n\n/**\n * Class representing a StreamingTargetPlugin\n */\nclass StreamingTargetPlugin implements WebpackPluginInstance {\n private options: StreamingTargetOptions;\n\n /**\n * Create a StreamingTargetPlugin\n * @param {StreamingTargetOptions} options - The options for the plugin\n */\n constructor(options: StreamingTargetOptions) {\n this.options = options || {};\n }\n\n /**\n * Apply the plugin to the compiler\n * @param {Compiler} compiler - The webpack compiler\n */\n apply(compiler: Compiler) {\n // When used with Next.js, context is needed to use Next.js webpack\n const { webpack } = compiler;\n\n compiler.options.output.chunkFormat = 'commonjs';\n if (compiler.options.output.enabledLibraryTypes === undefined) {\n compiler.options.output.enabledLibraryTypes = ['commonjs-module'];\n } else {\n compiler.options.output.enabledLibraryTypes.push('commonjs-module');\n }\n\n compiler.options.output.chunkLoading = 'async-node';\n\n // Disable default config\n // FIXME: enabledChunkLoadingTypes is of type 'string[] | undefined'\n // Can't use the 'false' value as it isn't the right format,\n // Emptying it out ensures theres no other readFileVm added to webpack runtime\n compiler.options.output.enabledChunkLoadingTypes = [];\n compiler.options.output.environment = {\n ...compiler.options.output.environment,\n dynamicImport: true,\n };\n\n new (\n webpack?.node?.NodeEnvironmentPlugin ||\n require('webpack/lib/node/NodeEnvironmentPlugin')\n )({\n infrastructureLogging: compiler.options.infrastructureLogging,\n }).apply(compiler);\n\n new (\n webpack?.node?.NodeTargetPlugin ||\n require('webpack/lib/node/NodeTargetPlugin')\n )().apply(compiler);\n new CommonJsChunkLoadingPlugin({\n asyncChunkLoading: true,\n name: this.options.name,\n remotes: this.options.remotes as Record<string, string>,\n baseURI: compiler.options.output.publicPath,\n promiseBaseURI: this.options.promiseBaseURI,\n debug: this.options.debug,\n }).apply(compiler);\n }\n}\n\nexport default StreamingTargetPlugin;\n"],"mappings":";;;;;;;AAkBA,IAAM,wBAAN,MAA6D;;;;;CAO3D,YAAY,SAAiC;AAC3C,OAAK,UAAU,WAAW,EAAE;;;;;;CAO9B,MAAM,UAAoB;EAExB,MAAM,EAAE,YAAY;AAEpB,WAAS,QAAQ,OAAO,cAAc;AACtC,MAAI,SAAS,QAAQ,OAAO,wBAAwB,OAClD,UAAS,QAAQ,OAAO,sBAAsB,CAAC,kBAAkB;MAEjE,UAAS,QAAQ,OAAO,oBAAoB,KAAK,kBAAkB;AAGrE,WAAS,QAAQ,OAAO,eAAe;AAMvC,WAAS,QAAQ,OAAO,2BAA2B,EAAE;AACrD,WAAS,QAAQ,OAAO,cAAc;GACpC,GAAG,SAAS,QAAQ,OAAO;GAC3B,eAAe;GAChB;AAED,OACE,SAAS,MAAM,oCACP,yCAAyC,GACjD,EACA,uBAAuB,SAAS,QAAQ,uBACzC,CAAC,CAAC,MAAM,SAAS;AAElB,OACE,SAAS,MAAM,+BACP,oCAAoC,IAC3C,CAAC,MAAM,SAAS;AACnB,MAAIA,oCAA2B;GAC7B,mBAAmB;GACnB,MAAM,KAAK,QAAQ;GACnB,SAAS,KAAK,QAAQ;GACtB,SAAS,SAAS,QAAQ,OAAO;GACjC,gBAAgB,KAAK,QAAQ;GAC7B,OAAO,KAAK,QAAQ;GACrB,CAAC,CAAC,MAAM,SAAS"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"public": true,
|
|
3
3
|
"name": "@module-federation/node",
|
|
4
|
-
"version": "2.7.
|
|
4
|
+
"version": "2.7.50",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/src/index.js",
|
|
7
7
|
"module": "./dist/src/index.mjs",
|
|
@@ -111,9 +111,9 @@
|
|
|
111
111
|
"encoding": "0.1.13",
|
|
112
112
|
"node-fetch": "2.7.0",
|
|
113
113
|
"tapable": "2.3.0",
|
|
114
|
-
"@module-federation/enhanced": "2.
|
|
115
|
-
"@module-federation/runtime": "2.
|
|
116
|
-
"@module-federation/sdk": "2.
|
|
114
|
+
"@module-federation/enhanced": "2.9.0",
|
|
115
|
+
"@module-federation/runtime": "2.9.0",
|
|
116
|
+
"@module-federation/sdk": "2.9.0"
|
|
117
117
|
},
|
|
118
118
|
"peerDependencies": {
|
|
119
119
|
"webpack": "^5.40.0"
|