MCPcopy
hub / github.com/triggerdotdev/trigger.dev / getPathAlias

Function getPathAlias

packages/cli/src/utils/pathAlias.ts:13–55  ·  view source on GitHub ↗
({
  projectPath,
  isTypescriptProject,
  extraDirectories,
}: Options)

Source from the content-addressed store, hash-verified

11// }
12// In this case, we would return "@"
13export 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}

Callers 4

pathAlias.test.tsFile · 0.90
installMethod · 0.90
installMethod · 0.90
installMethod · 0.90

Calls 4

pathExistsFunction · 0.90
findMethod · 0.80
keysMethod · 0.80
sliceMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…