@typecad/cuttlefish 0.1.0-alpha.1 → 0.1.0-alpha.2

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/cli.js CHANGED
@@ -12,7 +12,7 @@ import { resolveStrategy } from "./platform/registry.js";
12
12
  import { loadFrameworkPackage } from "./framework-package.js";
13
13
  import { getLoadedFramework, hasLoadedFramework } from "./framework-registry.js";
14
14
  import { loadCuttlefishConfig, generateVirtualTypeDeclaration } from "./config-loader.js";
15
- import { requireUIHook } from "./ui-hook.js";
15
+ import { requireUIHook, hasUIHook } from "./ui-hook.js";
16
16
  import { loadUIEngine } from "./ui/ui-bridge.js";
17
17
  import { runWatch, discoverWatchDirs } from "./watch.js";
18
18
  import { runExpectTests, assertTypeScriptInput, printDiagnostics, printMappedCompileErrors } from "./cli-utils.js";
@@ -321,7 +321,11 @@ async function main() {
321
321
  // Strategy not yet loaded — env.d.ts will have generic declarations only
322
322
  }
323
323
  generateVirtualTypeDeclaration(config, platformDeclarations);
324
- requireUIHook().generateProjectUITypeDeclarations(path.dirname(config.configPath));
324
+ // @typecad/ui is optional — skip UI type-decl generation when the engine
325
+ // is not loaded (no UI modules exist to declare).
326
+ if (hasUIHook()) {
327
+ requireUIHook().generateProjectUITypeDeclarations(path.dirname(config.configPath));
328
+ }
325
329
  }
326
330
  // Print branded header and build info
327
331
  ui.printHeader();
@@ -421,7 +425,11 @@ async function main() {
421
425
  console.log();
422
426
  try {
423
427
  if (config) {
424
- requireUIHook().generateProjectUITypeDeclarations(path.dirname(config.configPath));
428
+ // @typecad/ui is optional — skip UI type-decl generation when the
429
+ // engine is not loaded (no UI modules exist to declare).
430
+ if (hasUIHook()) {
431
+ requireUIHook().generateProjectUITypeDeclarations(path.dirname(config.configPath));
432
+ }
425
433
  }
426
434
  ui.printTranspiling();
427
435
  const rebuildResult = await transpileFile({
@@ -4,7 +4,7 @@ import ts from "typescript";
4
4
  import { makeDiagnostic } from "../ir/ast-node-utils.js";
5
5
  import { canonicalize, buildSemanticFacts } from "./semantic-facts.js";
6
6
  import { verifyFacts } from "./semantic-facts-verifier.js";
7
- import { requireUIHook } from "../ui-hook.js";
7
+ import { requireUIHook, hasUIHook } from "../ui-hook.js";
8
8
  /**
9
9
  * Type-checks TypeScript files using the TypeScript compiler.
10
10
  * Returns early if any errors are found.
@@ -54,7 +54,9 @@ export function typeCheckFiles(files, _boardPackage, entryFile) {
54
54
  }
55
55
  }
56
56
  }
57
- const uiModules = requireUIHook().allUIModules();
57
+ // @typecad/ui is optional — when the engine is not loaded there are no UI
58
+ // modules and nothing to register with the type-checker.
59
+ const uiModules = hasUIHook() ? requireUIHook().allUIModules() : [];
58
60
  if (uiModules.length > 0) {
59
61
  compilerOptions.allowArbitraryExtensions = true;
60
62
  const rootDirs = new Set((compilerOptions.rootDirs ?? []).map((dir) => path.resolve(dir)));
package/dist/testing.d.ts CHANGED
@@ -14,6 +14,7 @@ export { registerPlatformStrategy, resolveStrategy, clearAllProfileCaches } from
14
14
  export type { EmitMode, GeneratedOutputs, TargetProfile, PlatformContext } from "./types.js";
15
15
  export { findConfigFile, parseConfigFile, loadCuttlefishConfig, generateVirtualTypeDeclaration, } from "./config-loader.js";
16
16
  export { transpileFile } from "./transpile.js";
17
+ export { resetUIEngine, __simulateUIAbsentForTest } from "./ui/ui-bridge.js";
17
18
  export { scaffoldProject, normalizeProjectName, KNOWN_BOARDS, generateProjectPackageJson, generateProjectTsconfig, generateProjectConfig, generateProjectEnvDts, generateStarterSketch, generateGitignore, generateEslintConfig, runInitWizard, } from "./create/index.js";
18
19
  export type { InitProjectOptions } from "./create/index.js";
19
20
  export { scaffoldBoardPackages, parseBoardSpec, safeParseBoardSpec, stripJsonc, } from "./create/index.js";
package/dist/testing.js CHANGED
@@ -15,6 +15,8 @@ export { registerPlatformStrategy, resolveStrategy, clearAllProfileCaches } from
15
15
  export { findConfigFile, parseConfigFile, loadCuttlefishConfig, generateVirtualTypeDeclaration, } from "./config-loader.js";
16
16
  // ── Transpiler internal API ─────────────────────────────────────────────────
17
17
  export { transpileFile } from "./transpile.js";
18
+ // ── UI bridge (optional @typecad/ui) ─────────────────────────────────────────
19
+ export { resetUIEngine, __simulateUIAbsentForTest } from "./ui/ui-bridge.js";
18
20
  // ── Project scaffolding ──────────────────────────────────────────────────────
19
21
  export { scaffoldProject, normalizeProjectName, KNOWN_BOARDS, generateProjectPackageJson, generateProjectTsconfig, generateProjectConfig, generateProjectEnvDts, generateStarterSketch, generateGitignore, generateEslintConfig, runInitWizard, } from "./create/index.js";
20
22
  // ── Board codegen (`cuttlefish board add`) ───────────────────────────────────
package/dist/transpile.js CHANGED
@@ -6,7 +6,7 @@ import ts from "typescript";
6
6
  import { buildProgramIR } from "./ir/build-ir.js";
7
7
  import { classDeclarationToIR } from "./ir/declaration-builders.js";
8
8
  import { clickHandlers } from "./ir/transformers/ui-call-resolver.js";
9
- import { requireUIHook } from "./ui-hook.js";
9
+ import { requireUIHook, hasUIHook } from "./ui-hook.js";
10
10
  import { loadUIEngine } from "./ui/ui-bridge.js";
11
11
  import { setDisplayProfile, resetDisplayProfile } from "./stores/display-profile-store.js";
12
12
  import { setThemeCss, resetThemeCss, setThemeClass } from "./stores/theme-store.js";
@@ -344,9 +344,12 @@ export async function transpileFile(options) {
344
344
  // The graph build above already loaded all .ui.html modules; surface their
345
345
  // parser warnings (unknown CSS properties, unknown HTML tags) here so the
346
346
  // author sees typos and unsupported features instead of silent drops.
347
- for (const mod of requireUIHook().allUIModules()) {
348
- for (const d of mod.diagnostics) {
349
- diagnostics.push({ ...d, source: d.source ?? path.basename(mod.htmlPath) });
347
+ // Guarded: @typecad/ui is optional, so there may be no UI engine loaded.
348
+ if (hasUIHook()) {
349
+ for (const mod of requireUIHook().allUIModules()) {
350
+ for (const d of mod.diagnostics) {
351
+ diagnostics.push({ ...d, source: d.source ?? path.basename(mod.htmlPath) });
352
+ }
350
353
  }
351
354
  }
352
355
  // ── Semantic gates (Phase 3) ──────────────────────────────────────────────
@@ -459,9 +462,12 @@ export async function transpileFile(options) {
459
462
  profiler.captureMemorySnapshot("ir:post-build");
460
463
  profiler.endTimer("ir:build-all");
461
464
  // ── UI mount-time warnings (scroll memory budget, etc.) ─────────────────
462
- for (const mod of requireUIHook().allUIModules()) {
463
- for (const d of mod.mountDiagnostics) {
464
- diagnostics.push({ ...d, source: d.source ?? path.basename(mod.htmlPath) });
465
+ // Guarded: @typecad/ui is optional; no engine means no UI modules.
466
+ if (hasUIHook()) {
467
+ for (const mod of requireUIHook().allUIModules()) {
468
+ for (const d of mod.mountDiagnostics) {
469
+ diagnostics.push({ ...d, source: d.source ?? path.basename(mod.htmlPath) });
470
+ }
465
471
  }
466
472
  }
467
473
  throwIfFatalDiagnostics(rawIRArray.flatMap(({ filePath, programIR }) => programIR.diagnostics.map((diagnostic) => ({ filePath, diagnostic }))));
@@ -2,3 +2,15 @@
2
2
  * Called by transpile.ts at the start of each transpile run.
3
3
  * Safe to call when @typecad/ui is absent (hook stays null). */
4
4
  export declare function loadUIEngine(): Promise<void>;
5
+ /** Reset the UI bridge to its initial state: forget that a load was attempted
6
+ * and clear the registered hook. Mirrors the other `reset*` session helpers
7
+ * (clearCaches, resetDisplayProfile) so each transpile run — and each test —
8
+ * starts from a clean slate. */
9
+ export declare function resetUIEngine(): void;
10
+ /** Test-only: force the bridge into the "no @typecad/ui" state — mark the load
11
+ * as already attempted and leave the hook null, exactly as if the dynamic
12
+ * import in loadUIEngine() had failed because the package is not installed.
13
+ * This lets the test suite (which runs inside the monorepo where @typecad/ui
14
+ * IS resolvable) reproduce a plain end-user project that has not added
15
+ * @typecad/ui as a dependency. */
16
+ export declare function __simulateUIAbsentForTest(): void;
@@ -32,3 +32,21 @@ export async function loadUIEngine() {
32
32
  // @typecad/ui is not installed — cuttlefish works without UI support.
33
33
  }
34
34
  }
35
+ /** Reset the UI bridge to its initial state: forget that a load was attempted
36
+ * and clear the registered hook. Mirrors the other `reset*` session helpers
37
+ * (clearCaches, resetDisplayProfile) so each transpile run — and each test —
38
+ * starts from a clean slate. */
39
+ export function resetUIEngine() {
40
+ loaded = false;
41
+ setUIHook(null);
42
+ }
43
+ /** Test-only: force the bridge into the "no @typecad/ui" state — mark the load
44
+ * as already attempted and leave the hook null, exactly as if the dynamic
45
+ * import in loadUIEngine() had failed because the package is not installed.
46
+ * This lets the test suite (which runs inside the monorepo where @typecad/ui
47
+ * IS resolvable) reproduce a plain end-user project that has not added
48
+ * @typecad/ui as a dependency. */
49
+ export function __simulateUIAbsentForTest() {
50
+ loaded = true;
51
+ setUIHook(null);
52
+ }
package/package.json CHANGED
@@ -1,127 +1,127 @@
1
- {
2
- "name": "@typecad/cuttlefish",
3
- "version": "0.1.0-alpha.1",
4
- "description": "TypeScript to C++ transpiler — native, Arduino, and bare-metal targets",
5
- "type": "module",
6
- "main": "./dist/transpile.js",
7
- "types": "./dist/transpile.d.ts",
8
- "bin": {
9
- "cuttlefish": "dist/cli.js"
10
- },
11
- "exports": {
12
- ".": {
13
- "types": "./dist/transpile.d.ts",
14
- "default": "./dist/transpile.js"
15
- },
16
- "./testing": {
17
- "types": "./dist/testing.d.ts",
18
- "default": "./dist/testing.js"
19
- },
20
- "./api": {
21
- "types": "./dist/api/index.d.ts",
22
- "default": "./dist/api/index.js"
23
- },
24
- "./api/shared": {
25
- "types": "./dist/api/shared/index.d.ts",
26
- "default": "./dist/api/shared/index.js"
27
- },
28
- "./ui-hook": {
29
- "types": "./dist/ui-hook.d.ts",
30
- "default": "./dist/ui-hook.js"
31
- },
32
- "./config-loader": {
33
- "types": "./dist/config-loader.d.ts",
34
- "default": "./dist/config-loader.js"
35
- },
36
- "./stores/display-profile-store": {
37
- "types": "./dist/stores/display-profile-store.d.ts",
38
- "default": "./dist/stores/display-profile-store.js"
39
- },
40
- "./stores/theme-store": {
41
- "types": "./dist/stores/theme-store.d.ts",
42
- "default": "./dist/stores/theme-store.js"
43
- },
44
- "./api/schema": {
45
- "types": "./dist/api/schema/index.d.ts",
46
- "default": "./dist/api/schema/index.js"
47
- },
48
- "./emit/route-hal-op": {
49
- "types": "./dist/emit/route-hal-op.d.ts",
50
- "default": "./dist/emit/route-hal-op.js"
51
- },
52
- "./ir/transformers/ui-lowering": {
53
- "types": "./dist/ir/transformers/ui-lowering.d.ts",
54
- "default": "./dist/ir/transformers/ui-lowering.js"
55
- },
56
- "./ir/ui-element-auto-wire": {
57
- "types": "./dist/ir/ui-element-auto-wire.d.ts",
58
- "default": "./dist/ir/ui-element-auto-wire.js"
59
- },
60
- "./ir/transformers/ui-mount": {
61
- "types": "./dist/ir/transformers/ui-mount.d.ts",
62
- "default": "./dist/ir/transformers/ui-mount.js"
63
- },
64
- "./ir/transformers/ui-reactive": {
65
- "types": "./dist/ir/transformers/ui-reactive.d.ts",
66
- "default": "./dist/ir/transformers/ui-reactive.js"
67
- }
68
- },
69
- "files": [
70
- "dist"
71
- ],
72
- "publishConfig": {
73
- "access": "public"
74
- },
75
- "scripts": {
76
- "build": "tsc",
77
- "prepublishOnly": "npm run build",
78
- "start": "node dist/cli.js"
79
- },
80
- "dependencies": {
81
- "chalk": "^4.1.2",
82
- "typescript": "^5.7.3",
83
- "zod": "^3.24.0"
84
- },
85
- "peerDependencies": {
86
- "@typecad/ui": "0.1.0-alpha.1"
87
- },
88
- "peerDependenciesMeta": {
89
- "@typecad/ui": {
90
- "optional": true
91
- }
92
- },
93
- "optionalDependencies": {
94
- "@typecad/framework-native": "0.1.0-alpha.1"
95
- },
96
- "devDependencies": {
97
- "@types/node": "^22.10.7"
98
- },
99
- "license": "MIT",
100
- "repository": {
101
- "type": "git",
102
- "url": "git+https://github.com/justind000/typecode.git",
103
- "directory": "packages/cuttlefish"
104
- },
105
- "homepage": "https://github.com/justind000/typecode/tree/main/packages/cuttlefish",
106
- "bugs": {
107
- "url": "https://github.com/justind000/typecode/issues"
108
- },
109
- "keywords": [
110
- "arduino",
111
- "cli",
112
- "codegen",
113
- "cpp",
114
- "cuttlefish",
115
- "embedded",
116
- "firmware",
117
- "microcontroller",
118
- "transpiler",
119
- "typecad",
120
- "typescript"
121
- ],
122
- "engines": {
123
- "node": ">=18"
124
- },
125
- "author": "typecad0",
126
- "sideEffects": false
127
- }
1
+ {
2
+ "name": "@typecad/cuttlefish",
3
+ "version": "0.1.0-alpha.2",
4
+ "description": "TypeScript to C++ transpiler — native, Arduino, and bare-metal targets",
5
+ "type": "module",
6
+ "main": "./dist/transpile.js",
7
+ "types": "./dist/transpile.d.ts",
8
+ "bin": {
9
+ "cuttlefish": "dist/cli.js"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/transpile.d.ts",
14
+ "default": "./dist/transpile.js"
15
+ },
16
+ "./testing": {
17
+ "types": "./dist/testing.d.ts",
18
+ "default": "./dist/testing.js"
19
+ },
20
+ "./api": {
21
+ "types": "./dist/api/index.d.ts",
22
+ "default": "./dist/api/index.js"
23
+ },
24
+ "./api/shared": {
25
+ "types": "./dist/api/shared/index.d.ts",
26
+ "default": "./dist/api/shared/index.js"
27
+ },
28
+ "./ui-hook": {
29
+ "types": "./dist/ui-hook.d.ts",
30
+ "default": "./dist/ui-hook.js"
31
+ },
32
+ "./config-loader": {
33
+ "types": "./dist/config-loader.d.ts",
34
+ "default": "./dist/config-loader.js"
35
+ },
36
+ "./stores/display-profile-store": {
37
+ "types": "./dist/stores/display-profile-store.d.ts",
38
+ "default": "./dist/stores/display-profile-store.js"
39
+ },
40
+ "./stores/theme-store": {
41
+ "types": "./dist/stores/theme-store.d.ts",
42
+ "default": "./dist/stores/theme-store.js"
43
+ },
44
+ "./api/schema": {
45
+ "types": "./dist/api/schema/index.d.ts",
46
+ "default": "./dist/api/schema/index.js"
47
+ },
48
+ "./emit/route-hal-op": {
49
+ "types": "./dist/emit/route-hal-op.d.ts",
50
+ "default": "./dist/emit/route-hal-op.js"
51
+ },
52
+ "./ir/transformers/ui-lowering": {
53
+ "types": "./dist/ir/transformers/ui-lowering.d.ts",
54
+ "default": "./dist/ir/transformers/ui-lowering.js"
55
+ },
56
+ "./ir/ui-element-auto-wire": {
57
+ "types": "./dist/ir/ui-element-auto-wire.d.ts",
58
+ "default": "./dist/ir/ui-element-auto-wire.js"
59
+ },
60
+ "./ir/transformers/ui-mount": {
61
+ "types": "./dist/ir/transformers/ui-mount.d.ts",
62
+ "default": "./dist/ir/transformers/ui-mount.js"
63
+ },
64
+ "./ir/transformers/ui-reactive": {
65
+ "types": "./dist/ir/transformers/ui-reactive.d.ts",
66
+ "default": "./dist/ir/transformers/ui-reactive.js"
67
+ }
68
+ },
69
+ "files": [
70
+ "dist"
71
+ ],
72
+ "publishConfig": {
73
+ "access": "public"
74
+ },
75
+ "scripts": {
76
+ "build": "tsc",
77
+ "prepublishOnly": "npm run build",
78
+ "start": "node dist/cli.js"
79
+ },
80
+ "dependencies": {
81
+ "chalk": "^4.1.2",
82
+ "typescript": "^5.7.3",
83
+ "zod": "^3.24.0"
84
+ },
85
+ "peerDependencies": {
86
+ "@typecad/ui": "0.1.0-alpha.2"
87
+ },
88
+ "peerDependenciesMeta": {
89
+ "@typecad/ui": {
90
+ "optional": true
91
+ }
92
+ },
93
+ "optionalDependencies": {
94
+ "@typecad/framework-native": "0.1.0-alpha.2"
95
+ },
96
+ "devDependencies": {
97
+ "@types/node": "^22.10.7"
98
+ },
99
+ "license": "MIT",
100
+ "repository": {
101
+ "type": "git",
102
+ "url": "git+https://github.com/justind000/typecode.git",
103
+ "directory": "packages/cuttlefish"
104
+ },
105
+ "homepage": "https://github.com/justind000/typecode/tree/main/packages/cuttlefish",
106
+ "bugs": {
107
+ "url": "https://github.com/justind000/typecode/issues"
108
+ },
109
+ "keywords": [
110
+ "arduino",
111
+ "cli",
112
+ "codegen",
113
+ "cpp",
114
+ "cuttlefish",
115
+ "embedded",
116
+ "firmware",
117
+ "microcontroller",
118
+ "transpiler",
119
+ "typecad",
120
+ "typescript"
121
+ ],
122
+ "engines": {
123
+ "node": ">=18"
124
+ },
125
+ "author": "typecad0",
126
+ "sideEffects": false
127
+ }