Repository navigation
Description
Summary
Follow-up to #1261 / PR #1263. Package-level tree-shaking now works (unused @accordproject/* packages are dropped from web bundles), but per-export tree-shaking inside concerto-core does not — importing one export vs. the whole library differs by ~0.14%.
This epic tracks migrating concerto-core (and concerto-util) source from TypeScript export = / import X = require() to native ESM so bundlers can drop unused exports.
Root cause
The ESM build is esbuild --bundle (bundle: true), which produces a CJS-in-ESM blob (__commonJS / __esm wrappers). Bundlers cannot tree-shake inside that blob. Bundling is currently forced because 58 of 59 concerto-core/src files use TS export = / import X = require(), which is illegal as native ESM (tsc TS1203).
Spike measurement (GO — conditional)
A throwaway spike migrated one leaf module (securityexception.ts) to native ESM with bundle: false:
| Import | Bundle size |
|---|---|
1 export — current (bundle: true) |
595,862 B (596 KB) |
| All exports — current | 596,715 B (597 KB) |
| 1 export — after native-ESM migration | 22,908 B (22 KB) |
96.2% reduction (573 KB saved) for a single leaf import. The win is real and the migration is mechanical.
Condition: full wins require concerto-util to co-migrate — it is also a CJS-in-ESM blob, so leaf imports still pull in ~all of concerto-util until it too is native ESM. With both migrated, a SecurityException import would be <2 KB.
Migration shape
Bottom-up topological traversal of the import graph. Per-file pattern:
const X = require('./foo')→import X from './foo.js'const { X, Y } = require('@external')→import { X, Y } from '@external'export = ClassName→export { ClassName }; export default ClassName;- Migrate
globalize.tsbefore any file that uses it.
Build-path change:
- Replace the
build:esmesbuildbundle: truepass with an unbundled pass (tsc --module ES2020 --moduleResolution bundler, or esbuildbundle: false+splitting: true) emitting one.mjsper source file. - Update
tsconfig.build.json:module→ES2020,moduleResolution→bundler. Removingexport =resolvesTS1203.
File inventory (from spike):
- 4 pure leaf files (no internal
./requires):securityexception.ts,metamodelexception.ts,dayjs-setup.ts,serializer/validationexception.ts - ~38 files with only
const X = require('./internal')patterns - Complex hubs:
basemodelmanager.ts(20 internal requires),serializer/jsonpopulator.ts(8+4),factory.ts(10)
Recommended scope
- Migrate
concerto-utilto native ESM (~1–2 days) - Migrate
concerto-coreto native ESM, top-down (~2–3 days) - Update
tsconfig.build.json(module/moduleResolution) and replace thebuild:esmbundling step - Optional: per-module
exportsmap entries for deep imports - Verify downstream packages (
concerto-analysis,concerto-vocabulary, etc.) still build
Estimate: ~3–5 developer-days including test verification.
Constraints / risk
- Must keep all existing tests passing unchanged — this is a larger refactor than fix(concerto-core): remove ESM entrypoint from sideEffects to enable package-level tree shaking #1263 and stresses that guarantee more, hence a separate PR.
- Non-breaking for existing consumers (the CJS
requirepath and./dist/*deep-import escape hatch must keep working).
Tracked internally as beads epic concerto-334; spike concerto-08k.
Activity
test(esm): migrate deep source requires to named exports (#1304)
feat(concerto-cto,concerto-vocabulary): native ESM migration (#1304)
fix(build): emit ESM as a module graph so packages actually tree-shake
docs(esm): add MIGRATION.md for v5 and record the Option B decision
feat(concerto-core): ESM pilot — modelfile.ts + securityexception.ts …
feat(concerto-core): native ESM migration — model batch (#1304)
feat(concerto-core): native ESM migration — serializer batch (#1304)
feat(concerto-core): native ESM migration — introspect-a batch (#1304)
feat(concerto-core): native ESM migration — introspect-b batch (#1304)
feat(concerto-util): native ESM migration — util batch (#1304)
feat(concerto-core): native ESM migration — core-root batch (#1304)
fix(esm): resolve integration seam type errors after native-ESM migra…
docs(esm): add #1304 plan + cross-session handoff
test(esm): migrate deep source requires to named exports (#1304)
feat(concerto-cto,concerto-vocabulary): native ESM migration (#1304)
3 remaining items
feat(concerto-core): native ESM migration — model batch (#1304)
feat(concerto-core): native ESM migration — serializer batch (#1304)
feat(concerto-core): native ESM migration — introspect-a batch (#1304)
feat(concerto-core): native ESM migration — introspect-b batch (#1304)
feat(concerto-util): native ESM migration — util batch (#1304)
feat(concerto-core): native ESM migration — core-root batch (#1304)
fix(esm): resolve integration seam type errors after native-ESM migra…
docs(esm): add #1304 plan + cross-session handoff
test(esm): migrate deep source requires to named exports (#1304)
feat(concerto-cto,concerto-vocabulary): native ESM migration (#1304)
fix(build): emit ESM as a module graph so packages actually tree-shake
docs(esm): add MIGRATION.md for v5 and record the Option B decision
docs(esm): drop the #1304 planning document from the repo
feat(concerto)!: native ESM migration for per-export tree-shaking (v5…