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

Method resolve

ark/aot/graph.ts:1283–1319  ·  view source on GitHub ↗
(
		specifier: string,
		importer: SourceModule,
		isValueImport?: () => boolean
	)

Source from the content-addressed store, hash-verified

1281 }
1282
1283 resolve(
1284 specifier: string,
1285 importer: SourceModule,
1286 isValueImport?: () => boolean
1287 ): ImportTarget | SourceModule {
1288 if (specifier in arktypeNamespacesBySpecifier) {
1289 return {
1290 kind: "arktypeNamespace",
1291 specifier,
1292 value: arktypeNamespacesBySpecifier[specifier]
1293 }
1294 }
1295 const id = this.host.resolve(specifier, importer.id, isValueImport)
1296 if (!id) {
1297 return {
1298 kind: "unresolved",
1299 message: `\`${specifier}\` cannot be resolved from ${importer.path}`
1300 }
1301 }
1302 if (!this.isFollowed(id)) {
1303 // one defining Types, so the fix is to precompile it with the program
1304 const [, name] = dependencyOf(id) ?? []
1305 return {
1306 kind: "package",
1307 message:
1308 !name || !this.importsArktype(id) || this.readsOnlyRuntime(id) ?
1309 `\`${specifier}\` is a package the build does not read`
1310 : this.leavesDependencies ?
1311 `\`${specifier}\` is a package ark emit leaves to Node, though ${specifier === name ? "it" : name} imports arktype`
1312 : `\`${specifier}\` is a package the build does not read, though ${specifier === name ? "it" : name} imports arktype`
1313 }
1314 }
1315 const imports = (this.importsById[importer.id] ??= [])
1316 if (!imports.includes(id)) imports.push(id)
1317 this.modulesById[id] ??= this.load(id, specifier)
1318 return this.modulesById[id]
1319 }
1320
1321 // e.g. @hono/arktype-validator, reading only `type.errors`
1322 readsOnlyRuntime(file: string): boolean {

Callers 6

resolvesLocallyMethod · 0.95
importOfMethod · 0.95
exportOfMethod · 0.95
typeImportTargetOfMethod · 0.95
findExportedTypeMethod · 0.95
targetKindOfMethod · 0.95

Calls 7

isFollowedMethod · 0.95
importsArktypeMethod · 0.95
readsOnlyRuntimeMethod · 0.95
loadMethod · 0.95
dependencyOfFunction · 0.90
resolveMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected