import-js icon indicating copy to clipboard operation
import-js copied to clipboard

Properly import packages that end in "js"

Open trotzig opened this issue 9 years ago • 2 comments

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.

trotzig avatar Jul 15 '16 04:07 trotzig

We could generalize the ignore prefixes option.

lencioni avatar Jul 15 '16 05:07 lencioni

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;
},

lencioni avatar Jul 15 '16 15:07 lencioni