hereby 1.0.4 → 1.0.5
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 +34 -33
- package/dist/cli/reexec.js +7 -9
- package/dist/cli/runner.js +7 -12
- package/dist/cli/utils.js +22 -8
- package/dist/cli.js +2 -3
- package/package.json +2 -7
package/dist/cli/index.js
CHANGED
|
@@ -4,71 +4,72 @@ import { formatTasks } from "./formatTasks.js";
|
|
|
4
4
|
import { findHerebyfile, loadHerebyfile } from "./loadHerebyfile.js";
|
|
5
5
|
import { getUsage, parseArgs } from "./parseArgs.js";
|
|
6
6
|
import { reexec } from "./reexec.js";
|
|
7
|
-
import {
|
|
7
|
+
import { CLIRunner } from "./runner.js";
|
|
8
8
|
import { ExitCodeError, simplifyPath, UserError } from "./utils.js";
|
|
9
|
-
export async function main(
|
|
9
|
+
export async function main(d) {
|
|
10
10
|
try {
|
|
11
|
-
await mainWorker(
|
|
11
|
+
await mainWorker(d);
|
|
12
12
|
}
|
|
13
13
|
catch (e) {
|
|
14
14
|
if (e instanceof ExitCodeError) {
|
|
15
|
-
|
|
15
|
+
d.setExitCode(e.exitCode);
|
|
16
16
|
}
|
|
17
17
|
else if (e instanceof UserError) {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
d.error(`${chalk.red("Error")}: ${e.message}`);
|
|
19
|
+
d.setExitCode(1);
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
22
|
throw e;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
async function mainWorker(
|
|
27
|
-
const args = parseArgs(
|
|
26
|
+
async function mainWorker(d) {
|
|
27
|
+
const args = parseArgs(d.argv.slice(2));
|
|
28
28
|
if (args.help) {
|
|
29
|
-
|
|
29
|
+
d.log(getUsage());
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
-
let herebyfilePath = args.herebyfile ?? (await findHerebyfile(
|
|
33
|
-
herebyfilePath = path.resolve(
|
|
34
|
-
if (await reexec(
|
|
32
|
+
let herebyfilePath = args.herebyfile ?? (await findHerebyfile(d.cwd()));
|
|
33
|
+
herebyfilePath = path.resolve(d.cwd(), herebyfilePath);
|
|
34
|
+
if (await reexec(d, herebyfilePath)) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
d.chdir(path.dirname(herebyfilePath));
|
|
38
|
+
d.log(`Using ${simplifyPath(herebyfilePath)}`);
|
|
38
39
|
const herebyfile = await loadHerebyfile(herebyfilePath);
|
|
39
40
|
if (args.printTasks) {
|
|
40
|
-
|
|
41
|
+
d.log(formatTasks(herebyfile.tasks, herebyfile.defaultTask));
|
|
41
42
|
return;
|
|
42
43
|
}
|
|
44
|
+
const tasks = selectTasks(herebyfile, args.run);
|
|
45
|
+
try {
|
|
46
|
+
const runner = new CLIRunner(d);
|
|
47
|
+
await runner.runTasks(...tasks);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
// We will have already printed some message here.
|
|
51
|
+
// Set the error code and let the process run to completion,
|
|
52
|
+
// so we don't end up with an unflushed output.
|
|
53
|
+
throw new ExitCodeError(1, e);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function selectTasks(herebyfile, taskNames) {
|
|
43
57
|
const allTasks = new Map();
|
|
44
58
|
for (const task of herebyfile.tasks) {
|
|
45
59
|
allTasks.set(task.options.name, task);
|
|
46
60
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
tasks = args.run.map((name) => {
|
|
61
|
+
if (taskNames && taskNames.length > 0) {
|
|
62
|
+
return taskNames.map((name) => {
|
|
50
63
|
const task = allTasks.get(name);
|
|
51
64
|
if (!task) {
|
|
52
|
-
throw new UserError(`Task ${name} does not exist or is not exported in the Herebyfile.`);
|
|
65
|
+
throw new UserError(`Task "${name}" does not exist or is not exported in the Herebyfile.`);
|
|
53
66
|
}
|
|
54
67
|
return task;
|
|
55
68
|
});
|
|
56
69
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
throw new UserError("No default task defined; please specify a task name.");
|
|
60
|
-
}
|
|
61
|
-
tasks = [herebyfile.defaultTask];
|
|
62
|
-
}
|
|
63
|
-
system.log(`Using ${simplifyPath(herebyfilePath)}`);
|
|
64
|
-
try {
|
|
65
|
-
await runTasksWithCLIRunner(system, ...tasks);
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
// We will have already printed some message here.
|
|
69
|
-
// Set the error code and let the process run to completion,
|
|
70
|
-
// so we don't end up with an unflushed output.
|
|
71
|
-
throw new ExitCodeError(1);
|
|
70
|
+
if (!herebyfile.defaultTask) {
|
|
71
|
+
throw new UserError("No default task defined; please specify a task name.");
|
|
72
72
|
}
|
|
73
|
+
return [herebyfile.defaultTask];
|
|
73
74
|
}
|
|
74
75
|
//# sourceMappingURL=index.js.map
|
package/dist/cli/reexec.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import foregroundChild from "foreground-child";
|
|
3
|
-
import { resolve } from "import-meta-resolve";
|
|
4
2
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
5
3
|
import { UserError } from "./utils.js";
|
|
6
|
-
export async function reexec(
|
|
4
|
+
export async function reexec(d, herebyfilePath) {
|
|
7
5
|
// If hereby is installed globally, but run against a Herebyfile in some
|
|
8
6
|
// other package, that Herebyfile's import will resolve to a different
|
|
9
7
|
// installation of the hereby package. There's no guarantee that the two
|
|
@@ -27,12 +25,12 @@ export async function reexec(system, herebyfilePath) {
|
|
|
27
25
|
return false;
|
|
28
26
|
}
|
|
29
27
|
// TODO: If this turns out to be common, remove this warning.
|
|
30
|
-
|
|
31
|
-
const args = [...
|
|
32
|
-
foregroundChild(
|
|
28
|
+
d.error(`${chalk.yellow("Warning")}: re-running hereby as imported by the Herebyfile.`);
|
|
29
|
+
const args = [...d.execArgv, otherCLI, ...d.argv.slice(2)];
|
|
30
|
+
d.foregroundChild(d.execPath, args);
|
|
33
31
|
return true;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
async function resolveToPath(specifier, url) {
|
|
33
|
+
return fileURLToPath(new URL(await d.resolve(specifier, url.toString())));
|
|
34
|
+
}
|
|
37
35
|
}
|
|
38
36
|
//# sourceMappingURL=reexec.js.map
|
package/dist/cli/runner.js
CHANGED
|
@@ -1,38 +1,33 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
2
|
import chalk from "chalk";
|
|
3
|
-
import prettyMilliseconds from "pretty-ms";
|
|
4
3
|
import { Runner } from "../runner.js";
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
class CLIRunner extends Runner {
|
|
9
|
-
constructor(options) {
|
|
10
|
-
super(options);
|
|
4
|
+
export class CLIRunner extends Runner {
|
|
5
|
+
constructor(d) {
|
|
6
|
+
super({ concurrency: d.numCPUs });
|
|
11
7
|
this._errored = false;
|
|
12
8
|
this._startTimes = new WeakMap();
|
|
13
|
-
this.
|
|
9
|
+
this._d = d;
|
|
14
10
|
}
|
|
15
11
|
onTaskStart(task) {
|
|
16
12
|
this._startTimes.set(task, Date.now());
|
|
17
13
|
if (this._errored) {
|
|
18
14
|
return; // Skip logging.
|
|
19
15
|
}
|
|
20
|
-
this.
|
|
16
|
+
this._d.log(`Starting ${chalk.blue(task.options.name)}`);
|
|
21
17
|
}
|
|
22
18
|
onTaskFinish(task) {
|
|
23
19
|
if (this._errored) {
|
|
24
20
|
return; // Skip logging.
|
|
25
21
|
}
|
|
26
22
|
const took = Date.now() - checkDefined(this._startTimes.get(task));
|
|
27
|
-
this.
|
|
23
|
+
this._d.log(`Finished ${chalk.green(task.options.name)} in ${this._d.prettyMilliseconds(took)}`);
|
|
28
24
|
}
|
|
29
25
|
onTaskError(task, e) {
|
|
30
26
|
if (this._errored) {
|
|
31
27
|
return; // Skip logging.
|
|
32
28
|
}
|
|
33
29
|
this._errored = true;
|
|
34
|
-
this.
|
|
35
|
-
this._system.error(`${e}`);
|
|
30
|
+
this._d.error(`Error in ${chalk.red(task.options.name)}\n${e}`);
|
|
36
31
|
}
|
|
37
32
|
}
|
|
38
33
|
function checkDefined(value) {
|
package/dist/cli/utils.js
CHANGED
|
@@ -31,20 +31,34 @@ export class UserError extends Error {
|
|
|
31
31
|
* without logging anything.
|
|
32
32
|
*/
|
|
33
33
|
export class ExitCodeError {
|
|
34
|
-
constructor(exitCode) {
|
|
34
|
+
constructor(exitCode, reason) {
|
|
35
35
|
this.exitCode = exitCode;
|
|
36
|
+
this.reason = reason;
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
/* eslint-disable no-restricted-globals */
|
|
40
|
+
export async function real() {
|
|
41
|
+
const { default: foregroundChild } = await import("foreground-child");
|
|
42
|
+
const { resolve } = await import("import-meta-resolve");
|
|
43
|
+
const { default: prettyMilliseconds } = await import("pretty-ms");
|
|
39
44
|
return {
|
|
40
|
-
log
|
|
41
|
-
|
|
45
|
+
log: console.log,
|
|
46
|
+
error: console.error,
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
48
|
+
cwd: process.cwd,
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
50
|
+
chdir: process.chdir,
|
|
51
|
+
argv: process.argv,
|
|
52
|
+
execArgv: process.execArgv,
|
|
53
|
+
execPath: process.execPath,
|
|
54
|
+
setExitCode: (code) => {
|
|
55
|
+
process.exitCode = code;
|
|
42
56
|
},
|
|
43
|
-
error(message) {
|
|
44
|
-
process.stderr.write(message + "\n");
|
|
45
|
-
},
|
|
46
|
-
process,
|
|
47
57
|
numCPUs: os.cpus().length,
|
|
58
|
+
foregroundChild,
|
|
59
|
+
resolve,
|
|
60
|
+
prettyMilliseconds,
|
|
48
61
|
};
|
|
49
62
|
}
|
|
63
|
+
/* eslint-enable no-restricted-globals */
|
|
50
64
|
//# sourceMappingURL=utils.js.map
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { main } from "./cli/index.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
await main(createSystem(process));
|
|
3
|
+
import { real } from "./cli/utils.js";
|
|
4
|
+
await main(await real());
|
|
6
5
|
//# sourceMappingURL=cli.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hereby",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "A simple task runner",
|
|
5
5
|
"repository": "github:jakebailey/hereby",
|
|
6
6
|
"type": "module",
|
|
@@ -35,8 +35,7 @@
|
|
|
35
35
|
"LICENSE",
|
|
36
36
|
"./dist/**/*.js",
|
|
37
37
|
"!**/__tests__/**",
|
|
38
|
-
"./dist/index.d.ts"
|
|
39
|
-
"!./dist/testUtils.js"
|
|
38
|
+
"./dist/index.d.ts"
|
|
40
39
|
],
|
|
41
40
|
"dependencies": {
|
|
42
41
|
"chalk": "^5.0.1",
|
|
@@ -57,12 +56,10 @@
|
|
|
57
56
|
"@typescript-eslint/parser": "^5.33.1",
|
|
58
57
|
"ava": "^4.3.1",
|
|
59
58
|
"c8": "^7.12.0",
|
|
60
|
-
"cross-env": "^7.0.3",
|
|
61
59
|
"eslint": "^8.22.0",
|
|
62
60
|
"eslint-config-prettier": "^8.5.0",
|
|
63
61
|
"eslint-plugin-ava": "^13.2.0",
|
|
64
62
|
"eslint-plugin-simple-import-sort": "^7.0.0",
|
|
65
|
-
"esmock": "^1.9.4",
|
|
66
63
|
"execa": "^6.1.0",
|
|
67
64
|
"moq.ts": "^9.0.2",
|
|
68
65
|
"prettier": "^2.7.1",
|
|
@@ -91,8 +88,6 @@
|
|
|
91
88
|
"compile": false
|
|
92
89
|
},
|
|
93
90
|
"environmentVariables": {
|
|
94
|
-
"NODE_OPTIONS": "--loader=esmock",
|
|
95
|
-
"NODE_NO_WARNINGS": "1",
|
|
96
91
|
"FORCE_COLOR": "0"
|
|
97
92
|
}
|
|
98
93
|
},
|