wxt 0.20.13 → 0.20.14
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/dist/browser.d.mts +20 -0
- package/dist/browser.mjs +18 -3
- package/dist/builtin-modules/index.mjs +7 -2
- package/dist/builtin-modules/unimport.mjs +69 -75
- package/dist/cli/cli-utils.mjs +52 -50
- package/dist/cli/commands.mjs +77 -103
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +9 -4
- package/dist/core/{build.d.ts → build.d.mts} +6 -2
- package/dist/core/build.mjs +23 -4
- package/dist/core/builders/vite/index.mjs +292 -343
- package/dist/core/builders/vite/plugins/bundleAnalysis.mjs +11 -12
- package/dist/core/builders/vite/plugins/cssEntrypoints.mjs +27 -20
- package/dist/core/builders/vite/plugins/defineImportMeta.mjs +17 -12
- package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +104 -136
- package/dist/core/builders/vite/plugins/devServerGlobals.mjs +15 -14
- package/dist/core/builders/vite/plugins/download.mjs +23 -12
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.mjs +18 -14
- package/dist/core/builders/vite/plugins/extensionApiMock.mjs +31 -33
- package/dist/core/builders/vite/plugins/globals.mjs +14 -13
- package/dist/core/builders/vite/plugins/iifeFooter.mjs +17 -11
- package/dist/core/builders/vite/plugins/index.mjs +18 -16
- package/dist/core/builders/vite/plugins/noopBackground.mjs +21 -15
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +25 -23
- package/dist/core/builders/vite/plugins/resolveAppConfig.mjs +25 -23
- package/dist/core/builders/vite/plugins/resolveVirtualModules.mjs +27 -26
- package/dist/core/builders/vite/plugins/tsconfigPaths.mjs +11 -11
- package/dist/core/builders/vite/plugins/wxtPluginLoader.mjs +41 -47
- package/dist/core/{clean.d.ts → clean.d.mts} +7 -3
- package/dist/core/clean.mjs +38 -35
- package/dist/core/{create-server.d.ts → create-server.d.mts} +6 -2
- package/dist/core/create-server.mjs +236 -247
- package/dist/core/define-config.d.mts +6 -0
- package/dist/core/define-config.mjs +6 -2
- package/dist/core/define-web-ext-config.d.mts +13 -0
- package/dist/core/define-web-ext-config.mjs +16 -7
- package/dist/core/generate-wxt-dir.mjs +109 -148
- package/dist/core/index.d.mts +8 -0
- package/dist/core/index.mjs +10 -8
- package/dist/core/initialize.d.mts +8 -0
- package/dist/core/initialize.mjs +110 -124
- package/dist/core/keyboard-shortcuts.mjs +30 -28
- package/dist/core/package-managers/bun.mjs +18 -16
- package/dist/core/package-managers/deno.mjs +12 -8
- package/dist/core/package-managers/index.mjs +52 -60
- package/dist/core/package-managers/npm.mjs +51 -52
- package/dist/core/package-managers/pnpm.mjs +21 -18
- package/dist/core/package-managers/yarn.mjs +31 -28
- package/dist/core/prepare.d.mts +6 -0
- package/dist/core/prepare.mjs +12 -7
- package/dist/core/resolve-config.mjs +393 -462
- package/dist/core/runners/index.mjs +11 -6
- package/dist/core/runners/manual.mjs +16 -14
- package/dist/core/runners/safari.mjs +16 -14
- package/dist/core/runners/web-ext.mjs +62 -83
- package/dist/core/runners/wsl.mjs +16 -14
- package/dist/core/utils/arrays.mjs +23 -12
- package/dist/core/utils/building/build-entrypoints.mjs +44 -40
- package/dist/core/utils/building/detect-dev-changes.mjs +84 -105
- package/dist/core/utils/building/find-entrypoints.mjs +275 -359
- package/dist/core/utils/building/group-entrypoints.mjs +42 -35
- package/dist/core/utils/building/index.mjs +8 -6
- package/dist/core/utils/building/internal-build.mjs +87 -102
- package/dist/core/utils/building/rebuild.mjs +50 -30
- package/dist/core/utils/cache.mjs +29 -18
- package/dist/core/utils/constants.mjs +9 -1
- package/dist/core/utils/content-scripts.mjs +56 -54
- package/dist/core/utils/content-security-policy.mjs +36 -39
- package/dist/core/utils/entrypoints.mjs +51 -28
- package/dist/core/utils/env.mjs +22 -17
- package/dist/core/utils/environments/browser-environment.mjs +13 -12
- package/dist/core/utils/environments/environment.mjs +36 -33
- package/dist/core/utils/environments/extension-environment.mjs +15 -10
- package/dist/core/utils/environments/index.mjs +4 -2
- package/dist/core/utils/eslint.mjs +11 -10
- package/dist/core/utils/fs.mjs +23 -11
- package/dist/core/utils/globals.mjs +53 -51
- package/dist/core/utils/i18n.mjs +41 -32
- package/dist/core/utils/log/index.mjs +6 -4
- package/dist/core/utils/log/printBuildSummary.mjs +20 -25
- package/dist/core/utils/log/printFileList.mjs +30 -33
- package/dist/core/utils/log/printHeader.mjs +10 -5
- package/dist/core/utils/log/printTable.mjs +19 -21
- package/dist/core/utils/manifest.mjs +364 -479
- package/dist/core/utils/minimatch-multiple.mjs +26 -15
- package/dist/core/utils/network.mjs +30 -33
- package/dist/core/utils/number.mjs +7 -3
- package/dist/core/utils/package.mjs +20 -13
- package/dist/core/utils/paths.mjs +26 -7
- package/dist/core/utils/strings.mjs +19 -14
- package/dist/core/utils/syntax-errors.mjs +14 -16
- package/dist/core/utils/time.mjs +19 -15
- package/dist/core/utils/transform.mjs +129 -160
- package/dist/core/utils/types.d.mts +6 -0
- package/dist/core/utils/validation.mjs +43 -50
- package/dist/core/utils/virtual-modules.mjs +20 -12
- package/dist/core/utils/wsl.mjs +10 -3
- package/dist/core/wxt.mjs +66 -60
- package/dist/core/{zip.d.ts → zip.d.mts} +6 -2
- package/dist/core/zip.mjs +116 -140
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +12 -3
- package/dist/{modules.d.ts → modules.d.mts} +14 -16
- package/dist/modules.mjs +181 -51
- package/dist/testing/fake-browser.d.mts +2 -0
- package/dist/testing/fake-browser.mjs +3 -1
- package/dist/testing/index.d.mts +3 -0
- package/dist/testing/index.mjs +4 -2
- package/dist/testing/{wxt-vitest-plugin.d.ts → wxt-vitest-plugin.d.mts} +7 -9
- package/dist/testing/wxt-vitest-plugin.mjs +38 -19
- package/dist/types.d.mts +1453 -0
- package/dist/utils/app-config.d.mts +6 -0
- package/dist/utils/app-config.mjs +8 -2
- package/dist/utils/content-script-context.d.mts +137 -0
- package/dist/utils/content-script-context.mjs +192 -175
- package/dist/utils/content-script-ui/iframe.d.mts +42 -0
- package/dist/utils/content-script-ui/iframe.mjs +42 -27
- package/dist/utils/content-script-ui/integrated.d.mts +37 -0
- package/dist/utils/content-script-ui/integrated.mjs +36 -29
- package/dist/utils/content-script-ui/shadow-root.d.mts +80 -0
- package/dist/utils/content-script-ui/shadow-root.mjs +75 -82
- package/dist/utils/content-script-ui/shared.mjs +117 -150
- package/dist/utils/content-script-ui/types.d.mts +107 -0
- package/dist/utils/content-script-ui/types.mjs +1 -0
- package/dist/utils/{define-app-config.d.ts → define-app-config.d.mts} +5 -3
- package/dist/utils/define-app-config.mjs +22 -2
- package/dist/utils/define-background.d.mts +7 -0
- package/dist/utils/define-background.mjs +7 -3
- package/dist/utils/define-content-script.d.mts +6 -0
- package/dist/utils/define-content-script.mjs +6 -2
- package/dist/utils/define-unlisted-script.d.mts +7 -0
- package/dist/utils/define-unlisted-script.mjs +7 -3
- package/dist/utils/define-wxt-plugin.d.mts +6 -0
- package/dist/utils/define-wxt-plugin.mjs +6 -2
- package/dist/utils/inject-script.d.mts +41 -0
- package/dist/utils/inject-script.mjs +44 -34
- package/dist/utils/internal/custom-events.d.mts +9 -0
- package/dist/utils/internal/custom-events.mjs +18 -10
- package/dist/utils/internal/location-watcher.mjs +23 -20
- package/dist/utils/internal/logger.mjs +15 -12
- package/dist/utils/match-patterns.d.mts +1 -0
- package/dist/utils/match-patterns.mjs +3 -1
- package/dist/utils/{split-shadow-root-css.d.ts → split-shadow-root-css.d.mts} +6 -3
- package/dist/utils/split-shadow-root-css.mjs +16 -7
- package/dist/utils/storage.d.mts +1 -0
- package/dist/utils/storage.mjs +3 -1
- package/dist/version.d.mts +4 -0
- package/dist/version.mjs +5 -1
- package/dist/virtual/background-entrypoint.d.mts +4 -0
- package/dist/virtual/background-entrypoint.mjs +146 -161
- package/dist/virtual/content-script-isolated-world-entrypoint.d.mts +4 -0
- package/dist/virtual/content-script-isolated-world-entrypoint.mjs +26 -27
- package/dist/virtual/content-script-main-world-entrypoint.d.mts +4 -0
- package/dist/virtual/content-script-main-world-entrypoint.mjs +24 -24
- package/dist/virtual/mock-browser.d.mts +6 -0
- package/dist/virtual/mock-browser.mjs +5 -3
- package/dist/virtual/reload-html.d.mts +1 -0
- package/dist/virtual/reload-html.mjs +60 -53
- package/dist/virtual/unlisted-script-entrypoint.d.mts +4 -0
- package/dist/virtual/unlisted-script-entrypoint.mjs +35 -43
- package/package.json +47 -49
- package/dist/browser.d.ts +0 -30
- package/dist/builtin-modules/index.d.ts +0 -2
- package/dist/builtin-modules/unimport.d.ts +0 -5
- package/dist/cli/cli-utils.d.ts +0 -25
- package/dist/cli/commands.d.ts +0 -2
- package/dist/cli/index.d.ts +0 -1
- package/dist/core/builders/vite/index.d.ts +0 -7
- package/dist/core/builders/vite/plugins/bundleAnalysis.d.ts +0 -7
- package/dist/core/builders/vite/plugins/cssEntrypoints.d.ts +0 -13
- package/dist/core/builders/vite/plugins/defineImportMeta.d.ts +0 -14
- package/dist/core/builders/vite/plugins/devHtmlPrerender.d.ts +0 -7
- package/dist/core/builders/vite/plugins/devServerGlobals.d.ts +0 -6
- package/dist/core/builders/vite/plugins/download.d.ts +0 -10
- package/dist/core/builders/vite/plugins/entrypointGroupGlobals.d.ts +0 -6
- package/dist/core/builders/vite/plugins/extensionApiMock.d.ts +0 -6
- package/dist/core/builders/vite/plugins/globals.d.ts +0 -3
- package/dist/core/builders/vite/plugins/iifeFooter.d.ts +0 -8
- package/dist/core/builders/vite/plugins/index.d.ts +0 -16
- package/dist/core/builders/vite/plugins/noopBackground.d.ts +0 -6
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.d.ts +0 -6
- package/dist/core/builders/vite/plugins/resolveAppConfig.d.ts +0 -6
- package/dist/core/builders/vite/plugins/resolveVirtualModules.d.ts +0 -6
- package/dist/core/builders/vite/plugins/tsconfigPaths.d.ts +0 -3
- package/dist/core/builders/vite/plugins/wxtPluginLoader.d.ts +0 -6
- package/dist/core/define-config.d.ts +0 -2
- package/dist/core/define-web-ext-config.d.ts +0 -9
- package/dist/core/generate-wxt-dir.d.ts +0 -5
- package/dist/core/index.d.ts +0 -8
- package/dist/core/initialize.d.ts +0 -5
- package/dist/core/keyboard-shortcuts.d.ts +0 -12
- package/dist/core/package-managers/bun.d.ts +0 -2
- package/dist/core/package-managers/deno.d.ts +0 -2
- package/dist/core/package-managers/index.d.ts +0 -2
- package/dist/core/package-managers/npm.d.ts +0 -17
- package/dist/core/package-managers/pnpm.d.ts +0 -2
- package/dist/core/package-managers/types.d.ts +0 -2
- package/dist/core/package-managers/types.mjs +0 -0
- package/dist/core/package-managers/yarn.d.ts +0 -2
- package/dist/core/prepare.d.ts +0 -2
- package/dist/core/resolve-config.d.ts +0 -11
- package/dist/core/runners/index.d.ts +0 -2
- package/dist/core/runners/manual.d.ts +0 -5
- package/dist/core/runners/safari.d.ts +0 -5
- package/dist/core/runners/web-ext.d.ts +0 -5
- package/dist/core/runners/wsl.d.ts +0 -5
- package/dist/core/utils/arrays.d.ts +0 -13
- package/dist/core/utils/building/build-entrypoints.d.ts +0 -3
- package/dist/core/utils/building/detect-dev-changes.d.ts +0 -61
- package/dist/core/utils/building/find-entrypoints.d.ts +0 -5
- package/dist/core/utils/building/group-entrypoints.d.ts +0 -8
- package/dist/core/utils/building/index.d.ts +0 -6
- package/dist/core/utils/building/internal-build.d.ts +0 -12
- package/dist/core/utils/building/rebuild.d.ts +0 -23
- package/dist/core/utils/cache.d.ts +0 -8
- package/dist/core/utils/cli.d.ts +0 -3
- package/dist/core/utils/cli.mjs +0 -26
- package/dist/core/utils/constants.d.ts +0 -5
- package/dist/core/utils/content-scripts.d.ts +0 -12
- package/dist/core/utils/content-security-policy.d.ts +0 -14
- package/dist/core/utils/entrypoints.d.ts +0 -31
- package/dist/core/utils/env.d.ts +0 -5
- package/dist/core/utils/environments/browser-environment.d.ts +0 -3
- package/dist/core/utils/environments/environment.d.ts +0 -8
- package/dist/core/utils/environments/extension-environment.d.ts +0 -6
- package/dist/core/utils/environments/index.d.ts +0 -2
- package/dist/core/utils/eslint.d.ts +0 -1
- package/dist/core/utils/fs.d.ts +0 -13
- package/dist/core/utils/globals.d.ts +0 -11
- package/dist/core/utils/i18n.d.ts +0 -11
- package/dist/core/utils/log/index.d.ts +0 -4
- package/dist/core/utils/log/printBuildSummary.d.ts +0 -2
- package/dist/core/utils/log/printFileList.d.ts +0 -1
- package/dist/core/utils/log/printHeader.d.ts +0 -1
- package/dist/core/utils/log/printTable.d.ts +0 -1
- package/dist/core/utils/manifest.d.ts +0 -40
- package/dist/core/utils/minimatch-multiple.d.ts +0 -15
- package/dist/core/utils/network.d.ts +0 -7
- package/dist/core/utils/number.d.ts +0 -1
- package/dist/core/utils/package.d.ts +0 -6
- package/dist/core/utils/paths.d.ts +0 -11
- package/dist/core/utils/strings.d.ts +0 -14
- package/dist/core/utils/syntax-errors.d.ts +0 -11
- package/dist/core/utils/testing/fake-objects.d.ts +0 -11665
- package/dist/core/utils/testing/fake-objects.mjs +0 -326
- package/dist/core/utils/time.d.ts +0 -9
- package/dist/core/utils/transform.d.ts +0 -11
- package/dist/core/utils/types.d.ts +0 -13
- package/dist/core/utils/types.mjs +0 -0
- package/dist/core/utils/validation.d.ts +0 -15
- package/dist/core/utils/virtual-modules.d.ts +0 -22
- package/dist/core/utils/wsl.d.ts +0 -4
- package/dist/core/wxt.d.ts +0 -24
- package/dist/index.d.ts +0 -11
- package/dist/testing/fake-browser.d.ts +0 -10
- package/dist/testing/index.d.ts +0 -10
- package/dist/types.d.ts +0 -1459
- package/dist/types.mjs +0 -0
- package/dist/utils/app-config.d.ts +0 -2
- package/dist/utils/content-script-context.d.ts +0 -134
- package/dist/utils/content-script-ui/iframe.d.ts +0 -32
- package/dist/utils/content-script-ui/integrated.d.ts +0 -34
- package/dist/utils/content-script-ui/shadow-root.d.ts +0 -76
- package/dist/utils/content-script-ui/shared.d.ts +0 -5
- package/dist/utils/content-script-ui/types.d.ts +0 -104
- package/dist/utils/define-background.d.ts +0 -4
- package/dist/utils/define-content-script.d.ts +0 -3
- package/dist/utils/define-unlisted-script.d.ts +0 -4
- package/dist/utils/define-wxt-plugin.d.ts +0 -3
- package/dist/utils/inject-script.d.ts +0 -36
- package/dist/utils/internal/custom-events.d.ts +0 -10
- package/dist/utils/internal/dev-server-websocket.d.ts +0 -21
- package/dist/utils/internal/dev-server-websocket.mjs +0 -37
- package/dist/utils/internal/location-watcher.d.ts +0 -12
- package/dist/utils/internal/logger.d.ts +0 -9
- package/dist/utils/match-patterns.d.ts +0 -5
- package/dist/utils/storage.d.ts +0 -5
- package/dist/version.d.ts +0 -1
|
@@ -1,36 +1,59 @@
|
|
|
1
|
-
import path, { relative, resolve, extname } from "node:path";
|
|
2
1
|
import { normalizePath } from "./paths.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import path, { extname, relative, resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
//#region src/core/utils/entrypoints.ts
|
|
5
|
+
function getEntrypointName(entrypointsDir, inputPath) {
|
|
6
|
+
return path.relative(entrypointsDir, inputPath).split(/[./\\]/, 2)[0];
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
function getEntrypointOutputFile(entrypoint, ext) {
|
|
9
|
+
return resolve(entrypoint.outputDir, `${entrypoint.name}${ext}`);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Return's the entrypoint's output path relative to the output directory. Used for paths in the
|
|
13
|
+
* manifest and rollup's bundle.
|
|
14
|
+
*/
|
|
15
|
+
function getEntrypointBundlePath(entrypoint, outDir, ext) {
|
|
16
|
+
return normalizePath(relative(outDir, getEntrypointOutputFile(entrypoint, ext)));
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Given an entrypoint option, resolve it's value based on a target browser.
|
|
20
|
+
*/
|
|
21
|
+
function resolvePerBrowserOption(option, browser) {
|
|
22
|
+
if (typeof option === "object" && !Array.isArray(option)) return option[browser];
|
|
23
|
+
return option;
|
|
20
24
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Given an entrypoint option, resolve it's value based on a target browser.
|
|
27
|
+
*
|
|
28
|
+
* defaultIcon is special, it's the only key that's a record, which can confuse this function. So
|
|
29
|
+
* it's been manually excluded from resolution.
|
|
30
|
+
*/
|
|
31
|
+
function resolvePerBrowserOptions(options, browser) {
|
|
32
|
+
return Object.fromEntries(Object.entries(options).map(([key, value]) => [key, key === "defaultIcon" ? value : resolvePerBrowserOption(value, browser)]));
|
|
28
33
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Returns true when the entrypoint is an HTML entrypoint.
|
|
36
|
+
*
|
|
37
|
+
* Naively just checking the file extension of the input path.
|
|
38
|
+
*/
|
|
39
|
+
function isHtmlEntrypoint(entrypoint) {
|
|
40
|
+
const ext = extname(entrypoint.inputPath);
|
|
41
|
+
return [".html"].includes(ext);
|
|
32
42
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Returns true when the entrypoint is a JS entrypoint.
|
|
45
|
+
*
|
|
46
|
+
* Naively just checking the file extension of the input path.
|
|
47
|
+
*/
|
|
48
|
+
function isJsEntrypoint(entrypoint) {
|
|
49
|
+
const ext = extname(entrypoint.inputPath);
|
|
50
|
+
return [
|
|
51
|
+
".js",
|
|
52
|
+
".jsx",
|
|
53
|
+
".ts",
|
|
54
|
+
".tsx"
|
|
55
|
+
].includes(ext);
|
|
36
56
|
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { getEntrypointBundlePath, getEntrypointName, isHtmlEntrypoint, isJsEntrypoint, resolvePerBrowserOptions };
|
package/dist/core/utils/env.mjs
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import { config } from "dotenv";
|
|
2
2
|
import { expand } from "dotenv-expand";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
|
|
4
|
+
//#region src/core/utils/env.ts
|
|
5
|
+
/**
|
|
6
|
+
* Load environment files based on the current mode and browser.
|
|
7
|
+
*/
|
|
8
|
+
function loadEnv(mode, browser) {
|
|
9
|
+
return expand(config({
|
|
10
|
+
quiet: true,
|
|
11
|
+
path: [
|
|
12
|
+
`.env.${mode}.${browser}.local`,
|
|
13
|
+
`.env.${mode}.${browser}`,
|
|
14
|
+
`.env.${browser}.local`,
|
|
15
|
+
`.env.${browser}`,
|
|
16
|
+
`.env.${mode}.local`,
|
|
17
|
+
`.env.${mode}`,
|
|
18
|
+
`.env.local`,
|
|
19
|
+
`.env`
|
|
20
|
+
]
|
|
21
|
+
}));
|
|
20
22
|
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { loadEnv };
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { parseHTML } from "linkedom";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
export function getBrowserEnvironmentGlobals() {
|
|
7
|
-
const { window, document, global } = parseHTML(`
|
|
2
|
+
|
|
3
|
+
//#region src/core/utils/environments/browser-environment.ts
|
|
4
|
+
function getBrowserEnvironmentGlobals() {
|
|
5
|
+
const { window, document, global } = parseHTML(`
|
|
8
6
|
<html>
|
|
9
7
|
<head></head>
|
|
10
8
|
<body></body>
|
|
11
9
|
</html>
|
|
12
10
|
`);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
return {
|
|
12
|
+
...global,
|
|
13
|
+
window,
|
|
14
|
+
document,
|
|
15
|
+
self: global
|
|
16
|
+
};
|
|
19
17
|
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { getBrowserEnvironmentGlobals };
|
|
@@ -1,36 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
//#region src/core/utils/environments/environment.ts
|
|
2
|
+
function createEnvironment(getGlobals) {
|
|
3
|
+
const setup = () => {
|
|
4
|
+
const envGlobals = getGlobals();
|
|
5
|
+
const ogGlobals = getOgGlobals(envGlobals);
|
|
6
|
+
applyGlobals(envGlobals);
|
|
7
|
+
return () => {
|
|
8
|
+
applyGlobals(ogGlobals);
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
const run = async (fn) => {
|
|
12
|
+
const teardown = setup();
|
|
13
|
+
try {
|
|
14
|
+
return await fn();
|
|
15
|
+
} finally {
|
|
16
|
+
teardown();
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
setup,
|
|
21
|
+
run
|
|
22
|
+
};
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
function getOgGlobals(envGlobals) {
|
|
25
|
+
return Object.keys(envGlobals).reduce((acc, key) => {
|
|
26
|
+
acc[key] = globalThis[key];
|
|
27
|
+
return acc;
|
|
28
|
+
}, {});
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
30
|
+
function applyGlobals(globals) {
|
|
31
|
+
Object.entries(globals).forEach(([key, envValue]) => {
|
|
32
|
+
try {
|
|
33
|
+
globalThis[key] = envValue;
|
|
34
|
+
} catch {}
|
|
35
|
+
});
|
|
36
36
|
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { createEnvironment };
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import { fakeBrowser } from "@webext-core/fake-browser";
|
|
2
|
-
import { getBrowserEnvironmentGlobals } from "./browser-environment.mjs";
|
|
3
1
|
import { createEnvironment } from "./environment.mjs";
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { getBrowserEnvironmentGlobals } from "./browser-environment.mjs";
|
|
3
|
+
import { fakeBrowser } from "@webext-core/fake-browser";
|
|
4
|
+
|
|
5
|
+
//#region src/core/utils/environments/extension-environment.ts
|
|
6
|
+
function createExtensionEnvironment() {
|
|
7
|
+
return createEnvironment(getExtensionEnvironmentGlobals);
|
|
6
8
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
function getExtensionEnvironmentGlobals() {
|
|
10
|
+
return {
|
|
11
|
+
...getBrowserEnvironmentGlobals(),
|
|
12
|
+
chrome: fakeBrowser,
|
|
13
|
+
browser: fakeBrowser
|
|
14
|
+
};
|
|
13
15
|
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { createExtensionEnvironment, getExtensionEnvironmentGlobals };
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { getBrowserEnvironmentGlobals } from "./browser-environment.mjs";
|
|
2
|
+
import { createExtensionEnvironment, getExtensionEnvironmentGlobals } from "./extension-environment.mjs";
|
|
3
|
+
|
|
4
|
+
export { };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return [];
|
|
10
|
-
}
|
|
1
|
+
//#region src/core/utils/eslint.ts
|
|
2
|
+
async function getEslintVersion() {
|
|
3
|
+
try {
|
|
4
|
+
const { ESLint } = (await import("node:module")).default.createRequire(import.meta.url)("eslint");
|
|
5
|
+
return ESLint.version?.split(".") ?? [];
|
|
6
|
+
} catch {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
11
9
|
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { getEslintVersion };
|
package/dist/core/utils/fs.mjs
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
import fs from "fs-extra";
|
|
2
|
-
import glob from "fast-glob";
|
|
3
1
|
import { unnormalizePath } from "./paths.mjs";
|
|
4
2
|
import { wxt } from "../wxt.mjs";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import glob from "fast-glob";
|
|
5
|
+
|
|
6
|
+
//#region src/core/utils/fs.ts
|
|
7
|
+
/**
|
|
8
|
+
* Only write the contents to a file if it results in a change. This prevents unnecessary file
|
|
9
|
+
* watchers from being triggered, like WXT's dev server or the TS language server in editors.
|
|
10
|
+
*
|
|
11
|
+
* @param file The file to write to.
|
|
12
|
+
* @param newContents The new text content to write.
|
|
13
|
+
*/
|
|
14
|
+
async function writeFileIfDifferent(file, newContents) {
|
|
15
|
+
if (await fs.readFile(file, "utf-8").catch(() => void 0) !== newContents) await fs.writeFile(file, newContents);
|
|
10
16
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Get all the files in the project's public directory. Returned paths are relative to the
|
|
19
|
+
* `config.publicDir`.
|
|
20
|
+
*/
|
|
21
|
+
async function getPublicFiles() {
|
|
22
|
+
if (!await fs.exists(wxt.config.publicDir)) return [];
|
|
23
|
+
return (await glob("**/*", { cwd: wxt.config.publicDir })).map(unnormalizePath);
|
|
15
24
|
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { getPublicFiles, writeFileIfDifferent };
|
|
@@ -1,53 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
1
|
+
//#region src/core/utils/globals.ts
|
|
2
|
+
function getGlobals(config) {
|
|
3
|
+
return [
|
|
4
|
+
{
|
|
5
|
+
name: "MANIFEST_VERSION",
|
|
6
|
+
value: config.manifestVersion,
|
|
7
|
+
type: `2 | 3`
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
name: "BROWSER",
|
|
11
|
+
value: config.browser,
|
|
12
|
+
type: config.targetBrowsers.length === 0 ? "string" : config.targetBrowsers.map((browser) => `"${browser}"`).join(" | ")
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "CHROME",
|
|
16
|
+
value: config.browser === "chrome",
|
|
17
|
+
type: `boolean`
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "FIREFOX",
|
|
21
|
+
value: config.browser === "firefox",
|
|
22
|
+
type: `boolean`
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "SAFARI",
|
|
26
|
+
value: config.browser === "safari",
|
|
27
|
+
type: `boolean`
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "EDGE",
|
|
31
|
+
value: config.browser === "edge",
|
|
32
|
+
type: `boolean`
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "OPERA",
|
|
36
|
+
value: config.browser === "opera",
|
|
37
|
+
type: `boolean`
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "COMMAND",
|
|
41
|
+
value: config.command,
|
|
42
|
+
type: `"build" | "serve"`
|
|
43
|
+
}
|
|
44
|
+
];
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
];
|
|
46
|
+
function getEntrypointGlobals(entrypointName) {
|
|
47
|
+
return [{
|
|
48
|
+
name: "ENTRYPOINT",
|
|
49
|
+
value: entrypointName,
|
|
50
|
+
type: `string`
|
|
51
|
+
}];
|
|
53
52
|
}
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
export { getEntrypointGlobals, getGlobals };
|
package/dist/core/utils/i18n.mjs
CHANGED
|
@@ -1,35 +1,44 @@
|
|
|
1
|
+
//#region src/core/utils/i18n.ts
|
|
1
2
|
const predefinedMessages = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
3
|
+
"@@extension_id": {
|
|
4
|
+
message: "<browser.runtime.id>",
|
|
5
|
+
description: "The extension or app ID; you might use this string to construct URLs for resources inside the extension. Even unlocalized extensions can use this message.\nNote: You can't use this message in a manifest file."
|
|
6
|
+
},
|
|
7
|
+
"@@ui_locale": {
|
|
8
|
+
message: "<browser.i18n.getUiLocale()>",
|
|
9
|
+
description: ""
|
|
10
|
+
},
|
|
11
|
+
"@@bidi_dir": {
|
|
12
|
+
message: "<ltr|rtl>",
|
|
13
|
+
description: "The text direction for the current locale, either \"ltr\" for left-to-right languages such as English or \"rtl\" for right-to-left languages such as Japanese."
|
|
14
|
+
},
|
|
15
|
+
"@@bidi_reversed_dir": {
|
|
16
|
+
message: "<rtl|ltr>",
|
|
17
|
+
description: "If the @@bidi_dir is \"ltr\", then this is \"rtl\"; otherwise, it's \"ltr\"."
|
|
18
|
+
},
|
|
19
|
+
"@@bidi_start_edge": {
|
|
20
|
+
message: "<left|right>",
|
|
21
|
+
description: "If the @@bidi_dir is \"ltr\", then this is \"left\"; otherwise, it's \"right\"."
|
|
22
|
+
},
|
|
23
|
+
"@@bidi_end_edge": {
|
|
24
|
+
message: "<right|left>",
|
|
25
|
+
description: "If the @@bidi_dir is \"ltr\", then this is \"right\"; otherwise, it's \"left\"."
|
|
26
|
+
}
|
|
26
27
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Get a list of all messages and their metadata from JSON file contents.
|
|
30
|
+
*
|
|
31
|
+
* @param messagesJson The contents of a `_locales/en/messages.json` file.
|
|
32
|
+
*/
|
|
33
|
+
function parseI18nMessages(messagesJson) {
|
|
34
|
+
return Object.entries({
|
|
35
|
+
...predefinedMessages,
|
|
36
|
+
...messagesJson
|
|
37
|
+
}).map(([name, details]) => ({
|
|
38
|
+
name,
|
|
39
|
+
...details
|
|
40
|
+
}));
|
|
35
41
|
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { parseI18nMessages };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { printTable } from "./printTable.mjs";
|
|
2
|
+
import { printFileList } from "./printFileList.mjs";
|
|
3
|
+
import { printBuildSummary } from "./printBuildSummary.mjs";
|
|
4
|
+
import { printHeader } from "./printHeader.mjs";
|
|
5
|
+
|
|
6
|
+
export { };
|
|
@@ -1,32 +1,27 @@
|
|
|
1
|
-
import { resolve } from "path";
|
|
2
|
-
import { printFileList } from "./printFileList.mjs";
|
|
3
1
|
import { wxt } from "../../wxt.mjs";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const files = chunks.map(
|
|
16
|
-
(chunk) => resolve(wxt.config.outDir, chunk.fileName)
|
|
17
|
-
);
|
|
18
|
-
await printFileList(log, header, wxt.config.outDir, files);
|
|
2
|
+
import { printFileList } from "./printFileList.mjs";
|
|
3
|
+
import { resolve } from "path";
|
|
4
|
+
|
|
5
|
+
//#region src/core/utils/log/printBuildSummary.ts
|
|
6
|
+
async function printBuildSummary(log, header, output) {
|
|
7
|
+
const files = [...output.steps.flatMap((step) => step.chunks), ...output.publicAssets].sort((l, r) => {
|
|
8
|
+
const diff = getChunkSortWeight(l.fileName) - getChunkSortWeight(r.fileName);
|
|
9
|
+
if (diff !== 0) return diff;
|
|
10
|
+
return l.fileName.localeCompare(r.fileName);
|
|
11
|
+
}).map((chunk) => resolve(wxt.config.outDir, chunk.fileName));
|
|
12
|
+
await printFileList(log, header, wxt.config.outDir, files);
|
|
19
13
|
}
|
|
20
14
|
const DEFAULT_SORT_WEIGHT = 100;
|
|
21
15
|
const CHUNK_SORT_WEIGHTS = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
"manifest.json": 0,
|
|
17
|
+
".html": 1,
|
|
18
|
+
".js.map": 2,
|
|
19
|
+
".js": 2,
|
|
20
|
+
".css": 3
|
|
27
21
|
};
|
|
28
22
|
function getChunkSortWeight(filename) {
|
|
29
|
-
|
|
30
|
-
([key]) => filename.endsWith(key)
|
|
31
|
-
)?.[1] ?? DEFAULT_SORT_WEIGHT;
|
|
23
|
+
return Object.entries(CHUNK_SORT_WEIGHTS).find(([key]) => filename.endsWith(key))?.[1] ?? DEFAULT_SORT_WEIGHT;
|
|
32
24
|
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { printBuildSummary };
|