Galooshi / import-js

A tool to simplify importing JS modules
MIT License
525 stars 55 forks source link

Import gets not added #463

Open tujoworker opened 7 years ago

tujoworker commented 7 years ago

Hi!

thanks for making this great tool! I found that there is happening something strange.

I made a test repo: https://github.com/tujoworker/import-js-bug

git clone https://github.com/tujoworker/import-js-bug
cd import-js-bug
npm install

I use Atom Editor with the package "import-js" installed.

Once I try to index the sqlite database with the dependencies, noting than the index.js gets added. But once I go into ./node_modules/react-anime/package.json and change:

"main": "dist/anime.min.js",
to (without .min)
"main": "dist/anime.js",

... and I rerun the process to index the database, 'react-anime' gets added. Unfortunately with the name 'reactanime' (Where is this coming from?).

I would be happy if someone knows why the .min version is not supported.

Cordial,

Tobias

trotzig commented 7 years ago

Unfortunately with the name 'reactanime' (Where is this coming from?).

This is the normalized name that we use to match against variable names. It will for match things like ReactAnime & reactAnime. You can make it match Anime as well by adding react- to the ignorePackagePrefixes config option.

The fact that the main isn't properly being indexed is probably because the dist/anime.min.js is minified, and our code to detect exports isn't properly handling this. If you want to help fix this, a good starting point is to add a failing test to https://github.com/Galooshi/import-js/blob/master/lib/__tests__/findExports-test.js. Even if you can't fix the bug, a test case reproducing the issue will help a lot when writing a fix.

tujoworker commented 7 years ago

Nice, thanks so long. What is the best practise link / run this package locally to change and test code? I use Atom (apm link), but maybe this is not the best practise, and a cli setup is better?

trotzig commented 7 years ago

I haven't done much simultaneous development on import-js and atom-import-js at the same time. apm link and npm link might do the trick, you can also try the vim plugin or the sublime plugin, they both use the command-line tool under the hood (atom-import-js doesn't) so an npm link in the import-js project should be enough.

In this case, I think you can TDD the thing and call it done. That's what we've done in other cases when things haven't been properly indexed.