( build: EsbuildPluginBuild, program: string, scan: EsbuildScanState, esbuildResolve: BundlerResolve, cwd: string )
| 1182 | } |
| 1183 | // the scan's facts hold only while the bundle is what it read |
| 1184 | const scanEsbuildBundle = ( |
| 1185 | build: EsbuildPluginBuild, |
| 1186 | program: string, |
| 1187 | scan: EsbuildScanState, |
| 1188 | esbuildResolve: BundlerResolve, |
| 1189 | cwd: string |
| 1190 | ) => { |
| 1191 | build.initialOptions.metafile = true |
| 1192 | build.onStart(async () => { |
| 1193 | scan.scanned = undefined |
| 1194 | scan.verifies = false |
| 1195 | esbuildScan = undefined |
| 1196 | scan.loaded.clear() |
| 1197 | const result = await esbuildScanOf( |
| 1198 | build, |
| 1199 | program, |
| 1200 | path => |
| 1201 | transformedFilter.include.test(path) && |
| 1202 | !transformedFilter.exclude.test(path), |
| 1203 | scanned => scanChoosing(esbuildResolve, scanned), |
| 1204 | realCwd() |
| 1205 | ).catch( |
| 1206 | (e: unknown): ProgramScan<[ScannedProgram, ScannedUsage]> => ({ |
| 1207 | warnings: [unreadMessageOf(e)] |
| 1208 | }) |
| 1209 | ) |
| 1210 | const warnings = (result.warnings ?? []).map(text => ({ text })) |
| 1211 | if (!result.read) return { warnings } |
| 1212 | const [scanned, usage] = result.read |
| 1213 | scan.scanned = scanned |
| 1214 | scan.verifies = usage.verifies |
| 1215 | scan.holders = new Set(usage.holders) |
| 1216 | esbuildScan = { |
| 1217 | scanned, |
| 1218 | verifies: scan.verifies, |
| 1219 | loaded: scan.loaded, |
| 1220 | written: new Map(), |
| 1221 | replaced: new Set(usage.replaced), |
| 1222 | holders: scan.holders, |
| 1223 | issues: usage.issues |
| 1224 | } |
| 1225 | return { warnings } |
| 1226 | }) |
| 1227 | build.onEnd(async result => { |
| 1228 | // stored once the build ends, before it returns |
| 1229 | await request("ended").catch(() => undefined) |
| 1230 | if ( |
| 1231 | !scan.scanned || |
| 1232 | (!scan.verifies && !esbuildScan?.replaced.size) || |
| 1233 | !result.metafile || |
| 1234 | result.errors.length |
| 1235 | ) |
| 1236 | return |
| 1237 | const problem = unseenProblemOf( |
| 1238 | scan.scanned, |
| 1239 | esbuildImportsOf(result.metafile, cwd, scan.scanned), |
| 1240 | scan.loaded, |
| 1241 | scan.holders, |
no test coverage detected