Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/commands/help/index.ts
Original file line number Diff line number Diff line change
@@ -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<string, never>;
Expand Down Expand Up @@ -32,7 +32,7 @@ export class HelpProgram extends Program<HelpArgs, HelpInput> {
}

protected async execute(_input: HelpInput): Promise<number> {
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}`);
Expand Down
15 changes: 5 additions & 10 deletions src/create-qwik/background-install.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
});

Expand All @@ -60,14 +57,12 @@ export function backgroundInstallDeps(baseAppDir: string, outDir: string): Backg
},

async abort(): Promise<void> {
await proc.abort();
rmSync(tmpInstallDir, { recursive: true, force: true });
},

async complete(destDir: string): Promise<boolean> {
const result = await proc.result;
if (!result.status) {
rmSync(tmpInstallDir, { recursive: true, force: true });
if (!this.success) {
this.abort();
return false;
}

Expand Down
3 changes: 1 addition & 2 deletions src/create-qwik/run-interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -100,7 +100,6 @@ export async function runCreateInteractiveCli(): Promise<void> {
// -------------------------------------------------------------------------
// 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) => {
Expand Down
7 changes: 3 additions & 4 deletions src/create-qwik/run-non-interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -71,7 +71,7 @@ export async function runCreateCli(args: string[]): Promise<void> {
await createApp({
appId: template,
outDir: resolvedOutDir,
pkgManager: getPackageManagerName(),
pkgManager: pm.name,
});

// Initialize git repo with initial commit (CRQW-13)
Expand All @@ -82,9 +82,8 @@ export async function runCreateCli(args: string[]): Promise<void> {
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);
Expand Down
18 changes: 6 additions & 12 deletions src/integrations/update-app.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -88,23 +86,19 @@ export function integrationHasDeps(integration: IntegrationData): boolean {
* Install dependencies in the given working directory using panam.
*/
export async function installDeps(cwd: string): Promise<void> {
await install({ cwd });
await pm.install({ cwd });
}

/**
* Run a postInstall command in the given working directory.
* Uses npx for npm, or the package manager name directly for pnpm/yarn/bun.
*/
export async function runPostInstall(postInstallCmd: string, cwd: string): Promise<void> {
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}`);
}
}
Loading