Skip to content

Commit 09deade

Browse files
committed
feat: add esnext target to support using library via ES modules
closes #145
1 parent ffdfb4e commit 09deade

File tree

6 files changed

+49
-11
lines changed

6 files changed

+49
-11
lines changed

fixup.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
cat >build/cjs/package.json <<!EOF
4+
{
5+
"type": "commonjs"
6+
}
7+
!EOF
8+
9+
cat >build/esm/package.json <<!EOF
10+
{
11+
"type": "module"
12+
}
13+
!EOF

jest.config.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
module.exports = {
2-
roots: ['<rootDir>/src'],
3-
transform: {
4-
'^.+\\.tsx?$': 'ts-jest',
5-
},
6-
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
7-
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
2+
globals: {
3+
'ts-jest': {
4+
tsconfig: 'tsconfig-cjs.json'
5+
}
6+
},
7+
roots: ['<rootDir>/src'],
8+
transform: {
9+
'^.+\\.tsx?$': 'ts-jest',
10+
},
11+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
12+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
813
}

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
"name": "ydb-sdk",
33
"version": "3.2.0",
44
"description": "Node.js bindings for working with YDB API over gRPC",
5-
"main": "build/index.js",
5+
"main": "build/cjs/index.js",
6+
"module": "build/esm/index.js",
7+
"exports": {
8+
".": {
9+
"import": "./build/esm/index.js",
10+
"require": "./build/cjs/index.js"
11+
}
12+
},
613
"files": [
714
"build/**",
815
"certs/"
@@ -12,7 +19,7 @@
1219
"test:integration": "jest",
1320
"test:all": "run-p test:unit test:integration",
1421
"test": "npm run test:unit",
15-
"build": "tsc",
22+
"build": "tsc -p tsconfig-esm.json && tsc -p tsconfig-cjs.json && ./fixup.sh",
1623
"clean": "rm -rf build",
1724
"prepublish": "npm run clean && npm run build",
1825
"release": "standard-version"

tsconfig.json renamed to tsconfig-base.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"compilerOptions": {
3-
"target": "es2017",
4-
"module": "commonjs",
5-
"outDir": "build",
63
"moduleResolution": "node",
74
"esModuleInterop": true,
85
"pretty": true,

tsconfig-cjs.json

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

tsconfig-esm.json

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

0 commit comments

Comments
 (0)