evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
38.09k stars 1.14k forks source link

Question: `alias` doesnt match against the whole import (but replaces partials too) #2963

Closed mhsdesign closed 1 year ago

mhsdesign commented 1 year ago

in webpack (4) i was able to sucessfully use their "resolve" feature to archive the following: mapping my imports to a shim.

{
    "redux-saga/effects": "@neos-project/neos-ui-extensibility/dist/shims/vendor/redux-saga-effects/index",
    "redux-saga": "@neos-project/neos-ui-extensibility/dist/shims/vendor/redux-saga/index",
}

i personally would expect that this map would also work with the esbuild alias feature. But my assumption is wrong, i thought redux-saga would be handled like this /^redux-saga\/?$/ but the import is also replaced for this case:

import { take } from "redux-saga/effects"

will become

import { take } from "@neos-project/neos-ui-extensibility/dist/shims/vendor/redux-saga/index/effects"

(which i dindt anticipate for now)

it seems my first alias redux-saga/effects is not used but redux-saga will take effect and the effects subfolder/file is appended ...

maybe its a feature though ^^ i mean i could just adjust my code, but wanted to ask if this behaviour is intended.

evanw commented 1 year ago

Thanks for the report. This is actually a determinism issue as esbuild stops when it encounters the first match instead of checking all of them and taking the longest match. So this is definitely a bug with esbuild.

mhsdesign commented 1 year ago

Thank you for fixing it and your efforts ❤️