-
Notifications
You must be signed in to change notification settings - Fork 15
Typescript compilation #78
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
Conversation
.gitignore
Outdated
| __pycache__ | ||
|
|
||
| # Node Modules # | ||
| node_modules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having added node_modules, we do not want to add it to git
| workspace(name = "graknlabs_protocol") | ||
| workspace( | ||
| name = "graknlabs_protocol", | ||
| managed_directories = {"@npm": ["node_modules"]}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we've added node modules, we want to be able to use the modules as targets, which necessitates managing it as a directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we should rename @npm to @node_modules for clarity - what do you think?
We would make the same change in client-nodejs.
| name = "npm", | ||
| package_json = "//:package.json", | ||
| package_lock_json = "//:package-lock.json", | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performing an npm_install is required in order to get said node modules up to date and in the build, and we need to set up the nodejs rules so that we can fetch them in. (The node modules specifically required are the protoc compiler and the gen_grpc plugin for it)
| "protobuf/session_pb.d.ts", | ||
| "protobuf/session_pb.js", | ||
| "protobuf/transaction_pb.d.ts", | ||
| "protobuf/transaction_pb.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set of outputs changed to reflect we a) now only have a single service and b) we now have both a .js and a .d.ts file for every incoming proto file.
| --grpc_out='./$(@D)/' \ | ||
| --ts_out='./$(@D)/' \ | ||
| --proto_path=`dirname $(execpath //:WORKSPACE)` \ | ||
| $(execpaths //protobuf:proto-raw-buffers);", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This command is a bit brave, but divided by line:
- Symlinks the node runfiles required by the typescript plugin into the directory where the protocol compiler can see it
- Runs the node protoc compiler
- Using the protoc-gen-ts plugin to generate typescript type definitions in addition to the javascript definitions
- Outputting the javascript, typescript, and service definitions to the output directory specified by bazel ($(@d))
- Looking in the workspace for the relative paths to the .proto files
- using the .proto files as specified in the proto-raw-buffers filegroup as the inputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is excellent documentation, nice work! I think we should add it to the code itself, in comments, so this doesn't get lost in the ether.
grpc/nodejs/BUILD
Outdated
| "@npm//google-protobuf", | ||
| "//protobuf:proto-raw-buffers", | ||
| "//:WORKSPACE" | ||
| ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The required tools for the above command. Workspace only has to be included in order to find the relative path for the .proto files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, let's add this as a comment in the code itself 🙂 Something like: "We use //:WORKSPACE to find the relative path for the .proto files".
grpc/nodejs/protocol.json
Outdated
| "skipLibCheck": true, /* Skip type checking of declaration files. */ | ||
| "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Standard tsconfig file generated automatically by tsc, for tsc.
| "grpc-tools": "^1.9.1", | ||
| "grpc_tools_node_protoc_ts": "^5.0.1" | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node dependencies in order to compile typescript
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need both package.json files?
| "session.proto", | ||
| "transaction.proto", | ||
| ] | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The libraries we currently have pre-compile the .proto files, which is inconvenient as we wish to recompile them. Where we could (and in future should) build a full blown bazel rule extracting .src_file from the proto_library targets, for the time being providing a filegroup is equally legitimate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally with you on this one - let's raise a GitHub issue for it (in graknlabs/protocol) and possibly put a TODO in the source code linking to the issue so it doesn't get lost.
…ol into typescript-compilation
grpc/python/BUILD
Outdated
| py_library( | ||
| name = "protocol", | ||
| srcs = ["protocol_pkg"], | ||
| srcs = ["protocol-pkg"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed for consistency on the way past
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice effort!
However, will a Bazel target with - rather than _ work in Python @vmax ?
| }, | ||
| "devDependencies": { | ||
| "typescript": "3.9.7" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Package.json for compiling the npm package
alexjpwalker
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks excellent. I've highlighted a couple of trailing newlines and suggested that we add relevant documentation to GitHub and the source code where applicable.
| workspace(name = "graknlabs_protocol") | ||
| workspace( | ||
| name = "graknlabs_protocol", | ||
| managed_directories = {"@npm": ["node_modules"]}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we should rename @npm to @node_modules for clarity - what do you think?
We would make the same change in client-nodejs.
| --grpc_out='./$(@D)/' \ | ||
| --ts_out='./$(@D)/' \ | ||
| --proto_path=`dirname $(execpath //:WORKSPACE)` \ | ||
| $(execpaths //protobuf:proto-raw-buffers);", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is excellent documentation, nice work! I think we should add it to the code itself, in comments, so this doesn't get lost in the ether.
grpc/nodejs/BUILD
Outdated
| "@npm//google-protobuf", | ||
| "//protobuf:proto-raw-buffers", | ||
| "//:WORKSPACE" | ||
| ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, let's add this as a comment in the code itself 🙂 Something like: "We use //:WORKSPACE to find the relative path for the .proto files".
grpc/nodejs/package.json
Outdated
| "devDependencies": { | ||
| "typescript": "3.9.7" | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | |
| } | |
| "grpc-tools": "^1.9.1", | ||
| "grpc_tools_node_protoc_ts": "^5.0.1" | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need both package.json files?
| "session.proto", | ||
| "transaction.proto", | ||
| ] | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally with you on this one - let's raise a GitHub issue for it (in graknlabs/protocol) and possibly put a TODO in the source code linking to the issue so it doesn't get lost.
.grabl/automation.yml
Outdated
| export DEPLOY_NPM_PASSWORD=$REPO_GRAKN_PASSWORD | ||
| export DEPLOY_NPM_EMAIL=$REPO_GRAKN_EMAIL | ||
| bazel run --define version=$(git rev-parse HEAD) //grpc/nodejs:deploy-npm -- snapshot | ||
| dependencies: [build, build-dependency, test] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have a job test do we? In that case this should be removed
WORKSPACE
Outdated
| ######################### | ||
|
|
||
| load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
| http_archive( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update the version of rules_nodejs in @graknlabs_dependencies with this one and then have the WORKSPACE file load from there instead? You can get @alexjpwalker 's help for the know-how.
package.json
Outdated
| @@ -0,0 +1,11 @@ | |||
| { | |||
| "name": "protocol", | |||
| "version": "1.0.0", | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VERSION should match the version file shouldn't it? In that case, 2.0.0-alpha?
grpc/python/BUILD
Outdated
| py_library( | ||
| name = "protocol", | ||
| srcs = ["protocol_pkg"], | ||
| srcs = ["protocol-pkg"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice effort!
However, will a Bazel target with - rather than _ work in Python @vmax ?
Co-authored-by: Alex Walker <alexjpwalker@gmail.com>
| name = "graknlabs_dependencies", | ||
| remote = "https://github.com/Phillammon/dependencies", | ||
| commit = "8526f49ce77fcd8e9029ab4b08d0fd5d0b4497f8", # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_dependencies | ||
| commit = "63bfceddc8493e743f54ab230239cd42eb1bccdf", # sync-marker: do not remove this comment, this is used for sync-dependencies by @graknlabs_dependencies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update this before merging
alexjpwalker
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving - just remember to bump dependencies and verify that it builds in Grabl
What is the goal of this PR?
Compile protobuf files to typescript rather than raw javascript in the nodejs target.
What are the changes implemented in this PR?
Create genrule calling protoc compiler directly with the appropriate plugins to output both javascript and typescript type definition files when built.