hereby 1.6.3 → 1.7.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/README.md +2 -2
- 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 +12 -13
- package/dist/cli/runner.js +4 -4
- package/dist/cli/utils.js +18 -11
- package/dist/index.js +8 -8
- package/package.json +19 -16
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
|
|
|
@@ -108,7 +108,7 @@ well.
|
|
|
108
108
|
`hereby` does not support running tasks in series; specifying multiple tasks at
|
|
109
109
|
the CLI or as dependencies of another task will run them in parallel. This
|
|
110
110
|
matches the behavior of tools like `make`, which like `hereby` intend to encode
|
|
111
|
-
a
|
|
111
|
+
a dependency graph of tasks, not act as a script.
|
|
112
112
|
|
|
113
113
|
In general, if you're trying to emulate a serial task, you will likely be better
|
|
114
114
|
served by writing out explicit dependencies for your tasks.
|
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
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { pathToFileURL } from "url";
|
|
2
2
|
import { UserError } from "./utils.js";
|
|
3
|
+
const cliExportName = "hereby/cli";
|
|
4
|
+
/**
|
|
5
|
+
* Checks to see if we need to re-exec another version of hereby.
|
|
6
|
+
* If this function returns true, the caller should return immediately
|
|
7
|
+
* and do no further work.
|
|
8
|
+
*/
|
|
3
9
|
export async function reexec(d, herebyfilePath) {
|
|
4
10
|
// If hereby is installed globally, but run against a Herebyfile in some
|
|
5
11
|
// other package, that Herebyfile's import will resolve to a different
|
|
6
12
|
// installation of the hereby package. There's no guarantee that the two
|
|
7
|
-
// are compatible (in fact, are guaranteed not to
|
|
13
|
+
// are compatible (in fact, they are guaranteed not to as Task is a class).
|
|
8
14
|
//
|
|
9
15
|
// Rather than trying to fix this by messing around with Node's resolution
|
|
10
16
|
// (which won't work in ESM anyway), instead opt to figure out the location
|
|
11
|
-
// of hereby as imported by the Herebyfile, and
|
|
12
|
-
//
|
|
13
|
-
// TODO: Rather than spawning a child process, perhaps we could instead
|
|
14
|
-
// import the CLI from the other version and run it.
|
|
17
|
+
// of hereby as imported by the Herebyfile, and then "reexec" it by importing.
|
|
15
18
|
if (d.isPnP) {
|
|
16
19
|
// When we are running within PnP, we can't really figure out what to
|
|
17
20
|
// do. import-meta-resolve doesn't implement this, so we can't do
|
|
@@ -21,10 +24,10 @@ export async function reexec(d, herebyfilePath) {
|
|
|
21
24
|
// a mismatch.
|
|
22
25
|
return false;
|
|
23
26
|
}
|
|
24
|
-
const thisCLI = await
|
|
27
|
+
const thisCLI = await d.resolve(cliExportName, import.meta.url);
|
|
25
28
|
let otherCLI;
|
|
26
29
|
try {
|
|
27
|
-
otherCLI = await
|
|
30
|
+
otherCLI = await d.resolve(cliExportName, pathToFileURL(herebyfilePath).toString());
|
|
28
31
|
}
|
|
29
32
|
catch {
|
|
30
33
|
throw new UserError("Unable to find hereby; ensure hereby is installed in your package.");
|
|
@@ -32,11 +35,7 @@ export async function reexec(d, herebyfilePath) {
|
|
|
32
35
|
if (thisCLI === otherCLI) {
|
|
33
36
|
return false;
|
|
34
37
|
}
|
|
35
|
-
|
|
36
|
-
d.foregroundChild(d.execPath, args);
|
|
38
|
+
await import(otherCLI);
|
|
37
39
|
return true;
|
|
38
|
-
async function resolveToPath(specifier, url) {
|
|
39
|
-
return fileURLToPath(new URL(await d.resolve(specifier, url.toString())));
|
|
40
|
-
}
|
|
41
40
|
}
|
|
42
41
|
//# sourceMappingURL=reexec.js.map
|
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,
|
|
@@ -56,17 +52,28 @@ export async function real() {
|
|
|
56
52
|
chdir: process.chdir,
|
|
57
53
|
simplifyPath,
|
|
58
54
|
argv: process.argv,
|
|
59
|
-
execArgv: process.execArgv,
|
|
60
|
-
execPath: process.execPath,
|
|
61
55
|
setExitCode: (code) => {
|
|
62
56
|
process.exitCode = code;
|
|
63
57
|
},
|
|
64
|
-
version
|
|
58
|
+
version: async () => {
|
|
59
|
+
// Not bothering to memoize this function; it will only be called once.
|
|
60
|
+
const resolve = await importResolve();
|
|
61
|
+
const packageJsonPath = fileURLToPath(await resolve("hereby/package.json", import.meta.url));
|
|
62
|
+
const packageJson = await fs.promises.readFile(packageJsonPath, "utf-8");
|
|
63
|
+
const { version } = JSON.parse(packageJson);
|
|
64
|
+
return version;
|
|
65
|
+
},
|
|
65
66
|
isPnP: !!process.versions["pnp"],
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
resolve: async (specifier, parent) => {
|
|
68
|
+
const resolve = await importResolve();
|
|
69
|
+
return resolve(specifier, parent);
|
|
70
|
+
},
|
|
68
71
|
prettyMilliseconds,
|
|
69
72
|
};
|
|
70
73
|
/* eslint-enable no-restricted-globals */
|
|
71
74
|
}
|
|
75
|
+
function memoize(fn) {
|
|
76
|
+
let value;
|
|
77
|
+
return () => (value !== null && value !== void 0 ? value : (value = fn()));
|
|
78
|
+
}
|
|
72
79
|
//# sourceMappingURL=utils.js.map
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
* A hereby Task. To get an instance, call `test`.
|
|
3
3
|
*/
|
|
4
4
|
export class Task {
|
|
5
|
+
/* @internal */
|
|
6
|
+
get options() {
|
|
7
|
+
return this._options;
|
|
8
|
+
}
|
|
9
|
+
/* @internal */
|
|
10
|
+
static create(options) {
|
|
11
|
+
return new Task(options);
|
|
12
|
+
}
|
|
5
13
|
constructor(options) {
|
|
6
14
|
// Runtime typecheck; consumers of hereby may not have enabled
|
|
7
15
|
// typechecking, so this is helpful.
|
|
@@ -37,14 +45,6 @@ export class Task {
|
|
|
37
45
|
}
|
|
38
46
|
this._options = options;
|
|
39
47
|
}
|
|
40
|
-
/* @internal */
|
|
41
|
-
get options() {
|
|
42
|
-
return this._options;
|
|
43
|
-
}
|
|
44
|
-
/* @internal */
|
|
45
|
-
static create(options) {
|
|
46
|
-
return new Task(options);
|
|
47
|
-
}
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* Creates a new Task.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hereby",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "A simple task runner",
|
|
5
5
|
"repository": "github:jakebailey/hereby",
|
|
6
6
|
"type": "module",
|
|
@@ -38,12 +38,11 @@
|
|
|
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
|
-
"
|
|
46
|
-
"
|
|
44
|
+
"import-meta-resolve": "^2.2.1",
|
|
45
|
+
"picocolors": "^1.0.0",
|
|
47
46
|
"pretty-ms": "^8.0.0"
|
|
48
47
|
},
|
|
49
48
|
"devDependencies": {
|
|
@@ -51,22 +50,26 @@
|
|
|
51
50
|
"@tsconfig/node12": "^1.0.11",
|
|
52
51
|
"@types/command-line-args": "^5.2.0",
|
|
53
52
|
"@types/command-line-usage": "^5.0.2",
|
|
54
|
-
"@types/node": "^14.18.
|
|
53
|
+
"@types/node": "^14.18.36",
|
|
55
54
|
"@types/tmp": "^0.2.3",
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
57
|
-
"@typescript-eslint/parser": "^5.
|
|
58
|
-
"ava": "
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^5.48.2",
|
|
56
|
+
"@typescript-eslint/parser": "^5.48.2",
|
|
57
|
+
"ava": "~5.0.1",
|
|
59
58
|
"c8": "^7.12.0",
|
|
60
|
-
"dprint": "^0.
|
|
61
|
-
"eslint": "^8.
|
|
62
|
-
"eslint-plugin-ava": "^
|
|
63
|
-
"eslint-plugin-simple-import-sort": "^
|
|
59
|
+
"dprint": "^0.34.4",
|
|
60
|
+
"eslint": "^8.32.0",
|
|
61
|
+
"eslint-plugin-ava": "^14.0.0",
|
|
62
|
+
"eslint-plugin-simple-import-sort": "^9.0.0",
|
|
64
63
|
"execa": "^6.1.0",
|
|
65
64
|
"moq.ts": "^9.0.2",
|
|
66
|
-
"
|
|
67
|
-
"rimraf": "^3.0.2",
|
|
65
|
+
"rimraf": "^4.1.1",
|
|
68
66
|
"tmp": "^0.2.1",
|
|
69
|
-
"typescript": "~4.
|
|
67
|
+
"typescript": "~4.9.4"
|
|
68
|
+
},
|
|
69
|
+
"overrides": {
|
|
70
|
+
"ava": {
|
|
71
|
+
"emittery": "1.0.0"
|
|
72
|
+
}
|
|
70
73
|
},
|
|
71
74
|
"packageManager": "npm@8.17.0",
|
|
72
75
|
"volta": {
|
|
@@ -88,7 +91,7 @@
|
|
|
88
91
|
"compile": false
|
|
89
92
|
},
|
|
90
93
|
"environmentVariables": {
|
|
91
|
-
"
|
|
94
|
+
"NO_COLOR": "1"
|
|
92
95
|
}
|
|
93
96
|
},
|
|
94
97
|
"c8": {
|