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,356 +1,305 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "
|
|
1
|
+
import { normalizePath } from "../../utils/paths.mjs";
|
|
2
|
+
import { getEntrypointBundlePath, isHtmlEntrypoint } from "../../utils/entrypoints.mjs";
|
|
3
|
+
import { devHtmlPrerender } from "./plugins/devHtmlPrerender.mjs";
|
|
4
|
+
import { devServerGlobals } from "./plugins/devServerGlobals.mjs";
|
|
5
|
+
import { download } from "./plugins/download.mjs";
|
|
6
|
+
import { resolveVirtualModules } from "./plugins/resolveVirtualModules.mjs";
|
|
7
|
+
import { tsconfigPaths } from "./plugins/tsconfigPaths.mjs";
|
|
8
|
+
import { noopBackground } from "./plugins/noopBackground.mjs";
|
|
9
|
+
import { cssEntrypoints } from "./plugins/cssEntrypoints.mjs";
|
|
10
|
+
import { bundleAnalysis } from "./plugins/bundleAnalysis.mjs";
|
|
11
|
+
import { globals } from "./plugins/globals.mjs";
|
|
12
|
+
import { entrypointGroupGlobals } from "./plugins/entrypointGroupGlobals.mjs";
|
|
13
|
+
import { defineImportMeta } from "./plugins/defineImportMeta.mjs";
|
|
14
|
+
import { removeEntrypointMainFunction } from "./plugins/removeEntrypointMainFunction.mjs";
|
|
15
|
+
import { wxtPluginLoader } from "./plugins/wxtPluginLoader.mjs";
|
|
16
|
+
import { resolveAppConfig } from "./plugins/resolveAppConfig.mjs";
|
|
17
|
+
import { iifeFooter } from "./plugins/iifeFooter.mjs";
|
|
18
|
+
import "./plugins/index.mjs";
|
|
6
19
|
import { toArray } from "../../utils/arrays.mjs";
|
|
7
20
|
import { safeVarName } from "../../utils/strings.mjs";
|
|
21
|
+
import { createExtensionEnvironment } from "../../utils/environments/extension-environment.mjs";
|
|
22
|
+
import "../../utils/environments/index.mjs";
|
|
23
|
+
import fs from "fs-extra";
|
|
24
|
+
import { dirname, extname, join, relative } from "node:path";
|
|
8
25
|
import { ViteNodeServer } from "vite-node/server";
|
|
9
26
|
import { ViteNodeRunner } from "vite-node/client";
|
|
10
27
|
import { installSourcemapsSupport } from "vite-node/source-map";
|
|
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
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
requireDefaultExport(path, res);
|
|
215
|
-
return res.default;
|
|
216
|
-
},
|
|
217
|
-
async importEntrypoints(paths) {
|
|
218
|
-
const env = createExtensionEnvironment();
|
|
219
|
-
const { runner, server } = await createViteNodeImporter(paths);
|
|
220
|
-
const res = await env.run(
|
|
221
|
-
() => Promise.all(
|
|
222
|
-
paths.map(async (path) => {
|
|
223
|
-
const mod = await runner.executeFile(path);
|
|
224
|
-
requireDefaultExport(path, mod);
|
|
225
|
-
return mod.default;
|
|
226
|
-
})
|
|
227
|
-
)
|
|
228
|
-
);
|
|
229
|
-
await server.close();
|
|
230
|
-
return res;
|
|
231
|
-
},
|
|
232
|
-
async build(group) {
|
|
233
|
-
let entryConfig;
|
|
234
|
-
if (Array.isArray(group)) entryConfig = getMultiPageConfig(group);
|
|
235
|
-
else if (group.type === "content-script-style" || group.type === "unlisted-style")
|
|
236
|
-
entryConfig = getCssConfig(group);
|
|
237
|
-
else entryConfig = getLibModeConfig(group);
|
|
238
|
-
const buildConfig = vite.mergeConfig(await getBaseConfig(), entryConfig);
|
|
239
|
-
await hooks.callHook(
|
|
240
|
-
"vite:build:extendConfig",
|
|
241
|
-
toArray(group),
|
|
242
|
-
buildConfig
|
|
243
|
-
);
|
|
244
|
-
const result = await vite.build(buildConfig);
|
|
245
|
-
const chunks = getBuildOutputChunks(result);
|
|
246
|
-
return {
|
|
247
|
-
entrypoints: group,
|
|
248
|
-
chunks: await moveHtmlFiles(wxtConfig, group, chunks)
|
|
249
|
-
};
|
|
250
|
-
},
|
|
251
|
-
async createServer(info) {
|
|
252
|
-
const serverConfig = {
|
|
253
|
-
server: {
|
|
254
|
-
host: info.host,
|
|
255
|
-
port: info.port,
|
|
256
|
-
strictPort: true,
|
|
257
|
-
origin: info.origin
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
const baseConfig = await getBaseConfig();
|
|
261
|
-
const finalConfig = vite.mergeConfig(baseConfig, serverConfig);
|
|
262
|
-
await hooks.callHook("vite:devServer:extendConfig", finalConfig);
|
|
263
|
-
const viteServer = await vite.createServer(finalConfig);
|
|
264
|
-
const server = {
|
|
265
|
-
async listen() {
|
|
266
|
-
await viteServer.listen(info.port);
|
|
267
|
-
},
|
|
268
|
-
async close() {
|
|
269
|
-
await viteServer.close();
|
|
270
|
-
},
|
|
271
|
-
transformHtml(...args) {
|
|
272
|
-
return viteServer.transformIndexHtml(...args);
|
|
273
|
-
},
|
|
274
|
-
ws: {
|
|
275
|
-
send(message, payload) {
|
|
276
|
-
return viteServer.ws.send(message, payload);
|
|
277
|
-
},
|
|
278
|
-
on(message, cb) {
|
|
279
|
-
viteServer.ws.on(message, cb);
|
|
280
|
-
}
|
|
281
|
-
},
|
|
282
|
-
watcher: viteServer.watcher,
|
|
283
|
-
on(event, cb) {
|
|
284
|
-
viteServer.httpServer?.on(event, cb);
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
return server;
|
|
288
|
-
}
|
|
289
|
-
};
|
|
28
|
+
|
|
29
|
+
//#region src/core/builders/vite/index.ts
|
|
30
|
+
async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
|
|
31
|
+
const vite = await import("vite");
|
|
32
|
+
/**
|
|
33
|
+
* Returns the base vite config shared by all builds based on the inline and user config.
|
|
34
|
+
*/
|
|
35
|
+
const getBaseConfig = async (baseConfigOptions) => {
|
|
36
|
+
const config = await wxtConfig.vite(wxtConfig.env);
|
|
37
|
+
config.root = wxtConfig.root;
|
|
38
|
+
config.configFile = false;
|
|
39
|
+
config.logLevel = "warn";
|
|
40
|
+
config.mode = wxtConfig.mode;
|
|
41
|
+
config.envPrefix ??= ["VITE_", "WXT_"];
|
|
42
|
+
config.build ??= {};
|
|
43
|
+
config.publicDir = wxtConfig.publicDir;
|
|
44
|
+
config.build.copyPublicDir = false;
|
|
45
|
+
config.build.outDir = wxtConfig.outDir;
|
|
46
|
+
config.build.emptyOutDir = false;
|
|
47
|
+
if (config.build.minify == null && wxtConfig.command === "serve") config.build.minify = false;
|
|
48
|
+
if (config.build.sourcemap == null && wxtConfig.command === "serve") config.build.sourcemap = "inline";
|
|
49
|
+
config.server ??= {};
|
|
50
|
+
config.server.watch = { ignored: [`${wxtConfig.outBaseDir}/**`, `${wxtConfig.wxtDir}/**`] };
|
|
51
|
+
config.legacy ??= {};
|
|
52
|
+
config.legacy.skipWebSocketTokenCheck = true;
|
|
53
|
+
const server = getWxtDevServer?.();
|
|
54
|
+
config.plugins ??= [];
|
|
55
|
+
config.plugins.push(download(wxtConfig), devHtmlPrerender(wxtConfig, server), resolveVirtualModules(wxtConfig), devServerGlobals(wxtConfig, server), tsconfigPaths(wxtConfig), noopBackground(), globals(wxtConfig), defineImportMeta(), wxtPluginLoader(wxtConfig), resolveAppConfig(wxtConfig));
|
|
56
|
+
if (wxtConfig.analysis.enabled && !baseConfigOptions?.excludeAnalysisPlugin) config.plugins.push(bundleAnalysis(wxtConfig));
|
|
57
|
+
return config;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Return the basic config for building an entrypoint in [lib mode](https://vitejs.dev/guide/build.html#library-mode).
|
|
61
|
+
*/
|
|
62
|
+
const getLibModeConfig = (entrypoint) => {
|
|
63
|
+
const entry = getRollupEntry(entrypoint);
|
|
64
|
+
const plugins = [entrypointGroupGlobals(entrypoint)];
|
|
65
|
+
const iifeReturnValueName = safeVarName(entrypoint.name);
|
|
66
|
+
if (entrypoint.type === "content-script-style" || entrypoint.type === "unlisted-style") plugins.push(cssEntrypoints(entrypoint, wxtConfig));
|
|
67
|
+
if (entrypoint.type === "content-script" || entrypoint.type === "unlisted-script") plugins.push(iifeFooter(iifeReturnValueName));
|
|
68
|
+
return {
|
|
69
|
+
mode: wxtConfig.mode,
|
|
70
|
+
plugins,
|
|
71
|
+
build: {
|
|
72
|
+
lib: {
|
|
73
|
+
entry,
|
|
74
|
+
formats: ["iife"],
|
|
75
|
+
name: iifeReturnValueName,
|
|
76
|
+
fileName: entrypoint.name
|
|
77
|
+
},
|
|
78
|
+
rollupOptions: { output: {
|
|
79
|
+
entryFileNames: getEntrypointBundlePath(entrypoint, wxtConfig.outDir, ".js"),
|
|
80
|
+
assetFileNames: ({ name }) => {
|
|
81
|
+
if (entrypoint.type === "content-script" && name?.endsWith("css")) return `content-scripts/${entrypoint.name}.[ext]`;
|
|
82
|
+
else return `assets/${entrypoint.name}.[ext]`;
|
|
83
|
+
}
|
|
84
|
+
} }
|
|
85
|
+
},
|
|
86
|
+
define: { "process.env.NODE_ENV": JSON.stringify(wxtConfig.mode) }
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Return the basic config for building multiple entrypoints in [multi-page mode](https://vitejs.dev/guide/build.html#multi-page-app).
|
|
91
|
+
*/
|
|
92
|
+
const getMultiPageConfig = (entrypoints) => {
|
|
93
|
+
const htmlEntrypoints = new Set(entrypoints.filter(isHtmlEntrypoint).map((e) => e.name));
|
|
94
|
+
return {
|
|
95
|
+
mode: wxtConfig.mode,
|
|
96
|
+
plugins: [entrypointGroupGlobals(entrypoints)],
|
|
97
|
+
build: { rollupOptions: {
|
|
98
|
+
input: entrypoints.reduce((input, entry) => {
|
|
99
|
+
input[entry.name] = getRollupEntry(entry);
|
|
100
|
+
return input;
|
|
101
|
+
}, {}),
|
|
102
|
+
output: {
|
|
103
|
+
chunkFileNames: "chunks/[name]-[hash].js",
|
|
104
|
+
entryFileNames: ({ name }) => {
|
|
105
|
+
if (htmlEntrypoints.has(name)) return "chunks/[name]-[hash].js";
|
|
106
|
+
return "[name].js";
|
|
107
|
+
},
|
|
108
|
+
assetFileNames: "assets/[name]-[hash].[ext]"
|
|
109
|
+
}
|
|
110
|
+
} }
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Return the basic config for building a single CSS entrypoint in [multi-page mode](https://vitejs.dev/guide/build.html#multi-page-app).
|
|
115
|
+
*/
|
|
116
|
+
const getCssConfig = (entrypoint) => {
|
|
117
|
+
return {
|
|
118
|
+
mode: wxtConfig.mode,
|
|
119
|
+
plugins: [entrypointGroupGlobals(entrypoint)],
|
|
120
|
+
build: { rollupOptions: {
|
|
121
|
+
input: { [entrypoint.name]: entrypoint.inputPath },
|
|
122
|
+
output: { assetFileNames: () => {
|
|
123
|
+
if (entrypoint.type === "content-script-style") return `content-scripts/${entrypoint.name}.[ext]`;
|
|
124
|
+
else return `assets/${entrypoint.name}.[ext]`;
|
|
125
|
+
} }
|
|
126
|
+
} }
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
const createViteNodeImporter = async (paths) => {
|
|
130
|
+
const baseConfig = await getBaseConfig({ excludeAnalysisPlugin: true });
|
|
131
|
+
baseConfig.optimizeDeps ??= {};
|
|
132
|
+
baseConfig.optimizeDeps.noDiscovery = true;
|
|
133
|
+
baseConfig.optimizeDeps.include = [];
|
|
134
|
+
const envConfig = { plugins: paths.map((path) => removeEntrypointMainFunction(wxtConfig, path)) };
|
|
135
|
+
const config = vite.mergeConfig(baseConfig, envConfig);
|
|
136
|
+
const server = await vite.createServer(config);
|
|
137
|
+
await server.pluginContainer.buildStart({});
|
|
138
|
+
const node = new ViteNodeServer(server);
|
|
139
|
+
installSourcemapsSupport({ getSourceMap: (source) => node.getSourceMap(source) });
|
|
140
|
+
return {
|
|
141
|
+
runner: new ViteNodeRunner({
|
|
142
|
+
root: server.config.root,
|
|
143
|
+
base: server.config.base,
|
|
144
|
+
fetchModule(id) {
|
|
145
|
+
return node.fetchModule(id);
|
|
146
|
+
},
|
|
147
|
+
resolveId(id, importer) {
|
|
148
|
+
return node.resolveId(id, importer);
|
|
149
|
+
}
|
|
150
|
+
}),
|
|
151
|
+
server
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
const requireDefaultExport = (path, mod) => {
|
|
155
|
+
const relativePath = relative(wxtConfig.root, path);
|
|
156
|
+
if (mod?.default == null) {
|
|
157
|
+
const defineFn = relativePath.includes(".content") ? "defineContentScript" : relativePath.includes("background") ? "defineBackground" : "defineUnlistedScript";
|
|
158
|
+
throw Error(`${relativePath}: Default export not found, did you forget to call "export default ${defineFn}(...)"?`);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
return {
|
|
162
|
+
name: "Vite",
|
|
163
|
+
version: vite.version,
|
|
164
|
+
async importEntrypoint(path) {
|
|
165
|
+
const env = createExtensionEnvironment();
|
|
166
|
+
const { runner, server } = await createViteNodeImporter([path]);
|
|
167
|
+
const res = await env.run(() => runner.executeFile(path));
|
|
168
|
+
await server.close();
|
|
169
|
+
requireDefaultExport(path, res);
|
|
170
|
+
return res.default;
|
|
171
|
+
},
|
|
172
|
+
async importEntrypoints(paths) {
|
|
173
|
+
const env = createExtensionEnvironment();
|
|
174
|
+
const { runner, server } = await createViteNodeImporter(paths);
|
|
175
|
+
const res = await env.run(() => Promise.all(paths.map(async (path) => {
|
|
176
|
+
const mod = await runner.executeFile(path);
|
|
177
|
+
requireDefaultExport(path, mod);
|
|
178
|
+
return mod.default;
|
|
179
|
+
})));
|
|
180
|
+
await server.close();
|
|
181
|
+
return res;
|
|
182
|
+
},
|
|
183
|
+
async build(group) {
|
|
184
|
+
let entryConfig;
|
|
185
|
+
if (Array.isArray(group)) entryConfig = getMultiPageConfig(group);
|
|
186
|
+
else if (group.type === "content-script-style" || group.type === "unlisted-style") entryConfig = getCssConfig(group);
|
|
187
|
+
else entryConfig = getLibModeConfig(group);
|
|
188
|
+
const buildConfig = vite.mergeConfig(await getBaseConfig(), entryConfig);
|
|
189
|
+
await hooks.callHook("vite:build:extendConfig", toArray(group), buildConfig);
|
|
190
|
+
return {
|
|
191
|
+
entrypoints: group,
|
|
192
|
+
chunks: await moveHtmlFiles(wxtConfig, group, getBuildOutputChunks(await vite.build(buildConfig)))
|
|
193
|
+
};
|
|
194
|
+
},
|
|
195
|
+
async createServer(info) {
|
|
196
|
+
const serverConfig = { server: {
|
|
197
|
+
host: info.host,
|
|
198
|
+
port: info.port,
|
|
199
|
+
strictPort: true,
|
|
200
|
+
origin: info.origin
|
|
201
|
+
} };
|
|
202
|
+
const baseConfig = await getBaseConfig();
|
|
203
|
+
const finalConfig = vite.mergeConfig(baseConfig, serverConfig);
|
|
204
|
+
await hooks.callHook("vite:devServer:extendConfig", finalConfig);
|
|
205
|
+
const viteServer = await vite.createServer(finalConfig);
|
|
206
|
+
return {
|
|
207
|
+
async listen() {
|
|
208
|
+
await viteServer.listen(info.port);
|
|
209
|
+
},
|
|
210
|
+
async close() {
|
|
211
|
+
await viteServer.close();
|
|
212
|
+
},
|
|
213
|
+
transformHtml(...args) {
|
|
214
|
+
return viteServer.transformIndexHtml(...args);
|
|
215
|
+
},
|
|
216
|
+
ws: {
|
|
217
|
+
send(message, payload) {
|
|
218
|
+
return viteServer.ws.send(message, payload);
|
|
219
|
+
},
|
|
220
|
+
on(message, cb) {
|
|
221
|
+
viteServer.ws.on(message, cb);
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
watcher: viteServer.watcher,
|
|
225
|
+
on(event, cb) {
|
|
226
|
+
viteServer.httpServer?.on(event, cb);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
};
|
|
290
231
|
}
|
|
291
232
|
function getBuildOutputChunks(result) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
233
|
+
if ("on" in result) throw Error("wxt does not support vite watch mode.");
|
|
234
|
+
if (Array.isArray(result)) return result.flatMap(({ output }) => output);
|
|
235
|
+
return result.output;
|
|
295
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Returns the input module ID (virtual or real file) for an entrypoint. The returned string should
|
|
239
|
+
* be passed as an input to rollup.
|
|
240
|
+
*/
|
|
296
241
|
function getRollupEntry(entrypoint) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
return `${moduleId}?${entrypoint.inputPath}`;
|
|
310
|
-
}
|
|
311
|
-
return entrypoint.inputPath;
|
|
242
|
+
let virtualEntrypointType;
|
|
243
|
+
switch (entrypoint.type) {
|
|
244
|
+
case "background":
|
|
245
|
+
case "unlisted-script":
|
|
246
|
+
virtualEntrypointType = entrypoint.type;
|
|
247
|
+
break;
|
|
248
|
+
case "content-script":
|
|
249
|
+
virtualEntrypointType = entrypoint.options.world === "MAIN" ? "content-script-main-world" : "content-script-isolated-world";
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
if (virtualEntrypointType) return `${`virtual:wxt-${virtualEntrypointType}-entrypoint`}?${entrypoint.inputPath}`;
|
|
253
|
+
return entrypoint.inputPath;
|
|
312
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* Ensures the HTML files output by a multipage build are in the correct location. This does two
|
|
257
|
+
* things:
|
|
258
|
+
*
|
|
259
|
+
* 1. Moves the HTML files to their final location at `<outDir>/<entrypoint.name>.html`.
|
|
260
|
+
* 2. Updates the bundle so it summarizes the files correctly in the returned build output.
|
|
261
|
+
*
|
|
262
|
+
* Assets (JS and CSS) are output to the `<outDir>/assets` directory, and don't need to be modified.
|
|
263
|
+
* HTML files access them via absolute URLs, so we don't need to update any import paths in the HTML
|
|
264
|
+
* files either.
|
|
265
|
+
*/
|
|
313
266
|
async function moveHtmlFiles(config, group, chunks) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
fileName: newBundlePath
|
|
337
|
-
};
|
|
338
|
-
})
|
|
339
|
-
);
|
|
340
|
-
removeEmptyDirs(config.outDir);
|
|
341
|
-
return movedChunks;
|
|
267
|
+
if (!Array.isArray(group)) return chunks;
|
|
268
|
+
const entryMap = group.reduce((map, entry) => {
|
|
269
|
+
const a = normalizePath(relative(config.root, entry.inputPath));
|
|
270
|
+
map[a] = entry;
|
|
271
|
+
return map;
|
|
272
|
+
}, {});
|
|
273
|
+
const movedChunks = await Promise.all(chunks.map(async (chunk) => {
|
|
274
|
+
if (!chunk.fileName.endsWith(".html")) return chunk;
|
|
275
|
+
const entry = entryMap[chunk.fileName];
|
|
276
|
+
const oldBundlePath = chunk.fileName;
|
|
277
|
+
const newBundlePath = getEntrypointBundlePath(entry, config.outDir, extname(chunk.fileName));
|
|
278
|
+
const oldAbsPath = join(config.outDir, oldBundlePath);
|
|
279
|
+
const newAbsPath = join(config.outDir, newBundlePath);
|
|
280
|
+
await fs.ensureDir(dirname(newAbsPath));
|
|
281
|
+
await fs.move(oldAbsPath, newAbsPath, { overwrite: true });
|
|
282
|
+
return {
|
|
283
|
+
...chunk,
|
|
284
|
+
fileName: newBundlePath
|
|
285
|
+
};
|
|
286
|
+
}));
|
|
287
|
+
removeEmptyDirs(config.outDir);
|
|
288
|
+
return movedChunks;
|
|
342
289
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
290
|
+
/**
|
|
291
|
+
* Recursively remove all directories that are empty/
|
|
292
|
+
*/
|
|
293
|
+
async function removeEmptyDirs(dir) {
|
|
294
|
+
const files = await fs.readdir(dir);
|
|
295
|
+
for (const file of files) {
|
|
296
|
+
const filePath = join(dir, file);
|
|
297
|
+
if ((await fs.stat(filePath)).isDirectory()) await removeEmptyDirs(filePath);
|
|
298
|
+
}
|
|
299
|
+
try {
|
|
300
|
+
await fs.rmdir(dir);
|
|
301
|
+
} catch {}
|
|
356
302
|
}
|
|
303
|
+
|
|
304
|
+
//#endregion
|
|
305
|
+
export { createViteBuilder };
|