mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-10-07 02:58:02 +00:00
chore: upgrade tree-sitter to 0.25.0 and all grammar packages (#516)
This commit is contained in:
parent
e7e26d6345
commit
77dcb06a8d
3 changed files with 1180 additions and 1264 deletions
2343
gitnexus/package-lock.json
generated
2343
gitnexus/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -46,7 +46,6 @@
|
||||||
"test:watch": "vitest",
|
"test:watch": "vitest",
|
||||||
"test:coverage": "vitest run --coverage",
|
"test:coverage": "vitest run --coverage",
|
||||||
"prepare": "npm run build",
|
"prepare": "npm run build",
|
||||||
"postinstall": "node scripts/patch-tree-sitter-swift.cjs",
|
|
||||||
"prepack": "npm run build && chmod +x dist/cli/index.js"
|
"prepack": "npm run build && chmod +x dist/cli/index.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
@ -66,18 +65,18 @@
|
||||||
"mnemonist": "^0.39.0",
|
"mnemonist": "^0.39.0",
|
||||||
"onnxruntime-node": "^1.24.0",
|
"onnxruntime-node": "^1.24.0",
|
||||||
"pandemonium": "^2.4.0",
|
"pandemonium": "^2.4.0",
|
||||||
"tree-sitter": "0.22.4",
|
"tree-sitter": "^0.25.0",
|
||||||
"tree-sitter-c": "^0.21.0",
|
"tree-sitter-c": "^0.24.1",
|
||||||
"tree-sitter-c-sharp": "^0.21.0",
|
"tree-sitter-c-sharp": "^0.23.1",
|
||||||
"tree-sitter-cpp": "^0.22.0",
|
"tree-sitter-cpp": "^0.23.4",
|
||||||
"tree-sitter-go": "^0.21.0",
|
"tree-sitter-go": "^0.25.0",
|
||||||
"tree-sitter-java": "^0.21.0",
|
"tree-sitter-java": "^0.23.5",
|
||||||
"tree-sitter-javascript": "^0.21.0",
|
"tree-sitter-javascript": "^0.25.0",
|
||||||
"tree-sitter-php": "^0.23.12",
|
"tree-sitter-php": "^0.24.2",
|
||||||
"tree-sitter-python": "^0.21.0",
|
"tree-sitter-python": "^0.25.0",
|
||||||
"tree-sitter-ruby": "^0.23.1",
|
"tree-sitter-ruby": "^0.23.1",
|
||||||
"tree-sitter-rust": "^0.21.0",
|
"tree-sitter-rust": "^0.24.0",
|
||||||
"tree-sitter-typescript": "^0.21.0",
|
"tree-sitter-typescript": "^0.23.2",
|
||||||
"uuid": "^13.0.0"
|
"uuid": "^13.0.0"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
|
|
@ -100,7 +99,7 @@
|
||||||
"@huggingface/transformers": {
|
"@huggingface/transformers": {
|
||||||
"onnxruntime-node": "$onnxruntime-node"
|
"onnxruntime-node": "$onnxruntime-node"
|
||||||
},
|
},
|
||||||
"tree-sitter": "0.22.4"
|
"tree-sitter": "^0.25.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=20.0.0"
|
"node": ">=20.0.0"
|
||||||
|
|
|
||||||
|
|
@ -1,76 +0,0 @@
|
||||||
#!/usr/bin/env node
|
|
||||||
/**
|
|
||||||
* WORKAROUND: tree-sitter-swift@0.6.0 binding.gyp build failure
|
|
||||||
*
|
|
||||||
* Background:
|
|
||||||
* tree-sitter-swift@0.6.0's binding.gyp contains an "actions" array that
|
|
||||||
* invokes `tree-sitter generate` to regenerate parser.c from grammar.js.
|
|
||||||
* This is intended for grammar developers, but the published npm package
|
|
||||||
* already ships pre-generated parser files (parser.c, scanner.c), so the
|
|
||||||
* actions are unnecessary for consumers. Since consumers don't have
|
|
||||||
* tree-sitter-cli installed, the actions always fail during `npm install`.
|
|
||||||
*
|
|
||||||
* Why we can't just upgrade:
|
|
||||||
* tree-sitter-swift@0.7.1 fixes this (removes postinstall, ships prebuilds),
|
|
||||||
* but it requires tree-sitter@^0.22.1. The upstream project pins tree-sitter
|
|
||||||
* to ^0.21.0 and all other grammar packages depend on that version.
|
|
||||||
* Upgrading tree-sitter would be a separate breaking change.
|
|
||||||
*
|
|
||||||
* How this workaround works:
|
|
||||||
* 1. tree-sitter-swift's own postinstall fails (npm warns but continues)
|
|
||||||
* 2. This script runs as gitnexus's postinstall
|
|
||||||
* 3. It removes the "actions" array from binding.gyp
|
|
||||||
* 4. It rebuilds the native binding with the cleaned binding.gyp
|
|
||||||
*
|
|
||||||
* TODO: Remove this script when tree-sitter is upgraded to ^0.22.x,
|
|
||||||
* which allows using tree-sitter-swift@0.7.1+ directly.
|
|
||||||
*/
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
const { execSync } = require('child_process');
|
|
||||||
|
|
||||||
const swiftDir = path.join(__dirname, '..', 'node_modules', 'tree-sitter-swift');
|
|
||||||
const bindingPath = path.join(swiftDir, 'binding.gyp');
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!fs.existsSync(bindingPath)) {
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
const content = fs.readFileSync(bindingPath, 'utf8');
|
|
||||||
let needsRebuild = false;
|
|
||||||
|
|
||||||
if (content.includes('"actions"')) {
|
|
||||||
// Strip Python-style comments (#) and trailing commas before JSON parsing
|
|
||||||
const cleaned = content
|
|
||||||
.replace(/#[^\n]*/g, '') // Remove # comments
|
|
||||||
.replace(/,(\s*[\]}])/g, '$1'); // Remove trailing commas before ] or }
|
|
||||||
const gyp = JSON.parse(cleaned);
|
|
||||||
|
|
||||||
if (gyp.targets && gyp.targets[0] && gyp.targets[0].actions) {
|
|
||||||
delete gyp.targets[0].actions;
|
|
||||||
fs.writeFileSync(bindingPath, JSON.stringify(gyp, null, 2) + '\n');
|
|
||||||
console.log('[tree-sitter-swift] Patched binding.gyp (removed actions array)');
|
|
||||||
needsRebuild = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if native binding exists
|
|
||||||
const bindingNode = path.join(swiftDir, 'build', 'Release', 'tree_sitter_swift_binding.node');
|
|
||||||
if (!fs.existsSync(bindingNode)) {
|
|
||||||
needsRebuild = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (needsRebuild) {
|
|
||||||
console.log('[tree-sitter-swift] Rebuilding native binding...');
|
|
||||||
execSync('npx node-gyp rebuild', {
|
|
||||||
cwd: swiftDir,
|
|
||||||
stdio: 'pipe',
|
|
||||||
timeout: 120000,
|
|
||||||
});
|
|
||||||
console.log('[tree-sitter-swift] Native binding built successfully');
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.warn('[tree-sitter-swift] Could not build native binding:', err.message);
|
|
||||||
console.warn('[tree-sitter-swift] You may need to manually run: cd node_modules/tree-sitter-swift && npx node-gyp rebuild');
|
|
||||||
}
|
|
||||||
Loading…
Add table
Reference in a new issue