@kubb/cli 5.15.1 → 5.15.3
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/{Telemetry-C7Qwy2s7.js → Telemetry-BTeqnqie.js} +2 -2
- package/dist/{Telemetry-C7Qwy2s7.js.map → Telemetry-BTeqnqie.js.map} +1 -1
- package/dist/{Telemetry-B52pKz9i.cjs → Telemetry-DuO34wMx.cjs} +2 -2
- package/dist/{Telemetry-B52pKz9i.cjs.map → Telemetry-DuO34wMx.cjs.map} +1 -1
- package/dist/{background-CK2gQtTU.cjs → background-CdE3TOkv.cjs} +2 -2
- package/dist/{background-CK2gQtTU.cjs.map → background-CdE3TOkv.cjs.map} +1 -1
- package/dist/{background-BJCuXYuB.js → background-DxK8rpi2.js} +2 -2
- package/dist/{background-BJCuXYuB.js.map → background-DxK8rpi2.js.map} +1 -1
- package/dist/{background-D4mZCg-4.js → background-TT-XsxC2.js} +1 -1
- package/dist/{configFile-CoEpHdXG.cjs → configFile-CVfWdtKh.cjs} +4 -40
- package/dist/configFile-CVfWdtKh.cjs.map +1 -0
- package/dist/{configFile-C0DIXNMD.js → configFile-IHj8fRIw.js} +3 -39
- package/dist/configFile-IHj8fRIw.js.map +1 -0
- package/dist/{spinner-BZaln7O8.js → fs-Cf1FSRh9.js} +20 -41
- package/dist/fs-Cf1FSRh9.js.map +1 -0
- package/dist/index.cjs +14 -14
- package/dist/index.js +14 -14
- package/dist/{installWithSpinner-DpnpxHq5.js → installWithSpinner-BAlTSQlE.js} +3 -3
- package/dist/{installWithSpinner-DpnpxHq5.js.map → installWithSpinner-BAlTSQlE.js.map} +1 -1
- package/dist/{installWithSpinner-ONGfIVUJ.cjs → installWithSpinner-X9J7yxiR.cjs} +3 -3
- package/dist/{installWithSpinner-ONGfIVUJ.cjs.map → installWithSpinner-X9J7yxiR.cjs.map} +1 -1
- package/dist/intro-DRl-pwVs.js +72 -0
- package/dist/intro-DRl-pwVs.js.map +1 -0
- package/dist/intro-DuyzJ3Rb.cjs +102 -0
- package/dist/intro-DuyzJ3Rb.cjs.map +1 -0
- package/dist/{intro-9PB8sE8z.js → log-B-1vLxF1.js} +2 -66
- package/dist/log-B-1vLxF1.js.map +1 -0
- package/dist/{intro-YPaf1Imr.cjs → log-wv1OxLiq.cjs} +1 -95
- package/dist/log-wv1OxLiq.cjs.map +1 -0
- package/dist/{mascot-JSA0j3Q_.cjs → mascot-CC-D4ON2.cjs} +2 -2
- package/dist/{mascot-JSA0j3Q_.cjs.map → mascot-CC-D4ON2.cjs.map} +1 -1
- package/dist/{mascot--q1xjKw1.js → mascot-CmUUHLlx.js} +2 -2
- package/dist/{mascot--q1xjKw1.js.map → mascot-CmUUHLlx.js.map} +1 -1
- package/dist/{mcp-CcseJJwh.cjs → mcp-DMCyJrkw.cjs} +2 -2
- package/dist/{mcp-CcseJJwh.cjs.map → mcp-DMCyJrkw.cjs.map} +1 -1
- package/dist/{mcp-DUTsS8tR.js → mcp-DNMDPZOo.js} +2 -2
- package/dist/{mcp-DUTsS8tR.js.map → mcp-DNMDPZOo.js.map} +1 -1
- package/dist/{package-B1hUUjio.cjs → package-Bc9heh-c.cjs} +2 -2
- package/dist/package-Bc9heh-c.cjs.map +1 -0
- package/dist/package-Bm6L1D0Q.js +5 -0
- package/dist/package-Bm6L1D0Q.js.map +1 -0
- package/dist/{registry-B3eYk4LN.js → registry-Cy48PGdh.js} +3 -2
- package/dist/registry-Cy48PGdh.js.map +1 -0
- package/dist/{registry-YE1pFWL-.cjs → registry-Q77p5TZp.cjs} +3 -2
- package/dist/registry-Q77p5TZp.cjs.map +1 -0
- package/dist/reporters-9MqdcKPp.js +1 -0
- package/dist/{reporters-BM430HdQ.js → reporters-B_USHwD6.js} +297 -33
- package/dist/reporters-B_USHwD6.js.map +1 -0
- package/dist/{reporters-2cgjvXwR.cjs → reporters-DyjE3BzZ.cjs} +318 -20
- package/dist/reporters-DyjE3BzZ.cjs.map +1 -0
- package/dist/{run-CXVhxFfC.js → run-B4pveKq5.js} +10 -10
- package/dist/{run-CXVhxFfC.js.map → run-B4pveKq5.js.map} +1 -1
- package/dist/{run-CLiHI99L.js → run-B7p16C0S.js} +4 -4
- package/dist/{run-CLiHI99L.js.map → run-B7p16C0S.js.map} +1 -1
- package/dist/{run-dMTJfs4_.cjs → run-BBzw9B1L.cjs} +4 -4
- package/dist/{run-dMTJfs4_.cjs.map → run-BBzw9B1L.cjs.map} +1 -1
- package/dist/{run-DUwX6Icx.js → run-CBB5Hlgy.js} +10 -9
- package/dist/{run-DUwX6Icx.js.map → run-CBB5Hlgy.js.map} +1 -1
- package/dist/{run-CrM4jsix.cjs → run-CfumUZCl.cjs} +7 -6
- package/dist/{run-CrM4jsix.cjs.map → run-CfumUZCl.cjs.map} +1 -1
- package/dist/{run-D-nn9-Wq.js → run-Cgy4_JPy.js} +14 -18
- package/dist/run-Cgy4_JPy.js.map +1 -0
- package/dist/{run-1H9TGT8v.js → run-Ch7Uuu-u.js} +4 -3
- package/dist/{run-1H9TGT8v.js.map → run-Ch7Uuu-u.js.map} +1 -1
- package/dist/{run-BsrNfFIl.js → run-CkNLuV4M.js} +44 -38
- package/dist/run-CkNLuV4M.js.map +1 -0
- package/dist/{run-CyzKy-0p.cjs → run-CoPzxsoM.cjs} +20 -20
- package/dist/{run-CyzKy-0p.cjs.map → run-CoPzxsoM.cjs.map} +1 -1
- package/dist/{run-DTqMrPS9.js → run-CrDbD50I.js} +2 -2
- package/dist/{run-DTqMrPS9.js.map → run-CrDbD50I.js.map} +1 -1
- package/dist/{run-LY_UAYyM.cjs → run-Cxf3s3Ap.cjs} +48 -42
- package/dist/run-Cxf3s3Ap.cjs.map +1 -0
- package/dist/{run-BYP_t9dR.cjs → run-DCggecSY.cjs} +19 -24
- package/dist/run-DCggecSY.cjs.map +1 -0
- package/dist/{run-BrM7-NSV.js → run-DHfFHNfG.js} +13 -17
- package/dist/run-DHfFHNfG.js.map +1 -0
- package/dist/{run-DBnSbwtU.cjs → run-DQdcGuXL.cjs} +47 -61
- package/dist/run-DQdcGuXL.cjs.map +1 -0
- package/dist/{run-CvFakE3B.cjs → run-DT4hTOR2.cjs} +16 -21
- package/dist/run-DT4hTOR2.cjs.map +1 -0
- package/dist/{run-FEiyv6_U.js → run-DcEE0-8W.js} +40 -53
- package/dist/run-DcEE0-8W.js.map +1 -0
- package/dist/{run-Bq6gcfkS.js → run-MGGga_wU.js} +1 -1
- package/dist/{run-CQORv7Gq.cjs → run-S6Hkmn-h.cjs} +13 -12
- package/dist/{run-CQORv7Gq.cjs.map → run-S6Hkmn-h.cjs.map} +1 -1
- package/dist/{run-uPA5s3rI.cjs → run-UXFhmzzO.cjs} +2 -2
- package/dist/{run-uPA5s3rI.cjs.map → run-UXFhmzzO.cjs.map} +1 -1
- package/dist/shared-DcDHRtZx.js +58 -0
- package/dist/shared-DcDHRtZx.js.map +1 -0
- package/dist/shared-KKRMm1xX.cjs +87 -0
- package/dist/shared-KKRMm1xX.cjs.map +1 -0
- package/dist/{snapshot-CPF9zyZj.cjs → snapshot-BHFRCLgH.cjs} +7 -7
- package/dist/{snapshot-CPF9zyZj.cjs.map → snapshot-BHFRCLgH.cjs.map} +1 -1
- package/dist/{snapshot-CiV08NJr.js → snapshot-NH1AFDwz.js} +6 -6
- package/dist/{snapshot-CiV08NJr.js.map → snapshot-NH1AFDwz.js.map} +1 -1
- package/dist/spinner-DxsAllRI.js +48 -0
- package/dist/spinner-DxsAllRI.js.map +1 -0
- package/dist/{spinner-CfB0sIPy.cjs → spinner-RfMb7fd6.cjs} +50 -21
- package/dist/spinner-RfMb7fd6.cjs.map +1 -0
- package/dist/{status-C066YA-4.cjs → status-3A7fVPqb.cjs} +3 -3
- package/dist/{status-C066YA-4.cjs.map → status-3A7fVPqb.cjs.map} +1 -1
- package/dist/{status-Dj8tivag.js → status-BeJwJ7Xa.js} +3 -3
- package/dist/{status-Dj8tivag.js.map → status-BeJwJ7Xa.js.map} +1 -1
- package/dist/{studio-B4XsXgKj.js → studio-B-1AM1My.js} +12 -12
- package/dist/{studio-B4XsXgKj.js.map → studio-B-1AM1My.js.map} +1 -1
- package/dist/{studio-D9_-mKee.cjs → studio-BUhnJl4S.cjs} +12 -12
- package/dist/{studio-D9_-mKee.cjs.map → studio-BUhnJl4S.cjs.map} +1 -1
- package/dist/studioWorker.js +2 -2
- package/dist/{summary-Clvl5Hxs.cjs → summary-B2Apv5KO.cjs} +17 -2
- package/dist/summary-B2Apv5KO.cjs.map +1 -0
- package/dist/{summary-CbmQKA8l.js → summary-BQWHL_Ca.js} +12 -3
- package/dist/summary-BQWHL_Ca.js.map +1 -0
- package/dist/{text-Ep3AulAS.cjs → text-DMiX2dcG.cjs} +10 -1
- package/dist/text-DMiX2dcG.cjs.map +1 -0
- package/dist/{text-BmiI4s6N.js → text-EoYn04SX.js} +5 -2
- package/dist/text-EoYn04SX.js.map +1 -0
- package/dist/{utils-CbJ6hS_t.js → utils-CeMUE4P0.js} +90 -70
- package/dist/utils-CeMUE4P0.js.map +1 -0
- package/dist/{utils-CO89mxRU.cjs → utils-uSJAZuvP.cjs} +101 -69
- package/dist/utils-uSJAZuvP.cjs.map +1 -0
- package/dist/{validate-C5fyNF4v.js → validate--AEg1yAB.js} +3 -3
- package/dist/{validate-C5fyNF4v.js.map → validate--AEg1yAB.js.map} +1 -1
- package/dist/{validate-B3tLWYJU.cjs → validate-BVNrsXe2.cjs} +3 -3
- package/dist/{validate-B3tLWYJU.cjs.map → validate-BVNrsXe2.cjs.map} +1 -1
- package/package.json +8 -7
- package/dist/configFile-C0DIXNMD.js.map +0 -1
- package/dist/configFile-CoEpHdXG.cjs.map +0 -1
- package/dist/intro-9PB8sE8z.js.map +0 -1
- package/dist/intro-YPaf1Imr.cjs.map +0 -1
- package/dist/package-B1hUUjio.cjs.map +0 -1
- package/dist/package-MYPMnnTX.js +0 -5
- package/dist/package-MYPMnnTX.js.map +0 -1
- package/dist/registry-B3eYk4LN.js.map +0 -1
- package/dist/registry-YE1pFWL-.cjs.map +0 -1
- package/dist/reporters-2cgjvXwR.cjs.map +0 -1
- package/dist/reporters-BM430HdQ.js.map +0 -1
- package/dist/run-BYP_t9dR.cjs.map +0 -1
- package/dist/run-BrM7-NSV.js.map +0 -1
- package/dist/run-BsrNfFIl.js.map +0 -1
- package/dist/run-CvFakE3B.cjs.map +0 -1
- package/dist/run-D-nn9-Wq.js.map +0 -1
- package/dist/run-DBnSbwtU.cjs.map +0 -1
- package/dist/run-FEiyv6_U.js.map +0 -1
- package/dist/run-LY_UAYyM.cjs.map +0 -1
- package/dist/shared-C0EtrdUm.cjs +0 -123
- package/dist/shared-C0EtrdUm.cjs.map +0 -1
- package/dist/shared-Ct9stKpp.js +0 -94
- package/dist/shared-Ct9stKpp.js.map +0 -1
- package/dist/spinner-BZaln7O8.js.map +0 -1
- package/dist/spinner-CfB0sIPy.cjs.map +0 -1
- package/dist/summary-CbmQKA8l.js.map +0 -1
- package/dist/summary-Clvl5Hxs.cjs.map +0 -1
- package/dist/text-BmiI4s6N.js.map +0 -1
- package/dist/text-Ep3AulAS.cjs.map +0 -1
- package/dist/utils-BdibacYq.js +0 -244
- package/dist/utils-BdibacYq.js.map +0 -1
- package/dist/utils-CO89mxRU.cjs.map +0 -1
- package/dist/utils-CbJ6hS_t.js.map +0 -1
- package/dist/utils-CcARPB45.cjs +0 -286
- package/dist/utils-CcARPB45.cjs.map +0 -1
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import "./rolldown-runtime-xo6NMXYd.js";
|
|
2
|
-
import {
|
|
2
|
+
import { d as uninstallPackages, n as detectPackageManager, p as pascalCase } from "./utils-CeMUE4P0.js";
|
|
3
3
|
import { t as getErrorMessage } from "./errors-wzqmMpMo.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { i as read } from "./fs-Cf1FSRh9.js";
|
|
5
|
+
import { i as logStep, n as logError, t as logBlock } from "./log-B-1vLxF1.js";
|
|
6
|
+
import { n as logIntro, t as isInteractiveRun } from "./intro-DRl-pwVs.js";
|
|
7
|
+
import { o as yesArg, t as configArg } from "./shared-DcDHRtZx.js";
|
|
7
8
|
import { r as BUNDLED_PACKAGES, t as findConfigFile } from "./config-CQTxXvIG.js";
|
|
8
|
-
import { t as
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { a as ConfigEditOperation, i as readImports, n as editConfigFile, o as extensionKinds, r as readConfig, t as editConfig } from "./configFile-IHj8fRIw.js";
|
|
10
|
+
import { n as withSpinner } from "./spinner-DxsAllRI.js";
|
|
11
|
+
import { t as createSummary } from "./summary-BQWHL_Ca.js";
|
|
12
|
+
import { c as toRegistryId, l as toShortId, n as closestIds, r as fetchRegistryIndex, s as registryUrl } from "./registry-Cy48PGdh.js";
|
|
11
13
|
import { styleText } from "node:util";
|
|
12
14
|
import { define } from "gunshi";
|
|
13
15
|
import process from "node:process";
|
|
@@ -32,13 +34,7 @@ function removedLines({ before, after }) {
|
|
|
32
34
|
async function run({ id: input, configPath, yes, uninstall }) {
|
|
33
35
|
const cwd = process.cwd();
|
|
34
36
|
const hrStart = process.hrtime();
|
|
35
|
-
const summary = (
|
|
36
|
-
title,
|
|
37
|
-
status,
|
|
38
|
-
hrStart,
|
|
39
|
-
block: true,
|
|
40
|
-
lines
|
|
41
|
-
});
|
|
37
|
+
const summary = createSummary(hrStart);
|
|
42
38
|
const fail = (title, lines) => {
|
|
43
39
|
summary(title, "failed", lines);
|
|
44
40
|
process.exitCode = 1;
|
|
@@ -72,7 +68,7 @@ async function run({ id: input, configPath, yes, uninstall }) {
|
|
|
72
68
|
return fail(`No extension named ${input}`, suggestions.map((suggestion) => ` kubb remove ${suggestion}`));
|
|
73
69
|
}
|
|
74
70
|
const { artifact, manifest } = entry;
|
|
75
|
-
const kind =
|
|
71
|
+
const kind = pascalCase(manifest.kind);
|
|
76
72
|
if (manifest.kind === extensionKinds.adapter) return fail("The adapter cannot be removed", [` A config needs one adapter. Change it in ${configName} by hand.`]);
|
|
77
73
|
const view = readConfig(source);
|
|
78
74
|
const running = new Set(view.managed ? view.configs.flatMap((config) => [...config.plugins, ...config.parsers ?? []].filter((call) => !call.disabled).map((call) => call.packageName)) : []);
|
|
@@ -130,7 +126,7 @@ async function run({ id: input, configPath, yes, uninstall }) {
|
|
|
130
126
|
if (!written.outcomes[0]?.applied) return fail(`Could not edit ${configName}`, [` ${written.outcomes[0]?.reason ?? "the config file was not changed"}`]);
|
|
131
127
|
logStep(`${manifest.export}() removed from ${configName}`);
|
|
132
128
|
}
|
|
133
|
-
const packageManager = detectPackageManager(cwd);
|
|
129
|
+
const packageManager = await detectPackageManager(cwd);
|
|
134
130
|
if (uninstalls) await withSpinner({
|
|
135
131
|
message: `Uninstalling ${artifact.package} with ${packageManager.name}`,
|
|
136
132
|
promise: uninstallPackages([artifact.package], packageManager, cwd)
|
|
@@ -178,4 +174,4 @@ const command = define({
|
|
|
178
174
|
});
|
|
179
175
|
export { command, run };
|
|
180
176
|
|
|
181
|
-
//# sourceMappingURL=run-
|
|
177
|
+
//# sourceMappingURL=run-DHfFHNfG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-DHfFHNfG.js","names":[],"sources":["../src/runners/remove/run.ts"],"sourcesContent":["import path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { define } from 'gunshi'\nimport { BUNDLED_PACKAGES, ConfigEditOperation, extensionKinds, editConfig, editConfigFile, findConfigFile, readConfig, readImports } from '@internals/shared'\nimport { getErrorMessage, pascalCase, read } from '@internals/utils'\nimport { Diagnostics, readInstalledPackages } from '@kubb/core'\nimport { configArg, yesArg } from '../../commands/shared.ts'\nimport { isInteractiveRun, logIntro } from '../../ui/intro.ts'\nimport { logBlock, logError, logStep } from '../../ui/log.ts'\nimport { withSpinner } from '../../ui/spinner.ts'\nimport { createSummary } from '../../ui/summary.ts'\nimport { closestIds, fetchRegistryIndex, registryUrl, toRegistryId, toShortId } from '../../utils/registry.ts'\nimport { detectPackageManager, uninstallPackages } from '../init/utils.ts'\n\nexport type RemoveOptions = {\n /**\n * `owner/slug`, or a bare `slug` for an official extension.\n */\n id: string\n configPath?: string\n yes: boolean\n uninstall: boolean\n}\n\n/** The lines of `before` that `after` no longer has, trimmed. */\nfunction removedLines({ before, after }: { before: string; after: string }): Array<string> {\n const remaining = after.split('\\n')\n return before\n .split('\\n')\n .filter((line) => {\n const index = remaining.indexOf(line)\n if (index !== -1) remaining.splice(index, 1)\n return index === -1 && line.trim() !== ''\n })\n .map((line) => line.trim())\n}\n\n/**\n * Removes a plugin or parser from `kubb.config.ts` and uninstalls its package. Refuses the adapter,\n * which the config needs, and an extension another one in the config depends on. Previews the\n * change before asking.\n */\nexport async function run({ id: input, configPath, yes, uninstall }: RemoveOptions): Promise<void> {\n const cwd = process.cwd()\n const hrStart = process.hrtime()\n const summary = createSummary(hrStart)\n const fail = (title: string, lines: ReadonlyArray<string>) => {\n summary(title, 'failed', lines)\n process.exitCode = 1\n }\n logIntro({ title: isInteractiveRun({ yes }) ? undefined : styleText('bgCyan', styleText('black', ' Kubb Remove ')) })\n\n try {\n const id = toRegistryId(input)\n const configFile = configPath ? path.resolve(configPath) : findConfigFile(cwd)\n if (!configFile)\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: 'No kubb.config.ts found. Pass its path with --config.',\n help: 'Run `kubb remove <id> --config <path>`.',\n })\n const configName = path.relative(cwd, configFile) || configFile\n const [entries, installed, source] = await withSpinner({\n message: 'Reading the registry',\n promise: Promise.all([fetchRegistryIndex({ registry: registryUrl() }), readInstalledPackages({ root: cwd }), read(configFile)]),\n })\n const versions = new Map(installed.map((item) => [item.package, item.version]))\n\n const entry = entries.find((candidate) => candidate.id === id)\n if (!entry) {\n const suggestions = closestIds({ input: id, ids: entries.map((candidate) => candidate.id) }).map(toShortId)\n return fail(\n `No extension named ${input}`,\n suggestions.map((suggestion) => ` kubb remove ${suggestion}`),\n )\n }\n const { artifact, manifest } = entry\n const kind = pascalCase(manifest.kind)\n if (manifest.kind === extensionKinds.adapter)\n return fail('The adapter cannot be removed', [` A config needs one adapter. Change it in ${configName} by hand.`])\n\n // Only calls that run count: a plugin Studio switched off is a comment, as in Studio's own check.\n const view = readConfig(source)\n const running = new Set(\n view.managed\n ? view.configs.flatMap((config) => [...config.plugins, ...(config.parsers ?? [])].filter((call) => !call.disabled).map((call) => call.packageName))\n : [],\n )\n const dependents = entries.filter(\n (other) => other.id !== entry.id && other.manifest.dependencies?.includes(manifest.name) && running.has(other.artifact.package),\n )\n if (dependents.length) {\n const names = dependents.map((other) => other.manifest.name).join(', ')\n return fail(`${names} ${dependents.length === 1 ? 'needs' : 'need'} ${manifest.name}`, [` Remove ${names} first.`])\n }\n\n const edits = [\n {\n operation: ConfigEditOperation.REMOVE_EXTENSION,\n ...(manifest.kind === extensionKinds.parser ? { kind: extensionKinds.parser } : {}),\n plugin: artifact.package,\n },\n ]\n const preview = editConfig({ source, edits })\n const outcome = preview.outcomes[0]\n if (!outcome?.applied) return fail(`Could not edit ${configName}`, [` ${outcome?.reason ?? 'the config file was not changed'}`])\n\n // Bundled extensions leave the config but stay installed.\n const bundled = BUNDLED_PACKAGES.includes(artifact.package)\n // Another `defineConfig` entry can still import it, and uninstalling it then breaks the config.\n const stillImported = readImports(preview.source).includes(artifact.package)\n const uninstalls = uninstall && !bundled && !stillImported && versions.has(artifact.package)\n if (!preview.changed && !uninstalls) {\n summary(`${manifest.name} is not in the project`, 'success', [' No changes made'])\n return\n }\n\n const packageLine = (() => {\n if (uninstalls) return `Uninstalls ${artifact.package}`\n if (bundled) return `Keeps ${artifact.package}, which ships with kubb`\n if (stillImported) return `Keeps ${artifact.package}, which another config entry still imports`\n return 'Uninstalls nothing'\n })()\n logStep(`${kind} ${styleText('cyan', manifest.name)} v${versions.get(artifact.package) ?? artifact.version}`)\n logBlock([\n `Config ${configName}`,\n ...removedLines({ before: source, after: preview.source }).map((line) => styleText('red', ` - ${line}`)),\n packageLine,\n ])\n\n const confirmed = yes || (await clack.confirm({ message: 'Remove it?', initialValue: true }))\n if (clack.isCancel(confirmed) || !confirmed) {\n summary('Remove canceled', 'canceled', [` ${kind} ${manifest.name}`, ' No changes made'])\n return\n }\n\n if (preview.changed) {\n const written = await editConfigFile({ filePath: configFile, edits })\n if (!written.outcomes[0]?.applied) return fail(`Could not edit ${configName}`, [` ${written.outcomes[0]?.reason ?? 'the config file was not changed'}`])\n logStep(`${manifest.export}() removed from ${configName}`)\n }\n const packageManager = await detectPackageManager(cwd)\n if (uninstalls)\n await withSpinner({\n message: `Uninstalling ${artifact.package} with ${packageManager.name}`,\n promise: uninstallPackages([artifact.package], packageManager, cwd),\n })\n\n summary(`${kind} removed`, 'success', [\n ` Packages ${uninstalls ? `${artifact.package} uninstalled with ${packageManager.name}` : 'none uninstalled'}`,\n '',\n 'Next kubb generate',\n ])\n } catch (error) {\n logError(getErrorMessage(error))\n fail('Remove failed', [' See the error above'])\n }\n}\n\nexport const command = define({\n name: 'remove',\n description: 'Remove a plugin or parser from kubb.config.ts and uninstall its package.',\n examples: ['kubb remove plugin-zod', 'kubb remove acme/plugin-x --yes', 'kubb remove plugin-zod --no-uninstall'].join('\\n'),\n toKebab: true,\n args: {\n id: {\n type: 'positional',\n description: 'Registry id: owner/slug, or a slug for an official extension',\n required: true,\n },\n ...configArg,\n ...yesArg,\n uninstall: {\n type: 'boolean',\n description: 'Uninstall the package. Pass --no-uninstall to only edit the config',\n negatable: true,\n default: true,\n },\n },\n run: ({ values }) => run({ id: values.id, configPath: values.config, yes: values.yes, uninstall: values.uninstall }),\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,aAAa,EAAE,QAAQ,SAA2D;CACzF,MAAM,YAAY,MAAM,MAAM,IAAI;CAClC,OAAO,OACJ,MAAM,IAAI,CAAC,CACX,QAAQ,SAAS;EAChB,MAAM,QAAQ,UAAU,QAAQ,IAAI;EACpC,IAAI,UAAU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MAAM,iBAAiB,MAAM,qBAAqB,GAAG;EACrD,IAAI,YACF,MAAM,YAAY;GAChB,SAAS,gBAAgB,SAAS,QAAQ,QAAQ,eAAe;GACjE,SAAS,kBAAkB,CAAC,SAAS,OAAO,GAAG,gBAAgB,GAAG;EACpE,CAAC;EAEH,QAAQ,GAAG,KAAK,WAAW,WAAW;GACpC,eAAe,aAAa,GAAG,SAAS,QAAQ,oBAAoB,eAAe,SAAS;GAC5F;GACA;EACF,CAAC;CACH,SAAS,OAAO;EACd,SAAS,gBAAgB,KAAK,CAAC;EAC/B,KAAK,iBAAiB,CAAC,uBAAuB,CAAC;CACjD;AACF;AAEA,MAAa,UAAU,OAAO;CAC5B,MAAM;CACN,aAAa;CACb,UAAU;EAAC;EAA0B;EAAmC;CAAuC,CAAC,CAAC,KAAK,IAAI;CAC1H,SAAS;CACT,MAAM;EACJ,IAAI;GACF,MAAM;GACN,aAAa;GACb,UAAU;EACZ;EACA,GAAG;EACH,GAAG;EACH,WAAW;GACT,MAAM;GACN,aAAa;GACb,WAAW;GACX,SAAS;EACX;CACF;CACA,MAAM,EAAE,aAAa,IAAI;EAAE,IAAI,OAAO;EAAI,YAAY,OAAO;EAAQ,KAAK,OAAO;EAAK,WAAW,OAAO;CAAU,CAAC;AACrH,CAAC"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-C3-Zg-KD.cjs");
|
|
2
|
-
const
|
|
2
|
+
const require_utils = require("./utils-uSJAZuvP.cjs");
|
|
3
3
|
const require_time = require("./time-3BKoci3G.cjs");
|
|
4
|
-
const require_spinner = require("./spinner-
|
|
5
|
-
const require_package = require("./package-
|
|
6
|
-
const
|
|
4
|
+
const require_spinner = require("./spinner-RfMb7fd6.cjs");
|
|
5
|
+
const require_package = require("./package-Bc9heh-c.cjs");
|
|
6
|
+
const require_log = require("./log-wv1OxLiq.cjs");
|
|
7
|
+
const require_intro = require("./intro-DuyzJ3Rb.cjs");
|
|
7
8
|
const require_config = require("./config-CRrmj88c.cjs");
|
|
9
|
+
const require_configFile = require("./configFile-CVfWdtKh.cjs");
|
|
8
10
|
const require_config$1 = require("./config-BWj9jBVj.cjs");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const require_installWithSpinner = require("./installWithSpinner-
|
|
12
|
-
const require_text = require("./text-Ep3AulAS.cjs");
|
|
11
|
+
const require_text = require("./text-DMiX2dcG.cjs");
|
|
12
|
+
const require_registry = require("./registry-Q77p5TZp.cjs");
|
|
13
|
+
const require_installWithSpinner = require("./installWithSpinner-X9J7yxiR.cjs");
|
|
13
14
|
let node_util = require("node:util");
|
|
14
15
|
let gunshi = require("gunshi");
|
|
15
16
|
let node_process = require("node:process");
|
|
@@ -19,6 +20,7 @@ node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
|
19
20
|
let _clack_prompts = require("@clack/prompts");
|
|
20
21
|
_clack_prompts = require_rolldown_runtime.__toESM(_clack_prompts, 1);
|
|
21
22
|
let _kubb_core = require("@kubb/core");
|
|
23
|
+
let package_manager_detector = require("package-manager-detector");
|
|
22
24
|
let _gunshi_plugin_dryrun = require("@gunshi/plugin-dryrun");
|
|
23
25
|
// ../../internals/shared/src/init.ts
|
|
24
26
|
/** The `kubb.config.ts` `kubb init` writes before `kubb add` puts each plugin in. */
|
|
@@ -84,13 +86,8 @@ async function firstRun(configPath) {
|
|
|
84
86
|
/** The command that runs `kubb generate`: the `generate` script when it runs Kubb, otherwise `npx kubb generate`. */
|
|
85
87
|
function generateCommand({ packageManager, script, watch }) {
|
|
86
88
|
if (script !== "kubb generate") return `npx kubb generate${watch ? " --watch" : ""}`;
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
...packageManager.runCommand,
|
|
90
|
-
"generate"
|
|
91
|
-
].join(" ");
|
|
92
|
-
if (!watch) return run;
|
|
93
|
-
return packageManager.name === "npm" ? `${run} -- --watch` : `${run} --watch`;
|
|
89
|
+
const { command, args } = (0, package_manager_detector.resolveCommand)(packageManager.agent, "run", watch ? ["generate", "--watch"] : ["generate"]);
|
|
90
|
+
return [command, ...args].join(" ");
|
|
94
91
|
}
|
|
95
92
|
/**
|
|
96
93
|
* Runs the Kubb setup wizard: detects the package manager and specs, asks for the spec, plugins, and
|
|
@@ -100,20 +97,6 @@ function generateCommand({ packageManager, script, watch }) {
|
|
|
100
97
|
*/
|
|
101
98
|
async function run({ yes, input: inputFlag, output: outputFlag, plugins: pluginsFlag, dryRun }) {
|
|
102
99
|
const cwd = node_process.default.cwd();
|
|
103
|
-
/** Runs `task` behind a spinner, or prints one line when it is done in `--yes` mode. */
|
|
104
|
-
async function step({ start, task, done, failed }) {
|
|
105
|
-
const spinner = require_spinner.createSpinner();
|
|
106
|
-
if (!yes) spinner.start(start);
|
|
107
|
-
try {
|
|
108
|
-
const result = await task();
|
|
109
|
-
if (yes) console.log(`${(0, node_util.styleText)("green", "✓")} ${done(result)}`);
|
|
110
|
-
else spinner.stop(done(result));
|
|
111
|
-
return result;
|
|
112
|
-
} catch (error) {
|
|
113
|
-
if (!yes) spinner.error(failed);
|
|
114
|
-
throw error;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
100
|
if (!yes) require_intro.logIntro({ title: require_intro.isInteractiveRun({
|
|
118
101
|
yes,
|
|
119
102
|
dryRun: dryRun.enabled
|
|
@@ -128,18 +111,19 @@ async function run({ yes, input: inputFlag, output: outputFlag, plugins: plugins
|
|
|
128
111
|
initialValue: true
|
|
129
112
|
}))) cancelAndExit();
|
|
130
113
|
}
|
|
131
|
-
const packageManager = require_utils.detectPackageManager(cwd);
|
|
132
|
-
await
|
|
133
|
-
|
|
134
|
-
|
|
114
|
+
const packageManager = await require_utils.detectPackageManager(cwd);
|
|
115
|
+
await require_spinner.withSpinner({
|
|
116
|
+
message: `Initializing package.json with ${packageManager.name}`,
|
|
117
|
+
promise: require_utils.initPackageJson(cwd, packageManager),
|
|
135
118
|
done: () => `Created package.json with ${packageManager.name}`,
|
|
136
|
-
failed: "Could not create package.json"
|
|
119
|
+
failed: "Could not create package.json",
|
|
120
|
+
plain: yes
|
|
137
121
|
});
|
|
138
122
|
}
|
|
139
|
-
const packageManager = require_utils.detectPackageManager(cwd);
|
|
123
|
+
const packageManager = await require_utils.detectPackageManager(cwd);
|
|
140
124
|
const specs = await require_utils.findSpecFiles(cwd);
|
|
141
125
|
if (!yes) {
|
|
142
|
-
|
|
126
|
+
require_log.logStep(`Package manager ${packageManager.name}`);
|
|
143
127
|
if (specs[0]) {
|
|
144
128
|
const { version: specVersion, operations } = await require_utils.readSpecInfo(node_path.default.join(cwd, specs[0]));
|
|
145
129
|
const details = [
|
|
@@ -148,7 +132,7 @@ async function run({ yes, input: inputFlag, output: outputFlag, plugins: plugins
|
|
|
148
132
|
operations === void 0 ? void 0 : require_text.pluralize(operations, "operation"),
|
|
149
133
|
specs.length > 1 ? `+${specs.length - 1} more` : void 0
|
|
150
134
|
];
|
|
151
|
-
|
|
135
|
+
require_log.logStep(`Found ${details.filter(Boolean).join(" · ")}`);
|
|
152
136
|
}
|
|
153
137
|
}
|
|
154
138
|
const plugins = pluginsFlag || yes ? await registry : void 0;
|
|
@@ -184,18 +168,18 @@ async function run({ yes, input: inputFlag, output: outputFlag, plugins: plugins
|
|
|
184
168
|
label: "Another file"
|
|
185
169
|
}
|
|
186
170
|
],
|
|
187
|
-
initialValue: specs.includes(current) ? current :
|
|
188
|
-
})) :
|
|
171
|
+
initialValue: specs.includes(current) ? current : require_text.isHttpUrl(current) ? "url" : "file"
|
|
172
|
+
})) : require_text.isHttpUrl(current) ? "url" : "file";
|
|
189
173
|
if (specs.includes(choice)) return choice;
|
|
190
174
|
const isUrl = choice === "url";
|
|
191
|
-
const initial = isUrl ===
|
|
175
|
+
const initial = isUrl === require_text.isHttpUrl(current) && !specs.includes(current) ? current : void 0;
|
|
192
176
|
return unwrap(await _clack_prompts.text({
|
|
193
177
|
message: isUrl ? "Spec URL" : "Spec path",
|
|
194
178
|
placeholder: isUrl ? "https://example.com/openapi.yaml" : require_config.initDefaults.inputPath,
|
|
195
179
|
initialValue: initial,
|
|
196
180
|
defaultValue: isUrl ? void 0 : require_config.initDefaults.inputPath,
|
|
197
181
|
validate: (value) => {
|
|
198
|
-
if (isUrl &&
|
|
182
|
+
if (isUrl && !require_text.isHttpUrl(value ?? "")) return "Enter an http(s) URL";
|
|
199
183
|
}
|
|
200
184
|
}));
|
|
201
185
|
}
|
|
@@ -231,13 +215,13 @@ async function run({ yes, input: inputFlag, output: outputFlag, plugins: plugins
|
|
|
231
215
|
firstPass = false;
|
|
232
216
|
const missing = require_utils.missingPluginDependencies(choices.plugins.map((entry) => entry.manifest));
|
|
233
217
|
if (missing.length) {
|
|
234
|
-
|
|
218
|
+
require_log.logWarn(`${missing.join("\n")}\nAdd the missing plugins.`);
|
|
235
219
|
continue;
|
|
236
220
|
}
|
|
237
221
|
const config = buildConfig(choices);
|
|
238
222
|
const packages = [require_config.KUBB_PACKAGE_NAME, ...choices.plugins.map((entry) => entry.artifact.package)];
|
|
239
|
-
|
|
240
|
-
|
|
223
|
+
require_log.logStep(`Review ${require_config.KUBB_CONFIG_FILENAME}`);
|
|
224
|
+
require_log.logBlock([
|
|
241
225
|
...config.trimEnd().split("\n"),
|
|
242
226
|
"",
|
|
243
227
|
`${(0, node_util.styleText)("dim", "Installs")} ${packages.join(" ")} with ${packageManager.name}`
|
|
@@ -271,11 +255,11 @@ async function run({ yes, input: inputFlag, output: outputFlag, plugins: plugins
|
|
|
271
255
|
const packagesToInstall = [`${require_config.KUBB_PACKAGE_NAME}@${require_package.version}`, ...choices.plugins.map((entry) => require_registry.installSpec(entry.artifact))];
|
|
272
256
|
const packageNames = [require_config.KUBB_PACKAGE_NAME, ...choices.plugins.map((entry) => entry.artifact.package)];
|
|
273
257
|
const dry = { message: `install ${packagesToInstall.length} packages with ${packageManager.name}` };
|
|
274
|
-
if (yes) await
|
|
275
|
-
|
|
276
|
-
|
|
258
|
+
if (yes) await require_spinner.withSpinner({
|
|
259
|
+
message: "",
|
|
260
|
+
promise: dryRun.run(() => require_utils.installPackages(packagesToInstall, packageManager, cwd), dry),
|
|
277
261
|
done: () => `Installed ${packageNames.join(" ")} with ${packageManager.name}`,
|
|
278
|
-
|
|
262
|
+
plain: true
|
|
279
263
|
});
|
|
280
264
|
else await require_installWithSpinner.installWithSpinner({
|
|
281
265
|
packages: packagesToInstall,
|
|
@@ -284,31 +268,33 @@ async function run({ yes, input: inputFlag, output: outputFlag, plugins: plugins
|
|
|
284
268
|
cwd,
|
|
285
269
|
install: async (packages, packageManager, cwd, onLine) => void await dryRun.run(() => require_utils.installPackages(packages, packageManager, cwd, onLine), dry)
|
|
286
270
|
});
|
|
287
|
-
await
|
|
288
|
-
|
|
289
|
-
|
|
271
|
+
await require_spinner.withSpinner({
|
|
272
|
+
message: `Writing ${require_config.KUBB_CONFIG_FILENAME}`,
|
|
273
|
+
promise: dryRun.run(async () => void await require_spinner.write(configPath, buildConfig(choices)), { message: `write ${require_config.KUBB_CONFIG_FILENAME}` }),
|
|
290
274
|
done: () => `Wrote ${require_config.KUBB_CONFIG_FILENAME}`,
|
|
291
|
-
failed: `Could not write ${require_config.KUBB_CONFIG_FILENAME}
|
|
275
|
+
failed: `Could not write ${require_config.KUBB_CONFIG_FILENAME}`,
|
|
276
|
+
plain: yes
|
|
292
277
|
});
|
|
293
278
|
const scriptAdded = await dryRun.run(() => require_utils.addGenerateScript(cwd), {
|
|
294
279
|
message: "add a generate script to package.json",
|
|
295
280
|
resolve: async () => await require_utils.generateScript(cwd) === void 0
|
|
296
281
|
});
|
|
297
|
-
if (scriptAdded && !yes)
|
|
282
|
+
if (scriptAdded && !yes) require_log.logStep("Added \"generate\": \"kubb generate\" to package.json");
|
|
298
283
|
const script = scriptAdded ? "kubb generate" : await require_utils.generateScript(cwd);
|
|
299
284
|
const runStart = node_process.default.hrtime();
|
|
300
285
|
try {
|
|
301
|
-
await dryRun.run(() =>
|
|
302
|
-
|
|
303
|
-
|
|
286
|
+
await dryRun.run(() => require_spinner.withSpinner({
|
|
287
|
+
message: "Running the first generation",
|
|
288
|
+
promise: firstRun(configPath),
|
|
304
289
|
done: (files) => yes ? `Generated ${require_text.pluralize(files, "file")} in ${choices.outputPath}` : `First run ${require_text.pluralize(files, "file")} in ${choices.outputPath} · ${require_time.formatMs(require_time.getElapsedMs(runStart))}`,
|
|
305
|
-
failed: "First run failed"
|
|
290
|
+
failed: "First run failed",
|
|
291
|
+
plain: yes
|
|
306
292
|
}), {
|
|
307
293
|
message: "run the first generation",
|
|
308
294
|
resolve: () => 0
|
|
309
295
|
});
|
|
310
296
|
} catch (error) {
|
|
311
|
-
|
|
297
|
+
require_log.logError(error instanceof Error ? error.message : String(error));
|
|
312
298
|
const message = `Kubb is set up, but the first run failed. Fix the error, then run ${generateCommand({
|
|
313
299
|
packageManager,
|
|
314
300
|
script,
|
|
@@ -333,8 +319,8 @@ async function run({ yes, input: inputFlag, output: outputFlag, plugins: plugins
|
|
|
333
319
|
watch: true
|
|
334
320
|
})}`);
|
|
335
321
|
} catch (error) {
|
|
336
|
-
|
|
337
|
-
if (error instanceof Error)
|
|
322
|
+
require_log.logError((0, node_util.styleText)("red", "An error occurred during initialization"));
|
|
323
|
+
if (error instanceof Error) require_log.logError(error.message);
|
|
338
324
|
node_process.default.exit(1);
|
|
339
325
|
}
|
|
340
326
|
}
|
|
@@ -386,4 +372,4 @@ const command = (0, gunshi.defineWithTypes)()({
|
|
|
386
372
|
exports.command = command;
|
|
387
373
|
exports.run = run;
|
|
388
374
|
|
|
389
|
-
//# sourceMappingURL=run-
|
|
375
|
+
//# sourceMappingURL=run-DQdcGuXL.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-DQdcGuXL.cjs","names":["clack","editConfig","ConfigEditOperation","Diagnostics","KUBB_CONFIG_FILENAME","getConfigs","createKubb","resolveCommand","process","isInteractiveRun","fetchRegistryIndex","registryUrl","incompatibility","exists","path","detectPackageManager","withSpinner","initPackageJson","findSpecFiles","readSpecInfo","pluralize","initDefaults","findPlugin","parsePluginsFlag","isHttpUrl","styleText","missingPluginDependencies","KUBB_PACKAGE_NAME","version","installSpec","installPackages","installWithSpinner","write","addGenerateScript","generateScript","formatMs","getElapsedMs","defineWithTypes","dryRunId"],"sources":["../../../internals/shared/src/init.ts","../src/runners/init/run.ts"],"sourcesContent":["/** The `kubb.config.ts` `kubb init` writes before `kubb add` puts each plugin in. */\nexport function generateConfigFile({ inputPath, outputPath }: { inputPath: string; outputPath: string }): string {\n return `import { defineConfig } from 'kubb/config'\n\nexport default defineConfig({\n input: '${inputPath}',\n output: {\n path: '${outputPath}',\n clean: true,\n },\n plugins: [],\n})\n`\n}\n","import path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport type { DryRunExtension } from '@gunshi/plugin-dryrun'\nimport { defineWithTypes } from 'gunshi'\nimport { resolveCommand } from 'package-manager-detector'\nimport { ConfigEditOperation, editConfig, generateConfigFile, initDefaults, KUBB_CONFIG_FILENAME, KUBB_PACKAGE_NAME } from '@internals/shared'\nimport { exists, formatMs, getElapsedMs, write } from '@internals/utils'\nimport { createKubb, Diagnostics, type RegistryEntry } from '@kubb/core'\nimport { dryRunId, type DryRunExtensions } from '../../commands/shared.ts'\nimport { getConfigs } from '../../config.ts'\nimport { isHttpUrl, pluralize } from '../../ui/text.ts'\nimport { isInteractiveRun, logIntro, logOutro } from '../../ui/intro.ts'\nimport { logBlock, logError, logStep, logWarn } from '../../ui/log.ts'\nimport { withSpinner } from '../../ui/spinner.ts'\nimport { fetchRegistryIndex, incompatibility, installSpec, registryUrl } from '../../utils/registry.ts'\nimport { installWithSpinner } from '../installWithSpinner.ts'\nimport {\n addGenerateScript,\n detectPackageManager,\n findPlugin,\n findSpecFiles,\n generateScript,\n initPackageJson,\n installPackages,\n missingPluginDependencies,\n type PackageManagerInfo,\n parsePluginsFlag,\n readSpecInfo,\n} from './utils.ts'\nimport { version } from '../../../package.json'\n\nfunction cancelAndExit(message = 'Operation canceled.'): never {\n clack.cancel(message)\n process.exit(0)\n}\n\nfunction unwrap<T>(value: T): Exclude<T, symbol> {\n if (clack.isCancel(value)) cancelAndExit()\n return value as Exclude<T, symbol>\n}\n\ntype InitOptions = {\n /**\n * When `true`, skips all interactive prompts and uses the detected or default values.\n */\n yes: boolean\n /**\n * Input path flag value from `--input`. When provided, skips the input prompt.\n */\n input?: string\n /**\n * Output directory flag value from `--output`. When provided, skips the output prompt.\n */\n output?: string\n /**\n * Comma-separated plugin list from `--plugins`, e.g. `'plugin-ts,zod'`. When provided, skips the plugin selection prompt.\n */\n plugins?: string\n /**\n * Dry-run extension from `@gunshi/plugin-dryrun`. When enabled, package installation, file\n * writes, and the first run are skipped.\n */\n dryRun: DryRunExtension\n}\n\ntype Choices = {\n inputPath: string\n outputPath: string\n plugins: Array<RegistryEntry>\n}\n\n/** The full `kubb.config.ts` for `choices`, with each plugin added the way `kubb add` adds it. */\nfunction buildConfig({ inputPath, outputPath, plugins }: Choices): string {\n const { source, outcomes } = editConfig({\n source: generateConfigFile({ inputPath, outputPath }),\n edits: plugins.map((entry) => ({ operation: ConfigEditOperation.ADD_PLUGIN, plugin: entry.artifact.package })),\n extensions: new Map(plugins.map(({ artifact, manifest }) => [artifact.package, { package: artifact.package, version: artifact.version, manifest }])),\n })\n const failed = outcomes.find((outcome) => !outcome.applied)\n if (failed && failed.edit.operation === ConfigEditOperation.ADD_PLUGIN)\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: `Could not add ${failed.edit.plugin} to ${KUBB_CONFIG_FILENAME}: ${failed.reason}`,\n help: `Run kubb init without that plugin, then add it with kubb add.`,\n })\n return source\n}\n\n/** Generates from the config at `configPath` without reporters, and returns how many files it wrote. */\nasync function firstRun(configPath: string): Promise<number> {\n const { configs } = await getConfigs({ configPath })\n let files = 0\n for (const config of configs) {\n const result = await createKubb(config).generate()\n if (!result.success) throw new Error(result.diagnostics.flatMap((diagnostic) => (diagnostic.severity === 'error' ? [diagnostic.message] : [])).join('\\n'))\n files += result.files.length\n }\n return files\n}\n\n/** The command that runs `kubb generate`: the `generate` script when it runs Kubb, otherwise `npx kubb generate`. */\nfunction generateCommand({ packageManager, script, watch }: { packageManager: PackageManagerInfo; script: string | undefined; watch: boolean }): string {\n if (script !== 'kubb generate') return `npx kubb generate${watch ? ' --watch' : ''}`\n const { command, args } = resolveCommand(packageManager.agent, 'run', watch ? ['generate', '--watch'] : ['generate'])!\n return [command, ...args].join(' ')\n}\n\n/**\n * Runs the Kubb setup wizard: detects the package manager and specs, asks for the spec, plugins, and\n * output folder, shows the config for review, then installs, writes `kubb.config.ts`, adds a\n * `generate` script, and runs the first generation.\n * Pass `yes: true` to skip all prompts and print one line per step.\n */\nexport async function run({ yes, input: inputFlag, output: outputFlag, plugins: pluginsFlag, dryRun }: InitOptions): Promise<void> {\n const cwd = process.cwd()\n\n if (!yes) logIntro({ title: isInteractiveRun({ yes, dryRun: dryRun.enabled }) ? undefined : 'Set up Kubb' })\n\n try {\n // Start the registry fetch now but await it only at the plugin step, so the first prompt never waits on the network\n const registry = fetchRegistryIndex({ registry: registryUrl() }).then((entries) =>\n entries.filter((entry) => entry.kind === 'plugin' && !incompatibility(entry.manifest)),\n )\n registry.catch(() => {})\n\n if (!(await exists(path.join(cwd, 'package.json')))) {\n if (!yes) {\n const shouldInit = unwrap(await clack.confirm({ message: 'No package.json found. Would you like to create one?', initialValue: true }))\n if (!shouldInit) cancelAndExit()\n }\n\n const packageManager = await detectPackageManager(cwd)\n await withSpinner({\n message: `Initializing package.json with ${packageManager.name}`,\n promise: initPackageJson(cwd, packageManager),\n done: () => `Created package.json with ${packageManager.name}`,\n failed: 'Could not create package.json',\n plain: yes,\n })\n }\n\n const packageManager = await detectPackageManager(cwd)\n const specs = await findSpecFiles(cwd)\n\n if (!yes) {\n logStep(`Package manager ${packageManager.name}`)\n if (specs[0]) {\n const { version: specVersion, operations } = await readSpecInfo(path.join(cwd, specs[0]))\n const details = [\n specs[0].slice(2),\n specVersion ? `${specVersion.startsWith('2') ? 'Swagger' : 'OpenAPI'} ${specVersion}` : undefined,\n operations === undefined ? undefined : pluralize(operations, 'operation'),\n specs.length > 1 ? `+${specs.length - 1} more` : undefined,\n ]\n logStep(`Found ${details.filter(Boolean).join(' · ')}`)\n }\n }\n\n // `--plugins` and `--yes` need the registry before any prompt; the interactive path reads it at the plugin step\n const plugins = pluginsFlag || yes ? await registry : undefined\n const defaultPlugins = (entries: Array<RegistryEntry>) => initDefaults.plugins.flatMap((id) => findPlugin({ plugins: entries, id }) ?? [])\n\n const flagPlugins = pluginsFlag && plugins ? parsePluginsFlag({ plugins, value: pluginsFlag }) : undefined\n\n let choices: Choices = {\n inputPath: inputFlag ?? specs[0] ?? initDefaults.inputPath,\n outputPath: outputFlag ?? initDefaults.outputPath,\n plugins: flagPlugins ?? (plugins ? defaultPlugins(plugins) : []),\n }\n if (yes && !choices.plugins.length) {\n throw new Error('The registry has no default plugin. Pass --plugins to choose one.')\n }\n\n async function askInput(current: string): Promise<string> {\n const choice = specs.length\n ? unwrap(\n await clack.select({\n message: 'Which spec should Kubb read?',\n options: [\n ...specs.map((spec) => ({ value: spec, label: spec, hint: 'found in this repo' })),\n { value: 'url', label: 'A URL' },\n { value: 'file', label: 'Another file' },\n ],\n initialValue: specs.includes(current) ? current : isHttpUrl(current) ? 'url' : 'file',\n }),\n )\n : isHttpUrl(current)\n ? 'url'\n : 'file'\n if (specs.includes(choice)) return choice\n const isUrl = choice === 'url'\n const initial = isUrl === isHttpUrl(current) && !specs.includes(current) ? current : undefined\n return unwrap(\n await clack.text({\n message: isUrl ? 'Spec URL' : 'Spec path',\n placeholder: isUrl ? 'https://example.com/openapi.yaml' : initDefaults.inputPath,\n initialValue: initial,\n defaultValue: isUrl ? undefined : initDefaults.inputPath,\n validate: (value) => {\n if (isUrl && !isHttpUrl(value ?? '')) return 'Enter an http(s) URL'\n },\n }),\n )\n }\n\n async function askPlugins(previous: Array<RegistryEntry>): Promise<Array<RegistryEntry>> {\n const plugins = await registry\n const current = previous.length ? previous : defaultPlugins(plugins)\n const width = Math.max(...plugins.map((entry) => entry.manifest.displayName.length))\n const nameWidth = Math.max(...plugins.map((entry) => entry.manifest.name.length))\n const values = unwrap(\n await clack.multiselect({\n message: 'What should Kubb generate?',\n options: plugins.map(({ id, manifest }) => ({\n value: id,\n label: `${manifest.displayName.padEnd(width)} ${styleText('dim', manifest.name.padEnd(nameWidth))}`.trimEnd(),\n })),\n initialValues: current.map((entry) => entry.id),\n required: true,\n }),\n )\n return plugins.filter((entry) => values.includes(entry.id))\n }\n\n // Flags for all three choices leave nothing to ask or review, as before the review step existed\n const answered = yes || Boolean(inputFlag && outputFlag && pluginsFlag)\n if (!answered) {\n let firstPass = true\n while (true) {\n // The first pass skips the questions a flag answered; \"Change a choice\" asks them all again.\n choices = {\n inputPath: firstPass && inputFlag ? inputFlag : await askInput(choices.inputPath),\n plugins: firstPass && flagPlugins ? flagPlugins : await askPlugins(choices.plugins),\n outputPath:\n firstPass && outputFlag\n ? outputFlag\n : unwrap(await clack.text({ message: 'Output folder', placeholder: choices.outputPath, defaultValue: choices.outputPath })),\n }\n firstPass = false\n const missing = missingPluginDependencies(choices.plugins.map((entry) => entry.manifest))\n if (missing.length) {\n logWarn(`${missing.join('\\n')}\\nAdd the missing plugins.`)\n continue\n }\n const config = buildConfig(choices)\n const packages = [KUBB_PACKAGE_NAME, ...choices.plugins.map((entry) => entry.artifact.package)]\n logStep(`Review ${KUBB_CONFIG_FILENAME}`)\n logBlock([...config.trimEnd().split('\\n'), '', `${styleText('dim', 'Installs')} ${packages.join(' ')} with ${packageManager.name}`])\n const configExists = await exists(path.join(cwd, KUBB_CONFIG_FILENAME))\n const confirmed = unwrap(\n await clack.select({\n message: configExists ? `${KUBB_CONFIG_FILENAME} exists. Overwrite it?` : 'Create it?',\n options: [\n { value: true, label: 'Yes' },\n { value: false, label: 'Change a choice' },\n ],\n }),\n )\n if (confirmed) break\n }\n }\n\n // Check the selection against the plugins' manifests before installing anything\n const missing = missingPluginDependencies(choices.plugins.map((entry) => entry.manifest))\n if (missing.length) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.missingDependency,\n severity: 'error',\n message: `${missing.join('\\n')}\\nAdd the missing plugins and run kubb init again.`,\n })\n }\n\n const configPath = path.join(cwd, KUBB_CONFIG_FILENAME)\n if (answered && !yes && (await exists(configPath))) {\n const overwrite = unwrap(await clack.confirm({ message: `${KUBB_CONFIG_FILENAME} exists. Overwrite it?`, initialValue: false }))\n if (!overwrite) cancelAndExit('Keeping existing configuration.')\n }\n\n // Install `kubb` at the running CLI's version and each plugin at the version the registry pins\n const packagesToInstall = [`${KUBB_PACKAGE_NAME}@${version}`, ...choices.plugins.map((entry) => installSpec(entry.artifact))]\n const packageNames = [KUBB_PACKAGE_NAME, ...choices.plugins.map((entry) => entry.artifact.package)]\n const dry = { message: `install ${packagesToInstall.length} packages with ${packageManager.name}` }\n if (yes) {\n await withSpinner({\n message: '',\n promise: dryRun.run(() => installPackages(packagesToInstall, packageManager, cwd), dry),\n done: () => `Installed ${packageNames.join(' ')} with ${packageManager.name}`,\n plain: true,\n })\n } else {\n await installWithSpinner({\n packages: packagesToInstall,\n names: `${packagesToInstall.length} packages`,\n packageManager,\n cwd,\n install: async (packages, packageManager, cwd, onLine) => void (await dryRun.run(() => installPackages(packages, packageManager, cwd, onLine), dry)),\n })\n }\n\n await withSpinner({\n message: `Writing ${KUBB_CONFIG_FILENAME}`,\n promise: dryRun.run(async () => void (await write(configPath, buildConfig(choices))), { message: `write ${KUBB_CONFIG_FILENAME}` }),\n done: () => `Wrote ${KUBB_CONFIG_FILENAME}`,\n failed: `Could not write ${KUBB_CONFIG_FILENAME}`,\n plain: yes,\n })\n\n const scriptAdded = await dryRun.run(() => addGenerateScript(cwd), {\n message: 'add a generate script to package.json',\n resolve: async () => (await generateScript(cwd)) === undefined,\n })\n if (scriptAdded && !yes) logStep('Added \"generate\": \"kubb generate\" to package.json')\n\n const script = scriptAdded ? 'kubb generate' : await generateScript(cwd)\n const runStart = process.hrtime()\n try {\n await dryRun.run(\n () =>\n withSpinner({\n message: 'Running the first generation',\n promise: firstRun(configPath),\n done: (files) =>\n yes\n ? `Generated ${pluralize(files, 'file')} in ${choices.outputPath}`\n : `First run ${pluralize(files, 'file')} in ${choices.outputPath} · ${formatMs(getElapsedMs(runStart))}`,\n failed: 'First run failed',\n plain: yes,\n }),\n { message: 'run the first generation', resolve: () => 0 },\n )\n } catch (error) {\n logError(error instanceof Error ? error.message : String(error))\n const message = `Kubb is set up, but the first run failed. Fix the error, then run ${generateCommand({ packageManager, script, watch: false })}.`\n if (yes) console.log(message)\n else logOutro(styleText('yellow', message))\n process.exitCode = 1\n return\n }\n\n if (yes) {\n console.log(`Kubb is set up. Run ${generateCommand({ packageManager, script, watch: false })} after changing the spec.`)\n return\n }\n logOutro(`${styleText('green', '✓ Kubb is set up')}\\n ${styleText('dim', 'Next')} ${generateCommand({ packageManager, script, watch: true })}`)\n } catch (error) {\n logError(styleText('red', 'An error occurred during initialization'))\n if (error instanceof Error) {\n logError(error.message)\n }\n process.exit(1)\n }\n}\n\nexport const command = defineWithTypes<{ extensions: DryRunExtensions }>()({\n name: 'init',\n description: 'Set up a config, install plugins, and run the first generation.',\n examples: [\n 'kubb init',\n 'kubb init --yes',\n 'kubb init --input ./openapi.yaml --output ./src/gen --plugins plugin-ts,plugin-zod',\n 'kubb init --yes --input ./openapi.yaml --plugins ts,zod --output src/api',\n 'kubb init --plugins plugin-ts,plugin-axios,plugin-react-query',\n 'kubb init --yes --dry-run',\n ].join('\\n'),\n toKebab: true,\n args: {\n yes: {\n type: 'boolean',\n description: 'Skip prompts and use the detected spec, the default plugin, and the default output folder',\n short: 'y',\n default: false,\n },\n input: {\n type: 'string',\n description: 'Path to the OpenAPI specification',\n short: 'i',\n metavar: 'path',\n },\n output: {\n type: 'string',\n description: 'Output directory for generated files',\n short: 'o',\n metavar: 'path',\n },\n plugins: {\n type: 'string',\n description:\n 'Comma-separated Kubb registry ids of the plugins to add, the same ids `kubb add` takes (plugin-ts, plugin-zod, acme/plugin-x), or short names (ts, zod)',\n metavar: 'plugin-ts,plugin-zod,...',\n },\n },\n run: ({ values, extensions }) => run({ yes: values.yes, input: values.input, output: values.output, plugins: values.plugins, dryRun: extensions[dryRunId] }),\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAAgB,mBAAmB,EAAE,WAAW,cAAiE;CAC/G,OAAO;;;YAGG,UAAU;;aAET,WAAW;;;;;;AAMxB;;ACoBA,SAAS,cAAc,UAAU,uBAA8B;CAC7D,eAAM,OAAO,OAAO;CACpB,aAAA,QAAQ,KAAK,CAAC;AAChB;AAEA,SAAS,OAAU,OAA8B;CAC/C,IAAIA,eAAM,SAAS,KAAK,GAAG,cAAc;CACzC,OAAO;AACT;;AAiCA,SAAS,YAAY,EAAE,WAAW,YAAY,WAA4B;CACxE,MAAM,EAAE,QAAQ,aAAaC,mBAAAA,WAAW;EACtC,QAAQ,mBAAmB;GAAE;GAAW;EAAW,CAAC;EACpD,OAAO,QAAQ,KAAK,WAAW;GAAE,WAAWC,mBAAAA,oBAAoB;GAAY,QAAQ,MAAM,SAAS;EAAQ,EAAE;EAC7G,YAAY,IAAI,IAAI,QAAQ,KAAK,EAAE,UAAU,eAAe,CAAC,SAAS,SAAS;GAAE,SAAS,SAAS;GAAS,SAAS,SAAS;GAAS;EAAS,CAAC,CAAC,CAAC;CACrJ,CAAC;CACD,MAAM,SAAS,SAAS,MAAM,YAAY,CAAC,QAAQ,OAAO;CAC1D,IAAI,UAAU,OAAO,KAAK,cAAcA,mBAAAA,oBAAoB,YAC1D,MAAM,IAAIC,WAAAA,YAAY,MAAM;EAC1B,MAAMA,WAAAA,YAAY,KAAK;EACvB,UAAU;EACV,SAAS,iBAAiB,OAAO,KAAK,OAAO,MAAMC,eAAAA,qBAAqB,IAAI,OAAO;EACnF,MAAM;CACR,CAAC;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AQ;GACN,MAAM;GACN,aAAa;GACb,OAAO;GACP,SAAS;EACX;EACA,SAAS;GACP,MAAM;GACN,aACE;GACF,SAAS;EACX;CACF;CACA,MAAM,EAAE,QAAQ,iBAAiB,IAAI;EAAE,KAAK,OAAO;EAAK,OAAO,OAAO;EAAO,QAAQ,OAAO;EAAQ,SAAS,OAAO;EAAS,QAAQ,WAAWC,sBAAAA;CAAU,CAAC;AAC7J,CAAC"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-C3-Zg-KD.cjs");
|
|
2
|
-
const
|
|
2
|
+
const require_utils = require("./utils-uSJAZuvP.cjs");
|
|
3
3
|
const require_errors = require("./errors-BponpdjN.cjs");
|
|
4
|
-
const require_spinner = require("./spinner-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
const require_spinner = require("./spinner-RfMb7fd6.cjs");
|
|
5
|
+
const require_log = require("./log-wv1OxLiq.cjs");
|
|
6
|
+
const require_intro = require("./intro-DuyzJ3Rb.cjs");
|
|
7
|
+
const require_shared = require("./shared-KKRMm1xX.cjs");
|
|
7
8
|
const require_config = require("./config-CRrmj88c.cjs");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const require_configFile = require("./configFile-CVfWdtKh.cjs");
|
|
10
|
+
const require_summary = require("./summary-B2Apv5KO.cjs");
|
|
11
|
+
const require_registry = require("./registry-Q77p5TZp.cjs");
|
|
11
12
|
let node_util = require("node:util");
|
|
12
13
|
let gunshi = require("gunshi");
|
|
13
14
|
let node_process = require("node:process");
|
|
@@ -35,13 +36,7 @@ function removedLines({ before, after }) {
|
|
|
35
36
|
async function run({ id: input, configPath, yes, uninstall }) {
|
|
36
37
|
const cwd = node_process.default.cwd();
|
|
37
38
|
const hrStart = node_process.default.hrtime();
|
|
38
|
-
const summary =
|
|
39
|
-
title,
|
|
40
|
-
status,
|
|
41
|
-
hrStart,
|
|
42
|
-
block: true,
|
|
43
|
-
lines
|
|
44
|
-
});
|
|
39
|
+
const summary = require_summary.createSummary(hrStart);
|
|
45
40
|
const fail = (title, lines) => {
|
|
46
41
|
summary(title, "failed", lines);
|
|
47
42
|
node_process.default.exitCode = 1;
|
|
@@ -75,7 +70,7 @@ async function run({ id: input, configPath, yes, uninstall }) {
|
|
|
75
70
|
return fail(`No extension named ${input}`, suggestions.map((suggestion) => ` kubb remove ${suggestion}`));
|
|
76
71
|
}
|
|
77
72
|
const { artifact, manifest } = entry;
|
|
78
|
-
const kind =
|
|
73
|
+
const kind = require_utils.pascalCase(manifest.kind);
|
|
79
74
|
if (manifest.kind === require_configFile.extensionKinds.adapter) return fail("The adapter cannot be removed", [` A config needs one adapter. Change it in ${configName} by hand.`]);
|
|
80
75
|
const view = require_configFile.readConfig(source);
|
|
81
76
|
const running = new Set(view.managed ? view.configs.flatMap((config) => [...config.plugins, ...config.parsers ?? []].filter((call) => !call.disabled).map((call) => call.packageName)) : []);
|
|
@@ -108,8 +103,8 @@ async function run({ id: input, configPath, yes, uninstall }) {
|
|
|
108
103
|
if (stillImported) return `Keeps ${artifact.package}, which another config entry still imports`;
|
|
109
104
|
return "Uninstalls nothing";
|
|
110
105
|
})();
|
|
111
|
-
|
|
112
|
-
|
|
106
|
+
require_log.logStep(`${kind} ${(0, node_util.styleText)("cyan", manifest.name)} v${versions.get(artifact.package) ?? artifact.version}`);
|
|
107
|
+
require_log.logBlock([
|
|
113
108
|
`Config ${configName}`,
|
|
114
109
|
...removedLines({
|
|
115
110
|
before: source,
|
|
@@ -131,9 +126,9 @@ async function run({ id: input, configPath, yes, uninstall }) {
|
|
|
131
126
|
edits
|
|
132
127
|
});
|
|
133
128
|
if (!written.outcomes[0]?.applied) return fail(`Could not edit ${configName}`, [` ${written.outcomes[0]?.reason ?? "the config file was not changed"}`]);
|
|
134
|
-
|
|
129
|
+
require_log.logStep(`${manifest.export}() removed from ${configName}`);
|
|
135
130
|
}
|
|
136
|
-
const packageManager = require_utils.detectPackageManager(cwd);
|
|
131
|
+
const packageManager = await require_utils.detectPackageManager(cwd);
|
|
137
132
|
if (uninstalls) await require_spinner.withSpinner({
|
|
138
133
|
message: `Uninstalling ${artifact.package} with ${packageManager.name}`,
|
|
139
134
|
promise: require_utils.uninstallPackages([artifact.package], packageManager, cwd)
|
|
@@ -144,7 +139,7 @@ async function run({ id: input, configPath, yes, uninstall }) {
|
|
|
144
139
|
"Next kubb generate"
|
|
145
140
|
]);
|
|
146
141
|
} catch (error) {
|
|
147
|
-
|
|
142
|
+
require_log.logError(require_errors.getErrorMessage(error));
|
|
148
143
|
fail("Remove failed", [" See the error above"]);
|
|
149
144
|
}
|
|
150
145
|
}
|
|
@@ -182,4 +177,4 @@ const command = (0, gunshi.define)({
|
|
|
182
177
|
exports.command = command;
|
|
183
178
|
exports.run = run;
|
|
184
179
|
|
|
185
|
-
//# sourceMappingURL=run-
|
|
180
|
+
//# sourceMappingURL=run-DT4hTOR2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-DT4hTOR2.cjs","names":["process","createSummary","isInteractiveRun","styleText","toRegistryId","path","findConfigFile","Diagnostics","withSpinner","fetchRegistryIndex","registryUrl","readInstalledPackages","read","closestIds","toShortId","pascalCase","extensionKinds","readConfig","ConfigEditOperation","editConfig","BUNDLED_PACKAGES","readImports","clack","editConfigFile","detectPackageManager","uninstallPackages","getErrorMessage","define","configArg","yesArg"],"sources":["../src/runners/remove/run.ts"],"sourcesContent":["import path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { define } from 'gunshi'\nimport { BUNDLED_PACKAGES, ConfigEditOperation, extensionKinds, editConfig, editConfigFile, findConfigFile, readConfig, readImports } from '@internals/shared'\nimport { getErrorMessage, pascalCase, read } from '@internals/utils'\nimport { Diagnostics, readInstalledPackages } from '@kubb/core'\nimport { configArg, yesArg } from '../../commands/shared.ts'\nimport { isInteractiveRun, logIntro } from '../../ui/intro.ts'\nimport { logBlock, logError, logStep } from '../../ui/log.ts'\nimport { withSpinner } from '../../ui/spinner.ts'\nimport { createSummary } from '../../ui/summary.ts'\nimport { closestIds, fetchRegistryIndex, registryUrl, toRegistryId, toShortId } from '../../utils/registry.ts'\nimport { detectPackageManager, uninstallPackages } from '../init/utils.ts'\n\nexport type RemoveOptions = {\n /**\n * `owner/slug`, or a bare `slug` for an official extension.\n */\n id: string\n configPath?: string\n yes: boolean\n uninstall: boolean\n}\n\n/** The lines of `before` that `after` no longer has, trimmed. */\nfunction removedLines({ before, after }: { before: string; after: string }): Array<string> {\n const remaining = after.split('\\n')\n return before\n .split('\\n')\n .filter((line) => {\n const index = remaining.indexOf(line)\n if (index !== -1) remaining.splice(index, 1)\n return index === -1 && line.trim() !== ''\n })\n .map((line) => line.trim())\n}\n\n/**\n * Removes a plugin or parser from `kubb.config.ts` and uninstalls its package. Refuses the adapter,\n * which the config needs, and an extension another one in the config depends on. Previews the\n * change before asking.\n */\nexport async function run({ id: input, configPath, yes, uninstall }: RemoveOptions): Promise<void> {\n const cwd = process.cwd()\n const hrStart = process.hrtime()\n const summary = createSummary(hrStart)\n const fail = (title: string, lines: ReadonlyArray<string>) => {\n summary(title, 'failed', lines)\n process.exitCode = 1\n }\n logIntro({ title: isInteractiveRun({ yes }) ? undefined : styleText('bgCyan', styleText('black', ' Kubb Remove ')) })\n\n try {\n const id = toRegistryId(input)\n const configFile = configPath ? path.resolve(configPath) : findConfigFile(cwd)\n if (!configFile)\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: 'No kubb.config.ts found. Pass its path with --config.',\n help: 'Run `kubb remove <id> --config <path>`.',\n })\n const configName = path.relative(cwd, configFile) || configFile\n const [entries, installed, source] = await withSpinner({\n message: 'Reading the registry',\n promise: Promise.all([fetchRegistryIndex({ registry: registryUrl() }), readInstalledPackages({ root: cwd }), read(configFile)]),\n })\n const versions = new Map(installed.map((item) => [item.package, item.version]))\n\n const entry = entries.find((candidate) => candidate.id === id)\n if (!entry) {\n const suggestions = closestIds({ input: id, ids: entries.map((candidate) => candidate.id) }).map(toShortId)\n return fail(\n `No extension named ${input}`,\n suggestions.map((suggestion) => ` kubb remove ${suggestion}`),\n )\n }\n const { artifact, manifest } = entry\n const kind = pascalCase(manifest.kind)\n if (manifest.kind === extensionKinds.adapter)\n return fail('The adapter cannot be removed', [` A config needs one adapter. Change it in ${configName} by hand.`])\n\n // Only calls that run count: a plugin Studio switched off is a comment, as in Studio's own check.\n const view = readConfig(source)\n const running = new Set(\n view.managed\n ? view.configs.flatMap((config) => [...config.plugins, ...(config.parsers ?? [])].filter((call) => !call.disabled).map((call) => call.packageName))\n : [],\n )\n const dependents = entries.filter(\n (other) => other.id !== entry.id && other.manifest.dependencies?.includes(manifest.name) && running.has(other.artifact.package),\n )\n if (dependents.length) {\n const names = dependents.map((other) => other.manifest.name).join(', ')\n return fail(`${names} ${dependents.length === 1 ? 'needs' : 'need'} ${manifest.name}`, [` Remove ${names} first.`])\n }\n\n const edits = [\n {\n operation: ConfigEditOperation.REMOVE_EXTENSION,\n ...(manifest.kind === extensionKinds.parser ? { kind: extensionKinds.parser } : {}),\n plugin: artifact.package,\n },\n ]\n const preview = editConfig({ source, edits })\n const outcome = preview.outcomes[0]\n if (!outcome?.applied) return fail(`Could not edit ${configName}`, [` ${outcome?.reason ?? 'the config file was not changed'}`])\n\n // Bundled extensions leave the config but stay installed.\n const bundled = BUNDLED_PACKAGES.includes(artifact.package)\n // Another `defineConfig` entry can still import it, and uninstalling it then breaks the config.\n const stillImported = readImports(preview.source).includes(artifact.package)\n const uninstalls = uninstall && !bundled && !stillImported && versions.has(artifact.package)\n if (!preview.changed && !uninstalls) {\n summary(`${manifest.name} is not in the project`, 'success', [' No changes made'])\n return\n }\n\n const packageLine = (() => {\n if (uninstalls) return `Uninstalls ${artifact.package}`\n if (bundled) return `Keeps ${artifact.package}, which ships with kubb`\n if (stillImported) return `Keeps ${artifact.package}, which another config entry still imports`\n return 'Uninstalls nothing'\n })()\n logStep(`${kind} ${styleText('cyan', manifest.name)} v${versions.get(artifact.package) ?? artifact.version}`)\n logBlock([\n `Config ${configName}`,\n ...removedLines({ before: source, after: preview.source }).map((line) => styleText('red', ` - ${line}`)),\n packageLine,\n ])\n\n const confirmed = yes || (await clack.confirm({ message: 'Remove it?', initialValue: true }))\n if (clack.isCancel(confirmed) || !confirmed) {\n summary('Remove canceled', 'canceled', [` ${kind} ${manifest.name}`, ' No changes made'])\n return\n }\n\n if (preview.changed) {\n const written = await editConfigFile({ filePath: configFile, edits })\n if (!written.outcomes[0]?.applied) return fail(`Could not edit ${configName}`, [` ${written.outcomes[0]?.reason ?? 'the config file was not changed'}`])\n logStep(`${manifest.export}() removed from ${configName}`)\n }\n const packageManager = await detectPackageManager(cwd)\n if (uninstalls)\n await withSpinner({\n message: `Uninstalling ${artifact.package} with ${packageManager.name}`,\n promise: uninstallPackages([artifact.package], packageManager, cwd),\n })\n\n summary(`${kind} removed`, 'success', [\n ` Packages ${uninstalls ? `${artifact.package} uninstalled with ${packageManager.name}` : 'none uninstalled'}`,\n '',\n 'Next kubb generate',\n ])\n } catch (error) {\n logError(getErrorMessage(error))\n fail('Remove failed', [' See the error above'])\n }\n}\n\nexport const command = define({\n name: 'remove',\n description: 'Remove a plugin or parser from kubb.config.ts and uninstall its package.',\n examples: ['kubb remove plugin-zod', 'kubb remove acme/plugin-x --yes', 'kubb remove plugin-zod --no-uninstall'].join('\\n'),\n toKebab: true,\n args: {\n id: {\n type: 'positional',\n description: 'Registry id: owner/slug, or a slug for an official extension',\n required: true,\n },\n ...configArg,\n ...yesArg,\n uninstall: {\n type: 'boolean',\n description: 'Uninstall the package. Pass --no-uninstall to only edit the config',\n negatable: true,\n default: true,\n },\n },\n run: ({ values }) => run({ id: values.id, configPath: values.config, yes: values.yes, uninstall: values.uninstall }),\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,aAAa,EAAE,QAAQ,SAA2D;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