@bb-labs/bldr 0.0.4 → 0.0.5
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.js +81 -24
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -66,14 +66,32 @@ function run(cmd, args, cwd) {
|
|
|
66
66
|
return new Promise((resolve, reject) => {
|
|
67
67
|
const p = spawn(cmd, args, {
|
|
68
68
|
cwd,
|
|
69
|
-
stdio: "inherit",
|
|
69
|
+
stdio: ["inherit", "pipe", "pipe"], // pipe both stdout and stderr to capture all output
|
|
70
70
|
shell: process.platform === "win32",
|
|
71
71
|
});
|
|
72
|
+
let stdout = "";
|
|
73
|
+
let stderr = "";
|
|
74
|
+
if (p.stdout) {
|
|
75
|
+
p.stdout.on("data", (data) => {
|
|
76
|
+
stdout += data.toString();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (p.stderr) {
|
|
80
|
+
p.stderr.on("data", (data) => {
|
|
81
|
+
stderr += data.toString();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
72
84
|
p.on("exit", (code) => {
|
|
73
85
|
if (code === 0)
|
|
74
86
|
resolve();
|
|
75
|
-
else
|
|
76
|
-
|
|
87
|
+
else {
|
|
88
|
+
// Give a small delay to ensure all output data is captured
|
|
89
|
+
setTimeout(() => {
|
|
90
|
+
const allOutput = (stdout + stderr).trim();
|
|
91
|
+
const errorMsg = allOutput || `${cmd} ${args.join(" ")} failed with exit code ${code}`;
|
|
92
|
+
reject(new Error(errorMsg));
|
|
93
|
+
}, 100);
|
|
94
|
+
}
|
|
77
95
|
});
|
|
78
96
|
});
|
|
79
97
|
}
|
|
@@ -189,9 +207,11 @@ async function main() {
|
|
|
189
207
|
});
|
|
190
208
|
// Create a function to log to the bldr box
|
|
191
209
|
logToBldr = (text) => {
|
|
192
|
-
bldrBox
|
|
193
|
-
|
|
194
|
-
|
|
210
|
+
if (screen && bldrBox) {
|
|
211
|
+
bldrBox.insertBottom(text);
|
|
212
|
+
bldrBox.setScrollPerc(100);
|
|
213
|
+
screen.render();
|
|
214
|
+
}
|
|
195
215
|
};
|
|
196
216
|
// Override console.log and console.error for bldr messages
|
|
197
217
|
const originalLog = console.log;
|
|
@@ -218,6 +238,42 @@ async function main() {
|
|
|
218
238
|
await rmIfExists(outDirAbs);
|
|
219
239
|
const tscArgs = ["-p", tsconfigPath];
|
|
220
240
|
const aliasArgs = ["-p", tsconfigPath];
|
|
241
|
+
// Error handling function for watch mode
|
|
242
|
+
const handleFatalError = async (errorMessage) => {
|
|
243
|
+
// Always restore normal console logging for watch mode
|
|
244
|
+
if (args.watch) {
|
|
245
|
+
// Destroy UI first to avoid conflicts
|
|
246
|
+
if (screen) {
|
|
247
|
+
screen.destroy();
|
|
248
|
+
screen = null;
|
|
249
|
+
bldrBox = null;
|
|
250
|
+
tscBox = null;
|
|
251
|
+
aliasBox = null;
|
|
252
|
+
}
|
|
253
|
+
// Write directly to stderr to ensure visibility
|
|
254
|
+
process.stderr.write(`[bldr] ${errorMessage}\n`);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
// In build mode, just print normally
|
|
258
|
+
console.error(`[bldr] ${errorMessage}`);
|
|
259
|
+
}
|
|
260
|
+
// Kill all processes
|
|
261
|
+
if (tscWatch && !tscWatch.killed) {
|
|
262
|
+
tscWatch.kill();
|
|
263
|
+
}
|
|
264
|
+
if (aliasWatch && !aliasWatch.killed) {
|
|
265
|
+
aliasWatch.kill();
|
|
266
|
+
}
|
|
267
|
+
if (srcWatcher) {
|
|
268
|
+
try {
|
|
269
|
+
await srcWatcher.close();
|
|
270
|
+
}
|
|
271
|
+
catch (e) {
|
|
272
|
+
// ignore
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
process.exit(1);
|
|
276
|
+
};
|
|
221
277
|
if (!args.watch) {
|
|
222
278
|
// One-shot build: tsc -> tsc-alias
|
|
223
279
|
try {
|
|
@@ -240,9 +296,7 @@ async function main() {
|
|
|
240
296
|
await run("tsc-alias", aliasArgs, cwd);
|
|
241
297
|
}
|
|
242
298
|
catch (error) {
|
|
243
|
-
|
|
244
|
-
// Continue in watch mode even if initial build fails
|
|
245
|
-
console.log(`[bldr] continuing in watch mode...`);
|
|
299
|
+
await handleFatalError(`[bldr] initial build failed: ${error}`);
|
|
246
300
|
}
|
|
247
301
|
// 3) Start watchers
|
|
248
302
|
const tscWatch = spawnLongRunning("tsc", [...tscArgs, "-w"], cwd);
|
|
@@ -290,12 +344,10 @@ async function main() {
|
|
|
290
344
|
}
|
|
291
345
|
// If any child process errors or exits, shut down all processes
|
|
292
346
|
tscWatch.on("error", (error) => {
|
|
293
|
-
|
|
294
|
-
shutdown();
|
|
347
|
+
handleFatalError(`[bldr] tsc watcher error: ${error}`);
|
|
295
348
|
});
|
|
296
349
|
aliasWatch.on("error", (error) => {
|
|
297
|
-
|
|
298
|
-
shutdown();
|
|
350
|
+
handleFatalError(`[bldr] tsc-alias watcher error: ${error}`);
|
|
299
351
|
});
|
|
300
352
|
// 3) dist sync watcher: remove stale outputs on deletes/dir deletes
|
|
301
353
|
const cleaner = makeDistCleaner(rootDirAbs, outDirAbs);
|
|
@@ -349,20 +401,25 @@ async function main() {
|
|
|
349
401
|
});
|
|
350
402
|
// TypeScript compiler handles additions and changes automatically
|
|
351
403
|
const shutdown = async () => {
|
|
352
|
-
|
|
353
|
-
// Destroy screen
|
|
354
|
-
screen
|
|
404
|
+
console.log("\n[bldr] shutting down...");
|
|
405
|
+
// Destroy screen if it exists
|
|
406
|
+
if (screen) {
|
|
407
|
+
screen.destroy();
|
|
408
|
+
screen = null;
|
|
409
|
+
}
|
|
355
410
|
// Close file watcher
|
|
356
411
|
try {
|
|
357
|
-
|
|
358
|
-
|
|
412
|
+
if (srcWatcher) {
|
|
413
|
+
await srcWatcher.close();
|
|
414
|
+
}
|
|
415
|
+
console.log("[bldr] src watcher closed");
|
|
359
416
|
}
|
|
360
417
|
catch (error) {
|
|
361
|
-
|
|
418
|
+
console.error(`[bldr] error closing src watcher: ${error}`);
|
|
362
419
|
}
|
|
363
420
|
// Kill child processes
|
|
364
421
|
const killPromises = [];
|
|
365
|
-
if (!tscWatch.killed) {
|
|
422
|
+
if (tscWatch && !tscWatch.killed) {
|
|
366
423
|
killPromises.push(new Promise((resolve) => {
|
|
367
424
|
tscWatch.on("exit", () => resolve());
|
|
368
425
|
tscWatch.kill();
|
|
@@ -374,9 +431,9 @@ async function main() {
|
|
|
374
431
|
resolve();
|
|
375
432
|
}, 5000);
|
|
376
433
|
}));
|
|
377
|
-
|
|
434
|
+
console.log("[bldr] killing tsc watcher...");
|
|
378
435
|
}
|
|
379
|
-
if (!aliasWatch.killed) {
|
|
436
|
+
if (aliasWatch && !aliasWatch.killed) {
|
|
380
437
|
killPromises.push(new Promise((resolve) => {
|
|
381
438
|
aliasWatch.on("exit", () => resolve());
|
|
382
439
|
aliasWatch.kill();
|
|
@@ -388,11 +445,11 @@ async function main() {
|
|
|
388
445
|
resolve();
|
|
389
446
|
}, 5000);
|
|
390
447
|
}));
|
|
391
|
-
|
|
448
|
+
console.log("[bldr] killing tsc-alias watcher...");
|
|
392
449
|
}
|
|
393
450
|
// Wait for all child processes to exit
|
|
394
451
|
await Promise.all(killPromises);
|
|
395
|
-
|
|
452
|
+
console.log("[bldr] all processes cleaned up");
|
|
396
453
|
process.exit(0);
|
|
397
454
|
};
|
|
398
455
|
process.on("SIGINT", shutdown);
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bb-labs/bldr",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"bin": {
|
|
5
6
|
"bldr": "./dist/index.js"
|
|
6
7
|
},
|
|
@@ -10,8 +11,8 @@
|
|
|
10
11
|
"scripts": {
|
|
11
12
|
"build": "tsc",
|
|
12
13
|
"postbuild": "chmod +x dist/index.js",
|
|
13
|
-
"test:build": "
|
|
14
|
-
"test:watch": "
|
|
14
|
+
"test:build": "node dist/index.js --project test-src/tsconfig.json",
|
|
15
|
+
"test:watch": "node dist/index.js --watch --project test-src/tsconfig.json"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
18
|
"@types/blessed": "^0.1.27",
|