Skip to content

Commit ab7ffaf

Browse files
authored
Merge pull request #46 from shelfio/feature/esm-common-js-backwards-compatability
feat: type:module, commonJs backwards compatability
2 parents 5e9880a + 6d58deb commit ab7ffaf

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,25 @@ $ yarn add @shelf/postgres-local --dev
1212

1313
### 1. Start Postgres
1414

15+
#### ES Modules
16+
1517
```js
1618
import {start} from '@shelf/postgres-local';
1719

20+
await start({
21+
seedPath: "schema.sql",
22+
version: 17,
23+
port: 5555,
24+
includeInstallation: true,
25+
debugMode: false
26+
});
27+
```
28+
29+
#### CommonJS
30+
31+
```js
32+
const {start} = require('@shelf/postgres-local');
33+
1834
await start({
1935
seedPath: "schema.sql",
2036
version: 17,

package.json

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@shelf/postgres-local",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "Run Postgres locally",
55
"keywords": [
66
"postgres",
@@ -14,6 +14,7 @@
1414
"type": "git",
1515
"url": "git+https://github.com/shelfio/postgres-local.git"
1616
},
17+
"type": "module",
1718
"license": "MIT",
1819
"author": {
1920
"name": "Dmytro Harazdovskyi",
@@ -23,12 +24,24 @@
2324
"files": [
2425
"lib"
2526
],
26-
"main": "lib/index.js",
27+
"main": "./lib/cjs/index.cjs",
28+
"module": "./lib/esm/index.js",
2729
"types": "./lib/index.d.ts",
30+
"exports": {
31+
".": {
32+
"types": "./lib/index.d.ts",
33+
"import": "./lib/esm/index.js",
34+
"require": "./lib/cjs/index.cjs",
35+
"default": "./lib/esm/index.js"
36+
}
37+
},
2838
"scripts": {
29-
"build": "rm -rf lib/ && yarn build:types && yarn build:code",
30-
"build:code": "babel src --out-dir lib --ignore '**/*.test.ts' --extensions '.ts' && find ./lib -name '*.test.d.ts' -delete",
39+
"build": "rm -rf lib/ && yarn build:types && yarn clean:test-dts && yarn build:code",
40+
"build:code": "yarn build:cjs && yarn build:esm",
41+
"build:cjs": "babel src --out-dir lib/cjs --ignore '**/*.test.ts' --extensions '.ts' --out-file-extension '.cjs'",
42+
"build:esm": "tsc --project tsconfig.esm.json",
3143
"build:types": "tsc --emitDeclarationOnly --declaration --isolatedModules false --declarationDir lib",
44+
"clean:test-dts": "find ./lib -name '*.test.d.ts' -delete",
3245
"coverage": "yarn test --coverage",
3346
"lint": "eslint . --ext .js,.ts,.json --fix",
3447
"lint:ci": "eslint . --ext .js,.ts,.json",

tsconfig.esm.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "Node16",
5+
"outDir": "lib/esm",
6+
"moduleResolution": "node16",
7+
"declaration": false,
8+
"emitDeclarationOnly": false
9+
},
10+
"exclude": ["node_modules", "**/*.test.ts"]
11+
}

0 commit comments

Comments
 (0)