Skip to content

Commit

Permalink
feat: add declaration maps for consumers
Browse files Browse the repository at this point in the history
- 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. ezolenko/rollup-plugin-typescript2#221
      and the worse downstream version I had written first:
      jaredpalmer/tsdx#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:
    ezolenko/rollup-plugin-typescript2#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) :/
  • Loading branch information
agilgur5 committed Apr 20, 2022
1 parent 646b4b3 commit e3ac22d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions 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",
}

0 comments on commit e3ac22d

Please sign in to comment.