From 67c5b234ac2a50568a2611bb321e961e8e3e6894 Mon Sep 17 00:00:00 2001 From: Torgeir Hovden Date: Tue, 6 Dec 2022 19:00:27 +0100 Subject: [PATCH] fix: support typescript commonjs modules using moduleresolution nodenext (#401) * Use separate type file for the CJS module * Fix typo - use .cts for types --- package.json | 14 ++++++++++---- rollup.config.cjs | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 9043425c..105c50bc 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,14 @@ "bin": "lib/cli.js", "exports": { ".": { - "types": "./lib/main.d.ts", - "import": "./lib/main.js", - "require": "./lib/cjs/main.cjs" + "import": { + "types": "./lib/main.d.ts", + "default": "./lib/main.js" + }, + "require": { + "types": "./lib/cjs/main.d.cts", + "default": "./lib/cjs/main.cjs" + } } }, "repository": "github:puppeteer/replay", @@ -37,7 +42,8 @@ "lib", "!lib/**/*.d.ts", "!lib/**/*.d.ts.map", - "lib/main.d.ts" + "lib/main.d.ts", + "lib/cjs/main.d.cts" ], "author": "Chrome DevTools authors", "license": "Apache-2.0", diff --git a/rollup.config.cjs b/rollup.config.cjs index 73c853d6..cc6f83cd 100644 --- a/rollup.config.cjs +++ b/rollup.config.cjs @@ -22,10 +22,16 @@ module.exports = [ }, { input: 'src/main.ts', - output: { - file: 'lib/main.d.ts', - format: 'es', - }, + output: [ + { + file: 'lib/main.d.ts', + format: 'es', + }, + { + file: 'lib/cjs/main.d.cts', + format: 'cjs', + }, + ], external: [ 'devtools-protocol', 'devtools-protocol/types/protocol-mapping.js',