Skip to content

Commit

Permalink
feat: add ts_project validation of root/out/typing_out dir options (#552
Browse files Browse the repository at this point in the history
)

Close #551
  • Loading branch information
jbedard authored Feb 26, 2024
1 parent a6cf27b commit 9eed754
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
13 changes: 13 additions & 0 deletions ts/private/ts_lib.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ def _calculate_assets_outs(assets, out_dir = ".", root_dir = "."):
outs.append(out)
return outs

# Quick check to validate path options
# One usecase: https://github.com/aspect-build/rules_ts/issues/551
def _validate_tsconfig_dirs(root_dir, out_dir, typings_out_dir):
if root_dir and root_dir.find("../") != -1:
fail("root_dir cannot access parent directories")

if out_dir and out_dir.find("../") != -1:
fail("out_dir cannot output to parent directory")

if typings_out_dir and typings_out_dir.find("../") != -1:
fail("typings_out_dir cannot output to parent directory")

def _calculate_js_outs(srcs, out_dir = ".", root_dir = ".", allow_js = False, resolve_json_module = False, preserve_jsx = False, emit_declaration_only = False):
if emit_declaration_only:
return []
Expand Down Expand Up @@ -313,6 +325,7 @@ lib = struct(
is_js_src = _is_js_src,
out_paths = _to_js_out_paths,
to_out_path = _to_out_path,
validate_tsconfig_dirs = _validate_tsconfig_dirs,
calculate_js_outs = _calculate_js_outs,
calculate_map_outs = _calculate_map_outs,
calculate_typings_outs = _calculate_typings_outs,
Expand Down
6 changes: 5 additions & 1 deletion ts/private/ts_project.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ def _ts_project_impl(ctx):
map_outs = _lib.declare_outputs(ctx, [] if ctx.attr.transpile == 0 else _lib.calculate_map_outs(srcs, ctx.attr.out_dir, ctx.attr.root_dir, ctx.attr.source_map, ctx.attr.preserve_jsx, ctx.attr.emit_declaration_only))
typings_outs = _lib.declare_outputs(ctx, _lib.calculate_typings_outs(srcs, typings_out_dir, ctx.attr.root_dir, ctx.attr.declaration, ctx.attr.composite, ctx.attr.allow_js))
typing_maps_outs = _lib.declare_outputs(ctx, _lib.calculate_typing_maps_outs(srcs, typings_out_dir, ctx.attr.root_dir, ctx.attr.declaration_map, ctx.attr.allow_js))
validation_outs = _validate_lib.validation_action(ctx, tsconfig_inputs) if ctx.attr.validate else []

validation_outs = []
if ctx.attr.validate:
validation_outs.extend(_validate_lib.validation_action(ctx, tsconfig_inputs))
_lib.validate_tsconfig_dirs(ctx.attr.root_dir, ctx.attr.out_dir, typings_out_dir)

arguments = ctx.actions.args()
execution_requirements = {}
Expand Down

0 comments on commit 9eed754

Please sign in to comment.