summaryrefslogtreecommitdiff
path: root/ts/BUILD.bazel
blob: 4b86fe3d3cec395610b02e2b02e5b6a00f8963fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load("@aspect_rules_js//npm:defs.bzl", "npm_package")

filegroup(
    name = "distribution",
    srcs = [
        "BUILD.bazel",
        "compile_flat_file.sh",
    ] + glob([
        "*.ts",
    ]),
    visibility = ["//visibility:public"],
)

# Add an index to emulate the top-level package.json's "main" entry.
genrule(
    name = "generate_index.ts",
    outs = ["index.ts"],
    cmd = """echo "export * from './flatbuffers.js'" > $(OUTS)""",
)

ts_project(
    name = "flatbuffers_ts",
    srcs = [
        "builder.ts",
        "byte-buffer.ts",
        "constants.ts",
        "encoding.ts",
        "flatbuffers.ts",
        "types.ts",
        "utils.ts",
        ":index.ts",
    ],
    declaration = True,
    tsconfig = {
        "compilerOptions": {
            "module": "commonjs",
            "declaration": True,
            "moduleResolution": "node",
            "lib": [
                "ES2015",
                "ES2020.BigInt",
                "DOM",
            ],
            "types": ["node"],
            "strict": True,
        },
    },
    visibility = ["//visibility:public"],
    deps = [
        # Because the main repository instantiates the @npm repository, we need
        # to depend on the main repository's node import.
        "@//:node_modules/@types/node",
    ],
)

npm_package(
    name = "flatbuffers",
    srcs = [":flatbuffers_ts"],
    include_external_repositories = ["*"],
    package = "flatbuffers",
    visibility = ["//visibility:public"],
)

sh_binary(
    name = "compile_flat_file",
    srcs = ["compile_flat_file.sh"],
    data = [
        "@com_github_google_flatbuffers//:flatc",
        "@nodejs_linux_amd64//:node_bin",
    ],
    # We just depend directly on the linux amd64 nodejs binary, so only support
    # running this script on amd64 for now.
    target_compatible_with = [
        "@platforms//cpu:x86_64",
        "@platforms//os:linux",
    ],
    visibility = ["//visibility:public"],
    deps = ["@bazel_tools//tools/bash/runfiles"],
)