/
githubmirror
/
tldraw
Обзор
Документация
Войти
/
githubmirror
/
tldraw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
internal/scripts/process-compose-bin.cjs
97 строк
4 KB
Kevin Ingersoll
chore(dotcom): run dev with process-compose (#9301)
15 июл 2026, 19:03
Не верифицирован
15 июл 2026, 19:03
c26735e
Код
Авторство
О чём код?
#!/usr/bin/env node /* eslint-disable no-console */ // // The `process-compose` bin of @tldraw/scripts: self-provisioning process-compose. // // process-compose has no npm package, so installing it is normally a separate brew/curl step. Exposing // it as a workspace bin lets `yarn dev-app` (and anything else) call `process-compose` like any other // tool; on first use this downloads the pinned binary into node_modules/.cache, then execs it. Caching // it there (rather than a top-level dir) treats it like any bundled-binary dep: nuking node_modules // re-fetches it. Only people who actually run the dotcom stack pay the one-time download (Yarn doesn't // run a workspace's postinstall, so the fetch is lazy rather than eager). const { spawn, spawnSync } = require('node:child_process') const { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } = require('node:fs') const { arch: osArch, platform: osPlatform } = require('node:os') const { join } = require('node:path') // Bump this to upgrade process-compose for everyone; the next `yarn dev-app` re-downloads. const VERSION = 'v1.116.0' const repoRoot = join(__dirname, '..', '..') const binDir = join(repoRoot, 'node_modules', '.cache', 'process-compose') const binPath = join(binDir, 'process-compose') const stampPath = join(binDir, '.version') function releaseAsset() { const os = osPlatform() if (os !== 'darwin' && os !== 'linux') { throw new Error( `process-compose auto-install only supports macOS and Linux (got ${os}). ` + `Install it manually: https://f1bonacc1.github.io/process-compose/installation/` ) } // Map node's arch names to process-compose's release names; throw on anything else rather than // silently downloading a binary that won't run (e.g. 32-bit). const nodeArch = osArch() const arch = nodeArch === 'arm64' ? 'arm64' : nodeArch === 'x64' ? 'amd64' : null if (!arch) { throw new Error( `process-compose auto-install only supports arm64 and x64 (got ${nodeArch}). ` + `Install it manually: https://f1bonacc1.github.io/process-compose/installation/` ) } return `process-compose_${os}_${arch}.tar.gz` } async function ensureBinary() { const installed = existsSync(binPath) && existsSync(stampPath) && readFileSync(stampPath, 'utf8').trim() === VERSION if (installed) return const asset = releaseAsset() const url = `https://github.com/F1bonacc1/process-compose/releases/download/${VERSION}/${asset}` console.error(`Fetching process-compose ${VERSION} (${asset})…`) const res = await fetch(url, { redirect: 'follow' }) if (!res.ok) { throw new Error(`Failed to download process-compose: ${res.status} ${res.statusText} (${url})`) } mkdirSync(binDir, { recursive: true }) const tgz = join(binDir, asset) writeFileSync(tgz, Buffer.from(await res.arrayBuffer())) // The tarball contains the `process-compose` binary at its root. tar ships on macOS and Linux. const untar = spawnSync('tar', ['-xzf', tgz, '-C', binDir, 'process-compose'], { stdio: 'inherit', }) rmSync(tgz, { force: true }) if (untar.status !== 0) throw new Error('Failed to extract the process-compose archive') chmodSync(binPath, 0o755) writeFileSync(stampPath, VERSION) console.error(`process-compose ${VERSION} ready (${binPath})`) } async function main() { await ensureBinary() const child = spawn(binPath, process.argv.slice(2), { stdio: 'inherit' }) const forward = (signal) => { if (!child.killed) child.kill(signal) } process.on('SIGINT', () => forward('SIGINT')) process.on('SIGTERM', () => forward('SIGTERM')) process.on('SIGHUP', () => forward('SIGHUP')) child.on('error', (error) => { console.error(error) process.exit(1) }) child.on('exit', (code, signal) => process.exit(signal ? 1 : (code ?? 0))) } main().catch((error) => { console.error(error) process.exit(1) })