MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / resolveTsPathAlias

Function resolveTsPathAlias

lib/utils/typescript.js:30–57  ·  view source on GitHub ↗

* Resolve TypeScript path alias to actual file path * @param {string} importPath - Import path with alias (e.g., '#config/urls') * @param {object} tsConfig - Parsed tsconfig.json * @param {string} configDir - Directory containing tsconfig.json * @returns {string|null} - Resolved file path or nul

(importPath, tsConfig, configDir)

Source from the content-addressed store, hash-verified

28 * @returns {string|null} - Resolved file path or null if not an alias
29 */
30function resolveTsPathAlias(importPath, tsConfig, configDir) {
31 if (!tsConfig || !tsConfig.compilerOptions || !tsConfig.compilerOptions.paths) {
32 return null
33 }
34
35 const paths = tsConfig.compilerOptions.paths
36
37 for (const [pattern, targets] of Object.entries(paths)) {
38 if (!targets || targets.length === 0) {
39 continue
40 }
41
42 const patternRegex = new RegExp(
43 '^' + pattern.replace(/\*/g, '(.*)') + '$'
44 )
45 const match = importPath.match(patternRegex)
46
47 if (match) {
48 const wildcard = match[1] || ''
49 const target = targets[0]
50 const resolvedTarget = target.replace(/\*/g, wildcard)
51
52 return path.resolve(configDir, resolvedTarget)
53 }
54 }
55
56 return null
57}
58
59/**
60 * Transpile TypeScript files to ES modules with CommonJS shim support

Callers 1

transpileFileAndDepsFunction · 0.85

Calls 1

entriesMethod · 0.80

Tested by

no test coverage detected