@kumos/tree-sitter-parsers 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,18 +24,42 @@ console.log(metadataPath); // Path to the grammars metadata JSON
24
24
  ### Command-line usage
25
25
 
26
26
  ```bash
27
- # Get the path to the binary
28
- npx tree-sitter-parsers-path
27
+ # Get the path to the binary for your current platform
28
+ npx @kumos/tree-sitter-parsers
29
+
30
+ # Get the path for a specific platform
31
+ npx @kumos/tree-sitter-parsers --os linux --arch x64 --variant musl
32
+
33
+ # Get the metadata file path instead of binary
34
+ npx @kumos/tree-sitter-parsers --metadata
35
+
36
+ # Get macOS ARM64 binary path
37
+ npx @kumos/tree-sitter-parsers --os darwin --arch arm64
38
+
39
+ # Show help
40
+ npx @kumos/tree-sitter-parsers --help
29
41
  ```
30
42
 
43
+ #### CLI Options
44
+
45
+ - `--os <os>` - Target OS: `darwin`, `linux`, or `win32`
46
+ - `--arch <arch>` - Target architecture: `x64` or `arm64`
47
+ - `--variant <variant>` - Target variant (Linux only): `glibc` or `musl`
48
+ - `--metadata` - Return metadata JSON path instead of binary path
49
+ - `--help` - Show help message
50
+
31
51
  ### Build tools integration
32
52
 
33
53
  The binary path can be used in build scripts:
34
54
 
35
55
  ```bash
36
56
  # In a build script
37
- PARSER_LIB=$(npx tree-sitter-parsers-path)
57
+ PARSER_LIB=$(npx @kumos/tree-sitter-parsers)
38
58
  gcc myapp.c $PARSER_LIB -o myapp
59
+
60
+ # Cross-compilation example
61
+ LINUX_PARSER=$(npx @kumos/tree-sitter-parsers --os linux --arch x64)
62
+ x86_64-linux-gnu-gcc myapp.c $LINUX_PARSER -o myapp-linux
39
63
  ```
40
64
 
41
65
  ## Supported Platforms
@@ -74,8 +98,32 @@ npm run build:all
74
98
 
75
99
  # Create npm packages for distribution
76
100
  npm run create-packages
101
+
102
+ # Validate built libraries (recommended)
103
+ npm run validate
104
+
105
+ # Build and validate in one step
106
+ npm run build:validated
107
+ npm run build:all:validated
108
+ ```
109
+
110
+ ### Validation
111
+
112
+ The project includes a validation system that tests the actual linking and usage of the built libraries:
113
+
114
+ ```bash
115
+ # Validate current platform binaries
116
+ npm run validate
77
117
  ```
78
118
 
119
+ This validation:
120
+ - ✅ Tests actual Rust linking (catches MSVC/MinGW compatibility issues)
121
+ - ✅ Verifies grammar loading and function calls work correctly
122
+ - ✅ Tests basic parsing functionality
123
+ - ✅ Runs the exact same code path as consuming projects
124
+
125
+ **Important**: Always run validation before publishing or in CI pipelines to catch binary compatibility issues early.
126
+
79
127
  ## Architecture
80
128
 
81
129
  This project consists of:
@@ -1,10 +1,145 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- try {
4
- const { binaryPath } = require('../index.js');
5
- console.log(binaryPath);
6
- process.exit(0);
7
- } catch (error) {
8
- console.error(error.message);
9
- process.exit(1);
10
- }
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+
6
+ function printUsage() {
7
+ console.error('Usage: tree-sitter-parsers-path [options]');
8
+ console.error('');
9
+ console.error('Options:');
10
+ console.error(' --os <os> Target OS (darwin, linux, win32)');
11
+ console.error(' --arch <arch> Target architecture (x64, arm64)');
12
+ console.error(' --variant <variant> Target variant (glibc, musl) - Linux only');
13
+ console.error(' --metadata Return metadata file path instead of binary');
14
+ console.error(' --help Show this help message');
15
+ console.error('');
16
+ console.error('Examples:');
17
+ console.error(' # Get current platform binary');
18
+ console.error(' tree-sitter-parsers-path');
19
+ console.error('');
20
+ console.error(' # Get Linux x64 musl binary path');
21
+ console.error(' tree-sitter-parsers-path --os linux --arch x64 --variant musl');
22
+ console.error('');
23
+ console.error(' # Get macOS ARM64 metadata');
24
+ console.error(' tree-sitter-parsers-path --os darwin --arch arm64 --metadata');
25
+ }
26
+
27
+ function parseArgs() {
28
+ const args = process.argv.slice(2);
29
+ const options = {
30
+ os: null,
31
+ arch: null,
32
+ variant: null,
33
+ metadata: false,
34
+ help: false
35
+ };
36
+
37
+ for (let i = 0; i < args.length; i++) {
38
+ switch (args[i]) {
39
+ case '--os':
40
+ options.os = args[++i];
41
+ break;
42
+ case '--arch':
43
+ options.arch = args[++i];
44
+ break;
45
+ case '--variant':
46
+ options.variant = args[++i];
47
+ break;
48
+ case '--metadata':
49
+ options.metadata = true;
50
+ break;
51
+ case '--help':
52
+ case '-h':
53
+ options.help = true;
54
+ break;
55
+ }
56
+ }
57
+
58
+ return options;
59
+ }
60
+
61
+ function getBinaryName(os, arch, variant) {
62
+ // Map Node.js platform names to our binary naming convention
63
+ const osMap = {
64
+ 'darwin': 'macos',
65
+ 'linux': 'linux',
66
+ 'win32': 'windows'
67
+ };
68
+
69
+ const archMap = {
70
+ 'x64': 'x86_64',
71
+ 'arm64': 'aarch64'
72
+ };
73
+
74
+ const mappedOs = osMap[os];
75
+ const mappedArch = archMap[arch];
76
+
77
+ if (!mappedOs || !mappedArch) {
78
+ throw new Error(`Unsupported platform: ${os} ${arch}`);
79
+ }
80
+
81
+ let binaryName = `libtree-sitter-parsers-all-${mappedOs}-${mappedArch}`;
82
+
83
+ // Add variant for Linux
84
+ if (os === 'linux' && variant) {
85
+ binaryName += `-${variant}`;
86
+ } else if (os === 'linux' && !variant) {
87
+ // Default to glibc for Linux if no variant specified
88
+ binaryName += '-glibc';
89
+ }
90
+
91
+ return binaryName + '.a';
92
+ }
93
+
94
+ function getMetadataName(binaryName) {
95
+ return binaryName.replace('libtree-sitter-parsers-all-', 'grammars-').replace('.a', '.json');
96
+ }
97
+
98
+ function main() {
99
+ const options = parseArgs();
100
+
101
+ if (options.help) {
102
+ printUsage();
103
+ process.exit(0);
104
+ }
105
+
106
+ try {
107
+ // If no platform specified, use current platform
108
+ if (!options.os && !options.arch) {
109
+ const { binaryPath, metadataPath } = require('../index.js');
110
+ console.log(options.metadata ? metadataPath : binaryPath);
111
+ process.exit(0);
112
+ }
113
+
114
+ // Validate required options for specific platform query
115
+ if ((options.os && !options.arch) || (!options.os && options.arch)) {
116
+ console.error('Error: Both --os and --arch must be specified together');
117
+ printUsage();
118
+ process.exit(1);
119
+ }
120
+
121
+ // Get the binary name for the specified platform
122
+ const binaryName = getBinaryName(options.os, options.arch, options.variant);
123
+ const fileName = options.metadata ? getMetadataName(binaryName) : binaryName;
124
+
125
+ // Check in dist directory
126
+ const distPath = path.join(__dirname, '..', 'dist', fileName);
127
+
128
+ if (fs.existsSync(distPath)) {
129
+ console.log(distPath);
130
+ process.exit(0);
131
+ }
132
+
133
+ // If not in dist, check if it would be in a platform package
134
+ const packageName = `@kumos/tree-sitter-parsers-${options.os}-${options.arch}${options.variant ? '-' + options.variant : ''}`;
135
+ console.error(`Error: ${fileName} not found locally.`);
136
+ console.error(`It may be available in the ${packageName} package.`);
137
+ process.exit(1);
138
+
139
+ } catch (error) {
140
+ console.error('Error:', error.message);
141
+ process.exit(1);
142
+ }
143
+ }
144
+
145
+ main();
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "author": "",
2
+ "author": "Ivan Porto Carrero <ivan@flanders.co.nz>",
3
3
  "bin": {
4
4
  "tree-sitter-parsers-path": "./bin/tree-sitter-parsers-path.js"
5
5
  },
@@ -25,14 +25,14 @@
25
25
  "main": "index.js",
26
26
  "name": "@kumos/tree-sitter-parsers",
27
27
  "optionalDependencies": {
28
- "@kumos/tree-sitter-parsers-darwin-arm64": "0.1.1",
29
- "@kumos/tree-sitter-parsers-darwin-x64": "0.1.1",
30
- "@kumos/tree-sitter-parsers-linux-arm64": "0.1.1",
31
- "@kumos/tree-sitter-parsers-linux-arm64-musl": "0.1.1",
32
- "@kumos/tree-sitter-parsers-linux-x64": "0.1.1",
33
- "@kumos/tree-sitter-parsers-linux-x64-musl": "0.1.1",
34
- "@kumos/tree-sitter-parsers-win32-arm64": "0.1.1",
35
- "@kumos/tree-sitter-parsers-win32-x64": "0.1.1"
28
+ "@kumos/tree-sitter-parsers-darwin-arm64": "0.1.3",
29
+ "@kumos/tree-sitter-parsers-darwin-x64": "0.1.3",
30
+ "@kumos/tree-sitter-parsers-linux-arm64": "0.1.3",
31
+ "@kumos/tree-sitter-parsers-linux-arm64-musl": "0.1.3",
32
+ "@kumos/tree-sitter-parsers-linux-x64": "0.1.3",
33
+ "@kumos/tree-sitter-parsers-linux-x64-musl": "0.1.3",
34
+ "@kumos/tree-sitter-parsers-win32-arm64": "0.1.3",
35
+ "@kumos/tree-sitter-parsers-win32-x64": "0.1.3"
36
36
  },
37
37
  "repository": {
38
38
  "type": "git",
@@ -41,6 +41,8 @@
41
41
  "scripts": {
42
42
  "build": "node build-grammars.js",
43
43
  "build:all": "node build-grammars.js --all-platforms",
44
+ "build:all:validated": "npm run build:all && npm run validate",
45
+ "build:validated": "npm run build && npm run validate",
44
46
  "compile": "node build-grammars.js --compile-only",
45
47
  "create-packages": "node create-platform-packages.js",
46
48
  "fetch": "node build-grammars.js --fetch-only",
@@ -48,7 +50,8 @@
48
50
  "publish-all": "bash publish-packages.sh",
49
51
  "test-distribution": "node test-distribution.js",
50
52
  "test-distribution:arm64": "node test-distribution.js --arch arm64",
51
- "test-distribution:x64": "node test-distribution.js --arch x64"
53
+ "test-distribution:x64": "node test-distribution.js --arch x64",
54
+ "validate": "node validate.js"
52
55
  },
53
- "version": "0.1.1"
54
- }
56
+ "version": "0.1.3"
57
+ }