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

Function createTrackedPrecompiler

ark/aot/driver.ts:702–787  ·  view source on GitHub ↗
(
	opts: PrecompilePluginOptions,
	resolveInBundler?: BundlerResolver,
	leavesDependencies = false
)

Source from the content-addressed store, hash-verified

700let precompilersInThread = 0
701
702const createTrackedPrecompiler = (
703 opts: PrecompilePluginOptions,
704 resolveInBundler?: BundlerResolver,
705 leavesDependencies = false
706): TrackedPrecompiler => {
707 opts = withSettingsFile(opts)
708 const precompiler = createPrecompiler(opts)
709 precompiler.graph.leavesDependencies = leavesDependencies
710 const tracked: TrackedPrecompiler = {
711 precompiler,
712 host: precompiler.graph.host,
713 readTimes: {},
714 sources: {},
715 targetsByImporter: Object.create(null),
716 missesByImporter: {},
717 tsconfigsByImporter: {},
718 given: {},
719 unsnapshotted: emptySnapshot(undefined),
720 snapshot: undefined,
721 holds: undefined,
722 context: keyOf(opts, !!resolveInBundler, leavesDependencies),
723 asked: false,
724 resolveInBundler,
725 storable: ++precompilersInThread === 1,
726 analyzed: false,
727 forgotten: 0,
728 viewKey: undefined,
729 unread: undefined,
730 opts,
731 hasAnswered: false,
732 importsByFile: {}
733 }
734 const { readTimes, sources, targetsByImporter, tsconfigsByImporter } = tracked
735 precompiler.graph.host = {
736 resolve: (specifier, importer, isValueImport) => {
737 const targets = (targetsByImporter[importer] ??= Object.create(null))
738 if (specifier in targets) return targets[specifier]
739 const target = tracked.host.resolve(specifier, importer)
740 if (target === undefined && resolveInBundler) {
741 // an import that can't carry a Type isn't asked, nor is the miss kept
742 if (isValueImport?.() === false) {
743 const misses = (tracked.missesByImporter[importer] ??= new Set())
744 if (!misses.has(specifier)) {
745 misses.add(specifier)
746 tracked.unsnapshotted.resolutions.push([importer, specifier, null])
747 }
748 return
749 }
750 tracked.asked = true
751 const asked = resolveInBundler(specifier, importer)
752 tracked.unsnapshotted.asked.push([importer, specifier, asked ?? null])
753 return (targets[specifier] = asked)
754 }
755 tracked.unsnapshotted.resolutions.push([
756 importer,
757 specifier,
758 target ?? null
759 ])

Callers 1

trackFunction · 0.85

Calls 12

withSettingsFileFunction · 0.90
emptySnapshotFunction · 0.90
mtimeOfFunction · 0.90
hashOfFunction · 0.90
createPrecompilerFunction · 0.85
readFileMethod · 0.80
tsconfigOfMethod · 0.80
keyOfFunction · 0.70
resolveMethod · 0.65
hasMethod · 0.45
addMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected