Frontmatter for inline scripts
Personne n'a encore pris cette issue.
- Langage dominant
- JavaScript
- Étoiles
- 122k
- Forks
- 37.3k
- Merge moyen
- 4 j 2 h
- PR mergées (30 j)
- 283
Description
What is the problem this feature will solve?
Taking inspiration from nix, cargo, and python I would like a way for stand-alone scripts to embed configuration normally passed via package.json, node.config.json, argv, or wrapper scripts.
https://github.com/nodejs/node/issues/59565 asks to support typescript-module in extensionless files but proposals for #!/usr/bin/env node --ext mts were rejected because many systems don't support multi-word shebangs.
I don't think this limitation is exclusive to that --ext use cases, there are other options including --permission that cannot be set in a self contained script, yes you can use .env, node.config.json, or package.json but that's no-longer self contained.
This would also be an interesting integration point for package managers that could read dependencies from the frontmatter and support npm x ./script to install the script's inline dependencies.
https://nixos.wiki/wiki/Nix-shell_shebang
https://rust-lang.github.io/rfcs/3424-cargo-script.html
https://packaging.python.org/en/latest/specifications/inline-script-metadata/
What is the feature you are proposing to solve the problem?
The rough outline is for node to parse a leading comment in the main entry point and read command line arguments,
node.config, and package.json fields. The comment would only be read in the main entry point and would sit after explicit options in priority.
#!/usr/bin/env node
// ```node.config.json
// {
// "nodeOptions": { "ext": "mts" },
// "permission": {},
// }
// ```
await main(process.argv.slice(2))
async function main(args: string[]) {
console.log(args)
}
What alternatives have you considered?
Today I'll create directories with package.jsonuse .mts file extensions, or use nasty tricks to combine shell and ts into a single script
#!/bin/sh
':' // ; exec node --ext mts
// script goes here
let n: number = 1;
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Aucun fichier d’implémentation ni test n’est nommé. Commencez par comparer le format proposé avec les références liées de Node.js, Nix, Cargo et Python, puis déterminez comment le frontmatter doit interagir avec les options explicites, package.json, node.config.json et argv ; « done » nécessite qu’une syntaxe et un comportement soient convenus avant de pouvoir commencer l’implémentation.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, node.js, typescript
- Domaine
- cli, developer-experience
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- Calme
- Clarté
- À clarifier
- Accessibilité débutants
- 30/100