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

Function keptAcross

ark/aot/driver.ts:1012–1060  ·  view source on GitHub ↗
(
	tracked: TrackedPrecompiler,
	opts: PrecompilePluginOptions,
	// what the bundler resolved, as the precompiler learned it
	resolveLearned?: (specifier: string, importer: string) => string | undefined
)

Source from the content-addressed store, hash-verified

1010// changed, unless a change may reach past them, as a new resolution, setting
1011// or package does, or it may hold more it forgot than it reads
1012const keptAcross = (
1013 tracked: TrackedPrecompiler,
1014 opts: PrecompilePluginOptions,
1015 // what the bundler resolved, as the precompiler learned it
1016 resolveLearned?: (specifier: string, importer: string) => string | undefined
1017): TrackedPrecompiler | undefined => {
1018 const { precompiler, readTimes } = tracked
1019 if (
1020 (tracked.asked && !resolveLearned) ||
1021 tracked.forgotten > Object.keys(readTimes).length ||
1022 JSON.stringify(withSettingsFile(opts)) !== JSON.stringify(tracked.opts)
1023 )
1024 return
1025 const host = createNodeHost(tracked.opts)
1026 const resolvesAs = (specifier: string, importer: string, target?: string) =>
1027 (host.resolve(specifier, importer) ??
1028 resolveLearned?.(specifier, importer)) === target
1029 for (const importer in tracked.targetsByImporter) {
1030 const targets = tracked.targetsByImporter[importer]
1031 for (const specifier in targets)
1032 if (!resolvesAs(specifier, importer, targets[specifier])) return
1033 }
1034 for (const importer in tracked.missesByImporter) {
1035 for (const specifier of tracked.missesByImporter[importer])
1036 if (!resolvesAs(specifier, importer)) return
1037 }
1038 for (const importer in tracked.tsconfigsByImporter) {
1039 if (host.tsconfigOf?.(importer) !== tracked.tsconfigsByImporter[importer])
1040 return
1041 }
1042 const changed = Object.keys(readTimes).filter(
1043 file => readTimes[file] !== mtimeOf(file)
1044 )
1045 const forgotten = precompiler.forget(changed)
1046 if (!forgotten) return
1047 tracked.forgotten += forgotten.length
1048 for (const file of changed) {
1049 delete readTimes[file]
1050 delete tracked.sources[file]
1051 delete tracked.given[file]
1052 }
1053 tracked.host = host
1054 tracked.holds = undefined
1055 if (changed.length) tracked.storable = false
1056 // a build reads its own program, if any
1057 precompiler.readProgram(undefined)
1058 tracked.viewKey = tracked.unread = undefined
1059 return tracked
1060}
1061
1062type Resolution = [importer: string, specifier: string, target: string | null]
1063

Callers 2

answerFunction · 0.85
precompileFunction · 0.85

Calls 8

withSettingsFileFunction · 0.90
createNodeHostFunction · 0.90
mtimeOfFunction · 0.90
resolvesAsFunction · 0.85
tsconfigOfMethod · 0.80
filterMethod · 0.80
readProgramMethod · 0.80
forgetMethod · 0.45

Tested by

no test coverage detected