Skip to content

build: perform package.json substitutions in bazel build#22425

Merged
dgp1130 merged 1 commit intoangular:masterfrom
aspect-build:jq-substitutions
Jan 10, 2022
Merged

build: perform package.json substitutions in bazel build#22425
dgp1130 merged 1 commit intoangular:masterfrom
aspect-build:jq-substitutions

Conversation

@kormide
Copy link
Copy Markdown
Contributor

@kormide kormide commented Dec 24, 2021

@josephperrott @gregmagolan

This pr mimics the package.json substitutions that build.ts performs. The current build will not be affected by this change as we haven't yet flipped build.ts to use bazel.

Comment on lines +319 to +326
pkg_deps = [
"//packages/angular_devkit/architect:package.json",
"//packages/angular_devkit/build_angular:package.json",
"//packages/angular_devkit/build_webpack:package.json",
"//packages/angular_devkit/core:package.json",
"//packages/angular_devkit/schematics:package.json",
"//packages/schematics/angular:package.json",
],
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When doing tar substitution we need the dependent package.json files so that we can get the package name and change:

  "dependencies": {
    "@some-package: "0.0.0",
  }

to

  "dependencies": {
    "@some-package: "file:/path/to/pacakge.tar.gz",
  }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unlike release and snapshot stamping, which just needs to look for 0.0.0 and replace that.

Comment thread BUILD.bazel
Comment on lines +25 to +36
# If set will replace dependency versions with tarballs for packages in this repo
bool_flag(
name = "enable_package_json_tar_deps",
build_setting_default = False,
)

config_setting(
name = "package_json_use_tar_deps",
flag_values = {
":enable_package_json_tar_deps": "true",
},
)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is enabled by running yarn build:bazel --local. Once we flip to using the bazel script it will just be yarn build --local.

Comment thread tools/substitute_tar_deps.bzl Outdated
Comment thread tools/defaults.bzl Outdated
Comment thread tools/defaults.bzl Outdated
Comment thread tools/defaults.bzl Outdated
Comment thread tools/substitute_tar_deps.bzl
Comment thread tools/substitute_tar_deps.bzl
Comment thread tools/defaults.bzl Outdated
Copy link
Copy Markdown
Contributor

@gregmagolan gregmagolan left a comment

Choose a reason for hiding this comment

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

Very nice 🌮

Copy link
Copy Markdown
Member

@josephperrott josephperrott left a comment

Choose a reason for hiding this comment

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

LGTM

I think it looks good overall, but I want to have @devversion weigh in and see if he has any concerns or questions as this adds some complexity for substitution that we don't have in our other repositories.

@josephperrott josephperrott added action: review The PR is still awaiting reviews from at least one requested reviewer area: build & ci Related the build and CI infrastructure of the project target: patch This PR is targeted for the next patch release labels Jan 5, 2022
Copy link
Copy Markdown
Member

@josephperrott josephperrott left a comment

Choose a reason for hiding this comment

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

Discussed a little bit more with @devversion and I think we both are on the same page.

We have some concerns about using jq in the bzl file to modify the package.json

I think it would be more readable and become testable if we were to use a simple and easier to understand nodejs script that modifies the package.json file.

Copy link
Copy Markdown
Member

@josephperrott josephperrott left a comment

Choose a reason for hiding this comment

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

LGTM

Approved to merge this as is and then follow up with additional testing and reorganization

Copy link
Copy Markdown
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

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

lgtm, we should make sure to keep track of the jq follow-up.

@kormide
Copy link
Copy Markdown
Contributor Author

kormide commented Jan 6, 2022

lgtm, we should make sure to keep track of the jq follow-up.

The takeaway from our meeting yesterday was that we should:

  • move the large jq filter into a file
  • write a test to show an example of how it transforms a package.json file
  • link to the jq documentation

I'll be working on this next. Let me know if there's anything else you think I should add to that list.

@kormide
Copy link
Copy Markdown
Contributor Author

kormide commented Jan 6, 2022

Updated with the above ^.

Comment thread tools/defaults.bzl Outdated
Comment thread tools/test/BUILD.bazel
Comment thread tools/test/BUILD.bazel
Comment thread tools/test/BUILD.bazel Outdated
Comment thread tools/defaults.bzl
Copy link
Copy Markdown
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

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

lgtm still, great to see a test for this. I added a few minor comments but other than that it seems ready to me.

Comment thread tools/substitute_tar_deps.bzl Outdated
Comment thread tools/test/BUILD.bazel Outdated
Comment thread tools/test/BUILD.bazel Outdated
| del(.devDependencies)

# Add engines
+ {"engines": {"node": "^12.20.0 || ^14.15.0 || >=16.10.0", "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", "yarn": ">= 1.13.0"}} No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should the engines really be configured here? personally that seems like a bad spot for me to have it placed. Would it make sense to have it somewhere else in a common spot for configuration of release output?

e.g. in Angular components we have a general config starlark file at the workspace top-level.

This could be a follow-up discussion, but that's just something I feel like could be improved IMO

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It looks like engines is set in the root package.json, but it was overridden in here: https://github.com/angular/angular-cli/blob/master/lib/packages.ts#L87

What if we just keep it in the root package.json and have that field override the project package.json in the filter?

Or would you prefer stamped substitutions like in the components repo?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good point. I think we cannot use the top-level engines field because that one prohobits the use of NPM, while actual consumers of the CLI should be fine to use NPM. Generally I like how we did the majority of versions within Angular Components (it's obviously not done for the engines, but I like that approach where a single place controls these common things; and it's not deeply hidden in some files).

Please feel free to leave this as is and discuss with @josephperrott and/or the CLI team.

Copy link
Copy Markdown
Contributor Author

@kormide kormide Jan 7, 2022

Choose a reason for hiding this comment

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

I think it makes sense to do substitutions for the node engine. I have a PR coming up for substitution-related things so probably more fitting to put it in there. I'll tag you when it's up.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I would love to do the substitutions if possible, but the follow up makes sense to me.

With the substitutions in place, we could have the template markers placed here in the JQ process and then use the starlark to consistently place the engine values.

Copy link
Copy Markdown
Member

@josephperrott josephperrott left a comment

Choose a reason for hiding this comment

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

LGTM

| del(.devDependencies)

# Add engines
+ {"engines": {"node": "^12.20.0 || ^14.15.0 || >=16.10.0", "npm": "^6.11.0 || ^7.5.6 || >=8.0.0", "yarn": ">= 1.13.0"}} No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I would love to do the substitutions if possible, but the follow up makes sense to me.

With the substitutions in place, we could have the template markers placed here in the JQ process and then use the starlark to consistently place the engine values.

@devversion devversion added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jan 10, 2022
@dgp1130 dgp1130 merged commit 4b5c52b into angular:master Jan 10, 2022
@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: build & ci Related the build and CI infrastructure of the project target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants