Skip to content

Commit

Permalink
test: ts_project transpiler linked with failing tsc
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Jul 26, 2024
1 parent 19de94c commit eb47b67
Show file tree
Hide file tree
Showing 18 changed files with 587 additions and 527 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ examples/node_modules
examples/proto_grpc/node_modules
examples/linked_pkg/node_modules
examples/linked_lib/node_modules
examples/lib_nocompile_linked/node_modules
examples/linked_consumer/node_modules
examples/linked_empty_node_modules/node_modules
examples/linked_tsconfig/node_modules
Expand Down
19 changes: 19 additions & 0 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@npm//:defs.bzl", "npm_link_all_packages")

# Building this target results in bazel-bin/examples/node_modules/@myorg/js_lib, so that
Expand All @@ -25,6 +26,14 @@ npm_link_package(
visibility = ["//examples:__subpackages__"],
)

npm_link_package(
name = "node_modules/@myorg/lib_nocompile",
src = "//examples/lib_nocompile:pkg",
package = "@myorg/lib_nocompile",
root_package = "examples",
visibility = ["//examples:__subpackages__"],
)

npm_link_package(
name = "node_modules/@myorg/deps_lib",
src = "//examples/deps_lib:pkg",
Expand All @@ -41,3 +50,13 @@ npm_link_package(

# This macro expands to a npm_link_package for each third-party package in package.json
npm_link_all_packages(name = "node_modules")

# Direct references to linked non-compiling js_library packages should not force typechecking
# for both `npm_link_package` and `workspace:*` linked packages.
build_test(
name = "linked_non_compiling",
targets = [
":node_modules/@myorg/lib_nocompile",
":node_modules/@myorg/lib_nocompile_linked",
],
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by protoc-gen-connect-query v1.3.1 with parameter "keep_empty_files=true,target=js+dts"
// @generated by protoc-gen-connect-query v1.4.1 with parameter "keep_empty_files=true,target=js+dts"
// @generated from file examples/connect_node/proto/eliza.proto (package connectrpc.eliza.v1, syntax proto3)
/* eslint-disable */
// @ts-nocheck
Expand Down
4 changes: 4 additions & 0 deletions examples/js_lib_pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ load("@aspect_rules_js//js:defs.bzl", "js_library")
js_library(
name = "pkg",
srcs = [
# A typescript file is required to ensure types will exist within the `JsInfo(types)`
# that can be passed along the package linking chain. Otherwise no files will be copied
# into the sandbox for type-checking (even though tsc would pass if only the .js was there).
"index.d.ts",
"index.js",
],
visibility = ["//examples:__subpackages__"],
Expand Down
2 changes: 2 additions & 0 deletions examples/js_lib_pkg/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const _default: 1
export default _default
29 changes: 29 additions & 0 deletions examples/lib_nocompile/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//examples/transpiler:babel.bzl", "babel")

js_library(
name = "pkg",
srcs = [":lib"],
visibility = ["//examples:__subpackages__"],
)

ts_project(
name = "lib",
srcs = ["index.ts"],
declaration = True, # True even though we are asserting tsc is not run
tags = ["manual"], # manual to prevent test //... from triggering
transpiler = babel,
visibility = ["//examples:__subpackages__"],
)

# Targets which should never force tsc to run
build_test(
name = "lib-no-typecheck",
targets = [
":pkg",
":lib",
"index.js",
],
)
7 changes: 7 additions & 0 deletions examples/lib_nocompile/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// INTENTIONAL typecheck error
console.log(3 + global)

// INTENTIONAL typecheck error
const B: string = 42

module.exports.B = B
7 changes: 7 additions & 0 deletions examples/lib_nocompile/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"declaration": true
},
// Workaround https://github.com/microsoft/TypeScript/issues/59036
"exclude": []
}
29 changes: 29 additions & 0 deletions examples/lib_nocompile_linked/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//examples/transpiler:babel.bzl", "babel")

js_library(
name = "pkg",
srcs = [":lib"],
visibility = ["//examples:__subpackages__"],
)

ts_project(
name = "lib",
srcs = ["index.ts"],
declaration = True, # True even though we are asserting tsc is not run
tags = ["manual"], # manual to prevent test //... from triggering
transpiler = babel,
visibility = ["//examples:__subpackages__"],
)

# Targets which should never force tsc to run
build_test(
name = "lib-no-typecheck",
targets = [
":pkg",
":lib",
"index.js",
],
)
7 changes: 7 additions & 0 deletions examples/lib_nocompile_linked/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// INTENTIONAL typecheck error
console.log(3 + global)

// INTENTIONAL typecheck error
const B: string = 42

module.exports.B = B
3 changes: 3 additions & 0 deletions examples/lib_nocompile_linked/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "@myorg/lib_nocompile_linked"
}
7 changes: 7 additions & 0 deletions examples/lib_nocompile_linked/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"declaration": true
},
// Workaround https://github.com/microsoft/TypeScript/issues/59036
"exclude": []
}
11 changes: 11 additions & 0 deletions examples/linked_consumer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ js_test(
],
entry_point = "test_pkg_deps_linked.js",
)

# References to non-compiling js_library packages should not force typechecking when
# consumed by a js_test that does not require dts type information.
js_test(
name = "pkg_no_typechecking",
data = [
":node_modules/@myorg/lib_nocompile_linked",
"//examples:node_modules/@myorg/lib_nocompile",
],
entry_point = "test_pkg_nocompile_linked.js",
)
3 changes: 2 additions & 1 deletion examples/linked_consumer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"private": true,
"dependencies": {
"@lib/test": "workspace:*",
"@lib/test2": "workspace:*"
"@lib/test2": "workspace:*",
"@myorg/lib_nocompile_linked": "workspace:*"
}
}
6 changes: 6 additions & 0 deletions examples/linked_consumer/test_pkg_nocompile_linked.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Asserts packages containing non-compiling ts

const a = require('@myorg/lib_nocompile')
const b = require('@myorg/lib_nocompile_linked')

console.log('loaded non-compiling dependencies', a, b)
3 changes: 3 additions & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"source-map-support": "^0.5.21",
"typescript": "5.5.2",
"zone.js": "0.12.0"
},
"devDependencies": {
"@myorg/lib_nocompile_linked": "workspace:*"
}
}
Loading

0 comments on commit eb47b67

Please sign in to comment.