hereby 1.0.6 → 1.1.0
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/index.js +2 -2
- package/dist/cli/runner.js +36 -4
- package/dist/index.d.ts +5 -3
- package/package.json +6 -6
- package/dist/runner.js +0 -44
package/dist/cli/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { formatTasks } from "./formatTasks.js";
|
|
|
5
5
|
import { findHerebyfile, loadHerebyfile } from "./loadHerebyfile.js";
|
|
6
6
|
import { getUsage, parseArgs } from "./parseArgs.js";
|
|
7
7
|
import { reexec } from "./reexec.js";
|
|
8
|
-
import {
|
|
8
|
+
import { Runner } from "./runner.js";
|
|
9
9
|
import { ExitCodeError, simplifyPath, UserError } from "./utils.js";
|
|
10
10
|
export async function main(d) {
|
|
11
11
|
try {
|
|
@@ -44,7 +44,7 @@ async function mainWorker(d) {
|
|
|
44
44
|
}
|
|
45
45
|
const tasks = selectTasks(herebyfile, args.run);
|
|
46
46
|
try {
|
|
47
|
-
const runner = new
|
|
47
|
+
const runner = new Runner(d);
|
|
48
48
|
await runner.runTasks(...tasks);
|
|
49
49
|
}
|
|
50
50
|
catch (e) {
|
package/dist/cli/runner.js
CHANGED
|
@@ -1,13 +1,45 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
2
|
import chalk from "chalk";
|
|
3
|
-
import
|
|
4
|
-
export class
|
|
5
|
-
constructor(d) {
|
|
6
|
-
|
|
3
|
+
import pLimit from "p-limit";
|
|
4
|
+
export class Runner {
|
|
5
|
+
constructor(d, limiter) {
|
|
6
|
+
this._addedTasks = new WeakMap();
|
|
7
7
|
this._errored = false;
|
|
8
8
|
this._startTimes = new WeakMap();
|
|
9
|
+
this._limiter = limiter ?? pLimit(d.numCPUs);
|
|
9
10
|
this._d = d;
|
|
10
11
|
}
|
|
12
|
+
async runTasks(...tasks) {
|
|
13
|
+
await Promise.all(tasks.map((task) => {
|
|
14
|
+
const cached = this._addedTasks.get(task);
|
|
15
|
+
if (cached) {
|
|
16
|
+
return cached;
|
|
17
|
+
}
|
|
18
|
+
const promise = this._runTask(task);
|
|
19
|
+
this._addedTasks.set(task, promise);
|
|
20
|
+
return promise;
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
async _runTask(task) {
|
|
24
|
+
const { dependencies, run } = task.options;
|
|
25
|
+
if (dependencies) {
|
|
26
|
+
await this.runTasks(...dependencies);
|
|
27
|
+
}
|
|
28
|
+
if (!run) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
return this._limiter(async () => {
|
|
32
|
+
try {
|
|
33
|
+
this.onTaskStart(task);
|
|
34
|
+
await run();
|
|
35
|
+
this.onTaskFinish(task);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
this.onTaskError(task, e);
|
|
39
|
+
throw e;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
11
43
|
onTaskStart(task) {
|
|
12
44
|
this._startTimes.set(task, Date.now());
|
|
13
45
|
if (this._errored) {
|
package/dist/index.d.ts
CHANGED
|
@@ -14,11 +14,13 @@ export interface TaskOptions {
|
|
|
14
14
|
* A list of tasks that must has been run to completion before
|
|
15
15
|
* this task can execute.
|
|
16
16
|
*/
|
|
17
|
-
dependencies?: Task[] | undefined;
|
|
17
|
+
dependencies?: readonly Task[] | undefined;
|
|
18
18
|
/**
|
|
19
|
-
* A function to execute when this task is run.
|
|
19
|
+
* A function to execute when this task is run. If this function
|
|
20
|
+
* returns a promise, the task will not be marked as finished until
|
|
21
|
+
* that promise resolves.
|
|
20
22
|
*/
|
|
21
|
-
run?: (() => void |
|
|
23
|
+
run?: (() => void) | (() => PromiseLike<void>) | undefined;
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
26
|
* A hereby Task. To get an instance, call `test`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hereby",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A simple task runner",
|
|
5
5
|
"repository": "github:jakebailey/hereby",
|
|
6
6
|
"type": "module",
|
|
@@ -52,19 +52,19 @@
|
|
|
52
52
|
"@tsconfig/node14": "^1.0.3",
|
|
53
53
|
"@types/command-line-args": "^5.2.0",
|
|
54
54
|
"@types/command-line-usage": "^5.0.2",
|
|
55
|
-
"@types/node": "^14.18.
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
57
|
-
"@typescript-eslint/parser": "^5.
|
|
55
|
+
"@types/node": "^14.18.30",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^5.38.0",
|
|
57
|
+
"@typescript-eslint/parser": "^5.38.0",
|
|
58
58
|
"ava": "^4.3.3",
|
|
59
59
|
"c8": "^7.12.0",
|
|
60
|
-
"eslint": "^8.
|
|
60
|
+
"eslint": "^8.24.0",
|
|
61
61
|
"eslint-config-prettier": "^8.5.0",
|
|
62
62
|
"eslint-plugin-ava": "^13.2.0",
|
|
63
63
|
"eslint-plugin-simple-import-sort": "^8.0.0",
|
|
64
64
|
"execa": "^6.1.0",
|
|
65
65
|
"moq.ts": "^9.0.2",
|
|
66
66
|
"prettier": "^2.7.1",
|
|
67
|
-
"release-it": "^15.4.
|
|
67
|
+
"release-it": "^15.4.2",
|
|
68
68
|
"rimraf": "^3.0.2",
|
|
69
69
|
"tempy": "^3.0.0",
|
|
70
70
|
"typescript": "~4.8.3"
|
package/dist/runner.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import pLimit from "p-limit";
|
|
2
|
-
export class Runner {
|
|
3
|
-
constructor(options) {
|
|
4
|
-
this._addedTasks = new WeakMap();
|
|
5
|
-
this._limiter = (fn) => fn();
|
|
6
|
-
const concurrency = options?.concurrency;
|
|
7
|
-
if (concurrency !== undefined) {
|
|
8
|
-
this._limiter = pLimit(concurrency);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
async runTasks(...tasks) {
|
|
12
|
-
await Promise.all(tasks.map((task) => {
|
|
13
|
-
const cached = this._addedTasks.get(task);
|
|
14
|
-
if (cached) {
|
|
15
|
-
return cached;
|
|
16
|
-
}
|
|
17
|
-
const promise = this._runTask(task);
|
|
18
|
-
this._addedTasks.set(task, promise);
|
|
19
|
-
return promise;
|
|
20
|
-
}));
|
|
21
|
-
}
|
|
22
|
-
async _runTask(task) {
|
|
23
|
-
this.onTaskAdd?.(task);
|
|
24
|
-
const { dependencies, run } = task.options;
|
|
25
|
-
if (dependencies) {
|
|
26
|
-
await this.runTasks(...dependencies);
|
|
27
|
-
}
|
|
28
|
-
if (!run) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
return this._limiter(async () => {
|
|
32
|
-
try {
|
|
33
|
-
this.onTaskStart?.(task);
|
|
34
|
-
await run();
|
|
35
|
-
this.onTaskFinish?.(task);
|
|
36
|
-
}
|
|
37
|
-
catch (e) {
|
|
38
|
-
this.onTaskError?.(task, e);
|
|
39
|
-
throw e;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=runner.js.map
|