@rrlab/tsdown-plugin 0.1.1 → 0.1.2-git-c5c6e0f.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 +3 -1
- package/dist/index.mjs +13 -58
- package/package.json +3 -3
- package/src/index.ts +16 -60
package/dist/index.d.mts
CHANGED
|
@@ -16,6 +16,8 @@ declare class TsdownService extends ToolService {
|
|
|
16
16
|
}
|
|
17
17
|
declare function install(ctx: InstallContext): Promise<InstallResult>;
|
|
18
18
|
declare function uninstall(ctx: UninstallContext): Promise<UninstallResult>;
|
|
19
|
-
declare const tsdown: (options
|
|
19
|
+
declare const tsdown: (options?: {
|
|
20
|
+
only?: readonly "pack"[] | undefined;
|
|
21
|
+
} | undefined) => import("@rrlab/cli/plugin").Plugin;
|
|
20
22
|
//#endregion
|
|
21
23
|
export { TOOL_VERSIONS, TsdownService, tsdown as default, install, uninstall };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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
|
|
@@ -48,9 +48,18 @@ var TsdownService = class extends ToolService {
|
|
|
48
48
|
};
|
|
49
49
|
async function install(ctx) {
|
|
50
50
|
const existingPath = await findExistingConfig(ctx.appPkg.dirPath);
|
|
51
|
-
const action = await
|
|
51
|
+
const action = await decideScaffold(ctx, {
|
|
52
|
+
label: existingPath ? path.relative(ctx.appPkg.dirPath, existingPath) : DEFAULT_CONFIG_FILENAME,
|
|
53
|
+
fileExists: existingPath !== null,
|
|
54
|
+
patchHint: `rewrite to use ${CONFIG_PKG}, keep my options`,
|
|
55
|
+
unattendedExistingAction: "skip"
|
|
56
|
+
});
|
|
52
57
|
if (action === "skip") return { devDependencies: { tsdown: TOOL_VERSIONS.tsdown.install } };
|
|
53
|
-
const { factory } = PRESETS[await pickPreset(ctx
|
|
58
|
+
const { factory } = PRESETS[await pickPreset(ctx, {
|
|
59
|
+
message: "Which kind of build?",
|
|
60
|
+
presets: PRESETS,
|
|
61
|
+
defaultPreset: DEFAULT_PRESET
|
|
62
|
+
})];
|
|
54
63
|
const devDependencies = {
|
|
55
64
|
tsdown: TOOL_VERSIONS.tsdown.install,
|
|
56
65
|
[CONFIG_PKG]: await ctx.release.resolve(CONFIG_PKG)
|
|
@@ -118,52 +127,6 @@ async function findExistingConfig(cwd) {
|
|
|
118
127
|
}
|
|
119
128
|
return null;
|
|
120
129
|
}
|
|
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
130
|
function renderScaffold(factory) {
|
|
168
131
|
return `import { ${factory} } from "${CONFIG_PKG}";\n\nexport default ${factory}();\n`;
|
|
169
132
|
}
|
|
@@ -249,15 +212,7 @@ const tsdown = definePlugin(() => ({
|
|
|
249
212
|
apiVersion: 1,
|
|
250
213
|
install,
|
|
251
214
|
uninstall,
|
|
252
|
-
|
|
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
|
-
}
|
|
215
|
+
capabilities: ({ shell }) => ({ pack: new TsdownService(shell) })
|
|
261
216
|
}));
|
|
262
217
|
//#endregion
|
|
263
218
|
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.
|
|
3
|
+
"version": "0.1.2-git-c5c6e0f.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,11 @@
|
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"tsdown": ">=0.22.0",
|
|
41
|
-
"@rrlab/cli": "0.0.
|
|
41
|
+
"@rrlab/cli": "0.0.4-git-c5c6e0f.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"tsdown": "0.22.0",
|
|
45
|
-
"@rrlab/cli": "0.0.
|
|
45
|
+
"@rrlab/cli": "0.0.4-git-c5c6e0f.0",
|
|
46
46
|
"@rrlab/tsdown-config": "^0.1.0"
|
|
47
47
|
},
|
|
48
48
|
"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
|
|
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
|
|
272
|
+
const tsdown = definePlugin(() => ({
|
|
306
273
|
name: "tsdown",
|
|
307
274
|
apiVersion: 1,
|
|
308
275
|
install,
|
|
309
276
|
uninstall,
|
|
310
|
-
|
|
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;
|