Skip to content

Conversation

@AugustinMauroy
Copy link
Member

No description provided.

@AugustinMauroy AugustinMauroy added the awaiting reviewer Author has responded and needs action from the reviewer label Nov 8, 2025
@brunocroh
Copy link
Member

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.

@AugustinMauroy
Copy link
Member Author

Why not good idea never heard of theses package. But I need to see if there are compatible with JSSG

Comment on lines +8 to +22
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';
};
Copy link
Member

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?

i.e. https://www.npmjs.com/package/detect-package-manager?

Comment on lines +24 to +44
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 });
};
Copy link
Member

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.

@AugustinMauroy
Copy link
Member Author

close in favor of #256

@AugustinMauroy AugustinMauroy deleted the augustin/package-management-utilty branch December 13, 2025 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviewer Author has responded and needs action from the reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants