Skip to content

Commit

Permalink
feat: add esnext target to support using library via ES modules
Browse files Browse the repository at this point in the history
  • Loading branch information
tsufiev committed May 20, 2022
1 parent ffdfb4e commit 09deade
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
13 changes: 13 additions & 0 deletions fixup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

cat >build/cjs/package.json <<!EOF
{
"type": "commonjs"
}
!EOF

cat >build/esm/package.json <<!EOF
{
"type": "module"
}
!EOF
17 changes: 11 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
module.exports = {
roots: ['<rootDir>/src'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
globals: {
'ts-jest': {
tsconfig: 'tsconfig-cjs.json'
}
},
roots: ['<rootDir>/src'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
}
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
"name": "ydb-sdk",
"version": "3.2.0",
"description": "Node.js bindings for working with YDB API over gRPC",
"main": "build/index.js",
"main": "build/cjs/index.js",
"module": "build/esm/index.js",
"exports": {
".": {
"import": "./build/esm/index.js",
"require": "./build/cjs/index.js"
}
},
"files": [
"build/**",
"certs/"
Expand All @@ -12,7 +19,7 @@
"test:integration": "jest",
"test:all": "run-p test:unit test:integration",
"test": "npm run test:unit",
"build": "tsc",
"build": "tsc -p tsconfig-esm.json && tsc -p tsconfig-cjs.json && ./fixup.sh",
"clean": "rm -rf build",
"prepublish": "npm run clean && npm run build",
"release": "standard-version"
Expand Down
3 changes: 0 additions & 3 deletions tsconfig.json → tsconfig-base.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"outDir": "build",
"moduleResolution": "node",
"esModuleInterop": true,
"pretty": true,
Expand Down
8 changes: 8 additions & 0 deletions tsconfig-cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig-base.json",
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"outDir": "build/cjs"
}
}
8 changes: 8 additions & 0 deletions tsconfig-esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig-base.json",
"compilerOptions": {
"module": "esnext",
"outDir": "build/esm",
"target": "esnext"
}
}

0 comments on commit 09deade

Please sign in to comment.