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

feat(typescript): add JSNamedModuleInfo provider to ts_library outputs #1215

Merged
merged 1 commit into from
Oct 9, 2019

Conversation

gregmagolan
Copy link
Collaborator

@gregmagolan gregmagolan commented Sep 30, 2019

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.

Some related non-breaking changes:

  • node_module_library scripts attribute renamed to named_module_srcs. node_module_library is currently not part of the public API and in user code the npm targets are generated by generate_build_file.ts by yarn_install & npm_install.

BREAKING CHANGES:

The following breaking changes are from internal details so they should not affect most users. Some some downstream projects, however, such as Angular rely on these internal details 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 NpmPackageInfo; sources in the removed scripts field are provided by the JSNamedModuleInfo provider which node_module_library now provides
  • collect_node_modules_aspect renamed to just node_modules_aspect

@gregmagolan gregmagolan force-pushed the js_named_module_info branch 2 times, most recently from b12ed7a to 4fb81dd Compare September 30, 2019 19:47
@gregmagolan gregmagolan force-pushed the js_named_module_info branch 2 times, most recently from 2202a02 to 21e4e48 Compare September 30, 2019 21:07
doc = "Provides sources for npm dependencies installed with yarn_install and npm_install rules",
# `node_module_library` targets via the `node_modules_aspect` below.
NodeModuleInfo = provider(
doc = "Provides information about npm dependencies",
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI to remove js_library I think I'd like to produce this provider from npm_package too. Would be nice to include package name (could add in later PR)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had sources as direct and transitive_sources as direct + transitive but changed to just sources which are direct + transitive similar to what we decided for the JS providers. Does that sounds like the right approach for this?

+1 for adding package (or module_name) or later PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure. In JS tooling we sometimes want a strict-deps policy that requires distinguishing direct and transitive sources. I would bet we'll need direct for something sometime

Copy link
Collaborator Author

@gregmagolan gregmagolan Oct 1, 2019

Choose a reason for hiding this comment

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

Hmmmm. I like the idea of being able to differentiate as well even in the new JS providers. It would have solved my karma runtime_deps issue I saw earlier today by being able to just access sources of JSNamedModuleInfo instead of having to take all of transitive_sources.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Went with sources and direct_sources which now matches what we have in the JS providers. DeclarationInfo still differs with declarations and transitive_declarations however.

internal/node/npm_package_bin.bzl Outdated Show resolved Hide resolved
@gregmagolan gregmagolan force-pushed the js_named_module_info branch 4 times, most recently from 61f5516 to e6fed92 Compare October 1, 2019 00:08
internal/common/devmode_js_sources.bzl Outdated Show resolved Hide resolved
internal/node/npm_package_bin.bzl Outdated Show resolved Hide resolved
elif hasattr(d, "files"):
files = depset(transitive = [files, d.files])
files_depsets = [depset(ctx.files.srcs)]
for dep in ctx.attr.deps:
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this want to be a helper in providers.bzl? seems like I've seen the same impl many times?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

just two places (karma & protractor). those two rules are due for a cleaning so will note that down to look at.

@gregmagolan gregmagolan force-pushed the js_named_module_info branch 16 times, most recently from 7d8f36c to 8b43e6c Compare October 4, 2019 22:01
@gregmagolan gregmagolan force-pushed the js_named_module_info branch 18 times, most recently from 17947b3 to 14df712 Compare October 7, 2019 21:56
@buildsize
Copy link

buildsize bot commented Oct 7, 2019

File name Previous Size New Size Change
release.tar.gz 1.06 MB 1.06 MB -1002 bytes (0%)

Copy link
Collaborator

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

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

looks close, will give it one more look later

# See the License for the specific language governing permissions and
# limitations under the License.

"""NpmPackageInfo providers and apsect to collect node_modules from deps.
Copy link
Collaborator

Choose a reason for hiding this comment

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

seems like it shouldn't be in internal/ - maybe providers.bzl or next to it?

Copy link
Collaborator Author

@gregmagolan gregmagolan Oct 8, 2019

Choose a reason for hiding this comment

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

providers.bzl seems like the right place as I don't think we want to introduce too many load points. where do you think for node_modules_aspect?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

kick this downstream to later PR

# `node_module_library` rule as well as other targets that have direct or transitive deps on
# `node_module_library` targets via the `node_modules_aspect` below.
NpmPackageInfo = provider(
doc = "Provides information about npm dependencies",
Copy link
Collaborator

Choose a reason for hiding this comment

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

will need a bunch more doc here as it should be a public API

internal/node/node.bzl Outdated Show resolved Hide resolved
@@ -677,7 +677,7 @@ node_module_library(
node_module_library(
name = "core__contents",
srcs = [":core__files"],
scripts = [
named_module_srcs = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

kinda breaking for users, huh?
maybe we can paste a buildozer script into the release notes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think anyone is using node_module_library directly as it is still private API and their generated build files will be re-generated on update

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.

Some related non-breaking changes:

* node_module_library scripts attribute renamed to named_module_srcs. node_module_library is currently not part of the public API and in user code the npm targets are generated by generate_build_file.ts by yarn_install & npm_install.

BREAKING CHANGES:

The following breaking changes are from internal details so they should not affect most users. Some some downstream projects, however, such as Angular rely on these internal details 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 NpmPackageInfo; sources in the removed scripts field are provided by the JSNamedModuleInfo provider which node_module_library now provides
* collect_node_modules_aspect renamed to just node_modules_aspect

fix: nodejs_binary doesn't need declaration files
@gregmagolan gregmagolan force-pushed the js_named_module_info branch from e7b6788 to 35fff2b Compare October 8, 2019 16:34
@alexeagle alexeagle merged commit bb1f9b4 into bazel-contrib:master Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants