[bazel] Prepare demo pages for rules_js migration.

The follow-up CL https://skia-review.googlesource.com/c/buildbot/+/787697 migrates our repository to rules_js, rules_ts and rules_esbuild. This includes upgrading the underlying "esbuild" binary to a newer version, which handles JavaScript/TypeScript imports differently.

To illustrate, take the following two files:

    // test-sk-demo.ts
    console.log("test-sk-demo: Hello, world!");
    import './test-sk';
    console.log("test-sk-demo: Goodbye!");

    // test-sk.ts
    console.log("test-sk: Greetings from test-sk!")

Under the esbuild version currently in use, we get the following bundle (non-minified, etc.):

    "use strict";
    (() => {
      var __getOwnPropNames = Object.getOwnPropertyNames;
      var __commonJS = (cb, mod) => function __require() {
        return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
      };

      // bazel-out/k8-fastbuild/bin/golden/modules/test-sk/test-sk.js
      var require_test_sk = __commonJS({
        "bazel-out/k8-fastbuild/bin/golden/modules/test-sk/test-sk.js"() {
          "use strict";
          console.log("test-sk: Greetings from test-sk!");
        }
      });

      // bazel-out/k8-fastbuild/bin/golden/modules/test-sk/test-sk-demo.js
      var require_test_sk_demo = __commonJS({
        "bazel-out/k8-fastbuild/bin/golden/modules/test-sk/test-sk-demo.js"(exports) {
          Object.defineProperty(exports, "__esModule", { value: true });
          console.log("test-sk-demo: A");
          require_test_sk();
          console.log("test-sk-demo: B");
        }
      });
      "use strict";
      require_test_sk_demo();
    })();

And we observe the following in the browser's console:

    test-sk-demo: Hello, world!
    test-sk: Greetings from test-sk!
    test-sk-demo: Goodbye!

Under the new esbuild version, however, we get the following bundle:

    "use strict";
    (() => {
      // golden/modules/test-sk/test-sk.js
      console.log("test-sk: Greetings from test-sk!");

      // golden/modules/test-sk/test-sk-demo.ts
      console.log("test-sk-demo: Hello, world!");
      console.log("test-sk-demo: Goodbye!");
    })();

Which produces the following logs:

    test-sk: Greetings from test-sk!
    test-sk-demo: Hello, world!
    test-sk-demo: Goodbye!

Notice the "./test-sk" import was moved atop, which changes the evaluation order such that test-sk.ts is evaluated before test-sk-demo.ts.

Unfortunately this behavior breaks several demo pages that set up RPC mocks with fetchMock and then import the element under test. Example:

 - https://skia.googlesource.com/buildbot/+/af8f7d1d2f41c5067f66863940ec757c7ae3f414/perf/modules/commit-detail-picker-sk/commit-detail-picker-sk-demo.html#21
 - https://skia.googlesource.com/buildbot/+/af8f7d1d2f41c5067f66863940ec757c7ae3f414/perf/modules/commit-detail-picker-sk/commit-detail-picker-sk-demo.ts#39

In this example, the commit-detail-picker-sk custom element appears in the demo page's HTML. Due to the import order changes in the new esbuild, this leads to RPC errors because as soon as the custom element is connected to the DOM, it tries to fetch from an endpoint that hasn't yet been mocked.

I tried forcing the old esbuild behavior in a couple of ways, but none of them worked.

The solution I found is to rewrite these demo pages so that the custom element is dynamically created and attached to the DOM after we have mocked the necessary endpoints. We already use this pattern in many other demo pages, for example:

 - https://skia.googlesource.com/buildbot/+/af8f7d1d2f41c5067f66863940ec757c7ae3f414/golden/modules/triagelog-page-sk/triagelog-page-sk-demo.html#10
 - https://skia.googlesource.com/buildbot/+/af8f7d1d2f41c5067f66863940ec757c7ae3f414/golden/modules/triagelog-page-sk/triagelog-page-sk-demo.ts#41

In summary, this CL prepares our repository so that the rules_js migration does not break any demo pages.


Bug: b/314813928
Change-Id: I0efa886fa9cc7508c2e966e3cbbb5ca9abf37ccf
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/789409
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Leandro Lovisolo <lovisolo@google.com>
18 files changed
tree: 3565466b9b05034e6a7aedffc592bb3379d6e588
  1. am/
  2. android_ingest/
  3. android_stats/
  4. api/
  5. autoroll/
  6. bash/
  7. bazel/
  8. bisection/
  9. blamer/
  10. bugs-central/
  11. cabe/
  12. cd/
  13. cherrypick-watcher/
  14. cmd/
  15. codereview-watcher/
  16. codesize/
  17. comments/
  18. cq_watcher/
  19. ct/
  20. datahopper/
  21. debugger-app/
  22. demos/
  23. docker/
  24. docker_pushes_watcher/
  25. docs/
  26. docsyserver/
  27. ds/
  28. elements-sk/
  29. email/
  30. external/
  31. fiddlek/
  32. firestore/
  33. get_service_account/
  34. gitsync/
  35. go/
  36. gold-client/
  37. golden/
  38. helloworld/
  39. infra/
  40. infra-sk/
  41. jsdoc/
  42. jsfiddle/
  43. k8s-checker/
  44. k8s-deployer/
  45. kube/
  46. leasing/
  47. licenses/
  48. machine/
  49. make/
  50. modules/
  51. named-fiddles/
  52. new_element/
  53. npm-audit-mirror/
  54. npm_deps/
  55. perdiff/
  56. perf/
  57. periodic-trigger/
  58. proberk/
  59. promk/
  60. puppeteer-tests/
  61. sa-keys-checker/
  62. scrap/
  63. scripts/
  64. shaders/
  65. sk/
  66. skbug/
  67. skcq/
  68. skfe/
  69. skolo/
  70. skottie/
  71. static_server/
  72. status/
  73. task_driver/
  74. task_scheduler/
  75. temporal/
  76. test-service/
  77. tools/
  78. tree_status/
  79. trybot_updater/
  80. .bazelignore
  81. .bazelrc
  82. .bazelversion
  83. .eslintrc.js
  84. .gitattributes
  85. .gitignore
  86. .mockery.yaml
  87. .npmrc
  88. .prettierignore
  89. .prettierrc.json
  90. .puppeteerrc.js
  91. .vpython
  92. BAZEL_CHEATSHEET.md
  93. BUILD.bazel
  94. build_infra_prod.sh
  95. CDB.md
  96. cipd.ensure
  97. codereview.settings
  98. DATASTORE.md
  99. demopage.sh
  100. DEPS
  101. go.mod
  102. go.sum
  103. go_repositories.bzl
  104. karmatest.sh
  105. launch.md
  106. LICENSE
  107. Makefile
  108. OWNERS
  109. package-lock.json
  110. package.json
  111. PRESUBMIT.py
  112. PRIVACY_POLICY.md
  113. README.md
  114. STYLEGUIDE.md
  115. tools.go
  116. tsconfig.json
  117. whitespace.txt
  118. WORKSPACE
README.md

Skia-Buildbot Repository

This repo contains infrastructure code for Skia.

Getting the Source Code

The main source code repository is a Git repository hosted at https://skia.googlesource.com/buildbot.git. It is possible to check out this repository directly with git clone or via go get.

Using git clone allows you to work in whatever directory you want. You will still need to set GOPATH in order to build some apps (recommended to put this in a cache dir). E.g.:

$ cd ${WORKDIR}
$ git clone https://skia.googlesource.com/buildbot.git
$ export GOPATH=${HOME}/.cache/gopath/$(basename ${WORKDIR})
$ mkdir $GOPATH
$ cd buildbot

Install dependencies

Almost all applications are built with Bazel, and bazelisk is the recommended tool to ensure you have the right version of bazel installed:

go install github.com/bazelbuild/bazelisk@latest
go install github.com/bazelbuild/buildtools/buildifier@latest
go install github.com/kisielk/errcheck@latest
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/mikefarah/yq/v4@latest
go install go.chromium.org/luci/client/cmd/...@latest

Install other dependencies:

sudo apt-get install jq

Build ~everything

bazelisk build --config=mayberemote //...

Test everything

bazelisk test --config=mayberemote //...

Generated Code

To update generated code run the following in any directory:

go generate ./...

Running unit tests

Install Cloud SDK.

Use this command to run the presubmit tests:

./run_unittests --small