-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
language-support/ts generate package in commonjs format #4380
Changes from all commits
53cc52e
e382fca
355b6e5
1d0637b
04bab3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Copyright (c) 2020 The DAML Authors. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
load("@language_support_ts_deps//typescript:index.bzl", "tsc") | ||
|
||
def _da_ts_library_impl(ctx): | ||
return [ | ||
DefaultInfo( | ||
files = depset(ctx.files.srcs), | ||
runfiles = ctx.runfiles(files = ctx.files.srcs), | ||
), | ||
] | ||
|
||
_da_ts_library_rule = rule( | ||
_da_ts_library_impl, | ||
attrs = { | ||
"srcs": attr.label_list(allow_files = True), | ||
"deps": attr.label_list(allow_files = True), | ||
"module_name": attr.string(), | ||
"module_root": attr.string(), | ||
}, | ||
) | ||
|
||
def da_ts_library( | ||
name, | ||
tsconfig = "tsconfig.json", | ||
srcs = [], | ||
deps = [], | ||
module_name = "", | ||
module_root = "", | ||
**kwargs): | ||
"""Build a typescript library. | ||
|
||
Invokes tsc and generates definitions and commonjs files. | ||
|
||
Attrs: | ||
name: A unique name for the rule. | ||
tsconfig: The tsconfig.json file. | ||
The "files" attribute defines the typescript sources. | ||
srcs: The typescript source files. | ||
Defines which files are visible to the typescript compiler. | ||
deps: Typescript library dependencies. | ||
module_name: The import name of this library. E.g. @daml/types. | ||
module_root: Treat sources as rooted under module_name. | ||
""" | ||
outs = [ | ||
s.replace(".ts", ext) | ||
for ext in [".js", ".d.ts"] | ||
for s in srcs | ||
] | ||
tsc( | ||
name = "_%s_tsc" % name, | ||
data = [tsconfig] + srcs + deps, | ||
outs = outs, | ||
args = [ | ||
"--outDir", | ||
"$(RULEDIR)", | ||
"--project", | ||
"$(location %s)" % tsconfig, | ||
"--declaration", | ||
], | ||
**kwargs | ||
) | ||
|
||
# rules_nodejs does import remapping based on the module_name attribute. | ||
# The tsc macro is an instance of npm_package_bin under the covers which | ||
# doesn't take a module_name attribute. So, we use this wrapper rule to be | ||
# able to set the module_name attribute. | ||
_da_ts_library_rule( | ||
name = name, | ||
srcs = outs, | ||
# We don't do anything with the deps, but they are needed for | ||
# rules_nodejs's tracking of transitive dependencies. | ||
deps = deps, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do we find deps, via the global npm deps repo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rules_nodejs traces them through this attribute and makes sure they're in the right place in the execroot. They come either from local targets or from the npm deps repo. E.g. https://github.com/digital-asset/daml/pull/4380/files#diff-cb32cca6075c7ecf0996019a06da7488R16-R20 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense, thanks for the explanation! |
||
module_name = module_name, | ||
module_root = module_root, | ||
**kwargs | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these files still included in the package with the new rule?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes they are, just checked.