Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f9cd7aaf05 | |||
| 9049804413 | |||
| d027a496f5 | |||
| dd7abddb7c | |||
| 98d2792e02 | |||
| 39b76d3ec0 | |||
| bc29bfd434 | |||
| 5e60f37ec5 | |||
| 6f901b32eb | |||
| 927aca612e | |||
| 2dcdae91eb | |||
| eb758bdeb8 | |||
| 5acf51af9d | |||
| f9718a1b71 |
@@ -1,5 +1,70 @@
|
||||
# Changelog
|
||||
|
||||
## v0.15.1
|
||||
|
||||
[compare changes](https://github.com/wxt-dev/wxt/compare/v0.15.0...v0.15.1)
|
||||
|
||||
### 🚀 Enhancements
|
||||
|
||||
- Allow passing custom preferences to chrome, enabling dev mode on `chrome://extensions` and allowing content script sourcemaps automatically ([#384](https://github.com/wxt-dev/wxt/pull/384))
|
||||
|
||||
### 🩹 Fixes
|
||||
|
||||
- **security:** Upgrade to vite@5.0.12 to resolve CVE-2024-23331 ([39b76d3](https://github.com/wxt-dev/wxt/commit/39b76d3))
|
||||
|
||||
### 📖 Documentation
|
||||
|
||||
- Fixed doc errors on the guide/extension-api page ([#383](https://github.com/wxt-dev/wxt/pull/383))
|
||||
|
||||
### 🏡 Chore
|
||||
|
||||
- Fix vite version conflicts in demo extension ([98d2792](https://github.com/wxt-dev/wxt/commit/98d2792))
|
||||
|
||||
### ❤️ Contributors
|
||||
|
||||
- 0x7a7a <298164449@qq.com>
|
||||
|
||||
## v0.15.0
|
||||
|
||||
[compare changes](https://github.com/wxt-dev/wxt/compare/v0.14.7...v0.15.0)
|
||||
|
||||
### 🚀 Enhancements
|
||||
|
||||
- **zip:** ⚠️ Add `includeSources` and rename `ignoredSources` to `excludeSources` ([#378](https://github.com/wxt-dev/wxt/pull/378))
|
||||
|
||||
### 🩹 Fixes
|
||||
|
||||
- Generate missing sourcemap in `wxt:unimport` plugin ([#381](https://github.com/wxt-dev/wxt/pull/381))
|
||||
- ⚠️ Move browser constants to `import.meta.env` ([#380](https://github.com/wxt-dev/wxt/pull/380))
|
||||
- Enable inline sourcemaps by default during development ([#382](https://github.com/wxt-dev/wxt/pull/382))
|
||||
|
||||
### 📖 Documentation
|
||||
|
||||
- Fix typo ([f9718a1](https://github.com/wxt-dev/wxt/commit/f9718a1))
|
||||
|
||||
### 🏡 Chore
|
||||
|
||||
- Update contributor docs ([eb758bd](https://github.com/wxt-dev/wxt/commit/eb758bd))
|
||||
|
||||
#### ⚠️ Breaking Changes
|
||||
|
||||
Renamed `zip.ignoredSources` to `zip.excludeSources` in [#378](https://github.com/wxt-dev/wxt/pull/378)
|
||||
|
||||
Renamed undocumented constants for detecting the build config at runtime in [#380](https://github.com/wxt-dev/wxt/pull/380). Now documented here: https://wxt.dev/guide/multiple-browsers.html#runtime
|
||||
|
||||
- `__BROWSER__` → `import.meta.env.BROWSER`
|
||||
- `__COMMAND__` → `import.meta.env.COMMAND`
|
||||
- `__MANIFEST_VERSION__` → `import.meta.env.MANIFEST_VERSION`
|
||||
- `__IS_CHROME__` → `import.meta.env.CHROME`
|
||||
- `__IS_FIREFOX__` → `import.meta.env.FIREFOX`
|
||||
- `__IS_SAFARI__` → `import.meta.env.SAFARI`
|
||||
- `__IS_EDGE__` → `import.meta.env.EDGE`
|
||||
- `__IS_OPERA__` → `import.meta.env.OPERA`
|
||||
|
||||
### ❤️ Contributors
|
||||
|
||||
- Nenad Novaković ([@dvlden](https://github.com/dvlden))
|
||||
|
||||
## v0.14.7
|
||||
|
||||
[compare changes](https://github.com/wxt-dev/wxt/compare/v0.14.6...v0.14.7)
|
||||
|
||||
+9
-1
@@ -57,9 +57,17 @@ pnpm test
|
||||
pnpm docs:dev
|
||||
```
|
||||
|
||||
## Updating Docs
|
||||
|
||||
Documentation is written with VitePress, and is located in the `docs/` directory.
|
||||
|
||||
The API reference is generated from JSDoc comments in the source code. If there's a typo or change you want to make in there, you'll need to update the source code instead of a file in the `docs/` directory.
|
||||
|
||||
## Testing
|
||||
|
||||
WXT has unit and E2E tests. When making a change or adding a feature, make sure to update the tests or add new ones.
|
||||
WXT has unit and E2E tests. When making a change or adding a feature, make sure to update the tests or add new ones, if they exist.
|
||||
|
||||
> If they don't exist, feel free to create them, but that's a lot for a one-time contributor. A maintainer might add them to your PR though.
|
||||
|
||||
To run tests for a specific file, add the filename at the end of the test command:
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ export default defineBackground(() => {
|
||||
console.log(browser.runtime.id);
|
||||
logId();
|
||||
console.log({
|
||||
browser: __BROWSER__,
|
||||
chrome: __IS_CHROME__,
|
||||
firefox: __IS_FIREFOX__,
|
||||
manifestVersion: __MANIFEST_VERSION__,
|
||||
browser: import.meta.env.BROWSER,
|
||||
chrome: import.meta.env.CHROME,
|
||||
firefox: import.meta.env.FIREFOX,
|
||||
manifestVersion: import.meta.env.MANIFEST_VERSION,
|
||||
messages,
|
||||
});
|
||||
|
||||
|
||||
@@ -57,21 +57,19 @@ Here's a basic request/response example:
|
||||
// popup/main.ts
|
||||
const res = await browser.runtime.sendMessage('ping');
|
||||
|
||||
console.log('res'); // "pong"
|
||||
console.log(res); // "pong"
|
||||
```
|
||||
|
||||
```ts
|
||||
// background.ts
|
||||
export default defineBackground(() => {
|
||||
browser.runtime.onMessage.addEventListener(
|
||||
(message, sender, sendResponse) => {
|
||||
console.log(message); // "ping"
|
||||
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
console.log(message); // "ping"
|
||||
|
||||
// Wait 1 second and respond with "pong"
|
||||
setTimeout(() => sendResponse('pong'), 1000);
|
||||
return true;
|
||||
},
|
||||
);
|
||||
// Wait 1 second and respond with "pong"
|
||||
setTimeout(() => sendResponse('pong'), 1000);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
@@ -115,19 +115,19 @@ Only `defineBackground` and `defineContentScript` support per-browser options ri
|
||||
|
||||
To determine the browser or manifest version at runtime, you can use any of the below variables:
|
||||
|
||||
- `__BROWSER__`: A string, the target browser, usually equal to the `--browser` flag
|
||||
- `__MANIFEST_VERSION__`: A number, either `2` or `3`, depending on the manifest version targetted
|
||||
- `__IS_CHROME__`: A boolean equivalent to `__BROWSER__ === "chrome"`
|
||||
- `__IS_FIREFOX__`: A boolean equivalent to `__BROWSER__ === "firefox"`
|
||||
- `__IS_EDGE__`: A boolean equivalent to `__BROWSER__ === "edge"`
|
||||
- `__IS_SAFARI__`: A boolean equivalent to `__BROWSER__ === "safari"`
|
||||
- `__IS_OPERA__`: A boolean equivalent to `__BROWSER__ === "opera"`
|
||||
- `__COMMAND__`: A string, `"serve"` when running `wxt` for development or `"build"` in all other cases.
|
||||
- `import.meta.env.BROWSER`: A string, the target browser, usually equal to the `--browser` flag
|
||||
- `import.meta.env.MANIFEST_VERSION`: A number, either `2` or `3`, depending on the manifest version targetted
|
||||
- `import.meta.env.CHROME`: A boolean equivalent to `import.meta.env.BROWSER === "chrome"`
|
||||
- `import.meta.env.FIREFOX`: A boolean equivalent to `import.meta.env.BROWSER === "firefox"`
|
||||
- `import.meta.env.EDGE`: A boolean equivalent to `import.meta.env.BROWSER === "edge"`
|
||||
- `import.meta.env.SAFARI`: A boolean equivalent to `import.meta.env.BROWSER === "safari"`
|
||||
- `import.meta.env.OPERA`: A boolean equivalent to `import.meta.env.BROWSER === "opera"`
|
||||
- `import.meta.env.COMMAND`: A string, `"serve"` when running `wxt` for development or `"build"` in all other cases.
|
||||
|
||||
:::info
|
||||
These variables are constants defined at build time based on the build target. They do not actually detect which browser the code is running in.
|
||||
|
||||
For example, if you build for `--browser chrome` and publish it on Edge, `__BROWSER__` will be `"chrome"`, not `"edge"`. You have to build a separate ZIP for `--browser edge` before `__BROWSER__` will be `"edge"`.
|
||||
For example, if you build for `--browser chrome` and publish it on Edge, `import.meta.env.BROWSER` will be `"chrome"`, not `"edge"`. You have to build a separate ZIP for `--browser edge` before `import.meta.env.BROWSER` will be `"edge"`.
|
||||
|
||||
If you need to know the actual browser your code is being ran on, you should use a [user agent parser](https://www.npmjs.com/package/ua-parser-js).
|
||||
:::
|
||||
|
||||
@@ -19,7 +19,7 @@ If you want to try to use a different framework for unit tests, you will need to
|
||||
- **Auto-imports**: Add `unimport` to your test environment or disable them by setting `imports: false` in your `wxt.config.ts` file
|
||||
- **`browser` mock**: Mock the `webextension-polyfill` module globally with `wxt/dist/virtual/mock-browser.js`
|
||||
- **[Remote Code Bundling](/guide/remote-code)**: If you use it, configure your environment to handle the `url:` module prefix
|
||||
- **Global Variables**: If you consume them, manually define globals provided by WXT (like `__BROWSER__`) by adding them to the global scope before accessing them (`globalThis.__BROWSER__ = "chrome"`)
|
||||
- **Global Variables**: If you consume them, manually define globals provided by WXT (like `import.meta.env.BROWSER`) by adding them to the global scope before accessing them (`import.meta.env.BROWSER = "chrome"`)
|
||||
- **Import paths**: If you use the `@/` or `~/` path aliases, add them to your test environment
|
||||
|
||||
[Here's how Vitest is configured](https://github.com/wxt-dev/wxt/blob/main/src/testing/wxt-vitest-plugin.ts) for reference.
|
||||
|
||||
@@ -14,16 +14,19 @@ describe('TypeScript Project', () => {
|
||||
----------------------------------------
|
||||
// Generated by wxt
|
||||
export {}
|
||||
declare global {
|
||||
const __MANIFEST_VERSION__: 2 | 3;
|
||||
const __BROWSER__: string;
|
||||
const __IS_CHROME__: boolean;
|
||||
const __IS_FIREFOX__: boolean;
|
||||
const __IS_SAFARI__: boolean;
|
||||
const __IS_EDGE__: boolean;
|
||||
const __IS_OPERA__: boolean;
|
||||
const __COMMAND__: "build" | "serve";
|
||||
const __ENTRYPOINT__: string;
|
||||
interface ImportMetaEnv {
|
||||
readonly MANIFEST_VERSION: 2 | 3;
|
||||
readonly BROWSER: string;
|
||||
readonly CHROME: boolean;
|
||||
readonly FIREFOX: boolean;
|
||||
readonly SAFARI: boolean;
|
||||
readonly EDGE: boolean;
|
||||
readonly OPERA: boolean;
|
||||
readonly COMMAND: "build" | "serve";
|
||||
readonly ENTRYPOINT: string;
|
||||
}
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv
|
||||
}
|
||||
"
|
||||
`);
|
||||
@@ -133,7 +136,7 @@ describe('TypeScript Project', () => {
|
||||
options?: GetMessageOptions,
|
||||
): string;
|
||||
/**
|
||||
*
|
||||
* No message description.
|
||||
*
|
||||
* "<browser.i18n.getUiLocale()>"
|
||||
*/
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "wxt",
|
||||
"type": "module",
|
||||
"version": "0.14.7",
|
||||
"version": "0.15.1",
|
||||
"description": "Next gen framework for developing web extensions",
|
||||
"engines": {
|
||||
"node": ">=18",
|
||||
@@ -134,8 +134,8 @@
|
||||
"prompts": "^2.4.2",
|
||||
"rollup-plugin-visualizer": "^5.9.2",
|
||||
"unimport": "^3.4.0",
|
||||
"vite": "^5.0.0",
|
||||
"web-ext-run": "^0.1.2",
|
||||
"vite": "^5.0.12",
|
||||
"web-ext-run": "^0.2.0",
|
||||
"webextension-polyfill": "^0.10.0",
|
||||
"zip-dir": "^2.0.0"
|
||||
},
|
||||
|
||||
Generated
+46
-56
@@ -102,11 +102,11 @@ importers:
|
||||
specifier: ^3.4.0
|
||||
version: 3.4.0
|
||||
vite:
|
||||
specifier: ^5.0.0
|
||||
version: 5.0.5(@types/node@20.10.3)(sass@1.69.5)
|
||||
specifier: ^5.0.12
|
||||
version: 5.0.12(@types/node@20.10.3)(sass@1.69.5)
|
||||
web-ext-run:
|
||||
specifier: ^0.1.2
|
||||
version: 0.1.2
|
||||
specifier: ^0.2.0
|
||||
version: 0.2.0
|
||||
webextension-polyfill:
|
||||
specifier: ^0.10.0
|
||||
version: 0.10.0
|
||||
@@ -1165,14 +1165,14 @@ packages:
|
||||
resolution: {integrity: sha512-LlmbFLUB7+BDrb9nMuM0wlqtx9LZbBV2x3W98o02cD7Y8i10+sBenTlhG56vr47dzC7WIVXbURii+5jMJsyjLw==}
|
||||
dev: false
|
||||
|
||||
/@vitejs/plugin-vue@5.0.2(vite@5.0.10)(vue@3.4.3):
|
||||
/@vitejs/plugin-vue@5.0.2(vite@5.0.12)(vue@3.4.3):
|
||||
resolution: {integrity: sha512-kEjJHrLb5ePBvjD0SPZwJlw1QTRcjjCA9sB5VyfonoXVBxTS7TMnqL6EkLt1Eu61RDeiuZ/WN9Hf6PxXhPI2uA==}
|
||||
engines: {node: ^18.0.0 || >=20.0.0}
|
||||
peerDependencies:
|
||||
vite: ^5.0.0
|
||||
vue: ^3.2.25
|
||||
dependencies:
|
||||
vite: 5.0.10(@types/node@20.10.3)
|
||||
vite: 5.0.12(@types/node@20.10.3)(sass@1.69.5)
|
||||
vue: 3.4.3(typescript@5.3.2)
|
||||
dev: true
|
||||
|
||||
@@ -1815,15 +1815,15 @@ packages:
|
||||
engines: {node: '>=10'}
|
||||
dev: false
|
||||
|
||||
/chrome-launcher@0.15.1:
|
||||
resolution: {integrity: sha512-UugC8u59/w2AyX5sHLZUHoxBAiSiunUhZa3zZwMH6zPVis0C3dDKiRWyUGIo14tTbZHGVviWxv3PQWZ7taZ4fg==}
|
||||
/chrome-launcher@1.1.0:
|
||||
resolution: {integrity: sha512-rJYWeEAERwWIr3c3mEVXwNiODPEdMRlRxHc47B1qHPOolHZnkj7rMv1QSUfPoG6MgatWj5AxSpnKKR4QEwEQIQ==}
|
||||
engines: {node: '>=12.13.0'}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
'@types/node': 20.10.3
|
||||
escape-string-regexp: 4.0.0
|
||||
is-wsl: 2.2.0
|
||||
lighthouse-logger: 1.4.2
|
||||
lighthouse-logger: 2.0.1
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: false
|
||||
@@ -2993,6 +2993,18 @@ packages:
|
||||
engines: {node: '>=8'}
|
||||
dev: false
|
||||
|
||||
/is-plain-object@2.0.4:
|
||||
resolution: {integrity: sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
dependencies:
|
||||
isobject: 3.0.1
|
||||
dev: false
|
||||
|
||||
/is-primitive@3.0.1:
|
||||
resolution: {integrity: sha512-GljRxhWvlCNRfZyORiH77FwdFwGcMO620o37EOYC0ORWdq+WYNVqW0w2Juzew4M+L81l6/QS3t5gkkihyRqv9w==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
dev: false
|
||||
|
||||
/is-regex@1.1.4:
|
||||
resolution: {integrity: sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@@ -3091,6 +3103,11 @@ packages:
|
||||
/isexe@2.0.0:
|
||||
resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==}
|
||||
|
||||
/isobject@3.0.1:
|
||||
resolution: {integrity: sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
dev: false
|
||||
|
||||
/istanbul-lib-coverage@3.2.2:
|
||||
resolution: {integrity: sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==}
|
||||
engines: {node: '>=8'}
|
||||
@@ -3200,8 +3217,8 @@ packages:
|
||||
immediate: 3.0.6
|
||||
dev: false
|
||||
|
||||
/lighthouse-logger@1.4.2:
|
||||
resolution: {integrity: sha512-gPWxznF6TKmUHrOQjlVo2UbaL2EJ71mb2CCeRs/2qBpi4L/g4LUVc9+3lKQ6DTUZwJswfM7ainGrLO1+fOqa2g==}
|
||||
/lighthouse-logger@2.0.1:
|
||||
resolution: {integrity: sha512-ioBrW3s2i97noEmnXxmUq7cjIcVRjT5HBpAYy8zE11CxU9HqlWHHeRxfeN1tn8F7OEMVPIC9x1f8t3Z7US9ehQ==}
|
||||
dependencies:
|
||||
debug: 2.6.9
|
||||
marky: 1.2.5
|
||||
@@ -4242,6 +4259,14 @@ packages:
|
||||
dependencies:
|
||||
lru-cache: 6.0.0
|
||||
|
||||
/set-value@4.1.0:
|
||||
resolution: {integrity: sha512-zTEg4HL0RwVrqcWs3ztF+x1vkxfm0lP+MQQFPiMJTKVceBwEV0A569Ou8l9IYQG8jOZdMVI1hGsc0tmeD2o/Lw==}
|
||||
engines: {node: '>=11.0'}
|
||||
dependencies:
|
||||
is-plain-object: 2.0.4
|
||||
is-primitive: 3.0.1
|
||||
dev: false
|
||||
|
||||
/setimmediate@1.0.5:
|
||||
resolution: {integrity: sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==}
|
||||
dev: false
|
||||
@@ -4925,7 +4950,7 @@ packages:
|
||||
debug: 4.3.4
|
||||
pathe: 1.1.1
|
||||
picocolors: 1.0.0
|
||||
vite: 5.0.5(@types/node@20.10.3)(sass@1.69.5)
|
||||
vite: 5.0.12(@types/node@20.10.3)(sass@1.69.5)
|
||||
transitivePeerDependencies:
|
||||
- '@types/node'
|
||||
- less
|
||||
@@ -4936,44 +4961,8 @@ packages:
|
||||
- supports-color
|
||||
- terser
|
||||
|
||||
/vite@5.0.10(@types/node@20.10.3):
|
||||
resolution: {integrity: sha512-2P8J7WWgmc355HUMlFrwofacvr98DAjoE52BfdbwQtyLH06XKwaL/FMnmKM2crF0iX4MpmMKoDlNCB1ok7zHCw==}
|
||||
engines: {node: ^18.0.0 || >=20.0.0}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
'@types/node': ^18.0.0 || >=20.0.0
|
||||
less: '*'
|
||||
lightningcss: ^1.21.0
|
||||
sass: '*'
|
||||
stylus: '*'
|
||||
sugarss: '*'
|
||||
terser: ^5.4.0
|
||||
peerDependenciesMeta:
|
||||
'@types/node':
|
||||
optional: true
|
||||
less:
|
||||
optional: true
|
||||
lightningcss:
|
||||
optional: true
|
||||
sass:
|
||||
optional: true
|
||||
stylus:
|
||||
optional: true
|
||||
sugarss:
|
||||
optional: true
|
||||
terser:
|
||||
optional: true
|
||||
dependencies:
|
||||
'@types/node': 20.10.3
|
||||
esbuild: 0.19.8
|
||||
postcss: 8.4.32
|
||||
rollup: 4.6.1
|
||||
optionalDependencies:
|
||||
fsevents: 2.3.3
|
||||
dev: true
|
||||
|
||||
/vite@5.0.5(@types/node@20.10.3)(sass@1.69.5):
|
||||
resolution: {integrity: sha512-OekeWqR9Ls56f3zd4CaxzbbS11gqYkEiBtnWFFgYR2WV8oPJRRKq0mpskYy/XaoCL3L7VINDhqqOMNDiYdGvGg==}
|
||||
/vite@5.0.12(@types/node@20.10.3)(sass@1.69.5):
|
||||
resolution: {integrity: sha512-4hsnEkG3q0N4Tzf1+t6NdN9dg/L3BM+q8SWgbSPnJvrgH2kgdyzfVJwbR1ic69/4uMJJ/3dqDZZE5/WwqW8U1w==}
|
||||
engines: {node: ^18.0.0 || >=20.0.0}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
@@ -5023,7 +5012,7 @@ packages:
|
||||
'@docsearch/css': 3.5.2
|
||||
'@docsearch/js': 3.5.2
|
||||
'@types/markdown-it': 13.0.7
|
||||
'@vitejs/plugin-vue': 5.0.2(vite@5.0.10)(vue@3.4.3)
|
||||
'@vitejs/plugin-vue': 5.0.2(vite@5.0.12)(vue@3.4.3)
|
||||
'@vue/devtools-api': 6.5.1
|
||||
'@vueuse/core': 10.7.1(vue@3.4.3)
|
||||
'@vueuse/integrations': 10.7.1(focus-trap@7.5.4)(vue@3.4.3)
|
||||
@@ -5034,7 +5023,7 @@ packages:
|
||||
shikiji: 0.9.16
|
||||
shikiji-core: 0.9.16
|
||||
shikiji-transformers: 0.9.16
|
||||
vite: 5.0.10(@types/node@20.10.3)
|
||||
vite: 5.0.12(@types/node@20.10.3)(sass@1.69.5)
|
||||
vue: 3.4.3(typescript@5.3.2)
|
||||
transitivePeerDependencies:
|
||||
- '@algolia/client-search'
|
||||
@@ -5120,7 +5109,7 @@ packages:
|
||||
strip-literal: 1.3.0
|
||||
tinybench: 2.5.1
|
||||
tinypool: 0.8.1
|
||||
vite: 5.0.5(@types/node@20.10.3)(sass@1.69.5)
|
||||
vite: 5.0.12(@types/node@20.10.3)(sass@1.69.5)
|
||||
vite-node: 1.1.0(@types/node@20.10.3)(sass@1.69.5)
|
||||
why-is-node-running: 2.2.2
|
||||
transitivePeerDependencies:
|
||||
@@ -5195,14 +5184,14 @@ packages:
|
||||
graceful-fs: 4.2.11
|
||||
dev: false
|
||||
|
||||
/web-ext-run@0.1.2:
|
||||
resolution: {integrity: sha512-VygO7lg10keonbku5Lbi21zEz1k91odkW+c6YB5DGb+mITcRMVM2zr/tJ+Suh6wxNUOOFNbinoqDlSUWdxt6YQ==}
|
||||
/web-ext-run@0.2.0:
|
||||
resolution: {integrity: sha512-lAm05ELMr2WDPniyaHmyuPK0rb9tsftC8f/Ui5AQvlU6F3LqoBDfyzOaaUVQrLxtm4F5oax8AHPWswf/XjZzAg==}
|
||||
engines: {node: '>=18.0.0', npm: '>=8.0.0'}
|
||||
dependencies:
|
||||
'@babel/runtime': 7.23.9
|
||||
'@devicefarmer/adbkit': 3.2.6
|
||||
bunyan: 1.8.15
|
||||
chrome-launcher: 0.15.1
|
||||
chrome-launcher: 1.1.0
|
||||
debounce: 1.2.1
|
||||
es6-error: 4.1.1
|
||||
firefox-profile: 4.5.0
|
||||
@@ -5214,6 +5203,7 @@ packages:
|
||||
node-notifier: 10.0.1
|
||||
parse-json: 7.1.1
|
||||
promise-toolbox: 0.21.0
|
||||
set-value: 4.1.0
|
||||
source-map-support: 0.5.21
|
||||
strip-bom: 5.0.0
|
||||
strip-json-comments: 5.0.1
|
||||
|
||||
@@ -15,10 +15,12 @@ export class WxtLocationChangeEvent extends Event {
|
||||
* Returns an event name unique to the extension and content script that's running.
|
||||
*/
|
||||
export function getUniqueEventName(eventName: string): string {
|
||||
// During the build process, __ENTRYPOINT__ is not defined when importing entrypoints to get their
|
||||
// metadata.
|
||||
// During the build process, import.meta.env is not defined when importing
|
||||
// entrypoints to get their metadata.
|
||||
const entrypointName =
|
||||
typeof __ENTRYPOINT__ === 'undefined' ? 'build' : __ENTRYPOINT__;
|
||||
typeof import.meta.env === 'undefined'
|
||||
? 'build'
|
||||
: import.meta.env.ENTRYPOINT;
|
||||
|
||||
return `${browser.runtime.id}:${entrypointName}:${eventName}`;
|
||||
}
|
||||
|
||||
@@ -236,7 +236,9 @@ function mountUi(
|
||||
* Load the CSS for the current entrypoint.
|
||||
*/
|
||||
async function loadCss(): Promise<string> {
|
||||
const url = browser.runtime.getURL(`/content-scripts/${__ENTRYPOINT__}.css`);
|
||||
const url = browser.runtime.getURL(
|
||||
`/content-scripts/${import.meta.env.ENTRYPOINT}.css`,
|
||||
);
|
||||
try {
|
||||
const res = await fetch(url);
|
||||
return await res.text();
|
||||
|
||||
@@ -44,6 +44,10 @@ export async function createViteBuilder(
|
||||
if (config.build.minify == null && wxtConfig.command === 'serve') {
|
||||
config.build.minify = false;
|
||||
}
|
||||
// Enable inline sourcemaps for the dev command (so content scripts have sourcemaps)
|
||||
if (config.build.sourcemap == null && wxtConfig.command === 'serve') {
|
||||
config.build.sourcemap = 'inline';
|
||||
}
|
||||
|
||||
config.plugins ??= [];
|
||||
config.plugins.push(
|
||||
|
||||
@@ -14,7 +14,7 @@ export function entrypointGroupGlobals(
|
||||
const define: vite.InlineConfig['define'] = {};
|
||||
let name = Array.isArray(entrypointGroup) ? 'html' : entrypointGroup.name;
|
||||
for (const global of getEntrypointGlobals(name)) {
|
||||
define[global.name] = JSON.stringify(global.value);
|
||||
define[`import.meta.env.${global.name}`] = JSON.stringify(global.value);
|
||||
}
|
||||
return {
|
||||
define,
|
||||
|
||||
@@ -10,7 +10,7 @@ export function globals(
|
||||
config() {
|
||||
const define: vite.InlineConfig['define'] = {};
|
||||
for (const global of getGlobals(config)) {
|
||||
define[global.name] = JSON.stringify(global.value);
|
||||
define[`import.meta.env.${global.name}`] = JSON.stringify(global.value);
|
||||
}
|
||||
return {
|
||||
define,
|
||||
|
||||
@@ -36,7 +36,11 @@ export function unimport(
|
||||
// Don't transform non-js files
|
||||
if (!ENABLED_EXTENSIONS.has(extname(id))) return;
|
||||
|
||||
return unimport.injectImports(code, id);
|
||||
const injected = await unimport.injectImports(code, id);
|
||||
return {
|
||||
code: injected.code,
|
||||
map: injected.s.generateMap({ hires: 'boundary', source: id }),
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { WebExtRunInstance } from 'web-ext-run';
|
||||
import { ExtensionRunner } from '~/types';
|
||||
import { formatDuration } from '../utils/time';
|
||||
import defu from 'defu';
|
||||
|
||||
/**
|
||||
* Create an `ExtensionRunner` backed by `web-ext`.
|
||||
@@ -40,6 +41,10 @@ export function createWebExtRunner(): ExtensionRunner {
|
||||
: {
|
||||
chromiumBinary: wxtUserConfig?.binaries?.[config.browser],
|
||||
chromiumProfile: wxtUserConfig?.chromiumProfile,
|
||||
chromiumPref: defu(
|
||||
wxtUserConfig?.chromiumPref,
|
||||
DEFAULT_CHROMIUM_PREFS,
|
||||
),
|
||||
args: wxtUserConfig?.chromiumArgs,
|
||||
}),
|
||||
};
|
||||
@@ -75,3 +80,14 @@ export function createWebExtRunner(): ExtensionRunner {
|
||||
// https://github.com/mozilla/web-ext/blob/e37e60a2738478f512f1255c537133321f301771/src/util/logger.js#L12
|
||||
const WARN_LOG_LEVEL = 40;
|
||||
const ERROR_LOG_LEVEL = 50;
|
||||
|
||||
const DEFAULT_CHROMIUM_PREFS = {
|
||||
devtools: {
|
||||
synced_preferences_sync_disabled: {
|
||||
// Remove content scripts from sourcemap debugger ignore list so stack traces
|
||||
// and log locations show up properly, see:
|
||||
// https://github.com/wxt-dev/wxt/issues/236#issuecomment-1915364520
|
||||
skipContentScripts: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -136,7 +136,7 @@ declare module "wxt/browser" {
|
||||
|
||||
const overrides = messages.map((message) => {
|
||||
return ` /**
|
||||
* ${message.description ?? 'No message description.'}
|
||||
* ${message.description || 'No message description.'}
|
||||
*
|
||||
* "${message.message}"
|
||||
*/
|
||||
@@ -164,8 +164,11 @@ async function writeGlobalsDeclarationFile(
|
||||
[
|
||||
'// Generated by wxt',
|
||||
'export {}',
|
||||
'declare global {',
|
||||
...globals.map((global) => ` const ${global.name}: ${global.type};`),
|
||||
'interface ImportMetaEnv {',
|
||||
...globals.map((global) => ` readonly ${global.name}: ${global.type};`),
|
||||
'}',
|
||||
'interface ImportMeta {',
|
||||
' readonly env: ImportMetaEnv',
|
||||
'}',
|
||||
].join('\n') + '\n',
|
||||
);
|
||||
|
||||
@@ -241,8 +241,9 @@ function resolveInternalZipConfig(
|
||||
sourcesTemplate: '{{name}}-{{version}}-sources.zip',
|
||||
artifactTemplate: '{{name}}-{{version}}-{{browser}}.zip',
|
||||
sourcesRoot: root,
|
||||
includeSources: [],
|
||||
...mergedConfig.zip,
|
||||
ignoredSources: [
|
||||
excludeSources: [
|
||||
'**/node_modules',
|
||||
// WXT files
|
||||
'**/web-ext.config.ts',
|
||||
@@ -252,7 +253,7 @@ function resolveInternalZipConfig(
|
||||
'**/__tests__/**',
|
||||
'**/*.+(test|spec).?(c|m)+(j|t)s?(x)',
|
||||
// From user
|
||||
...(mergedConfig.zip?.ignoredSources ?? []),
|
||||
...(mergedConfig.zip?.excludeSources ?? []),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ export async function importEntrypointFile<T>(
|
||||
{ cause: err },
|
||||
);
|
||||
} else {
|
||||
config.logger.error(err);
|
||||
throw Error(`Failed to load entrypoint: ${filePath}`, { cause: err });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,42 +5,42 @@ export function getGlobals(
|
||||
): Array<{ name: string; value: any; type: string }> {
|
||||
return [
|
||||
{
|
||||
name: surroundInUnderscore('MANIFEST_VERSION'),
|
||||
name: 'MANIFEST_VERSION',
|
||||
value: config.manifestVersion,
|
||||
type: `2 | 3`,
|
||||
},
|
||||
{
|
||||
name: surroundInUnderscore('BROWSER'),
|
||||
name: 'BROWSER',
|
||||
value: config.browser,
|
||||
type: `string`,
|
||||
},
|
||||
{
|
||||
name: surroundInUnderscore('IS_CHROME'),
|
||||
name: 'CHROME',
|
||||
value: config.browser === 'chrome',
|
||||
type: `boolean`,
|
||||
},
|
||||
{
|
||||
name: surroundInUnderscore('IS_FIREFOX'),
|
||||
name: 'FIREFOX',
|
||||
value: config.browser === 'firefox',
|
||||
type: `boolean`,
|
||||
},
|
||||
{
|
||||
name: surroundInUnderscore('IS_SAFARI'),
|
||||
name: 'SAFARI',
|
||||
value: config.browser === 'safari',
|
||||
type: `boolean`,
|
||||
},
|
||||
{
|
||||
name: surroundInUnderscore('IS_EDGE'),
|
||||
name: 'EDGE',
|
||||
value: config.browser === 'edge',
|
||||
type: `boolean`,
|
||||
},
|
||||
{
|
||||
name: surroundInUnderscore('IS_OPERA'),
|
||||
name: 'OPERA',
|
||||
value: config.browser === 'opera',
|
||||
type: `boolean`,
|
||||
},
|
||||
{
|
||||
name: surroundInUnderscore('COMMAND'),
|
||||
name: 'COMMAND',
|
||||
value: config.command,
|
||||
type: `"build" | "serve"`,
|
||||
},
|
||||
@@ -50,17 +50,9 @@ export function getGlobals(
|
||||
export function getEntrypointGlobals(entrypointName: string) {
|
||||
return [
|
||||
{
|
||||
name: surroundInUnderscore('ENTRYPOINT'),
|
||||
name: 'ENTRYPOINT',
|
||||
value: entrypointName,
|
||||
type: `string`,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't hardcode the complete name so that the string litterals in this file aren't replaced during
|
||||
* tests (which causes syntax errors), only during builds.
|
||||
*/
|
||||
function surroundInUnderscore(name: string): string {
|
||||
return `__${name}__`;
|
||||
}
|
||||
|
||||
@@ -232,7 +232,8 @@ export const fakeInternalConfig = fakeObjectCreator<InternalConfig>(() => {
|
||||
},
|
||||
zip: {
|
||||
artifactTemplate: '{{name}}-{{version}}.zip',
|
||||
ignoredSources: [],
|
||||
includeSources: [],
|
||||
excludeSources: [],
|
||||
sourcesRoot: fakeDir(),
|
||||
sourcesTemplate: '{{name}}-sources.zip',
|
||||
name: faker.person.firstName().toLowerCase(),
|
||||
|
||||
+8
-3
@@ -62,10 +62,15 @@ export async function zip(config?: InlineConfig): Promise<string[]> {
|
||||
saveTo: sourcesZipPath,
|
||||
filter(path) {
|
||||
const relativePath = relative(internalConfig.zip.sourcesRoot, path);
|
||||
const matchedPattern = internalConfig.zip.ignoredSources.find(
|
||||
(pattern) => minimatch(relativePath, pattern),
|
||||
|
||||
return (
|
||||
internalConfig.zip.includeSources.some((pattern) =>
|
||||
minimatch(relativePath, pattern),
|
||||
) ||
|
||||
!internalConfig.zip.excludeSources.some((pattern) =>
|
||||
minimatch(relativePath, pattern),
|
||||
)
|
||||
);
|
||||
return matchedPattern == null;
|
||||
},
|
||||
});
|
||||
zipFiles.push(sourcesZipPath);
|
||||
|
||||
+42
-2
@@ -143,9 +143,22 @@ export interface InlineConfig {
|
||||
* @default config.root
|
||||
*/
|
||||
sourcesRoot?: string;
|
||||
/**
|
||||
* [Minimatch](https://www.npmjs.com/package/minimatch) patterns of files to include when
|
||||
* creating a ZIP of all your source code for Firefox. Patterns are relative to your
|
||||
* `config.zip.sourcesRoot`.
|
||||
*
|
||||
* This setting overrides `excludeSources`. So if a file matches both lists, it is included in the ZIP.
|
||||
*
|
||||
* @example
|
||||
* [
|
||||
* "coverage", // Ignore the coverage directory in the `sourcesRoot`
|
||||
* ]
|
||||
*/
|
||||
includeSources?: string[];
|
||||
/**
|
||||
* [Minimatch](https://www.npmjs.com/package/minimatch) patterns of files to exclude when
|
||||
* creating a ZIP of all your source code for Firfox. Patterns are relative to your
|
||||
* creating a ZIP of all your source code for Firefox. Patterns are relative to your
|
||||
* `config.zip.sourcesRoot`.
|
||||
*
|
||||
* Hidden files, node_modules, and tests are ignored by default.
|
||||
@@ -155,7 +168,7 @@ export interface InlineConfig {
|
||||
* "coverage", // Ignore the coverage directory in the `sourcesRoot`
|
||||
* ]
|
||||
*/
|
||||
ignoredSources?: string[];
|
||||
excludeSources?: string[];
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -661,6 +674,33 @@ export interface ExtensionRunnerConfig {
|
||||
* @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#chromium-profile
|
||||
*/
|
||||
chromiumProfile?: string;
|
||||
/**
|
||||
* An map of chrome preferences from https://chromium.googlesource.com/chromium/src/+/main/chrome/common/pref_names.h
|
||||
*
|
||||
* @example
|
||||
* // change your downloads directory
|
||||
* {
|
||||
* download: {
|
||||
* default_directory: "/my/custom/dir",
|
||||
* },
|
||||
* }
|
||||
*
|
||||
* @default
|
||||
* // Enable dev mode and allow content script sourcemaps
|
||||
* {
|
||||
* devtools: {
|
||||
* synced_preferences_sync_disabled: {
|
||||
* skipContentScripts: false,
|
||||
* },
|
||||
* }
|
||||
* extensions: {
|
||||
* ui: {
|
||||
* developer_mode: true,
|
||||
* },
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
chromiumPref?: string;
|
||||
/**
|
||||
* @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#pref
|
||||
*/
|
||||
|
||||
Vendored
+7
-4
@@ -1,7 +1,10 @@
|
||||
// Globals defined by the vite-plugins/devServerGlobals.ts and utils/globals.ts
|
||||
declare const __COMMAND__: 'build' | 'serve';
|
||||
declare const __DEV_SERVER_PROTOCOL__: string;
|
||||
declare const __DEV_SERVER_HOSTNAME__: string;
|
||||
declare const __DEV_SERVER_PORT__: string;
|
||||
declare const __MANIFEST_VERSION__: 2 | 3;
|
||||
declare const __ENTRYPOINT__: string;
|
||||
|
||||
// Globals defined by the vite-plugins/devServerGlobals.ts and utils/globals.ts
|
||||
interface ImportMetaEnv {
|
||||
readonly COMMAND: 'build' | 'serve';
|
||||
readonly MANIFEST_VERSION: 2 | 3;
|
||||
readonly ENTRYPOINT: string;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ export interface InternalConfig {
|
||||
name?: string;
|
||||
artifactTemplate: string;
|
||||
sourcesTemplate: string;
|
||||
ignoredSources: string[];
|
||||
includeSources: string[];
|
||||
excludeSources: string[];
|
||||
sourcesRoot: string;
|
||||
};
|
||||
transformManifest: (manifest: Manifest.WebExtensionManifest) => void;
|
||||
|
||||
@@ -5,7 +5,7 @@ import { browser } from 'wxt/browser';
|
||||
import { keepServiceWorkerAlive } from './utils/keep-service-worker-alive';
|
||||
import { reloadContentScript } from './utils/reload-content-scripts';
|
||||
|
||||
if (__COMMAND__ === 'serve') {
|
||||
if (import.meta.env.COMMAND === 'serve') {
|
||||
try {
|
||||
const ws = setupWebSocket((message) => {
|
||||
if (message.event === 'wxt:reload-extension') browser.runtime.reload();
|
||||
@@ -13,7 +13,7 @@ if (__COMMAND__ === 'serve') {
|
||||
reloadContentScript(message.data);
|
||||
});
|
||||
|
||||
if (__MANIFEST_VERSION__ === 3) {
|
||||
if (import.meta.env.MANIFEST_VERSION === 3) {
|
||||
// Tell the server the background script is loaded and ready to go
|
||||
ws.addEventListener('open', () => {
|
||||
const msg = { type: 'custom', event: 'wxt:background-initialized' };
|
||||
|
||||
@@ -5,12 +5,12 @@ import { ContentScriptContext } from 'wxt/client';
|
||||
(async () => {
|
||||
try {
|
||||
const { main, ...options } = definition;
|
||||
const ctx = new ContentScriptContext(__ENTRYPOINT__, options);
|
||||
const ctx = new ContentScriptContext(import.meta.env.ENTRYPOINT, options);
|
||||
|
||||
await main(ctx);
|
||||
} catch (err) {
|
||||
logger.error(
|
||||
`The content script "${__ENTRYPOINT__}" crashed on startup!`,
|
||||
`The content script "${import.meta.env.ENTRYPOINT}" crashed on startup!`,
|
||||
err,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { logger } from '../sandbox/utils/logger';
|
||||
await main();
|
||||
} catch (err) {
|
||||
logger.error(
|
||||
`The content script "${__ENTRYPOINT__}" crashed on startup!`,
|
||||
`The content script "${import.meta.env.ENTRYPOINT}" crashed on startup!`,
|
||||
err,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { logger } from '../sandbox/utils/logger';
|
||||
import { setupWebSocket } from './utils/setup-web-socket';
|
||||
|
||||
if (__COMMAND__ === 'serve') {
|
||||
if (import.meta.env.COMMAND === 'serve') {
|
||||
try {
|
||||
setupWebSocket((message) => {
|
||||
if (message.event === 'wxt:reload-page') {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { logger } from '../sandbox/utils/logger';
|
||||
await definition.main();
|
||||
} catch (err) {
|
||||
logger.error(
|
||||
`The unlisted script "${__ENTRYPOINT__}" crashed on startup!`,
|
||||
`The unlisted script "${import.meta.env.ENTRYPOINT}" crashed on startup!`,
|
||||
err,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,6 @@
|
||||
"@types/react-dom": "^18.2.18",
|
||||
"@vitejs/plugin-react": "^4.2.1",
|
||||
"typescript": "^5.3.3",
|
||||
"wxt": "^0.14.0"
|
||||
"wxt": "^0.15.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
"devDependencies": {
|
||||
"typescript": "^5.3.3",
|
||||
"vite-plugin-solid": "^2.8.0",
|
||||
"wxt": "^0.14.0"
|
||||
"wxt": "^0.15.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
"svelte-check": "^3.6.2",
|
||||
"tslib": "^2.6.2",
|
||||
"typescript": "^5.3.3",
|
||||
"wxt": "^0.14.0"
|
||||
"wxt": "^0.15.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,6 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.3.3",
|
||||
"wxt": "^0.14.0"
|
||||
"wxt": "^0.15.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,6 @@
|
||||
"@vitejs/plugin-vue": "^5.0.1",
|
||||
"typescript": "^5.3.3",
|
||||
"vue-tsc": "^1.8.27",
|
||||
"wxt": "^0.14.0"
|
||||
"wxt": "^0.15.0"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user