Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ concurrency:
jobs:
ci:
name: Run CI Pipeline
uses: SocketDev/socket-registry/.github/workflows/ci.yml@85a2fc0d33af6304246620365de3e7f053035a8d # main
uses: SocketDev/socket-registry/.github/workflows/ci.yml@51f34ffb69c5d38614a16078793af662b0cea38d # main
with:
test-script: 'pnpm run test --all --skip-build'
6 changes: 3 additions & 3 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ jobs:
echo "Sleeping for $delay seconds..."
sleep $delay

- uses: SocketDev/socket-registry/.github/actions/setup-and-install@85a2fc0d33af6304246620365de3e7f053035a8d # main
- uses: SocketDev/socket-registry/.github/actions/setup-and-install@51f34ffb69c5d38614a16078793af662b0cea38d # main

- name: Configure push credentials
env:
GH_TOKEN: ${{ github.token }}
run: git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git"

- uses: SocketDev/socket-registry/.github/actions/setup-git-signing@85a2fc0d33af6304246620365de3e7f053035a8d # main
- uses: SocketDev/socket-registry/.github/actions/setup-git-signing@51f34ffb69c5d38614a16078793af662b0cea38d # main
with:
gpg-private-key: ${{ secrets.BOT_GPG_PRIVATE_KEY }}

Expand Down Expand Up @@ -145,5 +145,5 @@ jobs:
> \`\`\`
EOF

- uses: SocketDev/socket-registry/.github/actions/cleanup-git-signing@85a2fc0d33af6304246620365de3e7f053035a8d # main
- uses: SocketDev/socket-registry/.github/actions/cleanup-git-signing@51f34ffb69c5d38614a16078793af662b0cea38d # main
if: always()
2 changes: 1 addition & 1 deletion .github/workflows/provenance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
permissions:
contents: write # To create GitHub releases
id-token: write # For npm trusted publishing via OIDC
uses: SocketDev/socket-registry/.github/workflows/provenance.yml@85a2fc0d33af6304246620365de3e7f053035a8d # main
uses: SocketDev/socket-registry/.github/workflows/provenance.yml@51f34ffb69c5d38614a16078793af662b0cea38d # main
with:
debug: ${{ inputs.debug }}
dist-tag: ${{ inputs.dist-tag }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/weekly-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ permissions:

jobs:
weekly-update:
uses: SocketDev/socket-registry/.github/workflows/weekly-update.yml@85a2fc0d33af6304246620365de3e7f053035a8d # main
uses: SocketDev/socket-registry/.github/workflows/weekly-update.yml@51f34ffb69c5d38614a16078793af662b0cea38d # main
with:
test-setup-script: 'pnpm run build'
test-script: 'pnpm test'
Expand Down
14 changes: 7 additions & 7 deletions external-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"pnpm": {
"description": "pnpm — the fleet's package manager.",
"version": "11.0.0-rc.5",
"version": "11.0.0",
"packageManager": "pnpm",
"repository": "github:pnpm/pnpm",
"release": "asset",
Expand All @@ -34,27 +34,27 @@
"checksums": {
"darwin-arm64": {
"asset": "pnpm-darwin-arm64.tar.gz",
"sha256": "32a50710ccacfdcf14e6d5995d5368298eec913b0ce3903b9e09b6555f06f4e5"
"sha256": "3620a0fcaf81ecd3aaeccd5965919d90dbc913f4d07a96e11e7cafc2c785054b"
},
"darwin-x64": {
"asset": "pnpm-darwin-x64.tar.gz",
"sha256": "71dca33f4275da6b43bf1eb40bdc4d876f59a116716eacbf01079c3d985ff85d"
"sha256": "1701748b75187f1333a9c616827943ff84ff46cc42becc156ff6864b9bd0f948"
},
"linux-arm64": {
"asset": "pnpm-linux-arm64.tar.gz",
"sha256": "2dd04127ff10b1f9dd20bae248b779c77a8ec67e3afa35e7256e5f94abddd493"
"sha256": "1e6d87ebfd7ff169966ff5b3ad71b780b883c68d3e59987df1096dfd8853df75"
},
"linux-x64": {
"asset": "pnpm-linux-x64.tar.gz",
"sha256": "7ebef4b616ba41fb0d54a207b36508fae3346723283a088b43fc1e038ee6fed0"
"sha256": "9b44acc77ada40fc41b665fde1d57367a5ebec31bd4b1b00598daed195da3e17"
},
"win-arm64": {
"asset": "pnpm-win32-arm64.zip",
"sha256": "e4a39ad4c251db5e34b18b98561ef25bab5506ad65cad2fa3602af58d1972667"
"sha256": "0746be8e98ca183078d0747559f0cbbd30a13a53eb177f67474eb3c52dc21bc8"
},
"win-x64": {
"asset": "pnpm-win32-x64.zip",
"sha256": "147485ae2f38c3d1ccf2f5db00d0244416bcd22b9114c02388e6a78f41538fc4"
"sha256": "581e222e622cd0cc4f0ac5f85dd0db76b65117e3b17507979d89e63fdc68edca"
}
}
},
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"description": "SDK for the Socket API client",
"homepage": "https://github.com/SocketDev/socket-sdk-js",
"license": "MIT",
"publishConfig": {
"access": "public",
"provenance": true
},
"author": {
"name": "Socket Inc",
"email": "eng@socket.dev",
Expand Down Expand Up @@ -73,7 +77,7 @@
"@babel/traverse": "7.26.4",
"@babel/types": "7.26.3",
"@oxlint/migrate": "1.52.0",
"@socketsecurity/lib": "5.25.1",
"@socketsecurity/lib": "5.26.1",
"@sveltejs/acorn-typescript": "1.0.8",
"@types/babel__traverse": "7.28.0",
"@types/node": "24.9.2",
Expand Down Expand Up @@ -111,7 +115,7 @@
},
"engines": {
"node": ">=18.20.8",
"pnpm": ">=11.0.0-rc.0"
"pnpm": ">=11.0.6"
},
"packageManager": "pnpm@11.0.0-rc.5"
"packageManager": "pnpm@11.0.6+sha512.97f906e1da2bedac3df83cadae04b4753a130092dd49d55cd36825ad3e623e9df3f97754f8f259e699172a360fac569acf2f908e7732bdae3eddb2dcf7e121fd"
}
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
loglevel: error
trustPolicy: no-downgrade

# Catalog: shared dependency versions referenced as "catalog:" in
# package.json. Hooks under .claude/hooks/* declare their deps via
# `catalog:` so they stay in lockstep with the root workspace.
catalog:
'@socketsecurity/lib': 5.25.1
'@types/node': 24.9.2

# Register .claude/hooks/* as workspace packages so taze (run via
# `pnpm run update`) sees and bumps their package.json manifests
# alongside the root. Keeps hook deps in lockstep with the main tree.
Expand Down Expand Up @@ -38,6 +45,15 @@ minimumReleaseAgeExclude:
- '@socketregistry/*'
- '@socketsecurity/*'

# Refuse transitive dependencies declared via git/tarball/local-tarball
# specs — an npm package shouldn't be allowed to drag in a git URL we
# don't control (bypasses npm registry validation, no provenance, no
# soak window). Direct git deps are still allowed (the test suite at
# pnpm/pkg-manager/core/test/install/blockExoticSubdeps.ts confirms
# this). pnpm's current default is `false`; declared explicitly so a
# future flip can't silently change install behavior.
blockExoticSubdeps: true

# Pin exact versions on `pnpm add`. Catalog and overrides should
# also be exact pins (5.24.0, not ^5.24.0).
saveExact: true
165 changes: 165 additions & 0 deletions scripts/power-state.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/**
* @fileoverview Detect whether the host is currently on AC power
* (vs battery). Used by long-running build/test scripts to size
* timeouts adaptively — laptops on battery throttle CPU hard
* (especially macOS), and a static timeout that fits AC will kill
* an otherwise-healthy run on battery.
*
* Two paths, in priority order:
*
* 1. `node:smol-power` — when running inside a node-smol binary
* that ships the smol_power native binding (socket-btm's custom
* Node distribution). Pure C++ syscalls, sub-millisecond.
*
* 2. Shellout fallback — system Node doesn't have node:smol-power.
* Each platform has a different mechanism:
* * macOS: `pmset -g batt` parses "AC Power" / "Battery Power"
* * Linux: reads /sys/class/power_supply/<entry>/online
* (no shellout, just open/read syscalls)
* * Windows: PowerShell `Get-CimInstance Win32_Battery`
*
* On detection failure we conservatively assume AC — the downstream
* timeout becomes the shorter / more aggressive value, which is
* appropriate for build servers and headless CI (those environments
* are expected to run at full speed).
*
* Returns a Promise so callers don't block the event loop on shellout
* paths.
*
* Byte-identical across the fleet via socket-repo-template's
* sync-scaffolding (IDENTICAL_FILES).
*/

import { existsSync, promises as fs } from 'node:fs'
import path from 'node:path'
import process from 'node:process'

import { spawn } from '@socketsecurity/lib/spawn'

// Probe for node:smol-power. Lives in socket-btm's node-smol binary.
// Wrapped in try/catch so this file is safe to import on system Node
// where the module doesn't exist.
let _smolPower: { isOnAcPower: () => boolean } | undefined
async function getSmolPower(): Promise<typeof _smolPower> {
if (_smolPower !== undefined) {
return _smolPower
}
try {
const mod = await import('node:smol-power')

Check failure on line 48 in scripts/power-state.mts

View workflow job for this annotation

GitHub Actions / Run CI Pipeline / 🧪 Test Matrix (25.9.0, macos-latest)

Cannot find module 'node:smol-power' or its corresponding type declarations.

Check failure on line 48 in scripts/power-state.mts

View workflow job for this annotation

GitHub Actions / Run CI Pipeline / 🧪 Test Matrix (25.9.0, ubuntu-latest)

Cannot find module 'node:smol-power' or its corresponding type declarations.
_smolPower = mod
return _smolPower
} catch {
_smolPower = undefined
return undefined
}
}

async function detectMacOs(): Promise<boolean> {
try {
// `pmset -g batt` on macOS prints lines like
// Now drawing from 'AC Power'
// Now drawing from 'Battery Power'
// Match the AC variant; everything else (battery, unknown) is
// treated as not-AC.
const result = await spawn('pmset', ['-g', 'batt'], {
stdio: ['ignore', 'pipe', 'ignore'],
})
return /AC Power/.test(result.stdout || '')

Check failure on line 67 in scripts/power-state.mts

View workflow job for this annotation

GitHub Actions / Run CI Pipeline / 🔎 Check

Argument of type 'string | Buffer<ArrayBufferLike>' is not assignable to parameter of type 'string'.

Check failure on line 67 in scripts/power-state.mts

View workflow job for this annotation

GitHub Actions / Run CI Pipeline / 🧪 Test Matrix (25.9.0, macos-latest)

Argument of type 'string | Buffer<ArrayBufferLike>' is not assignable to parameter of type 'string'.

Check failure on line 67 in scripts/power-state.mts

View workflow job for this annotation

GitHub Actions / Run CI Pipeline / 🧪 Test Matrix (25.9.0, ubuntu-latest)

Argument of type 'string | Buffer<ArrayBufferLike>' is not assignable to parameter of type 'string'.
} catch {
return true
}
}

async function detectLinux(): Promise<boolean> {
// Linux exposes power state under /sys/class/power_supply. Each
// AC adapter is its own dir (`AC`, `ADP1`, `AC0`, `ACAD`, …)
// with an `online` file holding "1" when power is connected.
// Containers and headless servers often have no power_supply
// tree at all — treat that as AC since those environments are
// expected to run at full speed.
const psDir = '/sys/class/power_supply'
if (!existsSync(psDir)) {
return true
}
try {
const entries = await fs.readdir(psDir)
for (const entry of entries) {
const onlineFile = path.join(psDir, entry, 'online')
if (!existsSync(onlineFile)) {
continue
}
try {
const value = await fs.readFile(onlineFile, 'utf8')
if (value.trim() === '1') {
return true
}
} catch {
// Unreadable entry — skip; another entry may report.
}
}
} catch {
// Directory enumeration failed — fall through to AC.
return true
}
return false
}

async function detectWindows(): Promise<boolean> {
try {
// Windows: query the battery status via PowerShell + CIM.
// `Win32_Battery.BatteryStatus`:
// 1 = Discharging (battery)
// 2 = On AC, not charging or fully charged
// 3..5 = Various battery states
// 6 = AC + charging
// Desktops with no battery return an empty result; treat as AC.
const result = await spawn(
'powershell.exe',
[
'-NoProfile',
'-Command',
'(Get-CimInstance -ClassName Win32_Battery).BatteryStatus',
],
{ stdio: ['ignore', 'pipe', 'ignore'] },
)
const trimmed = (result.stdout || '').trim()

Check failure on line 125 in scripts/power-state.mts

View workflow job for this annotation

GitHub Actions / Run CI Pipeline / 🔎 Check

Property 'trim' does not exist on type 'string | Buffer<ArrayBufferLike>'.

Check failure on line 125 in scripts/power-state.mts

View workflow job for this annotation

GitHub Actions / Run CI Pipeline / 🧪 Test Matrix (25.9.0, macos-latest)

Property 'trim' does not exist on type 'string | Buffer<ArrayBufferLike>'.

Check failure on line 125 in scripts/power-state.mts

View workflow job for this annotation

GitHub Actions / Run CI Pipeline / 🧪 Test Matrix (25.9.0, ubuntu-latest)

Property 'trim' does not exist on type 'string | Buffer<ArrayBufferLike>'.
if (trimmed === '') {
return true
}
const status = Number.parseInt(trimmed, 10)
if (Number.isNaN(status)) {
return true
}
return status === 2 || status === 6
} catch {
return true
}
}

/**
* Returns `true` if the host is on AC power. Conservative on
* detection failure (returns `true`) — callers using this for
* timeout sizing prefer a longer timeout to a too-short one.
*
* Prefers the native binding (`node:smol-power`) when running
* inside a node-smol binary; falls back to a per-platform path
* (shellout on macOS / Windows, direct sysfs reads on Linux) on
* system Node.
*/
export async function isOnAcPower(): Promise<boolean> {
const native = await getSmolPower()
if (native) {
return native.isOnAcPower()
}
if (process.platform === 'darwin') {
return await detectMacOs()
}
if (process.platform === 'linux') {
return await detectLinux()
}
if (process.platform === 'win32') {
return await detectWindows()
}
// Unsupported platform; conservative default.
return true
}
Loading
Loading