Skip to content

Commit

Permalink
fix(typescript): update typescript dependency to 4.8.4, move to apsec…
Browse files Browse the repository at this point in the history
…t-build/rules_ts (#5495)
  • Loading branch information
jaysachs committed Jan 13, 2023
1 parent f9155bf commit 301a10a
Show file tree
Hide file tree
Showing 15 changed files with 860 additions and 2,165 deletions.
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
startup --host_jvm_args=-Dbazel.DigestFunction=SHA256

# Disable persistent workers for Typescript (#3816)
build --strategy=TypeScriptCompile=sandboxed,local
build --strategy=TsProject=remote,sandboxed,local

# Compatibility flags to avoid regressions.
common --incompatible_disallow_empty_glob
Expand Down
4 changes: 4 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ refresh_compile_commands(
# With layering_check enabled, clangd warns about missing dependencies on standard library headers.
targets = {"//kythe/cxx/...": "--config=clang-tidy"},
)

load("@npm//:defs.bzl", "npm_link_all_packages")

npm_link_all_packages(name = "node_modules")
49 changes: 45 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,51 @@ load("//:setup.bzl", "kythe_rule_repositories", "remote_java_repository")

kythe_rule_repositories()

###
# BEGIN rules_ts setup
# loads are sensitive to intervening calls, so they need to happen at the
# top-level and not in e.g. a _ts_dependencies() function.
load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")

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

load("@aspect_rules_jasmine//jasmine:dependencies.bzl", "rules_jasmine_dependencies")

# Fetch dependencies which users need as well
rules_jasmine_dependencies()

# Fetch and register node, if you haven't already
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

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

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

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

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

npm_repositories()

load("@aspect_rules_jasmine//jasmine:repositories.bzl", "jasmine_repositories")

jasmine_repositories(name = "jasmine")

load("@jasmine//:npm_repositories.bzl", jasmine_npm_repositories = "npm_repositories")

jasmine_npm_repositories()

# END rules_ts setup
###

# gazelle:repository_macro external.bzl%_go_dependencies
load("//:external.bzl", "kythe_dependencies")

Expand All @@ -21,10 +66,6 @@ load("//tools/build_rules/external_tools:external_tools_configure.bzl", "externa

external_tools_configure()

load("@npm//@bazel/labs:package.bzl", "npm_bazel_labs_dependencies")

npm_bazel_labs_dependencies()

load("@maven//:compat.bzl", "compat_repositories")

compat_repositories()
Expand Down
9 changes: 0 additions & 9 deletions external.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_regi
load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_deps")
load("@rules_rust//proto:repositories.bzl", "rust_proto_repositories")
load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")
load("@build_bazel_rules_nodejs//:index.bzl", "npm_install")
load(
"@bazelruby_rules_ruby//ruby:deps.bzl",
"rules_ruby_dependencies",
Expand Down Expand Up @@ -1196,13 +1195,6 @@ def _go_dependencies():
version = "v0.0.0-20200804184101-5ec99f83aff1",
)

def _js_dependencies():
npm_install(
name = "npm",
package_json = "@io_kythe//:package.json",
package_lock_json = "@io_kythe//:package-lock.json",
)

def _bindings():
maybe(
native.bind,
Expand Down Expand Up @@ -1275,7 +1267,6 @@ def kythe_dependencies():
_cc_dependencies()
_go_dependencies()
_java_dependencies()
_js_dependencies()

# proto_library, cc_proto_library, and java_proto_library rules implicitly
# depend on @com_google_protobuf for protoc and proto runtimes.
Expand Down
13 changes: 0 additions & 13 deletions kythe/proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_java//java:defs.bzl", "java_proto_library")
load("//:visibility.bzl", "PUBLIC_PROTO_VISIBILITY")
load(":go.bzl", "go_kythe_proto")
load("@npm//@bazel/labs:index.bzl", "ts_proto_library")
load("@rules_rust//proto:proto.bzl", "rust_proto_library")

package(default_visibility = ["//kythe:proto_visibility"])
Expand Down Expand Up @@ -74,12 +73,6 @@ java_proto_library(
deps = [":common_proto"],
)

ts_proto_library(
name = "common_ts_proto",
proto = ":common_proto",
visibility = [PUBLIC_PROTO_VISIBILITY],
)

# Public Kythe GraphStore analyzer output format
proto_library(
name = "storage_proto",
Expand Down Expand Up @@ -748,9 +741,3 @@ cc_proto_library(
":generated_message_info_proto",
],
)

ts_proto_library(
name = "generated_message_info_ts_proto",
proto = ":generated_message_info_proto",
visibility = [PUBLIC_PROTO_VISIBILITY],
)
86 changes: 53 additions & 33 deletions kythe/typescript/BUILD
Original file line number Diff line number Diff line change
@@ -1,79 +1,99 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_library")
load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")
load("@aspect_rules_jasmine//jasmine:defs.bzl", "jasmine_test")
load("@aspect_rules_js//js:defs.bzl", "js_test")

package(default_visibility = ["//kythe:default_visibility"])

ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [],
)

ts_library(
ts_project(
name = "kythe",
srcs = ["kythe.ts"],
tsconfig = ":tsconfig",
declaration = True,
source_map = True,
supports_workers = False,
)

ts_library(
ts_project(
name = "indexer",
srcs = [
"indexer.ts",
"utf8.ts",
],
tsconfig = ":tsconfig",
declaration = True,
source_map = True,
supports_workers = False,
deps = [
":kythe",
"@npm//@types/node",
"@npm//typescript",
"//:node_modules/@types/node",
"//:node_modules/typescript",
],
)

ts_library(
ts_project(
name = "test_ts",
srcs = ["test.ts"],
tsconfig = ":tsconfig",
declaration = True,
source_map = True,
supports_workers = False,
deps = [
":indexer",
":kythe",
"@npm//@types/node",
"@npm//source-map-support",
"@npm//typescript",
"//:node_modules/@types/node",
"//:node_modules/source-map",
"//:node_modules/source-map-support",
"//:node_modules/typescript",
],
)

ts_library(
ts_project(
name = "utf8_test_ts",
testonly = True,
srcs = ["utf8_test.ts"],
tsconfig = ":tsconfig",
declaration = True,
source_map = True,
supports_workers = False,
deps = [
":indexer",
"@npm//@types/jasmine",
"@npm//typescript",
"//:node_modules/@types/jasmine",
"//:node_modules/balanced-match",
"//:node_modules/brace-expansion",
"//:node_modules/fs.realpath",
"//:node_modules/glob",
"//:node_modules/inflight",
"//:node_modules/inherits",
"//:node_modules/jasmine",
"//:node_modules/jasmine-core",
"//:node_modules/jasmine-reporters",
"//:node_modules/minimatch",
"//:node_modules/once",
"//:node_modules/typescript",
"//:node_modules/wrappy",
],
)

DISABLED_TESTS = []

nodejs_test(
js_test(
name = "indexer_test",
data = [
":test_ts",
] + glob(
["testdata/**/*"],
exclude = DISABLED_TESTS,
) + [
"//kythe/go/platform/tools/entrystream",
"//kythe/cxx/verifier",
],
entry_point = ":test.ts",
# See https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
templated_args = ["--bazel_patch_module_resolver"],
entry_point = ":test.js",
)

jasmine_node_test(
jasmine_test(
name = "utf8_test",
deps = [":utf8_test_ts"],
args = ["utf8_test.js"],
chdir = package_name(),
data = [
"utf8_test.js",
":utf8_test_ts",
],
include_declarations = True,
include_npm_linked_packages = True,
include_transitive_sources = True,
log_level = "debug",
patch_node_fs = True,
)
16 changes: 9 additions & 7 deletions kythe/typescript/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@ class Visitor {
}

visitFunctionLikeDeclaration(decl: ts.FunctionLikeDeclaration) {
this.visitDecorators(decl.decorators || []);
this.visitDecorators(ts.canHaveDecorators(decl) ? ts.getDecorators(decl) : []);
const {sym, vname} = this.getSymbolAndVNameForFunctionDeclaration(decl);
if (!vname) {
todo(
Expand Down Expand Up @@ -2031,7 +2031,7 @@ class Visitor {
let paramNum = 0;
const recurseVisit =
(param: ts.ParameterDeclaration|ts.BindingElement) => {
this.visitDecorators(param.decorators || []);
this.visitDecorators(ts.canHaveDecorators(param) ? ts.getDecorators(param) : []);

switch (param.name.kind) {
case ts.SyntaxKind.Identifier:
Expand Down Expand Up @@ -2098,9 +2098,11 @@ class Visitor {
}
}

visitDecorators(decors: ReadonlyArray<ts.Decorator>) {
for (const decor of decors) {
this.visit(decor);
visitDecorators(decors: ReadonlyArray<ts.Decorator> | undefined) {
if (decors) {
for (const decor of decors) {
this.visit(decor);
}
}
}

Expand Down Expand Up @@ -2146,12 +2148,12 @@ class Visitor {
// The entire module declaration defines the created namespace.
this.emitEdge(this.newAnchor(decl), EdgeKind.DEFINES, kValue);

if (decl.decorators) this.visitDecorators(decl.decorators);
this.visitDecorators(ts.canHaveDecorators(decl) ? ts.getDecorators(decl) : []);
if (decl.body) this.visit(decl.body);
}

visitClassDeclaration(decl: ts.ClassDeclaration) {
this.visitDecorators(decl.decorators || []);
this.visitDecorators(ts.canHaveDecorators(decl) ? ts.getDecorators(decl) : []);
let kClass: VName|undefined;
if (decl.name) {
const sym = this.host.getSymbolAtLocation(decl.name);
Expand Down

0 comments on commit 301a10a

Please sign in to comment.