From fe17463ba5488fe1f48e8026a83b049dd8f17bd8 Mon Sep 17 00:00:00 2001 From: adryd Date: Wed, 6 Dec 2023 17:52:30 -0500 Subject: [PATCH] make spacepackLite closer to real spacepack --- src/Patcher.js | 4 ++-- src/spacepackEverywhere.js | 4 ++-- src/spacepackLite.js | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Patcher.js b/src/Patcher.js index 1b08d94..5e79ff8 100644 --- a/src/Patcher.js +++ b/src/Patcher.js @@ -1,5 +1,5 @@ import matchModule from "./matchModule"; -import { getWpToolsFunc } from "./spacepackLite"; +import { getSpacepack } from "./spacepackLite"; class ConfigValidationError extends Error {} @@ -70,7 +70,7 @@ export default class Patcher { name: "spacepack", // This is sorta a scope hack. // If we rewrap this function, it will lose its scope (in this case the match module import and the chunk object name) - run: getWpToolsFunc(this.chunkObject), + run: getSpacepack(this.chunkObject), entry: true, }); } diff --git a/src/spacepackEverywhere.js b/src/spacepackEverywhere.js index f27cc84..ed4dab1 100644 --- a/src/spacepackEverywhere.js +++ b/src/spacepackEverywhere.js @@ -1,4 +1,4 @@ -import { getWpToolsFunc } from "./spacepackLite"; +import { getSpacepack } from "./spacepackLite"; function getWebpackVersion(chunkObject) { if (chunkObject instanceof Array) { @@ -37,7 +37,7 @@ function pushSpacepack(chunkObjectName) { switch (version) { case "modern": chunkObject.__spacepack_everywhere_injected = true; - chunkObject.push([["spacepack"], { spacepack: getWpToolsFunc(chunkObjectName, true) }, onChunkLoaded]); + chunkObject.push([["spacepack"], { spacepack: getSpacepack(chunkObjectName, true) }, onChunkLoaded]); break; } } diff --git a/src/spacepackLite.js b/src/spacepackLite.js index c6abdc4..ad22991 100644 --- a/src/spacepackLite.js +++ b/src/spacepackLite.js @@ -67,8 +67,8 @@ function getNamedRequire(webpackRequire) { return namedRequireObj; } -export function getWpToolsFunc(chunkObject, logSuccess = false) { - function wpTools(module, exports, webpackRequire) { +export function getSpacepack(chunkObject, logSuccess = false) { + function spacepack(module, exports, webpackRequire) { if (logSuccess) { console.log("[wpTools] spacepack loaded in " + chunkObject); } @@ -78,7 +78,7 @@ export function getWpToolsFunc(chunkObject, logSuccess = false) { // modules require cache (exports): webpackRequire.c // TODO: recurse in objects - function findModulesByExports(keysArg) { + function findByExports(keysArg) { if (!webpackRequire.c) { throw new Error("webpack runtime didn't export its moduleCache"); } @@ -98,7 +98,7 @@ export function getWpToolsFunc(chunkObject, logSuccess = false) { }); } - function findModulesByCode(search) { + function findByCode(search) { return Object.entries(webpackRequire.m) .filter(([moduleId, moduleFunc]) => { const funcStr = Function.prototype.toString.apply(moduleFunc); @@ -197,8 +197,8 @@ export function getWpToolsFunc(chunkObject, logSuccess = false) { chunkObject: window[chunkObject], name: chunkObject, - findModulesByCode, - findModulesByExports, + findByCode, + findByExports, findObjectFromKey, findObjectFromKeyValuePair, findObjectFromValue, @@ -231,7 +231,7 @@ export function getWpToolsFunc(chunkObject, logSuccess = false) { } // Mark as processed as to not loose scope if somehow passed to Patcher._patchModules() - wpTools.__wpt_processed = true; + spacepack.__wpt_processed = true; - return wpTools; + return spacepack; }