builderman 1.0.0 → 1.0.2
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.ts +1 -7
- package/dist/index.js +42 -21
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,12 +2,6 @@ export interface TaskConfig {
|
|
|
2
2
|
name: string;
|
|
3
3
|
command: string;
|
|
4
4
|
cwd: string;
|
|
5
|
-
}
|
|
6
|
-
export interface PipelineTaskConfig {
|
|
7
|
-
name: string;
|
|
8
|
-
path?: string;
|
|
9
|
-
cwd?: string;
|
|
10
|
-
command: string;
|
|
11
5
|
requiresEvents?: string[];
|
|
12
6
|
}
|
|
13
7
|
export interface Task extends TaskConfig {
|
|
@@ -28,4 +22,4 @@ export declare function task(config: TaskConfig): Task;
|
|
|
28
22
|
/**
|
|
29
23
|
* Creates a pipeline that manages task execution with event-based dependencies.
|
|
30
24
|
*/
|
|
31
|
-
export declare function pipeline(
|
|
25
|
+
export declare function pipeline(tasks: Task[]): Pipeline;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { EventEmitter } from "node:events";
|
|
3
|
+
import * as path from "node:path";
|
|
3
4
|
const EVENT_PREFIX = "__BUILDERMAN_EVENT__:";
|
|
4
5
|
/**
|
|
5
6
|
* Emits an event that can be received by the parent process.
|
|
@@ -17,29 +18,13 @@ export function task(config) {
|
|
|
17
18
|
name: config.name,
|
|
18
19
|
command: config.command,
|
|
19
20
|
cwd: config.cwd,
|
|
20
|
-
requiresEvents: [],
|
|
21
|
+
requiresEvents: config.requiresEvents || [],
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* Creates a pipeline that manages task execution with event-based dependencies.
|
|
25
26
|
*/
|
|
26
|
-
export function pipeline(
|
|
27
|
-
const tasks = configs.map((config) => {
|
|
28
|
-
if ("requiresEvents" in config || "path" in config) {
|
|
29
|
-
// It's a PipelineTaskConfig
|
|
30
|
-
const taskConfig = config;
|
|
31
|
-
return {
|
|
32
|
-
name: taskConfig.name,
|
|
33
|
-
command: taskConfig.command,
|
|
34
|
-
cwd: taskConfig.path || taskConfig.cwd || process.cwd(),
|
|
35
|
-
requiresEvents: taskConfig.requiresEvents || [],
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
// It's already a Task
|
|
40
|
-
return config;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
27
|
+
export function pipeline(tasks) {
|
|
43
28
|
return {
|
|
44
29
|
async run() {
|
|
45
30
|
const eventEmitter = new EventEmitter();
|
|
@@ -63,11 +48,47 @@ export function pipeline(configs) {
|
|
|
63
48
|
if (runningTasks.has(task.name)) {
|
|
64
49
|
return;
|
|
65
50
|
}
|
|
66
|
-
|
|
67
|
-
|
|
51
|
+
console.error(`[builderman] Starting task: ${task.name}`);
|
|
52
|
+
// Ensure node_modules/.bin is in PATH for local dependencies
|
|
53
|
+
// Resolve cwd relative to current working directory
|
|
54
|
+
const taskCwd = path.isAbsolute(task.cwd)
|
|
55
|
+
? task.cwd
|
|
56
|
+
: path.resolve(process.cwd(), task.cwd);
|
|
57
|
+
const localBinPath = path.join(taskCwd, "node_modules", ".bin");
|
|
58
|
+
// Build PATH with local node_modules/.bin first (as absolute path), then existing PATH
|
|
59
|
+
const existingPath = process.env.PATH || process.env.Path || "";
|
|
60
|
+
const pathSeparator = process.platform === "win32" ? ";" : ":";
|
|
61
|
+
// Collect all potential bin paths (local first, then root, then existing)
|
|
62
|
+
const binPaths = [localBinPath];
|
|
63
|
+
// Also add root node_modules/.bin if different from local
|
|
64
|
+
const rootBinPath = path.join(process.cwd(), "node_modules", ".bin");
|
|
65
|
+
if (rootBinPath !== localBinPath) {
|
|
66
|
+
binPaths.push(rootBinPath);
|
|
67
|
+
}
|
|
68
|
+
// Add existing PATH
|
|
69
|
+
if (existingPath) {
|
|
70
|
+
binPaths.push(existingPath);
|
|
71
|
+
}
|
|
72
|
+
const newPath = binPaths.join(pathSeparator);
|
|
73
|
+
const env = {
|
|
74
|
+
...process.env,
|
|
75
|
+
PATH: newPath,
|
|
76
|
+
Path: newPath, // Windows uses both PATH and Path
|
|
77
|
+
};
|
|
78
|
+
// Use shell mode to allow commands like "vite dev" to work properly
|
|
79
|
+
const child = spawn(task.command, {
|
|
68
80
|
cwd: task.cwd,
|
|
69
81
|
stdio: ["inherit", "pipe", "pipe"],
|
|
70
|
-
shell:
|
|
82
|
+
shell: true,
|
|
83
|
+
env,
|
|
84
|
+
});
|
|
85
|
+
// Handle spawn errors
|
|
86
|
+
child.on("error", (error) => {
|
|
87
|
+
console.error(`[${task.name}] Failed to start:`, error.message);
|
|
88
|
+
runningTasks.delete(task.name);
|
|
89
|
+
completedTasks.add(task.name);
|
|
90
|
+
process.exitCode = 1;
|
|
91
|
+
eventEmitter.emit("taskCompleted", task.name);
|
|
71
92
|
});
|
|
72
93
|
runningTasks.set(task.name, child);
|
|
73
94
|
// Parse events from stdout
|