tsconfig-paths
tsconfig-paths copied to clipboard
Exact patterns should match before asterisk patterns
With a config like this:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"app/utils": ["vendor/utils"],
"app/*": ["src/*"]
}
}
}
When someone imports app/utils, it should first do an exact match and resolve to "vendor/utils" before trying asterisk patterns sorted by the longest prefix. See microsoft/typescript. Note that the order of the patterns should not matter.
Currently, tsconfig-paths only finds the first match in the order of longest prefix. Patterns that don't have an asterisk, have a prefix length of 0, so they get matched after all patterns with asterisks in them.
What about supporting what webpack does?
https://webpack.js.org/configuration/resolve/#resolvealias
A trailing $ can also be added to the given object's keys to signify an exact match:
const path = require('path');
module.exports = {
//...
resolve: {
alias: {
xyz$: path.resolve(__dirname, 'path/to/file.js'),
},
},
};