nodejs / nodejs/node

Missing documentation for exports alternative paths

Aperta Adatta ai principianti
#58,600 3 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

doc
Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

Affected URL(s)

https://nodejs.org/api/packages.html

Description of the problem

Packages documentation is really helpful to understand motivations and practical usage of exports, from the simplest setup to nested conditions, wildcards, etc. However, it seems to lack a description and examples of "alternative paths" within exports, which I think is really powerful stuff, but currently underrated and not very popular (maybe because of the lack in documentation).

With "alternative paths" what I mean is using arrays as follows:

{
    "exports": {
        ".": {
            "development": {
                "types": "./src/index.ts",
                "import": "./src/index.js",
                "require": "./src/index.cjs",
                "default": "./src/index.cjs"
            },
            "import": {
                "types": "./types/index.d.ts",
                "default": [
                    "./src/index.js",
                    "./esm/index.js"
                ]
            },
            "require": [
                "./src/index.cjs",
                "./cjs/index.cjs"
            ],
            "default": [
                "./src/index.cjs",
                "./cjs/index.cjs"
            ]
        }
    }
}

The only hint I found in the documentation, is string[] syntax under exports.

Beside that, there are some mentions around:

I think that "alternative paths" is the perfect solution for situations like using your own package without having to build it first during development (e.g., TypeScript, transpiling, polyfilling, etc.)

If there is a spec I would love to update the docs myself.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dalla sezione «exports» della documentazione dei package all’indirizzo nodejs.org/api/packages.html e consulta i riferimenti collegati di Webpack e TypeScript sul comportamento dei percorsi alternativi. Aggiungi una descrizione ed esempi pratici di percorsi di esportazione con valori array, spiegando chiaramente nella documentazione quando si applicano gli esempi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, nodejs
Ambito
documentation
Tipo di issue
Documentazione
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
65/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.