From 21f8f3730e6fcf83488136dd21ac3c14608b81f8 Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Fri, 6 Dec 2024 22:42:09 +0100 Subject: [PATCH] fix rollup and source map paths --- scripts/rollup.config.mjs | 21 +++++++++++++-------- tsconfig.json | 1 - 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/scripts/rollup.config.mjs b/scripts/rollup.config.mjs index de0eff9..7fba7d5 100644 --- a/scripts/rollup.config.mjs +++ b/scripts/rollup.config.mjs @@ -28,7 +28,15 @@ export default defineConfig([ }), ], external: /node_modules/, - plugins: [del({ targets: 'dist/*' }), nodeResolve(), typescript()], + plugins: [ + del({ targets: 'dist/*' }), + nodeResolve(), + typescript({ + compilerOptions: { + outDir: path.dirname(pkg.exports['.'].import), + }, + }), + ], }, // es5 entry point @@ -55,6 +63,8 @@ export default defineConfig([ declaration: false, declarationMap: false, outDir: path.dirname(pkg.exports['./es5'].import), + // This is needed to correct source map paths + sourceRoot: '../src', }, }), ], @@ -62,7 +72,7 @@ export default defineConfig([ // Type declarations of default and es5 entry points { - input: 'dist/types/index.d.ts', + input: 'dist/index.d.ts', output: { file: pkg.exports['.'].types, format: 'esm', @@ -70,7 +80,7 @@ export default defineConfig([ plugins: [ dts(), del({ - targets: 'dist/types', + targets: ['dist/lib', 'dist/index.d.ts'], hook: 'buildEnd', runOnce: true, }), @@ -94,11 +104,6 @@ function getOutputConfig({ file, format, targets }) { sourcemap: true, freeze: false, generatedCode: 'es2015', - sourcemapPathTransform(relativeSourcePath) { - // This is necessary because of the tsconfig.compilerOptions.outDir option resulting in a path one level deeper than the output directory. - // But we also don't want to sync those output paths because that would make the setup for rollup-plugin-delete more complicated. - return relativeSourcePath.replace('../', '') - }, plugins: [ getBabelOutputPlugin({ presets: [ diff --git a/tsconfig.json b/tsconfig.json index ddf2b38..ebc5c92 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,6 @@ // Emit "declaration": true, "noEmit": true, - "outDir": "dist/types", "sourceMap": true, // Interop Constraints "esModuleInterop": true,