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,137 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import { kebabCaseAlphanumeric } from "./utils/strings.mjs";
|
|
4
|
+
import { getPackageJson } from "./utils/package.mjs";
|
|
5
|
+
import { minimatch } from "minimatch";
|
|
6
|
+
import { formatDuration } from "./utils/time.mjs";
|
|
7
|
+
import { printFileList } from "./utils/log/printFileList.mjs";
|
|
8
|
+
import { internalBuild } from "./utils/building/index.mjs";
|
|
9
|
+
import { registerWxt, wxt } from "./wxt.mjs";
|
|
10
|
+
import JSZip from "jszip";
|
|
11
|
+
import glob from "fast-glob";
|
|
12
|
+
import { normalizePath } from "./utils/paths.mjs";
|
|
13
|
+
export async function zip(config) {
|
|
14
|
+
await registerWxt("build", config);
|
|
15
|
+
const output = await internalBuild();
|
|
16
|
+
const start = Date.now();
|
|
17
|
+
wxt.logger.info("Zipping extension...");
|
|
18
|
+
const zipFiles = [];
|
|
19
|
+
const projectName = wxt.config.zip.name ?? kebabCaseAlphanumeric(
|
|
20
|
+
(await getPackageJson())?.name || path.dirname(process.cwd())
|
|
21
|
+
);
|
|
22
|
+
const applyTemplate = (template) => template.replaceAll("{{name}}", projectName).replaceAll("{{browser}}", wxt.config.browser).replaceAll(
|
|
23
|
+
"{{version}}",
|
|
24
|
+
output.manifest.version_name ?? output.manifest.version
|
|
25
|
+
).replaceAll("{{mode}}", wxt.config.mode).replaceAll("{{manifestVersion}}", `mv${wxt.config.manifestVersion}`);
|
|
26
|
+
await fs.ensureDir(wxt.config.outBaseDir);
|
|
27
|
+
const outZipFilename = applyTemplate(wxt.config.zip.artifactTemplate);
|
|
28
|
+
const outZipPath = path.resolve(wxt.config.outBaseDir, outZipFilename);
|
|
29
|
+
await zipDir(wxt.config.outDir, outZipPath);
|
|
30
|
+
zipFiles.push(outZipPath);
|
|
31
|
+
if (wxt.config.browser === "firefox") {
|
|
32
|
+
const { overrides, files: downloadedPackages } = await downloadPrivatePackages();
|
|
33
|
+
const sourcesZipFilename = applyTemplate(wxt.config.zip.sourcesTemplate);
|
|
34
|
+
const sourcesZipPath = path.resolve(
|
|
35
|
+
wxt.config.outBaseDir,
|
|
36
|
+
sourcesZipFilename
|
|
37
|
+
);
|
|
38
|
+
await zipDir(wxt.config.zip.sourcesRoot, sourcesZipPath, {
|
|
39
|
+
include: wxt.config.zip.includeSources,
|
|
40
|
+
exclude: wxt.config.zip.excludeSources,
|
|
41
|
+
transform(absolutePath, zipPath, content) {
|
|
42
|
+
if (zipPath.endsWith("package.json")) {
|
|
43
|
+
return addOverridesToPackageJson(absolutePath, content, overrides);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
additionalFiles: downloadedPackages
|
|
47
|
+
});
|
|
48
|
+
zipFiles.push(sourcesZipPath);
|
|
49
|
+
}
|
|
50
|
+
await printFileList(
|
|
51
|
+
wxt.logger.success,
|
|
52
|
+
`Zipped extension in ${formatDuration(Date.now() - start)}`,
|
|
53
|
+
wxt.config.outBaseDir,
|
|
54
|
+
zipFiles
|
|
55
|
+
);
|
|
56
|
+
return zipFiles;
|
|
57
|
+
}
|
|
58
|
+
async function zipDir(directory, outputPath, options) {
|
|
59
|
+
const archive = new JSZip();
|
|
60
|
+
const files = (await glob("**/*", {
|
|
61
|
+
cwd: directory,
|
|
62
|
+
// Ignore node_modules, otherwise this glob step takes forever
|
|
63
|
+
ignore: ["**/node_modules"],
|
|
64
|
+
onlyFiles: true
|
|
65
|
+
// TODO: Fix #738
|
|
66
|
+
// dot: true,
|
|
67
|
+
})).filter((relativePath) => {
|
|
68
|
+
return options?.include?.some((pattern) => minimatch(relativePath, pattern)) || !options?.exclude?.some((pattern) => minimatch(relativePath, pattern));
|
|
69
|
+
});
|
|
70
|
+
const filesToZip = [
|
|
71
|
+
...files,
|
|
72
|
+
...(options?.additionalFiles ?? []).map(
|
|
73
|
+
(file) => path.relative(directory, file)
|
|
74
|
+
)
|
|
75
|
+
];
|
|
76
|
+
for (const file of filesToZip) {
|
|
77
|
+
const absolutePath = path.resolve(directory, file);
|
|
78
|
+
if (file.endsWith(".json")) {
|
|
79
|
+
const content = await fs.readFile(absolutePath, "utf-8");
|
|
80
|
+
archive.file(
|
|
81
|
+
file,
|
|
82
|
+
await options?.transform?.(absolutePath, file, content) || content
|
|
83
|
+
);
|
|
84
|
+
} else {
|
|
85
|
+
const content = await fs.readFile(absolutePath);
|
|
86
|
+
archive.file(file, content);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
await options?.additionalWork?.(archive);
|
|
90
|
+
await new Promise(
|
|
91
|
+
(resolve, reject) => archive.generateNodeStream({
|
|
92
|
+
type: "nodebuffer",
|
|
93
|
+
...wxt.config.zip.compressionLevel === 0 ? { compression: "STORE" } : {
|
|
94
|
+
compression: "DEFLATE",
|
|
95
|
+
compressionOptions: { level: wxt.config.zip.compressionLevel }
|
|
96
|
+
}
|
|
97
|
+
}).pipe(fs.createWriteStream(outputPath)).on("error", reject).on("close", resolve)
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
async function downloadPrivatePackages() {
|
|
101
|
+
const overrides = {};
|
|
102
|
+
const files = [];
|
|
103
|
+
if (wxt.config.zip.downloadPackages.length > 0) {
|
|
104
|
+
const _downloadPackages = new Set(wxt.config.zip.downloadPackages);
|
|
105
|
+
const allPackages = await wxt.pm.listDependencies({
|
|
106
|
+
all: true,
|
|
107
|
+
cwd: wxt.config.root
|
|
108
|
+
});
|
|
109
|
+
const downloadPackages = allPackages.filter(
|
|
110
|
+
(pkg) => _downloadPackages.has(pkg.name)
|
|
111
|
+
);
|
|
112
|
+
for (const pkg of downloadPackages) {
|
|
113
|
+
wxt.logger.info(`Downloading package: ${pkg.name}@${pkg.version}`);
|
|
114
|
+
const id = `${pkg.name}@${pkg.version}`;
|
|
115
|
+
const tgzPath = await wxt.pm.downloadDependency(
|
|
116
|
+
id,
|
|
117
|
+
wxt.config.zip.downloadedPackagesDir
|
|
118
|
+
);
|
|
119
|
+
files.push(tgzPath);
|
|
120
|
+
overrides[id] = tgzPath;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return { overrides, files };
|
|
124
|
+
}
|
|
125
|
+
function addOverridesToPackageJson(absolutePackageJsonPath, content, overrides) {
|
|
126
|
+
if (Object.keys(overrides).length === 0) return content;
|
|
127
|
+
const packageJsonDir = path.dirname(absolutePackageJsonPath);
|
|
128
|
+
const oldPackage = JSON.parse(content);
|
|
129
|
+
const newPackage = {
|
|
130
|
+
...oldPackage,
|
|
131
|
+
[wxt.pm.overridesKey]: { ...oldPackage[wxt.pm.overridesKey] }
|
|
132
|
+
};
|
|
133
|
+
Object.entries(overrides).forEach(([key, absolutePath]) => {
|
|
134
|
+
newPackage[wxt.pm.overridesKey][key] = "file://./" + normalizePath(path.relative(packageJsonDir, absolutePath));
|
|
135
|
+
});
|
|
136
|
+
return JSON.stringify(newPackage, null, 2);
|
|
137
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,81 +1,6 @@
|
|
|
1
|
-
import { I as InlineConfig, B as BuildOutput, U as UserConfig, E as ExtensionRunnerConfig, W as WxtDevServer } from './index-nWRfwAJi.js';
|
|
2
|
-
export { x as BackgroundDefinition, n as BackgroundEntrypoint, i as BackgroundEntrypointOptions, j as BaseContentScriptEntrypointOptions, m as BaseEntrypoint, h as BaseEntrypointOptions, e as BuildStepOutput, J as ConfigEnv, w as ContentScriptDefinition, C as ContentScriptEntrypoint, ac as CopiedPublicFile, a5 as Dependency, r as Entrypoint, s as EntrypointGroup, $ as EslintGlobalsPropValue, a0 as Eslintrc, _ as ExtensionRunner, Z as FsCache, ad as GeneratedPublicFile, G as GenericEntrypoint, X as HookResult, u as IsolatedWorldContentScriptDefinition, k as IsolatedWorldContentScriptEntrypointOptions, L as Logger, v as MainWorldContentScriptDefinition, M as MainWorldContentScriptEntrypointOptions, t as OnContentScriptStopped, p as OptionsEntrypoint, l as OptionsEntrypointOptions, d as OutputAsset, c as OutputChunk, O as OutputFile, A as PerBrowserMap, z as PerBrowserOption, o as PopupEntrypoint, P as PopupEntrypointOptions, f as ReloadContentScriptPayload, ab as ResolvedBasePublicFile, R as ResolvedConfig, a1 as ResolvedEslintrc, D as ResolvedPerBrowserOptions, aa as ResolvedPublicFile, V as ServerInfo, q as SidepanelEntrypoint, S as SidepanelEntrypointOptions, T as TargetBrowser, g as TargetManifestVersion, y as UnlistedScriptDefinition, F as UserManifest, H as UserManifestFn, Y as Wxt, N as WxtBuilder, Q as WxtBuilderServer, K as WxtCommand, af as WxtDirEntry, ah as WxtDirFileEntry, ag as WxtDirTypeReferenceEntry, b as WxtHooks, a8 as WxtModule, a6 as WxtModuleOptions, a7 as WxtModuleSetup, a9 as WxtModuleWithMetadata, a4 as WxtPackageManager, ae as WxtPlugin, a3 as WxtResolvedUnimportOptions, a2 as WxtUnimportOptions, a as WxtViteConfig } from './index-nWRfwAJi.js';
|
|
3
|
-
import 'vite';
|
|
4
|
-
import 'webextension-polyfill';
|
|
5
|
-
import 'unimport';
|
|
6
|
-
import 'consola';
|
|
7
|
-
import '@aklinker1/rollup-plugin-visualizer';
|
|
8
|
-
import 'chokidar';
|
|
9
|
-
import 'c12';
|
|
10
|
-
import 'hookable';
|
|
11
|
-
import 'nypm';
|
|
12
|
-
|
|
13
1
|
/**
|
|
14
|
-
*
|
|
15
|
-
* the root directory, and merges that config with what is passed in.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* // Use config from `wxt.config.ts`
|
|
19
|
-
* const res = await build()
|
|
20
|
-
*
|
|
21
|
-
* // or override config `from wxt.config.ts`
|
|
22
|
-
* const res = await build({
|
|
23
|
-
* // Override config...
|
|
24
|
-
* })
|
|
2
|
+
* @module wxt
|
|
25
3
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
* Remove generated/temp files from the directory.
|
|
30
|
-
*
|
|
31
|
-
* @param config Optional config that will override your `<root>/wxt.config.ts`.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* await clean();
|
|
35
|
-
*/
|
|
36
|
-
declare function clean(config?: InlineConfig): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Remove generated/temp files from the directory.
|
|
39
|
-
*
|
|
40
|
-
* @deprecated
|
|
41
|
-
*
|
|
42
|
-
* @param root The directory to look for generated/temp files in. Defaults to `process.cwd()`. Can be relative to `process.cwd()` or absolute.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* await clean();
|
|
46
|
-
*/
|
|
47
|
-
declare function clean(root?: string): Promise<void>;
|
|
48
|
-
|
|
49
|
-
declare function defineConfig(config: UserConfig): UserConfig;
|
|
50
|
-
|
|
51
|
-
declare function defineRunnerConfig(config: ExtensionRunnerConfig): ExtensionRunnerConfig;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Creates a dev server and pre-builds all the files that need to exist before loading the extension.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* const server = await wxt.createServer({
|
|
58
|
-
* // Enter config...
|
|
59
|
-
* });
|
|
60
|
-
* await server.start();
|
|
61
|
-
*/
|
|
62
|
-
declare function createServer(inlineConfig?: InlineConfig): Promise<WxtDevServer>;
|
|
63
|
-
|
|
64
|
-
declare function initialize(options: {
|
|
65
|
-
directory: string;
|
|
66
|
-
template: string;
|
|
67
|
-
packageManager: string;
|
|
68
|
-
}): Promise<void>;
|
|
69
|
-
|
|
70
|
-
declare function prepare(config: InlineConfig): Promise<void>;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Build and zip the extension for distribution.
|
|
74
|
-
* @param config Optional config that will override your `<root>/wxt.config.ts`.
|
|
75
|
-
* @returns A list of all files included in the ZIP.
|
|
76
|
-
*/
|
|
77
|
-
declare function zip(config?: InlineConfig): Promise<string[]>;
|
|
78
|
-
|
|
79
|
-
var version = "0.18.14";
|
|
80
|
-
|
|
81
|
-
export { BuildOutput, ExtensionRunnerConfig, InlineConfig, UserConfig, WxtDevServer, build, clean, createServer, defineConfig, defineRunnerConfig, initialize, prepare, version, zip };
|
|
4
|
+
export * from './core';
|
|
5
|
+
export * from './types';
|
|
6
|
+
export * from './version';
|
package/dist/index.mjs
ADDED
package/dist/modules.d.ts
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
import { a6 as WxtModuleOptions, a8 as WxtModule, a7 as WxtModuleSetup, Y as Wxt, r as Entrypoint } from './index-nWRfwAJi.js';
|
|
2
|
-
import * as vite from 'vite';
|
|
3
|
-
import { UnimportOptions } from 'unimport';
|
|
4
|
-
import 'webextension-polyfill';
|
|
5
|
-
import 'consola';
|
|
6
|
-
import '@aklinker1/rollup-plugin-visualizer';
|
|
7
|
-
import 'chokidar';
|
|
8
|
-
import 'c12';
|
|
9
|
-
import 'hookable';
|
|
10
|
-
import 'nypm';
|
|
11
|
-
|
|
12
1
|
/**
|
|
13
2
|
* Utilities for creating reusable, build-time modules for WXT.
|
|
14
3
|
*
|
|
15
4
|
* @module wxt/modules
|
|
16
5
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
import type { Entrypoint, Wxt, WxtModule, WxtModuleOptions, WxtModuleSetup } from './types';
|
|
7
|
+
import * as vite from 'vite';
|
|
8
|
+
import type { UnimportOptions } from 'unimport';
|
|
9
|
+
export { WxtModule };
|
|
10
|
+
export declare function defineWxtModule<TOptions extends WxtModuleOptions>(module: WxtModule<TOptions> | WxtModuleSetup<TOptions>): WxtModule<TOptions>;
|
|
19
11
|
/**
|
|
20
12
|
* Adds a TS/JS file as an entrypoint to the project. This file will be bundled
|
|
21
13
|
* along with the other entrypoints.
|
|
@@ -39,7 +31,7 @@ declare function defineWxtModule<TOptions extends WxtModuleOptions>(module: WxtM
|
|
|
39
31
|
* });
|
|
40
32
|
* });
|
|
41
33
|
*/
|
|
42
|
-
declare function addEntrypoint(wxt: Wxt, entrypoint: Entrypoint): void;
|
|
34
|
+
export declare function addEntrypoint(wxt: Wxt, entrypoint: Entrypoint): void;
|
|
43
35
|
/**
|
|
44
36
|
* Copy files inside a directory (as if it were the public directory) into the
|
|
45
37
|
* extension's output directory. The directory itself is not copied, just the
|
|
@@ -53,7 +45,7 @@ declare function addEntrypoint(wxt: Wxt, entrypoint: Entrypoint): void;
|
|
|
53
45
|
* addPublicAssets(wxt, "./dist/prebundled");
|
|
54
46
|
* });
|
|
55
47
|
*/
|
|
56
|
-
declare function addPublicAssets(wxt: Wxt, dir: string): void;
|
|
48
|
+
export declare function addPublicAssets(wxt: Wxt, dir: string): void;
|
|
57
49
|
/**
|
|
58
50
|
* Merge additional vite config for one or more entrypoint "groups" that make
|
|
59
51
|
* up individual builds. Config in the project's `wxt.config.ts` file takes
|
|
@@ -72,7 +64,7 @@ declare function addPublicAssets(wxt: Wxt, dir: string): void;
|
|
|
72
64
|
* });
|
|
73
65
|
* });
|
|
74
66
|
*/
|
|
75
|
-
declare function addViteConfig(wxt: Wxt, viteConfig: (env: vite.ConfigEnv) => vite.UserConfig | undefined): void;
|
|
67
|
+
export declare function addViteConfig(wxt: Wxt, viteConfig: (env: vite.ConfigEnv) => vite.UserConfig | undefined): void;
|
|
76
68
|
/**
|
|
77
69
|
* Add a runtime plugin to the project. In each entrypoint, before executing
|
|
78
70
|
* the `main` function, plugins are executed.
|
|
@@ -86,7 +78,7 @@ declare function addViteConfig(wxt: Wxt, viteConfig: (env: vite.ConfigEnv) => vi
|
|
|
86
78
|
* addWxtPlugin(wxt, "wxt-module-analytics/client-plugin");
|
|
87
79
|
* });
|
|
88
80
|
*/
|
|
89
|
-
declare function addWxtPlugin(wxt: Wxt, plugin: string): void;
|
|
81
|
+
export declare function addWxtPlugin(wxt: Wxt, plugin: string): void;
|
|
90
82
|
/**
|
|
91
83
|
* Add an Unimport preset ([built-in](https://github.com/unjs/unimport?tab=readme-ov-file#built-in-presets),
|
|
92
84
|
* [custom](https://github.com/unjs/unimport?tab=readme-ov-file#custom-presets),
|
|
@@ -114,6 +106,4 @@ declare function addWxtPlugin(wxt: Wxt, plugin: string): void;
|
|
|
114
106
|
* addImportPreset(wxt, { package: "vue" });
|
|
115
107
|
* });
|
|
116
108
|
*/
|
|
117
|
-
declare function addImportPreset(wxt: Wxt, preset: UnimportOptions['presets'][0]): void;
|
|
118
|
-
|
|
119
|
-
export { WxtModule, addEntrypoint, addImportPreset, addPublicAssets, addViteConfig, addWxtPlugin, defineWxtModule };
|
|
109
|
+
export declare function addImportPreset(wxt: Wxt, preset: UnimportOptions['presets'][0]): void;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
// src/modules.ts
|
|
2
1
|
import * as vite from "vite";
|
|
3
2
|
import glob from "fast-glob";
|
|
4
3
|
import { resolve } from "node:path";
|
|
5
|
-
|
|
4
|
+
export {};
|
|
5
|
+
export function defineWxtModule(module) {
|
|
6
6
|
if (typeof module === "function") return { setup: module };
|
|
7
7
|
return module;
|
|
8
8
|
}
|
|
9
|
-
function addEntrypoint(wxt, entrypoint) {
|
|
9
|
+
export function addEntrypoint(wxt, entrypoint) {
|
|
10
10
|
wxt.hooks.hook("entrypoints:resolved", (wxt2, entrypoints) => {
|
|
11
11
|
entrypoints.push(entrypoint);
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
|
-
function addPublicAssets(wxt, dir) {
|
|
14
|
+
export function addPublicAssets(wxt, dir) {
|
|
15
15
|
wxt.hooks.hook("build:publicAssets", async (wxt2, files) => {
|
|
16
16
|
const moreFiles = await glob("**/*", { cwd: dir });
|
|
17
17
|
if (moreFiles.length === 0) {
|
|
@@ -23,7 +23,7 @@ function addPublicAssets(wxt, dir) {
|
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
-
function addViteConfig(wxt, viteConfig) {
|
|
26
|
+
export function addViteConfig(wxt, viteConfig) {
|
|
27
27
|
wxt.hooks.hook("ready", (wxt2) => {
|
|
28
28
|
const userVite = wxt2.config.vite;
|
|
29
29
|
wxt2.config.vite = async (env) => {
|
|
@@ -33,12 +33,12 @@ function addViteConfig(wxt, viteConfig) {
|
|
|
33
33
|
};
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
function addWxtPlugin(wxt, plugin) {
|
|
36
|
+
export function addWxtPlugin(wxt, plugin) {
|
|
37
37
|
wxt.hooks.hook("ready", (wxt2) => {
|
|
38
38
|
wxt2.config.plugins.push(plugin);
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
|
-
function addImportPreset(wxt, preset) {
|
|
41
|
+
export function addImportPreset(wxt, preset) {
|
|
42
42
|
wxt.hooks.hook("ready", (wxt2) => {
|
|
43
43
|
if (!wxt2.config.imports) return;
|
|
44
44
|
wxt2.config.imports.presets ??= [];
|
|
@@ -46,12 +46,3 @@ function addImportPreset(wxt, preset) {
|
|
|
46
46
|
wxt2.config.imports.presets.push(preset);
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
export {
|
|
51
|
-
defineWxtModule,
|
|
52
|
-
addEntrypoint,
|
|
53
|
-
addPublicAssets,
|
|
54
|
-
addViteConfig,
|
|
55
|
-
addWxtPlugin,
|
|
56
|
-
addImportPreset
|
|
57
|
-
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface WxtAppConfig {
|
|
2
|
+
}
|
|
3
|
+
/**
|
|
4
|
+
* Runtime app config defined in `<srcDir>/app.config.ts`.
|
|
5
|
+
*
|
|
6
|
+
* You can add fields to this interface via ["Module Augmentation"](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation):
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* // app.config.ts
|
|
10
|
+
* import 'wxt/sandbox';
|
|
11
|
+
*
|
|
12
|
+
* declare module "wxt/sandbox" {
|
|
13
|
+
* export interface WxtAppConfig {
|
|
14
|
+
* analytics: AnalyticsConfig
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function defineAppConfig(config: WxtAppConfig): WxtAppConfig;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface WxtWebSocket extends WebSocket {
|
|
2
|
+
addWxtEventListener(type: 'wxt:reload-extension', callback: (event: CustomEvent<undefined>) => void, options?: AddEventListenerOptions | boolean): void;
|
|
3
|
+
addWxtEventListener(type: 'wxt:reload-content-script', callback?: (event: CustomEvent<ReloadContentScriptPayload>) => void, options?: AddEventListenerOptions | boolean): void;
|
|
4
|
+
addWxtEventListener(type: 'wxt:reload-page', callback?: (event: CustomEvent<string>) => void, options?: AddEventListenerOptions | boolean): void;
|
|
5
|
+
sendCustom(event: string, payload?: any): void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Connect to the websocket and listen for messages.
|
|
9
|
+
*
|
|
10
|
+
* @param onMessage Optional callback that is called when a message is recieved and we've verified
|
|
11
|
+
* it's structure is what we expect.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getDevServerWebSocket(): WxtWebSocket;
|
|
14
|
+
export interface ReloadContentScriptPayload {
|
|
15
|
+
registration?: 'manifest' | 'runtime';
|
|
16
|
+
contentScript: {
|
|
17
|
+
matches: string[];
|
|
18
|
+
js?: string[];
|
|
19
|
+
css?: string[];
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { logger } from "./utils/logger.mjs";
|
|
2
|
+
let ws;
|
|
3
|
+
export function getDevServerWebSocket() {
|
|
4
|
+
if (import.meta.env.COMMAND !== "serve")
|
|
5
|
+
throw Error(
|
|
6
|
+
"Must be running WXT dev command to connect to call getDevServerWebSocket()"
|
|
7
|
+
);
|
|
8
|
+
if (ws == null) {
|
|
9
|
+
const serverUrl = `${__DEV_SERVER_PROTOCOL__}//${__DEV_SERVER_HOSTNAME__}:${__DEV_SERVER_PORT__}`;
|
|
10
|
+
logger.debug("Connecting to dev server @", serverUrl);
|
|
11
|
+
ws = new WebSocket(serverUrl, "vite-hmr");
|
|
12
|
+
ws.addWxtEventListener = ws.addEventListener.bind(ws);
|
|
13
|
+
ws.sendCustom = (event, payload) => ws?.send(JSON.stringify({ type: "custom", event, payload }));
|
|
14
|
+
ws.addEventListener("open", () => {
|
|
15
|
+
logger.debug("Connected to dev server");
|
|
16
|
+
});
|
|
17
|
+
ws.addEventListener("close", () => {
|
|
18
|
+
logger.debug("Disconnected from dev server");
|
|
19
|
+
});
|
|
20
|
+
ws.addEventListener("error", (event) => {
|
|
21
|
+
logger.error("Failed to connect to dev server", event);
|
|
22
|
+
});
|
|
23
|
+
ws.addEventListener("message", (e) => {
|
|
24
|
+
try {
|
|
25
|
+
const message = JSON.parse(e.data);
|
|
26
|
+
if (message.type === "custom") {
|
|
27
|
+
ws?.dispatchEvent(
|
|
28
|
+
new CustomEvent(message.event, { detail: message.data })
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
} catch (err) {
|
|
32
|
+
logger.error("Failed to handle message", err);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return ws;
|
|
37
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Any runtime APIs that don't use the web extension APIs.
|
|
3
|
+
*
|
|
4
|
+
* @module wxt/sandbox
|
|
5
|
+
*/
|
|
6
|
+
export * from './define-unlisted-script';
|
|
7
|
+
export * from './define-background';
|
|
8
|
+
export * from './define-content-script';
|
|
9
|
+
export * from './define-wxt-plugin';
|
|
10
|
+
export * from './define-app-config';
|
|
11
|
+
export * from '@webext-core/match-patterns';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function print(method, ...args) {
|
|
2
|
+
if (import.meta.env.MODE === "production") return;
|
|
3
|
+
if (typeof args[0] === "string") {
|
|
4
|
+
const message = args.shift();
|
|
5
|
+
method(`[wxt] ${message}`, ...args);
|
|
6
|
+
} else {
|
|
7
|
+
method("[wxt]", ...args);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export const logger = {
|
|
11
|
+
debug: (...args) => print(console.debug, ...args),
|
|
12
|
+
log: (...args) => print(console.log, ...args),
|
|
13
|
+
warn: (...args) => print(console.warn, ...args),
|
|
14
|
+
error: (...args) => print(console.error, ...args)
|
|
15
|
+
};
|
package/dist/storage.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
declare const storage: WxtStorage;
|
|
2
|
-
interface WxtStorage {
|
|
1
|
+
export declare const storage: WxtStorage;
|
|
2
|
+
export interface WxtStorage {
|
|
3
3
|
/**
|
|
4
4
|
* Get an item from storage, or return `null` if it doesn't exist.
|
|
5
5
|
*
|
|
@@ -108,8 +108,15 @@ interface WxtStorage {
|
|
|
108
108
|
defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: StorageItemKey): WxtStorageItem<TValue | null, TMetadata>;
|
|
109
109
|
defineItem<TValue, TMetadata extends Record<string, unknown> = {}>(key: StorageItemKey, options: WxtStorageItemOptions<TValue>): WxtStorageItem<TValue, TMetadata>;
|
|
110
110
|
}
|
|
111
|
-
interface WxtStorageItem<TValue, TMetadata extends Record<string, unknown>> {
|
|
111
|
+
export interface WxtStorageItem<TValue, TMetadata extends Record<string, unknown>> {
|
|
112
|
+
/**
|
|
113
|
+
* @deprecated Renamed to `fallback`, use it instead.
|
|
114
|
+
*/
|
|
112
115
|
defaultValue: TValue;
|
|
116
|
+
/**
|
|
117
|
+
* The value provided by the `fallback` option.
|
|
118
|
+
*/
|
|
119
|
+
fallback: TValue;
|
|
113
120
|
/**
|
|
114
121
|
* Get the latest value from storage.
|
|
115
122
|
*/
|
|
@@ -146,15 +153,19 @@ interface WxtStorageItem<TValue, TMetadata extends Record<string, unknown>> {
|
|
|
146
153
|
*/
|
|
147
154
|
migrate(): Promise<void>;
|
|
148
155
|
}
|
|
149
|
-
type StorageArea = 'local' | 'session' | 'sync' | 'managed';
|
|
150
|
-
type StorageItemKey = `${StorageArea}:${string}`;
|
|
151
|
-
interface GetItemOptions<T> {
|
|
156
|
+
export type StorageArea = 'local' | 'session' | 'sync' | 'managed';
|
|
157
|
+
export type StorageItemKey = `${StorageArea}:${string}`;
|
|
158
|
+
export interface GetItemOptions<T> {
|
|
152
159
|
/**
|
|
153
|
-
*
|
|
160
|
+
* @deprecated Renamed to `fallback`, use it instead.
|
|
154
161
|
*/
|
|
155
162
|
defaultValue?: T;
|
|
163
|
+
/**
|
|
164
|
+
* Default value returned when `getItem` would otherwise return `null`.
|
|
165
|
+
*/
|
|
166
|
+
fallback?: T;
|
|
156
167
|
}
|
|
157
|
-
interface RemoveItemOptions {
|
|
168
|
+
export interface RemoveItemOptions {
|
|
158
169
|
/**
|
|
159
170
|
* Optionally remove metadata when deleting a key.
|
|
160
171
|
*
|
|
@@ -162,15 +173,29 @@ interface RemoveItemOptions {
|
|
|
162
173
|
*/
|
|
163
174
|
removeMeta?: boolean;
|
|
164
175
|
}
|
|
165
|
-
interface SnapshotOptions {
|
|
176
|
+
export interface SnapshotOptions {
|
|
166
177
|
/**
|
|
167
178
|
* Exclude a list of keys. The storage area prefix should be removed since the snapshot is for a
|
|
168
179
|
* specific storage area already.
|
|
169
180
|
*/
|
|
170
181
|
excludeKeys?: string[];
|
|
171
182
|
}
|
|
172
|
-
interface WxtStorageItemOptions<T> {
|
|
173
|
-
|
|
183
|
+
export interface WxtStorageItemOptions<T> {
|
|
184
|
+
/**
|
|
185
|
+
* @deprecated Renamed to `fallback`, use it instead.
|
|
186
|
+
*/
|
|
187
|
+
defaultValue?: T;
|
|
188
|
+
/**
|
|
189
|
+
* Default value returned when `getValue` would otherwise return `null`.
|
|
190
|
+
*/
|
|
191
|
+
fallback?: T;
|
|
192
|
+
/**
|
|
193
|
+
* If passed, a value in storage will be initialized immediately after
|
|
194
|
+
* defining the storage item. This function returns the value that will be
|
|
195
|
+
* saved to storage during the initialization process if a value doesn't
|
|
196
|
+
* already exist.
|
|
197
|
+
*/
|
|
198
|
+
init?: () => T | Promise<T>;
|
|
174
199
|
/**
|
|
175
200
|
* Provide a version number for the storage item to enable migrations. When changing the version
|
|
176
201
|
* in the future, migration functions will be ran on application startup.
|
|
@@ -185,16 +210,14 @@ interface WxtStorageItemOptions<T> {
|
|
|
185
210
|
* Same as `Partial`, but includes `| null`. It makes all the properties of an object optional and
|
|
186
211
|
* nullable.
|
|
187
212
|
*/
|
|
188
|
-
type NullablePartial<T> = {
|
|
213
|
+
export type NullablePartial<T> = {
|
|
189
214
|
[key in keyof T]+?: T[key] | undefined | null;
|
|
190
215
|
};
|
|
191
216
|
/**
|
|
192
217
|
* Callback called when a value in storage is changed.
|
|
193
218
|
*/
|
|
194
|
-
type WatchCallback<T> = (newValue: T, oldValue: T) => void;
|
|
219
|
+
export type WatchCallback<T> = (newValue: T, oldValue: T) => void;
|
|
195
220
|
/**
|
|
196
221
|
* Call to remove a watch listener
|
|
197
222
|
*/
|
|
198
|
-
type Unwatch = () => void;
|
|
199
|
-
|
|
200
|
-
export { type GetItemOptions, type NullablePartial, type RemoveItemOptions, type SnapshotOptions, type StorageArea, type StorageItemKey, type Unwatch, type WatchCallback, type WxtStorage, type WxtStorageItem, type WxtStorageItemOptions, storage };
|
|
223
|
+
export type Unwatch = () => void;
|