From f1da8730804d260812021f80f8118d65fa1b3610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9A=A1=20Sigui=20=F0=9F=87=A8=F0=9F=87=AE?= Date: Sun, 5 Apr 2026 14:39:32 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor:=20Use=20Panam=20?= =?UTF-8?q?for=20the=20dependency=20manager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/help/index.ts | 4 ++-- src/create-qwik/background-install.ts | 15 +++++---------- src/create-qwik/run-interactive.ts | 3 +-- src/create-qwik/run-non-interactive.ts | 7 +++---- src/integrations/update-app.ts | 18 ++++++------------ 5 files changed, 17 insertions(+), 30 deletions(-) diff --git a/src/commands/help/index.ts b/src/commands/help/index.ts index eaca511..b1101f4 100644 --- a/src/commands/help/index.ts +++ b/src/commands/help/index.ts @@ -1,5 +1,5 @@ import { Program } from "../../core.ts"; -import { getPmRunCommand } from "../../utils/package-manager.ts"; +import pm from "panam/pm"; type HelpArgs = { _: string[] }; type HelpInput = Record; @@ -32,7 +32,7 @@ export class HelpProgram extends Program { } protected async execute(_input: HelpInput): Promise { - const pmRun = getPmRunCommand(); + const pmRun = pm.runCommand(); console.log("Available commands:\n"); for (const cmd of COMMAND_LIST) { console.log(` ${cmd.name.padEnd(18)} ${cmd.description}`); diff --git a/src/create-qwik/background-install.ts b/src/create-qwik/background-install.ts index 55151f5..68c5f19 100644 --- a/src/create-qwik/background-install.ts +++ b/src/create-qwik/background-install.ts @@ -1,7 +1,6 @@ import { copyFileSync, mkdirSync, renameSync, rmSync } from "node:fs"; import { join, resolve } from "node:path"; -import { $ } from "panam/executor"; -import { getPackageManagerName } from "../utils/package-manager.ts"; +import pm from "panam/pm"; /** * Result object for a background dependency install. @@ -43,14 +42,12 @@ export function backgroundInstallDeps(baseAppDir: string, outDir: string): Backg mkdirSync(tmpInstallDir, { recursive: true }); copyFileSync(join(baseAppDir, "package.json"), join(tmpInstallDir, "package.json")); - const pm = getPackageManagerName(); - // Start background install - const proc = $(pm, ["install"], { cwd: tmpInstallDir }); + const proc = pm.install({ cwd: tmpInstallDir }); // Track success state let success: boolean | undefined = undefined; - proc.result.then((r: { status: boolean }) => { + proc.then((r: { status: boolean }) => { success = r.status; }); @@ -60,14 +57,12 @@ export function backgroundInstallDeps(baseAppDir: string, outDir: string): Backg }, async abort(): Promise { - await proc.abort(); rmSync(tmpInstallDir, { recursive: true, force: true }); }, async complete(destDir: string): Promise { - const result = await proc.result; - if (!result.status) { - rmSync(tmpInstallDir, { recursive: true, force: true }); + if (!this.success) { + this.abort(); return false; } diff --git a/src/create-qwik/run-interactive.ts b/src/create-qwik/run-interactive.ts index 7143c9f..521e950 100644 --- a/src/create-qwik/run-interactive.ts +++ b/src/create-qwik/run-interactive.ts @@ -6,7 +6,7 @@ import { bye } from "../console.ts"; import { getRandomJoke } from "../commands/joke/jokes.ts"; import { installDeps } from "../integrations/update-app.ts"; import { loadAppStarters } from "../integrations/load-app-starters.ts"; -import { getPackageManagerName } from "../utils/package-manager.ts"; +import { name as detectedPm } from "panam/pm"; import { backgroundInstallDeps } from "./background-install.ts"; import { createApp } from "./create-app.ts"; import { initGitRepo } from "./git-init.ts"; @@ -100,7 +100,6 @@ export async function runCreateInteractiveCli(): Promise { // ------------------------------------------------------------------------- // Prompt 4: Package manager selection // ------------------------------------------------------------------------- - const detectedPm = getPackageManagerName(); const pmAnswer = await select({ message: "Which package manager do you prefer?", options: (["npm", "pnpm", "yarn", "bun"] as const).map((pm) => { diff --git a/src/create-qwik/run-non-interactive.ts b/src/create-qwik/run-non-interactive.ts index ad89fe7..4ac89aa 100644 --- a/src/create-qwik/run-non-interactive.ts +++ b/src/create-qwik/run-non-interactive.ts @@ -4,7 +4,7 @@ import { resolve } from "node:path"; import yargs from "yargs"; import { outro } from "../console.ts"; import { installDeps } from "../integrations/update-app.ts"; -import { getPackageManagerName } from "../utils/package-manager.ts"; +import pm from "panam/pm"; import { createApp } from "./create-app.ts"; import { initGitRepo } from "./git-init.ts"; import { loadAppStarters } from "../integrations/load-app-starters.ts"; @@ -71,7 +71,7 @@ export async function runCreateCli(args: string[]): Promise { await createApp({ appId: template, outDir: resolvedOutDir, - pkgManager: getPackageManagerName(), + pkgManager: pm.name, }); // Initialize git repo with initial commit (CRQW-13) @@ -82,9 +82,8 @@ export async function runCreateCli(args: string[]): Promise { await installDeps(resolvedOutDir); } - const pm = getPackageManagerName(); outro( - `Project created at ${resolvedOutDir}\n\nNext steps:\n cd ${resolvedOutDir}\n ${pm} install\n ${pm} run dev`, + `Project created at ${resolvedOutDir}\n\nNext steps:\n cd ${resolvedOutDir}\n ${pm.name} install\n ${pm.runCommand()} dev`, ); process.exit(0); diff --git a/src/integrations/update-app.ts b/src/integrations/update-app.ts index 62c6554..f56ed8d 100644 --- a/src/integrations/update-app.ts +++ b/src/integrations/update-app.ts @@ -1,9 +1,7 @@ import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { dirname, join } from "node:path"; -import { spawnSync } from "node:child_process"; -import { install } from "panam"; +import pm from "panam/pm"; import type { IntegrationData } from "../types.ts"; -import { getPackageManagerName } from "../utils/package-manager.ts"; /** * Merge scripts, dependencies, and devDependencies from an integration's @@ -88,7 +86,7 @@ export function integrationHasDeps(integration: IntegrationData): boolean { * Install dependencies in the given working directory using panam. */ export async function installDeps(cwd: string): Promise { - await install({ cwd }); + await pm.install({ cwd }); } /** @@ -96,15 +94,11 @@ export async function installDeps(cwd: string): Promise { * Uses npx for npm, or the package manager name directly for pnpm/yarn/bun. */ export async function runPostInstall(postInstallCmd: string, cwd: string): Promise { - const parts = postInstallCmd.split(" "); - const [command, ...args] = parts; + const [command] = postInstallCmd.split(" "); if (!command) return; - const pm = getPackageManagerName(); - const executor = pm === "npm" ? "npx" : pm; - - const result = spawnSync(executor, [command, ...args], { cwd, stdio: "inherit" }); - if (result.status !== 0) { - throw new Error(`Post-install command failed: ${postInstallCmd} (exit code ${result.status})`); + const result = await pm.x(postInstallCmd, { cwd }); + if (!result.status) { + throw new Error(`Post-install command failed: ${postInstallCmd}`); } }