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
bazel: generate graphql operation interfaces, css module typings #45682
Conversation
client/shared/dev/tools.bzl
Outdated
load("@aspect_rules_js//js:defs.bzl", "js_library") | ||
load("@npm//:typed-scss-modules/package_json.bzl", types_scss_modules_bin = "bin") | ||
|
||
def module_style_typings(name = "module_style_typings", deps = []): |
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.
On second thought, it might be better to not hide the name as eventually these will be included in the frontend packages and it will be clearer if the name is visible in the BUILD file.
types_scss_modules_bin.tsm( | ||
name = name, | ||
srcs = [":%s_sources" % name] + deps, | ||
outs = outs, | ||
args = [ | ||
"--logLevel", | ||
"error", | ||
"%s/**/*.module.scss" % native.package_name(), | ||
"--includePaths", | ||
"client", | ||
"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.
This mimics what the gulp script did, but with rules_js we can invoke an npm package binary as a build action directly in a BUILD 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.
Given the simplicity of this case, I didn't feel it was necessary to have Bazel and the legacy build share the same code path.
c35c718
to
b3b4898
Compare
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.
// Bazel entry point to generate a single graphql operations file; the legacy build | ||
// continues to import `generateGraphQlOperations` and generate all operations files. | ||
async function main(args) { | ||
await _generateGraphQlOperations([{ interfaceNameForOperations: args[0], outputPath: args[1] }]) | ||
} | ||
|
||
;(async () => { | ||
if (require.main === module) { | ||
await main(process.argv.slice(2)) | ||
} | ||
})() |
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 use the same approach as we do for other scripts shared with Bazel? It would be easier to maintain these scripts if the follow the same structure, validate arguments and handle errors in the same way.
sourcegraph/client/shared/dev/generateSchema.js
Lines 53 to 71 in 5dec121
async function main(args) { | |
if (args.length !== 1) { | |
throw new Error('Usage: <schemaName>') | |
} | |
const schemaName = args[0] | |
await generateSchema(schemaName) | |
} | |
if (require.main === module) { | |
main(process.argv.slice(2)).catch(error => { | |
console.error(error) | |
process.exit(1) | |
}) | |
} | |
module.exports = { | |
generateSchema, | |
} |
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.
9cd5709 look ok?
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.
@jbedard, yeah, looks great! Can we also validate CLI arguments and throw an error similar to what we do in the generateSchema.js
script?
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've done this in a fixup on the new PR: 7405f24
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.
Thank you! 💜
"//:node_modules/@graphql-codegen/cli", | ||
"//:node_modules/@graphql-codegen/typescript", | ||
"//:node_modules/@graphql-codegen/typescript-operations", | ||
"//:node_modules/prettier", |
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.
Would it be possible to automate maintenance of the list of dependencies here somehow later?
The issue with bazel hanging might be bazelbuild/bazel#16159 (comment) which occurs when the pnpm-lock is out of date, although I'm not sure if you'd be seeing that case. If you let it sit for a bit (I think mine is 30s) does it finish and then not occur again (until a package.json is updated...)? |
Yeah, it took around 2.5 minutes for me. Now I see the output again. Is there a way to see what's happening under the hood or prevent this by manually running some commands? |
The issue I linked to is I think the reason there is no output during that time. The case where I see this ~30s is when the yarn lock changes and the pnpm one must be updated. I'm not sure if you should be seeing that case though? Does bazel output any info about what was consuming that time? |
Here's the
|
No, nothing in there I recognize. Does it happen 100% of the time? Even when just running the build twice? Maybe add a comment to a .ts file so it's not 100% cached and it should be super fast the second time. |
Replaced with #45756 |
This creates bazel rules and targets for generating these. The existing scripts are modified to support running from bazel and are run in the BUILDs.
Test plan