wxt 0.21.4 → 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 +6 -6
- 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/{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 +136 -138
- 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} +4 -5
- 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 +17 -6
- 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 +8 -73
- 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 +1 -1
- package/dist/{core/utils → internal}/manifest.mjs +9 -9
- package/dist/{core → internal}/package-managers/bun.mjs +1 -1
- 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 +1 -1
- package/dist/{core → internal}/package-managers/pnpm.mjs +1 -1
- package/dist/{core → internal}/package-managers/yarn.mjs +1 -1
- 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 +14 -32
- 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/{core/utils → internal}/spinner.mjs +1 -1
- 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} +2 -12
- 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} +7 -6
- 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/{core/utils/log/wxtLogger.mjs → internal-utils/log/wxt-logger.mjs} +1 -1
- 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} +2 -2
- package/dist/{core/utils/strings.mjs → internal-utils/string-utils.mjs} +2 -2
- 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 +72 -19
- package/dist/utils/content-script-context.d.mts +1 -1
- package/dist/utils/content-script-ui/iframe.d.mts +5 -0
- package/dist/utils/content-script-ui/integrated.d.mts +5 -0
- package/dist/utils/content-script-ui/shadow-root.d.mts +5 -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 +7 -7
- 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/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 -6
- /package/dist/{core/utils → internal}/environments/index.mjs +0 -0
- /package/dist/{core/utils → internal}/virtual-modules.mjs +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { readJson } from "../internal-utils/fs-utils.mjs";
|
|
2
|
+
import { wxt } from "./wxt.mjs";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/internal/package.ts
|
|
5
5
|
/**
|
|
6
6
|
* Read the project's package.json.
|
|
7
7
|
*
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { wxt } from "
|
|
1
|
+
import { wxt } from "./wxt.mjs";
|
|
2
|
+
import { createSpinner } from "./spinner.mjs";
|
|
3
|
+
import { generateWxtDir } from "./generate-wxt-dir.mjs";
|
|
4
|
+
import { generateManifest, writeManifest } from "./manifest.mjs";
|
|
2
5
|
import { buildEntrypoints } from "./build-entrypoints.mjs";
|
|
3
|
-
|
|
4
|
-
import { generateWxtDir } from "../../generate-wxt-dir.mjs";
|
|
5
|
-
import { generateManifest, writeManifest } from "../manifest.mjs";
|
|
6
|
-
//#region src/core/utils/building/rebuild.ts
|
|
6
|
+
//#region src/internal/rebuild.ts
|
|
7
7
|
/**
|
|
8
8
|
* Given a configuration, list of entrypoints, and an existing, partial output,
|
|
9
9
|
* build the entrypoints and merge the new output with the existing output.
|
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import "
|
|
4
|
-
import { createFsCache } from "
|
|
5
|
-
import { getEslintVersion } from "
|
|
6
|
-
import { safeStringToNumber } from "
|
|
7
|
-
import { loadEnv } from "
|
|
1
|
+
import { normalizePath } from "../internal-utils/path-utils.mjs";
|
|
2
|
+
import { builtinModules } from "./builtin-modules/index.mjs";
|
|
3
|
+
import { pathExists } from "../internal-utils/fs-utils.mjs";
|
|
4
|
+
import { createFsCache } from "../internal-utils/cache-utils.mjs";
|
|
5
|
+
import { getEslintVersion } from "../internal-utils/eslint-utils.mjs";
|
|
6
|
+
import { safeStringToNumber } from "../internal-utils/number-utils.mjs";
|
|
7
|
+
import { loadEnv } from "../internal-utils/env-utils.mjs";
|
|
8
8
|
import { v } from "../inline/get-port-please/index.mjs";
|
|
9
|
-
import {
|
|
10
|
-
import { d } from "../inline/is-wsl/index.mjs";
|
|
11
|
-
import { createWslRunner } from "./runners/wsl.mjs";
|
|
12
|
-
import { createManualRunner } from "./runners/manual.mjs";
|
|
13
|
-
import { createWxtLogger } from "./utils/log/wxtLogger.mjs";
|
|
14
|
-
import { pathExists } from "./utils/fs.mjs";
|
|
15
|
-
import { glob } from "tinyglobby";
|
|
9
|
+
import { createWxtLogger } from "../internal-utils/log/wxt-logger.mjs";
|
|
16
10
|
import path from "node:path";
|
|
11
|
+
import { glob } from "tinyglobby";
|
|
17
12
|
import { loadConfig } from "c12";
|
|
18
13
|
import consola, { LogLevels } from "consola";
|
|
19
14
|
import defu from "defu";
|
|
20
|
-
import { fileURLToPath
|
|
21
|
-
//#region src/
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
//#region src/internal/resolve-config.ts
|
|
22
17
|
/**
|
|
23
18
|
* Given an inline config, discover the config file if necessary, merge the
|
|
24
19
|
* results, resolve any relative paths, and apply any defaults.
|
|
@@ -142,7 +137,7 @@ async function resolveConfig(inlineConfig, command) {
|
|
|
142
137
|
wxtModuleDir,
|
|
143
138
|
root,
|
|
144
139
|
webExt,
|
|
145
|
-
runner:
|
|
140
|
+
runner: void 0,
|
|
146
141
|
srcDir,
|
|
147
142
|
typesDir,
|
|
148
143
|
wxtDir,
|
|
@@ -363,7 +358,7 @@ async function getUnimportEslintOptions(logger, wxtDir, options) {
|
|
|
363
358
|
}
|
|
364
359
|
/** Returns the path to `node_modules/wxt`. */
|
|
365
360
|
function resolveWxtModuleDir() {
|
|
366
|
-
const url = import.meta.resolve("wxt"
|
|
361
|
+
const url = import.meta.resolve("wxt");
|
|
367
362
|
return path.resolve(fileURLToPath(url), "../..");
|
|
368
363
|
}
|
|
369
364
|
async function isDirMissing(dir) {
|
|
@@ -388,9 +383,8 @@ async function mergeBuilderConfig(logger, inlineConfig, userConfig) {
|
|
|
388
383
|
throw Error("Builder not found. Make sure vite is installed.");
|
|
389
384
|
}
|
|
390
385
|
async function resolveWxtUserModules(root, modulesDir, modules = []) {
|
|
391
|
-
const importer = pathToFileURL(path.join(root, "index.js")).href;
|
|
392
386
|
const npmModules = await Promise.all(modules.map(async (moduleId) => {
|
|
393
|
-
const mod = await import(import.meta.resolve(moduleId
|
|
387
|
+
const mod = await import(import.meta.resolve(moduleId));
|
|
394
388
|
if (mod.default == null) throw Error("Module missing default export: " + moduleId);
|
|
395
389
|
return {
|
|
396
390
|
...mod.default,
|
|
@@ -424,17 +418,5 @@ async function resolveWxtUserModules(root, modulesDir, modules = []) {
|
|
|
424
418
|
}));
|
|
425
419
|
return [...npmModules, ...localModules];
|
|
426
420
|
}
|
|
427
|
-
async function resolveRunner(browser, logger, webExt) {
|
|
428
|
-
if (browser === "safari") return createSafariRunner();
|
|
429
|
-
if (d) return createWslRunner();
|
|
430
|
-
try {
|
|
431
|
-
const { createWebExtRunner } = await import("./runners/web-ext.mjs");
|
|
432
|
-
return webExt.disabled ? createManualRunner() : createWebExtRunner();
|
|
433
|
-
} catch (err) {
|
|
434
|
-
if (err?.code !== "ERR_MODULE_NOT_FOUND") throw err;
|
|
435
|
-
logger.debug("Error loading the web-ext runner", err);
|
|
436
|
-
}
|
|
437
|
-
return createManualRunner();
|
|
438
|
-
}
|
|
439
421
|
//#endregion
|
|
440
422
|
export { resolveConfig };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { relative } from "node:path";
|
|
2
|
+
//#region src/internal/runners/manual.ts
|
|
3
|
+
/**
|
|
4
|
+
* Base runner that just tells developers to load the extension into their
|
|
5
|
+
* browser manually.
|
|
6
|
+
*
|
|
7
|
+
* You can extend this class and call any `super` method when your runner can't
|
|
8
|
+
* open the browser.
|
|
9
|
+
*/
|
|
10
|
+
var ManualRunner = class {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
}
|
|
14
|
+
canOpen() {
|
|
15
|
+
return Promise.resolve(false);
|
|
16
|
+
}
|
|
17
|
+
async openBrowser() {
|
|
18
|
+
this.config.logger.info(`Load "${relative(process.cwd(), this.config.outDir)}" as an unpacked extension manually`);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ManualRunner };
|
|
@@ -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 };
|
|
@@ -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,17 +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
|
-
async function getPublicFiles() {
|
|
29
|
-
if (!await pathExists(wxt.config.publicDir)) return [];
|
|
30
|
-
return (await glob("**/*", {
|
|
31
|
-
cwd: wxt.config.publicDir,
|
|
32
|
-
expandDirectories: false
|
|
33
|
-
})).map(unnormalizePath);
|
|
34
|
-
}
|
|
35
25
|
function getBytesDisplay(bytes) {
|
|
36
26
|
if (bytes < 1e3) return `${bytes} B`;
|
|
37
27
|
if (bytes < 999995) return `${(bytes / 1e3).toFixed(2)} kB`;
|
|
38
28
|
return `${(bytes / 1e6).toFixed(2)} MB`;
|
|
39
29
|
}
|
|
40
30
|
//#endregion
|
|
41
|
-
export { getBytesDisplay,
|
|
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,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { printTable } from "./
|
|
1
|
+
import { getBytesDisplay } from "../fs-utils.mjs";
|
|
2
|
+
import { wxt } from "../../internal/wxt.mjs";
|
|
3
|
+
import { printTable } from "./print-table.mjs";
|
|
4
4
|
import { lstat } from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { styleText } from "node:util";
|
|
7
|
-
//#region src/
|
|
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
19
|
size = getBytesDisplay(stats.size);
|
|
19
20
|
} catch (ex) {
|
|
@@ -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/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,6 +1,6 @@
|
|
|
1
|
-
import normalize_path_default from "
|
|
1
|
+
import normalize_path_default from "../inline/normalize-path/index.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
//#region src/
|
|
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 `\`.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { s } from "
|
|
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
|
}
|
|
@@ -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 };
|