wxt 0.20.13 → 0.20.15
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 +54 -50
- package/dist/cli/commands.mjs +78 -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 +293 -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 +105 -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 +26 -23
- package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +26 -24
- package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +28 -26
- package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +11 -11
- package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +42 -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 +110 -148
- package/dist/core/index.d.mts +9 -0
- package/dist/core/index.mjs +12 -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 +15 -10
- package/dist/core/runners/manual.mjs +13 -14
- package/dist/core/runners/safari.mjs +13 -14
- package/dist/core/runners/web-ext.mjs +62 -83
- package/dist/core/runners/wsl.mjs +13 -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 +278 -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 +86 -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/index.mjs +3 -0
- 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 +9 -5
- package/dist/core/utils/log/printTable.mjs +19 -21
- package/dist/core/utils/manifest.mjs +366 -479
- package/dist/core/utils/minimatch-multiple.mjs +26 -15
- package/dist/core/utils/network.mjs +27 -33
- package/dist/core/utils/number.mjs +7 -3
- package/dist/core/utils/package.mjs +20 -13
- package/dist/core/utils/paths.d.mts +8 -0
- 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 +11 -3
- package/dist/core/wxt.mjs +65 -60
- package/dist/core/{zip.d.ts → zip.d.mts} +6 -2
- package/dist/core/zip.mjs +118 -140
- package/dist/index.d.mts +13 -0
- package/dist/index.mjs +13 -3
- package/dist/{modules.d.ts → modules.d.mts} +14 -16
- package/dist/modules.mjs +179 -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 +1475 -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 +134 -0
- package/dist/utils/content-script-context.mjs +187 -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 +115 -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 +143 -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 +57 -53
- package/dist/virtual/unlisted-script-entrypoint.d.mts +4 -0
- package/dist/virtual/unlisted-script-entrypoint.mjs +35 -43
- package/package.json +56 -50
- 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,492 +1,423 @@
|
|
|
1
|
-
import { loadConfig } from "c12";
|
|
2
|
-
import { resolve as esmResolve } from "import-meta-resolve";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { createFsCache } from "./utils/cache.mjs";
|
|
5
|
-
import consola, { LogLevels } from "consola";
|
|
6
|
-
import defu from "defu";
|
|
7
|
-
import fs from "fs-extra";
|
|
8
1
|
import { normalizePath } from "./utils/paths.mjs";
|
|
9
|
-
import
|
|
2
|
+
import { createFsCache } from "./utils/cache.mjs";
|
|
3
|
+
import "./utils/index.mjs";
|
|
10
4
|
import { builtinModules } from "../builtin-modules/index.mjs";
|
|
11
5
|
import { getEslintVersion } from "./utils/eslint.mjs";
|
|
12
6
|
import { safeStringToNumber } from "./utils/number.mjs";
|
|
13
7
|
import { loadEnv } from "./utils/env.mjs";
|
|
8
|
+
import fs from "fs-extra";
|
|
9
|
+
import glob from "fast-glob";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { loadConfig } from "c12";
|
|
12
|
+
import { resolve as resolve$1 } from "import-meta-resolve";
|
|
13
|
+
import consola, { LogLevels } from "consola";
|
|
14
|
+
import defu from "defu";
|
|
14
15
|
import { getPort } from "get-port-please";
|
|
15
16
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
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
|
-
runnerConfig,
|
|
156
|
-
srcDir,
|
|
157
|
-
typesDir,
|
|
158
|
-
wxtDir,
|
|
159
|
-
zip: resolveZipConfig(root, browser, outBaseDir, mergedConfig),
|
|
160
|
-
analysis: resolveAnalysisConfig(root, mergedConfig),
|
|
161
|
-
userConfigMetadata: userConfigMetadata ?? {},
|
|
162
|
-
alias,
|
|
163
|
-
experimental: defu(mergedConfig.experimental, {}),
|
|
164
|
-
dev: {
|
|
165
|
-
server: devServerConfig,
|
|
166
|
-
reloadCommand
|
|
167
|
-
},
|
|
168
|
-
hooks: mergedConfig.hooks ?? {},
|
|
169
|
-
vite: mergedConfig.vite ?? (() => ({})),
|
|
170
|
-
builtinModules,
|
|
171
|
-
userModules,
|
|
172
|
-
plugins: [],
|
|
173
|
-
...moduleOptions
|
|
174
|
-
};
|
|
17
|
+
|
|
18
|
+
//#region src/core/resolve-config.ts
|
|
19
|
+
/**
|
|
20
|
+
* Given an inline config, discover the config file if necessary, merge the results, resolve any
|
|
21
|
+
* relative paths, and apply any defaults.
|
|
22
|
+
*
|
|
23
|
+
* Inline config always has priority over user config. Cli flags are passed as inline config if set.
|
|
24
|
+
* If unset, undefined is passed in, letting this function decide default values.
|
|
25
|
+
*/
|
|
26
|
+
async function resolveConfig(inlineConfig, command) {
|
|
27
|
+
let userConfig = {};
|
|
28
|
+
let userConfigMetadata;
|
|
29
|
+
if (inlineConfig.configFile !== false) {
|
|
30
|
+
const { config: loadedConfig, ...metadata } = await loadConfig({
|
|
31
|
+
configFile: inlineConfig.configFile,
|
|
32
|
+
name: "wxt",
|
|
33
|
+
cwd: inlineConfig.root ?? process.cwd()
|
|
34
|
+
});
|
|
35
|
+
userConfig = loadedConfig ?? {};
|
|
36
|
+
userConfigMetadata = metadata;
|
|
37
|
+
}
|
|
38
|
+
const mergedConfig = await mergeInlineConfig(inlineConfig, userConfig);
|
|
39
|
+
const debug = mergedConfig.debug ?? false;
|
|
40
|
+
const logger = mergedConfig.logger ?? consola;
|
|
41
|
+
if (debug) logger.level = LogLevels.debug;
|
|
42
|
+
const browser = mergedConfig.browser ?? "chrome";
|
|
43
|
+
const targetBrowsers = mergedConfig.targetBrowsers ?? [];
|
|
44
|
+
if (targetBrowsers.length > 0 && !targetBrowsers.includes(browser)) throw new Error(`Current target browser \`${browser}\` is not in your \`targetBrowsers\` list!`);
|
|
45
|
+
const manifestVersion = mergedConfig.manifestVersion ?? (browser === "firefox" || browser === "safari" ? 2 : 3);
|
|
46
|
+
const mode = mergedConfig.mode ?? COMMAND_MODES[command];
|
|
47
|
+
const env = {
|
|
48
|
+
browser,
|
|
49
|
+
command,
|
|
50
|
+
manifestVersion,
|
|
51
|
+
mode
|
|
52
|
+
};
|
|
53
|
+
loadEnv(mode, browser);
|
|
54
|
+
const root = path.resolve(inlineConfig.root ?? userConfig.root ?? process.cwd());
|
|
55
|
+
const wxtDir = path.resolve(root, ".wxt");
|
|
56
|
+
const wxtModuleDir = resolveWxtModuleDir();
|
|
57
|
+
const srcDir = path.resolve(root, mergedConfig.srcDir ?? root);
|
|
58
|
+
const entrypointsDir = path.resolve(srcDir, mergedConfig.entrypointsDir ?? "entrypoints");
|
|
59
|
+
if (await isDirMissing(entrypointsDir)) logMissingDir(logger, "Entrypoints", entrypointsDir);
|
|
60
|
+
const modulesDir = path.resolve(root, mergedConfig.modulesDir ?? "modules");
|
|
61
|
+
const filterEntrypoints = mergedConfig.filterEntrypoints?.length ? new Set(mergedConfig.filterEntrypoints) : void 0;
|
|
62
|
+
const publicDir = path.resolve(root, mergedConfig.publicDir ?? "public");
|
|
63
|
+
const typesDir = path.resolve(wxtDir, "types");
|
|
64
|
+
const outBaseDir = path.resolve(root, mergedConfig.outDir ?? ".output");
|
|
65
|
+
const modeSuffix = {
|
|
66
|
+
production: "",
|
|
67
|
+
development: "-dev"
|
|
68
|
+
}[mode] ?? `-${mode}`;
|
|
69
|
+
const outDirTemplate = (mergedConfig.outDirTemplate ?? `${browser}-mv${manifestVersion}${modeSuffix}`).replaceAll("{{browser}}", browser).replaceAll("{{manifestVersion}}", manifestVersion.toString()).replaceAll("{{modeSuffix}}", modeSuffix).replaceAll("{{mode}}", mode).replaceAll("{{command}}", command);
|
|
70
|
+
const outDir = path.resolve(outBaseDir, outDirTemplate);
|
|
71
|
+
const reloadCommand = mergedConfig.dev?.reloadCommand ?? "Alt+R";
|
|
72
|
+
if (inlineConfig.runner != null || userConfig.runner != null) logger.warn("`InlineConfig#runner` is deprecated, use `InlineConfig#webExt` instead. See https://wxt.dev/guide/resources/upgrading.html#v0-19-0-rarr-v0-20-0");
|
|
73
|
+
const runnerConfig = await loadConfig({
|
|
74
|
+
name: "web-ext",
|
|
75
|
+
cwd: root,
|
|
76
|
+
globalRc: true,
|
|
77
|
+
rcFile: ".webextrc",
|
|
78
|
+
overrides: inlineConfig.webExt ?? inlineConfig.runner,
|
|
79
|
+
defaults: userConfig.webExt ?? userConfig.runner
|
|
80
|
+
});
|
|
81
|
+
const alias = Object.fromEntries(Object.entries({
|
|
82
|
+
...mergedConfig.alias,
|
|
83
|
+
"@": srcDir,
|
|
84
|
+
"~": srcDir,
|
|
85
|
+
"@@": root,
|
|
86
|
+
"~~": root
|
|
87
|
+
}).map(([key, value]) => [key, path.resolve(root, value)]));
|
|
88
|
+
let devServerConfig;
|
|
89
|
+
if (command === "serve") {
|
|
90
|
+
if (mergedConfig.dev?.server?.hostname) logger.warn(`The 'hostname' option is deprecated, please use 'host' or 'origin' depending on your circumstances.`);
|
|
91
|
+
const host = mergedConfig.dev?.server?.host ?? mergedConfig.dev?.server?.hostname ?? "localhost";
|
|
92
|
+
let port = mergedConfig.dev?.server?.port;
|
|
93
|
+
const origin = mergedConfig.dev?.server?.origin ?? mergedConfig.dev?.server?.hostname ?? "localhost";
|
|
94
|
+
if (port == null || !isFinite(port)) port = await getPort({
|
|
95
|
+
host,
|
|
96
|
+
port: 3e3,
|
|
97
|
+
portRange: [3001, 3010]
|
|
98
|
+
});
|
|
99
|
+
const originWithProtocolAndPort = [
|
|
100
|
+
origin.match(/^https?:\/\//) ? "" : "http://",
|
|
101
|
+
origin,
|
|
102
|
+
origin.match(/:[0-9]+$/) ? "" : `:${port}`
|
|
103
|
+
].join("");
|
|
104
|
+
devServerConfig = {
|
|
105
|
+
host,
|
|
106
|
+
port,
|
|
107
|
+
origin: originWithProtocolAndPort,
|
|
108
|
+
watchDebounce: safeStringToNumber(process.env.WXT_WATCH_DEBOUNCE) ?? 800
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const userModules = await resolveWxtUserModules(root, modulesDir, mergedConfig.modules);
|
|
112
|
+
const moduleOptions = userModules.reduce((map, module) => {
|
|
113
|
+
if (module.configKey) map[module.configKey] = mergedConfig[module.configKey];
|
|
114
|
+
return map;
|
|
115
|
+
}, {});
|
|
116
|
+
return {
|
|
117
|
+
browser,
|
|
118
|
+
targetBrowsers,
|
|
119
|
+
command,
|
|
120
|
+
debug,
|
|
121
|
+
entrypointsDir,
|
|
122
|
+
modulesDir,
|
|
123
|
+
filterEntrypoints,
|
|
124
|
+
env,
|
|
125
|
+
fsCache: createFsCache(wxtDir),
|
|
126
|
+
imports: await getUnimportOptions(wxtDir, srcDir, logger, mergedConfig),
|
|
127
|
+
logger,
|
|
128
|
+
manifest: await resolveManifestConfig(env, mergedConfig.manifest),
|
|
129
|
+
manifestVersion,
|
|
130
|
+
mode,
|
|
131
|
+
outBaseDir,
|
|
132
|
+
outDir,
|
|
133
|
+
publicDir,
|
|
134
|
+
wxtModuleDir,
|
|
135
|
+
root,
|
|
136
|
+
runnerConfig,
|
|
137
|
+
srcDir,
|
|
138
|
+
typesDir,
|
|
139
|
+
wxtDir,
|
|
140
|
+
zip: resolveZipConfig(root, browser, outBaseDir, mergedConfig),
|
|
141
|
+
analysis: resolveAnalysisConfig(root, mergedConfig),
|
|
142
|
+
userConfigMetadata: userConfigMetadata ?? {},
|
|
143
|
+
alias,
|
|
144
|
+
experimental: defu(mergedConfig.experimental, {}),
|
|
145
|
+
dev: {
|
|
146
|
+
server: devServerConfig,
|
|
147
|
+
reloadCommand
|
|
148
|
+
},
|
|
149
|
+
hooks: mergedConfig.hooks ?? {},
|
|
150
|
+
vite: mergedConfig.vite ?? (() => ({})),
|
|
151
|
+
builtinModules,
|
|
152
|
+
userModules,
|
|
153
|
+
plugins: [],
|
|
154
|
+
...moduleOptions
|
|
155
|
+
};
|
|
175
156
|
}
|
|
176
157
|
async function resolveManifestConfig(env, manifest) {
|
|
177
|
-
|
|
158
|
+
return typeof manifest === "function" ? await manifest(env) : await (manifest ?? {});
|
|
178
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Merge the inline config and user config. Inline config is given priority. Defaults are not applied here.
|
|
162
|
+
*/
|
|
179
163
|
async function mergeInlineConfig(inlineConfig, userConfig) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
...merged,
|
|
194
|
-
// Custom merge values
|
|
195
|
-
imports,
|
|
196
|
-
manifest,
|
|
197
|
-
...builderConfig
|
|
198
|
-
};
|
|
164
|
+
const imports = inlineConfig.imports === false || userConfig.imports === false ? false : userConfig.imports == null && inlineConfig.imports == null ? void 0 : defu(inlineConfig.imports ?? {}, userConfig.imports ?? {});
|
|
165
|
+
const manifest = async (env) => {
|
|
166
|
+
const user = await resolveManifestConfig(env, userConfig.manifest);
|
|
167
|
+
return defu(await resolveManifestConfig(env, inlineConfig.manifest), user);
|
|
168
|
+
};
|
|
169
|
+
const merged = defu(inlineConfig, userConfig);
|
|
170
|
+
const builderConfig = await mergeBuilderConfig(merged.logger ?? consola, inlineConfig, userConfig);
|
|
171
|
+
return {
|
|
172
|
+
...merged,
|
|
173
|
+
imports,
|
|
174
|
+
manifest,
|
|
175
|
+
...builderConfig
|
|
176
|
+
};
|
|
199
177
|
}
|
|
200
178
|
function resolveZipConfig(root, browser, outBaseDir, mergedConfig) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
...mergedConfig.zip?.excludeSources ?? []
|
|
225
|
-
],
|
|
226
|
-
downloadPackages: mergedConfig.zip?.downloadPackages ?? [],
|
|
227
|
-
downloadedPackagesDir
|
|
228
|
-
};
|
|
179
|
+
const downloadedPackagesDir = path.resolve(root, ".wxt/local_modules");
|
|
180
|
+
return {
|
|
181
|
+
name: void 0,
|
|
182
|
+
sourcesTemplate: "{{name}}-{{version}}-sources.zip",
|
|
183
|
+
artifactTemplate: "{{name}}-{{version}}-{{browser}}.zip",
|
|
184
|
+
sourcesRoot: root,
|
|
185
|
+
includeSources: [],
|
|
186
|
+
compressionLevel: 9,
|
|
187
|
+
...mergedConfig.zip,
|
|
188
|
+
zipSources: mergedConfig.zip?.zipSources ?? ["firefox", "opera"].includes(browser),
|
|
189
|
+
exclude: mergedConfig.zip?.exclude ?? [],
|
|
190
|
+
excludeSources: [
|
|
191
|
+
"**/node_modules",
|
|
192
|
+
"**/web-ext.config.ts",
|
|
193
|
+
"**/.*",
|
|
194
|
+
"**/__tests__/**",
|
|
195
|
+
"**/*.+(test|spec).?(c|m)+(j|t)s?(x)",
|
|
196
|
+
`${path.relative(root, outBaseDir)}/**`,
|
|
197
|
+
...mergedConfig.zip?.excludeSources ?? []
|
|
198
|
+
],
|
|
199
|
+
downloadPackages: mergedConfig.zip?.downloadPackages ?? [],
|
|
200
|
+
downloadedPackagesDir
|
|
201
|
+
};
|
|
229
202
|
}
|
|
230
203
|
function resolveAnalysisConfig(root, mergedConfig) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
outputName: analysisOutputName,
|
|
244
|
-
keepArtifacts: mergedConfig.analysis?.keepArtifacts ?? false
|
|
245
|
-
};
|
|
204
|
+
const analysisOutputFile = path.resolve(root, mergedConfig.analysis?.outputFile ?? "stats.html");
|
|
205
|
+
const analysisOutputDir = path.dirname(analysisOutputFile);
|
|
206
|
+
const analysisOutputName = path.parse(analysisOutputFile).name;
|
|
207
|
+
return {
|
|
208
|
+
enabled: mergedConfig.analysis?.enabled ?? false,
|
|
209
|
+
open: mergedConfig.analysis?.open ?? false,
|
|
210
|
+
template: mergedConfig.analysis?.template ?? "treemap",
|
|
211
|
+
outputFile: analysisOutputFile,
|
|
212
|
+
outputDir: analysisOutputDir,
|
|
213
|
+
outputName: analysisOutputName,
|
|
214
|
+
keepArtifacts: mergedConfig.analysis?.keepArtifacts ?? false
|
|
215
|
+
};
|
|
246
216
|
}
|
|
247
217
|
async function getUnimportOptions(wxtDir, srcDir, logger, config) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
from: "wxt/utils/match-patterns",
|
|
362
|
-
imports: defineImportsAndTypes(
|
|
363
|
-
["InvalidMatchPattern", "MatchPattern"],
|
|
364
|
-
[]
|
|
365
|
-
)
|
|
366
|
-
}
|
|
367
|
-
],
|
|
368
|
-
virtualImports: ["#imports"],
|
|
369
|
-
debugLog: logger.debug,
|
|
370
|
-
warn: logger.warn,
|
|
371
|
-
dirsScanOptions: {
|
|
372
|
-
cwd: srcDir
|
|
373
|
-
},
|
|
374
|
-
eslintrc,
|
|
375
|
-
dirs: disabled ? [] : ["components", "composables", "hooks", "utils"],
|
|
376
|
-
disabled
|
|
377
|
-
};
|
|
378
|
-
return defu(
|
|
379
|
-
config.imports ?? {},
|
|
380
|
-
defaultOptions
|
|
381
|
-
);
|
|
218
|
+
const disabled = config.imports === false;
|
|
219
|
+
const eslintrc = await getUnimportEslintOptions(wxtDir, config.imports);
|
|
220
|
+
const invalidExports = ["options"];
|
|
221
|
+
const defineImportsAndTypes = (imports, typeImports) => [...imports, ...typeImports.map((name) => ({
|
|
222
|
+
name,
|
|
223
|
+
type: true
|
|
224
|
+
}))];
|
|
225
|
+
const defaultOptions = {
|
|
226
|
+
imports: [{
|
|
227
|
+
name: "fakeBrowser",
|
|
228
|
+
from: "wxt/testing"
|
|
229
|
+
}],
|
|
230
|
+
presets: [
|
|
231
|
+
{
|
|
232
|
+
from: "wxt/browser",
|
|
233
|
+
imports: defineImportsAndTypes(["browser"], ["Browser"])
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
from: "wxt/utils/storage",
|
|
237
|
+
imports: defineImportsAndTypes(["storage"], [
|
|
238
|
+
"StorageArea",
|
|
239
|
+
"WxtStorage",
|
|
240
|
+
"WxtStorageItem",
|
|
241
|
+
"StorageArea",
|
|
242
|
+
"StorageItemKey",
|
|
243
|
+
"StorageAreaChanges",
|
|
244
|
+
"MigrationError"
|
|
245
|
+
])
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
from: "wxt/utils/app-config",
|
|
249
|
+
imports: defineImportsAndTypes(["useAppConfig"], [])
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
from: "wxt/utils/content-script-context",
|
|
253
|
+
imports: defineImportsAndTypes(["ContentScriptContext"], ["WxtWindowEventMap"])
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
from: "wxt/utils/content-script-ui/iframe",
|
|
257
|
+
imports: defineImportsAndTypes(["createIframeUi"], ["IframeContentScriptUi", "IframeContentScriptUiOptions"]),
|
|
258
|
+
ignore: invalidExports
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
from: "wxt/utils/content-script-ui/integrated",
|
|
262
|
+
imports: defineImportsAndTypes(["createIntegratedUi"], ["IntegratedContentScriptUi", "IntegratedContentScriptUiOptions"]),
|
|
263
|
+
ignore: invalidExports
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
from: "wxt/utils/content-script-ui/shadow-root",
|
|
267
|
+
imports: defineImportsAndTypes(["createShadowRootUi"], ["ShadowRootContentScriptUi", "ShadowRootContentScriptUiOptions"]),
|
|
268
|
+
ignore: invalidExports
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
from: "wxt/utils/content-script-ui/types",
|
|
272
|
+
imports: defineImportsAndTypes([], [
|
|
273
|
+
"ContentScriptUi",
|
|
274
|
+
"ContentScriptUiOptions",
|
|
275
|
+
"ContentScriptOverlayAlignment",
|
|
276
|
+
"ContentScriptAppendMode",
|
|
277
|
+
"ContentScriptInlinePositioningOptions",
|
|
278
|
+
"ContentScriptOverlayPositioningOptions",
|
|
279
|
+
"ContentScriptModalPositioningOptions",
|
|
280
|
+
"ContentScriptPositioningOptions",
|
|
281
|
+
"ContentScriptAnchoredOptions",
|
|
282
|
+
"AutoMountOptions",
|
|
283
|
+
"StopAutoMount",
|
|
284
|
+
"AutoMount"
|
|
285
|
+
])
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
from: "wxt/utils/define-app-config",
|
|
289
|
+
imports: defineImportsAndTypes(["defineAppConfig"], ["WxtAppConfig"])
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
from: "wxt/utils/define-background",
|
|
293
|
+
imports: defineImportsAndTypes(["defineBackground"], [])
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
from: "wxt/utils/define-content-script",
|
|
297
|
+
imports: defineImportsAndTypes(["defineContentScript"], [])
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
from: "wxt/utils/define-unlisted-script",
|
|
301
|
+
imports: defineImportsAndTypes(["defineUnlistedScript"], [])
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
from: "wxt/utils/define-wxt-plugin",
|
|
305
|
+
imports: defineImportsAndTypes(["defineWxtPlugin"], [])
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
from: "wxt/utils/inject-script",
|
|
309
|
+
imports: defineImportsAndTypes(["injectScript"], ["ScriptPublicPath", "InjectScriptOptions"]),
|
|
310
|
+
ignore: invalidExports
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
from: "wxt/utils/match-patterns",
|
|
314
|
+
imports: defineImportsAndTypes(["InvalidMatchPattern", "MatchPattern"], [])
|
|
315
|
+
}
|
|
316
|
+
],
|
|
317
|
+
virtualImports: ["#imports"],
|
|
318
|
+
debugLog: logger.debug,
|
|
319
|
+
warn: logger.warn,
|
|
320
|
+
dirsScanOptions: { cwd: srcDir },
|
|
321
|
+
eslintrc,
|
|
322
|
+
dirs: disabled ? [] : [
|
|
323
|
+
"components",
|
|
324
|
+
"composables",
|
|
325
|
+
"hooks",
|
|
326
|
+
"utils"
|
|
327
|
+
],
|
|
328
|
+
disabled
|
|
329
|
+
};
|
|
330
|
+
return defu(config.imports ?? {}, defaultOptions);
|
|
382
331
|
}
|
|
383
332
|
async function getUnimportEslintOptions(wxtDir, options) {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
enabled === 9 ? "eslint-auto-imports.mjs" : "eslintrc-auto-import.json"
|
|
406
|
-
),
|
|
407
|
-
globalsPropValue: true
|
|
408
|
-
};
|
|
333
|
+
const inlineEnabled = options === false ? false : options?.eslintrc?.enabled ?? "auto";
|
|
334
|
+
let enabled;
|
|
335
|
+
switch (inlineEnabled) {
|
|
336
|
+
case "auto":
|
|
337
|
+
const version = await getEslintVersion();
|
|
338
|
+
let major = parseInt(version[0]);
|
|
339
|
+
if (isNaN(major)) enabled = false;
|
|
340
|
+
if (major <= 8) enabled = 8;
|
|
341
|
+
else if (major >= 9) enabled = 9;
|
|
342
|
+
else enabled = false;
|
|
343
|
+
break;
|
|
344
|
+
case true:
|
|
345
|
+
enabled = 8;
|
|
346
|
+
break;
|
|
347
|
+
default: enabled = inlineEnabled;
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
enabled,
|
|
351
|
+
filePath: path.resolve(wxtDir, enabled === 9 ? "eslint-auto-imports.mjs" : "eslintrc-auto-import.json"),
|
|
352
|
+
globalsPropValue: true
|
|
353
|
+
};
|
|
409
354
|
}
|
|
355
|
+
/**
|
|
356
|
+
* Returns the path to `node_modules/wxt`.
|
|
357
|
+
*/
|
|
410
358
|
function resolveWxtModuleDir() {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
return path.resolve(fileURLToPath(url), "../..");
|
|
359
|
+
const url = resolve$1("wxt", import.meta.url);
|
|
360
|
+
return path.resolve(fileURLToPath(url), "../..");
|
|
414
361
|
}
|
|
415
362
|
async function isDirMissing(dir) {
|
|
416
|
-
|
|
363
|
+
return !await fs.pathExists(dir);
|
|
417
364
|
}
|
|
418
365
|
function logMissingDir(logger, name, expected) {
|
|
419
|
-
|
|
420
|
-
`${name} directory not found: ./${normalizePath(
|
|
421
|
-
path.relative(process.cwd(), expected)
|
|
422
|
-
)}`
|
|
423
|
-
);
|
|
366
|
+
logger.warn(`${name} directory not found: ./${normalizePath(path.relative(process.cwd(), expected))}`);
|
|
424
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* Map of `ConfigEnv` commands to their default modes.
|
|
370
|
+
*/
|
|
425
371
|
const COMMAND_MODES = {
|
|
426
|
-
|
|
427
|
-
|
|
372
|
+
build: "production",
|
|
373
|
+
serve: "development"
|
|
428
374
|
};
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
return vite.mergeConfig(resolvedUserConfig, resolvedInlineConfig);
|
|
439
|
-
}
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
throw Error("Builder not found. Make sure vite is installed.");
|
|
375
|
+
async function mergeBuilderConfig(logger, inlineConfig, userConfig) {
|
|
376
|
+
const vite = await import("vite").catch((err) => {
|
|
377
|
+
logger.debug("Failed to import vite:", err);
|
|
378
|
+
});
|
|
379
|
+
if (vite) return { vite: async (env) => {
|
|
380
|
+
const [resolvedInlineConfig = {}, resolvedUserConfig = {}] = await Promise.all([inlineConfig.vite?.(env), userConfig.vite?.(env)]);
|
|
381
|
+
return vite.mergeConfig(resolvedUserConfig, resolvedInlineConfig);
|
|
382
|
+
} };
|
|
383
|
+
throw Error("Builder not found. Make sure vite is installed.");
|
|
443
384
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
if (config == null)
|
|
480
|
-
throw Error(
|
|
481
|
-
`No config found for ${file}. Did you forget to add a default export?`
|
|
482
|
-
);
|
|
483
|
-
config.name ??= file;
|
|
484
|
-
return {
|
|
485
|
-
...config,
|
|
486
|
-
type: "local",
|
|
487
|
-
id: absolutePath
|
|
488
|
-
};
|
|
489
|
-
})
|
|
490
|
-
);
|
|
491
|
-
return [...npmModules, ...localModules];
|
|
385
|
+
async function resolveWxtUserModules(root, modulesDir, modules = []) {
|
|
386
|
+
const importer = pathToFileURL(path.join(root, "index.js")).href;
|
|
387
|
+
const npmModules = await Promise.all(modules.map(async (moduleId) => {
|
|
388
|
+
const mod = await import(resolve$1(moduleId, importer));
|
|
389
|
+
if (mod.default == null) throw Error("Module missing default export: " + moduleId);
|
|
390
|
+
return {
|
|
391
|
+
...mod.default,
|
|
392
|
+
type: "node_module",
|
|
393
|
+
id: moduleId
|
|
394
|
+
};
|
|
395
|
+
}));
|
|
396
|
+
const localModulePaths = await glob(["*.[tj]s", "*/index.[tj]s"], {
|
|
397
|
+
cwd: modulesDir,
|
|
398
|
+
onlyFiles: true
|
|
399
|
+
}).catch(() => []);
|
|
400
|
+
localModulePaths.sort();
|
|
401
|
+
const localModules = await Promise.all(localModulePaths.map(async (file) => {
|
|
402
|
+
const absolutePath = normalizePath(path.resolve(modulesDir, file));
|
|
403
|
+
const { config } = await loadConfig({
|
|
404
|
+
configFile: absolutePath,
|
|
405
|
+
globalRc: false,
|
|
406
|
+
rcFile: false,
|
|
407
|
+
packageJson: false,
|
|
408
|
+
envName: false,
|
|
409
|
+
dotenv: false
|
|
410
|
+
});
|
|
411
|
+
if (config == null) throw Error(`No config found for ${file}. Did you forget to add a default export?`);
|
|
412
|
+
config.name ??= file;
|
|
413
|
+
return {
|
|
414
|
+
...config,
|
|
415
|
+
type: "local",
|
|
416
|
+
id: absolutePath
|
|
417
|
+
};
|
|
418
|
+
}));
|
|
419
|
+
return [...npmModules, ...localModules];
|
|
492
420
|
}
|
|
421
|
+
|
|
422
|
+
//#endregion
|
|
423
|
+
export { resolveConfig };
|