Skip to content

Bootstrap issue when pulling @bazel/typescript from npm #275

Closed

Description

@gregmagolan

When pulling @bazel/typescript from npm, there is a bootstrap issue since a user's WORKSPACE will need to reference @build_bazel_rules_typescript,

load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")
ts_setup_workspace()

but until you run yarn or npm that file does not exist as it comes from node_modules,

local_repository(
    name = "build_bazel_rules_typescript",
    path = "node_modules/@bazel/typescript",
)

This means that you can't run bazel run @nodejs//:yarn without first running a locally installed version of yarn or npm.

Activity

  1. qzmfranklin commented on Aug 21, 2018

    @qzmfranklin
    Contributor

    @gregmagolan 👍

    I think the idea of using a yarn/npm-ed version of @bazel/typescript is not good for exactly the reason you have described: you have to run yarn locally before running bazel run @nodejs//:yarn.

    I believe the 'correct' solution is to use yarn_install, loaded from rules_nodejs and have everything else (such as nodejs_binary) depend on it via the node_modules keyword.

    Any thoughts?

  2. self-assigned this
    on Sep 6, 2018
  3. gregmagolan commented on Sep 6, 2018

    @gregmagolan
    CollaboratorAuthor

    @qzmfranklin There's an issue with using yarn_install to pull down the rules_typescript external repository in that yarn install puts the node_modules in an external repository and there is no way to point a local_repository with a path inside of an external repository.

    The other option @alexeagle tried was to have node_repositories() run yarn and create the node_modules but because the node_module filegroup glob is eagerly evaluated when you run a bazel target, it is evaluated before node_repositories() runs and before the node_modules folder was created.

    We're working on an idiomatic install solution where the rules_typescript bazel repository will be pulled down in the WORKSPACE via http_archive and but there will still be an npm package with a name like @bazel/typescript that contains just the compiled .js files needed for its actions. This is more idiomatic since we are not shipping typescript files in an npm package, it improves the initial build time slightly since tsc_wrapped.js is already compiled and available to the ts_library rule, and it still allows for @bazel/typescript to pull down any transitive npm dependencies that are required to run ts_library and other rules. We'll have a version check to ensure that the npm package and the external repository versions match.

    I'll be working more on this this week. Stay tuned.

  4. gregmagolan commented on Oct 5, 2018

    @gregmagolan
    CollaboratorAuthor

    FInally resolved this with the release of npm fine grained deps and idiomatic install of rules_typescript. The @bazel/typescript npm package is now a .js only distribution and the build_bazel_rules_typescript is fetched via http_archive in your WORKSPACE.

    See https://github.com/alexeagle/angular-bazel-example as an example. In this example, build_bazel_rules_typescript is fetched in the rules_angular_dependencies() function which comes form the angular rules and @bazel/typescript and @bazel/karma which are both published from https://github.com/bazelbuild/rules_typescript are fetched in the package.json file.

    A simple example that doesn't include angular is here: https://github.com/bazelbuild/rules_typescript/tree/master/internal/e2e/package_typescript_karma

  5. added 2 commits that reference this issue on Oct 17, 2020
    af0c28e
    fdb0032
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions