({
projectPath,
isTypescriptProject,
extraDirectories,
}: Options)
| 11 | // } |
| 12 | // In this case, we would return "@" |
| 13 | export async function getPathAlias({ |
| 14 | projectPath, |
| 15 | isTypescriptProject, |
| 16 | extraDirectories, |
| 17 | }: Options) { |
| 18 | const configFileName = isTypescriptProject ? "tsconfig.json" : "jsconfig.json"; |
| 19 | const tsConfigPath = pathModule.join(projectPath, configFileName); |
| 20 | const configFileExists = await pathExists(tsConfigPath); |
| 21 | |
| 22 | //no config and javascript, no alias |
| 23 | if (!isTypescriptProject && !configFileExists) { |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | const { tsconfig } = await parse(tsConfigPath); |
| 28 | |
| 29 | const paths = tsconfig?.compilerOptions?.paths; |
| 30 | if (paths === undefined) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | const alias = Object.keys(paths).find((key) => { |
| 35 | const value = paths[key]; |
| 36 | |
| 37 | if (value.length === 0) { |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | const path = value[0]; |
| 42 | if (extraDirectories && extraDirectories.length > 0) { |
| 43 | return path === `./${extraDirectories.join("/")}/*`; |
| 44 | } else { |
| 45 | return path === "./*"; |
| 46 | } |
| 47 | }); |
| 48 | |
| 49 | // Make sure to remove the trailing "/*" |
| 50 | if (alias) { |
| 51 | return alias.slice(0, -2); |
| 52 | } |
| 53 | |
| 54 | return; |
| 55 | } |
no test coverage detected
searching dependent graphs…