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,12 +1,17 @@
|
|
|
1
|
+
import { wxt } from "../wxt.mjs";
|
|
1
2
|
import { createWslRunner } from "./wsl.mjs";
|
|
2
3
|
import { createWebExtRunner } from "./web-ext.mjs";
|
|
3
4
|
import { createSafariRunner } from "./safari.mjs";
|
|
4
5
|
import { createManualRunner } from "./manual.mjs";
|
|
5
6
|
import { isWsl } from "../utils/wsl.mjs";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
|
|
8
|
+
//#region src/core/runners/index.ts
|
|
9
|
+
async function createExtensionRunner() {
|
|
10
|
+
if (wxt.config.browser === "safari") return createSafariRunner();
|
|
11
|
+
if (await isWsl()) return createWslRunner();
|
|
12
|
+
if (wxt.config.runnerConfig.config?.disabled) return createManualRunner();
|
|
13
|
+
return createWebExtRunner();
|
|
12
14
|
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { createExtensionRunner };
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { relative } from "node:path";
|
|
2
1
|
import { wxt } from "../wxt.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
import { relative } from "node:path";
|
|
3
|
+
|
|
4
|
+
//#region src/core/runners/manual.ts
|
|
5
|
+
/**
|
|
6
|
+
* The manual runner tells the user to load the unpacked extension manually.
|
|
7
|
+
*/
|
|
8
|
+
function createManualRunner() {
|
|
9
|
+
return {
|
|
10
|
+
async openBrowser() {
|
|
11
|
+
wxt.logger.info(`Load "${relative(process.cwd(), wxt.config.outDir)}" as an unpacked extension manually`);
|
|
12
|
+
},
|
|
13
|
+
async closeBrowser() {}
|
|
14
|
+
};
|
|
16
15
|
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { createManualRunner };
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { relative } from "node:path";
|
|
2
1
|
import { wxt } from "../wxt.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
import { relative } from "node:path";
|
|
3
|
+
|
|
4
|
+
//#region src/core/runners/safari.ts
|
|
5
|
+
/**
|
|
6
|
+
* The Safari runner just logs a warning message because `web-ext` doesn't work with Safari.
|
|
7
|
+
*/
|
|
8
|
+
function createSafariRunner() {
|
|
9
|
+
return {
|
|
10
|
+
async openBrowser() {
|
|
11
|
+
wxt.logger.warn(`Cannot Safari using web-ext. Load "${relative(process.cwd(), wxt.config.outDir)}" as an unpacked extension manually`);
|
|
12
|
+
},
|
|
13
|
+
async closeBrowser() {}
|
|
14
|
+
};
|
|
16
15
|
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { createSafariRunner };
|
|
@@ -1,88 +1,67 @@
|
|
|
1
1
|
import { formatDuration } from "../utils/time.mjs";
|
|
2
|
-
import defu from "defu";
|
|
3
2
|
import { wxt } from "../wxt.mjs";
|
|
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
|
-
|
|
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
|
-
// Don't call `process.exit(0)` after starting web-ext
|
|
60
|
-
shouldExitProgram: false
|
|
61
|
-
};
|
|
62
|
-
wxt.logger.debug("web-ext config:", finalConfig);
|
|
63
|
-
wxt.logger.debug("web-ext options:", options);
|
|
64
|
-
const webExt = await import("web-ext-run");
|
|
65
|
-
runner = await webExt.default.cmd.run(finalConfig, options);
|
|
66
|
-
const duration = Date.now() - startTime;
|
|
67
|
-
wxt.logger.success(`Opened browser in ${formatDuration(duration)}`);
|
|
68
|
-
},
|
|
69
|
-
async closeBrowser() {
|
|
70
|
-
return await runner?.exit();
|
|
71
|
-
}
|
|
72
|
-
};
|
|
3
|
+
import defu from "defu";
|
|
4
|
+
|
|
5
|
+
//#region src/core/runners/web-ext.ts
|
|
6
|
+
/**
|
|
7
|
+
* Create an `ExtensionRunner` backed by `web-ext`.
|
|
8
|
+
*/
|
|
9
|
+
function createWebExtRunner() {
|
|
10
|
+
let runner;
|
|
11
|
+
return {
|
|
12
|
+
canOpen() {
|
|
13
|
+
return true;
|
|
14
|
+
},
|
|
15
|
+
async openBrowser() {
|
|
16
|
+
const startTime = Date.now();
|
|
17
|
+
if (wxt.config.browser === "firefox" && wxt.config.manifestVersion === 3) throw Error("Dev mode does not support Firefox MV3. For alternatives, see https://github.com/wxt-dev/wxt/issues/230#issuecomment-1806881653");
|
|
18
|
+
const webExtLogger = await import("web-ext-run/util/logger");
|
|
19
|
+
webExtLogger.consoleStream.write = ({ level, msg, name }) => {
|
|
20
|
+
if (level >= ERROR_LOG_LEVEL) wxt.logger.error(name, msg);
|
|
21
|
+
if (level >= WARN_LOG_LEVEL) wxt.logger.warn(msg);
|
|
22
|
+
};
|
|
23
|
+
const wxtUserConfig = wxt.config.runnerConfig.config;
|
|
24
|
+
const finalConfig = {
|
|
25
|
+
browserConsole: wxtUserConfig?.openConsole,
|
|
26
|
+
devtools: wxtUserConfig?.openDevtools,
|
|
27
|
+
startUrl: wxtUserConfig?.startUrls,
|
|
28
|
+
keepProfileChanges: wxtUserConfig?.keepProfileChanges,
|
|
29
|
+
chromiumPort: wxtUserConfig?.chromiumPort,
|
|
30
|
+
...wxt.config.browser === "firefox" ? {
|
|
31
|
+
firefox: wxtUserConfig?.binaries?.firefox,
|
|
32
|
+
firefoxProfile: wxtUserConfig?.firefoxProfile,
|
|
33
|
+
pref: wxtUserConfig?.firefoxPref,
|
|
34
|
+
args: wxtUserConfig?.firefoxArgs
|
|
35
|
+
} : {
|
|
36
|
+
chromiumBinary: wxtUserConfig?.binaries?.[wxt.config.browser],
|
|
37
|
+
chromiumProfile: wxtUserConfig?.chromiumProfile,
|
|
38
|
+
chromiumPref: defu(wxtUserConfig?.chromiumPref, DEFAULT_CHROMIUM_PREFS),
|
|
39
|
+
args: ["--unsafely-disable-devtools-self-xss-warnings", ...wxtUserConfig?.chromiumArgs ?? []]
|
|
40
|
+
},
|
|
41
|
+
target: wxt.config.browser === "firefox" ? "firefox-desktop" : "chromium",
|
|
42
|
+
sourceDir: wxt.config.outDir,
|
|
43
|
+
noReloadManagerExtension: true,
|
|
44
|
+
noReload: true,
|
|
45
|
+
noInput: true
|
|
46
|
+
};
|
|
47
|
+
const options = { shouldExitProgram: false };
|
|
48
|
+
wxt.logger.debug("web-ext config:", finalConfig);
|
|
49
|
+
wxt.logger.debug("web-ext options:", options);
|
|
50
|
+
runner = await (await import("web-ext-run")).default.cmd.run(finalConfig, options);
|
|
51
|
+
const duration = Date.now() - startTime;
|
|
52
|
+
wxt.logger.success(`Opened browser in ${formatDuration(duration)}`);
|
|
53
|
+
},
|
|
54
|
+
async closeBrowser() {
|
|
55
|
+
return await runner?.exit();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
73
58
|
}
|
|
74
59
|
const WARN_LOG_LEVEL = 40;
|
|
75
60
|
const ERROR_LOG_LEVEL = 50;
|
|
76
|
-
const DEFAULT_CHROMIUM_PREFS = {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// Was renamed at some point, see:
|
|
84
|
-
// https://github.com/wxt-dev/wxt/issues/912#issuecomment-2284288171
|
|
85
|
-
"skip-content-scripts": false
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
61
|
+
const DEFAULT_CHROMIUM_PREFS = { devtools: { synced_preferences_sync_disabled: {
|
|
62
|
+
skipContentScripts: false,
|
|
63
|
+
"skip-content-scripts": false
|
|
64
|
+
} } };
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { createWebExtRunner };
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { relative } from "node:path";
|
|
2
1
|
import { wxt } from "../wxt.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
import { relative } from "node:path";
|
|
3
|
+
|
|
4
|
+
//#region src/core/runners/wsl.ts
|
|
5
|
+
/**
|
|
6
|
+
* The WSL runner just logs a warning message because `web-ext` doesn't work in WSL.
|
|
7
|
+
*/
|
|
8
|
+
function createWslRunner() {
|
|
9
|
+
return {
|
|
10
|
+
async openBrowser() {
|
|
11
|
+
wxt.logger.warn(`Cannot open browser when using WSL. Load "${relative(process.cwd(), wxt.config.outDir)}" as an unpacked extension manually`);
|
|
12
|
+
},
|
|
13
|
+
async closeBrowser() {}
|
|
14
|
+
};
|
|
16
15
|
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { createWslRunner };
|
|
@@ -1,16 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
//#region src/core/utils/arrays.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if `predicate` returns truthy for all elements of the array.
|
|
4
|
+
*/
|
|
5
|
+
function every(array, predicate) {
|
|
6
|
+
for (let i = 0; i < array.length; i++) if (!predicate(array[i], i)) return false;
|
|
7
|
+
return true;
|
|
5
8
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Returns true when any of the predicates return true;
|
|
11
|
+
*/
|
|
12
|
+
function some(array, predicate) {
|
|
13
|
+
for (let i = 0; i < array.length; i++) if (predicate(array[i], i)) return true;
|
|
14
|
+
return false;
|
|
10
15
|
}
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Convert an item or array to an array.
|
|
18
|
+
*/
|
|
19
|
+
function toArray(a) {
|
|
20
|
+
return Array.isArray(a) ? a : [a];
|
|
13
21
|
}
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
function filterTruthy(array) {
|
|
23
|
+
return array.filter((item) => !!item);
|
|
16
24
|
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { every, filterTruthy, some, toArray };
|
|
@@ -1,47 +1,51 @@
|
|
|
1
|
+
import { toArray } from "../arrays.mjs";
|
|
2
|
+
import { wxt } from "../../wxt.mjs";
|
|
1
3
|
import { getPublicFiles } from "../fs.mjs";
|
|
2
4
|
import fs from "fs-extra";
|
|
3
5
|
import { dirname, resolve } from "path";
|
|
4
6
|
import pc from "picocolors";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
7
|
+
|
|
8
|
+
//#region src/core/utils/building/build-entrypoints.ts
|
|
9
|
+
async function buildEntrypoints(groups, spinner) {
|
|
10
|
+
const steps = [];
|
|
11
|
+
for (let i = 0; i < groups.length; i++) {
|
|
12
|
+
const group = groups[i];
|
|
13
|
+
const groupNames = toArray(group).map((e) => e.name);
|
|
14
|
+
const groupNameColored = groupNames.join(pc.dim(", "));
|
|
15
|
+
spinner.text = pc.dim(`[${i + 1}/${groups.length}]`) + ` ${groupNameColored}`;
|
|
16
|
+
try {
|
|
17
|
+
steps.push(await wxt.builder.build(group));
|
|
18
|
+
} catch (err) {
|
|
19
|
+
spinner.stop().clear();
|
|
20
|
+
wxt.logger.error(err);
|
|
21
|
+
throw Error(`Failed to build ${groupNames.join(", ")}`, { cause: err });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
publicAssets: await copyPublicDirectory(),
|
|
26
|
+
steps
|
|
27
|
+
};
|
|
24
28
|
}
|
|
25
29
|
async function copyPublicDirectory() {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
return publicAssets;
|
|
30
|
+
const files = (await getPublicFiles()).map((file) => ({
|
|
31
|
+
absoluteSrc: resolve(wxt.config.publicDir, file),
|
|
32
|
+
relativeDest: file
|
|
33
|
+
}));
|
|
34
|
+
await wxt.hooks.callHook("build:publicAssets", wxt, files);
|
|
35
|
+
if (files.length === 0) return [];
|
|
36
|
+
const publicAssets = [];
|
|
37
|
+
for (const file of files) {
|
|
38
|
+
const absoluteDest = resolve(wxt.config.outDir, file.relativeDest);
|
|
39
|
+
await fs.ensureDir(dirname(absoluteDest));
|
|
40
|
+
if ("absoluteSrc" in file) await fs.copyFile(file.absoluteSrc, absoluteDest);
|
|
41
|
+
else await fs.writeFile(absoluteDest, file.contents, "utf8");
|
|
42
|
+
publicAssets.push({
|
|
43
|
+
type: "asset",
|
|
44
|
+
fileName: file.relativeDest
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return publicAssets;
|
|
47
48
|
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { buildEntrypoints };
|
|
@@ -1,109 +1,88 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { normalizePath } from "../paths.mjs";
|
|
2
|
+
import { every, some } from "../arrays.mjs";
|
|
3
3
|
import { wxt } from "../../wxt.mjs";
|
|
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
|
-
|
|
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
|
-
if (isOnlyContentScripts) {
|
|
70
|
-
return {
|
|
71
|
-
type: "content-script-reload",
|
|
72
|
-
cachedOutput: unchangedOutput,
|
|
73
|
-
changedSteps: changedOutput.steps,
|
|
74
|
-
rebuildGroups: changedOutput.steps.map((step) => step.entrypoints)
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
type: "extension-reload",
|
|
79
|
-
cachedOutput: unchangedOutput,
|
|
80
|
-
rebuildGroups: changedOutput.steps.map((step) => step.entrypoints)
|
|
81
|
-
};
|
|
4
|
+
|
|
5
|
+
//#region src/core/utils/building/detect-dev-changes.ts
|
|
6
|
+
/**
|
|
7
|
+
* Compare the changed files vs the build output and determine what kind of reload needs to happen:
|
|
8
|
+
*
|
|
9
|
+
* - Do nothing
|
|
10
|
+
* - CSS or JS file associated with an HTML page is changed - this is handled automatically by the
|
|
11
|
+
* dev server
|
|
12
|
+
* - Change isn't used by any of the entrypoints
|
|
13
|
+
* - Reload Content script
|
|
14
|
+
* - CSS or JS file associated with a content script
|
|
15
|
+
* - Background script will be told to reload the content script
|
|
16
|
+
* - Reload HTML file
|
|
17
|
+
* - HTML file itself is saved - HMR doesn't handle this because the HTML pages are pre-rendered
|
|
18
|
+
* - Chrome is OK reloading the page when the HTML file is changed without reloading the whole
|
|
19
|
+
* extension. Not sure about firefox, this might need to change to an extension reload
|
|
20
|
+
* - Reload extension
|
|
21
|
+
* - Background script is changed
|
|
22
|
+
* - Manifest is different
|
|
23
|
+
* - Restart browser
|
|
24
|
+
* - web-ext.config.ts (runner config changes)
|
|
25
|
+
* - Full dev server restart
|
|
26
|
+
* - wxt.config.ts (main config file)
|
|
27
|
+
* - modules/* (any file related to WXT modules)
|
|
28
|
+
* - .env (environment variable changed could effect build)
|
|
29
|
+
*/
|
|
30
|
+
function detectDevChanges(changedFiles, currentOutput) {
|
|
31
|
+
if (some(changedFiles, (file) => file === wxt.config.userConfigMetadata.configFile)) return { type: "full-restart" };
|
|
32
|
+
if (some(changedFiles, (file) => file.startsWith(wxt.config.modulesDir))) return { type: "full-restart" };
|
|
33
|
+
if (some(changedFiles, (file) => file === wxt.config.runnerConfig.configFile)) return { type: "browser-restart" };
|
|
34
|
+
const changedSteps = new Set(changedFiles.flatMap((changedFile) => findEffectedSteps(changedFile, currentOutput)));
|
|
35
|
+
if (changedSteps.size === 0) if (some(changedFiles, (file) => file.startsWith(wxt.config.publicDir))) return {
|
|
36
|
+
type: "extension-reload",
|
|
37
|
+
rebuildGroups: [],
|
|
38
|
+
cachedOutput: currentOutput
|
|
39
|
+
};
|
|
40
|
+
else return { type: "no-change" };
|
|
41
|
+
const unchangedOutput = {
|
|
42
|
+
manifest: currentOutput.manifest,
|
|
43
|
+
steps: [],
|
|
44
|
+
publicAssets: [...currentOutput.publicAssets]
|
|
45
|
+
};
|
|
46
|
+
const changedOutput = {
|
|
47
|
+
manifest: currentOutput.manifest,
|
|
48
|
+
steps: [],
|
|
49
|
+
publicAssets: []
|
|
50
|
+
};
|
|
51
|
+
for (const step of currentOutput.steps) if (changedSteps.has(step)) changedOutput.steps.push(step);
|
|
52
|
+
else unchangedOutput.steps.push(step);
|
|
53
|
+
if (changedFiles.length > 0 && every(changedFiles, (file) => file.endsWith(".html"))) return {
|
|
54
|
+
type: "html-reload",
|
|
55
|
+
cachedOutput: unchangedOutput,
|
|
56
|
+
rebuildGroups: changedOutput.steps.map((step) => step.entrypoints)
|
|
57
|
+
};
|
|
58
|
+
if (changedOutput.steps.length > 0 && every(changedOutput.steps.flatMap((step) => step.entrypoints), (entry) => entry.type === "content-script")) return {
|
|
59
|
+
type: "content-script-reload",
|
|
60
|
+
cachedOutput: unchangedOutput,
|
|
61
|
+
changedSteps: changedOutput.steps,
|
|
62
|
+
rebuildGroups: changedOutput.steps.map((step) => step.entrypoints)
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
type: "extension-reload",
|
|
66
|
+
cachedOutput: unchangedOutput,
|
|
67
|
+
rebuildGroups: changedOutput.steps.map((step) => step.entrypoints)
|
|
68
|
+
};
|
|
82
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* For a single change, return all the step of the build output that were effected by it.
|
|
72
|
+
*/
|
|
83
73
|
function findEffectedSteps(changedFile, currentOutput) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
case "chunk": {
|
|
96
|
-
const modulePaths = chunk.moduleIds.map((path) => path.split("?")[0]);
|
|
97
|
-
return modulePaths.includes(changedPath);
|
|
98
|
-
}
|
|
99
|
-
default: {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
for (const step of currentOutput.steps) {
|
|
105
|
-
const effectedChunk = step.chunks.find((chunk) => isChunkEffected(chunk));
|
|
106
|
-
if (effectedChunk) changes.push(step);
|
|
107
|
-
}
|
|
108
|
-
return changes;
|
|
74
|
+
const changes = [];
|
|
75
|
+
const changedPath = normalizePath(changedFile);
|
|
76
|
+
const isChunkEffected = (chunk) => {
|
|
77
|
+
switch (chunk.type) {
|
|
78
|
+
case "asset": return changedPath.replace("/index.html", ".html").endsWith(chunk.fileName);
|
|
79
|
+
case "chunk": return chunk.moduleIds.map((path) => path.split("?")[0]).includes(changedPath);
|
|
80
|
+
default: return false;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
for (const step of currentOutput.steps) if (step.chunks.find((chunk) => isChunkEffected(chunk))) changes.push(step);
|
|
84
|
+
return changes;
|
|
109
85
|
}
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
export { detectDevChanges };
|