wxt 0.21.0 → 0.21.1
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 +0 -1
- 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/favicon-permission.mjs +28 -0
- package/dist/builtin-modules/index.mjs +3 -4
- package/dist/builtin-modules/unimport.mjs +1 -3
- package/dist/cli/cli-utils.mjs +8 -9
- 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 +123 -75
- 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 +34 -26
- package/dist/core/builders/vite/plugins/devServerGlobals.mjs +3 -3
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +2 -6
- package/dist/core/builders/vite/plugins/extensionApiMock.mjs +13 -8
- package/dist/core/builders/vite/plugins/globals.mjs +1 -3
- package/dist/core/builders/vite/plugins/iifeAnonymous.mjs +1 -2
- package/dist/core/builders/vite/plugins/iifeFooter.mjs +14 -7
- package/dist/core/builders/vite/plugins/index.mjs +17 -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 +3 -14
- package/dist/core/clean.mjs +19 -13
- package/dist/core/create-server.d.mts +6 -5
- package/dist/core/create-server.mjs +21 -117
- package/dist/core/define-config.mjs +1 -2
- package/dist/core/define-web-ext-config.d.mts +3 -6
- package/dist/core/define-web-ext-config.mjs +3 -12
- package/dist/core/generate-wxt-dir.mjs +53 -35
- package/dist/core/index.d.mts +3 -2
- package/dist/core/index.mjs +11 -11
- package/dist/core/initialize.mjs +28 -29
- package/dist/core/keyboard-shortcuts.mjs +4 -8
- 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 +63 -43
- package/dist/core/runners/manual.mjs +2 -6
- package/dist/core/runners/safari.mjs +3 -4
- package/dist/core/runners/web-ext.mjs +8 -11
- package/dist/core/runners/wsl.mjs +3 -4
- package/dist/core/utils/arrays.mjs +4 -11
- package/dist/core/utils/building/build-entrypoints.mjs +10 -11
- package/dist/core/utils/building/detect-dev-changes.mjs +37 -19
- package/dist/core/utils/building/find-entrypoints.mjs +40 -21
- 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 +21 -21
- 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/create-file-reloader.mjs +158 -0
- package/dist/core/utils/entrypoints.d.mts +10 -0
- package/dist/core/utils/entrypoints.mjs +6 -10
- package/dist/core/utils/env.mjs +24 -19
- 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 +2 -3
- package/dist/core/utils/index.d.mts +2 -0
- package/dist/core/utils/index.mjs +3 -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 +25 -21
- package/dist/core/utils/log/printHeader.mjs +3 -5
- package/dist/core/utils/log/printTable.mjs +1 -2
- package/dist/core/utils/manifest.mjs +39 -46
- 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 +3 -5
- package/dist/core/utils/theme-icons.mjs +71 -0
- package/dist/core/utils/time.mjs +1 -13
- package/dist/core/utils/transform.mjs +9 -7
- package/dist/core/utils/validation.mjs +1 -2
- package/dist/core/utils/virtual-modules.mjs +9 -15
- package/dist/core/wxt.mjs +11 -12
- package/dist/core/zip.d.mts +1 -0
- package/dist/core/zip.mjs +25 -20
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -3
- package/dist/modules.d.mts +64 -61
- package/dist/modules.mjs +70 -66
- package/dist/testing/fake-browser.mjs +1 -2
- package/dist/testing/wxt-vitest-plugin.d.mts +4 -2
- package/dist/testing/wxt-vitest-plugin.mjs +5 -7
- package/dist/types.d.mts +636 -450
- package/dist/utils/app-config.d.mts +1 -0
- package/dist/utils/app-config.mjs +3 -3
- package/dist/utils/content-script-context.d.mts +49 -39
- package/dist/utils/content-script-context.mjs +37 -32
- package/dist/utils/content-script-ui/iframe.d.mts +14 -15
- 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 +5 -8
- 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.d.mts +2 -2
- package/dist/utils/inject-script.mjs +4 -5
- 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.d.mts +1 -1
- package/dist/virtual/mock-browser.mjs +2 -4
- package/dist/virtual/reload-html.mjs +3 -10
- package/dist/virtual/unlisted-script-entrypoint.mjs +2 -7
- package/package.json +56 -49
- package/LICENSE +0 -21
- package/dist/core/builders/vite/plugins/download.mjs +0 -25
- package/dist/core/runners/index.mjs +0 -17
- package/dist/core/utils/minimatch-multiple.mjs +0 -28
- package/dist/core/utils/network.mjs +0 -38
- package/dist/core/utils/wsl.mjs +0 -12
- package/dist/testing/index.d.mts +0 -3
- package/dist/testing/index.mjs +0 -4
|
@@ -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 };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { normalizePath } from "../../../utils/paths.mjs";
|
|
2
|
-
import "../../../utils/index.mjs";
|
|
3
2
|
import { getEntrypointName } from "../../../utils/entrypoints.mjs";
|
|
3
|
+
import "../../../utils/index.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,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 };
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
//#region src/core/builders/vite/plugins/iifeFooter.ts
|
|
2
2
|
/**
|
|
3
|
-
* Add a footer with the returned value so it can return values to
|
|
4
|
-
* Footer is added a part of esbuild to make sure it's
|
|
5
|
-
* get's removed if added to
|
|
6
|
-
*
|
|
3
|
+
* Add a footer with the returned value so it can return values to
|
|
4
|
+
* `scripting.executeScript` Footer is added a part of esbuild to make sure it's
|
|
5
|
+
* not minified. It get's removed if added to
|
|
6
|
+
* `build.rollupOptions.output.footer` See
|
|
7
|
+
* https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/executeScript#return_value
|
|
7
8
|
*/
|
|
8
9
|
function iifeFooter(iifeReturnValueName) {
|
|
9
10
|
return {
|
|
10
11
|
name: "wxt:iife-footer",
|
|
11
12
|
generateBundle(_, bundle) {
|
|
12
|
-
for (const chunk of Object.values(bundle)) if (chunk.type === "chunk" && chunk.isEntry)
|
|
13
|
+
for (const chunk of Object.values(bundle)) if (chunk.type === "chunk" && chunk.isEntry) {
|
|
14
|
+
const code = chunk.code;
|
|
15
|
+
const marker = "\n//# sourceMappingURL=";
|
|
16
|
+
const returnValue = `${iifeReturnValueName};`;
|
|
17
|
+
const index = code.indexOf(marker);
|
|
18
|
+
if (index >= 0) chunk.code = code.slice(0, index + 1) + `${returnValue}\n` + code.slice(index + 1);
|
|
19
|
+
else chunk.code += `\n${returnValue}`;
|
|
20
|
+
}
|
|
13
21
|
}
|
|
14
22
|
};
|
|
15
23
|
}
|
|
16
|
-
|
|
17
24
|
//#endregion
|
|
18
|
-
export { iifeFooter };
|
|
25
|
+
export { iifeFooter };
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export { };
|
|
1
|
+
import "./devHtmlPrerender.mjs";
|
|
2
|
+
import "./devServerGlobals.mjs";
|
|
3
|
+
import "./resolveVirtualModules.mjs";
|
|
4
|
+
import "./tsconfigPaths.mjs";
|
|
5
|
+
import "./noopBackground.mjs";
|
|
6
|
+
import "./cssEntrypoints.mjs";
|
|
7
|
+
import "./bundleAnalysis.mjs";
|
|
8
|
+
import "./globals.mjs";
|
|
9
|
+
import "./extensionApiMock.mjs";
|
|
10
|
+
import "./entrypointGroupGlobals.mjs";
|
|
11
|
+
import "./defineImportMeta.mjs";
|
|
12
|
+
import "./removeEntrypointMainFunction.mjs";
|
|
13
|
+
import "./wxtPluginLoader.mjs";
|
|
14
|
+
import "./resolveAppConfig.mjs";
|
|
15
|
+
import "./iifeFooter.mjs";
|
|
16
|
+
import "./iifeAnonymous.mjs";
|
|
17
|
+
export {};
|
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
import { VIRTUAL_NOOP_BACKGROUND_MODULE_ID } from "../../../utils/constants.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/core/builders/vite/plugins/noopBackground.ts
|
|
4
3
|
/**
|
|
5
|
-
* In dev mode, if there's not a background script listed, we need to add one so
|
|
6
|
-
* connection is setup and the extension reloads HTML pages
|
|
4
|
+
* In dev mode, if there's not a background script listed, we need to add one so
|
|
5
|
+
* that the web socket connection is setup and the extension reloads HTML pages
|
|
6
|
+
* and content scripts correctly.
|
|
7
7
|
*/
|
|
8
8
|
function noopBackground() {
|
|
9
9
|
const virtualModuleId = VIRTUAL_NOOP_BACKGROUND_MODULE_ID;
|
|
10
10
|
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
11
11
|
return {
|
|
12
12
|
name: "wxt:noop-background",
|
|
13
|
-
resolveId
|
|
14
|
-
|
|
13
|
+
resolveId: {
|
|
14
|
+
filter: { id: new RegExp(`^${virtualModuleId}$`) },
|
|
15
|
+
handler() {
|
|
16
|
+
return resolvedVirtualModuleId;
|
|
17
|
+
}
|
|
15
18
|
},
|
|
16
|
-
load
|
|
17
|
-
|
|
19
|
+
load: {
|
|
20
|
+
filter: { id: new RegExp(`^${resolvedVirtualModuleId}$`) },
|
|
21
|
+
handler() {
|
|
22
|
+
return `import { defineBackground } from 'wxt/utils/define-background';\nexport default defineBackground(() => void 0)`;
|
|
23
|
+
}
|
|
18
24
|
}
|
|
19
25
|
};
|
|
20
26
|
}
|
|
21
|
-
|
|
22
27
|
//#endregion
|
|
23
|
-
export { noopBackground };
|
|
28
|
+
export { noopBackground };
|
|
@@ -2,10 +2,10 @@ import { normalizePath } from "../../../utils/paths.mjs";
|
|
|
2
2
|
import "../../../utils/index.mjs";
|
|
3
3
|
import { removeMainFunctionCode } from "../../../utils/transform.mjs";
|
|
4
4
|
import { resolve } from "node:path";
|
|
5
|
-
|
|
6
5
|
//#region src/core/builders/vite/plugins/removeEntrypointMainFunction.ts
|
|
7
6
|
/**
|
|
8
|
-
* Transforms entrypoints, removing the main function from the entrypoint if it
|
|
7
|
+
* Transforms entrypoints, removing the main function from the entrypoint if it
|
|
8
|
+
* exists.
|
|
9
9
|
*/
|
|
10
10
|
function removeEntrypointMainFunction(config, path) {
|
|
11
11
|
const absPath = normalizePath(resolve(config.root, path));
|
|
@@ -13,18 +13,16 @@ function removeEntrypointMainFunction(config, path) {
|
|
|
13
13
|
name: "wxt:remove-entrypoint-main-function",
|
|
14
14
|
transform: {
|
|
15
15
|
order: "pre",
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
16
|
+
filter: { id: new RegExp(`^${absPath}$`) },
|
|
17
|
+
handler(code) {
|
|
18
|
+
const newCode = removeMainFunctionCode(code);
|
|
19
|
+
config.logger.debug("transformed entrypoint", path);
|
|
20
|
+
config.logger.debug(`Original:\n---\n${code}\n---`);
|
|
21
|
+
config.logger.debug(`Transformed:\n---\n${newCode.code}\n---`);
|
|
22
|
+
return newCode;
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
};
|
|
27
26
|
}
|
|
28
|
-
|
|
29
27
|
//#endregion
|
|
30
|
-
export { removeEntrypointMainFunction };
|
|
28
|
+
export { removeEntrypointMainFunction };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { pathExists } from "fs
|
|
1
|
+
import { pathExists } from "../../../utils/fs.mjs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
-
|
|
4
3
|
//#region src/core/builders/vite/plugins/resolveAppConfig.ts
|
|
5
4
|
/**
|
|
6
|
-
* When importing `virtual:app-config`, resolve it to the `app.config.ts` file
|
|
5
|
+
* When importing `virtual:app-config`, resolve it to the `app.config.ts` file
|
|
6
|
+
* in the project.
|
|
7
7
|
*/
|
|
8
8
|
function resolveAppConfig(config) {
|
|
9
9
|
const virtualModuleId = "virtual:app-config";
|
|
@@ -14,15 +14,19 @@ function resolveAppConfig(config) {
|
|
|
14
14
|
config() {
|
|
15
15
|
return { optimizeDeps: { exclude: [virtualModuleId] } };
|
|
16
16
|
},
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
resolveId: {
|
|
18
|
+
filter: { id: new RegExp(`^${virtualModuleId}$`) },
|
|
19
|
+
async handler() {
|
|
20
|
+
return await pathExists(appConfigFile) ? appConfigFile : resolvedVirtualModuleId;
|
|
21
|
+
}
|
|
20
22
|
},
|
|
21
|
-
load
|
|
22
|
-
|
|
23
|
+
load: {
|
|
24
|
+
filter: { id: new RegExp(`^${resolvedVirtualModuleId}$`) },
|
|
25
|
+
handler() {
|
|
26
|
+
return `export default {}`;
|
|
27
|
+
}
|
|
23
28
|
}
|
|
24
29
|
};
|
|
25
30
|
}
|
|
26
|
-
|
|
27
31
|
//#endregion
|
|
28
|
-
export { resolveAppConfig };
|
|
32
|
+
export { resolveAppConfig };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { normalizePath } from "../../../utils/paths.mjs";
|
|
2
2
|
import "../../../utils/index.mjs";
|
|
3
3
|
import { virtualModuleNames } from "../../../utils/virtual-modules.mjs";
|
|
4
|
-
import
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
5
|
import { resolve } from "path";
|
|
6
|
-
|
|
7
6
|
//#region src/core/builders/vite/plugins/resolveVirtualModules.ts
|
|
8
7
|
/**
|
|
9
|
-
* Resolve all the virtual modules to the `node_modules/wxt/dist/virtual`
|
|
8
|
+
* Resolve all the virtual modules to the `node_modules/wxt/dist/virtual`
|
|
9
|
+
* directory.
|
|
10
10
|
*/
|
|
11
11
|
function resolveVirtualModules(config) {
|
|
12
12
|
return virtualModuleNames.map((name) => {
|
|
@@ -14,19 +14,21 @@ function resolveVirtualModules(config) {
|
|
|
14
14
|
const resolvedVirtualId = "\0" + virtualId;
|
|
15
15
|
return {
|
|
16
16
|
name: `wxt:resolve-virtual-${name}`,
|
|
17
|
-
resolveId
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
resolveId: {
|
|
18
|
+
filter: { id: new RegExp(virtualId) },
|
|
19
|
+
handler(id) {
|
|
20
|
+
return resolvedVirtualId + normalizePath(id.substring(id.indexOf(virtualId) + virtualId.length));
|
|
21
|
+
}
|
|
21
22
|
},
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
load: {
|
|
24
|
+
filter: { id: new RegExp(`^${resolvedVirtualId}`) },
|
|
25
|
+
async handler(id) {
|
|
26
|
+
const inputPath = id.replace(resolvedVirtualId, "");
|
|
27
|
+
return (await readFile(resolve(config.wxtModuleDir, `dist/virtual/${name}.mjs`), "utf-8")).replace(`virtual:user-${name}`, inputPath);
|
|
28
|
+
}
|
|
26
29
|
}
|
|
27
30
|
};
|
|
28
31
|
});
|
|
29
32
|
}
|
|
30
|
-
|
|
31
33
|
//#endregion
|
|
32
|
-
export { resolveVirtualModules };
|
|
34
|
+
export { resolveVirtualModules };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { normalizePath } from "../../../utils/paths.mjs";
|
|
2
2
|
import "../../../utils/index.mjs";
|
|
3
3
|
import { parseHTML } from "linkedom";
|
|
4
|
-
|
|
5
4
|
//#region src/core/builders/vite/plugins/wxtPluginLoader.ts
|
|
6
5
|
/**
|
|
7
|
-
* Resolve and load plugins for each entrypoint. This handles both JS
|
|
6
|
+
* Resolve and load plugins for each entrypoint. This handles both JS
|
|
7
|
+
* entrypoints via the `virtual:wxt-plugins` import, and HTML files by adding
|
|
8
|
+
* `virtual:wxt-html-plugins` to the document's `<head>`
|
|
8
9
|
*/
|
|
9
10
|
function wxtPluginLoader(config) {
|
|
10
11
|
const virtualModuleId = "virtual:wxt-plugins";
|
|
@@ -13,19 +14,24 @@ function wxtPluginLoader(config) {
|
|
|
13
14
|
const resolvedVirtualHtmlModuleId = "\0" + virtualHtmlModuleId;
|
|
14
15
|
return {
|
|
15
16
|
name: "wxt:plugin-loader",
|
|
16
|
-
resolveId
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
resolveId: {
|
|
18
|
+
filter: { id: [new RegExp(`^${virtualModuleId}$`), new RegExp(`^${virtualHtmlModuleId}$`)] },
|
|
19
|
+
handler(id) {
|
|
20
|
+
if (id === virtualModuleId) return resolvedVirtualModuleId;
|
|
21
|
+
return resolvedVirtualHtmlModuleId;
|
|
22
|
+
}
|
|
19
23
|
},
|
|
20
|
-
load
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
load: {
|
|
25
|
+
filter: { id: [new RegExp(`^${resolvedVirtualModuleId}$`), new RegExp(`^${resolvedVirtualHtmlModuleId}$`)] },
|
|
26
|
+
handler(id) {
|
|
27
|
+
if (id === resolvedVirtualModuleId) return `${config.plugins.map((plugin, i) => `import initPlugin${i} from '${normalizePath(plugin)}';`).join("\n")}\n\nexport function initPlugins() {\n${config.plugins.map((_, i) => ` initPlugin${i}();`).join("\n")}\n}`;
|
|
28
|
+
else return `import { initPlugins } from '${virtualModuleId}';
|
|
29
|
+
try {
|
|
30
|
+
initPlugins();
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.error("[wxt] Failed to initialize plugins", err);
|
|
33
|
+
}`;
|
|
34
|
+
}
|
|
29
35
|
},
|
|
30
36
|
transformIndexHtml: {
|
|
31
37
|
order: "pre",
|
|
@@ -40,12 +46,11 @@ try {
|
|
|
40
46
|
const newHead = document.createElement("head");
|
|
41
47
|
document.documentElement.prepend(newHead);
|
|
42
48
|
}
|
|
43
|
-
document.head
|
|
49
|
+
document.head?.prepend(script);
|
|
44
50
|
return document.toString();
|
|
45
51
|
}
|
|
46
52
|
}
|
|
47
53
|
};
|
|
48
54
|
}
|
|
49
|
-
|
|
50
55
|
//#endregion
|
|
51
|
-
export { wxtPluginLoader };
|
|
56
|
+
export { wxtPluginLoader };
|
package/dist/core/clean.d.mts
CHANGED
|
@@ -4,22 +4,11 @@ import { InlineConfig } from "../types.mjs";
|
|
|
4
4
|
/**
|
|
5
5
|
* Remove generated/temp files from the directory.
|
|
6
6
|
*
|
|
7
|
-
* @param config Optional config that will override your `<root>/wxt.config.ts`.
|
|
8
|
-
*
|
|
9
7
|
* @example
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
declare function clean(config?: InlineConfig): Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* Remove generated/temp files from the directory.
|
|
8
|
+
* await clean();
|
|
15
9
|
*
|
|
16
|
-
* @
|
|
17
|
-
*
|
|
18
|
-
* @param root The directory to look for generated/temp files in. Defaults to `process.cwd()`. Can be relative to `process.cwd()` or absolute.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* await clean();
|
|
10
|
+
* @param config Optional config that will override your `<root>/wxt.config.ts`.
|
|
22
11
|
*/
|
|
23
|
-
declare function clean(
|
|
12
|
+
declare function clean(config?: InlineConfig): Promise<void>;
|
|
24
13
|
//#endregion
|
|
25
14
|
export { clean };
|
package/dist/core/clean.mjs
CHANGED
|
@@ -1,41 +1,47 @@
|
|
|
1
1
|
import { registerWxt, wxt } from "./wxt.mjs";
|
|
2
|
-
import
|
|
3
|
-
import glob from "
|
|
2
|
+
import { rm } from "node:fs/promises";
|
|
3
|
+
import { glob } from "tinyglobby";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import
|
|
6
|
-
|
|
5
|
+
import { styleText } from "node:util";
|
|
7
6
|
//#region src/core/clean.ts
|
|
7
|
+
/**
|
|
8
|
+
* Remove generated/temp files from the directory.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* await clean();
|
|
12
|
+
*
|
|
13
|
+
* @param config Optional config that will override your `<root>/wxt.config.ts`.
|
|
14
|
+
*/
|
|
8
15
|
async function clean(config) {
|
|
9
|
-
if (typeof config === "string") config = { root: config };
|
|
10
16
|
await registerWxt("build", config);
|
|
11
17
|
wxt.logger.info("Cleaning Project");
|
|
12
18
|
const root = wxt.config.root;
|
|
13
19
|
const tempDirs = [
|
|
14
20
|
"node_modules/.vite",
|
|
15
21
|
"node_modules/.cache",
|
|
16
|
-
"
|
|
22
|
+
"{,**/}.wxt",
|
|
17
23
|
`${path.relative(root, wxt.config.outBaseDir)}/*`
|
|
18
24
|
];
|
|
19
|
-
wxt.logger.debug("Looking for:", tempDirs.map(
|
|
25
|
+
wxt.logger.debug("Looking for:", tempDirs.map((dir) => styleText("cyan", dir)).join(", "));
|
|
20
26
|
const directories = await glob(tempDirs, {
|
|
21
27
|
cwd: root,
|
|
22
28
|
absolute: true,
|
|
23
29
|
onlyDirectories: true,
|
|
24
|
-
deep: 2
|
|
30
|
+
deep: 2,
|
|
31
|
+
expandDirectories: false
|
|
25
32
|
});
|
|
26
33
|
if (directories.length === 0) {
|
|
27
34
|
wxt.logger.debug("No generated files found.");
|
|
28
35
|
return;
|
|
29
36
|
}
|
|
30
|
-
wxt.logger.debug("Found:", directories.map((dir) =>
|
|
37
|
+
wxt.logger.debug("Found:", directories.map((dir) => styleText("cyan", path.relative(root, dir))).join(", "));
|
|
31
38
|
for (const directory of directories) {
|
|
32
|
-
await
|
|
39
|
+
await rm(directory, {
|
|
33
40
|
force: true,
|
|
34
41
|
recursive: true
|
|
35
42
|
});
|
|
36
|
-
wxt.logger.debug("Deleted " +
|
|
43
|
+
wxt.logger.debug("Deleted " + styleText("cyan", path.relative(root, directory)));
|
|
37
44
|
}
|
|
38
45
|
}
|
|
39
|
-
|
|
40
46
|
//#endregion
|
|
41
|
-
export { clean };
|
|
47
|
+
export { clean };
|
|
@@ -2,13 +2,14 @@ import { InlineConfig, WxtDevServer } from "../types.mjs";
|
|
|
2
2
|
|
|
3
3
|
//#region src/core/create-server.d.ts
|
|
4
4
|
/**
|
|
5
|
-
* Creates a dev server and pre-builds all the files that need to exist before
|
|
5
|
+
* Creates a dev server and pre-builds all the files that need to exist before
|
|
6
|
+
* loading the extension.
|
|
6
7
|
*
|
|
7
8
|
* @example
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* const server = await wxt.createServer({
|
|
10
|
+
* // Enter config...
|
|
11
|
+
* });
|
|
12
|
+
* await server.start();
|
|
12
13
|
*/
|
|
13
14
|
declare function createServer(inlineConfig?: InlineConfig): Promise<WxtDevServer>;
|
|
14
15
|
//#endregion
|