TypeScript compilation
Bazel

TypeScript compilation


tsc_wrapped_tsconfig

tsc_wrapped_tsconfig(ctx, files, srcs, devmode_manifest, jsx_factory, **kwargs)

Produce a tsconfig.json that sets options required under Bazel.

Attributes

ctx

Unknown; Required

files

Unknown; Required

srcs

Unknown; Required

devmode_manifest

Unknown; Optional

jsx_factory

Unknown; Optional

**kwargs

Unknown; Optional


ts_library_macro

ts_library_macro(tsconfig, **kwargs)

Wraps ts_library to set the default for the tsconfig attribute.

This must be a macro so that the string is converted to a label in the context of the workspace that declares the ts_library target, rather than the workspace that defines ts_library, or the workspace where the build is taking place.

This macro is re-exported as ts_library in the public API.

Attributes

tsconfig

Unknown; Optional

the label pointing to a tsconfig.json file

**kwargs

Unknown; Optional

remaining args to pass to the ts_library rule


ts_library

ts_library(name, deps, srcs, compile_angular_templates, compiler, internal_testing_type_check_dependencies, node_modules, supports_workers, tsconfig, tsickle_typed)

ts_library type-checks and compiles a set of TypeScript sources to JavaScript.

It produces declarations files (.d.ts) which are used for compiling downstream TypeScript targets and JavaScript for the browser and Closure compiler.

Attributes

name

Name; Required

A unique name for this rule.

deps

List of labels; Optional; Default is []

srcs

List of labels; Required

The TypeScript source files to compile.

compile_angular_templates

Boolean; Optional; Default is False

Run the Angular ngtsc compiler under ts_library

compiler

Label; Optional; Default is @npm//@bazel/typescript/bin:tsc_wrapped

Sets a different TypeScript compiler binary to use for this library. For example, we use the vanilla TypeScript tsc.js for bootstrapping, and Angular compilations can replace this with ngc.

        The default ts_library compiler depends on the `@npm//@bazel/typescript`
        target which is setup for projects that use bazel managed npm deps that
        fetch the @bazel/typescript npm package. It is recommended that you use
        the workspace name `@npm` for bazel managed deps so the default
        compiler works out of the box. Otherwise, you'll have to override
        the compiler attribute manually.
internal_testing_type_check_dependencies

Boolean; Optional; Default is False

Testing only, whether to type check inputs that aren't srcs.

node_modules

Label; Optional; Default is @npm//typescript:typescript__typings

The npm packages which should be available during the compile.

        The default value is `@npm//typescript:typescript__typings` is setup
        for projects that use bazel managed npm deps that. It is recommended
        that you use the workspace name `@npm` for bazel managed deps so the
        default node_modules works out of the box. Otherwise, you'll have to
        override the node_modules attribute manually. This default is in place
        since ts_library will always depend on at least the typescript
        default libs which are provided by `@npm//typescript:typescript__typings`.

        This attribute is DEPRECATED. As of version 0.18.0 the recommended
        approach to npm dependencies is to use fine grained npm dependencies
        which are setup with the `yarn_install` or `npm_install` rules.

        For example, in targets that used a `//:node_modules` filegroup,

        ```
        ts_library(
          name = "my_lib",
          ...
          node_modules = "//:node_modules",
        )
        ```

        which specifies all files within the `//:node_modules` filegroup
        to be inputs to the `my_lib`. Using fine grained npm dependencies,
        `my_lib` is defined with only the npm dependencies that are
        needed:

        ```
        ts_library(
          name = "my_lib",
          ...
          deps = [
              "@npm//@types/foo",
              "@npm//@types/bar",
              "@npm//foo",
              "@npm//bar",
              ...
          ],
        )
        ```

        In this case, only the listed npm packages and their
        transitive deps are includes as inputs to the `my_lib` target
        which reduces the time required to setup the runfiles for this
        target (see https://github.com/bazelbuild/bazel/issues/5153).
        The default typescript libs are also available via the node_modules
        default in this case.

        The @npm external repository and the fine grained npm package
        targets are setup using the `yarn_install` or `npm_install` rule
        in your WORKSPACE file:

        yarn_install(
          name = "npm",
          package_json = "//:package.json",
          yarn_lock = "//:yarn.lock",
        )
supports_workers

Boolean; Optional; Default is True

Intended for internal use only. Allows you to disable the Bazel Worker strategy for this library. Typically used together with the "compiler" setting when using a non-worker aware compiler binary.

tsconfig

Label; Optional

A tsconfig.json file containing settings for TypeScript compilation. Note that some properties in the tsconfig are governed by Bazel and will be overridden, such as target and module.

        The default value is set to `//:tsconfig.json` by a macro. This means you must
        either:

        - Have your `tsconfig.json` file in the workspace root directory
        - Use an alias in the root BUILD.bazel file to point to the location of tsconfig:
          `alias(name="tsconfig.json", actual="//path/to:tsconfig-something.json")`
        - Give an explicit `tsconfig` attribute to all `ts_library` targets
tsickle_typed

Boolean; Optional; Default is True