#!/usr/bin/env node const fs = require('fs'); const path = require('path'); // Polyfill File if missing (Node 18) if (typeof File === 'undefined') { const { Blob } = require('buffer'); class File extends Blob { constructor(fileBits, fileName, options) { super(fileBits, options); this.name = fileName; this.lastModified = options?.lastModified || Date.now(); } } global.File = File; } // Try to find node_modules in runfiles // We traverse up to find the root of the workspace/runfiles let current = __dirname; let nodeModulesPath = null; // Safety break after 10 levels for (let i = 0; i < 10; i++) { const candidate = path.join(current, 'node_modules'); if (fs.existsSync(candidate)) { nodeModulesPath = candidate; break; } const parent = path.dirname(current); if (parent === current) break; current = parent; } if (nodeModulesPath) { // Add to module.paths to allow require() to find modules there module.paths.push(nodeModulesPath); // Also set NODE_PATH env var for subprocesses process.env.NODE_PATH = (process.env.NODE_PATH || '') + path.delimiter + nodeModulesPath; } require('@vscode/vsce/vsce');