-
-
Notifications
You must be signed in to change notification settings - Fork 31
feat(dep-manager): introduce
#270
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
Conversation
|
A very popular library that does something similar is ni, but if you only need the part that detects the package manager, you can use package-manager-detector, which is what ni uses internally. It might be worth taking a look at how they implemented it, since there are some edge cases covered there. We could handle the same scenarios ourselves, or use the library directly if you prefer. |
|
Why not good idea never heard of theses package. But I need to see if there are compatible with JSSG |
| export const detectPackageManager = (): 'npm' | 'yarn' | 'pnpm' => { | ||
| try { | ||
| console.log('Checking for yarn.lock file'); | ||
| accessSync('yarn.lock'); | ||
| console.log('Detected yarn.lock file'); | ||
| return 'yarn'; | ||
| } catch {} | ||
|
|
||
| try { | ||
| accessSync('pnpm-lock.yaml'); | ||
| return 'pnpm'; | ||
| } catch {} | ||
|
|
||
| return 'npm'; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we use a dependency that does this for us?
| export const removeDependency = ( | ||
| dependency: string, | ||
| stdio: StdioOptions = 'inherit', | ||
| ): void => { | ||
| const packageManager = detectPackageManager(); | ||
| let command = ''; | ||
|
|
||
| switch (packageManager) { | ||
| case 'npm': | ||
| command = `npm uninstall ${dependency}`; | ||
| break; | ||
| case 'yarn': | ||
| command = `yarn remove ${dependency}`; | ||
| break; | ||
| case 'pnpm': | ||
| command = `pnpm remove ${dependency}`; | ||
| break; | ||
| } | ||
|
|
||
| execSync(command, { stdio }); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is vulnerable to Remote Code Execution via a malicious package name.
|
close in favor of #256 |
No description provided.