hereby 1.4.1 → 1.4.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/cli/loadHerebyfile.js +26 -10
- package/package.json +1 -1
- package/dist/utils.js +0 -13
|
@@ -3,7 +3,6 @@ import fs from "fs/promises";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { pathToFileURL } from "url";
|
|
5
5
|
import { Task } from "../index.js";
|
|
6
|
-
import { forEachTask } from "../utils.js";
|
|
7
6
|
import { UserError } from "./utils.js";
|
|
8
7
|
const filenames = ["Herebyfile", "herebyfile"];
|
|
9
8
|
const extensions = ["mjs", "js"];
|
|
@@ -56,20 +55,37 @@ export async function loadHerebyfile(herebyfilePath) {
|
|
|
56
55
|
const tasks = Array.from(exportedTasks.values());
|
|
57
56
|
// We check this here by walking the DAG, as some dependencies may not be
|
|
58
57
|
// exported and therefore would not be seen by the above loop.
|
|
59
|
-
|
|
58
|
+
checkTaskInvariants(tasks);
|
|
60
59
|
return {
|
|
61
60
|
tasks,
|
|
62
61
|
defaultTask,
|
|
63
62
|
};
|
|
64
63
|
}
|
|
65
|
-
function
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
function checkTaskInvariants(tasks) {
|
|
65
|
+
const checkedTasks = new Set();
|
|
66
|
+
const taskStack = new Set();
|
|
67
|
+
const seenNames = new Set();
|
|
68
|
+
checkTaskInvariantsWorker(tasks);
|
|
69
|
+
function checkTaskInvariantsWorker(tasks) {
|
|
70
|
+
for (const task of tasks) {
|
|
71
|
+
if (checkedTasks.has(task)) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (taskStack.has(task)) {
|
|
75
|
+
throw new UserError(`Task "${chalk.blue(task.options.name)}" references itself.`);
|
|
76
|
+
}
|
|
77
|
+
const name = task.options.name;
|
|
78
|
+
if (seenNames.has(name)) {
|
|
79
|
+
throw new UserError(`Task "${chalk.blue(name)}" was declared twice.`);
|
|
80
|
+
}
|
|
81
|
+
seenNames.add(name);
|
|
82
|
+
if (task.options.dependencies) {
|
|
83
|
+
taskStack.add(task);
|
|
84
|
+
checkTaskInvariantsWorker(task.options.dependencies);
|
|
85
|
+
taskStack.delete(task);
|
|
86
|
+
}
|
|
87
|
+
checkedTasks.add(task);
|
|
71
88
|
}
|
|
72
|
-
|
|
73
|
-
});
|
|
89
|
+
}
|
|
74
90
|
}
|
|
75
91
|
//# sourceMappingURL=loadHerebyfile.js.map
|
package/package.json
CHANGED
package/dist/utils.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export function forEachTask(tasks, fn, seen = new Set()) {
|
|
2
|
-
tasks.forEach(visit);
|
|
3
|
-
return;
|
|
4
|
-
function visit(task) {
|
|
5
|
-
if (seen.has(task)) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
seen.add(task);
|
|
9
|
-
fn(task);
|
|
10
|
-
task.options.dependencies?.forEach(visit);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=utils.js.map
|