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,390 +1,309 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CSS_EXTENSIONS_PATTERN } from "../paths.mjs";
|
|
2
|
+
import { getEntrypointName, isHtmlEntrypoint, isJsEntrypoint, resolvePerBrowserOptions } from "../entrypoints.mjs";
|
|
3
|
+
import { VIRTUAL_NOOP_BACKGROUND_MODULE_ID } from "../constants.mjs";
|
|
4
|
+
import { wxt } from "../../wxt.mjs";
|
|
2
5
|
import fs from "fs-extra";
|
|
3
|
-
import { minimatch } from "minimatch";
|
|
4
|
-
import { parseHTML } from "linkedom";
|
|
5
|
-
import JSON5 from "json5";
|
|
6
6
|
import glob from "fast-glob";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
isHtmlEntrypoint,
|
|
10
|
-
isJsEntrypoint,
|
|
11
|
-
resolvePerBrowserOptions
|
|
12
|
-
} from "../../utils/entrypoints.mjs";
|
|
13
|
-
import { VIRTUAL_NOOP_BACKGROUND_MODULE_ID } from "../../utils/constants.mjs";
|
|
14
|
-
import { CSS_EXTENSIONS_PATTERN } from "../../utils/paths.mjs";
|
|
15
|
-
import pc from "picocolors";
|
|
16
|
-
import { wxt } from "../../wxt.mjs";
|
|
7
|
+
import { relative, resolve } from "path";
|
|
8
|
+
import { parseHTML } from "linkedom";
|
|
17
9
|
import { camelCase } from "scule";
|
|
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
|
-
entrypointsWithoutSkipped.push(
|
|
107
|
-
await getBackgroundEntrypoint(
|
|
108
|
-
{
|
|
109
|
-
inputPath: VIRTUAL_NOOP_BACKGROUND_MODULE_ID,
|
|
110
|
-
name: "background",
|
|
111
|
-
type: "background"
|
|
112
|
-
},
|
|
113
|
-
{}
|
|
114
|
-
)
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
const entrypoints = entrypointsWithoutSkipped.map((entry) => ({
|
|
118
|
-
...entry,
|
|
119
|
-
skipped: isEntrypointSkipped(entry)
|
|
120
|
-
}));
|
|
121
|
-
await wxt.hooks.callHook("entrypoints:resolved", wxt, entrypoints);
|
|
122
|
-
wxt.logger.debug("All entrypoints:", entrypoints);
|
|
123
|
-
const skippedEntrypointNames = entrypoints.filter((item) => item.skipped).map((item) => item.name);
|
|
124
|
-
if (skippedEntrypointNames.length) {
|
|
125
|
-
wxt.logger.warn(
|
|
126
|
-
[
|
|
127
|
-
"The following entrypoints have been skipped:",
|
|
128
|
-
...skippedEntrypointNames.map(
|
|
129
|
-
(item) => `${pc.dim("-")} ${pc.cyan(item)}`
|
|
130
|
-
)
|
|
131
|
-
].join("\n")
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
return entrypoints;
|
|
10
|
+
import pc from "picocolors";
|
|
11
|
+
import { minimatch } from "minimatch";
|
|
12
|
+
import JSON5 from "json5";
|
|
13
|
+
|
|
14
|
+
//#region src/core/utils/building/find-entrypoints.ts
|
|
15
|
+
/**
|
|
16
|
+
* Return entrypoints and their configuration by looking through the project's files.
|
|
17
|
+
*/
|
|
18
|
+
async function findEntrypoints() {
|
|
19
|
+
await fs.mkdir(wxt.config.wxtDir, { recursive: true });
|
|
20
|
+
try {
|
|
21
|
+
await fs.writeJson(resolve(wxt.config.wxtDir, "tsconfig.json"), {}, { flag: "wx" });
|
|
22
|
+
} catch (err) {
|
|
23
|
+
if (!(err instanceof Error) || !("code" in err) || err.code !== "EEXIST") throw err;
|
|
24
|
+
}
|
|
25
|
+
const relativePaths = await glob(Object.keys(PATH_GLOB_TO_TYPE_MAP), { cwd: wxt.config.entrypointsDir });
|
|
26
|
+
relativePaths.sort();
|
|
27
|
+
const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
|
|
28
|
+
const entrypointInfos = relativePaths.reduce((results, relativePath) => {
|
|
29
|
+
const inputPath = resolve(wxt.config.entrypointsDir, relativePath);
|
|
30
|
+
const name = getEntrypointName(wxt.config.entrypointsDir, inputPath);
|
|
31
|
+
const matchingGlob = pathGlobs.find((glob) => minimatch(relativePath, glob));
|
|
32
|
+
if (matchingGlob) {
|
|
33
|
+
const type = PATH_GLOB_TO_TYPE_MAP[matchingGlob];
|
|
34
|
+
results.push({
|
|
35
|
+
name,
|
|
36
|
+
inputPath,
|
|
37
|
+
type
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return results;
|
|
41
|
+
}, []).filter(({ name, inputPath }, _, entrypointInfos) => {
|
|
42
|
+
if (inputPath.endsWith(".html")) return true;
|
|
43
|
+
if (!/index\..+$/.test(inputPath)) return true;
|
|
44
|
+
return !entrypointInfos.some((entry) => entry.name === name && entry.inputPath.endsWith("index.html"));
|
|
45
|
+
});
|
|
46
|
+
await wxt.hooks.callHook("entrypoints:found", wxt, entrypointInfos);
|
|
47
|
+
preventNoEntrypoints(entrypointInfos);
|
|
48
|
+
preventDuplicateEntrypointNames(entrypointInfos);
|
|
49
|
+
let hasBackground = false;
|
|
50
|
+
const entrypointOptions = await importEntrypoints(entrypointInfos);
|
|
51
|
+
const entrypointsWithoutSkipped = await Promise.all(entrypointInfos.map(async (info) => {
|
|
52
|
+
const { type } = info;
|
|
53
|
+
const options = entrypointOptions[info.inputPath] ?? {};
|
|
54
|
+
switch (type) {
|
|
55
|
+
case "popup": return await getPopupEntrypoint(info, options);
|
|
56
|
+
case "sidepanel": return await getSidepanelEntrypoint(info, options);
|
|
57
|
+
case "options": return await getOptionsEntrypoint(info, options);
|
|
58
|
+
case "background":
|
|
59
|
+
hasBackground = true;
|
|
60
|
+
return await getBackgroundEntrypoint(info, options);
|
|
61
|
+
case "content-script": return await getContentScriptEntrypoint(info, options);
|
|
62
|
+
case "unlisted-page": return await getUnlistedPageEntrypoint(info, options);
|
|
63
|
+
case "unlisted-script": return await getUnlistedScriptEntrypoint(info, options);
|
|
64
|
+
case "content-script-style": return {
|
|
65
|
+
...info,
|
|
66
|
+
type,
|
|
67
|
+
outputDir: resolve(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
68
|
+
options: {
|
|
69
|
+
include: options.include,
|
|
70
|
+
exclude: options.exclude
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
default: return {
|
|
74
|
+
...info,
|
|
75
|
+
type,
|
|
76
|
+
outputDir: wxt.config.outDir,
|
|
77
|
+
options: {
|
|
78
|
+
include: options.include,
|
|
79
|
+
exclude: options.exclude
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}));
|
|
84
|
+
if (wxt.config.command === "serve" && !hasBackground) entrypointsWithoutSkipped.push(await getBackgroundEntrypoint({
|
|
85
|
+
inputPath: VIRTUAL_NOOP_BACKGROUND_MODULE_ID,
|
|
86
|
+
name: "background",
|
|
87
|
+
type: "background"
|
|
88
|
+
}, {}));
|
|
89
|
+
const entrypoints = entrypointsWithoutSkipped.map((entry) => ({
|
|
90
|
+
...entry,
|
|
91
|
+
skipped: isEntrypointSkipped(entry)
|
|
92
|
+
}));
|
|
93
|
+
await wxt.hooks.callHook("entrypoints:resolved", wxt, entrypoints);
|
|
94
|
+
wxt.logger.debug("All entrypoints:", entrypoints);
|
|
95
|
+
const skippedEntrypointNames = entrypoints.filter((item) => item.skipped).map((item) => item.name);
|
|
96
|
+
if (skippedEntrypointNames.length) wxt.logger.warn(["The following entrypoints have been skipped:", ...skippedEntrypointNames.map((item) => `${pc.dim("-")} ${pc.cyan(item)}`)].join("\n"));
|
|
97
|
+
return entrypoints;
|
|
135
98
|
}
|
|
99
|
+
/** Returns a map of input paths to the file's options. */
|
|
136
100
|
async function importEntrypoints(infos) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const res = await wxt.builder.importEntrypoints(
|
|
149
|
-
jsInfos.map((info) => info.inputPath)
|
|
150
|
-
);
|
|
151
|
-
res.forEach((res2, i) => {
|
|
152
|
-
resMap[jsInfos[i].inputPath] = res2;
|
|
153
|
-
});
|
|
154
|
-
})()
|
|
155
|
-
// CSS - never has options
|
|
156
|
-
]);
|
|
157
|
-
return resMap;
|
|
101
|
+
const resMap = {};
|
|
102
|
+
const htmlInfos = infos.filter((info) => isHtmlEntrypoint(info));
|
|
103
|
+
const jsInfos = infos.filter((info) => isJsEntrypoint(info));
|
|
104
|
+
await Promise.all([...htmlInfos.map(async (info) => {
|
|
105
|
+
resMap[info.inputPath] = await importHtmlEntrypoint(info);
|
|
106
|
+
}), (async () => {
|
|
107
|
+
(await wxt.builder.importEntrypoints(jsInfos.map((info) => info.inputPath))).forEach((res, i) => {
|
|
108
|
+
resMap[jsInfos[i].inputPath] = res;
|
|
109
|
+
});
|
|
110
|
+
})()]);
|
|
111
|
+
return resMap;
|
|
158
112
|
}
|
|
113
|
+
/** Extract `manifest.` options from meta tags, converting snake_case keys to camelCase */
|
|
159
114
|
async function importHtmlEntrypoint(info) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
return res;
|
|
115
|
+
const { document } = parseHTML(await fs.readFile(info.inputPath, "utf-8"));
|
|
116
|
+
const metaTags = document.querySelectorAll("meta");
|
|
117
|
+
const res = { title: document.querySelector("title")?.textContent || void 0 };
|
|
118
|
+
metaTags.forEach((tag) => {
|
|
119
|
+
const name = tag.name;
|
|
120
|
+
if (!name.startsWith("manifest.")) return;
|
|
121
|
+
const key = camelCase(name.slice(9));
|
|
122
|
+
try {
|
|
123
|
+
res[key] = JSON5.parse(tag.content);
|
|
124
|
+
} catch {
|
|
125
|
+
res[key] = tag.content;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return res;
|
|
177
129
|
}
|
|
178
130
|
function preventDuplicateEntrypointNames(files) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
[]
|
|
198
|
-
);
|
|
199
|
-
if (errorLines.length > 0) {
|
|
200
|
-
const errorContent = errorLines.join("\n");
|
|
201
|
-
throw Error(
|
|
202
|
-
`Multiple entrypoints with the same name detected, only one entrypoint for each name is allowed.
|
|
203
|
-
|
|
204
|
-
${errorContent}`
|
|
205
|
-
);
|
|
206
|
-
}
|
|
131
|
+
const namesToPaths = files.reduce((map, { name, inputPath }) => {
|
|
132
|
+
map[name] ??= [];
|
|
133
|
+
map[name].push(inputPath);
|
|
134
|
+
return map;
|
|
135
|
+
}, {});
|
|
136
|
+
const errorLines = Object.entries(namesToPaths).reduce((lines, [name, absolutePaths]) => {
|
|
137
|
+
if (absolutePaths.length > 1) {
|
|
138
|
+
lines.push(`- ${name}`);
|
|
139
|
+
absolutePaths.forEach((absolutePath) => {
|
|
140
|
+
lines.push(` - ${relative(wxt.config.root, absolutePath)}`);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return lines;
|
|
144
|
+
}, []);
|
|
145
|
+
if (errorLines.length > 0) {
|
|
146
|
+
const errorContent = errorLines.join("\n");
|
|
147
|
+
throw Error(`Multiple entrypoints with the same name detected, only one entrypoint for each name is allowed.\n\n${errorContent}`);
|
|
148
|
+
}
|
|
207
149
|
}
|
|
208
150
|
function preventNoEntrypoints(files) {
|
|
209
|
-
|
|
210
|
-
throw Error(`No entrypoints found in ${wxt.config.entrypointsDir}`);
|
|
211
|
-
}
|
|
151
|
+
if (files.length === 0) throw Error(`No entrypoints found in ${wxt.config.entrypointsDir}`);
|
|
212
152
|
}
|
|
213
153
|
async function getPopupEntrypoint(info, options) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
154
|
+
const strictOptions = resolvePerBrowserOptions({
|
|
155
|
+
browserStyle: options.browserStyle,
|
|
156
|
+
exclude: options.exclude,
|
|
157
|
+
include: options.include,
|
|
158
|
+
defaultIcon: options.defaultIcon,
|
|
159
|
+
defaultTitle: options.title,
|
|
160
|
+
mv2Key: options.type,
|
|
161
|
+
defaultArea: options.defaultArea
|
|
162
|
+
}, wxt.config.browser);
|
|
163
|
+
if (strictOptions.mv2Key && strictOptions.mv2Key !== "page_action") strictOptions.mv2Key = "browser_action";
|
|
164
|
+
const themeIcons = options.themeIcons;
|
|
165
|
+
return {
|
|
166
|
+
type: "popup",
|
|
167
|
+
name: "popup",
|
|
168
|
+
options: {
|
|
169
|
+
...strictOptions,
|
|
170
|
+
themeIcons
|
|
171
|
+
},
|
|
172
|
+
inputPath: info.inputPath,
|
|
173
|
+
outputDir: wxt.config.outDir
|
|
174
|
+
};
|
|
234
175
|
}
|
|
235
176
|
async function getOptionsEntrypoint(info, options) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
inputPath: info.inputPath,
|
|
250
|
-
outputDir: wxt.config.outDir
|
|
251
|
-
};
|
|
177
|
+
return {
|
|
178
|
+
type: "options",
|
|
179
|
+
name: "options",
|
|
180
|
+
options: resolvePerBrowserOptions({
|
|
181
|
+
browserStyle: options.browserStyle,
|
|
182
|
+
chromeStyle: options.chromeStyle,
|
|
183
|
+
exclude: options.exclude,
|
|
184
|
+
include: options.include,
|
|
185
|
+
openInTab: options.openInTab
|
|
186
|
+
}, wxt.config.browser),
|
|
187
|
+
inputPath: info.inputPath,
|
|
188
|
+
outputDir: wxt.config.outDir
|
|
189
|
+
};
|
|
252
190
|
}
|
|
253
191
|
async function getUnlistedPageEntrypoint(info, options) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
192
|
+
return {
|
|
193
|
+
type: "unlisted-page",
|
|
194
|
+
name: info.name,
|
|
195
|
+
inputPath: info.inputPath,
|
|
196
|
+
outputDir: wxt.config.outDir,
|
|
197
|
+
options: {
|
|
198
|
+
include: options.include,
|
|
199
|
+
exclude: options.exclude
|
|
200
|
+
}
|
|
201
|
+
};
|
|
264
202
|
}
|
|
265
203
|
async function getUnlistedScriptEntrypoint({ inputPath, name }, options) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
wxt.config.browser
|
|
277
|
-
)
|
|
278
|
-
};
|
|
204
|
+
return {
|
|
205
|
+
type: "unlisted-script",
|
|
206
|
+
name,
|
|
207
|
+
inputPath,
|
|
208
|
+
outputDir: wxt.config.outDir,
|
|
209
|
+
options: resolvePerBrowserOptions({
|
|
210
|
+
include: options.include,
|
|
211
|
+
exclude: options.exclude
|
|
212
|
+
}, wxt.config.browser)
|
|
213
|
+
};
|
|
279
214
|
}
|
|
280
215
|
async function getBackgroundEntrypoint({ inputPath, name }, options) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
name,
|
|
296
|
-
inputPath,
|
|
297
|
-
outputDir: wxt.config.outDir,
|
|
298
|
-
options: strictOptions
|
|
299
|
-
};
|
|
216
|
+
const strictOptions = resolvePerBrowserOptions({
|
|
217
|
+
include: options.include,
|
|
218
|
+
exclude: options.exclude,
|
|
219
|
+
persistent: options.persistent,
|
|
220
|
+
type: options.type
|
|
221
|
+
}, wxt.config.browser);
|
|
222
|
+
if (wxt.config.manifestVersion !== 3) delete strictOptions.type;
|
|
223
|
+
return {
|
|
224
|
+
type: "background",
|
|
225
|
+
name,
|
|
226
|
+
inputPath,
|
|
227
|
+
outputDir: wxt.config.outDir,
|
|
228
|
+
options: strictOptions
|
|
229
|
+
};
|
|
300
230
|
}
|
|
301
231
|
async function getContentScriptEntrypoint({ inputPath, name }, options) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
wxt.config.browser
|
|
310
|
-
)
|
|
311
|
-
};
|
|
232
|
+
return {
|
|
233
|
+
type: "content-script",
|
|
234
|
+
name,
|
|
235
|
+
inputPath,
|
|
236
|
+
outputDir: resolve(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
237
|
+
options: resolvePerBrowserOptions(options, wxt.config.browser)
|
|
238
|
+
};
|
|
312
239
|
}
|
|
313
240
|
async function getSidepanelEntrypoint(info, options) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
inputPath: info.inputPath,
|
|
329
|
-
outputDir: wxt.config.outDir
|
|
330
|
-
};
|
|
241
|
+
return {
|
|
242
|
+
type: "sidepanel",
|
|
243
|
+
name: info.name,
|
|
244
|
+
options: resolvePerBrowserOptions({
|
|
245
|
+
browserStyle: options.browserStyle,
|
|
246
|
+
exclude: options.exclude,
|
|
247
|
+
include: options.include,
|
|
248
|
+
defaultIcon: options.defaultIcon,
|
|
249
|
+
defaultTitle: options.title,
|
|
250
|
+
openAtInstall: options.openAtInstall
|
|
251
|
+
}, wxt.config.browser),
|
|
252
|
+
inputPath: info.inputPath,
|
|
253
|
+
outputDir: wxt.config.outDir
|
|
254
|
+
};
|
|
331
255
|
}
|
|
332
256
|
function isEntrypointSkipped(entry) {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
if (exclude?.length && !include?.length) {
|
|
344
|
-
return exclude.includes(wxt.config.browser);
|
|
345
|
-
}
|
|
346
|
-
if (include?.length && !exclude?.length) {
|
|
347
|
-
return !include.includes(wxt.config.browser);
|
|
348
|
-
}
|
|
349
|
-
return false;
|
|
257
|
+
if (wxt.config.filterEntrypoints != null) return !wxt.config.filterEntrypoints.has(entry.name);
|
|
258
|
+
const { include, exclude } = entry.options;
|
|
259
|
+
if (include?.length && exclude?.length) {
|
|
260
|
+
wxt.logger.warn(`The ${entry.name} entrypoint lists both include and exclude, but only one can be used per entrypoint. Entrypoint skipped.`);
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
if (exclude?.length && !include?.length) return exclude.includes(wxt.config.browser);
|
|
264
|
+
if (include?.length && !exclude?.length) return !include.includes(wxt.config.browser);
|
|
265
|
+
return false;
|
|
350
266
|
}
|
|
351
267
|
const PATH_GLOB_TO_TYPE_MAP = {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
268
|
+
"sandbox.html": "sandbox",
|
|
269
|
+
"sandbox/index.html": "sandbox",
|
|
270
|
+
"*.sandbox.html": "sandbox",
|
|
271
|
+
"*.sandbox/index.html": "sandbox",
|
|
272
|
+
"bookmarks.html": "bookmarks",
|
|
273
|
+
"bookmarks/index.html": "bookmarks",
|
|
274
|
+
"history.html": "history",
|
|
275
|
+
"history/index.html": "history",
|
|
276
|
+
"newtab.html": "newtab",
|
|
277
|
+
"newtab/index.html": "newtab",
|
|
278
|
+
"sidepanel.html": "sidepanel",
|
|
279
|
+
"sidepanel/index.html": "sidepanel",
|
|
280
|
+
"*.sidepanel.html": "sidepanel",
|
|
281
|
+
"*.sidepanel/index.html": "sidepanel",
|
|
282
|
+
"devtools.html": "devtools",
|
|
283
|
+
"devtools/index.html": "devtools",
|
|
284
|
+
"background.[jt]s": "background",
|
|
285
|
+
"background/index.[jt]s": "background",
|
|
286
|
+
[VIRTUAL_NOOP_BACKGROUND_MODULE_ID]: "background",
|
|
287
|
+
"content.[jt]s?(x)": "content-script",
|
|
288
|
+
"content/index.[jt]s?(x)": "content-script",
|
|
289
|
+
"*.content.[jt]s?(x)": "content-script",
|
|
290
|
+
"*.content/index.[jt]s?(x)": "content-script",
|
|
291
|
+
[`content.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
|
|
292
|
+
[`*.content.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
|
|
293
|
+
[`content/index.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
|
|
294
|
+
[`*.content/index.${CSS_EXTENSIONS_PATTERN}`]: "content-script-style",
|
|
295
|
+
"popup.html": "popup",
|
|
296
|
+
"popup/index.html": "popup",
|
|
297
|
+
"options.html": "options",
|
|
298
|
+
"options/index.html": "options",
|
|
299
|
+
"*.html": "unlisted-page",
|
|
300
|
+
"*/index.html": "unlisted-page",
|
|
301
|
+
"*.[jt]s?(x)": "unlisted-script",
|
|
302
|
+
"*/index.[jt]s?(x)": "unlisted-script",
|
|
303
|
+
[`*.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style",
|
|
304
|
+
[`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style"
|
|
389
305
|
};
|
|
390
306
|
const CONTENT_SCRIPT_OUT_DIR = "content-scripts";
|
|
307
|
+
|
|
308
|
+
//#endregion
|
|
309
|
+
export { findEntrypoints };
|