Skip to content

Commit 8ceb9b4

Browse files
chore: bump version.
1 parent bcba89f commit 8ceb9b4

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

docs/roadmap.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,38 @@
22

33
Status: draft
44

5-
## Pretty Output Mode
5+
## Idiomatic Exports Mode (aka `pretty`)
66

7-
Goal: Add an opt-in `pretty` (aka `idiomaticExports`) mode to reduce synthesized helper bags when converting between CJS and ESM.
7+
Goal: Add an opt-in `idiomaticExports` (current shorthand: `pretty`) mode to reduce synthesized helper bags when converting between CJS and ESM. Primary motivation: produce more idiomatic ESM output that is easier for bundlers to tree-shake when inputs qualify for the “safe” path.
88

99
### CJS → ESM
1010

11-
- Option: `pretty: 'safe' | 'aggressive'` (default: off).
11+
- Option: `pretty: 'safe' | 'aggressive'` (default: off). Consider exposing the option as `idiomaticExports` to better signal the intent and tree-shaking upside.
1212
- Safe mode rules (emit direct exports, avoid `__exports` when all are true):
1313
- Only top-level `exports.*` writes or a single `module.exports = { ... }` / `module.exports = fn`.
1414
- No reassignments after initial writes; no getters/setters; no computed/non-identifier keys; no mixed `exports` + `module.exports` unless we can rewrite deterministically.
1515
- No shadowed `module`/`exports`; no top-level `return`; no `require.cache/extensions`; no dynamic require inside export initializers; no TDZ hazards.
1616
- Aggressive mode: allow mixed exports + `module.exports` if we can derive both default and named exports; allow identifier-safe computed keys; allow a single reassignment.
17-
- Emission strategy:
17+
- Emission strategy (tree-shake-friendly when rules pass):
1818
- Named writes → `export const foo = ...` or `export { local as foo }`.
1919
- `module.exports = { ... }``export default { ... }` (+ optional named re-exports for plain identifiers if a sub-option is enabled).
2020
- `module.exports = fn``export default fn`.
2121
- Fallback to `__exports` when rules fail.
22+
- Tree shaking note: Safe mode outputs static `export` forms, which typical bundlers can eliminate when unused. Aggressive mode may reintroduce helper bags or conservative shapes, so shaking benefits are best-effort there.
2223
- Diagnostics: warn when `pretty` requested but fell back; warn when live-binding fidelity may differ in aggressive mode.
2324
- Tests: fixture matrix (safe object, safe function default, mixed exports+module.exports, computed keys, reassignments) with assertions on generated text (absence/presence of `__exports`) and runtime behavior.
2425

2526
### ESM → CJS
2627

27-
- Option: same `pretty` flag, but constrained by live bindings and TLA.
28+
- Option: same `pretty`/`idiomaticExports` flag, but constrained by live bindings and TLA.
2829
- Preconditions for pretty CJS:
2930
- `topLevelAwait === 'error'` or known-wrap path; `liveBindings !== 'strict'` (or accept relaxed semantics in aggressive mode).
3031
- No namespace exports requiring live getters; no export-all with live needs unless we accept relaxed semantics.
3132
- Emission strategy when safe:
3233
- Direct `exports.foo = foo;` and `module.exports = default` without namespace helpers.
3334
- Avoid namespace helper when `export * as ns` can map to `const ns = require(...); exports.ns = ns;` under relaxed live-binding semantics.
3435
- Keep helpers for TLA wrap and strict live bindings.
36+
- Tree shaking note: CJS output is inherently not statically tree-shakeable; “pretty” here is mostly about readability/minimal helpers rather than true shakeability.
3537
- Tests: fixtures verifying helper-free output under safe conditions and fallback when constraints are present.
3638

3739
## Documentation & UX

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@knighted/module",
3-
"version": "1.0.0-rc.4",
3+
"version": "1.0.0-rc.5",
44
"description": "Transforms differences between ES modules and CommonJS.",
55
"type": "module",
66
"main": "dist/module.js",

0 commit comments

Comments
 (0)