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

bazel: generate graphql operation interfaces, css module typings #45682

Closed
wants to merge 6 commits into from

Conversation

jbedard
Copy link
Contributor

@jbedard jbedard commented Dec 14, 2022

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

  • compile with bazel

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 = []):
Copy link
Contributor

@kormide kormide Dec 15, 2022

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.

Comment on lines +31 to +42
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",
],
Copy link
Contributor

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.

Copy link
Contributor

@kormide kormide Dec 15, 2022

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.

Copy link
Member

@valerybugakov valerybugakov left a comment

Choose a reason for hiding this comment

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

For some reason, bazel build ... and bazel info hang for me locally without any output after switching to this branch. But they worked as expected on the previous PR. Any tips on how to mitigate that?

ESLint errors and GraphQL operations type imports cause multiple CI failures:

Screenshot 2022-12-15 at 13 17 35

Screenshot 2022-12-15 at 13 18 06

Comment on lines 164 to 174
// 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))
}
})()
Copy link
Member

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.

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,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

9cd5709 look ok?

Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Thank you! 💜

client/shared/dev/generateGraphQlOperations.js Outdated Show resolved Hide resolved
client/shared/dev/generateGraphQlOperations.js Outdated Show resolved Hide resolved
client/shared/dev/generateGraphQlOperations.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
"//:node_modules/@graphql-codegen/cli",
"//:node_modules/@graphql-codegen/typescript",
"//:node_modules/@graphql-codegen/typescript-operations",
"//:node_modules/prettier",
Copy link
Member

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?

@jbedard
Copy link
Contributor Author

jbedard commented Dec 15, 2022

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...)?

@valerybugakov
Copy link
Member

If you let it sit for a bit (I think mine is 30s)

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?

@jbedard
Copy link
Contributor Author

jbedard commented Dec 15, 2022

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?

@valerybugakov
Copy link
Member

valerybugakov commented Dec 15, 2022

Here's the bazel info output. Anything rings the bell here?

λ bazel info
Starting local Bazel server and connecting to it...
bazel-bin: /private/var/tmp/_bazel_val/b74f98c07c1f7901aeeb711da373452f/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin
bazel-genfiles: /private/var/tmp/_bazel_val/b74f98c07c1f7901aeeb711da373452f/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin
bazel-testlogs: /private/var/tmp/_bazel_val/b74f98c07c1f7901aeeb711da373452f/execroot/__main__/bazel-out/darwin_arm64-fastbuild/testlogs
character-encoding: file.encoding = ISO-8859-1, defaultCharset = ISO-8859-1
command_log: /private/var/tmp/_bazel_val/b74f98c07c1f7901aeeb711da373452f/command.log
committed-heap-size: 1073MB
execution_root: /private/var/tmp/_bazel_val/b74f98c07c1f7901aeeb711da373452f/execroot/__main__
gc-count: 11
gc-time: 60ms
install_base: /var/tmp/_bazel_val/install/b87d93deaab718fa4775f187d0b2caae
java-home: /private/var/tmp/_bazel_val/install/b87d93deaab718fa4775f187d0b2caae/embedded_tools/jdk
java-runtime: OpenJDK Runtime Environment (build 11.0.10+9-LTS) by Azul Systems, Inc.
java-vm: OpenJDK 64-Bit Server VM (build 11.0.10+9-LTS, mixed mode) by Azul Systems, Inc.
max-heap-size: 17179MB
output_base: /private/var/tmp/_bazel_val/b74f98c07c1f7901aeeb711da373452f
output_path: /private/var/tmp/_bazel_val/b74f98c07c1f7901aeeb711da373452f/execroot/__main__/bazel-out
package_path: %workspace%
release: release 6.0.0rc3
repository_cache: /var/tmp/_bazel_val/cache/repos/v1
server_log: /private/var/tmp/_bazel_val/b74f98c07c1f7901aeeb711da373452f/java.log.macbook-pro-2.val.log.java.20221215-132143.27883
server_pid: 27883
used-heap-size: 720MB

@jbedard
Copy link
Contributor Author

jbedard commented Dec 15, 2022

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.

@jbedard
Copy link
Contributor Author

jbedard commented Dec 16, 2022

Replaced with #45756

@jbedard jbedard closed this Dec 16, 2022
@valerybugakov
Copy link
Member

Does it happen 100% of the time? Even when just running the build twice?

@jbedard, no, it happens sometimes. For example, when I switched from your previous PR to this one. Running bazel info or bazel build ... on #45756 works without delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants