( build: EsbuildBuild, program: string, isTransformed: (path: string) => boolean, scan: (program: ScannedProgram) => Promise<ScannedUsage>, cwd: string )
| 2914 | |
| 2915 | // what a production bundle's validators are read for, if the scan changes what the plugin writes |
| 2916 | const 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 | |
| 2961 | const esbuildImportsOf = ( |
| 2962 | metafile: Metafile, |
no test coverage detected