From c10b654351d9c8c2181da10c1319c244922024fe Mon Sep 17 00:00:00 2001 From: Brandon Ting Date: Sat, 25 Jan 2025 10:59:06 +0800 Subject: [PATCH 1/6] chore: upgrade package-manager-detector to 0.2.8 and adopt resolveCommand --- packages/cli/package.json | 2 +- packages/cli/src/commands/add.ts | 33 ++++++++++++++++----------- packages/cli/src/commands/init.ts | 33 ++++++++++++++++----------- packages/cli/src/commands/update.ts | 33 ++++++++++++++++----------- packages/cli/src/utils/auto-detect.ts | 14 +++++++----- packages/cli/src/utils/sveltekit.ts | 23 +++++++++++-------- 6 files changed, 83 insertions(+), 55 deletions(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index cf5983589..0117a7c37 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -52,7 +52,7 @@ "cross-env": "^7.0.3", "get-tsconfig": "^4.7.3", "ignore": "^5.3.1", - "package-manager-detector": "^0.1.2", + "package-manager-detector": "^0.2.8", "sisteransi": "^1.0.5", "tsup": "^8.0.0", "type-fest": "^3.13.1", diff --git a/packages/cli/src/commands/add.ts b/packages/cli/src/commands/add.ts index 0c4a5afb7..c6a85691d 100644 --- a/packages/cli/src/commands/add.ts +++ b/packages/cli/src/commands/add.ts @@ -5,6 +5,7 @@ import color from "chalk"; import { Command } from "commander"; import { execa } from "execa"; import * as v from "valibot"; +import { resolveCommand } from "package-manager-detector"; import { type Config, getConfig } from "../utils/get-config.js"; import { getEnvProxy } from "../utils/get-env-proxy.js"; import { ConfigError, error, handleError } from "../utils/errors.js"; @@ -244,19 +245,25 @@ async function runAdd(cwd: string, config: Config, options: AddOptions) { } // Install dependencies. - const commands = await detectPM(cwd, options.deps); - if (commands) { - const [pm, add] = commands.add.split(" ") as [string, string]; - tasks.push({ - title: `${highlight(pm)}: Installing dependencies`, - enabled: dependencies.size > 0, - async task() { - await execa(pm, [add, "-D", ...dependencies], { - cwd, - }); - return `Dependencies installed with ${highlight(pm)}`; - }, - }); + const pm = await detectPM(cwd, options.deps); + if (pm) { + const add = resolveCommand(pm, "add", ["-D", ...dependencies]); + if(add) { + tasks.push({ + title: `${highlight(pm)}: Installing dependencies`, + enabled: dependencies.size > 0, + async task() { + await execa(add.command, add.args, { + cwd, + }); + return `Dependencies installed with ${highlight(pm)}`; + }, + }); + } else { + p.log.warn( + `Could not detect a package manager in ${cwd}.` + ); + } } await p.tasks(tasks); diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index 04690b774..43abdf4ef 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -5,6 +5,7 @@ import color from "chalk"; import * as v from "valibot"; import { Command, Option } from "commander"; import { execa } from "execa"; +import { resolveCommand } from "package-manager-detector"; import * as cliConfig from "../utils/get-config.js"; import type { Config } from "../utils/get-config.js"; import { error, handleError } from "../utils/errors.js"; @@ -363,19 +364,25 @@ export async function runInit(cwd: string, config: Config, options: InitOptions) }); // Install dependencies. - const commands = await detectPM(cwd, options.deps); - if (commands) { - const [pm, add] = commands.add.split(" ") as [string, string]; - tasks.push({ - title: `${highlight(pm)}: Installing dependencies`, - enabled: options.deps, - async task() { - await execa(pm, [add, "-D", ...PROJECT_DEPENDENCIES], { - cwd, - }); - return `Dependencies installed with ${highlight(pm)}`; - }, - }); + const pm = await detectPM(cwd, options.deps); + if (pm) { + const add = resolveCommand(pm, "add", ["-D", ...PROJECT_DEPENDENCIES]); + if(add) { + tasks.push({ + title: `${highlight(pm)}: Installing dependencies`, + enabled: options.deps, + async task() { + await execa(add.command, add.args, { + cwd, + }); + return `Dependencies installed with ${highlight(pm)}`; + }, + }); + } else { + p.log.warn( + `Could not detect a package manager in ${cwd}.` + ); + } } await p.tasks(tasks); diff --git a/packages/cli/src/commands/update.ts b/packages/cli/src/commands/update.ts index d9c728ba8..eb2309b07 100644 --- a/packages/cli/src/commands/update.ts +++ b/packages/cli/src/commands/update.ts @@ -5,6 +5,7 @@ import color from "chalk"; import { Command } from "commander"; import { execa } from "execa"; import * as v from "valibot"; +import { resolveCommand } from "package-manager-detector"; import { type Config, getConfig } from "../utils/get-config.js"; import { error, handleError } from "../utils/errors.js"; import { fetchTree, getItemTargetPath, getRegistryIndex, resolveTree } from "../utils/registry"; @@ -225,19 +226,25 @@ async function runUpdate(cwd: string, config: Config, options: UpdateOptions) { } // Install dependencies. - const commands = await detectPM(cwd, true); - if (commands) { - const [pm, add] = commands.add.split(" ") as [string, string]; - tasks.push({ - title: `${highlight(pm)}: Installing dependencies`, - enabled: dependencies.size > 0, - async task() { - await execa(pm, [add, "-D", ...dependencies], { - cwd, - }); - return `Dependencies installed with ${highlight(pm)}`; - }, - }); + const pm = await detectPM(cwd, true); + if (pm) { + const add = resolveCommand(pm, "add", ["-D", ...dependencies]); + if(add) { + tasks.push({ + title: `${highlight(pm)}: Installing dependencies`, + enabled: dependencies.size > 0, + async task() { + await execa(add.command, add.args, { + cwd, + }); + return `Dependencies installed with ${highlight(pm)}`; + }, + }); + } else { + p.log.warn( + `Could not detect a package manager in ${cwd}.` + ); + } } await p.tasks(tasks); diff --git a/packages/cli/src/utils/auto-detect.ts b/packages/cli/src/utils/auto-detect.ts index 997475c84..96322b9e2 100644 --- a/packages/cli/src/utils/auto-detect.ts +++ b/packages/cli/src/utils/auto-detect.ts @@ -2,8 +2,8 @@ import fs from "node:fs"; import path from "node:path"; import ignore, { type Ignore } from "ignore"; import { type TsConfigResult, getTsconfig } from "get-tsconfig"; -import { detect } from "package-manager-detector"; -import { AGENTS, type Agent, COMMANDS } from "package-manager-detector/agents"; +import { AGENTS,type Agent, COMMANDS, detect } from "package-manager-detector"; +// import { AGENTS, type Agent, COMMANDS } from "package-manager-detector/agents"; import * as p from "./prompts.js"; import { cancel } from "./prompt-helpers.js"; @@ -98,9 +98,11 @@ export function detectLanguage(cwd: string): DetectLanguageResult | undefined { type Options = Array<{ value: Agent | undefined; label: Agent | "None" }>; export async function detectPM(cwd: string, prompt: boolean) { - let { agent } = await detect({ cwd }); - - if (agent === undefined && prompt) { + let agent: Agent | undefined; + const detectResult = await detect({ cwd }); + if (detectResult != null) { + agent = detectResult.agent; + } if (detectResult === null && prompt) { const options: Options = AGENTS.filter((agent) => !agent.includes("@")).map((pm) => ({ value: pm, label: pm, @@ -118,5 +120,5 @@ export async function detectPM(cwd: string, prompt: boolean) { agent = res; } - return agent ? COMMANDS[agent] : undefined; + return agent; } diff --git a/packages/cli/src/utils/sveltekit.ts b/packages/cli/src/utils/sveltekit.ts index 3b2aff6c3..326db906d 100644 --- a/packages/cli/src/utils/sveltekit.ts +++ b/packages/cli/src/utils/sveltekit.ts @@ -1,9 +1,9 @@ import fs from "node:fs"; import path from "node:path"; import { execa } from "execa"; -import { detect } from "package-manager-detector"; -import { COMMANDS } from "package-manager-detector/agents"; +import { detect, resolveCommand } from "package-manager-detector"; import { loadProjectPackageInfo } from "./get-package-info.js"; +import { log } from "./prompts.js"; // if it's a SvelteKit project, run `svelte-kit sync` if the `.svelte-kit` dir is missing export async function syncSvelteKit(cwd: string) { @@ -11,13 +11,18 @@ export async function syncSvelteKit(cwd: string) { if (isSvelteKit) { // we'll exit early since syncing is rather slow if (fs.existsSync(path.join(cwd, ".svelte-kit"))) return; - - const { agent } = await detect({ cwd }); - const [pm] = COMMANDS[agent ?? "npm"].agent.split(" ") as [string]; - await execa(pm === "npm" ? "npx" : pm, ["svelte-kit", "sync"], { - cwd, - }); - } + const detectResult = await detect({ cwd }); + const cmd = resolveCommand(detectResult?.agent ?? "npm", "execute", ["svelte-kit", "sync"]); + if(!cmd) { + log.warn( + `Could not detect a package manager in ${cwd} to sync svelte-kit.` + ); + return + } + await execa(cmd.command, cmd.args, { + cwd, + }); + } } /** From 9d85fe408add296782a33edfe4f72ef368170c46 Mon Sep 17 00:00:00 2001 From: Brandon Ting Date: Sat, 25 Jan 2025 11:01:54 +0800 Subject: [PATCH 2/6] lint: Format & lint the code with pnpm format and pnpm lint --- packages/cli/src/commands/add.ts | 32 +++++++++++++-------------- packages/cli/src/commands/init.ts | 30 ++++++++++++------------- packages/cli/src/commands/update.ts | 30 ++++++++++++------------- packages/cli/src/utils/auto-detect.ts | 9 ++++---- packages/cli/src/utils/sveltekit.ts | 18 +++++++-------- pnpm-lock.yaml | 22 +++++++++--------- 6 files changed, 67 insertions(+), 74 deletions(-) diff --git a/packages/cli/src/commands/add.ts b/packages/cli/src/commands/add.ts index c6a85691d..668db2032 100644 --- a/packages/cli/src/commands/add.ts +++ b/packages/cli/src/commands/add.ts @@ -247,23 +247,21 @@ async function runAdd(cwd: string, config: Config, options: AddOptions) { // Install dependencies. const pm = await detectPM(cwd, options.deps); if (pm) { - const add = resolveCommand(pm, "add", ["-D", ...dependencies]); - if(add) { - tasks.push({ - title: `${highlight(pm)}: Installing dependencies`, - enabled: dependencies.size > 0, - async task() { - await execa(add.command, add.args, { - cwd, - }); - return `Dependencies installed with ${highlight(pm)}`; - }, - }); - } else { - p.log.warn( - `Could not detect a package manager in ${cwd}.` - ); - } + const add = resolveCommand(pm, "add", ["-D", ...dependencies]); + if (add) { + tasks.push({ + title: `${highlight(pm)}: Installing dependencies`, + enabled: dependencies.size > 0, + async task() { + await execa(add.command, add.args, { + cwd, + }); + return `Dependencies installed with ${highlight(pm)}`; + }, + }); + } else { + p.log.warn(`Could not detect a package manager in ${cwd}.`); + } } await p.tasks(tasks); diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index 43abdf4ef..e6272720a 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -367,22 +367,20 @@ export async function runInit(cwd: string, config: Config, options: InitOptions) const pm = await detectPM(cwd, options.deps); if (pm) { const add = resolveCommand(pm, "add", ["-D", ...PROJECT_DEPENDENCIES]); - if(add) { - tasks.push({ - title: `${highlight(pm)}: Installing dependencies`, - enabled: options.deps, - async task() { - await execa(add.command, add.args, { - cwd, - }); - return `Dependencies installed with ${highlight(pm)}`; - }, - }); - } else { - p.log.warn( - `Could not detect a package manager in ${cwd}.` - ); - } + if (add) { + tasks.push({ + title: `${highlight(pm)}: Installing dependencies`, + enabled: options.deps, + async task() { + await execa(add.command, add.args, { + cwd, + }); + return `Dependencies installed with ${highlight(pm)}`; + }, + }); + } else { + p.log.warn(`Could not detect a package manager in ${cwd}.`); + } } await p.tasks(tasks); diff --git a/packages/cli/src/commands/update.ts b/packages/cli/src/commands/update.ts index eb2309b07..db650c5af 100644 --- a/packages/cli/src/commands/update.ts +++ b/packages/cli/src/commands/update.ts @@ -229,22 +229,20 @@ async function runUpdate(cwd: string, config: Config, options: UpdateOptions) { const pm = await detectPM(cwd, true); if (pm) { const add = resolveCommand(pm, "add", ["-D", ...dependencies]); - if(add) { - tasks.push({ - title: `${highlight(pm)}: Installing dependencies`, - enabled: dependencies.size > 0, - async task() { - await execa(add.command, add.args, { - cwd, - }); - return `Dependencies installed with ${highlight(pm)}`; - }, - }); - } else { - p.log.warn( - `Could not detect a package manager in ${cwd}.` - ); - } + if (add) { + tasks.push({ + title: `${highlight(pm)}: Installing dependencies`, + enabled: dependencies.size > 0, + async task() { + await execa(add.command, add.args, { + cwd, + }); + return `Dependencies installed with ${highlight(pm)}`; + }, + }); + } else { + p.log.warn(`Could not detect a package manager in ${cwd}.`); + } } await p.tasks(tasks); diff --git a/packages/cli/src/utils/auto-detect.ts b/packages/cli/src/utils/auto-detect.ts index 96322b9e2..f35c5419f 100644 --- a/packages/cli/src/utils/auto-detect.ts +++ b/packages/cli/src/utils/auto-detect.ts @@ -2,7 +2,7 @@ import fs from "node:fs"; import path from "node:path"; import ignore, { type Ignore } from "ignore"; import { type TsConfigResult, getTsconfig } from "get-tsconfig"; -import { AGENTS,type Agent, COMMANDS, detect } from "package-manager-detector"; +import { AGENTS, type Agent, COMMANDS, detect } from "package-manager-detector"; // import { AGENTS, type Agent, COMMANDS } from "package-manager-detector/agents"; import * as p from "./prompts.js"; import { cancel } from "./prompt-helpers.js"; @@ -99,10 +99,11 @@ export function detectLanguage(cwd: string): DetectLanguageResult | undefined { type Options = Array<{ value: Agent | undefined; label: Agent | "None" }>; export async function detectPM(cwd: string, prompt: boolean) { let agent: Agent | undefined; - const detectResult = await detect({ cwd }); - if (detectResult != null) { + const detectResult = await detect({ cwd }); + if (detectResult != null) { agent = detectResult.agent; - } if (detectResult === null && prompt) { + } + if (detectResult === null && prompt) { const options: Options = AGENTS.filter((agent) => !agent.includes("@")).map((pm) => ({ value: pm, label: pm, diff --git a/packages/cli/src/utils/sveltekit.ts b/packages/cli/src/utils/sveltekit.ts index 326db906d..883732c50 100644 --- a/packages/cli/src/utils/sveltekit.ts +++ b/packages/cli/src/utils/sveltekit.ts @@ -13,16 +13,14 @@ export async function syncSvelteKit(cwd: string) { if (fs.existsSync(path.join(cwd, ".svelte-kit"))) return; const detectResult = await detect({ cwd }); const cmd = resolveCommand(detectResult?.agent ?? "npm", "execute", ["svelte-kit", "sync"]); - if(!cmd) { - log.warn( - `Could not detect a package manager in ${cwd} to sync svelte-kit.` - ); - return - } - await execa(cmd.command, cmd.args, { - cwd, - }); - } + if (!cmd) { + log.warn(`Could not detect a package manager in ${cwd} to sync svelte-kit.`); + return; + } + await execa(cmd.command, cmd.args, { + cwd, + }); + } } /** diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b0bf3a2e7..7573030c9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13,7 +13,7 @@ importers: version: 2.27.7 '@huntabyte/eslint-config': specifier: ^0.3.2 - version: 0.3.2(@vue/compiler-sfc@3.4.36)(eslint-plugin-svelte@2.43.0(eslint@9.8.0)(svelte@4.2.18))(eslint@9.8.0)(svelte-eslint-parser@0.41.0(svelte@4.2.18))(svelte@4.2.18)(typescript@5.5.4)(vitest@1.6.0) + version: 0.3.2(@vue/compiler-sfc@3.4.36)(eslint-plugin-svelte@2.43.0(eslint@9.8.0)(svelte@4.2.18))(eslint@9.8.0)(svelte-eslint-parser@0.41.0(svelte@4.2.18))(svelte@4.2.18)(typescript@5.5.4)(vitest@1.6.0(@types/node@18.19.43)) '@huntabyte/eslint-plugin': specifier: ^0.1.0 version: 0.1.0(eslint@9.8.0) @@ -82,8 +82,8 @@ importers: specifier: ^5.3.1 version: 5.3.1 package-manager-detector: - specifier: ^0.1.2 - version: 0.1.2 + specifier: ^0.2.8 + version: 0.2.8 sisteransi: specifier: ^1.0.5 version: 1.0.5 @@ -4226,8 +4226,8 @@ packages: package-json-from-dist@1.0.0: resolution: {integrity: sha512-dATvCeZN/8wQsGywez1mzHtTlP22H8OEfPrVMLNr4/eGa+ijtLn/6M5f0dY8UKNrC2O9UCU6SSoG3qRKnt7STw==} - package-manager-detector@0.1.2: - resolution: {integrity: sha512-iePyefLTOm2gEzbaZKSW+eBMjg+UYsQvUKxmvGXAQ987K16efBg10MxIjZs08iyX+DY2/owKY9DIdu193kX33w==} + package-manager-detector@0.2.8: + resolution: {integrity: sha512-ts9KSdroZisdvKMWVAVCXiKqnqNfXz4+IbrBG8/BWx/TR5le+jfenvoBuIZ6UWM9nz47W7AbD9qYfAwfWMIwzA==} paneforge@0.0.2: resolution: {integrity: sha512-1xNMq+uslstqum4D8CzzkPGqnTWUlevjYtMjUhuEOiuz7E0fJHFuM8ogk8+LJnVbAg3hMJJ/9Mu4A1KaxK38oQ==} @@ -5656,7 +5656,7 @@ snapshots: '@jridgewell/gen-mapping': 0.3.5 '@jridgewell/trace-mapping': 0.3.25 - '@antfu/eslint-config@2.24.1(@vue/compiler-sfc@3.4.36)(eslint-plugin-svelte@2.43.0(eslint@9.8.0)(svelte@4.2.18))(eslint@9.8.0)(svelte-eslint-parser@0.41.0(svelte@4.2.18))(svelte@4.2.18)(typescript@5.5.4)(vitest@1.6.0)': + '@antfu/eslint-config@2.24.1(@vue/compiler-sfc@3.4.36)(eslint-plugin-svelte@2.43.0(eslint@9.8.0)(svelte@4.2.18))(eslint@9.8.0)(svelte-eslint-parser@0.41.0(svelte@4.2.18))(svelte@4.2.18)(typescript@5.5.4)(vitest@1.6.0(@types/node@18.19.43))': dependencies: '@antfu/install-pkg': 0.3.3 '@clack/prompts': 0.7.0 @@ -5681,7 +5681,7 @@ snapshots: eslint-plugin-toml: 0.11.1(eslint@9.8.0) eslint-plugin-unicorn: 55.0.0(eslint@9.8.0) eslint-plugin-unused-imports: 4.0.1(@typescript-eslint/eslint-plugin@8.0.1(@typescript-eslint/parser@8.0.1(eslint@9.8.0)(typescript@5.5.4))(eslint@9.8.0)(typescript@5.5.4))(eslint@9.8.0) - eslint-plugin-vitest: 0.5.4(@typescript-eslint/eslint-plugin@8.0.1(@typescript-eslint/parser@8.0.1(eslint@9.8.0)(typescript@5.5.4))(eslint@9.8.0)(typescript@5.5.4))(eslint@9.8.0)(typescript@5.5.4)(vitest@1.6.0) + eslint-plugin-vitest: 0.5.4(@typescript-eslint/eslint-plugin@8.0.1(@typescript-eslint/parser@8.0.1(eslint@9.8.0)(typescript@5.5.4))(eslint@9.8.0)(typescript@5.5.4))(eslint@9.8.0)(typescript@5.5.4)(vitest@1.6.0(@types/node@18.19.43)) eslint-plugin-vue: 9.27.0(eslint@9.8.0) eslint-plugin-yml: 1.14.0(eslint@9.8.0) eslint-processor-vue-blocks: 0.1.2(@vue/compiler-sfc@3.4.36)(eslint@9.8.0) @@ -6490,9 +6490,9 @@ snapshots: '@humanwhocodes/retry@0.3.0': {} - '@huntabyte/eslint-config@0.3.2(@vue/compiler-sfc@3.4.36)(eslint-plugin-svelte@2.43.0(eslint@9.8.0)(svelte@4.2.18))(eslint@9.8.0)(svelte-eslint-parser@0.41.0(svelte@4.2.18))(svelte@4.2.18)(typescript@5.5.4)(vitest@1.6.0)': + '@huntabyte/eslint-config@0.3.2(@vue/compiler-sfc@3.4.36)(eslint-plugin-svelte@2.43.0(eslint@9.8.0)(svelte@4.2.18))(eslint@9.8.0)(svelte-eslint-parser@0.41.0(svelte@4.2.18))(svelte@4.2.18)(typescript@5.5.4)(vitest@1.6.0(@types/node@18.19.43))': dependencies: - '@antfu/eslint-config': 2.24.1(@vue/compiler-sfc@3.4.36)(eslint-plugin-svelte@2.43.0(eslint@9.8.0)(svelte@4.2.18))(eslint@9.8.0)(svelte-eslint-parser@0.41.0(svelte@4.2.18))(svelte@4.2.18)(typescript@5.5.4)(vitest@1.6.0) + '@antfu/eslint-config': 2.24.1(@vue/compiler-sfc@3.4.36)(eslint-plugin-svelte@2.43.0(eslint@9.8.0)(svelte@4.2.18))(eslint@9.8.0)(svelte-eslint-parser@0.41.0(svelte@4.2.18))(svelte@4.2.18)(typescript@5.5.4)(vitest@1.6.0(@types/node@18.19.43)) '@antfu/install-pkg': 0.3.3 '@clack/prompts': 0.7.0 '@huntabyte/eslint-plugin': 0.1.0(eslint@9.8.0) @@ -8524,7 +8524,7 @@ snapshots: optionalDependencies: '@typescript-eslint/eslint-plugin': 8.0.1(@typescript-eslint/parser@7.18.0(eslint@9.8.0)(typescript@5.5.4))(eslint@9.8.0)(typescript@5.5.4) - eslint-plugin-vitest@0.5.4(@typescript-eslint/eslint-plugin@8.0.1(@typescript-eslint/parser@8.0.1(eslint@9.8.0)(typescript@5.5.4))(eslint@9.8.0)(typescript@5.5.4))(eslint@9.8.0)(typescript@5.5.4)(vitest@1.6.0): + eslint-plugin-vitest@0.5.4(@typescript-eslint/eslint-plugin@8.0.1(@typescript-eslint/parser@8.0.1(eslint@9.8.0)(typescript@5.5.4))(eslint@9.8.0)(typescript@5.5.4))(eslint@9.8.0)(typescript@5.5.4)(vitest@1.6.0(@types/node@18.19.43)): dependencies: '@typescript-eslint/utils': 7.18.0(eslint@9.8.0)(typescript@5.5.4) eslint: 9.8.0 @@ -9910,7 +9910,7 @@ snapshots: package-json-from-dist@1.0.0: {} - package-manager-detector@0.1.2: {} + package-manager-detector@0.2.8: {} paneforge@0.0.2(svelte@4.2.18): dependencies: From d5b5d31b955acf1dd648b127adad53fc317129db Mon Sep 17 00:00:00 2001 From: Brandon Ting Date: Sun, 26 Jan 2025 13:05:11 +0800 Subject: [PATCH 3/6] fix: throw error on failing to resolve command instead of log --- packages/cli/src/commands/add.ts | 29 +++++++++++++-------------- packages/cli/src/commands/init.ts | 29 +++++++++++++-------------- packages/cli/src/commands/update.ts | 27 ++++++++++++------------- packages/cli/src/utils/auto-detect.ts | 3 +-- 4 files changed, 42 insertions(+), 46 deletions(-) diff --git a/packages/cli/src/commands/add.ts b/packages/cli/src/commands/add.ts index 668db2032..85f343821 100644 --- a/packages/cli/src/commands/add.ts +++ b/packages/cli/src/commands/add.ts @@ -248,21 +248,20 @@ async function runAdd(cwd: string, config: Config, options: AddOptions) { const pm = await detectPM(cwd, options.deps); if (pm) { const add = resolveCommand(pm, "add", ["-D", ...dependencies]); - if (add) { - tasks.push({ - title: `${highlight(pm)}: Installing dependencies`, - enabled: dependencies.size > 0, - async task() { - await execa(add.command, add.args, { - cwd, - }); - return `Dependencies installed with ${highlight(pm)}`; - }, - }); - } else { - p.log.warn(`Could not detect a package manager in ${cwd}.`); - } - } + if(!add) { + throw error(`Could not detect a package manager in ${cwd}.`) + } + tasks.push({ + title: `${highlight(pm)}: Installing dependencies`, + enabled: dependencies.size > 0, + async task() { + await execa(add.command, add.args, { + cwd, + }); + return `Dependencies installed with ${highlight(pm)}`; + }, + }); + } await p.tasks(tasks); diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index e6272720a..722c66bfc 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -367,21 +367,20 @@ export async function runInit(cwd: string, config: Config, options: InitOptions) const pm = await detectPM(cwd, options.deps); if (pm) { const add = resolveCommand(pm, "add", ["-D", ...PROJECT_DEPENDENCIES]); - if (add) { - tasks.push({ - title: `${highlight(pm)}: Installing dependencies`, - enabled: options.deps, - async task() { - await execa(add.command, add.args, { - cwd, - }); - return `Dependencies installed with ${highlight(pm)}`; - }, - }); - } else { - p.log.warn(`Could not detect a package manager in ${cwd}.`); - } - } + if(!add) { + throw error(`Could not detect a package manager in ${cwd}.`) + } + tasks.push({ + title: `${highlight(pm)}: Installing dependencies`, + enabled: options.deps, + async task() { + await execa(add.command, add.args, { + cwd, + }); + return `Dependencies installed with ${highlight(pm)}`; + }, + }); + } await p.tasks(tasks); diff --git a/packages/cli/src/commands/update.ts b/packages/cli/src/commands/update.ts index db650c5af..6ebf77b87 100644 --- a/packages/cli/src/commands/update.ts +++ b/packages/cli/src/commands/update.ts @@ -229,20 +229,19 @@ async function runUpdate(cwd: string, config: Config, options: UpdateOptions) { const pm = await detectPM(cwd, true); if (pm) { const add = resolveCommand(pm, "add", ["-D", ...dependencies]); - if (add) { - tasks.push({ - title: `${highlight(pm)}: Installing dependencies`, - enabled: dependencies.size > 0, - async task() { - await execa(add.command, add.args, { - cwd, - }); - return `Dependencies installed with ${highlight(pm)}`; - }, - }); - } else { - p.log.warn(`Could not detect a package manager in ${cwd}.`); - } + if(!add) { + throw error(`Could not detect a package manager in ${cwd}.`) + } + tasks.push({ + title: `${highlight(pm)}: Installing dependencies`, + enabled: dependencies.size > 0, + async task() { + await execa(add.command, add.args, { + cwd, + }); + return `Dependencies installed with ${highlight(pm)}`; + }, + }); } await p.tasks(tasks); diff --git a/packages/cli/src/utils/auto-detect.ts b/packages/cli/src/utils/auto-detect.ts index f35c5419f..5b4cc6756 100644 --- a/packages/cli/src/utils/auto-detect.ts +++ b/packages/cli/src/utils/auto-detect.ts @@ -2,8 +2,7 @@ import fs from "node:fs"; import path from "node:path"; import ignore, { type Ignore } from "ignore"; import { type TsConfigResult, getTsconfig } from "get-tsconfig"; -import { AGENTS, type Agent, COMMANDS, detect } from "package-manager-detector"; -// import { AGENTS, type Agent, COMMANDS } from "package-manager-detector/agents"; +import { AGENTS, type Agent, detect } from "package-manager-detector"; import * as p from "./prompts.js"; import { cancel } from "./prompt-helpers.js"; From 08111f1599d706c4a432e5c8130b94d33ca7cab2 Mon Sep 17 00:00:00 2001 From: Brandon Ting Date: Sun, 26 Jan 2025 13:06:42 +0800 Subject: [PATCH 4/6] lint: run lint cmd --- packages/cli/src/commands/add.ts | 28 ++++++++++++++-------------- packages/cli/src/commands/init.ts | 28 ++++++++++++++-------------- packages/cli/src/commands/update.ts | 26 +++++++++++++------------- 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/packages/cli/src/commands/add.ts b/packages/cli/src/commands/add.ts index 85f343821..7d560a443 100644 --- a/packages/cli/src/commands/add.ts +++ b/packages/cli/src/commands/add.ts @@ -248,20 +248,20 @@ async function runAdd(cwd: string, config: Config, options: AddOptions) { const pm = await detectPM(cwd, options.deps); if (pm) { const add = resolveCommand(pm, "add", ["-D", ...dependencies]); - if(!add) { - throw error(`Could not detect a package manager in ${cwd}.`) - } - tasks.push({ - title: `${highlight(pm)}: Installing dependencies`, - enabled: dependencies.size > 0, - async task() { - await execa(add.command, add.args, { - cwd, - }); - return `Dependencies installed with ${highlight(pm)}`; - }, - }); - } + if (!add) { + throw error(`Could not detect a package manager in ${cwd}.`); + } + tasks.push({ + title: `${highlight(pm)}: Installing dependencies`, + enabled: dependencies.size > 0, + async task() { + await execa(add.command, add.args, { + cwd, + }); + return `Dependencies installed with ${highlight(pm)}`; + }, + }); + } await p.tasks(tasks); diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index 722c66bfc..124525123 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -367,20 +367,20 @@ export async function runInit(cwd: string, config: Config, options: InitOptions) const pm = await detectPM(cwd, options.deps); if (pm) { const add = resolveCommand(pm, "add", ["-D", ...PROJECT_DEPENDENCIES]); - if(!add) { - throw error(`Could not detect a package manager in ${cwd}.`) - } - tasks.push({ - title: `${highlight(pm)}: Installing dependencies`, - enabled: options.deps, - async task() { - await execa(add.command, add.args, { - cwd, - }); - return `Dependencies installed with ${highlight(pm)}`; - }, - }); - } + if (!add) { + throw error(`Could not detect a package manager in ${cwd}.`); + } + tasks.push({ + title: `${highlight(pm)}: Installing dependencies`, + enabled: options.deps, + async task() { + await execa(add.command, add.args, { + cwd, + }); + return `Dependencies installed with ${highlight(pm)}`; + }, + }); + } await p.tasks(tasks); diff --git a/packages/cli/src/commands/update.ts b/packages/cli/src/commands/update.ts index 6ebf77b87..f70b15117 100644 --- a/packages/cli/src/commands/update.ts +++ b/packages/cli/src/commands/update.ts @@ -229,19 +229,19 @@ async function runUpdate(cwd: string, config: Config, options: UpdateOptions) { const pm = await detectPM(cwd, true); if (pm) { const add = resolveCommand(pm, "add", ["-D", ...dependencies]); - if(!add) { - throw error(`Could not detect a package manager in ${cwd}.`) - } - tasks.push({ - title: `${highlight(pm)}: Installing dependencies`, - enabled: dependencies.size > 0, - async task() { - await execa(add.command, add.args, { - cwd, - }); - return `Dependencies installed with ${highlight(pm)}`; - }, - }); + if (!add) { + throw error(`Could not detect a package manager in ${cwd}.`); + } + tasks.push({ + title: `${highlight(pm)}: Installing dependencies`, + enabled: dependencies.size > 0, + async task() { + await execa(add.command, add.args, { + cwd, + }); + return `Dependencies installed with ${highlight(pm)}`; + }, + }); } await p.tasks(tasks); From fef1192425f903704994d36b9804d57bc7dcd878 Mon Sep 17 00:00:00 2001 From: Hunter Johnston <64506580+huntabyte@users.noreply.github.com> Date: Mon, 27 Jan 2025 10:23:34 -0500 Subject: [PATCH 5/6] add changeset --- .changeset/blue-cougars-compete.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/blue-cougars-compete.md diff --git a/.changeset/blue-cougars-compete.md b/.changeset/blue-cougars-compete.md new file mode 100644 index 000000000..71e4c6ba7 --- /dev/null +++ b/.changeset/blue-cougars-compete.md @@ -0,0 +1,5 @@ +--- +"shadcn-svelte": patch +--- + +update `package-manager-detector` version From e84f608606de385f8a7094a7230e952bdd9e55b6 Mon Sep 17 00:00:00 2001 From: Hunter Johnston Date: Wed, 29 Jan 2025 10:25:21 -0500 Subject: [PATCH 6/6] formatting --- sites/docs/src/lib/registry/default/ui/sheet/index.ts | 2 +- sites/docs/src/lib/registry/new-york/ui/sheet/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sites/docs/src/lib/registry/default/ui/sheet/index.ts b/sites/docs/src/lib/registry/default/ui/sheet/index.ts index 7e1f764be..efad47428 100644 --- a/sites/docs/src/lib/registry/default/ui/sheet/index.ts +++ b/sites/docs/src/lib/registry/default/ui/sheet/index.ts @@ -44,7 +44,7 @@ export const sheetVariants = tv({ top: "inset-x-0 top-0 border-b", bottom: "inset-x-0 bottom-0 border-t", left: "inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm", - right: "inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm", + right: "inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm", }, }, defaultVariants: { diff --git a/sites/docs/src/lib/registry/new-york/ui/sheet/index.ts b/sites/docs/src/lib/registry/new-york/ui/sheet/index.ts index 22e846705..efad47428 100644 --- a/sites/docs/src/lib/registry/new-york/ui/sheet/index.ts +++ b/sites/docs/src/lib/registry/new-york/ui/sheet/index.ts @@ -41,7 +41,7 @@ export const sheetVariants = tv({ base: "bg-background fixed z-50 gap-4 p-6 shadow-lg", variants: { side: { - top: "inset-x-0 top-0 border-b ", + top: "inset-x-0 top-0 border-b", bottom: "inset-x-0 bottom-0 border-t", left: "inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm", right: "inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm",