Skip to content

Commit

Permalink
feat(typescript): add JSNamedModuleInfo provider to ts_library outputs
Browse files Browse the repository at this point in the history
All rules that require devmode named sources are updated to use JSNamedModuleInfo. The rules affected are karma, protractor, ts_devserver, ts_proto_library (in labs) & npm_package.

BREAKING CHANGES:
The following breaking changes are from internal details so they should not affect most users, however, some downstream projects such as Angular rely on these and will need to be updated accordingly when updating to the next release.
* `sources_aspect` from `/internal/node/node.bzl` and `/internal/common/sources_aspect.bzl` is removed; its functionality was duplicate to what JSNamedModuleInfo providers
* NodeModuleSources is removed and its `sources` field is moved to NodeModuleInfo; sources in the `scripts` field are now provided by JSNamedModuleInfo
* node_module_library `scripts` attribute renamed to `named_sources`
* `collect_node_modules_aspect` renamed to just `node_modules_aspect`
  • Loading branch information
gregmagolan committed Oct 1, 2019
1 parent faaf73e commit e6fed92
Show file tree
Hide file tree
Showing 32 changed files with 776 additions and 416 deletions.
2 changes: 1 addition & 1 deletion examples/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"zone.js": "0.10.2"
},
"devDependencies": {
"@angular/bazel": "8.2.6",
"@angular/bazel": "9.0.0-next.8",
"@angular/cli": "8.3.4",
"@angular/compiler": "8.2.6",
"@angular/compiler-cli": "8.2.6",
Expand Down
35 changes: 0 additions & 35 deletions examples/angular/patches/@angular+bazel+8.2.6.patch

This file was deleted.

373 changes: 373 additions & 0 deletions examples/angular/patches/@angular+bazel+9.0.0-next.8.patch

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions examples/angular/src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ ts_library(
],
)

filegroup(
name = "initialize_testbed_js",
testonly = 1,
srcs = [":initialize_testbed"],
output_group = "es5_sources",
)

ng_module(
name = "src",
srcs = [
Expand Down
3 changes: 2 additions & 1 deletion examples/angular/src/app/hello-world/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ ts_web_test_suite(
"@io_bazel_rules_webtesting//browsers:firefox-local",
],
runtime_deps = [
"//src:initialize_testbed",
# Just run initialize_testbed.js and not its transitive deps
"//src:initialize_testbed_js",
],
deps = [
":test_lib",
Expand Down
115 changes: 48 additions & 67 deletions examples/angular/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@
dependencies:
tslib "^1.9.0"

"@angular/bazel@8.2.6":
version "8.2.6"
resolved "https://registry.yarnpkg.com/@angular/bazel/-/bazel-8.2.6.tgz#4733e060db262562450f1e67876cccc76185bc0a"
integrity sha512-1kpETFg+D6jG95NS0q62np/K4pRIY8ML1kJMqeE5JQYZsSEse8EllkBdWuVhCP2+dKFF2E0aVj/ZY7/yDlkTYw==
"@angular/bazel@9.0.0-next.8":
version "9.0.0-next.8"
resolved "https://registry.yarnpkg.com/@angular/bazel/-/bazel-9.0.0-next.8.tgz#ad3e5991e2c28d8431093df1d749c1179b7b67fd"
integrity sha512-mq0lWUQibqGciIJt1UIOgvhKs5p5IoFJtPgZPDhEGHcilCI86370Kkmula3JtQKMpZimHH5oCQMOymYy46IDOw==
dependencies:
"@angular-devkit/architect" "^0.800.0-beta.15"
"@angular-devkit/core" "^8.0.0-beta.15"
"@angular-devkit/schematics" "^8.0.0-beta.15"
"@microsoft/api-extractor" "7.0.21"
"@microsoft/api-extractor" "^7.3.9"
"@schematics/angular" "^8.0.0-beta.15"
"@types/node" "6.0.84"
semver "^5.6.0"
Expand Down Expand Up @@ -319,50 +319,53 @@
is-absolute "^1.0.0"
is-negated-glob "^1.0.0"

"@microsoft/[email protected]":
version "7.0.21"
resolved "https://registry.yarnpkg.com/@microsoft/api-extractor/-/api-extractor-7.0.21.tgz#d5ff9bba4ff7283503aac83ad489b16cad293fc7"
integrity sha512-7lFcHNykVz0tvgOz9juXqP+a1j0EmnJ9J080CBE/171IxL4fBrpslPhqN86dNuavuPragRpBLc8Okv/bV7FJPQ==
"@microsoft/[email protected]":
version "7.5.1"
resolved "https://registry.yarnpkg.com/@microsoft/api-extractor-model/-/api-extractor-model-7.5.1.tgz#54732ab60cc0761784a54fc00eaaf96145724160"
integrity sha512-qzgmJeoqpJqYDS1yj9YTPdd/+9OWGFwfzGFyr6kVarexomdPSltcoQYIS5JnrB/RFNeUgTNUlwn5mYdyp2Xv6A==
dependencies:
"@microsoft/node-core-library" "3.15.1"
"@microsoft/tsdoc" "0.12.14"

"@microsoft/api-extractor@^7.3.9":
version "7.4.6"
resolved "https://registry.yarnpkg.com/@microsoft/api-extractor/-/api-extractor-7.4.6.tgz#024f3944ae658e4cba7494e2fc001a67afb8cf2a"
integrity sha512-v/6v4tS/WzVGOhLyjgNsmJBnRN4gnW99FeCKTKgDeCZiRIdbemi+g/+ZZnS5YaNu6Yp6DfRR9558WV4RVS2vbA==
dependencies:
"@microsoft/node-core-library" "3.12.0"
"@microsoft/ts-command-line" "4.2.3"
"@microsoft/tsdoc" "0.12.5"
"@types/node" "8.5.8"
"@types/z-schema" "3.16.31"
"@microsoft/api-extractor-model" "7.5.1"
"@microsoft/node-core-library" "3.15.1"
"@microsoft/ts-command-line" "4.3.2"
"@microsoft/tsdoc" "0.12.14"
colors "~1.2.1"
lodash "~4.17.5"
lodash "~4.17.15"
resolve "1.8.1"
typescript "~3.1.6"
z-schema "~3.18.3"
source-map "~0.6.1"
typescript "~3.5.3"

"@microsoft/node-core-library@3.12.0":
version "3.12.0"
resolved "https://registry.yarnpkg.com/@microsoft/node-core-library/-/node-core-library-3.12.0.tgz#f9c27b8bb6b55d60b91d4e1962f42b03b9f8f47f"
integrity sha512-9T2dEXmmxZqnqcpHuIB8mTAOM/DNSi/QcAwKYDjvZvkd+PGT5lCUXjM9GL7SaR2NPa3UrWDGgFhNoqLqLfEPbw==
"@microsoft/node-core-library@3.15.1":
version "3.15.1"
resolved "https://registry.yarnpkg.com/@microsoft/node-core-library/-/node-core-library-3.15.1.tgz#78f6249493b09e9a5c39df9e55c5401d69f23f19"
integrity sha512-fUrcgu+w40k2GW8fiOUFby7jaKAAuDKaTrQuFQ3j+0Pg3ANnJ2uKtVf3bgFiNu+uVKpwVtLo4CPS8TwFduJRow==
dependencies:
"@types/fs-extra" "5.0.4"
"@types/jju" "~1.4.0"
"@types/node" "8.5.8"
"@types/z-schema" "3.16.31"
"@types/node" "8.10.54"
colors "~1.2.1"
fs-extra "~7.0.1"
jju "~1.4.0"
z-schema "~3.18.3"

"@microsoft/ts-command-line@4.2.3":
version "4.2.3"
resolved "https://registry.yarnpkg.com/@microsoft/ts-command-line/-/ts-command-line-4.2.3.tgz#20d6a1684148b9fc0df25ee7335c3bb227d47d4f"
integrity sha512-SIs4q7RcG7efBbh5Ffrf6V4jVLxWihD4NDRY3+gPiOG8CYawBzE22tTEloZ1yj/FBvBZQkQ0GYwXoPhn6ElYXA==
"@microsoft/ts-command-line@4.3.2":
version "4.3.2"
resolved "https://registry.yarnpkg.com/@microsoft/ts-command-line/-/ts-command-line-4.3.2.tgz#87341de2e24f279259297ebd38530300a9f97bc3"
integrity sha512-2QeyilabCe6IpBylPXuY6dCA1S9ym3Ii0zakXVPpyfjSj1NesnyuUeuh6e8kyIqzqJ+3LYjfPG63XzUBtwGqqw==
dependencies:
"@types/argparse" "1.0.33"
"@types/node" "8.5.8"
argparse "~1.0.9"
colors "~1.2.1"

"@microsoft/[email protected].5":
version "0.12.5"
resolved "https://registry.yarnpkg.com/@microsoft/tsdoc/-/tsdoc-0.12.5.tgz#c448a38902ccb5601c1b2ef3b1a105012ef7712c"
integrity sha512-xEAyvLXo4Cter/b0EMCWUZTgXOfLOPJ/Xr52WdjVclPx9eDmNTGFtZl8Pn/nqSnZsQBNcHL0eHk/YyRyyXXpiQ==
"@microsoft/[email protected].14":
version "0.12.14"
resolved "https://registry.yarnpkg.com/@microsoft/tsdoc/-/tsdoc-0.12.14.tgz#0e0810a0a174e50e22dfe8edb30599840712f22d"
integrity sha512-518yewjSga1jLdiLrcmpMFlaba5P+50b0TWNFUpC+SL9Yzf0kMi57qw+bMl+rQ08cGqH1vLx4eg9YFUbZXgZ0Q==

"@mrmlnc/readdir-enhanced@^2.2.1":
version "2.2.1"
Expand Down Expand Up @@ -478,33 +481,16 @@
resolved "https://registry.yarnpkg.com/@types/argparse/-/argparse-1.0.33.tgz#2728669427cdd74a99e53c9f457ca2866a37c52d"
integrity sha512-VQgHxyPMTj3hIlq9SY1mctqx+Jj8kpQfoLvDlVSDNOyuYs8JYfkuY3OW/4+dO657yPmNhHpePRx0/Tje5ImNVQ==

"@types/[email protected]":
version "5.0.4"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-5.0.4.tgz#b971134d162cc0497d221adde3dbb67502225599"
integrity sha512-DsknoBvD8s+RFfSGjmERJ7ZOP1HI0UZRA3FSI+Zakhrc/Gy26YQsLI+m5V5DHxroHRJqCDLKJp7Hixn8zyaF7g==
dependencies:
"@types/node" "*"

"@types/[email protected]":
version "3.4.0"
resolved "https://registry.yarnpkg.com/@types/jasmine/-/jasmine-3.4.0.tgz#018c56db42400c092aae47de21f710b7f04e4b06"
integrity sha512-6pUnBg6DuSB55xnxJ5+gW9JOkFrPsXkYAuqqEE8oyrpgDiPQ+TZ+1Zt4S+CHcRJcxyNYXeIXG4vHSzdF6y9Uvw==

"@types/jju@~1.4.0":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@types/jju/-/jju-1.4.1.tgz#0a39f5f8e84fec46150a7b9ca985c3f89ad98e9f"
integrity sha512-LFt+YA7Lv2IZROMwokZKiPNORAV5N3huMs3IKnzlE430HWhWYZ8b+78HiwJXJJP1V2IEjinyJURuRJfGoaFSIA==

"@types/long@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.0.tgz#719551d2352d301ac8b81db732acb6bdc28dbdef"
integrity sha512-1w52Nyx4Gq47uuu0EVcsHBxZFJgurQ+rTKS3qMHxR1GY2T8c2AJYd6vZoZ9q1rupaDjU0yT+Jc2XTyXkjeMA+Q==

"@types/node@*":
version "11.13.7"
resolved "https://registry.yarnpkg.com/@types/node/-/node-11.13.7.tgz#85dbb71c510442d00c0631f99dae957ce44fd104"
integrity sha512-suFHr6hcA9mp8vFrZTgrmqW2ZU3mbWsryQtQlY/QvwTISCw7nw/j+bCQPPohqmskhmqa5wLNuMHTTsc+xf1MQg==

"@types/[email protected]":
version "6.0.84"
resolved "https://registry.yarnpkg.com/@types/node/-/node-6.0.84.tgz#193ffe5a9f42864d425ffd9739d95b753c6a1eab"
Expand All @@ -515,10 +501,10 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-6.14.6.tgz#31df045b4c7618ff74d84f542fc3d29445dd566b"
integrity sha512-rFs9zCFtSHuseiNXxYxFlun8ibu+jtZPgRM+2ILCmeLiGeGLiIGxuOzD+cNyHegI1GD+da3R/cIbs9+xCLp13w==

"@types/node@8.5.8":
version "8.5.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.5.8.tgz#92509422653f10e9c0ac18d87e0610b39f9821c7"
integrity sha512-8KmlRxwbKZfjUHFIt3q8TF5S2B+/E5BaAoo/3mgc5h6FJzqxXkCK/VMetO+IRDtwtU6HUvovHMBn+XRj7SV9Qg==
"@types/node@8.10.54":
version "8.10.54"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.54.tgz#1c88eb253ac1210f1a5876953fb70f7cc4928402"
integrity sha512-kaYyLYf6ICn6/isAyD4K1MyWWd5Q3JgH6bnMN089LUx88+s4W8GvK9Q6JMBVu5vsFFp7pMdSxdKmlBXwH/VFRg==

"@types/node@^10.1.0":
version "10.14.5"
Expand All @@ -535,11 +521,6 @@
resolved "https://registry.yarnpkg.com/@types/selenium-webdriver/-/selenium-webdriver-3.0.16.tgz#50a4755f8e33edacd9c406729e9b930d2451902a"
integrity sha512-lMC2G0ItF2xv4UCiwbJGbnJlIuUixHrioOhNGHSCsYCJ8l4t9hMCUimCytvFv7qy6AfSzRxhRHoGa+UqaqwyeA==

"@types/[email protected]":
version "3.16.31"
resolved "https://registry.yarnpkg.com/@types/z-schema/-/z-schema-3.16.31.tgz#2eb1d00a5e4ec3fa58c76afde12e182b66dc5c1c"
integrity sha1-LrHQCl5Ow/pYx2r94S4YK2bcXBw=

"@yarnpkg/[email protected]", "@yarnpkg/lockfile@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31"
Expand Down Expand Up @@ -3891,12 +3872,12 @@ lodash.values@^2.4.1:
dependencies:
lodash.keys "~2.4.1"

lodash@^4.16.6, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@~4.17.5:
lodash@^4.16.6, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5:
version "4.17.11"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==

lodash@^4.17.15:
lodash@^4.17.15, lodash@~4.17.15:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
Expand Down Expand Up @@ -5655,7 +5636,7 @@ source-map@^0.5.6:
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=

source-map@^0.6.0, source-map@^0.6.1:
source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
Expand Down Expand Up @@ -6162,10 +6143,10 @@ [email protected], typescript@^3.0.1:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.5.tgz#2d2618d10bb566572b8d7aad5180d84257d70a99"
integrity sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==

typescript@~3.1.6:
version "3.1.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.1.6.tgz#b6543a83cfc8c2befb3f4c8fba6896f5b0c9be68"
integrity sha512-tDMYfVtvpb96msS1lDX9MEdHrW4yOuZ4Kdc4Him9oU796XldPYF/t2+uKoX0BBa0hXXwDlqYQbXY5Rzjzc5hBA==
typescript@~3.5.3:
version "3.5.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.3.tgz#c830f657f93f1ea846819e929092f5fe5983e977"
integrity sha512-ACzBtm/PhXBDId6a6sDJfroT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g==

ultron@~1.1.0:
version "1.1.1"
Expand Down
26 changes: 15 additions & 11 deletions internal/common/devmode_js_sources.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Outputs a manifest file with the sources listed.
"""

load(":sources_aspect.bzl", "sources_aspect")
load("@build_bazel_rules_nodejs//:providers.bzl", "JSNamedModuleInfo")

# Avoid using non-normalized paths (workspace/../other_workspace/path)
def _to_manifest_path(ctx, file):
Expand All @@ -27,26 +27,30 @@ def _to_manifest_path(ctx, file):
return ctx.workspace_name + "/" + file.short_path

def _devmode_js_sources_impl(ctx):
files = depset()

for d in ctx.attr.deps:
if hasattr(d, "node_sources"):
files = depset(transitive = [files, d.node_sources])
elif hasattr(d, "files"):
files = depset(transitive = [files, d.files])
sources_depsets = []
for dep in ctx.attr.deps:
if JSNamedModuleInfo in dep:
sources_depsets.append(dep[JSNamedModuleInfo].sources)
if hasattr(dep, "files"):
sources_depsets.append(dep.files)
sources = depset(transitive = sources_depsets)

ctx.actions.write(ctx.outputs.manifest, "".join([
_to_manifest_path(ctx, f) + "\n"
for f in files.to_list()
for f in sources.to_list()
if f.path.endswith(".js") or f.path.endswith(".mjs")
]))
return [DefaultInfo(files = files)]

return [DefaultInfo(
files = sources,
runfiles = ctx.runfiles(transitive_files = sources),
)]

devmode_js_sources = rule(
implementation = _devmode_js_sources_impl,
attrs = {
"deps": attr.label_list(
allow_files = True,
aspects = [sources_aspect],
),
},
outputs = {
Expand Down
Loading

0 comments on commit e6fed92

Please sign in to comment.