Fix postinstall script to support non-Yarn package managers#806
Fix postinstall script to support non-Yarn package managers#806sumomo015 wants to merge 2 commits intopostmanlabs:developfrom
Conversation
|
As English is not my native language, this PR description was generated with the assistance of AI. |
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where the postinstall script fails to correctly detect the package manager when using pnpm or npm in environments where Yarn is also installed globally. The fix ensures proper package manager detection by passing the INIT_CWD environment variable to the detect() function.
- Reads the
INIT_CWDenvironment variable to capture the initial working directory - Passes the
cwdoption to the package manager detection function for accurate identification
Comments suppressed due to low confidence (1)
npm/deepinstall.js:28
- Missing error handling for the promise rejection. If the
detect()function fails, the promise rejection will not be caught, leaving the script hanging or causing an unhandled promise rejection. Add a.catch()handler to properly handle errors and callnext()with the error.
detect({ cwd: initCwd }).then((res) => {
pm = res;
console.log('Detected package manager: ' + pm);
return next();
});
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I'd appreciate this! I had bumped into this issue before in #780 and #781 aimed to address it but I continue to face the issue (I mistakenly thought it was fixed, but turns out it still happens occasionally, probably due to our cache system for CI images that doesn't always trigger the One alternative solution would be to swap detect-package-manager for package-manager-detector), since the former seems to be kind of abandoned and the latter has become significantly more popular despite being newer. |
Description
Fixes #792
This PR resolves an issue where the postinstall script fails when using package managers other than Yarn (such as pnpm or npm) in environments where Yarn is also installed globally.
Problem
The current postinstall script in
npm/postinstall.jsattempts to detect the package manager being used, but fails to properly identify non-Yarn package managers when Yarn is installed globally. This causes the installation to fail with errors when users try to installpostman-code-generatorsusing pnpm or npm.Solution
Set the
INIT_CWDenvironment variable during package manager detection to ensure the script correctly identifies the package manager being used, regardless of whether Yarn is installed globally.Reproduction Steps (Before Fix)
docker build -t bug .Result: The build fails when trying to install
postman-code-generatorswith pnpm.