0

Guys I'm trying to write a ESlint plugin to sort the import modules based the rules of my company and I ran into this question that I don't know how to determine if an import is an external npm package.

e.g. import _ from 'lodash'; import moment from 'moment';

Thanks.

Joji
  • 4,703
  • 7
  • 41
  • 86
  • You could check against your current user-installed packages https://stackoverflow.com/questions/17937960/how-to-list-npm-user-installed-packages – zfrisch Oct 16 '18 at 22:02
  • @zfrisch thanks but I am trying to check this using JavaScript code – Joji Oct 16 '18 at 22:08
  • do you also want to check if - for example - babel, typescript etc. override node's module resolution? if you don't want to do that, you could simply check for `import moment from './moment'` (=local) or `import moment from 'moment'` (=external) (so just the `./` before the package name). We needs a bit more info. – axm__ Oct 16 '18 at 22:22
  • There is a rule in eslint plugin for imports which is called `order` (https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md). You can take a look how it is implemented there – Volodymyr Oct 16 '18 at 23:54

0 Answers0