wxt 0.20.18 → 0.20.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/wxt-publish-extension.mjs +4 -3
- package/dist/browser.d.mts +7 -6
- package/dist/browser.mjs +6 -5
- package/dist/builtin-modules/index.mjs +1 -3
- package/dist/builtin-modules/unimport.mjs +1 -3
- package/dist/cli/cli-utils.mjs +5 -6
- package/dist/cli/commands.mjs +1 -3
- package/dist/cli/index.mjs +1 -3
- package/dist/core/build.d.mts +9 -8
- package/dist/core/build.mjs +10 -11
- package/dist/core/builders/vite/index.mjs +27 -25
- package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +1 -3
- package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +6 -6
- package/dist/core/builders/vite/plugins/defineImportMeta.mjs +3 -4
- package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +33 -25
- package/dist/core/builders/vite/plugins/devServerGlobals.mjs +3 -3
- package/dist/core/builders/vite/plugins/download.mjs +15 -11
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +2 -6
- package/dist/core/builders/vite/plugins/extensionApiMock.mjs +13 -8
- package/dist/core/builders/vite/plugins/globals.mjs +1 -3
- package/dist/core/builders/vite/plugins/iifeAnonymous.mjs +1 -2
- package/dist/core/builders/vite/plugins/iifeFooter.mjs +14 -7
- package/dist/core/builders/vite/plugins/index.mjs +18 -19
- package/dist/core/builders/vite/plugins/noopBackground.mjs +14 -9
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +10 -12
- package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +14 -10
- package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +15 -13
- package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +1 -2
- package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +22 -17
- package/dist/core/clean.d.mts +7 -7
- package/dist/core/clean.mjs +6 -7
- package/dist/core/create-server.d.mts +6 -5
- package/dist/core/create-server.mjs +12 -11
- package/dist/core/define-config.mjs +1 -2
- package/dist/core/define-web-ext-config.d.mts +3 -4
- package/dist/core/define-web-ext-config.mjs +4 -7
- package/dist/core/generate-wxt-dir.mjs +8 -9
- package/dist/core/index.mjs +10 -11
- package/dist/core/initialize.mjs +10 -11
- package/dist/core/keyboard-shortcuts.mjs +2 -6
- package/dist/core/package-managers/bun.mjs +1 -3
- package/dist/core/package-managers/deno.mjs +1 -2
- package/dist/core/package-managers/index.mjs +1 -3
- package/dist/core/package-managers/npm.mjs +3 -5
- package/dist/core/package-managers/pnpm.mjs +1 -3
- package/dist/core/package-managers/yarn.mjs +1 -3
- package/dist/core/prepare.mjs +1 -3
- package/dist/core/resolve-config.mjs +20 -23
- package/dist/core/runners/index.mjs +1 -3
- package/dist/core/runners/manual.mjs +2 -6
- package/dist/core/runners/safari.mjs +3 -4
- package/dist/core/runners/web-ext.mjs +2 -6
- package/dist/core/runners/wsl.mjs +3 -4
- package/dist/core/utils/arrays.mjs +4 -11
- package/dist/core/utils/building/build-entrypoints.mjs +8 -9
- package/dist/core/utils/building/detect-dev-changes.mjs +21 -13
- package/dist/core/utils/building/find-entrypoints.mjs +16 -11
- package/dist/core/utils/building/group-entrypoints.mjs +3 -4
- package/dist/core/utils/building/index.mjs +7 -8
- package/dist/core/utils/building/internal-build.mjs +13 -13
- package/dist/core/utils/building/rebuild.mjs +10 -10
- package/dist/core/utils/cache.mjs +6 -8
- package/dist/core/utils/constants.mjs +3 -4
- package/dist/core/utils/content-scripts.mjs +3 -4
- package/dist/core/utils/content-security-policy.mjs +2 -5
- package/dist/core/utils/entrypoints.mjs +6 -10
- package/dist/core/utils/env.mjs +2 -6
- package/dist/core/utils/environments/browser-environment.mjs +1 -3
- package/dist/core/utils/environments/environment.mjs +1 -2
- package/dist/core/utils/environments/extension-environment.mjs +1 -3
- package/dist/core/utils/environments/index.mjs +3 -4
- package/dist/core/utils/eslint.mjs +1 -2
- package/dist/core/utils/fs.mjs +23 -14
- package/dist/core/utils/globals.mjs +1 -2
- package/dist/core/utils/i18n.mjs +1 -2
- package/dist/core/utils/index.mjs +2 -3
- package/dist/core/utils/log/index.mjs +5 -6
- package/dist/core/utils/log/printBuildSummary.mjs +1 -3
- package/dist/core/utils/log/printFileList.mjs +3 -5
- package/dist/core/utils/log/printHeader.mjs +1 -3
- package/dist/core/utils/log/printTable.mjs +1 -2
- package/dist/core/utils/manifest.mjs +23 -31
- package/dist/core/utils/minimatch-multiple.mjs +5 -7
- package/dist/core/utils/network.mjs +3 -5
- package/dist/core/utils/number.mjs +1 -2
- package/dist/core/utils/package.mjs +3 -5
- package/dist/core/utils/paths.d.mts +2 -2
- package/dist/core/utils/paths.mjs +7 -9
- package/dist/core/utils/strings.mjs +4 -7
- package/dist/core/utils/syntax-errors.mjs +1 -3
- package/dist/core/utils/time.mjs +2 -5
- package/dist/core/utils/transform.mjs +8 -6
- package/dist/core/utils/validation.mjs +1 -2
- package/dist/core/utils/virtual-modules.mjs +9 -15
- package/dist/core/utils/wsl.mjs +2 -6
- package/dist/core/wxt.mjs +7 -9
- package/dist/core/zip.d.mts +1 -0
- package/dist/core/zip.mjs +11 -10
- package/dist/index.d.mts +0 -1
- package/dist/index.mjs +1 -2
- package/dist/modules.d.mts +64 -61
- package/dist/modules.mjs +70 -66
- package/dist/testing/fake-browser.mjs +1 -2
- package/dist/testing/index.mjs +1 -2
- package/dist/testing/wxt-vitest-plugin.d.mts +4 -2
- package/dist/testing/wxt-vitest-plugin.mjs +5 -5
- package/dist/types.d.mts +455 -435
- package/dist/utils/app-config.mjs +1 -3
- package/dist/utils/content-script-context.d.mts +49 -39
- package/dist/utils/content-script-context.mjs +36 -31
- package/dist/utils/content-script-ui/iframe.d.mts +12 -13
- package/dist/utils/content-script-ui/iframe.mjs +1 -3
- package/dist/utils/content-script-ui/integrated.d.mts +8 -7
- package/dist/utils/content-script-ui/integrated.mjs +1 -3
- package/dist/utils/content-script-ui/shadow-root.d.mts +37 -25
- package/dist/utils/content-script-ui/shadow-root.mjs +4 -7
- package/dist/utils/content-script-ui/shared.mjs +1 -3
- package/dist/utils/content-script-ui/types.d.mts +29 -34
- package/dist/utils/content-script-ui/types.mjs +1 -1
- package/dist/utils/define-app-config.d.mts +4 -3
- package/dist/utils/define-app-config.mjs +5 -5
- package/dist/utils/define-background.mjs +1 -2
- package/dist/utils/define-content-script.mjs +1 -2
- package/dist/utils/define-unlisted-script.mjs +1 -2
- package/dist/utils/define-wxt-plugin.mjs +1 -2
- package/dist/utils/inject-script.mjs +1 -3
- package/dist/utils/internal/custom-events.mjs +3 -4
- package/dist/utils/internal/location-watcher.mjs +4 -6
- package/dist/utils/internal/logger.mjs +2 -5
- package/dist/utils/match-patterns.mjs +2 -3
- package/dist/utils/split-shadow-root-css.d.mts +6 -2
- package/dist/utils/split-shadow-root-css.mjs +7 -4
- package/dist/utils/storage.mjs +2 -3
- package/dist/version.mjs +2 -3
- package/dist/virtual/background-entrypoint.mjs +4 -16
- package/dist/virtual/content-script-isolated-world-entrypoint.mjs +2 -7
- package/dist/virtual/content-script-main-world-entrypoint.mjs +2 -7
- package/dist/virtual/mock-browser.mjs +1 -3
- package/dist/virtual/reload-html.mjs +3 -10
- package/dist/virtual/unlisted-script-entrypoint.mjs +2 -7
- package/package.json +17 -19
|
@@ -1,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,18 @@
|
|
|
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
|
-
import
|
|
18
|
-
|
|
19
|
-
export { };
|
|
1
|
+
import "./devHtmlPrerender.mjs";
|
|
2
|
+
import "./devServerGlobals.mjs";
|
|
3
|
+
import "./download.mjs";
|
|
4
|
+
import "./resolveVirtualModules.mjs";
|
|
5
|
+
import "./tsconfigPaths.mjs";
|
|
6
|
+
import "./noopBackground.mjs";
|
|
7
|
+
import "./cssEntrypoints.mjs";
|
|
8
|
+
import "./bundleAnalysis.mjs";
|
|
9
|
+
import "./globals.mjs";
|
|
10
|
+
import "./extensionApiMock.mjs";
|
|
11
|
+
import "./entrypointGroupGlobals.mjs";
|
|
12
|
+
import "./defineImportMeta.mjs";
|
|
13
|
+
import "./removeEntrypointMainFunction.mjs";
|
|
14
|
+
import "./wxtPluginLoader.mjs";
|
|
15
|
+
import "./resolveAppConfig.mjs";
|
|
16
|
+
import "./iifeFooter.mjs";
|
|
17
|
+
import "./iifeAnonymous.mjs";
|
|
18
|
+
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("vite-node 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,21 +4,21 @@ 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
|
-
*
|
|
8
|
+
* await clean();
|
|
9
|
+
*
|
|
10
|
+
* @param config Optional config that will override your `<root>/wxt.config.ts`.
|
|
11
11
|
*/
|
|
12
12
|
declare function clean(config?: InlineConfig): Promise<void>;
|
|
13
13
|
/**
|
|
14
14
|
* Remove generated/temp files from the directory.
|
|
15
15
|
*
|
|
16
16
|
* @deprecated
|
|
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
17
|
* @example
|
|
21
|
-
*
|
|
18
|
+
* await clean();
|
|
19
|
+
*
|
|
20
|
+
* @param root The directory to look for generated/temp files in. Defaults to
|
|
21
|
+
* `process.cwd()`. Can be relative to `process.cwd()` or absolute.
|
|
22
22
|
*/
|
|
23
23
|
declare function clean(root?: string): Promise<void>;
|
|
24
24
|
//#endregion
|
package/dist/core/clean.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
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
5
|
import pc from "picocolors";
|
|
6
|
-
|
|
7
6
|
//#region src/core/clean.ts
|
|
8
7
|
async function clean(config) {
|
|
9
8
|
if (typeof config === "string") config = { root: config };
|
|
@@ -21,7 +20,8 @@ async function clean(config) {
|
|
|
21
20
|
cwd: root,
|
|
22
21
|
absolute: true,
|
|
23
22
|
onlyDirectories: true,
|
|
24
|
-
deep: 2
|
|
23
|
+
deep: 2,
|
|
24
|
+
expandDirectories: false
|
|
25
25
|
});
|
|
26
26
|
if (directories.length === 0) {
|
|
27
27
|
wxt.logger.debug("No generated files found.");
|
|
@@ -29,13 +29,12 @@ async function clean(config) {
|
|
|
29
29
|
}
|
|
30
30
|
wxt.logger.debug("Found:", directories.map((dir) => pc.cyan(path.relative(root, dir))).join(", "));
|
|
31
31
|
for (const directory of directories) {
|
|
32
|
-
await
|
|
32
|
+
await rm(directory, {
|
|
33
33
|
force: true,
|
|
34
34
|
recursive: true
|
|
35
35
|
});
|
|
36
36
|
wxt.logger.debug("Deleted " + pc.cyan(path.relative(root, directory)));
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
|
|
40
39
|
//#endregion
|
|
41
|
-
export { clean };
|
|
40
|
+
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
|
|
@@ -16,16 +16,16 @@ import pc from "picocolors";
|
|
|
16
16
|
import { debounce } from "perfect-debounce";
|
|
17
17
|
import chokidar from "chokidar";
|
|
18
18
|
import { Mutex } from "async-mutex";
|
|
19
|
-
|
|
20
19
|
//#region src/core/create-server.ts
|
|
21
20
|
/**
|
|
22
|
-
* Creates a dev server and pre-builds all the files that need to exist before
|
|
21
|
+
* Creates a dev server and pre-builds all the files that need to exist before
|
|
22
|
+
* loading the extension.
|
|
23
23
|
*
|
|
24
24
|
* @example
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
25
|
+
* const server = await wxt.createServer({
|
|
26
|
+
* // Enter config...
|
|
27
|
+
* });
|
|
28
|
+
* await server.start();
|
|
29
29
|
*/
|
|
30
30
|
async function createServer(inlineConfig) {
|
|
31
31
|
await registerWxt("serve", inlineConfig);
|
|
@@ -147,8 +147,8 @@ async function createServerInternal() {
|
|
|
147
147
|
return server;
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
|
-
* Returns a function responsible for reloading different parts of the extension
|
|
151
|
-
* changes.
|
|
150
|
+
* Returns a function responsible for reloading different parts of the extension
|
|
151
|
+
* when a file changes.
|
|
152
152
|
*/
|
|
153
153
|
function createFileReloader(server) {
|
|
154
154
|
const fileChangedMutex = new Mutex();
|
|
@@ -204,7 +204,8 @@ function createFileReloader(server) {
|
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
206
|
/**
|
|
207
|
-
* From the server, tell the client to reload content scripts from the provided
|
|
207
|
+
* From the server, tell the client to reload content scripts from the provided
|
|
208
|
+
* build step outputs.
|
|
208
209
|
*/
|
|
209
210
|
function reloadContentScripts(steps, server) {
|
|
210
211
|
if (wxt.config.manifestVersion === 3) steps.forEach((step) => {
|
|
@@ -236,6 +237,7 @@ function getFilenameList(names) {
|
|
|
236
237
|
}
|
|
237
238
|
/**
|
|
238
239
|
* Based on the current build output, return a list of files that are:
|
|
240
|
+
*
|
|
239
241
|
* 1. Not in node_modules
|
|
240
242
|
* 2. Not inside project root
|
|
241
243
|
*/
|
|
@@ -248,6 +250,5 @@ function getExternalOutputDependencies(server) {
|
|
|
248
250
|
});
|
|
249
251
|
}).filter((file) => !file.includes("node_modules") && !file.startsWith("\0")).map(unnormalizePath).filter((file) => !file.startsWith(wxt.config.root)) ?? [];
|
|
250
252
|
}
|
|
251
|
-
|
|
252
253
|
//#endregion
|
|
253
|
-
export { createServer };
|
|
254
|
+
export { createServer };
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { WebExtConfig } from "../types.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/core/define-web-ext-config.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated Use `defineWebExtConfig` instead. Same function, different name.
|
|
6
|
-
*/
|
|
4
|
+
/** @deprecated Use `defineWebExtConfig` instead. Same function, different name. */
|
|
7
5
|
declare function defineRunnerConfig(config: WebExtConfig): WebExtConfig;
|
|
8
6
|
/**
|
|
9
|
-
* Configure how [`web-ext`](https://github.com/mozilla/web-ext) starts the
|
|
7
|
+
* Configure how [`web-ext`](https://github.com/mozilla/web-ext) starts the
|
|
8
|
+
* browser during development.
|
|
10
9
|
*/
|
|
11
10
|
declare function defineWebExtConfig(config: WebExtConfig): WebExtConfig;
|
|
12
11
|
//#endregion
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import consola from "consola";
|
|
2
|
-
|
|
3
2
|
//#region src/core/define-web-ext-config.ts
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated Use `defineWebExtConfig` instead. Same function, different name.
|
|
6
|
-
*/
|
|
3
|
+
/** @deprecated Use `defineWebExtConfig` instead. Same function, different name. */
|
|
7
4
|
function defineRunnerConfig(config) {
|
|
8
5
|
consola.warn("`defineRunnerConfig` is deprecated, use `defineWebExtConfig` instead. See https://wxt.dev/guide/resources/upgrading.html#v0-19-0-rarr-v0-20-0");
|
|
9
6
|
return defineWebExtConfig(config);
|
|
10
7
|
}
|
|
11
8
|
/**
|
|
12
|
-
* Configure how [`web-ext`](https://github.com/mozilla/web-ext) starts the
|
|
9
|
+
* Configure how [`web-ext`](https://github.com/mozilla/web-ext) starts the
|
|
10
|
+
* browser during development.
|
|
13
11
|
*/
|
|
14
12
|
function defineWebExtConfig(config) {
|
|
15
13
|
return config;
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
//#endregion
|
|
19
|
-
export { defineRunnerConfig, defineWebExtConfig };
|
|
16
|
+
export { defineRunnerConfig, defineWebExtConfig };
|
|
@@ -3,17 +3,17 @@ import "./utils/index.mjs";
|
|
|
3
3
|
import { getEntrypointBundlePath, isHtmlEntrypoint } from "./utils/entrypoints.mjs";
|
|
4
4
|
import { getEntrypointGlobals, getGlobals } from "./utils/globals.mjs";
|
|
5
5
|
import { wxt } from "./wxt.mjs";
|
|
6
|
-
import { getPublicFiles, writeFileIfDifferent } from "./utils/fs.mjs";
|
|
6
|
+
import { getPublicFiles, pathExists, writeFileIfDifferent } from "./utils/fs.mjs";
|
|
7
7
|
import { parseI18nMessages } from "./utils/i18n.mjs";
|
|
8
|
-
import
|
|
8
|
+
import { mkdir, readFile } from "node:fs/promises";
|
|
9
9
|
import path, { dirname, relative, resolve } from "node:path";
|
|
10
|
-
|
|
11
10
|
//#region src/core/generate-wxt-dir.ts
|
|
12
11
|
/**
|
|
13
|
-
* Generate and write all the files inside the `InternalConfig.typesDir`
|
|
12
|
+
* Generate and write all the files inside the `InternalConfig.typesDir`
|
|
13
|
+
* directory.
|
|
14
14
|
*/
|
|
15
15
|
async function generateWxtDir(entrypoints) {
|
|
16
|
-
await
|
|
16
|
+
await mkdir(wxt.config.typesDir, { recursive: true });
|
|
17
17
|
const entries = [{ module: "wxt/vite-builder-env" }];
|
|
18
18
|
wxt.config.userModules.forEach((module) => {
|
|
19
19
|
if (module.type === "node_module") entries.push({ module: module.id });
|
|
@@ -29,7 +29,7 @@ async function generateWxtDir(entrypoints) {
|
|
|
29
29
|
path: resolve(wxt.config.wxtDir, entry.path)
|
|
30
30
|
}));
|
|
31
31
|
await Promise.all(absoluteFileEntries.map(async (file) => {
|
|
32
|
-
await
|
|
32
|
+
await mkdir(dirname(file.path), { recursive: true });
|
|
33
33
|
await writeFileIfDifferent(file.path, file.text);
|
|
34
34
|
}));
|
|
35
35
|
}
|
|
@@ -90,7 +90,7 @@ declare module "wxt/browser" {
|
|
|
90
90
|
`;
|
|
91
91
|
const defaultLocalePath = path.resolve(wxt.config.publicDir, "_locales", defaultLocale ?? "", "messages.json");
|
|
92
92
|
let messages;
|
|
93
|
-
if (await
|
|
93
|
+
if (await pathExists(defaultLocalePath)) messages = parseI18nMessages(JSON.parse(await readFile(defaultLocalePath, "utf-8")));
|
|
94
94
|
else messages = parseI18nMessages({});
|
|
95
95
|
const renderGetMessageOverload = (keyType, description, translation) => {
|
|
96
96
|
const commentLines = [];
|
|
@@ -178,6 +178,5 @@ ${Object.entries(wxt.config.alias).flatMap(([alias, absolutePath]) => {
|
|
|
178
178
|
}`
|
|
179
179
|
};
|
|
180
180
|
}
|
|
181
|
-
|
|
182
181
|
//#endregion
|
|
183
|
-
export { generateWxtDir };
|
|
182
|
+
export { generateWxtDir };
|
package/dist/core/index.mjs
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./utils/paths.mjs";
|
|
2
2
|
import "./utils/index.mjs";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
export { };
|
|
3
|
+
import "./build.mjs";
|
|
4
|
+
import "./clean.mjs";
|
|
5
|
+
import "./define-config.mjs";
|
|
6
|
+
import "./define-web-ext-config.mjs";
|
|
7
|
+
import "./create-server.mjs";
|
|
8
|
+
import "./initialize.mjs";
|
|
9
|
+
import "./prepare.mjs";
|
|
10
|
+
import "./zip.mjs";
|
|
11
|
+
export {};
|
package/dist/core/initialize.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { pathExists } from "./utils/fs.mjs";
|
|
2
|
+
import { readdir, rename } from "node:fs/promises";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { consola as consola$1 } from "consola";
|
|
4
5
|
import pc from "picocolors";
|
|
5
6
|
import prompts from "prompts";
|
|
6
7
|
import { downloadTemplate } from "giget";
|
|
7
|
-
|
|
8
8
|
//#region src/core/initialize.ts
|
|
9
9
|
async function initialize(options) {
|
|
10
10
|
consola$1.info("Initializing new project");
|
|
@@ -53,8 +53,8 @@ async function initialize(options) {
|
|
|
53
53
|
input.directory ??= options.directory;
|
|
54
54
|
input.template ??= defaultTemplate;
|
|
55
55
|
input.packageManager ??= options.packageManager;
|
|
56
|
-
if (await
|
|
57
|
-
if (!((await
|
|
56
|
+
if (await pathExists(input.directory)) {
|
|
57
|
+
if (!((await readdir(input.directory)).filter((dir) => dir !== ".git").length === 0)) {
|
|
58
58
|
consola$1.error(`The directory ${path.resolve(input.directory)} is not empty. Aborted.`);
|
|
59
59
|
process.exit(1);
|
|
60
60
|
}
|
|
@@ -94,17 +94,17 @@ async function listTemplatesGithub() {
|
|
|
94
94
|
return await res.json();
|
|
95
95
|
}
|
|
96
96
|
async function cloneProject({ directory, template }) {
|
|
97
|
-
const {
|
|
98
|
-
const spinner =
|
|
97
|
+
const { createSpinner } = await import("nanospinner");
|
|
98
|
+
const spinner = createSpinner("Downloading template").start();
|
|
99
99
|
try {
|
|
100
100
|
await downloadTemplate(`gh:${REPO}/${template.path}`, {
|
|
101
101
|
dir: directory,
|
|
102
102
|
force: true
|
|
103
103
|
});
|
|
104
|
-
await
|
|
105
|
-
spinner.
|
|
104
|
+
await rename(path.join(directory, "_gitignore"), path.join(directory, ".gitignore")).catch((err) => consola$1.warn("Failed to move _gitignore to .gitignore:", err));
|
|
105
|
+
spinner.success();
|
|
106
106
|
} catch (err) {
|
|
107
|
-
spinner.
|
|
107
|
+
spinner.error();
|
|
108
108
|
throw Error(`Failed to setup new project: ${JSON.stringify(err, null, 2)}`);
|
|
109
109
|
}
|
|
110
110
|
}
|
|
@@ -121,6 +121,5 @@ const TEMPLATE_SORT_WEIGHT = {
|
|
|
121
121
|
react: 2
|
|
122
122
|
};
|
|
123
123
|
const REPO = "wxt-dev/wxt";
|
|
124
|
-
|
|
125
124
|
//#endregion
|
|
126
|
-
export { initialize };
|
|
125
|
+
export { initialize };
|