MCPcopy
hub / github.com/PlasmoHQ/plasmo / attemptResolveArray

Function attemptResolveArray

core/parcel-resolver-post/src/handle-ts-path.ts:162–193  ·  view source on GitHub ↗

Attempt to resolve any path associated with the alias to a file or directory index

(
  from: string,
  alias: string,
  realPaths: TsPaths,
  parentFile: string
)

Source from the content-addressed store, hash-verified

160// TODO support resource loaders like 'url:@alias/my.svg'
161/** Attempt to resolve any path associated with the alias to a file or directory index */
162function attemptResolveArray(
163 from: string,
164 alias: string,
165 realPaths: TsPaths,
166 parentFile: string
167) {
168 for (const option of realPaths) {
169 const absoluteBaseFile = resolve(
170 from.replace(trimStar(alias), trimStar(option))
171 )
172
173 const importExt = extname(absoluteBaseFile)
174
175 if (importExt.length > 0 && relevantExtSet.has(importExt as any)) {
176 return absoluteBaseFile
177 }
178
179 const parentExt = extname(parentFile)
180
181 const checkingExts = [
182 parentExt,
183 ...relevantExtList.filter((ext) => ext !== parentExt)
184 ]
185
186 const mod = findModule(absoluteBaseFile, checkingExts)
187
188 if (mod !== null) {
189 return mod
190 }
191 }
192 return null
193}
194
195type TSConfig = { compilerOptions: CompilerOptions; filePath: string }
196

Callers 1

attemptResolveFunction · 0.85

Calls 4

trimStarFunction · 0.90
findModuleFunction · 0.90
hasMethod · 0.80
resolveFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…