hereby 1.0.1 → 1.0.4
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 +7 -2
- package/dist/cli/reexec.js +8 -1
- package/dist/cli.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +27 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# hereby
|
|
2
2
|
|
|
3
|
-
[](https://npmjs.com/package/hereby)
|
|
4
|
+
[](https://nodejs.org)
|
|
5
|
+
[](https://packagephobia.com/result?p=hereby)
|
|
4
6
|
[](https://github.com/jakebailey/hereby/actions/workflows/ci.yml)
|
|
5
7
|
[](https://codecov.io/gh/jakebailey/hereby)
|
|
6
8
|
|
|
@@ -8,7 +10,10 @@
|
|
|
8
10
|
|
|
9
11
|
# Herebyfile.mjs
|
|
10
12
|
|
|
11
|
-
Tasks are defined in `Herebyfile.mjs
|
|
13
|
+
Tasks are defined in `Herebyfile.mjs`. Exported tasks are available to run
|
|
14
|
+
at the CLI, with support for `export default`.
|
|
15
|
+
|
|
16
|
+
For example:
|
|
12
17
|
|
|
13
18
|
```js
|
|
14
19
|
import { execa } from "execa";
|
package/dist/cli/reexec.js
CHANGED
|
@@ -2,6 +2,7 @@ import chalk from "chalk";
|
|
|
2
2
|
import foregroundChild from "foreground-child";
|
|
3
3
|
import { resolve } from "import-meta-resolve";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
5
|
+
import { UserError } from "./utils.js";
|
|
5
6
|
export async function reexec(system, herebyfilePath) {
|
|
6
7
|
// If hereby is installed globally, but run against a Herebyfile in some
|
|
7
8
|
// other package, that Herebyfile's import will resolve to a different
|
|
@@ -15,7 +16,13 @@ export async function reexec(system, herebyfilePath) {
|
|
|
15
16
|
// TODO: Rather than spawning a child process, perhaps we could instead
|
|
16
17
|
// import the CLI from the other version and run it.
|
|
17
18
|
const thisCLI = await resolveToPath("hereby/cli", new URL(import.meta.url));
|
|
18
|
-
|
|
19
|
+
let otherCLI;
|
|
20
|
+
try {
|
|
21
|
+
otherCLI = await resolveToPath("hereby/cli", pathToFileURL(herebyfilePath));
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
throw new UserError("Unable to find hereby; ensure hereby is installed in your package.");
|
|
25
|
+
}
|
|
19
26
|
if (thisCLI === otherCLI) {
|
|
20
27
|
return false;
|
|
21
28
|
}
|
package/dist/cli.js
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export class Task {
|
|
5
5
|
constructor(options) {
|
|
6
|
+
// Runtime typecheck; consumers of hereby may not have enabled
|
|
7
|
+
// typechecking, so this is helpful.
|
|
8
|
+
if (typeof options.name !== "string") {
|
|
9
|
+
throw new Error("Task name is not a string.");
|
|
10
|
+
}
|
|
11
|
+
if (typeof options.description !== "string" && typeof options.description !== "undefined") {
|
|
12
|
+
throw new Error("Task description is not a string or undefined.");
|
|
13
|
+
}
|
|
14
|
+
if (!Array.isArray(options.dependencies) && typeof options.dependencies !== "undefined") {
|
|
15
|
+
throw new Error("Task dependencies is not an array or undefined.");
|
|
16
|
+
}
|
|
17
|
+
if (options.dependencies) {
|
|
18
|
+
for (const dep of options.dependencies) {
|
|
19
|
+
if (!(dep instanceof Task)) {
|
|
20
|
+
throw new Error("Task dependency is not a task.");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (typeof options.run !== "function" && typeof options.run !== "undefined") {
|
|
25
|
+
throw new Error("Task run is not a function or undefined.");
|
|
26
|
+
}
|
|
27
|
+
// Non-type checks.
|
|
6
28
|
if (!options.name) {
|
|
7
29
|
throw new Error("Task name must not be empty.");
|
|
8
30
|
}
|
|
@@ -12,7 +34,11 @@ export class Task {
|
|
|
12
34
|
if (!options.dependencies?.length && !options.run) {
|
|
13
35
|
throw new Error("Task must have at run function or dependencies.");
|
|
14
36
|
}
|
|
15
|
-
this.
|
|
37
|
+
this._options = options;
|
|
38
|
+
}
|
|
39
|
+
/* @internal */
|
|
40
|
+
get options() {
|
|
41
|
+
return this._options;
|
|
16
42
|
}
|
|
17
43
|
/* @internal */
|
|
18
44
|
static create(options) {
|