Skip to content

Commit 6fee37b

Browse files
committed
Bundle zod as external dependency
1 parent e9737d6 commit 6fee37b

19 files changed

+111
-55
lines changed

.config/rollup.base.config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ export default function baseConfig(extendConfig = {}) {
154154
if (
155155
id.includes('/external/') &&
156156
!id.endsWith('/external/ink-table.mjs') &&
157-
!id.endsWith('/external/yoga-layout.mjs')
157+
!id.endsWith('/external/yoga-layout.mjs') &&
158+
!id.endsWith('/external/zod.mjs')
158159
) {
159160
return true
160161
}

.config/rollup.dist.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ export default async () => {
352352
[SHADOW_PNPM_BIN]: `${srcPath}/shadow/pnpm/bin.mts`,
353353
'external/ink-table': `${srcPath}/external/ink-table.mjs`,
354354
'external/yoga-layout': `${srcPath}/external/yoga-layout.mjs`,
355+
'external/zod': `${srcPath}/external/zod.mjs`,
355356
...(constants.ENV[INLINED_SOCKET_CLI_SENTRY_BUILD]
356357
? {
357358
[INSTRUMENT_WITH_SENTRY]: `${srcPath}/${INSTRUMENT_WITH_SENTRY}.mts`,

.github/workflows/publish-socketbin.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,40 @@ jobs:
6666
- name: Build stub
6767
run: pnpm run build:sea:stub
6868

69+
- name: Setup UPX (Linux/Windows)
70+
if: matrix.platform != 'darwin'
71+
uses: crazy-max/ghaction-upx@v3
72+
with:
73+
install-only: true
74+
6975
- name: Build binary
7076
run: |
7177
pnpm run build:sea -- \
7278
--platform=${{ matrix.platform }} \
7379
--arch=${{ matrix.arch }}
7480
81+
- name: Compress binary with UPX (Linux/Windows)
82+
if: matrix.platform != 'darwin'
83+
run: |
84+
# Find the binary file (different extensions for different platforms)
85+
BINARY_FILE=$(find dist/sea -name "socket-*" -type f | head -1)
86+
if [ -f "$BINARY_FILE" ]; then
87+
echo "Compressing $BINARY_FILE with UPX..."
88+
upx --best --lzma "$BINARY_FILE" || echo "UPX compression failed, continuing anyway"
89+
ls -lh "$BINARY_FILE"
90+
fi
91+
92+
- name: Sign binary (macOS)
93+
if: matrix.platform == 'darwin'
94+
run: |
95+
# Sign the macOS binary with ad-hoc signature for distribution
96+
BINARY_FILE=$(find dist/sea -name "socket-*" -type f | head -1)
97+
if [ -f "$BINARY_FILE" ]; then
98+
echo "Signing macOS binary: $BINARY_FILE"
99+
codesign --sign - --force "$BINARY_FILE"
100+
codesign -dv "$BINARY_FILE"
101+
fi
102+
75103
- name: Verify binary
76104
run: |
77105
ls -la dist/sea/socket-*

scripts/create-placeholder-packages.mjs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env node
21

32
/**
43
* @fileoverview Creates minimal placeholder packages for @socketbin/* to enable trusted publisher.
@@ -131,11 +130,9 @@ npm install -g socket
131130
async function main() {
132131
console.log('Creating @socketbin placeholder packages...\n')
133132

134-
const packageDirs = []
135-
for (const { platform, arch } of platforms) {
136-
const dir = await createPlaceholderPackage(platform, arch)
137-
packageDirs.push(dir)
138-
}
133+
const packageDirs = await Promise.all(
134+
platforms.map(({ arch, platform }) => createPlaceholderPackage(platform, arch))
135+
)
139136

140137
console.log('\n📦 Placeholder packages created!\n')
141138
console.log('To publish them:')
@@ -230,5 +227,5 @@ main()
230227

231228
main().catch(error => {
232229
console.error('Error:', error)
233-
process.exit(1)
230+
throw error
234231
})

scripts/generate-binary-package.mjs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env node
21

32
/**
43
* @fileoverview Generates package.json for @socketbin/* binary packages.
@@ -7,8 +6,8 @@
76

87
import { promises as fs } from 'node:fs'
98
import path from 'node:path'
10-
import { parseArgs } from 'node:util'
119
import { fileURLToPath } from 'node:url'
10+
import { parseArgs } from 'node:util'
1211

1312
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1413
const rootDir = path.join(__dirname, '..')
@@ -23,11 +22,10 @@ const { values } = parseArgs({
2322
}
2423
})
2524

26-
const { platform, arch, version, tool = 'cli', outdir } = values
25+
const { arch, outdir, platform, tool = 'cli', version } = values
2726

2827
if (!platform || !arch || !version) {
29-
console.error('Usage: generate-binary-package.mjs --platform=darwin --arch=arm64 --version=1.1.24')
30-
process.exit(1)
28+
throw new Error('Usage: generate-binary-package.mjs --platform=darwin --arch=arm64 --version=1.1.24')
3129
}
3230

3331
// Clean version (remove 'v' prefix if present)
@@ -154,7 +152,7 @@ async function generatePackage() {
154152
await fs.chmod(targetBinary, 0o755)
155153
}
156154
console.log(`Copied binary: ${sourceBinary} -> ${targetBinary}`)
157-
} catch (error) {
155+
} catch {
158156
console.warn(`Warning: Binary not found at ${sourceBinary}`)
159157
console.warn('Binary should be copied manually or in CI')
160158
}
@@ -163,7 +161,7 @@ async function generatePackage() {
163161
console.log(`\nTo publish:\n cd ${packageDir}\n npm publish --provenance --access public`)
164162
} catch (error) {
165163
console.error('Error generating package:', error)
166-
process.exit(1)
164+
throw error
167165
}
168166
}
169167

scripts/lint-affected.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* Supports cross-repository linting for Socket projects.
55
*/
66

7+
import { promises as fs } from 'node:fs'
78
import path from 'node:path'
89

9-
import { promises as fs } from 'node:fs'
1010

1111
import WIN32 from '@socketsecurity/registry/lib/constants/WIN32'
1212
import { logger } from '@socketsecurity/registry/lib/logger'

scripts/verify-socketbin-packages.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env node
21

32
/**
43
* @fileoverview Verifies that all @socketbin/* packages exist on npm registry.

src/cli.mts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ import { scheduleUpdateCheck } from './utils/update-manager.mts'
4646

4747
const __filename = fileURLToPath(import.meta.url)
4848

49-
// Check for --no-log flag early and silence logger if present
49+
// Check for --no-log or --json flag early and silence logger if present
50+
// When --json is set, we want clean JSON output without any logger noise
5051
const noLog =
51-
process.argv.includes('--no-log') || process.argv.includes('--noLog')
52+
process.argv.includes('--no-log') ||
53+
process.argv.includes('--noLog') ||
54+
process.argv.includes('--json')
5255
if (noLog) {
5356
// Silence all logger methods
5457
const noop = () => logger
@@ -117,7 +120,8 @@ void (async () => {
117120

118121
if (isJson) {
119122
const errorResult = formatErrorForJson(e)
120-
logger.log(serializeResultJson(errorResult))
123+
// Use console.log directly for JSON output to ensure it's not silenced
124+
console.log(serializeResultJson(errorResult))
121125
} else {
122126
// Add 2 newlines in stderr to bump below any spinner.
123127
logger.error('\n')

src/commands/manifest/output-requirements.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export async function outputRequirements(
3232
const json = serializeResultJson(result)
3333

3434
if (out === '-') {
35-
logger.log(json)
35+
// Use console.log directly for JSON output to ensure it's not silenced
36+
console.log(json)
3637
} else {
3738
fs.writeFileSync(out, json, 'utf8')
3839
}

src/commands/patch/manifest-schema.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @fileoverview Patch manifest schema for Socket CLI. Defines Zod validation schemas for patch manifest format including patch records with package specifiers, file hashes, and patch file locations. */
22

3-
import { z } from 'zod'
3+
import { z } from '../../external/zod.mjs'
44

55
export type PatchManifest = z.infer<typeof PatchManifestSchema>
66

0 commit comments

Comments
 (0)