chalk/supports-color

Support importing via deno #136

binyamin posted onGitHub

Problem

Currently, Deno imports default to browser.js, because Deno imports use URLs like a browser. browser.js reports "no color" because Deno's user-agent doesn't look like Chromium. Deno is a runtime like Node.js, so index.js is ideal. Using a Deno-friendly CDN, such as esm.sh, index.js would transpile fine.

Solution

Add "deno" to the exports map in the package.json.

{
  "exports": {
     "node": "./index.js", 
        "deno": "./index.js",
     "default": "./browser.js"
  }
}

I'm not really interested in adding special Deno support. Deno is soon going to have close to full Node.js support: https://deno.com/blog/changes#compatibility-with-node-and-npm

posted by sindresorhus over 2 years ago

@sindresorhus How about changing "default" to "browser"? That's more accurate, and doesn't restrict other runtimes to the browser version.

posted by binyamin over 2 years ago

From the Node.js docs:

For this reason, using "node" and "default" condition branches is usually preferable to using "node" and "browser" condition branches.

https://nodejs.org/api/packages.html#conditional-exports

posted by sindresorhus over 2 years ago

Fund this Issue

$0.00
Funded

Pull requests