mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-18 16:08:55 +00:00
When the system WebKit predates Safari 15.4 (macOS 11, and 12 before 12.3) and Safari's update has staged a newer WebKit, main re-execs once with DYLD_FRAMEWORK_PATH pointing at the staged frameworks and clears it again in the second process, so child processes keep the system frameworks. macOS 12.3+ and 13+ keep the system engine without a restart; an unreadable system version also keeps it. - Entitlements: allow-dyld-environment-variables only; library validation stays on (the staged framework is Apple-signed). - Bundle and link minimum back to 11.0 so Launch Services opens the app on Big Sur; .cargo/config.toml sets MACOSX_DEPLOYMENT_TARGET as a default a developer can override. - The staged copy is checked with a stat before the system version is read, so current macOS never spawns defaults at startup. - Debug builds skip the bindings export when the build checkout is absent. - Boot error page, install and contributor docs describe the Big Sur case. Tested by the contributor on macOS 11.7.11 (Safari 16.6.1 staged) and 26.5; by us on macOS 15.7.8 (no re-exec). Co-authored-by: qq471754603 <23146592+qq471754603@users.noreply.github.com>
99 lines
3.8 KiB
TypeScript
99 lines
3.8 KiB
TypeScript
import { readFileSync, readdirSync } from "node:fs";
|
|
import { dirname, resolve } from "node:path";
|
|
import { pathToFileURL } from "node:url";
|
|
import ts from "typescript";
|
|
|
|
// Safari 15.4 is the bundle's floor, macOS 12's engine (the app's minimum). On macOS 11 the app loads the newer WebKit staged by a Safari update (src-tauri/src/macos_webview.rs). Keep this floor in sync with vite.config.ts.
|
|
// Syntax lowering does not replace newer runtime APIs in dependencies.
|
|
const newerStatics = new Set([
|
|
"Promise.withResolvers",
|
|
"Object.groupBy",
|
|
"Map.groupBy",
|
|
"Array.fromAsync",
|
|
"Atomics.waitAsync",
|
|
"CSS.registerProperty",
|
|
"Uint8Array.fromBase64",
|
|
"Uint8Array.fromHex",
|
|
]);
|
|
const newerMethods = new Set([
|
|
"isWellFormed",
|
|
"toWellFormed",
|
|
// Safari 16 / 16.4 APIs above the floor.
|
|
"showPicker",
|
|
"supportedValuesOf",
|
|
"toSorted",
|
|
"toReversed",
|
|
"toSpliced",
|
|
]);
|
|
|
|
export function checkSource(source: string, startup: boolean): string[] {
|
|
const tree = ts.createSourceFile("bundle.js", source, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
const errors = new Set<string>();
|
|
const checkRegex = (pattern: string, flags: string) => {
|
|
if (flags.includes("v")) errors.add("RegExp v flag requires Safari 17");
|
|
if (/\(\?<([=!])/.test(pattern)) errors.add("RegExp lookbehind requires Safari 16.4");
|
|
};
|
|
const walk = (node: ts.Node) => {
|
|
if (ts.isRegularExpressionLiteral(node)) {
|
|
const end = node.text.lastIndexOf("/");
|
|
checkRegex(node.text.slice(1, end), node.text.slice(end + 1));
|
|
}
|
|
if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.attributes) {
|
|
errors.add("Import attributes require newer WebKit");
|
|
}
|
|
if (startup && ts.isPropertyAccessExpression(node)) {
|
|
const name = node.getText(tree);
|
|
if (newerStatics.has(name) || newerMethods.has(node.name.text)) errors.add(`${name} requires newer WebKit`);
|
|
}
|
|
if (
|
|
startup &&
|
|
(ts.isNewExpression(node) || ts.isCallExpression(node)) &&
|
|
node.expression.getText(tree) === "RegExp" &&
|
|
node.arguments?.[0] &&
|
|
ts.isStringLiteralLike(node.arguments[0])
|
|
) {
|
|
const flags = node.arguments[1];
|
|
checkRegex(node.arguments[0].text, flags && ts.isStringLiteralLike(flags) ? flags.text : "");
|
|
}
|
|
ts.forEachChild(node, walk);
|
|
};
|
|
walk(tree);
|
|
return [...errors];
|
|
}
|
|
|
|
export function checkBuild(dir: string): string[] {
|
|
const entry = readFileSync(resolve(dir, "index.html"), "utf8").match(/<script type="module"[^>]*src="([^"]+)"/);
|
|
if (!entry?.[1]) throw new Error("Production entry script was not found");
|
|
const startup = new Set<string>();
|
|
const visit = (file: string) => {
|
|
if (startup.has(file)) return;
|
|
startup.add(file);
|
|
const source = readFileSync(file, "utf8");
|
|
const tree = ts.createSourceFile(file, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
for (const node of tree.statements) {
|
|
if (
|
|
(ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) &&
|
|
node.moduleSpecifier &&
|
|
ts.isStringLiteral(node.moduleSpecifier)
|
|
) {
|
|
visit(resolve(dirname(file), node.moduleSpecifier.text));
|
|
}
|
|
}
|
|
};
|
|
visit(resolve(dir, entry[1].replace(/^\//, "")));
|
|
startup.add(resolve(dir, "boot.js"));
|
|
const errors: string[] = [];
|
|
for (const file of readdirSync(dir, { recursive: true, encoding: "utf8" })) {
|
|
if (!file.endsWith(".js")) continue;
|
|
const path = resolve(dir, file);
|
|
for (const error of checkSource(readFileSync(path, "utf8"), startup.has(path))) errors.push(`${file}: ${error}`);
|
|
}
|
|
return errors;
|
|
}
|
|
|
|
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
const errors = checkBuild(resolve("dist"));
|
|
if (errors.length) throw new Error(`Safari 15.4 compatibility check failed:\n${errors.join("\n")}`);
|
|
console.log("Safari 15.4 startup API and bundle syntax checks passed");
|
|
}
|