@open-wxa/wxa-runner-core 0.12.2 → 0.12.3

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/index.d.mts CHANGED
@@ -359,6 +359,8 @@ declare class DevServer {
359
359
  private socketProxy;
360
360
  private sockets;
361
361
  private watcher;
362
+ /** 上次编译失败时页面上显示着错误,修好后整页刷新才能清掉 */
363
+ private lastBuildFailed;
362
364
  private address;
363
365
  private lanAccess;
364
366
  /** 运行时生成的临时文件(canvas 导出、拍照等),随服务器进程存在 */
@@ -388,6 +390,7 @@ declare class DevServer {
388
390
  private runtimeDir;
389
391
  /** 只在监听文件变化时打开基础库的热更新开关,跑测试(watch: false)时运行环境与真机一致 */
390
392
  private get hotEnabled();
393
+ /** 返回初次扫描完成的时刻,此前已存在的文件不会作为改动报告 */
391
394
  private startWatching;
392
395
  private broadcast;
393
396
  }
package/dist/index.d.ts CHANGED
@@ -359,6 +359,8 @@ declare class DevServer {
359
359
  private socketProxy;
360
360
  private sockets;
361
361
  private watcher;
362
+ /** 上次编译失败时页面上显示着错误,修好后整页刷新才能清掉 */
363
+ private lastBuildFailed;
362
364
  private address;
363
365
  private lanAccess;
364
366
  /** 运行时生成的临时文件(canvas 导出、拍照等),随服务器进程存在 */
@@ -388,6 +390,7 @@ declare class DevServer {
388
390
  private runtimeDir;
389
391
  /** 只在监听文件变化时打开基础库的热更新开关,跑测试(watch: false)时运行环境与真机一致 */
390
392
  private get hotEnabled();
393
+ /** 返回初次扫描完成的时刻,此前已存在的文件不会作为改动报告 */
391
394
  private startWatching;
392
395
  private broadcast;
393
396
  }
package/dist/index.js CHANGED
@@ -642,8 +642,8 @@ var AppBuilder = class {
642
642
  this.pending = { covers: this.changes, result: result2 };
643
643
  }
644
644
  const { covers, result } = this.pending;
645
- const built = await result;
646
- if (covers >= wanted) return built;
645
+ if (covers >= wanted) return result;
646
+ await result.catch(() => void 0);
647
647
  }
648
648
  }
649
649
  /**
@@ -2036,6 +2036,8 @@ var DevServer = class {
2036
2036
  this.socketProxy = null;
2037
2037
  this.sockets = null;
2038
2038
  this.watcher = null;
2039
+ /** 上次编译失败时页面上显示着错误,修好后整页刷新才能清掉 */
2040
+ this.lastBuildFailed = false;
2039
2041
  this.address = "";
2040
2042
  this.lanAccess = false;
2041
2043
  /** 运行时生成的临时文件(canvas 导出、拍照等),随服务器进程存在 */
@@ -2079,10 +2081,12 @@ var DevServer = class {
2079
2081
  return Object.values(import_os3.default.networkInterfaces()).flat().filter((net2) => net2 && net2.family === "IPv4" && !net2.internal).map((net2) => `http://${net2.address}:${port}`);
2080
2082
  }
2081
2083
  async start() {
2084
+ if (this.options.watch !== false) await this.startWatching();
2082
2085
  try {
2083
2086
  const build2 = await this.builder.build();
2084
2087
  this.logger.log(`[wxa-runner] \u7F16\u8BD1\u5B8C\u6210\uFF1A${build2.pages.length} \u4E2A\u9875\u9762\uFF0C${build2.components.length} \u4E2A\u7EC4\u4EF6\uFF0C${build2.durationMs}ms`);
2085
2088
  } catch (error) {
2089
+ this.lastBuildFailed = true;
2086
2090
  this.logger.error(`[wxa-runner] \u7F16\u8BD1\u5931\u8D25\uFF1A
2087
2091
  ${error.message}`);
2088
2092
  }
@@ -2105,11 +2109,17 @@ ${error.message}`);
2105
2109
  }
2106
2110
  });
2107
2111
  const host = this.options.host || "localhost";
2108
- const port = await listen(server, this.options.port, host, this.logger);
2112
+ let port;
2113
+ try {
2114
+ port = await listen(server, this.options.port, host, this.logger);
2115
+ } catch (error) {
2116
+ await this.watcher?.close();
2117
+ this.watcher = null;
2118
+ throw error;
2119
+ }
2109
2120
  this.server = server;
2110
2121
  this.lanAccess = LOCAL_HOST_OF_ANY_ADDRESS.has(host);
2111
2122
  this.address = `http://${LOCAL_HOST_OF_ANY_ADDRESS.get(host) ?? host}:${port}`;
2112
- if (this.options.watch !== false) this.startWatching();
2113
2123
  this.ticketSource?.().then(requireUsableTicket).catch((error) => this.logger.warn(`[wxa-runner] \u5F00\u53D1\u8005\u5DE5\u5177\u7684\u767B\u5F55\u6001\u6682\u4E0D\u53EF\u7528\uFF08--devtools-login\uFF09\uFF1A${error.message}`));
2114
2124
  return this.address;
2115
2125
  }
@@ -2346,31 +2356,32 @@ ${error.message}`);
2346
2356
  get hotEnabled() {
2347
2357
  return this.options.watch !== false;
2348
2358
  }
2359
+ /** 返回初次扫描完成的时刻,此前已存在的文件不会作为改动报告 */
2349
2360
  startWatching() {
2350
- let lastBuildFailed = false;
2351
2361
  const watched = [this.project.root];
2352
2362
  const outsideRoot = (file) => import_path6.default.relative(this.project.root, file).startsWith("..");
2353
2363
  if (this.setupFile && outsideRoot(this.setupFile)) watched.push(this.setupFile);
2354
2364
  const projectConfig = import_path6.default.join(this.project.projectPath, "project.config.json");
2355
2365
  if (outsideRoot(projectConfig) && import_fs6.default.existsSync(projectConfig)) watched.push(projectConfig);
2356
2366
  this.watcher = watchProject(this.project.root, watched, async ({ files, structural }) => {
2357
- const reloadOnly = structural || lastBuildFailed;
2367
+ const reloadOnly = structural || this.lastBuildFailed;
2358
2368
  this.builder.invalidate(files);
2359
2369
  const label = files.length > 3 ? `${files.slice(0, 3).join(", ")} \u7B49 ${files.length} \u4E2A\u6587\u4EF6` : files.join(", ");
2360
2370
  try {
2361
2371
  const build2 = await this.builder.build();
2362
- lastBuildFailed = false;
2372
+ this.lastBuildFailed = false;
2363
2373
  const plan = reloadOnly ? null : planHotUpdate(files, build2);
2364
2374
  this.logger.log(`[wxa-runner] ${label} \u5DF2\u66F4\u65B0\uFF0C\u91CD\u65B0\u7F16\u8BD1 ${build2.durationMs}ms${plan ? "\uFF0C\u70ED\u66F4\u65B0" : ""}`);
2365
2375
  this.broadcast(plan ? { type: "hot", version: build2.version, ...plan } : { type: "reload" });
2366
2376
  } catch (error) {
2367
- lastBuildFailed = true;
2377
+ this.lastBuildFailed = true;
2368
2378
  const message = error.message;
2369
2379
  this.logger.error(`[wxa-runner] \u7F16\u8BD1\u5931\u8D25\uFF1A
2370
2380
  ${message}`);
2371
2381
  this.broadcast({ type: "error", message });
2372
2382
  }
2373
2383
  });
2384
+ return this.watcher.ready;
2374
2385
  }
2375
2386
  broadcast(message) {
2376
2387
  const data = JSON.stringify(message);