Specify namespace with url in ESM
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à
- Ferma
- Stack tecnologico
- javascript, nodejs
- Ambito
- backend
Direzione di ricerca
Start by reviewing the proposed native ESM URL syntax and the package.json exports idea described in the issue. Determine whether namespace and optional color parameters belong in the library, then define the supported import forms and tests needed to show the behavior is complete.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
When using native esm in Node, it's not possible anymore to use the pattern
const debug = require('debug')('namespace');
and we have to do
import createDebug from 'debug';
const debug = createDebug('namespace');
instead. In one of my projects, I've found myself to use an alternative approach though, where I do something like
import createDebug from 'debug';
const url = new URL(import.meta.url);
const [[namespace]] = url.searchParams;
export default createDebug(namespace);
so that it becomes possible to do stuff like
// In server
import debug from './debug.js?server';
// In worker
import debug from './debug.js?worker';
I was wondering whether it would be useful to have this functionality in the library itself. I'd be happy to clean my code up a bit and file a PR for this. An alternative approach would be to create my own npm module on top of the debug module if it's not desirable to have this in the library itself.
For the syntax, I was thinking about something like
import debug from 'debug/url?namespace'
where debug/url can become an exports in the package.json.
The url approach can be used to add more functionality as well, for example to force a specific color or something:
import createDebug from 'debug';
const url = new URL(import.meta.url);
const [namespace] = [...url.searchParams].find(([key, value]) => value === '');
const debug = createDebug(namespace);
const color = url.searchParams.get('color');
if (color !== null) {
debug.color = color;
}
export default debug;
I'd love to hear some thoughts about this from the maintainers.
- Lingua principale
- JavaScript
- Stelle
- 11.5k
- Fork
- 992
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
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 debug-js/debug
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
-
Debug as JSON Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 28/100
Tutte le issue di debug-js/debug
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Daemon passes --experimental-wasm-jspi unconditionally on Node >= 24; Node 26 rejects the flag Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Automattic/studio#4908 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
sugarlabs/musicblocks#8847 ·