Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .claude/skills/bump-cli-tools/references/cli-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
| Coana CLI | `COANA_CLI_VERSION` in `src/constants.mts` | Downloaded from the Socket API on first use and cached by the CLI. | Not part of the native executable. | [bump-coana](../../bump-coana/SKILL.md) |
| Socket Patch executable | `dependencies.@socketsecurity/socket-patch` in `package.json` | `src/sea/build-sea.mts` → `resources/socket-patch` | Built for targets with a matching locked platform package; the manifest records its digest. | [bump-socket-patch](../../bump-socket-patch/SKILL.md) |
| `uv` executable | `src/sea/stage/uv-pins.json` | `src/sea/stage/uv.mts` → `tools/uv` | Target archives are checksum-verified; the manifest records each binary digest. | [bump-uv](../../bump-uv/SKILL.md) |
| `cdxgen` JavaScript API | `devDependencies.@cyclonedx/cdxgen` in `package.json` | `.config/rollup.cdxgen-sea.config.mjs` and `src/sea/build-sea.mts` → `tools/cdxgen` | `darwin-arm64` only; capability stays disabled until provenance and notices are resolved. | [bump-cdxgen](../../bump-cdxgen/SKILL.md) |
| `synp` JavaScript package | `devDependencies.synp` in `package.json` | `src/sea/stage/synp.mts` → `tools/synp` | `darwin-arm64` only; Yarn Classic stays disabled until provenance and notices are resolved. | [bump-synp](../../bump-synp/SKILL.md) |
| `cdxgen` JavaScript API | `devDependencies.@cyclonedx/cdxgen` in `package.json` | `.config/rollup.cdxgen-sea.config.mjs` and `src/sea/build-sea.mts` → `tools/cdxgen` | Generates SBOMs for npm and Yarn Classic. | [bump-cdxgen](../../bump-cdxgen/SKILL.md) |
| `synp` JavaScript package | `devDependencies.synp` in `package.json` | `src/sea/stage/synp.mts` → `tools/synp` | Converts Yarn Classic lockfiles for cdxgen. | [bump-synp](../../bump-synp/SKILL.md) |
13 changes: 9 additions & 4 deletions .config/rollup.cdxgen-sea.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import jsonPlugin from '@rollup/plugin-json'
import { nodeResolve } from '@rollup/plugin-node-resolve'

import { readPnpmLock } from '../src/sea/pnpm-lock.mts'
import { seaWorkerTypeScript } from '../src/sea/rollup-workers.mts'

const root = path.resolve(
path.dirname(url.fileURLToPath(import.meta.url)),
Expand Down Expand Up @@ -492,19 +493,23 @@ function thirdPartyNoticePlugin() {
}

export default {
input:
process.env.SEA_CDXGEN_INPUT ||
path.join(root, 'node_modules/@cyclonedx/cdxgen/lib/cli/index.js'),
input: {
'lib/cli/index':
process.env.SEA_CDXGEN_INPUT ||
path.join(root, 'node_modules/@cyclonedx/cdxgen/lib/cli/index.js'),
'sea-worker': path.join(root, 'src/sea/adapters/cdxgen-worker.mts'),
},
output: {
dir:
process.env.SEA_CDXGEN_OUTPUT || path.join(root, 'dist/sea-cdxgen-api'),
format: 'es',
entryFileNames: 'lib/cli/index.js',
entryFileNames: '[name].js',
chunkFileNames: 'lib/cli/chunks/[name]-[hash].js',
assetFileNames: 'lib/cli/assets/[name]-[hash][extname]',
},
external: id => id.startsWith('node:'),
plugins: [
seaWorkerTypeScript(),
nodeResolve({ preferBuiltins: true, exportConditions: ['node'] }),
jsonPlugin(),
commonjsPlugin(),
Expand Down
16 changes: 10 additions & 6 deletions .config/rollup.dist.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { nodeResolve } from '@rollup/plugin-node-resolve'
import fastGlob from 'fast-glob'
import trash from 'trash'

import baseConfig, {
EXTERNAL_PACKAGES,
getBuildPackageName,
} from './rollup.base.config.mjs'
import constants from '../scripts/constants.js'
import { isDirEmptySync } from '../scripts/lib/fs.js'
import { hasKeys } from '../scripts/lib/objects.js'
Expand All @@ -25,14 +29,14 @@ import {
isBuiltin,
normalizeId,
} from '../scripts/utils/packages.js'
import {
COANA_CACHE_SOURCE_PATH,
coanaCacheDistPath,
} from '../src/paths/coana.mts'
import {
includedModulesInventoryPlugin,
writeCopiedPackageInventory,
} from '../src/sea/rollup-provenance.mjs'
import baseConfig, {
EXTERNAL_PACKAGES,
getBuildPackageName,
} from './rollup.base.config.mjs'

const {
CONSTANTS,
Expand Down Expand Up @@ -93,8 +97,8 @@ function relativeBlessedPath(filepath) {
// The cache script vendored from coana-package-manager, which coana/release.mts
// runs with `node`.
async function copyCoanaCache() {
const filepath = path.join(constants.srcPath, 'vendor/coana-cache.mjs')
const destPath = path.join(constants.distPath, 'coana-cache.mjs')
const filepath = path.join(constants.srcPath, COANA_CACHE_SOURCE_PATH)
const destPath = coanaCacheDistPath(constants.distPath)
await fs.copyFile(filepath, destPath)
}

Expand Down
5 changes: 4 additions & 1 deletion .config/rollup.synp-sea.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import url from 'node:url'
import commonjsPlugin from '@rollup/plugin-commonjs'
import { nodeResolve } from '@rollup/plugin-node-resolve'

import { seaWorkerTypeScript } from '../src/sea/rollup-workers.mts'

const root = path.resolve(
path.dirname(url.fileURLToPath(import.meta.url)),
'..',
Expand Down Expand Up @@ -192,7 +194,7 @@ function noticesPlugin() {
export default {
input:
process.env.SEA_SYNP_INPUT ||
path.join(root, 'src/sea/adapters/synp-worker.mjs'),
path.join(root, 'src/sea/adapters/synp-worker.mts'),
output: {
dir: process.env.SEA_SYNP_OUTPUT || path.join(root, 'dist/sea-synp'),
format: 'cjs',
Expand All @@ -215,6 +217,7 @@ export default {
'worker_threads',
].includes(id),
plugins: [
seaWorkerTypeScript(),
nodeResolve({ preferBuiltins: true, exportConditions: ['node'] }),
commonjsPlugin(),
noticesPlugin(),
Expand Down
1 change: 1 addition & 0 deletions .config/tsconfig.scripts.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"../scripts/release/packages.mts",
"../scripts/refresh/**/*.mts",
"../scripts/test/**/*.mts",
"../src/paths/*.mts",
"../src/sea/version.mts"
],
"exclude": ["../node_modules/**"]
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,9 @@ jobs:
- name: Build and test the SEA
env:
NODE_OPTIONS: ${{ runner.os == 'macOS' && '--max-old-space-size=4096' || '' }}
SOCKET_CLI_API_TOKEN: ${{ startsWith(needs.verify.outputs.version, '2.') && !startsWith(matrix.target, 'win32-') && secrets.SOCKET_API_TOKEN_FOR_CLI_AND_SFW || '' }} # zizmor: ignore[secrets-outside-env]
SOCKET_CLI_COANA_REQUIRED: ${{ startsWith(needs.verify.outputs.version, '2.') && '1' || '0' }}
shell: bash
run: |
pnpm build:sea
unset SOCKET_CLI_API_TOKEN
pnpm test:sea

- name: Pack verified platform binary
Expand Down
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,12 @@
!/src/external/blessed-contrib/lib/layout/
!/src/external/blessed-contrib/lib/widget/
!/src/external/blessed-contrib/lib/widget/charts/
!/src/paths/
!/src/paths/*.mts
!/src/sea/
!/src/sea/archive-paths.mts
!/src/sea/adapters/
!/src/sea/build/
!/src/sea/build/cdxgen-fixture.mts
!/src/sea/stage/
!/src/sea/stage/**
!/src/sea/download-cache.mts
Expand Down Expand Up @@ -1062,9 +1064,9 @@
!/src/npx-cli.mts
!/src/pnpm-cli.mts
!/src/sea/README.md
!/src/sea/adapters/cdxgen-worker.mjs
!/src/sea/adapters/cdxgen-worker.mts
!/src/sea/adapters/cdxgen.mts
!/src/sea/adapters/synp-worker.mjs
!/src/sea/adapters/synp-worker.mts
!/src/sea/adapters/synp.mts
!/src/sea/bootstrap.mts
!/src/sea/build-sea.mts
Expand All @@ -1089,6 +1091,7 @@
!/src/sea/build/publish.mts
!/src/sea/build/smoke-test.mts
!/src/sea/rollup-provenance.mjs
!/src/sea/rollup-workers.mts
!/src/sea/pnpm-lock.mts
!/src/sea/runtime.mts
!/src/sea/download-bytes.mts
Expand Down Expand Up @@ -1181,8 +1184,6 @@
!/src/utils/npm-config.mts
!/src/utils/npm-spec.mts
!/src/utils/objects.mts
!/src/utils/is-record.mjs
!/src/utils/is-record.d.mts
!/src/utils/organization.mts
!/src/utils/output-formatting.mts
!/src/utils/package-environment.mts
Expand Down
32 changes: 12 additions & 20 deletions scripts/setup/uv.mts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,17 @@ import path from 'node:path'
import process from 'node:process'
import { promisify } from 'node:util'

import { uvReleaseUrl } from '../../src/paths/uv.mts'
import pins from '../../src/sea/stage/uv-pins.json' with { type: 'json' }
import { isMainModule } from '../lib/is-main-module.mts'
import { runMain } from '../lib/run-main.mts'

const execFile = promisify(execFileCallback)
const UV_VERSION = '0.12.15'
const UV_DIGESTS = {
arm64:
'wtjxaDy/A91/eSUbn927LdJEsQy9JRpFfmaXqOxiSafoi+wHEFaNWvjxOpqwoMAky7UrBd0icT6PCttBpagKvA==',
x64: 'HnyqtvfbH/vq3MTydIYAbCr6hS8kC8kuZpXxrGJ/Nr2dac/wJQA3Z6S9bx95TYCTBdOZ1kPbDjtrzfIgwi4xDw==',
}

export interface UvRelease {
archiveRoot: string
asset: string
digest: string
url: string
version: string
}

Expand Down Expand Up @@ -71,13 +67,13 @@ export function uvSetupRelease(platform: string, arch: string): UvRelease {
'a platform outside Linux x64 or arm64',
)
}
const target = arch === 'x64' ? 'x86_64' : 'aarch64'
const archiveRoot = 'uv-' + target + '-unknown-linux-gnu'
const pin = pins.targets[`linux-${arch}`]
return {
archiveRoot,
asset: archiveRoot + '.tar.gz',
digest: UV_DIGESTS[arch],
version: UV_VERSION,
archiveRoot: path.posix.dirname(pin.executable),
asset: pin.archive,
digest: pin.sha256,
url: uvReleaseUrl(pin.archive),
version: pins.version,
}
}

Expand Down Expand Up @@ -128,11 +124,7 @@ export async function installUvForCi(
const fetcher = dependencies.fetcher ?? fetch
const extract = dependencies.extract ?? extractUvArchive
const probe = dependencies.probe ?? probeUvVersion
const url =
'https://github.com/astral-sh/uv/releases/download/' +
release.version +
'/' +
release.asset
const { url } = release
let bytes: Buffer
try {
const response = await fetcher(url, {
Expand All @@ -149,11 +141,11 @@ export async function installUvForCi(
}
throw new UvSetupError('DOWNLOAD_FAILED', url, 'a failed download')
}
if (createHash('sha512').update(bytes).digest('base64') !== release.digest) {
if (createHash('sha256').update(bytes).digest('hex') !== release.digest) {
throw new UvSetupError(
'CHECKSUM_MISMATCH',
release.asset,
'a SHA-512 digest mismatch',
'a SHA-256 digest mismatch',
)
}
const directory = await mkdtemp(path.join(runnerTemp, 'socket-uv-'))
Expand Down
4 changes: 2 additions & 2 deletions src/commands/manifest/bazel/bin-detect.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
isNodeScript,
resolveBazelExecutable,
} from './process.mts'
import { isStandaloneSea } from '../../../sea/runtime.mts'
import { isSea } from '../../../sea/runtime.mts'
import { InputError } from '../../../utils/errors.mts'

/**
Expand All @@ -28,7 +28,7 @@ export async function resolveBazelBinary(
env: NodeJS.ProcessEnv,
cwd: string,
): Promise<string> {
if (isStandaloneSea()) {
if (isSea()) {
const override = explicit ?? env['SOCKET_CLI_BAZEL_PATH']
if (!override) {
throw new InputError(
Expand Down
54 changes: 37 additions & 17 deletions src/commands/manifest/bazel/process.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import path from 'node:path'
import { setTimeout as sleep } from 'node:timers/promises'

import cmdShim from 'cmd-shim'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'

import { resolveBazelBinary } from './bin-detect.mts'
import {
Expand Down Expand Up @@ -406,11 +406,9 @@ if (args.includes('info')) { process.stdout.write(${JSON.stringify(`install_base

it('stops what a launcher started when the timeout expires', async () => {
const record = writeParentLauncher({ detached: false })
await expect(
spawnBazel(launcher, [], { cwd, timeout: 500 }),
).rejects.toBeInstanceOf(BazelTimeoutError)
await expireLauncherTimeout(record)
expect(await waitForExit(readChildPid(record))).toBe(true)
})
}, 30_000)

it('stops what a launcher started when cancelled', async () => {
const record = writeParentLauncher({ detached: false })
Expand All @@ -424,30 +422,48 @@ if (args.includes('info')) { process.stdout.write(${JSON.stringify(`install_base

it('settles a timeout when an escaped process keeps the output open', async () => {
const record = writeParentLauncher({ detached: true })
const startedAt = Date.now()
try {
await expect(
spawnBazel(launcher, [], { cwd, timeout: 500 }),
).rejects.toBeInstanceOf(BazelTimeoutError)
expect(Date.now() - startedAt).toBeLessThan(15_000)
await expireLauncherTimeout(record)
} finally {
const pid = readChildPid(record)
if (isAlive(pid)) {
process.kill(pid, 'SIGKILL')
if (existsSync(record)) {
const pid = readChildPid(record)
if (isAlive(pid)) {
process.kill(pid, 'SIGKILL')
}
// Windows can report process exit before inherited handles release the cwd.
expect(await waitForExit(pid)).toBe(true)
}
// Windows can report process exit before inherited handles release the cwd.
expect(await waitForExit(pid)).toBe(true)
}
}, 30_000)

async function expireLauncherTimeout(record: string): Promise<void> {
// Give the real launcher time to report its child before firing the timeout.
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
const result = spawnBazel(launcher, [], { cwd, timeout: 500 }).catch(
(e: unknown) => e,
)
try {
await waitForFile(record)
} finally {
try {
await vi.runAllTimersAsync()
} finally {
vi.useRealTimers()
}
}
expect(await result).toBeInstanceOf(BazelTimeoutError)
}

function writeParentLauncher(options: { detached: boolean }): string {
const record = path.join(cwd, 'child.pid')
writeFileSync(
launcher,
`const { spawn } = require('node:child_process')
const fs = require('node:fs')
const child = spawn(process.execPath, ['-e', 'setInterval(() => {}, 1000)'], { detached: ${options.detached}, stdio: 'inherit' })
fs.writeFileSync(${JSON.stringify(record)}, String(child.pid))
const record = ${JSON.stringify(record)}
fs.writeFileSync(record + '.tmp', String(child.pid))
fs.renameSync(record + '.tmp', record)
${options.detached ? 'child.unref()' : ''}
`,
)
Expand Down Expand Up @@ -498,10 +514,14 @@ async function waitForExit(pid: number): Promise<boolean> {
}

async function waitForFile(file: string): Promise<void> {
while (!existsSync(file)) {
const deadline = Date.now() + 10_000
while (!existsSync(file) && Date.now() < deadline) {
// eslint-disable-next-line no-await-in-loop
await sleep(50)
}
if (!existsSync(file)) {
throw new Error('Bazel test launcher did not report its child PID')
}
}

describe('splitBazelFlags', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/manifest/bazel/python-shim.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import os from 'node:os'
import path from 'node:path'

import { findBazelExecutable, prependBazelPath } from './process.mts'
import { isStandaloneSea } from '../../../sea/runtime.mts'
import { isSea } from '../../../sea/runtime.mts'
import { InputError } from '../../../utils/errors.mts'

export type PythonShimResult = {
Expand Down Expand Up @@ -53,7 +53,7 @@ export async function provisionPythonShim(
env: NodeJS.ProcessEnv,
cwd: string,
): Promise<PythonShimResult> {
if (isStandaloneSea()) {
if (isSea()) {
const override = env['SOCKET_CLI_PYTHON_PATH']
if (!override) {
throw new InputError(
Expand Down
Loading
Loading