|
| 1 | +# Duel v4 Migration Guide |
| 2 | + |
| 3 | +This guide highlights behavior changes introduced in v4 and how to adapt existing workflows. |
| 4 | + |
| 5 | +## Breaking/Behavioral Changes |
| 6 | + |
| 7 | +- **Specifier rewrites now default to safer behavior.** `--rewrite-policy` now defaults to `safe`, and `--validate-specifiers` is forced on when policy is `safe`. Missing targets skip rewrites and emit warnings instead of silently rewriting. |
| 8 | +- **Dual-package hazard detection enabled by default.** `--detect-dual-package-hazard` now defaults to `warn`, and `--dual-package-hazard-scope` defaults to `file`. You may see new warnings (or errors if configured). |
| 9 | +- **Build pipeline runs in a temp workspace copy.** Dual builds no longer mutate the root `package.json`; a temp copy is created with an adjusted `type`. External tools that watched in-place `package.json` edits will see different behavior. |
| 10 | + - **IMPORTANT:** The temp-copy flow adds some I/O for large repos (copying sources/reference packages and running transforms there). `node_modules` is skipped; when references exist, existing `dist` may be reused. Very large projects may see modestly slower runs compared to the old in-place mutation. |
| 11 | +- **Project references run with `tsc -b`.** When `tsconfig.json` contains references, builds switch to TypeScript build mode. Output shape can differ from `tsc -p` for some setups. |
| 12 | +- **Exports tooling additions.** New flags (`--exports-config`, `--exports-validate`) are available; when used, they can emit warnings or fail on invalid configs. |
| 13 | +- **Deprecated flags removed.** `--modules`, `--transform-syntax`, and `--target-extension` are gone; use `--mode globals` or `--mode full` instead. |
| 14 | + |
| 15 | +## Restoring v3-like Behavior |
| 16 | + |
| 17 | +- **Specifier rewrites:** use `--rewrite-policy warn --validate-specifiers false` to continue rewriting even when targets are missing (previous behavior). To fully bypass rewrites, set `--rewrite-policy skip`. |
| 18 | +- **Hazard detection:** disable by passing `--detect-dual-package-hazard off` (or set scope to `project` only if you want aggregated warnings). |
| 19 | +- **Build/package.json side effects:** if tooling depended on in-place `package.json` mutation, update it to read outputs from the temp dual build outputs (`dist/esm` / `dist/cjs` or `outDir` variants). No flag restores the old mutation pattern. |
| 20 | +- **TypeScript references:** if build mode changes output undesirably, remove `references` or run your own `tsc -p` before calling `duel`. |
| 21 | + |
| 22 | +## Recommended Migration Steps |
| 23 | + |
| 24 | +1. Pick a rewrite policy: |
| 25 | + - Safety-first (default): keep `--rewrite-policy safe` (default) and address any missing-target warnings by fixing paths or adding files. |
| 26 | + - Legacy: add `--rewrite-policy warn --validate-specifiers false` to mimic v3 rewrites. |
| 27 | +2. Decide on hazard handling: |
| 28 | + - Keep defaults to surface hazards. |
| 29 | + - Silence: `--detect-dual-package-hazard off`. |
| 30 | +3. Check CI/build scripts: remove assumptions about `package.json` being mutated; consume artifacts from the generated outDir(s). |
| 31 | +4. Projects with TS references: expect `tsc -b`; validate output paths and adjust if needed. |
| 32 | +5. If using exports helpers: verify `--exports-config` files and watch for new validation warnings/errors. |
| 33 | + |
| 34 | +## New/Notable Flags |
| 35 | + |
| 36 | +- `--rewrite-policy [safe|warn|skip]` (default: `safe`) |
| 37 | +- `--validate-specifiers` (defaults to `true` when policy is `safe`; otherwise `false`) |
| 38 | +- `--detect-dual-package-hazard [off|warn|error]` (default: `warn`) |
| 39 | +- `--dual-package-hazard-scope [file|project]` (default: `file`) |
| 40 | +- `--exports-config <path>` |
| 41 | +- `--exports-validate` |
| 42 | +- `--verbose` |
| 43 | + |
| 44 | +## Quick FAQ |
| 45 | + |
| 46 | +- **Why are some rewrites skipped now?** Missing targets + `rewrite-policy safe` causes skips with warnings. Use `warn` to force rewrites or fix the missing files. |
| 47 | +- **Can I suppress hazard warnings?** Yes, `--detect-dual-package-hazard off`. |
| 48 | +- **Why isn’t package.json changed anymore?** v4 writes to a temp copy to avoid mutating your root; watch the emitted outDir instead. |
0 commit comments