From 45552039f8f09ef1f56c3dc61b3a062c15ae81d0 Mon Sep 17 00:00:00 2001 From: adryd Date: Wed, 20 Dec 2023 15:39:33 -0500 Subject: [PATCH] add patchEntryChunk option to siteConfigs --- src/Patcher.js | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/Patcher.js b/src/Patcher.js index 5e79ff8..d3a9641 100644 --- a/src/Patcher.js +++ b/src/Patcher.js @@ -74,6 +74,16 @@ export default class Patcher { entry: true, }); } + + // Some ven and cyn magic + if (config.patchEntryChunk) { + this.modulesToInject.add({ + name: "patchEntryChunk", + run: (module, exports, webpackRequire) => {this._patchModules(webpackRequire.m)}, + entry: true, + }); + this.patchEntryChunk = true; + } } run() { @@ -92,6 +102,12 @@ export default class Patcher { Object.defineProperty(window, this.chunkObject, { set: function set(value) { realChunkObject = value; + if (patcher.patchEntryChunk) { + let newChunk = [["patchEntryChunk"], {}] + patcher._injectModules(newChunk); + realChunkObject.push(newChunk); + } + // Don't infinitely re-wrap .push() // Every webpack chunk reassigns the chunk array, triggering the setter every time // `(self.webpackChunk = self.webpackChunk || [])` @@ -268,23 +284,27 @@ export default class Patcher { validateProperty(`siteConfigs[${name}]`, config, "injectSpacepack", false, (value) => { return typeof value === "boolean"; }); - } - _validatePatchReplacement(replace, name, index) { - let indexStr = index === undefined ? "" : `[${index}]` - validateProperty(`siteConfigs[${this.name}].patches[${name}].replace${indexStr}`, replace, "match", true, (value) => { - return typeof value === "string" || value instanceof RegExp; + validateProperty(`siteConfigs[${name}]`, config, "patchEntryChunk", false, (value) => { + return typeof value === "boolean"; }); + } + _validatePatchReplacement(replace, name, index) { + let indexStr = index === undefined ? "" : `[${index}]`; validateProperty( - `siteConfigs[${this.name}].patches[${name}].replace`, + `siteConfigs[${this.name}].patches[${name}].replace${indexStr}`, replace, - "replacement", + "match", true, (value) => { - return typeof value === "string" || value instanceof Function; + return typeof value === "string" || value instanceof RegExp; }, ); + + validateProperty(`siteConfigs[${this.name}].patches[${name}].replace`, replace, "replacement", true, (value) => { + return typeof value === "string" || value instanceof Function; + }); } _validatePatchConfig(config) {