lukeed/resolve.exports

Should subpath mapping/pattern support conditions?

yyx990803 opened this issue ยท 4 comments

Example:

{
  "exports": {
    ".": {
      "import": "./main.js",
      "require": "./cjs.js"
    },
    "./dir-mapped/": {
      "import": "./dir/",
      "require": "./dir-cjs/"
    }
  }
}

The docs doesn't really specify this, but I think it makes sense. /cc @MylesBorins

Oh interesting. I'd never seen this but agree that it makes sense.
(I'm assuming you're referring to "./dir-mapped/" specifically.)

Just confirmed that it works in Node.js too (12.18, 14.15 โ€“ but not 12.14), so I think it was intended.
If @MylesBorins can confirm that's officially supported, I'll go ahead and implement this to maintain parity.

This is the only blocker for Vite to switch to use this package - great job!

Conditions were aways supported for subpath folders. v12.17.0 was the version of 12.x where we unflagged ESM, as such it can be expected that if you are using ESM unflagged today subpath folder mapping with conditions will be supported.

That said we have deprecated subpath folder mapping encouraging developers to instead use subpath patterns, which can do everything that subpath folder mapping can do and more.

Subpath patterns landed in v12.20.0 and v14.13.0.

Thank you Myles :) Both are supported here, just to make it easy. The bit for subpath folder mapping is easy to remove at a later date.

With that confirmation, I went ahead and added this missing piece. Will publish a patch version now.
Thanks!