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,364 @@
|
|
|
1
|
+
import { loadConfig } from "c12";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createFsCache } from "../../utils/cache.mjs";
|
|
4
|
+
import consola, { LogLevels } from "consola";
|
|
5
|
+
import defu from "defu";
|
|
6
|
+
import fs from "fs-extra";
|
|
7
|
+
import { normalizePath } from "../paths.mjs";
|
|
8
|
+
import glob from "fast-glob";
|
|
9
|
+
import { builtinModules } from "../../../builtin-modules/index.mjs";
|
|
10
|
+
import { getEslintVersion } from "../eslint.mjs";
|
|
11
|
+
export async function resolveConfig(inlineConfig, command) {
|
|
12
|
+
let userConfig = {};
|
|
13
|
+
let userConfigMetadata;
|
|
14
|
+
if (inlineConfig.configFile !== false) {
|
|
15
|
+
const { config: loadedConfig, ...metadata } = await loadConfig({
|
|
16
|
+
configFile: inlineConfig.configFile,
|
|
17
|
+
name: "wxt",
|
|
18
|
+
cwd: inlineConfig.root ?? process.cwd(),
|
|
19
|
+
rcFile: false,
|
|
20
|
+
jitiOptions: {
|
|
21
|
+
esmResolve: true
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
userConfig = loadedConfig ?? {};
|
|
25
|
+
userConfigMetadata = metadata;
|
|
26
|
+
}
|
|
27
|
+
const mergedConfig = await mergeInlineConfig(inlineConfig, userConfig);
|
|
28
|
+
const debug = mergedConfig.debug ?? false;
|
|
29
|
+
const logger = mergedConfig.logger ?? consola;
|
|
30
|
+
if (debug) logger.level = LogLevels.debug;
|
|
31
|
+
const browser = mergedConfig.browser ?? "chrome";
|
|
32
|
+
const manifestVersion = mergedConfig.manifestVersion ?? (browser === "firefox" || browser === "safari" ? 2 : 3);
|
|
33
|
+
const mode = mergedConfig.mode ?? COMMAND_MODES[command];
|
|
34
|
+
const env = { browser, command, manifestVersion, mode };
|
|
35
|
+
const root = path.resolve(
|
|
36
|
+
inlineConfig.root ?? userConfig.root ?? process.cwd()
|
|
37
|
+
);
|
|
38
|
+
const wxtDir = path.resolve(root, ".wxt");
|
|
39
|
+
const wxtModuleDir = await resolveWxtModuleDir();
|
|
40
|
+
const srcDir = path.resolve(root, mergedConfig.srcDir ?? root);
|
|
41
|
+
const entrypointsDir = path.resolve(
|
|
42
|
+
srcDir,
|
|
43
|
+
mergedConfig.entrypointsDir ?? "entrypoints"
|
|
44
|
+
);
|
|
45
|
+
const modulesDir = path.resolve(srcDir, mergedConfig.modulesDir ?? "modules");
|
|
46
|
+
if (await isDirMissing(entrypointsDir)) {
|
|
47
|
+
logMissingDir(logger, "Entrypoints", entrypointsDir);
|
|
48
|
+
}
|
|
49
|
+
const filterEntrypoints = !!mergedConfig.filterEntrypoints?.length ? new Set(mergedConfig.filterEntrypoints) : void 0;
|
|
50
|
+
const publicDir = path.resolve(srcDir, mergedConfig.publicDir ?? "public");
|
|
51
|
+
if (await isDirMissing(publicDir)) {
|
|
52
|
+
logMissingDir(logger, "Public", publicDir);
|
|
53
|
+
}
|
|
54
|
+
const typesDir = path.resolve(wxtDir, "types");
|
|
55
|
+
const outBaseDir = path.resolve(root, mergedConfig.outDir ?? ".output");
|
|
56
|
+
const outDir = path.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
|
|
57
|
+
const reloadCommand = mergedConfig.dev?.reloadCommand ?? "Alt+R";
|
|
58
|
+
const runnerConfig = await loadConfig({
|
|
59
|
+
name: "web-ext",
|
|
60
|
+
cwd: root,
|
|
61
|
+
globalRc: true,
|
|
62
|
+
rcFile: ".webextrc",
|
|
63
|
+
overrides: inlineConfig.runner,
|
|
64
|
+
defaults: userConfig.runner
|
|
65
|
+
});
|
|
66
|
+
const alias = Object.fromEntries(
|
|
67
|
+
Object.entries({
|
|
68
|
+
...mergedConfig.alias,
|
|
69
|
+
"@": srcDir,
|
|
70
|
+
"~": srcDir,
|
|
71
|
+
"@@": root,
|
|
72
|
+
"~~": root
|
|
73
|
+
}).map(([key, value]) => [key, path.resolve(root, value)])
|
|
74
|
+
);
|
|
75
|
+
let devServerConfig;
|
|
76
|
+
if (command === "serve") {
|
|
77
|
+
let port = mergedConfig.dev?.server?.port;
|
|
78
|
+
if (port == null || !isFinite(port)) {
|
|
79
|
+
const { default: getPort, portNumbers } = await import("get-port");
|
|
80
|
+
port = await getPort({ port: portNumbers(3e3, 3010) });
|
|
81
|
+
}
|
|
82
|
+
devServerConfig = {
|
|
83
|
+
port,
|
|
84
|
+
hostname: mergedConfig.dev?.server?.hostname ?? "localhost"
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const userModules = await resolveWxtUserModules(
|
|
88
|
+
modulesDir,
|
|
89
|
+
mergedConfig.modules
|
|
90
|
+
);
|
|
91
|
+
const moduleOptions = userModules.reduce(
|
|
92
|
+
(map, module) => {
|
|
93
|
+
if (module.configKey) {
|
|
94
|
+
map[module.configKey] = // @ts-expect-error
|
|
95
|
+
mergedConfig[module.configKey];
|
|
96
|
+
}
|
|
97
|
+
return map;
|
|
98
|
+
},
|
|
99
|
+
{}
|
|
100
|
+
);
|
|
101
|
+
const extensionApi = mergedConfig.extensionApi ?? "webextension-polyfill";
|
|
102
|
+
return {
|
|
103
|
+
browser,
|
|
104
|
+
command,
|
|
105
|
+
debug,
|
|
106
|
+
entrypointsDir,
|
|
107
|
+
modulesDir,
|
|
108
|
+
filterEntrypoints,
|
|
109
|
+
env,
|
|
110
|
+
fsCache: createFsCache(wxtDir),
|
|
111
|
+
imports: await getUnimportOptions(
|
|
112
|
+
wxtDir,
|
|
113
|
+
srcDir,
|
|
114
|
+
logger,
|
|
115
|
+
extensionApi,
|
|
116
|
+
mergedConfig
|
|
117
|
+
),
|
|
118
|
+
logger,
|
|
119
|
+
manifest: await resolveManifestConfig(env, mergedConfig.manifest),
|
|
120
|
+
manifestVersion,
|
|
121
|
+
mode,
|
|
122
|
+
outBaseDir,
|
|
123
|
+
outDir,
|
|
124
|
+
publicDir,
|
|
125
|
+
wxtModuleDir,
|
|
126
|
+
root,
|
|
127
|
+
runnerConfig,
|
|
128
|
+
srcDir,
|
|
129
|
+
typesDir,
|
|
130
|
+
wxtDir,
|
|
131
|
+
zip: resolveZipConfig(root, outBaseDir, mergedConfig),
|
|
132
|
+
transformManifest: mergedConfig.transformManifest,
|
|
133
|
+
analysis: resolveAnalysisConfig(root, mergedConfig),
|
|
134
|
+
userConfigMetadata: userConfigMetadata ?? {},
|
|
135
|
+
alias,
|
|
136
|
+
extensionApi,
|
|
137
|
+
browserModule: extensionApi === "chrome" ? "wxt/browser/chrome" : "wxt/browser",
|
|
138
|
+
entrypointLoader: mergedConfig.entrypointLoader ?? "vite-node",
|
|
139
|
+
experimental: defu(mergedConfig.experimental, {}),
|
|
140
|
+
dev: {
|
|
141
|
+
server: devServerConfig,
|
|
142
|
+
reloadCommand
|
|
143
|
+
},
|
|
144
|
+
hooks: mergedConfig.hooks ?? {},
|
|
145
|
+
vite: mergedConfig.vite ?? (() => ({})),
|
|
146
|
+
builtinModules,
|
|
147
|
+
userModules,
|
|
148
|
+
plugins: [],
|
|
149
|
+
...moduleOptions
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
async function resolveManifestConfig(env, manifest) {
|
|
153
|
+
return typeof manifest === "function" ? await manifest(env) : await (manifest ?? {});
|
|
154
|
+
}
|
|
155
|
+
async function mergeInlineConfig(inlineConfig, userConfig) {
|
|
156
|
+
const imports = inlineConfig.imports === false || userConfig.imports === false ? false : userConfig.imports == null && inlineConfig.imports == null ? void 0 : defu(inlineConfig.imports ?? {}, userConfig.imports ?? {});
|
|
157
|
+
const manifest = async (env) => {
|
|
158
|
+
const user = await resolveManifestConfig(env, userConfig.manifest);
|
|
159
|
+
const inline = await resolveManifestConfig(env, inlineConfig.manifest);
|
|
160
|
+
return defu(inline, user);
|
|
161
|
+
};
|
|
162
|
+
const transformManifest = (manifest2) => {
|
|
163
|
+
userConfig.transformManifest?.(manifest2);
|
|
164
|
+
inlineConfig.transformManifest?.(manifest2);
|
|
165
|
+
};
|
|
166
|
+
const merged = defu(inlineConfig, userConfig);
|
|
167
|
+
const builderConfig = await mergeBuilderConfig(
|
|
168
|
+
merged.logger ?? consola,
|
|
169
|
+
inlineConfig,
|
|
170
|
+
userConfig
|
|
171
|
+
);
|
|
172
|
+
return {
|
|
173
|
+
...merged,
|
|
174
|
+
// Custom merge values
|
|
175
|
+
transformManifest,
|
|
176
|
+
imports,
|
|
177
|
+
manifest,
|
|
178
|
+
...builderConfig
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function resolveZipConfig(root, outBaseDir, mergedConfig) {
|
|
182
|
+
const downloadedPackagesDir = path.resolve(root, ".wxt/local_modules");
|
|
183
|
+
return {
|
|
184
|
+
name: void 0,
|
|
185
|
+
sourcesTemplate: "{{name}}-{{version}}-sources.zip",
|
|
186
|
+
artifactTemplate: "{{name}}-{{version}}-{{browser}}.zip",
|
|
187
|
+
sourcesRoot: root,
|
|
188
|
+
includeSources: [],
|
|
189
|
+
compressionLevel: 9,
|
|
190
|
+
...mergedConfig.zip,
|
|
191
|
+
excludeSources: [
|
|
192
|
+
"**/node_modules",
|
|
193
|
+
// WXT files
|
|
194
|
+
"**/web-ext.config.ts",
|
|
195
|
+
// Hidden files
|
|
196
|
+
"**/.*",
|
|
197
|
+
// Tests
|
|
198
|
+
"**/__tests__/**",
|
|
199
|
+
"**/*.+(test|spec).?(c|m)+(j|t)s?(x)",
|
|
200
|
+
// Output directory
|
|
201
|
+
`${path.relative(root, outBaseDir)}/**`,
|
|
202
|
+
// From user
|
|
203
|
+
...mergedConfig.zip?.excludeSources ?? []
|
|
204
|
+
],
|
|
205
|
+
downloadPackages: mergedConfig.zip?.downloadPackages ?? [],
|
|
206
|
+
downloadedPackagesDir
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function resolveAnalysisConfig(root, mergedConfig) {
|
|
210
|
+
const analysisOutputFile = path.resolve(
|
|
211
|
+
root,
|
|
212
|
+
mergedConfig.analysis?.outputFile ?? "stats.html"
|
|
213
|
+
);
|
|
214
|
+
const analysisOutputDir = path.dirname(analysisOutputFile);
|
|
215
|
+
const analysisOutputName = path.parse(analysisOutputFile).name;
|
|
216
|
+
return {
|
|
217
|
+
enabled: mergedConfig.analysis?.enabled ?? false,
|
|
218
|
+
open: mergedConfig.analysis?.open ?? false,
|
|
219
|
+
template: mergedConfig.analysis?.template ?? "treemap",
|
|
220
|
+
outputFile: analysisOutputFile,
|
|
221
|
+
outputDir: analysisOutputDir,
|
|
222
|
+
outputName: analysisOutputName,
|
|
223
|
+
keepArtifacts: mergedConfig.analysis?.keepArtifacts ?? false
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
async function getUnimportOptions(wxtDir, srcDir, logger, extensionApi, config) {
|
|
227
|
+
if (config.imports === false) return false;
|
|
228
|
+
const defaultOptions = {
|
|
229
|
+
debugLog: logger.debug,
|
|
230
|
+
imports: [
|
|
231
|
+
{ name: "defineConfig", from: "wxt" },
|
|
232
|
+
{ name: "fakeBrowser", from: "wxt/testing" }
|
|
233
|
+
],
|
|
234
|
+
presets: [
|
|
235
|
+
{
|
|
236
|
+
package: "wxt/client",
|
|
237
|
+
// There seems to be a bug in unimport that thinks "options" is an
|
|
238
|
+
// export from wxt/client, but it doesn't actually exist... so it's
|
|
239
|
+
// ignored.
|
|
240
|
+
ignore: ["options"]
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
package: extensionApi === "chrome" ? "wxt/browser/chrome" : "wxt/browser"
|
|
244
|
+
},
|
|
245
|
+
{ package: "wxt/sandbox" },
|
|
246
|
+
{ package: "wxt/storage" }
|
|
247
|
+
],
|
|
248
|
+
warn: logger.warn,
|
|
249
|
+
dirs: ["components", "composables", "hooks", "utils"],
|
|
250
|
+
dirsScanOptions: {
|
|
251
|
+
cwd: srcDir
|
|
252
|
+
},
|
|
253
|
+
eslintrc: await getUnimportEslintOptions(wxtDir, config.imports?.eslintrc)
|
|
254
|
+
};
|
|
255
|
+
return defu(
|
|
256
|
+
config.imports ?? {},
|
|
257
|
+
defaultOptions
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
async function getUnimportEslintOptions(wxtDir, options) {
|
|
261
|
+
const rawEslintEnabled = options?.enabled ?? "auto";
|
|
262
|
+
let eslintEnabled;
|
|
263
|
+
switch (rawEslintEnabled) {
|
|
264
|
+
case "auto":
|
|
265
|
+
const version = await getEslintVersion();
|
|
266
|
+
let major = parseInt(version[0]);
|
|
267
|
+
if (major <= 8) eslintEnabled = 8;
|
|
268
|
+
else if (major >= 9) eslintEnabled = 9;
|
|
269
|
+
else eslintEnabled = 8;
|
|
270
|
+
break;
|
|
271
|
+
case true:
|
|
272
|
+
eslintEnabled = 8;
|
|
273
|
+
break;
|
|
274
|
+
default:
|
|
275
|
+
eslintEnabled = rawEslintEnabled;
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
enabled: eslintEnabled,
|
|
279
|
+
filePath: path.resolve(
|
|
280
|
+
wxtDir,
|
|
281
|
+
eslintEnabled === 9 ? "eslint-auto-imports.mjs" : "eslintrc-auto-import.json"
|
|
282
|
+
),
|
|
283
|
+
globalsPropValue: true
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
async function resolveWxtModuleDir() {
|
|
287
|
+
const requireResolve = globalThis.require?.resolve ?? (await import("node:module")).default.createRequire(import.meta.url).resolve;
|
|
288
|
+
return path.resolve(requireResolve("wxt"), "../..");
|
|
289
|
+
}
|
|
290
|
+
async function isDirMissing(dir) {
|
|
291
|
+
return !await fs.exists(dir);
|
|
292
|
+
}
|
|
293
|
+
function logMissingDir(logger, name, expected) {
|
|
294
|
+
logger.warn(
|
|
295
|
+
`${name} directory not found: ./${normalizePath(
|
|
296
|
+
path.relative(process.cwd(), expected)
|
|
297
|
+
)}`
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
const COMMAND_MODES = {
|
|
301
|
+
build: "production",
|
|
302
|
+
serve: "development"
|
|
303
|
+
};
|
|
304
|
+
export async function mergeBuilderConfig(logger, inlineConfig, userConfig) {
|
|
305
|
+
const vite = await import("vite").catch((err) => {
|
|
306
|
+
logger.debug("Failed to import vite:", err);
|
|
307
|
+
});
|
|
308
|
+
if (vite) {
|
|
309
|
+
return {
|
|
310
|
+
vite: async (env) => {
|
|
311
|
+
const resolvedInlineConfig = await inlineConfig.vite?.(env) ?? {};
|
|
312
|
+
const resolvedUserConfig = await userConfig.vite?.(env) ?? {};
|
|
313
|
+
return vite.mergeConfig(resolvedUserConfig, resolvedInlineConfig);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
throw Error("Builder not found. Make sure vite is installed.");
|
|
318
|
+
}
|
|
319
|
+
export async function resolveWxtUserModules(modulesDir, modules = []) {
|
|
320
|
+
const npmModules = await Promise.all(
|
|
321
|
+
modules.map(async (moduleId) => {
|
|
322
|
+
const mod = await import(
|
|
323
|
+
/* @vite-ignore */
|
|
324
|
+
moduleId
|
|
325
|
+
);
|
|
326
|
+
if (mod.default == null) {
|
|
327
|
+
throw Error("Module missing default export: " + moduleId);
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
...mod.default,
|
|
331
|
+
type: "node_module",
|
|
332
|
+
id: moduleId
|
|
333
|
+
};
|
|
334
|
+
})
|
|
335
|
+
);
|
|
336
|
+
const localModulePaths = await glob(["*.[tj]s", "*/index.[tj]s"], {
|
|
337
|
+
cwd: modulesDir,
|
|
338
|
+
onlyFiles: true
|
|
339
|
+
}).catch(() => []);
|
|
340
|
+
const localModules = await Promise.all(
|
|
341
|
+
localModulePaths.map(async (file) => {
|
|
342
|
+
const absolutePath = normalizePath(path.resolve(modulesDir, file));
|
|
343
|
+
const { config } = await loadConfig({
|
|
344
|
+
configFile: absolutePath,
|
|
345
|
+
globalRc: false,
|
|
346
|
+
rcFile: false,
|
|
347
|
+
packageJson: false,
|
|
348
|
+
envName: false,
|
|
349
|
+
dotenv: false
|
|
350
|
+
});
|
|
351
|
+
if (config == null)
|
|
352
|
+
throw Error(
|
|
353
|
+
`No config found for ${file}. Did you forget to add a default export?`
|
|
354
|
+
);
|
|
355
|
+
config.name ??= file;
|
|
356
|
+
return {
|
|
357
|
+
...config,
|
|
358
|
+
type: "local",
|
|
359
|
+
id: absolutePath
|
|
360
|
+
};
|
|
361
|
+
})
|
|
362
|
+
);
|
|
363
|
+
return [...npmModules, ...localModules];
|
|
364
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FsCache } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* A basic file system cache stored at `<srcDir>/.wxt/cache/<key>`. Just caches a string in a
|
|
4
|
+
* file for the given key.
|
|
5
|
+
*
|
|
6
|
+
* @param srcDir Absolute path to source directory. See `InternalConfig.srcDir`
|
|
7
|
+
*/
|
|
8
|
+
export declare function createFsCache(wxtDir: string): FsCache;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import fs, { ensureDir } from "fs-extra";
|
|
2
|
+
import { dirname, resolve } from "path";
|
|
3
|
+
import { writeFileIfDifferent } from "./fs.mjs";
|
|
4
|
+
export function createFsCache(wxtDir) {
|
|
5
|
+
const getPath = (key) => resolve(wxtDir, "cache", encodeURIComponent(key));
|
|
6
|
+
return {
|
|
7
|
+
async set(key, value) {
|
|
8
|
+
const path = getPath(key);
|
|
9
|
+
await ensureDir(dirname(path));
|
|
10
|
+
await writeFileIfDifferent(path, value);
|
|
11
|
+
},
|
|
12
|
+
async get(key) {
|
|
13
|
+
const path = getPath(key);
|
|
14
|
+
try {
|
|
15
|
+
return await fs.readFile(path, "utf-8");
|
|
16
|
+
} catch {
|
|
17
|
+
return void 0;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { LogLevels, consola } from "consola";
|
|
2
|
+
import { printHeader } from "./log/index.mjs";
|
|
3
|
+
import { formatDuration } from "./time.mjs";
|
|
4
|
+
export function defineCommand(cb, options) {
|
|
5
|
+
return async (...args) => {
|
|
6
|
+
const isDebug = !!args.find((arg) => arg?.debug);
|
|
7
|
+
if (isDebug) {
|
|
8
|
+
consola.level = LogLevels.debug;
|
|
9
|
+
}
|
|
10
|
+
const startTime = Date.now();
|
|
11
|
+
try {
|
|
12
|
+
printHeader();
|
|
13
|
+
const ongoing = await cb(...args);
|
|
14
|
+
if (!ongoing && !options?.disableFinishedLog)
|
|
15
|
+
consola.success(
|
|
16
|
+
`Finished in ${formatDuration(Date.now() - startTime)}`
|
|
17
|
+
);
|
|
18
|
+
} catch (err) {
|
|
19
|
+
consola.fail(
|
|
20
|
+
`Command failed after ${formatDuration(Date.now() - startTime)}`
|
|
21
|
+
);
|
|
22
|
+
consola.error(err);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VIRTUAL_NOOP_BACKGROUND_MODULE_ID = "virtual:user-background";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Manifest, Scripting } from 'wxt/browser';
|
|
2
|
+
import { ContentScriptEntrypoint, ResolvedConfig } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Returns a unique and consistent string hash based on a content scripts options.
|
|
5
|
+
*
|
|
6
|
+
* It is able to recognize default values,
|
|
7
|
+
*/
|
|
8
|
+
export declare function hashContentScriptOptions(options: ContentScriptEntrypoint['options']): string;
|
|
9
|
+
export declare function mapWxtOptionsToContentScript(options: ContentScriptEntrypoint['options'], js: string[] | undefined, css: string[] | undefined): Manifest.ContentScript;
|
|
10
|
+
export declare function mapWxtOptionsToRegisteredContentScript(options: ContentScriptEntrypoint['options'], js: string[] | undefined, css: string[] | undefined): Omit<Scripting.RegisteredContentScript, 'id'>;
|
|
11
|
+
export declare function getContentScriptJs(config: ResolvedConfig, entrypoint: ContentScriptEntrypoint): string[];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { getEntrypointBundlePath } from "./entrypoints.mjs";
|
|
2
|
+
export function hashContentScriptOptions(options) {
|
|
3
|
+
const simplifiedOptions = mapWxtOptionsToContentScript(
|
|
4
|
+
options,
|
|
5
|
+
void 0,
|
|
6
|
+
void 0
|
|
7
|
+
);
|
|
8
|
+
Object.keys(simplifiedOptions).forEach((key) => {
|
|
9
|
+
if (simplifiedOptions[key] == null) delete simplifiedOptions[key];
|
|
10
|
+
});
|
|
11
|
+
const withDefaults = {
|
|
12
|
+
exclude_globs: [],
|
|
13
|
+
exclude_matches: [],
|
|
14
|
+
include_globs: [],
|
|
15
|
+
match_about_blank: false,
|
|
16
|
+
run_at: "document_idle",
|
|
17
|
+
all_frames: false,
|
|
18
|
+
// @ts-expect-error - not in type
|
|
19
|
+
match_origin_as_fallback: false,
|
|
20
|
+
world: "ISOLATED",
|
|
21
|
+
...simplifiedOptions
|
|
22
|
+
};
|
|
23
|
+
return JSON.stringify(
|
|
24
|
+
Object.entries(withDefaults).map(([key, value]) => {
|
|
25
|
+
if (Array.isArray(value)) return [key, value.sort()];
|
|
26
|
+
else return [key, value];
|
|
27
|
+
}).sort((l, r) => l[0].localeCompare(r[0]))
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
export 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
|
+
// @ts-expect-error: untyped chrome options
|
|
42
|
+
match_origin_as_fallback: options.matchOriginAsFallback,
|
|
43
|
+
world: options.world
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function mapWxtOptionsToRegisteredContentScript(options, js, css) {
|
|
47
|
+
return {
|
|
48
|
+
allFrames: options.allFrames,
|
|
49
|
+
excludeMatches: options.excludeMatches,
|
|
50
|
+
matches: options.matches,
|
|
51
|
+
runAt: options.runAt,
|
|
52
|
+
js,
|
|
53
|
+
css,
|
|
54
|
+
// @ts-expect-error: Chrome accepts this, not typed in webextension-polyfill (https://developer.chrome.com/docs/extensions/reference/scripting/#type-RegisteredContentScript)
|
|
55
|
+
world: options.world
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function getContentScriptJs(config, entrypoint) {
|
|
59
|
+
return [getEntrypointBundlePath(entrypoint, config.outDir, ".js")];
|
|
60
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Directive names that make up CSPs. There are more, this is all I need for the plugin.
|
|
3
|
+
*/
|
|
4
|
+
export type CspDirective = 'default-src' | 'script-src' | 'object-src';
|
|
5
|
+
export declare class ContentSecurityPolicy {
|
|
6
|
+
private static DIRECTIVE_ORDER;
|
|
7
|
+
data: Record<string, string[]>;
|
|
8
|
+
constructor(csp?: string);
|
|
9
|
+
/**
|
|
10
|
+
* Ensure a set of values are listed under a directive.
|
|
11
|
+
*/
|
|
12
|
+
add(directive: CspDirective, ...newValues: string[]): ContentSecurityPolicy;
|
|
13
|
+
toString(): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export class ContentSecurityPolicy {
|
|
2
|
+
static DIRECTIVE_ORDER = {
|
|
3
|
+
"default-src": 0,
|
|
4
|
+
"script-src": 1,
|
|
5
|
+
"object-src": 2
|
|
6
|
+
};
|
|
7
|
+
data;
|
|
8
|
+
constructor(csp) {
|
|
9
|
+
if (csp) {
|
|
10
|
+
const sections = csp.split(";").map((section) => section.trim());
|
|
11
|
+
this.data = sections.reduce((data, section) => {
|
|
12
|
+
const [key, ...values] = section.split(" ").map((item) => item.trim());
|
|
13
|
+
if (key) data[key] = values;
|
|
14
|
+
return data;
|
|
15
|
+
}, {});
|
|
16
|
+
} else {
|
|
17
|
+
this.data = {};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Ensure a set of values are listed under a directive.
|
|
22
|
+
*/
|
|
23
|
+
add(directive, ...newValues) {
|
|
24
|
+
const values = this.data[directive] ?? [];
|
|
25
|
+
newValues.forEach((newValue) => {
|
|
26
|
+
if (!values.includes(newValue)) values.push(newValue);
|
|
27
|
+
});
|
|
28
|
+
this.data[directive] = values;
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
toString() {
|
|
32
|
+
const directives = Object.entries(this.data).sort(([l], [r]) => {
|
|
33
|
+
const lo = ContentSecurityPolicy.DIRECTIVE_ORDER[l] ?? 2;
|
|
34
|
+
const ro = ContentSecurityPolicy.DIRECTIVE_ORDER[r] ?? 2;
|
|
35
|
+
return lo - ro;
|
|
36
|
+
});
|
|
37
|
+
return directives.map((entry) => entry.flat().join(" ")).join("; ") + ";";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Entrypoint, PerBrowserOption, ResolvedPerBrowserOptions, TargetBrowser } from '../../types';
|
|
2
|
+
export declare function getEntrypointName(entrypointsDir: string, inputPath: string): string;
|
|
3
|
+
export declare function getEntrypointOutputFile(entrypoint: Entrypoint, ext: string): string;
|
|
4
|
+
/**
|
|
5
|
+
* Return's the entrypoint's output path relative to the output directory. Used for paths in the
|
|
6
|
+
* manifest and rollup's bundle.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getEntrypointBundlePath(entrypoint: Entrypoint, outDir: string, ext: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Given an entrypoint option, resolve it's value based on a target browser.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolvePerBrowserOption<T>(option: PerBrowserOption<T>, browser: TargetBrowser): T;
|
|
13
|
+
/**
|
|
14
|
+
* Given an entrypoint option, resolve it's value based on a target browser.
|
|
15
|
+
*
|
|
16
|
+
* defaultIcon is special, it's the only key that's a record, which can confuse this function. So
|
|
17
|
+
* it's been manually excluded from resolution.
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolvePerBrowserOptions<T extends Record<string, any>, TKeys extends keyof T>(options: T, browser: TargetBrowser): ResolvedPerBrowserOptions<T, TKeys>;
|
|
20
|
+
/**
|
|
21
|
+
* Returns true when the entrypoint is an HTML entrypoint.
|
|
22
|
+
*
|
|
23
|
+
* Naively just checking the file extension of the input path.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isHtmlEntrypoint(entrypoint: Entrypoint): boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import path, { relative, resolve } from "node:path";
|
|
2
|
+
import { normalizePath } from "./paths.mjs";
|
|
3
|
+
export function getEntrypointName(entrypointsDir, inputPath) {
|
|
4
|
+
const relativePath = path.relative(entrypointsDir, inputPath);
|
|
5
|
+
const name = relativePath.split(/[\.\/\\]/, 2)[0];
|
|
6
|
+
return name;
|
|
7
|
+
}
|
|
8
|
+
export function getEntrypointOutputFile(entrypoint, ext) {
|
|
9
|
+
return resolve(entrypoint.outputDir, `${entrypoint.name}${ext}`);
|
|
10
|
+
}
|
|
11
|
+
export function getEntrypointBundlePath(entrypoint, outDir, ext) {
|
|
12
|
+
return normalizePath(
|
|
13
|
+
relative(outDir, getEntrypointOutputFile(entrypoint, ext))
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
export function resolvePerBrowserOption(option, browser) {
|
|
17
|
+
if (typeof option === "object" && !Array.isArray(option))
|
|
18
|
+
return option[browser];
|
|
19
|
+
return option;
|
|
20
|
+
}
|
|
21
|
+
export function resolvePerBrowserOptions(options, browser) {
|
|
22
|
+
return Object.fromEntries(
|
|
23
|
+
Object.entries(options).map(([key, value]) => [
|
|
24
|
+
key,
|
|
25
|
+
key === "defaultIcon" ? value : resolvePerBrowserOption(value, browser)
|
|
26
|
+
])
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
export function isHtmlEntrypoint(entrypoint) {
|
|
30
|
+
return entrypoint.inputPath.endsWith(".html");
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getEslintVersion(): Promise<string[]>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export async function getEslintVersion() {
|
|
2
|
+
try {
|
|
3
|
+
const require = (await import("node:module")).default.createRequire(
|
|
4
|
+
import.meta.url
|
|
5
|
+
);
|
|
6
|
+
const { ESLint } = require("eslint");
|
|
7
|
+
return ESLint.version?.split(".") ?? [];
|
|
8
|
+
} catch (error) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Only write the contents to a file if it results in a change. This prevents unnecessary file
|
|
3
|
+
* watchers from being triggered, like WXT's dev server or the TS language server in editors.
|
|
4
|
+
*
|
|
5
|
+
* @param file The file to write to.
|
|
6
|
+
* @param newContents The new text content to write.
|
|
7
|
+
*/
|
|
8
|
+
export declare function writeFileIfDifferent(file: string, newContents: string): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Get all the files in the project's public directory. Returned paths are relative to the
|
|
11
|
+
* `config.publicDir`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getPublicFiles(): Promise<string[]>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import glob from "fast-glob";
|
|
3
|
+
import { unnormalizePath } from "./paths.mjs";
|
|
4
|
+
import { wxt } from "../wxt.mjs";
|
|
5
|
+
export async function writeFileIfDifferent(file, newContents) {
|
|
6
|
+
const existingContents = await fs.readFile(file, "utf-8").catch(() => void 0);
|
|
7
|
+
if (existingContents !== newContents) {
|
|
8
|
+
await fs.writeFile(file, newContents);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export async function getPublicFiles() {
|
|
12
|
+
if (!await fs.exists(wxt.config.publicDir)) return [];
|
|
13
|
+
const files = await glob("**/*", { cwd: wxt.config.publicDir });
|
|
14
|
+
return files.map(unnormalizePath);
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ResolvedConfig } from '../../types';
|
|
2
|
+
export declare function getGlobals(config: ResolvedConfig): Array<{
|
|
3
|
+
name: string;
|
|
4
|
+
value: any;
|
|
5
|
+
type: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function getEntrypointGlobals(entrypointName: string): {
|
|
8
|
+
name: string;
|
|
9
|
+
value: string;
|
|
10
|
+
type: string;
|
|
11
|
+
}[];
|