hereby 1.12.0 → 1.13.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 +14 -23
- package/dist/cli/utils.js +19 -3
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +11 -25
- package/package.json +8 -9
package/dist/cli/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { findHerebyfile, loadHerebyfile } from "./loadHerebyfile.js";
|
|
|
7
7
|
import { getUsage, parseArgs } from "./parseArgs.js";
|
|
8
8
|
import { reexec } from "./reexec.js";
|
|
9
9
|
import { Runner } from "./runner.js";
|
|
10
|
-
import { UserError } from "./utils.js";
|
|
10
|
+
import { prettyMilliseconds, UserError } from "./utils.js";
|
|
11
11
|
export async function main(d) {
|
|
12
12
|
try {
|
|
13
13
|
await mainWorker(d);
|
|
@@ -62,7 +62,7 @@ async function mainWorker(d) {
|
|
|
62
62
|
finally {
|
|
63
63
|
const took = performance.now() - start;
|
|
64
64
|
const failed = runner.failedTasks.length > 0;
|
|
65
|
-
d.log(`Completed ${taskNames}${failed ? pc.red(" with errors") : ""} in ${
|
|
65
|
+
d.log(`Completed ${taskNames}${failed ? pc.red(" with errors") : ""} in ${prettyMilliseconds(took)}`);
|
|
66
66
|
if (failed) {
|
|
67
67
|
const names = runner.failedTasks.sort().map((task) => pc.red(task)).join(", ");
|
|
68
68
|
d.log(`Failed tasks: ${names}`);
|
package/dist/cli/runner.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { performance } from "node:perf_hooks";
|
|
2
2
|
import pc from "picocolors";
|
|
3
|
+
import { prettyMilliseconds } from "./utils.js";
|
|
3
4
|
export class Runner {
|
|
4
5
|
constructor(_d) {
|
|
5
6
|
this._d = _d;
|
|
6
7
|
this._addedTasks = new Map();
|
|
7
8
|
this.failedTasks = [];
|
|
8
|
-
this._startTimes = new Map();
|
|
9
9
|
}
|
|
10
10
|
async runTasks(...tasks) {
|
|
11
11
|
// Using allSettled here so that we don't immediately exit; it could be
|
|
@@ -32,34 +32,25 @@ export class Runner {
|
|
|
32
32
|
}
|
|
33
33
|
if (!run)
|
|
34
34
|
return;
|
|
35
|
+
const start = performance.now();
|
|
35
36
|
try {
|
|
36
|
-
this.
|
|
37
|
+
if (this.failedTasks.length === 0) {
|
|
38
|
+
this._d.log(`Starting ${pc.blue(task.options.name)}`);
|
|
39
|
+
}
|
|
37
40
|
await run();
|
|
38
|
-
this.
|
|
41
|
+
if (this.failedTasks.length === 0) {
|
|
42
|
+
const took = performance.now() - start;
|
|
43
|
+
this._d.log(`Finished ${pc.green(task.options.name)} in ${prettyMilliseconds(took)}`);
|
|
44
|
+
}
|
|
39
45
|
}
|
|
40
46
|
catch (e) {
|
|
41
|
-
this.
|
|
47
|
+
this.failedTasks.push(task.options.name);
|
|
48
|
+
if (this.failedTasks.length === 1) {
|
|
49
|
+
const took = performance.now() - start;
|
|
50
|
+
this._d.error(`Error in ${pc.red(task.options.name)} in ${prettyMilliseconds(took)}\n${e}`);
|
|
51
|
+
}
|
|
42
52
|
throw e;
|
|
43
53
|
}
|
|
44
54
|
}
|
|
45
|
-
onTaskStart(task) {
|
|
46
|
-
this._startTimes.set(task, performance.now());
|
|
47
|
-
if (this.failedTasks.length > 0)
|
|
48
|
-
return; // Skip logging.
|
|
49
|
-
this._d.log(`Starting ${pc.blue(task.options.name)}`);
|
|
50
|
-
}
|
|
51
|
-
onTaskFinish(task) {
|
|
52
|
-
if (this.failedTasks.length > 0)
|
|
53
|
-
return; // Skip logging.
|
|
54
|
-
const took = performance.now() - this._startTimes.get(task);
|
|
55
|
-
this._d.log(`Finished ${pc.green(task.options.name)} in ${this._d.prettyMilliseconds(took)}`);
|
|
56
|
-
}
|
|
57
|
-
onTaskError(task, e) {
|
|
58
|
-
this.failedTasks.push(task.options.name);
|
|
59
|
-
if (this.failedTasks.length > 1)
|
|
60
|
-
return; // Skip logging.
|
|
61
|
-
const took = performance.now() - this._startTimes.get(task);
|
|
62
|
-
this._d.error(`Error in ${pc.red(task.options.name)} in ${this._d.prettyMilliseconds(took)}\n${e}`);
|
|
63
|
-
}
|
|
64
55
|
}
|
|
65
56
|
//# sourceMappingURL=runner.js.map
|
package/dist/cli/utils.js
CHANGED
|
@@ -28,14 +28,31 @@ export function findUp(dir, predicate) {
|
|
|
28
28
|
}
|
|
29
29
|
return undefined;
|
|
30
30
|
}
|
|
31
|
+
export function prettyMilliseconds(ms) {
|
|
32
|
+
if (ms < 1000)
|
|
33
|
+
return `${Math.ceil(ms)}ms`;
|
|
34
|
+
const seconds = (ms / 1000) % 60;
|
|
35
|
+
const minutes = Math.floor(ms / 60000) % 60;
|
|
36
|
+
const hours = Math.floor(ms / 3600000);
|
|
37
|
+
// Round to one decimal, with an epsilon to avoid floating point errors (e.g. 5.0000001 -> 5).
|
|
38
|
+
const roundedSeconds = Math.floor(seconds * 10 + 1e-7) / 10;
|
|
39
|
+
const parts = [];
|
|
40
|
+
if (hours > 0)
|
|
41
|
+
parts.push(`${hours}h`);
|
|
42
|
+
if (minutes > 0)
|
|
43
|
+
parts.push(`${minutes}m`);
|
|
44
|
+
if (roundedSeconds > 0) {
|
|
45
|
+
parts.push(roundedSeconds % 1 === 0 ? `${roundedSeconds}s` : `${roundedSeconds.toFixed(1)}s`);
|
|
46
|
+
}
|
|
47
|
+
return parts.join(" ");
|
|
48
|
+
}
|
|
31
49
|
/**
|
|
32
50
|
* UserError is a special error that, when caught in the CLI will be printed
|
|
33
51
|
* as a message only, without stacktrace. Use this instead of process.exit.
|
|
34
52
|
*/
|
|
35
53
|
export class UserError extends Error {
|
|
36
54
|
}
|
|
37
|
-
export
|
|
38
|
-
const { default: prettyMilliseconds } = await import("pretty-ms");
|
|
55
|
+
export function real() {
|
|
39
56
|
/* eslint-disable no-restricted-globals */
|
|
40
57
|
return {
|
|
41
58
|
columns: () => process.stdout.isTTY && process.stdout.columns || 80,
|
|
@@ -55,7 +72,6 @@ export async function real() {
|
|
|
55
72
|
const packageJson = fs.readFileSync(packageJsonURL, "utf8");
|
|
56
73
|
return JSON.parse(packageJson).version;
|
|
57
74
|
},
|
|
58
|
-
prettyMilliseconds,
|
|
59
75
|
};
|
|
60
76
|
/* eslint-enable no-restricted-globals */
|
|
61
77
|
}
|
package/dist/cli.js
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
1
2
|
/**
|
|
2
|
-
* A hereby Task. To get an instance, call `
|
|
3
|
+
* A hereby Task. To get an instance, call `task`.
|
|
3
4
|
*/
|
|
4
5
|
export class Task {
|
|
5
6
|
/* @internal */
|
|
@@ -13,34 +14,19 @@ export class Task {
|
|
|
13
14
|
// typechecking, so this is helpful.
|
|
14
15
|
var _a, _b;
|
|
15
16
|
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (typeof options.description !== "string" && options.description !== undefined) {
|
|
20
|
-
throw new TypeError("Task description is not a string or undefined.");
|
|
21
|
-
}
|
|
22
|
-
if (!Array.isArray(options.dependencies) && options.dependencies !== undefined) {
|
|
23
|
-
throw new TypeError("Task dependencies is not an array or undefined.");
|
|
24
|
-
}
|
|
17
|
+
assert.ok(typeof options.name === "string", "Task name is not a string.");
|
|
18
|
+
assert.ok(typeof options.description === "string" || options.description === undefined, "Task description is not a string or undefined.");
|
|
19
|
+
assert.ok(Array.isArray(options.dependencies) || options.dependencies === undefined, "Task dependencies is not an array or undefined.");
|
|
25
20
|
for (const dep of (_a = options.dependencies) !== null && _a !== void 0 ? _a : []) {
|
|
26
|
-
|
|
27
|
-
throw new TypeError("Task dependency is not a task.");
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (typeof options.run !== "function" && options.run !== undefined) {
|
|
31
|
-
throw new TypeError("Task run is not a function or undefined.");
|
|
21
|
+
assert.ok(dep instanceof Task, "Task dependency is not a task.");
|
|
32
22
|
}
|
|
23
|
+
assert.ok(typeof options.run === "function" || options.run === undefined, "Task run is not a function or undefined.");
|
|
33
24
|
/* eslint-enable @typescript-eslint/no-unnecessary-condition */
|
|
34
25
|
// Non-type checks.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
throw new Error('Task name must not start with "-".');
|
|
40
|
-
}
|
|
41
|
-
if (!((_b = options.dependencies) === null || _b === void 0 ? void 0 : _b.length) && !options.run) {
|
|
42
|
-
throw new Error("Task must have a run function or dependencies.");
|
|
43
|
-
}
|
|
26
|
+
assert.ok(options.name !== "", "Task name must not be empty.");
|
|
27
|
+
assert.ok(!options.name.startsWith("-"), 'Task name must not start with "-".');
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
29
|
+
assert.ok(!!(((_b = options.dependencies) === null || _b === void 0 ? void 0 : _b.length) || options.run), "Task must have a run function or dependencies.");
|
|
44
30
|
this.options = options;
|
|
45
31
|
}
|
|
46
32
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hereby",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "A simple task runner",
|
|
5
5
|
"repository": "github:jakebailey/hereby",
|
|
6
6
|
"type": "module",
|
|
@@ -42,33 +42,32 @@
|
|
|
42
42
|
"fastest-levenshtein": "^1.0.16",
|
|
43
43
|
"minimist": "^1.2.8",
|
|
44
44
|
"picocolors": "^1.1.0",
|
|
45
|
-
"pretty-ms": "^8.0.0",
|
|
46
45
|
"wordwrapjs": "^5.1.1"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
48
|
"@ava/typescript": "^3.0.1",
|
|
50
|
-
"@changesets/cli": "^2.
|
|
49
|
+
"@changesets/cli": "^2.30.0",
|
|
51
50
|
"@eslint/js": "^10.0.1",
|
|
52
51
|
"@tsconfig/node12": "^12.1.7",
|
|
53
52
|
"@types/minimist": "^1.2.5",
|
|
54
|
-
"@types/node": "^25.
|
|
53
|
+
"@types/node": "^25.3.3",
|
|
55
54
|
"@types/tmp": "^0.2.6",
|
|
56
55
|
"@types/wordwrapjs": "^5.1.2",
|
|
57
56
|
"ava": "~5.0.1",
|
|
58
|
-
"c8": "^
|
|
59
|
-
"dprint": "^0.
|
|
60
|
-
"eslint": "^10.0.
|
|
57
|
+
"c8": "^11.0.0",
|
|
58
|
+
"dprint": "^0.52.0",
|
|
59
|
+
"eslint": "^10.0.2",
|
|
61
60
|
"eslint-plugin-ava": "^16.0.0",
|
|
62
61
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
63
62
|
"eslint-plugin-unicorn": "^63.0.0",
|
|
64
63
|
"execa": "^6.1.0",
|
|
65
|
-
"globals": "^17.
|
|
64
|
+
"globals": "^17.4.0",
|
|
66
65
|
"monocart-coverage-reports": "^2.12.9",
|
|
67
66
|
"moq.ts": "^10.1.0",
|
|
68
67
|
"rimraf": "^5.0.10",
|
|
69
68
|
"tmp": "0.2.1",
|
|
70
69
|
"typescript": "^5.9.3",
|
|
71
|
-
"typescript-eslint": "^8.56.
|
|
70
|
+
"typescript-eslint": "^8.56.1"
|
|
72
71
|
},
|
|
73
72
|
"overrides": {
|
|
74
73
|
"ava": {
|