Compare commits

..

4 Commits

Author SHA1 Message Date
GitHub Actions 3ab9fe4ae3 chore(release): v0.9.2 2023-11-11 19:57:25 +00:00
Aaron 91b28c2cb9 feat: Experimental option to exclude webextension-polyfill (#231) 2023-11-11 13:53:47 -06:00
Aaron Klinker d1b523061f ci: Fix sync-release workflow 2023-11-11 12:49:40 -06:00
Aaron Klinker c69ea3967f Fix changelog 2023-11-11 12:47:32 -06:00
10 changed files with 112 additions and 4 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
name: Sync Releases
on:
workflow_dispatch:
push:
branches:
- main
@@ -18,4 +19,4 @@ jobs:
with:
node-version: 18
cache: pnpm
- run: pnpm sync-releases all
- run: pnpm sync-releases all --token ${{ secrets.GITHUB_TOKEN }}
+13 -2
View File
@@ -1,5 +1,17 @@
# Changelog
## v0.9.2
[compare changes](https://github.com/wxt-dev/wxt/compare/v0.9.1...v0.9.2)
### 🚀 Enhancements
- Experimental option to exclude `webextension-polyfill` ([#231](https://github.com/wxt-dev/wxt/pull/231))
### 🤖 CI
- Fix sync-release workflow ([d1b5230](https://github.com/wxt-dev/wxt/commit/d1b5230))
## v0.9.1
[compare changes](https://github.com/wxt-dev/wxt/compare/v0.9.0...v0.9.1)
@@ -25,7 +37,7 @@
- Remove whitespace from genearted `.wxt` files ([#211](https://github.com/wxt-dev/wxt/pull/211))
- Upgrade templates to `wxt@^0.9.0` ([#214](https://github.com/wxt-dev/wxt/pull/214))
- Update Vite dependency range to `^4.0.0 ([](https://github.com/wxt-dev/wxt/commit/))
- Update Vite dependency range to `^4.0.0 || ^5.0.0-0` ([f1e8084](https://github.com/wxt-dev/wxt/commit/f1e8084be89e512dde441b9197a99183c497f67d))
### 🤖 CI
@@ -34,7 +46,6 @@
### ❤️ Contributors
- Aaron Klinker ([@aaronklinker-st](http://github.com/aaronklinker-st))
- ^5.0.0-0` <f1e8084>
## v0.9.0
+21
View File
@@ -1,5 +1,6 @@
import { describe, it, expect } from 'vitest';
import { TestProject } from '../utils';
import { InlineConfig } from '~/types';
describe('User Config', () => {
// Root directory is tested with all tests.
@@ -85,4 +86,24 @@ describe('User Config', () => {
{\\"manifest_version\\":3,\\"name\\":\\"E2E Extension\\",\\"description\\":\\"Example description\\",\\"version\\":\\"0.0.0\\",\\"example_customization\\":[\\"production\\",\\"chrome\\",\\"3\\",\\"build\\"]}"
`);
});
it('should exclude the polyfill when the experimental setting is set to false', async () => {
const buildBackground = async (config?: InlineConfig) => {
const background = `export default defineBackground(() => console.log(browser.runtime.id));`;
const projectWithPolyfill = new TestProject();
projectWithPolyfill.addFile('entrypoints/background.ts', background);
await projectWithPolyfill.build(config);
return await projectWithPolyfill.serializeFile(
'.output/chrome-mv3/background.js',
);
};
const withPolyfill = await buildBackground();
const withoutPolyfill = await buildBackground({
experimental: {
includeBrowserPolyfill: false,
},
});
expect(withoutPolyfill).not.toBe(withPolyfill);
});
});
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "wxt",
"type": "module",
"version": "0.9.1",
"version": "0.9.2",
"description": "Next gen framework for developing web extensions",
"engines": {
"node": ">=18",
@@ -123,6 +123,10 @@ export async function getInternalConfig(
},
userConfigMetadata: userConfigMetadata ?? {},
alias,
experimental: {
includeBrowserPolyfill:
mergedConfig.experimental?.includeBrowserPolyfill ?? true,
},
};
finalConfig.vite = (env) =>
@@ -202,6 +206,10 @@ function mergeInlineConfig(
...userConfig.alias,
...inlineConfig.alias,
},
experimental: {
...userConfig.experimental,
...inlineConfig.experimental,
},
};
}
@@ -267,5 +275,7 @@ async function resolveInternalViteConfig(
}
internalVite.plugins.push(plugins.globals(finalConfig));
internalVite.plugins.push(plugins.excludeBrowserPolyfill(finalConfig));
return internalVite;
}
+3
View File
@@ -245,5 +245,8 @@ export const fakeInternalConfig = fakeObjectCreator<InternalConfig>(() => {
transformManifest: () => {},
userConfigMetadata: {},
alias: {},
experimental: {
includeBrowserPolyfill: true,
},
};
});
@@ -0,0 +1,33 @@
import { InternalConfig } from '~/types';
import * as vite from 'vite';
/**
* Apply the experimental config for disabling the polyfill. It works by aliasing the
* `webextension-polyfill` module to a virtual module and exporting the `chrome` global from the
* virtual module.
*/
export function excludeBrowserPolyfill(config: InternalConfig): vite.Plugin {
const virtualId = 'virtual:wxt-webextension-polyfill-disabled';
return {
name: 'wxt:exclude-browser-polyfill',
config() {
// Only apply the config if we're disabling the polyfill
if (config.experimental.includeBrowserPolyfill) return;
return {
resolve: {
alias: {
'webextension-polyfill': virtualId,
},
},
};
},
load(id) {
if (id === virtualId) {
// Use chrome instead of the polyfill when disabled.
return 'export default chrome';
}
},
};
}
+1
View File
@@ -11,3 +11,4 @@ export * from './bundleAnalysis';
export * from './globals';
export * from './webextensionPolyfillAlias';
export * from './webextensionPolyfillInlineDeps';
export * from './excludeBrowserPolyfill';
+25
View File
@@ -206,6 +206,31 @@ export interface InlineConfig {
* }
*/
alias?: Record<string, string>;
/**
* Experimental settings - use with caution.
*/
experimental?: {
/**
* Whether to use [`webextension-polyfill`](https://www.npmjs.com/package/webextension-polyfill)
* when importing `browser` from `wxt/browser`.
*
* When set to `false`, WXT will export the chrome global instead of the polyfill from
* `wxt/browser`.
*
* You should use `browser` to access the web extension APIs.
*
* @experimental This option will remain experimental until Manifest V2 is dead.
*
* @default true
* @example
* export default defineConfig({
* experimental: {
* includeBrowserPolyfill: false
* }
* })
*/
includeBrowserPolyfill?: boolean;
};
}
export interface WxtInlineViteConfig
+3
View File
@@ -53,6 +53,9 @@ export interface InternalConfig {
* Import aliases to absolute paths.
*/
alias: Record<string, string>;
experimental: {
includeBrowserPolyfill: boolean;
};
}
export interface FsCache {