8000 CJS output's `sourceMappingURL` and map `file` field point at the ESM map name · Issue #71 · colinhacks/zshy · GitHub
[go: up one dir, main page]

Skip to content

CJS output's sourceMappingURL and map file field point at the ESM map name #71

Open

Description

@yagop

When emitting the CJS build, the .cjs / .d.cts files keep the //# sourceMappingURL= comment from the original TS emit, so they reference *.js.map / *.d.ts.map instead of their own *.cjs.map / *.d.cts.map. The companion map files also carry the wrong "file" field (the .js / .d.ts name).

Because the ESM and CJS maps have different mappings, every CJS consumer — Node --enable-source-maps, source-map-support, ts-node/tsx, Jest/Mocha, IDE "go to definition" — resolves to the wrong map and misreports positions.

Repro

zshy's own published package exhibits it:

$ grep sourceMappingURL node_modules/zshy/dist/index.cjs
//# sourceMappingURL=index.js.map     # expected index.cjs.map

$ grep '"file"' node_modules/zshy/dist/index.cjs.map
"file":"index.js"                     # expected "index.cjs"

Same for .d.cts → .d.ts.map.

Cause

In compile.js, the host.writeFile hook renames the output path (.js→.cjs, etc.) but writes data unmodified, so the in-file sourceMappingURL comment and the map "file" field still reference the original names.

Fix

When renaming, also rewrite the contents — the sourceMappingURL comment in .cjs/.d.cts, and the "file" field in .cjs.map/.d.cts.map.

Version

zshy 0.7.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0