hereby 1.7.0 → 1.7.1

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.
@@ -2,8 +2,7 @@ import commandLineUsage from "command-line-usage";
2
2
  import pc from "picocolors";
3
3
  import { stringSorter, taskSorter } from "./utils.js";
4
4
  export function formatTasks(format, tasks, defaultTask) {
5
- tasks = tasks
6
- .slice(0)
5
+ tasks = [...tasks]
7
6
  .filter((task) => !task.options.hiddenFromTaskList)
8
7
  .sort(taskSorter);
9
8
  if (format === "simple") {
@@ -14,9 +13,9 @@ export function formatTasks(format, tasks, defaultTask) {
14
13
  header: "Available tasks",
15
14
  content: tasks.map((task) => {
16
15
  var _a;
17
- const name = task !== defaultTask
18
- ? pc.blue(task.options.name)
19
- : `${pc.green(task.options.name)} (default)`;
16
+ const name = task === defaultTask
17
+ ? `${pc.green(task.options.name)} (default)`
18
+ : pc.blue(task.options.name);
20
19
  const descriptionParts = [];
21
20
  if (task.options.description) {
22
21
  descriptionParts.push(task.options.description);
package/dist/cli/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import path from "path";
1
+ import path from "node:path";
2
2
  import pc from "picocolors";
3
3
  import { formatTasks } from "./formatTasks.js";
4
4
  import { findHerebyfile, loadHerebyfile } from "./loadHerebyfile.js";
@@ -79,7 +79,7 @@ export async function selectTasks(d, herebyfile, herebyfilePath, taskNames) {
79
79
  if (!task) {
80
80
  let message = `Task "${name}" does not exist or is not exported from ${d.simplifyPath(herebyfilePath)}.`;
81
81
  const { closest, distance } = await import("fastest-levenshtein");
82
- const candidate = closest(name, Array.from(allTasks.keys()));
82
+ const candidate = closest(name, [...allTasks.keys()]);
83
83
  if (distance(name, candidate) < name.length * 0.4) {
84
84
  message += ` Did you mean "${candidate}"?`;
85
85
  }
@@ -1,12 +1,12 @@
1
- import fs from "fs";
2
- import path from "path";
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { pathToFileURL } from "node:url";
3
4
  import pc from "picocolors";
4
- import { pathToFileURL } from "url";
5
5
  import { Task } from "../index.js";
6
6
  import { UserError } from "./utils.js";
7
7
  const filenames = ["Herebyfile", "herebyfile"];
8
8
  const extensions = ["mjs", "js"];
9
- const allFilenames = new Set(extensions.map((e) => filenames.map((f) => `${f}.${e}`)).flat());
9
+ const allFilenames = new Set(extensions.flatMap((e) => filenames.map((f) => `${f}.${e}`)));
10
10
  export async function findHerebyfile(dir) {
11
11
  const root = path.parse(dir).root;
12
12
  for (; dir !== root; dir = path.dirname(dir)) {
@@ -52,7 +52,7 @@ export async function loadHerebyfile(herebyfilePath) {
52
52
  if (exportedTasks.size === 0) {
53
53
  throw new UserError("No tasks found. Did you forget to export your tasks?");
54
54
  }
55
- const tasks = Array.from(exportedTasks.values());
55
+ const tasks = [...exportedTasks.values()];
56
56
  // We check this here by walking the DAG, as some dependencies may not be
57
57
  // exported and therefore would not be seen by the above loop.
58
58
  checkTaskInvariants(tasks);
@@ -20,7 +20,7 @@ export function parseArgs(argv) {
20
20
  help: options["help"],
21
21
  run: options["run"],
22
22
  herebyfile: options["herebyfile"],
23
- printTasks: options["tasks"] ? "normal" : options["tasks-simple"] ? "simple" : undefined,
23
+ printTasks: options["tasks"] ? "normal" : (options["tasks-simple"] ? "simple" : undefined),
24
24
  version: options["version"],
25
25
  };
26
26
  }
@@ -1,4 +1,4 @@
1
- import { pathToFileURL } from "url";
1
+ import { pathToFileURL } from "node:url";
2
2
  import { UserError } from "./utils.js";
3
3
  const cliExportName = "hereby/cli";
4
4
  /**
@@ -1,4 +1,4 @@
1
- import assert from "assert";
1
+ import assert from "node:assert";
2
2
  import pc from "picocolors";
3
3
  export class Runner {
4
4
  constructor(d) {
package/dist/cli/utils.js CHANGED
@@ -1,7 +1,7 @@
1
- import fs from "fs";
2
- import os from "os";
3
- import path from "path";
4
- import { fileURLToPath } from "url";
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
5
  export function taskSorter(a, b) {
6
6
  return stringSorter(a.options.name, b.options.name);
7
7
  }
@@ -59,7 +59,7 @@ export async function real() {
59
59
  // Not bothering to memoize this function; it will only be called once.
60
60
  const resolve = await importResolve();
61
61
  const packageJsonPath = fileURLToPath(await resolve("hereby/package.json", import.meta.url));
62
- const packageJson = await fs.promises.readFile(packageJsonPath, "utf-8");
62
+ const packageJson = await fs.promises.readFile(packageJsonPath, "utf8");
63
63
  const { version } = JSON.parse(packageJson);
64
64
  return version;
65
65
  },
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ export interface TaskOptions {
11
11
  */
12
12
  description?: string | undefined;
13
13
  /**
14
- * A list of tasks that must has been run to completion before
14
+ * A list of tasks that must have been run to completion before
15
15
  * this task can execute.
16
16
  */
17
17
  dependencies?: readonly Task[] | undefined;
package/dist/index.js CHANGED
@@ -15,23 +15,23 @@ export class Task {
15
15
  // typechecking, so this is helpful.
16
16
  var _a;
17
17
  if (typeof options.name !== "string") {
18
- throw new Error("Task name is not a string.");
18
+ throw new TypeError("Task name is not a string.");
19
19
  }
20
- if (typeof options.description !== "string" && typeof options.description !== "undefined") {
21
- throw new Error("Task description is not a string or undefined.");
20
+ if (typeof options.description !== "string" && options.description !== undefined) {
21
+ throw new TypeError("Task description is not a string or undefined.");
22
22
  }
23
- if (!Array.isArray(options.dependencies) && typeof options.dependencies !== "undefined") {
24
- throw new Error("Task dependencies is not an array or undefined.");
23
+ if (!Array.isArray(options.dependencies) && options.dependencies !== undefined) {
24
+ throw new TypeError("Task dependencies is not an array or undefined.");
25
25
  }
26
26
  if (options.dependencies) {
27
27
  for (const dep of options.dependencies) {
28
28
  if (!(dep instanceof Task)) {
29
- throw new Error("Task dependency is not a task.");
29
+ throw new TypeError("Task dependency is not a task.");
30
30
  }
31
31
  }
32
32
  }
33
- if (typeof options.run !== "function" && typeof options.run !== "undefined") {
34
- throw new Error("Task run is not a function or undefined.");
33
+ if (typeof options.run !== "function" && options.run !== undefined) {
34
+ throw new TypeError("Task run is not a function or undefined.");
35
35
  }
36
36
  // Non-type checks.
37
37
  if (!options.name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hereby",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "A simple task runner",
5
5
  "repository": "github:jakebailey/hereby",
6
6
  "type": "module",
@@ -60,6 +60,7 @@
60
60
  "eslint": "^8.32.0",
61
61
  "eslint-plugin-ava": "^14.0.0",
62
62
  "eslint-plugin-simple-import-sort": "^9.0.0",
63
+ "eslint-plugin-unicorn": "^45.0.2",
63
64
  "execa": "^6.1.0",
64
65
  "moq.ts": "^9.0.2",
65
66
  "rimraf": "^4.1.1",