Skip to content

Commit c1143e8

Browse files
committed
feat(vscode): switch vsix build to bazel aspects
v0.1.57 CMK-33447 Replace the vsix genrule with proper aspect_rules_js rules: - js_binary + js_run_binary wrapping esbuild.js for the bundle - copy_to_directory to stage only VSIX-bound files (keeps sandbox artifacts out of the package) - vsce_bin.vsce from the pnpm workspace to produce the VSIX - --allow-package-all-secrets / --allow-package-env-file to skip secretlint (rules aren't findable through the pnpm layout) esbuild's native ELF bin can't be invoked through aspect_rules_js's bin macro, so we keep esbuild.js as a tiny JS driver. Change-Id: Ia7d9dcf8075ccf3727164a8bd8316c85edd8d559
1 parent d69b6df commit c1143e8

2 files changed

Lines changed: 47 additions & 35 deletions

File tree

.ide/vscode/BUILD

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
load("@aspect_rules_js//js:defs.bzl", "js_library")
1+
load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
2+
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_library", "js_run_binary")
23
load("@npm//:defs.bzl", "npm_link_all_packages")
34
load("@npm//:vitest/package_json.bzl", vitest_bin = "bin")
5+
load("@npm//.ide/vscode:@vscode/vsce/package_json.bzl", vsce_bin = "bin")
46
load("@rules_python//python:defs.bzl", "py_binary")
57

68
npm_link_all_packages(name = "node_modules")
@@ -47,46 +49,56 @@ py_binary(
4749
srcs = ["scripts/generate_changelog.py"],
4850
)
4951

50-
genrule(
51-
name = "vsix",
52-
srcs = glob(
52+
js_binary(
53+
name = "esbuild_bundler",
54+
data = [":node_modules/esbuild"],
55+
entry_point = "esbuild.js",
56+
)
57+
58+
js_run_binary(
59+
name = "bundle",
60+
srcs = [":src_ts"],
61+
chdir = package_name(),
62+
out_dirs = ["out"],
63+
tool = ":esbuild_bundler",
64+
)
65+
66+
copy_to_directory(
67+
name = "vsix_staging",
68+
srcs = [
69+
".vscodeignore",
70+
"CLAUDE.md",
71+
"README.md",
72+
"icon.png",
73+
"icon.svg",
74+
"package.json",
75+
":bundle",
76+
] + glob(
5377
[
54-
"src/**",
5578
"config/**",
56-
"icons/**",
5779
"docs/**",
80+
"icons/**",
5881
"scripts/**",
5982
"changelog/**",
6083
],
6184
allow_empty = True,
62-
exclude = [
63-
"node_modules/**",
64-
"out/**",
65-
"*.vsix",
66-
],
67-
) + [
68-
"package.json",
69-
"tsconfig.json",
70-
"esbuild.js",
71-
".vscodeignore",
72-
"CLAUDE.md",
73-
"README.md",
74-
"icon.png",
75-
"icon.svg",
76-
],
85+
),
86+
root_paths = [package_name()],
87+
)
88+
89+
vsce_bin.vsce(
90+
name = "vsix",
91+
srcs = [":vsix_staging"],
7792
outs = ["cmk-vscode.vsix"],
78-
cmd = """
79-
ROOT=$$PWD
80-
EXT_DIR=$$(dirname $(location package.json))
81-
cd "$$EXT_DIR"
82-
node esbuild.js
83-
npx @vscode/vsce package --no-dependencies -o cmk-vscode.vsix 2>&1
84-
mkdir -p $$(dirname "$$ROOT/$@")
85-
cp cmk-vscode.vsix "$$ROOT/$@"
86-
""",
87-
local = True,
88-
tags = [
89-
"manual",
90-
"no-remote",
93+
args = [
94+
"package",
95+
"--no-dependencies",
96+
# Skip secretlint scan — it can't resolve its rules from the pnpm
97+
# node_modules layout. The extension source is public anyway.
98+
"--allow-package-all-secrets",
99+
"--allow-package-env-file",
100+
"-o",
101+
"../cmk-vscode.vsix",
91102
],
103+
chdir = package_name() + "/vsix_staging",
92104
)

.ide/vscode/CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Always run both steps together. Never skip the install step.
4949

5050
- **TypeScript** (`tsconfig.json`): Target ES2022, strict mode, CommonJS output to `out/`
5151
- **esbuild** (`esbuild.js`): Bundles `src/extension.ts``out/extension.js`, CSS imported as text via `loader: { '.css': 'text' }`, `vscode` marked external
52-
- **Bazel** (`BUILD`): genrule runs `npm ci``node esbuild.js``npx @vscode/vsce package`
52+
- **Bazel** (`BUILD`): `js_run_binary` runs `esbuild.js` (bundles to `out/extension.js`), then `vsce_bin.vsce` packages a staged copy into `cmk-vscode.vsix`. Deps come from the root pnpm workspace; no `npm ci` at build time.
5353
- **CSS type declarations**: `src/css.d.ts` allows `import css from './style.css'` as string
5454

5555
### Entry Point (`src/extension.ts`)

0 commit comments

Comments
 (0)