@tscircuit/cli 0.1.531 → 0.1.533

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/cli/entrypoint.js CHANGED
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawnSync } from "node:child_process"
3
- import { fileURLToPath } from "node:url"
3
+ import { existsSync } from "node:fs"
4
+ import { createRequire } from "node:module"
4
5
  import { dirname, join } from "node:path"
6
+ import { fileURLToPath } from "node:url"
5
7
 
6
8
  function commandExists(cmd) {
7
9
  try {
@@ -15,7 +17,28 @@ function commandExists(cmd) {
15
17
  const runner = commandExists("bun") ? "bun" : "tsx"
16
18
 
17
19
  const __dirname = dirname(fileURLToPath(import.meta.url))
18
- const mainPath = join(__dirname, "../dist/main.js")
20
+ const packageRoot = join(__dirname, "..")
21
+ const require = createRequire(import.meta.url)
22
+
23
+ const globalPackageJson = require("../package.json")
24
+
25
+ let mainPath = join(packageRoot, "dist/main.js")
26
+
27
+ try {
28
+ const localPackageJsonPath = require.resolve("@tscircuit/cli/package.json", {
29
+ paths: [process.cwd()],
30
+ })
31
+ const localPackageJson = require(localPackageJsonPath)
32
+ const localPackageRoot = dirname(localPackageJsonPath)
33
+ const localMainPath = join(localPackageRoot, "dist/main.js")
34
+
35
+ if (localPackageRoot !== packageRoot && existsSync(localMainPath)) {
36
+ console.warn(
37
+ `Using local @tscircuit/cli v${localPackageJson.version} instead of global v${globalPackageJson.version}`,
38
+ )
39
+ mainPath = localMainPath
40
+ }
41
+ } catch {}
19
42
 
20
43
  const { status } = spawnSync(runner, [mainPath, ...process.argv.slice(2)], {
21
44
  stdio: "inherit",