Skip to content

Commit 7f9b35b

Browse files
committed
Automatically update manifest version on 'npm version'
1 parent a648fc2 commit 7f9b35b

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

esbuild.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
const path = require('path');
7+
const fs = require('fs/promises');
8+
69
const esbuild = require("esbuild");
710
const { clean } = require('esbuild-plugin-clean');
811

912
const { NodeModulesPolyfillPlugin } = require('@esbuild-plugins/node-modules-polyfill');
1013
const { NodeGlobalsPolyfillPlugin } = require('@esbuild-plugins/node-globals-polyfill');
1114

15+
const manifest = require('./public/manifest.json');
16+
const packageJson = require('./package.json');
17+
1218
(async () => {
19+
manifest.version = packageJson.version; // Usually no-op, except during 'npm version'
20+
await fs.writeFile(path.join('.', 'public', 'manifest.json'), JSON.stringify(manifest, null, 4));
21+
1322
const result = await esbuild.build({
1423
entryPoints: [
1524
"./src/background.ts",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"build": "node ./esbuild.js && mkdir -p public/config/",
8+
"version": "npm run build && git add public/manifest.json",
89
"ts-check": "tsc --noEmit",
910
"test": "npm run ts-check",
1011
"start:dev": "node-dev ./start-dev-server.js & DEV_MODE=true npm run build"

public/manifest.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@
2121
],
2222
"web_accessible_resources": [
2323
{
24-
"resources": ["build/injected-script.js"],
25-
"matches": ["<all_urls>"]
24+
"resources": [
25+
"build/injected-script.js"
26+
],
27+
"matches": [
28+
"<all_urls>"
29+
]
2630
}
2731
]
2832
}

0 commit comments

Comments
 (0)