|
| 1 | +/** |
| 2 | + * Vendor @napi-rs/keyring into dist/node_modules/ for VSIX packaging. |
| 3 | + * |
| 4 | + * pnpm uses symlinks that vsce can't follow. This script resolves them and |
| 5 | + * copies the JS wrapper plus macOS/Windows .node binaries into dist/, where |
| 6 | + * Node's require() resolution finds them from dist/extension.js. |
| 7 | + */ |
| 8 | +import { |
| 9 | + cpSync, |
| 10 | + existsSync, |
| 11 | + mkdirSync, |
| 12 | + readdirSync, |
| 13 | + realpathSync, |
| 14 | + rmSync, |
| 15 | +} from "node:fs"; |
| 16 | +import { join, resolve } from "node:path"; |
| 17 | + |
| 18 | +const keyringPkg = resolve("node_modules/@napi-rs/keyring"); |
| 19 | +const outputDir = resolve("dist/node_modules/@napi-rs/keyring"); |
| 20 | + |
| 21 | +if (!existsSync(keyringPkg)) { |
| 22 | + console.error("@napi-rs/keyring not found — run pnpm install first"); |
| 23 | + process.exit(1); |
| 24 | +} |
| 25 | + |
| 26 | +// Copy the JS wrapper package (resolving pnpm symlinks) |
| 27 | +const resolvedPkg = realpathSync(keyringPkg); |
| 28 | +rmSync(outputDir, { recursive: true, force: true }); |
| 29 | +mkdirSync(outputDir, { recursive: true }); |
| 30 | +cpSync(resolvedPkg, outputDir, { recursive: true }); |
| 31 | + |
| 32 | +// Native binary packages live as siblings of the resolved keyring package in |
| 33 | +// pnpm's content-addressable store (they aren't hoisted to node_modules). |
| 34 | +const siblingsDir = resolve(resolvedPkg, ".."); |
| 35 | +const nativePackages = [ |
| 36 | + "keyring-darwin-arm64", |
| 37 | + "keyring-darwin-x64", |
| 38 | + "keyring-win32-arm64-msvc", |
| 39 | + "keyring-win32-x64-msvc", |
| 40 | +]; |
| 41 | + |
| 42 | +for (const pkg of nativePackages) { |
| 43 | + const pkgDir = join(siblingsDir, pkg); |
| 44 | + if (!existsSync(pkgDir)) { |
| 45 | + console.error( |
| 46 | + `Missing native package: ${pkg}\n` + |
| 47 | + "Ensure supportedArchitectures in pnpm-workspace.yaml includes all target platforms.", |
| 48 | + ); |
| 49 | + process.exit(1); |
| 50 | + } |
| 51 | + const nodeFile = readdirSync(pkgDir).find((f) => f.endsWith(".node")); |
| 52 | + if (!nodeFile) { |
| 53 | + console.error(`No .node binary found in ${pkg}`); |
| 54 | + process.exit(1); |
| 55 | + } |
| 56 | + cpSync(join(pkgDir, nodeFile), join(outputDir, nodeFile)); |
| 57 | +} |
| 58 | + |
| 59 | +console.log( |
| 60 | + `Vendored @napi-rs/keyring with ${nativePackages.length} platform binaries into dist/`, |
| 61 | +); |
0 commit comments