UNPKG

1.19 kBPlain TextView Raw
1import { tsModule } from "./tsproxy";
2import * as tsTypes from "typescript";
3import { IOptions } from "./ioptions";
4import * as _ from "lodash";
5
6export function getOptionsOverrides({ useTsconfigDeclarationDir, cacheRoot }: IOptions, tsConfigJson?: any): tsTypes.CompilerOptions
7{
8 const overrides = {
9 noEmitHelpers: false,
10 importHelpers: true,
11 noResolve: false,
12 noEmit: false,
13 inlineSourceMap: false,
14 outDir: `${cacheRoot}/placeholder`, // need an outdir that is different from source or tsconfig parsing trips up. https://github.com/Microsoft/TypeScript/issues/24715
15 moduleResolution: tsModule.ModuleResolutionKind.NodeJs,
16 };
17
18 const declaration = _.get(tsConfigJson, "compilerOptions.declaration", false);
19
20 if (!declaration)
21 (overrides as any).declarationDir = null;
22 if (declaration && !useTsconfigDeclarationDir)
23 (overrides as any).declarationDir = process.cwd();
24
25 // unsetting sourceRoot if sourceMap is not enabled (in case original tsconfig had inlineSourceMap set that is being unset and would cause TS5051)
26 const sourceMap = _.get(tsConfigJson, "compilerOptions.sourceMap", false);
27 if (!sourceMap)
28 (overrides as any).sourceRoot = null;
29
30 return overrides;
31}