Skip to content
New issue

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

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

Already on GitHub? # to your account

Fixed Package installation issue with legacy-peer-deps flag #856

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 4 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
"dependencies": {
"@antfu/ni": "^0.21.8",
"@clack/prompts": "^0.7.0",
"@material-ui/core": "^4.12.4",
"@sentry/integrations": "^7.69.0",
"@sentry/node": "^7.69.0",
"chalk": "^5.3.0",
"diff": "^5.1.0"
"diff": "^5.1.0",
"million": "^2.6.4"
},
"scripts": {
"prepare": "node build.mjs",
Expand All @@ -44,6 +46,7 @@
"@types/diff": "^5.0.3",
"@types/gradient-string": "^1.1.2",
"@types/node": "^18.14.1",
"@types/react": "^18.0.27",
"esbuild": "^0.14.54",
"esbuild-plugin-replace": "^1.4.0",
"prettier": "^2.8.4",
Expand Down
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 chalk from 'chalk';
import { abort, abortIfCancelled } from './utils';
import { npm, pnpm, yarn, bun, packageManagers } from './constants';
import type { PackageManager } from '../types';
import { isPackageInstalled } from './package-json';

/**
* Detect package manager by checking if the lock file exists.
Expand All @@ -28,7 +29,7 @@ export async function detectPackageManger(): Promise<PackageManager | null> {
return bun;
default:
return null;
}
}
}

/**
Expand All @@ -37,8 +38,9 @@ export async function detectPackageManger(): Promise<PackageManager | null> {
export function installPackageWithPackageManager(
packageManager: PackageManager,
packageName: string,
flag?:string
): void {
exec(`${packageManager.installCommand} ${packageName}@latest`);
exec(`${packageManager.installCommand} ${packageName}@latest --${flag}`);
}

/**
Expand Down Expand Up @@ -106,7 +108,7 @@ export async function installPackage({
}

const packageManager = await getPackageManager();

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

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