@typecad/cuttlefish 0.1.0-alpha.1
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/LICENSE +21 -0
- package/README.md +79 -0
- package/dist/api/board-types.d.ts +1 -0
- package/dist/api/board-types.js +4 -0
- package/dist/api/capabilities.d.ts +12 -0
- package/dist/api/capabilities.js +1 -0
- package/dist/api/config.d.ts +120 -0
- package/dist/api/config.js +7 -0
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.js +2 -0
- package/dist/api/schema/builder.d.ts +14 -0
- package/dist/api/schema/builder.js +15 -0
- package/dist/api/schema/index.d.ts +2 -0
- package/dist/api/schema/index.js +1 -0
- package/dist/api/schema/types.d.ts +257 -0
- package/dist/api/schema/types.js +4 -0
- package/dist/api/shared/async-runtime-static.d.ts +8 -0
- package/dist/api/shared/async-runtime-static.js +201 -0
- package/dist/api/shared/async-types.d.ts +42 -0
- package/dist/api/shared/async-types.js +8 -0
- package/dist/api/shared/board-resolver.d.ts +12 -0
- package/dist/api/shared/board-resolver.js +7 -0
- package/dist/api/shared/cpp-type-ir.d.ts +229 -0
- package/dist/api/shared/cpp-type-ir.js +672 -0
- package/dist/api/shared/display-adapter.d.ts +12 -0
- package/dist/api/shared/display-adapter.js +145 -0
- package/dist/api/shared/display-adapters/eink-mono.d.ts +2 -0
- package/dist/api/shared/display-adapters/eink-mono.js +53 -0
- package/dist/api/shared/display-adapters/sdl.d.ts +2 -0
- package/dist/api/shared/display-adapters/sdl.js +452 -0
- package/dist/api/shared/display-adapters/ssd1309.d.ts +2 -0
- package/dist/api/shared/display-adapters/ssd1309.js +136 -0
- package/dist/api/shared/display-adapters/st7796.d.ts +2 -0
- package/dist/api/shared/display-adapters/st7796.js +132 -0
- package/dist/api/shared/display-capabilities.d.ts +45 -0
- package/dist/api/shared/display-capabilities.js +54 -0
- package/dist/api/shared/display-op-ir.d.ts +62 -0
- package/dist/api/shared/display-op-ir.js +19 -0
- package/dist/api/shared/display-profile.d.ts +265 -0
- package/dist/api/shared/display-profile.js +338 -0
- package/dist/api/shared/graphics-strategy.d.ts +29 -0
- package/dist/api/shared/graphics-strategy.js +11 -0
- package/dist/api/shared/hal-op-ir.d.ts +393 -0
- package/dist/api/shared/hal-op-ir.js +18 -0
- package/dist/api/shared/index.d.ts +26 -0
- package/dist/api/shared/index.js +21 -0
- package/dist/api/shared/ir-core.d.ts +363 -0
- package/dist/api/shared/ir-core.js +8 -0
- package/dist/api/shared/ir-declarations.d.ts +201 -0
- package/dist/api/shared/ir-declarations.js +26 -0
- package/dist/api/shared/ir.d.ts +85 -0
- package/dist/api/shared/ir.js +13 -0
- package/dist/api/shared/platform-strategy.d.ts +402 -0
- package/dist/api/shared/platform-strategy.js +14 -0
- package/dist/api/shared/polyfill-helper-registry.d.ts +11 -0
- package/dist/api/shared/polyfill-helper-registry.js +86 -0
- package/dist/api/shared/polyfill-types.d.ts +33 -0
- package/dist/api/shared/polyfill-types.js +76 -0
- package/dist/api/shared/promise-runtime.d.ts +10 -0
- package/dist/api/shared/promise-runtime.js +244 -0
- package/dist/api/shared/snprintf-types.d.ts +29 -0
- package/dist/api/shared/snprintf-types.js +8 -0
- package/dist/api/shared/string-method-registry.d.ts +53 -0
- package/dist/api/shared/string-method-registry.js +168 -0
- package/dist/api/shared/toolchain-types.d.ts +63 -0
- package/dist/api/shared/toolchain-types.js +71 -0
- package/dist/api/shared/types.d.ts +50 -0
- package/dist/api/shared/types.js +6 -0
- package/dist/ast/parse.d.ts +2 -0
- package/dist/ast/parse.js +4 -0
- package/dist/cache.d.ts +26 -0
- package/dist/cache.js +95 -0
- package/dist/cli-utils.d.ts +37 -0
- package/dist/cli-utils.js +250 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +635 -0
- package/dist/config-loader.d.ts +78 -0
- package/dist/config-loader.js +508 -0
- package/dist/config-schema.d.ts +233 -0
- package/dist/config-schema.js +83 -0
- package/dist/create/board-checklist.d.ts +2 -0
- package/dist/create/board-checklist.js +52 -0
- package/dist/create/board-codegen.d.ts +9 -0
- package/dist/create/board-codegen.js +238 -0
- package/dist/create/board-generators.d.ts +12 -0
- package/dist/create/board-generators.js +652 -0
- package/dist/create/board-spec.d.ts +640 -0
- package/dist/create/board-spec.js +215 -0
- package/dist/create/eslint-rules-template.d.ts +2 -0
- package/dist/create/eslint-rules-template.js +672 -0
- package/dist/create/index.d.ts +11 -0
- package/dist/create/index.js +8 -0
- package/dist/create/init-scaffold.d.ts +27 -0
- package/dist/create/init-scaffold.js +150 -0
- package/dist/create/init-templates.d.ts +24 -0
- package/dist/create/init-templates.js +379 -0
- package/dist/create/init-wizard.d.ts +8 -0
- package/dist/create/init-wizard.js +168 -0
- package/dist/debug/breakpoint-loader.d.ts +24 -0
- package/dist/debug/breakpoint-loader.js +137 -0
- package/dist/debug/index.d.ts +3 -0
- package/dist/debug/index.js +7 -0
- package/dist/debug/preprocessor.d.ts +9 -0
- package/dist/debug/preprocessor.js +214 -0
- package/dist/debug/types.d.ts +32 -0
- package/dist/debug/types.js +6 -0
- package/dist/diagnostics/diagnostics-report.d.ts +51 -0
- package/dist/diagnostics/diagnostics-report.js +333 -0
- package/dist/diagnostics/json-schema.d.ts +138 -0
- package/dist/diagnostics/json-schema.js +27 -0
- package/dist/diagnostics/md-writer.d.ts +10 -0
- package/dist/diagnostics/md-writer.js +336 -0
- package/dist/diagnostics/mermaid-builder.d.ts +65 -0
- package/dist/diagnostics/mermaid-builder.js +681 -0
- package/dist/emit/cpp-emitter.d.ts +6 -0
- package/dist/emit/cpp-emitter.js +48 -0
- package/dist/emit/emitters/class-emitter.d.ts +2 -0
- package/dist/emit/emitters/class-emitter.js +523 -0
- package/dist/emit/emitters/emitter-context.d.ts +174 -0
- package/dist/emit/emitters/emitter-context.js +1 -0
- package/dist/emit/emitters/entrypoint-synthesizer.d.ts +2 -0
- package/dist/emit/emitters/entrypoint-synthesizer.js +175 -0
- package/dist/emit/emitters/function-emitter-impl.d.ts +19 -0
- package/dist/emit/emitters/function-emitter-impl.js +428 -0
- package/dist/emit/emitters/line-appender.d.ts +15 -0
- package/dist/emit/emitters/line-appender.js +344 -0
- package/dist/emit/emitters/namespace-emitter.d.ts +2 -0
- package/dist/emit/emitters/namespace-emitter.js +324 -0
- package/dist/emit/emitters/output-finalizer.d.ts +4 -0
- package/dist/emit/emitters/output-finalizer.js +267 -0
- package/dist/emit/emitters/setup.d.ts +3 -0
- package/dist/emit/emitters/setup.js +851 -0
- package/dist/emit/emitters/top-level-prep.d.ts +2 -0
- package/dist/emit/emitters/top-level-prep.js +706 -0
- package/dist/emit/emitters/type-decl-emitter.d.ts +2 -0
- package/dist/emit/emitters/type-decl-emitter.js +251 -0
- package/dist/emit/emitters/ui-emitter.d.ts +21 -0
- package/dist/emit/emitters/ui-emitter.js +564 -0
- package/dist/emit/enum-emitter.d.ts +1 -0
- package/dist/emit/enum-emitter.js +1 -0
- package/dist/emit/expression-renderer.d.ts +283 -0
- package/dist/emit/expression-renderer.js +1477 -0
- package/dist/emit/native-helpers-emitter.d.ts +11 -0
- package/dist/emit/native-helpers-emitter.js +34 -0
- package/dist/emit/route-hal-op.d.ts +5 -0
- package/dist/emit/route-hal-op.js +13 -0
- package/dist/emit/snprintf-helpers.d.ts +17 -0
- package/dist/emit/snprintf-helpers.js +462 -0
- package/dist/emit/statement-renderer.d.ts +189 -0
- package/dist/emit/statement-renderer.js +948 -0
- package/dist/emit/utils/async-state-machine.d.ts +42 -0
- package/dist/emit/utils/async-state-machine.js +343 -0
- package/dist/emit/utils/comment-helpers.d.ts +20 -0
- package/dist/emit/utils/comment-helpers.js +31 -0
- package/dist/emit/utils/cpp-helpers.d.ts +47 -0
- package/dist/emit/utils/cpp-helpers.js +85 -0
- package/dist/emit/utils/include-resolver.d.ts +58 -0
- package/dist/emit/utils/include-resolver.js +155 -0
- package/dist/emit/utils/index.d.ts +8 -0
- package/dist/emit/utils/index.js +12 -0
- package/dist/emit/utils/type-inference.d.ts +159 -0
- package/dist/emit/utils/type-inference.js +559 -0
- package/dist/eslint-check.d.ts +10 -0
- package/dist/eslint-check.js +102 -0
- package/dist/framework-package.d.ts +10 -0
- package/dist/framework-package.js +58 -0
- package/dist/framework-registry.d.ts +39 -0
- package/dist/framework-registry.js +30 -0
- package/dist/incremental-cache.d.ts +116 -0
- package/dist/incremental-cache.js +335 -0
- package/dist/ir/adc-range-validation.d.ts +11 -0
- package/dist/ir/adc-range-validation.js +250 -0
- package/dist/ir/ast-node-utils.d.ts +8 -0
- package/dist/ir/ast-node-utils.js +32 -0
- package/dist/ir/board-pin-utils.d.ts +13 -0
- package/dist/ir/board-pin-utils.js +65 -0
- package/dist/ir/board-resolver.d.ts +36 -0
- package/dist/ir/board-resolver.js +437 -0
- package/dist/ir/build-ir-state.d.ts +167 -0
- package/dist/ir/build-ir-state.js +306 -0
- package/dist/ir/build-ir.d.ts +2 -0
- package/dist/ir/build-ir.js +808 -0
- package/dist/ir/call-graph.d.ts +35 -0
- package/dist/ir/call-graph.js +194 -0
- package/dist/ir/compile-time-only.d.ts +2 -0
- package/dist/ir/compile-time-only.js +16 -0
- package/dist/ir/declaration-builders.d.ts +9 -0
- package/dist/ir/declaration-builders.js +608 -0
- package/dist/ir/entry-points.d.ts +30 -0
- package/dist/ir/entry-points.js +191 -0
- package/dist/ir/expression-to-ir.d.ts +5 -0
- package/dist/ir/expression-to-ir.js +2249 -0
- package/dist/ir/extract-property-chain.d.ts +10 -0
- package/dist/ir/extract-property-chain.js +30 -0
- package/dist/ir/feature-prescan.d.ts +3 -0
- package/dist/ir/feature-prescan.js +43 -0
- package/dist/ir/feature-registry.d.ts +30 -0
- package/dist/ir/feature-registry.js +816 -0
- package/dist/ir/filter.d.ts +7 -0
- package/dist/ir/filter.js +85 -0
- package/dist/ir/function-builder.d.ts +19 -0
- package/dist/ir/function-builder.js +670 -0
- package/dist/ir/hal/hal-emitter.d.ts +62 -0
- package/dist/ir/hal/hal-emitter.js +735 -0
- package/dist/ir/hal/hal-parser.d.ts +61 -0
- package/dist/ir/hal/hal-parser.js +473 -0
- package/dist/ir/hal/hal-plugins.d.ts +34 -0
- package/dist/ir/hal/hal-plugins.js +706 -0
- package/dist/ir/hal-resolver.d.ts +5 -0
- package/dist/ir/hal-resolver.js +5 -0
- package/dist/ir/heap-analysis.d.ts +8 -0
- package/dist/ir/heap-analysis.js +350 -0
- package/dist/ir/heap-array-validation.d.ts +24 -0
- package/dist/ir/heap-array-validation.js +29 -0
- package/dist/ir/identifier-collector.d.ts +18 -0
- package/dist/ir/identifier-collector.js +439 -0
- package/dist/ir/interrupt-analysis.d.ts +39 -0
- package/dist/ir/interrupt-analysis.js +467 -0
- package/dist/ir/memory-budget-validation.d.ts +10 -0
- package/dist/ir/memory-budget-validation.js +86 -0
- package/dist/ir/namespace-builder.d.ts +7 -0
- package/dist/ir/namespace-builder.js +152 -0
- package/dist/ir/ownership-analysis.d.ts +9 -0
- package/dist/ir/ownership-analysis.js +1207 -0
- package/dist/ir/peripheral-ownership.d.ts +3 -0
- package/dist/ir/peripheral-ownership.js +152 -0
- package/dist/ir/peripheral-symbols.d.ts +7 -0
- package/dist/ir/peripheral-symbols.js +57 -0
- package/dist/ir/peripheral-usage.d.ts +54 -0
- package/dist/ir/peripheral-usage.js +691 -0
- package/dist/ir/peripheral-validation.d.ts +8 -0
- package/dist/ir/peripheral-validation.js +77 -0
- package/dist/ir/pin-alias-conflict.d.ts +4 -0
- package/dist/ir/pin-alias-conflict.js +34 -0
- package/dist/ir/pin-capability-validation.d.ts +6 -0
- package/dist/ir/pin-capability-validation.js +413 -0
- package/dist/ir/pin-mode-validation.d.ts +10 -0
- package/dist/ir/pin-mode-validation.js +301 -0
- package/dist/ir/pin-safety.d.ts +11 -0
- package/dist/ir/pin-safety.js +58 -0
- package/dist/ir/program-analysis.d.ts +44 -0
- package/dist/ir/program-analysis.js +589 -0
- package/dist/ir/pulldown-validation.d.ts +7 -0
- package/dist/ir/pulldown-validation.js +49 -0
- package/dist/ir/pwm-timer-sharing.d.ts +4 -0
- package/dist/ir/pwm-timer-sharing.js +93 -0
- package/dist/ir/reachability.d.ts +68 -0
- package/dist/ir/reachability.js +224 -0
- package/dist/ir/register-decorators.d.ts +6 -0
- package/dist/ir/register-decorators.js +49 -0
- package/dist/ir/render-expr.d.ts +4 -0
- package/dist/ir/render-expr.js +127 -0
- package/dist/ir/resource-analysis.d.ts +19 -0
- package/dist/ir/resource-analysis.js +153 -0
- package/dist/ir/statement-to-ir.d.ts +23 -0
- package/dist/ir/statement-to-ir.js +349 -0
- package/dist/ir/symbol-table.d.ts +68 -0
- package/dist/ir/symbol-table.js +179 -0
- package/dist/ir/symbol-types.d.ts +56 -0
- package/dist/ir/symbol-types.js +107 -0
- package/dist/ir/timer0-pwm-timing-conflict.d.ts +4 -0
- package/dist/ir/timer0-pwm-timing-conflict.js +71 -0
- package/dist/ir/timing-validation.d.ts +7 -0
- package/dist/ir/timing-validation.js +95 -0
- package/dist/ir/transformers/array-methods.d.ts +8 -0
- package/dist/ir/transformers/array-methods.js +493 -0
- package/dist/ir/transformers/call-statement.d.ts +5 -0
- package/dist/ir/transformers/call-statement.js +758 -0
- package/dist/ir/transformers/callback-context-registry.d.ts +20 -0
- package/dist/ir/transformers/callback-context-registry.js +55 -0
- package/dist/ir/transformers/canvas-lowering.d.ts +42 -0
- package/dist/ir/transformers/canvas-lowering.js +249 -0
- package/dist/ir/transformers/control-flow.d.ts +8 -0
- package/dist/ir/transformers/control-flow.js +508 -0
- package/dist/ir/transformers/expressions.d.ts +7 -0
- package/dist/ir/transformers/expressions.js +406 -0
- package/dist/ir/transformers/hal-call-resolver.d.ts +29 -0
- package/dist/ir/transformers/hal-call-resolver.js +274 -0
- package/dist/ir/transformers/hal-emit-helpers.d.ts +14 -0
- package/dist/ir/transformers/hal-emit-helpers.js +63 -0
- package/dist/ir/transformers/namespace-methods.d.ts +20 -0
- package/dist/ir/transformers/namespace-methods.js +110 -0
- package/dist/ir/transformers/register-assignment.d.ts +5 -0
- package/dist/ir/transformers/register-assignment.js +56 -0
- package/dist/ir/transformers/ui-call-resolver.d.ts +149 -0
- package/dist/ir/transformers/ui-call-resolver.js +1136 -0
- package/dist/ir/transformers/ui-callback-lowering.d.ts +62 -0
- package/dist/ir/transformers/ui-callback-lowering.js +623 -0
- package/dist/ir/transformers/ui-mount.d.ts +20 -0
- package/dist/ir/transformers/ui-mount.js +35 -0
- package/dist/ir/transformers/ui-reactive.d.ts +68 -0
- package/dist/ir/transformers/ui-reactive.js +129 -0
- package/dist/ir/transformers/variables.d.ts +14 -0
- package/dist/ir/transformers/variables.js +1045 -0
- package/dist/ir/try-catch-validation.d.ts +26 -0
- package/dist/ir/try-catch-validation.js +128 -0
- package/dist/ir/type-resolution.d.ts +31 -0
- package/dist/ir/type-resolution.js +977 -0
- package/dist/ir/ui-element-auto-wire.d.ts +50 -0
- package/dist/ir/ui-element-auto-wire.js +218 -0
- package/dist/ir/unit-suspicion-validation.d.ts +12 -0
- package/dist/ir/unit-suspicion-validation.js +296 -0
- package/dist/ir/utils/walk-ir.d.ts +6 -0
- package/dist/ir/utils/walk-ir.js +162 -0
- package/dist/ir/validation-orchestrator.d.ts +4 -0
- package/dist/ir/validation-orchestrator.js +45 -0
- package/dist/libdef/base-class-resolver.d.ts +23 -0
- package/dist/libdef/base-class-resolver.js +50 -0
- package/dist/libdef/cpp-to-decl.d.ts +34 -0
- package/dist/libdef/cpp-to-decl.js +584 -0
- package/dist/libdef/header-parser.d.ts +53 -0
- package/dist/libdef/header-parser.js +269 -0
- package/dist/libdef/registry.d.ts +10 -0
- package/dist/libdef/registry.js +142 -0
- package/dist/mapping/peripheral-names.d.ts +23 -0
- package/dist/mapping/peripheral-names.js +63 -0
- package/dist/mapping/source-map.d.ts +46 -0
- package/dist/mapping/source-map.js +207 -0
- package/dist/orchestrator/dts-generator.d.ts +17 -0
- package/dist/orchestrator/dts-generator.js +83 -0
- package/dist/orchestrator/graph-builder.d.ts +18 -0
- package/dist/orchestrator/graph-builder.js +218 -0
- package/dist/orchestrator/semantic-facts-verifier.d.ts +38 -0
- package/dist/orchestrator/semantic-facts-verifier.js +121 -0
- package/dist/orchestrator/semantic-facts.d.ts +141 -0
- package/dist/orchestrator/semantic-facts.js +652 -0
- package/dist/orchestrator/type-checker.d.ts +39 -0
- package/dist/orchestrator/type-checker.js +760 -0
- package/dist/platform/async-runtime.d.ts +8 -0
- package/dist/platform/async-runtime.js +26 -0
- package/dist/platform/generic-strategy.d.ts +101 -0
- package/dist/platform/generic-strategy.js +289 -0
- package/dist/platform/index.d.ts +4 -0
- package/dist/platform/index.js +9 -0
- package/dist/platform/registry.d.ts +21 -0
- package/dist/platform/registry.js +42 -0
- package/dist/platform/toolchain.d.ts +4 -0
- package/dist/platform/toolchain.js +43 -0
- package/dist/preview/client.d.ts +1 -0
- package/dist/preview/client.js +137 -0
- package/dist/preview/server.d.ts +5 -0
- package/dist/preview/server.js +199 -0
- package/dist/profiler/index.d.ts +28 -0
- package/dist/profiler/index.js +28 -0
- package/dist/profiler/profiler.d.ts +95 -0
- package/dist/profiler/profiler.js +338 -0
- package/dist/profiler/types.d.ts +87 -0
- package/dist/profiler/types.js +12 -0
- package/dist/stores/display-profile-store.d.ts +16 -0
- package/dist/stores/display-profile-store.js +48 -0
- package/dist/stores/theme-store.d.ts +13 -0
- package/dist/stores/theme-store.js +30 -0
- package/dist/testing.d.ts +45 -0
- package/dist/testing.js +47 -0
- package/dist/transpile/resolution.d.ts +29 -0
- package/dist/transpile/resolution.js +282 -0
- package/dist/transpile.d.ts +3 -0
- package/dist/transpile.js +722 -0
- package/dist/types.d.ts +217 -0
- package/dist/types.js +1 -0
- package/dist/ui/ui-bridge.d.ts +4 -0
- package/dist/ui/ui-bridge.js +34 -0
- package/dist/ui-hook.d.ts +84 -0
- package/dist/ui-hook.js +45 -0
- package/dist/utils/cli.d.ts +3 -0
- package/dist/utils/cli.js +463 -0
- package/dist/utils/fs.d.ts +4 -0
- package/dist/utils/fs.js +23 -0
- package/dist/utils/logger.d.ts +2 -0
- package/dist/utils/logger.js +8 -0
- package/dist/utils/strings.d.ts +35 -0
- package/dist/utils/strings.js +142 -0
- package/dist/utils/ui.d.ts +66 -0
- package/dist/utils/ui.js +149 -0
- package/dist/watch.d.ts +35 -0
- package/dist/watch.js +111 -0
- package/package.json +127 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
function resolveLocalImport(fromFile, moduleSpecifier) {
|
|
4
|
+
if (!moduleSpecifier.startsWith(".")) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
let normalizedSpecifier = moduleSpecifier;
|
|
8
|
+
if (normalizedSpecifier.endsWith(".js")) {
|
|
9
|
+
normalizedSpecifier = normalizedSpecifier.slice(0, -3) + ".ts";
|
|
10
|
+
}
|
|
11
|
+
else if (normalizedSpecifier.endsWith(".mjs")) {
|
|
12
|
+
normalizedSpecifier = normalizedSpecifier.slice(0, -5) + ".ts";
|
|
13
|
+
}
|
|
14
|
+
const basePath = path.resolve(path.dirname(fromFile), normalizedSpecifier);
|
|
15
|
+
const candidates = [
|
|
16
|
+
basePath,
|
|
17
|
+
`${basePath}.ts`,
|
|
18
|
+
`${basePath}.tsx`,
|
|
19
|
+
path.join(basePath, "index.ts"),
|
|
20
|
+
path.join(basePath, "index.tsx"),
|
|
21
|
+
];
|
|
22
|
+
for (const candidate of candidates) {
|
|
23
|
+
if (!fs.existsSync(candidate) || !fs.statSync(candidate).isFile()) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const extension = path.extname(candidate).toLowerCase();
|
|
27
|
+
if (extension === ".ts" || extension === ".tsx") {
|
|
28
|
+
return path.resolve(candidate);
|
|
29
|
+
}
|
|
30
|
+
// .ui.html resolves as a UI module (not TypeScript). Only the .ui.html
|
|
31
|
+
// convention is accepted — plain .html is not a UI module.
|
|
32
|
+
if (candidate.toLowerCase().endsWith(".ui.html")) {
|
|
33
|
+
return path.resolve(candidate);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
function parseModuleSpecifier(moduleSpecifier) {
|
|
39
|
+
const parts = moduleSpecifier.split("/");
|
|
40
|
+
if (moduleSpecifier.startsWith("@")) {
|
|
41
|
+
const scope = parts[0];
|
|
42
|
+
const packageName = parts.length > 1 ? `${scope}/${parts[1]}` : scope;
|
|
43
|
+
const subpath = parts.length > 2 ? parts.slice(2).join("/") : "";
|
|
44
|
+
return { packageName, subpath };
|
|
45
|
+
}
|
|
46
|
+
const packageName = parts[0];
|
|
47
|
+
const subpath = parts.length > 1 ? parts.slice(1).join("/") : "";
|
|
48
|
+
return { packageName, subpath };
|
|
49
|
+
}
|
|
50
|
+
function findNodeModulesPackage(fromFile, packageName) {
|
|
51
|
+
let currentDir = path.dirname(path.resolve(fromFile));
|
|
52
|
+
while (currentDir !== path.dirname(currentDir)) {
|
|
53
|
+
const packageDir = path.join(currentDir, "node_modules", packageName);
|
|
54
|
+
if (fs.existsSync(packageDir) && fs.statSync(packageDir).isDirectory()) {
|
|
55
|
+
return packageDir;
|
|
56
|
+
}
|
|
57
|
+
currentDir = path.dirname(currentDir);
|
|
58
|
+
}
|
|
59
|
+
const rootPackageDir = path.join(currentDir, "node_modules", packageName);
|
|
60
|
+
if (fs.existsSync(rootPackageDir) && fs.statSync(rootPackageDir).isDirectory()) {
|
|
61
|
+
return rootPackageDir;
|
|
62
|
+
}
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
function readPackageJson(packageDir) {
|
|
66
|
+
const packageJsonPath = path.join(packageDir, "package.json");
|
|
67
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
const content = fs.readFileSync(packageJsonPath, "utf8");
|
|
72
|
+
return JSON.parse(content);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function resolvePackageExports(packageDir, subpath, packageJson) {
|
|
79
|
+
const exportsField = packageJson["exports"];
|
|
80
|
+
if (!exportsField || typeof exportsField !== "object") {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
const exportKey = subpath ? `./${subpath}` : ".";
|
|
84
|
+
let exportTarget = exportsField[exportKey];
|
|
85
|
+
if (exportTarget && typeof exportTarget === "object") {
|
|
86
|
+
const conditional = exportTarget;
|
|
87
|
+
exportTarget = conditional["types"] ?? conditional["import"] ?? conditional["default"];
|
|
88
|
+
}
|
|
89
|
+
if (typeof exportTarget !== "string") {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
return mapDistToSource(packageDir, exportTarget, subpath);
|
|
93
|
+
}
|
|
94
|
+
function mapDistToSource(packageDir, distPath, subpath) {
|
|
95
|
+
const relativePath = distPath.startsWith("./") ? distPath.slice(2) : distPath;
|
|
96
|
+
let sourcePath;
|
|
97
|
+
const packagesMatch = relativePath.match(/^dist\/(packages\/[^/]+\/src\/.+)\.js$/);
|
|
98
|
+
if (packagesMatch) {
|
|
99
|
+
sourcePath = path.join(packageDir, packagesMatch[1] + ".ts");
|
|
100
|
+
if (fs.existsSync(sourcePath)) {
|
|
101
|
+
return sourcePath;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const distSrcMatch = relativePath.match(/^dist\/(src\/.+)\.js$/);
|
|
105
|
+
if (distSrcMatch) {
|
|
106
|
+
sourcePath = path.join(packageDir, distSrcMatch[1] + ".ts");
|
|
107
|
+
if (fs.existsSync(sourcePath)) {
|
|
108
|
+
return sourcePath;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const distMatch = relativePath.match(/^dist\/(.+)\.js$/);
|
|
112
|
+
if (distMatch) {
|
|
113
|
+
sourcePath = path.join(packageDir, "src", distMatch[1] + ".ts");
|
|
114
|
+
if (fs.existsSync(sourcePath)) {
|
|
115
|
+
return sourcePath;
|
|
116
|
+
}
|
|
117
|
+
sourcePath = path.join(packageDir, distMatch[1] + ".ts");
|
|
118
|
+
if (fs.existsSync(sourcePath)) {
|
|
119
|
+
return sourcePath;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const subpathPrefix = subpath ? `${subpath}/` : "";
|
|
123
|
+
if (subpath) {
|
|
124
|
+
sourcePath = path.join(packageDir, "packages", subpath, "src", "index.ts");
|
|
125
|
+
if (fs.existsSync(sourcePath)) {
|
|
126
|
+
return sourcePath;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
sourcePath = path.join(packageDir, "src", subpathPrefix, "index.ts");
|
|
130
|
+
if (fs.existsSync(sourcePath)) {
|
|
131
|
+
return sourcePath;
|
|
132
|
+
}
|
|
133
|
+
sourcePath = path.join(packageDir, subpathPrefix, "index.ts");
|
|
134
|
+
if (fs.existsSync(sourcePath)) {
|
|
135
|
+
return sourcePath;
|
|
136
|
+
}
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
function resolveNpmPackageImport(fromFile, moduleSpecifier) {
|
|
140
|
+
const { packageName, subpath } = parseModuleSpecifier(moduleSpecifier);
|
|
141
|
+
const packageDir = findNodeModulesPackage(fromFile, packageName);
|
|
142
|
+
if (!packageDir) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
const packageJson = readPackageJson(packageDir);
|
|
146
|
+
if (!packageJson) {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
let sourcePath = resolvePackageExports(packageDir, subpath, packageJson);
|
|
150
|
+
if (!sourcePath) {
|
|
151
|
+
if (subpath) {
|
|
152
|
+
sourcePath = path.join(packageDir, "packages", subpath, "src", "index.ts");
|
|
153
|
+
}
|
|
154
|
+
if (!sourcePath || !fs.existsSync(sourcePath)) {
|
|
155
|
+
sourcePath = path.join(packageDir, "src", "index.ts");
|
|
156
|
+
}
|
|
157
|
+
if (!fs.existsSync(sourcePath)) {
|
|
158
|
+
sourcePath = path.join(packageDir, "index.ts");
|
|
159
|
+
}
|
|
160
|
+
if (!fs.existsSync(sourcePath)) {
|
|
161
|
+
sourcePath = undefined;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (!sourcePath) {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
let moduleKey = subpath || packageName.split("/").pop() || packageName;
|
|
168
|
+
if (moduleKey.endsWith(".js")) {
|
|
169
|
+
moduleKey = moduleKey.slice(0, -3);
|
|
170
|
+
}
|
|
171
|
+
else if (moduleKey.endsWith(".mjs")) {
|
|
172
|
+
moduleKey = moduleKey.slice(0, -4);
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
packagePath: packageDir,
|
|
176
|
+
sourcePath: path.resolve(sourcePath),
|
|
177
|
+
subpath,
|
|
178
|
+
packageName,
|
|
179
|
+
moduleKey,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
export function resolveImport(fromFile, moduleSpecifier, boardPackage) {
|
|
183
|
+
let effectiveSpecifier = moduleSpecifier;
|
|
184
|
+
// The `@typecad/board` virtual import resolves to the configured board package.
|
|
185
|
+
// (Case-insensitive so the documented mixed-case form is treated identically.)
|
|
186
|
+
if (moduleSpecifier.toLowerCase() === "@typecad/board" && boardPackage) {
|
|
187
|
+
effectiveSpecifier = boardPackage;
|
|
188
|
+
}
|
|
189
|
+
const localResolved = resolveLocalImport(fromFile, effectiveSpecifier);
|
|
190
|
+
if (localResolved) {
|
|
191
|
+
// .ui.html files resolve as UI modules, not TypeScript sources. Only set
|
|
192
|
+
// the flag when true, so `undefined` cleanly means "regular TS module".
|
|
193
|
+
if (localResolved.toLowerCase().endsWith(".ui.html")) {
|
|
194
|
+
return { sourcePath: localResolved, uiModule: true };
|
|
195
|
+
}
|
|
196
|
+
return { sourcePath: localResolved };
|
|
197
|
+
}
|
|
198
|
+
const npmResolved = resolveNpmPackageImport(fromFile, effectiveSpecifier);
|
|
199
|
+
if (npmResolved) {
|
|
200
|
+
return { sourcePath: npmResolved.sourcePath, npmPackage: npmResolved };
|
|
201
|
+
}
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
export function isInNodeModules(filePath) {
|
|
205
|
+
const normalized = path.resolve(filePath).replace(/\\/g, "/");
|
|
206
|
+
return normalized.includes("/node_modules/");
|
|
207
|
+
}
|
|
208
|
+
export function getNpmPackageInfoForFile(filePath, moduleSpecifier) {
|
|
209
|
+
if (!isInNodeModules(filePath)) {
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
const parts = moduleSpecifier.split("/");
|
|
213
|
+
let packageName;
|
|
214
|
+
let subpath;
|
|
215
|
+
if (moduleSpecifier.startsWith("@")) {
|
|
216
|
+
packageName = parts.length > 1 ? `${parts[0]}/${parts[1]}` : parts[0];
|
|
217
|
+
subpath = parts.length > 2 ? parts.slice(2).join("/") : "";
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
packageName = parts[0];
|
|
221
|
+
subpath = parts.length > 1 ? parts.slice(1).join("/") : "";
|
|
222
|
+
}
|
|
223
|
+
let moduleKey = subpath || packageName.split("/").pop() || packageName;
|
|
224
|
+
if (moduleKey.endsWith(".js")) {
|
|
225
|
+
moduleKey = moduleKey.slice(0, -3);
|
|
226
|
+
}
|
|
227
|
+
else if (moduleKey.endsWith(".mjs")) {
|
|
228
|
+
moduleKey = moduleKey.slice(0, -4);
|
|
229
|
+
}
|
|
230
|
+
let packageDir = path.dirname(filePath);
|
|
231
|
+
while (packageDir !== path.dirname(packageDir)) {
|
|
232
|
+
const packageJsonPath = path.join(packageDir, "package.json");
|
|
233
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
packageDir = path.dirname(packageDir);
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
packagePath: packageDir,
|
|
240
|
+
sourcePath: path.resolve(filePath),
|
|
241
|
+
subpath,
|
|
242
|
+
packageName,
|
|
243
|
+
moduleKey,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
export function detectNativeCppModule(fromFile, moduleSpecifier) {
|
|
247
|
+
if (!moduleSpecifier.startsWith(".")) {
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
const basePath = path.resolve(path.dirname(fromFile), moduleSpecifier);
|
|
251
|
+
const declCandidates = [`${basePath}.d.ts`, path.join(basePath, "index.d.ts")];
|
|
252
|
+
for (const declPath of declCandidates) {
|
|
253
|
+
if (!fs.existsSync(declPath) || !fs.statSync(declPath).isFile()) {
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
const cppPath = declPath.replace(/\.d\.ts$/i, ".cpp");
|
|
257
|
+
if (fs.existsSync(cppPath) && fs.statSync(cppPath).isFile()) {
|
|
258
|
+
const moduleKey = path.basename(declPath, ".d.ts");
|
|
259
|
+
const headerPath = declPath.replace(/\.d\.ts$/i, ".h");
|
|
260
|
+
const headerExists = fs.existsSync(headerPath) && fs.statSync(headerPath).isFile();
|
|
261
|
+
return {
|
|
262
|
+
declPath: path.resolve(declPath),
|
|
263
|
+
cppPath: path.resolve(cppPath),
|
|
264
|
+
headerPath: headerExists ? path.resolve(headerPath) : undefined,
|
|
265
|
+
moduleKey,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return undefined;
|
|
270
|
+
}
|
|
271
|
+
export function isCuttlefishSDKPath(filePath) {
|
|
272
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
273
|
+
return (/\/code\/core\//.test(normalized) ||
|
|
274
|
+
/\/code\/board-/.test(normalized) ||
|
|
275
|
+
/\/packages\/board-/.test(normalized) ||
|
|
276
|
+
/\/packages\/expect\//.test(normalized) ||
|
|
277
|
+
/\/packages\/cuttlefish\//.test(normalized) ||
|
|
278
|
+
/\/node_modules\/@typecad\/board-/.test(normalized) ||
|
|
279
|
+
/\/node_modules\/@typecad\/core\//.test(normalized) ||
|
|
280
|
+
/\/node_modules\/@typecad\/expect\//.test(normalized) ||
|
|
281
|
+
/\/node_modules\/@typecad\/cuttlefish\//.test(normalized));
|
|
282
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { GenerateLibdefOptions, GeneratedOutputs, TranspileOptions } from "./types.js";
|
|
2
|
+
export declare function transpileFile(options: TranspileOptions): Promise<GeneratedOutputs>;
|
|
3
|
+
export declare function generateLibraryDefinitions(options: GenerateLibdefOptions): string[];
|