Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions examples/out_dir/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,41 @@ ts_project(
tsconfig = {},
)

ts_project(
name = "out_dir-tsconfig-foo",
srcs = ["main.ts"],
declaration = True,
declaration_map = True,
out_dir = "tsconfig-foo",
tsconfig = "tsconfig-outdir-foo.json",
)

ts_project(
name = "out_dir-tsconfig-foo-overriden-to-dot",
srcs = ["main2.ts"],
declaration = True,
declaration_map = True,
extends = "tsconfig-outdir-foo.json",
tsconfig = {
"compilerOptions": {
"outDir": ".",
},
},
)

ts_project(
name = "out_dir-tsconfig-foo-overriden-to-dotslash-bar",
srcs = ["main2.ts"],
declaration = True,
declaration_map = True,
extends = "tsconfig-outdir-foo.json",
tsconfig = {
"compilerOptions": {
"outDir": "./bar",
},
},
)

ts_project(
name = "out_dir-declaration_dir",
srcs = ["main.ts"],
Expand All @@ -44,13 +79,31 @@ ts_project(
build_test(
name = "test",
targets = [
# outputs specified by the tsconfig attr
# outputs specified by the tsconfig attr dict
":out_dir-params-dot",
"main.js",
"main.d.ts",
"main.d.ts.map",

# outputs specified by the tsconfig attr
# outputs specified by the tsconfig attr dict
":out_dir-tsconfig-foo",
"tsconfig-foo/main.js",
"tsconfig-foo/main.d.ts",
"tsconfig-foo/main.d.ts.map",

# outputs specified by the tsconfig attr file but overriden to '.' by tsconfig attr dict
":out_dir-tsconfig-foo-overriden-to-dot",
"main2.js",
"main2.d.ts",
"main2.d.ts.map",

# outputs specified by the tsconfig attr file but overriden to 'bar' by tsconfig attr dict
":out_dir-tsconfig-foo-overriden-to-dotslash-bar",
"bar/main2.js",
"bar/main2.d.ts",
"bar/main2.d.ts.map",

# outputs specified by the tsconfig attr file
":out_dir-tsconfig",
"tsconfig/main.js",
"tsconfig/main.d.ts",
Expand Down
1 change: 1 addition & 0 deletions examples/out_dir/main2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('hello world')
7 changes: 7 additions & 0 deletions examples/out_dir/tsconfig-outdir-foo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"outDir": "tsconfig-foo"
}
}
12 changes: 8 additions & 4 deletions ts/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,14 @@ def ts_project(
resolve_json_module = compiler_options.setdefault("resolveJsonModule", resolve_json_module)

# These options are always passed on the tsc command line so don't include them
# in the tsconfig. At best they're redundant, but at worst we'll have a conflict
out_dir = compiler_options.pop("outDir", out_dir)
declaration_dir = compiler_options.pop("declarationDir", declaration_dir)
root_dir = compiler_options.pop("rootDir", root_dir)
# in the tsconfig if not already present. At best they're redundant, but at worst
# they will (minorly) differ from an extended config and we'll have a conflict.
#
# For example: an extended tsconfig contains `outDir:"foo"`, but within bazel we
# want to override to `outDir: "."`.
out_dir = compiler_options.get("outDir", out_dir)
declaration_dir = compiler_options.get("declarationDir", declaration_dir)
root_dir = compiler_options.get("rootDir", root_dir)

# When generating a tsconfig.json and we set rootDir we need to add the exclude field,
# because of these tickets (validation for not generated tsconfig is also present elsewhere):
Expand Down
6 changes: 4 additions & 2 deletions ts/private/ts_project_options_validator.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ function main(_a) {
var attr = 'out_dir'
var optionVal = getTsOption('outDir')
var attrIsFalsyOrUndefined = attrs[attr] === false || attrs[attr] === '' || attrs[attr] === undefined
if (attrIsFalsyOrUndefined && optionVal !== undefined) {
if (attrIsFalsyOrUndefined && optionVal !== undefined && optionVal != attrs[attr]) {
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.'
' rule, so that the output directory is known to Bazel.\n\n' +
'tsconfig: ' + JSON.stringify(optionVal) + '\n' +
'ts_project: ' + JSON.stringify(attrs[attr])
)
}
}
Expand Down