Skip to content

Commit 443138b

Browse files
committed
Fix CI issues and update tests
1 parent 606ca61 commit 443138b

File tree

5 files changed

+228
-25
lines changed

5 files changed

+228
-25
lines changed
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
2+
/**
3+
* @fileoverview Version consistency checker for Socket CLI release process.
4+
*
5+
* Ensures all @socketbin packages and the main socket package have the same version.
6+
* This is CRITICAL for the release process to work correctly.
7+
*/
8+
9+
import { existsSync, promises as fs } from 'node:fs'
10+
import path from 'node:path'
11+
import { fileURLToPath } from 'node:url'
12+
13+
import colors from 'yoctocolors-cjs'
14+
15+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
16+
const ROOT_DIR = path.join(__dirname, '..')
17+
18+
/**
19+
* Platform configurations for @socketbin packages.
20+
*/
21+
const PLATFORMS = [
22+
{ platform: 'darwin', arch: 'arm64' },
23+
{ platform: 'darwin', arch: 'x64' },
24+
{ platform: 'linux', arch: 'arm64' },
25+
{ platform: 'linux', arch: 'x64' },
26+
{ platform: 'win32', arch: 'arm64' },
27+
{ platform: 'win32', arch: 'x64' },
28+
]
29+
30+
/**
31+
* Read and parse a package.json file.
32+
*/
33+
async function readPackageJson(packagePath) {
34+
try {
35+
const content = await fs.readFile(packagePath, 'utf8')
36+
return JSON.parse(content)
37+
} catch (error) {
38+
if (error.code === 'ENOENT') {
39+
return null
40+
}
41+
throw error
42+
}
43+
}
44+
45+
/**
46+
* Check version consistency across all packages.
47+
*/
48+
async function checkVersionConsistency(targetVersion = null) {
49+
const errors = []
50+
const warnings = []
51+
const versions = new Map()
52+
53+
console.log('🔍 Checking version consistency...\n')
54+
55+
// Check main package.json version.
56+
const mainPackagePath = path.join(ROOT_DIR, 'package.json')
57+
const mainPackage = await readPackageJson(mainPackagePath)
58+
const mainVersion = mainPackage.version
59+
60+
console.log(`📦 Main package version: ${colors.cyan(mainVersion)}`)
61+
versions.set('socket (main)', mainVersion)
62+
63+
// If target version specified, check it matches.
64+
if (targetVersion && targetVersion !== mainVersion) {
65+
errors.push(
66+
`Main package version (${mainVersion}) does not match target version (${targetVersion})`
67+
)
68+
}
69+
70+
// Check socket npm package (the published one).
71+
const npmPackagePath = path.join(ROOT_DIR, 'src', 'sea', 'npm-package', 'package.json')
72+
if (existsSync(npmPackagePath)) {
73+
const npmPackage = await readPackageJson(npmPackagePath)
74+
if (npmPackage) {
75+
const npmVersion = npmPackage.version
76+
console.log(`📦 Socket npm package version: ${colors.cyan(npmVersion)}`)
77+
versions.set('socket (npm)', npmVersion)
78+
79+
if (npmVersion !== mainVersion) {
80+
errors.push(
81+
`Socket npm package version (${npmVersion}) does not match main version (${mainVersion})`
82+
)
83+
}
84+
85+
// Check optionalDependencies versions.
86+
if (npmPackage.optionalDependencies) {
87+
console.log('\n📦 Checking optionalDependencies versions:')
88+
for (const [dep, version] of Object.entries(npmPackage.optionalDependencies)) {
89+
if (dep.startsWith('@socketbin/')) {
90+
console.log(` ${dep}: ${colors.cyan(version)}`)
91+
versions.set(dep, version)
92+
93+
if (version !== mainVersion && version !== targetVersion) {
94+
warnings.push(
95+
`${dep} version in optionalDependencies (${version}) does not match expected version`
96+
)
97+
}
98+
}
99+
}
100+
}
101+
}
102+
} else {
103+
warnings.push('Socket npm package not found at src/sea/npm-package/package.json')
104+
}
105+
106+
// Check @socketbin binary packages.
107+
console.log('\n📦 Checking @socketbin package versions:')
108+
const platformChecks = await Promise.all(
109+
PLATFORMS.map(async ({ arch, platform }) => {
110+
const packageName = `@socketbin/cli-${platform}-${arch}`
111+
const packagePath = path.join(
112+
ROOT_DIR,
113+
'packages',
114+
'binaries',
115+
`cli-${platform}-${arch}`,
116+
'package.json'
117+
)
118+
119+
if (existsSync(packagePath)) {
120+
const pkg = await readPackageJson(packagePath)
121+
if (pkg) {
122+
const pkgVersion = pkg.version
123+
return {
124+
packageName,
125+
pkgVersion,
126+
exists: true,
127+
error: pkgVersion !== mainVersion
128+
? `${packageName} version (${pkgVersion}) does not match main version (${mainVersion})`
129+
: null
130+
}
131+
}
132+
}
133+
return {
134+
packageName,
135+
exists: false
136+
}
137+
})
138+
)
139+
140+
// Process results in order.
141+
for (const result of platformChecks) {
142+
if (result.exists) {
143+
console.log(` ${result.packageName}: ${colors.cyan(result.pkgVersion)}`)
144+
versions.set(result.packageName, result.pkgVersion)
145+
if (result.error) {
146+
errors.push(result.error)
147+
}
148+
} else {
149+
// Package doesn't exist yet (expected before first publish).
150+
console.log(` ${result.packageName}: ${colors.gray('(not created yet)')}`)
151+
}
152+
}
153+
154+
// Check for version mismatches.
155+
const uniqueVersions = new Set(versions.values())
156+
if (uniqueVersions.size > 1 && versions.size > 2) {
157+
console.log(`\n⚠️ Multiple versions detected: ${Array.from(uniqueVersions).join(', ')}`)
158+
}
159+
160+
// Print results.
161+
console.log()
162+
if (errors.length > 0) {
163+
console.log(colors.red('❌ Version consistency check failed!\n'))
164+
errors.forEach(error => console.log(` ${colors.red('✗')} ${error}`))
165+
166+
console.log('\n' + colors.yellow('To fix version mismatches:'))
167+
console.log(' 1. Update version in main package.json')
168+
console.log(' 2. Run: npm version <version> --no-git-tag-version in src/sea/npm-package')
169+
console.log(' 3. Ensure all @socketbin packages are regenerated with correct version')
170+
return false
171+
}
172+
173+
if (warnings.length > 0) {
174+
console.log(colors.yellow('⚠️ Warnings:\n'))
175+
warnings.forEach(warning => console.log(` ${colors.yellow('⚠')} ${warning}`))
176+
}
177+
178+
console.log(colors.green('✅ All package versions are consistent!'))
179+
return true
180+
}
181+
182+
/**
183+
* Main entry point.
184+
*/
185+
async function main() {
186+
// Check if a target version was provided.
187+
const targetVersion = process.argv[2]
188+
189+
if (targetVersion) {
190+
console.log(`Target version: ${colors.cyan(targetVersion)}\n`)
191+
}
192+
193+
const isConsistent = await checkVersionConsistency(targetVersion)
194+
process.exitCode = isConsistent ? 0 : 1
195+
}
196+
197+
// Run if executed directly.
198+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
199+
main().catch(error => {
200+
console.error(colors.red('Error:'), error.message)
201+
process.exitCode = 1
202+
})
203+
}
204+
205+
export { checkVersionConsistency }

scripts/publish-yao.mjs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { parseArgs } from 'node:util'
1818

1919
import colors from 'yoctocolors-cjs'
2020

21+
import { checkVersionConsistency } from './check-version-consistency.mjs'
22+
2123
const __dirname = path.dirname(fileURLToPath(import.meta.url))
2224
const ROOT_DIR = path.join(__dirname, '..')
2325
const BUILD_DIR = path.join(ROOT_DIR, 'build', 'yao')
@@ -135,9 +137,9 @@ async function checkNodeVersionsForPublish(silent = false) {
135137
const newerVersions = versions.filter(v => {
136138
const parts = v.split('.').map(Number)
137139
// Only check same major version for patch updates
138-
if (parts[0] !== currentParts[0]) return false
139-
if (parts[1] > currentParts[1]) return true
140-
if (parts[1] === currentParts[1] && parts[2] > currentParts[2]) return true
140+
if (parts[0] !== currentParts[0]) {return false}
141+
if (parts[1] > currentParts[1]) {return true}
142+
if (parts[1] === currentParts[1] && parts[2] > currentParts[2]) {return true}
141143
return false
142144
})
143145

@@ -154,10 +156,10 @@ async function checkNodeVersionsForPublish(silent = false) {
154156
console.log(colors.magenta('║') + ' 3. Update version in ' + colors.cyan('.config/socket-node.json'))
155157
console.log(colors.magenta('║'))
156158
console.log(colors.magenta('║') + ' Latest versions by major:')
157-
if (v24) console.log(colors.magenta('║') + ` Node 24: ${colors.cyan(`v${v24}`)}`)
158-
if (v22) console.log(colors.magenta('║') + ` Node 22: ${colors.cyan(`v${v22}`)}`)
159-
if (v20) console.log(colors.magenta('║') + ` Node 20: ${colors.cyan(`v${v20}`)}`)
160-
if (v18) console.log(colors.magenta('║') + ` Node 18: ${colors.cyan(`v${v18}`)}`)
159+
if (v24) {console.log(colors.magenta('║') + ` Node 24: ${colors.cyan(`v${v24}`)}`)}
160+
if (v22) {console.log(colors.magenta('║') + ` Node 22: ${colors.cyan(`v${v22}`)}`)}
161+
if (v20) {console.log(colors.magenta('║') + ` Node 20: ${colors.cyan(`v${v20}`)}`)}
162+
if (v18) {console.log(colors.magenta('║') + ` Node 18: ${colors.cyan(`v${v18}`)}`)}
161163
console.log(colors.magenta('═'.repeat(70)) + '\n')
162164
}
163165

@@ -166,7 +168,7 @@ async function checkNodeVersionsForPublish(silent = false) {
166168
available: { v24, v22, v20, v18 },
167169
hasUpdates: newerVersions.length > 0
168170
}
169-
} catch (e) {
171+
} catch {
170172
if (!silent) {
171173
console.warn(` Version check failed, using socket-node: v${SOCKET_NODE_VERSION}`)
172174
}
@@ -232,7 +234,8 @@ async function buildYaoBinary(platform, arch, nodeVersion) {
232234
PKG_CONFIG,
233235
'--targets', pkgTarget,
234236
'--output', outputPath,
235-
'--compress', 'GZip', // Use compression for smaller binaries
237+
// Use compression for smaller binaries
238+
'--compress', 'GZip',
236239
]
237240

238241
// Add minification in production
@@ -553,15 +556,16 @@ Notes:
553556
- Uses trusted publishing with --provenance flag
554557
- Each platform publishes as a separate npm package
555558
`)
556-
process.exit(0)
559+
process.exitCode = 0
560+
return
557561
}
558562

559563
console.log('🚀 Socket CLI Yao-PKG Publisher')
560564
console.log('================================\n')
561565

562566
try {
563567
// Get Node version
564-
let nodeVersion = values['node-version'] || SOCKET_NODE_VERSION
568+
const nodeVersion = values['node-version'] || SOCKET_NODE_VERSION
565569
console.log(`📦 Using socket-node version: v${nodeVersion}`)
566570

567571
// Check for available updates unless disabled

src/commands/analytics/cmd-analytics.test.mts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,9 @@ describe('socket analytics', async () => {
203203
throw err;
204204
^
205205
206-
Error: Cannot find module './globs.js'
206+
Error: Cannot find module './external/ink'
207207
Require stack:
208-
- /Users/jdalton/projects/socket-cli/dist/external/@socketsecurity/registry/dist/lib/fs.js
209-
- /Users/jdalton/projects/socket-cli/dist/constants.js
210-
- /Users/jdalton/projects/socket-cli/dist/vendor.js
208+
- /Users/jdalton/projects/socket-cli/dist/utils.js
211209
- /Users/jdalton/projects/socket-cli/dist/cli.js
212210
at Module._resolveFilename (node:internal/modules/cjs/loader:1420:15)
213211
at defaultResolveImpl (node:internal/modules/cjs/loader:1058:19)
@@ -217,13 +215,11 @@ describe('socket analytics', async () => {
217215
at wrapModuleLoad (node:internal/modules/cjs/loader:244:24)
218216
at Module.require (node:internal/modules/cjs/loader:1503:12)
219217
at require (node:internal/modules/helpers:152:16)
220-
at Object.<anonymous> (/Users/jdalton/projects/socket-cli/dist/external/@socketsecurity/registry/dist/lib/fs.js:5:17)
218+
at Object.<anonymous> (/Users/jdalton/projects/socket-cli/dist/utils.js:1:2437)
221219
at Module._compile (node:internal/modules/cjs/loader:1760:14) {
222220
code: 'MODULE_NOT_FOUND',
223221
requireStack: [
224-
'/Users/jdalton/projects/socket-cli/dist/external/@socketsecurity/registry/dist/lib/fs.js',
225-
'/Users/jdalton/projects/socket-cli/dist/constants.js',
226-
'/Users/jdalton/projects/socket-cli/dist/vendor.js',
222+
'/Users/jdalton/projects/socket-cli/dist/utils.js',
227223
'/Users/jdalton/projects/socket-cli/dist/cli.js'
228224
]
229225
}

src/commands/optimize/cmd-optimize.test.mts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,8 @@ describe('socket optimize', async () => {
262262
throw err;
263263
^
264264
265-
Error: Cannot find module './constants.js'
265+
Error: Cannot find module './external/ink'
266266
Require stack:
267-
- /Users/jdalton/projects/socket-cli/dist/external/@socketsecurity/sdk/dist/index.js
268267
- /Users/jdalton/projects/socket-cli/dist/utils.js
269268
- /Users/jdalton/projects/socket-cli/dist/cli.js
270269
at Module._resolveFilename (node:internal/modules/cjs/loader:1420:15)
@@ -275,11 +274,10 @@ describe('socket optimize', async () => {
275274
at wrapModuleLoad (node:internal/modules/cjs/loader:244:24)
276275
at Module.require (node:internal/modules/cjs/loader:1503:12)
277276
at require (node:internal/modules/helpers:152:16)
278-
at Object.<anonymous> (/Users/jdalton/projects/socket-cli/dist/external/@socketsecurity/sdk/dist/index.js:3:17)
277+
at Object.<anonymous> (/Users/jdalton/projects/socket-cli/dist/utils.js:1:2437)
279278
at Module._compile (node:internal/modules/cjs/loader:1760:14) {
280279
code: 'MODULE_NOT_FOUND',
281280
requireStack: [
282-
'/Users/jdalton/projects/socket-cli/dist/external/@socketsecurity/sdk/dist/index.js',
283281
'/Users/jdalton/projects/socket-cli/dist/utils.js',
284282
'/Users/jdalton/projects/socket-cli/dist/cli.js'
285283
]

src/commands/repository/cmd-repository-view.test.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ describe('socket repository view', async () => {
257257
throw err;
258258
^
259259
260-
Error: Cannot find module './external/@socketsecurity/registry/dist/lib/download-lock'
260+
Error: Cannot find module './external/ink'
261261
Require stack:
262262
- /Users/jdalton/projects/socket-cli/dist/utils.js
263263
- /Users/jdalton/projects/socket-cli/dist/cli.js
@@ -269,7 +269,7 @@ describe('socket repository view', async () => {
269269
at wrapModuleLoad (node:internal/modules/cjs/loader:244:24)
270270
at Module.require (node:internal/modules/cjs/loader:1503:12)
271271
at require (node:internal/modules/helpers:152:16)
272-
at Object.<anonymous> (/Users/jdalton/projects/socket-cli/dist/utils.js:1:1642)
272+
at Object.<anonymous> (/Users/jdalton/projects/socket-cli/dist/utils.js:1:2437)
273273
at Module._compile (node:internal/modules/cjs/loader:1760:14) {
274274
code: 'MODULE_NOT_FOUND',
275275
requireStack: [

0 commit comments

Comments
 (0)