| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- /** Prepare the target Electron distribution and pinned pnpm CLI. */
- import { execFileSync } from 'node:child_process'
- import { chmodSync, cpSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
- import { createRequire } from 'node:module'
- import { dirname, join } from 'node:path'
- import { parseArgs } from 'node:util'
- import { downloadArtifact } from '@electron/get'
- import extractZip from 'extract-zip'
- import { resolveDesktopBuildTarget, resolveDesktopTargetBuildPaths } from './desktop-build-paths.mjs'
- import { preparePrimaryRuntime } from './prepare-primary-runtime.ts'
- const BUILD_PATHS = resolveDesktopTargetBuildPaths()
- const RUNTIME_ROOT = BUILD_PATHS.runtime
- function preparePnpm(): string {
- const require = createRequire(import.meta.url)
- const manifestPath = require.resolve('pnpm')
- const manifest = JSON.parse(readFileSync(manifestPath, 'utf8')) as { version?: unknown }
- if (typeof manifest.version !== 'string') throw new Error('desktop runtime: pnpm manifest has no version')
- const packageDir = dirname(manifestPath)
- const destination = join(RUNTIME_ROOT, 'pnpm')
- rmSync(destination, { recursive: true, force: true })
- cpSync(packageDir, destination, { recursive: true })
- return manifest.version
- }
- async function main(): Promise<void> {
- const { values } = parseArgs({ options: { 'defer-primary-runtime-smoke': { type: 'boolean', default: false } } })
- const target = resolveDesktopBuildTarget()
- const platform = target.startsWith('mac-') ? 'darwin' : 'win32'
- const arch = target.endsWith('arm64') ? 'arm64' : 'x64'
- const require = createRequire(import.meta.url)
- const { version } = require('electron/package.json') as { version: string }
- const archive = await downloadArtifact({ version, platform, arch, artifactName: 'electron', cacheRoot: BUILD_PATHS.downloads })
- rmSync(BUILD_PATHS.electron, { recursive: true, force: true })
- await extractZip(archive, { dir: BUILD_PATHS.electron })
- const executable = join(BUILD_PATHS.electron, platform === 'win32' ? 'electron.exe' : 'Electron.app/Contents/MacOS/Electron')
- const nodeVersion = execFileSync(executable, ['-p', 'process.versions.node'], {
- encoding: 'utf8', env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' },
- }).trim()
- rmSync(RUNTIME_ROOT, { recursive: true, force: true })
- mkdirSync(RUNTIME_ROOT, { recursive: true })
- const pnpmVersion = preparePnpm()
- cpSync(join(import.meta.dirname, 'node-bin'), join(RUNTIME_ROOT, 'bin'), { recursive: true })
- chmodSync(join(RUNTIME_ROOT, 'bin', 'node'), 0o755)
- writeFileSync(join(RUNTIME_ROOT, 'versions.json'), `${JSON.stringify({
- schemaVersion: 1,
- node: nodeVersion,
- pnpm: pnpmVersion,
- }, undefined, 2)}\n`)
- await preparePrimaryRuntime({ deferSmoke: values['defer-primary-runtime-smoke'] })
- }
- await main()
|