wxt 0.20.13 → 0.20.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.d.mts +20 -0
- package/dist/browser.mjs +18 -3
- package/dist/builtin-modules/index.mjs +7 -2
- package/dist/builtin-modules/unimport.mjs +69 -75
- package/dist/cli/cli-utils.mjs +52 -50
- package/dist/cli/commands.mjs +77 -103
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +9 -4
- package/dist/core/{build.d.ts → build.d.mts} +6 -2
- package/dist/core/build.mjs +23 -4
- package/dist/core/builders/vite/index.mjs +292 -343
- package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +11 -12
- package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +27 -20
- package/dist/core/builders/vite/plugins/defineImportMeta.mjs +17 -12
- package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +104 -136
- package/dist/core/builders/vite/plugins/devServerGlobals.mjs +15 -14
- package/dist/core/builders/vite/plugins/download.mjs +23 -12
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +18 -14
- package/dist/core/builders/vite/plugins/extensionApiMock.mjs +31 -33
- package/dist/core/builders/vite/plugins/globals.mjs +14 -13
- package/dist/core/builders/vite/plugins/iifeFooter.mjs +17 -11
- package/dist/core/builders/vite/plugins/index.mjs +18 -16
- package/dist/core/builders/vite/plugins/noopBackground.mjs +21 -15
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +25 -23
- package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +25 -23
- package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +27 -26
- package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +11 -11
- package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +41 -47
- package/dist/core/{clean.d.ts → clean.d.mts} +7 -3
- package/dist/core/clean.mjs +38 -35
- package/dist/core/{create-server.d.ts → create-server.d.mts} +6 -2
- package/dist/core/create-server.mjs +236 -247
- package/dist/core/define-config.d.mts +6 -0
- package/dist/core/define-config.mjs +6 -2
- package/dist/core/define-web-ext-config.d.mts +13 -0
- package/dist/core/define-web-ext-config.mjs +16 -7
- package/dist/core/generate-wxt-dir.mjs +109 -148
- package/dist/core/index.d.mts +8 -0
- package/dist/core/index.mjs +10 -8
- package/dist/core/initialize.d.mts +8 -0
- package/dist/core/initialize.mjs +110 -124
- package/dist/core/keyboard-shortcuts.mjs +30 -28
- package/dist/core/package-managers/bun.mjs +18 -16
- package/dist/core/package-managers/deno.mjs +12 -8
- package/dist/core/package-managers/index.mjs +52 -60
- package/dist/core/package-managers/npm.mjs +51 -52
- package/dist/core/package-managers/pnpm.mjs +21 -18
- package/dist/core/package-managers/yarn.mjs +31 -28
- package/dist/core/prepare.d.mts +6 -0
- package/dist/core/prepare.mjs +12 -7
- package/dist/core/resolve-config.mjs +393 -462
- package/dist/core/runners/index.mjs +11 -6
- package/dist/core/runners/manual.mjs +16 -14
- package/dist/core/runners/safari.mjs +16 -14
- package/dist/core/runners/web-ext.mjs +62 -83
- package/dist/core/runners/wsl.mjs +16 -14
- package/dist/core/utils/arrays.mjs +23 -12
- package/dist/core/utils/building/build-entrypoints.mjs +44 -40
- package/dist/core/utils/building/detect-dev-changes.mjs +84 -105
- package/dist/core/utils/building/find-entrypoints.mjs +275 -359
- package/dist/core/utils/building/group-entrypoints.mjs +42 -35
- package/dist/core/utils/building/index.mjs +8 -6
- package/dist/core/utils/building/internal-build.mjs +87 -102
- package/dist/core/utils/building/rebuild.mjs +50 -30
- package/dist/core/utils/cache.mjs +29 -18
- package/dist/core/utils/constants.mjs +9 -1
- package/dist/core/utils/content-scripts.mjs +56 -54
- package/dist/core/utils/content-security-policy.mjs +36 -39
- package/dist/core/utils/entrypoints.mjs +51 -28
- package/dist/core/utils/env.mjs +22 -17
- package/dist/core/utils/environments/browser-environment.mjs +13 -12
- package/dist/core/utils/environments/environment.mjs +36 -33
- package/dist/core/utils/environments/extension-environment.mjs +15 -10
- package/dist/core/utils/environments/index.mjs +4 -2
- package/dist/core/utils/eslint.mjs +11 -10
- package/dist/core/utils/fs.mjs +23 -11
- package/dist/core/utils/globals.mjs +53 -51
- package/dist/core/utils/i18n.mjs +41 -32
- package/dist/core/utils/log/index.mjs +6 -4
- package/dist/core/utils/log/printBuildSummary.mjs +20 -25
- package/dist/core/utils/log/printFileList.mjs +30 -33
- package/dist/core/utils/log/printHeader.mjs +10 -5
- package/dist/core/utils/log/printTable.mjs +19 -21
- package/dist/core/utils/manifest.mjs +364 -479
- package/dist/core/utils/minimatch-multiple.mjs +26 -15
- package/dist/core/utils/network.mjs +30 -33
- package/dist/core/utils/number.mjs +7 -3
- package/dist/core/utils/package.mjs +20 -13
- package/dist/core/utils/paths.mjs +26 -7
- package/dist/core/utils/strings.mjs +19 -14
- package/dist/core/utils/syntax-errors.mjs +14 -16
- package/dist/core/utils/time.mjs +19 -15
- package/dist/core/utils/transform.mjs +129 -160
- package/dist/core/utils/types.d.mts +6 -0
- package/dist/core/utils/validation.mjs +43 -50
- package/dist/core/utils/virtual-modules.mjs +20 -12
- package/dist/core/utils/wsl.mjs +10 -3
- package/dist/core/wxt.mjs +66 -60
- package/dist/core/{zip.d.ts → zip.d.mts} +6 -2
- package/dist/core/zip.mjs +116 -140
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +12 -3
- package/dist/{modules.d.ts → modules.d.mts} +14 -16
- package/dist/modules.mjs +181 -51
- package/dist/testing/fake-browser.d.mts +2 -0
- package/dist/testing/fake-browser.mjs +3 -1
- package/dist/testing/index.d.mts +3 -0
- package/dist/testing/index.mjs +4 -2
- package/dist/testing/{wxt-vitest-plugin.d.ts → wxt-vitest-plugin.d.mts} +7 -9
- package/dist/testing/wxt-vitest-plugin.mjs +38 -19
- package/dist/types.d.mts +1453 -0
- package/dist/utils/app-config.d.mts +6 -0
- package/dist/utils/app-config.mjs +8 -2
- package/dist/utils/content-script-context.d.mts +137 -0
- package/dist/utils/content-script-context.mjs +192 -175
- package/dist/utils/content-script-ui/iframe.d.mts +42 -0
- package/dist/utils/content-script-ui/iframe.mjs +42 -27
- package/dist/utils/content-script-ui/integrated.d.mts +37 -0
- package/dist/utils/content-script-ui/integrated.mjs +36 -29
- package/dist/utils/content-script-ui/shadow-root.d.mts +80 -0
- package/dist/utils/content-script-ui/shadow-root.mjs +75 -82
- package/dist/utils/content-script-ui/shared.mjs +117 -150
- package/dist/utils/content-script-ui/types.d.mts +107 -0
- package/dist/utils/content-script-ui/types.mjs +1 -0
- package/dist/utils/{define-app-config.d.ts → define-app-config.d.mts} +5 -3
- package/dist/utils/define-app-config.mjs +22 -2
- package/dist/utils/define-background.d.mts +7 -0
- package/dist/utils/define-background.mjs +7 -3
- package/dist/utils/define-content-script.d.mts +6 -0
- package/dist/utils/define-content-script.mjs +6 -2
- package/dist/utils/define-unlisted-script.d.mts +7 -0
- package/dist/utils/define-unlisted-script.mjs +7 -3
- package/dist/utils/define-wxt-plugin.d.mts +6 -0
- package/dist/utils/define-wxt-plugin.mjs +6 -2
- package/dist/utils/inject-script.d.mts +41 -0
- package/dist/utils/inject-script.mjs +44 -34
- package/dist/utils/internal/custom-events.d.mts +9 -0
- package/dist/utils/internal/custom-events.mjs +18 -10
- package/dist/utils/internal/location-watcher.mjs +23 -20
- package/dist/utils/internal/logger.mjs +15 -12
- package/dist/utils/match-patterns.d.mts +1 -0
- package/dist/utils/match-patterns.mjs +3 -1
- package/dist/utils/{split-shadow-root-css.d.ts → split-shadow-root-css.d.mts} +6 -3
- package/dist/utils/split-shadow-root-css.mjs +16 -7
- package/dist/utils/storage.d.mts +1 -0
- package/dist/utils/storage.mjs +3 -1
- package/dist/version.d.mts +4 -0
- package/dist/version.mjs +5 -1
- package/dist/virtual/background-entrypoint.d.mts +4 -0
- package/dist/virtual/background-entrypoint.mjs +146 -161
- package/dist/virtual/content-script-isolated-world-entrypoint.d.mts +4 -0
- package/dist/virtual/content-script-isolated-world-entrypoint.mjs +26 -27
- package/dist/virtual/content-script-main-world-entrypoint.d.mts +4 -0
- package/dist/virtual/content-script-main-world-entrypoint.mjs +24 -24
- package/dist/virtual/mock-browser.d.mts +6 -0
- package/dist/virtual/mock-browser.mjs +5 -3
- package/dist/virtual/reload-html.d.mts +1 -0
- package/dist/virtual/reload-html.mjs +60 -53
- package/dist/virtual/unlisted-script-entrypoint.d.mts +4 -0
- package/dist/virtual/unlisted-script-entrypoint.mjs +35 -43
- package/package.json +47 -49
- package/dist/browser.d.ts +0 -30
- package/dist/builtin-modules/index.d.ts +0 -2
- package/dist/builtin-modules/unimport.d.ts +0 -5
- package/dist/cli/cli-utils.d.ts +0 -25
- package/dist/cli/commands.d.ts +0 -2
- package/dist/cli/index.d.ts +0 -1
- package/dist/core/builders/vite/index.d.ts +0 -7
- package/dist/core/builders/vite/plugins/bundleAnalysis.d.ts +0 -7
- package/dist/core/builders/vite/plugins/cssEntrypoints.d.ts +0 -13
- package/dist/core/builders/vite/plugins/defineImportMeta.d.ts +0 -14
- package/dist/core/builders/vite/plugins/devHtmlPrerender.d.ts +0 -7
- package/dist/core/builders/vite/plugins/devServerGlobals.d.ts +0 -6
- package/dist/core/builders/vite/plugins/download.d.ts +0 -10
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.d.ts +0 -6
- package/dist/core/builders/vite/plugins/extensionApiMock.d.ts +0 -6
- package/dist/core/builders/vite/plugins/globals.d.ts +0 -3
- package/dist/core/builders/vite/plugins/iifeFooter.d.ts +0 -8
- package/dist/core/builders/vite/plugins/index.d.ts +0 -16
- package/dist/core/builders/vite/plugins/noopBackground.d.ts +0 -6
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.d.ts +0 -6
- package/dist/core/builders/vite/plugins/resolveAppConfig.d.ts +0 -6
- package/dist/core/builders/vite/plugins/resolveVirtualModules.d.ts +0 -6
- package/dist/core/builders/vite/plugins/tsconfigPaths.d.ts +0 -3
- package/dist/core/builders/vite/plugins/wxtPluginLoader.d.ts +0 -6
- package/dist/core/define-config.d.ts +0 -2
- package/dist/core/define-web-ext-config.d.ts +0 -9
- package/dist/core/generate-wxt-dir.d.ts +0 -5
- package/dist/core/index.d.ts +0 -8
- package/dist/core/initialize.d.ts +0 -5
- package/dist/core/keyboard-shortcuts.d.ts +0 -12
- package/dist/core/package-managers/bun.d.ts +0 -2
- package/dist/core/package-managers/deno.d.ts +0 -2
- package/dist/core/package-managers/index.d.ts +0 -2
- package/dist/core/package-managers/npm.d.ts +0 -17
- package/dist/core/package-managers/pnpm.d.ts +0 -2
- package/dist/core/package-managers/types.d.ts +0 -2
- package/dist/core/package-managers/types.mjs +0 -0
- package/dist/core/package-managers/yarn.d.ts +0 -2
- package/dist/core/prepare.d.ts +0 -2
- package/dist/core/resolve-config.d.ts +0 -11
- package/dist/core/runners/index.d.ts +0 -2
- package/dist/core/runners/manual.d.ts +0 -5
- package/dist/core/runners/safari.d.ts +0 -5
- package/dist/core/runners/web-ext.d.ts +0 -5
- package/dist/core/runners/wsl.d.ts +0 -5
- package/dist/core/utils/arrays.d.ts +0 -13
- package/dist/core/utils/building/build-entrypoints.d.ts +0 -3
- package/dist/core/utils/building/detect-dev-changes.d.ts +0 -61
- package/dist/core/utils/building/find-entrypoints.d.ts +0 -5
- package/dist/core/utils/building/group-entrypoints.d.ts +0 -8
- package/dist/core/utils/building/index.d.ts +0 -6
- package/dist/core/utils/building/internal-build.d.ts +0 -12
- package/dist/core/utils/building/rebuild.d.ts +0 -23
- package/dist/core/utils/cache.d.ts +0 -8
- package/dist/core/utils/cli.d.ts +0 -3
- package/dist/core/utils/cli.mjs +0 -26
- package/dist/core/utils/constants.d.ts +0 -5
- package/dist/core/utils/content-scripts.d.ts +0 -12
- package/dist/core/utils/content-security-policy.d.ts +0 -14
- package/dist/core/utils/entrypoints.d.ts +0 -31
- package/dist/core/utils/env.d.ts +0 -5
- package/dist/core/utils/environments/browser-environment.d.ts +0 -3
- package/dist/core/utils/environments/environment.d.ts +0 -8
- package/dist/core/utils/environments/extension-environment.d.ts +0 -6
- package/dist/core/utils/environments/index.d.ts +0 -2
- package/dist/core/utils/eslint.d.ts +0 -1
- package/dist/core/utils/fs.d.ts +0 -13
- package/dist/core/utils/globals.d.ts +0 -11
- package/dist/core/utils/i18n.d.ts +0 -11
- package/dist/core/utils/log/index.d.ts +0 -4
- package/dist/core/utils/log/printBuildSummary.d.ts +0 -2
- package/dist/core/utils/log/printFileList.d.ts +0 -1
- package/dist/core/utils/log/printHeader.d.ts +0 -1
- package/dist/core/utils/log/printTable.d.ts +0 -1
- package/dist/core/utils/manifest.d.ts +0 -40
- package/dist/core/utils/minimatch-multiple.d.ts +0 -15
- package/dist/core/utils/network.d.ts +0 -7
- package/dist/core/utils/number.d.ts +0 -1
- package/dist/core/utils/package.d.ts +0 -6
- package/dist/core/utils/paths.d.ts +0 -11
- package/dist/core/utils/strings.d.ts +0 -14
- package/dist/core/utils/syntax-errors.d.ts +0 -11
- package/dist/core/utils/testing/fake-objects.d.ts +0 -11665
- package/dist/core/utils/testing/fake-objects.mjs +0 -326
- package/dist/core/utils/time.d.ts +0 -9
- package/dist/core/utils/transform.d.ts +0 -11
- package/dist/core/utils/types.d.ts +0 -13
- package/dist/core/utils/types.mjs +0 -0
- package/dist/core/utils/validation.d.ts +0 -15
- package/dist/core/utils/virtual-modules.d.ts +0 -22
- package/dist/core/utils/wsl.d.ts +0 -4
- package/dist/core/wxt.d.ts +0 -24
- package/dist/index.d.ts +0 -11
- package/dist/testing/fake-browser.d.ts +0 -10
- package/dist/testing/index.d.ts +0 -10
- package/dist/types.d.ts +0 -1459
- package/dist/types.mjs +0 -0
- package/dist/utils/app-config.d.ts +0 -2
- package/dist/utils/content-script-context.d.ts +0 -134
- package/dist/utils/content-script-ui/iframe.d.ts +0 -32
- package/dist/utils/content-script-ui/integrated.d.ts +0 -34
- package/dist/utils/content-script-ui/shadow-root.d.ts +0 -76
- package/dist/utils/content-script-ui/shared.d.ts +0 -5
- package/dist/utils/content-script-ui/types.d.ts +0 -104
- package/dist/utils/define-background.d.ts +0 -4
- package/dist/utils/define-content-script.d.ts +0 -3
- package/dist/utils/define-unlisted-script.d.ts +0 -4
- package/dist/utils/define-wxt-plugin.d.ts +0 -3
- package/dist/utils/inject-script.d.ts +0 -36
- package/dist/utils/internal/custom-events.d.ts +0 -10
- package/dist/utils/internal/dev-server-websocket.d.ts +0 -21
- package/dist/utils/internal/dev-server-websocket.mjs +0 -37
- package/dist/utils/internal/location-watcher.d.ts +0 -12
- package/dist/utils/internal/logger.d.ts +0 -9
- package/dist/utils/match-patterns.d.ts +0 -5
- package/dist/utils/storage.d.ts +0 -5
- package/dist/version.d.ts +0 -1
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { visualizer } from "@aklinker1/rollup-plugin-visualizer";
|
|
2
1
|
import path from "node:path";
|
|
2
|
+
import { visualizer } from "@aklinker1/rollup-plugin-visualizer";
|
|
3
|
+
|
|
4
|
+
//#region src/core/builders/vite/plugins/bundleAnalysis.ts
|
|
3
5
|
let increment = 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
`${config.analysis.outputName}-${increment++}.json`
|
|
10
|
-
)
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
export function resetBundleIncrement() {
|
|
14
|
-
increment = 0;
|
|
6
|
+
function bundleAnalysis(config) {
|
|
7
|
+
return visualizer({
|
|
8
|
+
template: "raw-data",
|
|
9
|
+
filename: path.resolve(config.analysis.outputDir, `${config.analysis.outputName}-${increment++}.json`)
|
|
10
|
+
});
|
|
15
11
|
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { bundleAnalysis };
|
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
import { getEntrypointBundlePath } from "../../../utils/entrypoints.mjs";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
|
|
3
|
+
//#region src/core/builders/vite/plugins/cssEntrypoints.ts
|
|
4
|
+
/**
|
|
5
|
+
* Rename CSS entrypoint outputs to ensure a JS file is not generated, and that the CSS file is
|
|
6
|
+
* placed in the correct place.
|
|
7
|
+
*
|
|
8
|
+
* It:
|
|
9
|
+
* 1. Renames CSS files to their final paths
|
|
10
|
+
* 2. Removes the JS file that get's output by lib mode
|
|
11
|
+
*
|
|
12
|
+
* THIS PLUGIN SHOULD ONLY BE APPLIED TO CSS LIB MODE BUILDS. It should not be added to every build.
|
|
13
|
+
*/
|
|
14
|
+
function cssEntrypoints(entrypoint, config) {
|
|
15
|
+
return {
|
|
16
|
+
name: "wxt:css-entrypoint",
|
|
17
|
+
config() {
|
|
18
|
+
return { build: { rollupOptions: { output: { assetFileNames: () => getEntrypointBundlePath(entrypoint, config.outDir, ".css") } } } };
|
|
19
|
+
},
|
|
20
|
+
generateBundle(_, bundle) {
|
|
21
|
+
Object.keys(bundle).forEach((file) => {
|
|
22
|
+
if (file.endsWith(".js")) delete bundle[file];
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
22
26
|
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { cssEntrypoints };
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
//#region src/core/builders/vite/plugins/defineImportMeta.ts
|
|
2
|
+
/**
|
|
3
|
+
* Overrides definitions for `import.meta.*`
|
|
4
|
+
*
|
|
5
|
+
* - `import.meta.url`: Without this, background service workers crash trying to access
|
|
6
|
+
* `document.location`, see https://github.com/wxt-dev/wxt/issues/392
|
|
7
|
+
*/
|
|
8
|
+
function defineImportMeta() {
|
|
9
|
+
return {
|
|
10
|
+
name: "wxt:define",
|
|
11
|
+
config() {
|
|
12
|
+
return { define: { "import.meta.url": "self.location.href" } };
|
|
13
|
+
}
|
|
14
|
+
};
|
|
13
15
|
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { defineImportMeta };
|
|
@@ -1,144 +1,112 @@
|
|
|
1
|
+
import { normalizePath } from "../../../utils/paths.mjs";
|
|
1
2
|
import { getEntrypointName } from "../../../utils/entrypoints.mjs";
|
|
2
|
-
import { parseHTML } from "linkedom";
|
|
3
3
|
import { dirname, relative, resolve } from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { parseHTML } from "linkedom";
|
|
5
5
|
import { hash } from "ohash";
|
|
6
|
+
|
|
7
|
+
//#region src/core/builders/vite/plugins/devHtmlPrerender.ts
|
|
6
8
|
const inlineScriptContents = {};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
config.logger.debug("transformIndexHtml " + ctx.filename);
|
|
73
|
-
config.logger.debug("Old HTML:\n" + html);
|
|
74
|
-
config.logger.debug("New HTML:\n" + newHtml);
|
|
75
|
-
return newHtml;
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
name: "wxt:virtualize-inline-scripts",
|
|
80
|
-
apply: "serve",
|
|
81
|
-
resolveId(id) {
|
|
82
|
-
if (id.startsWith(virtualInlineScript)) {
|
|
83
|
-
return "\0" + id;
|
|
84
|
-
}
|
|
85
|
-
if (id.startsWith("/chunks/")) {
|
|
86
|
-
return "\0noop";
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
load(id) {
|
|
90
|
-
if (id.startsWith(resolvedVirtualInlineScript)) {
|
|
91
|
-
const key = id.substring(id.indexOf("?") + 1);
|
|
92
|
-
return inlineScriptContents[key];
|
|
93
|
-
}
|
|
94
|
-
if (id === "\0noop") {
|
|
95
|
-
return "";
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
];
|
|
9
|
+
/**
|
|
10
|
+
* Pre-renders the HTML entrypoints when building the extension to connect to the dev server.
|
|
11
|
+
*/
|
|
12
|
+
function devHtmlPrerender(config, server) {
|
|
13
|
+
const htmlReloadId = "@wxt/reload-html";
|
|
14
|
+
const resolvedHtmlReloadId = resolve(config.wxtModuleDir, "dist/virtual/reload-html.mjs");
|
|
15
|
+
const virtualInlineScript = "virtual:wxt-inline-script";
|
|
16
|
+
const resolvedVirtualInlineScript = "\0" + virtualInlineScript;
|
|
17
|
+
return [{
|
|
18
|
+
apply: "build",
|
|
19
|
+
name: "wxt:dev-html-prerender",
|
|
20
|
+
config() {
|
|
21
|
+
return { resolve: { alias: { [htmlReloadId]: resolvedHtmlReloadId } } };
|
|
22
|
+
},
|
|
23
|
+
transform(code, id) {
|
|
24
|
+
if (config.command !== "serve" || server == null || !id.endsWith(".html")) return;
|
|
25
|
+
const { document } = parseHTML(code);
|
|
26
|
+
const _pointToDevServer = (querySelector, attr) => pointToDevServer(config, server, id, document, querySelector, attr);
|
|
27
|
+
_pointToDevServer("script[type=module]", "src");
|
|
28
|
+
_pointToDevServer("link[rel=stylesheet]", "href");
|
|
29
|
+
const reloader = document.createElement("script");
|
|
30
|
+
reloader.src = htmlReloadId;
|
|
31
|
+
reloader.type = "module";
|
|
32
|
+
document.head.appendChild(reloader);
|
|
33
|
+
const newHtml = document.toString();
|
|
34
|
+
config.logger.debug("transform " + id);
|
|
35
|
+
config.logger.debug("Old HTML:\n" + code);
|
|
36
|
+
config.logger.debug("New HTML:\n" + newHtml);
|
|
37
|
+
return newHtml;
|
|
38
|
+
},
|
|
39
|
+
async transformIndexHtml(html, ctx) {
|
|
40
|
+
if (config.command !== "serve" || server == null) return;
|
|
41
|
+
const originalUrl = `${server.origin}${ctx.path}`;
|
|
42
|
+
const name = getEntrypointName(config.entrypointsDir, ctx.filename);
|
|
43
|
+
const url = `${server.origin}/${name}.html`;
|
|
44
|
+
const { document } = parseHTML(await server.transformHtml(url, html, originalUrl));
|
|
45
|
+
document.querySelectorAll("script:not([src])").forEach((script) => {
|
|
46
|
+
const textContent = script.textContent ?? "";
|
|
47
|
+
const key = hash(textContent);
|
|
48
|
+
inlineScriptContents[key] = textContent;
|
|
49
|
+
const virtualScript = document.createElement("script");
|
|
50
|
+
virtualScript.type = "module";
|
|
51
|
+
virtualScript.src = `${server.origin}/@id/${virtualInlineScript}?${key}`;
|
|
52
|
+
script.replaceWith(virtualScript);
|
|
53
|
+
});
|
|
54
|
+
const viteClientScript = document.querySelector("script[src='/@vite/client']");
|
|
55
|
+
if (viteClientScript) viteClientScript.src = `${server.origin}${viteClientScript.src}`;
|
|
56
|
+
const newHtml = document.toString();
|
|
57
|
+
config.logger.debug("transformIndexHtml " + ctx.filename);
|
|
58
|
+
config.logger.debug("Old HTML:\n" + html);
|
|
59
|
+
config.logger.debug("New HTML:\n" + newHtml);
|
|
60
|
+
return newHtml;
|
|
61
|
+
}
|
|
62
|
+
}, {
|
|
63
|
+
name: "wxt:virtualize-inline-scripts",
|
|
64
|
+
apply: "serve",
|
|
65
|
+
resolveId(id) {
|
|
66
|
+
if (id.startsWith(virtualInlineScript)) return "\0" + id;
|
|
67
|
+
if (id.startsWith("/chunks/")) return "\0noop";
|
|
68
|
+
},
|
|
69
|
+
load(id) {
|
|
70
|
+
if (id.startsWith(resolvedVirtualInlineScript)) return inlineScriptContents[id.substring(id.indexOf("?") + 1)];
|
|
71
|
+
if (id === "\0noop") return "";
|
|
72
|
+
}
|
|
73
|
+
}];
|
|
100
74
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
let path = normalizePath(resolvedAbsolutePath);
|
|
128
|
-
if (!path.startsWith("/")) path = "/" + path;
|
|
129
|
-
element.setAttribute(attr, `${server.origin}/@fs${path}`);
|
|
130
|
-
} else {
|
|
131
|
-
const url = new URL(relativePath, server.origin);
|
|
132
|
-
element.setAttribute(attr, url.href);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
});
|
|
75
|
+
function pointToDevServer(config, server, id, document, querySelector, attr) {
|
|
76
|
+
document.querySelectorAll(querySelector).forEach((element) => {
|
|
77
|
+
if (element.hasAttribute("vite-ignore") || element.hasAttribute("wxt-ignore")) {
|
|
78
|
+
element.removeAttribute("wxt-ignore");
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const src = element.getAttribute(attr);
|
|
82
|
+
if (!src || isUrl(src)) return;
|
|
83
|
+
let resolvedAbsolutePath;
|
|
84
|
+
const matchingAlias = Object.entries(config.alias).find(([key]) => src.startsWith(key));
|
|
85
|
+
if (matchingAlias) {
|
|
86
|
+
const [alias, replacement] = matchingAlias;
|
|
87
|
+
resolvedAbsolutePath = resolve(config.root, src.replace(alias, replacement));
|
|
88
|
+
} else resolvedAbsolutePath = resolve(dirname(id), src);
|
|
89
|
+
if (resolvedAbsolutePath) {
|
|
90
|
+
const relativePath = normalizePath(relative(config.root, resolvedAbsolutePath));
|
|
91
|
+
if (relativePath.startsWith(".")) {
|
|
92
|
+
let path = normalizePath(resolvedAbsolutePath);
|
|
93
|
+
if (!path.startsWith("/")) path = "/" + path;
|
|
94
|
+
element.setAttribute(attr, `${server.origin}/@fs${path}`);
|
|
95
|
+
} else {
|
|
96
|
+
const url = new URL(relativePath, server.origin);
|
|
97
|
+
element.setAttribute(attr, url.href);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
136
101
|
}
|
|
137
102
|
function isUrl(str) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
103
|
+
try {
|
|
104
|
+
new URL(str);
|
|
105
|
+
return true;
|
|
106
|
+
} catch {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
144
109
|
}
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
export { devHtmlPrerender, pointToDevServer };
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
};
|
|
1
|
+
//#region src/core/builders/vite/plugins/devServerGlobals.ts
|
|
2
|
+
/**
|
|
3
|
+
* Defines global constants about the dev server. Helps scripts connect to the server's web socket.
|
|
4
|
+
*/
|
|
5
|
+
function devServerGlobals(config, server) {
|
|
6
|
+
return {
|
|
7
|
+
name: "wxt:dev-server-globals",
|
|
8
|
+
config() {
|
|
9
|
+
if (server == null || config.command == "build") return;
|
|
10
|
+
return { define: { __DEV_SERVER_ORIGIN__: JSON.stringify(server.origin.replace(/^http(s?):/, "ws$1:")) } };
|
|
11
|
+
}
|
|
12
|
+
};
|
|
15
13
|
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { devServerGlobals };
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import { fetchCached } from "../../../utils/network.mjs";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
|
|
3
|
+
//#region src/core/builders/vite/plugins/download.ts
|
|
4
|
+
/**
|
|
5
|
+
* Downloads any URL imports, like Google Analytics, into virtual modules so they are bundled with
|
|
6
|
+
* the extension instead of depending on remote code at runtime.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* import "url:https://google-tagmanager.com/gtag?id=XYZ";
|
|
10
|
+
*/
|
|
11
|
+
function download(config) {
|
|
12
|
+
return {
|
|
13
|
+
name: "wxt:download",
|
|
14
|
+
resolveId(id) {
|
|
15
|
+
if (id.startsWith("url:")) return "\0" + id;
|
|
16
|
+
},
|
|
17
|
+
async load(id) {
|
|
18
|
+
if (!id.startsWith("\0url:")) return;
|
|
19
|
+
return await fetchCached(id.replace("\0url:", ""), config);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
14
22
|
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { download };
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { getEntrypointGlobals } from "../../../utils/globals.mjs";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
|
|
3
|
+
//#region src/core/builders/vite/plugins/entrypointGroupGlobals.ts
|
|
4
|
+
/**
|
|
5
|
+
* Define a set of global variables specific to an entrypoint.
|
|
6
|
+
*/
|
|
7
|
+
function entrypointGroupGlobals(entrypointGroup) {
|
|
8
|
+
return {
|
|
9
|
+
name: "wxt:entrypoint-group-globals",
|
|
10
|
+
config() {
|
|
11
|
+
const define = {};
|
|
12
|
+
let name = Array.isArray(entrypointGroup) ? "html" : entrypointGroup.name;
|
|
13
|
+
for (const global of getEntrypointGlobals(name)) define[`import.meta.env.${global.name}`] = JSON.stringify(global.value);
|
|
14
|
+
return { define };
|
|
15
|
+
}
|
|
16
|
+
};
|
|
16
17
|
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { entrypointGroupGlobals };
|
|
@@ -1,37 +1,32 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
},
|
|
31
|
-
load(id) {
|
|
32
|
-
if (id === resolvedVirtualSetupModule) return setupTemplate;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
2
|
+
|
|
3
|
+
//#region src/core/builders/vite/plugins/extensionApiMock.ts
|
|
4
|
+
/**
|
|
5
|
+
* Mock `wxt/browser` and stub the global `browser`/`chrome` types with a fake version of the extension APIs
|
|
6
|
+
*/
|
|
7
|
+
function extensionApiMock(config) {
|
|
8
|
+
const virtualSetupModule = "virtual:wxt-setup";
|
|
9
|
+
const resolvedVirtualSetupModule = "\0" + virtualSetupModule;
|
|
10
|
+
return {
|
|
11
|
+
name: "wxt:extension-api-mock",
|
|
12
|
+
config() {
|
|
13
|
+
const replacement = path.resolve(config.wxtModuleDir, "dist/virtual/mock-browser");
|
|
14
|
+
return {
|
|
15
|
+
test: { setupFiles: [virtualSetupModule] },
|
|
16
|
+
resolve: { alias: [{
|
|
17
|
+
find: "wxt/browser",
|
|
18
|
+
replacement
|
|
19
|
+
}] },
|
|
20
|
+
ssr: { noExternal: ["wxt"] }
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
resolveId(id) {
|
|
24
|
+
if (id.endsWith(virtualSetupModule)) return resolvedVirtualSetupModule;
|
|
25
|
+
},
|
|
26
|
+
load(id) {
|
|
27
|
+
if (id === resolvedVirtualSetupModule) return setupTemplate;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
35
30
|
}
|
|
36
31
|
const setupTemplate = `
|
|
37
32
|
import { vi } from 'vitest';
|
|
@@ -40,3 +35,6 @@ const setupTemplate = `
|
|
|
40
35
|
vi.stubGlobal("chrome", fakeBrowser);
|
|
41
36
|
vi.stubGlobal("browser", fakeBrowser);
|
|
42
37
|
`;
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { extensionApiMock };
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { getGlobals } from "../../../utils/globals.mjs";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
};
|
|
2
|
+
|
|
3
|
+
//#region src/core/builders/vite/plugins/globals.ts
|
|
4
|
+
function globals(config) {
|
|
5
|
+
return {
|
|
6
|
+
name: "wxt:globals",
|
|
7
|
+
config() {
|
|
8
|
+
const define = {};
|
|
9
|
+
for (const global of getGlobals(config)) define[`import.meta.env.${global.name}`] = JSON.stringify(global.value);
|
|
10
|
+
return { define };
|
|
11
|
+
}
|
|
12
|
+
};
|
|
15
13
|
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { globals };
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
//#region src/core/builders/vite/plugins/iifeFooter.ts
|
|
2
|
+
/**
|
|
3
|
+
* Add a footer with the returned value so it can return values to `scripting.executeScript`
|
|
4
|
+
* Footer is added a part of esbuild to make sure it's not minified. It
|
|
5
|
+
* get's removed if added to `build.rollupOptions.output.footer`
|
|
6
|
+
* See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/executeScript#return_value
|
|
7
|
+
*/
|
|
8
|
+
function iifeFooter(iifeReturnValueName) {
|
|
9
|
+
return {
|
|
10
|
+
name: "wxt:iife-footer",
|
|
11
|
+
generateBundle(_, bundle) {
|
|
12
|
+
for (const chunk of Object.values(bundle)) if (chunk.type === "chunk" && chunk.isEntry) chunk.code += `${iifeReturnValueName};`;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
12
15
|
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { iifeFooter };
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { devHtmlPrerender, pointToDevServer } from "./devHtmlPrerender.mjs";
|
|
2
|
+
import { devServerGlobals } from "./devServerGlobals.mjs";
|
|
3
|
+
import { download } from "./download.mjs";
|
|
4
|
+
import { resolveVirtualModules } from "./resolveVirtualModules.mjs";
|
|
5
|
+
import { tsconfigPaths } from "./tsconfigPaths.mjs";
|
|
6
|
+
import { noopBackground } from "./noopBackground.mjs";
|
|
7
|
+
import { cssEntrypoints } from "./cssEntrypoints.mjs";
|
|
8
|
+
import { bundleAnalysis } from "./bundleAnalysis.mjs";
|
|
9
|
+
import { globals } from "./globals.mjs";
|
|
10
|
+
import { extensionApiMock } from "./extensionApiMock.mjs";
|
|
11
|
+
import { entrypointGroupGlobals } from "./entrypointGroupGlobals.mjs";
|
|
12
|
+
import { defineImportMeta } from "./defineImportMeta.mjs";
|
|
13
|
+
import { removeEntrypointMainFunction } from "./removeEntrypointMainFunction.mjs";
|
|
14
|
+
import { wxtPluginLoader } from "./wxtPluginLoader.mjs";
|
|
15
|
+
import { resolveAppConfig } from "./resolveAppConfig.mjs";
|
|
16
|
+
import { iifeFooter } from "./iifeFooter.mjs";
|
|
17
|
+
|
|
18
|
+
export { };
|