Skip to content

Commit

Permalink
build(bazel): allow a user to control a subset of angularCompilerOpti…
Browse files Browse the repository at this point in the history
…on in their tsconfig file when using ng_module (#28995)

PR Close #28995
  • Loading branch information
gregmagolan authored and benlesh committed Feb 27, 2019
1 parent cb339b8 commit 09fc669
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions packages/bazel/src/ngc-wrapped/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,64 @@ export function runOneBuild(args: string[], inputs?: {[path: string]: string}):
return false;
}
const {options: tsOptions, bazelOpts, files, config} = parsedOptions;
const angularCompilerOptions: {[k: string]: unknown} = config['angularCompilerOptions'] || {};

// Allow Bazel users to control some of the bazel options.
// Since TypeScript's "extends" mechanism applies only to "compilerOptions"
// we have to repeat some of their logic to get the user's "angularCompilerOptions".
if (config['extends']) {
// Load the user's config file
// Note: this doesn't handle recursive extends so only a user's top level
// `angularCompilerOptions` will be considered. As this code is going to be
// removed with Ivy, the added complication of handling recursive extends
// is likely not needed.
let userConfigFile =
resolveNormalizedPath(path.dirname(project), config['extends']);
if (!userConfigFile.endsWith('.json')) userConfigFile += '.json';
const {config: userConfig, error} =
ts.readConfigFile(userConfigFile, ts.sys.readFile);
if (error) {
console.error(ng.formatDiagnostics([error]));
return false;
}

// All user angularCompilerOptions values that a user has control
// over should be collected here
if (userConfig.angularCompilerOptions) {
angularCompilerOptions.diagnostics = angularCompilerOptions.diagnostics ||
userConfig.angularCompilerOptions.diagnostics;
angularCompilerOptions.trace = angularCompilerOptions.trace ||
userConfig.angularCompilerOptions.trace;

angularCompilerOptions.disableExpressionLowering = angularCompilerOptions.disableExpressionLowering ||
userConfig.angularCompilerOptions.disableExpressionLowering;
angularCompilerOptions.disableTypeScriptVersionCheck = angularCompilerOptions.disableTypeScriptVersionCheck ||
userConfig.angularCompilerOptions.disableTypeScriptVersionCheck;

angularCompilerOptions.i18nOutLocale = angularCompilerOptions.i18nOutLocale ||
userConfig.angularCompilerOptions.i18nOutLocale;
angularCompilerOptions.i18nOutFormat = angularCompilerOptions.i18nOutFormat ||
userConfig.angularCompilerOptions.i18nOutFormat;
angularCompilerOptions.i18nOutFile = angularCompilerOptions.i18nOutFile ||
userConfig.angularCompilerOptions.i18nOutFile;

angularCompilerOptions.i18nInFormat = angularCompilerOptions.i18nInFormat ||
userConfig.angularCompilerOptions.i18nInFormat;
angularCompilerOptions.i18nInLocale = angularCompilerOptions.i18nInLocale ||
userConfig.angularCompilerOptions.i18nInLocale;
angularCompilerOptions.i18nInFile = angularCompilerOptions.i18nInFile ||
userConfig.angularCompilerOptions.i18nInFile;

angularCompilerOptions.i18nInMissingTranslations = angularCompilerOptions.i18nInMissingTranslations ||
userConfig.angularCompilerOptions.i18nInMissingTranslations;
angularCompilerOptions.i18nUseExternalIds = angularCompilerOptions.i18nUseExternalIds ||
userConfig.angularCompilerOptions.i18nUseExternalIds;

angularCompilerOptions.preserveWhitespaces = angularCompilerOptions.preserveWhitespaces ||
userConfig.angularCompilerOptions.preserveWhitespaces;
}
}

const expectedOuts = config['angularCompilerOptions']['expectedOut'];

const {basePath} = ng.calcProjectFileAndBasePath(project);
Expand Down

0 comments on commit 09fc669

Please sign in to comment.