From 38a2b3bf6a5c4bc6864b8899b7588f3abcf59564 Mon Sep 17 00:00:00 2001 From: Stephan Schreiber Date: Thu, 3 Oct 2024 13:03:23 +0200 Subject: [PATCH] fix(repo): provide typings for both cjs and es builds --- packages/alias/package.json | 14 ++++-- packages/auto-install/package.json | 14 ++++-- packages/babel/package.json | 14 ++++-- packages/buble/package.json | 14 ++++-- packages/commonjs/package.json | 14 ++++-- packages/data-uri/package.json | 14 ++++-- packages/dsv/package.json | 14 ++++-- packages/dynamic-import-vars/package.json | 14 ++++-- packages/eslint/package.json | 14 ++++-- packages/esm-shim/package.json | 18 ++++--- packages/graphql/package.json | 14 ++++-- packages/html/package.json | 14 ++++-- packages/image/package.json | 14 ++++-- packages/inject/package.json | 14 ++++-- packages/json/package.json | 14 ++++-- packages/legacy/package.json | 14 ++++-- packages/multi-entry/package.json | 14 ++++-- packages/node-resolve/package.json | 14 ++++-- packages/pluginutils/package.json | 13 +++-- packages/replace/package.json | 18 ++++--- packages/run/package.json | 14 ++++-- packages/strip/package.json | 14 ++++-- packages/sucrase/package.json | 13 +++-- packages/swc/package.json | 18 ++++--- packages/terser/package.json | 18 ++++--- packages/typescript/package.json | 14 ++++-- packages/url/package.json | 14 ++++-- packages/virtual/package.json | 14 ++++-- packages/wasm/package.json | 14 ++++-- packages/yaml/package.json | 14 ++++-- shared/rollup.config.mjs | 58 ++++++++++++++++++++--- 31 files changed, 358 insertions(+), 134 deletions(-) diff --git a/packages/alias/package.json b/packages/alias/package.json index 9051cad88..1d46b5b5e 100755 --- a/packages/alias/package.json +++ b/packages/alias/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -65,7 +71,7 @@ "rollup": "^4.0.0-24", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "files": [ "!**/fixtures/**", diff --git a/packages/auto-install/package.json b/packages/auto-install/package.json index 8d2346268..d81b75874 100755 --- a/packages/auto-install/package.json +++ b/packages/auto-install/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -68,7 +74,7 @@ "rollup": "^4.0.0-24", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/babel/package.json b/packages/babel/package.json index f4668c20f..5bbd6d72a 100644 --- a/packages/babel/package.json +++ b/packages/babel/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -82,7 +88,7 @@ "rollup": "^4.0.0-24", "source-map": "^0.7.4" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "files": [ "!**/fixtures/**", diff --git a/packages/buble/package.json b/packages/buble/package.json index 54f5cfb29..1a8fc45c8 100644 --- a/packages/buble/package.json +++ b/packages/buble/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -72,7 +78,7 @@ "source-map": "^0.7.4", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/commonjs/package.json b/packages/commonjs/package.json index 83fe1254e..fc4dad728 100644 --- a/packages/commonjs/package.json +++ b/packages/commonjs/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=16.0.0 || 14 >= 14.17" @@ -80,7 +86,7 @@ "source-map-support": "^0.5.21", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/data-uri/package.json b/packages/data-uri/package.json index d74646536..f7450680c 100644 --- a/packages/data-uri/package.json +++ b/packages/data-uri/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -69,7 +75,7 @@ "rollup": "^4.0.0-24", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/dsv/package.json b/packages/dsv/package.json index 5dc0d5006..c2a7f0463 100755 --- a/packages/dsv/package.json +++ b/packages/dsv/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "scripts": { "build": "rollup -c", @@ -59,7 +65,7 @@ "del-cli": "^5.0.0", "rollup": "^4.0.0-24" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/dynamic-import-vars/package.json b/packages/dynamic-import-vars/package.json index d25ea21b9..e9e5eae44 100644 --- a/packages/dynamic-import-vars/package.json +++ b/packages/dynamic-import-vars/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -74,7 +80,7 @@ "prettier": "^2.7.1", "rollup": "^4.0.0-24" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/eslint/package.json b/packages/eslint/package.json index 7681a688c..300d3b6ea 100755 --- a/packages/eslint/package.json +++ b/packages/eslint/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -72,7 +78,7 @@ "rollup": "^4.0.0-24", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "files": [ "!**/fixtures/**", diff --git a/packages/esm-shim/package.json b/packages/esm-shim/package.json index e9ba2c84a..80d3eb841 100644 --- a/packages/esm-shim/package.json +++ b/packages/esm-shim/package.json @@ -13,12 +13,18 @@ "author": "Peter Placzek ", "homepage": "https://github.com/rollup/plugins/tree/master/packages/esm-shim#readme", "bugs": "https://github.com/rollup/plugins/issues", - "main": "dist/cjs/index.js", - "module": "dist/es/index.js", + "main": "./dist/cjs/index.js", + "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -66,5 +72,5 @@ "rollup": "^4.0.0-24", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts" + "types": "./dist/cjs/index.d.ts" } diff --git a/packages/graphql/package.json b/packages/graphql/package.json index dc3565952..776df27b3 100644 --- a/packages/graphql/package.json +++ b/packages/graphql/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -71,7 +77,7 @@ "graphql": "^16.6.0", "rollup": "^4.0.0-24" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/html/package.json b/packages/html/package.json index 2f53e9062..ebb6a89e2 100644 --- a/packages/html/package.json +++ b/packages/html/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -65,7 +71,7 @@ "rollup-plugin-postcss": "^4.0.2", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/image/package.json b/packages/image/package.json index 17eac8963..f0190f49f 100644 --- a/packages/image/package.json +++ b/packages/image/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -65,7 +71,7 @@ "@rollup/plugin-buble": "^1.0.0", "rollup": "^4.0.0-24" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/inject/package.json b/packages/inject/package.json index 7ecabd25f..5324a8cda 100644 --- a/packages/inject/package.json +++ b/packages/inject/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -73,7 +79,7 @@ "source-map": "^0.7.4", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "files": [ "!**/fixtures/**", diff --git a/packages/json/package.json b/packages/json/package.json index 5851ef6ed..78d2b9b9c 100755 --- a/packages/json/package.json +++ b/packages/json/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -69,7 +75,7 @@ "rollup": "^4.0.0-24", "source-map-support": "^0.5.21" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/legacy/package.json b/packages/legacy/package.json index 04b027ecd..a0294a7a8 100644 --- a/packages/legacy/package.json +++ b/packages/legacy/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -63,7 +69,7 @@ "del-cli": "^5.0.0", "rollup": "^4.0.0-24" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/multi-entry/package.json b/packages/multi-entry/package.json index 699a0eac1..732b0c212 100755 --- a/packages/multi-entry/package.json +++ b/packages/multi-entry/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -66,7 +72,7 @@ "devDependencies": { "rollup": "^4.0.0-24" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "files": [ "!**/fixtures/**", diff --git a/packages/node-resolve/package.json b/packages/node-resolve/package.json index 77ea2a20b..a533f0062 100644 --- a/packages/node-resolve/package.json +++ b/packages/node-resolve/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -78,7 +84,7 @@ "source-map": "^0.7.4", "string-capitalize": "^1.0.1" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/pluginutils/package.json b/packages/pluginutils/package.json index 2745ddcce..adb1481b5 100644 --- a/packages/pluginutils/package.json +++ b/packages/pluginutils/package.json @@ -19,9 +19,14 @@ "module": "./dist/es/index.js", "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -75,7 +80,7 @@ "rollup": "^4.0.0-24", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "extensions": [ "ts" diff --git a/packages/replace/package.json b/packages/replace/package.json index 0a07d5abe..08ff85cd4 100644 --- a/packages/replace/package.json +++ b/packages/replace/package.json @@ -13,12 +13,18 @@ "author": "Rich Harris ", "homepage": "https://github.com/rollup/plugins/tree/master/packages/replace#readme", "bugs": "https://github.com/rollup/plugins/issues", - "main": "dist/cjs/index.js", - "module": "dist/es/index.js", + "main": "./dist/cjs/index.js", + "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -72,7 +78,7 @@ "source-map": "^0.7.4", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/run/package.json b/packages/run/package.json index e13c22be4..31b04bb2b 100644 --- a/packages/run/package.json +++ b/packages/run/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -66,7 +72,7 @@ "sinon": "^14.0.0", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/strip/package.json b/packages/strip/package.json index b3272cede..080e81a91 100644 --- a/packages/strip/package.json +++ b/packages/strip/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -63,7 +69,7 @@ "acorn": "^8.8.0", "rollup": "^4.0.0-24" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "files": [ "!**/fixtures/**", diff --git a/packages/sucrase/package.json b/packages/sucrase/package.json index 986376ab6..6f17356b4 100644 --- a/packages/sucrase/package.json +++ b/packages/sucrase/package.json @@ -17,9 +17,14 @@ "module": "./dist/es/index.js", "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -69,7 +74,7 @@ "@rollup/plugin-alias": "^4.0.0", "rollup": "^4.0.0-24" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/swc/package.json b/packages/swc/package.json index 3dee9d25e..f0015a7a4 100644 --- a/packages/swc/package.json +++ b/packages/swc/package.json @@ -13,12 +13,18 @@ "author": "Peter Placzek ", "homepage": "https://github.com/rollup/plugins/tree/master/packages/swc#readme", "bugs": "https://github.com/rollup/plugins/issues", - "main": "dist/cjs/index.js", - "module": "dist/es/index.js", + "main": "./dist/cjs/index.js", + "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -70,5 +76,5 @@ "rollup": "^4.0.0-24", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts" + "types": "./dist/cjs/index.d.ts" } diff --git a/packages/terser/package.json b/packages/terser/package.json index 24f9a35a6..d3598091f 100644 --- a/packages/terser/package.json +++ b/packages/terser/package.json @@ -13,12 +13,18 @@ "author": "Peter Placzek ", "homepage": "https://github.com/rollup/plugins/tree/master/packages/terser#readme", "bugs": "https://github.com/rollup/plugins/issues", - "main": "dist/cjs/index.js", - "module": "dist/es/index.js", + "main": "./dist/cjs/index.js", + "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -70,5 +76,5 @@ "rollup": "^4.0.0-24", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts" + "types": "./dist/cjs/index.d.ts" } diff --git a/packages/typescript/package.json b/packages/typescript/package.json index 3504f38e3..e887f1530 100644 --- a/packages/typescript/package.json +++ b/packages/typescript/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -76,5 +82,5 @@ "rollup": "^4.0.0-24", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts" + "types": "./dist/cjs/index.d.ts" } diff --git a/packages/url/package.json b/packages/url/package.json index 6883535d5..12e91ecfd 100644 --- a/packages/url/package.json +++ b/packages/url/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -66,7 +72,7 @@ "globby": "^11.1.0", "rollup": "^4.0.0-24" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/virtual/package.json b/packages/virtual/package.json index e3bf35706..b02f8f4ff 100755 --- a/packages/virtual/package.json +++ b/packages/virtual/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -66,7 +72,7 @@ "rollup": "^4.0.0-24", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "files": [ "!**/fixtures/**", diff --git a/packages/wasm/package.json b/packages/wasm/package.json index c4723c27b..cb0aeeae5 100644 --- a/packages/wasm/package.json +++ b/packages/wasm/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -72,7 +78,7 @@ "source-map": "^0.7.4", "typescript": "^4.8.3" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/packages/yaml/package.json b/packages/yaml/package.json index cd7c102ab..8b1dca0f9 100755 --- a/packages/yaml/package.json +++ b/packages/yaml/package.json @@ -15,10 +15,16 @@ "bugs": "https://github.com/rollup/plugins/issues", "main": "./dist/cjs/index.js", "module": "./dist/es/index.js", + "type": "commonjs", "exports": { - "types": "./types/index.d.ts", - "import": "./dist/es/index.js", - "default": "./dist/cjs/index.js" + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + }, + "import": { + "types": "./dist/es/index.d.ts", + "default": "./dist/es/index.js" + } }, "engines": { "node": ">=14.0.0" @@ -67,7 +73,7 @@ "rollup": "^4.0.0-24", "source-map-support": "^0.5.21" }, - "types": "./types/index.d.ts", + "types": "./dist/cjs/index.d.ts", "ava": { "workerThreads": false, "files": [ diff --git a/shared/rollup.config.mjs b/shared/rollup.config.mjs index 377390a95..f113b4b00 100644 --- a/shared/rollup.config.mjs +++ b/shared/rollup.config.mjs @@ -1,12 +1,15 @@ +// @ts-check import { builtinModules } from 'module'; +import fs from 'node:fs/promises'; // eslint-disable-next-line import/no-extraneous-dependencies import typescript from '@rollup/plugin-typescript'; /** * Create a base rollup config - * @param {Record} pkg Imported package.json - * @param {string[]} external Imported package.json + * @param {Object} param + * @param {Record} param.pkg Imported package.json + * @param {string[]} [param.external] Dependencies that should remain external * @returns {import('rollup').RollupOptions} */ export function createConfig({ pkg, external = [] }) { @@ -26,12 +29,13 @@ export function createConfig({ pkg, external = [] }) { file: pkg.main, exports: 'named', footer: 'module.exports = Object.assign(exports.default, exports);', + plugins: emitCjsTypings(), sourcemap: true }, { format: 'es', file: pkg.module, - plugins: [emitModulePackageFile()], + plugins: emitEsmTypings(), sourcemap: true } ], @@ -39,14 +43,56 @@ export function createConfig({ pkg, external = [] }) { }; } -export function emitModulePackageFile() { +/** + * @returns {Array} + */ +export function emitCjsTypings() { + return [ + { + name: 'emit-cjs-types', + async generateBundle() { + this.emitFile({ + type: 'asset', + fileName: `index.d.ts`, + source: await fs.readFile('./types/index.d.ts') + }); + } + }, + emitPackageFile('commonjs') + ]; +} + +/** + * @returns {Array} + */ +function emitEsmTypings() { + return [ + { + name: 'emit-esm-declaration-file', + async generateBundle() { + this.emitFile({ + type: 'asset', + fileName: `index.d.ts`, + source: await fs.readFile('./types/index.d.ts') + }); + } + }, + emitPackageFile('module') + ]; +} + +/** + * @param {'module' | 'commonjs'} type + * @returns {import('rollup').Plugin} + */ +function emitPackageFile(type) { return { - name: 'emit-module-package-file', + name: 'emit-package-file', generateBundle() { this.emitFile({ type: 'asset', fileName: 'package.json', - source: `{"type":"module"}` + source: `{"type":"${type}"}` }); } };