MCPcopy Create free account
hub / github.com/arktypeio/arktype / resolve

Function resolve

ark/aot/host.ts:96–126  ·  view source on GitHub ↗
(specifier: string, importer: string)

Source from the content-addressed store, hash-verified

94 // asks for the same one thousands of times, each a realpath
95 const resolved = new Map<string, string | undefined>()
96 const resolve = (specifier: string, importer: string): string | undefined => {
97 if (!isAbsolute(importer)) return
98 let result = resolver.resolveFileSync(importer, specifier)
99 // a tsconfig the resolver can't load fails every resolution
100 if (result.error && /tsconfig/i.test(result.error)) {
101 resolverWithoutTsconfig ??= resolver.cloneWithOptions(resolveOptions)
102 result = resolverWithoutTsconfig.resolveFileSync(importer, specifier)
103 }
104 // e.g. `@app/schemas` from tests/user.test.ts, where tsconfig.json
105 // includes only src: TypeScript applies its `paths` to no file outside
106 // `include`, but esbuild, Bun and a bundler's alias for the same
107 // names apply them to every file under it, so the nearest's are tried
108 if (!result.path && !opts?.tsconfig && !isRelativeOrAbsolute(specifier)) {
109 const tsconfig = tsconfigIn(dirname(importer))
110 if (tsconfig) {
111 try {
112 // a resolver of its own, as a clone shares what the first found
113 const outside = (resolversByTsconfig[tsconfig] ??=
114 new ResolverFactory({
115 ...resolveOptions,
116 tsconfig: { configFile: tsconfig, references: "auto" }
117 })).resolveFileSync(importer, specifier)
118 if (outside.path) result = outside
119 } catch {
120 // one it can't load, which resolves nothing
121 }
122 }
123 }
124 // it keeps an importer's 8.3 names, which another importer may not have
125 return result.path && realPathOf(result.path)
126 }
127 return {
128 resolve: (specifier, importer) => {
129 const key = `${importer}\0${specifier}`

Callers 15

sourcesOfFunction · 0.70
holdsSkippedSourcesFunction · 0.70
componentsOfFunction · 0.70
checkFunction · 0.70
unprunedMessageOfFunction · 0.70
scriptOfFunction · 0.70
checkImportsFunction · 0.70
resolvedAgainFunction · 0.70
checkNextExternalsFunction · 0.70
checkAliasesFunction · 0.70
constructorMethod · 0.70
visitFunction · 0.70

Calls 4

isRelativeOrAbsoluteFunction · 0.85
tsconfigInFunction · 0.85
realPathOfFunction · 0.85
testMethod · 0.80

Tested by 1

sideFunction · 0.40