@tscircuit/eval 0.0.363 → 0.0.364
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/package.json +4 -1
- package/.github/workflows/bun-formatcheck.yml +0 -27
- package/.github/workflows/bun-pver-release.yml +0 -70
- package/.github/workflows/bun-test.yml +0 -87
- package/.github/workflows/bun-typecheck.yml +0 -27
- package/.github/workflows/playwright.yml +0 -40
- package/.github/workflows/update-deps.yml +0 -47
- package/.github/workflows/update-tscircuit-core.yml +0 -59
- package/biome.json +0 -50
- package/browser-tests/browser.test.ts +0 -15
- package/browser-tests/browsertest.html +0 -15
- package/browser-tests/browsertest.ts +0 -53
- package/bunfig.toml +0 -6
- package/lib/getPlatformConfig.ts +0 -41
- package/lib/getPossibleEntrypointComponentPaths.ts +0 -42
- package/lib/index.ts +0 -5
- package/lib/runner/CircuitRunner.ts +0 -201
- package/lib/runner/index.ts +0 -4
- package/lib/runner/normalizeFsMap.ts +0 -20
- package/lib/runner/resolveFilePath.ts +0 -90
- package/lib/runner/runTscircuitCode.ts +0 -30
- package/lib/runner/runTscircuitModule.ts +0 -37
- package/lib/runner/setupDefaultEntrypointIfNeeded.ts +0 -81
- package/lib/shared/static-asset-extensions.ts +0 -10
- package/lib/shared/types.ts +0 -79
- package/lib/utils/dirname.ts +0 -21
- package/lib/utils/get-imports-from-code.ts +0 -23
- package/lib/utils/index.ts +0 -1
- package/lib/utils/resolve-node-module.ts +0 -193
- package/lib/worker.ts +0 -246
- package/playwright.config.ts +0 -23
- package/scripts/build-worker-blob-url.ts +0 -27
- package/scripts/copy-core-versions.ts +0 -81
- package/scripts/validate-test-matrix.js +0 -148
- package/tests/circuit-runner/circuitrunner1-readme-example.test.tsx +0 -29
- package/tests/custom-component-with-fsmap/should-reject-invalid-main-component-path.test.ts +0 -26
- package/tests/custom-component-with-fsmap/should-render-multiple-components-from-fsmap.test.ts +0 -46
- package/tests/custom-component-with-fsmap/should-render-single-component-from-fsmap.test.ts +0 -38
- package/tests/examples/__snapshots__/example18-kicad-footprint-server.snap.svg +0 -1
- package/tests/examples/example01-readme-example.test.tsx +0 -30
- package/tests/examples/example02-multiple-files.test.tsx +0 -45
- package/tests/examples/example03-encoded-url.test.tsx +0 -28
- package/tests/examples/example04-root-child-issue.test.tsx +0 -37
- package/tests/examples/example05-event-recording.test.tsx +0 -44
- package/tests/examples/example06-dynamic-load-blob-url.test.tsx +0 -29
- package/tests/examples/example07-import-default-and-namespace.test.tsx +0 -74
- package/tests/examples/example08-footprinter-to220.test.tsx +0 -30
- package/tests/examples/example09-not-defined-component.test.tsx +0 -24
- package/tests/examples/example10-run-tscircuit-code.test.tsx +0 -14
- package/tests/examples/example11-flexible-import-extensions.test.tsx +0 -20
- package/tests/examples/example12-import-from-subdirectory.test.tsx +0 -26
- package/tests/examples/example13-webworker-without-entrypoint.test.tsx +0 -32
- package/tests/examples/example14-run-tscircuit-module.test.tsx +0 -20
- package/tests/examples/example15-run-tscircuit-module-with-props.test.tsx +0 -24
- package/tests/examples/example16-parts-engine.test.tsx +0 -118
- package/tests/examples/example17-parse-tscircuit-config.test.tsx +0 -49
- package/tests/examples/example18-kicad-footprint-server.test.tsx +0 -39
- package/tests/examples/example19-support-backwards-compat.test.tsx +0 -31
- package/tests/examples/example20-kicad-import.test.tsx +0 -48
- package/tests/features/circuit-event-forwarding.test.tsx +0 -45
- package/tests/features/enable-debug.test.ts +0 -26
- package/tests/features/execute-component-runner.test.tsx +0 -47
- package/tests/features/execute-component-worker.test.tsx +0 -25
- package/tests/features/fetch-proxy/fetch-override.test.ts +0 -46
- package/tests/features/fetch-proxy/fetch-proxy-validation.test.ts +0 -95
- package/tests/features/kill.test.ts +0 -24
- package/tests/features/manual-edits.test.tsx +0 -118
- package/tests/features/npm-import.test.tsx +0 -47
- package/tests/features/parent-directory-import.test.tsx +0 -26
- package/tests/features/platform-config.test.tsx +0 -23
- package/tests/features/prioritize-default-export.test.tsx +0 -27
- package/tests/features/project-config.test.tsx +0 -25
- package/tests/features/static-file-imports/static-file-import.test.ts +0 -50
- package/tests/fixtures/preload.ts +0 -10
- package/tests/fixtures/resourcePaths.ts +0 -3
- package/tests/node-resolution/node-module-resolution-1.test.tsx +0 -32
- package/tests/node-resolution/node-module-resolution-10.test.tsx +0 -30
- package/tests/node-resolution/node-module-resolution-11.test.tsx +0 -41
- package/tests/node-resolution/node-module-resolution-2.test.tsx +0 -33
- package/tests/node-resolution/node-module-resolution-3.test.tsx +0 -38
- package/tests/node-resolution/node-module-resolution-4.test.tsx +0 -29
- package/tests/node-resolution/node-module-resolution-5.test.tsx +0 -38
- package/tests/node-resolution/node-module-resolution-6.test.tsx +0 -40
- package/tests/node-resolution/node-module-resolution-7.test.tsx +0 -43
- package/tests/node-resolution/node-module-resolution-8.test.tsx +0 -32
- package/tests/node-resolution/node-module-resolution-9.test.tsx +0 -29
- package/tests/node-resolution/node-modules-resolution-12.test.tsx +0 -30
- package/tests/repros/group-wrapper.test.tsx +0 -18
- package/tests/repros/nine-keyboard-default-export.test.tsx +0 -26
- package/tests/util-fns/get-imports-from-code.test.tsx +0 -93
- package/tests/util-fns/getPossibleEntrypointComponentPaths.test.ts +0 -35
- package/tsconfig.json +0 -34
- package/tsup-lib.config.ts +0 -11
- package/tsup-runner.config.ts +0 -12
- package/tsup-webworker.config.ts +0 -21
- package/webworker/entrypoint.ts +0 -227
- package/webworker/eval-compiled-js.ts +0 -61
- package/webworker/execution-context.ts +0 -64
- package/webworker/fetchProxy.ts +0 -83
- package/webworker/import-eval-path.ts +0 -78
- package/webworker/import-local-file.ts +0 -93
- package/webworker/import-node-module.ts +0 -54
- package/webworker/import-npm-package.ts +0 -77
- package/webworker/import-snippet.ts +0 -30
- package/webworker/index.ts +0 -1
- package/webworker/transform-with-sucrase.ts +0 -68
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { dirname } from "./dirname"
|
|
2
|
-
|
|
3
|
-
interface PackageJson {
|
|
4
|
-
main?: string
|
|
5
|
-
module?: string
|
|
6
|
-
exports?: Record<string, string | Record<string, string>>
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface NodeResolutionContext {
|
|
10
|
-
fsMap: Record<string, string>
|
|
11
|
-
extensions: string[]
|
|
12
|
-
basePath: string
|
|
13
|
-
modulePath: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function createContext(
|
|
17
|
-
modulePath: string,
|
|
18
|
-
fsMap: Record<string, string>,
|
|
19
|
-
basePath: string,
|
|
20
|
-
): NodeResolutionContext {
|
|
21
|
-
return {
|
|
22
|
-
fsMap,
|
|
23
|
-
extensions: [".js", ".jsx", ".ts", ".tsx", ".json"],
|
|
24
|
-
basePath,
|
|
25
|
-
modulePath,
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function findPackageJson(nodeModulesPath: string, ctx: NodeResolutionContext) {
|
|
30
|
-
const packageJsonPath = `${nodeModulesPath}/package.json`
|
|
31
|
-
if (!ctx.fsMap[packageJsonPath]) return null
|
|
32
|
-
try {
|
|
33
|
-
return JSON.parse(ctx.fsMap[packageJsonPath]) as PackageJson
|
|
34
|
-
} catch {
|
|
35
|
-
return null
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function tryResolveWithExtensions(
|
|
40
|
-
path: string,
|
|
41
|
-
ctx: NodeResolutionContext,
|
|
42
|
-
): string | null {
|
|
43
|
-
if (ctx.fsMap[path]) return path
|
|
44
|
-
|
|
45
|
-
for (const ext of ctx.extensions) {
|
|
46
|
-
const pathWithExt = path.replace(/\.js$|\.jsx$/, "") + ext
|
|
47
|
-
if (ctx.fsMap[pathWithExt]) return pathWithExt
|
|
48
|
-
}
|
|
49
|
-
return null
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function resolveExportPath(
|
|
53
|
-
nodeModulesPath: string,
|
|
54
|
-
exportPath: string,
|
|
55
|
-
ctx: NodeResolutionContext,
|
|
56
|
-
): string | null {
|
|
57
|
-
const fullExportPath = `${nodeModulesPath}/${exportPath.replace(/^\.\//, "")}`
|
|
58
|
-
return tryResolveWithExtensions(fullExportPath, ctx)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function resolvePackageExports(
|
|
62
|
-
nodeModulesPath: string,
|
|
63
|
-
packageJson: PackageJson,
|
|
64
|
-
remainingPath: string,
|
|
65
|
-
ctx: NodeResolutionContext,
|
|
66
|
-
): string | null {
|
|
67
|
-
if (!packageJson.exports) return null
|
|
68
|
-
|
|
69
|
-
// Handle default export condition
|
|
70
|
-
const defaultExport = packageJson.exports["."]
|
|
71
|
-
if (remainingPath === "" && defaultExport) {
|
|
72
|
-
if (typeof defaultExport === "string") {
|
|
73
|
-
const resolved = resolveExportPath(nodeModulesPath, defaultExport, ctx)
|
|
74
|
-
if (resolved) return resolved
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Handle subpath exports
|
|
79
|
-
const subpathExport = remainingPath
|
|
80
|
-
? packageJson.exports[`./${remainingPath}`]
|
|
81
|
-
: null
|
|
82
|
-
if (subpathExport && typeof subpathExport === "string") {
|
|
83
|
-
const resolved = resolveExportPath(nodeModulesPath, subpathExport, ctx)
|
|
84
|
-
if (resolved) return resolved
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Handle conditional exports
|
|
88
|
-
const importExport = packageJson.exports["import"]
|
|
89
|
-
if (
|
|
90
|
-
remainingPath === "" &&
|
|
91
|
-
importExport &&
|
|
92
|
-
typeof importExport === "string"
|
|
93
|
-
) {
|
|
94
|
-
const resolved = resolveExportPath(nodeModulesPath, importExport, ctx)
|
|
95
|
-
if (resolved) return resolved
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return null
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function resolvePackageEntryPoint(
|
|
102
|
-
nodeModulesPath: string,
|
|
103
|
-
packageJson: PackageJson,
|
|
104
|
-
ctx: NodeResolutionContext,
|
|
105
|
-
): string | null {
|
|
106
|
-
const entryPoint = packageJson.module || packageJson.main || "index.js"
|
|
107
|
-
const fullPath = `${nodeModulesPath}/${entryPoint}`
|
|
108
|
-
return tryResolveWithExtensions(fullPath, ctx)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function resolveRemainingPath(
|
|
112
|
-
nodeModulesPath: string,
|
|
113
|
-
remainingPath: string,
|
|
114
|
-
ctx: NodeResolutionContext,
|
|
115
|
-
): string | null {
|
|
116
|
-
if (!remainingPath) {
|
|
117
|
-
// Try index files in the module root
|
|
118
|
-
for (const ext of ctx.extensions) {
|
|
119
|
-
const indexPath = `${nodeModulesPath}/index${ext}`
|
|
120
|
-
if (ctx.fsMap[indexPath]) return indexPath
|
|
121
|
-
}
|
|
122
|
-
return null
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const fullPath = `${nodeModulesPath}/${remainingPath}`
|
|
126
|
-
const directMatch = tryResolveWithExtensions(fullPath, ctx)
|
|
127
|
-
if (directMatch) return directMatch
|
|
128
|
-
|
|
129
|
-
// Try index files
|
|
130
|
-
for (const ext of ctx.extensions) {
|
|
131
|
-
const indexPath = `${fullPath}/index${ext}`
|
|
132
|
-
if (ctx.fsMap[indexPath]) return indexPath
|
|
133
|
-
}
|
|
134
|
-
return null
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function resolveNodeModuleInPath(
|
|
138
|
-
searchPath: string,
|
|
139
|
-
ctx: NodeResolutionContext,
|
|
140
|
-
): string | null {
|
|
141
|
-
const moduleParts = ctx.modulePath.split("/")
|
|
142
|
-
const scope = moduleParts[0].startsWith("@")
|
|
143
|
-
? moduleParts.slice(0, 2).join("/")
|
|
144
|
-
: moduleParts[0]
|
|
145
|
-
const remainingPath = moduleParts.slice(scope.includes("/") ? 2 : 1).join("/")
|
|
146
|
-
const nodeModulesPath = `${searchPath == "." ? "" : `${searchPath}/`}node_modules/${scope}`
|
|
147
|
-
|
|
148
|
-
// Try to find package.json
|
|
149
|
-
const packageJson = findPackageJson(nodeModulesPath, ctx)
|
|
150
|
-
if (packageJson) {
|
|
151
|
-
// Try resolving through exports field
|
|
152
|
-
const exportsResolution = resolvePackageExports(
|
|
153
|
-
nodeModulesPath,
|
|
154
|
-
packageJson,
|
|
155
|
-
remainingPath,
|
|
156
|
-
ctx,
|
|
157
|
-
)
|
|
158
|
-
if (exportsResolution) return exportsResolution
|
|
159
|
-
|
|
160
|
-
// Try resolving through main/module fields
|
|
161
|
-
const entryPointResolution = resolvePackageEntryPoint(
|
|
162
|
-
nodeModulesPath,
|
|
163
|
-
packageJson,
|
|
164
|
-
ctx,
|
|
165
|
-
)
|
|
166
|
-
if (entryPointResolution) return entryPointResolution
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Try resolving remaining path
|
|
170
|
-
const remainingPathResolution = resolveRemainingPath(
|
|
171
|
-
nodeModulesPath,
|
|
172
|
-
remainingPath,
|
|
173
|
-
ctx,
|
|
174
|
-
)
|
|
175
|
-
if (remainingPathResolution) return remainingPathResolution
|
|
176
|
-
|
|
177
|
-
// If not found and we have a parent directory, try there
|
|
178
|
-
const parentPath = dirname(searchPath)
|
|
179
|
-
if (parentPath && parentPath !== searchPath) {
|
|
180
|
-
return resolveNodeModuleInPath(parentPath, ctx)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return null
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export function resolveNodeModule(
|
|
187
|
-
modulePath: string,
|
|
188
|
-
fsMap: Record<string, string>,
|
|
189
|
-
basePath: string,
|
|
190
|
-
): string | null {
|
|
191
|
-
const ctx = createContext(modulePath, fsMap, basePath)
|
|
192
|
-
return resolveNodeModuleInPath(ctx.basePath, ctx)
|
|
193
|
-
}
|
package/lib/worker.ts
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import * as Comlink from "comlink"
|
|
2
|
-
export * from "./utils/index"
|
|
3
|
-
import type {
|
|
4
|
-
InternalWebWorkerApi,
|
|
5
|
-
WebWorkerConfiguration,
|
|
6
|
-
CircuitWebWorker,
|
|
7
|
-
} from "./shared/types"
|
|
8
|
-
import type { RootCircuitEventName } from "./shared/types"
|
|
9
|
-
|
|
10
|
-
export type { CircuitWebWorker, WebWorkerConfiguration }
|
|
11
|
-
|
|
12
|
-
declare global {
|
|
13
|
-
interface Window {
|
|
14
|
-
TSCIRCUIT_GLOBAL_CIRCUIT_WORKER: CircuitWebWorker | undefined
|
|
15
|
-
}
|
|
16
|
-
var TSCIRCUIT_GLOBAL_CIRCUIT_WORKER: CircuitWebWorker | undefined
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const createCircuitWebWorker = async (
|
|
20
|
-
configuration: Partial<WebWorkerConfiguration>,
|
|
21
|
-
): Promise<CircuitWebWorker> => {
|
|
22
|
-
// Kill existing global worker instance if present
|
|
23
|
-
const existingWorker = globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER
|
|
24
|
-
if (existingWorker && typeof existingWorker.kill === "function") {
|
|
25
|
-
if (configuration.verbose) {
|
|
26
|
-
console.log("[Worker] Killing previous global worker instance...")
|
|
27
|
-
}
|
|
28
|
-
try {
|
|
29
|
-
await existingWorker.kill()
|
|
30
|
-
} catch (e) {
|
|
31
|
-
if (configuration.verbose) {
|
|
32
|
-
console.warn(
|
|
33
|
-
"[Worker] Error killing previous global worker instance:",
|
|
34
|
-
e,
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
// Ensure the key is cleared even if kill throws an error
|
|
38
|
-
if (globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER === existingWorker) {
|
|
39
|
-
globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER = undefined
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (configuration.verbose) {
|
|
45
|
-
console.log(
|
|
46
|
-
"[Worker] Creating circuit web worker with config:",
|
|
47
|
-
configuration,
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
let workerBlobUrl =
|
|
52
|
-
configuration.webWorkerBlobUrl ?? configuration.webWorkerUrl
|
|
53
|
-
|
|
54
|
-
if (!workerBlobUrl) {
|
|
55
|
-
const cdnUrl = `https://cdn.jsdelivr.net/npm/@tscircuit/eval@${configuration.evalVersion ?? "latest"}/dist/webworker/entrypoint.js`
|
|
56
|
-
|
|
57
|
-
const workerBlob = await globalThis.fetch(cdnUrl).then((res) => res.blob())
|
|
58
|
-
workerBlobUrl = URL.createObjectURL(workerBlob)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const rawWorker = new Worker(workerBlobUrl, { type: "module" })
|
|
62
|
-
let workerInitError: any
|
|
63
|
-
rawWorker.addEventListener("error", (event) => {
|
|
64
|
-
console.error("[Worker] Error in worker", event)
|
|
65
|
-
workerInitError = event
|
|
66
|
-
})
|
|
67
|
-
rawWorker.addEventListener("unhandledrejection", (event) => {
|
|
68
|
-
console.error("[Worker] Unhandled rejection in worker", event)
|
|
69
|
-
})
|
|
70
|
-
rawWorker.addEventListener("messageerror", (event) => {
|
|
71
|
-
console.error("[Worker] Message error in worker", event)
|
|
72
|
-
})
|
|
73
|
-
const earlyMessageHandler = (event: MessageEvent) => {
|
|
74
|
-
console.log("[Worker] Message in worker", event)
|
|
75
|
-
}
|
|
76
|
-
rawWorker.addEventListener("message", earlyMessageHandler)
|
|
77
|
-
|
|
78
|
-
// Handle fetch requests from the worker
|
|
79
|
-
rawWorker.addEventListener("message", async (event: MessageEvent) => {
|
|
80
|
-
const data = event.data
|
|
81
|
-
if (data?.type !== "worker_fetch") return
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
const response = await globalThis.fetch(data.input, data.init)
|
|
85
|
-
const body = await response.text()
|
|
86
|
-
rawWorker.postMessage({
|
|
87
|
-
type: "worker_fetch_result",
|
|
88
|
-
requestId: data.requestId,
|
|
89
|
-
success: true,
|
|
90
|
-
response: {
|
|
91
|
-
body,
|
|
92
|
-
status: response.status,
|
|
93
|
-
statusText: response.statusText,
|
|
94
|
-
headers: (() => {
|
|
95
|
-
const obj: Record<string, string> = {}
|
|
96
|
-
response.headers.forEach((value, key) => {
|
|
97
|
-
obj[key] = value
|
|
98
|
-
})
|
|
99
|
-
return obj
|
|
100
|
-
})(),
|
|
101
|
-
},
|
|
102
|
-
})
|
|
103
|
-
} catch (err: any) {
|
|
104
|
-
rawWorker.postMessage({
|
|
105
|
-
type: "worker_fetch_result",
|
|
106
|
-
requestId: data.requestId,
|
|
107
|
-
success: false,
|
|
108
|
-
error: {
|
|
109
|
-
name: err.name,
|
|
110
|
-
message: err.message,
|
|
111
|
-
stack: err.stack,
|
|
112
|
-
},
|
|
113
|
-
})
|
|
114
|
-
}
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
if (workerInitError) {
|
|
118
|
-
throw workerInitError
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const comlinkWorker = Comlink.wrap<InternalWebWorkerApi>(rawWorker)
|
|
122
|
-
|
|
123
|
-
rawWorker.removeEventListener("message", earlyMessageHandler)
|
|
124
|
-
|
|
125
|
-
// Helper to serialize React elements for cross-worker communication
|
|
126
|
-
function serializeReactElement(element: any): any {
|
|
127
|
-
if (!element || typeof element !== "object") {
|
|
128
|
-
return element
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (element.type && element.props !== undefined) {
|
|
132
|
-
// This is a React element
|
|
133
|
-
return {
|
|
134
|
-
__isSerializedReactElement: true,
|
|
135
|
-
type: element.type,
|
|
136
|
-
props: serializeProps(element.props),
|
|
137
|
-
key: element.key,
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return element
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function serializeProps(props: any): any {
|
|
145
|
-
if (!props || typeof props !== "object") {
|
|
146
|
-
return props
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const serialized: any = {}
|
|
150
|
-
for (const [key, value] of Object.entries(props)) {
|
|
151
|
-
if (key === "children") {
|
|
152
|
-
if (Array.isArray(value)) {
|
|
153
|
-
serialized.children = value.map(serializeReactElement)
|
|
154
|
-
} else {
|
|
155
|
-
serialized.children = serializeReactElement(value)
|
|
156
|
-
}
|
|
157
|
-
} else {
|
|
158
|
-
serialized[key] = value
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return serialized
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Conditionally override global fetch inside the worker to route through the parent
|
|
165
|
-
// Only enable when explicitly requested via configuration
|
|
166
|
-
if (configuration.enableFetchProxy) {
|
|
167
|
-
rawWorker.postMessage({ type: "override_global_fetch" })
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (configuration.snippetsApiBaseUrl) {
|
|
171
|
-
await comlinkWorker.setSnippetsApiBaseUrl(configuration.snippetsApiBaseUrl)
|
|
172
|
-
}
|
|
173
|
-
if (configuration.platform) {
|
|
174
|
-
await comlinkWorker.setPlatformConfig(configuration.platform)
|
|
175
|
-
}
|
|
176
|
-
if (configuration.projectConfig) {
|
|
177
|
-
await comlinkWorker.setProjectConfig(configuration.projectConfig)
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
let isTerminated = false
|
|
181
|
-
|
|
182
|
-
// Create a wrapper that handles events directly through circuit instance
|
|
183
|
-
const wrapper: CircuitWebWorker = {
|
|
184
|
-
clearEventListeners: comlinkWorker.clearEventListeners.bind(comlinkWorker),
|
|
185
|
-
enableDebug: async (...args) => {
|
|
186
|
-
if (isTerminated) {
|
|
187
|
-
throw new Error("CircuitWebWorker was terminated, can't enableDebug")
|
|
188
|
-
}
|
|
189
|
-
return comlinkWorker.enableDebug.bind(comlinkWorker)(...args)
|
|
190
|
-
},
|
|
191
|
-
version: comlinkWorker.version.bind(comlinkWorker),
|
|
192
|
-
execute: async (...args) => {
|
|
193
|
-
if (isTerminated) {
|
|
194
|
-
throw new Error("CircuitWebWorker was terminated, can't execute")
|
|
195
|
-
}
|
|
196
|
-
return comlinkWorker.execute.bind(comlinkWorker)(...args)
|
|
197
|
-
},
|
|
198
|
-
executeComponent: async (component: any) => {
|
|
199
|
-
if (isTerminated) {
|
|
200
|
-
throw new Error(
|
|
201
|
-
"CircuitWebWorker was terminated, can't executeComponent",
|
|
202
|
-
)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// If it's a function, pass it as-is (will be proxied by Comlink)
|
|
206
|
-
if (typeof component === "function") {
|
|
207
|
-
return comlinkWorker.executeComponent.bind(comlinkWorker)(component)
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// If it's a React element, serialize it to a reconstructable format
|
|
211
|
-
if (component && typeof component === "object" && component.type) {
|
|
212
|
-
const serializedElement = serializeReactElement(component)
|
|
213
|
-
return comlinkWorker.executeComponent.bind(comlinkWorker)(
|
|
214
|
-
serializedElement,
|
|
215
|
-
)
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return comlinkWorker.executeComponent.bind(comlinkWorker)(component)
|
|
219
|
-
},
|
|
220
|
-
executeWithFsMap: async (...args) => {
|
|
221
|
-
if (isTerminated) {
|
|
222
|
-
throw new Error(
|
|
223
|
-
"CircuitWebWorker was terminated, can't executeWithFsMap",
|
|
224
|
-
)
|
|
225
|
-
}
|
|
226
|
-
return comlinkWorker.executeWithFsMap.bind(comlinkWorker)(...args)
|
|
227
|
-
},
|
|
228
|
-
renderUntilSettled: comlinkWorker.renderUntilSettled.bind(comlinkWorker),
|
|
229
|
-
getCircuitJson: comlinkWorker.getCircuitJson.bind(comlinkWorker),
|
|
230
|
-
on: (event: string, callback: (...args: any[]) => void) => {
|
|
231
|
-
const proxiedCallback = Comlink.proxy(callback)
|
|
232
|
-
comlinkWorker.on(event as RootCircuitEventName, proxiedCallback)
|
|
233
|
-
},
|
|
234
|
-
kill: async () => {
|
|
235
|
-
comlinkWorker[Comlink.releaseProxy]()
|
|
236
|
-
rawWorker.terminate()
|
|
237
|
-
isTerminated = true
|
|
238
|
-
if (globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER === wrapper) {
|
|
239
|
-
globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER = undefined
|
|
240
|
-
}
|
|
241
|
-
},
|
|
242
|
-
}
|
|
243
|
-
;(wrapper as any).__rawWorker = rawWorker
|
|
244
|
-
globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER = wrapper
|
|
245
|
-
return wrapper
|
|
246
|
-
}
|
package/playwright.config.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "@playwright/test"
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
testDir: "./browser-tests",
|
|
5
|
-
timeout: 30000,
|
|
6
|
-
expect: {
|
|
7
|
-
timeout: 5000,
|
|
8
|
-
},
|
|
9
|
-
fullyParallel: true,
|
|
10
|
-
forbidOnly: !!process.env.CI,
|
|
11
|
-
retries: process.env.CI ? 2 : 0,
|
|
12
|
-
workers: process.env.CI ? 1 : undefined,
|
|
13
|
-
reporter: "html",
|
|
14
|
-
use: {
|
|
15
|
-
actionTimeout: 0,
|
|
16
|
-
trace: "on-first-retry",
|
|
17
|
-
},
|
|
18
|
-
webServer: {
|
|
19
|
-
command: "bun run start:browser-test-server",
|
|
20
|
-
port: 3070,
|
|
21
|
-
reuseExistingServer: !process.env.CI,
|
|
22
|
-
},
|
|
23
|
-
})
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync } from "node:fs"
|
|
2
|
-
|
|
3
|
-
function createWorkerBlobCode(jsCode: string) {
|
|
4
|
-
// Convert the code to Base64 to avoid issues with special characters and newlines
|
|
5
|
-
const encodedCode = Buffer.from(jsCode).toString("base64")
|
|
6
|
-
|
|
7
|
-
// Create code that will construct a Blob URL from the Base64-encoded JavaScript
|
|
8
|
-
const blobCode = `
|
|
9
|
-
const decodedCode = atob("${encodedCode}")
|
|
10
|
-
const blob = new Blob([decodedCode], { type: "application/javascript" })
|
|
11
|
-
const blobUrl = URL.createObjectURL(blob)
|
|
12
|
-
export default blobUrl
|
|
13
|
-
`
|
|
14
|
-
|
|
15
|
-
return blobCode
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Generate the .d.ts file content
|
|
19
|
-
const typeDefinition = `declare const blobUrl: string
|
|
20
|
-
export default blobUrl
|
|
21
|
-
`
|
|
22
|
-
|
|
23
|
-
const workerCode = readFileSync("./dist/webworker/entrypoint.js", "utf-8")
|
|
24
|
-
const blobConstructorCode = createWorkerBlobCode(workerCode)
|
|
25
|
-
|
|
26
|
-
writeFileSync("./dist/blob-url.js", blobConstructorCode)
|
|
27
|
-
writeFileSync("./dist/blob-url.d.ts", typeDefinition)
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
import corePackageJson from "@tscircuit/core/package.json"
|
|
3
|
-
import currentPackageJson from "../package.json"
|
|
4
|
-
import { join } from "node:path"
|
|
5
|
-
|
|
6
|
-
const DONT_SYNC_FROM_CORE: string[] = []
|
|
7
|
-
|
|
8
|
-
const coreDeps: any = {
|
|
9
|
-
...corePackageJson.devDependencies,
|
|
10
|
-
...corePackageJson.dependencies,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const currentDeps: any = { ...currentPackageJson.devDependencies }
|
|
14
|
-
const depsToUpdate: any = {}
|
|
15
|
-
|
|
16
|
-
let modifiedDeps = false
|
|
17
|
-
|
|
18
|
-
// Update existing dependencies to match core
|
|
19
|
-
for (const [packageName, currentVersion] of Object.entries(currentDeps)) {
|
|
20
|
-
if (packageName in coreDeps && coreDeps[packageName] !== currentVersion) {
|
|
21
|
-
console.log(
|
|
22
|
-
`Updating ${packageName} from ${currentVersion} to ${coreDeps[packageName]}`,
|
|
23
|
-
)
|
|
24
|
-
depsToUpdate[packageName] = coreDeps[packageName as keyof typeof coreDeps]
|
|
25
|
-
modifiedDeps = true
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Add new dependencies from core that we don't have yet
|
|
30
|
-
for (const [packageName, version] of Object.entries(
|
|
31
|
-
corePackageJson.devDependencies || {},
|
|
32
|
-
)) {
|
|
33
|
-
if (
|
|
34
|
-
!DONT_SYNC_FROM_CORE.includes(packageName) &&
|
|
35
|
-
!(packageName in currentDeps)
|
|
36
|
-
) {
|
|
37
|
-
console.log(`Adding new dependency ${packageName}: ${version}`)
|
|
38
|
-
depsToUpdate[packageName] = version
|
|
39
|
-
modifiedDeps = true
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (modifiedDeps) {
|
|
44
|
-
// Use regex to replace the dependencies in the package.json
|
|
45
|
-
const packageJsonPath = join(import.meta.dirname, "../package.json")
|
|
46
|
-
let packageJson = await Bun.file(packageJsonPath).text()
|
|
47
|
-
|
|
48
|
-
// Update existing dependencies
|
|
49
|
-
for (const [packageName, version] of Object.entries(depsToUpdate)) {
|
|
50
|
-
if (packageName in currentDeps) {
|
|
51
|
-
const pattern = `"${packageName}":\\s*"${currentDeps[packageName].replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}"(,)?`
|
|
52
|
-
packageJson = packageJson.replace(
|
|
53
|
-
new RegExp(pattern),
|
|
54
|
-
`"${packageName}": "${version}"$1`,
|
|
55
|
-
)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Add new dependencies at the end of devDependencies
|
|
60
|
-
const newDeps = Object.entries(depsToUpdate).filter(
|
|
61
|
-
([packageName]) => !(packageName in currentDeps),
|
|
62
|
-
)
|
|
63
|
-
if (newDeps.length > 0) {
|
|
64
|
-
// Find the last dependency in devDependencies and add after it
|
|
65
|
-
const devDepsPattern = /"devDependencies":\s*{([^}]+)}/
|
|
66
|
-
const match = packageJson.match(devDepsPattern)
|
|
67
|
-
if (match) {
|
|
68
|
-
const devDepsContent = match[1]
|
|
69
|
-
const newDepsStr = newDeps
|
|
70
|
-
.map(([name, version]) => ` "${name}": "${version}"`)
|
|
71
|
-
.join(",\n")
|
|
72
|
-
const updatedDevDeps = `${devDepsContent.trimEnd()},\n${newDepsStr}`
|
|
73
|
-
packageJson = packageJson.replace(
|
|
74
|
-
devDepsPattern,
|
|
75
|
-
`"devDependencies": {${updatedDevDeps}}`,
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
await Bun.write(packageJsonPath, packageJson)
|
|
81
|
-
}
|