hereby 1.8.7 → 1.8.9
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 +4 -4
- package/dist/cli/formatTasks.js +3 -3
- package/dist/cli/index.js +4 -5
- package/dist/cli/loadHerebyfile.js +20 -24
- package/dist/cli/utils.js +15 -6
- package/package.json +14 -25
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
`hereby` is a simple task runner.
|
|
13
13
|
|
|
14
|
-
```
|
|
14
|
+
```console
|
|
15
15
|
$ npm i -D hereby
|
|
16
16
|
$ yarn add -D hereby
|
|
17
17
|
```
|
|
@@ -73,7 +73,7 @@ export const bundle = task({
|
|
|
73
73
|
|
|
74
74
|
Given the above Herebyfile:
|
|
75
75
|
|
|
76
|
-
```
|
|
76
|
+
```console
|
|
77
77
|
$ hereby build # Run the "build" task
|
|
78
78
|
$ hereby test # Run the "test" task, which depends on "build".
|
|
79
79
|
$ hereby # Run the default exported task.
|
|
@@ -84,7 +84,7 @@ $ hereby test bundle # Run the "test" and "bundle" tasks in parallel.
|
|
|
84
84
|
|
|
85
85
|
`hereby` also supports a handful of flags:
|
|
86
86
|
|
|
87
|
-
```
|
|
87
|
+
```console
|
|
88
88
|
-h, --help Display this usage guide.
|
|
89
89
|
--herebyfile path A path to a Herebyfile. Optional.
|
|
90
90
|
-T, --tasks Print a listing of the available tasks.
|
|
@@ -125,7 +125,7 @@ anyway).
|
|
|
125
125
|
To run tasks in a specific order and more than once, run `hereby` multiple
|
|
126
126
|
times:
|
|
127
127
|
|
|
128
|
-
```
|
|
128
|
+
```console
|
|
129
129
|
$ hereby build
|
|
130
130
|
$ hereby clean
|
|
131
131
|
$ hereby build
|
package/dist/cli/formatTasks.js
CHANGED
|
@@ -2,13 +2,13 @@ import commandLineUsage from "command-line-usage";
|
|
|
2
2
|
import pc from "picocolors";
|
|
3
3
|
import { compareTaskNames } from "./utils.js";
|
|
4
4
|
export function formatTasks(format, tasks, defaultTask) {
|
|
5
|
-
|
|
5
|
+
const visibleTasks = [...tasks].filter(isTaskVisible).sort(compareTaskNames);
|
|
6
6
|
if (format === "simple") {
|
|
7
|
-
return
|
|
7
|
+
return visibleTasks.map((task) => task.options.name).join("\n");
|
|
8
8
|
}
|
|
9
9
|
return commandLineUsage({
|
|
10
10
|
header: "Available tasks",
|
|
11
|
-
content:
|
|
11
|
+
content: visibleTasks.map((task) => {
|
|
12
12
|
var _a;
|
|
13
13
|
const name = task === defaultTask
|
|
14
14
|
? `${pc.green(task.options.name)} (default)`
|
package/dist/cli/index.js
CHANGED
|
@@ -35,7 +35,7 @@ async function mainWorker(d) {
|
|
|
35
35
|
d.log(getUsage());
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
-
let herebyfilePath = (_a = args.herebyfile) !== null && _a !== void 0 ? _a :
|
|
38
|
+
let herebyfilePath = (_a = args.herebyfile) !== null && _a !== void 0 ? _a : findHerebyfile(d.cwd());
|
|
39
39
|
herebyfilePath = path.resolve(d.cwd(), herebyfilePath);
|
|
40
40
|
if (await reexec(d, herebyfilePath)) {
|
|
41
41
|
return;
|
|
@@ -47,7 +47,7 @@ async function mainWorker(d) {
|
|
|
47
47
|
d.chdir(path.dirname(herebyfilePath));
|
|
48
48
|
const herebyfile = await loadHerebyfile(herebyfilePath);
|
|
49
49
|
if (args.printTasks) {
|
|
50
|
-
d.log(formatTasks(args.printTasks, herebyfile.tasks, herebyfile.defaultTask));
|
|
50
|
+
d.log(formatTasks(args.printTasks, herebyfile.tasks.values(), herebyfile.defaultTask));
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
53
|
const tasks = await selectTasks(d, herebyfile, herebyfilePath, args.run);
|
|
@@ -79,14 +79,13 @@ export async function selectTasks(d, herebyfile, herebyfilePath, taskNames) {
|
|
|
79
79
|
}
|
|
80
80
|
return [herebyfile.defaultTask];
|
|
81
81
|
}
|
|
82
|
-
const allTasks = new Map(herebyfile.tasks.map((task) => [task.options.name, task]));
|
|
83
82
|
const tasks = [];
|
|
84
83
|
for (const name of taskNames) {
|
|
85
|
-
const task =
|
|
84
|
+
const task = herebyfile.tasks.get(name);
|
|
86
85
|
if (!task) {
|
|
87
86
|
let message = `Task "${name}" does not exist or is not exported from ${d.simplifyPath(herebyfilePath)}.`;
|
|
88
87
|
const { closest, distance } = await import("fastest-levenshtein");
|
|
89
|
-
const candidate = closest(name, [...
|
|
88
|
+
const candidate = closest(name, [...herebyfile.tasks.keys()]);
|
|
90
89
|
if (distance(name, candidate) < name.length * 0.4) {
|
|
91
90
|
message += ` Did you mean "${candidate}"?`;
|
|
92
91
|
}
|
|
@@ -3,30 +3,29 @@ import path from "node:path";
|
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
import pc from "picocolors";
|
|
5
5
|
import { Task } from "../index.js";
|
|
6
|
-
import { UserError } from "./utils.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const root = path.parse(dir).root;
|
|
13
|
-
for (; dir !== root; dir = path.dirname(dir)) {
|
|
14
|
-
const entries = await fs.promises.readdir(dir);
|
|
15
|
-
const matching = entries.filter(isHerebyfile);
|
|
6
|
+
import { findUp, UserError } from "./utils.js";
|
|
7
|
+
const herebyfileRegExp = /^herebyfile\.m?js$/i;
|
|
8
|
+
export function findHerebyfile(dir) {
|
|
9
|
+
const result = findUp(dir, (dir) => {
|
|
10
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
11
|
+
const matching = entries.filter((e) => herebyfileRegExp.test(e.name));
|
|
16
12
|
if (matching.length > 1) {
|
|
17
|
-
throw new UserError(`Found more than one Herebyfile: ${matching.join(", ")}`);
|
|
13
|
+
throw new UserError(`Found more than one Herebyfile: ${matching.map((e) => e.name).join(", ")}`);
|
|
18
14
|
}
|
|
19
15
|
if (matching.length === 1) {
|
|
20
|
-
const candidate =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
throw new UserError(`${matching[0]} is not a file.`);
|
|
16
|
+
const candidate = matching[0];
|
|
17
|
+
if (!candidate.isFile()) {
|
|
18
|
+
throw new UserError(`${candidate.name} is not a file.`);
|
|
24
19
|
}
|
|
25
|
-
return candidate;
|
|
20
|
+
return path.join(dir, candidate.name);
|
|
26
21
|
}
|
|
27
|
-
if (entries.
|
|
28
|
-
|
|
22
|
+
if (entries.some((e) => e.name === "package.json")) {
|
|
23
|
+
return false; // TODO: Is this actually desirable? What about monorepos?
|
|
29
24
|
}
|
|
25
|
+
return undefined;
|
|
26
|
+
});
|
|
27
|
+
if (result) {
|
|
28
|
+
return result;
|
|
30
29
|
}
|
|
31
30
|
throw new UserError("Unable to find Herebyfile.");
|
|
32
31
|
}
|
|
@@ -55,14 +54,11 @@ export async function loadHerebyfile(herebyfilePath) {
|
|
|
55
54
|
if (exportedTasks.size === 0) {
|
|
56
55
|
throw new UserError("No tasks found. Did you forget to export your tasks?");
|
|
57
56
|
}
|
|
58
|
-
const tasks = [...exportedTasks.values()];
|
|
59
57
|
// We check this here by walking the DAG, as some dependencies may not be
|
|
60
58
|
// exported and therefore would not be seen by the above loop.
|
|
61
|
-
checkTaskInvariants(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
defaultTask,
|
|
65
|
-
};
|
|
59
|
+
checkTaskInvariants(exportedTasks);
|
|
60
|
+
const tasks = new Map([...exportedTasks].map((task) => [task.options.name, task]));
|
|
61
|
+
return { tasks, defaultTask };
|
|
66
62
|
}
|
|
67
63
|
function checkTaskInvariants(tasks) {
|
|
68
64
|
const checkedTasks = new Set();
|
package/dist/cli/utils.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
4
|
export function compareTaskNames(a, b) {
|
|
6
5
|
return compareStrings(a.options.name, b.options.name);
|
|
7
6
|
}
|
|
@@ -17,6 +16,18 @@ export function simplifyPath(p) {
|
|
|
17
16
|
}
|
|
18
17
|
return p;
|
|
19
18
|
}
|
|
19
|
+
export function findUp(p, predicate) {
|
|
20
|
+
const root = path.parse(p).root;
|
|
21
|
+
while (true) {
|
|
22
|
+
const result = predicate(p);
|
|
23
|
+
if (result !== undefined)
|
|
24
|
+
return result;
|
|
25
|
+
if (p === root)
|
|
26
|
+
break;
|
|
27
|
+
p = path.dirname(p);
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
20
31
|
/**
|
|
21
32
|
* UserError is a special error that, when caught in the CLI will be printed
|
|
22
33
|
* as a message only, without stacktrace. Use this instead of process.exit.
|
|
@@ -49,11 +60,9 @@ export async function real() {
|
|
|
49
60
|
process.exitCode = code;
|
|
50
61
|
},
|
|
51
62
|
version: async () => {
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
const { version } = JSON.parse(packageJson);
|
|
56
|
-
return version;
|
|
63
|
+
const packageJsonURL = new URL("../../package.json", import.meta.url);
|
|
64
|
+
const packageJson = await fs.promises.readFile(packageJsonURL, "utf8");
|
|
65
|
+
return JSON.parse(packageJson).version;
|
|
57
66
|
},
|
|
58
67
|
resolve: async (specifier, parent) => {
|
|
59
68
|
const { resolve } = await import("import-meta-resolve");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hereby",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.9",
|
|
4
4
|
"description": "A simple task runner",
|
|
5
5
|
"repository": "github:jakebailey/hereby",
|
|
6
6
|
"type": "module",
|
|
@@ -48,25 +48,26 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@ava/typescript": "^3.0.1",
|
|
51
|
+
"@changesets/cli": "^2.27.1",
|
|
51
52
|
"@tsconfig/node12": "^12.1.0",
|
|
52
|
-
"@types/command-line-usage": "^5.0.
|
|
53
|
-
"@types/minimist": "^1.2.
|
|
54
|
-
"@types/node": "^20.
|
|
55
|
-
"@types/tmp": "^0.2.
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
57
|
-
"@typescript-eslint/parser": "^6.
|
|
53
|
+
"@types/command-line-usage": "^5.0.4",
|
|
54
|
+
"@types/minimist": "^1.2.5",
|
|
55
|
+
"@types/node": "^20.10.6",
|
|
56
|
+
"@types/tmp": "^0.2.6",
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "^6.17.0",
|
|
58
|
+
"@typescript-eslint/parser": "^6.17.0",
|
|
58
59
|
"ava": "~5.0.1",
|
|
59
60
|
"c8": "^8.0.1",
|
|
60
|
-
"dprint": "^0.
|
|
61
|
-
"eslint": "^8.
|
|
61
|
+
"dprint": "^0.45.0",
|
|
62
|
+
"eslint": "^8.56.0",
|
|
62
63
|
"eslint-plugin-ava": "^14.0.0",
|
|
63
64
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
64
|
-
"eslint-plugin-unicorn": "^
|
|
65
|
+
"eslint-plugin-unicorn": "^50.0.1",
|
|
65
66
|
"execa": "^6.1.0",
|
|
66
|
-
"moq.ts": "^10.0
|
|
67
|
-
"rimraf": "^5.0.
|
|
67
|
+
"moq.ts": "^10.1.0",
|
|
68
|
+
"rimraf": "^5.0.5",
|
|
68
69
|
"tmp": "^0.2.1",
|
|
69
|
-
"typescript": "^5.
|
|
70
|
+
"typescript": "^5.3.3"
|
|
70
71
|
},
|
|
71
72
|
"overrides": {
|
|
72
73
|
"ava": {
|
|
@@ -101,17 +102,5 @@
|
|
|
101
102
|
"html",
|
|
102
103
|
"lcov"
|
|
103
104
|
]
|
|
104
|
-
},
|
|
105
|
-
"release-it": {
|
|
106
|
-
"npm": {
|
|
107
|
-
"publish": false
|
|
108
|
-
},
|
|
109
|
-
"git": {
|
|
110
|
-
"commitMessage": "Release v${version}",
|
|
111
|
-
"tagName": "v${version}"
|
|
112
|
-
},
|
|
113
|
-
"hooks": {
|
|
114
|
-
"before:init": "npm run build && npm run test"
|
|
115
|
-
}
|
|
116
105
|
}
|
|
117
106
|
}
|