Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions cli/build/worker-pool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import fs from "node:fs"
import path from "node:path"
import { dirname } from "node:path"
import { fileURLToPath } from "node:url"
import type { PlatformConfig } from "@tscircuit/props"
import type { PcbSnapshotSettings } from "lib/project-config/project-config-schema"
import { ThreadWorkerPool } from "lib/shared/thread-worker-pool"
Expand Down Expand Up @@ -32,19 +34,27 @@ type BuildJob = {
}
}

// import.meta.dir is Bun-only; import.meta.dirname is Node >=21.2
// Cast to include both so TypeScript does not complain about either.
type ImportMetaWithDir = { dir?: string; dirname?: string }
const __metaDir: string =
(import.meta as unknown as ImportMetaWithDir).dir ??
(import.meta as unknown as ImportMetaWithDir).dirname ??
dirname(fileURLToPath(import.meta.url))

const getWorkerEntrypointPath = (): string => {
// Check for .ts file first (development), then .js (published/dist)
const tsPath = path.join(import.meta.dir, "build.worker.ts")
const tsPath = path.join(__metaDir, "build.worker.ts")
if (fs.existsSync(tsPath)) {
return tsPath
}
// When bundled, main.js is in dist/ and worker is in dist/build/
const jsBundledPath = path.join(import.meta.dir, "build", "build.worker.js")
const jsBundledPath = path.join(__metaDir, "build", "build.worker.js")
if (fs.existsSync(jsBundledPath)) {
return jsBundledPath
}
// Fallback: same directory
return path.join(import.meta.dir, "build.worker.js")
return path.join(__metaDir, "build.worker.js")
}

/**
Expand Down
6 changes: 5 additions & 1 deletion cli/entrypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ function commandExists(cmd) {
}
}

const runner = commandExists("bun") ? "bun" : "tsx"
const runner = commandExists("bun")
? "bun"
: commandExists("tsx")
? "tsx"
: process.execPath

const __dirname = dirname(fileURLToPath(import.meta.url))
const packageRoot = join(__dirname, "..")
Expand Down
20 changes: 13 additions & 7 deletions cli/snapshot/worker-pool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import fs from "node:fs"
import path from "node:path"
import { dirname } from "node:path"
import { fileURLToPath } from "node:url"
import type { ProcessSnapshotFileOptions } from "lib/shared/process-snapshot-file"
import { ThreadWorkerPool } from "lib/shared/thread-worker-pool"
import type {
Expand All @@ -19,22 +21,26 @@ type SnapshotJob = {
>
}

// import.meta.dir is Bun-only; import.meta.dirname is Node >=21.2
// Cast to include both so TypeScript does not complain about either.
type ImportMetaWithDir = { dir?: string; dirname?: string }
const __metaDir: string =
(import.meta as unknown as ImportMetaWithDir).dir ??
(import.meta as unknown as ImportMetaWithDir).dirname ??
dirname(fileURLToPath(import.meta.url))

const getWorkerEntrypointPath = (): string => {
const tsPath = path.join(import.meta.dir, "snapshot.worker.ts")
const tsPath = path.join(__metaDir, "snapshot.worker.ts")
if (fs.existsSync(tsPath)) {
return tsPath
}

const jsBundledPath = path.join(
import.meta.dir,
"snapshot",
"snapshot.worker.js",
)
const jsBundledPath = path.join(__metaDir, "snapshot", "snapshot.worker.js")
if (fs.existsSync(jsBundledPath)) {
return jsBundledPath
}

return path.join(import.meta.dir, "snapshot.worker.js")
return path.join(__metaDir, "snapshot.worker.js")
}

export const snapshotFilesWithWorkerPool = async (options: {
Expand Down
Loading