aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2022-12-04 15:10:31 -0500
committerGitHub <[email protected]>2022-12-04 15:10:31 -0500
commitb17cfa4ec2b54a446b780cf0d642dcd7663d8dc0 (patch)
tree378ec930ef28dbb34d6549cd45f32c8f5fe12193
parentec86d6f99db743155edd8e1ae8b35c34e2714e86 (diff)
parent8c185d4b5e90add76abab31473e068bd35d66c76 (diff)
downloadSponsorBlock-b17cfa4ec2b54a446b780cf0d642dcd7663d8dc0.tar.gz
SponsorBlock-b17cfa4ec2b54a446b780cf0d642dcd7663d8dc0.zip
Merge pull request #1348 from mchangrh/configDiffPlugin
config diff plugin
-rw-r--r--webpack/configDiffPlugin.js66
-rw-r--r--webpack/webpack.common.js4
2 files changed, 69 insertions, 1 deletions
diff --git a/webpack/configDiffPlugin.js b/webpack/configDiffPlugin.js
new file mode 100644
index 00000000..ce5e5c5a
--- /dev/null
+++ b/webpack/configDiffPlugin.js
@@ -0,0 +1,66 @@
+/* eslint-disable @typescript-eslint/no-var-requires */
+const { readFile } = require("fs/promises")
+let logger;
+
+const readFileContents = (name) => readFile(name)
+ .then(data => JSON.parse(data))
+
+// partialDeepEquals from ajayyy/SponsorBlockServer
+function partialDeepEquals (actual, expected, logger) {
+ // loop over key, value of expected
+ let failed = false;
+ for (const [ key, value ] of Object.entries(expected)) {
+ if (key === "serverAddress" || key === "testingServerAddress" || key === "serverAddressComment" || key === "freeChapterAccess") continue
+ // if value is object, recurse
+ const actualValue = actual?.[key]
+ if (typeof value !== "string" && Array.isArray(value)) {
+ if (!arrayPartialDeepEquals(actualValue, value)) {
+ printActualExpected(key, actualValue, value, logger)
+ failed = true
+ }
+ } else if (typeof value === "object") {
+ if (partialDeepEquals(actualValue, value, logger)) {
+ console.log("obj failed")
+ printActualExpected(key, actualValue, value, logger)
+ failed = true
+ }
+ } else if (actualValue !== value) {
+ printActualExpected(key, actualValue, value, logger)
+ failed = true
+ }
+ }
+ return failed
+}
+
+const arrayPartialDeepEquals = (actual, expected) =>
+ expected.every(a => actual?.includes(a))
+
+function printActualExpected(key, actual, expected, logger) {
+ logger.error(`Differing value for: ${key}`)
+ logger.error(`Actual: ${JSON.stringify(actual)}`)
+ logger.error(`Expected: ${JSON.stringify(expected)}`)
+}
+
+class configDiffPlugin {
+ apply(compiler) {
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ compiler.hooks.done.tapAsync("configDiffPlugin", async (stats, callback) => {
+ logger = compiler.getInfrastructureLogger('configDiffPlugin')
+ logger.log('Checking for config.json diff...')
+
+ // check example
+ const exampleConfig = await readFileContents("./config.json.example")
+ const currentConfig = await readFileContents("./config.json")
+
+ const difference = partialDeepEquals(currentConfig, exampleConfig, logger)
+ if (difference) {
+ logger.warn("config.json is missing values from config.json.example")
+ } else {
+ logger.info("config.json is not missing any values from config.json.example")
+ }
+ callback()
+ })
+ }
+}
+
+module.exports = configDiffPlugin;
diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js
index d05dea03..0be6c63c 100644
--- a/webpack/webpack.common.js
+++ b/webpack/webpack.common.js
@@ -7,6 +7,7 @@ const BuildManifest = require('./webpack.manifest');
const srcDir = '../src/';
const fs = require("fs");
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
+const configDiffPlugin = require('./configDiffPlugin');
const edgeLanguages = [
"de",
@@ -116,6 +117,7 @@ module.exports = env => ({
browser: env.browser,
pretty: env.mode === "production",
stream: env.stream
- })
+ }),
+ new configDiffPlugin()
]
});