Execution — fw-07-bundler

Steps extracted from CONCEPTS.md. Read the concepts first; this file is the doing.

Record results in observation.md; tick checkpoints in verification.md.


2. Build order

entry -> parse imports -> dependency graph -> transform -> bundle
  1. Parse a module's imports (use an existing JS parser).
  2. Build the dependency graph; detect cycles.
  3. Transform each module (reuse fw-06).
  4. Emit a bundle with a tiny runtime module registry.
  5. Code splitting on dynamic import() — emit separate chunks, load on demand.
  6. Tree shaking: mark exports used; drop unused. Then find a case where it is unsafe (side effects at module scope) and implement the conservative fallback.
  7. Source maps.
  8. Caching + incremental rebuild: content-hash each module; rebuild only affected paths.
  9. HMR concepts: what must be true for a module to be replaceable without a reload?

3. Failure Lab

  1. Stale cache. Key the cache on filename only, not content. Produce a wrong bundle.
  2. Unsafe tree shaking. Drop a module with an import side effect. Break the app.
  3. Cycle. Create a circular import with top-level usage; observe the partially-initialised module.
  4. Broken source map. Off-by-one the mapping and try to debug through it.
  5. Over-splitting. Split into 200 chunks; measure the network cost against one bundle on a throttled connection.