Skip to content
Merged
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
35 changes: 34 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,37 @@ kotlin_repositories()

load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")

kt_register_toolchains()
kt_register_toolchains()

http_archive(
name = "aspect_rules_ts",
sha256 = "1149d4cf7f210de67e0fc5cd3e8f624de3ee976ac05af4f1484e57a74c12f2dc",
strip_prefix = "rules_ts-1.0.0-rc5",
url = "https://github.com/aspect-build/rules_ts/archive/refs/tags/v1.0.0-rc5.tar.gz",
)

load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")

rules_ts_dependencies(ts_version_from = "//typescript:package.json")

load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
name = "node",
node_version = DEFAULT_NODE_VERSION,
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")

npm_translate_lock(
name = "npm",
pnpm_lock = "//typescript:pnpm-lock.yaml",
)

load("@npm//:repositories.bzl", "npm_repositories")

npm_repositories()
22 changes: 22 additions & 0 deletions typescript/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@npm//:defs.bzl", "npm_link_all_packages")

npm_link_all_packages(name = "node_modules")

ts_project(
name = "typescript",
srcs = ["main.ts"],
declaration = True,
out_dir = ".",
deps = [
"//typescript:node_modules/@types/node",
],
)

build_test(
name = "typesctript_test",
targets = [
":typescript",
],
)
4 changes: 4 additions & 0 deletions typescript/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const hello: String = "Hello ";
export const world: String = "World "

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: semicolons after each line (ideally this would pass our linter tests which are not configured for this package)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.


console.log(hello, world)
7 changes: 7 additions & 0 deletions typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know nothing about typescript: do we need to track external dependencies like this though? For other languages, you can do most things through BUILD or WORKSPACE files, so I'm surprised we need these.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the documentation, we need those files as bazel builds entire projects. I have checked it works as it translated the code into a .js file in bazel-bin and when you execute it show hello world. I think we will improve this an all other examples for a most robust testing. This json file and more will increase in its dependency tree. Anyways, I will wait today, maybe we will have more comments from Will and Sara.

Just for your information, these are the rules I am using: https://github.com/aspect-build/rules_ts

"private": true,
"dependencies": {
"@types/node": "18.6.1",
"typescript": "4.8.2"
}
}
21 changes: 21 additions & 0 deletions typescript/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"declaration": true,
"baseUrl": ".",
"types": ["node"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this type? We generally aren't transpiling for Node.js (for the browser instead)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really have a requirement here. I just added typescript support with rules_ts and to execute a simple example. I think, however, that line 5 is not necessary. I will remove it.

}
}