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,128 @@
|
|
|
1
|
+
import prompts from "prompts";
|
|
2
|
+
import { consola } from "consola";
|
|
3
|
+
import { downloadTemplate } from "giget";
|
|
4
|
+
import fs from "fs-extra";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import pc from "picocolors";
|
|
7
|
+
export async function initialize(options) {
|
|
8
|
+
consola.info("Initalizing new project");
|
|
9
|
+
const templates = await listTemplates();
|
|
10
|
+
const defaultTemplate = templates.find(
|
|
11
|
+
(template) => template.name === options.template?.toLowerCase().trim()
|
|
12
|
+
);
|
|
13
|
+
const input = await prompts(
|
|
14
|
+
[
|
|
15
|
+
{
|
|
16
|
+
name: "directory",
|
|
17
|
+
type: () => options.directory == null ? "text" : void 0,
|
|
18
|
+
message: "Project Directory",
|
|
19
|
+
initial: options.directory
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "template",
|
|
23
|
+
type: () => defaultTemplate == null ? "select" : void 0,
|
|
24
|
+
message: "Choose a template",
|
|
25
|
+
choices: templates.map((template) => ({
|
|
26
|
+
title: TEMPLATE_COLORS[template.name]?.(template.name) ?? template.name,
|
|
27
|
+
value: template
|
|
28
|
+
}))
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "packageManager",
|
|
32
|
+
type: () => options.packageManager == null ? "select" : void 0,
|
|
33
|
+
message: "Package Manager",
|
|
34
|
+
choices: [
|
|
35
|
+
{ title: pc.red("npm"), value: "npm" },
|
|
36
|
+
{ title: pc.yellow("pnpm"), value: "pnpm" },
|
|
37
|
+
{ title: pc.cyan("yarn"), value: "yarn" },
|
|
38
|
+
{
|
|
39
|
+
title: `${pc.magenta("bun")}${pc.gray(" (experimental)")}`,
|
|
40
|
+
value: "bun"
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
{
|
|
46
|
+
onCancel: () => process.exit(1)
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
input.directory ??= options.directory;
|
|
50
|
+
input.template ??= defaultTemplate;
|
|
51
|
+
input.packageManager ??= options.packageManager;
|
|
52
|
+
const isExists = await fs.pathExists(input.directory);
|
|
53
|
+
if (isExists) {
|
|
54
|
+
const isEmpty = (await fs.readdir(input.directory)).length === 0;
|
|
55
|
+
if (!isEmpty) {
|
|
56
|
+
consola.error(
|
|
57
|
+
`The directory ${path.resolve(input.directory)} is not empty. Aborted.`
|
|
58
|
+
);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
await cloneProject(input);
|
|
63
|
+
const cdPath = path.relative(process.cwd(), path.resolve(input.directory));
|
|
64
|
+
console.log();
|
|
65
|
+
consola.log(
|
|
66
|
+
`\u2728 WXT project created with the ${TEMPLATE_COLORS[input.template.name]?.(input.template.name) ?? input.template.name} template.`
|
|
67
|
+
);
|
|
68
|
+
console.log();
|
|
69
|
+
consola.log("Next steps:");
|
|
70
|
+
let step = 0;
|
|
71
|
+
if (cdPath !== "") consola.log(` ${++step}.`, pc.cyan(`cd ${cdPath}`));
|
|
72
|
+
consola.log(` ${++step}.`, pc.cyan(`${input.packageManager} install`));
|
|
73
|
+
console.log();
|
|
74
|
+
}
|
|
75
|
+
async function listTemplates() {
|
|
76
|
+
try {
|
|
77
|
+
const res = await fetch("https://ungh.cc/repos/wxt-dev/wxt/files/main");
|
|
78
|
+
if (res.status >= 300)
|
|
79
|
+
throw Error(`Request failed with status ${res.status} ${res.statusText}`);
|
|
80
|
+
const data = await res.json();
|
|
81
|
+
return data.files.map((item) => item.path.match(/templates\/(.+)\/package\.json/)?.[1]).filter((name) => name != null).map((name) => ({ name, path: `templates/${name}` })).sort((l, r) => {
|
|
82
|
+
const lWeight = TEMPLATE_SORT_WEIGHT[l.name] ?? Number.MAX_SAFE_INTEGER;
|
|
83
|
+
const rWeight = TEMPLATE_SORT_WEIGHT[r.name] ?? Number.MAX_SAFE_INTEGER;
|
|
84
|
+
const diff = lWeight - rWeight;
|
|
85
|
+
if (diff !== 0) return diff;
|
|
86
|
+
return l.name.localeCompare(r.name);
|
|
87
|
+
});
|
|
88
|
+
} catch (err) {
|
|
89
|
+
consola.error(err);
|
|
90
|
+
throw Error(`Failed to load templates`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async function cloneProject({
|
|
94
|
+
directory,
|
|
95
|
+
template,
|
|
96
|
+
packageManager
|
|
97
|
+
}) {
|
|
98
|
+
const { default: ora } = await import("ora");
|
|
99
|
+
const spinner = ora("Downloading template").start();
|
|
100
|
+
try {
|
|
101
|
+
await downloadTemplate(`gh:wxt-dev/wxt/${template.path}`, {
|
|
102
|
+
dir: directory,
|
|
103
|
+
force: true
|
|
104
|
+
});
|
|
105
|
+
await fs.move(
|
|
106
|
+
path.join(directory, "_gitignore"),
|
|
107
|
+
path.join(directory, ".gitignore")
|
|
108
|
+
).catch(
|
|
109
|
+
(err) => consola.warn("Failed to move _gitignore to .gitignore:", err)
|
|
110
|
+
);
|
|
111
|
+
spinner.succeed();
|
|
112
|
+
} catch (err) {
|
|
113
|
+
spinner.fail();
|
|
114
|
+
throw Error(`Failed to setup new project: ${JSON.stringify(err, null, 2)}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const TEMPLATE_COLORS = {
|
|
118
|
+
vanilla: pc.blue,
|
|
119
|
+
vue: pc.green,
|
|
120
|
+
react: pc.cyan,
|
|
121
|
+
svelte: pc.red,
|
|
122
|
+
solid: pc.blue
|
|
123
|
+
};
|
|
124
|
+
const TEMPLATE_SORT_WEIGHT = {
|
|
125
|
+
vanilla: 0,
|
|
126
|
+
vue: 1,
|
|
127
|
+
react: 2
|
|
128
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { dedupeDependencies, npm } from "./npm.mjs";
|
|
2
|
+
export const bun = {
|
|
3
|
+
overridesKey: "overrides",
|
|
4
|
+
// But also supports "resolutions"
|
|
5
|
+
downloadDependency(...args) {
|
|
6
|
+
return npm.downloadDependency(...args);
|
|
7
|
+
},
|
|
8
|
+
async listDependencies(options) {
|
|
9
|
+
const args = ["pm", "ls"];
|
|
10
|
+
if (options?.all) {
|
|
11
|
+
args.push("--all");
|
|
12
|
+
}
|
|
13
|
+
const { execa } = await import("execa");
|
|
14
|
+
const res = await execa("bun", args, { cwd: options?.cwd });
|
|
15
|
+
return dedupeDependencies(
|
|
16
|
+
res.stdout.split("\n").slice(1).map((line) => line.trim()).map((line) => /.* (@?\S+)@(\S+)$/.exec(line)).filter((match) => !!match).map(([_, name, version]) => ({ name, version }))
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
detectPackageManager,
|
|
3
|
+
addDependency,
|
|
4
|
+
addDevDependency,
|
|
5
|
+
ensureDependencyInstalled,
|
|
6
|
+
installDependencies,
|
|
7
|
+
removeDependency
|
|
8
|
+
} from "nypm";
|
|
9
|
+
import { bun } from "./bun.mjs";
|
|
10
|
+
import { yarn } from "./yarn.mjs";
|
|
11
|
+
import { pnpm } from "./pnpm.mjs";
|
|
12
|
+
import { npm } from "./npm.mjs";
|
|
13
|
+
export async function createWxtPackageManager(root) {
|
|
14
|
+
const pm = await detectPackageManager(root, {
|
|
15
|
+
includeParentDirs: true
|
|
16
|
+
});
|
|
17
|
+
const requirePm = (cb) => {
|
|
18
|
+
if (pm == null) throw Error("Could not detect package manager");
|
|
19
|
+
return cb(pm);
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
get name() {
|
|
23
|
+
return requirePm((pm2) => pm2.name);
|
|
24
|
+
},
|
|
25
|
+
get command() {
|
|
26
|
+
return requirePm((pm2) => pm2.command);
|
|
27
|
+
},
|
|
28
|
+
get version() {
|
|
29
|
+
return requirePm((pm2) => pm2.version);
|
|
30
|
+
},
|
|
31
|
+
get majorVersion() {
|
|
32
|
+
return requirePm((pm2) => pm2.majorVersion);
|
|
33
|
+
},
|
|
34
|
+
get lockFile() {
|
|
35
|
+
return requirePm((pm2) => pm2.lockFile);
|
|
36
|
+
},
|
|
37
|
+
get files() {
|
|
38
|
+
return requirePm((pm2) => pm2.files);
|
|
39
|
+
},
|
|
40
|
+
addDependency,
|
|
41
|
+
addDevDependency,
|
|
42
|
+
ensureDependencyInstalled,
|
|
43
|
+
installDependencies,
|
|
44
|
+
removeDependency,
|
|
45
|
+
get overridesKey() {
|
|
46
|
+
return requirePm((pm2) => packageManagers[pm2.name].overridesKey);
|
|
47
|
+
},
|
|
48
|
+
downloadDependency(...args) {
|
|
49
|
+
return requirePm(
|
|
50
|
+
(pm2) => packageManagers[pm2.name].downloadDependency(...args)
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
listDependencies(...args) {
|
|
54
|
+
return requirePm(
|
|
55
|
+
(pm2) => packageManagers[pm2.name].listDependencies(...args)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const packageManagers = {
|
|
61
|
+
npm,
|
|
62
|
+
pnpm,
|
|
63
|
+
bun,
|
|
64
|
+
yarn
|
|
65
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Dependency } from '../../types';
|
|
2
|
+
import { WxtPackageManagerImpl } from './types';
|
|
3
|
+
export declare const npm: WxtPackageManagerImpl;
|
|
4
|
+
export declare function flattenNpmListOutput(projects: NpmListProject[]): Dependency[];
|
|
5
|
+
export declare function dedupeDependencies(dependencies: Dependency[]): Dependency[];
|
|
6
|
+
export interface NpmListProject {
|
|
7
|
+
name: string;
|
|
8
|
+
dependencies?: Record<string, NpmListDependency>;
|
|
9
|
+
devDependencies?: Record<string, NpmListDependency>;
|
|
10
|
+
}
|
|
11
|
+
export interface NpmListDependency {
|
|
12
|
+
version: string;
|
|
13
|
+
resolved?: string;
|
|
14
|
+
overridden?: boolean;
|
|
15
|
+
dependencies?: Record<string, NpmListDependency>;
|
|
16
|
+
devDependencies?: Record<string, NpmListDependency>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { ensureDir } from "fs-extra";
|
|
3
|
+
export const npm = {
|
|
4
|
+
overridesKey: "overrides",
|
|
5
|
+
async downloadDependency(id, downloadDir) {
|
|
6
|
+
await ensureDir(downloadDir);
|
|
7
|
+
const { execa } = await import("execa");
|
|
8
|
+
const res = await execa("npm", ["pack", id, "--json"], {
|
|
9
|
+
cwd: downloadDir
|
|
10
|
+
});
|
|
11
|
+
const packed = JSON.parse(res.stdout);
|
|
12
|
+
return path.resolve(downloadDir, packed[0].filename);
|
|
13
|
+
},
|
|
14
|
+
async listDependencies(options) {
|
|
15
|
+
const args = ["ls", "--json"];
|
|
16
|
+
if (options?.all) {
|
|
17
|
+
args.push("--depth", "Infinity");
|
|
18
|
+
}
|
|
19
|
+
const { execa } = await import("execa");
|
|
20
|
+
const res = await execa("npm", args, { cwd: options?.cwd });
|
|
21
|
+
const project = JSON.parse(res.stdout);
|
|
22
|
+
return flattenNpmListOutput([project]);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export function flattenNpmListOutput(projects) {
|
|
26
|
+
const queue = projects.flatMap(
|
|
27
|
+
(project) => {
|
|
28
|
+
const acc = [];
|
|
29
|
+
if (project.dependencies) acc.push(project.dependencies);
|
|
30
|
+
if (project.devDependencies) acc.push(project.devDependencies);
|
|
31
|
+
return acc;
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
const dependencies = [];
|
|
35
|
+
while (queue.length > 0) {
|
|
36
|
+
Object.entries(queue.pop()).forEach(([name, meta]) => {
|
|
37
|
+
dependencies.push({
|
|
38
|
+
name,
|
|
39
|
+
version: meta.version
|
|
40
|
+
});
|
|
41
|
+
if (meta.dependencies) queue.push(meta.dependencies);
|
|
42
|
+
if (meta.devDependencies) queue.push(meta.devDependencies);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return dedupeDependencies(dependencies);
|
|
46
|
+
}
|
|
47
|
+
export function dedupeDependencies(dependencies) {
|
|
48
|
+
const hashes = /* @__PURE__ */ new Set();
|
|
49
|
+
return dependencies.filter((dep) => {
|
|
50
|
+
const hash = `${dep.name}@${dep.version}`;
|
|
51
|
+
if (hashes.has(hash)) {
|
|
52
|
+
return false;
|
|
53
|
+
} else {
|
|
54
|
+
hashes.add(hash);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { flattenNpmListOutput, npm } from "./npm.mjs";
|
|
2
|
+
export const pnpm = {
|
|
3
|
+
overridesKey: "resolutions",
|
|
4
|
+
// "pnpm.overrides" has a higher priority, but I don't want to deal with nesting
|
|
5
|
+
downloadDependency(...args) {
|
|
6
|
+
return npm.downloadDependency(...args);
|
|
7
|
+
},
|
|
8
|
+
async listDependencies(options) {
|
|
9
|
+
const args = ["ls", "-r", "--json"];
|
|
10
|
+
if (options?.all) {
|
|
11
|
+
args.push("--depth", "Infinity");
|
|
12
|
+
}
|
|
13
|
+
if (typeof process !== "undefined" && process.env.WXT_PNPM_IGNORE_WORKSPACE === "true") {
|
|
14
|
+
args.push("--ignore-workspace");
|
|
15
|
+
}
|
|
16
|
+
const { execa } = await import("execa");
|
|
17
|
+
const res = await execa("pnpm", args, { cwd: options?.cwd });
|
|
18
|
+
const projects = JSON.parse(res.stdout);
|
|
19
|
+
return flattenNpmListOutput(projects);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { dedupeDependencies, npm } from "./npm.mjs";
|
|
2
|
+
export const yarn = {
|
|
3
|
+
overridesKey: "resolutions",
|
|
4
|
+
downloadDependency(...args) {
|
|
5
|
+
return npm.downloadDependency(...args);
|
|
6
|
+
},
|
|
7
|
+
async listDependencies(options) {
|
|
8
|
+
const args = ["list", "--json"];
|
|
9
|
+
if (options?.all) {
|
|
10
|
+
args.push("--depth", "Infinity");
|
|
11
|
+
}
|
|
12
|
+
const { execa } = await import("execa");
|
|
13
|
+
const res = await execa("yarn", args, { cwd: options?.cwd });
|
|
14
|
+
const tree = res.stdout.split("\n").map((line) => JSON.parse(line)).find((line) => line.type === "tree")?.data;
|
|
15
|
+
if (tree == null) throw Error("'yarn list --json' did not output a tree");
|
|
16
|
+
const queue = [...tree.trees];
|
|
17
|
+
const dependencies = [];
|
|
18
|
+
while (queue.length > 0) {
|
|
19
|
+
const { name: treeName, children } = queue.pop();
|
|
20
|
+
const match = /(@?\S+)@(\S+)$/.exec(treeName);
|
|
21
|
+
if (match) {
|
|
22
|
+
const [_, name, version] = match;
|
|
23
|
+
dependencies.push({ name, version });
|
|
24
|
+
}
|
|
25
|
+
if (children != null) {
|
|
26
|
+
queue.push(...children);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return dedupeDependencies(dependencies);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { findEntrypoints, generateTypesDir } from "./utils/building/index.mjs";
|
|
2
|
+
import { registerWxt, wxt } from "./wxt.mjs";
|
|
3
|
+
export async function prepare(config) {
|
|
4
|
+
await registerWxt("build", config);
|
|
5
|
+
wxt.logger.info("Generating types...");
|
|
6
|
+
const entrypoints = await findEntrypoints();
|
|
7
|
+
await generateTypesDir(entrypoints);
|
|
8
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createWslRunner } from "./wsl.mjs";
|
|
2
|
+
import { createWebExtRunner } from "./web-ext.mjs";
|
|
3
|
+
import { createSafariRunner } from "./safari.mjs";
|
|
4
|
+
import { createManualRunner } from "./manual.mjs";
|
|
5
|
+
import { isWsl } from "../utils/wsl.mjs";
|
|
6
|
+
import { wxt } from "../wxt.mjs";
|
|
7
|
+
export async function createExtensionRunner() {
|
|
8
|
+
if (wxt.config.browser === "safari") return createSafariRunner();
|
|
9
|
+
if (await isWsl()) return createWslRunner();
|
|
10
|
+
if (wxt.config.runnerConfig.config?.disabled) return createManualRunner();
|
|
11
|
+
return createWebExtRunner();
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { relative } from "node:path";
|
|
2
|
+
import { wxt } from "../wxt.mjs";
|
|
3
|
+
export function createManualRunner() {
|
|
4
|
+
return {
|
|
5
|
+
async openBrowser() {
|
|
6
|
+
wxt.logger.info(
|
|
7
|
+
`Load "${relative(
|
|
8
|
+
process.cwd(),
|
|
9
|
+
wxt.config.outDir
|
|
10
|
+
)}" as an unpacked extension manually`
|
|
11
|
+
);
|
|
12
|
+
},
|
|
13
|
+
async closeBrowser() {
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { relative } from "node:path";
|
|
2
|
+
import { wxt } from "../wxt.mjs";
|
|
3
|
+
export function createSafariRunner() {
|
|
4
|
+
return {
|
|
5
|
+
async openBrowser() {
|
|
6
|
+
wxt.logger.warn(
|
|
7
|
+
`Cannot Safari using web-ext. Load "${relative(
|
|
8
|
+
process.cwd(),
|
|
9
|
+
wxt.config.outDir
|
|
10
|
+
)}" as an unpacked extension manually`
|
|
11
|
+
);
|
|
12
|
+
},
|
|
13
|
+
async closeBrowser() {
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { formatDuration } from "../utils/time.mjs";
|
|
2
|
+
import defu from "defu";
|
|
3
|
+
import { wxt } from "../wxt.mjs";
|
|
4
|
+
export function createWebExtRunner() {
|
|
5
|
+
let runner;
|
|
6
|
+
return {
|
|
7
|
+
async openBrowser() {
|
|
8
|
+
const startTime = Date.now();
|
|
9
|
+
if (wxt.config.browser === "firefox" && wxt.config.manifestVersion === 3) {
|
|
10
|
+
throw Error(
|
|
11
|
+
"Dev mode does not support Firefox MV3. For alternatives, see https://github.com/wxt-dev/wxt/issues/230#issuecomment-1806881653"
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
const webExtLogger = await import("web-ext-run/util/logger");
|
|
15
|
+
webExtLogger.consoleStream.write = ({ level, msg, name }) => {
|
|
16
|
+
if (level >= ERROR_LOG_LEVEL) wxt.logger.error(name, msg);
|
|
17
|
+
if (level >= WARN_LOG_LEVEL) wxt.logger.warn(msg);
|
|
18
|
+
};
|
|
19
|
+
const wxtUserConfig = wxt.config.runnerConfig.config;
|
|
20
|
+
const userConfig = {
|
|
21
|
+
console: wxtUserConfig?.openConsole,
|
|
22
|
+
devtools: wxtUserConfig?.openDevtools,
|
|
23
|
+
startUrl: wxtUserConfig?.startUrls,
|
|
24
|
+
keepProfileChanges: wxtUserConfig?.keepProfileChanges,
|
|
25
|
+
...wxt.config.browser === "firefox" ? {
|
|
26
|
+
firefox: wxtUserConfig?.binaries?.firefox,
|
|
27
|
+
firefoxProfile: wxtUserConfig?.firefoxProfile,
|
|
28
|
+
prefs: wxtUserConfig?.firefoxPrefs,
|
|
29
|
+
args: wxtUserConfig?.firefoxArgs
|
|
30
|
+
} : {
|
|
31
|
+
chromiumBinary: wxtUserConfig?.binaries?.[wxt.config.browser],
|
|
32
|
+
chromiumProfile: wxtUserConfig?.chromiumProfile,
|
|
33
|
+
chromiumPref: defu(
|
|
34
|
+
wxtUserConfig?.chromiumPref,
|
|
35
|
+
DEFAULT_CHROMIUM_PREFS
|
|
36
|
+
),
|
|
37
|
+
args: wxtUserConfig?.chromiumArgs
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const finalConfig = {
|
|
41
|
+
...userConfig,
|
|
42
|
+
target: wxt.config.browser === "firefox" ? "firefox-desktop" : "chromium",
|
|
43
|
+
sourceDir: wxt.config.outDir,
|
|
44
|
+
// Don't add a "Reload Manager" extension alongside dev extension, WXT
|
|
45
|
+
// already handles reloads intenrally.
|
|
46
|
+
noReloadManagerExtension: true,
|
|
47
|
+
// WXT handles reloads, so disable auto-reload behaviors in web-ext
|
|
48
|
+
noReload: true,
|
|
49
|
+
noInput: true
|
|
50
|
+
};
|
|
51
|
+
const options = {
|
|
52
|
+
// Don't call `process.exit(0)` after starting web-ext
|
|
53
|
+
shouldExitProgram: false
|
|
54
|
+
};
|
|
55
|
+
wxt.logger.debug("web-ext config:", finalConfig);
|
|
56
|
+
wxt.logger.debug("web-ext options:", options);
|
|
57
|
+
const webExt = await import("web-ext-run");
|
|
58
|
+
runner = await webExt.default.cmd.run(finalConfig, options);
|
|
59
|
+
const duration = Date.now() - startTime;
|
|
60
|
+
wxt.logger.success(`Opened browser in ${formatDuration(duration)}`);
|
|
61
|
+
},
|
|
62
|
+
async closeBrowser() {
|
|
63
|
+
return await runner?.exit();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const WARN_LOG_LEVEL = 40;
|
|
68
|
+
const ERROR_LOG_LEVEL = 50;
|
|
69
|
+
const DEFAULT_CHROMIUM_PREFS = {
|
|
70
|
+
devtools: {
|
|
71
|
+
synced_preferences_sync_disabled: {
|
|
72
|
+
// Remove content scripts from sourcemap debugger ignore list so stack traces
|
|
73
|
+
// and log locations show up properly, see:
|
|
74
|
+
// https://github.com/wxt-dev/wxt/issues/236#issuecomment-1915364520
|
|
75
|
+
skipContentScripts: false
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { relative } from "node:path";
|
|
2
|
+
import { wxt } from "../wxt.mjs";
|
|
3
|
+
export function createWslRunner() {
|
|
4
|
+
return {
|
|
5
|
+
async openBrowser() {
|
|
6
|
+
wxt.logger.warn(
|
|
7
|
+
`Cannot open browser when using WSL. Load "${relative(
|
|
8
|
+
process.cwd(),
|
|
9
|
+
wxt.config.outDir
|
|
10
|
+
)}" as an unpacked extension manually`
|
|
11
|
+
);
|
|
12
|
+
},
|
|
13
|
+
async closeBrowser() {
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if `predicate` returns truthy for all elements of the array.
|
|
3
|
+
*/
|
|
4
|
+
export declare function every<T>(array: T[], predicate: (item: T, index: number) => boolean): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Returns true when any of the predicates return true;
|
|
7
|
+
*/
|
|
8
|
+
export declare function some<T>(array: T[], predicate: (item: T, index: number) => boolean): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Convert an item or array to an array.
|
|
11
|
+
*/
|
|
12
|
+
export declare function toArray<T>(a: T | T[]): T[];
|
|
13
|
+
export declare function filterTruthy<T>(array: Array<T | undefined>): T[];
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
function every(array, predicate) {
|
|
1
|
+
export function every(array, predicate) {
|
|
3
2
|
for (let i = 0; i < array.length; i++)
|
|
4
3
|
if (!predicate(array[i], i)) return false;
|
|
5
4
|
return true;
|
|
6
5
|
}
|
|
7
|
-
function some(array, predicate) {
|
|
6
|
+
export function some(array, predicate) {
|
|
8
7
|
for (let i = 0; i < array.length; i++)
|
|
9
8
|
if (predicate(array[i], i)) return true;
|
|
10
9
|
return false;
|
|
11
10
|
}
|
|
12
|
-
function toArray(a) {
|
|
11
|
+
export function toArray(a) {
|
|
13
12
|
return Array.isArray(a) ? a : [a];
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
some,
|
|
19
|
-
toArray
|
|
20
|
-
};
|
|
14
|
+
export function filterTruthy(array) {
|
|
15
|
+
return array.filter((item) => !!item);
|
|
16
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { getPublicFiles } from "../../utils/fs.mjs";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import { dirname, resolve } from "path";
|
|
4
|
+
import pc from "picocolors";
|
|
5
|
+
import { wxt } from "../../wxt.mjs";
|
|
6
|
+
import { toArray } from "../arrays.mjs";
|
|
7
|
+
export async function buildEntrypoints(groups, spinner) {
|
|
8
|
+
const steps = [];
|
|
9
|
+
for (let i = 0; i < groups.length; i++) {
|
|
10
|
+
const group = groups[i];
|
|
11
|
+
const groupNames = toArray(group).map((e) => e.name);
|
|
12
|
+
const groupNameColored = groupNames.join(pc.dim(", "));
|
|
13
|
+
spinner.text = pc.dim(`[${i + 1}/${groups.length}]`) + ` ${groupNameColored}`;
|
|
14
|
+
try {
|
|
15
|
+
steps.push(await wxt.builder.build(group));
|
|
16
|
+
} catch (err) {
|
|
17
|
+
spinner.stop().clear();
|
|
18
|
+
wxt.logger.error(err);
|
|
19
|
+
throw Error(`Failed to build ${groupNames.join(", ")}`, { cause: err });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const publicAssets = await copyPublicDirectory();
|
|
23
|
+
return { publicAssets, steps };
|
|
24
|
+
}
|
|
25
|
+
async function copyPublicDirectory() {
|
|
26
|
+
const files = (await getPublicFiles()).map((file) => ({
|
|
27
|
+
absoluteSrc: resolve(wxt.config.publicDir, file),
|
|
28
|
+
relativeDest: file
|
|
29
|
+
}));
|
|
30
|
+
await wxt.hooks.callHook("build:publicAssets", wxt, files);
|
|
31
|
+
if (files.length === 0) return [];
|
|
32
|
+
const publicAssets = [];
|
|
33
|
+
for (const file of files) {
|
|
34
|
+
const absoluteDest = resolve(wxt.config.outDir, file.relativeDest);
|
|
35
|
+
await fs.ensureDir(dirname(absoluteDest));
|
|
36
|
+
if ("absoluteSrc" in file) {
|
|
37
|
+
await fs.copyFile(file.absoluteSrc, absoluteDest);
|
|
38
|
+
} else {
|
|
39
|
+
await fs.writeFile(absoluteDest, file.contents, "utf8");
|
|
40
|
+
}
|
|
41
|
+
publicAssets.push({
|
|
42
|
+
type: "asset",
|
|
43
|
+
fileName: file.relativeDest
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return publicAssets;
|
|
47
|
+
}
|