Skip to content

Commit c1c4916

Browse files
fc-anjosmarcoroth
andauthored
Node: Fix CommonJS packaging in @herb-tools/node (#375)
This Pull Request fixes the packaging for CJS consumers of the Node package. Previously, the CommonJS entry failed due to a Rollup bundling configuration issue in `@herb-tools/node`. The package used separate `.cts/.mts` source files, but Rollup wasn't properly bundling local dependencies for the CJS build, leaving runtime requires that failed. This change adopts the established pattern: a single `src/index.ts` source file that Rollup transforms into both ESM and CJS outputs. This matches the proven strategy used by the other packages. This change adopts the established pattern: a single `src/index.ts` source file that Rollup transforms into both ESM and CJS outputs. This matches the strategy used by the other packages. Co-authored-by: Marco Roth <marco.roth@intergga.ch>
1 parent 2f2ba1c commit c1c4916

File tree

6 files changed

+364
-32
lines changed

6 files changed

+364
-32
lines changed

javascript/packages/node/package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
1414
"gypfile": true,
1515
"main": "./dist/herb-node.cjs",
1616
"module": "./dist/herb-node.esm.js",
17-
"types": "./dist/types/index-esm.d.mts",
17+
"types": "./dist/types/index.d.ts",
1818
"exports": {
1919
"./package.json": "./package.json",
2020
".": {
21-
"types": "./dist/types/index-esm.d.mts",
22-
"import": "./dist/herb-node.esm.js",
23-
"require": "./dist/herb-node.cjs",
24-
"default": "./dist/herb-node.esm.js"
21+
"import": {
22+
"types": "./dist/types/index.d.ts",
23+
"default": "./dist/herb-node.esm.js"
24+
},
25+
"require": {
26+
"types": "./dist/types/index.d.ts",
27+
"default": "./dist/herb-node.cjs"
28+
}
2529
}
2630
},
2731
"scripts": {

javascript/packages/node/rollup.config.mjs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import typescript from "@rollup/plugin-typescript"
22
import { nodeResolve } from "@rollup/plugin-node-resolve"
3+
import commonjs from "@rollup/plugin-commonjs"
34
import json from "@rollup/plugin-json"
45

56
const external = [
@@ -23,7 +24,7 @@ function isExternal(id) {
2324

2425
export default [
2526
{
26-
input: "src/index-esm.mts",
27+
input: "src/index.ts",
2728
output: {
2829
file: "dist/herb-node.esm.js",
2930
format: "esm",
@@ -43,20 +44,23 @@ export default [
4344
},
4445

4546
{
46-
input: "src/index-cjs.cts",
47+
input: "src/index.ts",
4748
output: {
4849
file: "dist/herb-node.cjs",
4950
format: "cjs",
5051
sourcemap: true,
5152
},
5253
external: isExternal,
5354
plugins: [
54-
nodeResolve(),
55-
json(),
5655
typescript({
5756
tsconfig: "./tsconfig.json",
57+
declaration: true,
58+
declarationDir: "./dist/types",
5859
rootDir: "src/",
5960
}),
61+
nodeResolve({ extensions: [".js", ".ts", ".cts"] }),
62+
commonjs({ extensions: [".js", ".cjs", ".cts"], ignoreDynamicRequires: true }),
63+
json(),
6064
],
6165
},
6266
]

javascript/packages/node/src/index-cjs.cts

Lines changed: 0 additions & 22 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)