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

Function unseenProblemOf

ark/aot/scan.ts:635–685  ·  view source on GitHub ↗
(
	scanned: ScannedProgram,
	imports: Imports,
	loaded: LoadedSources,
	// each module creating a validator
	holders: ReadonlySet<string>,
	cwd: string
)

Source from the content-addressed store, hash-verified

633
634// why the bundle may hold a read its scan didn't see, if it may
635export const unseenProblemOf = (
636 scanned: ScannedProgram,
637 imports: Imports,
638 loaded: LoadedSources,
639 // each module creating a validator
640 holders: ReadonlySet<string>,
641 cwd: string
642): string | undefined => {
643 const pathOf = (id: string) =>
644 isAbsolute(id) ? printablePathOf(cwd, id) : id
645 // what any code may import whole: entries, import() targets and modules with no file
646 const whole = new Set([
647 ...scanned.entries,
648 ...scanned.dynamicImports,
649 ...scanned.exposed
650 ])
651 for (const entry of imports.entries) {
652 if (entry === undefined || !(whole.has(entry) || isAsset(entry))) {
653 return writeUnseenMessage(
654 `it built ${entry === undefined ? "an entry" : pathOf(entry)} as an entry`
655 )
656 }
657 }
658 for (const id of imports.modules) {
659 // e.g. esbuild's stdin, which the bundler reads as the scan did
660 if (id === undefined || !scanned.modules[id]?.transformed) continue
661 if (loaded.get(id) !== scanned.modules[id].source) {
662 // a plugin ahead rewrote it after the scan read its file, as
663 // TanStack Router's code splitting does
664 return loaded.has(id) ?
665 writeUnseenMessage(
666 `it built ${pathOf(id)} from other code than it read, as a plugin ahead of arktype's rewrote it after it read its file`,
667 "List precompile.vite() right after your framework's plugin and ahead of react(), a Babel plugin or another that rewrites modules, or set prune: false to build them whole"
668 )
669 : writeUnseenMessage(`another plugin loaded ${pathOf(id)}`)
670 }
671 }
672 const reaching = reachingOf(scanned, holders)
673 for (const [importer, target] of imports.edges) {
674 // e.g. a framework's runtime importing the app's generated config
675 if (!reaching.has(target) || whole.has(target)) continue
676 if (
677 importer === undefined ||
678 !Object.values(scanned.targets[importer] ?? {}).includes(target)
679 ) {
680 return writeUnseenMessage(
681 `${importer === undefined ? "a module it can't read" : pathOf(importer)} imports ${pathOf(target)}`
682 )
683 }
684 }
685}
686
687const reachingOf = (
688 scanned: ScannedProgram,

Callers 2

scanEsbuildBundleFunction · 0.90
prune.test.tsFile · 0.90

Calls 6

isAssetFunction · 0.85
writeUnseenMessageFunction · 0.85
reachingOfFunction · 0.85
pathOfFunction · 0.70
getMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected