@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,230 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
3
|
+
import postcss from "postcss";
|
|
4
|
+
import loadPostcssConfig from "postcss-load-config";
|
|
5
|
+
// ../cli/src/css-platform.ts
|
|
6
|
+
var buildTargets = /* @__PURE__ */ new Set([
|
|
7
|
+
"web",
|
|
8
|
+
"ios",
|
|
9
|
+
"android",
|
|
10
|
+
"visionos",
|
|
11
|
+
"macos",
|
|
12
|
+
"windows",
|
|
13
|
+
"linux",
|
|
14
|
+
"gtk",
|
|
15
|
+
"native"
|
|
16
|
+
]);
|
|
17
|
+
var targets = /* @__PURE__ */ new Set([...buildTargets, "mobile"]);
|
|
18
|
+
var qualified = /\.(web|ios|android|visionos|mobile|macos|windows|linux|gtk|native)\.css$/;
|
|
19
|
+
var cssId = /\.css(?:[?#].*)?$/;
|
|
20
|
+
var cleanId = (id) => id.split(/[?#]/, 1)[0];
|
|
21
|
+
function suffixes(platform) {
|
|
22
|
+
if (platform === "ios" || platform === "android") return [platform, "mobile"];
|
|
23
|
+
if (platform === "visionos") return ["ios", "mobile"];
|
|
24
|
+
return platform === "native" ? [] : [platform];
|
|
25
|
+
}
|
|
26
|
+
function matches(condition, platform) {
|
|
27
|
+
return condition === platform || condition === "mobile" && [
|
|
28
|
+
"ios",
|
|
29
|
+
"android",
|
|
30
|
+
"visionos"
|
|
31
|
+
].includes(platform) || condition === "native" && platform !== "web";
|
|
32
|
+
}
|
|
33
|
+
var deferredLayerPrefix = "xplat-platform-";
|
|
34
|
+
var deferredLayerName = /^xplat-platform-([a-z]+(?:_[a-z]+)*)$/;
|
|
35
|
+
function platformTargetNames(rule) {
|
|
36
|
+
const names = rule.params.replace(/\/\*[\s\S]*?\*\//g, " ").split(",").map((name) => name.trim());
|
|
37
|
+
if (!rule.nodes || names.some((name) => !targets.has(name))) throw rule.error(`Expected @platform <target>[, <target> ...] { ... }; targets: ${[...targets].join(", ")}`);
|
|
38
|
+
return names;
|
|
39
|
+
}
|
|
40
|
+
/** Targets carried by a deferred `@layer xplat-platform-*` block, if it is one. */
|
|
41
|
+
function deferredLayerNames(rule) {
|
|
42
|
+
if (rule.name !== "layer" || !rule.nodes) return;
|
|
43
|
+
const names = deferredLayerName.exec(rule.params.trim())?.[1].split("_");
|
|
44
|
+
return names?.every((name) => targets.has(name)) ? names : void 0;
|
|
45
|
+
}
|
|
46
|
+
function filterPlatforms(root, platform) {
|
|
47
|
+
const conditions = /* @__PURE__ */ new Map();
|
|
48
|
+
root.walkAtRules((rule) => {
|
|
49
|
+
const names = rule.name === "platform" ? platformTargetNames(rule) : deferredLayerNames(rule);
|
|
50
|
+
if (names) conditions.set(rule, names);
|
|
51
|
+
});
|
|
52
|
+
for (const [rule, names] of conditions) if (names.some((name) => matches(name, platform))) rule.replaceWith(...rule.nodes);
|
|
53
|
+
else rule.remove();
|
|
54
|
+
}
|
|
55
|
+
/** Compile platform blocks while retaining source positions for diagnostics. */
|
|
56
|
+
function platformCssPlugin(platform, deferred = /* @__PURE__ */ new Set()) {
|
|
57
|
+
return {
|
|
58
|
+
postcssPlugin: "xplat-platform",
|
|
59
|
+
Once(root) {
|
|
60
|
+
if (![...deferred].some((id) => root.source?.input.file?.endsWith(id))) filterPlatforms(root, platform);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Deferred sheets reach Vite's CSS minifier before the final projection, and
|
|
66
|
+
* minifiers warn on the unknown `@platform` at-rule. Rewriting the blocks as
|
|
67
|
+
* uniquely named `@layer` wrappers keeps every class reachable for validation
|
|
68
|
+
* and minifies silently; the projection decodes them. Layers are legal
|
|
69
|
+
* everywhere `@platform` is, including nested inside matching blocks.
|
|
70
|
+
*/
|
|
71
|
+
function platformDeferPlugin(deferred) {
|
|
72
|
+
return {
|
|
73
|
+
postcssPlugin: "xplat-platform-defer",
|
|
74
|
+
Once(root) {
|
|
75
|
+
const file = root.source?.input.file;
|
|
76
|
+
if (!file || ![...deferred].some((id) => file.endsWith(id))) return;
|
|
77
|
+
root.walkAtRules("platform", (rule) => {
|
|
78
|
+
const names = platformTargetNames(rule);
|
|
79
|
+
rule.name = "layer";
|
|
80
|
+
rule.params = `${deferredLayerPrefix}${names.join("_")}`;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Parse platform CSS without losing authored declaration positions for audits. */
|
|
86
|
+
function parsePlatformCss(css, platform, from) {
|
|
87
|
+
const root = postcss.parse(css, { from });
|
|
88
|
+
filterPlatforms(root, platform);
|
|
89
|
+
return root;
|
|
90
|
+
}
|
|
91
|
+
/** Whether emitted CSS still carries platform conditions awaiting projection. */
|
|
92
|
+
function hasPlatformConditions(css) {
|
|
93
|
+
return css.includes("@platform") || css.includes(deferredLayerPrefix);
|
|
94
|
+
}
|
|
95
|
+
/** Filter authored or generated CSS before a target-specific consumer parses it. */
|
|
96
|
+
function filterPlatformCss(css, platform, from) {
|
|
97
|
+
return hasPlatformConditions(css) ? parsePlatformCss(css, platform, from).toString() : css;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Select platform CSS siblings and compile build-time `@platform` blocks.
|
|
101
|
+
* CSS suffixes replace the unsuffixed file; they never append to it. Explicit
|
|
102
|
+
* platform filenames stay exact. Native presets include this automatically;
|
|
103
|
+
* web apps add `xplatCss('web')` to their Vite plugins.
|
|
104
|
+
*/
|
|
105
|
+
function xplatCss(platform = "web") {
|
|
106
|
+
if (!buildTargets.has(platform)) throw new Error(`Unknown CSS build target: ${platform}`);
|
|
107
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
108
|
+
const deferred = /* @__PURE__ */ new Set();
|
|
109
|
+
let aliases = [];
|
|
110
|
+
const select = (id) => {
|
|
111
|
+
const file = cleanId(id);
|
|
112
|
+
if (!file.endsWith(".css") || qualified.test(file)) return id;
|
|
113
|
+
const choices = [...suffixes(platform).map((suffix) => file.slice(0, -4) + `.${suffix}.css`), file];
|
|
114
|
+
for (const choice of choices) candidates.add(choice);
|
|
115
|
+
const selected = choices.find((choice) => existsSync(choice));
|
|
116
|
+
return selected ? selected + id.slice(file.length) : id;
|
|
117
|
+
};
|
|
118
|
+
return {
|
|
119
|
+
name: "xplat-platform-css",
|
|
120
|
+
api: {
|
|
121
|
+
platform,
|
|
122
|
+
defer: (id) => deferred.add(id),
|
|
123
|
+
filter: (css, from) => filterPlatformCss(css, platform, from),
|
|
124
|
+
hasPlatformConditions,
|
|
125
|
+
project(css, from, previousMap) {
|
|
126
|
+
const result = postcss([platformCssPlugin(platform)]).process(css, {
|
|
127
|
+
from,
|
|
128
|
+
to: from,
|
|
129
|
+
map: previousMap ? {
|
|
130
|
+
prev: previousMap,
|
|
131
|
+
inline: false,
|
|
132
|
+
annotation: false
|
|
133
|
+
} : false
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
css: result.css,
|
|
137
|
+
map: result.map?.toString()
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
enforce: "pre",
|
|
142
|
+
async config(userConfig) {
|
|
143
|
+
if (userConfig.css?.transformer === "lightningcss") throw new Error("xplatCss requires the PostCSS transformer; use Lightning CSS for minification instead");
|
|
144
|
+
const configuredAliases = userConfig.resolve?.alias ?? [];
|
|
145
|
+
aliases = Array.isArray(configuredAliases) ? [...configuredAliases] : Object.entries(configuredAliases).map(([find, replacement]) => ({
|
|
146
|
+
find,
|
|
147
|
+
replacement
|
|
148
|
+
}));
|
|
149
|
+
const configured = userConfig.css?.postcss;
|
|
150
|
+
let settings = {};
|
|
151
|
+
if (configured && typeof configured === "object") {
|
|
152
|
+
const { plugins, ...options } = configured;
|
|
153
|
+
settings = {
|
|
154
|
+
options,
|
|
155
|
+
plugins
|
|
156
|
+
};
|
|
157
|
+
} else try {
|
|
158
|
+
settings = await loadPostcssConfig({}, typeof configured === "string" ? configured : userConfig.root ?? process.cwd());
|
|
159
|
+
} catch (error) {
|
|
160
|
+
if (!(error instanceof Error) || !error.message.includes("No PostCSS Config found")) throw error;
|
|
161
|
+
}
|
|
162
|
+
userConfig.css ??= {};
|
|
163
|
+
userConfig.css.postcss = {
|
|
164
|
+
...settings.options,
|
|
165
|
+
plugins: [
|
|
166
|
+
platformCssPlugin(platform, deferred),
|
|
167
|
+
platformDeferPlugin(deferred),
|
|
168
|
+
...settings.plugins ?? []
|
|
169
|
+
]
|
|
170
|
+
};
|
|
171
|
+
return { resolve: { alias: [{
|
|
172
|
+
find: cssId,
|
|
173
|
+
replacement: "$&",
|
|
174
|
+
customResolver: async function(source, importer, options) {
|
|
175
|
+
for (const alias of aliases) {
|
|
176
|
+
if (typeof alias.find === "string" ? source !== alias.find && !source.startsWith(alias.find + "/") : !alias.find.test(source)) continue;
|
|
177
|
+
source = source.replace(alias.find, alias.replacement);
|
|
178
|
+
if (alias.customResolver) {
|
|
179
|
+
const result = await (typeof alias.customResolver === "function" ? alias.customResolver : alias.customResolver.resolveId).call(this, source, importer, options);
|
|
180
|
+
return typeof result === "string" ? select(result) : result && typeof result === "object" ? {
|
|
181
|
+
...result,
|
|
182
|
+
id: select(result.id)
|
|
183
|
+
} : result;
|
|
184
|
+
}
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
const file = cleanId(source);
|
|
188
|
+
const local = file.startsWith(".") && importer ? resolve(dirname(cleanId(importer)), file) : isAbsolute(file) && existsSync(file) ? file : void 0;
|
|
189
|
+
if (local) {
|
|
190
|
+
const selected = select(local + source.slice(file.length));
|
|
191
|
+
if (existsSync(cleanId(selected))) return selected;
|
|
192
|
+
}
|
|
193
|
+
const resolved = await this.resolve(source, importer, {
|
|
194
|
+
...options,
|
|
195
|
+
skipSelf: true
|
|
196
|
+
});
|
|
197
|
+
return resolved ? {
|
|
198
|
+
...resolved,
|
|
199
|
+
id: select(resolved.id)
|
|
200
|
+
} : null;
|
|
201
|
+
}
|
|
202
|
+
}] } };
|
|
203
|
+
},
|
|
204
|
+
transform(code, id) {
|
|
205
|
+
if (!cssId.test(id) || /(?:\?|&)(?:raw|url)(?:&|$)/.test(id) || !code.includes("@platform") || [...deferred].some((suffix) => cleanId(id).endsWith(suffix))) return;
|
|
206
|
+
const result = postcss([platformCssPlugin(platform)]).process(code, {
|
|
207
|
+
from: cleanId(id),
|
|
208
|
+
map: {
|
|
209
|
+
inline: false,
|
|
210
|
+
annotation: false
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
return {
|
|
214
|
+
code: result.css,
|
|
215
|
+
map: result.map?.toString() ?? null
|
|
216
|
+
};
|
|
217
|
+
},
|
|
218
|
+
configureServer(server) {
|
|
219
|
+
const changed = (file) => {
|
|
220
|
+
if (!candidates.has(file)) return;
|
|
221
|
+
server.restart().catch((error) => server.config.logger.error(String(error)));
|
|
222
|
+
};
|
|
223
|
+
server.watcher.on("add", changed).on("unlink", changed);
|
|
224
|
+
server.httpServer?.once("close", () => {
|
|
225
|
+
server.watcher.off("add", changed).off("unlink", changed);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
export { filterPlatformCss, hasPlatformConditions, parsePlatformCss, platformCssPlugin, xplatCss };
|
|
@@ -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 };
|