From c6b1eb75ec2786707e4c3787e6565fa45ac9e91b Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 5 May 2022 12:20:16 -0700 Subject: [PATCH] fix: rollup dts --- package.json | 7 ++++--- rollup.config.cjs | 11 ++++++++++- tsconfig.json | 2 +- yarn.lock | 18 +++++++++++++++++- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index b3f0fb054..e05d94ec9 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "dist" ], "type": "module", - "types": "dist/dts/index.d.ts", + "types": "dist/index.d.ts", "main": "dist/cjs/index.cjs", "module": "dist/index.js", "exports": { @@ -34,9 +34,9 @@ "i18n:compile": "yarn i18n:extract && lingui compile", "i18n:pseudo": "lingui extract --locale pseudo && lingui compile", "prepare": "yarn contracts:compile && yarn i18n:compile", - "prepublishOnly": "tsc && yarn build", + "prepublishOnly": "yarn build", "start": "cosmos", - "build": "rollup --config --failAfterWarnings", + "build": "tsc && rollup --config --failAfterWarnings", "release": "semantic-release", "lint": "eslint .", "test": "jest" @@ -182,6 +182,7 @@ "react-test-renderer": "^18.0.0", "redux": "^4.1.2", "rollup": "^2.63.0", + "rollup-plugin-dts": "^4.2.1", "rollup-plugin-multi-input": "^1.3.1", "rollup-plugin-node-externals": "^3.1.2", "rollup-plugin-scss": "^3.0.0", diff --git a/rollup.config.cjs b/rollup.config.cjs index 6dbdb03e8..ed6202a07 100644 --- a/rollup.config.cjs +++ b/rollup.config.cjs @@ -9,6 +9,7 @@ const commonjs = require('@rollup/plugin-commonjs') const json = require('@rollup/plugin-json') const { nodeResolve: resolve } = require('@rollup/plugin-node-resolve') const replace = require('@rollup/plugin-replace') +const { default: dts } = require('rollup-plugin-dts') const url = require('@rollup/plugin-url') const svgr = require('@svgr/rollup') const { default: multi } = require('rollup-plugin-multi-input') @@ -89,6 +90,14 @@ const cjs = { watch: false, } +const types = { + input: 'dts/index.d.ts', + output: { file: 'dist/index.d.ts' }, + external: (source) => source.endsWith('.scss'), + plugins: [dts({ compilerOptions: { baseUrl: 'dts' } })], + watch: false, +} + const locales = { input: 'src/locales/*.js', output: [ @@ -117,7 +126,7 @@ const assets = [ }, ] -const config = [esm, cjs, locales] +const config = [esm, cjs, types, locales] config.config = { ...esm, output: { ...esm.output, sourcemap: true } } config.assets = assets module.exports = config diff --git a/tsconfig.json b/tsconfig.json index e1393f30b..9c9009610 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,7 @@ "allowSyntheticDefaultImports": true, "baseUrl": "src", "declaration": true, - "declarationDir": "dist/dts", + "declarationDir": "dts", "downlevelIteration": true, "emitDeclarationOnly": true, "esModuleInterop": true, diff --git a/yarn.lock b/yarn.lock index 73abc0d9c..9ef2367d9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8653,6 +8653,13 @@ magic-string@^0.25.7: dependencies: sourcemap-codec "^1.4.4" +magic-string@^0.26.1: + version "0.26.1" + resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.26.1.tgz#ba9b651354fa9512474199acecf9c6dbe93f97fd" + integrity sha512-ndThHmvgtieXe8J/VGPjG+Apu7v7ItcD5mhEIvOscWjPF/ccOiLxHaSuCAS2G+3x4GKsAbT8u7zdyamupui8Tg== + dependencies: + sourcemap-codec "^1.4.8" + make-dir@^3.0.0, make-dir@^3.0.2, make-dir@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f" @@ -10781,6 +10788,15 @@ rimraf@~2.4.0: dependencies: glob "^6.0.1" +rollup-plugin-dts@^4.2.1: + version "4.2.1" + resolved "https://registry.yarnpkg.com/rollup-plugin-dts/-/rollup-plugin-dts-4.2.1.tgz#c17968a0f7c5ae70a9e0ab37e715f3ef63da01c7" + integrity sha512-eaxQZNUJ5iQcxNGlpJ1CUgG4OSVqWjDZ3nNSWBIoGrpcote2aNphSe1RJOaSYkb8dwn3o+rYm1vvld/5z3EGSQ== + dependencies: + magic-string "^0.26.1" + optionalDependencies: + "@babel/code-frame" "^7.16.7" + rollup-plugin-multi-input@^1.3.1: version "1.3.1" resolved "https://registry.yarnpkg.com/rollup-plugin-multi-input/-/rollup-plugin-multi-input-1.3.1.tgz#07b903b618c005871fea1bd0c4efae7d1aac4fa1" @@ -11220,7 +11236,7 @@ source-map@~0.8.0-beta.0: dependencies: whatwg-url "^7.0.0" -sourcemap-codec@^1.4.4: +sourcemap-codec@^1.4.4, sourcemap-codec@^1.4.8: version "1.4.8" resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz#ea804bd94857402e6992d05a38ef1ae35a9ab4c4" integrity sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==