-
Notifications
You must be signed in to change notification settings - Fork 71
/
get-options-overrides.ts
74 lines (61 loc) · 2.64 KB
/
get-options-overrides.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import * as path from "path";
import * as tsTypes from "typescript";
import { createFilter as createRollupFilter, normalizePath as normalize } from "@rollup/pluginutils";
import { tsModule } from "./tsproxy";
import { IOptions } from "./ioptions";
import { IContext } from "./context";
export function getOptionsOverrides({ useTsconfigDeclarationDir, cacheRoot }: IOptions, preParsedTsconfig?: tsTypes.ParsedCommandLine): tsTypes.CompilerOptions
{
const overrides: tsTypes.CompilerOptions = {
noEmitHelpers: false,
importHelpers: true,
noResolve: false,
noEmit: false,
noEmitOnError: false,
inlineSourceMap: false,
outDir: normalize(`${cacheRoot}/placeholder`), // need an outdir that is different from source or tsconfig parsing trips up. https://github.com/Microsoft/TypeScript/issues/24715
moduleResolution: tsModule.ModuleResolutionKind.NodeJs,
allowNonTsExtensions: true,
};
if (!preParsedTsconfig)
return overrides;
if (preParsedTsconfig.options.module === undefined)
overrides.module = tsModule.ModuleKind.ES2015;
// only set declarationDir if useTsconfigDeclarationDir is enabled
if (!useTsconfigDeclarationDir)
overrides.declarationDir = undefined;
// 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;
if (!sourceMap)
overrides.sourceRoot = undefined;
return overrides;
}
function expandIncludeWithDirs(include: string | string[], dirs: string[])
{
const newDirs: string[] = [];
dirs.forEach(root => {
if (include instanceof Array)
include.forEach(x => newDirs.push(normalize(path.join(root, x))));
else
newDirs.push(normalize(path.join(root, include)));
});
return newDirs;
}
export function createFilter(context: IContext, pluginOptions: IOptions, parsedConfig: tsTypes.ParsedCommandLine)
{
let included = pluginOptions.include;
let excluded = pluginOptions.exclude;
if (parsedConfig.options.rootDirs)
{
included = expandIncludeWithDirs(included, parsedConfig.options.rootDirs);
excluded = expandIncludeWithDirs(excluded, parsedConfig.options.rootDirs);
}
if (parsedConfig.projectReferences)
{
included = expandIncludeWithDirs(included, parsedConfig.projectReferences.map((x) => x.path)).concat(included);
excluded = expandIncludeWithDirs(excluded, parsedConfig.projectReferences.map((x) => x.path)).concat(excluded);
}
context.debug(() => `included:\n${JSON.stringify(included, undefined, 4)}`);
context.debug(() => `excluded:\n${JSON.stringify(excluded, undefined, 4)}`);
return createRollupFilter(included, excluded, { resolve: parsedConfig.options.rootDir });
}