Skip to content

Commit 0397230

Browse files
author
Georg Traar
committed
Add support for CJS and ESM builds
1 parent 899ada0 commit 0397230

File tree

8 files changed

+43
-7
lines changed

8 files changed

+43
-7
lines changed

examples/cjs-example.cjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
let CrateDBClient = require('../dist/cjs/CrateDBClient.js');
2+
let client = new CrateDBClient.CrateDBClient();
3+
4+
client
5+
.execute('SELECT 1;')
6+
.then((res) => console.log(res))
7+
.catch((err) => console.error(err));

examples/esm-example.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { CrateDBClient } from '../dist/esm/CrateDBClient.js';
2+
let client = new CrateDBClient();
3+
4+
client
5+
.execute('SELECT 1;')
6+
.then((res) => console.log(res))
7+
.catch((err) => console.error(err));

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22
"name": "@proddata/node-cratedb",
33
"version": "0.0.8",
44
"description": "Node.js client for CrateDB",
5-
"main": "dist/CrateDBClient.js",
65
"types": "dist/index.d.ts",
76
"type": "module",
7+
"main": "dist/cjs/index.cjs",
8+
"module": "dist/esm/index.js",
9+
"exports": {
10+
"import": "./dist/esm/index.js",
11+
"require": "./dist/cjs/index.js"
12+
},
813
"scripts": {
9-
"build": "tsc",
14+
"build": "npm run build:clean && npm run build:esm && npm run build:cjs",
15+
"build:clean": "rm -rf dist",
16+
"build:esm": "tsc --project tsconfig.esm.json && echo '{\"type\": \"module\"}' > dist/esm/package.json",
17+
"build:cjs": "tsc --project tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
1018
"prepare": "npm run build",
1119
"format": "prettier --write 'src/**/*.{ts,tsx,js,jsx}'",
1220
"check-format": "prettier --check 'src/**/*.{ts,tsx,js,jsx}'",
@@ -51,4 +59,4 @@
5159
"engines": {
5260
"node": ">=21.0.0"
5361
}
54-
}
62+
}

src/CrateDBClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import http, { AgentOptions } from 'http';
33
import https from 'https';
44
import { URL } from 'url';
55
import { CrateDBCursor } from './CrateDBCursor.js';
6-
import { CrateDBSerializer } from '../src/CrateDBSerializer';
6+
import { CrateDBSerializer } from './CrateDBSerializer.js';
77
import {
88
CrateDBConfig,
99
CrateDBBaseResponse,

src/CrateDBSerializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CrateDBTypes } from './CrateDBTypes';
1+
import { CrateDBTypes } from './CrateDBTypes.js';
22
import { CrateDBBaseResponse } from './interfaces';
33

44
export class CrateDBSerializer {

tsconfig.cjs.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "dist/cjs",
5+
"module": "commonjs"
6+
}
7+
}

tsconfig.esm.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "dist/esm",
5+
"module": "ES2022"
6+
}
7+
}

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"compilerOptions": {
3+
"outDir": "dist",
4+
"rootDir": "src",
35
"target": "ES2022",
46
"module": "ES2022",
57
"moduleResolution": "node",
6-
"outDir": "dist",
7-
"rootDir": "src",
88
"declaration": true,
99
"sourceMap": true,
1010
"strict": true,

0 commit comments

Comments
 (0)