@tbox.cn/app-build 1.0.0-alpha.19 → 1.0.0-alpha.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-build",
3
- "version": "1.0.0-alpha.19",
3
+ "version": "1.0.0-alpha.21",
4
4
  "type": "module",
5
5
  "description": "tbox-app 1.0 build-time leaf: scan apps/ modules/ and generate manifest, registries, documents; Vite plugin and checks.",
6
6
  "exports": {
@@ -100,21 +100,45 @@ try {
100
100
  watch: { buildDelay: 300 },
101
101
  },
102
102
  });
103
+ // end 单飞:BUNDLE_END 与竞态补偿共用;BUNDLE_START 归零供下一轮重建上报。
104
+ let endSent = false;
105
+ const notifyEnd = (durationMs) => {
106
+ if (endSent) return;
107
+ endSent = true;
108
+ send({ tbox: 'static-build', v: 1, type: 'end', durationMs });
109
+ };
110
+ const publishAndNotify = (durationMs) => {
111
+ if (endSent) return;
112
+ try {
113
+ publish();
114
+ notifyEnd(durationMs);
115
+ } catch (err) {
116
+ fail('publish', err?.message ?? err);
117
+ }
118
+ };
103
119
  watcher.on('event', (event) => {
104
120
  if (closing) return;
105
121
  if (event.code === 'BUNDLE_START') {
122
+ endSent = false;
106
123
  send({ tbox: 'static-build', v: 1, type: 'start' });
107
124
  } else if (event.code === 'BUNDLE_END') {
108
- try {
109
- publish();
110
- send({ tbox: 'static-build', v: 1, type: 'end', durationMs: event.duration });
111
- } catch (err) {
112
- fail('publish', err?.message ?? err);
113
- }
125
+ publishAndNotify(event.duration);
114
126
  } else if (event.code === 'ERROR') {
115
127
  fail('build', event.error?.message ?? event.error);
116
128
  }
117
129
  });
130
+ // 竞态补偿:极快机器上首轮 BUNDLE_START/END 可能在监听器挂载前已发完(构建已完成但
131
+ // publish 未执行)——挂载后短暂轮询,staging 有完整产物且 end 未上报则补发一次。
132
+ void (async () => {
133
+ for (let i = 0; i < 12 && !closing && !endSent; i++) {
134
+ await new Promise((r) => setTimeout(r, 250));
135
+ if (closing || endSent) return;
136
+ if (existsSync(path.join(staging, 'index.html'))) {
137
+ publishAndNotify(0);
138
+ return;
139
+ }
140
+ }
141
+ })();
118
142
  } catch (err) {
119
143
  fail('build', err?.message ?? err);
120
144
  process.exit(1);