Skip to content
Open
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
65 changes: 65 additions & 0 deletions examples/dts_srcs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""ts_project(srcs) containing .d.ts files with various outDir/rootDir settings.

A .d.ts src is never transpiled or relocated by tsc, so it is passed through to
JsInfo(types) (the `types` output group) at its source location.
"""

load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load("@bazel_lib//lib:testing.bzl", "assert_outputs")

ts_project(
name = "default",
srcs = [
"index.ts",
"types.d.ts",
],
declaration = True,
)

assert_outputs(
name = "default_types_test",
actual = ":default_types",
expected = [
"dts_srcs/index.d.ts",
"dts_srcs/types.d.ts",
],
)

ts_project(
name = "out_dir",
srcs = [
"index.ts",
"types.d.ts",
],
declaration = True,
out_dir = "dist",
)

assert_outputs(
name = "out_dir_types_test",
actual = ":out_dir_types",
expected = [
"dts_srcs/dist/index.d.ts",
"dts_srcs/types.d.ts",
],
)

ts_project(
name = "root_dir_out_dir",
srcs = [
"src/index.ts",
"src/types.d.ts",
],
declaration = True,
out_dir = "dist2",
root_dir = "src",
)

assert_outputs(
name = "root_dir_out_dir_types_test",
actual = ":root_dir_out_dir_types",
expected = [
"dts_srcs/dist2/index.d.ts",
"dts_srcs/src/types.d.ts",
],
)
2 changes: 2 additions & 0 deletions examples/dts_srcs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './types'
export const value = 1
2 changes: 2 additions & 0 deletions examples/dts_srcs/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './types'
export const value = 1
1 change: 1 addition & 0 deletions examples/dts_srcs/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type A = number
5 changes: 5 additions & 0 deletions examples/dts_srcs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"declaration": true
}
}
1 change: 1 addition & 0 deletions examples/dts_srcs/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type A = number
9 changes: 6 additions & 3 deletions ts/private/ts_project.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ See https://github.com/aspect-build/rules_ts/issues/361 for more details.
#
# Unfortunately this duplicates logic in ts_lib.calculate_outs:
# files collide iff the following conditions are met:
# - They are files not renamed when transpiled (ext in [.d.ts, js, json])
# - They are files not renamed when transpiled (ext in [js, json])
# - out_dir == root_dir
#
# The duplication is hard to avoid, since calculate_outs works on path strings
Expand All @@ -242,8 +242,11 @@ See https://github.com/aspect-build/rules_ts/issues/361 for more details.
for s in srcs_inputs:
if _lib.is_js_src(s.path, ctx.attr.allow_js, ctx.attr.resolve_json_module):
output_sources.append(s)
if _lib.is_typings_src(s.path):
output_types.append(s)

# Add .d.ts inputs which are never emitted by tsc.
for s in srcs_inputs:
if _lib.is_typings_src(s.path):
output_types.append(s)

is_root_module = ctx.label.workspace_root == ""

Expand Down
Loading