@tscircuit/eval 0.0.298 → 0.0.299

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.
@@ -51,7 +51,7 @@ export const resolveFilePath = (
51
51
  }
52
52
 
53
53
  // Search for file with a set of different extensions
54
- const extension = ["tsx", "ts", "json", "js", "jsx"]
54
+ const extension = ["tsx", "ts", "json", "js", "jsx", "obj"]
55
55
  for (const ext of extension) {
56
56
  const possibleFilePath = `${normalizedResolvedPath}.${ext}`
57
57
  if (normalizedFilePathMap.has(possibleFilePath)) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/eval",
3
3
  "main": "dist/lib/index.js",
4
- "version": "0.0.298",
4
+ "version": "0.0.299",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "bun run build:lib && bun run build:webworker && bun run build:blob-url && bun run build:runner && bun run build:worker-wrapper",
@@ -0,0 +1,49 @@
1
+ import { expect, test } from "bun:test"
2
+ import type {
3
+ AnyCircuitElement,
4
+ AnySourceComponent,
5
+ CadComponent,
6
+ } from "circuit-json"
7
+ import { CircuitRunner } from "lib/runner/CircuitRunner"
8
+
9
+ test("should support importing .obj files", async () => {
10
+ const runner = new CircuitRunner()
11
+
12
+ const fsMap = {
13
+ "my-model.obj": `v 1.0 1.0 0.0`, // some dummy obj content
14
+ "user-code.tsx": `
15
+ import myObjUrl from "./my-model.obj"
16
+
17
+ export default () => (
18
+ <chip
19
+ name="C1"
20
+ cadModel={{
21
+ objUrl: myObjUrl,
22
+ }}
23
+ />
24
+ )
25
+ `,
26
+ }
27
+
28
+ await runner.executeWithFsMap({
29
+ fsMap,
30
+ mainComponentPath: "user-code.tsx",
31
+ })
32
+
33
+ await runner.renderUntilSettled()
34
+ const circuitJson = await runner.getCircuitJson()
35
+
36
+ const chip =
37
+ (circuitJson.find(
38
+ (elm) => elm.type === "source_component" && elm.name === "C1",
39
+ ) as AnyCircuitElement) || undefined
40
+ const cadModel =
41
+ (circuitJson.find((elm) => elm.type === "cad_component") as CadComponent) ||
42
+ undefined
43
+
44
+ expect(chip).toBeDefined()
45
+ expect(cadModel?.model_obj_url).toBeString()
46
+ expect(cadModel?.model_obj_url).toStartWith("blob:")
47
+
48
+ await runner.kill()
49
+ })
@@ -34,6 +34,13 @@ export const importLocalFile = async (
34
34
  __esModule: true,
35
35
  default: jsonData,
36
36
  }
37
+ } else if (fsPath.endsWith(".obj")) {
38
+ const objBlob = new Blob([fileContent], { type: "model/obj" })
39
+ const objUrl = URL.createObjectURL(objBlob)
40
+ preSuppliedImports[fsPath] = {
41
+ __esModule: true,
42
+ default: objUrl,
43
+ }
37
44
  } else if (fsPath.endsWith(".tsx") || fsPath.endsWith(".ts")) {
38
45
  const importNames = getImportsFromCode(fileContent)
39
46