Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ gazelle(
js_library(
name = "protobufjs_bootstrap_scripts",
srcs = [
"@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules/long/dist/long.js",
"@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules/protobufjs/dist/minimal/protobuf.min.js",
"@build_bazel_rules_typescript_protobufs_compiletime_deps//node_modules/long:dist/long.js",
"@build_bazel_rules_typescript_protobufs_compiletime_deps//node_modules/protobufjs:dist/minimal/protobuf.min.js",
],
# Make devmode loading work when it does require("protobufjs/minimal")
# so this is shimmed to define it to equal global.protobuf
Expand All @@ -56,15 +56,15 @@ js_library(
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")

# A nodejs_binary for @bazel/typescript/tsc_wrapped to use by default in
# ts_library that depends on @npm//:@bazel/typescript instead of the
# ts_library that depends on @npm//@bazel/typescript instead of the
# output of the //internal/tsc_wrapped ts_library rule. This
# default is for downstream users that depend on the @bazel/karma npm
# package. The generated @npm//:@bazel/typescript/tsc_wrapped target
# default is for downstream users that depend on the @bazel/typescript npm
# package. The generated @npm//@bazel/typescript/bin:tsc_wrapped target
# does not work because it does not have the node `--expose-gc` flag
# set which is required to support the call to `global.gc()`.
nodejs_binary(
name = "@bazel/typescript/tsc_wrapped",
data = ["@npm//:@bazel/typescript"],
data = ["@npm//@bazel/typescript"],
entry_point = "@bazel/typescript/tsc_wrapped/tsc_wrapped.js",
install_source_map_support = False,
templated_args = ["--node_options=--expose-gc"],
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ ts_library(
name = "my_code",
srcs = glob(["*.ts"]),
deps = [
"@npm//:@types/node",
"@npm//:@types/foo",
"@npm//:foo",
"@npm//@types/node",
"@npm//@types/foo",
"@npm//foo",
"//path/to/other:library",
],
)
```

You can also you the `@npm//:@types` target which will include all
You can also you the `@npm//@types` target which will include all
packages in the `@types` scope as dependencies.

If you are using self-managed npm dependencies, you can use the
Expand Down
16 changes: 5 additions & 11 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,15 @@ yarn_install(
# Install a hermetic version of node.
node_repositories(preserve_symlinks = True)

# Note: We depend on @bazel/typescript in package.json
# so that the target @npm//@bazel/typescript is defined
# as it is referenced in /BUILD.bazel for use downstream.
# This target and package is not used locally so
# the version of this depedency does not matter.
yarn_install(
name = "npm",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
manual_build_file_contents = """
filegroup(
name = "@bazel/typescript",
srcs = [],
)

filegroup(
name = "@bazel/karma",
srcs = [],
)
""",
)

load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
Expand Down
16 changes: 8 additions & 8 deletions docs/api/build_defs.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ <h3 id="ts_library_args">Attributes</h3>
<p>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 <code>ngc</code>.</p>
<pre><code> The default ts_library compiler depends on the `@npm//:@bazel/typescript`
<pre><code> 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
Expand All @@ -258,15 +258,15 @@ <h3 id="ts_library_args">Attributes</h3>
<tr id="ts_library.node_modules">
<td><code>node_modules</code></td>
<td>
<p><code><a href="https://bazel.build/docs/build-ref.html#labels">Label</a>; Optional; Default is @npm//:typescript__typings</code></p>
<p><code><a href="https://bazel.build/docs/build-ref.html#labels">Label</a>; Optional; Default is @npm//typescript:typescript__typings</code></p>
<p>The npm packages which should be available during the compile.</p>
<pre><code> The default value is `@npm//:typescript__typings` is setup
<pre><code> 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__typings`.
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
Expand All @@ -292,10 +292,10 @@ <h3 id="ts_library_args">Attributes</h3>
name = "my_lib",
...
deps = [
"@npm//:@types/foo",
"@npm//:@types/bar",
"@npm//:foo",
"@npm//:bar",
"@npm//@types/foo",
"@npm//@types/bar",
"@npm//foo",
"@npm//bar",
...
],
)
Expand Down
2 changes: 1 addition & 1 deletion docs/api/karma/ts_web_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ <h3 id="ts_web_test_args">Attributes</h3>
<tr id="ts_web_test.karma">
<td><code>karma</code></td>
<td>
<p><code><a href="https://bazel.build/docs/build-ref.html#labels">Label</a>; Optional; Default is @npm//:@bazel/karma/karma</code></p>
<p><code><a href="https://bazel.build/docs/build-ref.html#labels">Label</a>; Optional; Default is @npm//@bazel/karma/bin:karma</code></p>

</td>
</tr>
Expand Down
6 changes: 3 additions & 3 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ ts_library(
":foo_ts_library",
"//examples/generated_ts",
"//examples/some_library:lib",
"@npm//:typescript",
# Example of using the `@npm//:@types` target to depend on all
"@npm//typescript",
# Example of using the `@npm//@types` target to depend on all
# @types packages and with the types attribute of tsconfig not
# specified. In this case, typescript will automatically discover
# all types under node_modules/@types and included them in the compile.
# See getAutomaticTypeDirectiveNames in
# https://github.com/Microsoft/TypeScript/blob/master/src/compiler/moduleNameResolver.ts.
"@npm//:@types",
"@npm//@types",
],
)

Expand Down
6 changes: 3 additions & 3 deletions examples/app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ ts_library(
srcs = ["app_e2e_test.ts"],
tsconfig = "//examples:tsconfig-test",
deps = [
"@npm//:@types/jasmine",
"@npm//:@types/node",
"@npm//:protractor",
"@npm//@types/jasmine",
"@npm//@types/node",
"@npm//protractor",
],
)
2 changes: 1 addition & 1 deletion examples/googmodule/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ jasmine_node_test(
srcs = ["googmodule_output_test.js"],
data = [
":es5_output",
"@npm//:jasmine",
"@npm//jasmine",
],
)
18 changes: 9 additions & 9 deletions examples/protocol_buffers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ ts_library(
tsconfig = "//examples:tsconfig-test",
deps = [
":car",
"@npm//:@types/jasmine",
"@npm//:@types/long",
"@npm//:@types/node",
"@npm//:long",
"@npm//@types/jasmine",
"@npm//@types/long",
"@npm//@types/node",
"@npm//long",
],
)

Expand Down Expand Up @@ -83,8 +83,8 @@ rollup_bundle(
genrule(
name = "protobufjs",
srcs = [
"@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules/protobufjs/dist/minimal/protobuf.min.js",
"@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules/long/dist/long.js",
"@build_bazel_rules_typescript_protobufs_compiletime_deps//node_modules/protobufjs:dist/minimal/protobuf.min.js",
"@build_bazel_rules_typescript_protobufs_compiletime_deps//node_modules/long:dist/long.js",
],
outs = [
"protobuf.min.js",
Expand All @@ -108,8 +108,8 @@ ts_library(
srcs = ["app_e2e_test.ts"],
tsconfig = "//examples:tsconfig-test",
deps = [
"@npm//:@types/jasmine",
"@npm//:@types/node",
"@npm//:protractor",
"@npm//@types/jasmine",
"@npm//@types/node",
"@npm//protractor",
],
)
4 changes: 2 additions & 2 deletions examples/testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ ts_library(
tsconfig = "//examples:tsconfig-test",
deps = [
":lib",
"@npm//:@types/jasmine",
"@npm//:@types/node",
"@npm//@types/jasmine",
"@npm//@types/node",
],
)

Expand Down
2 changes: 1 addition & 1 deletion examples/tsconfig-bar.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"strict": true,
"lib": ["es2015.promise", "dom", "es5"],
// Auto-discover all types in this configuration since we don't
// specify `types = []` and the ts_library rule depends on `@npm//:@types`.
// specify `types = []` and the ts_library rule depends on `@npm//@types`.
// Typescript will automatically discover all types under node_modules/@types
// and included them in the build. See getAutomaticTypeDirectiveNames in
// https://github.com/Microsoft/TypeScript/blob/master/src/compiler/moduleNameResolver.ts.
Expand Down
34 changes: 17 additions & 17 deletions internal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary", "jasmine_node_test
nodejs_binary(
name = "tsc",
data = [
"@npm//:source-map-support",
"@npm//:typescript",
"@npm//source-map-support",
"@npm//typescript",
],
entry_point = "typescript/lib/tsc.js",
visibility = ["//internal:__subpackages__"],
Expand Down Expand Up @@ -65,25 +65,25 @@ ts_library(
# work with vanilla tsc.
# Workaround for https://github.com/Microsoft/TypeScript/issues/22208
deps = [
"@npm//:@types/node",
"@npm//:tsickle",
"@npm//:tsutils",
"@npm//:typescript",
"@npm//@types/node",
"@npm//tsickle",
"@npm//tsutils",
"@npm//typescript",
],
)

# Other ts_library rules will use this custom compiler, which calls the
# TypeScript APIs to act like tsc, but adds capabilities like Bazel workers.
# TODO(gregmagolan): make @npm//:tsickle dependency optional
# TODO(gregmagolan): make @npm//tsickle dependency optional
nodejs_binary(
name = "tsc_wrapped_bin",
data = [
":tsc_wrapped",
"@npm//:protobufjs",
"@npm//:source-map-support",
"@npm//:tsickle",
"@npm//:tsutils",
"@npm//:typescript",
"@npm//protobufjs",
"@npm//source-map-support",
"@npm//tsickle",
"@npm//tsutils",
"@npm//typescript",
],
entry_point = "build_bazel_rules_typescript/internal/tsc_wrapped/tsc_wrapped.js",
templated_args = ["--node_options=--expose-gc"],
Expand All @@ -96,9 +96,9 @@ ts_library(
tsconfig = "//internal:tsc_wrapped/tsconfig.json",
deps = [
":tsc_wrapped",
"@npm//:@types/jasmine",
"@npm//:@types/node",
"@npm//:typescript",
"@npm//@types/jasmine",
"@npm//@types/node",
"@npm//typescript",
],
)

Expand All @@ -107,8 +107,8 @@ jasmine_node_test(
srcs = [],
deps = [
":test_lib",
"@npm//:jasmine",
"@npm//:typescript",
"@npm//jasmine",
"@npm//typescript",
],
)

Expand Down
29 changes: 20 additions & 9 deletions internal/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ load("@build_bazel_rules_nodejs//internal/common:node_module_info.bzl", "NodeMod

_DEFAULT_COMPILER = "@build_bazel_rules_typescript//:@bazel/typescript/tsc_wrapped"

def _trim_package_node_modules(package_name):
# trim a package name down to its path prior to a node_modules
# segment. 'foo/node_modules/bar' would become 'foo' and
# 'node_modules/bar' would become ''
segments = []
for n in package_name.split("/"):
if n == "node_modules":
break
segments += [n]
return "/".join(segments)

def _compute_node_modules_root(ctx):
"""Computes the node_modules root from the node_modules and deps attributes.

Expand All @@ -37,7 +48,7 @@ def _compute_node_modules_root(ctx):
# ctx.files.node_modules is not an empty list
node_modules_root = "/".join([f for f in [
ctx.attr.node_modules.label.workspace_root,
ctx.attr.node_modules.label.package,
_trim_package_node_modules(ctx.attr.node_modules.label.package),
"node_modules",
] if f])
for d in ctx.attr.deps:
Expand Down Expand Up @@ -257,7 +268,7 @@ ts_library = rule(
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`
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
Expand All @@ -282,13 +293,13 @@ ts_library = rule(
"node_modules": attr.label(
doc = """The npm packages which should be available during the compile.

The default value is `@npm//:typescript__typings` is setup
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__typings`.
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
Expand All @@ -314,10 +325,10 @@ ts_library = rule(
name = "my_lib",
...
deps = [
"@npm//:@types/foo",
"@npm//:@types/bar",
"@npm//:foo",
"@npm//:bar",
"@npm//@types/foo",
"@npm//@types/bar",
"@npm//foo",
"@npm//bar",
...
],
)
Expand All @@ -340,7 +351,7 @@ ts_library = rule(
yarn_lock = "//:yarn.lock",
)
""",
default = Label("@npm//:typescript__typings"),
default = Label("@npm//typescript:typescript__typings"),
),
}),
outputs = {
Expand Down
2 changes: 1 addition & 1 deletion internal/devserver/ts_devserver.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ ts_devserver = rule(
doc = """The port that the devserver will listen on.""",
default = 5432,
),
"_requirejs_script": attr.label(allow_single_file = True, default = Label("@build_bazel_rules_typescript_devserver_deps//:node_modules/requirejs/require.js")),
"_requirejs_script": attr.label(allow_single_file = True, default = Label("@build_bazel_rules_typescript_devserver_deps//node_modules/requirejs:require.js")),
"_devserver": attr.label(
default = Label("//devserver"),
executable = True,
Expand Down
Loading