Skip to content

Commit e342ee2

Browse files
authored
chore(ci+deps): cascade socket-registry to 51f34ffb + drift updates (#1302)
* chore(deps): drift updates from #1286 — pnpm catalog + cli + scripts Synced from socket-repo-template / fleet-canonical drift work. - package.json + pnpm-lock.yaml + pnpm-workspace.yaml — catalog alignment with @socketsecurity/lib + @socketregistry/* fleet - packages/cli/src/cli-entry.mts — lib import refresh - packages/cli/src/utils/terminal/ascii-header.mts — drift sync - packages/cli/test/unit/constants/paths.test.mts — paths-test drift - packages/package-builder/templates/socketaddon-main/index.mjs — template drift - scripts/check.mts — adopt shared check pipeline - scripts/power-state.mts — fleet-canonical helper sync from socket-repo-template@c23dfef Splits content out of #1286, paired with the cascade SHA bump in the commit before this one. * chore(deps): regenerate pnpm-lock.yaml after rebase
1 parent 382072c commit e342ee2

9 files changed

Lines changed: 321 additions & 98 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"update": "node scripts/update.mts",
4848
"// Setup": "",
4949
"setup": "node scripts/setup.mts",
50-
"preinstall": "node scripts/bootstrap-firewall-deps.mts",
5150
"postinstall": "node scripts/setup.mts --install --quiet",
5251
"prepare": "husky",
5352
"pretest": "pnpm run build:cli"
@@ -74,6 +73,7 @@
7473
"@pnpm/lockfile.detect-dep-types": "catalog:",
7574
"@pnpm/lockfile.fs": "catalog:",
7675
"@pnpm/logger": "catalog:",
76+
"@sinclair/typebox": "catalog:",
7777
"@socketregistry/hyrious__bun.lockb": "catalog:",
7878
"@socketregistry/indent-string": "catalog:",
7979
"@socketregistry/is-interactive": "catalog:",

packages/cli/src/cli-entry.mts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Set global Socket theme for consistent CLI branding.
44
import { isError } from '@socketsecurity/lib/errors'
5-
import { setTheme } from '@socketsecurity/lib/themes'
5+
import { setTheme } from '@socketsecurity/lib/themes/context'
66
setTheme('socket')
77

88
import { promises as fs } from 'node:fs'
@@ -214,8 +214,9 @@ void (async () => {
214214
try {
215215
logger.error('Fatal error:', err)
216216
} catch {
217-
// Fallback to console if logger fails.
218-
console.error('Fatal error:', err)
217+
// Last-ditch fallback when logger itself throws — the catch
218+
// ensures we still report the original error before exit.
219+
console.error('Fatal error:', err) // # socket-hook: allow logger
219220
}
220221

221222
// Track CLI error for fatal exceptions.
@@ -234,8 +235,8 @@ process.on('uncaughtException', async err => {
234235
try {
235236
logger.error('Uncaught exception:', err)
236237
} catch {
237-
// Fallback to console if logger fails.
238-
console.error('Uncaught exception:', err)
238+
// Last-ditch fallback when logger itself throws.
239+
console.error('Uncaught exception:', err) // # socket-hook: allow logger
239240
}
240241

241242
// Track CLI error for uncaught exception.
@@ -248,7 +249,8 @@ process.on('uncaughtException', async err => {
248249
try {
249250
logger.error('Error in uncaughtException handler:', e)
250251
} catch {
251-
console.error('Error in uncaughtException handler:', e)
252+
// Last-ditch fallback when logger itself throws.
253+
console.error('Error in uncaughtException handler:', e) // # socket-hook: allow logger
252254
}
253255
} finally {
254256
// eslint-disable-next-line n/no-process-exit
@@ -262,8 +264,8 @@ process.on('unhandledRejection', async (reason, promise) => {
262264
try {
263265
logger.error('Unhandled rejection at:', promise, 'reason:', reason)
264266
} catch {
265-
// Fallback to console if logger fails.
266-
console.error('Unhandled rejection at:', promise, 'reason:', reason)
267+
// Last-ditch fallback when logger itself throws.
268+
console.error('Unhandled rejection at:', promise, 'reason:', reason) // # socket-hook: allow logger
267269
}
268270

269271
// Track CLI error for unhandled rejection.
@@ -277,7 +279,8 @@ process.on('unhandledRejection', async (reason, promise) => {
277279
try {
278280
logger.error('Error in unhandledRejection handler:', e)
279281
} catch {
280-
console.error('Error in unhandledRejection handler:', e)
282+
// Last-ditch fallback when logger itself throws.
283+
console.error('Error in unhandledRejection handler:', e) // # socket-hook: allow logger
281284
}
282285
} finally {
283286
// eslint-disable-next-line n/no-process-exit

packages/cli/src/utils/terminal/ascii-header.mts

Lines changed: 59 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
import colors from 'yoctocolors-cjs'
99

10-
import { applyShimmer } from '@socketsecurity/lib/effects/text-shimmer'
10+
import { configToSpec, frameColors } from '@socketsecurity/lib/effects/shimmer'
11+
import { colorsToAnsi } from '@socketsecurity/lib/effects/shimmer-terminal'
1112

1213
import type {
13-
ShimmerColorGradient,
14-
ShimmerState,
15-
} from '@socketsecurity/lib/effects/text-shimmer'
14+
Palette,
15+
RGB,
16+
ShimmerSpec,
17+
} from '@socketsecurity/lib/effects/shimmer'
1618

1719
/**
1820
* Color themes for header styling.
@@ -93,60 +95,72 @@ function applyHexColor(text: string, hexColor: string): string {
9395
return `\x1b[38;2;${r};${g};${b}m${text}\x1b[0m`
9496
}
9597

98+
/**
99+
* Pick the brighter of two RGB colors. Used to compose two shimmer
100+
* waves into one frame: each wave's `frameColors[i]` is computed
101+
* independently, then merged so the brighter highlight wins per char.
102+
* Treats luminance as the simple sum of channels — fine here because
103+
* both waves share base + highlight palettes.
104+
*/
105+
function brighterRgb(a: RGB, b: RGB): RGB {
106+
return a[0] + a[1] + a[2] >= b[0] + b[1] + b[2] ? a : b
107+
}
108+
96109
/**
97110
* Render ASCII logo with shimmer effect for given frame.
98-
* Uses socket-registry's applyShimmer with theme color gradients.
99-
* Features dual shimmer waves and slanted diagonal movement.
111+
*
112+
* Uses socket-lib's @socketsecurity/lib/effects/shimmer engine
113+
* (5.26.1+). Builds two ShimmerSpecs per line — primary + secondary
114+
* offset by 35 frames — and merges their per-char colors with
115+
* `brighterRgb` so the dual-wave look is preserved. Each line gets a
116+
* `slantOffset = i * 4` added to the frame counter, producing a
117+
* diagonal wave across the logo. Applies bold via ANSI before the
118+
* shimmer's truecolor escape so terminals render the highlight bold.
100119
*/
101120
export function renderShimmerFrame(
102121
frame: number,
103122
theme: HeaderTheme = 'default',
104123
): string {
105-
const themeGradient = THEME_COLORS_RGB[
106-
theme
107-
] as unknown as ShimmerColorGradient
124+
const themePalette = THEME_COLORS_RGB[theme] as unknown as Palette
108125

109-
// Apply shimmer to each line of the ASCII logo with slanted offset.
110126
const lines: string[] = []
111127
for (let i = 0; i < ASCII_LOGO.length; i++) {
112128
const line = ASCII_LOGO[i]!
129+
const lineLength = line.length
113130

114-
// Apply bold formatting first so applyShimmer can detect and preserve it.
115-
const boldLine = `\x1b[1m${line}\x1b[0m`
116-
117-
// Create slanted shimmer by offsetting each line's frame position.
118-
// This creates a diagonal wave effect across the logo.
131+
// Slant the wave by offsetting each line's frame counter — same
132+
// 4-frame-per-row delta as the previous implementation.
119133
const slantOffset = i * 4
120-
121-
// Primary shimmer wave.
122-
const shimmerState1: ShimmerState = {
123-
currentDir: 'ltr',
124-
mode: 'ltr',
125-
speed: 0.25,
126-
step: frame + slantOffset,
127-
}
128-
129-
// Secondary shimmer wave (offset to create dual wave effect).
130-
const shimmerState2: ShimmerState = {
131-
currentDir: 'ltr',
132-
mode: 'ltr',
133-
speed: 0.25,
134-
step: frame + slantOffset + 35,
135-
}
136-
137-
// Apply first shimmer pass (will detect and preserve bold).
138-
const shimmered1 = applyShimmer(boldLine, shimmerState1, {
139-
color: themeGradient,
140-
direction: 'ltr',
141-
})
142-
143-
// Apply second shimmer pass for dual wave effect.
144-
const shimmered2 = applyShimmer(shimmered1, shimmerState2, {
145-
color: themeGradient,
146-
direction: 'ltr',
147-
})
148-
149-
lines.push(shimmered2)
134+
const speed = 0.25
135+
136+
// Build the shimmer spec once and reuse for both waves — the
137+
// spec is frame-independent (positionAt is a closure over speed
138+
// + textLength + direction). The two waves differ only in the
139+
// frame counter passed to `frameColors`.
140+
const spec: ShimmerSpec = configToSpec(
141+
{
142+
color: themePalette,
143+
dir: 'ltr',
144+
speed,
145+
},
146+
lineLength,
147+
)
148+
149+
// Compute per-char colors for both waves and merge.
150+
const primaryColors = frameColors(spec, lineLength, frame + slantOffset)
151+
const secondaryColors = frameColors(
152+
spec,
153+
lineLength,
154+
frame + slantOffset + 35,
155+
)
156+
const merged: RGB[] = primaryColors.map((c, idx) =>
157+
brighterRgb(c, secondaryColors[idx]!),
158+
)
159+
160+
// Render to ANSI truecolor + wrap in bold for the brighter look
161+
// the previous implementation produced. \x1b[1m turns bold on,
162+
// colorsToAnsi emits per-char truecolor codes, \x1b[0m resets.
163+
lines.push(`\x1b[1m${colorsToAnsi(line, merged)}\x1b[0m`)
150164
}
151165

152166
return lines.join('\n')

packages/cli/test/unit/constants/paths.test.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ describe('paths constants', () => {
142142

143143
it('getBinCliPath returns path to CLI entry point', () => {
144144
const result = getBinCliPath()
145-
expect(result).toContain('cli.js')
145+
// The bundle entry is `dist/index.js` (was `dist/cli.js` before
146+
// the unified-build rename in src/constants/paths.mts).
147+
expect(result).toContain('dist/index.js')
146148
})
147149

148150
it('getDistPath returns distPath', () => {

packages/package-builder/templates/socketaddon-main/index.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,30 @@ function loadNativeAddon() {
106106
}
107107

108108
if (buildOutDir) {
109+
// First: look for a sibling-package-style layout
110+
// `socketaddon-iocraft-<platformId>/iocraft.node` next to the
111+
// main package.
109112
const siblingPath = join(buildOutDir, `socketaddon-iocraft-${platformId}`, 'iocraft.node')
110113
if (existsSync(siblingPath)) {
111114
return require(siblingPath)
112115
}
116+
// Second: look inside the main package's bundled
117+
// `node_modules/@socketaddon/iocraft-<platformId>/iocraft.node`.
118+
// This is where pnpm leaves the optionalDependency when it's
119+
// installed into the file: package's local node_modules but
120+
// not lifted into the consumer's .pnpm store (which happens
121+
// for `file:` deps that declare optionalDependencies).
122+
const bundledPath = join(
123+
buildOutDir,
124+
'socketaddon-iocraft',
125+
'node_modules',
126+
'@socketaddon',
127+
`iocraft-${platformId}`,
128+
'iocraft.node',
129+
)
130+
if (existsSync(bundledPath)) {
131+
return require(bundledPath)
132+
}
113133
}
114134

115135
throw new Error('Not in development build structure')

0 commit comments

Comments
 (0)