Quellcode durchsuchen

chore: fix manifest.json

Gerald vor 3 Jahren
Ursprung
Commit
cc60d99d90
4 geänderte Dateien mit 29 neuen und 26 gelöschten Zeilen
  1. 18 14
      .postcssrc.js
  2. 6 8
      gulpfile.js
  3. 3 3
      scripts/manifest-helper.js
  4. 2 1
      scripts/webpack.conf.js

+ 18 - 14
.postcssrc.js

@@ -1,15 +1,19 @@
+const { readManifest } = require('./scripts/manifest-helper');
 const cfg = require('@gera2ld/plaid/postcss/precss')({});
-const manifest = require('./dist/manifest.json');
-const minChrome = parseInt(manifest.minimum_chrome_version);
-const minFirefox = parseInt(manifest.browser_specific_settings.gecko.strict_min_version);
-if (minChrome < 76 || minFirefox < 67) {
-  // Disabling `prefers-color-scheme` polyfill because we use our own one
-  cfg.plugins.forEach((p, i) => {
-    if ((p.postcss || {}).postcssPlugin === 'precss') {
-      cfg.plugins[i] = require('precss')({
-        features: { 'prefers-color-scheme-query': false },
-      });
-    }
-  });
-}
-module.exports = cfg;
+
+module.exports = async () => {
+  const manifest = await readManifest();
+  const minChrome = parseInt(manifest.minimum_chrome_version);
+  const minFirefox = parseInt(manifest.browser_specific_settings.gecko.strict_min_version);
+  if (minChrome < 76 || minFirefox < 67) {
+    // Disabling `prefers-color-scheme` polyfill because we use our own one
+    cfg.plugins.forEach((p, i) => {
+      if ((p.postcss || {}).postcssPlugin === 'precss') {
+        cfg.plugins[i] = require('precss')({
+          features: { 'prefers-color-scheme-query': false },
+        });
+      }
+    });
+  }
+  return cfg;
+};

+ 6 - 8
gulpfile.js

@@ -42,15 +42,13 @@ async function jsProd() {
 }
 
 /**
- * Versioning
- *
- * The version of extension is composed of `version` and `beta` fields in `package.json`.
- *
- * Note: prerelease is ignored and not recommended since both Chrome and Firefox do not support semver
+ * manifest is already handled in ListBackgroundScriptsPlugin
  *
+ * This task is only used to tweak dist/manifest.json without rebuilding
  */
 async function manifest() {
-  const data = await buildManifest();
+  const base = JSON.parse(await fs.readFile(`${DIST}/manifest.json`, 'utf8'));
+  const data = await buildManifest(base);
   await fs.mkdir(DIST).catch(() => {});
   await fs.writeFile(`${DIST}/manifest.json`, JSON.stringify(data), 'utf8');
 }
@@ -168,8 +166,8 @@ const pack = gulp.parallel(createIcons, copyI18n, copyZip);
 exports.clean = clean;
 exports.manifest = manifest;
 // Making sure `manifest` finishes before its `version` is used by webpack.conf.js
-exports.dev = gulp.series(manifest, gulp.parallel(pack, jsDev), watch);
-exports.build = gulp.series(clean, manifest, gulp.parallel(pack, jsProd));
+exports.dev = gulp.series(gulp.parallel(pack, jsDev), watch);
+exports.build = gulp.series(clean, gulp.parallel(pack, jsProd));
 exports.i18n = updateI18n;
 exports.check = checkI18n;
 exports.copyI18n = copyI18n;

+ 3 - 3
scripts/manifest-helper.js

@@ -8,8 +8,8 @@ async function readManifest() {
   return data;
 }
 
-async function buildManifest() {
-  const data = await readManifest();
+async function buildManifest(base) {
+  const data = base ? { ...base } : await readManifest();
   data.version = getVersion();
   if (process.env.TARGET === 'selfHosted') {
     data.browser_specific_settings.gecko.update_url = 'https://raw.githubusercontent.com/violentmonkey/violentmonkey/updates/updates.json';
@@ -49,7 +49,7 @@ class ListBackgroundScriptsPlugin {
     compiler.hooks.afterEmit.tap(this.constructor.name, async compilation => {
       const dist = compilation.outputOptions.path;
       const path = `${dist}/manifest.json`;
-      const manifest = JSON.parse(await fs.readFile(path, { encoding: 'utf8' }));
+      const manifest = await buildManifest();
       const bgId = 'background/index';
       const bgEntry = compilation.entrypoints.get(bgId);
       const scripts = bgEntry.chunks.map(c => c.files[0]);

+ 2 - 1
scripts/webpack.conf.js

@@ -7,6 +7,7 @@ const { ListBackgroundScriptsPlugin } = require('./manifest-helper');
 const { addWrapperWithGlobals, getCodeMirrorThemes, getUniqIdB64 } = require('./webpack-util');
 const ProtectWebpackBootstrapPlugin = require('./webpack-protect-bootstrap-plugin');
 const projectConfig = require('./plaid.conf');
+const { getVersion } = require('./version-helper');
 const mergedConfig = shallowMerge(defaultOptions, projectConfig);
 
 // Avoiding collisions with globals of a content-mode userscript
@@ -14,7 +15,7 @@ const INIT_FUNC_NAME = `Violentmonkey:${getUniqIdB64()}`;
 const VAULT_ID = '__VAULT_ID__';
 const HANDSHAKE_ID = '__HANDSHAKE_ID__';
 // eslint-disable-next-line import/no-dynamic-require
-const VM_VER = require(`${defaultOptions.distDir}/manifest.json`).version;
+const VM_VER = getVersion();
 const WEBPACK_OPTS = {
   node: {
     global: false,