mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 16:02:32 +00:00
Migrate fileURLToPath(import.meta.url) / dirname(...) boilerplate to the
native import.meta.dirname / import.meta.filename, then enable the rule
at error so new code stays on the native form.
The oxlint autofix rewrites the expression but leaves the now-unused
node:url / node:path imports behind (which the already-enabled
no-unused-vars=error would then flag), so this commit also removes those
34 orphaned imports — trimming the named import where other names are
still used, deleting the line where it was the sole import.
Scope is build scripts + Node-env tests only (config/scripts, tools/
benchmarks, *.test.{ts,mjs}, vitest configs); zero shipped runtime code.
The native properties are exact equivalents (Node >= 20.11; repo is on
24), so behavior is unchanged.
Verified: oxlint 0 errors tree-wide (root + mobile), oxfmt clean,
typecheck (node+cli+web) + mobile tsc pass, root vitest 22825 passed /
0 failed, mobile vitest 1018 passed. Exercised the rewritten scripts
directly: build:relay (6 targets), ensure-native-runtime,
verify-macos-entitlements all run correctly with import.meta.dirname.
64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
#!/usr/bin/env node
|
|
import { accessSync, constants, existsSync } from 'node:fs'
|
|
import { spawnSync } from 'node:child_process'
|
|
import { resolve } from 'node:path'
|
|
|
|
function isExecutable(filePath, platform, access = accessSync) {
|
|
if (platform === 'win32') {
|
|
return true
|
|
}
|
|
|
|
try {
|
|
access(filePath, constants.X_OK)
|
|
return true
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|
|
|
|
function quoteWindowsArg(value) {
|
|
return `"${value.replace(/"/g, '""')}"`
|
|
}
|
|
|
|
function spawnOptionalSetup(spawn, setupPath, worktreePath, platform, env) {
|
|
if (platform === 'win32') {
|
|
spawn(
|
|
env.ComSpec || 'cmd.exe',
|
|
['/d', '/s', '/c', `call ${quoteWindowsArg(setupPath)} ${quoteWindowsArg(worktreePath)}`],
|
|
{
|
|
stdio: 'inherit',
|
|
windowsVerbatimArguments: true
|
|
}
|
|
)
|
|
return
|
|
}
|
|
|
|
spawn(setupPath, [worktreePath], {
|
|
stdio: 'inherit'
|
|
})
|
|
}
|
|
|
|
export function runInternalDevSetup({
|
|
env = process.env,
|
|
cwd = process.cwd(),
|
|
platform = process.platform,
|
|
exists = existsSync,
|
|
access = accessSync,
|
|
spawn = spawnSync
|
|
} = {}) {
|
|
const setupPath = env.ORCA_INTERNAL_DEV_SETUP?.trim()
|
|
if (!setupPath || !exists(setupPath) || !isExecutable(setupPath, platform, access)) {
|
|
return 0
|
|
}
|
|
|
|
// Why: this hook is an optional local accelerator; failures should not block
|
|
// creating a worktree or running the normal dependency install.
|
|
spawnOptionalSetup(spawn, setupPath, env.ORCA_WORKTREE_PATH || cwd, platform, env)
|
|
|
|
return 0
|
|
}
|
|
|
|
if (process.argv[1] && resolve(import.meta.filename) === resolve(process.argv[1])) {
|
|
process.exit(runInternalDevSetup())
|
|
}
|