From 1c501117cdf7aec3bb47f9e7405a4a9fd3ba8ed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaus=20Nyga=CC=8Ard?= Date: Sun, 11 Feb 2024 10:27:20 +0200 Subject: [PATCH] fix exports in package.json, add index.d.cts to dist --- .changeset/spicy-boxes-cry.md | 5 +++++ package.json | 11 +++-------- vite.config.js | 12 +++++++++++- 3 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 .changeset/spicy-boxes-cry.md diff --git a/.changeset/spicy-boxes-cry.md b/.changeset/spicy-boxes-cry.md new file mode 100644 index 00000000..6201fdae --- /dev/null +++ b/.changeset/spicy-boxes-cry.md @@ -0,0 +1,5 @@ +--- +"react-share": patch +--- + +Fixed `exports` in package.json to comply with the `publint` and `attw` tools. May solve issues when your project uses CommonJS modules and Node.js v16 or newer. diff --git a/package.json b/package.json index 9dbd9023..ba6bcd8d 100644 --- a/package.json +++ b/package.json @@ -7,16 +7,11 @@ "types": "./dist/index.d.ts", "module": "./dist/index.js", "exports": { - ".": { - "import": "./dist/index.js", - "require": "./dist/index.cjs", - "types": "./dist/index.d.ts" - } + "import": "./dist/index.js", + "require": "./dist/index.cjs" }, "sideEffects": false, - "files": [ - "dist" - ], + "files": ["dist"], "scripts": { "build": "vite build", "build-demo": "vite build --config vite.demo.config.js", diff --git a/vite.config.js b/vite.config.js index 6bf65c25..59d36af9 100644 --- a/vite.config.js +++ b/vite.config.js @@ -7,7 +7,17 @@ import dts from 'vite-plugin-dts'; const { dependencies, peerDependencies } = JSON.parse(fs.readFileSync(`./package.json`, 'utf8')); export default defineConfig({ - plugins: [react(), dts({ rollupTypes: true })], + plugins: [ + react(), + dts({ + rollupTypes: true, + afterBuild: () => { + // https://github.com/qmhc/vite-plugin-dts/issues/267 + fs.copyFileSync('dist/index.d.ts', 'dist/index.d.cts'); + }, + }), + ], + build: { target: 'es2017', lib: {