Skip to content

Commit 6f24eb1

Browse files
committed
fix: unify dependency installation for npm and pnpm
1 parent 7c0495b commit 6f24eb1

1 file changed

Lines changed: 7 additions & 40 deletions

File tree

adminforth/commands/createApp/utils.js

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -487,42 +487,13 @@ async function writeTemplateFiles(dirname, cwd, useNpm, includePrismaMigrations,
487487
}
488488
}
489489

490-
async function installDependenciesPnpm(ctx, cwd) {
491-
const isWindows = process.platform === 'win32';
492-
493-
const nodeBinary = process.execPath;
494-
const pnpmPath = path.join(path.dirname(nodeBinary), isWindows ? 'pnpm.cmd' : 'pnpm');
495-
const customDir = ctx.customDir;
496-
if (isWindows) {
497-
const res = await Promise.all([
498-
execAsync(`pnpm install`, { cwd, env: { PATH: process.env.PATH } }),
499-
execAsync(`pnpm install`, { cwd: customDir, env: { PATH: process.env.PATH } }),
500-
]);
501-
} else {
502-
const res = await Promise.all([
503-
execAsync(`${nodeBinary} ${pnpmPath} install`, { cwd, env: { PATH: process.env.PATH } }),
504-
execAsync(`${nodeBinary} ${pnpmPath} install`, { cwd: customDir, env: { PATH: process.env.PATH } }),
505-
]);
506-
}
507-
}
490+
async function installDependencies(ctx, cwd, packageManager) {
491+
const command = `${packageManager} install`;
508492

509-
async function installDependenciesNpm(ctx, cwd) {
510-
const isWindows = process.platform === 'win32';
511-
512-
const nodeBinary = process.execPath;
513-
const npmPath = path.join(path.dirname(nodeBinary), isWindows ? 'npm.cmd' : 'npm');
514-
const customDir = ctx.customDir;
515-
if (isWindows) {
516-
const res = await Promise.all([
517-
execAsync(`npm install`, { cwd, env: { PATH: process.env.PATH } }),
518-
execAsync(`npm install`, { cwd: customDir, env: { PATH: process.env.PATH } }),
519-
]);
520-
} else {
521-
const res = await Promise.all([
522-
execAsync(`${nodeBinary} ${npmPath} install`, { cwd, env: { PATH: process.env.PATH } }),
523-
execAsync(`${nodeBinary} ${npmPath} install`, { cwd: customDir, env: { PATH: process.env.PATH } }),
524-
]);
525-
}
493+
await Promise.all([
494+
execAsync(command, { cwd, env: process.env }),
495+
execAsync(command, { cwd: ctx.customDir, env: process.env }),
496+
]);
526497
}
527498

528499
function generateFinalInstructionsPnpm(skipPrismaSetup, options) {
@@ -596,11 +567,7 @@ export function prepareWorkflow(options) {
596567
{
597568
title: '📦 Installing dependencies...',
598569
task: async (ctx) => {
599-
if (options.useNpm) {
600-
await installDependenciesNpm(ctx, ctx.projectDir);
601-
} else {
602-
await installDependenciesPnpm(ctx, ctx.projectDir);
603-
}
570+
await installDependencies(ctx, ctx.projectDir, options.useNpm ? 'npm' : 'pnpm');
604571
}
605572
},
606573
{

0 commit comments

Comments
 (0)