From 5e0d32ba42aadb01dd1182e876f2a6bcde295844 Mon Sep 17 00:00:00 2001 From: ScriptedAlchemy Date: Fri, 16 Dec 2022 13:14:10 -0800 Subject: [PATCH 1/9] feat: worker support --- packages/node/global.d.ts | 14 +- .../LoadFileChunkLoadingRuntimeModule.ts | 49 ++++--- .../node/src/plugins/NodeFederationPlugin.ts | 24 ++-- .../node/src/plugins/StreamingTargetPlugin.ts | 2 + .../src/plugins/UniversalFederationPlugin.ts | 2 +- packages/node/src/plugins/loadScript.ts | 88 ++++++++---- packages/node/src/utils/flush-chunks.js | 10 +- packages/node/src/utils/hot-reload.ts | 8 +- yarn.lock | 127 +++++++++++++++++- 9 files changed, 252 insertions(+), 72 deletions(-) diff --git a/packages/node/global.d.ts b/packages/node/global.d.ts index ebe682fb860..86005c412d0 100644 --- a/packages/node/global.d.ts +++ b/packages/node/global.d.ts @@ -10,14 +10,16 @@ declare module 'webpack/lib/Template'; declare module 'webpack/lib/util/compileBooleanMatcher'; declare module 'webpack/lib/util/identifier'; -declare const global: typeof globalThis & { - usedChunks: Set; - flushChunks: () => Promise>; - __remote_scope__: { + +// globals.d.ts +declare module globalThis { + var usedChunks: Set; + var flushChunks: () => Promise>; + var __remote_scope__: { _config: Record; [K: string]: { fake?: boolean; }; }; - webpackChunkLoad; -}; + var webpackChunkLoad: ()=> any; +} diff --git a/packages/node/src/plugins/LoadFileChunkLoadingRuntimeModule.ts b/packages/node/src/plugins/LoadFileChunkLoadingRuntimeModule.ts index 02b158890a4..63c104c07ab 100644 --- a/packages/node/src/plugins/LoadFileChunkLoadingRuntimeModule.ts +++ b/packages/node/src/plugins/LoadFileChunkLoadingRuntimeModule.ts @@ -208,9 +208,9 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule { "// load script equivalent for server side", `${RuntimeGlobals.loadScript} = ${runtimeTemplate.basicFunction('url,callback,chunkId', [ Template.indent([ - "if(!global.__remote_scope__) {", + "if(!globalThis.__remote_scope__) {", Template.indent(["// create a global scope for container, similar to how remotes are set on window in the browser", - "global.__remote_scope__ = {", + "globalThis.__remote_scope__ = {", "_config: {},", "}", ]), @@ -245,13 +245,13 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule { 'var promise = new Promise(async function(resolve, reject) {', Template.indent([ 'installedChunkData = installedChunks[chunkId] = [resolve, reject];', - `var filename = require('path').join(__dirname, ${JSON.stringify( + `var filename = typeof process !== \"undefined\" ? require('path').join(__dirname, ${JSON.stringify( rootOutputDir )} + ${ RuntimeGlobals.getChunkScriptFilename - }(chunkId));`, - "var fs = require('fs');", - 'if(fs.existsSync(filename)) {', + }(chunkId)) : false;`, + "var fs = typeof process !== \"undefined\" ? require('fs') : false;", + 'if(fs && fs.existsSync(filename)) {', Template.indent([ "fs.readFile(filename, 'utf-8', function(err, content) {", Template.indent([ @@ -266,7 +266,6 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule { '} else {', Template.indent([ loadScriptTemplate, - this._getLogger(`'needs to load remote module from ${JSON.stringify( name )}'`), @@ -282,19 +281,29 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule { return acc; }, {} as Record) )};`, - 'Object.assign(global.__remote_scope__._config, remotes)', - 'const remoteRegistry = global.__remote_scope__._config', + Template.indent([ + "if(!globalThis.__remote_scope__) {", + Template.indent(["// create a global scope for container, similar to how remotes are set on window in the browser", + "globalThis.__remote_scope__ = {", + "_config: {},", + "}", + ]), + "}", + ]), + 'Object.assign(globalThis.__remote_scope__._config, remotes)', + 'console.log("after reg");', + 'const remoteRegistry = globalThis.__remote_scope__._config', /* TODO: keying by global should be ok, but need to verify - need to deal with when user passes promise new promise() global will/should still exist - but can only be known at runtime */ this._getLogger(`'remotes keyed by global name'`,JSON.stringify(remotes)), - this._getLogger(`'remote scope configs'`,'global.__remote_scope__._config'), + this._getLogger(`'remote scope configs'`,'globalThis.__remote_scope__._config'), this._getLogger(`'before remote scope'`), - this._getLogger(`'global.__remote_scope__'`,`global.__remote_scope__`), - this._getLogger(`'global.__remote_scope__[${JSON.stringify( + this._getLogger(`'globalThis.__remote_scope__'`,`globalThis.__remote_scope__`), + this._getLogger(`'globalThis.__remote_scope__[${JSON.stringify( name - )}]'`,`global.__remote_scope__[${JSON.stringify( + )}]'`,`globalThis.__remote_scope__[${JSON.stringify( name )}]`), @@ -330,10 +339,16 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule { // there may still be a use case for that with promise new promise, depending on how we design it. `var scriptUrl = new URL(requestedRemote);`, - this._getLogger(`'global.__remote_scope__'`,`global.__remote_scope__`), + this._getLogger(`'globalThis.__remote_scope__'`,`globalThis.__remote_scope__`), `var chunkName = ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`, this._getLogger(`'chunkname to request'`,`chunkName`), - `var fileToReplace = require('path').basename(scriptUrl.pathname);`, + "console.log(scriptUrl)", + ` + var getBasenameFromUrl = (url) => { + const urlParts = url.split('/'); + return urlParts[urlParts.length - 1]; + }; + var fileToReplace = typeof process !== "undefined" ? require('path').basename(scriptUrl.pathname) : getBasenameFromUrl(scriptUrl.pathname);`, `scriptUrl.pathname = scriptUrl.pathname.replace(fileToReplace, chunkName);`, this._getLogger(`'will load remote chunk'`, `scriptUrl.toString()`), `loadScript(scriptUrl.toString(), function(err, content) {`, @@ -341,12 +356,16 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule { this._getLogger(`'load script callback fired'`), "if(err) {console.error('error loading remote chunk', scriptUrl.toString(),'got',content); return reject(err);}", 'var chunk = {};', + "if(typeof process !== 'undefined') {", 'try {', "require('vm').runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\n})', filename)" + "(chunk, require, require('path').dirname(filename), filename);", '} catch (e) {', "console.error('runInThisContext threw', e)", '}', + '} else {', + "eval('(function(exports, require, __dirname, __filename) {' + content + '\\n})')(chunk, __webpack_require__, '.', chunkName);", + '}', 'installChunk(chunk);', ]), '});', diff --git a/packages/node/src/plugins/NodeFederationPlugin.ts b/packages/node/src/plugins/NodeFederationPlugin.ts index 8f8fcc32864..abd51c668fd 100644 --- a/packages/node/src/plugins/NodeFederationPlugin.ts +++ b/packages/node/src/plugins/NodeFederationPlugin.ts @@ -33,21 +33,21 @@ export const parseRemotes = (remotes: Record) => Object.entries(rem }, {} as Record); // server template to convert remote into promise new promise and use require.loadChunk to load the chunk export const generateRemoteTemplate = (url: string, global: any) => `new Promise(function (resolve, reject) { - if(!global.__remote_scope__) { + if(!globalThis.__remote_scope__) { // create a global scope for container, similar to how remotes are set on window in the browser - global.__remote_scope__ = { + globalThis.__remote_scope__ = { _config: {}, } } - if (typeof global.__remote_scope__[${JSON.stringify(global)}] !== 'undefined') return resolve(global.__remote_scope__[${JSON.stringify(global)}]); - global.__remote_scope__._config[${JSON.stringify(global)}] = ${JSON.stringify(url)}; + if (typeof globalThis.__remote_scope__[${JSON.stringify(global)}] !== 'undefined') return resolve(globalThis.__remote_scope__[${JSON.stringify(global)}]); + globalThis.__remote_scope__._config[${JSON.stringify(global)}] = ${JSON.stringify(url)}; var __webpack_error__ = new Error(); __webpack_require__.l( ${JSON.stringify(url)}, function (event) { - if (typeof global.__remote_scope__[${JSON.stringify(global)}] !== 'undefined') return resolve(global.__remote_scope__[${JSON.stringify(global)}]); + if (typeof globalThis.__remote_scope__[${JSON.stringify(global)}] !== 'undefined') return resolve(globalThis.__remote_scope__[${JSON.stringify(global)}]); var realSrc = event && event.target && event.target.src; __webpack_error__.message = 'Loading script failed.\\n(' + event.message + ': ' + realSrc + ')'; __webpack_error__.name = 'ScriptExternalLoadError'; @@ -78,9 +78,9 @@ export const generateRemoteTemplate = (url: string, global: any) => `new Promise } const proxy = { get: (arg)=>{ - // if(!global.__remote_scope__[${JSON.stringify(global)}].__initialized) { + // if(!globalThis.__remote_scope__[${JSON.stringify(global)}].__initialized) { // try { - // global.__remote_scope__[${JSON.stringify(global)}].__initialized = true; + // globalThis.__remote_scope__[${JSON.stringify(global)}].__initialized = true; // proxy.init(__webpack_require__.S.default); // } catch(e) {} // } @@ -88,7 +88,7 @@ export const generateRemoteTemplate = (url: string, global: any) => `new Promise const m = f(); return ()=>new Proxy(m, { get: (target, prop)=>{ - if(global.usedChunks) global.usedChunks.add(${JSON.stringify(global)} + "->" + arg); + if(globalThis.usedChunks) globalThis.usedChunks.add(${JSON.stringify(global)} + "->" + arg); return target[prop]; } }) @@ -107,7 +107,7 @@ export const generateRemoteTemplate = (url: string, global: any) => `new Promise return target[prop] }, set(target, property, value) { - if(global.usedChunks) global.usedChunks.add(${JSON.stringify(global)} + "->" + property); + if(globalThis.usedChunks) globalThis.usedChunks.add(${JSON.stringify(global)} + "->" + property); if (target[property]) { return target[property] } @@ -116,14 +116,14 @@ export const generateRemoteTemplate = (url: string, global: any) => `new Promise } } try { - global.__remote_scope__[${JSON.stringify(global)}].init(new Proxy(shareScope, handler)) + globalThis.__remote_scope__[${JSON.stringify(global)}].init(new Proxy(shareScope, handler)) } catch (e) { } - global.__remote_scope__[${JSON.stringify(global)}].__initialized = true + globalThis.__remote_scope__[${JSON.stringify(global)}].__initialized = true } } - if (!global.__remote_scope__[${JSON.stringify(global)}].__initialized) { + if (!globalThis.__remote_scope__[${JSON.stringify(global)}].__initialized) { proxy.init(__webpack_require__.S.default) } return proxy diff --git a/packages/node/src/plugins/StreamingTargetPlugin.ts b/packages/node/src/plugins/StreamingTargetPlugin.ts index 2161f228ac7..b66adda9bd4 100644 --- a/packages/node/src/plugins/StreamingTargetPlugin.ts +++ b/packages/node/src/plugins/StreamingTargetPlugin.ts @@ -63,3 +63,5 @@ class StreamingTargetPlugin { } export default StreamingTargetPlugin; + + diff --git a/packages/node/src/plugins/UniversalFederationPlugin.ts b/packages/node/src/plugins/UniversalFederationPlugin.ts index f80dbeb3499..2d9f0afae12 100644 --- a/packages/node/src/plugins/UniversalFederationPlugin.ts +++ b/packages/node/src/plugins/UniversalFederationPlugin.ts @@ -18,7 +18,7 @@ class UniversalFederationPlugin { private context: NodeFederationContext; constructor(options: NodeFederationOptions, context: NodeFederationContext) { - this._options = options || {} as NodeFederationOptions; + this._options = Object.assign({remotes: {}, exposes: {}, shared: {}},options) as NodeFederationOptions; this.context = context || {} as NodeFederationContext; } diff --git a/packages/node/src/plugins/loadScript.ts b/packages/node/src/plugins/loadScript.ts index 2a24ff3abb3..e10f96ba119 100644 --- a/packages/node/src/plugins/loadScript.ts +++ b/packages/node/src/plugins/loadScript.ts @@ -18,16 +18,16 @@ export default ` } else { throw new Error("invalid number of arguments"); } - if (global.webpackChunkLoad) { - global.webpackChunkLoad(url).then(function (resp) { + if (globalThis.webpackChunkLoad) { + globalThis.webpackChunkLoad(url).then(function (resp) { return resp.text(); }).then(function (rawData) { cb(null, rawData); }).catch(function (err) { - console.error('Federated Chunk load failed', error); - return cb(error) + console.error('Federated Chunk load failed', err); + return cb(err) }); - } else { + } else if (typeof process !== 'undefined') { //TODO https support let request = (url.startsWith('https') ? require('https') : require('http')).get(url, function (resp) { if (resp.statusCode === 200) { @@ -47,6 +47,15 @@ export default ` console.error('Federated Chunk load failed', error); return cb(error) }); + } else { + fetch(url).then(function (resp) { + return resp.text(); + }).then(function (rawData) { + cb(null, rawData); + }).catch(function (err) { + console.error('Federated Chunk load failed', err); + return cb(err) + }) } } `; @@ -55,28 +64,59 @@ export default ` //language=JS export const executeLoadTemplate = ` function executeLoad(url, callback, name) { - if(!name) { + if (!name) { throw new Error('__webpack_require__.l name is required for ' + url); } - if (typeof global.__remote_scope__[name] !== 'undefined') return callback(global.__remote_scope__[name]); - const vm = require('vm'); - (global.webpackChunkLoad || global.fetch || require("node-fetch"))(url).then(function (res) { - return res.text(); - }).then(function (scriptContent) { - try { - const vmContext = {exports, require, module, global, __filename, __dirname, URL,console,process,Buffer, ...global, remoteEntryName: name}; - const remote = vm.runInNewContext(scriptContent + '\\nmodule.exports', vmContext, {filename: 'node-federation-loader-' + name + '.vm'}); - global.__remote_scope__[name] = remote[name] || remote; - global.__remote_scope__._config[name] = url; - callback(global.__remote_scope__[name]) - } catch (e) { - console.error('executeLoad hit catch block'); + if (typeof globalThis.__remote_scope__[name] !== 'undefined') return callback(globalThis.__remote_scope__[name]); + // if its a worker or node + if (typeof process !== 'undefined') { + const vm = require('vm'); + (globalThis.webpackChunkLoad || globalThis.fetch || require("node-fetch"))(url).then(function (res) { + return res.text(); + }).then(function (scriptContent) { + try { + const vmContext = { + exports, + require, + module, + global, + __filename, + __dirname, + URL, + console, + process, + Buffer, ...global, + remoteEntryName: name + }; + const remote = vm.runInNewContext(scriptContent + '\\nmodule.exports', vmContext, {filename: 'node-federation-loader-' + name + '.vm'}); + globalThis.__remote_scope__[name] = remote[name] || remote; + globalThis.__remote_scope__._config[name] = url; + callback(globalThis.__remote_scope__[name]) + } catch (e) { + console.error('executeLoad hit catch block'); + e.target = {src: url}; + callback(e); + } + }).catch((e) => { e.target = {src: url}; callback(e); - } - }).catch((e) => { - e.target = {src: url}; - callback(e); - }); + }); + } else { + fetch(url).then(function (res) { + return res.text(); + }).then(function (scriptContent) { + try { + const remote = eval('let module = {};' + scriptContent + '\\nmodule.exports') + // const remote = vm.runInNewContext(scriptContent + '\\nmodule.exports', vmContext, {filename: 'node-federation-loader-' + name + '.vm'}); + globalThis.__remote_scope__[name] = remote[name] || remote; + globalThis.__remote_scope__._config[name] = url; + callback(globalThis.__remote_scope__[name]) + } catch (e) { + console.error('executeLoad hit catch block',e); + e.target = {src: url}; + callback(e); + } + }); + } } `; diff --git a/packages/node/src/utils/flush-chunks.js b/packages/node/src/utils/flush-chunks.js index cab9799f425..0cc3a1de1b6 100644 --- a/packages/node/src/utils/flush-chunks.js +++ b/packages/node/src/utils/flush-chunks.js @@ -1,19 +1,19 @@ export const usedChunks = new Set() -global.usedChunks = usedChunks +globalThis.usedChunks = usedChunks export const flushChunks = async () => { const allFlushed = await Promise.all(Array.from(usedChunks).map(async (chunk) => { const chunks = new Set(); const [remote, request] = chunk.split('->'); - if(!global.__remote_scope__._config[remote]) { + if(!globalThis.__remote_scope__._config[remote]) { return } // fetch the json file try { - const statsFile = global.__remote_scope__._config[remote].replace('remoteEntry.js', 'federated-stats.json') + const statsFile = globalThis.__remote_scope__._config[remote].replace('remoteEntry.js', 'federated-stats.json') const stats = await fetch(statsFile).then(async (res) => await res.json()) - chunks.add(global.__remote_scope__._config[remote].replace('ssr', 'chunks')) - const [prefix] = global.__remote_scope__._config[remote].split('static/') + chunks.add(globalThis.__remote_scope__._config[remote].replace('ssr', 'chunks')) + const [prefix] = globalThis.__remote_scope__._config[remote].split('static/') if (stats.federatedModules) { stats.federatedModules.forEach((modules) => { if (modules.exposes?.[request]) { diff --git a/packages/node/src/utils/hot-reload.ts b/packages/node/src/utils/hot-reload.ts index 8b3f9602712..5df7562246b 100644 --- a/packages/node/src/utils/hot-reload.ts +++ b/packages/node/src/utils/hot-reload.ts @@ -2,8 +2,8 @@ const hashmap = {} as Record; import crypto from 'crypto'; export const revalidate = () => { - if (global.__remote_scope__) { - const remoteScope = global.__remote_scope__; + if (globalThis.__remote_scope__) { + const remoteScope = globalThis.__remote_scope__; return new Promise((res) => { const fetches = []; @@ -93,7 +93,7 @@ export const revalidate = () => { req = __non_webpack_require__ as NodeRequire; } - global.__remote_scope__ = { + globalThis.__remote_scope__ = { _config: {}, }; @@ -117,7 +117,7 @@ export const revalidate = () => { }; function getFetchModule() { - const loadedModule = global.webpackChunkLoad || global.fetch + const loadedModule = globalThis.webpackChunkLoad || globalThis.fetch if (loadedModule) { return loadedModule } diff --git a/yarn.lock b/yarn.lock index 433ff18079d..24009aac943 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1651,6 +1651,10 @@ version "0.0.0" uid "" +"@module-federation/node@0.9.5": + version "0.0.0" + uid "" + "@module-federation/node@link:./dist/packages/node": version "0.0.0" uid "" @@ -1659,6 +1663,10 @@ version "0.0.0" uid "" +"@module-federation/utilities@1.0.1": + version "0.0.0" + uid "" + "@module-federation/utilities@link:./dist/packages/utilities": version "0.0.0" uid "" @@ -1668,6 +1676,11 @@ resolved "https://registry.yarnpkg.com/@next/env/-/env-13.0.0.tgz#38527956680693c90b4522ab4ab9a2fbe3a17f67" integrity sha512-65v9BVuah2Mplohm4+efsKEnoEuhmlGm8B2w6vD1geeEP2wXtlSJCvR/cCRJ3fD8wzCQBV41VcMBQeYET6MRkg== +"@next/env@13.0.6": + version "13.0.6" + resolved "https://registry.yarnpkg.com/@next/env/-/env-13.0.6.tgz#3fcab11ffbe95bff127827d9f7f3139bc5e6adff" + integrity sha512-yceT6DCHKqPRS1cAm8DHvDvK74DLIkDQdm5iV+GnIts8h0QbdHvkUIkdOvQoOODgpr6018skbmSQp12z5OWIQQ== + "@next/eslint-plugin-next@12.2.5": version "12.2.5" resolved "https://registry.yarnpkg.com/@next/eslint-plugin-next/-/eslint-plugin-next-12.2.5.tgz#4f3acccd2ed4f9300fbf9fd480cc8a0b261889a8" @@ -1687,66 +1700,131 @@ resolved "https://registry.yarnpkg.com/@next/swc-android-arm-eabi/-/swc-android-arm-eabi-13.0.0.tgz#15cd89d19d3c00d123fdfe367bab38c362f6c515" integrity sha512-+DUQkYF93gxFjWY+CYWE1QDX6gTgnUiWf+W4UqZjM1Jcef8U97fS6xYh+i+8rH4MM0AXHm7OSakvfOMzmjU6VA== +"@next/swc-android-arm-eabi@13.0.6": + version "13.0.6" + resolved "https://registry.yarnpkg.com/@next/swc-android-arm-eabi/-/swc-android-arm-eabi-13.0.6.tgz#c971e5a3f8aae875ac1d9fdb159b7e126d8d98d5" + integrity sha512-FGFSj3v2Bluw8fD/X+1eXIEB0PhoJE0zfutsAauRhmNpjjZshLDgoXMWm1jTRL/04K/o9gwwO2+A8+sPVCH1uw== + "@next/swc-android-arm64@13.0.0": version "13.0.0" resolved "https://registry.yarnpkg.com/@next/swc-android-arm64/-/swc-android-arm64-13.0.0.tgz#9410365bb07097268d4773a46b02cfe6b3fe3ab7" integrity sha512-RW9Uy3bMSc0zVGCa11klFuwfP/jdcdkhdruqnrJ7v+7XHm6OFKkSRzX6ee7yGR1rdDZvTnP4GZSRSpzjLv/N0g== +"@next/swc-android-arm64@13.0.6": + version "13.0.6" + resolved "https://registry.yarnpkg.com/@next/swc-android-arm64/-/swc-android-arm64-13.0.6.tgz#ecacae60f1410136cc31f9e1e09e78e624ca2d68" + integrity sha512-7MgbtU7kimxuovVsd7jSJWMkIHBDBUsNLmmlkrBRHTvgzx5nDBXogP0hzZm7EImdOPwVMPpUHRQMBP9mbsiJYQ== + "@next/swc-darwin-arm64@13.0.0": version "13.0.0" resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.0.0.tgz#caf262fb5cb8bb335f6f344fd67a44dc8bf6a084" integrity sha512-APA26nps1j4qyhOIzkclW/OmgotVHj1jBxebSpMCPw2rXfiNvKNY9FA0TcuwPmUCNqaTnm703h6oW4dvp73A4Q== +"@next/swc-darwin-arm64@13.0.6": + version "13.0.6" + resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.0.6.tgz#266e9e0908024760eba0dfce17edc90ffcba5fdc" + integrity sha512-AUVEpVTxbP/fxdFsjVI9d5a0CFn6NVV7A/RXOb0Y+pXKIIZ1V5rFjPwpYfIfyOo2lrqgehMNQcyMRoTrhq04xg== + "@next/swc-darwin-x64@13.0.0": version "13.0.0" resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-13.0.0.tgz#6b214753410e1d8512a1491045acea1e188df7d6" integrity sha512-qsUhUdoFuRJiaJ7LnvTQ6GZv1QnMDcRXCIjxaN0FNVXwrjkq++U7KjBUaxXkRzLV4C7u0NHLNOp0iZwNNE7ypw== +"@next/swc-darwin-x64@13.0.6": + version "13.0.6" + resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-13.0.6.tgz#4be4ca7bc37f9c93d2e38be5ff313873ad758c09" + integrity sha512-SasCDJlshglsPnbzhWaIF6VEGkQy2NECcAOxPwaPr0cwbbt4aUlZ7QmskNzgolr5eAjFS/xTr7CEeKJtZpAAtQ== + "@next/swc-freebsd-x64@13.0.0": version "13.0.0" resolved "https://registry.yarnpkg.com/@next/swc-freebsd-x64/-/swc-freebsd-x64-13.0.0.tgz#eeb176bdb585f48882bdac1d04271b918ca87590" integrity sha512-sCdyCbboS7CwdnevKH9J6hkJI76LUw1jVWt4eV7kISuLiPba3JmehZSWm80oa4ADChRVAwzhLAo2zJaYRrInbg== +"@next/swc-freebsd-x64@13.0.6": + version "13.0.6" + resolved "https://registry.yarnpkg.com/@next/swc-freebsd-x64/-/swc-freebsd-x64-13.0.6.tgz#42eb9043ee65ea5927ba550f4b59827d7064c47b" + integrity sha512-6Lbxd9gAdXneTkwHyYW/qtX1Tdw7ND9UbiGsGz/SP43ZInNWnW6q0au4hEVPZ9bOWWRKzcVoeTBdoMpQk9Hx9w== + "@next/swc-linux-arm-gnueabihf@13.0.0": version "13.0.0" resolved "https://registry.yarnpkg.com/@next/swc-linux-arm-gnueabihf/-/swc-linux-arm-gnueabihf-13.0.0.tgz#2c2a9622c93f87a8baca94e068f674da4cae6018" integrity sha512-/X/VxfFA41C9jrEv+sUsPLQ5vbDPVIgG0CJrzKvrcc+b+4zIgPgtfsaWq9ockjHFQi3ycvlZK4TALOXO8ovQ6Q== +"@next/swc-linux-arm-gnueabihf@13.0.6": + version "13.0.6" + resolved "https://registry.yarnpkg.com/@next/swc-linux-arm-gnueabihf/-/swc-linux-arm-gnueabihf-13.0.6.tgz#aab663282b5f15d12bf9de1120175f438a44c924" + integrity sha512-wNdi5A519e1P+ozEuYOhWPzzE6m1y7mkO6NFwn6watUwO0X9nZs7fT9THmnekvmFQpaZ6U+xf2MQ9poQoCh6jQ== + "@next/swc-linux-arm64-gnu@13.0.0": version "13.0.0" resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.0.0.tgz#69505827e2928fb18034150fd4d754d54c4a1c4b" integrity sha512-x6Oxr1GIi0ZtNiT6jbw+JVcbEi3UQgF7mMmkrgfL4mfchOwXtWSHKTSSPnwoJWJfXYa0Vy1n8NElWNTGAqoWFw== +"@next/swc-linux-arm64-gnu@13.0.6": + version "13.0.6" + resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.0.6.tgz#5e2b6df4636576a00befb7bd414820a12161a9af" + integrity sha512-e8KTRnleQY1KLk5PwGV5hrmvKksCc74QRpHl5ffWnEEAtL2FE0ave5aIkXqErsPdXkiKuA/owp3LjQrP+/AH7Q== + "@next/swc-linux-arm64-musl@13.0.0": version "13.0.0" resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.0.0.tgz#487a88f2583a046e882328fe0665b37eca4fd0f6" integrity sha512-SnMH9ngI+ipGh3kqQ8+mDtWunirwmhQnQeZkEq9e/9Xsgjf04OetqrqRHKM1HmJtG2qMUJbyXFJ0F81TPuT+3g== +"@next/swc-linux-arm64-musl@13.0.6": + version "13.0.6" + resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.0.6.tgz#4a5e91a36cf140cad974df602d647e64b1b9473f" + integrity sha512-/7RF03C3mhjYpHN+pqOolgME3guiHU5T3TsejuyteqyEyzdEyLHod+jcYH6ft7UZ71a6TdOewvmbLOtzHW2O8A== + "@next/swc-linux-x64-gnu@13.0.0": version "13.0.0" resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.0.0.tgz#29e89c7e4fd2e2b16ad059076f6261998aee53df" integrity sha512-VSQwTX9EmdbotArtA1J67X8964oQfe0xHb32x4tu+JqTR+wOHyG6wGzPMdXH2oKAp6rdd7BzqxUXXf0J+ypHlw== +"@next/swc-linux-x64-gnu@13.0.6": + version "13.0.6" + resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.0.6.tgz#accb8a721a99e704565b936f16e96fa0c67e8db1" + integrity sha512-kxyEXnYHpOEkFnmrlwB1QlzJtjC6sAJytKcceIyFUHbCaD3W/Qb5tnclcnHKTaFccizZRePXvV25Ok/eUSpKTw== + "@next/swc-linux-x64-musl@13.0.0": version "13.0.0" resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.0.0.tgz#2f63aae922d2b2829aec21bf8f9adda8b6c16365" integrity sha512-xBCP0nnpO0q4tsytXkvIwWFINtbFRyVY5gxa1zB0vlFtqYR9lNhrOwH3CBrks3kkeaePOXd611+8sjdUtrLnXA== +"@next/swc-linux-x64-musl@13.0.6": + version "13.0.6" + resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.0.6.tgz#2affaa2f4f01bc190a539d895118a6ad1a477645" + integrity sha512-N0c6gubS3WW1oYYgo02xzZnNatfVQP/CiJq2ax+DJ55ePV62IACbRCU99TZNXXg+Kos6vNW4k+/qgvkvpGDeyA== + "@next/swc-win32-arm64-msvc@13.0.0": version "13.0.0" resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.0.0.tgz#4117bad96c2a6775f70294fba45c63951a8a21ac" integrity sha512-NutwDafqhGxqPj/eiUixJq9ImS/0sgx6gqlD7jRndCvQ2Q8AvDdu1+xKcGWGNnhcDsNM/n1avf1e62OG1GaqJg== +"@next/swc-win32-arm64-msvc@13.0.6": + version "13.0.6" + resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.0.6.tgz#28e5c042772865efd05197a8d1db5920156997fc" + integrity sha512-QjeMB2EBqBFPb/ac0CYr7GytbhUkrG4EwFWbcE0vsRp4H8grt25kYpFQckL4Jak3SUrp7vKfDwZ/SwO7QdO8vw== + "@next/swc-win32-ia32-msvc@13.0.0": version "13.0.0" resolved "https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.0.0.tgz#5914eb86f9ea92a00d76cb094dd9734b3bf2012c" integrity sha512-zNaxaO+Kl/xNz02E9QlcVz0pT4MjkXGDLb25qxtAzyJL15aU0+VjjbIZAYWctG59dvggNIUNDWgoBeVTKB9xLg== +"@next/swc-win32-ia32-msvc@13.0.6": + version "13.0.6" + resolved "https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.0.6.tgz#30d91a6d847fa8bce9f8a0f9d2b469d574270be5" + integrity sha512-EQzXtdqRTcmhT/tCq81rIwE36Y3fNHPInaCuJzM/kftdXfa0F+64y7FAoMO13npX8EG1+SamXgp/emSusKrCXg== + "@next/swc-win32-x64-msvc@13.0.0": version "13.0.0" resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.0.0.tgz#c54a5a739dee04b20338d305226a2acdf701f67f" integrity sha512-FFOGGWwTCRMu9W7MF496Urefxtuo2lttxF1vwS+1rIRsKvuLrWhVaVTj3T8sf2EBL6gtJbmh4TYlizS+obnGKA== +"@next/swc-win32-x64-msvc@13.0.6": + version "13.0.6" + resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.0.6.tgz#dfa28ddb335c16233d22cf39ec8cdf723e6587a1" + integrity sha512-pSkqZ//UP/f2sS9T7IvHLfEWDPTX0vRyXJnAUNisKvO3eF3e1xdhDX7dix/X3Z3lnN4UjSwOzclAI87JFbOwmQ== + "@nodelib/fs.scandir@2.1.5": version "2.1.5" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" @@ -2522,6 +2600,13 @@ dependencies: tslib "^2.4.0" +"@swc/helpers@0.4.14": + version "0.4.14" + resolved "https://registry.yarnpkg.com/@swc/helpers/-/helpers-0.4.14.tgz#1352ac6d95e3617ccb7c1498ff019654f1e12a74" + integrity sha512-4C7nX/dvpzB7za4Ql9K81xK3HPxCpHMgwTZVyf+9JQ6VUbn9jjZVN7/Nkdz/Ugzs2CSjqnL/UPXroiVBVHUWUw== + dependencies: + tslib "^2.4.0" + "@swc/helpers@~0.3.3": version "0.3.17" resolved "https://registry.yarnpkg.com/@swc/helpers/-/helpers-0.3.17.tgz#7c1b91f43c77e2bba99492162a498d465ef253d5" @@ -5514,6 +5599,13 @@ encodeurl@~1.0.2: resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" integrity sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w== +encoding@^0.1.13: + version "0.1.13" + resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.13.tgz#56574afdd791f54a8e9b2785c0582a2d26210fa9" + integrity sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A== + dependencies: + iconv-lite "^0.6.2" + end-of-stream@^1.0.0, end-of-stream@^1.1.0, end-of-stream@^1.4.1: version "1.4.4" resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0" @@ -5988,7 +6080,7 @@ event-emitter@^0.3.5: d "1" es5-ext "~0.10.14" -eventemitter3@^4.0.0, eventemitter3@^4.0.4: +eventemitter3@^4.0.0, eventemitter3@^4.0.4, eventemitter3@^4.0.7: version "4.0.7" resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f" integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw== @@ -6140,7 +6232,7 @@ fast-glob@3.2.7: merge2 "^1.3.0" micromatch "^4.0.4" -fast-glob@^3.0.3, fast-glob@^3.2.12, fast-glob@^3.2.5, fast-glob@^3.2.7, fast-glob@^3.2.9: +fast-glob@^3.0.3, fast-glob@^3.2.11, fast-glob@^3.2.12, fast-glob@^3.2.5, fast-glob@^3.2.7, fast-glob@^3.2.9: version "3.2.12" resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.12.tgz#7f39ec99c2e6ab030337142da9e0c18f37afae80" integrity sha512-DVj4CQIYYow0BlaelwK1pHl5n5cRSJfM60UA0zK891sVInoPri2Ekj7+e1CT3/3qxXenpI+nBBmQAcJPJgaj4w== @@ -7123,7 +7215,7 @@ iconv-lite@0.4.24, iconv-lite@^0.4.24: dependencies: safer-buffer ">= 2.1.2 < 3" -iconv-lite@0.6.3, iconv-lite@^0.6.3: +iconv-lite@0.6.3, iconv-lite@^0.6.2, iconv-lite@^0.6.3: version "0.6.3" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.6.3.tgz#a52f80bf38da1952eb5c681790719871a1a72501" integrity sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw== @@ -9023,6 +9115,31 @@ next@13.0.0: "@next/swc-win32-ia32-msvc" "13.0.0" "@next/swc-win32-x64-msvc" "13.0.0" +"next@^12 || ^13": + version "13.0.6" + resolved "https://registry.yarnpkg.com/next/-/next-13.0.6.tgz#f9a2e9e2df9ad60e1b6b716488c9ad501a383621" + integrity sha512-COvigvms2LRt1rrzfBQcMQ2GZd86Mvk1z+LOLY5pniFtL4VrTmhZ9salrbKfSiXbhsD01TrDdD68ec3ABDyscA== + dependencies: + "@next/env" "13.0.6" + "@swc/helpers" "0.4.14" + caniuse-lite "^1.0.30001406" + postcss "8.4.14" + styled-jsx "5.1.0" + optionalDependencies: + "@next/swc-android-arm-eabi" "13.0.6" + "@next/swc-android-arm64" "13.0.6" + "@next/swc-darwin-arm64" "13.0.6" + "@next/swc-darwin-x64" "13.0.6" + "@next/swc-freebsd-x64" "13.0.6" + "@next/swc-linux-arm-gnueabihf" "13.0.6" + "@next/swc-linux-arm64-gnu" "13.0.6" + "@next/swc-linux-arm64-musl" "13.0.6" + "@next/swc-linux-x64-gnu" "13.0.6" + "@next/swc-linux-x64-musl" "13.0.6" + "@next/swc-win32-arm64-msvc" "13.0.6" + "@next/swc-win32-ia32-msvc" "13.0.6" + "@next/swc-win32-x64-msvc" "13.0.6" + ngx-deploy-npm@^4.2.5: version "4.2.5" resolved "https://registry.yarnpkg.com/ngx-deploy-npm/-/ngx-deploy-npm-4.2.5.tgz#0a85b73520c6b041240fa83bac0f04cb6b7a2e40" @@ -9040,7 +9157,7 @@ node-addon-api@^3.2.1: resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.2.1.tgz#81325e0a2117789c0128dab65e7e38f07ceba161" integrity sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A== -node-fetch@2.6.7: +node-fetch@2.6.7, node-fetch@^2.6.7: version "2.6.7" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ== @@ -10826,7 +10943,7 @@ react-test-renderer@18.2.0: react-shallow-renderer "^16.15.0" scheduler "^0.23.0" -react@18.2.0: +react@18.2.0, "react@^17 || ^18": version "18.2.0" resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5" integrity sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ== From 8f98fe765c9b1f2f21716222afdd88cb8ff3319e Mon Sep 17 00:00:00 2001 From: ScriptedAlchemy Date: Fri, 30 Jun 2023 15:14:36 -0700 Subject: [PATCH 2/9] feat: support edge workers --- packages/nextjs-mf/README.md | 10 ++++----- .../nextjs-mf/src/loaders/fixImageLoader.ts | 2 +- .../LoadFileChunkLoadingRuntimeModule.ts | 22 +++++++++---------- .../node/src/plugins/NodeFederationPlugin.ts | 14 ++++++------ packages/node/src/plugins/loadScript.ts | 10 ++++----- packages/node/src/utils/flush-chunks.ts | 8 +++---- packages/node/src/utils/hot-reload.ts | 4 ++-- packages/utilities/src/utils/common.ts | 8 +++---- 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/packages/nextjs-mf/README.md b/packages/nextjs-mf/README.md index d844194b053..775d165a827 100644 --- a/packages/nextjs-mf/README.md +++ b/packages/nextjs-mf/README.md @@ -240,7 +240,7 @@ const SampleComponent = lazy(() => import('next2/sampleComponent')); Delegated modules are now a standard feature in module federation, giving you the ability to manage the loading procedure of remote modules via an internally bundled file by webpack. This is facilitated by exporting a promise in the delegate file that resolves to a remote/container interface. -A container interface represents the fundamental `{get, init}` API that remote entries present to a consuming app. Within the browser, a remote container could be `window.app1`, and in Node, it could be `global.__remote_scope__.app1`. +A container interface represents the fundamental `{get, init}` API that remote entries present to a consuming app. Within the browser, a remote container could be `window.app1`, and in Node, it could be `globalThis.__remote_scope__.app1`. Implementing a method for script loading in the delegate file is necessary for the utilization of delegated modules. Although the built-in `__webpack_require__.l` method of webpack is a prevalent method, any method is suitable. This method is made available to the runtime and is identical to the method webpack employs internally to load remotes. @@ -338,9 +338,9 @@ const remotes = { // remote-delegate.js module.exports = new Promise((resolve, reject) => { // some node specific for NodeFederation - if (!global.__remote_scope__) { + if (!globalThis.__remote_scope__) { // create a global scope for container, similar to how remotes are set on window in the browser - global.__remote_scope__ = { + globalThis.__remote_scope__ = { _config: {}, }; } @@ -351,7 +351,7 @@ module.exports = new Promise((resolve, reject) => { const [containerGlobal, url] = currentRequest.split('@'); // if node server, register the containers known origins if (typeof window === 'undefined') { - global.__remote_scope__._config[global] = url; + globalThis.__remote_scope__._config[global] = url; } const __webpack_error__ = new Error(); // if you use NodeFederationPlugin, ive build a server-side version of __webpack_require__.l, with the same api. @@ -360,7 +360,7 @@ module.exports = new Promise((resolve, reject) => { url, function (event) { // resolve promise with container, for browser env or node env. - const container = typeof window === 'undefined' ? global.__remote_scope__[containerGlobal] : window[containerGlobal]; + const container = typeof window === 'undefined' ? globalThis.__remote_scope__[containerGlobal] : window[containerGlobal]; console.log('delegate resolving', container); if (typeof container !== 'undefined') return resolve(container); var realSrc = event && event.target && event.target.src; diff --git a/packages/nextjs-mf/src/loaders/fixImageLoader.ts b/packages/nextjs-mf/src/loaders/fixImageLoader.ts index c7acd6210c1..2ae42e4fee5 100644 --- a/packages/nextjs-mf/src/loaders/fixImageLoader.ts +++ b/packages/nextjs-mf/src/loaders/fixImageLoader.ts @@ -42,7 +42,7 @@ export async function fixImageLoader( Template.asString([ 'try {', Template.indent([ - 'const remoteEntry = global.__remote_scope__ && global.__remote_scope__._config[__webpack_runtime_id__];', + 'const remoteEntry = globalThis.__remote_scope__ && globalThis.__remote_scope__._config[__webpack_runtime_id__];', `if (remoteEntry) {`, Template.indent([ `const splitted = remoteEntry.split('/_next')`, diff --git a/packages/node/src/plugins/LoadFileChunkLoadingRuntimeModule.ts b/packages/node/src/plugins/LoadFileChunkLoadingRuntimeModule.ts index 22f1789fc33..ef5f6e820d5 100644 --- a/packages/node/src/plugins/LoadFileChunkLoadingRuntimeModule.ts +++ b/packages/node/src/plugins/LoadFileChunkLoadingRuntimeModule.ts @@ -236,10 +236,10 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule { 'url,callback,chunkId', [ Template.indent([ - 'if(!global.__remote_scope__) {', + 'if(!globalThis.__remote_scope__) {', Template.indent([ '// create a global scope for container, similar to how remotes are set on window in the browser', - 'global.__remote_scope__ = {', + 'globalThis.__remote_scope__ = {', '_config: {},', '}', ]), @@ -326,8 +326,8 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule { {} as Record ) )};`, - 'Object.assign(global.__remote_scope__._config, remotes)', - 'const remoteRegistry = global.__remote_scope__._config', + 'Object.assign(globalThis.__remote_scope__._config, remotes)', + 'const remoteRegistry = globalThis.__remote_scope__._config', /* TODO: keying by global should be ok, but need to verify - need to deal with when user passes promise new promise() global will/should still exist - but can only be known at runtime */ @@ -337,19 +337,19 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule { ), this._getLogger( `'remote scope configs'`, - 'global.__remote_scope__._config' + 'globalThis.__remote_scope__._config' ), this._getLogger(`'before remote scope'`), this._getLogger( - `'global.__remote_scope__'`, - `global.__remote_scope__` + `'globalThis.__remote_scope__'`, + `globalThis.__remote_scope__` ), this._getLogger( - `'global.__remote_scope__[${JSON.stringify( + `'globalThis.__remote_scope__[${JSON.stringify( name )}]'`, - `global.__remote_scope__[${JSON.stringify(name)}]` + `globalThis.__remote_scope__[${JSON.stringify(name)}]` ), /* TODO: this global.REMOTE_CONFIG doesnt work in this v5 core, not sure if i need to keep it or not @@ -397,8 +397,8 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule { `var scriptUrl = new URL(requestedRemote);`, this._getLogger( - `'global.__remote_scope__'`, - `global.__remote_scope__` + `'globalThis.__remote_scope__'`, + `globalThis.__remote_scope__` ), `var chunkName = ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`, this._getLogger( diff --git a/packages/node/src/plugins/NodeFederationPlugin.ts b/packages/node/src/plugins/NodeFederationPlugin.ts index 600ffdd1493..5a865125fa1 100644 --- a/packages/node/src/plugins/NodeFederationPlugin.ts +++ b/packages/node/src/plugins/NodeFederationPlugin.ts @@ -47,19 +47,19 @@ export const generateRemoteTemplate = ( url: string, global: any ) => `new Promise(function (resolve, reject) { - if(!global.__remote_scope__) { + if(!globalThis.__remote_scope__) { // create a global scope for container, similar to how remotes are set on window in the browser - global.__remote_scope__ = { + globalThis.__remote_scope__ = { _config: {}, } } - if (typeof global.__remote_scope__[${JSON.stringify( + if (typeof globalThis.__remote_scope__[${JSON.stringify( global - )}] !== 'undefined') return resolve(global.__remote_scope__[${JSON.stringify( + )}] !== 'undefined') return resolve(globalThis.__remote_scope__[${JSON.stringify( global )}]); - global.__remote_scope__._config[${JSON.stringify( + globalThis.__remote_scope__._config[${JSON.stringify( global )}] = ${JSON.stringify(url)}; var __webpack_error__ = new Error(); @@ -67,9 +67,9 @@ export const generateRemoteTemplate = ( __webpack_require__.l( ${JSON.stringify(url)}, function (event) { - if (typeof global.__remote_scope__[${JSON.stringify( + if (typeof globalThis.__remote_scope__[${JSON.stringify( global - )}] !== 'undefined') return resolve(global.__remote_scope__[${JSON.stringify( + )}] !== 'undefined') return resolve(globalThis.__remote_scope__[${JSON.stringify( global )}]); var realSrc = event && event.target && event.target.src; diff --git a/packages/node/src/plugins/loadScript.ts b/packages/node/src/plugins/loadScript.ts index 97043bf4986..359767fe4d9 100644 --- a/packages/node/src/plugins/loadScript.ts +++ b/packages/node/src/plugins/loadScript.ts @@ -47,7 +47,7 @@ export const executeLoadTemplate = ` throw new Error('__webpack_require__.l name is required for ' + url); } - if (typeof global.__remote_scope__[name] !== 'undefined') return callback(global.__remote_scope__[name]); + if (typeof globalThis.__remote_scope__[name] !== 'undefined') return callback(globalThis.__remote_scope__[name]); const vm = require('vm'); (global.webpackChunkLoad || global.fetch || require("node-fetch"))(url).then(function (res) { return res.text(); @@ -59,11 +59,11 @@ export const executeLoadTemplate = ` const remote = vm.runInNewContext(scriptContent + '\\nmodule.exports', vmContext, {filename: 'node-federation-loader-' + name + '.vm'}); const foundContainer = remote[name] || remote - if(!global.__remote_scope__[name]) { - global.__remote_scope__[name] = foundContainer; - global.__remote_scope__._config[name] = url; + if(!globalThis.__remote_scope__[name]) { + globalThis.__remote_scope__[name] = foundContainer; + globalThis.__remote_scope__._config[name] = url; } - callback(global.__remote_scope__[name]); + callback(globalThis.__remote_scope__[name]); } catch (e) { console.error('executeLoad hit catch block'); e.target = {src: url}; diff --git a/packages/node/src/utils/flush-chunks.ts b/packages/node/src/utils/flush-chunks.ts index 31aaf344ddf..5a2d59fc923 100644 --- a/packages/node/src/utils/flush-chunks.ts +++ b/packages/node/src/utils/flush-chunks.ts @@ -73,7 +73,7 @@ const processChunk = async (chunk, shareMap, hostStats) => { const [remote, request] = chunk.split('->'); // If the remote is not defined in the global config, return - if (!global.__remote_scope__._config[remote]) { + if (!globalThis.__remote_scope__._config[remote]) { console.error( `flush chunks:`, `Remote ${remote} is not defined in the global config` @@ -83,12 +83,12 @@ const processChunk = async (chunk, shareMap, hostStats) => { try { // Extract the remote name from the URL - const remoteName = new URL(global.__remote_scope__._config[remote]).pathname + const remoteName = new URL(globalThis.__remote_scope__._config[remote]).pathname .split('/') .pop(); // Construct the stats file URL from the remote config - const statsFile = global.__remote_scope__._config[remote] + const statsFile = globalThis.__remote_scope__._config[remote] .replace(remoteName, 'federated-stats.json') .replace('ssr', 'chunks'); @@ -107,7 +107,7 @@ const processChunk = async (chunk, shareMap, hostStats) => { // ); // Extract the prefix from the remote config - const [prefix] = global.__remote_scope__._config[remote].split('static/'); + const [prefix] = globalThis.__remote_scope__._config[remote].split('static/'); // Process federated modules from the stats object // @ts-ignore diff --git a/packages/node/src/utils/hot-reload.ts b/packages/node/src/utils/hot-reload.ts index 096e1e6f330..900bd0c22ea 100644 --- a/packages/node/src/utils/hot-reload.ts +++ b/packages/node/src/utils/hot-reload.ts @@ -15,7 +15,7 @@ const performReload = (shouldReload: any) => { } //@ts-ignore - global.__remote_scope__ = { + globalThis.__remote_scope__ = { _config: {}, _medusa: {}, }; @@ -39,7 +39,7 @@ const performReload = (shouldReload: any) => { webpack whether its hash has changed since last time or not */ export const revalidate = () => { - if (global.__remote_scope__) { + if (globalThis.__remote_scope__) { const remoteScope = global.__remote_scope__; return new Promise((res) => { diff --git a/packages/utilities/src/utils/common.ts b/packages/utilities/src/utils/common.ts index 32f61e0faae..3b15f16bfb6 100644 --- a/packages/utilities/src/utils/common.ts +++ b/packages/utilities/src/utils/common.ts @@ -76,10 +76,10 @@ export const loadScript = (keyOrRuntimeRemoteItem: string | RuntimeRemote) => { }; // @ts-ignore - if (!global.__remote_scope__) { + if (!globalThis.__remote_scope__) { // create a global scope for container, similar to how remotes are set on window in the browser // @ts-ignore - global.__remote_scope__ = { + globalThis.__remote_scope__ = { // @ts-ignore _config: {}, }; @@ -87,7 +87,7 @@ export const loadScript = (keyOrRuntimeRemoteItem: string | RuntimeRemote) => { // @ts-ignore const globalScope = // @ts-ignore - typeof window !== 'undefined' ? window : global.__remote_scope__; + typeof window !== 'undefined' ? window : globalThis.__remote_scope__; if (typeof window === 'undefined') { globalScope['_config'][containerKey] = reference.url; @@ -258,7 +258,7 @@ export const getContainer = async ( // @ts-ignore const containerScope = // @ts-ignore - typeof window !== 'undefined' ? window : global.__remote_scope__; + typeof window !== 'undefined' ? window : globalThis.__remote_scope__; if (typeof remoteContainer === 'string') { if (containerScope[remoteContainer]) { From ae23a47911a96b8d55c7336e358905020b37eedb Mon Sep 17 00:00:00 2001 From: ScriptedAlchemy Date: Fri, 30 Jun 2023 17:26:46 -0700 Subject: [PATCH 3/9] feat: support edge workers --- packages/node/src/plugins/loadScript.ts | 88 +++++++++++++++++-------- 1 file changed, 61 insertions(+), 27 deletions(-) diff --git a/packages/node/src/plugins/loadScript.ts b/packages/node/src/plugins/loadScript.ts index 359767fe4d9..67b39b2cc94 100644 --- a/packages/node/src/plugins/loadScript.ts +++ b/packages/node/src/plugins/loadScript.ts @@ -6,16 +6,28 @@ //language=JS export default ` function loadScript(url, cb, chunkID) { - if (global.webpackChunkLoad) { - global.webpackChunkLoad(url).then(function (resp) { + var url; + var cb = arguments[arguments.length - 1]; + if (typeof cb !== "function") { + throw new Error("last argument should be a function"); + } + if (arguments.length === 2) { + url = arguments[0]; + } else if (arguments.length === 3) { + url = new URL(arguments[1], arguments[0]).toString(); + } else { + throw new Error("invalid number of arguments"); + } + if (globalThis.webpackChunkLoad) { + globalThis.webpackChunkLoad(url).then(function (resp) { return resp.text(); }).then(function (rawData) { cb(null, rawData); }).catch(function (err) { - console.error('Federated Chunk load failed', error); - return cb(error) + console.error('Federated Chunk load failed', err); + return cb(err) }); - } else { + } else if (typeof process !== 'undefined') { //TODO https support let request = (url.startsWith('https') ? require('https') : require('http')).get(url, function (resp) { if (resp.statusCode === 200) { @@ -35,6 +47,15 @@ export default ` console.error('Federated Chunk load failed', error); return cb(error) }); + } else { + fetch(url).then(function (resp) { + return resp.text(); + }).then(function (rawData) { + cb(null, rawData); + }).catch(function (err) { + console.error('Federated Chunk load failed', err); + return cb(err) + }) } } `; @@ -43,35 +64,48 @@ export default ` //language=JS export const executeLoadTemplate = ` function executeLoad(url, callback, name) { - if(!name) { + if (!name) { throw new Error('__webpack_require__.l name is required for ' + url); } - if (typeof globalThis.__remote_scope__[name] !== 'undefined') return callback(globalThis.__remote_scope__[name]); - const vm = require('vm'); - (global.webpackChunkLoad || global.fetch || require("node-fetch"))(url).then(function (res) { - return res.text(); - }).then(function (scriptContent) { - try { - // TODO: remove conditional in v7, this is to prevent breaking change between v6.0.x and v6.1.x - const vmContext = typeof URLSearchParams === 'undefined' ?{exports, require, module, global, __filename, __dirname, URL, URLSearchParams, console, process,Buffer, ...global, remoteEntryName: name}: + // if its a worker or node + if (typeof process !== 'undefined') { + const vm = require('vm'); + (globalThis.webpackChunkLoad || globalThis.fetch || require("node-fetch"))(url).then(function (res) { + return res.text(); + }).then(function (scriptContent) { + try { + const vmContext = typeof URLSearchParams === 'undefined' ?{exports, require, module, global, __filename, __dirname, URL, URLSearchParams, console, process,Buffer, ...global, remoteEntryName: name}: {exports, require, module, global, __filename, __dirname, URL, URLSearchParams, console, process,Buffer, ...global, remoteEntryName: name}; - const remote = vm.runInNewContext(scriptContent + '\\nmodule.exports', vmContext, {filename: 'node-federation-loader-' + name + '.vm'}); - const foundContainer = remote[name] || remote - - if(!globalThis.__remote_scope__[name]) { - globalThis.__remote_scope__[name] = foundContainer; + const remote = vm.runInNewContext(scriptContent + '\\nmodule.exports', vmContext, {filename: 'node-federation-loader-' + name + '.vm'}); + globalThis.__remote_scope__[name] = remote[name] || remote; globalThis.__remote_scope__._config[name] = url; + callback(globalThis.__remote_scope__[name]) + } catch (e) { + console.error('executeLoad hit catch block'); + e.target = {src: url}; + callback(e); } - callback(globalThis.__remote_scope__[name]); - } catch (e) { - console.error('executeLoad hit catch block'); + }).catch((e) => { e.target = {src: url}; callback(e); - } - }).catch((e) => { - e.target = {src: url}; - callback(e); - }); + }); + } else { + fetch(url).then(function (res) { + return res.text(); + }).then(function (scriptContent) { + try { + const remote = eval('let module = {};' + scriptContent + '\\nmodule.exports') + // const remote = vm.runInNewContext(scriptContent + '\\nmodule.exports', vmContext, {filename: 'node-federation-loader-' + name + '.vm'}); + globalThis.__remote_scope__[name] = remote[name] || remote; + globalThis.__remote_scope__._config[name] = url; + callback(globalThis.__remote_scope__[name]) + } catch (e) { + console.error('executeLoad hit catch block',e); + e.target = {src: url}; + callback(e); + } + }); + } } `; From 01305bd85463535541dcba8fed8fd8ab96743791 Mon Sep 17 00:00:00 2001 From: ScriptedAlchemy Date: Fri, 30 Jun 2023 17:47:41 -0700 Subject: [PATCH 4/9] fix: global refs to globalThis --- packages/node/global.d.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/node/global.d.ts b/packages/node/global.d.ts index 19be47d09b9..7bd89d9ba4b 100644 --- a/packages/node/global.d.ts +++ b/packages/node/global.d.ts @@ -9,16 +9,21 @@ declare module 'webpack/lib/RuntimeModule'; declare module 'webpack/lib/Template'; declare module 'webpack/lib/util/compileBooleanMatcher'; declare module 'webpack/lib/util/identifier'; - -declare const global: typeof globalThis & { - usedChunks: Set; - flushChunks: () => Promise>; - __remote_scope__: { +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface global {} +declare global { + //eslint-disable-next-line + var usedChunks: Set; + //eslint-disable-next-line + var flushChunks: () => Promise>; + //eslint-disable-next-line + var __remote_scope__: { _config: Record; _medusa?: Record; [K: string]: { fake?: boolean; }; }; - webpackChunkLoad; -}; + //eslint-disable-next-line + var webpackChunkLoad; +} From 4c985ba6760e95e016b16e331f6ecbf3c4d07ce8 Mon Sep 17 00:00:00 2001 From: ScriptedAlchemy Date: Fri, 30 Jun 2023 18:05:33 -0700 Subject: [PATCH 5/9] fix: global refs to globalThis --- packages/node/global.d.ts | 19 +++++++------------ packages/node/src/utils/flush-chunks.ts | 4 ++++ packages/node/src/utils/hot-reload.ts | 7 +++++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/node/global.d.ts b/packages/node/global.d.ts index 7bd89d9ba4b..a92403ee924 100644 --- a/packages/node/global.d.ts +++ b/packages/node/global.d.ts @@ -9,21 +9,16 @@ declare module 'webpack/lib/RuntimeModule'; declare module 'webpack/lib/Template'; declare module 'webpack/lib/util/compileBooleanMatcher'; declare module 'webpack/lib/util/identifier'; -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface global {} -declare global { - //eslint-disable-next-line - var usedChunks: Set; - //eslint-disable-next-line - var flushChunks: () => Promise>; - //eslint-disable-next-line - var __remote_scope__: { + +declare const globalThis: typeof globalThis & { + usedChunks: Set; + flushChunks: () => Promise>; + __remote_scope__: { _config: Record; _medusa?: Record; [K: string]: { fake?: boolean; }; }; - //eslint-disable-next-line - var webpackChunkLoad; -} + webpackChunkLoad; +}; diff --git a/packages/node/src/utils/flush-chunks.ts b/packages/node/src/utils/flush-chunks.ts index 5a2d59fc923..a8ece7ad7de 100644 --- a/packages/node/src/utils/flush-chunks.ts +++ b/packages/node/src/utils/flush-chunks.ts @@ -73,6 +73,7 @@ const processChunk = async (chunk, shareMap, hostStats) => { const [remote, request] = chunk.split('->'); // If the remote is not defined in the global config, return + //@ts-ignore if (!globalThis.__remote_scope__._config[remote]) { console.error( `flush chunks:`, @@ -83,11 +84,13 @@ const processChunk = async (chunk, shareMap, hostStats) => { try { // Extract the remote name from the URL + //@ts-ignore const remoteName = new URL(globalThis.__remote_scope__._config[remote]).pathname .split('/') .pop(); // Construct the stats file URL from the remote config + //@ts-ignore const statsFile = globalThis.__remote_scope__._config[remote] .replace(remoteName, 'federated-stats.json') .replace('ssr', 'chunks'); @@ -107,6 +110,7 @@ const processChunk = async (chunk, shareMap, hostStats) => { // ); // Extract the prefix from the remote config + //@ts-ignore const [prefix] = globalThis.__remote_scope__._config[remote].split('static/'); // Process federated modules from the stats object diff --git a/packages/node/src/utils/hot-reload.ts b/packages/node/src/utils/hot-reload.ts index 900bd0c22ea..26eef601fe1 100644 --- a/packages/node/src/utils/hot-reload.ts +++ b/packages/node/src/utils/hot-reload.ts @@ -39,8 +39,10 @@ const performReload = (shouldReload: any) => { webpack whether its hash has changed since last time or not */ export const revalidate = () => { + //@ts-ignore if (globalThis.__remote_scope__) { - const remoteScope = global.__remote_scope__; + //@ts-ignore + const remoteScope = globalThis.__remote_scope__; return new Promise((res) => { const fetches = []; @@ -159,7 +161,8 @@ export const revalidate = () => { allows us to use fetch in our tests without having to mock out nodefetch */ function getFetchModule() { - const loadedModule = global.webpackChunkLoad || global.fetch; + //@ts-ignore + const loadedModule = globalThis.webpackChunkLoad || global.webpackChunkLoad || global.fetch; if (loadedModule) { return loadedModule; } From e84155afa4bc3fcb8314b18833e68c4808861726 Mon Sep 17 00:00:00 2001 From: ScriptedAlchemy Date: Fri, 30 Jun 2023 18:26:37 -0700 Subject: [PATCH 6/9] fix: global refs to globalThis --- .../LoadFileChunkLoadingRuntimeModule.ts | 1 + packages/node/src/plugins/loadScript.ts | 34 +++++-------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/packages/node/src/plugins/LoadFileChunkLoadingRuntimeModule.ts b/packages/node/src/plugins/LoadFileChunkLoadingRuntimeModule.ts index ef5f6e820d5..fcaeee645af 100644 --- a/packages/node/src/plugins/LoadFileChunkLoadingRuntimeModule.ts +++ b/packages/node/src/plugins/LoadFileChunkLoadingRuntimeModule.ts @@ -413,6 +413,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule { ), `loadScript(scriptUrl.toString(), function(err, content) {`, Template.indent([ + "console.log('fiding load script callback')", this._getLogger(`'load script callback fired'`), "if(err) {console.error('error loading remote chunk', scriptUrl.toString(),'got',content,'with error', err); return reject(err);}", 'var chunk = {};', diff --git a/packages/node/src/plugins/loadScript.ts b/packages/node/src/plugins/loadScript.ts index 67b39b2cc94..492ca545bff 100644 --- a/packages/node/src/plugins/loadScript.ts +++ b/packages/node/src/plugins/loadScript.ts @@ -6,28 +6,16 @@ //language=JS export default ` function loadScript(url, cb, chunkID) { - var url; - var cb = arguments[arguments.length - 1]; - if (typeof cb !== "function") { - throw new Error("last argument should be a function"); - } - if (arguments.length === 2) { - url = arguments[0]; - } else if (arguments.length === 3) { - url = new URL(arguments[1], arguments[0]).toString(); - } else { - throw new Error("invalid number of arguments"); - } - if (globalThis.webpackChunkLoad) { - globalThis.webpackChunkLoad(url).then(function (resp) { + if (global.webpackChunkLoad) { + global.webpackChunkLoad(url).then(function (resp) { return resp.text(); }).then(function (rawData) { cb(null, rawData); }).catch(function (err) { - console.error('Federated Chunk load failed', err); - return cb(err) + console.error('Federated Chunk load failed', error); + return cb(error) }); - } else if (typeof process !== 'undefined') { + } else { //TODO https support let request = (url.startsWith('https') ? require('https') : require('http')).get(url, function (resp) { if (resp.statusCode === 200) { @@ -47,15 +35,6 @@ export default ` console.error('Federated Chunk load failed', error); return cb(error) }); - } else { - fetch(url).then(function (resp) { - return resp.text(); - }).then(function (rawData) { - cb(null, rawData); - }).catch(function (err) { - console.error('Federated Chunk load failed', err); - return cb(err) - }) } } `; @@ -67,6 +46,7 @@ export const executeLoadTemplate = ` if (!name) { throw new Error('__webpack_require__.l name is required for ' + url); } + if (typeof globalThis.__remote_scope__[name] !== 'undefined') return callback(globalThis.__remote_scope__[name]); // if its a worker or node if (typeof process !== 'undefined') { @@ -79,10 +59,12 @@ export const executeLoadTemplate = ` {exports, require, module, global, __filename, __dirname, URL, URLSearchParams, console, process,Buffer, ...global, remoteEntryName: name}; const remote = vm.runInNewContext(scriptContent + '\\nmodule.exports', vmContext, {filename: 'node-federation-loader-' + name + '.vm'}); globalThis.__remote_scope__[name] = remote[name] || remote; + globalThis.__remote_scope__._config[name] = url; callback(globalThis.__remote_scope__[name]) } catch (e) { console.error('executeLoad hit catch block'); + e.target = {src: url}; callback(e); } From 2124ee4c81322af3e589ff387570cc222dc2cbd0 Mon Sep 17 00:00:00 2001 From: ScriptedAlchemy Date: Fri, 30 Jun 2023 18:36:18 -0700 Subject: [PATCH 7/9] feat: backmerge prev edgeworker progress --- packages/node/src/plugins/LoadFileChunkLoadingRuntimeModule.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/node/src/plugins/LoadFileChunkLoadingRuntimeModule.ts b/packages/node/src/plugins/LoadFileChunkLoadingRuntimeModule.ts index 3d22fbfd192..6a28b503177 100644 --- a/packages/node/src/plugins/LoadFileChunkLoadingRuntimeModule.ts +++ b/packages/node/src/plugins/LoadFileChunkLoadingRuntimeModule.ts @@ -320,7 +320,6 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule { "}", ]), 'Object.assign(globalThis.__remote_scope__._config, remotes)', - 'console.log("after reg");', 'const remoteRegistry = globalThis.__remote_scope__._config', /* TODO: keying by global should be ok, but need to verify - need to deal with when user passes promise new promise() global will/should still exist - but can only be known at runtime From 9a740d7810c3e8a7314d1a82c195185bdcc44742 Mon Sep 17 00:00:00 2001 From: ScriptedAlchemy Date: Fri, 30 Jun 2023 20:30:59 -0700 Subject: [PATCH 8/9] fix: use runInThisContext for remote containers --- packages/node/src/plugins/loadScript.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/node/src/plugins/loadScript.ts b/packages/node/src/plugins/loadScript.ts index bdd6c1c73b7..04e2b5787f2 100644 --- a/packages/node/src/plugins/loadScript.ts +++ b/packages/node/src/plugins/loadScript.ts @@ -75,15 +75,18 @@ export const executeLoadTemplate = ` return res.text(); }).then(function (scriptContent) { try { - const vmContext = typeof URLSearchParams === 'undefined' ?{exports, require, module, global, __filename, __dirname, URL, URLSearchParams, console, process,Buffer, ...global, remoteEntryName: name}: - {exports, require, module, global, __filename, __dirname, URL, URLSearchParams, console, process,Buffer, ...global, remoteEntryName: name}; + const m = require('module'); - const remote = vm.runInNewContext(scriptContent + '\\nmodule.exports', vmContext, {filename: 'node-federation-loader-' + name + '.vm'}); + const remoteCapsule = vm.runInThisContext(m.wrap(scriptContent), 'node-federation-loader-' + name + '.vm') + const exp = {}; + let remote = {exports:{}}; + remoteCapsule(exp,require,remote,'node-federation-loader-' + name + '.vm',__dirname); + remote = remote.exports || remote; globalThis.__remote_scope__[name] = remote[name] || remote; globalThis.__remote_scope__._config[name] = url; callback(globalThis.__remote_scope__[name]) } catch (e) { - console.error('executeLoad hit catch block'); + console.error('executeLoad hit catch block', e); e.target = {src: url}; callback(e); } @@ -97,7 +100,6 @@ export const executeLoadTemplate = ` }).then(function (scriptContent) { try { const remote = eval('let module = {};' + scriptContent + '\\nmodule.exports') - // const remote = vm.runInNewContext(scriptContent + '\\nmodule.exports', vmContext, {filename: 'node-federation-loader-' + name + '.vm'}); globalThis.__remote_scope__[name] = remote[name] || remote; globalThis.__remote_scope__._config[name] = url; callback(globalThis.__remote_scope__[name]) From 2843616f1432955788b2a74bcc2f3cf0aaee57c5 Mon Sep 17 00:00:00 2001 From: ScriptedAlchemy Date: Fri, 30 Jun 2023 20:41:45 -0700 Subject: [PATCH 9/9] fix: remove unused flush logic --- packages/node/src/utils/flush-chunks.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/node/src/utils/flush-chunks.ts b/packages/node/src/utils/flush-chunks.ts index a8ece7ad7de..7acf17ee9b2 100644 --- a/packages/node/src/utils/flush-chunks.ts +++ b/packages/node/src/utils/flush-chunks.ts @@ -73,7 +73,6 @@ const processChunk = async (chunk, shareMap, hostStats) => { const [remote, request] = chunk.split('->'); // If the remote is not defined in the global config, return - //@ts-ignore if (!globalThis.__remote_scope__._config[remote]) { console.error( `flush chunks:`, @@ -90,7 +89,6 @@ const processChunk = async (chunk, shareMap, hostStats) => { .pop(); // Construct the stats file URL from the remote config - //@ts-ignore const statsFile = globalThis.__remote_scope__._config[remote] .replace(remoteName, 'federated-stats.json') .replace('ssr', 'chunks'); @@ -110,7 +108,6 @@ const processChunk = async (chunk, shareMap, hostStats) => { // ); // Extract the prefix from the remote config - //@ts-ignore const [prefix] = globalThis.__remote_scope__._config[remote].split('static/'); // Process federated modules from the stats object @@ -142,9 +139,7 @@ const processChunk = async (chunk, shareMap, hostStats) => { // Check if the module is in the shareMap if (shareMap[module]) { // If the module is from the host, log the host stats - if (shareMap[module][0].startsWith('host__')) { - console.log('host', hostStats); - } + } }); }