diff --git a/.changeset/strong-buckets-nail.md b/.changeset/strong-buckets-nail.md new file mode 100644 index 0000000..19677c3 --- /dev/null +++ b/.changeset/strong-buckets-nail.md @@ -0,0 +1,5 @@ +--- +"@vlandoss/run-run": patch +--- + +Add tsdown to tools diff --git a/packages/run-run/package.json b/packages/run-run/package.json index 917a0fa..cf24300 100644 --- a/packages/run-run/package.json +++ b/packages/run-run/package.json @@ -14,7 +14,16 @@ "author": "rcrd ", "type": "module", "exports": { - "./config": "./src/lib/config.ts" + "./config": { + "bun": "./src/lib/config.ts", + "types": "./dist/config.d.mts", + "default": "./dist/config.mjs" + }, + "./tools/*": { + "bun": "./src/lib/tools/*.ts", + "types": "./dist/tools/*.d.mts", + "default": "./dist/tools/*.mjs" + } }, "bin": { "rr": "./bin.ts", @@ -25,12 +34,15 @@ }, "files": [ "bin.ts", + "dist", "src", "tools", "tsconfig.json" ], "scripts": { + "build": "tsdown", "test": "bun test", + "prepublishOnly": "pnpm build", "test:types": "rr tsc" }, "dependencies": { diff --git a/packages/run-run/src/lib/config.ts b/packages/run-run/src/lib/config.ts index fa269e4..47aec30 100644 --- a/packages/run-run/src/lib/config.ts +++ b/packages/run-run/src/lib/config.ts @@ -1,4 +1,4 @@ -import type { UserConfig } from "../types/config"; +import type { UserConfig } from "../types/config.ts"; export function defineConfig(config: UserConfig) { return config; diff --git a/packages/run-run/src/lib/tools/tsdown.ts b/packages/run-run/src/lib/tools/tsdown.ts new file mode 100644 index 0000000..06f210b --- /dev/null +++ b/packages/run-run/src/lib/tools/tsdown.ts @@ -0,0 +1 @@ +export * from "tsdown"; diff --git a/packages/run-run/src/program/__tests__/__snapshots__/snapshots.test.ts.snap b/packages/run-run/src/program/__tests__/__snapshots__/snapshots.test.ts.snap index d651883..0e78d14 100644 --- a/packages/run-run/src/program/__tests__/__snapshots__/snapshots.test.ts.snap +++ b/packages/run-run/src/program/__tests__/__snapshots__/snapshots.test.ts.snap @@ -183,6 +183,7 @@ Commands: biome oxfmt oxlint + tsdown help [command] display help for command " `; diff --git a/packages/run-run/src/program/commands/tools.ts b/packages/run-run/src/program/commands/tools.ts index ad581a7..f37341a 100644 --- a/packages/run-run/src/program/commands/tools.ts +++ b/packages/run-run/src/program/commands/tools.ts @@ -5,6 +5,7 @@ import type { Context } from "#/services/ctx"; import { OxfmtService } from "#/services/oxfmt"; import { OxlintService } from "#/services/oxlint"; import type { ToolService } from "#/services/tool"; +import { TsdownService } from "#/services/tsdown"; type ActionParams = { args: string[]; @@ -18,6 +19,8 @@ function getToolService(bin: string, shell: ShellService): ToolService { return new OxfmtService(shell); case "oxlint": return new OxlintService(shell); + case "tsdown": + return new TsdownService(shell); default: throw new Error(`Unknown tool: ${bin}`); } @@ -41,5 +44,6 @@ export function createToolsCommand(ctx: Context) { .description("expose the internal tools 🛠️") .addCommand(createToolCommand("biome", ctx.shell)) .addCommand(createToolCommand("oxfmt", ctx.shell)) - .addCommand(createToolCommand("oxlint", ctx.shell)); + .addCommand(createToolCommand("oxlint", ctx.shell)) + .addCommand(createToolCommand("tsdown", ctx.shell)); } diff --git a/packages/run-run/src/services/biome.ts b/packages/run-run/src/services/biome.ts index 06bd1b1..9fc8d65 100644 --- a/packages/run-run/src/services/biome.ts +++ b/packages/run-run/src/services/biome.ts @@ -9,7 +9,7 @@ export class BiomeService extends ToolService implements Formatter, Linter, Stat super({ bin: "biome", ui: TOOL_LABELS.BIOME, shellService }); } - getBinDir() { + override getBinDir() { return require.resolve("@biomejs/biome/bin/biome"); } diff --git a/packages/run-run/src/services/oxfmt.ts b/packages/run-run/src/services/oxfmt.ts index b978c85..e02eab2 100644 --- a/packages/run-run/src/services/oxfmt.ts +++ b/packages/run-run/src/services/oxfmt.ts @@ -8,7 +8,7 @@ export class OxfmtService extends ToolService implements Formatter { super({ bin: "oxfmt", ui: TOOL_LABELS.OXFMT, shellService }); } - getBinDir() { + override getBinDir() { return require.resolve("oxfmt/bin/oxfmt"); } diff --git a/packages/run-run/src/services/oxlint.ts b/packages/run-run/src/services/oxlint.ts index 4436434..90dede8 100644 --- a/packages/run-run/src/services/oxlint.ts +++ b/packages/run-run/src/services/oxlint.ts @@ -8,7 +8,7 @@ export class OxlintService extends ToolService implements Linter { super({ bin: "oxlint", ui: TOOL_LABELS.OXLINT, shellService }); } - getBinDir() { + override getBinDir() { return require.resolve("oxlint/bin/oxlint"); } diff --git a/packages/run-run/src/services/tool.ts b/packages/run-run/src/services/tool.ts index 4881e0e..352a7bb 100644 --- a/packages/run-run/src/services/tool.ts +++ b/packages/run-run/src/services/tool.ts @@ -19,7 +19,7 @@ export abstract class ToolService { this.#shellService = shellService; } - abstract getBinDir(): string; + getBinDir?(): string; exec(args: string | string[]) { const $ = this.#shell(); @@ -27,9 +27,11 @@ export abstract class ToolService { } #shell = memoize((cwd?: string) => { + const { getBinDir } = this; + return this.#shellService.child({ cwd, - preferLocal: gracefullBinDir(() => this.getBinDir()), + ...(getBinDir && { preferLocal: gracefullBinDir(() => getBinDir()) }), }).$; }); diff --git a/packages/run-run/src/services/tsdown.ts b/packages/run-run/src/services/tsdown.ts new file mode 100644 index 0000000..609b7f9 --- /dev/null +++ b/packages/run-run/src/services/tsdown.ts @@ -0,0 +1,9 @@ +import type { ShellService } from "@vlandoss/clibuddy"; +import { TOOL_LABELS } from "#/program/ui"; +import { ToolService } from "./tool"; + +export class TsdownService extends ToolService { + constructor(shellService: ShellService) { + super({ bin: "tsdown", ui: TOOL_LABELS.TSDOWN, shellService }); + } +} diff --git a/packages/run-run/tools/tsdown b/packages/run-run/tools/tsdown new file mode 100755 index 0000000..73b1c3c --- /dev/null +++ b/packages/run-run/tools/tsdown @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +bunx rr tools tsdown "$@" diff --git a/packages/run-run/tsdown.config.ts b/packages/run-run/tsdown.config.ts new file mode 100644 index 0000000..a844b7f --- /dev/null +++ b/packages/run-run/tsdown.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from "tsdown"; + +export default defineConfig({ + entry: ["src/lib/**/*.ts"], + format: "esm", + dts: true, +}); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..6763df3 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "paths": { + "@vlandoss/run-run/*": ["./packages/run-run/src/lib/*"] + } + } +}