Skip to content

Commit

Permalink
refactor: cleanup a TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eagle committed Aug 27, 2020
1 parent 18f0f1c commit 1efc73d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
10 changes: 8 additions & 2 deletions packages/typescript/internal/ts_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ def _relative_path(tsconfig_path, dest):
workspace_root = "/".join([".."] * len(tsconfig_path.dirname.split("/")))
return _join(workspace_root, dest.path)

# TODO: basename isn't exactly correct, there could be a subdir
return dest.basename
# Bazel guarantees that srcs are beneath the package directory, and we disallow
# tsconfig.json being generated with a "/" in the name.
# So we can calculate a relative path from e.g.
# bazel-out/darwin-fastbuild/bin/packages/typescript/test/ts_project/generated_tsconfig/gen_src
# to <generated file packages/typescript/test/ts_project/generated_tsconfig/gen_src/subdir/a.ts>
return dest.path[len(tsconfig_path.dirname) + 1:]

def _write_tsconfig_rule(ctx):
# TODO: is it useful to expand Make variables in the content?
Expand Down Expand Up @@ -109,6 +113,8 @@ def write_tsconfig(name, config, files, out, extends = None):
out: the file to write
extends: a label for a tsconfig.json file to extend from, if any
"""
if out.find("/") >= 0:
fail("tsconfig should be generated in the package directory, to make relative pathing simple")

if extends:
config["extends"] = "__extends__"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ load("//packages/typescript:index.bzl", "ts_project")

ts_project(
tsconfig = {
"types": [],
"compilerOptions": {
"types": [],
},
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ load("//packages/typescript:index.bzl", "ts_project")

write_file(
name = "gen_src",
out = "a.ts",
out = "subdir/a.ts",
content = ["export const a: string = 'hello world';"],
)

ts_project(
srcs = ["a.ts"],
srcs = ["subdir/a.ts"],
tsconfig = {
"rootDir": "subdir",
"types": [],
},
)
Expand All @@ -19,5 +20,4 @@ generated_file_test(
name = "test",
src = "expected.js_",
generated = ":a.js",
tags = ["manual"],
)

0 comments on commit 1efc73d

Please sign in to comment.