@toothfairyai/tfcode 2.0.1 → 2.1.0
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/bin/tfcode.js +50 -10
- package/package.json +13 -13
- 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
|
|
7
|
-
const
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
3
|
+
"version": "2.1.0",
|
|
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
|
|
13
|
-
"@toothfairyai/tfcode-windows-x64": "2.0
|
|
14
|
-
"@toothfairyai/tfcode-linux-x64-baseline-musl": "2.0
|
|
15
|
-
"@toothfairyai/tfcode-darwin-x64-baseline": "2.0
|
|
16
|
-
"@toothfairyai/tfcode-linux-x64-musl": "2.0
|
|
17
|
-
"@toothfairyai/tfcode-windows-x64-baseline": "2.0
|
|
18
|
-
"@toothfairyai/tfcode-linux-arm64-musl": "2.0
|
|
19
|
-
"@toothfairyai/tfcode-windows-arm64": "2.0
|
|
20
|
-
"@toothfairyai/tfcode-linux-x64": "2.0
|
|
21
|
-
"@toothfairyai/tfcode-darwin-x64": "2.0
|
|
22
|
-
"@toothfairyai/tfcode-linux-x64-baseline": "2.0
|
|
23
|
-
"@toothfairyai/tfcode-darwin-arm64": "2.0
|
|
12
|
+
"@toothfairyai/tfcode-linux-arm64": "2.1.0",
|
|
13
|
+
"@toothfairyai/tfcode-windows-x64": "2.1.0",
|
|
14
|
+
"@toothfairyai/tfcode-linux-x64-baseline-musl": "2.1.0",
|
|
15
|
+
"@toothfairyai/tfcode-darwin-x64-baseline": "2.1.0",
|
|
16
|
+
"@toothfairyai/tfcode-linux-x64-musl": "2.1.0",
|
|
17
|
+
"@toothfairyai/tfcode-windows-x64-baseline": "2.1.0",
|
|
18
|
+
"@toothfairyai/tfcode-linux-arm64-musl": "2.1.0",
|
|
19
|
+
"@toothfairyai/tfcode-windows-arm64": "2.1.0",
|
|
20
|
+
"@toothfairyai/tfcode-linux-x64": "2.1.0",
|
|
21
|
+
"@toothfairyai/tfcode-darwin-x64": "2.1.0",
|
|
22
|
+
"@toothfairyai/tfcode-linux-x64-baseline": "2.1.0",
|
|
23
|
+
"@toothfairyai/tfcode-darwin-arm64": "2.1.0"
|
|
24
24
|
},
|
|
25
25
|
"engines": {
|
|
26
26
|
"node": ">=18"
|
package/bin/tfcode
DELETED
|
Binary file
|