wxt 0.19.28 → 0.19.29

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.
@@ -1,4 +1,5 @@
1
1
  import { debounce } from "perfect-debounce";
2
+ import chokidar from "chokidar";
2
3
  import { getEntrypointBundlePath, isHtmlEntrypoint } from "./utils/entrypoints.mjs";
3
4
  import {
4
5
  getContentScriptCssFiles,
@@ -21,6 +22,7 @@ import {
21
22
  mapWxtOptionsToRegisteredContentScript
22
23
  } from "./utils/content-scripts.mjs";
23
24
  import { createKeyboardShortcuts } from "./keyboard-shortcuts.mjs";
25
+ import { isBabelSyntaxError, logBabelSyntaxError } from "./utils/syntax-errors.mjs";
24
26
  export async function createServer(inlineConfig) {
25
27
  await registerWxt("serve", inlineConfig);
26
28
  wxt.server = await createServerInternal();
@@ -116,7 +118,24 @@ async function createServerInternal() {
116
118
  };
117
119
  const keyboardShortcuts = createKeyboardShortcuts(server);
118
120
  const buildAndOpenBrowser = async () => {
119
- server.currentOutput = await internalBuild();
121
+ try {
122
+ server.currentOutput = await internalBuild();
123
+ } catch (err) {
124
+ if (!isBabelSyntaxError(err)) {
125
+ throw err;
126
+ }
127
+ logBabelSyntaxError(err);
128
+ wxt.logger.info("Waiting for syntax error to be fixed...");
129
+ await new Promise((resolve) => {
130
+ const watcher = chokidar.watch(err.id, { ignoreInitial: true });
131
+ watcher.on("all", () => {
132
+ watcher.close();
133
+ wxt.logger.info("Syntax error resolved, rebuilding...");
134
+ resolve();
135
+ });
136
+ });
137
+ return buildAndOpenBrowser();
138
+ }
120
139
  try {
121
140
  server.watcher.add(getExternalOutputDependencies(server));
122
141
  } catch (err) {
@@ -132,7 +151,7 @@ function createFileReloader(server) {
132
151
  const changeQueue = [];
133
152
  const cb = async (event, path) => {
134
153
  changeQueue.push([event, path]);
135
- await fileChangedMutex.runExclusive(async () => {
154
+ const reloading = fileChangedMutex.runExclusive(async () => {
136
155
  if (server.currentOutput == null) return;
137
156
  const fileChanges = changeQueue.splice(0, changeQueue.length).map(([_, file]) => file);
138
157
  if (fileChanges.length === 0) return;
@@ -182,6 +201,12 @@ function createFileReloader(server) {
182
201
  } catch {
183
202
  }
184
203
  });
204
+ await reloading.catch((error) => {
205
+ if (!isBabelSyntaxError(error)) {
206
+ throw error;
207
+ }
208
+ logBabelSyntaxError(error);
209
+ });
185
210
  };
186
211
  return debounce(cb, wxt.config.dev.server.watchDebounce, {
187
212
  leading: true,
@@ -303,11 +303,6 @@ function addEntrypoints(manifest, entrypoints, buildOutput) {
303
303
  const runtimeContentScripts = contentScripts.filter(
304
304
  (cs) => cs.options.registration === "runtime"
305
305
  );
306
- if (runtimeContentScripts.length > 0 && wxt.config.manifestVersion === 2) {
307
- throw Error(
308
- 'Cannot use `registration: "runtime"` with MV2 content scripts, it is a MV3-only feature.'
309
- );
310
- }
311
306
  runtimeContentScripts.forEach((script) => {
312
307
  script.options.matches?.forEach((matchPattern) => {
313
308
  addHostPermission(manifest, matchPattern);
@@ -0,0 +1,11 @@
1
+ export interface BabelSyntaxError extends SyntaxError {
2
+ code: 'BABEL_PARSER_SYNTAX_ERROR';
3
+ frame?: string;
4
+ id: string;
5
+ loc: {
6
+ line: number;
7
+ column: number;
8
+ };
9
+ }
10
+ export declare function isBabelSyntaxError(error: unknown): error is BabelSyntaxError;
11
+ export declare function logBabelSyntaxError(error: BabelSyntaxError): void;
@@ -0,0 +1,20 @@
1
+ import { relative } from "node:path";
2
+ import pc from "picocolors";
3
+ import { wxt } from "../wxt.mjs";
4
+ export function isBabelSyntaxError(error) {
5
+ return error instanceof SyntaxError && error.code === "BABEL_PARSER_SYNTAX_ERROR";
6
+ }
7
+ export function logBabelSyntaxError(error) {
8
+ let filename = relative(wxt.config.root, error.id);
9
+ if (filename.startsWith("..")) {
10
+ filename = error.id;
11
+ }
12
+ let message = error.message.replace(
13
+ /\(\d+:\d+\)$/,
14
+ `(${filename}:${error.loc.line}:${error.loc.column + 1})`
15
+ );
16
+ if (error.frame) {
17
+ message += "\n\n" + pc.red(error.frame);
18
+ }
19
+ wxt.logger.error(message);
20
+ }
package/dist/version.mjs CHANGED
@@ -1 +1 @@
1
- export const version = "0.19.28";
1
+ export const version = "0.19.29";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wxt",
3
3
  "type": "module",
4
- "version": "0.19.28",
4
+ "version": "0.19.29",
5
5
  "description": "⚡ Next-gen Web Extension Framework",
6
6
  "repository": {
7
7
  "type": "git",