Skip to content

Commit

Permalink
Fix config validation
Browse files Browse the repository at this point in the history
  • Loading branch information
adryd325 committed Dec 6, 2023
1 parent cef5475 commit 4a2d2a0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
11 changes: 0 additions & 11 deletions build/dev.js

This file was deleted.

37 changes: 24 additions & 13 deletions src/Patcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,23 @@ export default class Patcher {
});
}

_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[${this.name}].patches[${name}].replace`,
replace,
"replacement",
true,
(value) => {
return typeof value === "string" || value instanceof Function;
},
);
}

_validatePatchConfig(config) {
validateProperty(`siteConfigs[${this.name}].patches[?]`, config, "name", true, (value) => {
return typeof value === "string";
Expand All @@ -293,19 +310,13 @@ export default class Patcher {
return typeof value === "object";
});

validateProperty(`siteConfigs[${this.name}].patches[${name}].replace`, config.replace, "match", true, (value) => {
return typeof value === "string" || value instanceof RegExp;
});

validateProperty(
`siteConfigs[${this.name}].patches[${name}].replace`,
config.replace,
"replacement",
true,
(value) => {
return typeof value === "string" || value instanceof Function;
},
);
if (config.replace instanceof Array) {
config.replace.forEach((replacement, index) => {
this._validatePatchReplacement(replacement, name, index);
});
} else {
this._validatePatchReplacement(config.replace, name);
}
}

_validateModuleConfig(config) {
Expand Down

0 comments on commit 4a2d2a0

Please sign in to comment.