From 6c44f3d24598d1ab31b63aceaa7164ded3a68c12 Mon Sep 17 00:00:00 2001 From: EGOIST <0x142857@gmail.com> Date: Sat, 25 Dec 2021 12:00:48 +0800 Subject: [PATCH] fix(dts): apply required defaults to rollup-plugin-dts, closes emitted dts is bundled source #509 --- package.json | 2 +- src/rollup.ts | 14 ++++++++++++++ tsup.config.ts | 24 ------------------------ 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 18ad2091..3ab32497 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "wait-for-expect": "^3.0.2" }, "peerDependencies": { - "typescript": "^4.5.4" + "typescript": "^4.1.0" }, "peerDependenciesMeta": { "typescript": { diff --git a/src/rollup.ts b/src/rollup.ts index d01a3e05..b309c8d7 100644 --- a/src/rollup.ts +++ b/src/rollup.ts @@ -155,6 +155,20 @@ const getRollupConfig = async ( compilerOptions: { ...compilerOptions, baseUrl: path.resolve(compilerOptions.baseUrl || '.'), + // Ensure ".d.ts" modules are generated + declaration: true, + // Skip ".js" generation + noEmit: false, + emitDeclarationOnly: true, + // Skip code generation when error occurs + noEmitOnError: true, + // Avoid extra work + checkJs: false, + declarationMap: false, + skipLibCheck: true, + preserveSymlinks: false, + // Ensure we can parse the latest code + target: ts.ScriptTarget.ESNext, }, }), ].filter(Boolean), diff --git a/tsup.config.ts b/tsup.config.ts index f13b48d5..18f862e1 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -9,28 +9,4 @@ export default defineConfig({ // otherwise `Options` will not be exported by `tsup`, not sure how this happens, probbably a bug in rollup-plugin-dts entry: './src/index.ts', }, - esbuildPlugins: [ - { - name: 'patch-rollup-plugin-dts', - setup(build) { - let removed = false - build.onLoad({ filter: /rollup-plugin-dts/ }, async (args) => { - const code = await fs.promises.readFile(args.path, 'utf-8') - const RE = /preserveSymlinks:\s+true,/ - if (RE.test(code)) { - removed = true - } - return { - contents: code.replace(RE, ''), - loader: 'js', - } - }) - build.onEnd(() => { - if (!removed) { - throw new Error('rollup-plugin-dts was not patched') - } - }) - }, - }, - ], })