Files
hy 7b057c05f8 refactor: reorganize scripts and update paths for build and release processes
- Removed obsolete test script `test_crawl4ai_fit_markdown.py`.
- Deleted `verify-package-main-obfuscation.mjs` as it is no longer needed.
- Updated paths in `app-update-publish-config.test.ts` to reflect new script locations.
- Refactored `package-content-policy.test.ts` to use new paths for content policy scripts.
- Adjusted `package-main-obfuscation.test.ts` to point to the new obfuscation script locations.
- Modified `package-size-budget.test.ts` to use updated paths for size budget scripts.
- Changed `r2-update-metadata-contract.test.ts` to reference the new metadata script.
- Updated `release-fragment-contract.test.ts` to use the new fragment contract script.
- Refactored `release-storage-layout.test.ts` to point to the new storage layout script.
- Added `runtime-trace.test.ts` to test runtime tracing functionality.
- Updated `node-pty-native-release.test.ts` to reflect new paths for native release scripts.
2026-07-20 17:03:38 +08:00

51 lines
1.6 KiB
JavaScript

import fs from 'node:fs'
import path from 'node:path'
const isFile = (filePath) => {
try {
return fs.statSync(filePath).isFile()
} catch {
return false
}
}
export const getNodePtySpawnHelperPath = (directory) => path.join(directory, 'spawn-helper')
export const isNodePtyNativeReleaseReady = (directory, platform = process.platform) => {
if (platform === 'win32') {
return isFile(path.join(directory, 'conpty.node')) || isFile(path.join(directory, 'pty.node'))
}
const bindingPath = path.join(directory, 'pty.node')
const helperPath = getNodePtySpawnHelperPath(directory)
if (!isFile(bindingPath) || !isFile(helperPath)) return false
try {
fs.accessSync(helperPath, fs.constants.X_OK)
return true
} catch {
return false
}
}
export const prepareNodePtyNativeRelease = (directory, platform = process.platform) => {
if (platform === 'win32') return isNodePtyNativeReleaseReady(directory, platform)
const helperPath = getNodePtySpawnHelperPath(directory)
if (!isFile(path.join(directory, 'pty.node')) || !isFile(helperPath)) return false
try {
const currentMode = fs.statSync(helperPath).mode & 0o777
fs.chmodSync(helperPath, currentMode | 0o111)
} catch {
return false
}
return isNodePtyNativeReleaseReady(directory, platform)
}
export const assertNodePtyNativeReleaseReady = (directory, label, platform = process.platform) => {
if (prepareNodePtyNativeRelease(directory, platform)) return
const helperSuffix = platform === 'win32' ? '' : ' or spawn-helper is not executable'
throw new Error(`${label} is incomplete${helperSuffix}: ${directory}`)
}