unimported
Advanced tools
Comparing version 1.9.0 to 1.10.0
import { ProcessedResult } from './process'; | ||
import { Context } from './index'; | ||
import { MapLike } from 'typescript'; | ||
export interface UnimportedConfig { | ||
@@ -12,2 +13,4 @@ flow?: boolean; | ||
moduleDirectory?: string[]; | ||
aliases?: MapLike<string[]>; | ||
rootDir?: string; | ||
} | ||
@@ -14,0 +17,0 @@ export declare function expandGlob(patterns: string | string[]): Promise<string[]>; |
@@ -56,3 +56,4 @@ "use strict"; | ||
]); | ||
const aliases = {}; | ||
const config = yield config_1.getConfig(); | ||
let aliases = {}; | ||
// add support for (meteor) root slash import | ||
@@ -70,11 +71,13 @@ aliases['/'] = [`${projectPath}/`]; | ||
if ((_b = tsconfig === null || tsconfig === void 0 ? void 0 : tsconfig.compilerOptions) === null || _b === void 0 ? void 0 : _b.paths) { | ||
const paths = tsconfig.compilerOptions.paths; | ||
const root = path_1.join(projectPath, tsconfig.compilerOptions.rootDir || '.'); | ||
// normalize the aliases. The keys maintain trailing '/' to ease path comparison, | ||
// in: { '@components/*': ['src/components/*'] } | ||
// out: { '@components/': ['src/components/'] } | ||
for (const key of Object.keys(tsconfig.compilerOptions.paths)) { | ||
const alias = key.replace(/\*$/, ''); | ||
aliases[alias] = ensureArray_1.ensureArray(tsconfig.compilerOptions.paths[key]).map((x) => path_1.join(root, x.replace(/\*$/, ''))); | ||
} | ||
aliases = Object.assign(aliases, normalizeAliases(root, paths)); | ||
} | ||
// add support for additional path aliases (in typescript compiler path | ||
// like setup) | ||
if (config === null || config === void 0 ? void 0 : config.aliases) { | ||
const paths = config.aliases; | ||
const root = path_1.join(projectPath, (config === null || config === void 0 ? void 0 : config.rootDir) || '.'); | ||
aliases = Object.assign(aliases, normalizeAliases(root, paths)); | ||
} | ||
return aliases; | ||
@@ -84,2 +87,13 @@ }); | ||
exports.getAliases = getAliases; | ||
// normalize the aliases. The keys maintain trailing '/' to ease path comparison, | ||
// in: { '@components/*': ['src/components/*'] } | ||
// out: { '@components/': ['src/components/'] } | ||
function normalizeAliases(root, paths) { | ||
const aliases = {}; | ||
for (const key of Object.keys(paths)) { | ||
const alias = key.replace(/\*$/, ''); | ||
aliases[alias] = ensureArray_1.ensureArray(paths[key]).map((x) => path_1.join(root, x.replace(/\*$/, ''))); | ||
} | ||
return aliases; | ||
} | ||
function getDependencies(projectPath) { | ||
@@ -86,0 +100,0 @@ return __awaiter(this, void 0, void 0, function* () { |
{ | ||
"name": "unimported", | ||
"version": "1.9.0", | ||
"version": "1.10.0", | ||
"description": "Scans your nodejs project folder and shows obsolete files and modules", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -77,2 +77,25 @@ # unimported | ||
**Custom aliases** | ||
If you wish to use aliases to import your modules & these can't be imported | ||
directly (e.g. `tsconfig.json` in the case of Typescript), there is an option | ||
`aliases` to provide the correct path mapping: | ||
```json | ||
{ | ||
"aliases": { | ||
"@components/*": ["./components", "./components/*"], | ||
... | ||
} | ||
} | ||
``` | ||
_Note:_ you may wish to also add the `rootDir` option to specify the base path to | ||
start looking for the aliases from: | ||
```json | ||
{ | ||
"rootDir": "./src" | ||
} | ||
``` | ||
## Report | ||
@@ -252,2 +275,3 @@ | ||
<td align="center"><a href="http://www.code-root.com/"><img src="https://avatars.githubusercontent.com/u/57859?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lucas Westermann</b></sub></a><br /><a href="https://github.com/smeijer/unimported/commits?author=lswest" title="Code">💻</a> <a href="https://github.com/smeijer/unimported/commits?author=lswest" title="Tests">⚠️</a></td> | ||
<td align="center"><a href="https://github.com/simonwinter"><img src="https://avatars.githubusercontent.com/u/1104537?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Simon Winter</b></sub></a><br /><a href="https://github.com/smeijer/unimported/commits?author=simonwinter" title="Code">💻</a> <a href="https://github.com/smeijer/unimported/commits?author=simonwinter" title="Tests">⚠️</a></td> | ||
</tr> | ||
@@ -254,0 +278,0 @@ </table> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59688
993
284