wxt 0.20.18 → 0.20.20
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-publish-extension.mjs +4 -3
- package/dist/browser.d.mts +7 -6
- package/dist/browser.mjs +6 -5
- package/dist/builtin-modules/index.mjs +1 -3
- package/dist/builtin-modules/unimport.mjs +1 -3
- package/dist/cli/cli-utils.mjs +5 -6
- package/dist/cli/commands.mjs +1 -3
- package/dist/cli/index.mjs +1 -3
- package/dist/core/build.d.mts +9 -8
- package/dist/core/build.mjs +10 -11
- package/dist/core/builders/vite/index.mjs +27 -25
- package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +1 -3
- package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +6 -6
- package/dist/core/builders/vite/plugins/defineImportMeta.mjs +3 -4
- package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +33 -25
- package/dist/core/builders/vite/plugins/devServerGlobals.mjs +3 -3
- package/dist/core/builders/vite/plugins/download.mjs +15 -11
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +2 -6
- package/dist/core/builders/vite/plugins/extensionApiMock.mjs +13 -8
- package/dist/core/builders/vite/plugins/globals.mjs +1 -3
- package/dist/core/builders/vite/plugins/iifeAnonymous.mjs +1 -2
- package/dist/core/builders/vite/plugins/iifeFooter.mjs +14 -7
- package/dist/core/builders/vite/plugins/index.mjs +18 -19
- package/dist/core/builders/vite/plugins/noopBackground.mjs +14 -9
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +10 -12
- package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +14 -10
- package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +15 -13
- package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +1 -2
- package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +22 -17
- package/dist/core/clean.d.mts +7 -7
- package/dist/core/clean.mjs +6 -7
- package/dist/core/create-server.d.mts +6 -5
- package/dist/core/create-server.mjs +12 -11
- package/dist/core/define-config.mjs +1 -2
- package/dist/core/define-web-ext-config.d.mts +3 -4
- package/dist/core/define-web-ext-config.mjs +4 -7
- package/dist/core/generate-wxt-dir.mjs +8 -9
- package/dist/core/index.mjs +10 -11
- package/dist/core/initialize.mjs +10 -11
- package/dist/core/keyboard-shortcuts.mjs +2 -6
- package/dist/core/package-managers/bun.mjs +1 -3
- package/dist/core/package-managers/deno.mjs +1 -2
- package/dist/core/package-managers/index.mjs +1 -3
- package/dist/core/package-managers/npm.mjs +3 -5
- package/dist/core/package-managers/pnpm.mjs +1 -3
- package/dist/core/package-managers/yarn.mjs +1 -3
- package/dist/core/prepare.mjs +1 -3
- package/dist/core/resolve-config.mjs +20 -23
- package/dist/core/runners/index.mjs +1 -3
- package/dist/core/runners/manual.mjs +2 -6
- package/dist/core/runners/safari.mjs +3 -4
- package/dist/core/runners/web-ext.mjs +2 -6
- package/dist/core/runners/wsl.mjs +3 -4
- package/dist/core/utils/arrays.mjs +4 -11
- package/dist/core/utils/building/build-entrypoints.mjs +8 -9
- package/dist/core/utils/building/detect-dev-changes.mjs +21 -13
- package/dist/core/utils/building/find-entrypoints.mjs +16 -11
- package/dist/core/utils/building/group-entrypoints.mjs +3 -4
- package/dist/core/utils/building/index.mjs +7 -8
- package/dist/core/utils/building/internal-build.mjs +13 -13
- package/dist/core/utils/building/rebuild.mjs +10 -10
- package/dist/core/utils/cache.mjs +6 -8
- package/dist/core/utils/constants.mjs +3 -4
- package/dist/core/utils/content-scripts.mjs +3 -4
- package/dist/core/utils/content-security-policy.mjs +2 -5
- package/dist/core/utils/entrypoints.mjs +6 -10
- package/dist/core/utils/env.mjs +2 -6
- package/dist/core/utils/environments/browser-environment.mjs +1 -3
- package/dist/core/utils/environments/environment.mjs +1 -2
- package/dist/core/utils/environments/extension-environment.mjs +1 -3
- package/dist/core/utils/environments/index.mjs +3 -4
- package/dist/core/utils/eslint.mjs +1 -2
- package/dist/core/utils/fs.mjs +23 -14
- package/dist/core/utils/globals.mjs +1 -2
- package/dist/core/utils/i18n.mjs +1 -2
- package/dist/core/utils/index.mjs +2 -3
- package/dist/core/utils/log/index.mjs +5 -6
- package/dist/core/utils/log/printBuildSummary.mjs +1 -3
- package/dist/core/utils/log/printFileList.mjs +3 -5
- package/dist/core/utils/log/printHeader.mjs +1 -3
- package/dist/core/utils/log/printTable.mjs +1 -2
- package/dist/core/utils/manifest.mjs +23 -31
- package/dist/core/utils/minimatch-multiple.mjs +5 -7
- package/dist/core/utils/network.mjs +3 -5
- package/dist/core/utils/number.mjs +1 -2
- package/dist/core/utils/package.mjs +3 -5
- package/dist/core/utils/paths.d.mts +2 -2
- package/dist/core/utils/paths.mjs +7 -9
- package/dist/core/utils/strings.mjs +4 -7
- package/dist/core/utils/syntax-errors.mjs +1 -3
- package/dist/core/utils/time.mjs +2 -5
- package/dist/core/utils/transform.mjs +8 -6
- package/dist/core/utils/validation.mjs +1 -2
- package/dist/core/utils/virtual-modules.mjs +9 -15
- package/dist/core/utils/wsl.mjs +2 -6
- package/dist/core/wxt.mjs +7 -9
- package/dist/core/zip.d.mts +1 -0
- package/dist/core/zip.mjs +11 -10
- package/dist/index.d.mts +0 -1
- package/dist/index.mjs +1 -2
- package/dist/modules.d.mts +64 -61
- package/dist/modules.mjs +70 -66
- package/dist/testing/fake-browser.mjs +1 -2
- package/dist/testing/index.mjs +1 -2
- package/dist/testing/wxt-vitest-plugin.d.mts +4 -2
- package/dist/testing/wxt-vitest-plugin.mjs +5 -5
- package/dist/types.d.mts +455 -435
- package/dist/utils/app-config.mjs +1 -3
- package/dist/utils/content-script-context.d.mts +49 -39
- package/dist/utils/content-script-context.mjs +36 -31
- package/dist/utils/content-script-ui/iframe.d.mts +12 -13
- package/dist/utils/content-script-ui/iframe.mjs +1 -3
- package/dist/utils/content-script-ui/integrated.d.mts +8 -7
- package/dist/utils/content-script-ui/integrated.mjs +1 -3
- package/dist/utils/content-script-ui/shadow-root.d.mts +37 -25
- package/dist/utils/content-script-ui/shadow-root.mjs +4 -7
- package/dist/utils/content-script-ui/shared.mjs +1 -3
- package/dist/utils/content-script-ui/types.d.mts +29 -34
- package/dist/utils/content-script-ui/types.mjs +1 -1
- package/dist/utils/define-app-config.d.mts +4 -3
- package/dist/utils/define-app-config.mjs +5 -5
- package/dist/utils/define-background.mjs +1 -2
- package/dist/utils/define-content-script.mjs +1 -2
- package/dist/utils/define-unlisted-script.mjs +1 -2
- package/dist/utils/define-wxt-plugin.mjs +1 -2
- package/dist/utils/inject-script.mjs +1 -3
- package/dist/utils/internal/custom-events.mjs +3 -4
- package/dist/utils/internal/location-watcher.mjs +4 -6
- package/dist/utils/internal/logger.mjs +2 -5
- package/dist/utils/match-patterns.mjs +2 -3
- package/dist/utils/split-shadow-root-css.d.mts +6 -2
- package/dist/utils/split-shadow-root-css.mjs +7 -4
- package/dist/utils/storage.mjs +2 -3
- package/dist/version.mjs +2 -3
- package/dist/virtual/background-entrypoint.mjs +4 -16
- package/dist/virtual/content-script-isolated-world-entrypoint.mjs +2 -7
- package/dist/virtual/content-script-main-world-entrypoint.mjs +2 -7
- package/dist/virtual/mock-browser.mjs +1 -3
- package/dist/virtual/reload-html.mjs +3 -10
- package/dist/virtual/unlisted-script-entrypoint.mjs +2 -7
- package/package.json +17 -19
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import normalize from "normalize-path";
|
|
3
|
-
|
|
4
3
|
//#region src/core/utils/paths.ts
|
|
5
4
|
/**
|
|
6
|
-
* Converts system paths to normalized bundler path.
|
|
7
|
-
*
|
|
5
|
+
* Converts system paths to normalized bundler path. On Windows, this returns
|
|
6
|
+
* paths with `/` instead of `\`.
|
|
8
7
|
*/
|
|
9
8
|
function normalizePath(path) {
|
|
10
9
|
return normalize(path);
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
|
-
* Given a normalized path, convert it to the system path style. On Windows,
|
|
12
|
+
* Given a normalized path, convert it to the system path style. On Windows,
|
|
13
|
+
* switch to , otherwise use /.
|
|
14
14
|
*/
|
|
15
15
|
function unnormalizePath(path$1) {
|
|
16
16
|
return path.normalize(path$1);
|
|
17
17
|
}
|
|
18
|
-
const
|
|
18
|
+
const CSS_EXTENSIONS_PATTERN = `+(${[
|
|
19
19
|
"css",
|
|
20
20
|
"scss",
|
|
21
21
|
"sass",
|
|
22
22
|
"less",
|
|
23
23
|
"styl",
|
|
24
24
|
"stylus"
|
|
25
|
-
]
|
|
26
|
-
const CSS_EXTENSIONS_PATTERN = `+(${CSS_EXTENSIONS.join("|")})`;
|
|
27
|
-
|
|
25
|
+
].join("|")})`;
|
|
28
26
|
//#endregion
|
|
29
|
-
export { CSS_EXTENSIONS_PATTERN, normalizePath, unnormalizePath };
|
|
27
|
+
export { CSS_EXTENSIONS_PATTERN, normalizePath, unnormalizePath };
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import { camelCase } from "scule";
|
|
2
|
-
|
|
3
2
|
//#region src/core/utils/strings.ts
|
|
4
3
|
function kebabCaseAlphanumeric(str) {
|
|
5
4
|
return str.toLowerCase().replace(/[^a-z0-9-\s]/g, "").replace(/\s+/g, "-");
|
|
6
5
|
}
|
|
7
|
-
/**
|
|
8
|
-
* Return a safe variable name for a given string.
|
|
9
|
-
*/
|
|
6
|
+
/** Return a safe variable name for a given string. */
|
|
10
7
|
function safeVarName(str) {
|
|
11
8
|
const name = camelCase(kebabCaseAlphanumeric(str));
|
|
12
9
|
if (name.match(/^[a-z]/)) return name;
|
|
13
10
|
return "_" + name;
|
|
14
11
|
}
|
|
15
12
|
/**
|
|
16
|
-
* Converts a string to a valid filename (NOT path), stripping out invalid
|
|
13
|
+
* Converts a string to a valid filename (NOT path), stripping out invalid
|
|
14
|
+
* characters.
|
|
17
15
|
*/
|
|
18
16
|
function safeFilename(str) {
|
|
19
17
|
return kebabCaseAlphanumeric(str);
|
|
20
18
|
}
|
|
21
|
-
|
|
22
19
|
//#endregion
|
|
23
|
-
export { safeFilename, safeVarName };
|
|
20
|
+
export { safeFilename, safeVarName };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { wxt } from "../wxt.mjs";
|
|
2
2
|
import { relative } from "node:path";
|
|
3
3
|
import pc from "picocolors";
|
|
4
|
-
|
|
5
4
|
//#region src/core/utils/syntax-errors.ts
|
|
6
5
|
function isBabelSyntaxError(error) {
|
|
7
6
|
return error instanceof SyntaxError && error.code === "BABEL_PARSER_SYNTAX_ERROR";
|
|
@@ -13,6 +12,5 @@ function logBabelSyntaxError(error) {
|
|
|
13
12
|
if (error.frame) message += "\n\n" + pc.red(error.frame);
|
|
14
13
|
wxt.logger.error(message);
|
|
15
14
|
}
|
|
16
|
-
|
|
17
15
|
//#endregion
|
|
18
|
-
export { isBabelSyntaxError, logBabelSyntaxError };
|
|
16
|
+
export { isBabelSyntaxError, logBabelSyntaxError };
|
package/dist/core/utils/time.mjs
CHANGED
|
@@ -5,9 +5,7 @@ function formatDuration(duration) {
|
|
|
5
5
|
if (duration < 6e4) return `${(duration / 1e3).toFixed(1)} s`;
|
|
6
6
|
return `${(duration / 1e3).toFixed(0)} s`;
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
9
|
-
* Add a timeout to a promise.
|
|
10
|
-
*/
|
|
8
|
+
/** Add a timeout to a promise. */
|
|
11
9
|
function withTimeout(promise, duration) {
|
|
12
10
|
return new Promise((res, rej) => {
|
|
13
11
|
const timeout = setTimeout(() => {
|
|
@@ -16,6 +14,5 @@ function withTimeout(promise, duration) {
|
|
|
16
14
|
promise.then(res).catch(rej).finally(() => clearTimeout(timeout));
|
|
17
15
|
});
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
//#endregion
|
|
21
|
-
export { formatDuration, withTimeout };
|
|
18
|
+
export { formatDuration, withTimeout };
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { parseModule } from "magicast";
|
|
2
|
-
|
|
3
2
|
//#region src/core/utils/transform.ts
|
|
4
3
|
/**
|
|
5
4
|
* Removes any code used at runtime related to an entrypoint's main function.
|
|
5
|
+
*
|
|
6
6
|
* 1. Removes or clears out `main` function from returned object
|
|
7
|
-
* 2. Removes any unused functions/variables outside the definition that aren't
|
|
7
|
+
* 2. Removes any unused functions/variables outside the definition that aren't
|
|
8
|
+
* being called/used
|
|
8
9
|
* 3. Removes unused imports
|
|
9
|
-
*
|
|
10
|
+
* 4. Removes value-less, side-effect only imports (like `import "./styles.css"` or
|
|
11
|
+
* `import "polyfill"`)
|
|
10
12
|
*/
|
|
11
13
|
function removeMainFunctionCode(code) {
|
|
12
14
|
const mod = parseModule(code);
|
|
@@ -134,7 +136,8 @@ function removeSideEffectImports(mod) {
|
|
|
134
136
|
deleteImportAst(mod, (node) => node.specifiers.length === 0);
|
|
135
137
|
}
|
|
136
138
|
/**
|
|
137
|
-
* Util to get the AST as a simple JSON object, stripping out large objects and
|
|
139
|
+
* Util to get the AST as a simple JSON object, stripping out large objects and
|
|
140
|
+
* file locations to keep it readible
|
|
138
141
|
*/
|
|
139
142
|
function getSimpleAstJson(ast) {
|
|
140
143
|
if (!ast) return ast;
|
|
@@ -142,6 +145,5 @@ function getSimpleAstJson(ast) {
|
|
|
142
145
|
else if (typeof ast === "object") return Object.fromEntries(Object.entries(ast).filter(([key]) => key !== "loc" && key !== "start" && key !== "end").map(([key, value]) => [key, getSimpleAstJson(value)]));
|
|
143
146
|
else return ast;
|
|
144
147
|
}
|
|
145
|
-
|
|
146
148
|
//#endregion
|
|
147
|
-
export { removeMainFunctionCode };
|
|
149
|
+
export { removeMainFunctionCode };
|
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
//#region src/core/utils/virtual-modules.ts
|
|
2
|
-
const virtualEntrypointTypes = [
|
|
3
|
-
"content-script-main-world",
|
|
4
|
-
"content-script-isolated-world",
|
|
5
|
-
"background",
|
|
6
|
-
"unlisted-script"
|
|
7
|
-
];
|
|
8
|
-
/**
|
|
9
|
-
* All the names of entrypoint files in the `src/virtual/` and `dist/virtual/` directories, minus the extension.
|
|
10
|
-
*/
|
|
11
|
-
const virtualEntrypointModuleNames = virtualEntrypointTypes.map((name) => `${name}-entrypoint`);
|
|
12
1
|
/**
|
|
13
|
-
* All the names of files in the `src/virtual/` and `dist/virtual/` directories,
|
|
2
|
+
* All the names of files in the `src/virtual/` and `dist/virtual/` directories,
|
|
3
|
+
* minus the extension.
|
|
14
4
|
*/
|
|
15
5
|
const virtualModuleNames = [
|
|
16
|
-
...
|
|
6
|
+
...[
|
|
7
|
+
"content-script-main-world",
|
|
8
|
+
"content-script-isolated-world",
|
|
9
|
+
"background",
|
|
10
|
+
"unlisted-script"
|
|
11
|
+
].map((name) => `${name}-entrypoint`),
|
|
17
12
|
"mock-browser",
|
|
18
13
|
"reload-html"
|
|
19
14
|
];
|
|
20
|
-
|
|
21
15
|
//#endregion
|
|
22
|
-
export { virtualModuleNames };
|
|
16
|
+
export { virtualModuleNames };
|
package/dist/core/utils/wsl.mjs
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import isWsl_ from "is-wsl";
|
|
2
|
-
|
|
3
2
|
//#region src/core/utils/wsl.ts
|
|
4
|
-
/**
|
|
5
|
-
* Returns true when running on WSL or WSL2.
|
|
6
|
-
*/
|
|
3
|
+
/** Returns true when running on WSL or WSL2. */
|
|
7
4
|
function isWsl() {
|
|
8
5
|
return isWsl_;
|
|
9
6
|
}
|
|
10
|
-
|
|
11
7
|
//#endregion
|
|
12
|
-
export { isWsl };
|
|
8
|
+
export { isWsl };
|
package/dist/core/wxt.mjs
CHANGED
|
@@ -4,15 +4,16 @@ import { createWxtPackageManager } from "./package-managers/index.mjs";
|
|
|
4
4
|
import { createViteBuilder } from "./builders/vite/index.mjs";
|
|
5
5
|
import { relative } from "path";
|
|
6
6
|
import { createHooks } from "hookable";
|
|
7
|
-
|
|
8
7
|
//#region src/core/wxt.ts
|
|
9
8
|
/**
|
|
10
|
-
* Global variable set once `createWxt` is called once. Since this variable is
|
|
11
|
-
* global can be used instead of passing the variable as a
|
|
9
|
+
* Global variable set once `createWxt` is called once. Since this variable is
|
|
10
|
+
* used everywhere, this global can be used instead of passing the variable as a
|
|
11
|
+
* function parameter everywhere.
|
|
12
12
|
*/
|
|
13
13
|
let wxt;
|
|
14
14
|
/**
|
|
15
|
-
* Create and register a global instance of the Wxt interface for use throughout
|
|
15
|
+
* Create and register a global instance of the Wxt interface for use throughout
|
|
16
|
+
* the project.
|
|
16
17
|
*/
|
|
17
18
|
async function registerWxt(command, inlineConfig = {}) {
|
|
18
19
|
process.env.NODE_ENV ??= inlineConfig.mode ?? (command === "serve" ? "development" : "production");
|
|
@@ -63,12 +64,9 @@ async function initWxtModule(module) {
|
|
|
63
64
|
if (module.hooks) wxt.hooks.addHooks(module.hooks);
|
|
64
65
|
await module.setup?.(wxt, module.configKey ? wxt.config[module.configKey] : void 0);
|
|
65
66
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Unloads WXT modules.
|
|
68
|
-
*/
|
|
67
|
+
/** Unloads WXT modules. */
|
|
69
68
|
function deinitWxtModules() {
|
|
70
69
|
wxt.hooks.removeAllHooks();
|
|
71
70
|
}
|
|
72
|
-
|
|
73
71
|
//#endregion
|
|
74
|
-
export { deinitWxtModules, initWxtModules, registerWxt, wxt };
|
|
72
|
+
export { deinitWxtModules, initWxtModules, registerWxt, wxt };
|
package/dist/core/zip.d.mts
CHANGED
|
@@ -3,6 +3,7 @@ import { InlineConfig } from "../types.mjs";
|
|
|
3
3
|
//#region src/core/zip.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Build and zip the extension for distribution.
|
|
6
|
+
*
|
|
6
7
|
* @param config Optional config that will override your `<root>/wxt.config.ts`.
|
|
7
8
|
* @returns A list of all files included in the ZIP.
|
|
8
9
|
*/
|
package/dist/core/zip.mjs
CHANGED
|
@@ -10,14 +10,15 @@ import { getPackageJson } from "./utils/package.mjs";
|
|
|
10
10
|
import { internalBuild } from "./utils/building/internal-build.mjs";
|
|
11
11
|
import "./utils/building/index.mjs";
|
|
12
12
|
import { minimatchMultiple } from "./utils/minimatch-multiple.mjs";
|
|
13
|
-
import
|
|
14
|
-
import glob from "
|
|
13
|
+
import { mkdir, readFile } from "node:fs/promises";
|
|
14
|
+
import { glob } from "tinyglobby";
|
|
15
15
|
import path from "node:path";
|
|
16
|
+
import { createWriteStream } from "node:fs";
|
|
16
17
|
import JSZip from "jszip";
|
|
17
|
-
|
|
18
18
|
//#region src/core/zip.ts
|
|
19
19
|
/**
|
|
20
20
|
* Build and zip the extension for distribution.
|
|
21
|
+
*
|
|
21
22
|
* @param config Optional config that will override your `<root>/wxt.config.ts`.
|
|
22
23
|
* @returns A list of all files included in the ZIP.
|
|
23
24
|
*/
|
|
@@ -31,7 +32,7 @@ async function zip(config) {
|
|
|
31
32
|
const packageJson = await getPackageJson();
|
|
32
33
|
const projectName = wxt.config.zip.name ?? safeFilename(packageJson?.name || path.basename(process.cwd()));
|
|
33
34
|
const applyTemplate = (template) => template.replaceAll("{{name}}", projectName).replaceAll("{{browser}}", wxt.config.browser).replaceAll("{{version}}", output.manifest.version_name ?? output.manifest.version).replaceAll("{{packageVersion}}", packageJson?.version).replaceAll("{{mode}}", wxt.config.mode).replaceAll("{{manifestVersion}}", `mv${wxt.config.manifestVersion}`);
|
|
34
|
-
await
|
|
35
|
+
await mkdir(wxt.config.outBaseDir, { recursive: true });
|
|
35
36
|
await wxt.hooks.callHook("zip:extension:start", wxt);
|
|
36
37
|
const outZipFilename = applyTemplate(wxt.config.zip.artifactTemplate);
|
|
37
38
|
const outZipPath = path.resolve(wxt.config.outBaseDir, outZipFilename);
|
|
@@ -65,17 +66,18 @@ async function zipDir(directory, outputPath, options) {
|
|
|
65
66
|
const filesToZip = [...(await glob(["**/*", ...options?.include || []], {
|
|
66
67
|
cwd: directory,
|
|
67
68
|
ignore: ["**/node_modules"],
|
|
68
|
-
onlyFiles: true
|
|
69
|
+
onlyFiles: true,
|
|
70
|
+
expandDirectories: false
|
|
69
71
|
})).filter((relativePath) => {
|
|
70
72
|
return minimatchMultiple(relativePath, options?.include) || !minimatchMultiple(relativePath, options?.exclude);
|
|
71
73
|
}), ...(options?.additionalFiles ?? []).map((file) => path.relative(directory, file))];
|
|
72
74
|
for (const file of filesToZip) {
|
|
73
75
|
const absolutePath = path.resolve(directory, file);
|
|
74
76
|
if (file.endsWith(".json")) {
|
|
75
|
-
const content = await
|
|
77
|
+
const content = await readFile(absolutePath, "utf-8");
|
|
76
78
|
archive.file(file, await options?.transform?.(absolutePath, file, content) || content);
|
|
77
79
|
} else {
|
|
78
|
-
const content = await
|
|
80
|
+
const content = await readFile(absolutePath);
|
|
79
81
|
archive.file(file, content);
|
|
80
82
|
}
|
|
81
83
|
}
|
|
@@ -86,7 +88,7 @@ async function zipDir(directory, outputPath, options) {
|
|
|
86
88
|
compression: "DEFLATE",
|
|
87
89
|
compressionOptions: { level: wxt.config.zip.compressionLevel }
|
|
88
90
|
}
|
|
89
|
-
}).pipe(
|
|
91
|
+
}).pipe(createWriteStream(outputPath)).on("error", reject).on("close", resolve));
|
|
90
92
|
}
|
|
91
93
|
async function downloadPrivatePackages() {
|
|
92
94
|
const overrides = {};
|
|
@@ -123,6 +125,5 @@ function addOverridesToPackageJson(absolutePackageJsonPath, content, overrides)
|
|
|
123
125
|
});
|
|
124
126
|
return JSON.stringify(newPackage, null, 2);
|
|
125
127
|
}
|
|
126
|
-
|
|
127
128
|
//#endregion
|
|
128
|
-
export { zip };
|
|
129
|
+
export { zip };
|
package/dist/index.d.mts
CHANGED
|
@@ -8,6 +8,5 @@ import { initialize } from "./core/initialize.mjs";
|
|
|
8
8
|
import { prepare } from "./core/prepare.mjs";
|
|
9
9
|
import { zip } from "./core/zip.mjs";
|
|
10
10
|
import { normalizePath } from "./core/utils/paths.mjs";
|
|
11
|
-
import "./core/index.mjs";
|
|
12
11
|
import { version } from "./version.mjs";
|
|
13
12
|
export { BackgroundDefinition, BackgroundEntrypoint, BackgroundEntrypointOptions, BaseContentScriptEntrypointOptions, BaseEntrypoint, BaseEntrypointOptions, BaseScriptEntrypointOptions, BuildOutput, BuildStepOutput, ConfigEnv, ContentScriptDefinition, ContentScriptEntrypoint, CopiedPublicFile, Dependency, Entrypoint, EntrypointGroup, EntrypointInfo, EslintGlobalsPropValue, Eslintrc, ExtensionRunner, ExtensionRunnerConfig, FsCache, GeneratedPublicFile, GenericEntrypoint, HookResult, InlineConfig, IsolatedWorldContentScriptDefinition, IsolatedWorldContentScriptEntrypointOptions, Logger, MainWorldContentScriptDefinition, MainWorldContentScriptEntrypointOptions, OnContentScriptStopped, OptionsEntrypoint, OptionsEntrypointOptions, OutputAsset, OutputChunk, OutputFile, PerBrowserMap, PerBrowserOption, PopupEntrypoint, PopupEntrypointOptions, ReloadContentScriptPayload, ResolvedBasePublicFile, ResolvedConfig, ResolvedEslintrc, ResolvedPerBrowserOptions, ResolvedPublicFile, ServerInfo, SidepanelEntrypoint, SidepanelEntrypointOptions, TargetBrowser, TargetManifestVersion, ThemeIcon, UnlistedScriptDefinition, UnlistedScriptEntrypoint, UserConfig, UserManifest, UserManifestFn, WebExtConfig, Wxt, WxtBuilder, WxtBuilderServer, WxtCommand, WxtDevServer, WxtDirEntry, WxtDirFileEntry, WxtDirTypeReferenceEntry, WxtHooks, WxtModule, WxtModuleOptions, WxtModuleSetup, WxtModuleWithMetadata, WxtPackageManager, WxtPlugin, WxtResolvedUnimportOptions, WxtUnimportOptions, WxtViteConfig, build, clean, createServer, defineConfig, defineRunnerConfig, defineWebExtConfig, initialize, normalizePath, prepare, version, zip };
|
package/dist/index.mjs
CHANGED
|
@@ -9,5 +9,4 @@ import { initialize } from "./core/initialize.mjs";
|
|
|
9
9
|
import { prepare } from "./core/prepare.mjs";
|
|
10
10
|
import { zip } from "./core/zip.mjs";
|
|
11
11
|
import "./core/index.mjs";
|
|
12
|
-
|
|
13
|
-
export { build, clean, createServer, defineConfig, defineRunnerConfig, defineWebExtConfig, initialize, normalizePath, prepare, version, zip };
|
|
12
|
+
export { build, clean, createServer, defineConfig, defineRunnerConfig, defineWebExtConfig, initialize, normalizePath, prepare, version, zip };
|
package/dist/modules.d.mts
CHANGED
|
@@ -16,20 +16,20 @@ declare function defineWxtModule<TOptions extends WxtModuleOptions>(module: WxtM
|
|
|
16
16
|
* To extract entrypoint options from a JS/TS file, use
|
|
17
17
|
* `wxt.builder.importEntrypoint` (see example).
|
|
18
18
|
*
|
|
19
|
-
* @param wxt The wxt instance provided by the module's setup function.
|
|
20
|
-
* @param entrypoint The entrypoint to be bundled along with the extension.
|
|
21
|
-
*
|
|
22
19
|
* @example
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
20
|
+
* export default defineWxtModule(async (wxt, options) => {
|
|
21
|
+
* const entrypointPath = '/path/to/my-entrypoint.ts';
|
|
22
|
+
* addEntrypoint(wxt, {
|
|
23
|
+
* type: 'content-script',
|
|
24
|
+
* name: 'some-name',
|
|
25
|
+
* inputPath: entrypointPath,
|
|
26
|
+
* outputDir: wxt.config.outDir,
|
|
27
|
+
* options: await wxt.builder.importEntrypoint(entrypointPath),
|
|
28
|
+
* });
|
|
31
29
|
* });
|
|
32
|
-
*
|
|
30
|
+
*
|
|
31
|
+
* @param wxt The wxt instance provided by the module's setup function.
|
|
32
|
+
* @param entrypoint The entrypoint to be bundled along with the extension.
|
|
33
33
|
*/
|
|
34
34
|
declare function addEntrypoint(wxt: Wxt, entrypoint: Entrypoint): void;
|
|
35
35
|
/**
|
|
@@ -37,79 +37,82 @@ declare function addEntrypoint(wxt: Wxt, entrypoint: Entrypoint): void;
|
|
|
37
37
|
* extension's output directory. The directory itself is not copied, just the
|
|
38
38
|
* files inside it. If a filename matches an existing one, it is ignored.
|
|
39
39
|
*
|
|
40
|
+
* @example
|
|
41
|
+
* export default defineWxtModule((wxt, options) => {
|
|
42
|
+
* addPublicAssets(wxt, './dist/prebundled');
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
40
45
|
* @param wxt The wxt instance provided by the module's setup function.
|
|
41
46
|
* @param dir The directory to copy.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* export default defineWxtModule((wxt, options) => {
|
|
45
|
-
* addPublicAssets(wxt, "./dist/prebundled");
|
|
46
|
-
* });
|
|
47
47
|
*/
|
|
48
48
|
declare function addPublicAssets(wxt: Wxt, dir: string): void;
|
|
49
49
|
/**
|
|
50
|
-
* Merge additional vite config for one or more entrypoint "groups" that make
|
|
51
|
-
*
|
|
50
|
+
* Merge additional vite config for one or more entrypoint "groups" that make up
|
|
51
|
+
* individual builds. Config in the project's `wxt.config.ts` file takes
|
|
52
52
|
* precedence over any config added by this function.
|
|
53
53
|
*
|
|
54
|
-
* @param wxt The wxt instance provided by the module's setup function.
|
|
55
|
-
* @param viteConfig A function that returns the vite config the module is
|
|
56
|
-
adding. Same format as `vite` in `wxt.config.ts`.
|
|
57
|
-
*
|
|
58
54
|
* @example
|
|
59
|
-
*
|
|
55
|
+
* export default defineWxtModule((wxt, options) => {
|
|
60
56
|
* addViteConfig(wxt, () => ({
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
57
|
+
* build: {
|
|
58
|
+
* sourceMaps: true,
|
|
59
|
+
* },
|
|
64
60
|
* });
|
|
65
|
-
*
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* @param wxt The wxt instance provided by the module's setup function.
|
|
64
|
+
* @param viteConfig A function that returns the vite config the module is
|
|
65
|
+
* adding. Same format as `vite` in `wxt.config.ts`.
|
|
66
66
|
*/
|
|
67
67
|
declare function addViteConfig(wxt: Wxt, viteConfig: (env: vite.ConfigEnv) => vite.UserConfig | undefined): void;
|
|
68
68
|
/**
|
|
69
|
-
* Add a runtime plugin to the project. In each entrypoint, before executing
|
|
70
|
-
*
|
|
69
|
+
* Add a runtime plugin to the project. In each entrypoint, before executing the
|
|
70
|
+
* `main` function, plugins are executed.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* export default defineWxtModule((wxt) => {
|
|
74
|
+
* addWxtPlugin(wxt, 'wxt-module-analytics/client-plugin');
|
|
75
|
+
* });
|
|
71
76
|
*
|
|
72
77
|
* @param wxt The wxt instance provided by the module's setup function.
|
|
73
78
|
* @param plugin An import from an NPM module, or an absolute file path to the
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* export default defineWxtModule((wxt) => {
|
|
78
|
-
* addWxtPlugin(wxt, "wxt-module-analytics/client-plugin");
|
|
79
|
-
* });
|
|
79
|
+
* file to load at runtime.
|
|
80
80
|
*/
|
|
81
81
|
declare function addWxtPlugin(wxt: Wxt, plugin: string): void;
|
|
82
82
|
/**
|
|
83
|
-
* Add an Unimport preset
|
|
83
|
+
* Add an Unimport preset
|
|
84
|
+
* ([built-in](https://github.com/unjs/unimport?tab=readme-ov-file#built-in-presets),
|
|
84
85
|
* [custom](https://github.com/unjs/unimport?tab=readme-ov-file#custom-presets),
|
|
85
|
-
* or
|
|
86
|
+
* or
|
|
87
|
+
* [auto-scanned](https://github.com/unjs/unimport?tab=readme-ov-file#exports-auto-scan)),
|
|
86
88
|
* to the project's list of auto-imported utilities.
|
|
87
89
|
*
|
|
88
90
|
* Some things to note:
|
|
89
|
-
* - This function will only de-duplicate built-in preset names. It will not
|
|
90
|
-
* stop you adding duplicate custom or auto-scanned presets.
|
|
91
|
-
* - If the project has disabled imports, this function has no effect.
|
|
92
91
|
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
92
|
+
* - This function will only de-duplicate built-in preset names. It will not stop
|
|
93
|
+
* you adding duplicate custom or auto-scanned presets.
|
|
94
|
+
* - If the project has disabled imports, this function has no effect.
|
|
95
95
|
*
|
|
96
96
|
* @example
|
|
97
|
-
*
|
|
97
|
+
* export default defineWxtModule((wxt) => {
|
|
98
98
|
* // Built-in preset:
|
|
99
99
|
* addImportPreset(wxt, "vue");
|
|
100
100
|
* // Custom preset:
|
|
101
101
|
* addImportPreset(wxt, {
|
|
102
|
-
*
|
|
103
|
-
*
|
|
102
|
+
* from: "vue",
|
|
103
|
+
* imports: ["ref", "reactive", ...],
|
|
104
104
|
* });
|
|
105
105
|
* // Auto-scanned preset:
|
|
106
106
|
* addImportPreset(wxt, { package: "vue" });
|
|
107
|
-
*
|
|
107
|
+
* });
|
|
108
|
+
*
|
|
109
|
+
* @param wxt The wxt instance provided by the module's setup function.
|
|
110
|
+
* @param preset The preset to add to the project.
|
|
108
111
|
*/
|
|
109
112
|
declare function addImportPreset(wxt: Wxt, preset: UnimportOptions['presets'][0]): void;
|
|
110
113
|
/**
|
|
111
|
-
* Adds an import alias to the project's TSConfig paths and bundler. Path can
|
|
112
|
-
*
|
|
114
|
+
* Adds an import alias to the project's TSConfig paths and bundler. Path can be
|
|
115
|
+
* absolute or relative to the project's root directory.
|
|
113
116
|
*
|
|
114
117
|
* Usually, this is used to provide access to some code generated by your
|
|
115
118
|
* module. In the example below, a `i18n` plugin generates a variable that it
|
|
@@ -117,22 +120,22 @@ declare function addImportPreset(wxt: Wxt, preset: UnimportOptions['presets'][0]
|
|
|
117
120
|
* to it.
|
|
118
121
|
*
|
|
119
122
|
* @example
|
|
120
|
-
*
|
|
123
|
+
* import path from 'node:path';
|
|
121
124
|
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
125
|
+
* export default defineWxtModule((wxt) => {
|
|
126
|
+
* const i18nPath = path.resolve(wxt.config.wxtDir, 'i18n.ts');
|
|
124
127
|
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
128
|
+
* // Generate the file
|
|
129
|
+
* wxt.hooks.hook('prepare:types', (_, entries) => {
|
|
130
|
+
* entries.push({
|
|
131
|
+
* path: i18nPath,
|
|
132
|
+
* text: `export const i18n = ...`,
|
|
133
|
+
* });
|
|
130
134
|
* });
|
|
131
|
-
* });
|
|
132
135
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
+
* // Add alias
|
|
137
|
+
* addAlias(wxt, '#i18n', i18nPath);
|
|
138
|
+
* });
|
|
136
139
|
*/
|
|
137
140
|
declare function addAlias(wxt: Wxt, alias: string, path: string): void;
|
|
138
141
|
//#endregion
|