@adamhl8/bask 0.4.0 → 0.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 +6 -3
- package/dist/cli.js +15 -3
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ export const hello = task(() => {
|
|
|
116
116
|
|
|
117
117
|
```ts
|
|
118
118
|
export const releaseRun = task({ desc: "Run from CI", hidden: true }, async ({ sh }) => {
|
|
119
|
-
await sh`
|
|
119
|
+
await sh`release-it --ci`
|
|
120
120
|
})
|
|
121
121
|
|
|
122
122
|
export const bumpDeps = task({ alias: ["up", "update-deps"] }, async ({ sh }) => {
|
|
@@ -234,6 +234,9 @@ export const lint = task(async ({ sh }) => {
|
|
|
234
234
|
})
|
|
235
235
|
```
|
|
236
236
|
|
|
237
|
+
> [!TIP]
|
|
238
|
+
> Like a `package.json` script, `sh` finds installed bins in `node_modules/.bin`, so `oxlint` and `bun oxlint` both work.
|
|
239
|
+
|
|
237
240
|
To run a command without printing it, use `.echo(false)`:
|
|
238
241
|
|
|
239
242
|
```ts
|
|
@@ -321,11 +324,11 @@ import { build, lint } from "./shared-tasks.ts"
|
|
|
321
324
|
export * from "./shared-tasks.ts"
|
|
322
325
|
|
|
323
326
|
export const astroSync = task(async ({ sh }) => {
|
|
324
|
-
await sh`
|
|
327
|
+
await sh`astro sync`
|
|
325
328
|
})
|
|
326
329
|
|
|
327
330
|
export const astroBuild = task(async ({ sh }) => {
|
|
328
|
-
await sh`
|
|
331
|
+
await sh`astro build`
|
|
329
332
|
})
|
|
330
333
|
|
|
331
334
|
lint.before(astroSync)
|
package/dist/cli.js
CHANGED
|
@@ -6,16 +6,27 @@ import path from "node:path";
|
|
|
6
6
|
import bun from "bun";
|
|
7
7
|
import { parseArgs } from "node:util";
|
|
8
8
|
//#region src/cli.ts
|
|
9
|
+
const cwd = process.cwd();
|
|
9
10
|
const isModule = (value) => typeof value === "object" && Boolean(value);
|
|
10
11
|
const isParseArgsError = (error) => error instanceof TypeError && "code" in error && typeof error.code === "string" && error.code.startsWith("ERR_PARSE_ARGS_");
|
|
11
12
|
/** Finds the project's own bask CLI, so a global `bask` runs the version the project pins. */
|
|
12
13
|
const resolveLocalCli = () => {
|
|
13
14
|
try {
|
|
14
|
-
return bun.resolveSync("@adamhl8/bask/cli",
|
|
15
|
+
return bun.resolveSync("@adamhl8/bask/cli", cwd);
|
|
15
16
|
} catch {
|
|
16
17
|
return;
|
|
17
18
|
}
|
|
18
19
|
};
|
|
20
|
+
/** Lists `node_modules/.bin` for `dir` and each of its parents, nearest first. */
|
|
21
|
+
const getBinDirs = (dir) => {
|
|
22
|
+
const binDir = path.join(dir, "node_modules", ".bin");
|
|
23
|
+
const parent = path.dirname(dir);
|
|
24
|
+
return parent === dir ? [binDir] : [binDir, ...getBinDirs(parent)];
|
|
25
|
+
};
|
|
26
|
+
/** Prepends the project's `.bin` folders to `PATH`, like `bun run` does, so tasks can run installed bins by name. */
|
|
27
|
+
const addBinDirsToPath = () => {
|
|
28
|
+
process.env["PATH"] = [...getBinDirs(cwd), process.env["PATH"]].filter(Boolean).join(path.delimiter);
|
|
29
|
+
};
|
|
19
30
|
const parseCliArgs = () => {
|
|
20
31
|
try {
|
|
21
32
|
return parseArgs({
|
|
@@ -53,12 +64,13 @@ const main = async () => {
|
|
|
53
64
|
const args = parseCliArgs();
|
|
54
65
|
if (!args) return;
|
|
55
66
|
const { values, positionals } = args;
|
|
56
|
-
const baskPath = path.
|
|
67
|
+
const baskPath = path.join(cwd, "bask.ts");
|
|
57
68
|
if (!await bun.file(baskPath).exists()) {
|
|
58
|
-
printError(`no bask.ts in ${
|
|
69
|
+
printError(`no bask.ts in ${cwd}`);
|
|
59
70
|
process.exitCode = 1;
|
|
60
71
|
return;
|
|
61
72
|
}
|
|
73
|
+
addBinDirsToPath();
|
|
62
74
|
const baskModule = await import(baskPath);
|
|
63
75
|
if (!isModule(baskModule)) throw new Error("failed to import bask.ts");
|
|
64
76
|
try {
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env bun\n\nimport path from \"node:path\"\nimport { parseArgs } from \"node:util\"\n\nimport bun from \"bun\"\n\nimport { BaskFileError, formatTaskList, getTaskIndex, list, setBaskModule } from \"#registry.ts\"\nimport { getFailedTask } from \"#task.ts\"\nimport type { Task } from \"#task.ts\"\nimport { printError } from \"#utils.ts\"\n\nconst isModule = (value: unknown): value is Record<string, unknown> => typeof value === \"object\" && Boolean(value)\n\nconst isParseArgsError = (error: unknown): error is TypeError & { code: string } =>\n error instanceof TypeError &&\n \"code\" in error &&\n typeof error.code === \"string\" &&\n error.code.startsWith(\"ERR_PARSE_ARGS_\")\n\n/** Finds the project's own bask CLI, so a global `bask` runs the version the project pins. */\nconst resolveLocalCli = () => {\n try {\n return bun.resolveSync(\"@adamhl8/bask/cli\",
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env bun\n\nimport path from \"node:path\"\nimport { parseArgs } from \"node:util\"\n\nimport bun from \"bun\"\n\nimport { BaskFileError, formatTaskList, getTaskIndex, list, setBaskModule } from \"#registry.ts\"\nimport { getFailedTask } from \"#task.ts\"\nimport type { Task } from \"#task.ts\"\nimport { printError } from \"#utils.ts\"\n\nconst cwd = process.cwd()\n\nconst isModule = (value: unknown): value is Record<string, unknown> => typeof value === \"object\" && Boolean(value)\n\nconst isParseArgsError = (error: unknown): error is TypeError & { code: string } =>\n error instanceof TypeError &&\n \"code\" in error &&\n typeof error.code === \"string\" &&\n error.code.startsWith(\"ERR_PARSE_ARGS_\")\n\n/** Finds the project's own bask CLI, so a global `bask` runs the version the project pins. */\nconst resolveLocalCli = () => {\n try {\n return bun.resolveSync(\"@adamhl8/bask/cli\", cwd)\n } catch {\n return\n }\n}\n\n/** Lists `node_modules/.bin` for `dir` and each of its parents, nearest first. */\nconst getBinDirs = (dir: string): string[] => {\n const binDir = path.join(dir, \"node_modules\", \".bin\")\n const parent = path.dirname(dir)\n return parent === dir ? [binDir] : [binDir, ...getBinDirs(parent)]\n}\n\n/** Prepends the project's `.bin` folders to `PATH`, like `bun run` does, so tasks can run installed bins by name. */\nconst addBinDirsToPath = () => {\n // oxlint-disable-next-line node/no-process-env - commands in `sh` look up bins on this `PATH`\n process.env[\"PATH\"] = [...getBinDirs(cwd), process.env[\"PATH\"]].filter(Boolean).join(path.delimiter)\n}\n\nconst parseCliArgs = () => {\n try {\n return parseArgs({ options: { list: { type: \"boolean\", short: \"l\" } }, allowPositionals: true })\n } catch (error) {\n if (!isParseArgsError(error)) throw error\n printError(error.message)\n process.exitCode = 2\n return\n }\n}\n\n/** Runs a task and reports a failed command in one line, naming the innermost task that failed. */\nconst runTask = async (taskToRun: Task, taskName: string) => {\n try {\n await taskToRun()\n } catch (error) {\n // Rethrow anything else, because a bug in a task file needs its stack trace.\n if (!(error instanceof bun.$.ShellError)) throw error\n\n const failedTask = getFailedTask(error)\n const failedEntry = getTaskIndex()\n .values()\n .find((entry) => entry.task === failedTask)\n // Fall back to the task you ran, because a task that isn't exported has no name.\n const failedName = failedEntry?.name ?? taskName\n printError(`task '${failedName}' failed with exit code ${error.exitCode}`)\n process.exitCode = error.exitCode\n }\n}\n\nconst main = async () => {\n // Import the local CLI and stop, because it runs its own `main` when loaded.\n // The local copy resolves to its own path, so it skips this and runs normally.\n const localCli = resolveLocalCli()\n if (localCli && localCli !== import.meta.path) {\n await import(localCli)\n return\n }\n\n const args = parseCliArgs()\n if (!args) return\n const { values, positionals } = args\n\n const baskPath = path.join(cwd, \"bask.ts\")\n if (!(await bun.file(baskPath).exists())) {\n printError(`no bask.ts in ${cwd}`)\n process.exitCode = 1\n return\n }\n\n addBinDirsToPath()\n const baskModule: unknown = await import(baskPath)\n if (!isModule(baskModule)) throw new Error(\"failed to import bask.ts\")\n try {\n setBaskModule(baskModule)\n } catch (error) {\n if (!(error instanceof BaskFileError)) throw error\n printError(error.message)\n process.exitCode = 1\n return\n }\n\n const [taskName] = positionals\n\n if (values.list || (taskName === undefined && !getTaskIndex().has(\"default\"))) {\n await runTask(list, \"list\")\n return\n }\n\n const selectedEntry = getTaskIndex().get(taskName ?? \"default\")\n\n if (!selectedEntry) {\n printError(`unknown task '${taskName ?? \"default\"}'`)\n process.stderr.write(`\\n${formatTaskList()}\\n`)\n process.exitCode = 1\n return\n }\n\n await runTask(selectedEntry.task, selectedEntry.name)\n}\n\nawait main()\n"],"mappings":";;;;;;;;AAYA,MAAM,MAAM,QAAQ,IAAI;AAExB,MAAM,YAAY,UAAqD,OAAO,UAAU,YAAY,QAAQ,KAAK;AAEjH,MAAM,oBAAoB,UACxB,iBAAiB,aACjB,UAAU,SACV,OAAO,MAAM,SAAS,YACtB,MAAM,KAAK,WAAW,iBAAiB;;AAGzC,MAAM,wBAAwB;CAC5B,IAAI;EACF,OAAO,IAAI,YAAY,qBAAqB,GAAG;CACjD,QAAQ;EACN;CACF;AACF;;AAGA,MAAM,cAAc,QAA0B;CAC5C,MAAM,SAAS,KAAK,KAAK,KAAK,gBAAgB,MAAM;CACpD,MAAM,SAAS,KAAK,QAAQ,GAAG;CAC/B,OAAO,WAAW,MAAM,CAAC,MAAM,IAAI,CAAC,QAAQ,GAAG,WAAW,MAAM,CAAC;AACnE;;AAGA,MAAM,yBAAyB;CAE7B,QAAQ,IAAI,UAAU,CAAC,GAAG,WAAW,GAAG,GAAG,QAAQ,IAAI,OAAO,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,KAAK,SAAS;AACrG;AAEA,MAAM,qBAAqB;CACzB,IAAI;EACF,OAAO,UAAU;GAAE,SAAS,EAAE,MAAM;IAAE,MAAM;IAAW,OAAO;GAAI,EAAE;GAAG,kBAAkB;EAAK,CAAC;CACjG,SAAS,OAAO;EACd,IAAI,CAAC,iBAAiB,KAAK,GAA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