From a08200dabe146feb3d386cc7d7191e62d0631d96 Mon Sep 17 00:00:00 2001 From: isaacs Date: Sun, 15 Jan 2023 13:25:58 -0800 Subject: [PATCH] List types separately in each dist type The uglier more correct work around for TypeScript's strange interaction with package.json exports in hybrid modules. --- package.json | 12 ++++++++---- test/index.js | 11 ++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 685105be..901b4cb8 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,16 @@ "main": "./dist/cjs/src/index.js", "module": "./dist/mjs/src/index.js", "bin": "./dist/cjs/src/bin.js", - "types": "./dist/cjs/src/index.d.ts", "exports": { ".": { - "types": "./dist/cjs/src/index.d.ts", - "import": "./dist/mjs/src/index.js", - "require": "./dist/cjs/src/index.js" + "import": { + "default": "./dist/mjs/src/index.js", + "types": "./dist/mjs/src/index.d.ts" + }, + "require": { + "default": "./dist/cjs/src/index.js", + "types": "./dist/cjs/src/index.d.ts" + } } }, "files": [ diff --git a/test/index.js b/test/index.js index d0fe6ecc..74929d0f 100644 --- a/test/index.js +++ b/test/index.js @@ -4,9 +4,14 @@ t.same( require('../package.json').exports, { '.': { - types: './dist/cjs/src/index.d.ts', - import: './dist/mjs/src/index.js', - require: './dist/cjs/src/index.js', + import: { + default: './dist/mjs/src/index.js', + types: './dist/mjs/src/index.d.ts', + }, + require: { + default: './dist/cjs/src/index.js', + types: './dist/cjs/src/index.d.ts', + }, }, }, 'nothing else exported except main'