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

Function esbuildScanOf

ark/aot/unplugin.ts:2916–2959  ·  view source on GitHub ↗
(
	build: EsbuildBuild,
	program: string,
	isTransformed: (path: string) => boolean,
	scan: (program: ScannedProgram) => Promise<ScannedUsage>,
	cwd: string
)

Source from the content-addressed store, hash-verified

2914
2915// what a production bundle's validators are read for, if the scan changes what the plugin writes
2916const esbuildScanOf = async (
2917 build: EsbuildBuild,
2918 program: string,
2919 isTransformed: (path: string) => boolean,
2920 scan: (program: ScannedProgram) => Promise<ScannedUsage>,
2921 cwd: string
2922): Promise<ProgramScan<[ScannedProgram, ScannedUsage]>> => {
2923 const entries = await esbuildEntriesOf(build)
2924 if (typeof entries === "string")
2925 return { warnings: [writeUnprunedMessage(entries)] }
2926 const scanned = await scanProgram(program, entries, {
2927 resolve: async (specifier, importer, kind) => {
2928 const result = await build.resolve(specifier, {
2929 kind,
2930 importer,
2931 resolveDir: dirname(importer),
2932 pluginData: esbuildResolution
2933 })
2934 return (
2935 result.errors.length ? undefined
2936 : result.external ? null
2937 : result.namespace === "file" ? result.path
2938 : undefined
2939 )
2940 },
2941 readFile,
2942 isTransformed,
2943 idOf: fileOf,
2944 cwd
2945 })
2946 if (typeof scanned === "string")
2947 return { warnings: [writeUnprunedMessage(scanned)] }
2948 // each entry is its own bundle unless it splits what they share; an
2949 // injected module is unscanned
2950 scanned.isOneChunk =
2951 scanned.entries.length === 1 &&
2952 !build.initialOptions.splitting &&
2953 !build.initialOptions.inject?.length
2954 const usage = await scan(scanned)
2955 return {
2956 read: usage.written ? [scanned, usage] : undefined,
2957 warnings: warningsOf(usage)
2958 }
2959}
2960
2961const esbuildImportsOf = (
2962 metafile: Metafile,

Callers 1

scanEsbuildBundleFunction · 0.85

Calls 6

writeUnprunedMessageFunction · 0.90
scanProgramFunction · 0.90
esbuildEntriesOfFunction · 0.85
scanFunction · 0.85
warningsOfFunction · 0.70
resolveMethod · 0.65

Tested by

no test coverage detected