@octane-xplat/build 0.0.0-stage → 0.20.0
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 +4 -2
- package/dist/add-worker.js +66 -0
- package/dist/build-worker.js +276 -0
- package/dist/compatibility-check.js +153 -0
- package/dist/compatibility-data/compatibility.js +106 -0
- package/dist/compatibility-data/compatibility.json +305 -0
- package/dist/compatibility.js +229 -0
- package/dist/css-layers.js +63 -0
- package/dist/css-platform.js +230 -0
- package/dist/css-platform.types.d.ts +11 -0
- package/dist/dev-inspector.web.js +125 -0
- package/dist/dev-log-client.web.js +79 -0
- package/dist/dev-log-server.js +13 -0
- package/dist/doctor-checks.js +317 -0
- package/dist/doctor-tool.js +27 -0
- package/dist/env.js +3 -0
- package/dist/fmt-plan.js +149 -0
- package/dist/fonts-worker.js +31 -0
- package/dist/fonts.js +614 -0
- package/dist/inline-stylesheets.js +37 -0
- package/dist/linux/config.js +43 -0
- package/dist/linux/host/bridge-selftest.linux.js +255 -0
- package/dist/linux/host/gjs-host.js +1412 -0
- package/dist/linux/package.js +176 -0
- package/dist/linux-gtk/vite.d.ts +23 -0
- package/dist/linux-gtk/vite.js +194 -0
- package/dist/macos/config.js +141 -0
- package/dist/macos/doctor-checks.js +58 -0
- package/dist/macos/executables.js +39 -0
- package/dist/macos/jsc-host/runtime.js +134 -0
- package/dist/macos/native.js +287 -0
- package/dist/macos/runtime-package.js +30 -0
- package/dist/macos/tab-item.js +62 -0
- package/dist/macos/vite.d.ts +21 -0
- package/dist/macos/vite.js +111 -0
- package/dist/markdown.js +11 -0
- package/dist/mason-engine.js +20 -0
- package/dist/mcp/contracts/actions.js +133 -0
- package/dist/mcp/dev-bridge.js +363 -0
- package/dist/mcp/dev-socket.js +161 -0
- package/dist/mcp/dev-stack.js +134 -0
- package/dist/mcp/inspection/dom.web.js +46 -0
- package/dist/native-regex.js +123 -0
- package/dist/package-manager.js +106 -0
- package/dist/package-root.js +48 -0
- package/dist/patches.js +356 -0
- package/dist/route-config.js +53 -0
- package/dist/route-data.js +42 -0
- package/dist/route-generator.js +514 -0
- package/dist/route-path.js +29 -0
- package/dist/route-source.js +67 -0
- package/dist/targets.js +38 -0
- package/dist/tsconfig-envs.js +287 -0
- package/dist/tsrx-leaf.js +57 -0
- package/dist/typecheck-globals/macos.d.ts +21 -0
- package/dist/typecheck-globals/native.d.ts +26 -0
- package/dist/ui/src/markdown/markdown-ast.js +33 -0
- package/dist/ui/src/markdown/markdown-character-references.js +79 -0
- package/dist/ui/src/markdown/markdown-parse.js +1930 -0
- package/dist/ui/src/markdown/markdown-plugins.js +564 -0
- package/dist/ui/src/markdown/markdown-url.js +17 -0
- package/dist/updates-worker.js +34 -0
- package/dist/upgrade-worker.js +63 -0
- package/dist/vite.d.ts +85 -0
- package/dist/vite.js +628 -0
- package/dist/workshop-worker.js +181 -0
- package/package.json +72 -5
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { srcUrl } from "../../env.js";
|
|
2
|
+
import { readFileSync, statSync } from "node:fs";
|
|
3
|
+
import "node:module";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
// ../cli/src/macos/jsc-host/runtime.ts
|
|
8
|
+
var hostRoot = fileURLToPath(srcUrl(import.meta.url, ""));
|
|
9
|
+
var prebuiltRoot = join(hostRoot, "prebuilt");
|
|
10
|
+
join(prebuiltRoot, "macos");
|
|
11
|
+
var minimumJscHostSystemVersion = "13.5";
|
|
12
|
+
var macOSArchitectures = ["arm64", "x86_64"];
|
|
13
|
+
function isFile(path) {
|
|
14
|
+
try {
|
|
15
|
+
return statSync(path).isFile();
|
|
16
|
+
} catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
var machOArchNames = /* @__PURE__ */ new Map([[16777228, "arm64"], [16777223, "x86_64"]]);
|
|
21
|
+
/** Slice `bytes` into thin Mach-O images: itself, or each fat-arch member. */
|
|
22
|
+
function machOSlices(bytes) {
|
|
23
|
+
const magic = bytes.readUInt32BE(0);
|
|
24
|
+
if (magic !== 3405691582 && magic !== 3405691583) return [bytes];
|
|
25
|
+
const wide = magic === 3405691583;
|
|
26
|
+
const count = bytes.readUInt32BE(4);
|
|
27
|
+
const entrySize = wide ? 32 : 20;
|
|
28
|
+
const slices = [];
|
|
29
|
+
for (let index = 0; index < count; index++) {
|
|
30
|
+
const entry = 8 + index * entrySize;
|
|
31
|
+
if (entry + entrySize > bytes.length) break;
|
|
32
|
+
const offset = wide ? Number(bytes.readBigUInt64BE(entry + 8)) : bytes.readUInt32BE(entry + 8);
|
|
33
|
+
const size = wide ? Number(bytes.readBigUInt64BE(entry + 16)) : bytes.readUInt32BE(entry + 12);
|
|
34
|
+
slices.push(bytes.subarray(offset, offset + size));
|
|
35
|
+
}
|
|
36
|
+
return slices;
|
|
37
|
+
}
|
|
38
|
+
function inspectMachO(bytes, label, issues, minimumSystemVersion = minimumJscHostSystemVersion, architectures = macOSArchitectures) {
|
|
39
|
+
if (bytes.length < 32) {
|
|
40
|
+
issues.push(`${label} is not a Mach-O binary`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const found = /* @__PURE__ */ new Set();
|
|
44
|
+
let images = 0;
|
|
45
|
+
for (const slice of machOSlices(bytes)) {
|
|
46
|
+
if (slice.length < 32 || slice.readUInt32LE(0) !== 4277009103) continue;
|
|
47
|
+
images++;
|
|
48
|
+
const arch = machOArchNames.get(slice.readUInt32LE(4));
|
|
49
|
+
if (arch) found.add(arch);
|
|
50
|
+
inspectThinMachO(slice, arch ? `${label} (${arch})` : label, issues, minimumSystemVersion);
|
|
51
|
+
}
|
|
52
|
+
if (!images) {
|
|
53
|
+
issues.push(`${label} is not a Mach-O binary`);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
for (const arch of architectures) if (!found.has(arch)) issues.push(`${label} lacks an ${arch} slice`);
|
|
57
|
+
}
|
|
58
|
+
function inspectThinMachO(slice, label, issues, minimumSystemVersion) {
|
|
59
|
+
const commands = slice.readUInt32LE(16);
|
|
60
|
+
let offset = 32;
|
|
61
|
+
let minimumVersion;
|
|
62
|
+
for (let index = 0; index < commands; index++) {
|
|
63
|
+
if (offset + 8 > slice.length) {
|
|
64
|
+
issues.push(`${label} has truncated load commands`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const command = slice.readUInt32LE(offset);
|
|
68
|
+
const size = slice.readUInt32LE(offset + 4);
|
|
69
|
+
if (size < 8 || offset + size > slice.length) {
|
|
70
|
+
issues.push(`${label} has invalid load commands`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (command === 50 && size >= 24) {
|
|
74
|
+
const version = slice.readUInt32LE(offset + 12);
|
|
75
|
+
minimumVersion = `${version >>> 16}.${version >>> 8 & 255}`;
|
|
76
|
+
}
|
|
77
|
+
if (command === 12 && size >= 24) {
|
|
78
|
+
const nameOffset = slice.readUInt32LE(offset + 8);
|
|
79
|
+
if (nameOffset < size) {
|
|
80
|
+
const name = slice.toString("utf8", offset + nameOffset, offset + size).split("\0")[0];
|
|
81
|
+
if (name.startsWith("@rpath/")) issues.push(`${label} requires an unpackaged library: ${name}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
offset += size;
|
|
85
|
+
}
|
|
86
|
+
if (!minimumVersion) issues.push(`${label} does not declare a macOS deployment target`);
|
|
87
|
+
else {
|
|
88
|
+
const [major, minor] = minimumVersion.split(".").map(Number);
|
|
89
|
+
const [allowedMajor, allowedMinor] = minimumSystemVersion.split(".").map(Number);
|
|
90
|
+
if (major > allowedMajor || major === allowedMajor && minor > allowedMinor) issues.push(`${label} requires macOS ${minimumVersion}, above the declared ${minimumSystemVersion}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function inspectJscHost() {
|
|
94
|
+
const issues = [];
|
|
95
|
+
let manifest;
|
|
96
|
+
try {
|
|
97
|
+
manifest = JSON.parse(readFileSync(join(prebuiltRoot, "manifest.json"), "utf8"));
|
|
98
|
+
} catch {
|
|
99
|
+
return {
|
|
100
|
+
issues: ["JavaScriptCore host manifest is missing or invalid"],
|
|
101
|
+
manifest: null
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
for (const [relativePath, expectedHash] of Object.entries(manifest.sha256 ?? {})) {
|
|
105
|
+
const path = join(prebuiltRoot, relativePath);
|
|
106
|
+
if (!isFile(path)) {
|
|
107
|
+
issues.push(`JavaScriptCore host file is missing: ${relativePath}`);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const bytes = readFileSync(path);
|
|
111
|
+
if (createHash("sha256").update(bytes).digest("hex") !== expectedHash) issues.push(`JavaScriptCore host checksum mismatch: ${relativePath}`);
|
|
112
|
+
if (relativePath.endsWith("/host") || relativePath.endsWith("/NativeScript")) inspectMachO(bytes, relativePath, issues);
|
|
113
|
+
else if (relativePath.endsWith("/objc-metadata-generator")) {
|
|
114
|
+
const generatorIssues = [];
|
|
115
|
+
inspectMachO(bytes, relativePath, generatorIssues, minimumJscHostSystemVersion);
|
|
116
|
+
issues.push(...generatorIssues.filter((issue) => !issue.includes("unpackaged library")));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
for (const relativePath of [
|
|
120
|
+
"macos/host",
|
|
121
|
+
"macos/metadata.macos.arm64.nsmd",
|
|
122
|
+
"macos/metadata.macos.x86_64.nsmd",
|
|
123
|
+
"macos/NativeScript.framework/Versions/A/NativeScript",
|
|
124
|
+
"macos/objc-metadata-generator"
|
|
125
|
+
]) if (!manifest.sha256?.[relativePath]) issues.push(`JavaScriptCore host manifest omits ${relativePath}`);
|
|
126
|
+
if (!Array.isArray(manifest.architectures) || manifest.architectures.length !== macOSArchitectures.length || !macOSArchitectures.every((arch) => manifest.architectures.includes(arch))) issues.push(`JavaScriptCore host manifest architectures must be ${macOSArchitectures.join(",")}`);
|
|
127
|
+
if (manifest.minimumSystemVersion !== "13.5") issues.push("JavaScriptCore host deployment target differs from package configuration");
|
|
128
|
+
if (!isFile(join(hostRoot, "shim.js"))) issues.push("JavaScriptCore host shim is missing");
|
|
129
|
+
return {
|
|
130
|
+
issues,
|
|
131
|
+
manifest
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
export { hostRoot, inspectJscHost, inspectMachO, macOSArchitectures, minimumJscHostSystemVersion, prebuiltRoot };
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { macOSExecutable } from "./executables.js";
|
|
2
|
+
import { installedPackageRoot } from "../package-root.js";
|
|
3
|
+
import { prebuiltRoot } from "./jsc-host/runtime.js";
|
|
4
|
+
import fs, { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
5
|
+
import "node:module";
|
|
6
|
+
import { basename, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { execFile } from "node:child_process";
|
|
10
|
+
import "node:fs/promises";
|
|
11
|
+
import { promisify } from "node:util";
|
|
12
|
+
// ../cli/src/macos/native.ts
|
|
13
|
+
var execute = promisify(execFile);
|
|
14
|
+
var hash = (value) => createHash("sha256").update(value).digest("hex");
|
|
15
|
+
var compilerExtensions = /* @__PURE__ */ new Set([
|
|
16
|
+
".c",
|
|
17
|
+
".m",
|
|
18
|
+
".mm",
|
|
19
|
+
".swift",
|
|
20
|
+
".zig"
|
|
21
|
+
]);
|
|
22
|
+
fileURLToPath(import.meta.url);
|
|
23
|
+
async function run(command, args, stage, env = process.env) {
|
|
24
|
+
try {
|
|
25
|
+
return (await execute(command, args, {
|
|
26
|
+
timeout: 18e4,
|
|
27
|
+
maxBuffer: 33554432,
|
|
28
|
+
env
|
|
29
|
+
})).stdout.trim();
|
|
30
|
+
} catch (error) {
|
|
31
|
+
const diagnostics = (error.stderr ?? error.message).split("\n").filter((line) => /error:|fatal error:|aborted|failed|dyld:/.test(line));
|
|
32
|
+
throw new Error(`[macos-native] ${stage}: ${command} exited ${error.code ?? error.signal ?? "unsuccessfully"}\n${(diagnostics.join("\n") || error.stderr || error.message).slice(-6e3)}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function inside(root, path) {
|
|
36
|
+
const rel = relative(root, path);
|
|
37
|
+
return rel === "" || !isAbsolute(rel) && rel !== ".." && !rel.startsWith(`..${sep}`);
|
|
38
|
+
}
|
|
39
|
+
function strings(value, label, fallback = []) {
|
|
40
|
+
if (value === void 0) return fallback;
|
|
41
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string" || !item.trim())) throw new Error(`${label} must be an array of nonempty strings`);
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
function nativeFiles(root, dir = root, seen = /* @__PURE__ */ new Set()) {
|
|
45
|
+
const actual = realpathSync(dir);
|
|
46
|
+
if (!inside(root, actual)) throw new Error(`Native input escapes platforms/macos: ${dir}`);
|
|
47
|
+
if (seen.has(actual)) throw new Error(`Native input contains a symlink cycle: ${dir}`);
|
|
48
|
+
seen.add(actual);
|
|
49
|
+
const files = [];
|
|
50
|
+
for (const entry of readdirSync(dir).sort()) {
|
|
51
|
+
const path = join(dir, entry);
|
|
52
|
+
if (!inside(root, realpathSync(path))) throw new Error(`Native input escapes platforms/macos: ${path}`);
|
|
53
|
+
if (statSync(path).isDirectory()) files.push(...nativeFiles(root, path, seen));
|
|
54
|
+
else if (statSync(path).isFile()) files.push(path);
|
|
55
|
+
}
|
|
56
|
+
seen.delete(actual);
|
|
57
|
+
return files;
|
|
58
|
+
}
|
|
59
|
+
function select(root, nativeRoot, patterns, label) {
|
|
60
|
+
if (typeof fs.globSync !== "function") throw new Error("[macos-native] Native source selection requires Node 22.17 or later");
|
|
61
|
+
const files = /* @__PURE__ */ new Set();
|
|
62
|
+
for (const pattern of patterns) {
|
|
63
|
+
if (isAbsolute(pattern) || pattern.split(/[\\/]/).includes("..")) throw new Error(`${label}: package-relative paths required`);
|
|
64
|
+
const matches = fs.globSync(pattern, { cwd: root }).sort();
|
|
65
|
+
if (!matches.length) throw new Error(`${label}: no files match ${pattern}`);
|
|
66
|
+
for (const match of matches) {
|
|
67
|
+
const path = realpathSync(join(root, match));
|
|
68
|
+
if (!inside(nativeRoot, path) || !statSync(path).isFile()) throw new Error(`${label}: input must be a file inside platforms/macos: ${match}`);
|
|
69
|
+
files.add(path);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return [...files].sort();
|
|
73
|
+
}
|
|
74
|
+
function resourceMap(root, nativeRoot, value, label) {
|
|
75
|
+
if (value === void 0) return [];
|
|
76
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${label} must map app resource paths to package files`);
|
|
77
|
+
return Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([destination, source]) => {
|
|
78
|
+
if (!destination.trim() || isAbsolute(destination) || destination.split(/[\\/]/).some((part) => part === ".." || part === ".") || typeof source !== "string" || !source.trim()) throw new Error(`${label} must use safe relative app paths and package files`);
|
|
79
|
+
return {
|
|
80
|
+
destination,
|
|
81
|
+
source: select(root, nativeRoot, [source], label)[0]
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function noticeFile(root, nativeRoot, value, label) {
|
|
86
|
+
if (value === void 0) return null;
|
|
87
|
+
if (typeof value !== "string" || !value.trim()) throw new Error(`${label} must be a package-relative file inside platforms/macos`);
|
|
88
|
+
return select(root, nativeRoot, [value], label)[0];
|
|
89
|
+
}
|
|
90
|
+
/** Resolve runtime dependencies in dependency order, including pnpm/workspace links. */
|
|
91
|
+
function discoverMacOSNative(appRoot) {
|
|
92
|
+
const packages = /* @__PURE__ */ new Map();
|
|
93
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
94
|
+
const leaves = [];
|
|
95
|
+
const prebuilt = [];
|
|
96
|
+
const prebuiltFiles = /* @__PURE__ */ new Map();
|
|
97
|
+
function visit(root) {
|
|
98
|
+
root = realpathSync(root);
|
|
99
|
+
if (packages.has(root) || visiting.has(root)) return;
|
|
100
|
+
visiting.add(root);
|
|
101
|
+
const manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
102
|
+
const deps = {
|
|
103
|
+
...manifest.peerDependencies,
|
|
104
|
+
...manifest.dependencies,
|
|
105
|
+
...manifest.optionalDependencies
|
|
106
|
+
};
|
|
107
|
+
const dependencyRoots = [];
|
|
108
|
+
for (const name of Object.keys(deps).sort()) {
|
|
109
|
+
const dep = installedPackageRoot(root, name);
|
|
110
|
+
if (!dep) {
|
|
111
|
+
if (name in (manifest.optionalDependencies ?? {}) || !(name in (manifest.dependencies ?? {}))) continue;
|
|
112
|
+
throw new Error(`[macos-native] ${manifest.name}: dependency ${name} is not installed; run bun install`);
|
|
113
|
+
}
|
|
114
|
+
dependencyRoots.push(dep);
|
|
115
|
+
visit(dep);
|
|
116
|
+
}
|
|
117
|
+
visiting.delete(root);
|
|
118
|
+
const nativeRoot = join(root, "platforms/macos");
|
|
119
|
+
const config = manifest.xplat?.macos;
|
|
120
|
+
let leaf;
|
|
121
|
+
if (config !== void 0 && (!config || typeof config !== "object" || Array.isArray(config))) throw new Error(`[macos-native] ${manifest.name}: xplat.macos must be an object`);
|
|
122
|
+
if (config !== void 0 || existsSync(nativeRoot)) {
|
|
123
|
+
if (!existsSync(nativeRoot)) throw new Error(`[macos-native] ${manifest.name}: platforms/macos is missing`);
|
|
124
|
+
const allowed = /* @__PURE__ */ new Set([
|
|
125
|
+
"sources",
|
|
126
|
+
"headers",
|
|
127
|
+
"includePaths",
|
|
128
|
+
"frameworks",
|
|
129
|
+
"libraries",
|
|
130
|
+
"defines",
|
|
131
|
+
"swiftWholeModuleOptimization",
|
|
132
|
+
"swiftHeaderImports",
|
|
133
|
+
"resources",
|
|
134
|
+
"notices",
|
|
135
|
+
"prebuiltLibraries"
|
|
136
|
+
]);
|
|
137
|
+
for (const key of Object.keys(config ?? {})) if (!allowed.has(key)) throw new Error(`[macos-native] ${manifest.name}: unknown xplat.macos.${key}`);
|
|
138
|
+
const files = nativeFiles(nativeRoot);
|
|
139
|
+
const defaults = files.filter((path) => inside(join(nativeRoot, "src"), path) && compilerExtensions.has(extname(path)));
|
|
140
|
+
const sources = config?.sources === void 0 ? defaults : select(root, nativeRoot, strings(config.sources, `${manifest.name} sources`), `${manifest.name} sources`);
|
|
141
|
+
const prebuiltLibraries = select(root, nativeRoot, strings(config?.prebuiltLibraries, `${manifest.name} prebuiltLibraries`), `${manifest.name} prebuiltLibraries`);
|
|
142
|
+
for (const path of prebuiltLibraries) if (extname(path) !== ".dylib") throw new Error(`[macos-native] ${manifest.name}: prebuilt library must be a .dylib: ${path}`);
|
|
143
|
+
if (!sources.length && prebuiltLibraries.length) {
|
|
144
|
+
for (const key of Object.keys(config)) if (key !== "prebuiltLibraries" && key !== "notices") throw new Error(`[macos-native] ${manifest.name}: xplat.macos.${key} requires native sources`);
|
|
145
|
+
} else if (sources.length || config !== void 0) {
|
|
146
|
+
if (!sources.length) throw new Error(`[macos-native] ${manifest.name}: no native sources`);
|
|
147
|
+
for (const path of sources) if (!compilerExtensions.has(extname(path))) throw new Error(`[macos-native] ${manifest.name}: unsupported source ${path}`);
|
|
148
|
+
const headers = config?.headers === void 0 ? files.filter((path) => inside(join(nativeRoot, "include"), path) && extname(path) === ".h") : select(root, nativeRoot, strings(config.headers, `${manifest.name} headers`), `${manifest.name} headers`);
|
|
149
|
+
if (!headers.length && !sources.some((path) => extname(path) === ".swift")) throw new Error(`[macos-native] ${manifest.name}: public headers are required`);
|
|
150
|
+
const includePaths = strings(config?.includePaths, `${manifest.name} includePaths`).map((path) => {
|
|
151
|
+
const actual = realpathSync(resolve(root, path));
|
|
152
|
+
if (!inside(nativeRoot, actual) || !statSync(actual).isDirectory()) throw new Error(`${manifest.name}: includePaths must be directories inside platforms/macos`);
|
|
153
|
+
return actual;
|
|
154
|
+
});
|
|
155
|
+
const frameworks = strings(config?.frameworks, `${manifest.name} frameworks`);
|
|
156
|
+
const libraries = strings(config?.libraries, `${manifest.name} libraries`);
|
|
157
|
+
const defines = strings(config?.defines, `${manifest.name} defines`);
|
|
158
|
+
const swiftHeaderImports = strings(config?.swiftHeaderImports, `${manifest.name} swiftHeaderImports`);
|
|
159
|
+
for (const header of swiftHeaderImports) if (!/^[A-Za-z][A-Za-z0-9_]*\/[A-Za-z0-9_./-]+\.h$/.test(header) || header.split("/").includes("..")) throw new Error(`${manifest.name}: invalid Swift Objective-C header import ${header}`);
|
|
160
|
+
const swiftWholeModuleOptimization = config?.swiftWholeModuleOptimization ?? false;
|
|
161
|
+
if (typeof swiftWholeModuleOptimization !== "boolean") throw new Error(`${manifest.name}: swiftWholeModuleOptimization must be boolean`);
|
|
162
|
+
if (swiftHeaderImports.length && !sources.some((path) => extname(path) === ".swift")) throw new Error(`${manifest.name}: swiftHeaderImports require Swift sources`);
|
|
163
|
+
const resources = resourceMap(root, nativeRoot, config?.resources, `${manifest.name} resources`);
|
|
164
|
+
const notices = noticeFile(root, nativeRoot, config?.notices, `${manifest.name} notices`);
|
|
165
|
+
for (const name of [...frameworks, ...libraries]) if (!/^[A-Za-z0-9_+-]+$/.test(name)) throw new Error(`${manifest.name}: invalid system framework/library ${name}`);
|
|
166
|
+
for (const define of defines) if (!/^[A-Za-z_][A-Za-z0-9_]*(?:=[^\r\n]+)?$/.test(define)) throw new Error(`${manifest.name}: invalid define ${define}`);
|
|
167
|
+
const id = `Xplat_${(manifest.name ?? "app").replace(/[^A-Za-z0-9]/g, "_")}_${hash(root).slice(0, 8)}`;
|
|
168
|
+
leaf = {
|
|
169
|
+
root,
|
|
170
|
+
name: manifest.name ?? root,
|
|
171
|
+
id,
|
|
172
|
+
nativeRoot,
|
|
173
|
+
sources,
|
|
174
|
+
headers,
|
|
175
|
+
includePaths,
|
|
176
|
+
frameworks,
|
|
177
|
+
libraries,
|
|
178
|
+
defines,
|
|
179
|
+
swiftWholeModuleOptimization,
|
|
180
|
+
swiftHeaderImports,
|
|
181
|
+
resources,
|
|
182
|
+
notices,
|
|
183
|
+
files,
|
|
184
|
+
dependencyRoots
|
|
185
|
+
};
|
|
186
|
+
leaves.push(leaf);
|
|
187
|
+
}
|
|
188
|
+
if (prebuiltLibraries.length) {
|
|
189
|
+
const notices = leaf ? null : noticeFile(root, nativeRoot, config?.notices, `${manifest.name} notices`);
|
|
190
|
+
for (const path of prebuiltLibraries) {
|
|
191
|
+
const file = basename(path);
|
|
192
|
+
if (prebuiltFiles.has(file)) throw new Error(`[macos-native] Multiple packages ship prebuilt ${file}`);
|
|
193
|
+
prebuiltFiles.set(file, manifest.name);
|
|
194
|
+
prebuilt.push({
|
|
195
|
+
name: manifest.name,
|
|
196
|
+
file,
|
|
197
|
+
source: path,
|
|
198
|
+
notices
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
packages.set(root, {
|
|
204
|
+
manifest,
|
|
205
|
+
dependencyRoots,
|
|
206
|
+
leaf
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
visit(appRoot);
|
|
210
|
+
const resourceDestinations = /* @__PURE__ */ new Set();
|
|
211
|
+
for (const leaf of leaves) for (const { destination } of leaf.resources) {
|
|
212
|
+
if (resourceDestinations.has(destination)) throw new Error(`[macos-native] Multiple leaves package the same app resource: ${destination}`);
|
|
213
|
+
resourceDestinations.add(destination);
|
|
214
|
+
}
|
|
215
|
+
const defineValues = /* @__PURE__ */ new Map();
|
|
216
|
+
for (const leaf of leaves) for (const define of leaf.defines) {
|
|
217
|
+
const key = define.split("=")[0];
|
|
218
|
+
if (defineValues.has(key) && defineValues.get(key) !== define) throw new Error(`[macos-native] ${leaf.name}: conflicting definition for ${key} across native leaves`);
|
|
219
|
+
defineValues.set(key, define);
|
|
220
|
+
}
|
|
221
|
+
for (const leaf of leaves) {
|
|
222
|
+
const seen = /* @__PURE__ */ new Set([leaf.root]);
|
|
223
|
+
const deps = /* @__PURE__ */ new Set();
|
|
224
|
+
function collect(root) {
|
|
225
|
+
if (seen.has(root)) return;
|
|
226
|
+
seen.add(root);
|
|
227
|
+
const pkg = packages.get(root);
|
|
228
|
+
if (pkg.leaf) deps.add(pkg.leaf.id);
|
|
229
|
+
for (const dep of pkg.dependencyRoots) collect(dep);
|
|
230
|
+
}
|
|
231
|
+
for (const root of leaf.dependencyRoots) collect(root);
|
|
232
|
+
leaf.dependencies = leaves.filter((dep) => deps.has(dep.id)).map((dep) => dep.id);
|
|
233
|
+
if (leaf.dependencies.some((id) => leaves.findIndex((dep) => dep.id === id) >= leaves.indexOf(leaf))) throw new Error(`[macos-native] ${leaf.name}: native dependency cycle`);
|
|
234
|
+
}
|
|
235
|
+
const inputs = [...packages.entries()].map(([root, pkg]) => [root, pkg.manifest]);
|
|
236
|
+
for (const leaf of leaves) for (const path of leaf.files) inputs.push([path, hash(readFileSync(path))]);
|
|
237
|
+
for (const lib of prebuilt) {
|
|
238
|
+
inputs.push([lib.source, hash(readFileSync(lib.source))]);
|
|
239
|
+
if (lib.notices) inputs.push([lib.notices, hash(readFileSync(lib.notices))]);
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
leaves,
|
|
243
|
+
prebuilt,
|
|
244
|
+
fingerprint: hash(JSON.stringify(inputs))
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/** Validate the toolchain only when the app actually has native leaves. */
|
|
248
|
+
async function inspectMacOSNative(appRoot) {
|
|
249
|
+
const graph = discoverMacOSNative(appRoot);
|
|
250
|
+
if (!graph.leaves.length) return {
|
|
251
|
+
...graph,
|
|
252
|
+
toolchain: null
|
|
253
|
+
};
|
|
254
|
+
if (process.platform !== "darwin" || process.arch !== "arm64" && process.arch !== "x64") throw new Error("[macos-native] Native leaves require a Mac running macOS arm64 or x86_64: the metadata generator loads the Command Line Tools libclang for the build host architecture");
|
|
255
|
+
const sdkEnv = process.env.XPLAT_MACOS_SDK;
|
|
256
|
+
const sdk = sdkEnv && sdkEnv.startsWith("/") ? sdkEnv : await run("xcrun", [
|
|
257
|
+
"--sdk",
|
|
258
|
+
sdkEnv || "macosx",
|
|
259
|
+
"--show-sdk-path"
|
|
260
|
+
], "locate macOS SDK; install/select Xcode");
|
|
261
|
+
const clang = await run("xcrun", ["--find", "clang"], "locate Xcode compiler");
|
|
262
|
+
const swift = graph.leaves.some((leaf) => leaf.sources.some((path) => extname(path) === ".swift")) ? process.env.XPLAT_MACOS_SWIFTC || await run("xcrun", ["--find", "swiftc"], "locate Swift compiler") : null;
|
|
263
|
+
const zig = graph.leaves.some((leaf) => leaf.sources.some((path) => extname(path) === ".zig")) ? await run("zig", ["version"], "Zig sources require Zig on PATH") : null;
|
|
264
|
+
const manifest = JSON.parse(readFileSync(join(prebuiltRoot, "manifest.json"), "utf8"));
|
|
265
|
+
let generator = join(prebuiltRoot, manifest.metadataGenerator?.path ?? "missing-metadata-generator");
|
|
266
|
+
if (!manifest.metadataGenerator || !existsSync(generator) || hash(readFileSync(generator)) !== manifest.sha256[manifest.metadataGenerator.path]) throw new Error("[macos-native] Metadata generator missing or checksum differs; reinstall the project macOS build tooling");
|
|
267
|
+
generator = await macOSExecutable(appRoot, manifest.metadataGenerator.path);
|
|
268
|
+
const libclang = await run(generator, ["--xplat-check"], "load metadata generator; install compatible Command Line Tools libclang");
|
|
269
|
+
const clangVersion = await run(clang, ["--version"], "inspect compiler");
|
|
270
|
+
const swiftVersion = swift ? await run(swift, ["--version"], "inspect Swift compiler") : null;
|
|
271
|
+
return {
|
|
272
|
+
...graph,
|
|
273
|
+
toolchain: {
|
|
274
|
+
sdk,
|
|
275
|
+
clang,
|
|
276
|
+
swift,
|
|
277
|
+
zig,
|
|
278
|
+
libclang,
|
|
279
|
+
clangVersion,
|
|
280
|
+
swiftVersion,
|
|
281
|
+
sdkSettings: hash(readFileSync(join(sdk, "SDKSettings.json"))),
|
|
282
|
+
generator,
|
|
283
|
+
generatorHash: manifest.sha256[manifest.metadataGenerator.path]
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
export { discoverMacOSNative, inspectMacOSNative };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { installedPackageRoot } from "../package-root.js";
|
|
2
|
+
import { readFileSync, statSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
// ../cli/src/macos/runtime-package.ts
|
|
5
|
+
var macOSRuntimePackageName = "@nativescript/macos-node-api";
|
|
6
|
+
var requiredPackageFiles = ["index.d.ts", "LICENSE"];
|
|
7
|
+
function readPackageManifest(path) {
|
|
8
|
+
try {
|
|
9
|
+
const manifest = JSON.parse(readFileSync(path, "utf8"));
|
|
10
|
+
return manifest && typeof manifest === "object" && !Array.isArray(manifest) ? manifest : null;
|
|
11
|
+
} catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function isFile(path) {
|
|
16
|
+
try {
|
|
17
|
+
return statSync(path).isFile();
|
|
18
|
+
} catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function inspectMacOSRuntimePackage(appRoot) {
|
|
23
|
+
const packageRoot = installedPackageRoot(appRoot, "@nativescript/macos-node-api") ?? join(appRoot, "node_modules", ..."@nativescript/macos-node-api".split("/"));
|
|
24
|
+
return {
|
|
25
|
+
packageRoot,
|
|
26
|
+
packageManifest: readPackageManifest(join(packageRoot, "package.json")),
|
|
27
|
+
missingPaths: requiredPackageFiles.filter((path) => !isFile(join(packageRoot, path)))
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export { inspectMacOSRuntimePackage, macOSRuntimePackageName };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { parseModule } from "@tsrx/core";
|
|
2
|
+
// ../cli/src/macos/tab-item.ts
|
|
3
|
+
/** Keep native handles inside a source-tree component that owns their portals. */
|
|
4
|
+
function tabItemContentRoots() {
|
|
5
|
+
return {
|
|
6
|
+
name: "xplat-appkit-owned-content",
|
|
7
|
+
enforce: "pre",
|
|
8
|
+
transform(source, id) {
|
|
9
|
+
if (!/\.(?:tsx|tsrx)(?:\?|$)/.test(id) || /\.web\.(?:tsx|tsrx)(?:\?|$)/.test(id) || id.includes("/macos-appkit/src/portal-components.macos.tsx")) return null;
|
|
10
|
+
if (/@jsxImportSource\s+@octane-xplat\/jsx\/dom\b/.test(source)) return null;
|
|
11
|
+
if (!/tabviewitem|listview/.test(source)) return null;
|
|
12
|
+
const ast = parseModule(source, id.split("?")[0]);
|
|
13
|
+
const edits = [];
|
|
14
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
15
|
+
const names = {
|
|
16
|
+
tabviewitem: "__PortalTabItem",
|
|
17
|
+
listview: "__PortalList"
|
|
18
|
+
};
|
|
19
|
+
function binding(tag) {
|
|
20
|
+
if (bindings.has(tag)) return bindings.get(tag);
|
|
21
|
+
let name = "__Xplat" + names[tag];
|
|
22
|
+
while (source.includes(name)) name += "_";
|
|
23
|
+
bindings.set(tag, name);
|
|
24
|
+
return name;
|
|
25
|
+
}
|
|
26
|
+
function visit(node) {
|
|
27
|
+
if (!node || typeof node !== "object") return;
|
|
28
|
+
if (node.type === "JSXElement" && node.openingElement.name.type === "JSXIdentifier") {
|
|
29
|
+
const tag = node.openingElement.name.name;
|
|
30
|
+
if (tag in names) {
|
|
31
|
+
const name = binding(tag);
|
|
32
|
+
edits.push([
|
|
33
|
+
node.openingElement.name.start,
|
|
34
|
+
node.openingElement.name.end,
|
|
35
|
+
name
|
|
36
|
+
]);
|
|
37
|
+
if (node.closingElement) edits.push([
|
|
38
|
+
node.closingElement.name.start,
|
|
39
|
+
node.closingElement.name.end,
|
|
40
|
+
name
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
for (const [key, value] of Object.entries(node)) {
|
|
45
|
+
if (key === "metadata" || key === "loc") continue;
|
|
46
|
+
if (Array.isArray(value)) for (const child of value) visit(child);
|
|
47
|
+
else if (value && typeof value === "object") visit(value);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
visit(ast);
|
|
51
|
+
if (!edits.length) return null;
|
|
52
|
+
let code = source;
|
|
53
|
+
for (const [start, end, replacement] of edits.sort((a, b) => b[0] - a[0])) code = code.slice(0, start) + replacement + code.slice(end);
|
|
54
|
+
code += `\nimport { ${[...bindings].map(([tag, name]) => `${names[tag]} as ${name}`).join(", ")} } from '@octane-xplat/macos-appkit'\n`;
|
|
55
|
+
return {
|
|
56
|
+
code,
|
|
57
|
+
map: null
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export { tabItemContentRoots };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { UserConfig } from 'vite'
|
|
2
|
+
|
|
3
|
+
export interface XplatMacOSOptions {
|
|
4
|
+
/** App directory used to resolve its toolchain and renderer. Defaults to cwd. */
|
|
5
|
+
root?: string
|
|
6
|
+
/** Bundle the renderer and Octane for the host. Defaults to true. */
|
|
7
|
+
packaged?: boolean
|
|
8
|
+
/** Enable Octane's universal component HMR. Defaults to false. */
|
|
9
|
+
hmr?: boolean
|
|
10
|
+
/** Override the application entry; defaults to src/main.mjs when packaged. */
|
|
11
|
+
entry?: string
|
|
12
|
+
outDir?: string
|
|
13
|
+
/** Override renderer rules; defaults to all reachable TSX/TSRX source. */
|
|
14
|
+
rules?: unknown[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Configure the experimental AppKit renderer using the app's installed toolchain. */
|
|
18
|
+
export function xplatMacOS(
|
|
19
|
+
env: { mode: string } | string,
|
|
20
|
+
options?: XplatMacOSOptions,
|
|
21
|
+
): Promise<UserConfig>
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { xplatCss } from "../css-platform.js";
|
|
2
|
+
import { xplatBoundary, xplatNodeEnvDefine } from "../vite.js";
|
|
3
|
+
import { nativeDevSocketPlugin } from "../mcp/dev-socket.js";
|
|
4
|
+
import { tabItemContentRoots } from "./tab-item.js";
|
|
5
|
+
import { xplatInlineStylesheets } from "../inline-stylesheets.js";
|
|
6
|
+
import { realpathSync } from "node:fs";
|
|
7
|
+
import { createRequire } from "node:module";
|
|
8
|
+
import { join, resolve } from "node:path";
|
|
9
|
+
import { pathToFileURL } from "node:url";
|
|
10
|
+
// ../cli/src/macos/vite.ts
|
|
11
|
+
var renderer = "@octane-xplat/macos-appkit";
|
|
12
|
+
var runtime = "@nativescript/macos-node-api";
|
|
13
|
+
/** AppKit compiler and bundle setup; the consuming app owns the toolchain. */
|
|
14
|
+
async function xplatMacOS(env, options = {}) {
|
|
15
|
+
const mode = typeof env === "string" ? env : env.mode;
|
|
16
|
+
const root = resolve(options.root ?? process.cwd());
|
|
17
|
+
const appRequire = createRequire(join(root, "package.json"));
|
|
18
|
+
const { octane } = await import(pathToFileURL(realpathSync(appRequire.resolve("@octanejs/vite-plugin"))).href);
|
|
19
|
+
const packaged = options.packaged ?? true;
|
|
20
|
+
const resolveApp = (name) => realpathSync(appRequire.resolve(name));
|
|
21
|
+
return {
|
|
22
|
+
root,
|
|
23
|
+
define: xplatNodeEnvDefine(mode),
|
|
24
|
+
plugins: [
|
|
25
|
+
...mode === "development" ? [nativeDevSocketPlugin()].filter(Boolean) : [],
|
|
26
|
+
xplatCss("macos"),
|
|
27
|
+
xplatInlineStylesheets(),
|
|
28
|
+
xplatBoundary("macos"),
|
|
29
|
+
tabItemContentRoots(),
|
|
30
|
+
octane({
|
|
31
|
+
hmr: options.hmr ?? false,
|
|
32
|
+
exclude: ["types/macos", ...options.exclude ?? []],
|
|
33
|
+
renderers: {
|
|
34
|
+
registry: { macos: {
|
|
35
|
+
module: renderer,
|
|
36
|
+
target: "universal",
|
|
37
|
+
server: "unsupported",
|
|
38
|
+
text: "host",
|
|
39
|
+
intrinsics: "@octane-xplat/jsx"
|
|
40
|
+
} },
|
|
41
|
+
rules: options.rules ?? [{
|
|
42
|
+
include: "**/*.{tsx,tsrx}",
|
|
43
|
+
renderer: "macos"
|
|
44
|
+
}]
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
],
|
|
48
|
+
build: {
|
|
49
|
+
cssCodeSplit: true,
|
|
50
|
+
outDir: options.outDir ?? (packaged ? "dist/package-build" : "dist"),
|
|
51
|
+
emptyOutDir: packaged,
|
|
52
|
+
lib: {
|
|
53
|
+
entry: options.entry ?? (packaged ? "src/main.ts" : "src/App.tsx"),
|
|
54
|
+
formats: packaged ? ["cjs"] : ["es"],
|
|
55
|
+
fileName: packaged ? "main" : "app"
|
|
56
|
+
},
|
|
57
|
+
rollupOptions: {
|
|
58
|
+
external: packaged ? [runtime, /^node:/] : [
|
|
59
|
+
runtime,
|
|
60
|
+
renderer,
|
|
61
|
+
/^octane\//
|
|
62
|
+
],
|
|
63
|
+
output: { codeSplitting: false }
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
resolve: {
|
|
67
|
+
conditions: ["macos", "native"],
|
|
68
|
+
dedupe: ["octane"],
|
|
69
|
+
alias: [
|
|
70
|
+
...packaged ? [{
|
|
71
|
+
find: /^@octane-xplat\/macos-appkit$/,
|
|
72
|
+
replacement: resolveApp(renderer)
|
|
73
|
+
}] : [],
|
|
74
|
+
{
|
|
75
|
+
find: /^octane$/,
|
|
76
|
+
replacement: "octane/universal/native"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
find: /^@nativescript-community\/octane$/,
|
|
80
|
+
replacement: renderer
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
find: "./escape-props",
|
|
84
|
+
replacement: resolveApp(`${renderer}/compat/escape-props`)
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
find: /^@nativescript\/core$/,
|
|
88
|
+
replacement: resolveApp(`${renderer}/compat/native-core`)
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
find: /^@nativescript\/core\/animation-frame$/,
|
|
92
|
+
replacement: resolveApp(`${renderer}/compat/native-core`)
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
extensions: [
|
|
96
|
+
".macos.tsrx",
|
|
97
|
+
".tsrx",
|
|
98
|
+
".macos.tsx",
|
|
99
|
+
".tsx",
|
|
100
|
+
".macos.ts",
|
|
101
|
+
".ts",
|
|
102
|
+
".mts",
|
|
103
|
+
".ts",
|
|
104
|
+
".jsx",
|
|
105
|
+
".js",
|
|
106
|
+
".json"
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export { xplatMacOS };
|
package/dist/markdown.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { parseMdDoc } from "./ui/src/markdown/markdown-parse.js";
|
|
2
|
+
// ../cli/src/markdown.ts
|
|
3
|
+
/** Bake Markdown source into a versioned `MdDoc` (v2) for route codegen.
|
|
4
|
+
* The JSON round-trip drops absent optional fields (`start` on an unordered
|
|
5
|
+
* list, `delimiter`, `spread`, …) so the embedded literal is exactly what
|
|
6
|
+
* `JSON.parse` hands the runtime — assertRouteDataJson rejects undefined
|
|
7
|
+
* fields as silently-dropped data otherwise. */
|
|
8
|
+
function mdToDoc(src) {
|
|
9
|
+
return JSON.parse(JSON.stringify(parseMdDoc(src)));
|
|
10
|
+
}
|
|
11
|
+
export { mdToDoc };
|