Skip to content
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

Merged
merged 5 commits into from
Feb 4, 2020
Merged

Conversation

aherrmann-da
Copy link
Contributor

The npm packages generated by rules_nodejs' native ts_library rule use
the UMD package format. This breaks webpack which attempts to determine
dependencies by static code analysis and fails on UMD. To avoid this we
call tsc directly to ensure generation of commonjs modules.

Pull Request Checklist

  • Read and understand the contribution guidelines
  • Include appropriate tests
  • Set a descriptive title and thorough description
  • Add a reference to the issue this PR will solve, if appropriate
  • Include changelog additions in one or more commit message bodies between the CHANGELOG_BEGIN and CHANGELOG_END tags
  • Normal production system change, include purpose of change in description

NOTE: CI is not automatically run on non-members pull-requests for security
reasons. The reviewer will have to comment with /AzurePipelines run to
trigger the build.

CHANGELOG_BEGIN
CHANGELOG_END
The npm packages generated by rules_nodejs' native ts_library rule use
the UMD package format. This breaks webpack which attempts to determine
dependencies by static code analysis and fails on UMD. To avoid this we
call `tsc` directly to ensure generation of commonjs modules.
@aherrmann-da aherrmann-da requested review from hurryabit and a user February 4, 2020 14:58
Copy link
Contributor

@cocreature cocreature left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this looks much simpler than I though it would be.
One comment on package names.

language-support/ts/daml-ledger/BUILD.bazel Outdated Show resolved Hide resolved
language-support/ts/daml-react/BUILD.bazel Outdated Show resolved Hide resolved
@aherrmann-da
Copy link
Contributor Author

The first attempt didn't work because it generated conflicting outputs with the ts_library rules. Simply modifying the output paths in the ts_commonjs_library rule did also affect the paths in the final package.

Taking a step back, we don't need the ts_library rule if we can generate sufficient outputs for pkg_npm and the jest and eslint tests by calling tsc directly. So, I've replaced ts_library completely by a rule that I now called da_ts_library. It sets the right attributes for rules_nodejs' module renaming to still work. I.e. imports of the form @daml/types are still mapped to daml-types within Bazel.

srcs = outs,
# We don't do anything with the deps, but they are needed for
# rules_nodejs's tracking of transitive dependencies.
deps = deps,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we find deps, via the global npm deps repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, thanks for the explanation!

Copy link
Contributor

@hurryabit hurryabit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me with my limited knowledge of bazel.

@hurryabit hurryabit merged commit 2dbd51b into master Feb 4, 2020
@hurryabit hurryabit deleted the node-pkg branch February 4, 2020 17:50
data = [
":LICENSE",
":README.md",
":package.json",
Copy link

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?

Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants