-
Notifications
You must be signed in to change notification settings - Fork 245
RFC: Add preunpack
life cycle script
#403
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
Open
ryansonshine
wants to merge
2
commits into
npm:main
Choose a base branch
from
ryansonshine:preunpack
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# RFC: Add `preunpack` life cycle script | ||
|
||
## Summary | ||
|
||
Add a `preunpack` life cycle script that runs before anything else. | ||
|
||
## Motivation | ||
|
||
npm v7 introduced a new order of running the `preinstall` script, where it runs **after** dependencies are installed, breaking backward compatibility with packages expecting to run a script **before** dependencies are installed. | ||
|
||
By introducing a new life cycle script that will run first in the execution order, we can give a path forward to packages that require a script to run **before** dependencies are installed. | ||
|
||
Use cases: | ||
|
||
* Handling authentication for private registries with short-lived tokens (i.e., AWS, GCP, Azure) | ||
* Generating workspaces from gRPC proto files before workspaces and dependencies get evaluated. | ||
|
||
## Detailed Explanation | ||
|
||
A `preunpack` life cycle script that is **first** in execution order: | ||
|
||
* Runs on local `npm install` without any arguments | ||
* Runs on non-local `npm install` (from a package being unpacked) | ||
* Runs on `npm ci` | ||
|
||
Example usage in the case of handling authentication for AWS CodeArtifact: | ||
|
||
```json | ||
{ | ||
"name": "my-app", | ||
"version": "1.0.0", | ||
"description": "A sample application consuming a private scoped npm package", | ||
"main": "index.js", | ||
"scripts": { | ||
"preunpack": "npm run co:login", | ||
"co:login": "aws codeartifact login --tool npm --repository my-repo --domain my-domain" | ||
}, | ||
"dependencies": { | ||
"@myorg/my-package": "^1.0.0" | ||
} | ||
} | ||
``` | ||
|
||
When running `npm install`, the `npm run co:login` will be run before any dependencies are installed. | ||
|
||
## Rationale and Alternatives | ||
|
||
### Implement a separate top level "events" field | ||
|
||
The idea here would be to implement a top-level "events" field to keep the current behavior of "scripts" while providing a better implementation elsewhere as described in [this comment](https://github.com/npm/cli/issues/2660#issuecomment-794415767). | ||
|
||
This approach would undoubtedly address the use cases outlined above, but the scope may be too large when we need a quicker stop-gap for the interim. | ||
|
||
### Revert back to the `preinstall` functionality from versions before v7 | ||
|
||
See [Unresolved Questions and Bikeshedding](#unresolved-questions-and-bikeshedding). | ||
|
||
## Implementation | ||
|
||
<!-- Give a high-level overview of implementation requirements and concerns. Be specific about areas of code that need to change, and what their potential effects are. Discuss which repositories and sub-components will be affected, and what its overall code effect might be. --> | ||
|
||
<!-- THIS SECTION IS REQUIRED FOR RATIFICATION -- you can skip it if you don't know the technical details when first submitting the proposal, but it must be there before it's accepted --> | ||
|
||
## Prior Art | ||
|
||
* npm v6 | ||
|
||
## Unresolved Questions and Bikeshedding | ||
|
||
* Are there any security implications with this approach? | ||
* Are we sure we don't want to revert back to the `preinstall` functionality of npm v6? | ||
|
||
<!-- THIS SECTION SHOULD BE REMOVED BEFORE RATIFICATION --> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.