Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix installation for non-pnpm package managers #395

Merged
merged 1 commit into from
Jan 12, 2025
Merged
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
35 changes: 21 additions & 14 deletions scripts/init.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ const internalContentFiles = [
const allInternalContent = [...internalContentDirs, ...internalContentFiles];

const runCommand = {
pnpm: 'pnpm',
npm: 'npx',
yarn: 'yarn',
bun: 'bun',
pnpm: 'pnpm create next-app@latest',
npm: 'npx create-next-app@latest',
yarn: 'yarn create next-app@latest',
bun: 'bun create next-app@latest',
};

program
Expand All @@ -57,23 +57,36 @@ program

log(chalk.green('Creating new next-forge project...'));
execSync(
`${runCommand[packageManager]} create next-app@latest ${projectName} --example "${url}" --disable-git`,
`${runCommand[packageManager]} ${projectName} --example "${url}" --disable-git`,
execSyncOpts
);
process.chdir(projectDir);

if (packageManager === 'bun') {
log(chalk.green('Configuring Bun workspaces...'));
if (packageManager !== 'pnpm') {
const packageJsonPath = join(projectDir, 'package.json');
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));

log(chalk.green('Updating package manager configuration...'));

if (packageManager === 'bun') {
packageJson.packageManager = '[email protected]';
} else if (packageManager === 'npm') {
packageJson.packageManager = '[email protected]';
} else if (packageManager === 'yarn') {
packageJson.packageManager = '[email protected]';
}

log(chalk.green('Updating workspace config...'));
packageJson.workspaces = ['apps/*', 'packages/*'];
packageJson.packageManager = '[email protected]';

writeFileSync(
packageJsonPath,
`${JSON.stringify(packageJson, null, 2)}\n`
);

log(chalk.green('Removing pnpm configuration...'));
rmSync('pnpm-lock.yaml', { force: true });
rmSync('pnpm-workspace.yaml', { force: true });
}

log(chalk.green('Deleting internal content...'));
Expand All @@ -98,12 +111,6 @@ program
}
}

if (packageManager !== 'pnpm') {
log(chalk.green('Removing pnpm lockfile and workspace config...'));
rmSync('pnpm-lock.yaml', { force: true });
rmSync('pnpm-workspace.yaml', { force: true });
}

log(chalk.green('Installing dependencies...'));
execSync(`${packageManager} install`, execSyncOpts);

Expand Down
Loading