@@ -30,6 +30,50 @@ load("@bazel_skylib//rules:build_test.bzl", "build_test")
30
30
31
31
ts_config = _ts_config
32
32
33
+ # Copied from aspect_bazel_lib
34
+ # https://github.com/aspect-build/bazel-lib/blob/main/lib/private/utils.bzl#L73-L82
35
+ # TODO(6.0): depend on that library and remove this copy
36
+ def _to_label (param ):
37
+ """Converts a string to a Label. If Label is supplied, the same label is returned.
38
+
39
+ Args:
40
+ param: a string representing a label or a Label
41
+ Returns:
42
+ a Label
43
+ """
44
+ param_type = type (param )
45
+ if param_type == "string" :
46
+ if param .startswith ("@" ):
47
+ return Label (param )
48
+ if param .startswith ("//" ):
49
+ return Label ("@" + param )
50
+
51
+ # resolve the relative label from the current package
52
+ # if 'param' is in another workspace, then this would return the label relative to that workspace, eg:
53
+ # `Label("@my//foo:bar").relative("@other//baz:bill") == Label("@other//baz:bill")`
54
+ if param .startswith (":" ):
55
+ param = param [1 :]
56
+ if native .package_name ():
57
+ return Label ("@//" + native .package_name ()).relative (param )
58
+ else :
59
+ return Label ("@//:" + param )
60
+
61
+ elif param_type == "Label" :
62
+ return param
63
+ else :
64
+ fail ("Expected 'string' or 'Label' but got '%s'" % param_type )
65
+
66
+ # copied from aspect_bazel_lib, see comment above
67
+ def _is_external_label (param ):
68
+ """Returns True if the given Label (or stringy version of a label) represents a target outside of the workspace
69
+
70
+ Args:
71
+ param: a string or label
72
+ Returns:
73
+ a bool
74
+ """
75
+ return len (_to_label (param ).workspace_root ) > 0
76
+
33
77
_DEFAULT_TYPESCRIPT_PACKAGE = (
34
78
# BEGIN-INTERNAL
35
79
"@npm" +
@@ -96,12 +140,16 @@ def ts_project(
96
140
Worse, if you build them separately then the output directory will contain whichever
97
141
one you happened to build most recently. This is highly discouraged.
98
142
143
+ As a thin wrapper, this rule doesn't try to compensate for behavior of the TypeScript compiler.
144
+ See https://github.com/bazelbuild/rules_nodejs/wiki/Debugging-problems-with-ts_project for notes
145
+ that may help you debug issues.
146
+
99
147
> Note: in order for TypeScript to resolve relative references to the bazel-out folder,
100
148
> we recommend that the base tsconfig contain a rootDirs section that includes all
101
149
> possible locations they may appear.
102
150
>
103
151
> We hope this will not be needed in some future release of TypeScript.
104
- > Follow https://github.com/microsoft/TypeScript/issues/37257 for more info.
152
+ > Follow https://github.com/microsoft/TypeScript/issues/37378 for more info.
105
153
>
106
154
> For example, if the base tsconfig file relative to the workspace root is
107
155
> `path/to/tsconfig.json` then you should configure like:
@@ -434,6 +482,7 @@ def ts_project(
434
482
allow_js = allow_js ,
435
483
tsconfig = tsconfig ,
436
484
extends = extends ,
485
+ has_local_deps = len ([d for d in deps if not _is_external_label (d )]) > 0 ,
437
486
** common_kwargs
438
487
)
439
488
tsc_deps = tsc_deps + ["_validate_%s_options" % name ]
0 commit comments