@native-sdk/cli 0.4.4 → 0.5.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/build/app.zig +371 -5
- package/build/ts_run.mjs +102 -0
- package/build.zig +255 -1
- package/build.zig.zon +1 -0
- package/package.json +19 -10
- package/packages/core/package-lock.json +44 -0
- package/packages/core/package.json +38 -0
- package/packages/core/rt/rt.zig +1579 -0
- package/packages/core/sdk/bytes_text_methods.d.ts +88 -0
- package/packages/core/sdk/core.ts +694 -0
- package/packages/core/sdk/events.ts +137 -0
- package/packages/core/sdk/text.ts +519 -0
- package/packages/core/src/checker.ts +1869 -0
- package/packages/core/src/cli.ts +68 -0
- package/packages/core/src/devhost.ts +291 -0
- package/packages/core/src/devhost_resolver.mjs +22 -0
- package/packages/core/src/diagnostics.ts +417 -0
- package/packages/core/src/emitter.ts +8815 -0
- package/packages/core/src/infer.ts +1515 -0
- package/packages/core/src/modules.ts +173 -0
- package/packages/core/src/ownership.ts +740 -0
- package/packages/core/src/text_polyfill.ts +337 -0
- package/packages/core/src/text_tables.ts +408 -0
- package/packages/core/src/transpile.ts +146 -0
- package/packages/core/src/typed_ast.ts +546 -0
- package/packages/core/src/types.ts +815 -0
- package/skill-data/native-ui/SKILL.md +14 -0
- package/skill-data/ts-core/SKILL.md +493 -0
- package/skill-data/zig/SKILL.md +10 -0
- package/src/app_runner/root.zig +24 -0
- package/src/app_runner/ts_core_main.zig +231 -0
- package/src/platform/windows/webview2_host.cpp +24 -0
- package/src/primitives/app_manifest/comptime_scene.zig +341 -0
- package/src/primitives/app_manifest/root.zig +5 -0
- package/src/primitives/canvas/commands.zig +14 -7
- package/src/primitives/canvas/layout_audit.zig +5 -5
- package/src/primitives/canvas/lazy_tls.zig +73 -0
- package/src/primitives/canvas/render_generic_resources.zig +22 -15
- package/src/primitives/canvas/root.zig +11 -0
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/text_atlas.zig +40 -32
- package/src/primitives/canvas/text_layout_cache.zig +29 -22
- package/src/primitives/canvas/text_measure_cache.zig +56 -41
- package/src/primitives/canvas/text_spans.zig +39 -26
- package/src/primitives/canvas/tokens.zig +69 -0
- package/src/primitives/canvas/ui.zig +125 -0
- package/src/primitives/canvas/ui_markup.zig +22 -3
- package/src/primitives/canvas/ui_markup_compiled.zig +97 -7
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +275 -0
- package/src/primitives/canvas/ui_markup_contract.zig +68 -14
- package/src/primitives/canvas/ui_markup_contract_tests.zig +257 -2
- package/src/primitives/canvas/ui_markup_reflect.zig +214 -0
- package/src/primitives/canvas/ui_markup_view.zig +105 -1
- package/src/primitives/canvas/ui_markup_view_tests.zig +336 -0
- package/src/primitives/canvas/ui_schema.zig +8 -0
- package/src/primitives/canvas/ui_schema_tests.zig +5 -4
- package/src/primitives/canvas/widget_builtin_tests.zig +309 -5
- package/src/primitives/canvas/widget_invalidation.zig +14 -7
- package/src/primitives/canvas/widget_layout.zig +138 -2
- package/src/primitives/canvas/widget_metrics.zig +16 -8
- package/src/primitives/canvas/widget_render.zig +25 -15
- package/src/primitives/canvas/widget_render_controls.zig +15 -9
- package/src/primitives/canvas/widget_runtime_tests.zig +44 -0
- package/src/root.zig +7 -0
- package/src/runtime/canvas_frame.zig +57 -36
- package/src/runtime/canvas_images.zig +9 -3
- package/src/runtime/canvas_widget_control_tests.zig +5 -6
- package/src/runtime/canvas_widget_runtime.zig +7 -4
- package/src/runtime/core.zig +16 -0
- package/src/runtime/effects.zig +1525 -133
- package/src/runtime/effects_fetch_tests.zig +42 -0
- package/src/runtime/effects_file_tests.zig +220 -0
- package/src/runtime/effects_host_tests.zig +594 -0
- package/src/runtime/effects_tests.zig +287 -0
- package/src/runtime/root.zig +18 -0
- package/src/runtime/session_replay.zig +7 -1
- package/src/runtime/tests.zig +2 -0
- package/src/runtime/ts_core_host.zig +1505 -0
- package/src/runtime/ts_core_host_tests.zig +1408 -0
- package/src/runtime/ts_ui_app.zig +469 -0
- package/src/runtime/ui_app.zig +189 -38
- package/src/runtime/ui_app_tests.zig +221 -0
- package/src/runtime/ui_app_window_tests.zig +182 -0
- package/src/runtime/view_canvas.zig +24 -17
- package/src/runtime/view_widget_tree.zig +2 -2
- package/src/tooling/codesign.zig +212 -105
- package/src/tooling/doctor.zig +78 -0
- package/src/tooling/manifest.zig +47 -0
- package/src/tooling/package.zig +435 -20
- package/src/tooling/raw_manifest.zig +15 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +777 -34
- package/src/tooling/ts_core.zig +1099 -0
- package/src/tooling/verbs.zig +105 -2
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// The core's import graph: which .ts files make up one app core, resolved
|
|
2
|
+
// from src/core.ts BEFORE the type-checked program is built, so every
|
|
3
|
+
// module-boundary mistake is a teaching diagnostic (NS1034-NS1037) instead
|
|
4
|
+
// of a raw tsc resolution error.
|
|
5
|
+
//
|
|
6
|
+
// The boundary rules (spec: "src/ is the boundary"):
|
|
7
|
+
// - "@native-sdk/core" is the intrinsic SDK surface — typed, never emitted.
|
|
8
|
+
// - "@native-sdk/core/<lib>" names a shipped SDK library module (subset
|
|
9
|
+
// TypeScript, transpiled into the core when imported — module-granular
|
|
10
|
+
// tree-shaking falls out of walking the graph from the entry).
|
|
11
|
+
// - "./x.ts" (and "./sub/x.ts") resolve inside the ENTRY MODULE'S
|
|
12
|
+
// directory subtree — its src/. Escaping it (../, absolute paths) is
|
|
13
|
+
// NS1034; bare npm specifiers are NS1035; a specifier that names no
|
|
14
|
+
// file is NS1037.
|
|
15
|
+
// - Runtime import cycles are NS1036. Type-only edges (`import type`,
|
|
16
|
+
// `export type`) are exempt — they erase under node and constrain no
|
|
17
|
+
// emission order — but still pull their target into the graph, because
|
|
18
|
+
// its type declarations must exist in the emitted module.
|
|
19
|
+
//
|
|
20
|
+
// The returned file list is the canonical module order everywhere
|
|
21
|
+
// downstream (type table, checker, inference, emission): the entry first,
|
|
22
|
+
// then its imports depth-first in source order — deterministic, so emitted
|
|
23
|
+
// output is stable across runs.
|
|
24
|
+
|
|
25
|
+
import path from "node:path";
|
|
26
|
+
import fs from "node:fs";
|
|
27
|
+
import { ts, sdkCoreModulePath, sdkLibraryModules } from "./typed_ast.ts";
|
|
28
|
+
import { makeDiagnostic, type SubsetDiagnostic } from "./diagnostics.ts";
|
|
29
|
+
|
|
30
|
+
export interface ModuleGraph {
|
|
31
|
+
/// Absolute paths in module order: the entry first, then imports
|
|
32
|
+
/// depth-first. Includes imported SDK library modules; never sdk/core.ts.
|
|
33
|
+
readonly files: readonly string[];
|
|
34
|
+
/// The subset of `files` that are SDK library modules (checker
|
|
35
|
+
/// diagnostics inside these are SDK bugs, not app bugs).
|
|
36
|
+
readonly sdkFiles: ReadonlySet<string>;
|
|
37
|
+
readonly diagnostics: SubsetDiagnostic[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface Edge {
|
|
41
|
+
readonly specifier: string;
|
|
42
|
+
readonly typeOnly: boolean;
|
|
43
|
+
readonly node: ts.Node;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// Import/re-export edges of one parsed file, in source order.
|
|
47
|
+
function edgesOf(file: ts.SourceFile): Edge[] {
|
|
48
|
+
const out: Edge[] = [];
|
|
49
|
+
for (const stmt of file.statements) {
|
|
50
|
+
if (ts.isImportDeclaration(stmt) && ts.isStringLiteral(stmt.moduleSpecifier)) {
|
|
51
|
+
out.push({
|
|
52
|
+
specifier: stmt.moduleSpecifier.text,
|
|
53
|
+
typeOnly: stmt.importClause?.isTypeOnly ?? false,
|
|
54
|
+
node: stmt,
|
|
55
|
+
});
|
|
56
|
+
} else if (ts.isExportDeclaration(stmt) && stmt.moduleSpecifier && ts.isStringLiteral(stmt.moduleSpecifier)) {
|
|
57
|
+
out.push({ specifier: stmt.moduleSpecifier.text, typeOnly: stmt.isTypeOnly, node: stmt });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function diag(
|
|
64
|
+
id: "NS1034" | "NS1035" | "NS1036" | "NS1037",
|
|
65
|
+
site: string,
|
|
66
|
+
file: ts.SourceFile,
|
|
67
|
+
node: ts.Node,
|
|
68
|
+
): SubsetDiagnostic {
|
|
69
|
+
const lc = file.getLineAndCharacterOfPosition(node.getStart(file));
|
|
70
|
+
return makeDiagnostic(id, site, file.fileName, lc.line + 1, lc.character + 1);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/// Walk the import graph from `entry` (absolute or cwd-relative path).
|
|
74
|
+
/// Reads and parses each file once — no type checking here; the caller
|
|
75
|
+
/// builds the checked program only when the graph is clean.
|
|
76
|
+
export function resolveModuleGraph(entry: string): ModuleGraph {
|
|
77
|
+
const entryPath = path.resolve(entry);
|
|
78
|
+
const boundary = path.dirname(entryPath);
|
|
79
|
+
const sdkBoundary = path.dirname(sdkCoreModulePath);
|
|
80
|
+
const diagnostics: SubsetDiagnostic[] = [];
|
|
81
|
+
const files: string[] = [];
|
|
82
|
+
const sdkFiles = new Set<string>();
|
|
83
|
+
const visiting = new Set<string>(); // DFS stack for runtime-cycle detection
|
|
84
|
+
const done = new Set<string>();
|
|
85
|
+
|
|
86
|
+
const insideBoundary = (p: string, root: string): boolean => {
|
|
87
|
+
const rel = path.relative(root, p);
|
|
88
|
+
return rel !== "" && !rel.startsWith("..") && !path.isAbsolute(rel);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const visit = (filePath: string, fromCycleTrail: string[]): void => {
|
|
92
|
+
if (done.has(filePath)) return;
|
|
93
|
+
if (visiting.has(filePath)) return; // a cycle is reported at its back-edge
|
|
94
|
+
visiting.add(filePath);
|
|
95
|
+
files.push(filePath);
|
|
96
|
+
|
|
97
|
+
const text = fs.readFileSync(filePath, "utf8");
|
|
98
|
+
const parsed = ts.createSourceFile(filePath, text, ts.ScriptTarget.ESNext, true);
|
|
99
|
+
const isSdk = sdkFiles.has(filePath);
|
|
100
|
+
const root = isSdk ? sdkBoundary : boundary;
|
|
101
|
+
|
|
102
|
+
for (const edge of edgesOf(parsed)) {
|
|
103
|
+
const spec = edge.specifier;
|
|
104
|
+
if (spec === "@native-sdk/core") continue; // the intrinsic surface — typed, never emitted
|
|
105
|
+
if (sdkLibraryModules.has(spec)) {
|
|
106
|
+
const target = path.resolve(sdkLibraryModules.get(spec)!);
|
|
107
|
+
if (!fs.existsSync(target)) {
|
|
108
|
+
diagnostics.push(diag("NS1037", `The SDK is missing \`${spec}\` (${target}) — is the checkout complete?`, parsed, edge.node));
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
sdkFiles.add(target);
|
|
112
|
+
follow(target, edge, parsed, filePath, fromCycleTrail);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (spec.startsWith("@native-sdk/")) {
|
|
116
|
+
if (edge.typeOnly) continue;
|
|
117
|
+
diagnostics.push(diag(
|
|
118
|
+
"NS1037",
|
|
119
|
+
`\`${spec}\` names no SDK module (this SDK ships ${["@native-sdk/core", ...sdkLibraryModules.keys()].join(", ")}).`,
|
|
120
|
+
parsed,
|
|
121
|
+
edge.node,
|
|
122
|
+
));
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (!spec.startsWith(".")) {
|
|
126
|
+
if (edge.typeOnly) continue; // type-only npm imports erase — free
|
|
127
|
+
diagnostics.push(diag("NS1035", `\`import ... from "${spec}"\` brings a runtime npm dependency into the core.`, parsed, edge.node));
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
// A relative specifier: resolve against the importing file.
|
|
131
|
+
const resolved = path.resolve(path.dirname(filePath), spec);
|
|
132
|
+
if (!insideBoundary(resolved, root) || path.isAbsolute(spec)) {
|
|
133
|
+
diagnostics.push(diag("NS1034", `\`import ... from "${spec}"\` resolves outside ${isSdk ? "the SDK's module directory" : "the core's src/ directory"}.`, parsed, edge.node));
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (!spec.endsWith(".ts")) {
|
|
137
|
+
const withExt = `${resolved}.ts`;
|
|
138
|
+
const hint = fs.existsSync(withExt)
|
|
139
|
+
? `\`import ... from "${spec}"\` omits the file extension (\`${spec}.ts\` exists).`
|
|
140
|
+
: `\`import ... from "${spec}"\` names no .ts module file.`;
|
|
141
|
+
diagnostics.push(diag("NS1037", hint, parsed, edge.node));
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (!fs.existsSync(resolved)) {
|
|
145
|
+
diagnostics.push(diag("NS1037", `\`import ... from "${spec}"\` names no file (looked for ${resolved}).`, parsed, edge.node));
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
follow(resolved, edge, parsed, filePath, fromCycleTrail);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
visiting.delete(filePath);
|
|
152
|
+
done.add(filePath);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const follow = (target: string, edge: Edge, parsed: ts.SourceFile, from: string, trail: string[]): void => {
|
|
156
|
+
if (visiting.has(target)) {
|
|
157
|
+
// A back-edge. Runtime cycles are taught; type-only ones erase.
|
|
158
|
+
if (!edge.typeOnly) {
|
|
159
|
+
const names = [...trail, from, target].map((p) => path.basename(p));
|
|
160
|
+
diagnostics.push(diag("NS1036", `\`import ... from "${edge.specifier}"\` closes an import cycle (${names.join(" -> ")}).`, parsed, edge.node));
|
|
161
|
+
}
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
visit(target, [...trail, from]);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
if (!fs.existsSync(entryPath)) {
|
|
168
|
+
// The caller reports the unreadable entry itself.
|
|
169
|
+
return { files: [], sdkFiles, diagnostics };
|
|
170
|
+
}
|
|
171
|
+
visit(entryPath, []);
|
|
172
|
+
return { files, sdkFiles, diagnostics };
|
|
173
|
+
}
|