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,38 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
//#region src/core/utils/building/group-entrypoints.ts
|
|
2
|
+
/**
|
|
3
|
+
* Entrypoints are built in groups. HTML pages can all be built together in a single step,
|
|
4
|
+
* content scripts must be build individually, etc.
|
|
5
|
+
*
|
|
6
|
+
* This function returns the entrypoints put into these types of groups.
|
|
7
|
+
*/
|
|
8
|
+
function groupEntrypoints(entrypoints) {
|
|
9
|
+
const groupIndexMap = {};
|
|
10
|
+
const groups = [];
|
|
11
|
+
for (const entry of entrypoints) {
|
|
12
|
+
if (entry.skipped) continue;
|
|
13
|
+
let group = ENTRY_TYPE_TO_GROUP_MAP[entry.type];
|
|
14
|
+
if (entry.type === "background" && entry.options.type === "module") group = "esm";
|
|
15
|
+
if (group === "individual") groups.push(entry);
|
|
16
|
+
else {
|
|
17
|
+
let groupIndex = groupIndexMap[group];
|
|
18
|
+
if (groupIndex == null) {
|
|
19
|
+
groupIndex = groups.push([]) - 1;
|
|
20
|
+
groupIndexMap[group] = groupIndex;
|
|
21
|
+
}
|
|
22
|
+
groups[groupIndex].push(entry);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return groups;
|
|
22
26
|
}
|
|
23
27
|
const ENTRY_TYPE_TO_GROUP_MAP = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
sandbox: "sandboxed-esm",
|
|
29
|
+
popup: "esm",
|
|
30
|
+
newtab: "esm",
|
|
31
|
+
history: "esm",
|
|
32
|
+
options: "esm",
|
|
33
|
+
devtools: "esm",
|
|
34
|
+
bookmarks: "esm",
|
|
35
|
+
sidepanel: "esm",
|
|
36
|
+
"unlisted-page": "esm",
|
|
37
|
+
background: "individual",
|
|
38
|
+
"content-script": "individual",
|
|
39
|
+
"unlisted-script": "individual",
|
|
40
|
+
"unlisted-style": "individual",
|
|
41
|
+
"content-script-style": "individual"
|
|
38
42
|
};
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { groupEntrypoints };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { buildEntrypoints } from "./build-entrypoints.mjs";
|
|
2
|
+
import { detectDevChanges } from "./detect-dev-changes.mjs";
|
|
3
|
+
import { findEntrypoints } from "./find-entrypoints.mjs";
|
|
4
|
+
import { groupEntrypoints } from "./group-entrypoints.mjs";
|
|
5
|
+
import { rebuild } from "./rebuild.mjs";
|
|
6
|
+
import { internalBuild } from "./internal-build.mjs";
|
|
7
|
+
|
|
8
|
+
export { };
|
|
@@ -1,112 +1,96 @@
|
|
|
1
|
+
import { unnormalizePath } from "../paths.mjs";
|
|
2
|
+
import { formatDuration } from "../time.mjs";
|
|
3
|
+
import { wxt } from "../../wxt.mjs";
|
|
1
4
|
import { findEntrypoints } from "./find-entrypoints.mjs";
|
|
2
|
-
import pc from "picocolors";
|
|
3
|
-
import fs from "fs-extra";
|
|
4
5
|
import { groupEntrypoints } from "./group-entrypoints.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import glob from "fast-glob";
|
|
8
|
-
import { unnormalizePath } from "../../utils/paths.mjs";
|
|
6
|
+
import { printBuildSummary } from "../log/printBuildSummary.mjs";
|
|
7
|
+
import "../log/index.mjs";
|
|
9
8
|
import { rebuild } from "./rebuild.mjs";
|
|
9
|
+
import { ValidationError, validateEntrypoints } from "../validation.mjs";
|
|
10
|
+
import fs from "fs-extra";
|
|
11
|
+
import glob from "fast-glob";
|
|
10
12
|
import { relative } from "node:path";
|
|
11
|
-
import {
|
|
12
|
-
ValidationError,
|
|
13
|
-
validateEntrypoints
|
|
14
|
-
} from "../validation.mjs";
|
|
15
|
-
import { wxt } from "../../wxt.mjs";
|
|
16
13
|
import { mergeJsonOutputs } from "@aklinker1/rollup-plugin-visualizer";
|
|
14
|
+
import pc from "picocolors";
|
|
17
15
|
import { isCI } from "ci-info";
|
|
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
|
-
wxt.logger.info(`Opening ${pc.yellow(statsPath)} in browser...`);
|
|
65
|
-
const { default: open } = await import("open");
|
|
66
|
-
open(wxt.config.analysis.outputFile);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return output;
|
|
16
|
+
|
|
17
|
+
//#region src/core/utils/building/internal-build.ts
|
|
18
|
+
/**
|
|
19
|
+
* Builds the extension based on an internal config. No more config discovery is performed, the
|
|
20
|
+
* build is based on exactly what is passed in.
|
|
21
|
+
*
|
|
22
|
+
* This function:
|
|
23
|
+
* 1. Cleans the output directory
|
|
24
|
+
* 2. Executes the rebuild function with a blank previous output so everything is built (see
|
|
25
|
+
* `rebuild` for more details)
|
|
26
|
+
* 3. Prints the summary
|
|
27
|
+
*/
|
|
28
|
+
async function internalBuild() {
|
|
29
|
+
await wxt.hooks.callHook("build:before", wxt);
|
|
30
|
+
const verb = wxt.config.command === "serve" ? "Pre-rendering" : "Building";
|
|
31
|
+
const target = `${wxt.config.browser}-mv${wxt.config.manifestVersion}`;
|
|
32
|
+
wxt.logger.info(`${verb} ${pc.cyan(target)} for ${pc.cyan(wxt.config.mode)} with ${pc.green(`${wxt.builder.name} ${wxt.builder.version}`)}`);
|
|
33
|
+
const startTime = Date.now();
|
|
34
|
+
await fs.rm(wxt.config.outDir, {
|
|
35
|
+
recursive: true,
|
|
36
|
+
force: true
|
|
37
|
+
});
|
|
38
|
+
await fs.ensureDir(wxt.config.outDir);
|
|
39
|
+
const entrypoints = await findEntrypoints();
|
|
40
|
+
wxt.logger.debug("Detected entrypoints:", entrypoints);
|
|
41
|
+
const validationResults = validateEntrypoints(entrypoints);
|
|
42
|
+
if (validationResults.errorCount + validationResults.warningCount > 0) printValidationResults(validationResults);
|
|
43
|
+
if (validationResults.errorCount > 0) throw new ValidationError(`Entrypoint validation failed`, { cause: validationResults });
|
|
44
|
+
const groups = groupEntrypoints(entrypoints);
|
|
45
|
+
await wxt.hooks.callHook("entrypoints:grouped", wxt, groups);
|
|
46
|
+
const { output, warnings } = await rebuild(entrypoints, groups, void 0);
|
|
47
|
+
await wxt.hooks.callHook("build:done", wxt, output);
|
|
48
|
+
await printBuildSummary(wxt.logger.success, `Built extension in ${formatDuration(Date.now() - startTime)}`, output);
|
|
49
|
+
for (const warning of warnings) wxt.logger.warn(...warning);
|
|
50
|
+
if (wxt.config.analysis.enabled) {
|
|
51
|
+
await combineAnalysisStats();
|
|
52
|
+
const statsPath = relative(wxt.config.root, wxt.config.analysis.outputFile);
|
|
53
|
+
wxt.logger.info(`Analysis complete:\n ${pc.gray("└─")} ${pc.yellow(statsPath)}`);
|
|
54
|
+
if (wxt.config.analysis.open) if (isCI) wxt.logger.debug(`Skipped opening ${pc.yellow(statsPath)} in CI`);
|
|
55
|
+
else {
|
|
56
|
+
wxt.logger.info(`Opening ${pc.yellow(statsPath)} in browser...`);
|
|
57
|
+
const { default: open } = await import("open");
|
|
58
|
+
await open(wxt.config.analysis.outputFile);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return output;
|
|
71
62
|
}
|
|
72
63
|
async function combineAnalysisStats() {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (!wxt.config.analysis.keepArtifacts) {
|
|
84
|
-
await Promise.all(absolutePaths.map((statsFile) => fs.remove(statsFile)));
|
|
85
|
-
}
|
|
64
|
+
const absolutePaths = (await glob(`${wxt.config.analysis.outputName}-*.json`, {
|
|
65
|
+
cwd: wxt.config.analysis.outputDir,
|
|
66
|
+
absolute: true
|
|
67
|
+
})).map(unnormalizePath);
|
|
68
|
+
await mergeJsonOutputs({
|
|
69
|
+
inputs: absolutePaths,
|
|
70
|
+
template: wxt.config.analysis.template,
|
|
71
|
+
filename: wxt.config.analysis.outputFile
|
|
72
|
+
});
|
|
73
|
+
if (!wxt.config.analysis.keepArtifacts) await Promise.all(absolutePaths.map((statsFile) => fs.remove(statsFile)));
|
|
86
74
|
}
|
|
87
|
-
function printValidationResults({
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
errors2.forEach((err) => {
|
|
106
|
-
const type = err.type === "error" ? pc.red("ERROR") : pc.yellow("WARN");
|
|
107
|
-
const recieved = pc.dim(`(recieved: ${JSON.stringify(err.value)})`);
|
|
108
|
-
wxt.logger.log(` - ${type} ${err.message} ${recieved}`);
|
|
109
|
-
});
|
|
110
|
-
console.log();
|
|
111
|
-
});
|
|
75
|
+
function printValidationResults({ errorCount, errors, warningCount }) {
|
|
76
|
+
(errorCount > 0 ? wxt.logger.error : wxt.logger.warn)(`Entrypoint validation failed: ${errorCount} error${errorCount === 1 ? "" : "s"}, ${warningCount} warning${warningCount === 1 ? "" : "s"}`);
|
|
77
|
+
const cwd = process.cwd();
|
|
78
|
+
const entrypointErrors = errors.reduce((map, error) => {
|
|
79
|
+
const entryErrors = map.get(error.entrypoint) ?? [];
|
|
80
|
+
entryErrors.push(error);
|
|
81
|
+
map.set(error.entrypoint, entryErrors);
|
|
82
|
+
return map;
|
|
83
|
+
}, /* @__PURE__ */ new Map());
|
|
84
|
+
Array.from(entrypointErrors.entries()).forEach(([entrypoint, errors]) => {
|
|
85
|
+
wxt.logger.log(relative(cwd, entrypoint.inputPath) + "\n");
|
|
86
|
+
errors.forEach((err) => {
|
|
87
|
+
const type = err.type === "error" ? pc.red("ERROR") : pc.yellow("WARN");
|
|
88
|
+
const received = pc.dim(`(received: ${JSON.stringify(err.value)})`);
|
|
89
|
+
wxt.logger.log(` - ${type} ${err.message} ${received}`);
|
|
90
|
+
});
|
|
91
|
+
console.log();
|
|
92
|
+
});
|
|
112
93
|
}
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
export { internalBuild };
|
|
@@ -1,33 +1,53 @@
|
|
|
1
|
-
import { generateWxtDir } from "../../generate-wxt-dir.mjs";
|
|
2
|
-
import { buildEntrypoints } from "./build-entrypoints.mjs";
|
|
3
|
-
import { generateManifest, writeManifest } from "../../utils/manifest.mjs";
|
|
4
1
|
import { wxt } from "../../wxt.mjs";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { buildEntrypoints } from "./build-entrypoints.mjs";
|
|
3
|
+
import { generateWxtDir } from "../../generate-wxt-dir.mjs";
|
|
4
|
+
import { generateManifest, writeManifest } from "../manifest.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/core/utils/building/rebuild.ts
|
|
7
|
+
/**
|
|
8
|
+
* Given a configuration, list of entrypoints, and an existing, partial output, build the
|
|
9
|
+
* entrypoints and merge the new output with the existing output.
|
|
10
|
+
*
|
|
11
|
+
* This function will:
|
|
12
|
+
* 1. Generate the .wxt directory's types
|
|
13
|
+
* 2. Build the `entrypointGroups` (and copies public files)
|
|
14
|
+
* 3. Generate the latest manifest for all entrypoints
|
|
15
|
+
* 4. Write the new manifest to the file system
|
|
16
|
+
*
|
|
17
|
+
* @param config Internal config containing all the project information.
|
|
18
|
+
* @param allEntrypoints List of entrypoints used to generate the types inside .wxt directory.
|
|
19
|
+
* @param entrypointGroups The list of entrypoint groups to build.
|
|
20
|
+
* @param existingOutput The previous output to combine the rebuild results into. An emptry array if
|
|
21
|
+
* this is the first build.
|
|
22
|
+
*/
|
|
23
|
+
async function rebuild(allEntrypoints, entrypointGroups, existingOutput = {
|
|
24
|
+
steps: [],
|
|
25
|
+
publicAssets: []
|
|
8
26
|
}) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
};
|
|
27
|
+
const { default: ora } = await import("ora");
|
|
28
|
+
const spinner = ora(`Preparing...`).start();
|
|
29
|
+
await generateWxtDir(allEntrypoints).catch((err) => {
|
|
30
|
+
wxt.logger.warn("Failed to update .wxt directory:", err);
|
|
31
|
+
if (wxt.config.command === "build") throw err;
|
|
32
|
+
});
|
|
33
|
+
const newOutput = await buildEntrypoints(entrypointGroups, spinner);
|
|
34
|
+
const mergedOutput = {
|
|
35
|
+
steps: [...existingOutput.steps, ...newOutput.steps],
|
|
36
|
+
publicAssets: newOutput.publicAssets
|
|
37
|
+
};
|
|
38
|
+
const { manifest: newManifest, warnings: manifestWarnings } = await generateManifest(allEntrypoints, mergedOutput);
|
|
39
|
+
const finalOutput = {
|
|
40
|
+
manifest: newManifest,
|
|
41
|
+
...mergedOutput
|
|
42
|
+
};
|
|
43
|
+
await writeManifest(newManifest, finalOutput);
|
|
44
|
+
spinner.clear().stop();
|
|
45
|
+
return {
|
|
46
|
+
output: finalOutput,
|
|
47
|
+
manifest: newManifest,
|
|
48
|
+
warnings: manifestWarnings
|
|
49
|
+
};
|
|
33
50
|
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
export { rebuild };
|
|
@@ -1,21 +1,32 @@
|
|
|
1
|
+
import { writeFileIfDifferent } from "./fs.mjs";
|
|
1
2
|
import fs, { ensureDir } from "fs-extra";
|
|
2
3
|
import { dirname, resolve } from "path";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
|
|
5
|
+
//#region src/core/utils/cache.ts
|
|
6
|
+
/**
|
|
7
|
+
* A basic file system cache stored at `<srcDir>/.wxt/cache/<key>`. Just caches a string in a
|
|
8
|
+
* file for the given key.
|
|
9
|
+
*
|
|
10
|
+
* @param srcDir Absolute path to source directory. See `InternalConfig.srcDir`
|
|
11
|
+
*/
|
|
12
|
+
function createFsCache(wxtDir) {
|
|
13
|
+
const getPath = (key) => resolve(wxtDir, "cache", encodeURIComponent(key));
|
|
14
|
+
return {
|
|
15
|
+
async set(key, value) {
|
|
16
|
+
const path = getPath(key);
|
|
17
|
+
await ensureDir(dirname(path));
|
|
18
|
+
await writeFileIfDifferent(path, value);
|
|
19
|
+
},
|
|
20
|
+
async get(key) {
|
|
21
|
+
const path = getPath(key);
|
|
22
|
+
try {
|
|
23
|
+
return await fs.readFile(path, "utf-8");
|
|
24
|
+
} catch {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
21
29
|
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { createFsCache };
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/core/utils/constants.ts
|
|
2
|
+
/**
|
|
3
|
+
* Module ID used to build the background in dev mode if the extension doesn't include a background
|
|
4
|
+
* script/service worker.
|
|
5
|
+
*/
|
|
6
|
+
const VIRTUAL_NOOP_BACKGROUND_MODULE_ID = "virtual:user-background";
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { VIRTUAL_NOOP_BACKGROUND_MODULE_ID };
|
|
@@ -1,59 +1,61 @@
|
|
|
1
1
|
import { getEntrypointBundlePath } from "./entrypoints.mjs";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
2
|
+
|
|
3
|
+
//#region src/core/utils/content-scripts.ts
|
|
4
|
+
/**
|
|
5
|
+
* Returns a unique and consistent string hash based on a content scripts options.
|
|
6
|
+
*
|
|
7
|
+
* It is able to recognize default values,
|
|
8
|
+
*/
|
|
9
|
+
function hashContentScriptOptions(options) {
|
|
10
|
+
const simplifiedOptions = mapWxtOptionsToContentScript(options, void 0, void 0);
|
|
11
|
+
Object.keys(simplifiedOptions).forEach((key) => {
|
|
12
|
+
if (simplifiedOptions[key] == null) delete simplifiedOptions[key];
|
|
13
|
+
});
|
|
14
|
+
const withDefaults = {
|
|
15
|
+
exclude_globs: [],
|
|
16
|
+
exclude_matches: [],
|
|
17
|
+
include_globs: [],
|
|
18
|
+
match_about_blank: false,
|
|
19
|
+
run_at: "document_idle",
|
|
20
|
+
all_frames: false,
|
|
21
|
+
match_origin_as_fallback: false,
|
|
22
|
+
world: "ISOLATED",
|
|
23
|
+
...simplifiedOptions
|
|
24
|
+
};
|
|
25
|
+
return JSON.stringify(Object.entries(withDefaults).map(([key, value]) => {
|
|
26
|
+
if (Array.isArray(value)) return [key, value.sort()];
|
|
27
|
+
else return [key, value];
|
|
28
|
+
}).sort((l, r) => l[0].localeCompare(r[0])));
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
30
|
+
function mapWxtOptionsToContentScript(options, js, css) {
|
|
31
|
+
return {
|
|
32
|
+
matches: options.matches ?? [],
|
|
33
|
+
all_frames: options.allFrames,
|
|
34
|
+
match_about_blank: options.matchAboutBlank,
|
|
35
|
+
exclude_globs: options.excludeGlobs,
|
|
36
|
+
exclude_matches: options.excludeMatches,
|
|
37
|
+
include_globs: options.includeGlobs,
|
|
38
|
+
run_at: options.runAt,
|
|
39
|
+
css,
|
|
40
|
+
js,
|
|
41
|
+
match_origin_as_fallback: options.matchOriginAsFallback,
|
|
42
|
+
world: options.world
|
|
43
|
+
};
|
|
45
44
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
function mapWxtOptionsToRegisteredContentScript(options, js, css) {
|
|
46
|
+
return {
|
|
47
|
+
allFrames: options.allFrames,
|
|
48
|
+
excludeMatches: options.excludeMatches,
|
|
49
|
+
matches: options.matches,
|
|
50
|
+
runAt: options.runAt,
|
|
51
|
+
js,
|
|
52
|
+
css,
|
|
53
|
+
world: options.world
|
|
54
|
+
};
|
|
56
55
|
}
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
function getContentScriptJs(config, entrypoint) {
|
|
57
|
+
return [getEntrypointBundlePath(entrypoint, config.outDir, ".js")];
|
|
59
58
|
}
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
export { getContentScriptJs, hashContentScriptOptions, mapWxtOptionsToContentScript, mapWxtOptionsToRegisteredContentScript };
|
|
@@ -1,39 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return directives.map((entry) => entry.flat().join(" ")).join("; ") + ";";
|
|
38
|
-
}
|
|
39
|
-
}
|
|
1
|
+
//#region src/core/utils/content-security-policy.ts
|
|
2
|
+
var ContentSecurityPolicy = class ContentSecurityPolicy {
|
|
3
|
+
static DIRECTIVE_ORDER = {
|
|
4
|
+
"default-src": 0,
|
|
5
|
+
"script-src": 1,
|
|
6
|
+
"object-src": 2
|
|
7
|
+
};
|
|
8
|
+
data;
|
|
9
|
+
constructor(csp) {
|
|
10
|
+
if (csp) this.data = csp.split(";").map((section) => section.trim()).reduce((data, section) => {
|
|
11
|
+
const [key, ...values] = section.split(" ").map((item) => item.trim());
|
|
12
|
+
if (key) data[key] = values;
|
|
13
|
+
return data;
|
|
14
|
+
}, {});
|
|
15
|
+
else this.data = {};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Ensure a set of values are listed under a directive.
|
|
19
|
+
*/
|
|
20
|
+
add(directive, ...newValues) {
|
|
21
|
+
const values = this.data[directive] ?? [];
|
|
22
|
+
newValues.forEach((newValue) => {
|
|
23
|
+
if (!values.includes(newValue)) values.push(newValue);
|
|
24
|
+
});
|
|
25
|
+
this.data[directive] = values;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
toString() {
|
|
29
|
+
return Object.entries(this.data).sort(([l], [r]) => {
|
|
30
|
+
return (ContentSecurityPolicy.DIRECTIVE_ORDER[l] ?? 2) - (ContentSecurityPolicy.DIRECTIVE_ORDER[r] ?? 2);
|
|
31
|
+
}).map((entry) => entry.flat().join(" ")).join("; ") + ";";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { ContentSecurityPolicy };
|