bunosh 0.4.11 → 0.4.14

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 CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env bun
1
+ #!/usr/bin/env node
2
2
 
3
3
  // Set up global variables BEFORE any imports
4
4
  globalThis._bunoshStartTime = Date.now();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunosh",
3
- "version": "0.4.11",
3
+ "version": "0.4.14",
4
4
  "type": "module",
5
5
  "module": "index.js",
6
6
  "bin": {
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/program.js CHANGED
@@ -32,7 +32,6 @@ export const banner = () => {
32
32
  } catch (e) {
33
33
  }
34
34
  console.log(color.gray('🍲 ', color.yellowBright.bold('BUNOSH'), color.yellow(version)));
35
-
36
35
  console.log();
37
36
  };
38
37
 
@@ -203,6 +202,20 @@ export default async function bunosh(commands, sources) {
203
202
  }
204
203
  command.hook('preAction', (_thisCommand) => {
205
204
  process.env.BUNOSH_COMMAND_STARTED = true;
205
+
206
+ const isBun = typeof Bun !== 'undefined';
207
+ const runtime = isBun ? 'Bun' : 'Node.js';
208
+ const runtimeColor = isBun ? color.red : color.green;
209
+
210
+ let runtimeVersion;
211
+ if (isBun) {
212
+ runtimeVersion = Bun.version;
213
+ } else {
214
+ runtimeVersion = process.version;
215
+ }
216
+
217
+ console.log(color.gray(`Runtime: `, runtimeColor.bold(runtime), color.gray(` (${runtimeVersion})`)));
218
+ console.log();
206
219
  })
207
220
 
208
221
  let argsAndOptsDescription = [];
@@ -275,6 +288,20 @@ export default async function bunosh(commands, sources) {
275
288
  }
276
289
  command.hook('preAction', (_thisCommand) => {
277
290
  process.env.BUNOSH_COMMAND_STARTED = true;
291
+
292
+ const isBun = typeof Bun !== 'undefined';
293
+ const runtime = isBun ? 'Bun' : 'Node.js';
294
+ const runtimeColor = isBun ? color.red : color.green;
295
+
296
+ let runtimeVersion;
297
+ if (isBun) {
298
+ runtimeVersion = Bun.version;
299
+ } else {
300
+ runtimeVersion = process.version;
301
+ }
302
+
303
+ console.log(color.gray(`Runtime: `, runtimeColor.bold(runtime), color.gray(` (${runtimeVersion})`)));
304
+ console.log();
278
305
  })
279
306
 
280
307
  let argsAndOptsDescription = [];
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 currentTaskId = getCurrentTaskId();
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
 
@@ -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
- const taskInfo = createTaskInfo(taskName, currentTaskId);
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
 
@@ -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
- const taskInfo = createTaskInfo(cmd);
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