Closed supercairos closed 11 months ago
Adding source_maps
in the transpiler options fixe the issue;
partial.make(
swc,
swcrc = "//hydra-api:.swcrc",
source_maps = True,
),
This is expected when configuring a transpiler, or even when just configuring a custom tsconfig file.
The ts_project
rule needs to know what files tsc (or other transpiler such as swc) will output. When using tsconfig = {}
the ts_project
macro can infer some of those options, but when things like sourcemaps are configured within a tsconfig.json
file or as options with in the transpiler like (like you case) the ts_project
rule needs things like source_map
set manually to know what files to expect as outputs.
I'll close this for now but feel free to continue the discussion here, or correct me if I'm misunderstanding something.
I see your point, but I believe it's redundant. Maybe we can find a way to propagate arguments from one to an other.
Today you end-up having to set both of the source_maps:
ts_project(
name = "lib",
srcs = glob([
"src/**/*.ts",
]),
declaration = True,
declaration_map = True,
source_map = True,
transpiler = partial.make(
swc,
source_maps = True,
swcrc = ":.swcrc",
),
tsconfig = "tsconfig",
validate = True,
deps = [
":node_modules",
],
)
and they also both have different different spellings source_map
& source_maps
And we should also have an exemple with SWC in either then SWC repo or this repo to showcase this beavior
It does unfortunately feel redundant, but they are separate inputs to separate tools, serving different purposes.
We do propagate ts_project(tsconfig = {"compilerOptions": {"sourceMap"}})
where the information is actually available, but when simply given tsconfig = ":target-x"
or transpiler = x
there is no way to determine if that tsconfig or tool has source maps enabled without this extra information that unfortunately feels redundant.
and they also both have different different spellings source_map & source_maps
The rule options are named after the options in the tools. For typescript it is the tsconfig sourceMap
or cli --sourceMap
while with swc it is plural. This is another case where when mixing the two (typescript and swc) it seems odd but I think this is still the best.
And we should also have an exemple with SWC in either then SWC repo or this repo to showcase this beavior
Maybe a note in the transpiler docs would be sufficient? Seems worth mentioning but I'm not sure about a full example that would run in CI etc. is necessary.
Ok!
But should we make the ts_project
a bit more 'agnostic' ?
I feel that the API was only written for tsc and using swc seams like a workaround.
For swc, It shouldn't require a tsconfig or anything more than maybe the declare = True
flag ?
While the transpiler can be swapped out rules_ts is still specifically for typescript so I don't think it should be agnostic. If you only want swc then you should only need rules_swc.
Note that even when the ts_project
transpiler is replaced with something such as swc (or babel, or esbuild etc) tsc still does type-checking and dts generation which still requires the tsconfig.
What happened?
Using
ts_project
doesn't produce source_maps if transpiler is defined toswc
on rules 2.0doesn't work.
Version
Development (host) and target OS/architectures:
Output of
bazel --version
: 6.4.0Version of the Aspect rules, or other relevant rules from your
WORKSPACE
orMODULE.bazel
file: rules: 2.1.0Language(s) and/or frameworks involved: Pure TS;
How to reproduce
No response
Any other information?
No response