mirror of
https://github.com/Orkas-AI/Orkas.git
synced 2026-12-04 02:56:32 +08:00
Restore the pre-tsx install-root boundary so new transitive Main imports cannot read paths before ORKAS_WORKSPACE_ROOT exists. Cover cold source/package startup and explicit root overrides; include the initializer in isolated native-loader fixtures. Validation: 58 focused deterministic cases and macOS Electron startup/preload/send E2E passed. Cold-start cases failed before repair. Retained warnings: Electron ASAR DEP0180, local CLI registry warmup latency, and denied native notification permission. Windows/Linux startup covered by controlled contracts, not native GUI runs.
91 lines
3.7 KiB
JavaScript
91 lines
3.7 KiB
JavaScript
// Electron entry shim: register tsx so the main process can
|
|
// `require('./src/main')` and resolve to src/main/index.ts (Node folder →
|
|
// index.ts rule + tsx/cjs transpilation). Keeps __dirname semantics identical
|
|
// to running plain JS — no compile step in dev.
|
|
//
|
|
// TypeScript hooks:
|
|
// - `tsx/cjs` (sync require hook) handles src/main/**/*.ts on the require()
|
|
// code path.
|
|
// - `tsx/esm` (ESM loader, registered via node:module) handles dynamic
|
|
// `import()` specifiers that resolve to .ts files — notably the
|
|
// `import('#core-agent')` subpath import that targets core-agent source.
|
|
// Native .mjs dependencies stay on Main's native loader path so synchronous
|
|
// ESM linking does not wait on a transpilation worker for each JavaScript edge.
|
|
'use strict';
|
|
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
// Hidden source E2E runs must opt out of Dock activation before Main imports
|
|
// or Electron's ready event. Visible debugging keeps the normal app policy.
|
|
if (process.defaultApp === true && process.platform === 'darwin'
|
|
&& String(process.env.ORKAS_E2E_HIDE_WINDOW || '').trim() === '1') {
|
|
require('electron').app.setActivationPolicy('accessory');
|
|
}
|
|
|
|
for (const arg of process.argv.slice(1)) {
|
|
if (typeof arg !== 'string') continue;
|
|
if (arg.startsWith('--orkas-profile=')) {
|
|
process.env.ORKAS_PROFILE = arg.slice('--orkas-profile='.length);
|
|
} else if (arg.startsWith('--orkas-api-base-url=')) {
|
|
process.env.ORKAS_API_BASE_URL = arg.slice('--orkas-api-base-url='.length);
|
|
} else if (arg.startsWith('--orkas-voice-api-base=')) {
|
|
process.env.ORKAS_VOICE_API_BASE = arg.slice('--orkas-voice-api-base='.length);
|
|
}
|
|
}
|
|
|
|
function configurePackagedEsbuildBinary() {
|
|
if (!process.versions.electron || !process.resourcesPath || process.env.ESBUILD_BINARY_PATH) {
|
|
return;
|
|
}
|
|
|
|
const platformPackages = {
|
|
'darwin:arm64': ['@esbuild', 'darwin-arm64', 'bin', 'esbuild'],
|
|
'darwin:x64': ['@esbuild', 'darwin-x64', 'bin', 'esbuild'],
|
|
'linux:arm64': ['@esbuild', 'linux-arm64', 'bin', 'esbuild'],
|
|
'linux:x64': ['@esbuild', 'linux-x64', 'bin', 'esbuild'],
|
|
'win32:arm64': ['@esbuild', 'win32-arm64', 'esbuild.exe'],
|
|
'win32:ia32': ['@esbuild', 'win32-ia32', 'esbuild.exe'],
|
|
'win32:x64': ['@esbuild', 'win32-x64', 'esbuild.exe'],
|
|
};
|
|
const parts = platformPackages[`${process.platform}:${process.arch}`];
|
|
if (!parts) return;
|
|
|
|
const bin = path.join(
|
|
process.resourcesPath,
|
|
'app.asar.unpacked',
|
|
'node_modules',
|
|
...parts,
|
|
);
|
|
if (fs.existsSync(bin)) {
|
|
process.env.ESBUILD_BINARY_PATH = bin;
|
|
}
|
|
}
|
|
|
|
function configureWindowsVcRuntimePath() {
|
|
if (process.platform !== 'win32') return;
|
|
const platformKey = `${process.platform}-${process.arch}`;
|
|
const candidates = [
|
|
process.resourcesPath && path.join(process.resourcesPath, 'runtime', 'vc', platformKey),
|
|
path.join(__dirname, 'resources', 'runtime', 'vc', platformKey),
|
|
].filter(Boolean);
|
|
const runtimeDir = candidates.find((dir) => fs.existsSync(path.join(dir, 'vcruntime140.dll')));
|
|
if (!runtimeDir) return;
|
|
const entries = String(process.env.PATH || '').split(path.delimiter).filter(Boolean);
|
|
process.env.PATH = [runtimeDir, ...entries.filter((entry) => path.resolve(entry) !== path.resolve(runtimeDir))]
|
|
.join(path.delimiter);
|
|
}
|
|
|
|
configureWindowsVcRuntimePath();
|
|
configurePackagedEsbuildBinary();
|
|
|
|
// Establish storage before any TypeScript import can snapshot paths.ts.
|
|
// Main's transitive imports must not depend on their source order for this.
|
|
require('./src/main/install-data-root.cjs');
|
|
|
|
require('tsx/cjs');
|
|
require('./src/main/util/native-esm-loader.js').registerNativeEsmLoader();
|
|
require('tsx/esm/api').register();
|
|
|
|
require('./src/main');
|