fix(deps): normalize audited peers to the exact runtime

This commit is contained in:
Gergő Magyar 2026-10-10 15:00:48 +03:00 • committed by GitHub
parent 7a418580a9
commit 201a868e6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,6 @@
#!/usr/bin/env node
/**
* Prepare the tested native parser bundle for npm pack/publish.
* Prepare the tested native parser dependencies for installation and publication.
*
* A dependency's npm overrides do not apply in a consumer project. Several
* ABI-compatible grammars still advertise older runtime peers, so bundling
@ -11,6 +11,7 @@ const fs = require('node:fs');
const path = require('node:path');
const RUNTIME = '0.25.1';
// Upstream metadata is an input to validate, never the peer range we ship.
const AUDITED_PEERS = new Map([
['tree-sitter-c@0.23.6', '^0.22.1'],
['tree-sitter-cpp@0.23.4', '^0.21.1'],
@ -60,11 +61,13 @@ function prepareTreeSitterBundle(packageRoot = path.resolve(__dirname, '..')) {
const pkg = readJson(file);
const original = AUDITED_PEERS.get(`${pkg.name}@${pkg.version}`);
if (original) {
const peer = `${original} || ${RUNTIME}`;
if (![original, peer].includes(pkg.peerDependencies?.['tree-sitter'])) {
// Also accept bundles prepared before peers were pinned exactly, so
// an existing checkout can migrate through ordinary npm install.
const accepted = [original, `${original} || ${RUNTIME}`, RUNTIME];
if (!accepted.includes(pkg.peerDependencies?.['tree-sitter'])) {
throw new Error(`Unexpected tree-sitter peer metadata for ${pkg.name}@${pkg.version}`);
}
pkg.peerDependencies['tree-sitter'] = peer;
pkg.peerDependencies['tree-sitter'] = RUNTIME;
patches.push({ file, pkg });
}
}