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: Fixed the million package installation by adding choice to use legacy-peer-deps flag. #857

Merged
merged 6 commits into from
Dec 29, 2023
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
39 changes: 36 additions & 3 deletions packages/cli/src/utils/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { abort, abortIfCancelled } from './utils';
import { npm, pnpm, yarn, bun, packageManagers } from './constants';
import type { PackageManager } from '../types';
import { isPackageInstalled } from './package-json';

Check warning on line 10 in packages/cli/src/utils/package-manager.ts

View workflow job for this annotation

GitHub Actions / build (19.x)

`./package-json` import should occur before import of `../types`

/**
* Detect package manager by checking if the lock file exists.
Expand All @@ -28,7 +29,7 @@
return bun;
default:
return null;
}
}
}

/**
Expand All @@ -37,8 +38,9 @@
export function installPackageWithPackageManager(
packageManager: PackageManager,
packageName: string,
flag = ''
): void {
exec(`${packageManager.installCommand} ${packageName}@latest`);
exec(`${packageManager.installCommand} ${packageName}@latest ${flag}`);
}

/**
Expand Down Expand Up @@ -106,7 +108,7 @@
}

const packageManager = await getPackageManager();

const s = clack.spinner();
s.start(
`${alreadyInstalled ? 'Updating' : 'Installing'} ${chalk.bold.cyan(
Expand All @@ -116,13 +118,44 @@

try {
installPackageWithPackageManager(packageManager, packageName);

await sleep(1000);

const installed = await isPackageInstalled()

if(!installed) {

s.stop();

const shouldUseLegacyPeerDeps = await clack.confirm({
message: `The ${chalk.bold.cyan(
packageName,
)} package did not install, would you like to use the "--legacy-peer-deps" flag?`,
})

if (!shouldUseLegacyPeerDeps) {
throw new Error('Please try again or refer docs to install manually: https://million.dev/docs/install')
}

installPackageWithPackageManager(packageManager, packageName, '--legacy-peer-deps');

s.start(
`${alreadyInstalled ? 'Updating' : 'Installing'} ${chalk.bold.cyan(
packageName,
)} with ${chalk.bold(packageManager.label)} and the "--legacy-peer-deps" flag.`,
);

await sleep(1000);

}

s.stop(
`${alreadyInstalled ? 'Updated' : 'Installed'} ${chalk.bold.cyan(
packageName,
)} with ${chalk.bold(packageManager.label)}.`,
);


} catch (e) {
clack.log.error(
`${chalk.red('Error during installation.')}\n\n${chalk.dim(
Expand Down
Loading