Commit ae96ad7
authored
feat: dual-publish ESM + CJS builds (#52)
## Summary
Closes #48.
The SDK has been ESM-only since extraction, which forced CJS consumers
(Node services that `require()`) to either re-implement the client or
use dynamic-import workarounds. This PR adds a CommonJS build alongside
the existing ESM output so a plain `require("@layerv/qurl")` works out
of the box.
## What changed
- **Two `tsc` passes from one source tree.** `tsconfig.json` keeps
emitting ESM (now under `dist/esm/`); a new `tsconfig.cjs.json` extends
it and emits CJS to `dist/cjs/`.
- **Per-condition `exports` map** — `import` and `require` each point at
their matching build, with `types` first inside each so
`moduleResolution: Node16` consumers resolve the correct `.d.ts`.
- **Sidecar `package.json` per dist tree.** `scripts/postbuild.mjs`
writes `{"type":"commonjs"}` into `dist/cjs/` and `{"type":"module"}`
into `dist/esm/` so Node pins each tree's module format independently of
the root `"type"` field.
- **End-to-end smoke fixtures.** `smoke/cjs.cjs` and `smoke/esm.mjs`
self-reference `@layerv/qurl` (matching how a downstream consumer
resolves it) and assert the public surface loads. CI runs both after
`npm run build`.
- **Legacy `main` / `module` / `types` fields** kept for tooling that
doesn't read `exports`.
- **README + CONTRIBUTING** updated to drop the ESM-only note and
document the dual-build layout.
## Acceptance criteria (from #48)
- [x] `require('@layerv/qurl')` works without flags or workarounds —
`smoke/cjs.cjs` proves it.
- [x] Existing ESM consumers keep working — `smoke/esm.mjs` proves it;
existing test suite (67 tests) still passes.
- [x] Both entry points come out of one build — `npm run build` runs
both tsc passes + the postbuild sidecar drop.
- [x] `exports` gains a `require` condition; types resolve from both
entry points.
- [x] CI smoke: both fixtures run on every PR.
- [x] Additive change — no breaking change to ESM consumers; Release
Please will publish as a minor.
## Heads-up for reviewers
- The `dist/` layout changes from `dist/index.js` to
`dist/{esm,cjs}/index.js`. Anyone deep-importing past the public root
(e.g. `@layerv/qurl/dist/index.js`) would break. Issue #48 notes the SDK
has zero real consumers today, so this is acceptable; the `exports`
field is the public contract going forward.
- TypeScript 6 deprecated `moduleResolution: Node10`. The CJS tsconfig
sets `ignoreDeprecations: "6.0"` to silence the warning until we
migrate; the resolution algorithm itself still works correctly for CJS
output.
## Test plan
- [x] `npm run build` — both passes succeed, sidecars land
- [x] `npm test` — 67 existing tests pass
- [x] `npm run smoke:dist` — CJS + ESM self-reference fixtures both
resolve and instantiate
- [x] `node -e 'const {QURLClient} = require("./dist/cjs");
console.log(new QURLClient({apiKey:"x"}))'` — masked-key inspect output
prints
- [x] `node --input-type=module -e '...'` ESM equivalent — same output
- [x] `npm pack --dry-run` — only `dist/` ships; `smoke/`, `scripts/`,
`tsconfig.cjs.json` correctly excluded1 parent e12f44f commit ae96ad7
11 files changed
Lines changed: 177 additions & 12 deletions
File tree
- .github/workflows
- scripts
- smoke
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
24 | 58 | | |
25 | 59 | | |
26 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | | - | |
11 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
12 | 20 | | |
13 | 21 | | |
14 | 22 | | |
15 | | - | |
16 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
17 | 26 | | |
18 | 27 | | |
19 | | - | |
20 | | - | |
21 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
22 | 32 | | |
23 | 33 | | |
24 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
0 commit comments