Skip to content

Commit d19e358

Browse files
committed
WIP moving to Bazel
1 parent 8cdf3cd commit d19e358

14 files changed

+746
-14399
lines changed

.bazeliskrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BAZELISK_BASE_URL=https://github.com/aspect-build/aspect-cli/releases/download
2+
USE_BAZEL_VERSION=aspect/2025.11.0

.bazelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
common --@aspect_rules_ts//ts:skipLibCheck=honor_tsconfig
2+
3+
# Use "tsc" as the transpiler when ts_project has no `transpiler` set.
4+
# Bazel 6.4 or greater: 'common' means 'any command that supports this flag'
5+
common --@aspect_rules_ts//ts:default_to_tsc_transpiler

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8.2.1

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ node_modules/
88
npm-debug.log
99
yarn-error.log
1010

11+
# Bazel output directories
12+
bazel-*
13+
1114
# Note: /dist/Autolinker.js and /dist/Autolinker.min.js are not gitignored to
1215
# allow for Bower
1316
/dist/commonjs

.npmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

BUILD.bazel

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
load("@npm//:defs.bzl", "npm_link_all_packages")
2+
load("@aspect_rules_esbuild//esbuild:defs.bzl", "esbuild")
3+
load("@aspect_rules_js//js:defs.bzl", "js_library")
4+
load("@aspect_rules_js//npm:defs.bzl", "npm_package")
5+
load("@aspect_rules_ts//ts:defs.bzl", "ts_project", "ts_config")
6+
load("@bazel_skylib//rules:write_file.bzl", "write_file")
7+
8+
npm_link_all_packages(name = "node_modules")
9+
10+
src_files = glob(["src/**/*.ts"])
11+
12+
npm_package(
13+
name = "package",
14+
package = "autolinker",
15+
srcs = [
16+
":library"
17+
] + src_files, # include the src files for source maps to reference
18+
)
19+
20+
js_library(
21+
name = "library",
22+
srcs = [
23+
":src_esm",
24+
":src_cjs",
25+
],
26+
deps = [
27+
":esm_declarations",
28+
":cjs_declarations",
29+
]
30+
)
31+
32+
esbuild(
33+
name = "src_esm",
34+
entry_point = "src/index.ts",
35+
srcs = src_files,
36+
output = "esm/index.mjs",
37+
sourcemap = "linked",
38+
format = "esm",
39+
target = "es2022",
40+
platform = "node",
41+
tsconfig = ":tsconfig",
42+
)
43+
44+
esbuild(
45+
name = "src_cjs",
46+
entry_point = "src/index.ts",
47+
srcs = src_files,
48+
output = "cjs/index.cjs",
49+
sourcemap = "linked",
50+
format = "cjs",
51+
target = "es2022",
52+
platform = "node",
53+
tsconfig = ":tsconfig",
54+
)
55+
56+
ts_project(
57+
name = "esm_declarations",
58+
srcs = src_files,
59+
root_dir = "src",
60+
out_dir = "esm",
61+
source_map = True,
62+
emit_declaration_only = True,
63+
declaration = True,
64+
declaration_map = True,
65+
tsconfig = ":tsconfig_esm",
66+
)
67+
68+
ts_config(
69+
name = "tsconfig_esm",
70+
src = "tsconfig-esm.json",
71+
deps = ["tsconfig.json"],
72+
)
73+
74+
write_file(
75+
name = "tsconfig_esm_file",
76+
out = "tsconfig-esm.json",
77+
content = ["""
78+
{
79+
"extends": "./tsconfig.json",
80+
"compilerOptions": {
81+
"target": "esnext",
82+
"module": "esnext",
83+
"noEmit": false
84+
}
85+
}
86+
"""]
87+
)
88+
89+
ts_project(
90+
name = "cjs_declarations",
91+
srcs = src_files,
92+
root_dir = "src",
93+
out_dir = "cjs",
94+
source_map = True,
95+
emit_declaration_only = True,
96+
declaration = True,
97+
declaration_map = True,
98+
tsconfig = ":tsconfig_cjs",
99+
)
100+
101+
ts_config(
102+
name = "tsconfig_cjs",
103+
src = "tsconfig-cjs.json",
104+
deps = ["tsconfig.json"],
105+
)
106+
107+
write_file(
108+
name = "tsconfig_cjs_file",
109+
out = "tsconfig-cjs.json",
110+
content = ["""
111+
{
112+
"extends": "./tsconfig.json",
113+
"compilerOptions": {
114+
"target": "esnext",
115+
"module": "commonjs",
116+
"noEmit": false
117+
}
118+
}
119+
"""]
120+
)
121+
122+
ts_config(
123+
name = "tsconfig",
124+
src = "tsconfig.json",
125+
visibility = [":__subpackages__"],
126+
)

MODULE.bazel

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# rules_js
2+
bazel_dep(name = "aspect_rules_js", version = "2.3.7")
3+
bazel_dep(name = "rules_nodejs", version = "6.3.5")
4+
5+
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node", dev_dependency = True)
6+
node.toolchain(node_version = "22.14.0")
7+
8+
npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
9+
npm.npm_translate_lock(
10+
name = "npm",
11+
pnpm_lock = "//:pnpm-lock.yaml",
12+
)
13+
use_repo(npm, "npm")
14+
15+
pnpm = use_extension("@aspect_rules_js//npm:extensions.bzl", "pnpm")
16+
# Allows developers to use the matching pnpm version, for example:
17+
# bazel run -- @pnpm --dir /home/runner/work/rules_js/rules_js install
18+
use_repo(pnpm, "pnpm")
19+
20+
# rules_ts
21+
bazel_dep(name = "aspect_rules_ts", version = "3.5.3")
22+
23+
rules_ts_ext = use_extension("@aspect_rules_ts//ts:extensions.bzl", "ext", dev_dependency = True)
24+
rules_ts_ext.deps(
25+
ts_version_from = "//:package.json",
26+
)
27+
28+
use_repo(rules_ts_ext, "npm_typescript")
29+
30+
# rules_esbuild
31+
bazel_dep(name = "aspect_rules_esbuild", version = "0.22.1")
32+
33+
# bazel_skylib
34+
bazel_dep(name = "bazel_skylib", version = "1.7.1")

0 commit comments

Comments
 (0)