import-js
import-js copied to clipboard
Properly import packages that end in "js"
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.
We could generalize the ignore prefixes option.
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;
},