wxt 0.18.15 → 0.19.0
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/bin/wxt.mjs +1 -1
- package/dist/browser/chrome.d.ts +17 -0
- package/dist/browser/chrome.mjs +7 -0
- package/dist/browser/index.d.ts +18 -0
- package/dist/browser/index.mjs +2 -0
- package/dist/builtin-modules/index.d.ts +2 -0
- package/dist/builtin-modules/index.mjs +2 -0
- package/dist/builtin-modules/unimport.d.ts +8 -0
- package/dist/builtin-modules/unimport.mjs +99 -0
- package/dist/cli/cli-utils.d.ts +25 -0
- package/dist/cli/cli-utils.mjs +58 -0
- package/dist/cli/commands.d.ts +2 -0
- package/dist/cli/commands.mjs +104 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.mjs +11 -0
- package/dist/client/app-config.d.ts +2 -0
- package/dist/client/app-config.mjs +4 -0
- package/dist/client/content-scripts/content-script-context.d.ts +114 -0
- package/dist/client/content-scripts/content-script-context.mjs +169 -0
- package/dist/client/content-scripts/custom-events.d.ts +10 -0
- package/dist/client/content-scripts/custom-events.mjs +13 -0
- package/dist/client/content-scripts/index.d.ts +2 -0
- package/dist/client/content-scripts/index.mjs +2 -0
- package/dist/client/content-scripts/location-watcher.d.ts +12 -0
- package/dist/client/content-scripts/location-watcher.mjs +22 -0
- package/dist/client/content-scripts/ui/index.d.ts +23 -0
- package/dist/client/content-scripts/ui/index.mjs +188 -0
- package/dist/{client.d.ts → client/content-scripts/ui/types.d.ts} +17 -45
- package/dist/client/content-scripts/ui/types.mjs +0 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.mjs +2 -0
- package/dist/core/build.d.ts +15 -0
- package/dist/core/build.mjs +6 -0
- package/dist/core/builders/vite/index.d.ts +3 -0
- package/dist/core/builders/vite/index.mjs +285 -0
- package/dist/core/builders/vite/plugins/bundleAnalysis.d.ts +7 -0
- package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +15 -0
- package/dist/core/builders/vite/plugins/cssEntrypoints.d.ts +13 -0
- package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +22 -0
- package/dist/core/builders/vite/plugins/defineImportMeta.d.ts +14 -0
- package/dist/core/builders/vite/plugins/defineImportMeta.mjs +13 -0
- package/dist/core/builders/vite/plugins/devHtmlPrerender.d.ts +7 -0
- package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +140 -0
- package/dist/core/builders/vite/plugins/devServerGlobals.d.ts +6 -0
- package/dist/core/builders/vite/plugins/devServerGlobals.mjs +15 -0
- package/dist/core/builders/vite/plugins/download.d.ts +10 -0
- package/dist/core/builders/vite/plugins/download.mjs +14 -0
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.d.ts +6 -0
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +16 -0
- package/dist/core/builders/vite/plugins/extensionApiMock.d.ts +11 -0
- package/dist/core/builders/vite/plugins/extensionApiMock.mjs +26 -0
- package/dist/core/builders/vite/plugins/globals.d.ts +3 -0
- package/dist/core/builders/vite/plugins/globals.mjs +15 -0
- package/dist/core/builders/vite/plugins/index.d.ts +17 -0
- package/dist/core/builders/vite/plugins/index.mjs +17 -0
- package/dist/core/builders/vite/plugins/multipageMove.d.ts +20 -0
- package/dist/core/builders/vite/plugins/multipageMove.mjs +59 -0
- package/dist/core/builders/vite/plugins/noopBackground.d.ts +6 -0
- package/dist/core/builders/vite/plugins/noopBackground.mjs +17 -0
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.d.ts +6 -0
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +12 -0
- package/dist/core/builders/vite/plugins/resolveAppConfig.d.ts +6 -0
- package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +26 -0
- package/dist/core/builders/vite/plugins/resolveExtensionApi.d.ts +10 -0
- package/dist/core/builders/vite/plugins/resolveExtensionApi.mjs +15 -0
- package/dist/core/builders/vite/plugins/resolveVirtualModules.d.ts +6 -0
- package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +30 -0
- package/dist/core/builders/vite/plugins/tsconfigPaths.d.ts +3 -0
- package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +12 -0
- package/dist/core/builders/vite/plugins/wxtPluginLoader.d.ts +6 -0
- package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +56 -0
- package/dist/core/clean.d.ts +21 -0
- package/dist/core/clean.mjs +38 -0
- package/dist/core/create-server.d.ts +11 -0
- package/dist/core/create-server.mjs +206 -0
- package/dist/core/define-config.d.ts +2 -0
- package/dist/core/define-config.mjs +3 -0
- package/dist/core/define-runner-config.d.ts +2 -0
- package/dist/core/define-runner-config.mjs +3 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.mjs +8 -0
- package/dist/core/initialize.d.ts +5 -0
- package/dist/core/initialize.mjs +128 -0
- package/dist/core/package-managers/bun.d.ts +2 -0
- package/dist/core/package-managers/bun.mjs +19 -0
- package/dist/core/package-managers/index.d.ts +2 -0
- package/dist/core/package-managers/index.mjs +65 -0
- package/dist/core/package-managers/npm.d.ts +17 -0
- package/dist/core/package-managers/npm.mjs +58 -0
- package/dist/core/package-managers/pnpm.d.ts +2 -0
- package/dist/core/package-managers/pnpm.mjs +21 -0
- package/dist/core/package-managers/types.d.ts +2 -0
- package/dist/core/package-managers/types.mjs +0 -0
- package/dist/core/package-managers/yarn.d.ts +2 -0
- package/dist/core/package-managers/yarn.mjs +31 -0
- package/dist/core/prepare.d.ts +2 -0
- package/dist/core/prepare.mjs +8 -0
- package/dist/core/runners/index.d.ts +2 -0
- package/dist/core/runners/index.mjs +12 -0
- package/dist/core/runners/manual.d.ts +5 -0
- package/dist/core/runners/manual.mjs +16 -0
- package/dist/core/runners/safari.d.ts +5 -0
- package/dist/core/runners/safari.mjs +16 -0
- package/dist/core/runners/web-ext.d.ts +5 -0
- package/dist/core/runners/web-ext.mjs +78 -0
- package/dist/core/runners/wsl.d.ts +5 -0
- package/dist/core/runners/wsl.mjs +16 -0
- package/dist/core/utils/arrays.d.ts +13 -0
- package/dist/{chunk-BERPNPEZ.js → core/utils/arrays.mjs} +6 -10
- package/dist/core/utils/building/build-entrypoints.d.ts +3 -0
- package/dist/core/utils/building/build-entrypoints.mjs +47 -0
- package/dist/core/utils/building/detect-dev-changes.d.ts +57 -0
- package/dist/core/utils/building/detect-dev-changes.mjs +93 -0
- package/dist/core/utils/building/find-entrypoints.d.ts +5 -0
- package/dist/core/utils/building/find-entrypoints.mjs +385 -0
- package/dist/core/utils/building/generate-wxt-dir.d.ts +5 -0
- package/dist/core/utils/building/generate-wxt-dir.mjs +192 -0
- package/dist/core/utils/building/group-entrypoints.d.ts +8 -0
- package/dist/core/utils/building/group-entrypoints.mjs +37 -0
- package/dist/core/utils/building/import-entrypoint.d.ts +16 -0
- package/dist/core/utils/building/import-entrypoint.mjs +97 -0
- package/dist/core/utils/building/index.d.ts +9 -0
- package/dist/core/utils/building/index.mjs +9 -0
- package/dist/core/utils/building/internal-build.d.ts +12 -0
- package/dist/core/utils/building/internal-build.mjs +112 -0
- package/dist/core/utils/building/rebuild.d.ts +23 -0
- package/dist/core/utils/building/rebuild.mjs +39 -0
- package/dist/core/utils/building/resolve-config.d.ts +11 -0
- package/dist/core/utils/building/resolve-config.mjs +364 -0
- package/dist/core/utils/cache.d.ts +8 -0
- package/dist/core/utils/cache.mjs +21 -0
- package/dist/core/utils/cli.d.ts +3 -0
- package/dist/core/utils/cli.mjs +26 -0
- package/dist/core/utils/constants.d.ts +5 -0
- package/dist/core/utils/constants.mjs +1 -0
- package/dist/core/utils/content-scripts.d.ts +11 -0
- package/dist/core/utils/content-scripts.mjs +60 -0
- package/dist/core/utils/content-security-policy.d.ts +14 -0
- package/dist/core/utils/content-security-policy.mjs +39 -0
- package/dist/core/utils/entrypoints.d.ts +25 -0
- package/dist/core/utils/entrypoints.mjs +31 -0
- package/dist/core/utils/eslint.d.ts +1 -0
- package/dist/core/utils/eslint.mjs +11 -0
- package/dist/core/utils/fs.d.ts +13 -0
- package/dist/core/utils/fs.mjs +15 -0
- package/dist/core/utils/globals.d.ts +11 -0
- package/dist/core/utils/globals.mjs +53 -0
- package/dist/core/utils/i18n.d.ts +11 -0
- package/dist/core/utils/i18n.mjs +35 -0
- package/dist/core/utils/log/index.d.ts +4 -0
- package/dist/core/utils/log/index.mjs +4 -0
- package/dist/core/utils/log/printBuildSummary.d.ts +2 -0
- package/dist/core/utils/log/printBuildSummary.mjs +32 -0
- package/dist/core/utils/log/printFileList.d.ts +1 -0
- package/dist/core/utils/log/printFileList.mjs +42 -0
- package/dist/core/utils/log/printHeader.d.ts +1 -0
- package/dist/core/utils/log/printHeader.mjs +7 -0
- package/dist/core/utils/log/printTable.d.ts +1 -0
- package/dist/core/utils/log/printTable.mjs +22 -0
- package/dist/core/utils/manifest.d.ts +44 -0
- package/dist/core/utils/manifest.mjs +512 -0
- package/dist/core/utils/network.d.ts +7 -0
- package/dist/core/utils/network.mjs +38 -0
- package/dist/core/utils/package.d.ts +6 -0
- package/dist/core/utils/package.mjs +14 -0
- package/dist/core/utils/paths.d.ts +11 -0
- package/dist/core/utils/paths.mjs +10 -0
- package/dist/core/utils/strings.d.ts +14 -0
- package/dist/core/utils/strings.mjs +18 -0
- package/dist/core/utils/testing/fake-objects.d.ts +4556 -0
- package/dist/core/utils/testing/fake-objects.mjs +322 -0
- package/dist/core/utils/time.d.ts +9 -0
- package/dist/core/utils/time.mjs +17 -0
- package/dist/core/utils/transform.d.ts +9 -0
- package/dist/core/utils/transform.mjs +17 -0
- package/dist/core/utils/types.d.ts +10 -0
- package/dist/core/utils/types.mjs +0 -0
- package/dist/core/utils/validation.d.ts +15 -0
- package/dist/core/utils/validation.mjs +55 -0
- package/dist/core/utils/virtual-modules.d.ts +22 -0
- package/dist/core/utils/virtual-modules.mjs +14 -0
- package/dist/core/utils/wsl.d.ts +4 -0
- package/dist/core/utils/wsl.mjs +4 -0
- package/dist/core/wxt.d.ts +19 -0
- package/dist/core/wxt.mjs +41 -0
- package/dist/core/zip.d.ts +7 -0
- package/dist/core/zip.mjs +137 -0
- package/dist/index.d.ts +4 -79
- package/dist/index.mjs +3 -0
- package/dist/modules.d.ts +10 -20
- package/dist/{chunk-6XSIWUWF.js → modules.mjs} +7 -16
- package/dist/sandbox/define-app-config.d.ts +19 -0
- package/dist/sandbox/define-app-config.mjs +3 -0
- package/dist/sandbox/define-background.d.ts +3 -0
- package/dist/sandbox/define-background.mjs +4 -0
- package/dist/sandbox/define-content-script.d.ts +2 -0
- package/dist/sandbox/define-content-script.mjs +3 -0
- package/dist/sandbox/define-unlisted-script.d.ts +3 -0
- package/dist/sandbox/define-unlisted-script.mjs +4 -0
- package/dist/sandbox/define-wxt-plugin.d.ts +2 -0
- package/dist/sandbox/define-wxt-plugin.mjs +3 -0
- package/dist/sandbox/dev-server-websocket.d.ts +21 -0
- package/dist/sandbox/dev-server-websocket.mjs +37 -0
- package/dist/sandbox/index.d.ts +11 -0
- package/dist/sandbox/index.mjs +6 -0
- package/dist/sandbox/utils/logger.d.ts +9 -0
- package/dist/sandbox/utils/logger.mjs +15 -0
- package/dist/storage.d.ts +39 -16
- package/dist/{storage.js → storage.mjs} +30 -41
- package/dist/testing/fake-browser.d.ts +1 -0
- package/dist/testing/fake-browser.mjs +1 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.mjs +2 -0
- package/dist/{testing.d.ts → testing/wxt-vitest-plugin.d.ts} +3 -15
- package/dist/testing/wxt-vitest-plugin.mjs +26 -0
- package/dist/{index-nWRfwAJi.d.cts → types.d.ts} +150 -264
- package/dist/types.mjs +0 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.mjs +1 -0
- package/dist/virtual/{background-entrypoint.js → background-entrypoint.mjs} +31 -40
- package/dist/virtual/{content-script-isolated-world-entrypoint.js → content-script-isolated-world-entrypoint.mjs} +9 -13
- package/dist/virtual/{content-script-main-world-entrypoint.js → content-script-main-world-entrypoint.mjs} +9 -14
- package/dist/virtual/mock-browser.mjs +6 -0
- package/dist/virtual/{reload-html.js → reload-html.mjs} +8 -9
- package/dist/virtual/{unlisted-script-entrypoint.js → unlisted-script-entrypoint.mjs} +8 -12
- package/package.json +47 -57
- package/dist/browser.d.ts +0 -18
- package/dist/browser.js +0 -6
- package/dist/chunk-BM6QYGAW.js +0 -1063
- package/dist/chunk-FNTE2L27.js +0 -7
- package/dist/chunk-FP7RYLVL.js +0 -3617
- package/dist/chunk-KPD5J7PZ.js +0 -1065
- package/dist/chunk-QGM4M3NI.js +0 -37
- package/dist/chunk-SGKCDMVR.js +0 -38
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -4438
- package/dist/client.js +0 -424
- package/dist/define-app-config-bg54F_lV.d.ts +0 -294
- package/dist/execa-4UBDUBJZ.js +0 -7244
- package/dist/execa-QLUM2B3W.js +0 -7245
- package/dist/index-nWRfwAJi.d.ts +0 -1401
- package/dist/index.cjs +0 -14473
- package/dist/index.d.cts +0 -81
- package/dist/index.js +0 -696
- package/dist/modules.cjs +0 -96
- package/dist/modules.d.cts +0 -119
- package/dist/modules.js +0 -17
- package/dist/prompt-25QIVJDC.js +0 -755
- package/dist/prompt-7BMKNSWS.js +0 -754
- package/dist/sandbox.d.ts +0 -16
- package/dist/sandbox.js +0 -36
- package/dist/storage.cjs +0 -439
- package/dist/storage.d.cts +0 -200
- package/dist/testing.cjs +0 -2815
- package/dist/testing.d.cts +0 -30
- package/dist/testing.js +0 -40
- package/dist/virtual/mock-browser.js +0 -6
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { resolve } from "path";
|
|
2
|
+
import { faker } from "@faker-js/faker";
|
|
3
|
+
import merge from "lodash.merge";
|
|
4
|
+
import { mock } from "vitest-mock-extended";
|
|
5
|
+
import { vi } from "vitest";
|
|
6
|
+
import { setWxtForTesting } from "../../../core/wxt.mjs";
|
|
7
|
+
faker.seed(import.meta.test.SEED);
|
|
8
|
+
function fakeObjectCreator(base) {
|
|
9
|
+
return (overrides) => merge(base(), overrides);
|
|
10
|
+
}
|
|
11
|
+
export function fakeFileName() {
|
|
12
|
+
return faker.string.alphanumeric() + "." + faker.string.alpha({ length: 3 });
|
|
13
|
+
}
|
|
14
|
+
export function fakeFile(root = process.cwd()) {
|
|
15
|
+
return resolve(root, fakeFileName());
|
|
16
|
+
}
|
|
17
|
+
export function fakeDir(root = process.cwd()) {
|
|
18
|
+
return resolve(root, faker.string.alphanumeric());
|
|
19
|
+
}
|
|
20
|
+
export const fakeEntrypoint = () => faker.helpers.arrayElement([
|
|
21
|
+
fakePopupEntrypoint,
|
|
22
|
+
fakeGenericEntrypoint,
|
|
23
|
+
fakeOptionsEntrypoint,
|
|
24
|
+
fakeBackgroundEntrypoint,
|
|
25
|
+
fakeContentScriptEntrypoint,
|
|
26
|
+
fakeUnlistedScriptEntrypoint
|
|
27
|
+
])();
|
|
28
|
+
export const fakeContentScriptEntrypoint = fakeObjectCreator(() => ({
|
|
29
|
+
type: "content-script",
|
|
30
|
+
inputPath: fakeFile("src"),
|
|
31
|
+
name: faker.string.alpha(),
|
|
32
|
+
options: {
|
|
33
|
+
matches: [],
|
|
34
|
+
matchAboutBlank: faker.datatype.boolean(),
|
|
35
|
+
matchOriginAsFallback: faker.helpers.arrayElement([
|
|
36
|
+
true,
|
|
37
|
+
false,
|
|
38
|
+
void 0
|
|
39
|
+
]),
|
|
40
|
+
runAt: faker.helpers.arrayElement([
|
|
41
|
+
"document_start",
|
|
42
|
+
"document_end",
|
|
43
|
+
"document_idle",
|
|
44
|
+
void 0
|
|
45
|
+
])
|
|
46
|
+
},
|
|
47
|
+
outputDir: fakeDir(".output"),
|
|
48
|
+
skipped: faker.datatype.boolean()
|
|
49
|
+
}));
|
|
50
|
+
export const fakeBackgroundEntrypoint = fakeObjectCreator(
|
|
51
|
+
() => ({
|
|
52
|
+
type: "background",
|
|
53
|
+
inputPath: "entrypoints/background.ts",
|
|
54
|
+
name: "background",
|
|
55
|
+
options: {
|
|
56
|
+
persistent: faker.datatype.boolean(),
|
|
57
|
+
type: faker.helpers.maybe(() => "module")
|
|
58
|
+
},
|
|
59
|
+
outputDir: fakeDir(".output"),
|
|
60
|
+
skipped: faker.datatype.boolean()
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
export const fakeUnlistedScriptEntrypoint = fakeObjectCreator(() => ({
|
|
64
|
+
type: "unlisted-script",
|
|
65
|
+
inputPath: fakeFile("src"),
|
|
66
|
+
name: faker.string.alpha(),
|
|
67
|
+
outputDir: fakeDir(".output"),
|
|
68
|
+
options: {},
|
|
69
|
+
skipped: faker.datatype.boolean()
|
|
70
|
+
}));
|
|
71
|
+
export const fakeOptionsEntrypoint = fakeObjectCreator(
|
|
72
|
+
() => ({
|
|
73
|
+
type: "options",
|
|
74
|
+
inputPath: "entrypoints/options.html",
|
|
75
|
+
name: "options",
|
|
76
|
+
outputDir: fakeDir(".output"),
|
|
77
|
+
options: {
|
|
78
|
+
browserStyle: faker.datatype.boolean(),
|
|
79
|
+
chromeStyle: faker.datatype.boolean(),
|
|
80
|
+
openInTab: faker.datatype.boolean()
|
|
81
|
+
},
|
|
82
|
+
skipped: faker.datatype.boolean()
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
export const fakePopupEntrypoint = fakeObjectCreator(() => ({
|
|
86
|
+
type: "popup",
|
|
87
|
+
inputPath: "entrypoints/popup.html",
|
|
88
|
+
name: "popup",
|
|
89
|
+
outputDir: fakeDir(".output"),
|
|
90
|
+
options: {
|
|
91
|
+
defaultTitle: faker.helpers.arrayElement([
|
|
92
|
+
faker.person.fullName(),
|
|
93
|
+
void 0
|
|
94
|
+
]),
|
|
95
|
+
defaultIcon: faker.helpers.arrayElement([
|
|
96
|
+
{
|
|
97
|
+
"16": "icon/16.png",
|
|
98
|
+
"24": "icon/24.png",
|
|
99
|
+
"64": "icon/64.png"
|
|
100
|
+
}
|
|
101
|
+
]),
|
|
102
|
+
mv2Key: faker.helpers.arrayElement([
|
|
103
|
+
"browser_action",
|
|
104
|
+
"page_action",
|
|
105
|
+
void 0
|
|
106
|
+
])
|
|
107
|
+
},
|
|
108
|
+
skipped: faker.datatype.boolean()
|
|
109
|
+
}));
|
|
110
|
+
export const fakeSidepanelEntrypoint = fakeObjectCreator(
|
|
111
|
+
() => ({
|
|
112
|
+
type: "sidepanel",
|
|
113
|
+
inputPath: "entrypoints/sidepanel.html",
|
|
114
|
+
name: "sidepanel",
|
|
115
|
+
outputDir: fakeDir(".output"),
|
|
116
|
+
options: {
|
|
117
|
+
defaultTitle: faker.helpers.arrayElement([
|
|
118
|
+
faker.person.fullName(),
|
|
119
|
+
void 0
|
|
120
|
+
]),
|
|
121
|
+
defaultIcon: faker.helpers.arrayElement([
|
|
122
|
+
{
|
|
123
|
+
"16": "icon/16.png",
|
|
124
|
+
"24": "icon/24.png",
|
|
125
|
+
"64": "icon/64.png"
|
|
126
|
+
}
|
|
127
|
+
]),
|
|
128
|
+
openAtInstall: faker.helpers.arrayElement([true, false, void 0])
|
|
129
|
+
},
|
|
130
|
+
skipped: faker.datatype.boolean()
|
|
131
|
+
})
|
|
132
|
+
);
|
|
133
|
+
export const fakeGenericEntrypoint = fakeObjectCreator(
|
|
134
|
+
() => ({
|
|
135
|
+
type: faker.helpers.arrayElement([
|
|
136
|
+
"sandbox",
|
|
137
|
+
"bookmarks",
|
|
138
|
+
"history",
|
|
139
|
+
"newtab",
|
|
140
|
+
"devtools",
|
|
141
|
+
"unlisted-page",
|
|
142
|
+
"unlisted-script"
|
|
143
|
+
]),
|
|
144
|
+
inputPath: fakeFile("src"),
|
|
145
|
+
name: faker.string.alpha(),
|
|
146
|
+
outputDir: fakeDir(".output"),
|
|
147
|
+
options: {},
|
|
148
|
+
skipped: faker.datatype.boolean()
|
|
149
|
+
})
|
|
150
|
+
);
|
|
151
|
+
export const fakeOutputChunk = fakeObjectCreator(() => ({
|
|
152
|
+
type: "chunk",
|
|
153
|
+
fileName: faker.string.alphanumeric(),
|
|
154
|
+
moduleIds: []
|
|
155
|
+
}));
|
|
156
|
+
export const fakeOutputAsset = fakeObjectCreator(() => ({
|
|
157
|
+
type: "asset",
|
|
158
|
+
fileName: fakeFileName()
|
|
159
|
+
}));
|
|
160
|
+
export function fakeOutputFile() {
|
|
161
|
+
return faker.helpers.arrayElement([fakeOutputAsset(), fakeOutputChunk()]);
|
|
162
|
+
}
|
|
163
|
+
export const fakeManifest = fakeObjectCreator(
|
|
164
|
+
() => ({
|
|
165
|
+
manifest_version: faker.helpers.arrayElement([2, 3]),
|
|
166
|
+
name: faker.string.alphanumeric(),
|
|
167
|
+
version: `${faker.number.int()}.${faker.number.int()}.${faker.number.int()}`
|
|
168
|
+
})
|
|
169
|
+
);
|
|
170
|
+
export const fakeUserManifest = fakeObjectCreator(() => ({
|
|
171
|
+
name: faker.string.alphanumeric(),
|
|
172
|
+
version: `${faker.number.int()}.${faker.number.int()}.${faker.number.int()}`
|
|
173
|
+
}));
|
|
174
|
+
export function fakeArray(createItem, count = 3) {
|
|
175
|
+
const array = [];
|
|
176
|
+
for (let i = 0; i < count; i++) {
|
|
177
|
+
array.push(createItem());
|
|
178
|
+
}
|
|
179
|
+
return array;
|
|
180
|
+
}
|
|
181
|
+
export const fakeResolvedConfig = fakeObjectCreator(() => {
|
|
182
|
+
const browser = faker.helpers.arrayElement(["chrome", "firefox"]);
|
|
183
|
+
const command = faker.helpers.arrayElement(["build", "serve"]);
|
|
184
|
+
const manifestVersion = faker.helpers.arrayElement([2, 3]);
|
|
185
|
+
const mode = faker.helpers.arrayElement(["development", "production"]);
|
|
186
|
+
return {
|
|
187
|
+
browser,
|
|
188
|
+
command,
|
|
189
|
+
entrypointsDir: fakeDir(),
|
|
190
|
+
modulesDir: fakeDir(),
|
|
191
|
+
builtinModules: [],
|
|
192
|
+
userModules: [],
|
|
193
|
+
env: { browser, command, manifestVersion, mode },
|
|
194
|
+
fsCache: mock(),
|
|
195
|
+
imports: {
|
|
196
|
+
eslintrc: {
|
|
197
|
+
enabled: faker.helpers.arrayElement([false, 8, 9]),
|
|
198
|
+
filePath: fakeFile(),
|
|
199
|
+
globalsPropValue: faker.helpers.arrayElement([
|
|
200
|
+
true,
|
|
201
|
+
false,
|
|
202
|
+
"readable",
|
|
203
|
+
"readonly",
|
|
204
|
+
"writable",
|
|
205
|
+
"writeable"
|
|
206
|
+
])
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
logger: mock(),
|
|
210
|
+
manifest: fakeUserManifest(),
|
|
211
|
+
manifestVersion,
|
|
212
|
+
mode,
|
|
213
|
+
outBaseDir: fakeDir(),
|
|
214
|
+
outDir: fakeDir(),
|
|
215
|
+
publicDir: fakeDir(),
|
|
216
|
+
root: fakeDir(),
|
|
217
|
+
wxtModuleDir: fakeDir(),
|
|
218
|
+
runnerConfig: {
|
|
219
|
+
config: {}
|
|
220
|
+
},
|
|
221
|
+
debug: faker.datatype.boolean(),
|
|
222
|
+
srcDir: fakeDir(),
|
|
223
|
+
typesDir: fakeDir(),
|
|
224
|
+
wxtDir: fakeDir(),
|
|
225
|
+
analysis: {
|
|
226
|
+
enabled: false,
|
|
227
|
+
open: false,
|
|
228
|
+
template: "treemap",
|
|
229
|
+
outputFile: fakeFile(),
|
|
230
|
+
outputDir: fakeDir(),
|
|
231
|
+
outputName: "stats",
|
|
232
|
+
keepArtifacts: false
|
|
233
|
+
},
|
|
234
|
+
zip: {
|
|
235
|
+
artifactTemplate: "{{name}}-{{version}}.zip",
|
|
236
|
+
includeSources: [],
|
|
237
|
+
excludeSources: [],
|
|
238
|
+
sourcesRoot: fakeDir(),
|
|
239
|
+
sourcesTemplate: "{{name}}-sources.zip",
|
|
240
|
+
name: faker.person.firstName().toLowerCase(),
|
|
241
|
+
downloadedPackagesDir: fakeDir(),
|
|
242
|
+
downloadPackages: [],
|
|
243
|
+
compressionLevel: 9
|
|
244
|
+
},
|
|
245
|
+
transformManifest: () => {
|
|
246
|
+
},
|
|
247
|
+
userConfigMetadata: {},
|
|
248
|
+
alias: {},
|
|
249
|
+
extensionApi: "webextension-polyfill",
|
|
250
|
+
browserModule: "wxt/browser",
|
|
251
|
+
entrypointLoader: "vite-node",
|
|
252
|
+
experimental: {},
|
|
253
|
+
dev: {
|
|
254
|
+
reloadCommand: "Alt+R"
|
|
255
|
+
},
|
|
256
|
+
hooks: {},
|
|
257
|
+
vite: () => ({}),
|
|
258
|
+
plugins: []
|
|
259
|
+
};
|
|
260
|
+
});
|
|
261
|
+
export const fakeWxt = fakeObjectCreator(() => ({
|
|
262
|
+
config: fakeResolvedConfig(),
|
|
263
|
+
hooks: mock(),
|
|
264
|
+
logger: mock(),
|
|
265
|
+
reloadConfig: vi.fn(),
|
|
266
|
+
pm: mock(),
|
|
267
|
+
server: faker.helpers.arrayElement([void 0, fakeWxtDevServer()]),
|
|
268
|
+
builder: mock()
|
|
269
|
+
}));
|
|
270
|
+
export const fakeWxtDevServer = fakeObjectCreator(() => ({
|
|
271
|
+
currentOutput: fakeBuildOutput(),
|
|
272
|
+
hostname: "localhost",
|
|
273
|
+
origin: "http://localhost:3000",
|
|
274
|
+
port: 3e3,
|
|
275
|
+
reloadContentScript: vi.fn(),
|
|
276
|
+
reloadExtension: vi.fn(),
|
|
277
|
+
reloadPage: vi.fn(),
|
|
278
|
+
restart: vi.fn(),
|
|
279
|
+
restartBrowser: vi.fn(),
|
|
280
|
+
start: vi.fn(),
|
|
281
|
+
stop: vi.fn(),
|
|
282
|
+
transformHtml: vi.fn(),
|
|
283
|
+
watcher: mock(),
|
|
284
|
+
ws: mock()
|
|
285
|
+
}));
|
|
286
|
+
export function setFakeWxt(overrides) {
|
|
287
|
+
const wxt = fakeWxt(overrides);
|
|
288
|
+
setWxtForTesting(wxt);
|
|
289
|
+
return wxt;
|
|
290
|
+
}
|
|
291
|
+
export const fakeBuildOutput = fakeObjectCreator(() => ({
|
|
292
|
+
manifest: fakeManifest(),
|
|
293
|
+
publicAssets: fakeArray(fakeOutputAsset),
|
|
294
|
+
steps: fakeArray(fakeBuildStepOutput)
|
|
295
|
+
}));
|
|
296
|
+
export const fakeBuildStepOutput = fakeObjectCreator(() => ({
|
|
297
|
+
chunks: fakeArray(fakeOutputChunk),
|
|
298
|
+
entrypoints: fakeArray(fakeEntrypoint)
|
|
299
|
+
}));
|
|
300
|
+
export const fakeManifestCommand = fakeObjectCreator(() => ({
|
|
301
|
+
description: faker.string.sample(),
|
|
302
|
+
shortcut: `${faker.helpers.arrayElement(["ctrl", "alt"])}+${faker.number.int({
|
|
303
|
+
min: 0,
|
|
304
|
+
max: 9
|
|
305
|
+
})}`
|
|
306
|
+
}));
|
|
307
|
+
export const fakeDevServer = fakeObjectCreator(() => ({
|
|
308
|
+
hostname: "localhost",
|
|
309
|
+
origin: "http://localhost",
|
|
310
|
+
port: 5173,
|
|
311
|
+
reloadContentScript: vi.fn(),
|
|
312
|
+
reloadExtension: vi.fn(),
|
|
313
|
+
reloadPage: vi.fn(),
|
|
314
|
+
restart: vi.fn(),
|
|
315
|
+
restartBrowser: vi.fn(),
|
|
316
|
+
stop: vi.fn(),
|
|
317
|
+
start: vi.fn(),
|
|
318
|
+
watcher: mock(),
|
|
319
|
+
transformHtml: vi.fn(),
|
|
320
|
+
ws: mock(),
|
|
321
|
+
currentOutput: void 0
|
|
322
|
+
}));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function formatDuration(duration: number): string;
|
|
2
|
+
/**
|
|
3
|
+
* Add a timeout to a promise.
|
|
4
|
+
*/
|
|
5
|
+
export declare function withTimeout<T>(promise: Promise<T>, duration: number): Promise<T>;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Don't use in production, just for testing and slowing things down.
|
|
8
|
+
*/
|
|
9
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function formatDuration(duration) {
|
|
2
|
+
if (duration < 1e3) return `${duration} ms`;
|
|
3
|
+
if (duration < 1e4) return `${(duration / 1e3).toFixed(3)} s`;
|
|
4
|
+
if (duration < 6e4) return `${(duration / 1e3).toFixed(1)} s`;
|
|
5
|
+
return `${(duration / 1e3).toFixed(0)} s`;
|
|
6
|
+
}
|
|
7
|
+
export function withTimeout(promise, duration) {
|
|
8
|
+
return new Promise((res, rej) => {
|
|
9
|
+
const timeout = setTimeout(() => {
|
|
10
|
+
rej(`Promise timed out after ${duration}ms`);
|
|
11
|
+
}, duration);
|
|
12
|
+
promise.then(res).catch(rej).finally(() => clearTimeout(timeout));
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export function sleep(ms) {
|
|
16
|
+
return new Promise((res) => setTimeout(res, ms));
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes any code used at runtime related to an entrypoint's main function.
|
|
3
|
+
* - Removes or clears out `main` function from returned object
|
|
4
|
+
* - TODO: Removes unused imports after main function has been removed to prevent importing runtime modules
|
|
5
|
+
*/
|
|
6
|
+
export declare function removeMainFunctionCode(code: string): {
|
|
7
|
+
code: string;
|
|
8
|
+
map?: string;
|
|
9
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { parseModule } from "magicast";
|
|
2
|
+
export function removeMainFunctionCode(code) {
|
|
3
|
+
const mod = parseModule(code);
|
|
4
|
+
emptyMainFunction(mod);
|
|
5
|
+
return mod.generate();
|
|
6
|
+
}
|
|
7
|
+
function emptyMainFunction(mod) {
|
|
8
|
+
if (mod.exports?.default?.$type === "function-call") {
|
|
9
|
+
if (mod.exports.default.$ast?.arguments?.[0]?.body) {
|
|
10
|
+
mod.exports.default.$ast.arguments[0].body.body = [];
|
|
11
|
+
} else if (mod.exports.default.$ast?.arguments?.[0]?.properties) {
|
|
12
|
+
mod.exports.default.$ast.arguments[0].properties = mod.exports.default.$ast.arguments[0].properties.filter(
|
|
13
|
+
(prop) => prop.key.name !== "main"
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove optional from key, but keep undefined if present
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* type Test = NullablyRequired<{a?: string, b: number}>
|
|
6
|
+
* // type Test = {a: string | undefined, b: number}
|
|
7
|
+
*/
|
|
8
|
+
export type NullablyRequired<T> = {
|
|
9
|
+
[K in keyof Required<T>]: T[K];
|
|
10
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Entrypoint } from '../../types';
|
|
2
|
+
export declare function validateEntrypoints(entrypoints: Entrypoint[]): ValidationResults;
|
|
3
|
+
export interface ValidationResult {
|
|
4
|
+
type: 'warning' | 'error';
|
|
5
|
+
message: string;
|
|
6
|
+
entrypoint: Entrypoint;
|
|
7
|
+
value: any;
|
|
8
|
+
}
|
|
9
|
+
export interface ValidationResults {
|
|
10
|
+
errors: ValidationResult[];
|
|
11
|
+
errorCount: number;
|
|
12
|
+
warningCount: number;
|
|
13
|
+
}
|
|
14
|
+
export declare class ValidationError extends Error {
|
|
15
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export function validateEntrypoints(entrypoints) {
|
|
2
|
+
const errors = entrypoints.flatMap((entrypoint) => {
|
|
3
|
+
switch (entrypoint.type) {
|
|
4
|
+
case "content-script":
|
|
5
|
+
return validateContentScriptEntrypoint(entrypoint);
|
|
6
|
+
default:
|
|
7
|
+
return validateBaseEntrypoint(entrypoint);
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
let errorCount = 0;
|
|
11
|
+
let warningCount = 0;
|
|
12
|
+
for (const err of errors) {
|
|
13
|
+
if (err.type === "warning") warningCount++;
|
|
14
|
+
else errorCount++;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
errors,
|
|
18
|
+
errorCount,
|
|
19
|
+
warningCount
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function validateContentScriptEntrypoint(definition) {
|
|
23
|
+
const errors = validateBaseEntrypoint(definition);
|
|
24
|
+
if (definition.options.matches == null) {
|
|
25
|
+
errors.push({
|
|
26
|
+
type: "error",
|
|
27
|
+
message: "`matches` is required",
|
|
28
|
+
value: definition.options.matches,
|
|
29
|
+
entrypoint: definition
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return errors;
|
|
33
|
+
}
|
|
34
|
+
function validateBaseEntrypoint(definition) {
|
|
35
|
+
const errors = [];
|
|
36
|
+
if (definition.options.exclude != null && !Array.isArray(definition.options.exclude)) {
|
|
37
|
+
errors.push({
|
|
38
|
+
type: "error",
|
|
39
|
+
message: "`exclude` must be an array of browser names",
|
|
40
|
+
value: definition.options.exclude,
|
|
41
|
+
entrypoint: definition
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (definition.options.include != null && !Array.isArray(definition.options.include)) {
|
|
45
|
+
errors.push({
|
|
46
|
+
type: "error",
|
|
47
|
+
message: "`include` must be an array of browser names",
|
|
48
|
+
value: definition.options.include,
|
|
49
|
+
entrypoint: definition
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return errors;
|
|
53
|
+
}
|
|
54
|
+
export class ValidationError extends Error {
|
|
55
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const virtualEntrypointTypes: ("background" | "unlisted-script" | "content-script-main-world" | "content-script-isolated-world")[];
|
|
2
|
+
export type VirtualEntrypointType = (typeof virtualEntrypointTypes)[0];
|
|
3
|
+
/**
|
|
4
|
+
* All the names of entrypoint files in the `src/virtual/` and `dist/virtual/` directories, minus the extension.
|
|
5
|
+
*/
|
|
6
|
+
export declare const virtualEntrypointModuleNames: ("background-entrypoint" | "unlisted-script-entrypoint" | "content-script-main-world-entrypoint" | "content-script-isolated-world-entrypoint")[];
|
|
7
|
+
/**
|
|
8
|
+
* Name of entrypoint files in the `src/virtual/` and `dist/virtual/` directories, minus the extension.
|
|
9
|
+
*/
|
|
10
|
+
export type VirtualEntrypointModuleName = (typeof virtualEntrypointModuleNames)[0];
|
|
11
|
+
/**
|
|
12
|
+
* All the names of files in the `src/virtual/` and `dist/virtual/` directories, minus the extension.
|
|
13
|
+
*/
|
|
14
|
+
export declare const virtualModuleNames: ("background-entrypoint" | "unlisted-script-entrypoint" | "content-script-main-world-entrypoint" | "content-script-isolated-world-entrypoint" | "mock-browser" | "reload-html")[];
|
|
15
|
+
/**
|
|
16
|
+
* Name of files in the `src/virtual/` and `dist/virtual/` directories, minus the extension.
|
|
17
|
+
*/
|
|
18
|
+
export type VirtualModuleName = (typeof virtualModuleNames)[0];
|
|
19
|
+
/**
|
|
20
|
+
* Import alias used for importing a virtual module
|
|
21
|
+
*/
|
|
22
|
+
export type VirtualModuleId = `virtual:wxt-${VirtualModuleName}`;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const virtualEntrypointTypes = [
|
|
2
|
+
"content-script-main-world",
|
|
3
|
+
"content-script-isolated-world",
|
|
4
|
+
"background",
|
|
5
|
+
"unlisted-script"
|
|
6
|
+
];
|
|
7
|
+
export const virtualEntrypointModuleNames = virtualEntrypointTypes.map(
|
|
8
|
+
(name) => `${name}-entrypoint`
|
|
9
|
+
);
|
|
10
|
+
export const virtualModuleNames = [
|
|
11
|
+
...virtualEntrypointModuleNames,
|
|
12
|
+
"mock-browser",
|
|
13
|
+
"reload-html"
|
|
14
|
+
];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { InlineConfig, ResolvedConfig, Wxt, WxtCommand, WxtDevServer } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Global variable set once `createWxt` is called once. Since this variable is used everywhere, this
|
|
4
|
+
* global can be used instead of passing the variable as a function parameter everywhere.
|
|
5
|
+
*/
|
|
6
|
+
export declare let wxt: Wxt;
|
|
7
|
+
/**
|
|
8
|
+
* Create and register a global instance of the Wxt interface for use throughout the project.
|
|
9
|
+
*/
|
|
10
|
+
export declare function registerWxt(command: WxtCommand, inlineConfig?: InlineConfig, getServer?: (config: ResolvedConfig) => Promise<WxtDevServer>): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* @internal ONLY USE FOR TESTING.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* setWxtForTesting(fakeWxt({ ... }));
|
|
16
|
+
* // Or use the shorthand
|
|
17
|
+
* setFakeWxt({ ... })
|
|
18
|
+
*/
|
|
19
|
+
export declare function setWxtForTesting(testInstance: Wxt): void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { resolveConfig } from "./utils/building/index.mjs";
|
|
2
|
+
import { createHooks } from "hookable";
|
|
3
|
+
import { createWxtPackageManager } from "./package-managers/index.mjs";
|
|
4
|
+
import { createViteBuilder } from "./builders/vite/index.mjs";
|
|
5
|
+
import { builtinModules } from "../builtin-modules/index.mjs";
|
|
6
|
+
export let wxt;
|
|
7
|
+
export async function registerWxt(command, inlineConfig = {}, getServer) {
|
|
8
|
+
const hooks = createHooks();
|
|
9
|
+
const config = await resolveConfig(inlineConfig, command);
|
|
10
|
+
const server = await getServer?.(config);
|
|
11
|
+
const builder = await createViteBuilder(config, hooks, server);
|
|
12
|
+
const pm = await createWxtPackageManager(config.root);
|
|
13
|
+
wxt = {
|
|
14
|
+
config,
|
|
15
|
+
hooks,
|
|
16
|
+
get logger() {
|
|
17
|
+
return config.logger;
|
|
18
|
+
},
|
|
19
|
+
async reloadConfig() {
|
|
20
|
+
wxt.config = await resolveConfig(inlineConfig, command);
|
|
21
|
+
},
|
|
22
|
+
pm,
|
|
23
|
+
builder,
|
|
24
|
+
server
|
|
25
|
+
};
|
|
26
|
+
const initModule = async (module) => {
|
|
27
|
+
if (module.hooks) wxt.hooks.addHooks(module.hooks);
|
|
28
|
+
await module.setup?.(
|
|
29
|
+
wxt,
|
|
30
|
+
// @ts-expect-error: Untyped configKey field
|
|
31
|
+
module.configKey ? config[module.configKey] : void 0
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
for (const builtinModule of builtinModules) await initModule(builtinModule);
|
|
35
|
+
for (const userModule of config.userModules) await initModule(userModule);
|
|
36
|
+
wxt.hooks.addHooks(config.hooks);
|
|
37
|
+
await wxt.hooks.callHook("ready", wxt);
|
|
38
|
+
}
|
|
39
|
+
export function setWxtForTesting(testInstance) {
|
|
40
|
+
wxt = testInstance;
|
|
41
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InlineConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Build and zip the extension for distribution.
|
|
4
|
+
* @param config Optional config that will override your `<root>/wxt.config.ts`.
|
|
5
|
+
* @returns A list of all files included in the ZIP.
|
|
6
|
+
*/
|
|
7
|
+
export declare function zip(config?: InlineConfig): Promise<string[]>;
|