Skip to content

Commit 5c4e070

Browse files
committed
Fix webpacktools.runtimes only catching 2 total runtimes when there are
more than two Changes webpackTools.runtimes[chunkObjectName] to be an array of runtimes using that name, rather than before where subsequent runtimes would be accessed like `webpackTools.runtimes[chunkObjectName + "_" + index]` Spacepack __namedRequire is renamed to namedRequire
1 parent 7d8be59 commit 5c4e070

1 file changed

Lines changed: 10 additions & 19 deletions

File tree

src/spacepackLite.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ function extractPrivateCache(webpackRequire) {
7777
cache = this;
7878
return { exports: {} };
7979
},
80-
set() { },
80+
set() {},
8181
configurable: true,
82-
})
82+
});
8383

8484
webpackRequire(sym);
8585
delete Object.prototype[sym];
@@ -220,8 +220,7 @@ export function getSpacepack(chunkObject, logSuccess = false) {
220220
modules: webpackRequire.m,
221221
cache: cache,
222222

223-
224-
__namedRequire: getNamedRequire(webpackRequire),
223+
namedRequire: getNamedRequire(webpackRequire),
225224

226225
findByCode,
227226
findByExports,
@@ -242,24 +241,16 @@ export function getSpacepack(chunkObject, logSuccess = false) {
242241

243242
// If already registered with the same chunk object name
244243
if (runtimesRegistry[chunkObject]) {
245-
console.warn("[wpTools] Multiple active runtimes for " + chunkObject);
246-
247-
let currId = 0;
248-
if (runtimesRegistry[chunkObject].__wpTools_multiRuntime_id) {
249-
currId = runtimesRegistry[chunkObject].__wpTools_multiRuntime_id;
250-
}
244+
console.warn(
245+
`[wpTools] Duplicate runtimes for ${chunkObject}. Spacepack for other runtimes is accessible through wpTools.runtimes if necesary. `,
246+
);
251247

252-
runtimesRegistry[chunkObject + "_" + currId] = runtimesRegistry[chunkObject];
253-
254-
currId++;
255-
runtimesRegistry[chunkObject + "_" + currId] = exportedRequire;
256-
257-
// The last runtime load seems to be the one that's most active
258-
runtimesRegistry[chunkObject] = exportedRequire;
248+
runtimesRegistry[chunkObject].push(exportedRequire);
249+
} else {
250+
runtimesRegistry[chunkObject] = [exportedRequire];
259251
}
260-
runtimesRegistry[chunkObject] = exportedRequire;
261-
window["spacepack_" + chunkObject] = exportedRequire;
262252
}
253+
window["spacepack_" + chunkObject] = exportedRequire;
263254
window["spacepack"] = exportedRequire;
264255
}
265256

0 commit comments

Comments
 (0)