wxt 0.20.18 → 0.20.19
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 +6 -6
- 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 +15 -17
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* A alias around `publish-extension` that is always installed on the path
|
|
4
|
-
* `publish-browser-extension` as a direct dependency
|
|
5
|
-
* sub-dependency binaries to
|
|
3
|
+
* A alias around `publish-extension` that is always installed on the path
|
|
4
|
+
* without having to install `publish-browser-extension` as a direct dependency
|
|
5
|
+
* (like for PNPM, which doesn't link sub-dependency binaries to
|
|
6
|
+
* "node_modules/.bin")
|
|
6
7
|
*/
|
|
7
8
|
await import('publish-browser-extension/cli');
|
package/dist/browser.d.mts
CHANGED
|
@@ -3,12 +3,16 @@ import { Browser, browser as browser$1 } from "@wxt-dev/browser";
|
|
|
3
3
|
|
|
4
4
|
//#region src/browser.d.ts
|
|
5
5
|
/**
|
|
6
|
-
* This interface is empty because it is generated per-project when running `wxt
|
|
6
|
+
* This interface is empty because it is generated per-project when running `wxt
|
|
7
|
+
* prepare`. See:
|
|
8
|
+
*
|
|
7
9
|
* - `.wxt/types/paths.d.ts`
|
|
8
10
|
*/
|
|
9
11
|
interface WxtRuntime {}
|
|
10
12
|
/**
|
|
11
|
-
* This interface is empty because it is generated per-project when running `wxt
|
|
13
|
+
* This interface is empty because it is generated per-project when running `wxt
|
|
14
|
+
* prepare`. See:
|
|
15
|
+
*
|
|
12
16
|
* - `.wxt/types/i18n.d.ts`
|
|
13
17
|
*/
|
|
14
18
|
interface WxtI18n {}
|
|
@@ -20,10 +24,7 @@ type ScriptInjection<Args extends any[], Result> = Browser.scripting.ScriptInjec
|
|
|
20
24
|
type InjectionResult<Result> = Array<Browser.scripting.InjectionResult<Awaited<Result>>>;
|
|
21
25
|
interface WxtScripting {
|
|
22
26
|
executeScript: {
|
|
23
|
-
/**
|
|
24
|
-
* @see {@link Browser.scripting.executeScript}
|
|
25
|
-
*/
|
|
26
|
-
<Args extends any[], Result>(injection: ScriptInjection<Args, Result>): Promise<InjectionResult<Result>>;
|
|
27
|
+
/** @see {@link Browser.scripting.executeScript} */<Args extends any[], Result>(injection: ScriptInjection<Args, Result>): Promise<InjectionResult<Result>>;
|
|
27
28
|
<Args extends any[], Result>(injection: ScriptInjection<Args, Result>, callback: (results: InjectionResult<Result>) => void): void;
|
|
28
29
|
};
|
|
29
30
|
}
|
package/dist/browser.mjs
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { browser as browser$1 } from "@wxt-dev/browser";
|
|
2
|
-
|
|
3
2
|
//#region src/browser.ts
|
|
4
3
|
/**
|
|
5
|
-
* Contains the `browser` export which you should use to access the extension
|
|
4
|
+
* Contains the `browser` export which you should use to access the extension
|
|
5
|
+
* APIs in your project:
|
|
6
|
+
*
|
|
6
7
|
* ```ts
|
|
7
8
|
* import { browser } from 'wxt/browser';
|
|
8
9
|
*
|
|
9
10
|
* browser.runtime.onInstalled.addListener(() => {
|
|
10
11
|
* // ...
|
|
11
|
-
* })
|
|
12
|
+
* });
|
|
12
13
|
* ```
|
|
14
|
+
*
|
|
13
15
|
* @module wxt/browser
|
|
14
16
|
*/
|
|
15
17
|
const browser = browser$1;
|
|
16
|
-
|
|
17
18
|
//#endregion
|
|
18
|
-
export { browser };
|
|
19
|
+
export { browser };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { addViteConfig, defineWxtModule } from "../modules.mjs";
|
|
2
2
|
import { createUnimport, toExports } from "unimport";
|
|
3
3
|
import UnimportPlugin from "unimport/unplugin";
|
|
4
|
-
|
|
5
4
|
//#region src/builtin-modules/unimport.ts
|
|
6
5
|
var unimport_default = defineWxtModule({
|
|
7
6
|
name: "wxt:built-in:unimport",
|
|
@@ -86,6 +85,5 @@ export default {
|
|
|
86
85
|
`
|
|
87
86
|
};
|
|
88
87
|
}
|
|
89
|
-
|
|
90
88
|
//#endregion
|
|
91
|
-
export { unimport_default as default };
|
|
89
|
+
export { unimport_default as default };
|
package/dist/cli/cli-utils.mjs
CHANGED
|
@@ -6,10 +6,10 @@ import "../core/utils/log/index.mjs";
|
|
|
6
6
|
import { ValidationError } from "../core/utils/validation.mjs";
|
|
7
7
|
import consola, { LogLevels } from "consola";
|
|
8
8
|
import spawn from "nano-spawn";
|
|
9
|
-
|
|
10
9
|
//#region src/cli/cli-utils.ts
|
|
11
10
|
/**
|
|
12
|
-
* Wrap an action handler to add a timer, error handling, and maybe enable debug
|
|
11
|
+
* Wrap an action handler to add a timer, error handling, and maybe enable debug
|
|
12
|
+
* mode.
|
|
13
13
|
*/
|
|
14
14
|
function wrapAction(cb, options) {
|
|
15
15
|
return async (...args) => {
|
|
@@ -28,8 +28,8 @@ function wrapAction(cb, options) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* Array flags, when not passed, are either `undefined` or `[undefined]`. This
|
|
32
|
-
* the
|
|
31
|
+
* Array flags, when not passed, are either `undefined` or `[undefined]`. This
|
|
32
|
+
* function filters out the
|
|
33
33
|
*/
|
|
34
34
|
function getArrayFromFlags(flags, name) {
|
|
35
35
|
const result = filterTruthy(toArray(flags[name]));
|
|
@@ -57,6 +57,5 @@ function createAliasedCommand(base, name, alias, bin, docsUrl) {
|
|
|
57
57
|
function isAliasedCommand(command) {
|
|
58
58
|
return !!command && aliasCommandNames.has(command.name);
|
|
59
59
|
}
|
|
60
|
-
|
|
61
60
|
//#endregion
|
|
62
|
-
export { createAliasedCommand, getArrayFromFlags, isAliasedCommand, wrapAction };
|
|
61
|
+
export { createAliasedCommand, getArrayFromFlags, isAliasedCommand, wrapAction };
|
package/dist/cli/commands.mjs
CHANGED
|
@@ -7,7 +7,6 @@ import { zip } from "../core/zip.mjs";
|
|
|
7
7
|
import "../core/index.mjs";
|
|
8
8
|
import { createAliasedCommand, getArrayFromFlags, wrapAction } from "./cli-utils.mjs";
|
|
9
9
|
import cac from "cac";
|
|
10
|
-
|
|
11
10
|
//#region src/cli/commands.ts
|
|
12
11
|
const cli = cac("wxt");
|
|
13
12
|
cli.option("--debug", "enable debug mode");
|
|
@@ -76,6 +75,5 @@ cli.command("init [directory]", "initialize a new project").option("-t, --templa
|
|
|
76
75
|
});
|
|
77
76
|
}, { disableFinishedLog: true }));
|
|
78
77
|
createAliasedCommand(cli, "submit", "publish-extension", "wxt-publish-extension", "https://www.npmjs.com/publish-browser-extension");
|
|
79
|
-
|
|
80
78
|
//#endregion
|
|
81
|
-
export { cli as default };
|
|
79
|
+
export { cli as default };
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { version } from "../version.mjs";
|
|
2
2
|
import { isAliasedCommand } from "./cli-utils.mjs";
|
|
3
3
|
import cli from "./commands.mjs";
|
|
4
|
-
|
|
5
4
|
//#region src/cli/index.ts
|
|
6
5
|
cli.parse(process.argv, { run: false });
|
|
7
6
|
if (!isAliasedCommand(cli.matchedCommand)) {
|
|
@@ -10,6 +9,5 @@ if (!isAliasedCommand(cli.matchedCommand)) {
|
|
|
10
9
|
cli.parse(process.argv, { run: false });
|
|
11
10
|
}
|
|
12
11
|
await cli.runMatchedCommand();
|
|
13
|
-
|
|
14
12
|
//#endregion
|
|
15
|
-
export {
|
|
13
|
+
export {};
|
package/dist/core/build.d.mts
CHANGED
|
@@ -2,17 +2,18 @@ import { BuildOutput, InlineConfig } from "../types.mjs";
|
|
|
2
2
|
|
|
3
3
|
//#region src/core/build.d.ts
|
|
4
4
|
/**
|
|
5
|
-
* Bundles the extension for production. Returns a promise of the build result.
|
|
6
|
-
* the root directory, and merges that
|
|
5
|
+
* Bundles the extension for production. Returns a promise of the build result.
|
|
6
|
+
* Discovers the `wxt.config.ts` file in the root directory, and merges that
|
|
7
|
+
* config with what is passed in.
|
|
7
8
|
*
|
|
8
9
|
* @example
|
|
9
|
-
*
|
|
10
|
-
*
|
|
10
|
+
* // Use config from `wxt.config.ts`
|
|
11
|
+
* const res = await build();
|
|
11
12
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* // or override config `from wxt.config.ts`
|
|
14
|
+
* const res = await build({
|
|
15
|
+
* // Override config...
|
|
16
|
+
* });
|
|
16
17
|
*/
|
|
17
18
|
declare function build(config?: InlineConfig): Promise<BuildOutput>;
|
|
18
19
|
//#endregion
|
package/dist/core/build.mjs
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { registerWxt } from "./wxt.mjs";
|
|
2
2
|
import { internalBuild } from "./utils/building/internal-build.mjs";
|
|
3
3
|
import "./utils/building/index.mjs";
|
|
4
|
-
|
|
5
4
|
//#region src/core/build.ts
|
|
6
5
|
/**
|
|
7
|
-
* Bundles the extension for production. Returns a promise of the build result.
|
|
8
|
-
* the root directory, and merges that
|
|
6
|
+
* Bundles the extension for production. Returns a promise of the build result.
|
|
7
|
+
* Discovers the `wxt.config.ts` file in the root directory, and merges that
|
|
8
|
+
* config with what is passed in.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* // Use config from `wxt.config.ts`
|
|
12
|
+
* const res = await build();
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* // or override config `from wxt.config.ts`
|
|
15
|
+
* const res = await build({
|
|
16
|
+
* // Override config...
|
|
17
|
+
* });
|
|
18
18
|
*/
|
|
19
19
|
async function build(config) {
|
|
20
20
|
await registerWxt("build", config);
|
|
21
21
|
return await internalBuild();
|
|
22
22
|
}
|
|
23
|
-
|
|
24
23
|
//#endregion
|
|
25
|
-
export { build };
|
|
24
|
+
export { build };
|
|
@@ -22,17 +22,17 @@ import { toArray } from "../../utils/arrays.mjs";
|
|
|
22
22
|
import { safeVarName } from "../../utils/strings.mjs";
|
|
23
23
|
import { createExtensionEnvironment } from "../../utils/environments/extension-environment.mjs";
|
|
24
24
|
import "../../utils/environments/index.mjs";
|
|
25
|
-
import
|
|
25
|
+
import { mkdir, readdir, rename, rmdir, stat } from "node:fs/promises";
|
|
26
26
|
import { dirname, extname, join, relative } from "node:path";
|
|
27
27
|
import { ViteNodeServer } from "vite-node/server";
|
|
28
28
|
import { ViteNodeRunner } from "vite-node/client";
|
|
29
29
|
import { installSourcemapsSupport } from "vite-node/source-map";
|
|
30
|
-
|
|
31
30
|
//#region src/core/builders/vite/index.ts
|
|
32
31
|
async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
|
|
33
32
|
const vite = await import("vite");
|
|
34
33
|
/**
|
|
35
|
-
* Returns the base vite config shared by all builds based on the inline and
|
|
34
|
+
* Returns the base vite config shared by all builds based on the inline and
|
|
35
|
+
* user config.
|
|
36
36
|
*/
|
|
37
37
|
const getBaseConfig = async (baseConfigOptions) => {
|
|
38
38
|
const config = await wxtConfig.vite(wxtConfig.env);
|
|
@@ -59,7 +59,8 @@ async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
|
|
|
59
59
|
return config;
|
|
60
60
|
};
|
|
61
61
|
/**
|
|
62
|
-
* Return the basic config for building an entrypoint in [lib
|
|
62
|
+
* Return the basic config for building an entrypoint in [lib
|
|
63
|
+
* mode](https://vitejs.dev/guide/build.html#library-mode).
|
|
63
64
|
*/
|
|
64
65
|
const getLibModeConfig = (entrypoint) => {
|
|
65
66
|
const entry = getRollupEntry(entrypoint);
|
|
@@ -94,7 +95,8 @@ async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
|
|
|
94
95
|
};
|
|
95
96
|
};
|
|
96
97
|
/**
|
|
97
|
-
* Return the basic config for building multiple entrypoints in [multi-page
|
|
98
|
+
* Return the basic config for building multiple entrypoints in [multi-page
|
|
99
|
+
* mode](https://vitejs.dev/guide/build.html#multi-page-app).
|
|
98
100
|
*/
|
|
99
101
|
const getMultiPageConfig = (entrypoints) => {
|
|
100
102
|
const htmlEntrypoints = new Set(entrypoints.filter(isHtmlEntrypoint).map((e) => e.name));
|
|
@@ -118,7 +120,8 @@ async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
|
|
|
118
120
|
};
|
|
119
121
|
};
|
|
120
122
|
/**
|
|
121
|
-
* Return the basic config for building a single CSS entrypoint in [multi-page
|
|
123
|
+
* Return the basic config for building a single CSS entrypoint in [multi-page
|
|
124
|
+
* mode](https://vitejs.dev/guide/build.html#multi-page-app).
|
|
122
125
|
*/
|
|
123
126
|
const getCssConfig = (entrypoint) => {
|
|
124
127
|
return {
|
|
@@ -242,8 +245,8 @@ function getBuildOutputChunks(result) {
|
|
|
242
245
|
return result.output;
|
|
243
246
|
}
|
|
244
247
|
/**
|
|
245
|
-
* Returns the input module ID (virtual or real file) for an entrypoint. The
|
|
246
|
-
* be passed as an input to rollup.
|
|
248
|
+
* Returns the input module ID (virtual or real file) for an entrypoint. The
|
|
249
|
+
* returned string should be passed as an input to rollup.
|
|
247
250
|
*/
|
|
248
251
|
function getRollupEntry(entrypoint) {
|
|
249
252
|
let virtualEntrypointType;
|
|
@@ -260,15 +263,17 @@ function getRollupEntry(entrypoint) {
|
|
|
260
263
|
return entrypoint.inputPath;
|
|
261
264
|
}
|
|
262
265
|
/**
|
|
263
|
-
* Ensures the HTML files output by a multipage build are in the correct
|
|
264
|
-
* things:
|
|
266
|
+
* Ensures the HTML files output by a multipage build are in the correct
|
|
267
|
+
* location. This does two things:
|
|
265
268
|
*
|
|
266
|
-
* 1. Moves the HTML files to their final location at
|
|
267
|
-
*
|
|
269
|
+
* 1. Moves the HTML files to their final location at
|
|
270
|
+
* `<outDir>/<entrypoint.name>.html`.
|
|
271
|
+
* 2. Updates the bundle so it summarizes the files correctly in the returned build
|
|
272
|
+
* output.
|
|
268
273
|
*
|
|
269
|
-
* Assets (JS and CSS) are output to the `<outDir>/assets` directory, and don't
|
|
270
|
-
* HTML files access them via absolute URLs, so we don't
|
|
271
|
-
* files either.
|
|
274
|
+
* Assets (JS and CSS) are output to the `<outDir>/assets` directory, and don't
|
|
275
|
+
* need to be modified. HTML files access them via absolute URLs, so we don't
|
|
276
|
+
* need to update any import paths in the HTML files either.
|
|
272
277
|
*/
|
|
273
278
|
async function moveHtmlFiles(config, group, chunks) {
|
|
274
279
|
if (!Array.isArray(group)) return chunks;
|
|
@@ -284,8 +289,8 @@ async function moveHtmlFiles(config, group, chunks) {
|
|
|
284
289
|
const newBundlePath = getEntrypointBundlePath(entry, config.outDir, extname(chunk.fileName));
|
|
285
290
|
const oldAbsPath = join(config.outDir, oldBundlePath);
|
|
286
291
|
const newAbsPath = join(config.outDir, newBundlePath);
|
|
287
|
-
await
|
|
288
|
-
await
|
|
292
|
+
await mkdir(dirname(newAbsPath), { recursive: true });
|
|
293
|
+
await rename(oldAbsPath, newAbsPath);
|
|
289
294
|
return {
|
|
290
295
|
...chunk,
|
|
291
296
|
fileName: newBundlePath
|
|
@@ -294,19 +299,16 @@ async function moveHtmlFiles(config, group, chunks) {
|
|
|
294
299
|
await removeEmptyDirs(config.outDir);
|
|
295
300
|
return movedChunks;
|
|
296
301
|
}
|
|
297
|
-
/**
|
|
298
|
-
* Recursively remove all directories that are empty/
|
|
299
|
-
*/
|
|
302
|
+
/** Recursively remove all directories that are empty/ */
|
|
300
303
|
async function removeEmptyDirs(dir) {
|
|
301
|
-
const files = await
|
|
304
|
+
const files = await readdir(dir);
|
|
302
305
|
for (const file of files) {
|
|
303
306
|
const filePath = join(dir, file);
|
|
304
|
-
if ((await
|
|
307
|
+
if ((await stat(filePath)).isDirectory()) await removeEmptyDirs(filePath);
|
|
305
308
|
}
|
|
306
309
|
try {
|
|
307
|
-
await
|
|
310
|
+
await rmdir(dir);
|
|
308
311
|
} catch {}
|
|
309
312
|
}
|
|
310
|
-
|
|
311
313
|
//#endregion
|
|
312
|
-
export { createViteBuilder };
|
|
314
|
+
export { createViteBuilder };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { visualizer } from "@aklinker1/rollup-plugin-visualizer";
|
|
3
|
-
|
|
4
3
|
//#region src/core/builders/vite/plugins/bundleAnalysis.ts
|
|
5
4
|
let increment = 0;
|
|
6
5
|
function bundleAnalysis(config) {
|
|
@@ -9,6 +8,5 @@ function bundleAnalysis(config) {
|
|
|
9
8
|
filename: path.resolve(config.analysis.outputDir, `${config.analysis.outputName}-${increment++}.json`)
|
|
10
9
|
});
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
//#endregion
|
|
14
|
-
export { bundleAnalysis };
|
|
12
|
+
export { bundleAnalysis };
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { getEntrypointBundlePath } from "../../../utils/entrypoints.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/core/builders/vite/plugins/cssEntrypoints.ts
|
|
4
3
|
/**
|
|
5
|
-
* Rename CSS entrypoint outputs to ensure a JS file is not generated, and that
|
|
6
|
-
* placed in the correct place.
|
|
4
|
+
* Rename CSS entrypoint outputs to ensure a JS file is not generated, and that
|
|
5
|
+
* the CSS file is placed in the correct place.
|
|
7
6
|
*
|
|
8
7
|
* It:
|
|
8
|
+
*
|
|
9
9
|
* 1. Renames CSS files to their final paths
|
|
10
10
|
* 2. Removes the JS file that get's output by lib mode
|
|
11
11
|
*
|
|
12
|
-
* THIS PLUGIN SHOULD ONLY BE APPLIED TO CSS LIB MODE BUILDS. It should not be
|
|
12
|
+
* THIS PLUGIN SHOULD ONLY BE APPLIED TO CSS LIB MODE BUILDS. It should not be
|
|
13
|
+
* added to every build.
|
|
13
14
|
*/
|
|
14
15
|
function cssEntrypoints(entrypoint, config) {
|
|
15
16
|
return {
|
|
@@ -24,6 +25,5 @@ function cssEntrypoints(entrypoint, config) {
|
|
|
24
25
|
}
|
|
25
26
|
};
|
|
26
27
|
}
|
|
27
|
-
|
|
28
28
|
//#endregion
|
|
29
|
-
export { cssEntrypoints };
|
|
29
|
+
export { cssEntrypoints };
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Overrides definitions for `import.meta.*`
|
|
4
4
|
*
|
|
5
|
-
* - `import.meta.url`: Without this, background service workers crash trying to
|
|
6
|
-
* `document.location`, see https://github.com/wxt-dev/wxt/issues/392
|
|
5
|
+
* - `import.meta.url`: Without this, background service workers crash trying to
|
|
6
|
+
* access `document.location`, see https://github.com/wxt-dev/wxt/issues/392
|
|
7
7
|
*/
|
|
8
8
|
function defineImportMeta() {
|
|
9
9
|
return {
|
|
@@ -13,6 +13,5 @@ function defineImportMeta() {
|
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
|
|
17
16
|
//#endregion
|
|
18
|
-
export { defineImportMeta };
|
|
17
|
+
export { defineImportMeta };
|
|
@@ -4,11 +4,11 @@ import { getEntrypointName } from "../../../utils/entrypoints.mjs";
|
|
|
4
4
|
import { dirname, relative, resolve } from "node:path";
|
|
5
5
|
import { parseHTML } from "linkedom";
|
|
6
6
|
import { hash } from "ohash";
|
|
7
|
-
|
|
8
7
|
//#region src/core/builders/vite/plugins/devHtmlPrerender.ts
|
|
9
8
|
const inlineScriptContents = {};
|
|
10
9
|
/**
|
|
11
|
-
* Pre-renders the HTML entrypoints when building the extension to connect to
|
|
10
|
+
* Pre-renders the HTML entrypoints when building the extension to connect to
|
|
11
|
+
* the dev server.
|
|
12
12
|
*/
|
|
13
13
|
function devHtmlPrerender(config, server) {
|
|
14
14
|
const htmlReloadId = "@wxt/reload-html";
|
|
@@ -21,21 +21,24 @@ function devHtmlPrerender(config, server) {
|
|
|
21
21
|
config() {
|
|
22
22
|
return { resolve: { alias: { [htmlReloadId]: resolvedHtmlReloadId } } };
|
|
23
23
|
},
|
|
24
|
-
transform
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
transform: {
|
|
25
|
+
filter: { id: /\.html$/ },
|
|
26
|
+
handler(code, id) {
|
|
27
|
+
if (config.command !== "serve" || server == null) return;
|
|
28
|
+
const { document } = parseHTML(code);
|
|
29
|
+
const _pointToDevServer = (querySelector, attr) => pointToDevServer(config, server, id, document, querySelector, attr);
|
|
30
|
+
_pointToDevServer("script[type=module]", "src");
|
|
31
|
+
_pointToDevServer("link[rel=stylesheet]", "href");
|
|
32
|
+
const reloader = document.createElement("script");
|
|
33
|
+
reloader.src = htmlReloadId;
|
|
34
|
+
reloader.type = "module";
|
|
35
|
+
document.head.appendChild(reloader);
|
|
36
|
+
const newHtml = document.toString();
|
|
37
|
+
config.logger.debug("transform " + id);
|
|
38
|
+
config.logger.debug("Old HTML:\n" + code);
|
|
39
|
+
config.logger.debug("New HTML:\n" + newHtml);
|
|
40
|
+
return newHtml;
|
|
41
|
+
}
|
|
39
42
|
},
|
|
40
43
|
async transformIndexHtml(html, ctx) {
|
|
41
44
|
if (config.command !== "serve" || server == null) return;
|
|
@@ -63,13 +66,19 @@ function devHtmlPrerender(config, server) {
|
|
|
63
66
|
}, {
|
|
64
67
|
name: "wxt:virtualize-inline-scripts",
|
|
65
68
|
apply: "serve",
|
|
66
|
-
resolveId
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
resolveId: {
|
|
70
|
+
filter: { id: [new RegExp(`^${virtualInlineScript}`), /* @__PURE__ */ new RegExp("^/chunks/")] },
|
|
71
|
+
handler(id) {
|
|
72
|
+
if (id.startsWith("/chunks/")) return "\0noop";
|
|
73
|
+
return `\0${id}`;
|
|
74
|
+
}
|
|
69
75
|
},
|
|
70
|
-
load
|
|
71
|
-
|
|
72
|
-
|
|
76
|
+
load: {
|
|
77
|
+
filter: { id: [new RegExp(`^${resolvedVirtualInlineScript}`), /* @__PURE__ */ new RegExp("^\0noop")] },
|
|
78
|
+
handler(id) {
|
|
79
|
+
if (id === "\0noop") return "";
|
|
80
|
+
return inlineScriptContents[id.substring(id.indexOf("?") + 1)];
|
|
81
|
+
}
|
|
73
82
|
}
|
|
74
83
|
}];
|
|
75
84
|
}
|
|
@@ -108,6 +117,5 @@ function isUrl(str) {
|
|
|
108
117
|
return false;
|
|
109
118
|
}
|
|
110
119
|
}
|
|
111
|
-
|
|
112
120
|
//#endregion
|
|
113
|
-
export { devHtmlPrerender, pointToDevServer };
|
|
121
|
+
export { devHtmlPrerender, pointToDevServer };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
//#region src/core/builders/vite/plugins/devServerGlobals.ts
|
|
2
2
|
/**
|
|
3
|
-
* Defines global constants about the dev server. Helps scripts connect to the
|
|
3
|
+
* Defines global constants about the dev server. Helps scripts connect to the
|
|
4
|
+
* server's web socket.
|
|
4
5
|
*/
|
|
5
6
|
function devServerGlobals(config, server) {
|
|
6
7
|
return {
|
|
@@ -11,6 +12,5 @@ function devServerGlobals(config, server) {
|
|
|
11
12
|
}
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
|
-
|
|
15
15
|
//#endregion
|
|
16
|
-
export { devServerGlobals };
|
|
16
|
+
export { devServerGlobals };
|
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import { fetchCached } from "../../../utils/network.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/core/builders/vite/plugins/download.ts
|
|
4
3
|
/**
|
|
5
|
-
* Downloads any URL imports, like Google Analytics, into virtual modules so
|
|
6
|
-
* the extension instead of depending on remote code at
|
|
4
|
+
* Downloads any URL imports, like Google Analytics, into virtual modules so
|
|
5
|
+
* they are bundled with the extension instead of depending on remote code at
|
|
6
|
+
* runtime.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
*
|
|
9
|
+
* import 'url:https://google-tagmanager.com/gtag?id=XYZ';
|
|
10
10
|
*/
|
|
11
11
|
function download(config) {
|
|
12
12
|
return {
|
|
13
13
|
name: "wxt:download",
|
|
14
|
-
resolveId
|
|
15
|
-
|
|
14
|
+
resolveId: {
|
|
15
|
+
filter: { id: /^url:/ },
|
|
16
|
+
handler(id) {
|
|
17
|
+
return `\0${id}`;
|
|
18
|
+
}
|
|
16
19
|
},
|
|
17
|
-
load
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
load: {
|
|
21
|
+
filter: { id: /^\x00url:/ },
|
|
22
|
+
handler(id) {
|
|
23
|
+
return fetchCached(id.replace("\0url:", ""), config);
|
|
24
|
+
}
|
|
20
25
|
}
|
|
21
26
|
};
|
|
22
27
|
}
|
|
23
|
-
|
|
24
28
|
//#endregion
|
|
25
|
-
export { download };
|
|
29
|
+
export { download };
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { getEntrypointGlobals } from "../../../utils/globals.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/core/builders/vite/plugins/entrypointGroupGlobals.ts
|
|
4
|
-
/**
|
|
5
|
-
* Define a set of global variables specific to an entrypoint.
|
|
6
|
-
*/
|
|
3
|
+
/** Define a set of global variables specific to an entrypoint. */
|
|
7
4
|
function entrypointGroupGlobals(entrypointGroup) {
|
|
8
5
|
return {
|
|
9
6
|
name: "wxt:entrypoint-group-globals",
|
|
@@ -15,6 +12,5 @@ function entrypointGroupGlobals(entrypointGroup) {
|
|
|
15
12
|
}
|
|
16
13
|
};
|
|
17
14
|
}
|
|
18
|
-
|
|
19
15
|
//#endregion
|
|
20
|
-
export { entrypointGroupGlobals };
|
|
16
|
+
export { entrypointGroupGlobals };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
|
|
3
2
|
//#region src/core/builders/vite/plugins/extensionApiMock.ts
|
|
4
3
|
/**
|
|
5
|
-
* Mock `wxt/browser` and stub the global `browser`/`chrome` types with a fake
|
|
4
|
+
* Mock `wxt/browser` and stub the global `browser`/`chrome` types with a fake
|
|
5
|
+
* version of the extension APIs
|
|
6
6
|
*/
|
|
7
7
|
function extensionApiMock(config) {
|
|
8
8
|
const virtualSetupModule = "virtual:wxt-setup";
|
|
@@ -20,11 +20,17 @@ function extensionApiMock(config) {
|
|
|
20
20
|
ssr: { noExternal: ["wxt"] }
|
|
21
21
|
};
|
|
22
22
|
},
|
|
23
|
-
resolveId
|
|
24
|
-
|
|
23
|
+
resolveId: {
|
|
24
|
+
filter: { id: new RegExp(`${virtualSetupModule}$`) },
|
|
25
|
+
handler() {
|
|
26
|
+
return resolvedVirtualSetupModule;
|
|
27
|
+
}
|
|
25
28
|
},
|
|
26
|
-
load
|
|
27
|
-
|
|
29
|
+
load: {
|
|
30
|
+
filter: { id: new RegExp(`^${resolvedVirtualSetupModule}$`) },
|
|
31
|
+
handler() {
|
|
32
|
+
return setupTemplate;
|
|
33
|
+
}
|
|
28
34
|
}
|
|
29
35
|
};
|
|
30
36
|
}
|
|
@@ -35,6 +41,5 @@ const setupTemplate = `
|
|
|
35
41
|
vi.stubGlobal("chrome", fakeBrowser);
|
|
36
42
|
vi.stubGlobal("browser", fakeBrowser);
|
|
37
43
|
`;
|
|
38
|
-
|
|
39
44
|
//#endregion
|
|
40
|
-
export { extensionApiMock };
|
|
45
|
+
export { extensionApiMock };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { getGlobals } from "../../../utils/globals.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/core/builders/vite/plugins/globals.ts
|
|
4
3
|
function globals(config) {
|
|
5
4
|
return {
|
|
@@ -11,6 +10,5 @@ function globals(config) {
|
|
|
11
10
|
}
|
|
12
11
|
};
|
|
13
12
|
}
|
|
14
|
-
|
|
15
13
|
//#endregion
|
|
16
|
-
export { globals };
|
|
14
|
+
export { globals };
|