From b14060c4cf8e40cbd8f54fee830d4b6b680f007a Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Wed, 20 Apr 2022 17:11:17 -0400 Subject: [PATCH] feat: add declaration maps for consumers - fancy source maps for declarations - apparently I left these out of `ts-library-base` so they didn't get copied here either - but most of my tsconfig there was copied too, so I suspect I left it out either because of @wessberg/rollup-plugin-ts's bugs with it or because TSDX previously had bugs with it - c.f. https://github.com/ezolenko/rollup-plugin-typescript2/pull/221 and the worse downstream version I had written first: https://github.com/jaredpalmer/tsdx/pull/488 - Unfortunately I did encounter a small error with declaration maps when using rpts2 as a configPlugin, due to an unexpected edge case in code I wrote myself in the above PR - wrote up an issue for it and will probably PR it myself too: https://github.com/ezolenko/rollup-plugin-typescript2/issues/310 - as a workaround, I wrote a small `tsconfig.rollup.json` to be used with rpts2 as a configPlugin that disables `declarationMap` - and also adds some optimizations over my base tsconfig - took me a bit to figure out how to use options with configPlugins, as that was one of the reasons I didn't use @rollup/plugin-babel as the configPlugin - I still can't get it to read my `babel.config.js` even with options as it has no option for this (it auto-detects it) :/ --- package.json | 2 +- tsconfig.json | 2 ++ tsconfig.rollup.json | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tsconfig.rollup.json diff --git a/package.json b/package.json index c173f49..fc6a033 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "clean": "rm -rf dist/ && rm -f *.tgz", "clean:build": "npm run clean && npm run build", "build": "concurrently -n rollup,tsc \"npm run build:rollup\" \"npm run build:types\"", - "build:rollup": "rollup -c rollup.config.ts --configPlugin rollup-plugin-typescript2", + "build:rollup": "rollup -c rollup.config.ts --configPlugin \"rollup-plugin-typescript2={ tsconfig: 'tsconfig.rollup.json' } \" ", "build:types": "tsc -p tsconfig.build.json", "build:watch": "concurrently -n rollup,tsc \"npm run build:rollup -- -w\" \"npm run build:types -- -w\"", "tsc": "tsc", diff --git a/tsconfig.json b/tsconfig.json index 1d7d016..a008b62 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,8 @@ "outDir": "dist/", // output .d.ts declaration files for consumers "declaration": true, + // output .d.ts.map declaration map files for consumers + "declarationMap": true, // output .js.map sourcemap files for consumers "sourceMap": true, // use Node's module resolution algorithm, instead of the legacy TS one diff --git a/tsconfig.rollup.json b/tsconfig.rollup.json new file mode 100644 index 0000000..d834bfd --- /dev/null +++ b/tsconfig.rollup.json @@ -0,0 +1,12 @@ +{ + // tsconfig.json is used for type-checking _all_ files, tsconfig.rollup.json is just used for parsing rollup.config.ts + "extends": "./tsconfig.json", + // allowlist of files to build -- this is just an optimization + "files": ["rollup.config.ts"], + "compilerOptions": { + // this is currently erroring when used for configPlugins: https://github.com/ezolenko/rollup-plugin-typescript2/issues/310 + "declarationMap": false, + }, + // read this file as a tsconfig even though it's named slightly differently + "$schema": "https://json.schemastore.org/tsconfig", +}