hereby 1.0.5 → 1.1.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/dist/cli/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import chalk from "chalk";
2
+ import { closest, distance } from "fastest-levenshtein";
2
3
  import path from "path";
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
- import { CLIRunner } from "./runner.js";
8
+ import { Runner } from "./runner.js";
8
9
  import { ExitCodeError, simplifyPath, UserError } from "./utils.js";
9
10
  export async function main(d) {
10
11
  try {
@@ -43,7 +44,7 @@ async function mainWorker(d) {
43
44
  }
44
45
  const tasks = selectTasks(herebyfile, args.run);
45
46
  try {
46
- const runner = new CLIRunner(d);
47
+ const runner = new Runner(d);
47
48
  await runner.runTasks(...tasks);
48
49
  }
49
50
  catch (e) {
@@ -62,7 +63,12 @@ export function selectTasks(herebyfile, taskNames) {
62
63
  return taskNames.map((name) => {
63
64
  const task = allTasks.get(name);
64
65
  if (!task) {
65
- throw new UserError(`Task "${name}" does not exist or is not exported in the Herebyfile.`);
66
+ let message = `Task "${name}" does not exist or is not exported in the Herebyfile.`;
67
+ const candidate = closest(name, Array.from(allTasks.keys()));
68
+ if (distance(name, candidate) < name.length * 0.4) {
69
+ message += ` Did you mean "${candidate}?"`;
70
+ }
71
+ throw new UserError(message);
66
72
  }
67
73
  return task;
68
74
  });
@@ -1,13 +1,45 @@
1
1
  import assert from "assert";
2
2
  import chalk from "chalk";
3
- import { Runner } from "../runner.js";
4
- export class CLIRunner extends Runner {
5
- constructor(d) {
6
- super({ concurrency: d.numCPUs });
3
+ import pLimit from "p-limit";
4
+ export class Runner {
5
+ constructor(d, limiter) {
6
+ this._addedTasks = new WeakMap();
7
7
  this._errored = false;
8
8
  this._startTimes = new WeakMap();
9
+ this._limiter = limiter ?? pLimit(d.numCPUs);
9
10
  this._d = d;
10
11
  }
12
+ async runTasks(...tasks) {
13
+ await Promise.all(tasks.map((task) => {
14
+ const cached = this._addedTasks.get(task);
15
+ if (cached) {
16
+ return cached;
17
+ }
18
+ const promise = this._runTask(task);
19
+ this._addedTasks.set(task, promise);
20
+ return promise;
21
+ }));
22
+ }
23
+ async _runTask(task) {
24
+ const { dependencies, run } = task.options;
25
+ if (dependencies) {
26
+ await this.runTasks(...dependencies);
27
+ }
28
+ if (!run) {
29
+ return;
30
+ }
31
+ return this._limiter(async () => {
32
+ try {
33
+ this.onTaskStart(task);
34
+ await run();
35
+ this.onTaskFinish(task);
36
+ }
37
+ catch (e) {
38
+ this.onTaskError(task, e);
39
+ throw e;
40
+ }
41
+ });
42
+ }
11
43
  onTaskStart(task) {
12
44
  this._startTimes.set(task, Date.now());
13
45
  if (this._errored) {
package/dist/cli/utils.js CHANGED
@@ -36,11 +36,11 @@ export class ExitCodeError {
36
36
  this.reason = reason;
37
37
  }
38
38
  }
39
- /* eslint-disable no-restricted-globals */
40
39
  export async function real() {
41
40
  const { default: foregroundChild } = await import("foreground-child");
42
41
  const { resolve } = await import("import-meta-resolve");
43
42
  const { default: prettyMilliseconds } = await import("pretty-ms");
43
+ /* eslint-disable no-restricted-globals */
44
44
  return {
45
45
  log: console.log,
46
46
  error: console.error,
@@ -59,6 +59,6 @@ export async function real() {
59
59
  resolve,
60
60
  prettyMilliseconds,
61
61
  };
62
+ /* eslint-enable no-restricted-globals */
62
63
  }
63
- /* eslint-enable no-restricted-globals */
64
64
  //# sourceMappingURL=utils.js.map
package/dist/index.d.ts CHANGED
@@ -14,11 +14,13 @@ export interface TaskOptions {
14
14
  * A list of tasks that must has been run to completion before
15
15
  * this task can execute.
16
16
  */
17
- dependencies?: Task[] | undefined;
17
+ dependencies?: readonly Task[] | undefined;
18
18
  /**
19
- * A function to execute when this task is run.
19
+ * A function to execute when this task is run. If this function
20
+ * returns a promise, the task will not be marked as finished until
21
+ * that promise resolves.
20
22
  */
21
- run?: (() => void | Promise<void>) | undefined;
23
+ run?: (() => void) | (() => PromiseLike<void>) | undefined;
22
24
  }
23
25
  /**
24
26
  * A hereby Task. To get an instance, call `test`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hereby",
3
- "version": "1.0.5",
3
+ "version": "1.1.0",
4
4
  "description": "A simple task runner",
5
5
  "repository": "github:jakebailey/hereby",
6
6
  "type": "module",
@@ -41,9 +41,10 @@
41
41
  "chalk": "^5.0.1",
42
42
  "command-line-args": "^5.2.1",
43
43
  "command-line-usage": "^6.1.3",
44
+ "fastest-levenshtein": "^1.0.16",
44
45
  "foreground-child": "^2.0.0",
45
46
  "import-meta-resolve": "^2.1.0",
46
- "p-queue": "^7.3.0",
47
+ "p-limit": "^4.0.0",
47
48
  "pretty-ms": "^8.0.0"
48
49
  },
49
50
  "devDependencies": {
@@ -51,22 +52,22 @@
51
52
  "@tsconfig/node14": "^1.0.3",
52
53
  "@types/command-line-args": "^5.2.0",
53
54
  "@types/command-line-usage": "^5.0.2",
54
- "@types/node": "^14.18.24",
55
- "@typescript-eslint/eslint-plugin": "^5.33.1",
56
- "@typescript-eslint/parser": "^5.33.1",
57
- "ava": "^4.3.1",
55
+ "@types/node": "^14.18.30",
56
+ "@typescript-eslint/eslint-plugin": "^5.38.0",
57
+ "@typescript-eslint/parser": "^5.38.0",
58
+ "ava": "^4.3.3",
58
59
  "c8": "^7.12.0",
59
- "eslint": "^8.22.0",
60
+ "eslint": "^8.24.0",
60
61
  "eslint-config-prettier": "^8.5.0",
61
62
  "eslint-plugin-ava": "^13.2.0",
62
- "eslint-plugin-simple-import-sort": "^7.0.0",
63
+ "eslint-plugin-simple-import-sort": "^8.0.0",
63
64
  "execa": "^6.1.0",
64
65
  "moq.ts": "^9.0.2",
65
66
  "prettier": "^2.7.1",
66
- "release-it": "^15.3.0",
67
+ "release-it": "^15.4.2",
67
68
  "rimraf": "^3.0.2",
68
69
  "tempy": "^3.0.0",
69
- "typescript": "^4.7.4"
70
+ "typescript": "~4.8.3"
70
71
  },
71
72
  "packageManager": "npm@8.17.0",
72
73
  "volta": {
package/dist/runner.js DELETED
@@ -1,40 +0,0 @@
1
- import PQueue from "p-queue";
2
- export class Runner {
3
- constructor(options) {
4
- this._addedTasks = new WeakMap();
5
- this._queue = new PQueue({ concurrency: options?.concurrency ?? Infinity });
6
- }
7
- async runTasks(...tasks) {
8
- await Promise.all(tasks.map((task) => {
9
- const cached = this._addedTasks.get(task);
10
- if (cached) {
11
- return cached;
12
- }
13
- const promise = this._runTask(task);
14
- this._addedTasks.set(task, promise);
15
- return promise;
16
- }));
17
- }
18
- async _runTask(task) {
19
- this.onTaskAdd?.(task);
20
- const { dependencies, run } = task.options;
21
- if (dependencies) {
22
- await this.runTasks(...dependencies);
23
- }
24
- if (!run) {
25
- return;
26
- }
27
- return this._queue.add(async () => {
28
- try {
29
- this.onTaskStart?.(task);
30
- await run();
31
- this.onTaskFinish?.(task);
32
- }
33
- catch (e) {
34
- this.onTaskError?.(task, e);
35
- throw e;
36
- }
37
- });
38
- }
39
- }
40
- //# sourceMappingURL=runner.js.map