hereby 1.4.2 → 1.5.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 CHANGED
@@ -8,10 +8,15 @@
8
8
 
9
9
  `hereby` is a simple task runner.
10
10
 
11
- # Herebyfile.mjs
11
+ ```
12
+ $ npm i -D hereby
13
+ $ yarn add -D hereby
14
+ ```
15
+
16
+ ## Herebyfile.mjs
12
17
 
13
- Tasks are defined in `Herebyfile.mjs`. Exported tasks are available to run
14
- at the CLI, with support for `export default`.
18
+ Tasks are defined in `Herebyfile.mjs`. Exported tasks are available to run at
19
+ the CLI, with support for `export default`.
15
20
 
16
21
  For example:
17
22
 
@@ -39,43 +44,86 @@ export const lint = task({
39
44
  run: async () => {
40
45
  await runLinter(...);
41
46
  },
42
- })
47
+ });
43
48
 
44
49
  export const testAndLint = task({
45
50
  name: "testAndLint",
46
51
  dependencies: [test, lint],
47
- })
52
+ });
48
53
 
49
54
  export default testAndLint;
55
+
56
+ export const bundle = task({
57
+ name: "bundle",
58
+ dependencies: [build],
59
+ run: async () => {
60
+ await execa("esbuild", [
61
+ "--bundle",
62
+ "./out/index.js",
63
+ "--outfile", "./out/bundled.js",
64
+ ]);
65
+ },
66
+ });
50
67
  ```
51
68
 
52
- # Running tasks
69
+ ## Running tasks
53
70
 
54
71
  Given the above Herebyfile:
55
72
 
56
73
  ```
57
- $ hereby build # Run only build
58
- $ hereby test # Run test, which depends on build.
59
- $ hereby # Run the default exported task.
74
+ $ hereby build # Run the "build" task
75
+ $ hereby test # Run the "test" task, which depends on "build".
76
+ $ hereby # Run the default exported task.
77
+ $ hereby test bundle # Run the "test" and "bundle" tasks in parallel.
60
78
  ```
61
79
 
62
- # Flags
80
+ ## Flags
63
81
 
64
82
  `hereby` also supports a handful of flags:
65
83
 
66
84
  ```
67
- -h, --help Display this usage guide.
68
- --herebyfile path A path to a Herebyfile. Optional.
69
- -T, --tasks Print a listing of the available tasks.
85
+ -h, --help Display this usage guide.
86
+ --herebyfile path A path to a Herebyfile. Optional.
87
+ -T, --tasks Print a listing of the available tasks.
70
88
  ```
71
89
 
72
- # ESM
90
+ ## ESM
73
91
 
74
- `hereby` is implemented in ES modules. But, don't fret! This does not mean
75
- that your project must be ESM-only, only that your `Herebyfile` must be ESM
76
- module so that `hereby`'s `task` function can be imported. It's recommended
77
- to use the filename `Herebyfile.mjs` to ensure that it is treated as ESM. This
78
- will work in a CommonJS project; ES modules can import CommonJS modules.
92
+ `hereby` is implemented in ES modules. But, don't fret! This does not mean that
93
+ your project must be ESM-only, only that your `Herebyfile` must be ESM module so
94
+ that `hereby`'s `task` function can be imported. It's recommended to use the
95
+ filename `Herebyfile.mjs` to ensure that it is treated as ESM. This will work in
96
+ a CommonJS project; ES modules can import CommonJS modules.
79
97
 
80
- If your package already sets `"type": "module"`, `Herebyfile.js` will work
81
- as well.
98
+ If your package already sets `"type": "module"`, `Herebyfile.js` will work as
99
+ well.
100
+
101
+ ## Caveats
102
+
103
+ ### No serial tasks
104
+
105
+ `hereby` does not support running tasks in series; specifying multiple tasks at
106
+ the CLI or as dependencies of another task will run them in parallel. This
107
+ matches the behavior of tools like `make`, which like `hereby` intend to encode
108
+ a dedpendency graph of tasks, not act as a script.
109
+
110
+ In general, if you're trying to emulate a serial task, you will likely be better
111
+ served by writing out explicit dependencies for your tasks.
112
+
113
+ ### Tasks only run once
114
+
115
+ `hereby` will only run each task once during its execution. This means that
116
+ tasks which consist of other tasks run in order like a script cannot be
117
+ constructed. For example, it's not possible to run "build", then "clean", then
118
+ "build" again within the same invocation of `hereby`, since "build" will only be
119
+ executed once (and the lack of serial tasks prevents such a construction
120
+ anyway).
121
+
122
+ To run tasks in a specific order and more than once, run `hereby` multiple
123
+ times:
124
+
125
+ ```
126
+ $ hereby build
127
+ $ hereby clean
128
+ $ hereby build
129
+ ```
@@ -13,7 +13,9 @@ export function formatTasks(format, tasks, defaultTask) {
13
13
  sections.push({
14
14
  header: "Available tasks",
15
15
  content: tasks.map((task) => {
16
- const name = task !== defaultTask ? chalk.blue(task.options.name) : `${chalk.green(task.options.name)} (default)`;
16
+ const name = task !== defaultTask
17
+ ? chalk.blue(task.options.name)
18
+ : `${chalk.green(task.options.name)} (default)`;
17
19
  const descriptionParts = [];
18
20
  if (task.options.description) {
19
21
  descriptionParts.push(task.options.description);
package/dist/cli/index.js CHANGED
@@ -6,7 +6,7 @@ import { findHerebyfile, loadHerebyfile } from "./loadHerebyfile.js";
6
6
  import { getUsage, parseArgs } from "./parseArgs.js";
7
7
  import { reexec } from "./reexec.js";
8
8
  import { Runner } from "./runner.js";
9
- import { ExitCodeError, simplifyPath, UserError } from "./utils.js";
9
+ import { ExitCodeError, UserError } from "./utils.js";
10
10
  export async function main(d) {
11
11
  try {
12
12
  await mainWorker(d);
@@ -40,27 +40,34 @@ async function mainWorker(d) {
40
40
  return;
41
41
  }
42
42
  d.chdir(path.dirname(herebyfilePath));
43
- if (!args.printTasks) {
44
- d.log(`Using ${simplifyPath(herebyfilePath)}`);
45
- }
46
43
  const herebyfile = await loadHerebyfile(herebyfilePath);
47
44
  if (args.printTasks) {
48
45
  d.log(formatTasks(args.printTasks, herebyfile.tasks, herebyfile.defaultTask));
49
46
  return;
50
47
  }
51
- const tasks = selectTasks(herebyfile, args.run);
48
+ const tasks = selectTasks(d, herebyfile, herebyfilePath, args.run);
49
+ const taskNames = tasks.map((t) => t.options.name).sort().map((name) => chalk.blue(name)).join(", ");
50
+ d.log(`Using ${chalk.yellow(d.simplifyPath(herebyfilePath))} to run ${taskNames}`);
51
+ const start = Date.now();
52
+ let errored = false;
52
53
  try {
53
54
  const runner = new Runner(d);
54
55
  await runner.runTasks(...tasks);
55
56
  }
56
57
  catch (e) {
58
+ errored = true;
57
59
  // We will have already printed some message here.
58
60
  // Set the error code and let the process run to completion,
59
61
  // so we don't end up with an unflushed output.
60
62
  throw new ExitCodeError(1, e);
61
63
  }
64
+ finally {
65
+ const took = Date.now() - start;
66
+ d.log(`Completed ${taskNames}${errored ? chalk.red(" with errors") : ""} in ${d.prettyMilliseconds(took)}`);
67
+ }
62
68
  }
63
- export function selectTasks(herebyfile, taskNames) {
69
+ // Exported for testing.
70
+ export function selectTasks(d, herebyfile, herebyfilePath, taskNames) {
64
71
  const allTasks = new Map();
65
72
  for (const task of herebyfile.tasks) {
66
73
  allTasks.set(task.options.name, task);
@@ -69,7 +76,7 @@ export function selectTasks(herebyfile, taskNames) {
69
76
  return taskNames.map((name) => {
70
77
  const task = allTasks.get(name);
71
78
  if (!task) {
72
- let message = `Task "${name}" does not exist or is not exported in the Herebyfile.`;
79
+ let message = `Task "${name}" does not exist or is not exported from ${d.simplifyPath(herebyfilePath)}.`;
73
80
  const candidate = closest(name, Array.from(allTasks.keys()));
74
81
  if (distance(name, candidate) < name.length * 0.4) {
75
82
  message += ` Did you mean "${candidate}"?`;
@@ -80,7 +87,7 @@ export function selectTasks(herebyfile, taskNames) {
80
87
  });
81
88
  }
82
89
  if (!herebyfile.defaultTask) {
83
- throw new UserError("No default task defined; please specify a task name.");
90
+ throw new UserError(`No default task has been exported from ${d.simplifyPath(herebyfilePath)}; please specify a task name.`);
84
91
  }
85
92
  return [herebyfile.defaultTask];
86
93
  }
package/dist/cli/utils.js CHANGED
@@ -8,6 +8,7 @@ export function taskSorter(a, b) {
8
8
  export function stringSorter(a, b) {
9
9
  return a.localeCompare(b);
10
10
  }
11
+ // Exported for testing.
11
12
  export function simplifyPath(p) {
12
13
  let homedir = os.homedir();
13
14
  if (!p.endsWith(path.sep)) {
@@ -53,6 +54,7 @@ export async function real() {
53
54
  cwd: process.cwd,
54
55
  // eslint-disable-next-line @typescript-eslint/unbound-method
55
56
  chdir: process.chdir,
57
+ simplifyPath,
56
58
  argv: process.argv,
57
59
  execArgv: process.execArgv,
58
60
  execPath: process.execPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hereby",
3
- "version": "1.4.2",
3
+ "version": "1.5.0",
4
4
  "description": "A simple task runner",
5
5
  "repository": "github:jakebailey/hereby",
6
6
  "type": "module",
@@ -53,18 +53,17 @@
53
53
  "@types/command-line-args": "^5.2.0",
54
54
  "@types/command-line-usage": "^5.0.2",
55
55
  "@types/node": "^14.18.31",
56
- "@typescript-eslint/eslint-plugin": "^5.38.1",
57
- "@typescript-eslint/parser": "^5.38.1",
56
+ "@typescript-eslint/eslint-plugin": "^5.39.0",
57
+ "@typescript-eslint/parser": "^5.39.0",
58
58
  "ava": "^4.3.3",
59
59
  "c8": "^7.12.0",
60
+ "dprint": "^0.32.1",
60
61
  "eslint": "^8.24.0",
61
- "eslint-config-prettier": "^8.5.0",
62
62
  "eslint-plugin-ava": "^13.2.0",
63
63
  "eslint-plugin-simple-import-sort": "^8.0.0",
64
64
  "execa": "^6.1.0",
65
65
  "moq.ts": "^9.0.2",
66
- "prettier": "^2.7.1",
67
- "release-it": "^15.4.2",
66
+ "release-it": "^15.4.3",
68
67
  "rimraf": "^3.0.2",
69
68
  "tempy": "^3.0.0",
70
69
  "typescript": "~4.8.4"