-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(experimental): First-class support for excluding `webextension-p…
…olyfill` (#847)
- Loading branch information
Showing
38 changed files
with
264 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/// <reference types="chrome" /> | ||
/** | ||
* EXPERIMENTAL | ||
* | ||
* Includes the `chrome` API and types when using `extensionApi: 'chrome'`. | ||
* | ||
* @module wxt/browser/chrome | ||
*/ | ||
|
||
export interface WxtRuntime { | ||
// Overriden per-project | ||
} | ||
export interface WxtI18n { | ||
// Overriden per-project | ||
} | ||
|
||
export type Chrome = typeof chrome; | ||
export type WxtBrowser = Omit<Chrome, 'runtime' | 'i18n'> & { | ||
runtime: WxtRuntime & Omit<Chrome['runtime'], 'getURL'>; | ||
i18n: WxtI18n & Omit<Chrome['i18n'], 'getMessage'>; | ||
}; | ||
|
||
export const browser: WxtBrowser = | ||
// @ts-expect-error | ||
globalThis.browser?.runtime?.id == null | ||
? globalThis.chrome | ||
: // @ts-expect-error | ||
globalThis.browser; |
3 changes: 3 additions & 0 deletions
3
packages/wxt/src/browser.ts → packages/wxt/src/browser/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/wxt/src/client/content-scripts/content-script-context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
packages/wxt/src/core/builders/vite/plugins/excludeBrowserPolyfill.ts
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
packages/wxt/src/core/builders/vite/plugins/extensionApiMock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import path from 'node:path'; | ||
import type * as vite from 'vite'; | ||
import { ResolvedConfig } from '../../../../types'; | ||
|
||
/** | ||
* Mock `webextension-polyfill`, `wxt/browser`, and `wxt/browser/*` by inlining | ||
* all dependencies that import them and adding a custom alias so that Vite | ||
* resolves to a mocked version of the module. | ||
* | ||
* TODO: Detect non-wxt dependencies (like `@webext-core/*`) that import `webextension-polyfill` via | ||
* `npm list` and inline them automatically. | ||
*/ | ||
export function extensionApiMock(config: ResolvedConfig): vite.PluginOption { | ||
return { | ||
name: 'wxt:extension-api-mock', | ||
config() { | ||
const replacement = path.resolve( | ||
config.wxtModuleDir, | ||
'dist/virtual/mock-browser', | ||
); | ||
return { | ||
resolve: { | ||
alias: [ | ||
{ find: 'webextension-polyfill', replacement }, | ||
// wxt/browser, wxt/browser/... | ||
{ find: /^wxt\/browser.*/, replacement }, | ||
], | ||
}, | ||
ssr: { | ||
// Inline all WXT modules so vite processes them so the aliases can | ||
// be resolved | ||
noExternal: ['wxt'], | ||
}, | ||
}; | ||
}, | ||
}; | ||
} |
Oops, something went wrong.