@toothfairyai/tfcode 1.0.3 → 1.0.4

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/LICENSE CHANGED
File without changes
package/bin/tfcode CHANGED
Binary file
package/bin/tfcode.js CHANGED
@@ -1,19 +1,19 @@
1
1
  #!/usr/bin/env node
2
- const { spawn } = require("child_process")
3
- const path = require("path")
4
- const fs = require("fs")
2
+ const { spawn } = require('child_process')
3
+ const path = require('path')
4
+ const fs = require('fs')
5
5
 
6
- const binary = process.platform === "win32" ? "tfcode.exe" : "tfcode"
6
+ const binary = process.platform === 'win32' ? 'tfcode.exe' : 'tfcode'
7
7
  const binaryPath = path.join(__dirname, binary)
8
8
 
9
9
  if (!fs.existsSync(binaryPath)) {
10
- console.error("tfcode binary not found at " + binaryPath)
10
+ console.error('tfcode binary not found. Run: npm install @toothfairyai/tfcode')
11
11
  process.exit(1)
12
12
  }
13
13
 
14
14
  const child = spawn(binaryPath, process.argv.slice(2), {
15
- stdio: "inherit",
15
+ stdio: 'inherit',
16
16
  env: process.env
17
17
  })
18
18
 
19
- child.on("exit", (code) => process.exit(code || 0))
19
+ child.on('exit', (code) => process.exit(code || 0))
package/package.json CHANGED
@@ -1 +1,22 @@
1
- {"name":"@toothfairyai/tfcode","version":"1.0.3","bin":{"tfcode":"./bin/tfcode.js"},"scripts":{"postinstall":"node ./postinstall.mjs"},"license":"MIT","optionalDependencies":{"@toothfairyai/tfcode-darwin-arm64":"1.0.3"},"engines":{"node":">=18"},"homepage":"https://toothfairyai.com/developers/tfcode","repository":{"type":"git","url":"https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git"}}
1
+ {
2
+ "name": "@toothfairyai/tfcode",
3
+ "version": "1.0.4",
4
+ "bin": {
5
+ "tfcode": "./bin/tfcode.js"
6
+ },
7
+ "scripts": {
8
+ "postinstall": "node ./postinstall.mjs"
9
+ },
10
+ "license": "MIT",
11
+ "optionalDependencies": {
12
+ "@toothfairyai/tfcode-darwin-arm64": "1.0.4"
13
+ },
14
+ "engines": {
15
+ "node": ">=18"
16
+ },
17
+ "homepage": "https://toothfairyai.com/developers/tfcode",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git"
21
+ }
22
+ }
package/postinstall.mjs CHANGED
@@ -86,7 +86,17 @@ async function downloadBinary() {
86
86
  const { platform, arch, needsBaseline, abi } = detectPlatform()
87
87
  const version = await getVersion()
88
88
 
89
- // Build filename
89
+ // Check if binary already exists (included in npm package)
90
+ const binaryName = platform === "windows" ? "tfcode.exe" : "tfcode"
91
+ const binDir = path.join(__dirname, "bin")
92
+ const existingBinary = path.join(binDir, binaryName)
93
+
94
+ if (fs.existsSync(existingBinary)) {
95
+ console.log(`✓ Binary already exists at ${existingBinary}`)
96
+ return
97
+ }
98
+
99
+ // Build filename for download
90
100
  let target = `tfcode-${platform}-${arch}`
91
101
  if (needsBaseline) target += "-baseline"
92
102
  if (abi) target += `-${abi}`
@@ -98,7 +108,6 @@ async function downloadBinary() {
98
108
  console.log(`Downloading tfcode v${version} for ${target}...`)
99
109
 
100
110
  // Download
101
- const binDir = path.join(__dirname, "bin")
102
111
  if (!fs.existsSync(binDir)) fs.mkdirSync(binDir, { recursive: true })
103
112
 
104
113
  const tmpDir = path.join(os.tmpdir(), `tfcode-install-${process.pid}`)
@@ -114,17 +123,42 @@ async function downloadBinary() {
114
123
  // Fallback to npm optionalDependencies
115
124
  try {
116
125
  const pkgName = `@toothfairyai/${target}`
117
- const pkgPath = require.resolve(`${pkgName}/package.json`)
118
- const pkgDir = path.dirname(pkgPath)
126
+
127
+ // ESM-compatible module resolution
128
+ let pkgDir
129
+ try {
130
+ const pkgUrl = import.meta.resolve(`${pkgName}/package.json`)
131
+ const pkgPath = fileURLToPath(pkgUrl)
132
+ pkgDir = path.dirname(pkgPath)
133
+ } catch (e) {
134
+ console.error(`Could not resolve ${pkgName}:`, e.message)
135
+ throw e
136
+ }
137
+
119
138
  const binaryName = platform === "windows" ? "tfcode.exe" : "tfcode"
120
139
  const binaryPath = path.join(pkgDir, "bin", binaryName)
121
140
 
141
+ console.log(`Looking for binary at: ${binaryPath}`)
142
+
122
143
  if (fs.existsSync(binaryPath)) {
144
+ console.log(`Found binary at npm package location`)
123
145
  setupBinary(binaryPath, platform)
124
146
  return
147
+ } else {
148
+ console.error(`Binary not found at ${binaryPath}`)
125
149
  }
126
- } catch {}
150
+ } catch (e) {
151
+ console.error("npm package fallback failed:", e.message)
152
+ }
127
153
 
154
+ console.error("")
155
+ console.error("Installation failed. The binary could not be downloaded or found.")
156
+ console.error("")
157
+ console.error("Possible solutions:")
158
+ console.error(" 1. If this is a private installation, set TFCODE_GITEA_HOST to an accessible host")
159
+ console.error(" 2. Manually download the binary and place it in the bin/ directory")
160
+ console.error(" 3. Contact ToothFairyAI support for assistance")
161
+ console.error("")
128
162
  process.exit(1)
129
163
  }
130
164
 
@@ -137,7 +171,6 @@ async function downloadBinary() {
137
171
  }
138
172
 
139
173
  // Move binary
140
- const binaryName = platform === "windows" ? "tfcode.exe" : "tfcode"
141
174
  const extractedBinary = path.join(tmpDir, "tfcode")
142
175
  const targetBinary = path.join(binDir, binaryName)
143
176