Skip to content

Commit

Permalink
refactor: convert from_source example to ts_project
Browse files Browse the repository at this point in the history
We no longer recommend ts_library so we shouldn't use it in examples
  • Loading branch information
alexeagle committed May 29, 2021
1 parent 66769c7 commit fc880a3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ example_integration_test(

example_integration_test(
name = "examples_cypress",
bazel_commands = ["test --sandbox_debug //..."],
npm_packages = {
"//packages/cypress:npm_package": "@bazel/cypress",
"//packages/typescript:npm_package": "@bazel/typescript",
Expand Down
8 changes: 4 additions & 4 deletions examples/from_source/BUILD
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test", "nodejs_binary", "npm_package_bin")
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
load("//:index.bzl", "custom_ts_library")
load("//:index.bzl", "custom_ts_project")

# thin macro around ts_library that sets some implicit dependencies
# thin macro around ts_project that sets some implicit dependencies
# while passing though all other attributes
# is used here to show how to generate stardoc for rules that consume rules_nodejs from source
custom_ts_library(
custom_ts_project(
name = "main",
srcs = ["main.ts"],
)
Expand All @@ -30,7 +30,7 @@ bzl_library(
],
)

# generation of the docs for the custom_ts_library macro used above
# generation of the docs for the custom_ts_project macro used above
stardoc(
name = "docs",
out = "docs.md",
Expand Down
12 changes: 7 additions & 5 deletions examples/from_source/index.bzl
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
"""Example package for generating stardoc from rules_nodejs at source"""

load("@build_bazel_rules_nodejs//packages/typescript:index.bzl", "ts_library")
load("@build_bazel_rules_nodejs//packages/typescript:index.bzl", "ts_project")

def custom_ts_library(name, deps = [], **kwargs):
def custom_ts_project(name, deps = [], **kwargs):
"""
Helper wrapper around ts_library adding default attributes and dependencies
Helper wrapper around ts_project adding default attributes and dependencies
Args:
name: The name that should be given the this rule
deps: A list of dependencies for this rule
kwargs: All other attrs are passed to ts_library
kwargs: All other attrs are passed to ts_project
"""

ts_library(
ts_project(
name = name,
tsconfig = "tsconfig.json",
deps = [
"@npm//tsutils",
"@npm//@types/node",
] + deps,
validate = False,
**kwargs
)
3 changes: 2 additions & 1 deletion examples/from_source/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"lib": [
"ES2017"
"ES2017",
"dom"
],
"types": []
}
Expand Down

0 comments on commit fc880a3

Please sign in to comment.