Skip to content

feat: decouple @bazel/worker from rules_typescript - #2918

Merged
alexeagle merged 18 commits into
bazel-contrib:stablefrom
thesayyn:worker-multiplex
Sep 8, 2021
Merged

alexeagle merged 18 commits into
bazel-contrib:stablefrom
thesayyn:worker-multiplex

Conversation

@thesayyn

@thesayyn thesayyn commented Sep 4, 2021 •

Copy link
Copy Markdown
Collaborator

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

@bazel/worker uses an old version of bazel worker protocol and coupled with rules_typescript which is not maintained anymore.
Since the used protocol is old, it lacks some of the new features such as cancellation and multiplex-workers.

Issue Number: #1306

What is the new behavior?

  • Now the worker_protocol.proto is checked into the third-party directory and the corresponding code is generated by protoc-gen-ts.
  • New version of the package does not rely on just-in-time loading of the proto file and gets complete type safety.
  • Package is now fully rewritten in typescript and there is no other third-party dependency other than google-protobuf.
  • It is ready to handle cancellation but we have to introduce some breaking changes such as runOneBuild returning a cancel callback to handle the cancellation and taking a callback argument to call when the task is complete. similar to what we see on bundlers like webpack and rollup.
  • A new argument (third) console is passed to runOneBuild callback to let the consumer have an API to write debug messages and feel right at home.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

the new protocol file is generated by using protoc-gen-ts which is mostly maintained by me and a few open source contributors hence I am not sure if you would like to rely on a third-party project. might be a deal-breaker for you.

additionally, in this PR I have only changed things to make room for the incoming support for multiplex workers.

@thesayyn thesayyn changed the title feat: decouple @bazel/workers and support cancellation feat: decouple @bazel/workers from rules_typescript and support cancellation Sep 4, 2021
@thesayyn

thesayyn commented Sep 4, 2021

Copy link
Copy Markdown
Collaborator Author

I would like to hear your thoughts and the points that I should improve

@alexeagle

Copy link
Copy Markdown
Collaborator

The variations of TS generation for .proto files is pretty confusing for sure. I like the comparison table on the bottom of your readme. https://github.com/thesayyn/protoc-gen-ts#alternatives

However you only use it as a build-time dependency within our repo to generate those files, not a runtime dependency for our users, so the bar is a lot lower on stability. We'll very rarely change the worker_protocol.proto so we'll rarely need to run the tool. If your repo disappears we could find another generator, or worst case we could edit the files by hand if a field or two gets added to the worker_protocol.proto in the future.

The bigger concern to figure out first is if this is a breaking change, then we can't land it yet. I'd rather not start a 5.x branch yet since I'll have to cherry-pick and manage two branches for 6 months until the next major - usually we only start that process a couple months before the release.

So I guess we'd like to explore how to make this non-breaking. Either by restoring back-compat or distributing it alongside the existing implementation.

@thesayyn

thesayyn commented Sep 4, 2021

Copy link
Copy Markdown
Collaborator Author

Hmm, then I would vote that we make this non-breaking change and make this reflect the current API. Once we land this, I could send another PR which we could get landed in the next major release.

I will send another commit to restore backward compatibility.

@thesayyn

thesayyn commented Sep 4, 2021

Copy link
Copy Markdown
Collaborator Author

Some of the tests are failing. will pick them tomorrow

@thesayyn
thesayyn requested a review from jbedard as a code owner September 4, 2021 23:23
@thesayyn

thesayyn commented Sep 4, 2021 •

Copy link
Copy Markdown
Collaborator Author

Now some packages (those have worker support) have a direct dependency on @bazel/worker.

@thesayyn

thesayyn commented Sep 4, 2021 •

Copy link
Copy Markdown
Collaborator Author

@alexeagle I would very much appreciate your thoughts on how I could make these packages depend on the worker package and make the tests pass

@alexeagle

Copy link
Copy Markdown
Collaborator

I'm on mobile, but check the examples/BUILD file?

@thesayyn

thesayyn commented Sep 5, 2021

Copy link
Copy Markdown
Collaborator Author

Unfortunately npm_packages only replace occurrences in the root package and not dependants of the root package. So when @bazel/typescript it will be replaced by npm_packages but the dependencies of @bazel/typescript which is the dependency of @bazel/typescript

@thesayyn thesayyn changed the title feat: decouple @bazel/workers from rules_typescript and support cancellation feat: decouple @bazel/worker from rules_typescript Sep 5, 2021
@thesayyn

thesayyn commented Sep 5, 2021

Copy link
Copy Markdown
Collaborator Author

@alexeagle ready for a review. and got all the tests passing

Comment thread examples/BUILD.bazel Resolved
Comment thread examples/esbuild/WORKSPACE Resolved
"devDependencies": {
"@types/node": "12.12.50",
"protobufjs": "6.10.1",
"google-protobuf": "^3.6.1",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if the example has to change, that means it's a breaking change...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I have no clue how I can make this non-breaking change... may be you have something on your mind.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

also, I have no idea why this was needed in the first place. Shouldn’t rules_nodejs list this as a dependency even if the repository is consumed from the source?

I only added this because the tests were yelling at me

I believe that the problem lies somewhere else.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Shouldn’t this be handled by rules_nodejs_dev_dependencies? perhaps something similar? as I don’t rely on the consumer's npm repository, I don’t see why this should be listed as a dependency by the consumer.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

rules_nodejs_dev_dependencies is only for when you want to consume our rules from source. normal users shouldn't need it. but since this is the examples/from_source it actually does make sense here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

should I add it to this example? or shall we make separate PR for this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

sorry it was my mistake, as it's building rules_nodejs from source it's expected that our dev dependencies leak through. So far we have the rules_nodejs_dev_dependencies for starlark dependencies, but we don't have anything for npm dependencies (in theory it should be the root package json but we don't actually publish @bazel/javascript we treat it as private)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hmm. That’s what I was expecting. so is this okay to have this change?

@@ -0,0 +1,333 @@
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if you're going to check in a generated file, we should at least have a test that asserts it's up-to-date

how hard is it to leave the generated file in bazel-out and not check in as a source file?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

there are some reasons behind this

  • have IDE recognize the file
  • somehow rules_proto does not work on windows. it throws an error with a message "bazel-out is not an external or internal command" which probably has something to do with how rules_proto tries to invoke protoc. so the windows tests are going to fail. I have seen it before.
  • generating this file every time is not an option since ts_project won’t pick it up. it might create cycling dependency between worker and typescript package since they are relying on each other to build (not sure though)

I would prefer to add a generated_file_test and make an assertion. this test would be disabled on windows though because of the problem I have described above.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

generated_file_test (or bazel_skylib diff_test) with a windows CI exclusion SGTM

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

also the comment up here should include the bazel run command that updates the file content (in the unlikely case that worker_protocol.proto changes)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

have the assertion test in place: //packages/worker:copy_worker_protocol

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I couldn’t put the update command comment into the generated file. the assertion fails. so instead I put it into the build file. I hope that's fine

@alexeagle alexeagle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

looking really close :)

@@ -0,0 +1,333 @@
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

generated_file_test (or bazel_skylib diff_test) with a windows CI exclusion SGTM

Comment thread examples/BUILD.bazel Resolved
@@ -0,0 +1,333 @@
/**
* Generated by the protoc-gen-ts. DO NOT EDIT!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

also the comment up here should include the bazel run command that updates the file content (in the unlikely case that worker_protocol.proto changes)

Comment thread packages/worker/src/metadata.ts Resolved
@thesayyn

thesayyn commented Sep 7, 2021

Copy link
Copy Markdown
Collaborator Author

I believe that this is ready for another review.

@alexeagle alexeagle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

super nice 🌮

@alexeagle
alexeagle merged commit bda0472 into bazel-contrib:stable Sep 8, 2021
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.

2 participants