Skip to content

Commit

Permalink
(fix): declaration maps should have correct sources
Browse files Browse the repository at this point in the history
- change declarationDir default to be Rollup's output destination
  instead of cwd
  - previously, it was set to cwd if useTsconfigDeclarationDir wasn't
    true, however, declarations aren't output to cwd, but to Rollup's
    output destination, so this was incorrect

- also change the one line in the docs that says it'll be
  `process.cwd()`; every other reference says it'll be the output dest
  • Loading branch information
agilgur5 committed Mar 29, 2020
1 parent 294d654 commit f107eba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -46,7 +46,7 @@ The plugin inherits all compiler options and file lists from your `tsconfig.json
* `noEmit`: false
* `inlineSourceMap`: false (see [#71](https://github.com/ezolenko/rollup-plugin-typescript2/issues/71))
* `outDir`: `./placeholder` in cache root, see [83](https://github.com/ezolenko/rollup-plugin-typescript2/issues/83) and [Microsoft/TypeScript/issues/24715](https://github.com/Microsoft/TypeScript/issues/24715)
* `declarationDir`: `process.cwd()` (*only if `useTsconfigDeclarationDir` is false in the plugin options*)
* `declarationDir`: Rollup's `output.file` or `output.dir` (*only if `useTsconfigDeclarationDir` is false in the plugin options*)
* `moduleResolution`: `node` (*`classic` is [deprecated](https://www.typescriptlang.org/docs/handbook/module-resolution.html). It also breaks this plugin, see [#12](https://github.com/ezolenko/rollup-plugin-typescript2/issues/12) and [#14](https://github.com/ezolenko/rollup-plugin-typescript2/issues/14)*)
* `allowNonTsExtensions`: true to let other plugins on the chain generate typescript, update plugin's include filter to pick them up (see [#111](https://github.com/ezolenko/rollup-plugin-typescript2/issues/111))

Expand Down
4 changes: 1 addition & 3 deletions src/get-options-overrides.ts
Expand Up @@ -6,7 +6,7 @@ import * as _ from "lodash";
import { join } from "path";
import { IContext } from "./context";

export function getOptionsOverrides({ useTsconfigDeclarationDir, cacheRoot, cwd }: IOptions, preParsedTsconfig?: tsTypes.ParsedCommandLine): tsTypes.CompilerOptions
export function getOptionsOverrides({ cacheRoot }: IOptions, preParsedTsconfig?: tsTypes.ParsedCommandLine): tsTypes.CompilerOptions
{
const overrides: tsTypes.CompilerOptions = {
noEmitHelpers: false,
Expand All @@ -27,8 +27,6 @@ export function getOptionsOverrides({ useTsconfigDeclarationDir, cacheRoot, cwd
const declaration = preParsedTsconfig.options.declaration;
if (!declaration)
overrides.declarationDir = undefined;
if (declaration && !useTsconfigDeclarationDir)
overrides.declarationDir = cwd;

// unsetting sourceRoot if sourceMap is not enabled (in case original tsconfig had inlineSourceMap set that is being unset and would cause TS5051)
const sourceMap = preParsedTsconfig.options.sourceMap;
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Expand Up @@ -12,7 +12,7 @@ import { parseTsConfig } from "./parse-tsconfig";
import { printDiagnostics } from "./print-diagnostics";
import { TSLIB, TSLIB_VIRTUAL, tslibSource, tslibVersion } from "./tslib";
import { blue, red, yellow, green } from "colors/safe";
import { relative } from "path";
import { relative, dirname } from "path";
import { normalize } from "./normalize";
import { satisfies } from "semver";
import findCacheDir from "find-cache-dir";
Expand Down Expand Up @@ -326,6 +326,11 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
if (!parsedConfig.options.declaration)
return;

if (!pluginOptions.useTsconfigDeclarationDir)
parsedConfig.options.declarationDir = _output.file
? dirname(_output.file)
: _output.dir;

_.each(parsedConfig.fileNames, (name) =>
{
const key = normalize(name);
Expand Down

0 comments on commit f107eba

Please sign in to comment.