wxt 0.21.3 → 0.21.5
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/README.md +1 -1
- package/dist/{core/build.d.mts → build.d.mts} +2 -2
- package/dist/{core/build.mjs → build.mjs} +3 -4
- package/dist/{core/clean.d.mts → clean.d.mts} +2 -2
- package/dist/{core/clean.mjs → clean.mjs} +3 -3
- package/dist/cli/cli-utils.mjs +11 -8
- package/dist/cli/commands.mjs +10 -9
- package/dist/{core/create-server.d.mts → create-server.d.mts} +2 -2
- package/dist/{core/create-server.mjs → create-server.mjs} +13 -14
- package/dist/define-config.d.mts +6 -0
- package/dist/{core/define-config.mjs → define-config.mjs} +1 -1
- package/dist/{core/define-web-ext-config.d.mts → define-web-ext-config.d.mts} +2 -2
- package/dist/{core/define-web-ext-config.mjs → define-web-ext-config.mjs} +1 -1
- package/dist/index.d.mts +12 -12
- package/dist/index.mjs +10 -11
- package/dist/{core/initialize.d.mts → initialize.d.mts} +2 -1
- package/dist/{core/initialize.mjs → initialize.mjs} +22 -7
- package/dist/inline/dotenv-expand/index.mjs +31 -0
- package/dist/inline/get-port-please/index.mjs +196 -0
- package/dist/inline/is-wsl/index.mjs +44 -0
- package/dist/inline/normalize-path/index.mjs +23 -0
- package/dist/inline/ohash/index.mjs +113 -0
- package/dist/inline/scule/index.mjs +50 -0
- package/dist/{core/utils/building → internal}/build-entrypoints.mjs +5 -5
- package/dist/internal/builders/unknown.mjs +22 -0
- package/dist/{core → internal}/builders/vite/index.mjs +144 -139
- package/dist/internal/builders/vite/plugins/add-entrypoint-group-runtime-env-entries.mjs +16 -0
- package/dist/internal/builders/vite/plugins/add-runtime-env-entries.mjs +14 -0
- package/dist/{core/builders/vite/plugins/bundleAnalysis.mjs → internal/builders/vite/plugins/bundle-analysis.mjs} +1 -1
- package/dist/{core/builders/vite/plugins/cssEntrypoints.mjs → internal/builders/vite/plugins/css-entrypoints.mjs} +2 -2
- package/dist/{core/builders/vite/plugins/defineImportMeta.mjs → internal/builders/vite/plugins/define-import-meta.mjs} +1 -1
- package/dist/{core/builders/vite/plugins/devHtmlPrerender.mjs → internal/builders/vite/plugins/dev-html-prerender.mjs} +6 -7
- package/dist/{core/builders/vite/plugins/devServerGlobals.mjs → internal/builders/vite/plugins/dev-server-globals.mjs} +1 -1
- package/dist/{core/builders/vite/plugins/extensionApiMock.mjs → internal/builders/vite/plugins/extension-api-mock.mjs} +1 -1
- package/dist/{core/builders/vite/plugins/iifeAnonymous.mjs → internal/builders/vite/plugins/iife-anonymous.mjs} +1 -1
- package/dist/{core/builders/vite/plugins/iifeFooter.mjs → internal/builders/vite/plugins/iife-footer.mjs} +1 -1
- package/dist/internal/builders/vite/plugins/index.mjs +17 -0
- package/dist/{core/builders/vite/plugins/noopBackground.mjs → internal/builders/vite/plugins/noop-background.mjs} +2 -2
- package/dist/{core/builders/vite/plugins/removeEntrypointMainFunction.mjs → internal/builders/vite/plugins/remove-entrypoint-main-function.mjs} +3 -4
- package/dist/{core/builders/vite/plugins/resolveAppConfig.mjs → internal/builders/vite/plugins/resolve-app-config.mjs} +2 -2
- package/dist/{core/builders/vite/plugins/resolveVirtualModules.mjs → internal/builders/vite/plugins/resolve-virtual-modules.mjs} +8 -6
- package/dist/{core/builders/vite/plugins/tsconfigPaths.mjs → internal/builders/vite/plugins/tsconfig-paths.mjs} +1 -1
- package/dist/internal/builders/vite/plugins/wxt-plugin-loader.mjs +77 -0
- package/dist/{builtin-modules → internal/builtin-modules}/escape-unicode.mjs +2 -2
- package/dist/{builtin-modules → internal/builtin-modules}/favicon-permission.mjs +2 -2
- package/dist/{builtin-modules → internal/builtin-modules}/index.mjs +4 -2
- package/dist/internal/builtin-modules/plugins.mjs +21 -0
- package/dist/{builtin-modules → internal/builtin-modules}/unimport.mjs +20 -9
- package/dist/{core/utils → internal}/constants.mjs +1 -1
- package/dist/internal/detect-builder.mjs +9 -0
- package/dist/{core/utils/building → internal}/detect-dev-changes.mjs +4 -4
- package/dist/internal/detect-runner.mjs +11 -0
- package/dist/internal/entrypoint-finders/flat.mjs +84 -0
- package/dist/internal/environments/browser-environment.mjs +48 -0
- package/dist/{core/utils → internal}/environments/environment.mjs +1 -1
- package/dist/{core/utils → internal}/environments/extension-environment.mjs +1 -1
- package/dist/{core/utils/create-file-reloader.mjs → internal/file-reloader.mjs} +10 -11
- package/dist/{core/utils/building → internal}/find-entrypoints.mjs +10 -75
- package/dist/{core → internal}/generate-wxt-dir.mjs +10 -10
- package/dist/internal/get-public-files.mjs +14 -0
- package/dist/{core/utils/building → internal}/group-entrypoints.mjs +1 -1
- package/dist/{core/utils → internal}/i18n.mjs +1 -1
- package/dist/{core/utils/building → internal}/internal-build.mjs +10 -10
- package/dist/{core → internal}/keyboard-shortcuts.mjs +2 -1
- package/dist/{core/utils → internal}/manifest.mjs +14 -14
- package/dist/internal/package-managers/bun.mjs +22 -0
- package/dist/{core → internal}/package-managers/deno.mjs +1 -1
- package/dist/{core → internal}/package-managers/index.mjs +1 -1
- package/dist/{core → internal}/package-managers/npm.mjs +11 -5
- package/dist/{core → internal}/package-managers/pnpm.mjs +6 -3
- package/dist/{core → internal}/package-managers/yarn.mjs +6 -3
- package/dist/{core/utils → internal}/package.mjs +3 -3
- package/dist/{core/utils/building → internal}/rebuild.mjs +5 -5
- package/dist/{core → internal}/resolve-config.mjs +22 -42
- package/dist/internal/runners/manual.mjs +22 -0
- package/dist/internal/runners/web-ext.mjs +79 -0
- package/dist/{core/utils/globals.mjs → internal/runtime-env-entries.mjs} +4 -4
- package/dist/internal/spinner.mjs +69 -0
- package/dist/{core/utils → internal}/syntax-errors.mjs +2 -2
- package/dist/{core/utils → internal}/theme-icons.mjs +3 -3
- package/dist/{core/utils → internal}/transform.mjs +1 -1
- package/dist/{core/utils → internal}/validation.mjs +1 -1
- package/dist/{core → internal}/wxt.mjs +24 -7
- package/dist/{core/utils/arrays.mjs → internal-utils/array-utils.mjs} +1 -1
- package/dist/{core/utils/cache.mjs → internal-utils/cache-utils.mjs} +3 -3
- package/dist/{core/utils/content-scripts.mjs → internal-utils/content-script-utils.mjs} +2 -2
- package/dist/{core/utils/content-security-policy.mjs → internal-utils/csp-utils.mjs} +1 -1
- package/dist/{core/utils/entrypoints.d.mts → internal-utils/entrypoint-utils.d.mts} +2 -2
- package/dist/{core/utils/entrypoints.mjs → internal-utils/entrypoint-utils.mjs} +2 -2
- package/dist/{core/utils/env.mjs → internal-utils/env-utils.mjs} +3 -3
- package/dist/internal-utils/eslint-utils.mjs +8 -0
- package/dist/{core/utils/fs.mjs → internal-utils/fs-utils.mjs} +6 -11
- package/dist/internal-utils/log/index.mjs +6 -0
- package/dist/{core/utils/log/printBuildSummary.mjs → internal-utils/log/print-build-summary.mjs} +3 -3
- package/dist/{core/utils/log/printFileList.mjs → internal-utils/log/print-file-list.mjs} +9 -8
- package/dist/{core/utils/log/printHeader.mjs → internal-utils/log/print-header.mjs} +2 -2
- package/dist/{core/utils/log/printTable.mjs → internal-utils/log/print-table.mjs} +1 -1
- package/dist/internal-utils/log/wxt-logger.mjs +32 -0
- package/dist/internal-utils/module-utils.mjs +32 -0
- package/dist/{core/utils/number.mjs → internal-utils/number-utils.mjs} +1 -1
- package/dist/{core/utils/paths.d.mts → internal-utils/path-utils.d.mts} +1 -1
- package/dist/{core/utils/paths.mjs → internal-utils/path-utils.mjs} +3 -3
- package/dist/{core/utils/strings.mjs → internal-utils/string-utils.mjs} +3 -3
- package/dist/{core/utils/time.mjs → internal-utils/time-utils.mjs} +1 -1
- package/dist/{core/utils/types.d.mts → internal-utils/type-utils.d.mts} +2 -1
- package/dist/{modules.d.mts → modules/index.d.mts} +10 -4
- package/dist/{modules.mjs → modules/index.mjs} +14 -5
- package/dist/prepare.d.mts +6 -0
- package/dist/prepare.mjs +11 -0
- package/dist/testing/wxt-vitest-plugin.mjs +7 -7
- package/dist/types.d.mts +97 -47
- package/dist/utils/content-script-context.d.mts +1 -1
- package/dist/utils/content-script-ui/iframe.d.mts +7 -0
- package/dist/utils/content-script-ui/iframe.mjs +2 -0
- package/dist/utils/content-script-ui/integrated.d.mts +7 -0
- package/dist/utils/content-script-ui/integrated.mjs +2 -0
- package/dist/utils/content-script-ui/shadow-root.d.mts +7 -0
- package/dist/utils/content-script-ui/shadow-root.mjs +2 -0
- package/dist/utils/content-script-ui/types.d.mts +23 -7
- package/dist/utils/internal/custom-events.d.mts +11 -1
- package/dist/utils/internal/custom-events.mjs +4 -0
- package/dist/version.mjs +1 -1
- package/dist/virtual/background-entrypoint.mjs +11 -0
- package/dist/{core/zip.d.mts → zip.d.mts} +2 -2
- package/dist/{core/zip.mjs → zip.mjs} +11 -13
- package/package.json +14 -15
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +0 -16
- package/dist/core/builders/vite/plugins/globals.mjs +0 -14
- package/dist/core/builders/vite/plugins/index.mjs +0 -17
- package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +0 -56
- package/dist/core/define-config.d.mts +0 -6
- package/dist/core/index.d.mts +0 -10
- package/dist/core/index.mjs +0 -12
- package/dist/core/package-managers/bun.mjs +0 -19
- package/dist/core/prepare.d.mts +0 -6
- package/dist/core/prepare.mjs +0 -12
- package/dist/core/runners/manual.mjs +0 -11
- package/dist/core/runners/safari.mjs +0 -14
- package/dist/core/runners/web-ext.mjs +0 -63
- package/dist/core/runners/wsl.mjs +0 -14
- package/dist/core/utils/building/index.mjs +0 -7
- package/dist/core/utils/environments/browser-environment.mjs +0 -18
- package/dist/core/utils/eslint.mjs +0 -11
- package/dist/core/utils/index.d.mts +0 -2
- package/dist/core/utils/index.mjs +0 -3
- package/dist/core/utils/log/index.mjs +0 -5
- /package/dist/{core/utils → internal}/environments/index.mjs +0 -0
- /package/dist/{core/utils → internal}/virtual-modules.mjs +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { d } from "../../inline/is-wsl/index.mjs";
|
|
2
|
+
import { formatDuration } from "../../internal-utils/time-utils.mjs";
|
|
3
|
+
import { mkdir } from "node:fs/promises";
|
|
4
|
+
import { relative } from "node:path";
|
|
5
|
+
import defu from "defu";
|
|
6
|
+
//#region src/internal/runners/web-ext.ts
|
|
7
|
+
/**
|
|
8
|
+
* WXT's default `ExtensionRunner` that uses web-ext to open the browser. It
|
|
9
|
+
* cannot open the browser automatically in some environments, like WSL.
|
|
10
|
+
*/
|
|
11
|
+
var WebExtRunner = class {
|
|
12
|
+
instance;
|
|
13
|
+
constructor(webExt, logger, config) {
|
|
14
|
+
this.webExt = webExt;
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
this.config = config;
|
|
17
|
+
}
|
|
18
|
+
async canOpen() {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
async openBrowser() {
|
|
22
|
+
if (this.config.browser === "safari") return this.logManualReason("Cannot open Safari using web-ext");
|
|
23
|
+
if (d) return this.logManualReason("Cannot open browser when using WSL");
|
|
24
|
+
if (this.config.webExt.config.disabled) return this.config.logger.info(this.loadManualMessage());
|
|
25
|
+
const startTime = Date.now();
|
|
26
|
+
this.logger.consoleStream.write = ({ level, msg, name }) => {
|
|
27
|
+
if (level >= ERROR_LOG_LEVEL) this.config.logger.error(name, msg);
|
|
28
|
+
if (level >= WARN_LOG_LEVEL) this.config.logger.warn(msg);
|
|
29
|
+
};
|
|
30
|
+
const wxtUserConfig = this.config.webExt.config;
|
|
31
|
+
if (this.config.browser !== "firefox" && wxtUserConfig?.chromiumProfile) await mkdir(wxtUserConfig.chromiumProfile, { recursive: true });
|
|
32
|
+
const finalConfig = {
|
|
33
|
+
browserConsole: wxtUserConfig?.openConsole,
|
|
34
|
+
devtools: wxtUserConfig?.openDevtools,
|
|
35
|
+
startUrl: wxtUserConfig?.startUrls,
|
|
36
|
+
keepProfileChanges: wxtUserConfig?.keepProfileChanges,
|
|
37
|
+
chromiumPort: wxtUserConfig?.chromiumPort,
|
|
38
|
+
...this.config.browser === "firefox" ? {
|
|
39
|
+
firefox: wxtUserConfig?.binaries?.firefox,
|
|
40
|
+
firefoxProfile: wxtUserConfig?.firefoxProfile,
|
|
41
|
+
pref: wxtUserConfig?.firefoxPref,
|
|
42
|
+
args: wxtUserConfig?.firefoxArgs
|
|
43
|
+
} : {
|
|
44
|
+
chromiumBinary: wxtUserConfig?.binaries?.[this.config.browser],
|
|
45
|
+
chromiumProfile: wxtUserConfig?.chromiumProfile,
|
|
46
|
+
chromiumPref: defu(wxtUserConfig?.chromiumPref, DEFAULT_CHROMIUM_PREFS),
|
|
47
|
+
args: ["--unsafely-disable-devtools-self-xss-warnings", ...wxtUserConfig?.chromiumArgs ?? []]
|
|
48
|
+
},
|
|
49
|
+
target: this.config.browser === "firefox" ? "firefox-desktop" : "chromium",
|
|
50
|
+
sourceDir: this.config.outDir,
|
|
51
|
+
noReloadManagerExtension: true,
|
|
52
|
+
noReload: true,
|
|
53
|
+
noInput: true
|
|
54
|
+
};
|
|
55
|
+
const options = { shouldExitProgram: false };
|
|
56
|
+
this.config.logger.debug("web-ext config:", finalConfig);
|
|
57
|
+
this.config.logger.debug("web-ext options:", options);
|
|
58
|
+
this.instance = await this.webExt.cmd.run(finalConfig, options);
|
|
59
|
+
const duration = Date.now() - startTime;
|
|
60
|
+
this.config.logger.success(`Opened browser in ${formatDuration(duration)}`);
|
|
61
|
+
}
|
|
62
|
+
async closeBrowser() {
|
|
63
|
+
await this.instance?.exit();
|
|
64
|
+
}
|
|
65
|
+
logManualReason(reason) {
|
|
66
|
+
this.config.logger.warn(`${reason}. ${this.loadManualMessage()}`);
|
|
67
|
+
}
|
|
68
|
+
loadManualMessage() {
|
|
69
|
+
return `Load "${relative(process.cwd(), this.config.outDir)}" as an unpacked extension manually`;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const WARN_LOG_LEVEL = 40;
|
|
73
|
+
const ERROR_LOG_LEVEL = 50;
|
|
74
|
+
const DEFAULT_CHROMIUM_PREFS = { devtools: { synced_preferences_sync_disabled: {
|
|
75
|
+
skipContentScripts: false,
|
|
76
|
+
"skip-content-scripts": false
|
|
77
|
+
} } };
|
|
78
|
+
//#endregion
|
|
79
|
+
export { WebExtRunner };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
//#region src/
|
|
2
|
-
function
|
|
1
|
+
//#region src/internal/runtime-env-entries.ts
|
|
2
|
+
function getRuntimeEnvEntries(config) {
|
|
3
3
|
return [
|
|
4
4
|
{
|
|
5
5
|
name: "MANIFEST_VERSION",
|
|
@@ -43,7 +43,7 @@ function getGlobals(config) {
|
|
|
43
43
|
}
|
|
44
44
|
];
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function getEntrypointRuntimeEnvEntries(entrypointName) {
|
|
47
47
|
return [{
|
|
48
48
|
name: "ENTRYPOINT",
|
|
49
49
|
value: entrypointName,
|
|
@@ -51,4 +51,4 @@ function getEntrypointGlobals(entrypointName) {
|
|
|
51
51
|
}];
|
|
52
52
|
}
|
|
53
53
|
//#endregion
|
|
54
|
-
export {
|
|
54
|
+
export { getEntrypointRuntimeEnvEntries, getRuntimeEnvEntries };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
//#region src/internal/spinner.ts
|
|
3
|
+
function createSpinner(initialText = "", options = {}) {
|
|
4
|
+
const { color = "cyan" } = options;
|
|
5
|
+
const frames = [
|
|
6
|
+
"⠋",
|
|
7
|
+
"⠙",
|
|
8
|
+
"⠹",
|
|
9
|
+
"⠸",
|
|
10
|
+
"⠼",
|
|
11
|
+
"⠴",
|
|
12
|
+
"⠦",
|
|
13
|
+
"⠧",
|
|
14
|
+
"⠇",
|
|
15
|
+
"⠏"
|
|
16
|
+
];
|
|
17
|
+
const FRAME_INTERVAL = 80;
|
|
18
|
+
let frameIndex = 0;
|
|
19
|
+
let timer = null;
|
|
20
|
+
let text = initialText;
|
|
21
|
+
function render() {
|
|
22
|
+
const frame = frames[frameIndex % frames.length];
|
|
23
|
+
const coloredFrame = color ? styleText(color, frame) : frame;
|
|
24
|
+
process.stdout.write(`\r${coloredFrame} ${text}\x1B[K`);
|
|
25
|
+
}
|
|
26
|
+
const spinner = {
|
|
27
|
+
start(startText) {
|
|
28
|
+
if (startText !== void 0) text = startText;
|
|
29
|
+
if (timer) return spinner;
|
|
30
|
+
process.stdout.write("\x1B[?25l");
|
|
31
|
+
render();
|
|
32
|
+
timer = setInterval(() => {
|
|
33
|
+
frameIndex++;
|
|
34
|
+
render();
|
|
35
|
+
}, FRAME_INTERVAL);
|
|
36
|
+
return spinner;
|
|
37
|
+
},
|
|
38
|
+
update(opts = {}) {
|
|
39
|
+
text = typeof opts === "string" ? opts : opts.text ?? text;
|
|
40
|
+
if (timer) render();
|
|
41
|
+
return spinner;
|
|
42
|
+
},
|
|
43
|
+
clear() {
|
|
44
|
+
if (timer) {
|
|
45
|
+
clearInterval(timer);
|
|
46
|
+
timer = null;
|
|
47
|
+
}
|
|
48
|
+
process.stdout.write("\r\x1B[K");
|
|
49
|
+
process.stdout.write("\x1B[?25h");
|
|
50
|
+
return spinner;
|
|
51
|
+
},
|
|
52
|
+
stop(finalText = "") {
|
|
53
|
+
spinner.clear();
|
|
54
|
+
if (finalText) process.stdout.write(finalText + "\n");
|
|
55
|
+
return spinner;
|
|
56
|
+
},
|
|
57
|
+
success(finalText) {
|
|
58
|
+
const message = finalText ?? text;
|
|
59
|
+
return spinner.stop(`${styleText("green", "✔")} ${message}`);
|
|
60
|
+
},
|
|
61
|
+
error(finalText) {
|
|
62
|
+
const message = finalText ?? text;
|
|
63
|
+
return spinner.stop(`${styleText("red", "✖")} ${message}`);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
return spinner;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { createSpinner };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { wxt } from "
|
|
1
|
+
import { wxt } from "./wxt.mjs";
|
|
2
2
|
import { relative } from "node:path";
|
|
3
3
|
import { styleText } from "node:util";
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/internal/syntax-errors.ts
|
|
5
5
|
function isBabelSyntaxError(error) {
|
|
6
6
|
return error instanceof SyntaxError && error.code === "BABEL_PARSER_SYNTAX_ERROR";
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { normalizePath } from "
|
|
2
|
-
import { wxt } from "
|
|
3
|
-
//#region src/
|
|
1
|
+
import { normalizePath } from "../internal-utils/path-utils.mjs";
|
|
2
|
+
import { wxt } from "./wxt.mjs";
|
|
3
|
+
//#region src/internal/theme-icons.ts
|
|
4
4
|
/**
|
|
5
5
|
* Firefox only.
|
|
6
6
|
*
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { builtinModules } from "
|
|
2
|
-
import { createViteBuilder } from "./builders/vite/index.mjs";
|
|
1
|
+
import { builtinModules } from "./builtin-modules/index.mjs";
|
|
3
2
|
import { createWxtPackageManager } from "./package-managers/index.mjs";
|
|
4
3
|
import { resolveConfig } from "./resolve-config.mjs";
|
|
5
|
-
import {
|
|
4
|
+
import { FlatEntrypointFinder } from "./entrypoint-finders/flat.mjs";
|
|
5
|
+
import { detectBuilder } from "./detect-builder.mjs";
|
|
6
|
+
import { detectRunner } from "./detect-runner.mjs";
|
|
6
7
|
import { relative } from "path";
|
|
7
|
-
|
|
8
|
+
import { createHooks } from "hookable";
|
|
9
|
+
//#region src/internal/wxt.ts
|
|
8
10
|
/**
|
|
9
11
|
* Global variable set once `createWxt` is called once. Since this variable is
|
|
10
12
|
* used everywhere, this global can be used instead of passing the variable as a
|
|
@@ -12,14 +14,27 @@ import { relative } from "path";
|
|
|
12
14
|
*/
|
|
13
15
|
let wxt;
|
|
14
16
|
/**
|
|
15
|
-
* Create and register a global instance of the Wxt interface for use
|
|
16
|
-
* the project.
|
|
17
|
+
* Create and register a global instance of the `Wxt` interface for use
|
|
18
|
+
* throughout the project.
|
|
17
19
|
*/
|
|
18
20
|
async function registerWxt(command, inlineConfig = {}) {
|
|
19
21
|
process.env.NODE_ENV ??= inlineConfig.mode ?? (command === "serve" ? "development" : "production");
|
|
20
22
|
const hooks = createHooks();
|
|
21
23
|
const config = await resolveConfig(inlineConfig, command);
|
|
22
|
-
const [builder,
|
|
24
|
+
const [pm, builder, runner] = await Promise.all([
|
|
25
|
+
createWxtPackageManager(config.root),
|
|
26
|
+
detectBuilder(config, hooks, () => wxt.server),
|
|
27
|
+
detectRunner(config)
|
|
28
|
+
]);
|
|
29
|
+
const entrypointFinder = new FlatEntrypointFinder(config);
|
|
30
|
+
Object.defineProperty(config, "runner", {
|
|
31
|
+
get() {
|
|
32
|
+
return runner;
|
|
33
|
+
},
|
|
34
|
+
set(value) {
|
|
35
|
+
wxt.runner = value;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
23
38
|
wxt = {
|
|
24
39
|
config,
|
|
25
40
|
hooks,
|
|
@@ -39,6 +54,8 @@ async function registerWxt(command, inlineConfig = {}) {
|
|
|
39
54
|
},
|
|
40
55
|
pm,
|
|
41
56
|
builder,
|
|
57
|
+
runner,
|
|
58
|
+
entrypointFinder,
|
|
42
59
|
server: void 0
|
|
43
60
|
};
|
|
44
61
|
await initWxtModules();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/
|
|
1
|
+
//#region src/internal-utils/array-utils.ts
|
|
2
2
|
/** Checks if `predicate` returns truthy for all elements of the array. */
|
|
3
3
|
function every(array, predicate) {
|
|
4
4
|
for (let i = 0; i < array.length; i++) if (!predicate(array[i], i)) return false;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { writeFileIfDifferent } from "./fs.mjs";
|
|
2
|
-
import { mkdir, readFile } from "node:fs/promises";
|
|
1
|
+
import { writeFileIfDifferent } from "./fs-utils.mjs";
|
|
3
2
|
import { dirname, resolve } from "path";
|
|
4
|
-
|
|
3
|
+
import { mkdir, readFile } from "node:fs/promises";
|
|
4
|
+
//#region src/internal-utils/cache-utils.ts
|
|
5
5
|
/**
|
|
6
6
|
* A basic file system cache stored at `<srcDir>/.wxt/cache/<key>`. Just caches
|
|
7
7
|
* a string in a file for the given key.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getEntrypointBundlePath } from "./
|
|
2
|
-
//#region src/
|
|
1
|
+
import { getEntrypointBundlePath } from "./entrypoint-utils.mjs";
|
|
2
|
+
//#region src/internal-utils/content-script-utils.ts
|
|
3
3
|
/**
|
|
4
4
|
* Returns a unique and consistent string hash based on a content scripts
|
|
5
5
|
* options.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Entrypoint } from "
|
|
1
|
+
import { Entrypoint } from "../types.mjs";
|
|
2
2
|
|
|
3
|
-
//#region src/
|
|
3
|
+
//#region src/internal-utils/entrypoint-utils.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Return's the entrypoint's output path relative to the output directory. Used
|
|
6
6
|
* for paths in the manifest and rollup's bundle.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { normalizePath } from "./
|
|
1
|
+
import { normalizePath } from "./path-utils.mjs";
|
|
2
2
|
import path, { extname, relative, resolve } from "node:path";
|
|
3
|
-
//#region src/
|
|
3
|
+
//#region src/internal-utils/entrypoint-utils.ts
|
|
4
4
|
function getEntrypointName(entrypointsDir, inputPath) {
|
|
5
5
|
return path.relative(entrypointsDir, inputPath).split(/[./\\]/, 2)[0];
|
|
6
6
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import dotenv_expand_default from "../inline/dotenv-expand/index.mjs";
|
|
2
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
3
|
import { parseEnv } from "node:util";
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/internal-utils/env-utils.ts
|
|
5
5
|
/** Returns true when running in a CI environment. */
|
|
6
6
|
function isCI() {
|
|
7
7
|
return !!process.env.CI && process.env.CI !== "false";
|
|
@@ -27,7 +27,7 @@ function loadEnv(mode, browser) {
|
|
|
27
27
|
return [];
|
|
28
28
|
}
|
|
29
29
|
}));
|
|
30
|
-
expand({ parsed });
|
|
30
|
+
dotenv_expand_default.expand({ parsed });
|
|
31
31
|
return parsed;
|
|
32
32
|
}
|
|
33
33
|
//#endregion
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { tryImport } from "./module-utils.mjs";
|
|
2
|
+
//#region src/internal-utils/eslint-utils.ts
|
|
3
|
+
async function getEslintVersion() {
|
|
4
|
+
const mod = await tryImport(() => import("eslint"));
|
|
5
|
+
return mod ? mod.ESLint.version?.split(".") ?? [] : [];
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { getEslintVersion };
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { unnormalizePath } from "./paths.mjs";
|
|
2
|
-
import { wxt } from "../wxt.mjs";
|
|
3
1
|
import { access, readFile, writeFile } from "node:fs/promises";
|
|
4
|
-
|
|
5
|
-
//#region src/core/utils/fs.ts
|
|
2
|
+
//#region src/internal-utils/fs-utils.ts
|
|
6
3
|
async function pathExists(path) {
|
|
7
4
|
try {
|
|
8
5
|
await access(path);
|
|
@@ -25,12 +22,10 @@ async function readJson(path) {
|
|
|
25
22
|
async function writeFileIfDifferent(file, newContents) {
|
|
26
23
|
if (await readFile(file, "utf-8").catch(() => void 0) !== newContents) await writeFile(file, newContents);
|
|
27
24
|
}
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
return (
|
|
31
|
-
|
|
32
|
-
expandDirectories: false
|
|
33
|
-
})).map(unnormalizePath);
|
|
25
|
+
function getBytesDisplay(bytes) {
|
|
26
|
+
if (bytes < 1e3) return `${bytes} B`;
|
|
27
|
+
if (bytes < 999995) return `${(bytes / 1e3).toFixed(2)} kB`;
|
|
28
|
+
return `${(bytes / 1e6).toFixed(2)} MB`;
|
|
34
29
|
}
|
|
35
30
|
//#endregion
|
|
36
|
-
export {
|
|
31
|
+
export { getBytesDisplay, pathExists, readJson, writeFileIfDifferent };
|
package/dist/{core/utils/log/printBuildSummary.mjs → internal-utils/log/print-build-summary.mjs}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { wxt } from "../../wxt.mjs";
|
|
2
|
-
import { printFileList } from "./
|
|
1
|
+
import { wxt } from "../../internal/wxt.mjs";
|
|
2
|
+
import { printFileList } from "./print-file-list.mjs";
|
|
3
3
|
import { resolve } from "path";
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/internal-utils/log/print-build-summary.ts
|
|
5
5
|
async function printBuildSummary(log, header, output) {
|
|
6
6
|
const files = [...output.steps.flatMap((step) => step.chunks), ...output.publicAssets].sort((l, r) => {
|
|
7
7
|
const diff = getChunkSortWeight(l.fileName) - getChunkSortWeight(r.fileName);
|
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getBytesDisplay } from "../fs-utils.mjs";
|
|
2
|
+
import { wxt } from "../../internal/wxt.mjs";
|
|
3
|
+
import { printTable } from "./print-table.mjs";
|
|
3
4
|
import { lstat } from "node:fs/promises";
|
|
4
5
|
import path from "node:path";
|
|
5
6
|
import { styleText } from "node:util";
|
|
6
|
-
|
|
7
|
-
//#region src/core/utils/log/printFileList.ts
|
|
7
|
+
//#region src/internal-utils/log/print-file-list.ts
|
|
8
8
|
async function printFileList(log, header, baseDir, files) {
|
|
9
9
|
let totalSize = 0;
|
|
10
10
|
const fileRows = await Promise.all(files.map(async (file, i) => {
|
|
11
|
-
const
|
|
11
|
+
const absoluteFile = path.resolve(baseDir, file);
|
|
12
|
+
const parts = [path.relative(process.cwd(), baseDir) + path.sep, path.relative(baseDir, absoluteFile)];
|
|
12
13
|
const prefix = i === files.length - 1 ? " └─" : " ├─";
|
|
13
14
|
const chunkColor = getChunkColor(file);
|
|
14
15
|
let size = "";
|
|
15
16
|
try {
|
|
16
|
-
const stats = await lstat(
|
|
17
|
+
const stats = await lstat(absoluteFile);
|
|
17
18
|
totalSize += stats.size;
|
|
18
|
-
size =
|
|
19
|
+
size = getBytesDisplay(stats.size);
|
|
19
20
|
} catch (ex) {
|
|
20
21
|
wxt.logger.warn(`Could not get stats of '${file}' error: ${ex}`);
|
|
21
22
|
}
|
|
22
23
|
return [`${styleText("gray", prefix)} ${styleText("dim", parts[0])}${styleText(chunkColor, parts[1])}`, styleText("dim", size)];
|
|
23
24
|
}));
|
|
24
|
-
fileRows.push([`${styleText("cyan", "Σ Total size:")} ${
|
|
25
|
+
fileRows.push([`${styleText("cyan", "Σ Total size:")} ${getBytesDisplay(totalSize)}`]);
|
|
25
26
|
printTable(log, header, fileRows);
|
|
26
27
|
}
|
|
27
28
|
const DEFAULT_COLOR = "blue";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { version } from "
|
|
1
|
+
import { version } from "../../version.mjs";
|
|
2
2
|
import { consola as consola$1 } from "consola";
|
|
3
3
|
import { styleText } from "node:util";
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/internal-utils/log/print-header.ts
|
|
5
5
|
function printHeader() {
|
|
6
6
|
consola$1.log(`\n${styleText("gray", "WXT")} ${styleText(["bold", "gray"], version)}`);
|
|
7
7
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/internal-utils/log/wxt-logger.ts
|
|
2
|
+
const warned = /* @__PURE__ */ new Set();
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a `Logger` with a `warnOnce`. The set of already-warned messages is
|
|
5
|
+
* scoped to this wrapper instance, so it's reset whenever a new wrapper is
|
|
6
|
+
* created, e.g. once per `resolveConfig` call.
|
|
7
|
+
*/
|
|
8
|
+
function createWxtLogger(logger) {
|
|
9
|
+
return {
|
|
10
|
+
get level() {
|
|
11
|
+
return logger.level;
|
|
12
|
+
},
|
|
13
|
+
set level(value) {
|
|
14
|
+
logger.level = value;
|
|
15
|
+
},
|
|
16
|
+
debug: logger.debug,
|
|
17
|
+
log: logger.log.bind(logger),
|
|
18
|
+
info: logger.info.bind(logger),
|
|
19
|
+
warn: logger.warn.bind(logger),
|
|
20
|
+
error: logger.error.bind(logger),
|
|
21
|
+
fatal: logger.fatal.bind(logger),
|
|
22
|
+
success: logger.success.bind(logger),
|
|
23
|
+
warnOnce: (...args) => {
|
|
24
|
+
const key = JSON.stringify(args);
|
|
25
|
+
if (warned.has(key)) return;
|
|
26
|
+
warned.add(key);
|
|
27
|
+
logger.warn(...args);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { createWxtLogger };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/internal-utils/module-utils.ts
|
|
2
|
+
/**
|
|
3
|
+
* Returns the result of the first mapper function that resolves successfully.
|
|
4
|
+
* If an error other than "module-not-found" is thrown, it is re-thrown
|
|
5
|
+
* immediately.
|
|
6
|
+
*
|
|
7
|
+
* @param mappers - An array of functions that dynamically import a module and
|
|
8
|
+
* return a value based on it.
|
|
9
|
+
* @returns The result of the first module that resolves successfully.
|
|
10
|
+
*/
|
|
11
|
+
async function withFirstModule(...mappers) {
|
|
12
|
+
for (const map of mappers) try {
|
|
13
|
+
return await map();
|
|
14
|
+
} catch (err) {
|
|
15
|
+
if (!isModuleNotFound(err)) throw err;
|
|
16
|
+
}
|
|
17
|
+
throw Error("No optional modules found");
|
|
18
|
+
}
|
|
19
|
+
async function tryImport(fn) {
|
|
20
|
+
try {
|
|
21
|
+
return await fn();
|
|
22
|
+
} catch (err) {
|
|
23
|
+
if (isModuleNotFound(err)) return void 0;
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const MODULE_NOT_FOUND_CODE = "ERR_MODULE_NOT_FOUND";
|
|
28
|
+
function isModuleNotFound(err) {
|
|
29
|
+
return err?.code === MODULE_NOT_FOUND_CODE;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { tryImport, withFirstModule };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import normalize_path_default from "../inline/normalize-path/index.mjs";
|
|
1
2
|
import path from "node:path";
|
|
2
|
-
|
|
3
|
-
//#region src/core/utils/paths.ts
|
|
3
|
+
//#region src/internal-utils/path-utils.ts
|
|
4
4
|
/**
|
|
5
5
|
* Converts system paths to normalized bundler path. On Windows, this returns
|
|
6
6
|
* paths with `/` instead of `\`.
|
|
7
7
|
*/
|
|
8
8
|
function normalizePath(path) {
|
|
9
|
-
return
|
|
9
|
+
return normalize_path_default(path);
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Given a normalized path, convert it to the system path style. On Windows,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//#region src/
|
|
1
|
+
import { s } from "../inline/scule/index.mjs";
|
|
2
|
+
//#region src/internal-utils/string-utils.ts
|
|
3
3
|
function kebabCaseAlphanumeric(str) {
|
|
4
4
|
return str.toLowerCase().replace(/[^a-z0-9-\s]/g, "").replace(/\s+/g, "-");
|
|
5
5
|
}
|
|
6
6
|
/** Return a safe variable name for a given string. */
|
|
7
7
|
function safeVarName(str) {
|
|
8
|
-
const name =
|
|
8
|
+
const name = s(kebabCaseAlphanumeric(str));
|
|
9
9
|
if (name.match(/^[a-z]/)) return name;
|
|
10
10
|
return "_" + name;
|
|
11
11
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { styleText } from "node:util";
|
|
1
2
|
import { Browser } from "@wxt-dev/browser";
|
|
2
3
|
|
|
3
|
-
//#region src/
|
|
4
|
+
//#region src/internal-utils/type-utils.d.ts
|
|
4
5
|
type ManifestContentScript = NonNullable<Browser.runtime.Manifest['content_scripts']>[number];
|
|
5
6
|
//#endregion
|
|
6
7
|
export { ManifestContentScript };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Entrypoint, Wxt, WxtModule, WxtModuleOptions, WxtModuleSetup } from "
|
|
1
|
+
import { Entrypoint, Wxt, WxtModule, WxtModuleOptions, WxtModuleSetup } from "../types.mjs";
|
|
2
2
|
import { UnimportOptions } from "unimport";
|
|
3
3
|
import * as vite from "vite";
|
|
4
4
|
|
|
5
|
-
//#region src/modules.d.ts
|
|
5
|
+
//#region src/modules/index.d.ts
|
|
6
6
|
declare function defineWxtModule<TOptions extends WxtModuleOptions>(module: WxtModule<TOptions> | WxtModuleSetup<TOptions>): WxtModule<TOptions>;
|
|
7
7
|
/**
|
|
8
8
|
* Adds a TS/JS file as an entrypoint to the project. This file will be bundled
|
|
@@ -71,14 +71,20 @@ declare function addViteConfig(wxt: Wxt, viteConfig: (env: vite.ConfigEnv) => vi
|
|
|
71
71
|
*
|
|
72
72
|
* @example
|
|
73
73
|
* export default defineWxtModule((wxt) => {
|
|
74
|
-
* addWxtPlugin(
|
|
74
|
+
* addWxtPlugin(
|
|
75
|
+
* wxt,
|
|
76
|
+
* 'wxt-module-analytics/background-plugin',
|
|
77
|
+
* (entrypoint) => entrypoint.type === 'background',
|
|
78
|
+
* );
|
|
75
79
|
* });
|
|
76
80
|
*
|
|
77
81
|
* @param wxt The wxt instance provided by the module's setup function.
|
|
78
82
|
* @param plugin An import from an NPM module, or an absolute file path to the
|
|
79
83
|
* file to load at runtime.
|
|
84
|
+
* @param apply Optional. Return `true` to load the plugin in the given
|
|
85
|
+
* entrypoint. Defaults to loading the plugin in every entrypoint.
|
|
80
86
|
*/
|
|
81
|
-
declare function addWxtPlugin(wxt: Wxt, plugin: string): void;
|
|
87
|
+
declare function addWxtPlugin(wxt: Wxt, plugin: string, apply?: (entrypoint: Entrypoint) => boolean): void;
|
|
82
88
|
/**
|
|
83
89
|
* Add an Unimport preset
|
|
84
90
|
* ([built-in](https://github.com/unjs/unimport?tab=readme-ov-file#built-in-presets),
|