( compilation: BundlerCompilation, read: BuiltRead, isTransformed: (id: string) => boolean )
| 2290 | |
| 2291 | // each module a compilation's entries reach, as the plugin reads them |
| 2292 | const builtEntriesOf = ( |
| 2293 | compilation: BundlerCompilation, |
| 2294 | read: BuiltRead, |
| 2295 | isTransformed: (id: string) => boolean |
| 2296 | ): BuiltModule[] => { |
| 2297 | const built = new Map<BuiltBundlerModule, BuiltModule>() |
| 2298 | const graph = compilation.moduleGraph |
| 2299 | const unbuilt: [BuiltBundlerModule, BuiltModule][] = [] |
| 2300 | const builtOf = (module: BuiltBundlerModule): BuiltModule => { |
| 2301 | const known = built.get(module) |
| 2302 | if (known) return known |
| 2303 | const id = builtIdOf(module) |
| 2304 | // one of the modules Next.js builds a listed package's entry as holds |
| 2305 | // some of the file's re-exports and nothing else, so it's read as its |
| 2306 | // file, which names each, and each import it was built with resolves |
| 2307 | // what the file names so |
| 2308 | const isBarrel = isBarrelModule(module) |
| 2309 | const transformed = |
| 2310 | !!id && isTransformed(id) && (isBarrel || loadsThroughPlugin(module)) |
| 2311 | const of: BuiltModule = { |
| 2312 | id, |
| 2313 | source: |
| 2314 | !id ? undefined |
| 2315 | : transformed ? |
| 2316 | read.loaded.has(id) ? |
| 2317 | read.loaded.get(id) |
| 2318 | : readFile(id) |
| 2319 | : dependencyOf(id) ? undefined |
| 2320 | : module.originalSource?.()?.source().toString(), |
| 2321 | transformed, |
| 2322 | mappings: id && read.mappings.get(id), |
| 2323 | imports: [], |
| 2324 | built: |
| 2325 | transformed && !isBarrel ? |
| 2326 | module.originalSource?.()?.source().toString() |
| 2327 | : undefined |
| 2328 | } |
| 2329 | built.set(module, of) |
| 2330 | unbuilt.push([module, of]) |
| 2331 | return of |
| 2332 | } |
| 2333 | const entries = [...compilation.entries.values(), compilation.globalEntry] |
| 2334 | .flatMap(entry => |
| 2335 | entry ? [...entry.dependencies, ...entry.includeDependencies] : [] |
| 2336 | ) |
| 2337 | .flatMap(dependency => { |
| 2338 | const module = graph.getModule(dependency as never) as |
| 2339 | | BuiltBundlerModule |
| 2340 | | null |
| 2341 | | undefined |
| 2342 | return module ? builtOf(module) : [] |
| 2343 | }) |
| 2344 | const importsIn = ( |
| 2345 | { dependencies, blocks }: BuiltBlock, |
| 2346 | isDynamic: boolean |
| 2347 | ): BuiltImport[] => [ |
| 2348 | ...dependencies.flatMap(dependency => { |
| 2349 | const module = graph.getModule(dependency as never) as |
no test coverage detected