@octane-xplat/build 0.0.1 → 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 +71 -9
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { SourceMap } from "node:module";
|
|
3
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
// ../cli/src/mcp/dev-stack.ts
|
|
5
|
+
function createDevStackResolver(getServer, options = {}) {
|
|
6
|
+
const HTTP_FRAME = /(https?:\/\/[^\s)"']+?):(\d+):(\d+)/g;
|
|
7
|
+
const FS_PREFIX = "/@fs";
|
|
8
|
+
const NS_MODULE_PREFIX = "/ns/m/";
|
|
9
|
+
const MAX_DEVICE_MODULE_BYTES = 5242880;
|
|
10
|
+
const transformFor = async (moduleUrl, cache) => {
|
|
11
|
+
const viteServer = getServer();
|
|
12
|
+
let entry = cache.get(moduleUrl);
|
|
13
|
+
if (entry === void 0) {
|
|
14
|
+
try {
|
|
15
|
+
entry = options.cachedOnly ? (await viteServer.moduleGraph.getModuleByUrl(moduleUrl))?.transformResult : await viteServer.transformRequest(moduleUrl);
|
|
16
|
+
} catch {
|
|
17
|
+
entry = null;
|
|
18
|
+
}
|
|
19
|
+
cache.set(moduleUrl, entry);
|
|
20
|
+
}
|
|
21
|
+
return entry;
|
|
22
|
+
};
|
|
23
|
+
const deviceCodeFor = async (pathname, search, origin, cache) => {
|
|
24
|
+
const viteServer = getServer();
|
|
25
|
+
const key = `device:${pathname}${search}`;
|
|
26
|
+
let code = cache.get(key);
|
|
27
|
+
if (code === void 0) {
|
|
28
|
+
code = null;
|
|
29
|
+
try {
|
|
30
|
+
const base = viteServer.resolvedUrls?.local?.[0] ?? origin;
|
|
31
|
+
const res = await fetch(new URL(pathname + search, base));
|
|
32
|
+
if (res.ok) {
|
|
33
|
+
const body = await res.text();
|
|
34
|
+
if (body.length <= MAX_DEVICE_MODULE_BYTES) code = body;
|
|
35
|
+
}
|
|
36
|
+
} catch {}
|
|
37
|
+
cache.set(key, code);
|
|
38
|
+
}
|
|
39
|
+
return code;
|
|
40
|
+
};
|
|
41
|
+
const deviceModuleUrl = (rel) => {
|
|
42
|
+
const viteServer = getServer();
|
|
43
|
+
if (rel.startsWith("@fs/") || existsSync(join(viteServer.config.root, rel))) return `/${rel}`;
|
|
44
|
+
for (let dir = dirname(viteServer.config.root);; dir = dirname(dir)) {
|
|
45
|
+
const abs = join(dir, rel);
|
|
46
|
+
if (existsSync(abs)) return `${FS_PREFIX}${abs.split(sep).join("/")}`;
|
|
47
|
+
if (dirname(dir) === dir) return `/${rel}`;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const indent = (text) => text.length - text.trimStart().length;
|
|
51
|
+
const mapDevicePosition = (deviceCode, transformedCode, line0, col0) => {
|
|
52
|
+
const deviceLines = deviceCode.split("\n");
|
|
53
|
+
const transformedLines = transformedCode.split("\n");
|
|
54
|
+
const text = deviceLines[line0]?.trim();
|
|
55
|
+
if (!text || text.length < 8) return;
|
|
56
|
+
let bestBefore = -1;
|
|
57
|
+
let nearest = -1;
|
|
58
|
+
let nearestDistance = Infinity;
|
|
59
|
+
for (let i = 0; i < transformedLines.length; i++) {
|
|
60
|
+
if (transformedLines[i].trim() !== text) continue;
|
|
61
|
+
const distance = Math.abs(i - line0);
|
|
62
|
+
if (distance < nearestDistance) {
|
|
63
|
+
nearestDistance = distance;
|
|
64
|
+
nearest = i;
|
|
65
|
+
}
|
|
66
|
+
if (i <= line0) bestBefore = i;
|
|
67
|
+
}
|
|
68
|
+
const index = bestBefore >= 0 ? bestBefore : nearest;
|
|
69
|
+
if (index < 0) return;
|
|
70
|
+
return {
|
|
71
|
+
line: index,
|
|
72
|
+
col: Math.max(0, indent(transformedLines[index]) + (col0 - indent(deviceLines[line0])))
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
const resolveFrame = async (url, line, col, cache) => {
|
|
76
|
+
const viteServer = getServer();
|
|
77
|
+
const { origin, pathname, search } = new URL(url);
|
|
78
|
+
if (options.origin && origin !== options.origin) return;
|
|
79
|
+
if (!Number.isSafeInteger(line) || !Number.isSafeInteger(col) || line < 1 || col < 1) return;
|
|
80
|
+
const isDeviceModule = pathname.startsWith(NS_MODULE_PREFIX);
|
|
81
|
+
if (options.cachedOnly && isDeviceModule) return;
|
|
82
|
+
const moduleUrl = isDeviceModule ? deviceModuleUrl(pathname.slice(6)) : pathname + search;
|
|
83
|
+
const transformed = await transformFor(moduleUrl, cache);
|
|
84
|
+
const map = transformed?.map;
|
|
85
|
+
if (!map || options.cachedOnly && JSON.stringify(map).length > MAX_DEVICE_MODULE_BYTES) return;
|
|
86
|
+
let generatedLine = line - 1;
|
|
87
|
+
let generatedColumn = col - 1;
|
|
88
|
+
if (isDeviceModule) {
|
|
89
|
+
const deviceCode = await deviceCodeFor(pathname, search, origin, cache);
|
|
90
|
+
if (!deviceCode || !transformed.code) return;
|
|
91
|
+
const mapped = mapDevicePosition(deviceCode, transformed.code, generatedLine, generatedColumn);
|
|
92
|
+
if (!mapped) return;
|
|
93
|
+
generatedLine = mapped.line;
|
|
94
|
+
generatedColumn = mapped.col;
|
|
95
|
+
}
|
|
96
|
+
let sourceMap = cache.get(`map:${moduleUrl}`);
|
|
97
|
+
if (!sourceMap) {
|
|
98
|
+
sourceMap = new SourceMap(map);
|
|
99
|
+
cache.set(`map:${moduleUrl}`, sourceMap);
|
|
100
|
+
}
|
|
101
|
+
const found = sourceMap.findEntry(generatedLine, generatedColumn);
|
|
102
|
+
if (!found?.originalSource) return;
|
|
103
|
+
const modulePath = isDeviceModule ? moduleUrl : pathname;
|
|
104
|
+
const moduleId = (await viteServer.moduleGraph.getModuleByUrl(moduleUrl))?.file ?? (modulePath.startsWith(FS_PREFIX) ? modulePath.slice(4) : join(viteServer.config.root, modulePath));
|
|
105
|
+
const original = found.originalSource;
|
|
106
|
+
const sourcePath = isAbsolute(original) ? original : resolve(dirname(moduleId), typeof map.sourceRoot === "string" ? map.sourceRoot : ".", original);
|
|
107
|
+
return `${relative(viteServer.config.root, sourcePath).split(sep).join("/")}:${found.originalLine + 1}:${found.originalColumn + 1}`;
|
|
108
|
+
};
|
|
109
|
+
const resolveStack = async (stack) => {
|
|
110
|
+
const cache = /* @__PURE__ */ new Map();
|
|
111
|
+
const parts = [];
|
|
112
|
+
let last = 0;
|
|
113
|
+
let changed = false;
|
|
114
|
+
let frames = 0;
|
|
115
|
+
for (const match of stack.matchAll(HTTP_FRAME)) {
|
|
116
|
+
if (++frames > 64) break;
|
|
117
|
+
let resolved;
|
|
118
|
+
try {
|
|
119
|
+
resolved = await resolveFrame(match[1], Number(match[2]), Number(match[3]), cache);
|
|
120
|
+
} catch {}
|
|
121
|
+
if (resolved && (!options.cachedOnly || resolved.length <= 8192)) {
|
|
122
|
+
parts.push(stack.slice(last, match.index), resolved);
|
|
123
|
+
last = match.index + match[0].length;
|
|
124
|
+
changed = true;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (!changed) return;
|
|
128
|
+
parts.push(stack.slice(last));
|
|
129
|
+
const result = parts.join("");
|
|
130
|
+
return options.cachedOnly && Buffer.byteLength(result) > 16384 ? void 0 : result;
|
|
131
|
+
};
|
|
132
|
+
return resolveStack;
|
|
133
|
+
}
|
|
134
|
+
export { createDevStackResolver };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// ../cli/src/mcp/inspection/dom.web.ts
|
|
2
|
+
function inspectDOM({ control, offset = 0, limit = 20, focus = false }) {
|
|
3
|
+
const selector = "[id],[data-testid]";
|
|
4
|
+
const matches = control ? [...document.querySelectorAll(selector)].filter((el) => (control.kind === "id" ? el.id : el.getAttribute("data-testid")) === control.name) : [...document.querySelectorAll(selector)];
|
|
5
|
+
if (control && matches.length !== 1) return { error: {
|
|
6
|
+
code: matches.length ? "ambiguous_selection" : "not_found",
|
|
7
|
+
message: `Stable control matched ${matches.length} hosts.`
|
|
8
|
+
} };
|
|
9
|
+
const controls = matches.slice(offset, offset + limit).map((el) => {
|
|
10
|
+
const frame = el.getBoundingClientRect();
|
|
11
|
+
const hidden = frame.width <= 0 || frame.height <= 0 || getComputedStyle(el).visibility !== "visible";
|
|
12
|
+
const privateSelector = "input[type=password],input[type=hidden],[data-xplat-private]";
|
|
13
|
+
const sensitive = el.matches(privateSelector) || !!el.closest("[data-xplat-private]") || !!el.querySelector(privateSelector);
|
|
14
|
+
const x = frame.x + frame.width / 2;
|
|
15
|
+
const y = frame.y + frame.height / 2;
|
|
16
|
+
const hit = document.elementFromPoint(x, y);
|
|
17
|
+
const disabled = el.matches(":disabled") || el.getAttribute("aria-disabled") === "true";
|
|
18
|
+
if (focus && !hidden && !disabled && !sensitive) el.focus();
|
|
19
|
+
return {
|
|
20
|
+
id: el.id || null,
|
|
21
|
+
testID: el.getAttribute("data-testid"),
|
|
22
|
+
tag: el.tagName.toLowerCase(),
|
|
23
|
+
role: el.getAttribute("role"),
|
|
24
|
+
text: sensitive ? "[redacted]" : (el.innerText ?? el.textContent ?? "").slice(0, 500),
|
|
25
|
+
value: sensitive ? "[redacted]" : typeof el.value === "string" ? el.value.slice(0, 500) : null,
|
|
26
|
+
checked: typeof el.checked === "boolean" ? el.checked : null,
|
|
27
|
+
disabled,
|
|
28
|
+
hidden,
|
|
29
|
+
sensitive,
|
|
30
|
+
focused: document.activeElement === el,
|
|
31
|
+
hitTarget: hit === el || el.contains(hit),
|
|
32
|
+
frame: {
|
|
33
|
+
x: frame.x,
|
|
34
|
+
y: frame.y,
|
|
35
|
+
width: frame.width,
|
|
36
|
+
height: frame.height
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
controls,
|
|
42
|
+
total: matches.length,
|
|
43
|
+
nextOffset: offset + controls.length < matches.length ? offset + controls.length : null
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export { inspectDOM };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { transformAsync, transformSync, types } from "@babel/core";
|
|
2
|
+
import unicodeSets from "@babel/plugin-transform-unicode-sets-regex";
|
|
3
|
+
import unicodeProperties from "@babel/plugin-transform-unicode-property-regex";
|
|
4
|
+
// ../cli/src/native-regex.ts
|
|
5
|
+
var HAS_PROPERTY_ESCAPE = /\\[pP]\{/;
|
|
6
|
+
var JS_MODULE_ID = /\.[cm]?[jt]sx?(?:[?#]|$)/;
|
|
7
|
+
var REGEX_ESCAPE_PLUGINS = () => [unicodeSets, unicodeProperties];
|
|
8
|
+
/** Compile `\p{NAME}` to its equivalent character-class ranges for splicing
|
|
9
|
+
* into template-literal RegExp patterns. Returns the class inner text and
|
|
10
|
+
* whether the property is negated. */
|
|
11
|
+
var expansionCache = /* @__PURE__ */ new Map();
|
|
12
|
+
function expandEscape(letter, body) {
|
|
13
|
+
const key = `${letter}{${body}}`;
|
|
14
|
+
let entry = expansionCache.get(key);
|
|
15
|
+
if (entry === void 0) {
|
|
16
|
+
const res = transformSync(`/${"\\" + key}/u`, {
|
|
17
|
+
filename: "xplat-escape.js",
|
|
18
|
+
configFile: false,
|
|
19
|
+
babelrc: false,
|
|
20
|
+
sourceMaps: false,
|
|
21
|
+
ast: false,
|
|
22
|
+
plugins: REGEX_ESCAPE_PLUGINS()
|
|
23
|
+
});
|
|
24
|
+
if (!res?.code) throw new Error(`Failed to expand Unicode property escape ${key}`);
|
|
25
|
+
const src = res.code.trim().replace(/;+$/, "");
|
|
26
|
+
const negated = src.startsWith("/[^");
|
|
27
|
+
entry = {
|
|
28
|
+
inner: src.slice(negated ? 3 : 2, src.lastIndexOf("]")),
|
|
29
|
+
negated
|
|
30
|
+
};
|
|
31
|
+
expansionCache.set(key, entry);
|
|
32
|
+
}
|
|
33
|
+
return entry;
|
|
34
|
+
}
|
|
35
|
+
var TEMPLATE_PROPERTY_ESCAPE = /\\([pP])\{([^}]+)\}/g;
|
|
36
|
+
/** True when `offset` in the regex source sits inside a `[…]` class
|
|
37
|
+
* (`u`-mode classes don't nest; `\` escapes the next character). */
|
|
38
|
+
function inClass(source, offset) {
|
|
39
|
+
let open = false;
|
|
40
|
+
for (let i = 0; i < offset; i++) {
|
|
41
|
+
const ch = source[i];
|
|
42
|
+
if (ch === "\\") i++;
|
|
43
|
+
else if (ch === "[") open = true;
|
|
44
|
+
else if (ch === "]") open = false;
|
|
45
|
+
}
|
|
46
|
+
return open;
|
|
47
|
+
}
|
|
48
|
+
/** Rewrite `\p{…}` escapes inside a template-literal `u`-flag pattern into
|
|
49
|
+
* explicit ranges so computed `new RegExp(\`…\`, 'u')` calls survive on
|
|
50
|
+
* ICU-less runtimes. Works on the cooked (regex-source) text and re-escapes
|
|
51
|
+
* it for the template. Leaves the pattern untouched when a `\P{…}` sits
|
|
52
|
+
* inside a class, which cannot be expressed without set operations. */
|
|
53
|
+
function expandTemplateEscapes(pattern) {
|
|
54
|
+
const next = pattern.quasis.map(({ value: { cooked } }) => {
|
|
55
|
+
if (cooked == null || !HAS_PROPERTY_ESCAPE.test(cooked)) return null;
|
|
56
|
+
for (const m of cooked.matchAll(TEMPLATE_PROPERTY_ESCAPE)) if (m[1] === "P" && inClass(cooked, m.index)) return;
|
|
57
|
+
return cooked.replace(TEMPLATE_PROPERTY_ESCAPE, (_m, letter, body, offset) => {
|
|
58
|
+
const exp = expandEscape(letter, body);
|
|
59
|
+
if (inClass(cooked, offset)) return exp.inner;
|
|
60
|
+
return exp.negated ? `[^${exp.inner}]` : `[${exp.inner}]`;
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
if (next.includes(void 0)) return;
|
|
64
|
+
next.forEach((cooked, i) => {
|
|
65
|
+
if (cooked == null) return;
|
|
66
|
+
const raw = cooked.replace(/[\\`]|\$(?=\{)/g, "\\$&");
|
|
67
|
+
pattern.quasis[i].value = {
|
|
68
|
+
raw,
|
|
69
|
+
cooked
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/** Compile Unicode properties for the pinned ICU-less runtimes without changing globals. */
|
|
74
|
+
function transformNativeRegex(code, filename = "xplat-native.ts") {
|
|
75
|
+
return transformAsync(code, {
|
|
76
|
+
filename,
|
|
77
|
+
configFile: false,
|
|
78
|
+
babelrc: false,
|
|
79
|
+
sourceMaps: true,
|
|
80
|
+
plugins: [() => ({ visitor: { "NewExpression|CallExpression"(path) {
|
|
81
|
+
const node = path.node;
|
|
82
|
+
if (!types.isNewExpression(node) && !types.isCallExpression(node)) return;
|
|
83
|
+
if (!types.isIdentifier(node.callee, { name: "RegExp" }) || path.scope.getBinding("RegExp") || node.arguments.length !== 2) return;
|
|
84
|
+
const [pattern, flags] = node.arguments;
|
|
85
|
+
if (!types.isStringLiteral(flags) || !/[uv]/.test(flags.value)) return;
|
|
86
|
+
if (types.isStringLiteral(pattern) && HAS_PROPERTY_ESCAPE.test(pattern.value)) {
|
|
87
|
+
path.replaceWith(types.regExpLiteral(pattern.value, flags.value));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (types.isTemplateLiteral(pattern) && !flags.value.includes("v")) expandTemplateEscapes(pattern);
|
|
91
|
+
} } }), ...REGEX_ESCAPE_PLUGINS()]
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function nativeUnicodeRegex() {
|
|
95
|
+
return {
|
|
96
|
+
name: "xplat-native-unicode-regex",
|
|
97
|
+
config() {
|
|
98
|
+
return { optimizeDeps: { rolldownOptions: { plugins: [nativeUnicodeRegexOptimizeDeps()] } } };
|
|
99
|
+
},
|
|
100
|
+
async transform(code, id) {
|
|
101
|
+
if (!HAS_PROPERTY_ESCAPE.test(code) || !JS_MODULE_ID.test(id)) return null;
|
|
102
|
+
const result = await transformNativeRegex(code, id.split("?")[0]);
|
|
103
|
+
return result ? {
|
|
104
|
+
code: result.code,
|
|
105
|
+
map: result.map
|
|
106
|
+
} : null;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function nativeUnicodeRegexOptimizeDeps() {
|
|
111
|
+
return {
|
|
112
|
+
name: "xplat-native-unicode-regex-optimize-deps",
|
|
113
|
+
async transform(code, id) {
|
|
114
|
+
if (!HAS_PROPERTY_ESCAPE.test(code) || !JS_MODULE_ID.test(id)) return null;
|
|
115
|
+
const result = await transformNativeRegex(code, id.split("?")[0]);
|
|
116
|
+
return result ? {
|
|
117
|
+
code: result.code,
|
|
118
|
+
map: result.map
|
|
119
|
+
} : null;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
export { nativeUnicodeRegex, transformNativeRegex };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { installedPackageRoot, installedToolPackageRoot } from "./package-root.js";
|
|
2
|
+
import { existsSync, globSync, readFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { parseDocument } from "yaml";
|
|
5
|
+
import { parse as parse$2 } from "jsonc-parser";
|
|
6
|
+
// ../cli/src/package-manager.ts
|
|
7
|
+
/** Read project metadata without treating malformed files as absent. */
|
|
8
|
+
function readProjectPackage(root) {
|
|
9
|
+
const file = join(root, "package.json");
|
|
10
|
+
return existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : {};
|
|
11
|
+
}
|
|
12
|
+
/** Workspace patterns shared by patch discovery and workspace-root selection. */
|
|
13
|
+
function readProjectWorkspace(root, selectedManager) {
|
|
14
|
+
const pkg = readProjectPackage(root);
|
|
15
|
+
const manager = selectedManager ?? pkg.packageManager?.split("@")[0];
|
|
16
|
+
const yaml = join(root, "pnpm-workspace.yaml");
|
|
17
|
+
if (manager !== "bun" && existsSync(yaml)) {
|
|
18
|
+
const doc = parseDocument(readFileSync(yaml, "utf8"));
|
|
19
|
+
if (doc.errors.length) throw new Error(`Cannot read ${yaml}: ${doc.errors[0].message}`);
|
|
20
|
+
return doc.toJS() ?? {};
|
|
21
|
+
}
|
|
22
|
+
const workspace = pkg.workspaces;
|
|
23
|
+
return {
|
|
24
|
+
packages: Array.isArray(workspace) ? workspace : workspace?.packages ?? [],
|
|
25
|
+
catalog: pkg.catalog ?? workspace?.catalog ?? {},
|
|
26
|
+
catalogs: pkg.catalogs ?? workspace?.catalogs ?? {},
|
|
27
|
+
overrides: pkg.overrides ?? {},
|
|
28
|
+
patchedDependencies: pkg.patchedDependencies ?? {}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Enumerate included workspace members, honoring exclusions and nested globs. */
|
|
32
|
+
function workspaceMembers(root, manager) {
|
|
33
|
+
const patterns = readProjectWorkspace(root, manager).packages ?? [];
|
|
34
|
+
const included = patterns.filter((pattern) => !pattern.startsWith("!"));
|
|
35
|
+
const excluded = patterns.filter((pattern) => pattern.startsWith("!")).map((pattern) => pattern.slice(1));
|
|
36
|
+
return included.length ? globSync(included, {
|
|
37
|
+
cwd: root,
|
|
38
|
+
exclude: [
|
|
39
|
+
...excluded,
|
|
40
|
+
"**/node_modules",
|
|
41
|
+
"**/node_modules/**",
|
|
42
|
+
"**/.git",
|
|
43
|
+
"**/.git/**"
|
|
44
|
+
]
|
|
45
|
+
}).map((path) => resolve(root, path)) : [];
|
|
46
|
+
}
|
|
47
|
+
/** Patches belong to the workspace root, including invocations from a member. */
|
|
48
|
+
function packageManagerRoot(dir) {
|
|
49
|
+
const start = resolve(dir);
|
|
50
|
+
for (let at = dirname(start); at !== dirname(at); at = dirname(at)) {
|
|
51
|
+
if (!existsSync(join(at, "package.json")) && !existsSync(join(at, "pnpm-workspace.yaml"))) continue;
|
|
52
|
+
if (workspaceMembers(at).includes(start)) return at;
|
|
53
|
+
}
|
|
54
|
+
return start;
|
|
55
|
+
}
|
|
56
|
+
/** Select the declared package manager before consulting potentially stale locks. */
|
|
57
|
+
function packageManagerFor(dir, explicit) {
|
|
58
|
+
const root = packageManagerRoot(dir);
|
|
59
|
+
const pkg = readProjectPackage(root);
|
|
60
|
+
const declared = explicit ?? pkg.packageManager?.split("@")[0];
|
|
61
|
+
if (declared) {
|
|
62
|
+
if (declared === "bun" || declared === "pnpm") return declared;
|
|
63
|
+
throw new Error(`Xplat supports Bun and pnpm projects; found packageManager ${declared}.`);
|
|
64
|
+
}
|
|
65
|
+
const bun = existsSync(join(root, "bun.lock")) || existsSync(join(root, "bun.lockb"));
|
|
66
|
+
const pnpm = existsSync(join(root, "pnpm-lock.yaml"));
|
|
67
|
+
if (bun && pnpm) throw new Error("Both Bun and pnpm lockfiles exist. Set packageManager in package.json or pass --package-manager.");
|
|
68
|
+
if (bun) return "bun";
|
|
69
|
+
if (pnpm) return "pnpm";
|
|
70
|
+
if (pkg.patchedDependencies) return "bun";
|
|
71
|
+
return existsSync(join(root, "pnpm-workspace.yaml")) ? "pnpm" : "bun";
|
|
72
|
+
}
|
|
73
|
+
/** Parse Bun's text lockfile (JSON with comments and trailing commas). */
|
|
74
|
+
function readBunLock(root) {
|
|
75
|
+
const file = join(root, "bun.lock");
|
|
76
|
+
if (!existsSync(file)) {
|
|
77
|
+
if (existsSync(join(root, "bun.lockb"))) throw new Error("xplat patches needs bun.lock. Run bun install --save-text-lockfile --lockfile-only to convert bun.lockb.");
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const errors = [];
|
|
81
|
+
const lock = parse$2(readFileSync(file, "utf8"), errors, { allowTrailingComma: true });
|
|
82
|
+
if (errors.length || !lock || typeof lock !== "object") throw new Error(`Cannot read ${file}: invalid Bun lockfile`);
|
|
83
|
+
return lock;
|
|
84
|
+
}
|
|
85
|
+
/** Resolve an installed tool through the selected project package manager. */
|
|
86
|
+
function packageManagerExec(dir, args) {
|
|
87
|
+
const cmd = packageManagerFor(dir);
|
|
88
|
+
const tool = {
|
|
89
|
+
vite: "vite",
|
|
90
|
+
tsc: "typescript"
|
|
91
|
+
}[args[0]];
|
|
92
|
+
const root = tool && !installedPackageRoot(dir, tool) && installedToolPackageRoot(dir, tool);
|
|
93
|
+
if (root) {
|
|
94
|
+
const manifest = readProjectPackage(root);
|
|
95
|
+
const bin = typeof manifest.bin === "string" ? manifest.bin : manifest.bin?.[args[0]];
|
|
96
|
+
if (bin) return {
|
|
97
|
+
cmd: "node",
|
|
98
|
+
args: [join(root, bin), ...args.slice(1)]
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
cmd,
|
|
103
|
+
args: [cmd === "bun" ? "run" : "exec", ...args]
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export { packageManagerExec, packageManagerFor, packageManagerRoot, readBunLock, readProjectPackage, readProjectWorkspace, workspaceMembers };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
// ../cli/src/package-root.ts
|
|
5
|
+
/** Directory of the installed package `name` as resolved from `fromDir`,
|
|
6
|
+
* walking Node's node_modules lookup chain (so pnpm workspaces with
|
|
7
|
+
* `nodeLinker: hoisted` resolve deps living only in the workspace root).
|
|
8
|
+
* Does not require `<name>/package.json` to be in the package's exports —
|
|
9
|
+
* only that the package directory exists on the chain. Returns the realpath
|
|
10
|
+
* (pnpm store/virtual-store links are followed) or null when absent. */
|
|
11
|
+
function installedPackageRoot(fromDir, name) {
|
|
12
|
+
for (const base of createRequire(join(fromDir, "package.json")).resolve.paths(`${name}/`) ?? []) {
|
|
13
|
+
const candidate = join(base, name, "package.json");
|
|
14
|
+
if (existsSync(candidate)) return realpathSync(dirname(candidate));
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
/** Like {@link installedPackageRoot} but only requires the package directory
|
|
19
|
+
* to exist on the node_modules chain — used where an installed (possibly
|
|
20
|
+
* symlinked) dep's location matters, not its manifest. */
|
|
21
|
+
function installedPackageDir(fromDir, name) {
|
|
22
|
+
for (const base of createRequire(join(fromDir, "package.json")).resolve.paths(`${name}/`) ?? []) {
|
|
23
|
+
const candidate = join(base, name);
|
|
24
|
+
if (existsSync(candidate)) return realpathSync(candidate);
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
/** Resolve an app's tool, falling back only to the installed umbrella's declared tools. */
|
|
29
|
+
function installedToolPackageRoot(fromDir, name) {
|
|
30
|
+
const direct = installedPackageRoot(fromDir, name);
|
|
31
|
+
const appManifest = join(fromDir, "package.json");
|
|
32
|
+
const app = existsSync(appManifest) ? JSON.parse(readFileSync(appManifest, "utf8")) : {};
|
|
33
|
+
if (direct && (app.dependencies?.[name] || app.devDependencies?.[name])) return direct;
|
|
34
|
+
const umbrella = installedPackageRoot(fromDir, "octane-xplat");
|
|
35
|
+
if (!umbrella) return direct;
|
|
36
|
+
return JSON.parse(readFileSync(join(umbrella, "package.json"), "utf8")).dependencies?.[name] ? installedPackageRoot(umbrella, name) : direct;
|
|
37
|
+
}
|
|
38
|
+
/** Resolve a tool's module entry from the app, falling back only to the
|
|
39
|
+
* installed umbrella's declared dependency. Returns null when neither has it. */
|
|
40
|
+
function resolveProjectTool(fromDir, name) {
|
|
41
|
+
const root = installedToolPackageRoot(fromDir, name);
|
|
42
|
+
if (!root) return null;
|
|
43
|
+
try {
|
|
44
|
+
return createRequire(join(root, "package.json")).resolve(name);
|
|
45
|
+
} catch {}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
export { installedPackageDir, installedPackageRoot, installedToolPackageRoot, resolveProjectTool };
|