diff --git a/api/db/generic-json-level.ts b/api/db/generic-json-level.ts index 80b37ce9..c8bb1bf6 100644 --- a/api/db/generic-json-level.ts +++ b/api/db/generic-json-level.ts @@ -5,7 +5,7 @@ import { AbstractValueIterator, } from "abstract-level" import { promises as fs } from "fs" -import path from "path" +import path from "path/posix" interface JSONLevelOptions {} diff --git a/api/db/get-db.ts b/api/db/get-db.ts index 3d9da27b..862aab86 100644 --- a/api/db/get-db.ts +++ b/api/db/get-db.ts @@ -1,5 +1,5 @@ import { mkdirSync } from "fs" -import * as Path from "path" +import * as Path from "path/posix" import { ZodLevelDatabase } from "./zod-level-db" let globalDb: ZodLevelDatabase | undefined diff --git a/cli/lib/cmd-fns/dev/check-if-initialized.ts b/cli/lib/cmd-fns/dev/check-if-initialized.ts index 5f2cea77..f72282da 100644 --- a/cli/lib/cmd-fns/dev/check-if-initialized.ts +++ b/cli/lib/cmd-fns/dev/check-if-initialized.ts @@ -1,6 +1,6 @@ import { AppContext } from "../../util/app-context" import kleur from "kleur" -import * as Path from "path" +import * as Path from "path/posix" import { existsSync, readFileSync } from "fs" export const checkIfInitialized = async (ctx: AppContext) => { diff --git a/cli/lib/cmd-fns/dev/index.ts b/cli/lib/cmd-fns/dev/index.ts index 3feb2e70..f8ffde48 100644 --- a/cli/lib/cmd-fns/dev/index.ts +++ b/cli/lib/cmd-fns/dev/index.ts @@ -4,7 +4,7 @@ import fs from "fs" import kleur from "kleur" import posthog from "cli/lib/posthog" import open from "open" -import * as Path from "path" +import * as Path from "path/posix" import prompts from "prompts" import { z } from "zod" import { AppContext } from "../../util/app-context" diff --git a/cli/lib/cmd-fns/dev/soupify-and-upload-example-file.ts b/cli/lib/cmd-fns/dev/soupify-and-upload-example-file.ts index 9dc555b7..c2c0d612 100644 --- a/cli/lib/cmd-fns/dev/soupify-and-upload-example-file.ts +++ b/cli/lib/cmd-fns/dev/soupify-and-upload-example-file.ts @@ -1,5 +1,5 @@ import kleur from "kleur" -import { join as joinPath } from "path" +import { join as joinPath } from "path/posix" import { AxiosInstance } from "axios" import { readdirSync, readFileSync } from "fs" import { soupify } from "cli/lib/soupify" diff --git a/cli/lib/cmd-fns/dev/start-edit-event-watcher.ts b/cli/lib/cmd-fns/dev/start-edit-event-watcher.ts index 0635bd13..e43b84b0 100644 --- a/cli/lib/cmd-fns/dev/start-edit-event-watcher.ts +++ b/cli/lib/cmd-fns/dev/start-edit-event-watcher.ts @@ -5,7 +5,7 @@ import { AppContext } from "cli/lib/util/app-context" import fg from "fast-glob" import fs from "fs" import { Project, ts } from "ts-morph" -import * as Path from "path" +import * as Path from "path/posix" import { deriveSelectorFromPcbComponentId } from "./derive-selector-from-pcb-component-id" import type { EditEvent } from "@tscircuit/manual-edit-events" import { diff --git a/cli/lib/cmd-fns/dev/upload-examples-from-directory.ts b/cli/lib/cmd-fns/dev/upload-examples-from-directory.ts index 3ff87f44..0be267d6 100644 --- a/cli/lib/cmd-fns/dev/upload-examples-from-directory.ts +++ b/cli/lib/cmd-fns/dev/upload-examples-from-directory.ts @@ -1,5 +1,5 @@ import kleur from "kleur" -import { join as joinPath } from "path" +import { join as joinPath } from "path/posix" import { AxiosInstance } from "axios" import { readdirSync, readFileSync } from "fs" import { soupify } from "cli/lib/soupify" diff --git a/cli/lib/cmd-fns/init/create-or-modify-npmrc.ts b/cli/lib/cmd-fns/init/create-or-modify-npmrc.ts index e5ad0f76..d461f7f1 100644 --- a/cli/lib/cmd-fns/init/create-or-modify-npmrc.ts +++ b/cli/lib/cmd-fns/init/create-or-modify-npmrc.ts @@ -1,6 +1,6 @@ import { existsSync, writeFileSync } from "fs" import kleur from "kleur" -import * as Path from "path" +import * as Path from "path/posix" import { getGeneratedNpmrc } from "./get-generated-npmrc" import { AppContext } from "cli/lib/util/app-context" diff --git a/cli/lib/cmd-fns/init/index.ts b/cli/lib/cmd-fns/init/index.ts index 57a158af..6fcb2c3e 100644 --- a/cli/lib/cmd-fns/init/index.ts +++ b/cli/lib/cmd-fns/init/index.ts @@ -8,7 +8,7 @@ import { writeFile, appendFileSync, } from "fs" -import * as Path from "node:path" +import * as Path from "node:path/posix" import $ from "dax-sh" import { getGeneratedReadme } from "./get-generated-readme" import { getGeneratedTsconfig } from "./get-generated-tsconfig" diff --git a/cli/lib/cmd-fns/open.ts b/cli/lib/cmd-fns/open.ts index 623b9c73..e9c379d0 100644 --- a/cli/lib/cmd-fns/open.ts +++ b/cli/lib/cmd-fns/open.ts @@ -1,7 +1,7 @@ import { existsSync, readFileSync } from "fs" import kleur from "kleur" import { AppContext } from "cli/lib/util/app-context" -import * as Path from "path" +import * as Path from "path/posix" import open from "open" export const openCmd = async (ctx: AppContext, args: any) => { diff --git a/cli/lib/cmd-fns/publish/index.ts b/cli/lib/cmd-fns/publish/index.ts index b4d2e8ed..bfb713d7 100644 --- a/cli/lib/cmd-fns/publish/index.ts +++ b/cli/lib/cmd-fns/publish/index.ts @@ -1,7 +1,7 @@ import kleur from "kleur" import { z } from "zod" import { AppContext } from "../../util/app-context" -import * as Path from "path" +import * as Path from "path/posix" import * as fs from "fs/promises" import { existsSync, readFileSync } from "fs" import { getAllPackageFiles } from "cli/lib/util/get-all-package-files" diff --git a/cli/lib/cmd-fns/render.ts b/cli/lib/cmd-fns/render.ts index de63ba6e..282afee9 100644 --- a/cli/lib/cmd-fns/render.ts +++ b/cli/lib/cmd-fns/render.ts @@ -1,7 +1,7 @@ import { soupify } from "cli/lib/soupify" import type { AppContext } from "cli/lib/util/app-context" import fs from "fs" -import path from "path" +import path from "path/posix" export const renderCmd = async ( ctx: AppContext, diff --git a/cli/lib/cmd-fns/soupify.ts b/cli/lib/cmd-fns/soupify.ts index eb0c8838..eff3e92e 100644 --- a/cli/lib/cmd-fns/soupify.ts +++ b/cli/lib/cmd-fns/soupify.ts @@ -1,6 +1,6 @@ import { AppContext } from "../util/app-context" import { z } from "zod" -import * as Path from "path" +import * as Path from "path/posix" import { unlink } from "node:fs/promises" import { soupify } from "cli/lib/soupify" import { writeFileSync } from "fs" diff --git a/cli/lib/export-fns/export-gerbers.ts b/cli/lib/export-fns/export-gerbers.ts index 6df2d5ef..95fd50de 100644 --- a/cli/lib/export-fns/export-gerbers.ts +++ b/cli/lib/export-fns/export-gerbers.ts @@ -1,6 +1,6 @@ import { AppContext } from "../util/app-context" import { z } from "zod" -import * as Path from "path" +import * as Path from "path/posix" import { unlink } from "node:fs/promises" import { soupify } from "cli/lib/soupify" import * as fs from "fs" @@ -29,6 +29,7 @@ export const exportGerbersToFile = async ( }, ctx, ) + console.log(soup,'soup') console.log(kleur.gray("[soup to gerber json]...")) const gerber_layer_cmds = convertSoupToGerberCommands(soup, { @@ -91,7 +92,7 @@ export const exportGerbersToZipBuffer = async ( ) => { const tempDir = Path.join(".tscircuit", "tmp-gerber-zip") fs.mkdirSync(tempDir, { recursive: true }) - +console.log('step two') await exportGerbersToFile( { example_file_path: params.example_file_path, @@ -100,6 +101,7 @@ export const exportGerbersToZipBuffer = async ( }, ctx, ) + console.log('step last') const buffer = fs.readFileSync(Path.join(tempDir, "gerbers.zip")) diff --git a/cli/lib/export-fns/export-pnp-csv.ts b/cli/lib/export-fns/export-pnp-csv.ts index 512c2313..89800564 100644 --- a/cli/lib/export-fns/export-pnp-csv.ts +++ b/cli/lib/export-fns/export-pnp-csv.ts @@ -1,6 +1,6 @@ import { AppContext } from "../util/app-context" import { z } from "zod" -import * as Path from "path" +import * as Path from "path/posix" import { unlink } from "node:fs/promises" import { soupify } from "cli/lib/soupify" import { convertCircuitJsonToPickAndPlaceCsv } from "circuit-json-to-pnp-csv" diff --git a/cli/lib/soupify/get-tmp-entrpoint-filepath.ts b/cli/lib/soupify/get-tmp-entrpoint-filepath.ts index 4911c49d..6b008a89 100644 --- a/cli/lib/soupify/get-tmp-entrpoint-filepath.ts +++ b/cli/lib/soupify/get-tmp-entrpoint-filepath.ts @@ -1,4 +1,4 @@ -import Path from "node:path" +import Path from "node:path/posix" import fs from "fs/promises" export const getTmpEntrypointFilePath = async (filePath: string) => { diff --git a/cli/lib/soupify/run-entrypoint-file.ts b/cli/lib/soupify/run-entrypoint-file.ts index 4032e33b..59e5f354 100644 --- a/cli/lib/soupify/run-entrypoint-file.ts +++ b/cli/lib/soupify/run-entrypoint-file.ts @@ -17,44 +17,58 @@ export const runEntrypointFile = async ( }: { tmpEntrypointPath: string; tmpOutputPath: string }, ctx: Pick, ) => { + try{ + console.log(1) debug(`using runtime ${ctx.runtime}`) const processCmdPart1 = ctx.runtime === "node" ? $`npx tsx ${tmpEntrypointPath}` : $`bun ${tmpEntrypointPath}` + console.log(2) debug(`starting process....`) - const processResult = await processCmdPart1 - .stdout(debug.enabled ? "inheritPiped" : "piped") + console.log(debug.enabled) + + try{ + const processResult = await processCmdPart1 .stderr(debug.enabled ? "inheritPiped" : "piped") - .noThrow() - + .stdout(debug.enabled ? "inheritPiped" : "piped") + }catch(e){ + console.log(e) + } + + console.log(tmpOutputPath + ) const rawSoup = await readFile(tmpOutputPath, "utf-8") - const errText = processResult.stderr + // const errText = processResult.stderr + console.log(4) if (ctx.params.cleanup !== false) { debug(`deleting ${tmpEntrypointPath}`) await unlink(tmpEntrypointPath) debug(`deleting ${tmpOutputPath}`) await unlink(tmpOutputPath) } - + try { debug(`parsing result of soupify...`) const soup = JSON.parse(rawSoup) - + if (soup.COMPILE_ERROR) { // console.log(kleur.red(`Failed to compile ${filePath}`)) console.log(kleur.red(soup.COMPILE_ERROR)) throw new Error(soup.COMPILE_ERROR) } - + console.log('final') return soup } catch (e: any) { // console.log(kleur.red(`Failed to parse result of soupify: ${e.toString()}`)) const t = Date.now() console.log(`Dumping raw output to .tscircuit/err-${t}.log`) - writeFileSync(`.tscircuit/err-${t}.log`, rawSoup + "\n\n" + errText) - throw new Error(errText) + // writeFileSync(`.tscircuit/err-${t}.log`, rawSoup + "\n\n" + errText) + // throw new Error(errText) } +}catch(e){ + console.log(e) +} } diff --git a/cli/lib/soupify/soupify-with-core.ts b/cli/lib/soupify/soupify-with-core.ts index e06e6f37..f209477b 100644 --- a/cli/lib/soupify/soupify-with-core.ts +++ b/cli/lib/soupify/soupify-with-core.ts @@ -1,7 +1,7 @@ import { AppContext } from "../util/app-context" import { z } from "zod" import $ from "dax-sh" -import * as Path from "path" +import * as Path from "path/posix" import { unlink } from "node:fs/promises" import kleur from "kleur" import { writeFileSync } from "fs" @@ -22,53 +22,51 @@ export const soupifyWithCore = async ( ctx: Pick, ) => { let { filePath, exportName } = params - exportName ??= await getExportNameFromFile(filePath) - const { tmpEntrypointPath, tmpOutputPath } = - await getTmpEntrypointFilePath(filePath) - + + let { tmpEntrypointPath, tmpOutputPath } = await getTmpEntrypointFilePath(filePath) // Remove existing entrypoint or tmp output files await fs.unlink(tmpEntrypointPath).catch(() => {}) await fs.unlink(tmpOutputPath).catch(() => {}) - debug(`writing to ${tmpEntrypointPath}`) writeFileSync( tmpEntrypointPath, ` -import React from "react" -import { Circuit } from "@tscircuit/core" -import * as EXPORTS from "./${Path.basename(filePath)}" -import { writeFileSync } from "node:fs" - -const Component = EXPORTS["${exportName}"] - -const project = new Circuit() - -try { - project.add() -} catch (e: any) { - console.log("[during .add()] ", e.toString()) - writeFileSync("${tmpOutputPath}", JSON.stringify({ - COMPILE_ERROR: e.toString() + "\\n\\n" + e.stack, - })) - throw e -} - -try { - project.render() -} catch (e: any) { - console.log(e.toString()) - writeFileSync("${tmpOutputPath}", JSON.stringify({ - COMPILE_ERROR: e.toString() + "\\n\\n" + e.stack, - })) - throw e -} - - -writeFileSync("${tmpOutputPath}", JSON.stringify(project.getCircuitJson())) -`.trim(), - ) - - return await runEntrypointFile({ tmpEntrypointPath, tmpOutputPath }, ctx) -} + import React from "react" + import { Circuit } from "@tscircuit/core" + import * as EXPORTS from "./${Path.basename(filePath)}" + import { writeFileSync } from "node:fs" + + const Component = EXPORTS["${exportName}"] + + const project = new Circuit() + + try { + project.add() + } catch (e: any) { + console.log("[during .add()] ", e.toString()) + writeFileSync("${tmpOutputPath}", JSON.stringify({ + COMPILE_ERROR: e.toString() + "\\n\\n" + e.stack, + })) + throw e + } + + try { + project.render() + } catch (e: any) { + console.log(e.toString()) + writeFileSync("${tmpOutputPath}", JSON.stringify({ + COMPILE_ERROR: e.toString() + "\\n\\n" + e.stack, + })) + throw e + } + + + writeFileSync("${tmpOutputPath}", JSON.stringify(project.getCircuitJson())) + `.trim(), + ) + + return await runEntrypointFile({ tmpEntrypointPath, tmpOutputPath }, ctx) + } + \ No newline at end of file diff --git a/cli/lib/util/lint-project.ts b/cli/lib/util/lint-project.ts index 3dadd117..73bbf40c 100644 --- a/cli/lib/util/lint-project.ts +++ b/cli/lib/util/lint-project.ts @@ -1,6 +1,6 @@ import * as ts from "typescript" import * as fs from "fs" -import * as path from "path" +import * as path from "path/posix" interface LintResult { filePath: string diff --git a/cli/tests/export-gerber-keyboard.test.ts b/cli/tests/export-gerber-keyboard.test.ts index 610f3754..a24a9076 100644 --- a/cli/tests/export-gerber-keyboard.test.ts +++ b/cli/tests/export-gerber-keyboard.test.ts @@ -1,7 +1,7 @@ import { test, expect, describe } from "bun:test" import { $ } from "bun" import { temporaryDirectory } from "tempy" -import { join } from "path" +import { join } from "path/posix" import { existsSync } from "fs" test("tsci export gerbers --input example-project/examples/macrokeypad.tsx", async () => { diff --git a/cli/tests/export-gerber.test.ts b/cli/tests/export-gerber.test.ts index 21709b8b..135844cf 100644 --- a/cli/tests/export-gerber.test.ts +++ b/cli/tests/export-gerber.test.ts @@ -1,7 +1,7 @@ import { test, expect, describe } from "bun:test" import { $ } from "bun" import { temporaryDirectory } from "tempy" -import { join } from "path" +import { join } from "path/posix" import { existsSync, readdirSync, readFileSync } from "fs" import extract from "extract-zip" import pcbStackup from "pcb-stackup" diff --git a/cli/tests/export-kicad-pcb.test.ts b/cli/tests/export-kicad-pcb.test.ts index 9ce7b342..b35ddce8 100644 --- a/cli/tests/export-kicad-pcb.test.ts +++ b/cli/tests/export-kicad-pcb.test.ts @@ -1,7 +1,7 @@ import { test, expect, describe } from "bun:test" import { $ } from "bun" import { temporaryDirectory } from "tempy" -import { join } from "path" +import { join } from "path/posix" import { existsSync, readFileSync } from "fs" test("tsci export kicad_pcb --input example-project/examples/macrokeypad.tsx", async () => {