From 9700b5eb5682d4a9ad82a4376121f8a46a761ab4 Mon Sep 17 00:00:00 2001 From: Mihail Vratchanski <Mivr@users.noreply.github.com> Date: Tue, 7 Jan 2025 02:35:36 +0200 Subject: [PATCH] feat: validate tsconfig outDir vs ts_project(out_dir) --- ts/private/ts_project_options_validator.js | 14 ++++++++++++++ ts/private/ts_validate_options.bzl | 1 + 2 files changed, 15 insertions(+) diff --git a/ts/private/ts_project_options_validator.js b/ts/private/ts_project_options_validator.js index 016213b6..f35d9086 100755 --- a/ts/private/ts_project_options_validator.js +++ b/ts/private/ts_project_options_validator.js @@ -102,6 +102,17 @@ function main(_a) { } } } + function check_out_dir() { + var attr = 'out_dir' + var optionVal = getTsOption('outDir') + var attrIsFalsyOrUndefined = attrs[attr] === false || attrs[attr] === '' || attrs[attr] === undefined + if (attrIsFalsyOrUndefined && optionVal !== undefined) { + throw new Error( + 'When outDir is set in the tsconfig it must also be set in the ts_project' + + ' rule, so that the output directory is known to Bazel.' + ) + } + } var jsxEmit = ((_b = {}), (_b[ts.JsxEmit.None] = 'none'), @@ -163,6 +174,7 @@ function main(_a) { check('declaration') check('incremental') check('tsBuildInfoFile', 'ts_build_info_file') + check_out_dir() check_nocheck() check_preserve_jsx() if (failures.length > 0) { @@ -201,6 +213,8 @@ function main(_a) { attrs.declaration + '\n// declaration_map: ' + attrs.declaration_map + + '\n// out_dir: ' + + attrs.out_dir + '\n// incremental: ' + attrs.incremental + '\n// source_map: ' + diff --git a/ts/private/ts_validate_options.bzl b/ts/private/ts_validate_options.bzl index ff5f2669..b8a89b4d 100644 --- a/ts/private/ts_validate_options.bzl +++ b/ts/private/ts_validate_options.bzl @@ -28,6 +28,7 @@ def _validate_action(ctx, tsconfig_inputs): allow_js = ctx.attr.allow_js, declaration = ctx.attr.declaration, declaration_map = ctx.attr.declaration_map, + out_dir = ctx.attr.out_dir, preserve_jsx = ctx.attr.preserve_jsx, composite = ctx.attr.composite, no_emit = ctx.attr.no_emit,