Skip to content

Commit

Permalink
add patchEntryChunk option to siteConfigs
Browse files Browse the repository at this point in the history
  • Loading branch information
adryd325 committed Dec 20, 2023
1 parent b96fee2 commit 4555203
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/Patcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 || [])`
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4555203

Please sign in to comment.