Skip to content

Commit

Permalink
chore: replace find-up with package-manager-detector (#1237)
Browse files Browse the repository at this point in the history
Co-authored-by: AdrianGonz97 <[email protected]>
  • Loading branch information
benmccann and AdrianGonz97 authored Aug 14, 2024
1 parent 5fdbbdb commit e67c1fd
Show file tree
Hide file tree
Showing 11 changed files with 6,074 additions and 5,029 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-insects-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"shadcn-svelte": patch
---

chore: use `package-manager-detector`
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"ci:release": "pnpm ci:build && pnpm ci:publish"
},
"engines": {
"pnpm": ">=8",
"pnpm": ">=9",
"node": ">=18"
},
"packageManager": "pnpm@8.15.8",
"packageManager": "pnpm@9.7.1",
"repository": {
"type": "git",
"url": "https://github.com/huntabyte/shadcn-svelte.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"chalk": "5.2.0",
"commander": "^10.0.1",
"execa": "^7.2.0",
"find-up": "^7.0.0",
"is-unicode-supported": "^2.0.0",
"node-fetch-native": "^1.6.4"
},
Expand All @@ -53,6 +52,7 @@
"cross-env": "^7.0.3",
"get-tsconfig": "^4.7.3",
"ignore": "^5.3.1",
"package-manager-detector": "^0.1.2",
"sisteransi": "^1.0.5",
"tsup": "^8.0.0",
"type-fest": "^3.13.1",
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import color from "chalk";
import { Command } from "commander";
import { execa } from "execa";
import * as v from "valibot";
import { detect } from "package-manager-detector";
import { COMMANDS } from "package-manager-detector/agents";
import { type Config, getConfig } from "../utils/get-config.js";
import { getEnvProxy } from "../utils/get-env-proxy.js";
import { getPackageManager } from "../utils/get-package-manager.js";
import { ConfigError, error, handleError } from "../utils/errors.js";
import {
fetchTree,
Expand Down Expand Up @@ -248,8 +249,9 @@ async function runAdd(cwd: string, config: Config, options: AddOptions) {
title: "Installing package dependencies",
enabled: dependencies.size > 0,
async task() {
const packageManager = await getPackageManager(cwd);
await execa(packageManager, ["add", ...dependencies], {
const { agent } = await detect({ cwd });
const [pm, add] = COMMANDS[agent ?? "npm"].add.split(" ") as [string, string];
await execa(pm, [add, ...dependencies], {
cwd,
});
return "Dependencies installed";
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import color from "chalk";
import * as v from "valibot";
import { Command, Option } from "commander";
import { execa } from "execa";
import { detect } from "package-manager-detector";
import { COMMANDS } from "package-manager-detector/agents";
import * as cliConfig from "../utils/get-config.js";
import type { Config } from "../utils/get-config.js";
import { getPackageManager } from "../utils/get-package-manager.js";
import { error, handleError } from "../utils/errors.js";
import { getBaseColors, getRegistryBaseColor, getStyles } from "../utils/registry";
import * as templates from "../utils/templates.js";
Expand Down Expand Up @@ -363,9 +364,9 @@ export async function runInit(cwd: string, config: Config, options: InitOptions)
tasks.push({
title: "Installing dependencies",
async task() {
const packageManager = await getPackageManager(cwd);

await execa(packageManager, ["add", ...PROJECT_DEPENDENCIES], {
const { agent } = await detect({ cwd });
const [pm, add] = COMMANDS[agent ?? "npm"].add.split(" ") as [string, string];
await execa(pm, [add, ...PROJECT_DEPENDENCIES], {
cwd,
});
return "Dependencies installed";
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import color from "chalk";
import { Command } from "commander";
import { execa } from "execa";
import * as v from "valibot";
import { detect } from "package-manager-detector";
import { COMMANDS } from "package-manager-detector/agents";
import { type Config, getConfig } from "../utils/get-config.js";
import { getPackageManager } from "../utils/get-package-manager.js";
import { error, handleError } from "../utils/errors.js";
import { fetchTree, getItemTargetPath, getRegistryIndex, resolveTree } from "../utils/registry";
import { UTILS, UTILS_JS } from "../utils/templates.js";
Expand Down Expand Up @@ -229,8 +230,9 @@ async function runUpdate(cwd: string, config: Config, options: UpdateOptions) {
title: "Installing package dependencies",
enabled: dependencies.size > 0,
async task() {
const packageManager = await getPackageManager(cwd);
await execa(packageManager, ["add", ...dependencies], {
const { agent } = await detect({ cwd });
const [pm, add] = COMMANDS[agent ?? "npm"].add.split(" ") as [string, string];
await execa(pm, [add, ...dependencies], {
cwd,
});
return "Dependencies installed";
Expand Down
69 changes: 0 additions & 69 deletions packages/cli/src/utils/get-package-manager.ts

This file was deleted.

8 changes: 5 additions & 3 deletions packages/cli/src/utils/sveltekit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import fs from "node:fs";
import path from "node:path";
import { execa } from "execa";
import { getPackageManager } from "./get-package-manager.js";
import { detect } from "package-manager-detector";
import { COMMANDS } from "package-manager-detector/agents";
import { loadProjectPackageInfo } from "./get-package-info.js";

// if it's a SvelteKit project, run `svelte-kit sync` if the `.svelte-kit` dir is missing
Expand All @@ -11,8 +12,9 @@ export async function syncSvelteKit(cwd: string) {
// we'll exit early since syncing is rather slow
if (fs.existsSync(path.join(cwd, ".svelte-kit"))) return;

const packageManager = await getPackageManager(cwd);
await execa(packageManager === "npm" ? "npx" : packageManager, ["svelte-kit", "sync"], {
const { agent } = await detect({ cwd });
const [pm] = COMMANDS[agent ?? "npm"].agent.split(" ") as [string];
await execa(pm === "npm" ? "npx" : pm, ["svelte-kit", "sync"], {
cwd,
});
}
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/test/commands/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { execa } from "execa";
import { afterEach, expect, it, vi } from "vitest";
import { runInit } from "../../src/commands/init";
import { getConfig } from "../../src/utils/get-config";
import * as getPackageManager from "../../src/utils/get-package-manager";
import * as registry from "../../src/utils/registry";

vi.mock("execa");
Expand All @@ -16,7 +15,6 @@ vi.mock("fs/promises", () => ({
vi.mock("ora");

it("init (config-full)", async () => {
vi.spyOn(getPackageManager, "getPackageManager").mockResolvedValue("pnpm");
vi.spyOn(registry, "getRegistryBaseColor").mockResolvedValue({
inlineColors: {
light: {},
Expand Down
22 changes: 0 additions & 22 deletions packages/cli/test/utils/get-package-manager.spec.ts

This file was deleted.

Loading

0 comments on commit e67c1fd

Please sign in to comment.