"use strict"; /** * Supply a stub `vscode` host so extension sources can be unit tested. * * These files run under `node --test` (see the package's test script), where * patching `Module._load` is enough. A bare `bun test` from the repository * root also picks them up by filename, and Bun resolves `require` through its * own resolver without consulting `Module._load` -- so under Bun the same * files failed with "Cannot find package 'vscode'". Registering a virtual * module covers that case, leaving one shim that works under both runners. * * Returns a function restoring the original loader. */ function installVsCodeHost(stub) { const Module = require("node:module"); if (typeof Bun !== "undefined") { require("bun").plugin({ name: "vscode-host-stub", setup(build) { build.module("vscode", () => ({ exports: stub, loader: "object" })); }, }); return () => {}; } const originalLoad = Module._load; Module._load = function load(request, parent, isMain) { if (request === "vscode") return stub; return originalLoad.call(this, request, parent, isMain); }; return () => { Module._load = originalLoad; }; } module.exports = { installVsCodeHost };