@rrlab/tsdown-plugin 0.1.1 → 0.1.2-git-2238423.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/dist/index.d.mts CHANGED
@@ -5,7 +5,6 @@ import { ShellService } from "@vlandoss/clibuddy";
5
5
  declare const TOOL_VERSIONS: {
6
6
  readonly tsdown: {
7
7
  readonly install: "^0.22.0";
8
- readonly peer: ">=0.22.0";
9
8
  };
10
9
  };
11
10
  //#endregion
@@ -16,6 +15,8 @@ declare class TsdownService extends ToolService {
16
15
  }
17
16
  declare function install(ctx: InstallContext): Promise<InstallResult>;
18
17
  declare function uninstall(ctx: UninstallContext): Promise<UninstallResult>;
19
- declare const tsdown: (options: void) => import("@rrlab/cli/plugin").Plugin;
18
+ declare const tsdown: (options?: {
19
+ only?: readonly "pack"[] | undefined;
20
+ } | undefined) => import("@rrlab/cli/plugin").Plugin;
20
21
  //#endregion
21
22
  export { TOOL_VERSIONS, TsdownService, tsdown as default, install, uninstall };
package/dist/index.mjs CHANGED
@@ -1,13 +1,10 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
- import { ToolService, definePlugin } from "@rrlab/cli/plugin";
3
+ import { ToolService, decideScaffold, definePlugin, pickPreset } from "@rrlab/cli/plugin";
4
4
  import { colorize } from "@vlandoss/clibuddy";
5
5
  import { generateCode, parseModule } from "magicast";
6
6
  //#region src/tool-versions.ts
7
- const TOOL_VERSIONS = { tsdown: {
8
- install: "^0.22.0",
9
- peer: ">=0.22.0"
10
- } };
7
+ const TOOL_VERSIONS = { tsdown: { install: "^0.22.0" } };
11
8
  //#endregion
12
9
  //#region src/index.ts
13
10
  const FROM = import.meta.url;
@@ -48,9 +45,18 @@ var TsdownService = class extends ToolService {
48
45
  };
49
46
  async function install(ctx) {
50
47
  const existingPath = await findExistingConfig(ctx.appPkg.dirPath);
51
- const action = await decideScaffoldAction(ctx, existingPath);
48
+ const action = await decideScaffold(ctx, {
49
+ label: existingPath ? path.relative(ctx.appPkg.dirPath, existingPath) : DEFAULT_CONFIG_FILENAME,
50
+ fileExists: existingPath !== null,
51
+ patchHint: `rewrite to use ${CONFIG_PKG}, keep my options`,
52
+ unattendedExistingAction: "skip"
53
+ });
52
54
  if (action === "skip") return { devDependencies: { tsdown: TOOL_VERSIONS.tsdown.install } };
53
- const { factory } = PRESETS[await pickPreset(ctx)];
55
+ const { factory } = PRESETS[await pickPreset(ctx, {
56
+ message: "Which kind of build?",
57
+ presets: PRESETS,
58
+ defaultPreset: DEFAULT_PRESET
59
+ })];
54
60
  const devDependencies = {
55
61
  tsdown: TOOL_VERSIONS.tsdown.install,
56
62
  [CONFIG_PKG]: await ctx.release.resolve(CONFIG_PKG)
@@ -118,52 +124,6 @@ async function findExistingConfig(cwd) {
118
124
  }
119
125
  return null;
120
126
  }
121
- async function decideScaffoldAction(ctx, existingPath) {
122
- if (!existingPath) {
123
- if (ctx.flags.yes || ctx.flags.nonInteractive) return "create";
124
- const choice = await ctx.prompts.confirm({
125
- message: `Scaffold ${DEFAULT_CONFIG_FILENAME} from ${CONFIG_PKG}?`,
126
- initialValue: true
127
- });
128
- if (ctx.prompts.isCancel(choice)) throw new Error("Cancelled by user.");
129
- return choice ? "create" : "skip";
130
- }
131
- if (ctx.flags.yes || ctx.flags.nonInteractive) return "skip";
132
- const relPath = path.relative(ctx.appPkg.dirPath, existingPath);
133
- const choice = await ctx.prompts.select({
134
- message: `${relPath} already exists. What do you want to do?`,
135
- options: [
136
- {
137
- value: "patch",
138
- label: `Patch — rewrite to use ${CONFIG_PKG}, keep my options`
139
- },
140
- {
141
- value: "skip",
142
- label: "Skip — leave it alone"
143
- },
144
- {
145
- value: "overwrite",
146
- label: "Overwrite — replace with a fresh scaffold"
147
- }
148
- ],
149
- initialValue: "patch"
150
- });
151
- if (ctx.prompts.isCancel(choice)) throw new Error("Cancelled by user.");
152
- return choice;
153
- }
154
- async function pickPreset(ctx) {
155
- if (ctx.flags.yes || ctx.flags.nonInteractive) return DEFAULT_PRESET;
156
- const choice = await ctx.prompts.select({
157
- message: "Which kind of build?",
158
- options: Object.entries(PRESETS).map(([value, meta]) => ({
159
- value,
160
- label: meta.label
161
- })),
162
- initialValue: DEFAULT_PRESET
163
- });
164
- if (ctx.prompts.isCancel(choice)) throw new Error("Cancelled by user.");
165
- return choice;
166
- }
167
127
  function renderScaffold(factory) {
168
128
  return `import { ${factory} } from "${CONFIG_PKG}";\n\nexport default ${factory}();\n`;
169
129
  }
@@ -249,15 +209,7 @@ const tsdown = definePlugin(() => ({
249
209
  apiVersion: 1,
250
210
  install,
251
211
  uninstall,
252
- async setup({ shell }) {
253
- const svc = new TsdownService(shell);
254
- try {
255
- await svc.getBinDir();
256
- } catch (_err) {
257
- throw new Error("@rrlab/tsdown-plugin requires tsdown to be installed in the host project. Run: rr plugins add tsdown (or: pnpm add -D tsdown)");
258
- }
259
- return { pack: svc };
260
- }
212
+ capabilities: ({ shell }) => ({ pack: new TsdownService(shell) })
261
213
  }));
262
214
  //#endregion
263
215
  export { TOOL_VERSIONS, TsdownService, tsdown as default, install, uninstall };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rrlab/tsdown-plugin",
3
- "version": "0.1.1",
3
+ "version": "0.1.2-git-2238423.0",
4
4
  "description": "tsdown plugin for @rrlab/cli — provides the pack capability for building TS libraries.",
5
5
  "homepage": "https://github.com/variableland/dx/tree/main/run-run/tsdown-plugin#readme",
6
6
  "bugs": {
@@ -38,11 +38,13 @@
38
38
  },
39
39
  "peerDependencies": {
40
40
  "tsdown": ">=0.22.0",
41
- "@rrlab/cli": "0.0.3"
41
+ "@rrlab/cli": "0.0.4-git-2238423.0"
42
42
  },
43
43
  "devDependencies": {
44
+ "@types/semver": "^7.7.1",
45
+ "semver": "^7.8.1",
44
46
  "tsdown": "0.22.0",
45
- "@rrlab/cli": "0.0.3",
47
+ "@rrlab/cli": "0.0.4-git-2238423.0",
46
48
  "@rrlab/tsdown-config": "^0.1.0"
47
49
  },
48
50
  "scripts": {
package/src/index.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import {
4
+ decideScaffold,
4
5
  definePlugin,
5
6
  type InstallContext,
6
7
  type InstallResult,
8
+ pickPreset,
7
9
  ToolService,
8
10
  type UninstallContext,
9
11
  type UninstallResult,
@@ -41,8 +43,6 @@ const PRESETS: Record<Preset, PresetInfo> = {
41
43
  };
42
44
  const DEFAULT_PRESET: Preset = "lib";
43
45
 
44
- type ExistingFileAction = "patch" | "skip" | "overwrite";
45
-
46
46
  export class TsdownService extends ToolService {
47
47
  constructor(shellService: ShellService) {
48
48
  super({ pkg: "tsdown", ui: UI, shellService, from: FROM });
@@ -55,12 +55,22 @@ export class TsdownService extends ToolService {
55
55
 
56
56
  export async function install(ctx: InstallContext): Promise<InstallResult> {
57
57
  const existingPath = await findExistingConfig(ctx.appPkg.dirPath);
58
- const action = await decideScaffoldAction(ctx, existingPath);
58
+ const action = await decideScaffold(ctx, {
59
+ label: existingPath ? path.relative(ctx.appPkg.dirPath, existingPath) : DEFAULT_CONFIG_FILENAME,
60
+ fileExists: existingPath !== null,
61
+ patchHint: `rewrite to use ${CONFIG_PKG}, keep my options`,
62
+ unattendedExistingAction: "skip",
63
+ });
64
+
59
65
  if (action === "skip") {
60
66
  return { devDependencies: { tsdown: TOOL_VERSIONS.tsdown.install } };
61
67
  }
62
68
 
63
- const preset = await pickPreset(ctx);
69
+ const preset = await pickPreset(ctx, {
70
+ message: "Which kind of build?",
71
+ presets: PRESETS,
72
+ defaultPreset: DEFAULT_PRESET,
73
+ });
64
74
  const { factory } = PRESETS[preset];
65
75
 
66
76
  const devDependencies: Record<string, string> = {
@@ -150,49 +160,6 @@ async function findExistingConfig(cwd: string): Promise<string | null> {
150
160
  return null;
151
161
  }
152
162
 
153
- async function decideScaffoldAction(ctx: InstallContext, existingPath: string | null): Promise<"create" | ExistingFileAction> {
154
- if (!existingPath) {
155
- if (ctx.flags.yes || ctx.flags.nonInteractive) return "create";
156
- const choice = await ctx.prompts.confirm({
157
- message: `Scaffold ${DEFAULT_CONFIG_FILENAME} from ${CONFIG_PKG}?`,
158
- initialValue: true,
159
- });
160
- if (ctx.prompts.isCancel(choice)) throw new Error("Cancelled by user.");
161
- return choice ? "create" : "skip";
162
- }
163
-
164
- // Existing file: don't silently rewrite under --yes — that's user code.
165
- if (ctx.flags.yes || ctx.flags.nonInteractive) return "skip";
166
-
167
- const relPath = path.relative(ctx.appPkg.dirPath, existingPath);
168
- const choice = await ctx.prompts.select<ExistingFileAction>({
169
- message: `${relPath} already exists. What do you want to do?`,
170
- options: [
171
- { value: "patch", label: `Patch — rewrite to use ${CONFIG_PKG}, keep my options` },
172
- { value: "skip", label: "Skip — leave it alone" },
173
- { value: "overwrite", label: "Overwrite — replace with a fresh scaffold" },
174
- ],
175
- initialValue: "patch",
176
- });
177
- if (ctx.prompts.isCancel(choice)) throw new Error("Cancelled by user.");
178
- return choice;
179
- }
180
-
181
- async function pickPreset(ctx: InstallContext): Promise<Preset> {
182
- if (ctx.flags.yes || ctx.flags.nonInteractive) return DEFAULT_PRESET;
183
-
184
- const choice = await ctx.prompts.select<Preset>({
185
- message: "Which kind of build?",
186
- options: (Object.entries(PRESETS) as Array<[Preset, PresetInfo]>).map(([value, meta]) => ({
187
- value,
188
- label: meta.label,
189
- })),
190
- initialValue: DEFAULT_PRESET,
191
- });
192
- if (ctx.prompts.isCancel(choice)) throw new Error("Cancelled by user.");
193
- return choice;
194
- }
195
-
196
163
  function renderScaffold(factory: FactoryName): string {
197
164
  return `import { ${factory} } from "${CONFIG_PKG}";\n\nexport default ${factory}();\n`;
198
165
  }
@@ -302,23 +269,12 @@ function setCalleeName(mod: ProxifiedModule, newName: string): void {
302
269
  ast.callee.name = newName;
303
270
  }
304
271
 
305
- const tsdown = definePlugin<void>(() => ({
272
+ const tsdown = definePlugin(() => ({
306
273
  name: "tsdown",
307
274
  apiVersion: 1,
308
275
  install,
309
276
  uninstall,
310
- async setup({ shell }) {
311
- const svc = new TsdownService(shell);
312
- try {
313
- await svc.getBinDir();
314
- } catch (_err) {
315
- throw new Error(
316
- "@rrlab/tsdown-plugin requires tsdown to be installed in the host project. " +
317
- "Run: rr plugins add tsdown (or: pnpm add -D tsdown)",
318
- );
319
- }
320
- return { pack: svc };
321
- },
277
+ capabilities: ({ shell }) => ({ pack: new TsdownService(shell) }),
322
278
  }));
323
279
 
324
280
  export default tsdown;
@@ -1,3 +1,3 @@
1
1
  export const TOOL_VERSIONS = {
2
- tsdown: { install: "^0.22.0", peer: ">=0.22.0" },
2
+ tsdown: { install: "^0.22.0" },
3
3
  } as const;