( port: MessagePort, data: PrecompilerWorkerData )
| 163 | } |
| 164 | |
| 165 | const answerRequests = ( |
| 166 | port: MessagePort, |
| 167 | data: PrecompilerWorkerData |
| 168 | ): void => { |
| 169 | let tracked: TrackedPrecompiler | undefined |
| 170 | let conflictsWithThread = false |
| 171 | // the request it's answering, by its place among those it was sent |
| 172 | let answering = -1 |
| 173 | let unasked = false |
| 174 | const resolveInBundler = bundlerResolverOf( |
| 175 | data, |
| 176 | () => answering, |
| 177 | () => (unasked = true), |
| 178 | // what it read before it stopped waiting may be partial |
| 179 | () => (tracked = undefined) |
| 180 | ) |
| 181 | const track = () => |
| 182 | createTrackedPrecompiler( |
| 183 | data.precompilerOptions, |
| 184 | resolveInBundler, |
| 185 | !!data.leavesDependencies |
| 186 | ) |
| 187 | // kept across the resets that keep the precompiler, as a rebuild asks again |
| 188 | // for modules nothing changed |
| 189 | let transformedById: Record<string, KeptModule> = {} |
| 190 | // each program the build scanned, by the key its transforms name |
| 191 | let scansByProgram: Record<string, Scan> = {} |
| 192 | // the scans this build stored, written once it ends. A scan the cache gives |
| 193 | // may need a new one to scan it again, for a check the build runs once it |
| 194 | // has given every module, and a build cut short, as by a kill, never stored |
| 195 | // that check's answer, so each build after it would scan again whatever |
| 196 | // changed since, as a package install does to node_modules |
| 197 | let unended: (() => void)[] = [] |
| 198 | const end = () => { |
| 199 | for (const write of unended) write() |
| 200 | unended = [] |
| 201 | } |
| 202 | // the precompiler holding a scan's usage: where the cache answered it, a new |
| 203 | // one scans it again for a module unlike those the cache holds, and must |
| 204 | // write what the cache gave the bundler |
| 205 | const scanned = (scan: Scan): TrackedPrecompiler => { |
| 206 | if (scan.tracked) return viewing(scan.tracked, scan) |
| 207 | const { usage, given, snapshot } = scan.served! |
| 208 | const written = scan.written! |
| 209 | scan.served = scan.written = undefined |
| 210 | const rescanned = track() |
| 211 | const { precompiler } = rescanned |
| 212 | const reproduces = |
| 213 | JSON.stringify(precompiler.scan(scan.program)) === |
| 214 | JSON.stringify(usage) && |
| 215 | given.every(id => { |
| 216 | const { source, mappings, answer } = written[id] |
| 217 | return ( |
| 218 | JSON.stringify( |
| 219 | transformedModuleOf( |
| 220 | precompiler, |
| 221 | source, |
| 222 | id, |
no test coverage detected