Galooshi / import-js

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

Properly import packages that end in "js" #309

Open trotzig opened 8 years ago

trotzig commented 8 years ago

At Brigade, we have this in our .importjs.json config:

  "aliases": {
    "Raven": "raven-js",
    "Uri": "urijs",
  },

If we simply would ignore the "js" part of a package, these could be automatically imported and wouldn't have to be part of the aliases configuration.

lencioni commented 8 years ago

We could generalize the ignore prefixes option.

lencioni commented 8 years ago

I wonder if we could generalize it in a way that would allow us to also handle aliases like "cx": "classnames". Not sure about the naming, but maybe something like:

packageNameAlternatives({ packageName }) {
  const alternatives = [];

  const prefix = 'my-prefix-';
  if (packageName.startsWith(prefix)) {
    alternatives.push(packageName.slice(prefix.length));
  }

  const suffix = '-js';
  if (packageName.endsWith(suffix)) {
    alternatives.push(packageName.slice(0, 0 - prefix.length));
  }

  if (packageName === 'classnames') {
    alternatives.push('cx');
  }

  return alternatives;
},