Skip to content

Merge compiler options deep #14178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,26 @@ namespace ts {
return output;
}

/**
* Merge compiler options of a config file (tsconfig.json) with "extend" config.
* For primitive types overrides values from extend with value from main config file.
* For arrays (e.g. "lib"") concats and dedup them.
*
* @param baseOptions
* @param options
*/
export function mergeCompilerOptions(baseOptions: CompilerOptions, options: CompilerOptions): CompilerOptions {
return Object.keys(options).reduce((newOptions, key) => {
const param = options[key];
if (!newOptions.hasOwnProperty(key) || !Array.isArray(newOptions[key])) {
newOptions[key] = param;
return newOptions;
}
newOptions[key] = deduplicate<any>((newOptions[key] as any).concat(param));
return newOptions;
}, assign({}, baseOptions));
}

/**
* Parse the contents of a config file (tsconfig.json).
* @param json The contents of the config file to parse
Expand Down Expand Up @@ -896,7 +916,8 @@ namespace ts {
if (files && !json["files"]) {
json["files"] = files;
}
options = assign({}, baseOptions, options);

options = mergeCompilerOptions(baseOptions, options);
}

options = extend(existingOptions, options);
Expand Down