diff --git a/package.json b/package.json index 89eb2d6..0088a52 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,15 @@ "repository": "https://github.com/mike-marcacci/node-redlock.git", "homepage": "https://github.com/mike-marcacci/node-redlock#readme", "bugs": "https://github.com/mike-marcacci/node-redlock/issues", - "main": "dist/index.js", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/index.d.ts", + "exports": { + ".": { + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + } + }, "keywords": [ "nodejs", "redlock", @@ -20,8 +28,10 @@ ], "files": [ "dist/index.d.ts", - "dist/index.js", - "dist/index.js.map" + "dist/esm/index.js", + "dist/esm/index.js.map", + "dist/cjs/index.js", + "dist/cjs/index.js.map" ], "engines": { "node": ">=12" @@ -49,10 +59,10 @@ "scripts": { "format": "prettier --list-different --write '**/*.{json,yml,md,ts}'", "lint": "prettier -c '**/*.{json,yml,md,ts}' && eslint src --ext ts", - "build": "rm -rf dist && tsc", + "build": "rm -rf dist && tsc && tsc -p tsconfig.cjs.json && ./tools/fixup", "build:development": "rm -rf dist && tsc --watch", - "test": "ava --verbose dist/*.test.js", - "test:development": "ava --verbose --watch dist/*.test.js", + "test": "cd dist/esm && ava --verbose *.test.js", + "test:development": "cd dist/esm && ava --verbose --watch *.test.js", "prepare": "yarn build", "prepublishOnly": "yarn install && yarn lint && yarn build" }, diff --git a/tools/fixup b/tools/fixup new file mode 100755 index 0000000..5a45407 --- /dev/null +++ b/tools/fixup @@ -0,0 +1,16 @@ +#!/bin/bash +# +# Add package.json files to cjs/esm subtrees +# + +cat >dist/cjs/package.json <dist/esm/package.json <