[RRFC] Add lifecycle hooks that can be mapped to user defined scripts (1:M) in package.json
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- javascript
Direzione di ricerca
Inizia con la sezione hooks proposta di package.json e con l’issue 9384 di npm/cli citata nell’RFC. Esamina come npm analizza attualmente i nomi degli script e gli hook del ciclo di vita, quindi definisci le regole del delimitatore e della risoluzione di pre/post. Il lavoro è completato quando la proposta ha una sintassi concordata, un comportamento di esecuzione e un ambito adatti all’implementazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Motivation ("The Why")
Scripts in package.json oftentimes rely on prior state or context in order to execute as expected. For example, injecting the right .env files to have respective apps not upload things such as test data into production.
Current conventions for most applications handle this in a few ways:
- Manually add an inline variable to the command such as
NODE_ENV={whatever}, or for node 20+ projects use the--env-fileswitch. This gets cumbersome when you need to make 3+ copies of many regular scripts (eg.dev|start|build) and the commands themselves have enough other switches to worry about. - Use external libraries like
dotenvresolve this for them. Any addition of dependencies introduces the classic issues of new surface areas for vulnerabilities, as well as relying on the availability of respective maintainers to update them when contracts change, etc etc. Also, I still haven't found an external dependency that addresses this gap directly.
Example
Allow for an opt-in, zero-dependency solution that gives developers a cleaner, DRYer package.json. Example snippet:
"scripts": {
"serve": "node server.js",
"build": "node scripts/build-client.js"
},
// act as hooks to run before script execution
"hooks": {
"dev": "NODE_ENV=development && NODE_OPTIONS=--env-file=.env.development",
"stg": "NODE_ENV=staging && NODE_OPTIONS=--env-file=.env.staging",
// and so on...
}
and when running in the terminal, the environment keywords will then be parsed for as hooks, delimited by : for example, and then execute those commands "pre" lifecycle hook style.
npm run dev:serve
npm run stg:serve
This kind of functionality can be abstracted to other use cases where pre or post lifecycle hooks can be leveraged for any group of scripts that wants to be decorated by them.
How
Current Behaviour
User generated npm scripts cannot define any pre/before or post/after hooks that can be referenced by their key signature.
Desired Behaviour
User generated npm scripts CAN reference pre/before or post/after hooks that are defined in a new section in package.json, using an agreed upon delimiter such as colon (:). The placement of the hook key, either on the left (pre/before) or on the right (post/after) side of the script executes the hook script that the separated key maps to.
References
- Originally opened as an issue in npm/cli
- Lingua principale
- JavaScript
- Stelle
- 780
- Fork
- 266
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di npm/rfcs
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 38/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
Issue simili
-
docs: add SECURITY.md vulnerability reporting policyForse già presa @AK-Lmn l’ha presa oggi. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 72/100
flisk-sh/linux2wasm#12 ·
I maintainer di solito rispondono entro 1 giorno
-
possible bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
Mintplex-Labs/anything-llm#7388 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 60/100
I maintainer di solito rispondono entro 1 giorno
-
v6: Minified bootstrap.min.css is missing header infoForse già presa @lazerg l’ha presa oggi. Apertabug build confirmed has-pr v6
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
[workshop-sync] workshop/side-quest-26-01-forecast-costs.md: forecast default history window is inaccurateForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertadocumentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
githubnext/gh-aw-workshop#6332 ·
I maintainer di solito rispondono entro 1 giorno