Skip to content

Commit ca14975

Browse files
Added support for builds in CommonJS and ECMAScript module formats
1 parent c7c8f65 commit ca14975

File tree

6 files changed

+73
-18
lines changed

6 files changed

+73
-18
lines changed

configs/tsconfig.base.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"strict": true,
4+
"esModuleInterop": true,
5+
"forceConsistentCasingInFileNames": true,
6+
"skipLibCheck": true,
7+
"checkJs": true,
8+
"allowJs": true,
9+
"declaration": true,
10+
"declarationMap": true,
11+
"allowSyntheticDefaultImports": true
12+
},
13+
"include": [
14+
"../source/"
15+
],
16+
"exclude": [
17+
"../node_modules/"
18+
],
19+
"extends": "@express-rate-limit/tsconfig"
20+
}

configs/tsconfig.cjs.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"compilerOptions": {
4+
"lib": [
5+
"ES6",
6+
"DOM"
7+
],
8+
"target": "ES6",
9+
"module": "CommonJS",
10+
"moduleResolution": "Node",
11+
"outDir": "../dist/cjs",
12+
"declarationDir": "../dist/cjs/types"
13+
}
14+
}

configs/tsconfig.esm.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"compilerOptions": {
4+
"lib": [
5+
"ES2022",
6+
"DOM"
7+
],
8+
"target": "ES2022",
9+
"module": "NodeNext",
10+
"moduleResolution": "NodeNext",
11+
"outDir": "../dist/esm",
12+
"declarationDir": "../dist/esm/types"
13+
}
14+
}

package.json

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,30 @@
22
"name": "@acpr/rate-limit-postgresql",
33
"version": "1.0.0",
44
"description": "A PostgreSQL store for the `express-rate-limit` middleware",
5-
"main": "dist/index.js",
6-
"types": "dist/index.d.ts",
5+
"types": "./dist/cjs/types/index.d.ts",
6+
"main": "./dist/cjs/index.js",
7+
"files": [
8+
"dist/**/*"
9+
],
10+
"exports": {
11+
".": {
12+
"import": {
13+
"types": "./dist/esm/types/index.d.ts",
14+
"default": "./dist/esm/index.mjs"
15+
},
16+
"require": {
17+
"types": "./dist/cjs/types/index.d.ts",
18+
"default": "./dist/cjs/index.js"
19+
}
20+
}
21+
},
722
"scripts": {
823
"test": "echo \"Error: no test specified\" && exit 1",
9-
"build": "tsc",
24+
"clean": "rm -rf ./dist",
25+
"build": "npm run clean && npm run build:esm && npm run build:cjs && cp source/db/migrations/ dist/ -r",
26+
"build:esm": "tsc -p ./configs/tsconfig.esm.json && mv dist/esm/index.js dist/esm/index.mjs",
27+
"build:cjs": "tsc -p ./configs/tsconfig.cjs.json",
28+
"prepack": "npm run build",
1029
"prepare": "husky install"
1130
},
1231
"keywords": [
@@ -32,8 +51,8 @@
3251
"postgres"
3352
],
3453
"author": {
35-
"name": "Adrian C. Prelipcean"
36-
},
54+
"name": "Adrian C. Prelipcean"
55+
},
3756
"license": "MIT",
3857
"dependencies": {
3958
"express-rate-limit": "6.11.0",

source/lib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class PostgresStore implements Store {
7676
host: this.config['host'] || 'localhost',
7777
port: this.config['port'] || 5432,
7878
}
79-
await migrate(dbConfig, __dirname + '/migrations')
79+
await migrate(dbConfig, __dirname + '/../migrations')
8080
}
8181

8282
/**

tsconfig.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)