bunosh 0.4.10 → 0.4.13
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/bunosh.js +4 -22
- package/package.json +1 -1
- package/src/io.js +1 -1
- package/src/printer.js +37 -0
- package/src/task.js +6 -5
- package/src/tasks/exec.js +17 -4
- package/src/tasks/fetch.js +12 -2
- package/src/tasks/shell.js +12 -2
package/bunosh.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
1
|
|
|
3
2
|
// Set up global variables BEFORE any imports
|
|
4
3
|
globalThis._bunoshStartTime = Date.now();
|
|
@@ -326,8 +325,11 @@ process.on('exit', (code) => {
|
|
|
326
325
|
const tasksWarning = tasksExecuted.filter(ti => ti.result?.status === TaskStatus.WARNING).length;
|
|
327
326
|
|
|
328
327
|
const commandArgs = process.argv.slice(2);
|
|
328
|
+
|
|
329
|
+
// Test environment detection
|
|
329
330
|
const isTestEnvironment = process.env.NODE_ENV === 'test' ||
|
|
330
|
-
(typeof
|
|
331
|
+
(typeof jest !== 'undefined' && jest.isRunning) ||
|
|
332
|
+
(process.env.VITEST_WORKER_ID !== undefined) ||
|
|
331
333
|
commandArgs.some(arg => {
|
|
332
334
|
const lowerArg = arg.toLowerCase();
|
|
333
335
|
return lowerArg.includes('vitest') ||
|
|
@@ -338,26 +340,6 @@ process.on('exit', (code) => {
|
|
|
338
340
|
|
|
339
341
|
const ignoreFailuresMode = globalThis._bunoshIgnoreFailuresMode || false;
|
|
340
342
|
|
|
341
|
-
if (process.env.BUNOSH_DEBUG) {
|
|
342
|
-
console.log('\n[DEBUG] Exit handler:');
|
|
343
|
-
console.log(' tasksFailed:', tasksFailed);
|
|
344
|
-
console.log(' isTestEnvironment:', isTestEnvironment);
|
|
345
|
-
console.log(' ignoreFailuresMode:', ignoreFailuresMode);
|
|
346
|
-
console.log(' NODE_ENV:', process.env.NODE_ENV);
|
|
347
|
-
console.log(' commandArgs:', commandArgs);
|
|
348
|
-
console.log(' full process.argv:', process.argv);
|
|
349
|
-
if (isTestEnvironment) {
|
|
350
|
-
const matchingArg = commandArgs.find(arg => {
|
|
351
|
-
const lowerArg = arg.toLowerCase();
|
|
352
|
-
return lowerArg.includes('vitest') ||
|
|
353
|
-
lowerArg.includes('jest') ||
|
|
354
|
-
lowerArg === '--test' ||
|
|
355
|
-
lowerArg.startsWith('test:');
|
|
356
|
-
});
|
|
357
|
-
console.log(' Matched command arg:', matchingArg);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
343
|
if (tasksFailed > 0 && !isTestEnvironment && !ignoreFailuresMode) {
|
|
362
344
|
process.exitCode = 1;
|
|
363
345
|
}
|
package/package.json
CHANGED
package/src/io.js
CHANGED
package/src/printer.js
CHANGED
|
@@ -12,6 +12,38 @@ export class Printer {
|
|
|
12
12
|
this.formatter = createFormatter();
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
|
|
16
|
+
shouldPrint() {
|
|
17
|
+
// Check if this task should be silent
|
|
18
|
+
if (this.taskId) {
|
|
19
|
+
const taskInfo = runningTasks.get(this.taskId);
|
|
20
|
+
|
|
21
|
+
// This task is explicitly marked as silent
|
|
22
|
+
if (taskInfo && taskInfo.isSilent) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Check if any parent task is silent (including full hierarchy)
|
|
27
|
+
if (taskInfo && taskInfo.parentId) {
|
|
28
|
+
let currentTask = taskInfo;
|
|
29
|
+
while (currentTask) {
|
|
30
|
+
const parentTask = runningTasks.get(currentTask.parentId);
|
|
31
|
+
if (!parentTask) break;
|
|
32
|
+
|
|
33
|
+
// If any parent in the hierarchy is silent, this task should be silent
|
|
34
|
+
if (parentTask.isSilent) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
currentTask = parentTask;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Default to printing
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
15
47
|
print(taskName, status, extra = {}) {
|
|
16
48
|
if (status === 'start' && !this.startTime) {
|
|
17
49
|
this.startTime = Date.now();
|
|
@@ -21,6 +53,11 @@ export class Printer {
|
|
|
21
53
|
extra.duration = Date.now() - this.startTime;
|
|
22
54
|
}
|
|
23
55
|
|
|
56
|
+
// Check if we should print this output
|
|
57
|
+
if (!this.shouldPrint()) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
24
61
|
// Get task info to check for parent task
|
|
25
62
|
let displayTaskName = taskName;
|
|
26
63
|
if (this.taskId) {
|
package/src/task.js
CHANGED
|
@@ -81,8 +81,8 @@ export function getTaskPrefix(taskId) {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
|
|
84
|
-
export function createTaskInfo(name, parentId = null) {
|
|
85
|
-
const taskInfo = new TaskInfo(name, Date.now(), TaskStatus.RUNNING, parentId);
|
|
84
|
+
export function createTaskInfo(name, parentId = null, isSilent = false) {
|
|
85
|
+
const taskInfo = new TaskInfo(name, Date.now(), TaskStatus.RUNNING, parentId, isSilent);
|
|
86
86
|
runningTasks.set(taskInfo.id, taskInfo);
|
|
87
87
|
tasksExecuted.push(taskInfo);
|
|
88
88
|
|
|
@@ -109,12 +109,13 @@ export function finishTaskInfo(taskInfo, success = true, error = null, output =
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
export class TaskInfo {
|
|
112
|
-
constructor(name, startTime, status, parentId = null) {
|
|
112
|
+
constructor(name, startTime, status, parentId = null, isSilent = false) {
|
|
113
113
|
this.id = `task-${++taskCounter}-${Math.random().toString(36).substring(7)}`;
|
|
114
114
|
this.name = name;
|
|
115
115
|
this.startTime = startTime;
|
|
116
116
|
this.status = status;
|
|
117
117
|
this.parentId = parentId;
|
|
118
|
+
this.isSilent = isSilent;
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
|
|
@@ -124,7 +125,7 @@ export async function tryTask(name, fn, isSilent = true) {
|
|
|
124
125
|
name = fn.toString().slice(0, 50).replace(/\s+/g, ' ').trim();
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
const taskInfo = createTaskInfo(name);
|
|
128
|
+
const taskInfo = createTaskInfo(name, null, isSilent);
|
|
128
129
|
|
|
129
130
|
const shouldPrint = !globalSilenceMode && !isSilent;
|
|
130
131
|
const printer = new Printer('task', taskInfo.id);
|
|
@@ -181,7 +182,7 @@ export async function task(name, fn, isSilent = false) {
|
|
|
181
182
|
name = fn.toString().slice(0, 50).replace(/\s+/g, ' ').trim();
|
|
182
183
|
}
|
|
183
184
|
|
|
184
|
-
const taskInfo = createTaskInfo(name);
|
|
185
|
+
const taskInfo = createTaskInfo(name, null, isSilent);
|
|
185
186
|
|
|
186
187
|
const shouldPrint = !globalSilenceMode && !isSilent;
|
|
187
188
|
const printer = new Printer('task', taskInfo.id);
|
package/src/tasks/exec.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TaskResult, createTaskInfo, finishTaskInfo, getCurrentTaskId } from '../task.js';
|
|
1
|
+
import { TaskResult, createTaskInfo, finishTaskInfo, getCurrentTaskId, runningTasks } from '../task.js';
|
|
2
2
|
import Printer from '../printer.js';
|
|
3
3
|
|
|
4
4
|
const isBun = typeof Bun !== 'undefined';
|
|
@@ -14,7 +14,7 @@ export default function exec(strings, ...values) {
|
|
|
14
14
|
throw new Error('exec() must be called as a template literal: exec`command` or exec("command")');
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
const cmd = strings.reduce((accumulator, str, i) => {
|
|
19
19
|
return accumulator + str + (values[i] || '');
|
|
20
20
|
}, '');
|
|
@@ -23,12 +23,25 @@ export default function exec(strings, ...values) {
|
|
|
23
23
|
let cwd = null;
|
|
24
24
|
|
|
25
25
|
const cmdPromise = new Promise(async (resolve, reject) => {
|
|
26
|
+
// Wait for the next event loop tick to ensure .env() and .cwd() have been called
|
|
27
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
28
|
+
|
|
29
|
+
const currentTaskId = getCurrentTaskId();
|
|
30
|
+
|
|
31
|
+
// Check if parent task is silent
|
|
32
|
+
let isParentSilent = false;
|
|
33
|
+
if (currentTaskId) {
|
|
34
|
+
const parentTask = runningTasks.get(currentTaskId);
|
|
35
|
+
if (parentTask && parentTask.isSilent) {
|
|
36
|
+
isParentSilent = true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
26
40
|
const extraInfo = {};
|
|
27
41
|
if (cwd) extraInfo.cwd = cwd;
|
|
28
42
|
if (envs) extraInfo.env = envs;
|
|
29
43
|
|
|
30
|
-
const
|
|
31
|
-
const taskInfo = createTaskInfo(cmd, currentTaskId);
|
|
44
|
+
const taskInfo = createTaskInfo(cmd, currentTaskId, isParentSilent);
|
|
32
45
|
const printer = new Printer('exec', taskInfo.id);
|
|
33
46
|
printer.start(cmd, extraInfo);
|
|
34
47
|
|
package/src/tasks/fetch.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TaskResult, createTaskInfo, finishTaskInfo, getCurrentTaskId } from '../task.js';
|
|
1
|
+
import { TaskResult, createTaskInfo, finishTaskInfo, getCurrentTaskId, runningTasks } from '../task.js';
|
|
2
2
|
import Printer from '../printer.js';
|
|
3
3
|
|
|
4
4
|
export default async function httpFetch() {
|
|
@@ -7,7 +7,17 @@ export default async function httpFetch() {
|
|
|
7
7
|
const taskName = `${method} ${url}`;
|
|
8
8
|
|
|
9
9
|
const currentTaskId = getCurrentTaskId();
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
// Check if parent task is silent
|
|
12
|
+
let isParentSilent = false;
|
|
13
|
+
if (currentTaskId) {
|
|
14
|
+
const parentTask = runningTasks.get(currentTaskId);
|
|
15
|
+
if (parentTask && parentTask.isSilent) {
|
|
16
|
+
isParentSilent = true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const taskInfo = createTaskInfo(taskName, currentTaskId, isParentSilent);
|
|
11
21
|
const printer = new Printer('fetch', taskInfo.id);
|
|
12
22
|
printer.start(taskName);
|
|
13
23
|
|
package/src/tasks/shell.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TaskResult, createTaskInfo, finishTaskInfo } from "../task.js";
|
|
1
|
+
import { TaskResult, createTaskInfo, finishTaskInfo, getCurrentTaskId, runningTasks } from "../task.js";
|
|
2
2
|
import Printer from "../printer.js";
|
|
3
3
|
|
|
4
4
|
const isBun = typeof Bun !== 'undefined' && typeof Bun.spawn === 'function';
|
|
@@ -58,7 +58,17 @@ export default function shell(strings, ...values) {
|
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
// Check if parent task is silent
|
|
62
|
+
let isParentSilent = false;
|
|
63
|
+
const currentTaskId = getCurrentTaskId();
|
|
64
|
+
if (currentTaskId) {
|
|
65
|
+
const parentTask = runningTasks.get(currentTaskId);
|
|
66
|
+
if (parentTask && parentTask.isSilent) {
|
|
67
|
+
isParentSilent = true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const taskInfo = createTaskInfo(cmd, null, isParentSilent);
|
|
62
72
|
const printer = new Printer("shell", taskInfo.id);
|
|
63
73
|
printer.start(cmd, extraInfo);
|
|
64
74
|
|