hereby 1.8.6 → 1.8.7
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/formatTasks.js +5 -11
- package/dist/cli/index.js +27 -25
- package/dist/cli/loadHerebyfile.js +5 -4
- package/dist/cli/runner.js +4 -9
- package/dist/cli/utils.js +5 -16
- package/dist/cli.js +1 -9
- package/package.json +4 -4
package/dist/cli/formatTasks.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import commandLineUsage from "command-line-usage";
|
|
2
2
|
import pc from "picocolors";
|
|
3
|
-
import {
|
|
3
|
+
import { compareTaskNames } from "./utils.js";
|
|
4
4
|
export function formatTasks(format, tasks, defaultTask) {
|
|
5
5
|
tasks = tasks.filter(isTaskVisible).sort(compareTaskNames);
|
|
6
6
|
if (format === "simple") {
|
|
@@ -13,16 +13,10 @@ export function formatTasks(format, tasks, defaultTask) {
|
|
|
13
13
|
const name = task === defaultTask
|
|
14
14
|
? `${pc.green(task.options.name)} (default)`
|
|
15
15
|
: pc.blue(task.options.name);
|
|
16
|
-
let descriptionParts;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const deps = (_a = task.options.dependencies) === null || _a === void 0 ? void 0 : _a.filter(isTaskVisible);
|
|
21
|
-
if (deps && deps.length > 0) {
|
|
22
|
-
const depNames = deps
|
|
23
|
-
.map((task) => task.options.name)
|
|
24
|
-
.sort(compareStrings)
|
|
25
|
-
.map((v) => pc.blue(v));
|
|
16
|
+
let descriptionParts = task.options.description ? [task.options.description] : undefined;
|
|
17
|
+
const deps = (_a = task.options.dependencies) === null || _a === void 0 ? void 0 : _a.filter(isTaskVisible).sort(compareTaskNames);
|
|
18
|
+
if (deps === null || deps === void 0 ? void 0 : deps.length) {
|
|
19
|
+
const depNames = deps.map((task) => pc.blue(task.options.name));
|
|
26
20
|
(descriptionParts !== null && descriptionParts !== void 0 ? descriptionParts : (descriptionParts = [])).push(`Depends on: ${depNames.join(", ")}`);
|
|
27
21
|
}
|
|
28
22
|
return { name, description: descriptionParts === null || descriptionParts === void 0 ? void 0 : descriptionParts.join("\n") };
|
package/dist/cli/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import util from "node:util";
|
|
2
3
|
import pc from "picocolors";
|
|
3
4
|
import { formatTasks } from "./formatTasks.js";
|
|
4
5
|
import { findHerebyfile, loadHerebyfile } from "./loadHerebyfile.js";
|
|
5
6
|
import { getUsage, parseArgs } from "./parseArgs.js";
|
|
6
7
|
import { reexec } from "./reexec.js";
|
|
7
8
|
import { Runner } from "./runner.js";
|
|
8
|
-
import {
|
|
9
|
+
import { ExitCodeError, UserError } from "./utils.js";
|
|
9
10
|
export async function main(d) {
|
|
10
11
|
try {
|
|
11
12
|
await mainWorker(d);
|
|
@@ -13,14 +14,18 @@ export async function main(d) {
|
|
|
13
14
|
catch (e) {
|
|
14
15
|
if (e instanceof ExitCodeError) {
|
|
15
16
|
d.setExitCode(e.exitCode);
|
|
17
|
+
return;
|
|
16
18
|
}
|
|
17
|
-
|
|
19
|
+
if (e instanceof UserError) {
|
|
18
20
|
d.error(`${pc.red("Error")}: ${e.message}`);
|
|
19
|
-
|
|
21
|
+
}
|
|
22
|
+
else if (util.types.isNativeError(e) && e.stack) {
|
|
23
|
+
d.error(e.stack);
|
|
20
24
|
}
|
|
21
25
|
else {
|
|
22
|
-
|
|
26
|
+
d.error(`${e}`);
|
|
23
27
|
}
|
|
28
|
+
d.setExitCode(1);
|
|
24
29
|
}
|
|
25
30
|
}
|
|
26
31
|
async function mainWorker(d) {
|
|
@@ -68,30 +73,27 @@ async function mainWorker(d) {
|
|
|
68
73
|
}
|
|
69
74
|
// Exported for testing.
|
|
70
75
|
export async function selectTasks(d, herebyfile, herebyfilePath, taskNames) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
if (taskNames.length === 0) {
|
|
77
|
+
if (!herebyfile.defaultTask) {
|
|
78
|
+
throw new UserError(`No default task has been exported from ${d.simplifyPath(herebyfilePath)}; please specify a task name.`);
|
|
79
|
+
}
|
|
80
|
+
return [herebyfile.defaultTask];
|
|
74
81
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
throw new UserError(message);
|
|
82
|
+
const allTasks = new Map(herebyfile.tasks.map((task) => [task.options.name, task]));
|
|
83
|
+
const tasks = [];
|
|
84
|
+
for (const name of taskNames) {
|
|
85
|
+
const task = allTasks.get(name);
|
|
86
|
+
if (!task) {
|
|
87
|
+
let message = `Task "${name}" does not exist or is not exported from ${d.simplifyPath(herebyfilePath)}.`;
|
|
88
|
+
const { closest, distance } = await import("fastest-levenshtein");
|
|
89
|
+
const candidate = closest(name, [...allTasks.keys()]);
|
|
90
|
+
if (distance(name, candidate) < name.length * 0.4) {
|
|
91
|
+
message += ` Did you mean "${candidate}"?`;
|
|
87
92
|
}
|
|
88
|
-
|
|
93
|
+
throw new UserError(message);
|
|
89
94
|
}
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
if (!herebyfile.defaultTask) {
|
|
93
|
-
throw new UserError(`No default task has been exported from ${d.simplifyPath(herebyfilePath)}; please specify a task name.`);
|
|
95
|
+
tasks.push(task);
|
|
94
96
|
}
|
|
95
|
-
return
|
|
97
|
+
return tasks;
|
|
96
98
|
}
|
|
97
99
|
//# sourceMappingURL=index.js.map
|
|
@@ -4,14 +4,15 @@ import { pathToFileURL } from "node:url";
|
|
|
4
4
|
import pc from "picocolors";
|
|
5
5
|
import { Task } from "../index.js";
|
|
6
6
|
import { UserError } from "./utils.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
function isHerebyfile(p) {
|
|
8
|
+
p = p.toLowerCase();
|
|
9
|
+
return p === "herebyfile.mjs" || p === "herebyfile.js";
|
|
10
|
+
}
|
|
10
11
|
export async function findHerebyfile(dir) {
|
|
11
12
|
const root = path.parse(dir).root;
|
|
12
13
|
for (; dir !== root; dir = path.dirname(dir)) {
|
|
13
14
|
const entries = await fs.promises.readdir(dir);
|
|
14
|
-
const matching = entries.filter(
|
|
15
|
+
const matching = entries.filter(isHerebyfile);
|
|
15
16
|
if (matching.length > 1) {
|
|
16
17
|
throw new UserError(`Found more than one Herebyfile: ${matching.join(", ")}`);
|
|
17
18
|
}
|
package/dist/cli/runner.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import assert from "node:assert";
|
|
2
1
|
import pc from "picocolors";
|
|
3
2
|
export class Runner {
|
|
4
|
-
constructor(
|
|
3
|
+
constructor(_d) {
|
|
4
|
+
this._d = _d;
|
|
5
5
|
this._addedTasks = new Map();
|
|
6
6
|
this._errored = false;
|
|
7
7
|
this._startTimes = new Map();
|
|
8
|
-
this._d = d;
|
|
9
8
|
}
|
|
10
9
|
async runTasks(...tasks) {
|
|
11
10
|
// Using allSettled here so that we don't immediately exit; it could be
|
|
@@ -55,7 +54,7 @@ export class Runner {
|
|
|
55
54
|
if (this._errored) {
|
|
56
55
|
return; // Skip logging.
|
|
57
56
|
}
|
|
58
|
-
const took = Date.now() -
|
|
57
|
+
const took = Date.now() - this._startTimes.get(task);
|
|
59
58
|
this._d.log(`Finished ${pc.green(task.options.name)} in ${this._d.prettyMilliseconds(took)}`);
|
|
60
59
|
}
|
|
61
60
|
onTaskError(task, e) {
|
|
@@ -63,12 +62,8 @@ export class Runner {
|
|
|
63
62
|
return; // Skip logging.
|
|
64
63
|
}
|
|
65
64
|
this._errored = true;
|
|
66
|
-
const took = Date.now() -
|
|
65
|
+
const took = Date.now() - this._startTimes.get(task);
|
|
67
66
|
this._d.error(`Error in ${pc.red(task.options.name)} in ${this._d.prettyMilliseconds(took)}\n${e}`);
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
|
-
function checkDefined(value) {
|
|
71
|
-
assert(value !== undefined);
|
|
72
|
-
return value;
|
|
73
|
-
}
|
|
74
69
|
//# sourceMappingURL=runner.js.map
|
package/dist/cli/utils.js
CHANGED
|
@@ -6,13 +6,11 @@ export function compareTaskNames(a, b) {
|
|
|
6
6
|
return compareStrings(a.options.name, b.options.name);
|
|
7
7
|
}
|
|
8
8
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
9
|
-
|
|
9
|
+
const compareStrings = new Intl.Collator(undefined, { numeric: true }).compare;
|
|
10
10
|
// Exported for testing.
|
|
11
11
|
export function simplifyPath(p) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
homedir += path.sep;
|
|
15
|
-
}
|
|
12
|
+
p = path.normalize(p);
|
|
13
|
+
const homedir = path.normalize(os.homedir() + path.sep);
|
|
16
14
|
if (p.startsWith(homedir)) {
|
|
17
15
|
p = p.slice(homedir.length);
|
|
18
16
|
return `~${path.sep}${p}`;
|
|
@@ -24,9 +22,6 @@ export function simplifyPath(p) {
|
|
|
24
22
|
* as a message only, without stacktrace. Use this instead of process.exit.
|
|
25
23
|
*/
|
|
26
24
|
export class UserError extends Error {
|
|
27
|
-
constructor(message) {
|
|
28
|
-
super(message);
|
|
29
|
-
}
|
|
30
25
|
}
|
|
31
26
|
/**
|
|
32
27
|
* When thrown, ExitCodeError causes the process to exit with a specific error code,
|
|
@@ -39,7 +34,6 @@ export class ExitCodeError {
|
|
|
39
34
|
}
|
|
40
35
|
}
|
|
41
36
|
export async function real() {
|
|
42
|
-
const importResolve = memoize(async () => (await import("import-meta-resolve")).resolve);
|
|
43
37
|
const { default: prettyMilliseconds } = await import("pretty-ms");
|
|
44
38
|
/* eslint-disable no-restricted-globals */
|
|
45
39
|
return {
|
|
@@ -55,23 +49,18 @@ export async function real() {
|
|
|
55
49
|
process.exitCode = code;
|
|
56
50
|
},
|
|
57
51
|
version: async () => {
|
|
58
|
-
|
|
59
|
-
const resolve = await importResolve();
|
|
52
|
+
const { resolve } = await import("import-meta-resolve");
|
|
60
53
|
const packageJsonPath = fileURLToPath(await resolve("hereby/package.json", import.meta.url));
|
|
61
54
|
const packageJson = await fs.promises.readFile(packageJsonPath, "utf8");
|
|
62
55
|
const { version } = JSON.parse(packageJson);
|
|
63
56
|
return version;
|
|
64
57
|
},
|
|
65
58
|
resolve: async (specifier, parent) => {
|
|
66
|
-
const resolve = await
|
|
59
|
+
const { resolve } = await import("import-meta-resolve");
|
|
67
60
|
return resolve(specifier, parent);
|
|
68
61
|
},
|
|
69
62
|
prettyMilliseconds,
|
|
70
63
|
};
|
|
71
64
|
/* eslint-enable no-restricted-globals */
|
|
72
65
|
}
|
|
73
|
-
function memoize(fn) {
|
|
74
|
-
let value;
|
|
75
|
-
return () => (value !== null && value !== void 0 ? value : (value = fn()));
|
|
76
|
-
}
|
|
77
66
|
//# sourceMappingURL=utils.js.map
|
package/dist/cli.js
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import { main } from "./cli/index.js";
|
|
2
2
|
import { real } from "./cli/utils.js";
|
|
3
3
|
async function run() {
|
|
4
|
-
|
|
5
|
-
await main(await real());
|
|
6
|
-
}
|
|
7
|
-
catch (e) {
|
|
8
|
-
// eslint-disable-next-line no-restricted-globals
|
|
9
|
-
console.error(e);
|
|
10
|
-
// eslint-disable-next-line no-restricted-globals
|
|
11
|
-
process.exitCode = 1;
|
|
12
|
-
}
|
|
4
|
+
await main(await real());
|
|
13
5
|
}
|
|
14
6
|
void run();
|
|
15
7
|
//# sourceMappingURL=cli.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hereby",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.7",
|
|
4
4
|
"description": "A simple task runner",
|
|
5
5
|
"repository": "github:jakebailey/hereby",
|
|
6
6
|
"type": "module",
|
|
@@ -51,10 +51,10 @@
|
|
|
51
51
|
"@tsconfig/node12": "^12.1.0",
|
|
52
52
|
"@types/command-line-usage": "^5.0.2",
|
|
53
53
|
"@types/minimist": "^1.2.2",
|
|
54
|
-
"@types/node": "^
|
|
54
|
+
"@types/node": "^20.5.9",
|
|
55
55
|
"@types/tmp": "^0.2.3",
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
57
|
-
"@typescript-eslint/parser": "^6.
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^6.6.0",
|
|
57
|
+
"@typescript-eslint/parser": "^6.6.0",
|
|
58
58
|
"ava": "~5.0.1",
|
|
59
59
|
"c8": "^8.0.1",
|
|
60
60
|
"dprint": "^0.40.2",
|