cypress-cucumber-preprocessor
cypress-cucumber-preprocessor copied to clipboard
fix: prevent postinstall script from running when installed as dependency using pnpm
The postinstall script runs patch-package even when the package is installed as a dependency, causing installation failures for users who don't have patch-package installed in their projects. This issue is particularly evident when using pnpm, which handles module isolation more strictly.
Problem:
The postinstall script attempts to run patch-package, which isn't available in user projects, causing installation to fail. The workaround is for the user to add patch-package as a top-level dev-dependency in their own project.
Solution:
This fix updates patches/patch.js to check if the script is running inside a node_modules directory. If it is, the script assumes it's being installed as a dependency and skips running patch-package.
Compatibility:
Tested with npm, pnpm, and yarn. The fix works across all package managers.
Testing:
- Verified that
postinstallruns during local development. - Confirmed that installation succeeds without errors in a test project.
Hey @badeball - I read your proposal in cucumber's repo. Would you still consider completing this PR to unblock pnpm users?
Would you still consider completing this PR to unblock pnpm users?
This would at the very least have to test the mentioned package managers. Preferably using a different jobs to test latest version of each, using one of the examples.
I'm also not a fan of the heuristics implemented here. You're removing the possibility of working inside a node_modules directory. While I don't do this myself, I see no reason for why this library should not allow it.
Edit: Scratch this - as this will exclusively affect developers of the library, ie. me only.
I tried using pnpm to install dependencies of one of the examples (esbuild-cjs) and it runs seemingly fine and without errors. What issue have you observed?