Skip to content
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

build(bazel): allow a user to control a subset of angularCompilerOption in their tsconfig file when using ng_module #28995

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 59 additions & 0 deletions packages/bazel/src/ngc-wrapped/index.ts
Expand Up @@ -49,6 +49,65 @@ 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']) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah in my case with this code it gets: /home/ocombe/.cache/bazel/_bazel_ocombe/df516b31b5c55b244dfb17f03a952d3d/execroot/angular/packages/tsconfig-build.json but it doesn't read the local tsconfig file that I defined in my bundle test folder

// 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) {
Copy link
Contributor

@ocombe ocombe Feb 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you make a loop that gets all properties of userConfig? We wouldn't need to maintain this when we add new compiler config options. And worst case scenario it would set an option that wouldn't be used

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are some properties which bazel needs to control, I think flatModuleId is an example.

ngc-wrapped is planned to be deprecated with Ivy so we don't need to put that much care here about maintainability

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