wxt 0.20.27 → 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/dist/cli/cli-utils.mjs +2 -2
- package/dist/core/builders/vite/index.mjs +85 -46
- package/dist/core/builders/vite/plugins/devHtmlPrerender.mjs +1 -1
- package/dist/core/builders/vite/plugins/index.mjs +0 -1
- package/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs +1 -1
- package/dist/core/clean.d.mts +0 -11
- package/dist/core/clean.mjs +9 -2
- package/dist/core/create-server.mjs +12 -11
- package/dist/core/define-web-ext-config.d.mts +1 -3
- package/dist/core/define-web-ext-config.mjs +1 -7
- package/dist/core/generate-wxt-dir.mjs +27 -25
- package/dist/core/index.d.mts +3 -2
- package/dist/core/index.mjs +1 -0
- package/dist/core/initialize.mjs +5 -5
- package/dist/core/resolve-config.mjs +40 -24
- package/dist/core/runners/web-ext.mjs +6 -5
- package/dist/core/utils/building/detect-dev-changes.mjs +17 -7
- package/dist/core/utils/building/internal-build.mjs +1 -1
- package/dist/core/utils/create-file-reloader.mjs +82 -27
- package/dist/core/utils/entrypoints.d.mts +10 -0
- package/dist/core/utils/index.d.mts +2 -0
- package/dist/core/utils/index.mjs +1 -0
- package/dist/core/utils/time.mjs +1 -10
- package/dist/core/utils/transform.mjs +1 -1
- package/dist/core/zip.mjs +15 -11
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +3 -2
- package/dist/testing/wxt-vitest-plugin.mjs +0 -2
- package/dist/types.d.mts +102 -41
- package/dist/utils/app-config.d.mts +1 -0
- package/dist/utils/app-config.mjs +2 -0
- package/dist/utils/content-script-ui/shadow-root.mjs +1 -1
- package/dist/version.mjs +1 -1
- package/dist/virtual/mock-browser.d.mts +1 -1
- package/dist/virtual/mock-browser.mjs +1 -1
- package/package.json +22 -20
- package/dist/core/builders/vite/plugins/download.mjs +0 -30
- package/dist/core/runners/index.mjs +0 -15
- package/dist/core/utils/network.mjs +0 -36
- package/dist/core/utils/picomatch-multiple.mjs +0 -24
- package/dist/core/utils/wsl.mjs +0 -8
- package/dist/testing/index.d.mts +0 -3
- package/dist/testing/index.mjs +0 -3
package/README.md
CHANGED
|
@@ -54,7 +54,6 @@ Or see the [installation guide](https://wxt.dev/guide/installation.html) to get
|
|
|
54
54
|
- 📦 [Module system](https://wxt.dev/guide/essentials/wxt-modules.html#overview) for reusing code between extensions
|
|
55
55
|
- 🖍️ Quickly bootstrap a new project
|
|
56
56
|
- 📏 Bundle analysis
|
|
57
|
-
- ⬇️ Download and bundle remote URL imports
|
|
58
57
|
|
|
59
58
|
## Sponsors
|
|
60
59
|
|
package/dist/cli/cli-utils.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { filterTruthy, toArray } from "../core/utils/arrays.mjs";
|
|
2
|
-
import { formatDuration } from "../core/utils/time.mjs";
|
|
3
2
|
import { registerWxt } from "../core/wxt.mjs";
|
|
3
|
+
import { formatDuration } from "../core/utils/time.mjs";
|
|
4
4
|
import { printHeader } from "../core/utils/log/printHeader.mjs";
|
|
5
5
|
import "../core/utils/log/index.mjs";
|
|
6
6
|
import { ValidationError } from "../core/utils/validation.mjs";
|
|
7
|
-
import consola, { LogLevels } from "consola";
|
|
8
7
|
import spawn from "nano-spawn";
|
|
8
|
+
import consola, { LogLevels } from "consola";
|
|
9
9
|
//#region src/cli/cli-utils.ts
|
|
10
10
|
/**
|
|
11
11
|
* Wrap an action handler to add a timer, error handling, and maybe enable debug
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { normalizePath } from "../../utils/paths.mjs";
|
|
2
|
+
import { getEntrypointBundlePath, isHtmlEntrypoint } from "../../utils/entrypoints.mjs";
|
|
2
3
|
import "../../utils/index.mjs";
|
|
3
4
|
import { toArray } from "../../utils/arrays.mjs";
|
|
4
|
-
import { getEntrypointBundlePath, isHtmlEntrypoint } from "../../utils/entrypoints.mjs";
|
|
5
5
|
import { createExtensionEnvironment } from "../../utils/environments/extension-environment.mjs";
|
|
6
6
|
import "../../utils/environments/index.mjs";
|
|
7
7
|
import { safeVarName } from "../../utils/strings.mjs";
|
|
8
8
|
import { devHtmlPrerender } from "./plugins/devHtmlPrerender.mjs";
|
|
9
9
|
import { devServerGlobals } from "./plugins/devServerGlobals.mjs";
|
|
10
|
-
import { download } from "./plugins/download.mjs";
|
|
11
10
|
import { resolveVirtualModules } from "./plugins/resolveVirtualModules.mjs";
|
|
12
11
|
import { tsconfigPaths } from "./plugins/tsconfigPaths.mjs";
|
|
13
12
|
import { noopBackground } from "./plugins/noopBackground.mjs";
|
|
@@ -23,10 +22,7 @@ import { iifeFooter } from "./plugins/iifeFooter.mjs";
|
|
|
23
22
|
import { iifeAnonymous } from "./plugins/iifeAnonymous.mjs";
|
|
24
23
|
import "./plugins/index.mjs";
|
|
25
24
|
import { mkdir, readdir, rename, rmdir, stat } from "node:fs/promises";
|
|
26
|
-
import { dirname, extname, join, relative } from "node:path";
|
|
27
|
-
import { ViteNodeRunner } from "vite-node/client";
|
|
28
|
-
import { ViteNodeServer } from "vite-node/server";
|
|
29
|
-
import { installSourcemapsSupport } from "vite-node/source-map";
|
|
25
|
+
import { dirname, extname, join, relative, resolve } from "node:path";
|
|
30
26
|
//#region src/core/builders/vite/index.ts
|
|
31
27
|
async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
|
|
32
28
|
const vite = await import("vite");
|
|
@@ -49,7 +45,15 @@ async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
|
|
|
49
45
|
if (config.build.minify == null && wxtConfig.command === "serve") config.build.minify = false;
|
|
50
46
|
if (config.build.sourcemap == null && wxtConfig.command === "serve") config.build.sourcemap = "inline";
|
|
51
47
|
config.server ??= {};
|
|
52
|
-
config.server.watch = {
|
|
48
|
+
config.server.watch = {
|
|
49
|
+
...wxtConfig.watchOptions,
|
|
50
|
+
ignored: [
|
|
51
|
+
`${wxtConfig.outBaseDir}/**`,
|
|
52
|
+
`${wxtConfig.wxtDir}/**`,
|
|
53
|
+
...getRunnerProfileWatchIgnores(wxtConfig),
|
|
54
|
+
...toArray(wxtConfig.watchOptions.ignored ?? [])
|
|
55
|
+
]
|
|
56
|
+
};
|
|
53
57
|
config.legacy ??= {};
|
|
54
58
|
config.legacy.skipWebSocketTokenCheck = true;
|
|
55
59
|
if (isRolldownVersion(vite.version)) {} else {
|
|
@@ -58,7 +62,7 @@ async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
|
|
|
58
62
|
}
|
|
59
63
|
const server = getWxtDevServer?.();
|
|
60
64
|
config.plugins ??= [];
|
|
61
|
-
config.plugins.push(
|
|
65
|
+
config.plugins.push(devHtmlPrerender(wxtConfig, server), resolveVirtualModules(wxtConfig), devServerGlobals(wxtConfig, server), tsconfigPaths(wxtConfig), noopBackground(), globals(wxtConfig), defineImportMeta(), wxtPluginLoader(wxtConfig), resolveAppConfig(wxtConfig));
|
|
62
66
|
if (wxtConfig.analysis.enabled && !baseConfigOptions?.excludeAnalysisPlugin) config.plugins.push(bundleAnalysis(wxtConfig));
|
|
63
67
|
return config;
|
|
64
68
|
};
|
|
@@ -74,7 +78,7 @@ async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
|
|
|
74
78
|
if (entrypoint.type === "content-script" || entrypoint.type === "unlisted-script") {
|
|
75
79
|
if (typeof entrypoint.options.globalName === "string") iifeReturnValueName = entrypoint.options.globalName;
|
|
76
80
|
else if (typeof entrypoint.options.globalName === "function") iifeReturnValueName = entrypoint.options.globalName(entrypoint);
|
|
77
|
-
if (entrypoint.options.globalName
|
|
81
|
+
if (!entrypoint.options.globalName) plugins.push(iifeAnonymous(iifeReturnValueName));
|
|
78
82
|
else plugins.push(iifeFooter(iifeReturnValueName));
|
|
79
83
|
}
|
|
80
84
|
return {
|
|
@@ -89,8 +93,8 @@ async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
|
|
|
89
93
|
},
|
|
90
94
|
rollupOptions: { output: {
|
|
91
95
|
entryFileNames: getEntrypointBundlePath(entrypoint, wxtConfig.outDir, ".js"),
|
|
92
|
-
assetFileNames: (
|
|
93
|
-
if (entrypoint.type === "content-script" && name
|
|
96
|
+
assetFileNames: (assetInfo) => {
|
|
97
|
+
if (entrypoint.type === "content-script" && getRollupAssetNames(assetInfo).some((name) => name.endsWith("css"))) return `content-scripts/${entrypoint.name}.[ext]`;
|
|
94
98
|
else return `assets/${entrypoint.name}.[ext]`;
|
|
95
99
|
}
|
|
96
100
|
} }
|
|
@@ -140,59 +144,60 @@ async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
|
|
|
140
144
|
} }
|
|
141
145
|
};
|
|
142
146
|
};
|
|
143
|
-
const
|
|
147
|
+
const createImporterEnvironment = async (paths) => {
|
|
144
148
|
const baseConfig = await getBaseConfig({ excludeAnalysisPlugin: true });
|
|
145
149
|
baseConfig.optimizeDeps ??= {};
|
|
146
150
|
baseConfig.optimizeDeps.noDiscovery = true;
|
|
147
151
|
baseConfig.optimizeDeps.include = [];
|
|
148
152
|
const envConfig = { plugins: paths.map((path) => removeEntrypointMainFunction(wxtConfig, path)) };
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
resolveId(id, importer) {
|
|
162
|
-
return node.resolveId(id, importer);
|
|
153
|
+
const importerConfig = vite.mergeConfig(baseConfig, envConfig);
|
|
154
|
+
const config = await vite.resolveConfig(vite.mergeConfig(importerConfig || {}, {
|
|
155
|
+
configFile: false,
|
|
156
|
+
envDir: false,
|
|
157
|
+
cacheDir: process.cwd(),
|
|
158
|
+
environments: { inline: {
|
|
159
|
+
consumer: "server",
|
|
160
|
+
dev: { moduleRunnerTransform: true },
|
|
161
|
+
resolve: {
|
|
162
|
+
external: true,
|
|
163
|
+
mainFields: [],
|
|
164
|
+
conditions: ["node"]
|
|
163
165
|
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
166
|
+
} }
|
|
167
|
+
}), "serve");
|
|
168
|
+
const environment = vite.createRunnableDevEnvironment("inline", config, {
|
|
169
|
+
runnerOptions: { hmr: { logger: false } },
|
|
170
|
+
hot: false
|
|
171
|
+
});
|
|
172
|
+
await environment.init();
|
|
173
|
+
return environment;
|
|
167
174
|
};
|
|
168
|
-
|
|
175
|
+
function requireDefaultExport(path, mod) {
|
|
169
176
|
const relativePath = relative(wxtConfig.root, path);
|
|
170
177
|
if (mod?.default == null) {
|
|
171
178
|
const defineFn = relativePath.includes(".content") ? "defineContentScript" : relativePath.includes("background") ? "defineBackground" : "defineUnlistedScript";
|
|
172
179
|
throw Error(`${relativePath}: Default export not found, did you forget to call "export default ${defineFn}(...)"?`);
|
|
173
180
|
}
|
|
174
|
-
}
|
|
181
|
+
}
|
|
175
182
|
return {
|
|
176
183
|
name: "Vite",
|
|
177
184
|
version: vite.version,
|
|
178
185
|
async importEntrypoint(path) {
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
const res = await env.run(() => runner.executeFile(path));
|
|
182
|
-
await server.close();
|
|
183
|
-
requireDefaultExport(path, res);
|
|
184
|
-
return res.default;
|
|
186
|
+
const [module] = await this.importEntrypoints([path]);
|
|
187
|
+
return module;
|
|
185
188
|
},
|
|
186
189
|
async importEntrypoints(paths) {
|
|
187
|
-
const
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
190
|
+
const context = createExtensionEnvironment();
|
|
191
|
+
const environment = await createImporterEnvironment(paths);
|
|
192
|
+
try {
|
|
193
|
+
return await context.run(async () => await Promise.all(paths.map(async (path) => {
|
|
194
|
+
const module = await environment.runner.import(path);
|
|
195
|
+
requireDefaultExport(path, module);
|
|
196
|
+
return module.default;
|
|
197
|
+
})));
|
|
198
|
+
} finally {
|
|
199
|
+
await environment.close();
|
|
200
|
+
}
|
|
196
201
|
},
|
|
197
202
|
async build(group) {
|
|
198
203
|
let entryConfig;
|
|
@@ -243,6 +248,40 @@ async function createViteBuilder(wxtConfig, hooks, getWxtDevServer) {
|
|
|
243
248
|
}
|
|
244
249
|
};
|
|
245
250
|
}
|
|
251
|
+
function getRunnerProfileWatchIgnores(wxtConfig) {
|
|
252
|
+
const root = normalizePath(wxtConfig.root);
|
|
253
|
+
const chromiumArgProfiles = extractPathArgs(wxtConfig.webExt.config?.chromiumArgs, "--user-data-dir");
|
|
254
|
+
const firefoxArgProfiles = extractPathArgs(wxtConfig.webExt.config?.firefoxArgs, "-profile");
|
|
255
|
+
const profiles = [
|
|
256
|
+
wxtConfig.webExt.config?.chromiumProfile,
|
|
257
|
+
wxtConfig.webExt.config?.firefoxProfile,
|
|
258
|
+
...chromiumArgProfiles,
|
|
259
|
+
...firefoxArgProfiles
|
|
260
|
+
].filter((profile) => typeof profile === "string");
|
|
261
|
+
return Array.from(new Set(profiles.map((profile) => normalizePath(resolve(wxtConfig.root, profile))).filter((profilePath) => profilePath !== root).map((profilePath) => `${profilePath}/**`)));
|
|
262
|
+
}
|
|
263
|
+
function extractPathArgs(args, flag) {
|
|
264
|
+
if (!args?.length) return [];
|
|
265
|
+
const paths = [];
|
|
266
|
+
for (let i = 0; i < args.length; i++) {
|
|
267
|
+
const arg = args[i];
|
|
268
|
+
if (arg.startsWith(`${flag}=`)) {
|
|
269
|
+
const value = arg.slice(flag.length + 1).trim();
|
|
270
|
+
if (value) paths.push(value);
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
if (arg === flag) {
|
|
274
|
+
const nextValue = args[i + 1]?.trim();
|
|
275
|
+
if (nextValue) paths.push(nextValue);
|
|
276
|
+
i += 1;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return paths;
|
|
280
|
+
}
|
|
281
|
+
function getRollupAssetNames(assetInfo) {
|
|
282
|
+
if (Array.isArray(assetInfo.names)) return assetInfo.names;
|
|
283
|
+
return assetInfo.name ? [assetInfo.name] : [];
|
|
284
|
+
}
|
|
246
285
|
function getBuildOutputChunks(result) {
|
|
247
286
|
if ("on" in result) throw Error("wxt does not support vite watch mode.");
|
|
248
287
|
if (Array.isArray(result)) return result.flatMap(({ output }) => output);
|
|
@@ -1,6 +1,6 @@
|
|
|
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";
|
|
@@ -16,7 +16,7 @@ function removeEntrypointMainFunction(config, path) {
|
|
|
16
16
|
filter: { id: new RegExp(`^${absPath}$`) },
|
|
17
17
|
handler(code) {
|
|
18
18
|
const newCode = removeMainFunctionCode(code);
|
|
19
|
-
config.logger.debug("
|
|
19
|
+
config.logger.debug("transformed entrypoint", path);
|
|
20
20
|
config.logger.debug(`Original:\n---\n${code}\n---`);
|
|
21
21
|
config.logger.debug(`Transformed:\n---\n${newCode.code}\n---`);
|
|
22
22
|
return newCode;
|
package/dist/core/clean.d.mts
CHANGED
|
@@ -10,16 +10,5 @@ import { InlineConfig } from "../types.mjs";
|
|
|
10
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
|
-
/**
|
|
14
|
-
* Remove generated/temp files from the directory.
|
|
15
|
-
*
|
|
16
|
-
* @deprecated
|
|
17
|
-
* @example
|
|
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
|
-
*/
|
|
23
|
-
declare function clean(root?: string): Promise<void>;
|
|
24
13
|
//#endregion
|
|
25
14
|
export { clean };
|
package/dist/core/clean.mjs
CHANGED
|
@@ -4,15 +4,22 @@ import { glob } from "tinyglobby";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { styleText } from "node:util";
|
|
6
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
|
+
*/
|
|
7
15
|
async function clean(config) {
|
|
8
|
-
if (typeof config === "string") config = { root: config };
|
|
9
16
|
await registerWxt("build", config);
|
|
10
17
|
wxt.logger.info("Cleaning Project");
|
|
11
18
|
const root = wxt.config.root;
|
|
12
19
|
const tempDirs = [
|
|
13
20
|
"node_modules/.vite",
|
|
14
21
|
"node_modules/.cache",
|
|
15
|
-
"
|
|
22
|
+
"{,**/}.wxt",
|
|
16
23
|
`${path.relative(root, wxt.config.outBaseDir)}/*`
|
|
17
24
|
];
|
|
18
25
|
wxt.logger.debug("Looking for:", tempDirs.map((dir) => styleText("cyan", dir)).join(", "));
|
|
@@ -2,7 +2,6 @@ import { unnormalizePath } from "./utils/paths.mjs";
|
|
|
2
2
|
import { deinitWxtModules, initWxtModules, registerWxt, wxt } from "./wxt.mjs";
|
|
3
3
|
import { internalBuild } from "./utils/building/internal-build.mjs";
|
|
4
4
|
import "./utils/building/index.mjs";
|
|
5
|
-
import { createExtensionRunner } from "./runners/index.mjs";
|
|
6
5
|
import { createKeyboardShortcuts } from "./keyboard-shortcuts.mjs";
|
|
7
6
|
import { isBabelSyntaxError, logBabelSyntaxError } from "./utils/syntax-errors.mjs";
|
|
8
7
|
import { createFileReloader, reloadContentScripts } from "./utils/create-file-reloader.mjs";
|
|
@@ -33,7 +32,7 @@ async function createServerInternal() {
|
|
|
33
32
|
origin
|
|
34
33
|
};
|
|
35
34
|
};
|
|
36
|
-
let
|
|
35
|
+
let builderServer = await wxt.builder.createServer(getServerInfo());
|
|
37
36
|
let wasStopped = false;
|
|
38
37
|
const server = {
|
|
39
38
|
get host() {
|
|
@@ -55,7 +54,6 @@ async function createServerInternal() {
|
|
|
55
54
|
async start() {
|
|
56
55
|
if (wasStopped) {
|
|
57
56
|
await wxt.reloadConfig();
|
|
58
|
-
runner = await createExtensionRunner();
|
|
59
57
|
builderServer = await wxt.builder.createServer(getServerInfo());
|
|
60
58
|
await initWxtModules();
|
|
61
59
|
}
|
|
@@ -71,14 +69,12 @@ async function createServerInternal() {
|
|
|
71
69
|
const reloadOnChange = createFileReloader(server);
|
|
72
70
|
server.watcher.on("all", async (...args) => {
|
|
73
71
|
await reloadOnChange(args[0], args[1]);
|
|
74
|
-
keyboardShortcuts.start();
|
|
75
72
|
});
|
|
76
|
-
keyboardShortcuts.printHelp({ canReopenBrowser: !wxt.config.runnerConfig.config.disabled && !!runner.canOpen?.() });
|
|
77
73
|
},
|
|
78
74
|
async stop() {
|
|
79
75
|
wasStopped = true;
|
|
80
76
|
keyboardShortcuts.stop();
|
|
81
|
-
await runner.closeBrowser?.();
|
|
77
|
+
await wxt.config.runner.closeBrowser?.();
|
|
82
78
|
await builderServer.close();
|
|
83
79
|
await wxt.hooks.callHook("server:closed", wxt, server);
|
|
84
80
|
deinitWxtModules();
|
|
@@ -101,12 +97,12 @@ async function createServerInternal() {
|
|
|
101
97
|
server.ws.send("wxt:reload-extension");
|
|
102
98
|
},
|
|
103
99
|
async restartBrowser() {
|
|
104
|
-
await runner.closeBrowser?.();
|
|
100
|
+
await wxt.config.runner.closeBrowser?.();
|
|
105
101
|
keyboardShortcuts.stop();
|
|
106
102
|
await wxt.reloadConfig();
|
|
107
|
-
|
|
108
|
-
await runner.openBrowser();
|
|
103
|
+
await wxt.config.runner.openBrowser();
|
|
109
104
|
keyboardShortcuts.start();
|
|
105
|
+
keyboardShortcuts.printHelp({ canReopenBrowser: !wxt.config.webExt.config.disabled && !!wxt.config.runner.canOpen?.() });
|
|
110
106
|
}
|
|
111
107
|
};
|
|
112
108
|
const keyboardShortcuts = createKeyboardShortcuts(server);
|
|
@@ -118,7 +114,10 @@ async function createServerInternal() {
|
|
|
118
114
|
logBabelSyntaxError(err);
|
|
119
115
|
wxt.logger.info("Waiting for syntax error to be fixed...");
|
|
120
116
|
await new Promise((resolve) => {
|
|
121
|
-
const watcher = chokidar.watch(err.id, {
|
|
117
|
+
const watcher = chokidar.watch(err.id, {
|
|
118
|
+
...wxt.config.watchOptions,
|
|
119
|
+
ignoreInitial: true
|
|
120
|
+
});
|
|
122
121
|
watcher.on("all", () => {
|
|
123
122
|
watcher.close();
|
|
124
123
|
wxt.logger.info("Syntax error resolved, rebuilding...");
|
|
@@ -132,7 +131,9 @@ async function createServerInternal() {
|
|
|
132
131
|
} catch (err) {
|
|
133
132
|
wxt.config.logger.warn("Failed to register additional file paths:", err);
|
|
134
133
|
}
|
|
135
|
-
await runner.openBrowser();
|
|
134
|
+
await wxt.config.runner.openBrowser();
|
|
135
|
+
keyboardShortcuts.start();
|
|
136
|
+
keyboardShortcuts.printHelp({ canReopenBrowser: !wxt.config.webExt.config.disabled && !!wxt.config.runner.canOpen?.() });
|
|
136
137
|
};
|
|
137
138
|
builderServer.on?.("close", () => keyboardShortcuts.stop());
|
|
138
139
|
return server;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { WebExtConfig } from "../types.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/core/define-web-ext-config.d.ts
|
|
4
|
-
/** @deprecated Use `defineWebExtConfig` instead. Same function, different name. */
|
|
5
|
-
declare function defineRunnerConfig(config: WebExtConfig): WebExtConfig;
|
|
6
4
|
/**
|
|
7
5
|
* Configure how [`web-ext`](https://github.com/mozilla/web-ext) starts the
|
|
8
6
|
* browser during development.
|
|
9
7
|
*/
|
|
10
8
|
declare function defineWebExtConfig(config: WebExtConfig): WebExtConfig;
|
|
11
9
|
//#endregion
|
|
12
|
-
export {
|
|
10
|
+
export { defineWebExtConfig };
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import consola from "consola";
|
|
2
1
|
//#region src/core/define-web-ext-config.ts
|
|
3
|
-
/** @deprecated Use `defineWebExtConfig` instead. Same function, different name. */
|
|
4
|
-
function defineRunnerConfig(config) {
|
|
5
|
-
consola.warn("`defineRunnerConfig` is deprecated, use `defineWebExtConfig` instead. See https://wxt.dev/guide/resources/upgrading.html#v0-19-0-rarr-v0-20-0");
|
|
6
|
-
return defineWebExtConfig(config);
|
|
7
|
-
}
|
|
8
2
|
/**
|
|
9
3
|
* Configure how [`web-ext`](https://github.com/mozilla/web-ext) starts the
|
|
10
4
|
* browser during development.
|
|
@@ -13,4 +7,4 @@ function defineWebExtConfig(config) {
|
|
|
13
7
|
return config;
|
|
14
8
|
}
|
|
15
9
|
//#endregion
|
|
16
|
-
export {
|
|
10
|
+
export { defineWebExtConfig };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { normalizePath } from "./utils/paths.mjs";
|
|
2
|
-
import "./utils/index.mjs";
|
|
3
2
|
import { getEntrypointBundlePath, isHtmlEntrypoint } from "./utils/entrypoints.mjs";
|
|
3
|
+
import "./utils/index.mjs";
|
|
4
4
|
import { getEntrypointGlobals, getGlobals } from "./utils/globals.mjs";
|
|
5
5
|
import { wxt } from "./wxt.mjs";
|
|
6
6
|
import { getPublicFiles, pathExists, writeFileIfDifferent } from "./utils/fs.mjs";
|
|
@@ -167,32 +167,34 @@ async function getTsConfigEntry() {
|
|
|
167
167
|
if (res.startsWith(".") || res.startsWith("/")) return res;
|
|
168
168
|
return "./" + res;
|
|
169
169
|
};
|
|
170
|
+
const tsconfig = {
|
|
171
|
+
compilerOptions: {
|
|
172
|
+
lib: [
|
|
173
|
+
"ESNext",
|
|
174
|
+
"DOM",
|
|
175
|
+
"DOM.Iterable"
|
|
176
|
+
],
|
|
177
|
+
target: "ESNext",
|
|
178
|
+
module: "Preserve",
|
|
179
|
+
moduleDetection: "force",
|
|
180
|
+
moduleResolution: "Bundler",
|
|
181
|
+
allowImportingTsExtensions: true,
|
|
182
|
+
verbatimModuleSyntax: true,
|
|
183
|
+
noEmit: true,
|
|
184
|
+
strict: true,
|
|
185
|
+
skipLibCheck: true,
|
|
186
|
+
noFallthroughCasesInSwitch: true,
|
|
187
|
+
noUncheckedIndexedAccess: true,
|
|
188
|
+
noImplicitOverride: true,
|
|
189
|
+
paths: Object.fromEntries(Object.entries(wxt.config.alias).map(([alias, absolutePath]) => [alias, getTsconfigPath(absolutePath)]).flatMap(([alias, path]) => [[alias, [path]], [alias + "/*", [path + "/*"]]]))
|
|
190
|
+
},
|
|
191
|
+
include: [`${getTsconfigPath(wxt.config.root)}/**/*`, "./wxt.d.ts"],
|
|
192
|
+
exclude: [getTsconfigPath(wxt.config.root) + "/**/node_modules", getTsconfigPath(wxt.config.outBaseDir)]
|
|
193
|
+
};
|
|
194
|
+
await wxt.hooks.callHook("prepare:tsconfig", wxt, { tsconfig });
|
|
170
195
|
return {
|
|
171
196
|
path: "tsconfig.json",
|
|
172
|
-
text:
|
|
173
|
-
"compilerOptions": {
|
|
174
|
-
"target": "ESNext",
|
|
175
|
-
"module": "ESNext",
|
|
176
|
-
"moduleResolution": "Bundler",
|
|
177
|
-
"noEmit": true,
|
|
178
|
-
"esModuleInterop": true,
|
|
179
|
-
"forceConsistentCasingInFileNames": true,
|
|
180
|
-
"resolveJsonModule": true,
|
|
181
|
-
"strict": true,
|
|
182
|
-
"skipLibCheck": true,
|
|
183
|
-
"paths": {
|
|
184
|
-
${Object.entries(wxt.config.alias).flatMap(([alias, absolutePath]) => {
|
|
185
|
-
const aliasPath = getTsconfigPath(absolutePath);
|
|
186
|
-
return [`"${alias}": ["${aliasPath}"]`, `"${alias}/*": ["${aliasPath}/*"]`];
|
|
187
|
-
}).map((line) => ` ${line}`).join(",\n")}
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
"include": [
|
|
191
|
-
"${getTsconfigPath(wxt.config.root)}/**/*",
|
|
192
|
-
"./wxt.d.ts"
|
|
193
|
-
],
|
|
194
|
-
"exclude": ["${getTsconfigPath(wxt.config.outBaseDir)}"]
|
|
195
|
-
}`
|
|
197
|
+
text: JSON.stringify(tsconfig, null, 2)
|
|
196
198
|
};
|
|
197
199
|
}
|
|
198
200
|
//#endregion
|
package/dist/core/index.d.mts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { build } from "./build.mjs";
|
|
2
2
|
import { clean } from "./clean.mjs";
|
|
3
3
|
import { defineConfig } from "./define-config.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { defineWebExtConfig } from "./define-web-ext-config.mjs";
|
|
5
5
|
import { createServer } from "./create-server.mjs";
|
|
6
6
|
import { initialize } from "./initialize.mjs";
|
|
7
7
|
import { prepare } from "./prepare.mjs";
|
|
8
8
|
import { zip } from "./zip.mjs";
|
|
9
|
-
import { normalizePath } from "./utils/paths.mjs";
|
|
9
|
+
import { normalizePath } from "./utils/paths.mjs";
|
|
10
|
+
import { getEntrypointBundlePath } from "./utils/entrypoints.mjs";
|
package/dist/core/index.mjs
CHANGED
package/dist/core/initialize.mjs
CHANGED
|
@@ -31,6 +31,10 @@ async function initialize(options) {
|
|
|
31
31
|
type: () => options.packageManager == null ? "select" : void 0,
|
|
32
32
|
message: "Package Manager",
|
|
33
33
|
choices: [
|
|
34
|
+
{
|
|
35
|
+
title: styleText("magenta", "bun"),
|
|
36
|
+
value: "bun"
|
|
37
|
+
},
|
|
34
38
|
{
|
|
35
39
|
title: styleText("red", "npm"),
|
|
36
40
|
value: "npm"
|
|
@@ -42,15 +46,11 @@ async function initialize(options) {
|
|
|
42
46
|
{
|
|
43
47
|
title: styleText("cyan", "yarn"),
|
|
44
48
|
value: "yarn"
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
title: styleText("magenta", "bun"),
|
|
48
|
-
value: "bun"
|
|
49
49
|
}
|
|
50
50
|
]
|
|
51
51
|
}
|
|
52
52
|
], { onCancel: () => process.exit(1) });
|
|
53
|
-
input.directory
|
|
53
|
+
input.directory ||= options.directory || ".";
|
|
54
54
|
input.template ??= defaultTemplate;
|
|
55
55
|
input.packageManager ??= options.packageManager;
|
|
56
56
|
if (await pathExists(input.directory)) {
|