Skip to content

Commit 3e91304

Browse files
committed
Add explicit exports field
1 parent cb0dceb commit 3e91304

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

fix-exports-type.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#! /bin/bash
2+
3+
# This script defines the type of exports in the dist directory using minimal
4+
# package.json files. Setting the type in the main package.json file does not
5+
# work because we want to support both CommonJS and ES Module exports in the
6+
# same package.
7+
8+
cat >dist/cjs/package.json <<!EOF
9+
{
10+
"type": "commonjs"
11+
}
12+
!EOF
13+
echo "Exports type set to CommonJS in dist/cjs/package.json"
14+
15+
cat >dist/esm/package.json <<!EOF
16+
{
17+
"type": "module"
18+
}
19+
!EOF
20+
echo "Exports type set to ES Module in dist/esm/package.json"

package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,25 @@
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm/index.js",
77
"types": "dist/esm/index.d.ts",
8+
"exports": {
9+
".": {
10+
"require": "./dist/cjs/index.js",
11+
"import": "./dist/esm/index.js",
12+
"types": "./dist/esm/index.d.ts"
13+
}
14+
},
815
"scripts": {
9-
"build": "rimraf dist && npm run build:esm && npm run build:cjs",
16+
"build": "rimraf dist && npm run build:esm && npm run build:cjs && ./fix-exports-type.sh",
1017
"build:esm": "tsc -p tsconfig.esm.json",
1118
"build:cjs": "tsc -p tsconfig.json",
1219
"test": "karma start",
13-
"types": "tsc -p tsconfig.json",
20+
"types": "tsc -p tsconfig.esm.json",
1421
"lint": "eslint . --ext .ts,.tsx",
1522
"lint:fix": "eslint . --ext .ts,.tsx --fix",
1623
"docs:generate": "rimraf documentation-website/* && typedoc",
1724
"docs:serve": "live-server ./documentation-website"
1825
},
19-
"author": "",
26+
"author": "DittoLive Inc.",
2027
"license": "ISC",
2128
"repository": {
2229
"type": "git",

0 commit comments

Comments
 (0)