@toothfairyai/tfcode 1.0.2 → 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/bin/tfcode ADDED
Binary file
package/bin/tfcode.js CHANGED
@@ -3,9 +3,8 @@ const { spawn } = require('child_process')
3
3
  const path = require('path')
4
4
  const fs = require('fs')
5
5
 
6
- const binDir = path.join(__dirname, 'bin')
7
6
  const binary = process.platform === 'win32' ? 'tfcode.exe' : 'tfcode'
8
- const binaryPath = path.join(binDir, binary)
7
+ const binaryPath = path.join(__dirname, binary)
9
8
 
10
9
  if (!fs.existsSync(binaryPath)) {
11
10
  console.error('tfcode binary not found. Run: npm install @toothfairyai/tfcode')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toothfairyai/tfcode",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "bin": {
5
5
  "tfcode": "./bin/tfcode.js"
6
6
  },
@@ -9,18 +9,7 @@
9
9
  },
10
10
  "license": "MIT",
11
11
  "optionalDependencies": {
12
- "@toothfairyai/tfcode-linux-arm64": "1.0.2",
13
- "@toothfairyai/tfcode-windows-x64": "1.0.2",
14
- "@toothfairyai/tfcode-linux-x64-baseline-musl": "1.0.2",
15
- "@toothfairyai/tfcode-darwin-x64-baseline": "1.0.2",
16
- "@toothfairyai/tfcode-linux-x64-musl": "1.0.2",
17
- "@toothfairyai/tfcode-windows-x64-baseline": "1.0.2",
18
- "@toothfairyai/tfcode-linux-arm64-musl": "1.0.2",
19
- "@toothfairyai/tfcode-windows-arm64": "1.0.2",
20
- "@toothfairyai/tfcode-linux-x64": "1.0.2",
21
- "@toothfairyai/tfcode-darwin-x64": "1.0.2",
22
- "@toothfairyai/tfcode-linux-x64-baseline": "1.0.2",
23
- "@toothfairyai/tfcode-darwin-arm64": "1.0.2"
12
+ "@toothfairyai/tfcode-darwin-arm64": "1.0.4"
24
13
  },
25
14
  "engines": {
26
15
  "node": ">=18"
package/postinstall.mjs CHANGED
@@ -4,6 +4,10 @@ import fs from "fs"
4
4
  import path from "path"
5
5
  import os from "os"
6
6
  import { spawnSync } from "child_process"
7
+ import { fileURLToPath } from "url"
8
+
9
+ const __filename = fileURLToPath(import.meta.url)
10
+ const __dirname = path.dirname(__filename)
7
11
 
8
12
  const GITEA_HOST = process.env.TFCODE_GITEA_HOST || "gitea.toothfairyai.com"
9
13
  const GITEA_REPO = process.env.TFCODE_GITEA_REPO || "ToothFairyAI/tf_code"
@@ -82,7 +86,17 @@ async function downloadBinary() {
82
86
  const { platform, arch, needsBaseline, abi } = detectPlatform()
83
87
  const version = await getVersion()
84
88
 
85
- // 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
86
100
  let target = `tfcode-${platform}-${arch}`
87
101
  if (needsBaseline) target += "-baseline"
88
102
  if (abi) target += `-${abi}`
@@ -94,7 +108,6 @@ async function downloadBinary() {
94
108
  console.log(`Downloading tfcode v${version} for ${target}...`)
95
109
 
96
110
  // Download
97
- const binDir = path.join(__dirname, "bin")
98
111
  if (!fs.existsSync(binDir)) fs.mkdirSync(binDir, { recursive: true })
99
112
 
100
113
  const tmpDir = path.join(os.tmpdir(), `tfcode-install-${process.pid}`)
@@ -110,17 +123,42 @@ async function downloadBinary() {
110
123
  // Fallback to npm optionalDependencies
111
124
  try {
112
125
  const pkgName = `@toothfairyai/${target}`
113
- const pkgPath = require.resolve(`${pkgName}/package.json`)
114
- 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
+
115
138
  const binaryName = platform === "windows" ? "tfcode.exe" : "tfcode"
116
139
  const binaryPath = path.join(pkgDir, "bin", binaryName)
117
140
 
141
+ console.log(`Looking for binary at: ${binaryPath}`)
142
+
118
143
  if (fs.existsSync(binaryPath)) {
144
+ console.log(`Found binary at npm package location`)
119
145
  setupBinary(binaryPath, platform)
120
146
  return
147
+ } else {
148
+ console.error(`Binary not found at ${binaryPath}`)
121
149
  }
122
- } catch {}
150
+ } catch (e) {
151
+ console.error("npm package fallback failed:", e.message)
152
+ }
123
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("")
124
162
  process.exit(1)
125
163
  }
126
164
 
@@ -133,7 +171,6 @@ async function downloadBinary() {
133
171
  }
134
172
 
135
173
  // Move binary
136
- const binaryName = platform === "windows" ? "tfcode.exe" : "tfcode"
137
174
  const extractedBinary = path.join(tmpDir, "tfcode")
138
175
  const targetBinary = path.join(binDir, binaryName)
139
176
 
@@ -174,6 +211,9 @@ async function main() {
174
211
  console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
175
212
  console.log("")
176
213
 
214
+ // Download and setup binary
215
+ await downloadBinary()
216
+
177
217
  // Check for Python (needed for TF integration)
178
218
  try {
179
219
  const result = spawnSync("python3", ["--version"], { encoding: "utf8" })