@octane-xplat/build 0.0.0-nightly.g1b95ef7

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.
Files changed (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/dist/add-worker.js +66 -0
  4. package/dist/build-worker.js +287 -0
  5. package/dist/compatibility-check.js +155 -0
  6. package/dist/compatibility-data/compatibility.js +109 -0
  7. package/dist/compatibility-data/compatibility.json +298 -0
  8. package/dist/compatibility.js +240 -0
  9. package/dist/css-platform.js +236 -0
  10. package/dist/css-platform.types.d.ts +11 -0
  11. package/dist/dev-inspector.web.js +125 -0
  12. package/dist/dev-log-client.web.js +79 -0
  13. package/dist/dev-log-server.js +13 -0
  14. package/dist/devtools-worker.js +94 -0
  15. package/dist/doctor-checks.js +414 -0
  16. package/dist/doctor-tool.js +27 -0
  17. package/dist/env.js +3 -0
  18. package/dist/fmt-plan.js +149 -0
  19. package/dist/fonts-worker.js +31 -0
  20. package/dist/fonts.js +614 -0
  21. package/dist/inline-stylesheets.js +44 -0
  22. package/dist/linux/config.js +43 -0
  23. package/dist/linux/gtk-runtime.js +86 -0
  24. package/dist/linux/package.js +189 -0
  25. package/dist/linux-gtk/bindings.mjs +675 -0
  26. package/dist/linux-gtk/native-gi-projection.js +36 -0
  27. package/dist/linux-gtk/vite.d.ts +39 -0
  28. package/dist/linux-gtk/vite.js +281 -0
  29. package/dist/macos/config.js +136 -0
  30. package/dist/macos/core-ui.js +59 -0
  31. package/dist/macos/core-vite.js +122 -0
  32. package/dist/macos/doctor-checks.js +58 -0
  33. package/dist/macos/executables.js +39 -0
  34. package/dist/macos/jsc-host/runtime.js +134 -0
  35. package/dist/macos/native.js +286 -0
  36. package/dist/macos/runtime-package.js +30 -0
  37. package/dist/macos/tab-item.js +62 -0
  38. package/dist/macos/vite.d.ts +13 -0
  39. package/dist/macos/vite.js +22 -0
  40. package/dist/markdown.js +11 -0
  41. package/dist/mason-engine.js +20 -0
  42. package/dist/mcp/contracts/actions.js +133 -0
  43. package/dist/mcp/dev-bridge.js +363 -0
  44. package/dist/mcp/dev-socket.js +203 -0
  45. package/dist/mcp/dev-stack.js +134 -0
  46. package/dist/mcp/inspection/dom.web.js +46 -0
  47. package/dist/native-regex.js +123 -0
  48. package/dist/package-manager.js +106 -0
  49. package/dist/package-root.js +48 -0
  50. package/dist/patches.js +356 -0
  51. package/dist/route-config.js +53 -0
  52. package/dist/route-data.js +42 -0
  53. package/dist/route-generator.js +514 -0
  54. package/dist/route-path.js +29 -0
  55. package/dist/route-source.js +67 -0
  56. package/dist/targets.js +37 -0
  57. package/dist/tsconfig-envs.js +400 -0
  58. package/dist/tsconfig-pin.js +31 -0
  59. package/dist/tsrx-leaf.js +57 -0
  60. package/dist/typecheck-globals/macos.d.ts +21 -0
  61. package/dist/typecheck-globals/native.d.ts +42 -0
  62. package/dist/ui/src/markdown/markdown-ast.js +33 -0
  63. package/dist/ui/src/markdown/markdown-character-references.js +79 -0
  64. package/dist/ui/src/markdown/markdown-parse.js +1930 -0
  65. package/dist/ui/src/markdown/markdown-plugins.js +564 -0
  66. package/dist/ui/src/markdown/markdown-url.js +17 -0
  67. package/dist/updates-worker.js +34 -0
  68. package/dist/upgrade-worker.js +63 -0
  69. package/dist/vite-target.js +57 -0
  70. package/dist/vite.d.ts +125 -0
  71. package/dist/vite.js +797 -0
  72. package/dist/workshop-worker.js +181 -0
  73. package/package.json +74 -0
@@ -0,0 +1,236 @@
1
+ import { buildTarget } from "./vite-target.js";
2
+ import { existsSync } from "node:fs";
3
+ import { dirname, isAbsolute, resolve } from "node:path";
4
+ import postcss from "postcss";
5
+ import loadPostcssConfig from "postcss-load-config";
6
+ // ../cli/src/css-platform.ts
7
+ var buildTargets = /* @__PURE__ */ new Set([
8
+ "web",
9
+ "ios",
10
+ "android",
11
+ "visionos",
12
+ "macos",
13
+ "windows",
14
+ "linux",
15
+ "gtk",
16
+ "native"
17
+ ]);
18
+ var targets = /* @__PURE__ */ new Set([...buildTargets, "mobile"]);
19
+ var qualified = /\.(web|ios|android|visionos|mobile|macos|windows|linux|gtk|native)\.css$/;
20
+ var cssId = /\.css(?:[?#].*)?$/;
21
+ var cleanId = (id) => id.split(/[?#]/, 1)[0];
22
+ /** `?raw`/`?url` css requests resolve to a JavaScript wrapper (an
23
+ * `export default` string or a URL), not stylesheet text — native CSS
24
+ * transforms must skip them. */
25
+ var cssWrapperQuery = /(?:\?|&)(?:raw|url)(?:&|$)/;
26
+ function suffixes(platform) {
27
+ if (platform === "ios" || platform === "android") return [platform, "mobile"];
28
+ if (platform === "visionos") return ["ios", "mobile"];
29
+ return platform === "native" ? [] : [platform];
30
+ }
31
+ function matches(condition, platform) {
32
+ return condition === platform || condition === "mobile" && [
33
+ "ios",
34
+ "android",
35
+ "visionos"
36
+ ].includes(platform) || condition === "native" && platform !== "web";
37
+ }
38
+ var deferredLayerPrefix = "xplat-platform-";
39
+ var deferredLayerName = /^xplat-platform-([a-z]+(?:_[a-z]+)*)$/;
40
+ function platformTargetNames(rule) {
41
+ const names = rule.params.replace(/\/\*[\s\S]*?\*\//g, " ").split(",").map((name) => name.trim());
42
+ if (!rule.nodes || names.some((name) => !targets.has(name))) throw rule.error(`Expected @platform <target>[, <target> ...] { ... }; targets: ${[...targets].join(", ")}`);
43
+ return names;
44
+ }
45
+ /** Targets carried by a deferred `@layer xplat-platform-*` block, if it is one. */
46
+ function deferredLayerNames(rule) {
47
+ if (rule.name !== "layer" || !rule.nodes) return;
48
+ const names = deferredLayerName.exec(rule.params.trim())?.[1].split("_");
49
+ return names?.every((name) => targets.has(name)) ? names : void 0;
50
+ }
51
+ function filterPlatforms(root, platform) {
52
+ const conditions = /* @__PURE__ */ new Map();
53
+ root.walkAtRules((rule) => {
54
+ const names = rule.name === "platform" ? platformTargetNames(rule) : deferredLayerNames(rule);
55
+ if (names) conditions.set(rule, names);
56
+ });
57
+ for (const [rule, names] of conditions) if (names.some((name) => matches(name, platform))) rule.replaceWith(...rule.nodes);
58
+ else rule.remove();
59
+ }
60
+ /** Compile platform blocks while retaining source positions for diagnostics. */
61
+ function platformCssPlugin(platform, deferred = /* @__PURE__ */ new Set()) {
62
+ return {
63
+ postcssPlugin: "xplat-platform",
64
+ Once(root) {
65
+ if (![...deferred].some((id) => root.source?.input.file?.endsWith(id))) filterPlatforms(root, platform);
66
+ }
67
+ };
68
+ }
69
+ /**
70
+ * Deferred sheets reach Vite's CSS minifier before the final projection, and
71
+ * minifiers warn on the unknown `@platform` at-rule. Rewriting the blocks as
72
+ * uniquely named `@layer` wrappers keeps every class reachable for validation
73
+ * and minifies silently; the projection decodes them. Layers are legal
74
+ * everywhere `@platform` is, including nested inside matching blocks.
75
+ */
76
+ function platformDeferPlugin(deferred) {
77
+ return {
78
+ postcssPlugin: "xplat-platform-defer",
79
+ Once(root) {
80
+ const file = root.source?.input.file;
81
+ if (!file || ![...deferred].some((id) => file.endsWith(id))) return;
82
+ root.walkAtRules("platform", (rule) => {
83
+ const names = platformTargetNames(rule);
84
+ rule.name = "layer";
85
+ rule.params = `${deferredLayerPrefix}${names.join("_")}`;
86
+ });
87
+ }
88
+ };
89
+ }
90
+ /** Parse platform CSS without losing authored declaration positions for audits. */
91
+ function parsePlatformCss(css, platform, from) {
92
+ const root = postcss.parse(css, { from });
93
+ filterPlatforms(root, platform);
94
+ return root;
95
+ }
96
+ /** Whether emitted CSS still carries platform conditions awaiting projection. */
97
+ function hasPlatformConditions(css) {
98
+ return css.includes("@platform") || css.includes(deferredLayerPrefix);
99
+ }
100
+ /** Filter authored or generated CSS before a target-specific consumer parses it. */
101
+ function filterPlatformCss(css, platform, from) {
102
+ return hasPlatformConditions(css) ? parsePlatformCss(css, platform, from).toString() : css;
103
+ }
104
+ /**
105
+ * Select platform CSS siblings and compile build-time `@platform` blocks.
106
+ * CSS suffixes replace the unsuffixed file; they never append to it. Explicit
107
+ * platform filenames stay exact. Native presets include this automatically;
108
+ * custom configs can add `css()` to their Vite plugins.
109
+ */
110
+ function css(platform = buildTarget()) {
111
+ if (!buildTargets.has(platform)) throw new Error(`Unknown CSS build target: ${platform}`);
112
+ const candidates = /* @__PURE__ */ new Set();
113
+ const deferred = /* @__PURE__ */ new Set();
114
+ let aliases = [];
115
+ const select = (id) => {
116
+ const file = cleanId(id);
117
+ if (!file.endsWith(".css") || qualified.test(file)) return id;
118
+ const choices = [...suffixes(platform).map((suffix) => file.slice(0, -4) + `.${suffix}.css`), file];
119
+ for (const choice of choices) candidates.add(choice);
120
+ const selected = choices.find((choice) => existsSync(choice));
121
+ return selected ? selected + id.slice(file.length) : id;
122
+ };
123
+ return {
124
+ name: "xplat-platform-css",
125
+ api: {
126
+ platform,
127
+ preserveLayers: true,
128
+ defer: (id) => deferred.add(id),
129
+ filter: (css, from) => filterPlatformCss(css, platform, from),
130
+ hasPlatformConditions,
131
+ project(css, from, previousMap) {
132
+ const result = postcss([platformCssPlugin(platform)]).process(css, {
133
+ from,
134
+ to: from,
135
+ map: previousMap ? {
136
+ prev: previousMap,
137
+ inline: false,
138
+ annotation: false
139
+ } : false
140
+ });
141
+ return {
142
+ css: result.css,
143
+ map: result.map?.toString()
144
+ };
145
+ }
146
+ },
147
+ enforce: "pre",
148
+ async config(userConfig) {
149
+ if (userConfig.css?.transformer === "lightningcss") throw new Error("css requires the PostCSS transformer; use Lightning CSS for minification instead");
150
+ const configuredAliases = userConfig.resolve?.alias ?? [];
151
+ aliases = Array.isArray(configuredAliases) ? [...configuredAliases] : Object.entries(configuredAliases).map(([find, replacement]) => ({
152
+ find,
153
+ replacement
154
+ }));
155
+ const configured = userConfig.css?.postcss;
156
+ let settings = {};
157
+ if (configured && typeof configured === "object") {
158
+ const { plugins, ...options } = configured;
159
+ settings = {
160
+ options,
161
+ plugins
162
+ };
163
+ } else try {
164
+ settings = await loadPostcssConfig({}, typeof configured === "string" ? configured : userConfig.root ?? process.cwd());
165
+ } catch (error) {
166
+ if (!(error instanceof Error) || !error.message.includes("No PostCSS Config found")) throw error;
167
+ }
168
+ userConfig.css ??= {};
169
+ userConfig.css.postcss = {
170
+ ...settings.options,
171
+ plugins: [
172
+ platformCssPlugin(platform, deferred),
173
+ platformDeferPlugin(deferred),
174
+ ...settings.plugins ?? []
175
+ ]
176
+ };
177
+ return { resolve: { alias: [{
178
+ find: cssId,
179
+ replacement: "$&",
180
+ customResolver: async function(source, importer, options) {
181
+ for (const alias of aliases) {
182
+ if (typeof alias.find === "string" ? source !== alias.find && !source.startsWith(alias.find + "/") : !alias.find.test(source)) continue;
183
+ source = source.replace(alias.find, alias.replacement);
184
+ if (alias.customResolver) {
185
+ const result = await (typeof alias.customResolver === "function" ? alias.customResolver : alias.customResolver.resolveId).call(this, source, importer, options);
186
+ return typeof result === "string" ? select(result) : result && typeof result === "object" ? {
187
+ ...result,
188
+ id: select(result.id)
189
+ } : result;
190
+ }
191
+ break;
192
+ }
193
+ const file = cleanId(source);
194
+ const local = file.startsWith(".") && importer ? resolve(dirname(cleanId(importer)), file) : isAbsolute(file) && existsSync(file) ? file : void 0;
195
+ if (local) {
196
+ const selected = select(local + source.slice(file.length));
197
+ if (existsSync(cleanId(selected))) return selected;
198
+ }
199
+ const resolved = await this.resolve(source, importer, {
200
+ ...options,
201
+ skipSelf: true
202
+ });
203
+ return resolved ? {
204
+ ...resolved,
205
+ id: select(resolved.id)
206
+ } : null;
207
+ }
208
+ }] } };
209
+ },
210
+ transform(code, id) {
211
+ if (!cssId.test(id) || cssWrapperQuery.test(id) || !code.includes("@platform") || [...deferred].some((suffix) => cleanId(id).endsWith(suffix))) return;
212
+ const result = postcss([platformCssPlugin(platform)]).process(code, {
213
+ from: cleanId(id),
214
+ map: {
215
+ inline: false,
216
+ annotation: false
217
+ }
218
+ });
219
+ return {
220
+ code: result.css,
221
+ map: result.map?.toString() ?? null
222
+ };
223
+ },
224
+ configureServer(server) {
225
+ const changed = (file) => {
226
+ if (!candidates.has(file)) return;
227
+ server.restart().catch((error) => server.config.logger.error(String(error)));
228
+ };
229
+ server.watcher.on("add", changed).on("unlink", changed);
230
+ server.httpServer?.once("close", () => {
231
+ server.watcher.off("add", changed).off("unlink", changed);
232
+ });
233
+ }
234
+ };
235
+ }
236
+ export { css, cssWrapperQuery, filterPlatformCss, hasPlatformConditions, parsePlatformCss, platformCssPlugin };
@@ -0,0 +1,11 @@
1
+ /** Renderer targets accepted by platform CSS selection and `@platform` blocks. */
2
+ export type CssPlatform =
3
+ | 'web'
4
+ | 'ios'
5
+ | 'android'
6
+ | 'visionos'
7
+ | 'macos'
8
+ | 'windows'
9
+ | 'linux'
10
+ | 'gtk'
11
+ | 'native'
@@ -0,0 +1,125 @@
1
+ // ../cli/src/dev-inspector.web.ts
2
+ function installDevInspector(inspectDOM) {
3
+ const scope = globalThis;
4
+ const key = "octane-xplat.dev-inspector";
5
+ if (!scope.document || scope[key]) return;
6
+ const documentId = `doc_${scope.crypto.randomUUID()}`;
7
+ scope[key] = {
8
+ version: 1,
9
+ documentId,
10
+ interact(args) {
11
+ const control = args?.control;
12
+ if (!args || Object.keys(args).some((key) => ![
13
+ "documentId",
14
+ "control",
15
+ "mechanism",
16
+ "expiresAt"
17
+ ].includes(key)) || !control || !["id", "testID"].includes(control.kind) || typeof control.name !== "string" || !control.name || control.name.length > 256 || args.mechanism !== "handler-dispatch" || !Number.isSafeInteger(args.expiresAt)) return {
18
+ error: {
19
+ code: "invalid_selection",
20
+ message: "Invalid named-host interaction request."
21
+ },
22
+ outcome: "not-run"
23
+ };
24
+ if (args.documentId !== documentId) return {
25
+ error: {
26
+ code: "stale_identity",
27
+ message: "The document changed; inspect again."
28
+ },
29
+ outcome: "not-run"
30
+ };
31
+ if (Date.now() >= args.expiresAt) return {
32
+ error: {
33
+ code: "unavailable",
34
+ message: "Interaction delivery expired before dispatch."
35
+ },
36
+ outcome: "not-run"
37
+ };
38
+ const select = () => [...scope.document.querySelectorAll("[id],[data-testid]")].filter((element) => (control.kind === "id" ? element.id : element.getAttribute("data-testid")) === control.name);
39
+ const selected = select();
40
+ const before = inspectDOM({
41
+ control,
42
+ offset: 0,
43
+ limit: 1,
44
+ focus: false
45
+ });
46
+ if (before.error) return {
47
+ ...before,
48
+ outcome: "not-run"
49
+ };
50
+ const host = before.controls[0];
51
+ if (!host || host.hidden || host.disabled || host.sensitive || !host.hitTarget) return {
52
+ error: {
53
+ code: "unavailable",
54
+ message: "Control is hidden, disabled, private or obscured; no input was sent."
55
+ },
56
+ outcome: "not-run"
57
+ };
58
+ const current = select();
59
+ if (selected.length !== 1 || current.length !== 1 || current[0] !== selected[0] || !current[0].isConnected) return {
60
+ error: {
61
+ code: "stale_identity",
62
+ message: "The selected host changed before dispatch; inspect again."
63
+ },
64
+ outcome: "not-run"
65
+ };
66
+ if (!(current[0] instanceof scope.HTMLElement)) return {
67
+ error: {
68
+ code: "unsupported_capability",
69
+ message: "Handler dispatch requires an HTML host."
70
+ },
71
+ outcome: "not-run"
72
+ };
73
+ if (Date.now() >= args.expiresAt) return {
74
+ error: {
75
+ code: "unavailable",
76
+ message: "Interaction delivery expired before dispatch."
77
+ },
78
+ outcome: "not-run"
79
+ };
80
+ try {
81
+ scope.HTMLElement.prototype.click.call(current[0]);
82
+ } catch {
83
+ return {
84
+ error: {
85
+ code: "execution_failure",
86
+ message: "Handler dispatch threw; effects are unknown."
87
+ },
88
+ outcome: "unknown"
89
+ };
90
+ }
91
+ return {
92
+ documentId,
93
+ ...before,
94
+ inputSent: true,
95
+ mechanism: "handler-dispatch",
96
+ eventTrusted: false,
97
+ assertion: "Programmatic click dispatch only; inspect the intended app state separately."
98
+ };
99
+ },
100
+ inspect(args) {
101
+ const offset = args?.offset ?? 0;
102
+ const limit = args?.limit ?? 20;
103
+ const control = args?.control;
104
+ if (!args || Object.keys(args).some((key) => ![
105
+ "offset",
106
+ "limit",
107
+ "control"
108
+ ].includes(key)) || !Number.isSafeInteger(offset) || offset < 0 || !Number.isSafeInteger(limit) || limit < 1 || limit > 100 || control !== void 0 && (!control || !["id", "testID"].includes(control.kind) || typeof control.name !== "string" || !control.name || control.name.length > 256)) return { error: {
109
+ code: "invalid_selection",
110
+ message: "Invalid named-host inspection request."
111
+ } };
112
+ const result = inspectDOM({
113
+ control,
114
+ offset,
115
+ limit,
116
+ focus: false
117
+ });
118
+ return result.error ? result : {
119
+ documentId,
120
+ ...result
121
+ };
122
+ }
123
+ };
124
+ }
125
+ export { installDevInspector };
@@ -0,0 +1,79 @@
1
+ // ../cli/src/dev-log-client.web.ts
2
+ function installBrowserLogs(token, endpoint) {
3
+ const browser = globalThis;
4
+ if (browser.__XPLAT_LOGS_INSTALLED__) return;
5
+ browser.__XPLAT_LOGS_INSTALLED__ = true;
6
+ let queue = [];
7
+ let dropped = 0;
8
+ let sending = false;
9
+ const format = (value) => {
10
+ try {
11
+ if (value instanceof Error) return String(value.stack ?? value.message);
12
+ if (value === null || [
13
+ "string",
14
+ "number",
15
+ "boolean",
16
+ "undefined",
17
+ "bigint"
18
+ ].includes(typeof value)) return String(value);
19
+ return "[object omitted]";
20
+ } catch {
21
+ return "[unprintable]";
22
+ }
23
+ };
24
+ const flush = async () => {
25
+ if (sending || !queue.length && !dropped) return;
26
+ sending = true;
27
+ const records = queue.splice(0, 10);
28
+ const lost = dropped;
29
+ dropped = 0;
30
+ try {
31
+ if (!(await browser.fetch(endpoint, {
32
+ method: "POST",
33
+ headers: {
34
+ "content-type": "application/json",
35
+ "x-xplat-dev-token": token
36
+ },
37
+ body: JSON.stringify({
38
+ records,
39
+ dropped: lost
40
+ }),
41
+ keepalive: true
42
+ })).ok) throw new Error("log delivery failed");
43
+ } catch {
44
+ dropped += records.length + lost;
45
+ } finally {
46
+ sending = false;
47
+ if (queue.length || dropped) browser.setTimeout(flush, 1e3);
48
+ }
49
+ };
50
+ const record = (level, values) => {
51
+ if (queue.length === 100) {
52
+ queue.shift();
53
+ dropped++;
54
+ }
55
+ const text = values.slice(0, 10).map((value) => format(value).slice(0, 2049)).join(" ");
56
+ const line = text.length > 2048 || values.length > 10 ? text.slice(0, 2035) + " [truncated]" : text;
57
+ queue.push({
58
+ level,
59
+ line
60
+ });
61
+ flush();
62
+ };
63
+ for (const level of ["warn", "error"]) {
64
+ const original = browser.console[level];
65
+ browser.console[level] = function(...values) {
66
+ original.apply(this, values);
67
+ record(level, values);
68
+ };
69
+ }
70
+ browser.addEventListener("error", (event) => {
71
+ record("error", [event.error ?? event.message ?? "Resource failed to load"]);
72
+ }, true);
73
+ browser.addEventListener("unhandledrejection", (event) => record("error", [event.reason]));
74
+ }
75
+ /** Development HTML script; no browser hooks are installed in release builds. */
76
+ function browserLogScript(token, endpoint) {
77
+ return `(${installBrowserLogs.toString()})(${JSON.stringify(token)}, ${JSON.stringify(endpoint)});`;
78
+ }
79
+ export { browserLogScript };
@@ -0,0 +1,13 @@
1
+ // ../cli/src/dev-log-server.ts
2
+ /** Shared wire validation for the retained HTTP bridge and native dev worker. */
3
+ function formatBrowserLogBatch(body) {
4
+ const input = body;
5
+ if (!input || !Array.isArray(input.records) || input.records.length > 10 || !Number.isSafeInteger(input.dropped ?? 0) || Number(input.dropped ?? 0) < 0 || input.records.some((record) => !record || !["warn", "error"].includes(record.level) || typeof record.line !== "string" || record.line.length > 2048)) throw new Error("Invalid browser log batch.");
6
+ let text = input.dropped ? `[browser:warn] ${input.dropped} browser log records lost before delivery.\n` : "";
7
+ for (const record of input.records) for (const line of record.line.split(/\r?\n/)) text += `[browser:${record.level}] ${line}\n`;
8
+ return {
9
+ text,
10
+ accepted: input.records.length
11
+ };
12
+ }
13
+ export { formatBrowserLogBatch };
@@ -0,0 +1,94 @@
1
+ import { lstatSync, realpathSync, renameSync, statSync, writeFileSync } from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import { basename, dirname, isAbsolute, join, sep } from "node:path";
4
+ import { pathToFileURL } from "node:url";
5
+ import { Console } from "node:console";
6
+ // ../cli/src/devtools-worker.ts
7
+ function devtoolsEntry(project, subpath = "desktop-node") {
8
+ for (let at = project;; at = dirname(at)) {
9
+ for (const anchor of ["@octane-xplat/devtools", "octane-xplat"]) {
10
+ const host = join(at, "node_modules", anchor);
11
+ let found = false;
12
+ try {
13
+ lstatSync(host);
14
+ found = true;
15
+ } catch (error) {
16
+ if (error.code !== "ENOENT") throw error;
17
+ }
18
+ if (!found) continue;
19
+ const require = createRequire(join(host, "package.json"));
20
+ let root;
21
+ let entry;
22
+ try {
23
+ root = dirname(realpathSync(require.resolve("@octane-xplat/devtools/package.json")));
24
+ entry = realpathSync(require.resolve(`@octane-xplat/devtools/${subpath}`));
25
+ } catch (error) {
26
+ if (error.code === "MODULE_NOT_FOUND" || error.code === "ERR_MODULE_NOT_FOUND") continue;
27
+ throw error;
28
+ }
29
+ if (!entry.startsWith(root + sep) || !statSync(entry).isFile()) throw new Error("Reinstall @octane-xplat/devtools: its entry must remain inside the selected package");
30
+ return entry;
31
+ }
32
+ if (dirname(at) === at) break;
33
+ }
34
+ throw new Error("Install octane-xplat in the selected project: bun add -D octane-xplat");
35
+ }
36
+ async function devtoolsWebOperation(request) {
37
+ const project = realpathSync(process.cwd());
38
+ const outDir = request.outDir;
39
+ if (typeof outDir !== "string" || !isAbsolute(outDir) || !/^staging-[a-f0-9]{32}$/.test(basename(outDir)) || !lstatSync(outDir).isDirectory()) throw new Error("Invalid DevTools browser build directory");
40
+ const { buildDevtoolsWeb } = await import(pathToFileURL(devtoolsEntry(project, "web-build")).href);
41
+ await buildDevtoolsWeb(project, outDir);
42
+ return { version: 1 };
43
+ }
44
+ async function devtoolsDesktopService(request, requestFile, resultFile) {
45
+ const project = realpathSync(process.cwd());
46
+ if (request.target !== "macos") throw new Error("Unsupported devtools target");
47
+ const directory = realpathSync(dirname(requestFile));
48
+ if (dirname(request.serviceStateFile) !== directory || basename(request.serviceStateFile) !== "service.json" || request.resourceRoot !== join(directory, "resources")) throw new Error("Invalid native-owned service paths");
49
+ if (request.profileRoot !== "" && (!request.profileRoot.startsWith(project + sep) || !basename(request.profileRoot).startsWith(".xplat-go-profile-") || !lstatSync(request.profileRoot).isDirectory())) throw new Error("Invalid native-owned compiler profile");
50
+ globalThis.console = new Console({
51
+ stdout: process.stdout,
52
+ stderr: process.stderr
53
+ });
54
+ const api = await import(pathToFileURL(devtoolsEntry(project)).href);
55
+ if (api.DEVTOOLS_DESKTOP_LIFECYCLE_VERSION !== 1) throw new Error("Update @octane-xplat/devtools in the selected project to provide desktop lifecycle v1");
56
+ const data = {
57
+ version: 1,
58
+ project,
59
+ operation: "devtools-desktop",
60
+ target: "macos",
61
+ state: "accepted"
62
+ };
63
+ writeFileSync(resultFile, JSON.stringify({
64
+ protocol: request.protocol,
65
+ version: request.version,
66
+ id: request.id,
67
+ ok: true,
68
+ data,
69
+ warnings: []
70
+ }));
71
+ await api.devtoolsDesktop({
72
+ cwd: project,
73
+ resourceRoot: request.resourceRoot,
74
+ profileRoot: request.profileRoot || void 0,
75
+ onStarted: ({ kind, pid, url }) => {
76
+ const value = JSON.stringify({
77
+ protocol: "octane-project-service",
78
+ version: 1,
79
+ id: request.id,
80
+ project,
81
+ operation: "devtools-desktop",
82
+ target: "macos",
83
+ kind,
84
+ pid,
85
+ url
86
+ });
87
+ if (Buffer.byteLength(value) > 65536) throw new Error("Service startup evidence exceeds 64 KiB");
88
+ writeFileSync(request.serviceStateFile + ".next", value, { mode: 384 });
89
+ renameSync(request.serviceStateFile + ".next", request.serviceStateFile);
90
+ }
91
+ });
92
+ return data;
93
+ }
94
+ export { devtoolsDesktopService, devtoolsEntry, devtoolsWebOperation };