Files
Luke SandbergandGitHub 0d61306201 Simplify how json imports work by turning it into a source transform (#89631)
# Refactor JSON module handling in Turbopack

## What?
Moves the JSON module handling from a separate crate (`turbopack-json`) into the `turbopack-ecmascript` crate as a source transform, similar to how text and binary files are handled.

## Why?
This simplifies the codebase by:
1. Removing a separate crate dependency
2. Using a consistent pattern for handling non-JavaScript assets
    * notably by sending them through the normal asset pipeline we unlock other behaviors in turbopack like scope-hoisting
3. Improving error handling for invalid JSON files

## How?
- Removed the `turbopack-json` crate
- Added a new `json_source_transform.rs` module to `turbopack-ecmascript`
- Implemented two modes for JSON handling:
  - Spec-compliant ESM mode (for `import ... with { type: 'json' }`)
  - Webpack-compatible CommonJS mode (for regular imports)
- Added "no side effects" directive to JSON, text, and binary modules to preserve tree shaking
- Updated error handling to provide better feedback for invalid JSON
- Opt'd out traced modules from json/bytes/text processing, this is more correct and should be a bit faster.  On the other hand this exposed a subtle issue with traced dependencies
2026-02-18 09:57:57 -08:00
..