Skip to content

package-layout convention: never bundle, ship dist/ as one file per module #582

Done

Description

@Shinrai

docs/conventions/package-layout.md tells libraries to bundle src/ with tsup into dist/index.mjs (plus bin/<name>.mjs for a CLI), modeled on vitest-runner. Bundling duplicates code whenever a package has more than one entry:

  • vitest-runner: the CLI bundle re-ships the whole library (48 KB next to 40 KB), and the two helper scripts ship in both dist/ and bin/ because import.meta.url paths resolve against whichever bundle the inlined code ended up in. Filed as Stop bundling: ship dist/ as one file per module, CLI imports the library vitest-runner#160.
  • lib-sqlite-wasm: it has four entries that share classes. Separate bundles gave each entry its own copy of the error class, which broke instanceof, so the build turned on splitting, and 0.1.0/0.2.0 ship hashed chunk-*.mjs files.

The build shouldn't move code around or merge it into one file. Minify (and obfuscate, where a repo wants that) each file in place, but never duplicate code to fit a bundler. The convention should say:

  • dist/ (and bin/) mirror src/, one file per module, minified in place with keepNames.
  • No bundling, no splitting, no chunk-* files, and no code duplicated across entries or between dist/ and bin/. A CLI imports the library from dist/.
  • The hand-written index.cjs require(esm) shim stays as it is.

Reference implementation: CLDMV/lib-sqlite-wasm scripts/build-js.mjs (on its fix/unbundled-dist branch until merged). tsc emits dist/ with rewriteRelativeImportExtensions, then esbuild minifies each file in place with source maps chained back to src/. Plain-.mjs repos can run esbuild with bundle: false directly.

Once this lands, the repos still on the tsup bundle need migrating. I'll inventory them and file one issue each.

Activity

  1. added
    type: documentation
    priority: high
    status: not started
    status: in progress
    and removed
    status: not started
    on Nov 26, 2026
  2. added 2 commits that reference this issue on Nov 26, 2026
    74cf411
    e56cd05
  3. added
    status: implemented
    and removed
    status: in progress
    on Nov 26, 2026
  4. cldmv-bot commented on Nov 26, 2026

    @cldmv-bot
    Contributor

    Marked status: implemented — resolved by #584, merged into next. This issue closes automatically when that work ships to the default branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: highstatus: implementedtype: documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions