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,264 +1,253 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import chokidar from "chokidar";
|
|
1
|
+
import { unnormalizePath } from "./utils/paths.mjs";
|
|
3
2
|
import { getEntrypointBundlePath, isHtmlEntrypoint } from "./utils/entrypoints.mjs";
|
|
4
|
-
import {
|
|
5
|
-
getContentScriptCssFiles,
|
|
6
|
-
getContentScriptsCssMap
|
|
7
|
-
} from "./utils/manifest.mjs";
|
|
8
|
-
import {
|
|
9
|
-
internalBuild,
|
|
10
|
-
detectDevChanges,
|
|
11
|
-
rebuild,
|
|
12
|
-
findEntrypoints
|
|
13
|
-
} from "./utils/building/index.mjs";
|
|
14
|
-
import { createExtensionRunner } from "./runners/index.mjs";
|
|
15
|
-
import { Mutex } from "async-mutex";
|
|
16
|
-
import pc from "picocolors";
|
|
17
|
-
import { relative } from "node:path";
|
|
18
3
|
import { deinitWxtModules, initWxtModules, registerWxt, wxt } from "./wxt.mjs";
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} from "./utils/
|
|
4
|
+
import { detectDevChanges } from "./utils/building/detect-dev-changes.mjs";
|
|
5
|
+
import { findEntrypoints } from "./utils/building/find-entrypoints.mjs";
|
|
6
|
+
import { getContentScriptJs, mapWxtOptionsToRegisteredContentScript } from "./utils/content-scripts.mjs";
|
|
7
|
+
import { getContentScriptCssFiles, getContentScriptsCssMap } from "./utils/manifest.mjs";
|
|
8
|
+
import { rebuild } from "./utils/building/rebuild.mjs";
|
|
9
|
+
import { internalBuild } from "./utils/building/internal-build.mjs";
|
|
10
|
+
import "./utils/building/index.mjs";
|
|
11
|
+
import { createExtensionRunner } from "./runners/index.mjs";
|
|
24
12
|
import { createKeyboardShortcuts } from "./keyboard-shortcuts.mjs";
|
|
25
13
|
import { isBabelSyntaxError, logBabelSyntaxError } from "./utils/syntax-errors.mjs";
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
14
|
+
import { relative } from "node:path";
|
|
15
|
+
import pc from "picocolors";
|
|
16
|
+
import { debounce } from "perfect-debounce";
|
|
17
|
+
import chokidar from "chokidar";
|
|
18
|
+
import { Mutex } from "async-mutex";
|
|
19
|
+
|
|
20
|
+
//#region src/core/create-server.ts
|
|
21
|
+
/**
|
|
22
|
+
* Creates a dev server and pre-builds all the files that need to exist before loading the extension.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const server = await wxt.createServer({
|
|
26
|
+
* // Enter config...
|
|
27
|
+
* });
|
|
28
|
+
* await server.start();
|
|
29
|
+
*/
|
|
30
|
+
async function createServer(inlineConfig) {
|
|
31
|
+
await registerWxt("serve", inlineConfig);
|
|
32
|
+
wxt.server = await createServerInternal();
|
|
33
|
+
await wxt.hooks.callHook("server:created", wxt, wxt.server);
|
|
34
|
+
return wxt.server;
|
|
31
35
|
}
|
|
32
36
|
async function createServerInternal() {
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
};
|
|
145
|
-
builderServer.on?.("close", () => keyboardShortcuts.stop());
|
|
146
|
-
return server;
|
|
37
|
+
const getServerInfo = () => {
|
|
38
|
+
const { host, port, origin } = wxt.config.dev.server;
|
|
39
|
+
return {
|
|
40
|
+
host,
|
|
41
|
+
port,
|
|
42
|
+
origin
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
let [runner, builderServer] = await Promise.all([createExtensionRunner(), wxt.builder.createServer(getServerInfo())]);
|
|
46
|
+
let wasStopped = false;
|
|
47
|
+
const server = {
|
|
48
|
+
get host() {
|
|
49
|
+
return getServerInfo().host;
|
|
50
|
+
},
|
|
51
|
+
get port() {
|
|
52
|
+
return getServerInfo().port;
|
|
53
|
+
},
|
|
54
|
+
get origin() {
|
|
55
|
+
return getServerInfo().origin;
|
|
56
|
+
},
|
|
57
|
+
get watcher() {
|
|
58
|
+
return builderServer.watcher;
|
|
59
|
+
},
|
|
60
|
+
get ws() {
|
|
61
|
+
return builderServer.ws;
|
|
62
|
+
},
|
|
63
|
+
currentOutput: void 0,
|
|
64
|
+
async start() {
|
|
65
|
+
if (wasStopped) {
|
|
66
|
+
await wxt.reloadConfig();
|
|
67
|
+
runner = await createExtensionRunner();
|
|
68
|
+
builderServer = await wxt.builder.createServer(getServerInfo());
|
|
69
|
+
await initWxtModules();
|
|
70
|
+
}
|
|
71
|
+
await builderServer.listen();
|
|
72
|
+
const hostInfo = server.host === "localhost" ? "" : ` (listening on ${server.host})`;
|
|
73
|
+
wxt.logger.success(`Started dev server @ ${server.origin}${hostInfo}`);
|
|
74
|
+
await wxt.hooks.callHook("server:started", wxt, server);
|
|
75
|
+
server.ws.on("wxt:background-initialized", () => {
|
|
76
|
+
if (server.currentOutput == null) return;
|
|
77
|
+
reloadContentScripts(server.currentOutput.steps, server);
|
|
78
|
+
});
|
|
79
|
+
await buildAndOpenBrowser();
|
|
80
|
+
const reloadOnChange = createFileReloader(server);
|
|
81
|
+
server.watcher.on("all", async (...args) => {
|
|
82
|
+
await reloadOnChange(args[0], args[1]);
|
|
83
|
+
keyboardShortcuts.start();
|
|
84
|
+
});
|
|
85
|
+
keyboardShortcuts.printHelp({ canReopenBrowser: !wxt.config.runnerConfig.config.disabled && !!runner.canOpen?.() });
|
|
86
|
+
},
|
|
87
|
+
async stop() {
|
|
88
|
+
wasStopped = true;
|
|
89
|
+
keyboardShortcuts.stop();
|
|
90
|
+
await runner.closeBrowser();
|
|
91
|
+
await builderServer.close();
|
|
92
|
+
await wxt.hooks.callHook("server:closed", wxt, server);
|
|
93
|
+
deinitWxtModules();
|
|
94
|
+
server.currentOutput = void 0;
|
|
95
|
+
},
|
|
96
|
+
async restart() {
|
|
97
|
+
await server.stop();
|
|
98
|
+
await server.start();
|
|
99
|
+
},
|
|
100
|
+
transformHtml(url, html, originalUrl) {
|
|
101
|
+
return builderServer.transformHtml(url, html, originalUrl);
|
|
102
|
+
},
|
|
103
|
+
reloadContentScript(payload) {
|
|
104
|
+
server.ws.send("wxt:reload-content-script", payload);
|
|
105
|
+
},
|
|
106
|
+
reloadPage(path) {
|
|
107
|
+
server.ws.send("wxt:reload-page", path);
|
|
108
|
+
},
|
|
109
|
+
reloadExtension() {
|
|
110
|
+
server.ws.send("wxt:reload-extension");
|
|
111
|
+
},
|
|
112
|
+
async restartBrowser() {
|
|
113
|
+
await runner.closeBrowser();
|
|
114
|
+
keyboardShortcuts.stop();
|
|
115
|
+
await wxt.reloadConfig();
|
|
116
|
+
runner = await createExtensionRunner();
|
|
117
|
+
await runner.openBrowser();
|
|
118
|
+
keyboardShortcuts.start();
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const keyboardShortcuts = createKeyboardShortcuts(server);
|
|
122
|
+
const buildAndOpenBrowser = async () => {
|
|
123
|
+
try {
|
|
124
|
+
server.currentOutput = await internalBuild();
|
|
125
|
+
} catch (err) {
|
|
126
|
+
if (!isBabelSyntaxError(err)) throw err;
|
|
127
|
+
logBabelSyntaxError(err);
|
|
128
|
+
wxt.logger.info("Waiting for syntax error to be fixed...");
|
|
129
|
+
await new Promise((resolve) => {
|
|
130
|
+
const watcher = chokidar.watch(err.id, { ignoreInitial: true });
|
|
131
|
+
watcher.on("all", () => {
|
|
132
|
+
watcher.close();
|
|
133
|
+
wxt.logger.info("Syntax error resolved, rebuilding...");
|
|
134
|
+
resolve();
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
return buildAndOpenBrowser();
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
server.watcher.add(getExternalOutputDependencies(server));
|
|
141
|
+
} catch (err) {
|
|
142
|
+
wxt.config.logger.warn("Failed to register additional file paths:", err);
|
|
143
|
+
}
|
|
144
|
+
await runner.openBrowser();
|
|
145
|
+
};
|
|
146
|
+
builderServer.on?.("close", () => keyboardShortcuts.stop());
|
|
147
|
+
return server;
|
|
147
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Returns a function responsible for reloading different parts of the extension when a file
|
|
151
|
+
* changes.
|
|
152
|
+
*/
|
|
148
153
|
function createFileReloader(server) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
} catch {
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
await reloading.catch((error) => {
|
|
204
|
-
if (!isBabelSyntaxError(error)) {
|
|
205
|
-
throw error;
|
|
206
|
-
}
|
|
207
|
-
logBabelSyntaxError(error);
|
|
208
|
-
});
|
|
209
|
-
};
|
|
210
|
-
return debounce(cb, wxt.config.dev.server.watchDebounce, {
|
|
211
|
-
leading: true,
|
|
212
|
-
trailing: false
|
|
213
|
-
});
|
|
154
|
+
const fileChangedMutex = new Mutex();
|
|
155
|
+
const changeQueue = [];
|
|
156
|
+
const cb = async (event, path) => {
|
|
157
|
+
changeQueue.push([event, path]);
|
|
158
|
+
await fileChangedMutex.runExclusive(async () => {
|
|
159
|
+
if (server.currentOutput == null) return;
|
|
160
|
+
const fileChanges = changeQueue.splice(0, changeQueue.length).map(([_, file]) => file);
|
|
161
|
+
if (fileChanges.length === 0) return;
|
|
162
|
+
await wxt.reloadConfig();
|
|
163
|
+
const changes = detectDevChanges(fileChanges, server.currentOutput);
|
|
164
|
+
if (changes.type === "no-change") return;
|
|
165
|
+
if (changes.type === "full-restart") {
|
|
166
|
+
wxt.logger.info("Config changed, restarting server...");
|
|
167
|
+
server.restart();
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (changes.type === "browser-restart") {
|
|
171
|
+
wxt.logger.info("Runner config changed, restarting browser...");
|
|
172
|
+
server.restartBrowser();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
wxt.logger.info(`Changed: ${Array.from(new Set(fileChanges)).map((file) => pc.dim(relative(wxt.config.root, file))).join(", ")}`);
|
|
176
|
+
const allEntrypoints = await findEntrypoints();
|
|
177
|
+
try {
|
|
178
|
+
const { output: newOutput } = await rebuild(allEntrypoints, changes.rebuildGroups, changes.cachedOutput);
|
|
179
|
+
server.currentOutput = newOutput;
|
|
180
|
+
switch (changes.type) {
|
|
181
|
+
case "extension-reload":
|
|
182
|
+
server.reloadExtension();
|
|
183
|
+
wxt.logger.success(`Reloaded extension`);
|
|
184
|
+
break;
|
|
185
|
+
case "html-reload":
|
|
186
|
+
const { reloadedNames } = reloadHtmlPages(changes.rebuildGroups, server);
|
|
187
|
+
wxt.logger.success(`Reloaded: ${getFilenameList(reloadedNames)}`);
|
|
188
|
+
break;
|
|
189
|
+
case "content-script-reload":
|
|
190
|
+
reloadContentScripts(changes.changedSteps, server);
|
|
191
|
+
const rebuiltNames = changes.rebuildGroups.flat().map((entry) => entry.name);
|
|
192
|
+
wxt.logger.success(`Reloaded: ${getFilenameList(rebuiltNames)}`);
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
} catch {}
|
|
196
|
+
}).catch((error) => {
|
|
197
|
+
if (!isBabelSyntaxError(error)) throw error;
|
|
198
|
+
logBabelSyntaxError(error);
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
return debounce(cb, wxt.config.dev.server.watchDebounce, {
|
|
202
|
+
leading: true,
|
|
203
|
+
trailing: false
|
|
204
|
+
});
|
|
214
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* From the server, tell the client to reload content scripts from the provided build step outputs.
|
|
208
|
+
*/
|
|
215
209
|
function reloadContentScripts(steps, server) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
css
|
|
230
|
-
)
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
} else {
|
|
234
|
-
server.reloadExtension();
|
|
235
|
-
}
|
|
210
|
+
if (wxt.config.manifestVersion === 3) steps.forEach((step) => {
|
|
211
|
+
if (server.currentOutput == null) return;
|
|
212
|
+
const entry = step.entrypoints;
|
|
213
|
+
if (Array.isArray(entry) || entry.type !== "content-script") return;
|
|
214
|
+
const js = getContentScriptJs(wxt.config, entry);
|
|
215
|
+
const cssMap = getContentScriptsCssMap(server.currentOutput, [entry]);
|
|
216
|
+
const css = getContentScriptCssFiles([entry], cssMap);
|
|
217
|
+
server.reloadContentScript({
|
|
218
|
+
registration: entry.options.registration,
|
|
219
|
+
contentScript: mapWxtOptionsToRegisteredContentScript(entry.options, js, css)
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
else server.reloadExtension();
|
|
236
223
|
}
|
|
237
224
|
function reloadHtmlPages(groups, server) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
reloadedNames: htmlEntries.map((entry) => entry.name)
|
|
245
|
-
};
|
|
225
|
+
const htmlEntries = groups.flat().filter(isHtmlEntrypoint);
|
|
226
|
+
htmlEntries.forEach((entry) => {
|
|
227
|
+
const path = getEntrypointBundlePath(entry, wxt.config.outDir, ".html");
|
|
228
|
+
server.reloadPage(path);
|
|
229
|
+
});
|
|
230
|
+
return { reloadedNames: htmlEntries.map((entry) => entry.name) };
|
|
246
231
|
}
|
|
247
232
|
function getFilenameList(names) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
233
|
+
return names.map((name) => {
|
|
234
|
+
return pc.cyan(name);
|
|
235
|
+
}).join(pc.dim(", "));
|
|
251
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Based on the current build output, return a list of files that are:
|
|
239
|
+
* 1. Not in node_modules
|
|
240
|
+
* 2. Not inside project root
|
|
241
|
+
*/
|
|
252
242
|
function getExternalOutputDependencies(server) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
});
|
|
261
|
-
}).filter(
|
|
262
|
-
(file) => !file.includes("node_modules") && !file.startsWith("\0")
|
|
263
|
-
).map(unnormalizePath).filter((file) => !file.startsWith(wxt.config.root)) ?? [];
|
|
243
|
+
return server.currentOutput?.steps.flatMap((step, i) => {
|
|
244
|
+
if (Array.isArray(step.entrypoints) && i === 0) return [];
|
|
245
|
+
return step.chunks.flatMap((chunk) => {
|
|
246
|
+
if (chunk.type === "asset") return [];
|
|
247
|
+
return chunk.moduleIds;
|
|
248
|
+
});
|
|
249
|
+
}).filter((file) => !file.includes("node_modules") && !file.startsWith("\0")).map(unnormalizePath).filter((file) => !file.startsWith(wxt.config.root)) ?? [];
|
|
264
250
|
}
|
|
251
|
+
|
|
252
|
+
//#endregion
|
|
253
|
+
export { createServer };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WebExtConfig } from "../types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/core/define-web-ext-config.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use `defineWebExtConfig` instead. Same function, different name.
|
|
6
|
+
*/
|
|
7
|
+
declare function defineRunnerConfig(config: WebExtConfig): WebExtConfig;
|
|
8
|
+
/**
|
|
9
|
+
* Configure how [`web-ext`](https://github.com/mozilla/web-ext) starts the browser during development.
|
|
10
|
+
*/
|
|
11
|
+
declare function defineWebExtConfig(config: WebExtConfig): WebExtConfig;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { defineRunnerConfig, defineWebExtConfig };
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import consola from "consola";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
|
|
3
|
+
//#region src/core/define-web-ext-config.ts
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use `defineWebExtConfig` instead. Same function, different name.
|
|
6
|
+
*/
|
|
7
|
+
function defineRunnerConfig(config) {
|
|
8
|
+
consola.warn("`defineRunnerConfig` is deprecated, use `defineWebExtConfig` instead. See https://wxt.dev/guide/resources/upgrading.html#v0-19-0-rarr-v0-20-0");
|
|
9
|
+
return defineWebExtConfig(config);
|
|
7
10
|
}
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Configure how [`web-ext`](https://github.com/mozilla/web-ext) starts the browser during development.
|
|
13
|
+
*/
|
|
14
|
+
function defineWebExtConfig(config) {
|
|
15
|
+
return config;
|
|
10
16
|
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { defineRunnerConfig, defineWebExtConfig };
|