Skip to content
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

fix(npm): Support running npm lifecycle scripts with global resolver #24735

Closed
wants to merge 7 commits into from

Conversation

nathanwhit
Copy link
Member

Closes #16164

This PR adds support for running lifecycle scripts when using the global npm resolver. This allows you to run packages like duckdb (or other install script dependent packages) without having to use a node modules dir.

I only copied two of the tests over because the local and global resolver use pretty much the same code for the script execution.

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should do this for two reasons:

  1. Running lifecycle scripts in the global cache impacts all projects. I think we should leave the global cache the same way that it was downloaded. If we don't, it may lead to confusion because the cache state evolves over time.
  2. Not all, but many lifecycle scripts do things like inspecting the node_modules directory structure or installing stuff. For example, sometimes packages look at what other dependencies are in the node_modules directory and do stuff based on that.

So I think we should require a node_modules directory if someone wants to run lifecycle scripts. It's true that this may net make more things work though.

Copy link
Member

@dsherret dsherret Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One idea we may want to consider is creating a folder in the cache directory beside the package folder and have the new folder contain the original package. Then we run install scripts in the original folder. Then if someone is using a node_modules directory, we always pull from the cache folder with the original package instead of the one that had post-install scripts run in it.

That said, I'm still a bit concerned about some post install scripts causing havoc in the global cache and the fact that it affects all programs. Maybe not a big deal though?

This also affecting the global state of how Deno works across all programs is also not too great, but it's maybe better than not working at all (though that may lead to confusion when something doesn't work on one person's machine or the CI, but it does on another).

@marvinhagemeister
Copy link
Contributor

FYI: Another package that needs to run lifecycle scripts is sqlite3 without it, it just breaks with a binding not found error. It installs the actual sqlite bindings in a postinstall script.

@nathanwhit nathanwhit marked this pull request as draft August 3, 2024 01:06
@nathanwhit
Copy link
Member Author

Closing in favor of #25786

@nathanwhit nathanwhit closed this Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for install scripts (ex. "postinstall") for "npm:" specifiers with global node modules
3 participants