chase-moskal / importly

import map generator
MIT License
58 stars 5 forks source link

support package.json "exports" #37

Open chase-moskal opened 1 year ago

chase-moskal commented 1 year ago

i think importly currently only works with the "main" field, eg, "main": "./x/index.js" — iirc, we also support "module" field...

we really should add support all this newfangled "exports" field

i'm pretty sure importly will fail to provide a correct importmap for packages that are using this standard..

amazingly, despite it apparently being around since node 12, i haven't personally encountered this problem in the wild yet, but i recently learned about tsconfig nodenext, and that led to this, so i've been thinking about this lately..

five minutes later...

yikes, there's also all this crazy "imports" field stuff too...
do we need this also? i mean there's #dep syntax and wildcards/*.js :scream:

why did they have to do this to me? :skull:

i think i'm going to ignore and procrastinate this issue until the exact last microsecond before some important package i rely on forces me to implement this in order to use it. for now, i'll stick to "main", and for anything outside that, i'll reference the damn .js manually..

eg, @benev/construct/mini might have to be @benev/construct/x/mini.js as a workaround...

meanwhile, if any damn package in my dependency graph requires the funky "import" field mappings in order to work, everything will explode... yikes man.. you know, the nodejs team better have made library that can magically handle all this funky stuff or my head will explode..

lukeed's resolve.exports!! :clap: :clap:

configurable "exports" and "imports" resolver

hell yeah!! it even does the imports!?!?! :sunglasses: :sunglasses:

if this fella did this not in an official capacity for the nodejs team — then that's negligent malpractice on node's part — and this guy deserves a gold medal and a briefcase full of money :laughing:

chase-moskal commented 12 months ago

yo, i think i also need to add support for browser package.json field https://docs.npmjs.com/cli/v10/configuring-npm/package-json#browser

chase-moskal commented 12 months ago

linked issue about browser field support in import maps https://github.com/WICG/import-maps/issues/296

chase-moskal commented 11 months ago

fyi, we encountered a package in the wild that uses this fancy export stuff (which importly doesn't currently support)

@ffmpeg/ffmpeg — you can see in their package.json

  "exports": {
    ".": {
      "types": "./dist/esm/index.d.ts",
      "node": "./dist/esm/empty.mjs",
      "default": {
        "import": "./dist/esm/index.js",
        "require": "./dist/umd/ffmpeg.js"
      }
    }
  },

so the current workaround, to get your app working now, is to manually directly import the es module in your app:

import {FFmpeg} from "@ffmpeg/ffmpeg/dist/esm/index.js"