Skip to content

Move the CJS entry out of src/cjs/ to src/index.cjs (and the ESM entry to src/index.mjs) #157

Closed

Description

@Shinrai

Problem

The thin CommonJS entry is src/cjs/index.cjs, a folder holding one file. It exists only so tsup's publicDir: "src/cjs" can copy it into dist/. The file does require("./index.mjs").default, but there's no src/index.mjs next to it (the ESM entry is src/fix-header.mjs). So it only resolves once copied into dist/, and it can't be loaded or tested from source.

The CLDMV library convention (as in CLDMV/llm-translator, and proposed for CLDMV/vitest-runner#98) is one name for both source and output:

  • src/index.mjs is the ESM entry, bundled to dist/index.mjs.
  • src/index.cjs is the CJS entry, copied verbatim to dist/index.cjs by a tsup onSuccess copyFileSync.
  • require("./index.mjs") resolves to the sibling in src/ and in dist/, so the CJS entry can also be tested from source.

Proposal

  • git mv src/fix-header.mjs src/index.mjs and git mv src/cjs/index.cjs src/index.cjs (keeps history); remove the empty src/cjs/. Run npm run fix:headers to update the @Filename headers.
  • Update imports of fix-header.mjs (src/cli.mjs, tests), the fix-headers-dev export condition in package.json, and tsup.config.mjs's entry ({ index: "src/index.mjs" }).
  • tsup.config.mjs: drop publicDir: "src/cjs"; add onSuccess() { copyFileSync("src/index.cjs", "dist/index.cjs"); }. Update the file comments in tsup.config.mjs and the CJS entry that describe publicDir.
  • Optionally add require: "./src/index.cjs" to the fix-headers-dev condition, as stubborn-tcp, wisp and mxnet-control do. Then add a source-level vitest test that the CJS entry matches the ESM default export.
  • Regenerate types/ and check types/index.d.mts still resolves the entry declaration.
  • Check that dist/index.cjs is byte-identical to before and that tests/cjs/entry.test.cjs and the full suite pass.
  • Update any README/docs layout notes; leave docs/changelog/** history alone.

Non-goals

  • Changing what the CJS entry does (the require_module guard + require("./index.mjs").default).

Related

  • CLDMV/vitest-runner#98, and the matching src/cjs-shim.cjs → src/index.cjs issues in stubborn-tcp, wisp and mxnet-control.

Activity

  1. added
    type: enhancement
    priority: low
    area: core
    status: not started
    type: bug
    and removed
    type: enhancement
    on Oct 25, 2026
  2. added
    status: implemented
    and removed
    status: not started
    on Nov 1, 2026
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

    area: corepriority: lowstatus: implementedtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions