1load("@aspect_rules_js//npm:defs.bzl", "npm_package") 2load("@aspect_rules_ts//ts:defs.bzl", "ts_project") 3load("@flatbuffers_npm//:defs.bzl", "npm_link_all_packages") 4load("@rules_shell//shell:sh_binary.bzl", "sh_binary") 5 6filegroup( 7 name = "distribution", 8 srcs = [ 9 "BUILD.bazel", 10 "compile_flat_file.sh", 11 "pnpm-lock.yaml", 12 ] + glob([ 13 "*.ts", 14 ]), 15 visibility = ["//visibility:public"], 16) 17 18npm_link_all_packages(name = "node_modules") 19 20# Add an index to emulate the top-level package.json's "main" entry. 21genrule( 22 name = "generate_index.ts", 23 outs = ["index.ts"], 24 cmd = """echo "export * from './flatbuffers.js'" > $(OUTS)""", 25) 26 27ts_project( 28 name = "flatbuffers_ts", 29 srcs = [ 30 "builder.ts", 31 "byte-buffer.ts", 32 "constants.ts", 33 "encoding.ts", 34 "flatbuffers.ts", 35 "types.ts", 36 "utils.ts", 37 ":index.ts", 38 ], 39 declaration = True, 40 tsconfig = { 41 "compilerOptions": { 42 "module": "commonjs", 43 "declaration": True, 44 "moduleResolution": "node", 45 "lib": [ 46 "ES2015", 47 "ES2020.BigInt", 48 "DOM", 49 ], 50 "types": ["node"], 51 "strict": True, 52 }, 53 }, 54 visibility = ["//visibility:public"], 55 deps = [ 56 ":node_modules/@types/node", 57 ], 58) 59 60npm_package( 61 name = "flatbuffers", 62 srcs = [":flatbuffers_ts"], 63 include_external_repositories = ["*"], 64 package = "flatbuffers", 65 visibility = ["//visibility:public"], 66) 67 68sh_binary( 69 name = "compile_flat_file", 70 srcs = ["compile_flat_file.sh"], 71 data = [ 72 "//:flatc", 73 "@nodejs_linux_amd64//:node_bin", 74 ], 75 # We just depend directly on the linux amd64 nodejs binary, so only support 76 # running this script on amd64 for now. 77 target_compatible_with = [ 78 "@platforms//cpu:x86_64", 79 "@platforms//os:linux", 80 ], 81 visibility = ["//visibility:public"], 82 deps = ["@bazel_tools//tools/bash/runfiles"], 83) 84