refactor(polyfill): replace `webextension-polyfill` with simple `browser` fallback to `chrome`

This commit is contained in:
Thomas Rupprecht 2024-02-24 17:24:43 +01:00
parent 923a906a9e
commit 8023167072
9 changed files with 9 additions and 33 deletions

1
.gitignore vendored
View File

@ -1,2 +1 @@
/web-ext-artifacts
src/browser-polyfill.js

View File

@ -31,6 +31,7 @@ All notable changes to this project will be documented in this file.
- Update dependencies
- Update dependencies
- Update `husky`
- Update dependencies
### ✳️ Other

View File

@ -43,10 +43,7 @@ Example: `npm run watch:firefox-android -- --firefox-apk=org.mozilla.fenix --fir
## Build
```ssh
// For Firefox
$ npm run build:firefox
// For Chromium
$ npm run build:chromium
$ npm run build
```
## Release

View File

@ -20,8 +20,7 @@
},
"excludes": [
"**/node_modules",
"**/*-lock.json",
"src/browser-polyfill.js"
"**/*-lock.json"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.88.7.wasm",

View File

@ -7,7 +7,6 @@ const noUnsanitized = require('eslint-plugin-no-unsanitized');
module.exports = [
{
files: ['**/*.js'],
ignores: ['src/browser-polyfill.js'],
languageOptions: {
globals: {
...globals.browser,

9
package-lock.json generated
View File

@ -7,11 +7,7 @@
"": {
"name": "usrspace-browser-addon",
"version": "0.9.5",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
"webextension-polyfill": "^0.10.0"
},
"devDependencies": {
"@commitlint/cli": "^18.6.0",
"@commitlint/config-conventional": "^18.6.0",
@ -8809,11 +8805,6 @@
"node": ">= 8"
}
},
"node_modules/webextension-polyfill": {
"version": "0.10.0",
"resolved": "https://registry.npmjs.org/webextension-polyfill/-/webextension-polyfill-0.10.0.tgz",
"integrity": "sha512-c5s35LgVa5tFaHhrZDnr3FpQpjj1BB+RXhLTYUxGqBVN460HkbM8TBtEqdXWbpTKfzwCcjAZVF7zXCYSKtcp9g=="
},
"node_modules/webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",

View File

@ -2,9 +2,6 @@
"name": "usrspace-browser-addon",
"description": "WebExtension for the Hacker-/Maker-Space /usr/space",
"version": "0.9.5",
"dependencies": {
"webextension-polyfill": "^0.10.0"
},
"devDependencies": {
"@commitlint/cli": "^18.6.0",
"@commitlint/config-conventional": "^18.6.0",
@ -25,9 +22,6 @@
"web-ext": "^7.11.0"
},
"scripts": {
"copy-browser-polyfill": "cp node_modules/webextension-polyfill/dist/browser-polyfill.js src/browser-polyfill.js",
"inject-browser-polyfill": "sed -i -r \"s#// \\[INJECT-BROWSER-POLYFILL]#import '\\./browser-polyfill\\.js';#\" src/*.js",
"uninject-browser-polyfill": "sed -i -r \"s#import '\\./browser-polyfill\\.js';#// \\[INJECT-BROWSER-POLYFILL]#\" src/*.js",
"copy-version": "sed -i 's/^\t\"version\": \".*\",$/\t\"version\": \"'$(rg '^\t\"version\": \"(.+)\",$' -r '$1' < package.json)'\",/' src/manifest.json",
"update-changelog": "npm exec git-cliff > CHANGELOG.md",
"lint": "npm run lint:web-ext && npm run lint:js && npm run lint:css",
@ -42,17 +36,11 @@
"watch:firefox-android": "web-ext run -t firefox-android",
"watch:chromium": "web-ext run -t chromium",
"prebuild": "cp LICENSE.txt src/",
"prebuild:firefox": "npm run prebuild",
"prebuild:chromium": "npm run prebuild && npm run inject-browser-polyfill",
"build:firefox": "web-ext build -i browser-polyfill.js",
"build:chromium": "web-ext build",
"build": "web-ext build",
"postbuild": "rm src/LICENSE.txt",
"postbuild:firefox": "npm run postbuild",
"postbuild:chromium": "npm run postbuild && npm run uninject-browser-polyfill",
"postinstall": "npm run copy-browser-polyfill",
"preversion": "npm run fmt:check && npm run lint && npm test",
"version": "npm run copy-version && npm run update-changelog && git add CHANGELOG.md src/manifest.json",
"postversion": "npm run build:firefox",
"postversion": "npm run build",
"prepare": "husky",
"commit": "git-cz"
},

View File

@ -1,5 +1,6 @@
import { REFRESH_TIMEOUT, HOMEPAGE, API_URLS, BADGE_COLORS } from './config.js';
// [INJECT-BROWSER-POLYFILL]
globalThis.browser ??= chrome;
browser.runtime.onInstalled.addListener(async (details) => {
init();

View File

@ -1,5 +1,6 @@
import { QUICK_LINKS } from './config.js';
// [INJECT-BROWSER-POLYFILL]
globalThis.browser ??= chrome;
const dateTimeFormat = Intl.DateTimeFormat([], { dateStyle: 'medium', timeStyle: 'short' });