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
- Parse a module's imports (use an existing JS parser).
- Build the dependency graph; detect cycles.
- Transform each module (reuse
fw-06). - Emit a bundle with a tiny runtime module registry.
- Code splitting on dynamic
import()— emit separate chunks, load on demand. - 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.
- Source maps.
- Caching + incremental rebuild: content-hash each module; rebuild only affected paths.
- HMR concepts: what must be true for a module to be replaceable without a reload?
3. Failure Lab
- Stale cache. Key the cache on filename only, not content. Produce a wrong bundle.
- Unsafe tree shaking. Drop a module with an import side effect. Break the app.
- Cycle. Create a circular import with top-level usage; observe the partially-initialised module.
- Broken source map. Off-by-one the mapping and try to debug through it.
- Over-splitting. Split into 200 chunks; measure the network cost against one bundle on a throttled connection.