@toothfairyai/tfcode 2.0.1 → 2.0.2

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.
Files changed (3) hide show
  1. package/bin/tfcode.js +50 -10
  2. package/package.json +13 -13
  3. package/bin/tfcode +0 -0
package/bin/tfcode.js CHANGED
@@ -1,19 +1,59 @@
1
1
  #!/usr/bin/env node
2
- const { spawn } = require('child_process')
2
+ const { spawn, spawnSync } = require('child_process')
3
3
  const path = require('path')
4
4
  const fs = require('fs')
5
+ const os = require('os')
5
6
 
6
- const binary = process.platform === 'win32' ? 'tfcode.exe' : 'tfcode'
7
- const binaryPath = path.join(__dirname, binary)
7
+ const platform = os.platform() === 'darwin' ? 'darwin' : os.platform() === 'win32' ? 'windows' : 'linux'
8
+ const arch = os.arch() === 'arm64' ? 'arm64' : 'x64'
9
+ const binName = platform === 'windows' ? 'tfcode.exe' : 'tfcode'
8
10
 
9
- if (!fs.existsSync(binaryPath)) {
10
- console.error('tfcode binary not found. Run: npm install @toothfairyai/tfcode')
11
- process.exit(1)
11
+ function needBaseline() {
12
+ if (arch !== 'x64' || platform === 'windows') return false
13
+ try {
14
+ if (platform === 'linux') {
15
+ return !fs.readFileSync('/proc/cpuinfo', 'utf8').toLowerCase().includes('avx2')
16
+ }
17
+ const r = spawnSync('sysctl', ['-n', 'hw.optional.avx2_0'], { encoding: 'utf8' })
18
+ return r.stdout.trim() !== '1'
19
+ } catch {
20
+ return false
21
+ }
22
+ }
23
+
24
+ function libcAbi() {
25
+ if (platform !== 'linux') return ''
26
+ try {
27
+ if (fs.existsSync('/etc/alpine-release')) return 'musl'
28
+ const r = spawnSync('ldd', ['--version'], { encoding: 'utf8' })
29
+ if ((r.stdout + r.stderr).toLowerCase().includes('musl')) return 'musl'
30
+ } catch {}
31
+ return ''
12
32
  }
13
33
 
14
- const child = spawn(binaryPath, process.argv.slice(2), {
15
- stdio: 'inherit',
16
- env: process.env
17
- })
34
+ const baseline = needBaseline()
35
+ const abi = libcAbi()
36
+ let target = 'tfcode-' + platform + '-' + arch
37
+ if (baseline) target += '-baseline'
38
+ if (abi) target += '-' + abi
39
+
40
+ let binaryPath
41
+ try {
42
+ const dir = path.dirname(require.resolve('@toothfairyai/' + target + '/package.json'))
43
+ const candidate = path.join(dir, 'bin', binName)
44
+ if (fs.existsSync(candidate)) binaryPath = candidate
45
+ } catch {}
46
+
47
+ if (!binaryPath) {
48
+ const bundled = path.join(__dirname, binName)
49
+ if (fs.existsSync(bundled)) binaryPath = bundled
50
+ }
51
+
52
+ if (!binaryPath) {
53
+ console.error('tfcode binary not found for ' + target + '. Try: npm install -g --allow-scripts=@toothfairyai/tfcode')
54
+ process.exit(1)
55
+ }
18
56
 
57
+ const child = spawn(binaryPath, process.argv.slice(2), { stdio: 'inherit', env: process.env })
19
58
  child.on('exit', (code) => process.exit(code || 0))
59
+ child.on('error', (err) => { console.error('Failed to start tfcode:', err.message); process.exit(1) })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toothfairyai/tfcode",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "bin": {
5
5
  "tfcode": "./bin/tfcode.js"
6
6
  },
@@ -9,18 +9,18 @@
9
9
  },
10
10
  "license": "MIT",
11
11
  "optionalDependencies": {
12
- "@toothfairyai/tfcode-linux-arm64": "2.0.1",
13
- "@toothfairyai/tfcode-windows-x64": "2.0.1",
14
- "@toothfairyai/tfcode-linux-x64-baseline-musl": "2.0.1",
15
- "@toothfairyai/tfcode-darwin-x64-baseline": "2.0.1",
16
- "@toothfairyai/tfcode-linux-x64-musl": "2.0.1",
17
- "@toothfairyai/tfcode-windows-x64-baseline": "2.0.1",
18
- "@toothfairyai/tfcode-linux-arm64-musl": "2.0.1",
19
- "@toothfairyai/tfcode-windows-arm64": "2.0.1",
20
- "@toothfairyai/tfcode-linux-x64": "2.0.1",
21
- "@toothfairyai/tfcode-darwin-x64": "2.0.1",
22
- "@toothfairyai/tfcode-linux-x64-baseline": "2.0.1",
23
- "@toothfairyai/tfcode-darwin-arm64": "2.0.1"
12
+ "@toothfairyai/tfcode-linux-arm64": "2.0.2",
13
+ "@toothfairyai/tfcode-windows-x64": "2.0.2",
14
+ "@toothfairyai/tfcode-linux-x64-baseline-musl": "2.0.2",
15
+ "@toothfairyai/tfcode-darwin-x64-baseline": "2.0.2",
16
+ "@toothfairyai/tfcode-linux-x64-musl": "2.0.2",
17
+ "@toothfairyai/tfcode-windows-x64-baseline": "2.0.2",
18
+ "@toothfairyai/tfcode-linux-arm64-musl": "2.0.2",
19
+ "@toothfairyai/tfcode-windows-arm64": "2.0.2",
20
+ "@toothfairyai/tfcode-linux-x64": "2.0.2",
21
+ "@toothfairyai/tfcode-darwin-x64": "2.0.2",
22
+ "@toothfairyai/tfcode-linux-x64-baseline": "2.0.2",
23
+ "@toothfairyai/tfcode-darwin-arm64": "2.0.2"
24
24
  },
25
25
  "engines": {
26
26
  "node": ">=18"
package/bin/tfcode DELETED
Binary file