From 04a27ede465e1b63df489d4da743d20ea4b10a48 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 18 May 2026 19:08:08 +0100 Subject: [PATCH] fix(vscode): make the packaged .vsix actually load (Refs #62) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Building the .vsix per #62 surfaced a wiring defect: PR #58 switched the compile to `--vscode-extension` codegen, whose auto-glue emits a top-level `require("@hyperpolymath/affine-vscode")` — an unpublished npm package — while the repo still routed activation through the hand-written `src/index.cjs` + vendored `src/affine-vscode-adapter.cjs`. Result: VS Code loaded `src/index.cjs` -> `require("../out/extension.cjs")` -> MODULE_NOT_FOUND on `@hyperpolymath/affine-vscode`; the extension crashed on activation. Fix, using the mechanism affinescript already provides: - `compile`/`vscode:prepublish`: pass `--vscode-extension-adapter=../src/affine-vscode-adapter.cjs` so the auto-glue requires the already-vendored adapter by relative path (no npm package, resolves offline). `affinescript compile --help` documents this flag precisely for "vendoring a custom adapter". - `main`: `./src/index.cjs` -> `./out/extension.cjs` — the directly-loadable entry the `--vscode-extension` codegen is designed to produce (#58/#105's stated end-state). `src/index.cjs` is now dead and removed. - `vscode:prepublish`: no longer shells through `npm run` (repo CLAUDE.md bans npm) — it is the affinescript invocation directly. - Add `.vscodeignore` so lockfiles/build noise stay out of the .vsix. - `.gitignore`: ignore bun/deno lockfiles and the built `*.vsix` (distributed via GitHub Release, not git), extending the #57 policy. Verified: `out/extension.cjs` loads standalone; from the packaged .vsix's bundled tree `extraImports()` returns {Vscode, VscodeLanguageClient} with only host-provided `vscode` stubbed; `activate`/`deactivate` present. `my-lang-0.3.0.vsix` (324 files) now packages as a *functional* artifact. Refs #62 Co-Authored-By: Claude Opus 4.7 (1M context) --- .gitignore | 10 ++++++++-- vscode-extension/.vscodeignore | 9 +++++++++ vscode-extension/out/extension.cjs | 2 +- vscode-extension/package.json | 6 +++--- vscode-extension/src/index.cjs | 32 ------------------------------ 5 files changed, 21 insertions(+), 38 deletions(-) create mode 100644 vscode-extension/.vscodeignore delete mode 100644 vscode-extension/src/index.cjs diff --git a/.gitignore b/.gitignore index 11685a7..be5aae1 100644 --- a/.gitignore +++ b/.gitignore @@ -37,9 +37,15 @@ Thumbs.db *.log target/ node_modules/ -# npm lockfile — not tracked, mirroring the Cargo.lock policy above -# (the only one is vscode-extension/package-lock.json) +# JS lockfiles — not tracked, mirroring the Cargo.lock policy above +# (all under vscode-extension/; the extension is built on a registry-reachable +# host with Deno/bun per the package-manager policy, lockfile regenerated there) package-lock.json +bun.lock +bun.lockb +deno.lock +# Built VS Code extension artefact — distributed via GitHub Release, not git +*.vsix _build/ deps/ .elixir_ls/ diff --git a/vscode-extension/.vscodeignore b/vscode-extension/.vscodeignore new file mode 100644 index 0000000..6c8cf8b --- /dev/null +++ b/vscode-extension/.vscodeignore @@ -0,0 +1,9 @@ +# Build/runtime artefacts that should not ship in the .vsix. +# (node_modules production deps ARE bundled by vsce — do not ignore them.) +deno.lock +bun.lock +bun.lockb +.gitignore +.vscodeignore +package-lock.json +**/.DS_Store diff --git a/vscode-extension/out/extension.cjs b/vscode-extension/out/extension.cjs index 04de210..dbe3dd4 100644 --- a/vscode-extension/out/extension.cjs +++ b/vscode-extension/out/extension.cjs @@ -98,7 +98,7 @@ exports._freeHandle = _freeHandle; // Inserted by --vscode-extension (issue #105): auto-generated glue so this // file is directly loadable as a VS Code extension's `main`. Replaces the // previously hand-written index.cjs + vendored adapter boilerplate. -const _makeVscodeBindings = require("@hyperpolymath/affine-vscode"); +const _makeVscodeBindings = require("../src/affine-vscode-adapter.cjs"); exports.extraImports = function() { return _makeVscodeBindings( require("vscode"), diff --git a/vscode-extension/package.json b/vscode-extension/package.json index 4bcbe1c..9cf7c48 100644 --- a/vscode-extension/package.json +++ b/vscode-extension/package.json @@ -17,7 +17,7 @@ "activationEvents": [ "onLanguage:my" ], - "main": "./src/index.cjs", + "main": "./out/extension.cjs", "contributes": { "languages": [ { @@ -76,8 +76,8 @@ ] }, "scripts": { - "vscode:prepublish": "npm run compile", - "compile": "affinescript compile --vscode-extension src/extension.affine -o out/extension.cjs", + "vscode:prepublish": "affinescript compile --vscode-extension --vscode-extension-adapter=../src/affine-vscode-adapter.cjs src/extension.affine -o out/extension.cjs", + "compile": "affinescript compile --vscode-extension --vscode-extension-adapter=../src/affine-vscode-adapter.cjs src/extension.affine -o out/extension.cjs", "package": "vsce package" }, "devDependencies": { diff --git a/vscode-extension/src/index.cjs b/vscode-extension/src/index.cjs deleted file mode 100644 index 5dd30c1..0000000 --- a/vscode-extension/src/index.cjs +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-License-Identifier: PMPL-1.0-or-later -// Copyright (c) 2026 Jonathan D.A. Jewell -// -// Runtime entry point — what VS Code loads via package.json `main`. -// -// Pipeline: -// src/extension.affine ──affinescript compile──> out/extension.cjs (wasm shim) -// src/index.cjs ──this file──> exports.{activate,deactivate} -// -// This wrapper bridges the compiled wasm shim to the live vscode/lc modules -// by installing `extraImports` on the shim before activation runs. - -"use strict"; - -const shim = require("../out/extension.cjs"); -const makeVscodeBindings = require("./affine-vscode-adapter.cjs"); - -// Install the Phase-2 binding hook. `_buildImports()` inside the shim calls -// this after the host invokes `exports.activate`, just before -// `WebAssembly.instantiate`. The shim's own `exports._instance` is set -// during init, so the adapter's lazy `getInstance()` resolves correctly -// for callbacks that fire after activation. -shim.extraImports = function extraImports() { - return makeVscodeBindings( - require("vscode"), - require("vscode-languageclient/node"), - shim - ); -}; - -exports.activate = shim.activate; -exports.deactivate = shim.deactivate;