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
11 changes: 5 additions & 6 deletions .github/workflows/windows-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,19 @@ jobs:
with:
bun-version: 1.3.1

- name: Cache node_modules
- name: Cache Bun install cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/bun.lockb', '**/package.json') }}
path: ~/.bun/install/cache
key: ${{ runner.os }}-bun-${{ hashFiles('bun.lock') }}
restore-keys: |
${{ runner.os }}-node-modules-
${{ runner.os }}-bun-

- name: Install dependencies
run: bun install
run: bun install --frozen-lockfile

- name: Run Windows-only tests
shell: bash
run: |
shopt -s globstar
bun run scripts/run-tests-with-retry.ts --timeout 30000 tests/windows/**/*.test.ts

38 changes: 24 additions & 14 deletions bun.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions cli/build/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,10 @@ export const registerBuild = (program: Command) => {
const entryFile = fileArgIsDirectFile
? resolvedFileArgPath
: transpileEntrypoint
const isRealTsEntrypoint = Boolean(
entryFile &&
(entryFile.endsWith(".ts") || entryFile.endsWith(".tsx")),
)
if (!entryFile) {
if (
hasConfiguredIncludeBoardFiles &&
Expand All @@ -776,6 +780,12 @@ export const registerBuild = (program: Command) => {
)
exitBuild(1, "transpile entry file not found")
}
} else if (!isRealTsEntrypoint && !transpileExplicitlyRequested) {
console.log(
hasConfiguredIncludeBoardFiles
? "Skipping transpilation because includeBoardFiles is configured and no library entrypoint was found."
: "Skipping transpilation because entrypoint is not a TypeScript file.",
)
} else {
const transpileSuccess = await transpileFile({
input: entryFile,
Expand Down
65 changes: 65 additions & 0 deletions lib/shared/get-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,58 @@ const findEntrypointsRecursively = (
return results
}

const findCircuitJsonFiles = (
dir: string,
projectDir: string,
maxDepth: number = MAX_SEARCH_DEPTH,
): string[] => {
if (maxDepth <= 0 || !isValidDirectory(dir, projectDir)) {
return []
}

const results: string[] = []

try {
const entries = fs.readdirSync(dir, { withFileTypes: true })

for (const entry of entries) {
if (results.length >= MAX_RESULTS) break

if (
entry.isFile() &&
(entry.name === "circuit.json" || entry.name.endsWith(".circuit.json"))
) {
const filePath = path.resolve(dir, entry.name)
if (isValidDirectory(filePath, projectDir)) {
results.push(filePath)
}
}
}

for (const entry of entries) {
if (results.length >= MAX_RESULTS) break

if (
entry.isDirectory() &&
!entry.name.startsWith(".") &&
entry.name !== "node_modules" &&
entry.name !== "dist"
) {
const subdirPath = path.resolve(dir, entry.name)
if (isValidDirectory(subdirPath, projectDir)) {
results.push(
...findCircuitJsonFiles(subdirPath, projectDir, maxDepth - 1),
)
}
}
}
} catch {
return []
}

return results
}

const validateProjectDir = (projectDir: string): string => {
const resolvedDir = path.resolve(projectDir)
if (!fs.existsSync(resolvedDir)) {
Expand Down Expand Up @@ -202,6 +254,19 @@ export const getEntrypoint = async ({
}
}

// No entrypoint found - check for circuit.json files as implicit entrypoints
// This allows `tsci push` to work the same as `tsci dev` which supports circuit.json files
const circuitJsonFiles = findCircuitJsonFiles(
validatedProjectDir,
validatedProjectDir,
).sort()

if (circuitJsonFiles.length > 0) {
const chosenFile = path.relative(validatedProjectDir, circuitJsonFiles[0])
onSuccess(`Using circuit.json as implicit entrypoint: '${chosenFile}'`)
return circuitJsonFiles[0]
}

onError(
kleur.red(
"No entrypoint found. Run 'tsci init' to bootstrap a basic project or specify a file with 'tsci push <file>'",
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tscircuit/cli",
"version": "0.1.1398",
"version": "0.1.1405",
"main": "dist/cli/main.js",
"exports": {
".": "./dist/cli/main.js",
Expand All @@ -18,8 +18,8 @@
"@tscircuit/image-utils": "^0.0.3",
"@tscircuit/krt-wasm": "^0.1.0",
"@tscircuit/math-utils": "0.0.36",
"@tscircuit/props": "^0.0.532",
"@tscircuit/runframe": "^0.0.1982",
"@tscircuit/props": "^0.0.536",
"@tscircuit/runframe": "^0.0.2002",
"@tscircuit/schematic-match-adapt": "^0.0.22",
"@types/bun": "^1.2.2",
"@types/configstore": "^6.0.2",
Expand Down Expand Up @@ -71,7 +71,7 @@
"semver": "^7.6.3",
"stepts": "^0.0.3",
"tempy": "^3.1.0",
"tscircuit": "0.0.1772-libonly",
"tscircuit": "0.0.1784-libonly",
"tsx": "^4.7.1",
"typed-ky": "^0.0.4",
"zod": "^3.23.8"
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/build/build-ci-keep-tscircuit-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ test("build --ci keeps tscircuit in devDependencies", async () => {
expect(packageJson.dependencies.tscircuit).toBeUndefined()
expect(packageJson.dependencies.lodash).toBe("^4.17.21")
expect(packageJson.devDependencies.tscircuit).toBe("^0.0.101")
}, 60_000)
}, 100_000)
46 changes: 46 additions & 0 deletions tests/get-entrypoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,49 @@ test("getEntrypoint warns when multiple common locations exist", async () => {
expect(warnings[0]).toContain("Choosing 'index.tsx'")
expect(warnings[0]).toContain("'src/index.tsx'")
})

test("getEntrypoint returns circuit.json as implicit entrypoint when no tsx/ts files exist", async () => {
const { tmpDir } = await getCliTestFixture()

// Create only a circuit.json file, no tsx/ts entrypoints
await fs.writeFile(
path.join(tmpDir, "prebuilt.circuit.json"),
JSON.stringify([{ type: "source_component", name: "U1" }]),
)

let onSuccessMessage = ""
const entrypoint = await getEntrypoint({
projectDir: tmpDir,
onSuccess: (msg) => {
onSuccessMessage = msg
},
})

expect(entrypoint).not.toBeNull()
expect(entrypoint).toBe(path.join(tmpDir, "prebuilt.circuit.json"))
expect(onSuccessMessage).toContain(
"Using circuit.json as implicit entrypoint",
)
})

test("getEntrypoint prefers tsx entrypoint over circuit.json", async () => {
const { tmpDir } = await getCliTestFixture()

// Create both a circuit.json and an index.tsx
await fs.writeFile(
path.join(tmpDir, "prebuilt.circuit.json"),
JSON.stringify([{ type: "source_component", name: "U1" }]),
)
await fs.writeFile(
path.join(tmpDir, "index.tsx"),
'export default () => <board width="10mm" height="10mm"></board>',
)

const entrypoint = await getEntrypoint({
projectDir: tmpDir,
})

// Should prefer the tsx file since it comes first in ALLOWED_ENTRYPOINT_NAMES
expect(entrypoint).not.toBeNull()
expect(entrypoint).toBe(path.join(tmpDir, "index.tsx"))
})
Loading