ilearnio / module-alias

Register aliases of directories and custom module paths in Node
MIT License
1.76k stars 69 forks source link

Does it intentionally matches partials? #6

Closed alexFaunt closed 8 years ago

alexFaunt commented 8 years ago

Hi,

I started to use this to alias 'react' to 'node_modules/preact-compat' but that has the side effect of matching 'react-router' to 'node_modules/preact-compat/-router'

Line 25 matches if the module starts with the alias or not request.indexOf(alias) === 0 an exact match fixes my problem as in request === alias

Or is it intentional that it matches partials too?

Cheers

ilearnio commented 8 years ago

Hi @alexFaunt. I believe you need to remove the "node_modules/" from the beginning of the target string. The alias should look like "react-router": "preact-compat/-router"

alexFaunt commented 8 years ago

Hi @ilearnio In my use case I don't want it to replace 'react-router' with anything. I want 'react' to be replaced with 'preact-compat' and 'react-router' to remain as it is.

But as it just matches the start of the string it replaces both and breaks the react-router import.

ilearnio commented 8 years ago

I just fixed this issue and updated the npm package to v2.0.0 (since it's a breaking change). Try to upgrade and please leave a note if it works well for you now.

alexFaunt commented 8 years ago

👍 Perfect, thanks