Missing documentation for exports alternative paths
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- JavaScript
- Estrellas
- 122k
- Forks
- 37.3k
- Merge medio
- 4 d 2 h
- PR fusionados (30 d)
- 283
Descripción
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:
- Webpack's official docs citing Node.js behaviour: https://webpack.js.org/guides/package-exports/#alternatives.
- Notable TypeScript issue requesting aligning to Node.js behaviour: https://github.com/nodejs/node/issues/37928
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con la sección «exports» de la documentación de paquetes en nodejs.org/api/packages.html y revisa las referencias enlazadas de Webpack y TypeScript sobre el comportamiento de las rutas alternativas. Añade una descripción y ejemplos prácticos de rutas de exportación con valores de tipo array, explicando claramente en la documentación cuándo se aplican los ejemplos.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, nodejs
- Área
- documentation
- Tipo de issue
- Documentación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 65/100