@tscircuit/eval 0.0.362 → 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/dist/blob-url.js +1 -1
- package/dist/webworker/entrypoint.js +120 -120
- package/package.json +7 -4
- 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,77 +0,0 @@
|
|
|
1
|
-
import { evalCompiledJs } from "./eval-compiled-js"
|
|
2
|
-
import type { ExecutionContext } from "./execution-context"
|
|
3
|
-
import { dirname } from "lib/utils/dirname"
|
|
4
|
-
import Debug from "debug"
|
|
5
|
-
import { getImportsFromCode } from "lib/utils/get-imports-from-code"
|
|
6
|
-
import { importEvalPath } from "./import-eval-path"
|
|
7
|
-
import { transformWithSucrase } from "./transform-with-sucrase"
|
|
8
|
-
|
|
9
|
-
const debug = Debug("tsci:eval:import-npm-package")
|
|
10
|
-
|
|
11
|
-
function extractPackagePathFromJSDelivr(url: string) {
|
|
12
|
-
const prefix = "https://cdn.jsdelivr.net/npm/"
|
|
13
|
-
if (url.startsWith(prefix)) {
|
|
14
|
-
return url.substring(prefix.length).replace(/\/\+esm$/, "")
|
|
15
|
-
}
|
|
16
|
-
return url
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export async function importNpmPackage(
|
|
20
|
-
importName: string,
|
|
21
|
-
ctx: ExecutionContext,
|
|
22
|
-
depth = 0,
|
|
23
|
-
) {
|
|
24
|
-
debug(`importing npm package: ${importName}`)
|
|
25
|
-
const { preSuppliedImports } = ctx
|
|
26
|
-
|
|
27
|
-
if (preSuppliedImports[importName]) return
|
|
28
|
-
|
|
29
|
-
const npmCdnUrl = `https://cdn.jsdelivr.net/npm/${importName}/+esm`
|
|
30
|
-
|
|
31
|
-
let finalUrl: string | undefined
|
|
32
|
-
const { content, error } = await globalThis
|
|
33
|
-
.fetch(npmCdnUrl)
|
|
34
|
-
.then(async (res) => {
|
|
35
|
-
finalUrl = res.url
|
|
36
|
-
if (!res.ok)
|
|
37
|
-
throw new Error(
|
|
38
|
-
`Could not fetch "${importName}" from jsdelivr: ${res.statusText}`,
|
|
39
|
-
)
|
|
40
|
-
return { content: await res.text(), error: null }
|
|
41
|
-
})
|
|
42
|
-
.catch((e) => ({ error: e, content: null }))
|
|
43
|
-
|
|
44
|
-
if (error) {
|
|
45
|
-
console.error("Error fetching npm import", importName, error)
|
|
46
|
-
throw error
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const finalImportName = extractPackagePathFromJSDelivr(finalUrl!)
|
|
50
|
-
const cwd = dirname(finalImportName)
|
|
51
|
-
|
|
52
|
-
const importNames = getImportsFromCode(content!)
|
|
53
|
-
for (const subImportName of importNames) {
|
|
54
|
-
if (!preSuppliedImports[subImportName]) {
|
|
55
|
-
await importEvalPath(subImportName, ctx, depth + 1, {
|
|
56
|
-
cwd,
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const transformedCode = transformWithSucrase(
|
|
62
|
-
content!,
|
|
63
|
-
finalImportName || importName,
|
|
64
|
-
)
|
|
65
|
-
try {
|
|
66
|
-
const exports = evalCompiledJs(
|
|
67
|
-
transformedCode,
|
|
68
|
-
preSuppliedImports,
|
|
69
|
-
cwd,
|
|
70
|
-
).exports
|
|
71
|
-
preSuppliedImports[importName] = exports
|
|
72
|
-
preSuppliedImports[finalImportName] = exports
|
|
73
|
-
preSuppliedImports[finalUrl!] = exports
|
|
74
|
-
} catch (e: any) {
|
|
75
|
-
throw new Error(`Eval npm package error for "${importName}": ${e.message}`)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { evalCompiledJs } from "./eval-compiled-js"
|
|
2
|
-
import type { ExecutionContext } from "./execution-context"
|
|
3
|
-
|
|
4
|
-
export async function importSnippet(
|
|
5
|
-
importName: string,
|
|
6
|
-
ctx: ExecutionContext,
|
|
7
|
-
depth = 0,
|
|
8
|
-
) {
|
|
9
|
-
const { preSuppliedImports } = ctx
|
|
10
|
-
const fullSnippetName = importName.replace("@tsci/", "").replace(".", "/")
|
|
11
|
-
|
|
12
|
-
const { cjs, error } = await globalThis
|
|
13
|
-
.fetch(`${ctx.cjsRegistryUrl}/${fullSnippetName}`)
|
|
14
|
-
.then(async (res) => ({ cjs: await res.text(), error: null }))
|
|
15
|
-
.catch((e) => ({ error: e, cjs: null }))
|
|
16
|
-
|
|
17
|
-
if (error) {
|
|
18
|
-
console.error("Error fetching import", importName, error)
|
|
19
|
-
return
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
preSuppliedImports[importName] = evalCompiledJs(
|
|
24
|
-
cjs!,
|
|
25
|
-
preSuppliedImports,
|
|
26
|
-
).exports
|
|
27
|
-
} catch (e) {
|
|
28
|
-
console.error("Error importing snippet", e)
|
|
29
|
-
}
|
|
30
|
-
}
|
package/webworker/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./entrypoint"
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { transform, type Transform as SucraseTransform } from "sucrase"
|
|
2
|
-
|
|
3
|
-
const TS_EXTENSIONS = new Set([".ts", ".tsx", ".mts", ".cts"])
|
|
4
|
-
const JSX_EXTENSIONS = new Set([".tsx", ".jsx", ".ts"])
|
|
5
|
-
|
|
6
|
-
const stripQueryAndHash = (filePath: string) => {
|
|
7
|
-
const queryIndex = filePath.indexOf("?")
|
|
8
|
-
const hashIndex = filePath.indexOf("#")
|
|
9
|
-
|
|
10
|
-
let endIndex = filePath.length
|
|
11
|
-
|
|
12
|
-
if (queryIndex !== -1 && hashIndex !== -1) {
|
|
13
|
-
endIndex = Math.min(queryIndex, hashIndex)
|
|
14
|
-
} else if (queryIndex !== -1) {
|
|
15
|
-
endIndex = queryIndex
|
|
16
|
-
} else if (hashIndex !== -1) {
|
|
17
|
-
endIndex = hashIndex
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return filePath.slice(0, endIndex)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const getExtension = (filePath: string) => {
|
|
24
|
-
const normalizedPath = stripQueryAndHash(filePath)
|
|
25
|
-
const lastDotIndex = normalizedPath.lastIndexOf(".")
|
|
26
|
-
|
|
27
|
-
if (lastDotIndex === -1) {
|
|
28
|
-
return ""
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const lastSlashIndex = Math.max(
|
|
32
|
-
normalizedPath.lastIndexOf("/"),
|
|
33
|
-
normalizedPath.lastIndexOf("\\"),
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
if (lastSlashIndex > lastDotIndex) {
|
|
37
|
-
return ""
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return normalizedPath.slice(lastDotIndex).toLowerCase()
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const getTransformsForFilePath = (filePath: string) => {
|
|
44
|
-
const extension = getExtension(filePath)
|
|
45
|
-
|
|
46
|
-
const transforms: SucraseTransform[] = ["imports"]
|
|
47
|
-
|
|
48
|
-
if (TS_EXTENSIONS.has(extension)) {
|
|
49
|
-
transforms.unshift("typescript")
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (JSX_EXTENSIONS.has(extension)) {
|
|
53
|
-
transforms.push("jsx")
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return transforms
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const transformWithSucrase = (code: string, filePath: string) => {
|
|
60
|
-
const transforms = getTransformsForFilePath(filePath)
|
|
61
|
-
const { code: transformedCode } = transform(code, {
|
|
62
|
-
filePath,
|
|
63
|
-
production: true,
|
|
64
|
-
transforms,
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
return transformedCode
|
|
68
|
-
}
|