hereby 1.6.3 → 1.6.4
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/README.md +1 -1
- package/dist/cli/formatTasks.js +4 -4
- package/dist/cli/index.js +14 -12
- package/dist/cli/loadHerebyfile.js +7 -7
- package/dist/cli/reexec.js +1 -1
- package/dist/cli/runner.js +4 -4
- package/dist/cli/utils.js +23 -9
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://npmjs.com/package/hereby)
|
|
4
4
|
[](https://nodejs.org)
|
|
5
5
|
[](https://packagephobia.com/result?p=hereby)
|
|
6
|
-
](https://github.com/XAMPPRocky/tokei)
|
|
7
7
|
[](https://github.com/jakebailey/hereby/actions/workflows/ci.yml)
|
|
8
8
|
[](https://codecov.io/gh/jakebailey/hereby)
|
|
9
9
|
|
package/dist/cli/formatTasks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
1
|
import commandLineUsage from "command-line-usage";
|
|
2
|
+
import pc from "picocolors";
|
|
3
3
|
import { stringSorter, taskSorter } from "./utils.js";
|
|
4
4
|
export function formatTasks(format, tasks, defaultTask) {
|
|
5
5
|
tasks = tasks
|
|
@@ -15,8 +15,8 @@ export function formatTasks(format, tasks, defaultTask) {
|
|
|
15
15
|
content: tasks.map((task) => {
|
|
16
16
|
var _a;
|
|
17
17
|
const name = task !== defaultTask
|
|
18
|
-
?
|
|
19
|
-
: `${
|
|
18
|
+
? pc.blue(task.options.name)
|
|
19
|
+
: `${pc.green(task.options.name)} (default)`;
|
|
20
20
|
const descriptionParts = [];
|
|
21
21
|
if (task.options.description) {
|
|
22
22
|
descriptionParts.push(task.options.description);
|
|
@@ -26,7 +26,7 @@ export function formatTasks(format, tasks, defaultTask) {
|
|
|
26
26
|
const depNames = deps
|
|
27
27
|
.map((task) => task.options.name)
|
|
28
28
|
.sort(stringSorter)
|
|
29
|
-
.map((v) =>
|
|
29
|
+
.map((v) => pc.blue(v));
|
|
30
30
|
descriptionParts.push(`Depends on: ${depNames.join(", ")}`);
|
|
31
31
|
}
|
|
32
32
|
return { name, description: descriptionParts.join("\n") };
|
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import { closest, distance } from "fastest-levenshtein";
|
|
3
1
|
import path from "path";
|
|
2
|
+
import pc from "picocolors";
|
|
4
3
|
import { formatTasks } from "./formatTasks.js";
|
|
5
4
|
import { findHerebyfile, loadHerebyfile } from "./loadHerebyfile.js";
|
|
6
5
|
import { getUsage, parseArgs } from "./parseArgs.js";
|
|
@@ -16,7 +15,7 @@ export async function main(d) {
|
|
|
16
15
|
d.setExitCode(e.exitCode);
|
|
17
16
|
}
|
|
18
17
|
else if (e instanceof UserError) {
|
|
19
|
-
d.error(`${
|
|
18
|
+
d.error(`${pc.red("Error")}: ${e.message}`);
|
|
20
19
|
d.setExitCode(1);
|
|
21
20
|
}
|
|
22
21
|
else {
|
|
@@ -37,7 +36,7 @@ async function mainWorker(d) {
|
|
|
37
36
|
return;
|
|
38
37
|
}
|
|
39
38
|
if (args.version) {
|
|
40
|
-
d.log(`hereby ${d.version}`);
|
|
39
|
+
d.log(`hereby ${await d.version()}`);
|
|
41
40
|
return;
|
|
42
41
|
}
|
|
43
42
|
d.chdir(path.dirname(herebyfilePath));
|
|
@@ -46,9 +45,9 @@ async function mainWorker(d) {
|
|
|
46
45
|
d.log(formatTasks(args.printTasks, herebyfile.tasks, herebyfile.defaultTask));
|
|
47
46
|
return;
|
|
48
47
|
}
|
|
49
|
-
const tasks = selectTasks(d, herebyfile, herebyfilePath, args.run);
|
|
50
|
-
const taskNames = tasks.map((t) => t.options.name).sort().map((name) =>
|
|
51
|
-
d.log(`Using ${
|
|
48
|
+
const tasks = await selectTasks(d, herebyfile, herebyfilePath, args.run);
|
|
49
|
+
const taskNames = tasks.map((t) => t.options.name).sort().map((name) => pc.blue(name)).join(", ");
|
|
50
|
+
d.log(`Using ${pc.yellow(d.simplifyPath(herebyfilePath))} to run ${taskNames}`);
|
|
52
51
|
const start = Date.now();
|
|
53
52
|
let errored = false;
|
|
54
53
|
try {
|
|
@@ -64,28 +63,31 @@ async function mainWorker(d) {
|
|
|
64
63
|
}
|
|
65
64
|
finally {
|
|
66
65
|
const took = Date.now() - start;
|
|
67
|
-
d.log(`Completed ${taskNames}${errored ?
|
|
66
|
+
d.log(`Completed ${taskNames}${errored ? pc.red(" with errors") : ""} in ${d.prettyMilliseconds(took)}`);
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
// Exported for testing.
|
|
71
|
-
export function selectTasks(d, herebyfile, herebyfilePath, taskNames) {
|
|
70
|
+
export async function selectTasks(d, herebyfile, herebyfilePath, taskNames) {
|
|
72
71
|
const allTasks = new Map();
|
|
73
72
|
for (const task of herebyfile.tasks) {
|
|
74
73
|
allTasks.set(task.options.name, task);
|
|
75
74
|
}
|
|
76
75
|
if (taskNames && taskNames.length > 0) {
|
|
77
|
-
|
|
76
|
+
const tasks = [];
|
|
77
|
+
for (const name of taskNames) {
|
|
78
78
|
const task = allTasks.get(name);
|
|
79
79
|
if (!task) {
|
|
80
80
|
let message = `Task "${name}" does not exist or is not exported from ${d.simplifyPath(herebyfilePath)}.`;
|
|
81
|
+
const { closest, distance } = await import("fastest-levenshtein");
|
|
81
82
|
const candidate = closest(name, Array.from(allTasks.keys()));
|
|
82
83
|
if (distance(name, candidate) < name.length * 0.4) {
|
|
83
84
|
message += ` Did you mean "${candidate}"?`;
|
|
84
85
|
}
|
|
85
86
|
throw new UserError(message);
|
|
86
87
|
}
|
|
87
|
-
|
|
88
|
-
}
|
|
88
|
+
tasks.push(task);
|
|
89
|
+
}
|
|
90
|
+
return tasks;
|
|
89
91
|
}
|
|
90
92
|
if (!herebyfile.defaultTask) {
|
|
91
93
|
throw new UserError(`No default task has been exported from ${d.simplifyPath(herebyfilePath)}; please specify a task name.`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { promises as fs } from "fs";
|
|
1
|
+
import fs from "fs";
|
|
3
2
|
import path from "path";
|
|
3
|
+
import pc from "picocolors";
|
|
4
4
|
import { pathToFileURL } from "url";
|
|
5
5
|
import { Task } from "../index.js";
|
|
6
6
|
import { UserError } from "./utils.js";
|
|
@@ -10,14 +10,14 @@ const allFilenames = new Set(extensions.map((e) => filenames.map((f) => `${f}.${
|
|
|
10
10
|
export async function findHerebyfile(dir) {
|
|
11
11
|
const root = path.parse(dir).root;
|
|
12
12
|
for (; dir !== root; dir = path.dirname(dir)) {
|
|
13
|
-
const entries = await fs.readdir(dir);
|
|
13
|
+
const entries = await fs.promises.readdir(dir);
|
|
14
14
|
const matching = entries.filter((e) => allFilenames.has(e));
|
|
15
15
|
if (matching.length > 1) {
|
|
16
16
|
throw new UserError(`Found more than one Herebyfile: ${matching.join(", ")}`);
|
|
17
17
|
}
|
|
18
18
|
if (matching.length === 1) {
|
|
19
19
|
const candidate = path.join(dir, matching[0]);
|
|
20
|
-
const stat = await fs.stat(candidate);
|
|
20
|
+
const stat = await fs.promises.stat(candidate);
|
|
21
21
|
if (!stat.isFile()) {
|
|
22
22
|
throw new UserError(`${matching[0]} is not a file.`);
|
|
23
23
|
}
|
|
@@ -39,7 +39,7 @@ export async function loadHerebyfile(herebyfilePath) {
|
|
|
39
39
|
defaultTask = value;
|
|
40
40
|
}
|
|
41
41
|
else if (exportedTasks.has(value)) {
|
|
42
|
-
throw new UserError(`Task "${
|
|
42
|
+
throw new UserError(`Task "${pc.blue(value.options.name)}" has been exported twice.`);
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
45
|
exportedTasks.add(value);
|
|
@@ -72,11 +72,11 @@ function checkTaskInvariants(tasks) {
|
|
|
72
72
|
continue;
|
|
73
73
|
}
|
|
74
74
|
if (taskStack.has(task)) {
|
|
75
|
-
throw new UserError(`Task "${
|
|
75
|
+
throw new UserError(`Task "${pc.blue(task.options.name)}" references itself.`);
|
|
76
76
|
}
|
|
77
77
|
const name = task.options.name;
|
|
78
78
|
if (seenNames.has(name)) {
|
|
79
|
-
throw new UserError(`Task "${
|
|
79
|
+
throw new UserError(`Task "${pc.blue(name)}" was declared twice.`);
|
|
80
80
|
}
|
|
81
81
|
seenNames.add(name);
|
|
82
82
|
if (task.options.dependencies) {
|
package/dist/cli/reexec.js
CHANGED
|
@@ -33,7 +33,7 @@ export async function reexec(d, herebyfilePath) {
|
|
|
33
33
|
return false;
|
|
34
34
|
}
|
|
35
35
|
const args = [...d.execArgv, otherCLI, ...d.argv.slice(2)];
|
|
36
|
-
d.foregroundChild(d.execPath, args);
|
|
36
|
+
await d.foregroundChild(d.execPath, args);
|
|
37
37
|
return true;
|
|
38
38
|
async function resolveToPath(specifier, url) {
|
|
39
39
|
return fileURLToPath(new URL(await d.resolve(specifier, url.toString())));
|
package/dist/cli/runner.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
|
-
import
|
|
2
|
+
import pc from "picocolors";
|
|
3
3
|
export class Runner {
|
|
4
4
|
constructor(d) {
|
|
5
5
|
this._addedTasks = new WeakMap();
|
|
@@ -49,14 +49,14 @@ export class Runner {
|
|
|
49
49
|
if (this._errored) {
|
|
50
50
|
return; // Skip logging.
|
|
51
51
|
}
|
|
52
|
-
this._d.log(`Starting ${
|
|
52
|
+
this._d.log(`Starting ${pc.blue(task.options.name)}`);
|
|
53
53
|
}
|
|
54
54
|
onTaskFinish(task) {
|
|
55
55
|
if (this._errored) {
|
|
56
56
|
return; // Skip logging.
|
|
57
57
|
}
|
|
58
58
|
const took = Date.now() - checkDefined(this._startTimes.get(task));
|
|
59
|
-
this._d.log(`Finished ${
|
|
59
|
+
this._d.log(`Finished ${pc.green(task.options.name)} in ${this._d.prettyMilliseconds(took)}`);
|
|
60
60
|
}
|
|
61
61
|
onTaskError(task, e) {
|
|
62
62
|
if (this._errored) {
|
|
@@ -64,7 +64,7 @@ export class Runner {
|
|
|
64
64
|
}
|
|
65
65
|
this._errored = true;
|
|
66
66
|
const took = Date.now() - checkDefined(this._startTimes.get(task));
|
|
67
|
-
this._d.error(`Error in ${
|
|
67
|
+
this._d.error(`Error in ${pc.red(task.options.name)} in ${this._d.prettyMilliseconds(took)}\n${e}`);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
function checkDefined(value) {
|
package/dist/cli/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from "fs";
|
|
2
2
|
import os from "os";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
@@ -40,12 +40,8 @@ export class ExitCodeError {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
export async function real() {
|
|
43
|
-
const
|
|
44
|
-
const { resolve } = await import("import-meta-resolve");
|
|
43
|
+
const importResolve = memoize(async () => (await import("import-meta-resolve")).resolve);
|
|
45
44
|
const { default: prettyMilliseconds } = await import("pretty-ms");
|
|
46
|
-
const packageJsonPath = fileURLToPath(await resolve("hereby/package.json", import.meta.url));
|
|
47
|
-
const packageJson = await fs.readFile(packageJsonPath, "utf-8");
|
|
48
|
-
const { version } = JSON.parse(packageJson);
|
|
49
45
|
/* eslint-disable no-restricted-globals */
|
|
50
46
|
return {
|
|
51
47
|
log: console.log,
|
|
@@ -61,12 +57,30 @@ export async function real() {
|
|
|
61
57
|
setExitCode: (code) => {
|
|
62
58
|
process.exitCode = code;
|
|
63
59
|
},
|
|
64
|
-
version
|
|
60
|
+
version: async () => {
|
|
61
|
+
// Not bothering to memoize this function; it will only be called once.
|
|
62
|
+
const resolve = await importResolve();
|
|
63
|
+
const packageJsonPath = fileURLToPath(await resolve("hereby/package.json", import.meta.url));
|
|
64
|
+
const packageJson = await fs.promises.readFile(packageJsonPath, "utf-8");
|
|
65
|
+
const { version } = JSON.parse(packageJson);
|
|
66
|
+
return version;
|
|
67
|
+
},
|
|
65
68
|
isPnP: !!process.versions["pnp"],
|
|
66
|
-
foregroundChild,
|
|
67
|
-
|
|
69
|
+
foregroundChild: async (program, args) => {
|
|
70
|
+
// Not bothering to memoize this import; it will only be called once.
|
|
71
|
+
const { default: foregroundChild } = await import("foreground-child");
|
|
72
|
+
foregroundChild(program, args);
|
|
73
|
+
},
|
|
74
|
+
resolve: async (specifier, parent) => {
|
|
75
|
+
const resolve = await importResolve();
|
|
76
|
+
return resolve(specifier, parent);
|
|
77
|
+
},
|
|
68
78
|
prettyMilliseconds,
|
|
69
79
|
};
|
|
70
80
|
/* eslint-enable no-restricted-globals */
|
|
71
81
|
}
|
|
82
|
+
function memoize(fn) {
|
|
83
|
+
let value;
|
|
84
|
+
return () => (value !== null && value !== void 0 ? value : (value = fn()));
|
|
85
|
+
}
|
|
72
86
|
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hereby",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.4",
|
|
4
4
|
"description": "A simple task runner",
|
|
5
5
|
"repository": "github:jakebailey/hereby",
|
|
6
6
|
"type": "module",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"./dist/index.d.ts"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"chalk": "^5.1.2",
|
|
42
41
|
"command-line-args": "^5.2.1",
|
|
43
42
|
"command-line-usage": "^6.1.3",
|
|
44
43
|
"fastest-levenshtein": "^1.0.16",
|
|
45
44
|
"foreground-child": "^2.0.0",
|
|
46
45
|
"import-meta-resolve": "^2.1.0",
|
|
46
|
+
"picocolors": "^1.0.0",
|
|
47
47
|
"pretty-ms": "^8.0.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"@tsconfig/node12": "^1.0.11",
|
|
52
52
|
"@types/command-line-args": "^5.2.0",
|
|
53
53
|
"@types/command-line-usage": "^5.0.2",
|
|
54
|
+
"@types/foreground-child": "^2.0.0",
|
|
54
55
|
"@types/node": "^14.18.32",
|
|
55
56
|
"@types/tmp": "^0.2.3",
|
|
56
57
|
"@typescript-eslint/eslint-plugin": "^5.40.1",
|
|
@@ -88,7 +89,7 @@
|
|
|
88
89
|
"compile": false
|
|
89
90
|
},
|
|
90
91
|
"environmentVariables": {
|
|
91
|
-
"
|
|
92
|
+
"NO_COLOR": "1"
|
|
92
93
|
}
|
|
93
94
|
},
|
|
94
95
|
"c8": {
|