Skip to content

Commit 3a4b36e

Browse files
committed
Normalize Windows platform naming for npm packages
Standardize naming: 'win' for file/folder/npm names, 'win32' for platform checks. Changes: - Add releasePlatform field to PLATFORM_CONFIGS (win vs win32) - Add getReleasePlatform() helper function - Update npm package names: @socketbin/cli-win-{x64,arm64} - Update external-tools-platforms.mjs keys to win-{x64,arm64} - Update workflow to use releasePlatform for artifact names/paths - Update paths.mjs to normalize win32 → win for directory names This enables consistent naming across GitHub releases and npm packages. Old packages (@socketbin/cli-win32-*) will need deprecation placeholders.
1 parent d719082 commit 3a4b36e

File tree

8 files changed

+92
-30
lines changed

8 files changed

+92
-30
lines changed

.github/workflows/provenance.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
build-binaries:
7474
if: ${{ inputs.socket }}
7575
needs: [build-cli]
76-
name: Build ${{ matrix.platform }}-${{ matrix.arch }}${{ matrix.libc && '-musl' || '' }}
76+
name: Build ${{ matrix.releasePlatform }}-${{ matrix.arch }}${{ matrix.libc && '-musl' || '' }}
7777
runs-on: ${{ matrix.runner }}
7878
permissions:
7979
contents: read
@@ -116,8 +116,8 @@ jobs:
116116
- name: Upload binary
117117
uses: actions/upload-artifact@v4
118118
with:
119-
name: binary-${{ matrix.platform }}-${{ matrix.arch }}${{ matrix.libc && '-musl' || '' }}
120-
path: packages/package-builder/build/prod/out/socketbin-cli-${{ matrix.platform }}-${{ matrix.arch }}${{ matrix.libc && '-musl' || '' }}/socket${{ matrix.platform == 'win32' && '.exe' || '' }}
119+
name: binary-${{ matrix.releasePlatform }}-${{ matrix.arch }}${{ matrix.libc && '-musl' || '' }}
120+
path: packages/package-builder/build/prod/out/socketbin-cli-${{ matrix.releasePlatform }}-${{ matrix.arch }}${{ matrix.libc && '-musl' || '' }}/socket${{ matrix.platform == 'win32' && '.exe' || '' }}
121121
retention-days: 1
122122

123123
# Publish all packages.
@@ -190,7 +190,8 @@ jobs:
190190
mkdir -p "$PKG_DIR"
191191
192192
# Copy binary from artifact.
193-
if [ "$PLATFORM" = "win32" ]; then
193+
# Check for 'win' (release naming, not win32).
194+
if [ "$PLATFORM" = "win" ]; then
194195
cp "artifacts/binary-${target}/socket.exe" "$PKG_DIR/"
195196
else
196197
cp "artifacts/binary-${target}/socket" "$PKG_DIR/"

packages/build-infra/lib/platform-targets.mjs

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
* @fileoverview Shared platform target utilities for SEA builds.
33
* Provides constants and parsing functions for platform/arch/libc combinations.
44
* This is the single source of truth for all platform definitions.
5+
*
6+
* Naming convention:
7+
* - `platform`: Node.js process.platform value (darwin, linux, win32)
8+
* - `releasePlatform`: Normalized for file/folder/npm names (darwin, linux, win)
59
*/
610

711
/**
812
* Complete platform configuration with all metadata.
913
* This is the authoritative source for platform definitions.
1014
* @type {ReadonlyArray<{
1115
* platform: string,
16+
* releasePlatform: string,
1217
* arch: string,
1318
* libc?: string,
1419
* runner: string,
@@ -26,6 +31,7 @@ export const PLATFORM_CONFIGS = Object.freeze([
2631
description: 'macOS ARM64 (Apple Silicon)',
2732
os: 'darwin',
2833
platform: 'darwin',
34+
releasePlatform: 'darwin',
2935
runner: 'macos-latest',
3036
},
3137
{
@@ -35,6 +41,7 @@ export const PLATFORM_CONFIGS = Object.freeze([
3541
description: 'macOS x64 (Intel)',
3642
os: 'darwin',
3743
platform: 'darwin',
44+
releasePlatform: 'darwin',
3845
runner: 'macos-latest',
3946
},
4047
{
@@ -44,6 +51,7 @@ export const PLATFORM_CONFIGS = Object.freeze([
4451
description: 'Linux ARM64 (glibc)',
4552
os: 'linux',
4653
platform: 'linux',
54+
releasePlatform: 'linux',
4755
runner: 'ubuntu-latest',
4856
},
4957
{
@@ -54,6 +62,7 @@ export const PLATFORM_CONFIGS = Object.freeze([
5462
libc: 'musl',
5563
os: 'linux',
5664
platform: 'linux',
65+
releasePlatform: 'linux',
5766
runner: 'ubuntu-latest',
5867
},
5968
{
@@ -63,6 +72,7 @@ export const PLATFORM_CONFIGS = Object.freeze([
6372
description: 'Linux x64 (glibc)',
6473
os: 'linux',
6574
platform: 'linux',
75+
releasePlatform: 'linux',
6676
runner: 'ubuntu-latest',
6777
},
6878
{
@@ -73,6 +83,7 @@ export const PLATFORM_CONFIGS = Object.freeze([
7383
libc: 'musl',
7484
os: 'linux',
7585
platform: 'linux',
86+
releasePlatform: 'linux',
7687
runner: 'ubuntu-latest',
7788
},
7889
{
@@ -82,6 +93,7 @@ export const PLATFORM_CONFIGS = Object.freeze([
8293
description: 'Windows ARM64',
8394
os: 'win32',
8495
platform: 'win32',
96+
releasePlatform: 'win',
8597
runner: 'windows-latest',
8698
},
8799
{
@@ -91,24 +103,41 @@ export const PLATFORM_CONFIGS = Object.freeze([
91103
description: 'Windows x64',
92104
os: 'win32',
93105
platform: 'win32',
106+
releasePlatform: 'win',
94107
runner: 'windows-latest',
95108
},
96109
])
97110

98111
/**
99-
* Valid platform targets for SEA builds.
100-
* Format: <platform>-<arch>[-musl]
112+
* Valid platform targets for SEA builds (using releasePlatform for naming).
113+
* Format: <releasePlatform>-<arch>[-musl]
101114
* Derived from PLATFORM_CONFIGS.
102115
*/
103116
export const PLATFORM_TARGETS = PLATFORM_CONFIGS.map(
104-
c => `${c.platform}-${c.arch}${c.libc ? `-${c.libc}` : ''}`,
117+
c => `${c.releasePlatform}-${c.arch}${c.libc ? `-${c.libc}` : ''}`,
105118
)
106119

107120
/**
108-
* Valid platforms.
121+
* Get the release platform name for file/folder/npm naming.
122+
* Converts win32 → win, leaves others unchanged.
123+
*
124+
* @param {string} platform - Node.js platform (darwin, linux, win32).
125+
* @returns {string} Release platform (darwin, linux, win).
126+
*/
127+
export function getReleasePlatform(platform) {
128+
return platform === 'win32' ? 'win' : platform
129+
}
130+
131+
/**
132+
* Valid platforms (Node.js process.platform values).
109133
*/
110134
export const VALID_PLATFORMS = ['darwin', 'linux', 'win32']
111135

136+
/**
137+
* Valid release platforms (for file/folder/npm naming).
138+
*/
139+
export const VALID_RELEASE_PLATFORMS = ['darwin', 'linux', 'win']
140+
112141
/**
113142
* Valid architectures.
114143
*/
@@ -124,7 +153,8 @@ export const VALID_ARCHS = ['arm64', 'x64']
124153

125154
/**
126155
* Parse a platform target string into components.
127-
* Handles formats: darwin-arm64, linux-x64, linux-arm64-musl, win32-x64
156+
* Handles formats: darwin-arm64, linux-x64, linux-arm64-musl, win-x64, win32-x64
157+
* Accepts both 'win' (release naming) and 'win32' (Node.js naming) for Windows.
128158
*
129159
* @param {string} target - Target string (e.g., "darwin-arm64" or "linux-x64-musl").
130160
* @returns {PlatformTargetInfo | null} Parsed info or null if invalid.
@@ -136,6 +166,10 @@ export const VALID_ARCHS = ['arm64', 'x64']
136166
* @example
137167
* parsePlatformTarget('linux-x64-musl')
138168
* // { platform: 'linux', arch: 'x64', libc: 'musl' }
169+
*
170+
* @example
171+
* parsePlatformTarget('win-x64')
172+
* // { platform: 'win32', arch: 'x64' }
139173
*/
140174
export function parsePlatformTarget(target) {
141175
if (!target || typeof target !== 'string') {
@@ -159,7 +193,11 @@ export function parsePlatformTarget(target) {
159193
// Handle standard platform-arch.
160194
const parts = target.split('-')
161195
if (parts.length === 2) {
162-
const [platform, arch] = parts
196+
let [platform, arch] = parts
197+
// Normalize 'win' to 'win32' for internal use.
198+
if (platform === 'win') {
199+
platform = 'win32'
200+
}
163201
if (VALID_PLATFORMS.includes(platform) && VALID_ARCHS.includes(arch)) {
164202
return { arch, platform }
165203
}
@@ -180,13 +218,16 @@ export function isPlatformTarget(target) {
180218

181219
/**
182220
* Get the full platform config for a target string.
221+
* Accepts both release naming (win-x64) and Node.js naming (win32-x64).
183222
*
184-
* @param {string} target - Target string (e.g., "darwin-arm64" or "linux-x64-musl").
223+
* @param {string} target - Target string (e.g., "darwin-arm64", "win-x64", or "linux-x64-musl").
185224
* @returns {typeof PLATFORM_CONFIGS[number] | undefined} Full platform config or undefined.
186225
*/
187226
export function getPlatformConfig(target) {
188227
return PLATFORM_CONFIGS.find(
189-
c => `${c.platform}-${c.arch}${c.libc ? `-${c.libc}` : ''}` === target,
228+
c =>
229+
`${c.releasePlatform}-${c.arch}${c.libc ? `-${c.libc}` : ''}` === target ||
230+
`${c.platform}-${c.arch}${c.libc ? `-${c.libc}` : ''}` === target,
190231
)
191232
}
192233

packages/cli/scripts/constants/external-tools-platforms.mjs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
* - socket-patch-x86_64-apple-darwin.tar.gz (darwin-x64)
3030
* - socket-patch-aarch64-unknown-linux-gnu.tar.gz (linux-arm64 glibc)
3131
* - socket-patch-x86_64-unknown-linux-musl.tar.gz (linux-x64 musl)
32-
* - socket-patch-aarch64-pc-windows-msvc.zip (win32-arm64)
33-
* - socket-patch-x86_64-pc-windows-msvc.zip (win32-x64)
32+
* - socket-patch-aarch64-pc-windows-msvc.zip (win-arm64)
33+
* - socket-patch-x86_64-pc-windows-msvc.zip (win-x64)
3434
*
3535
* MISSING BUILDS (using fallbacks):
3636
* - linux-x64 (glibc): Using musl build as fallback. Musl binaries are statically
@@ -130,7 +130,7 @@ export const PLATFORM_MAP_TOOLS = {
130130

131131
// Windows ARM64 - Python, TruffleHog, and socket-patch are native arm64.
132132
// Trivy, OpenGrep, and sfw use x64 binaries (Windows 11 ARM64 emulates x64).
133-
'win32-arm64': {
133+
'win-arm64': {
134134
__proto__: null,
135135
opengrep: 'opengrep-core_windows_x86.zip', // x64 emulated.
136136
python:
@@ -142,7 +142,7 @@ export const PLATFORM_MAP_TOOLS = {
142142
},
143143

144144
// Windows x86_64 - all native x86_64.
145-
'win32-x64': {
145+
'win-x64': {
146146
__proto__: null,
147147
opengrep: 'opengrep-core_windows_x86.zip',
148148
python:
@@ -153,3 +153,16 @@ export const PLATFORM_MAP_TOOLS = {
153153
trufflehog: 'trufflehog_3.93.1_windows_amd64.tar.gz',
154154
},
155155
}
156+
157+
/**
158+
* Get platform key for EXTERNAL_TOOLS_BY_PLATFORM lookup.
159+
* Normalizes process.platform (win32) to release naming (win).
160+
*
161+
* @param {string} platform - process.platform value (darwin, linux, win32).
162+
* @param {string} arch - process.arch value (arm64, x64).
163+
* @returns {string} Normalized platform key (e.g., 'win-x64').
164+
*/
165+
export function getPlatformKey(platform, arch) {
166+
const releasePlatform = platform === 'win32' ? 'win' : platform
167+
return `${releasePlatform}-${arch}`
168+
}

packages/cli/scripts/test-download-external-tools.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const PLATFORM_MAP = {
3737
trufflehog: 'trufflehog_3.93.1_linux_amd64.tar.gz',
3838
opengrep: 'opengrep-core_linux_x86.tar.gz',
3939
},
40-
'win32-x64': {
40+
'win-x64': {
4141
trivy: 'trivy_0.69.1_windows-64bit.zip',
4242
trufflehog: 'trufflehog_3.93.1_windows_amd64.tar.gz',
4343
opengrep: 'opengrep-core_windows_x86.zip',
@@ -56,10 +56,11 @@ const TOOL_REPOS = {
5656
}
5757

5858
/**
59-
* Get current platform identifier.
59+
* Get current platform identifier (normalized for release naming).
60+
* Uses 'win' instead of 'win32' for Windows.
6061
*/
6162
function getCurrentPlatform() {
62-
const platform = process.platform
63+
const platform = process.platform === 'win32' ? 'win' : process.platform
6364
const arch = process.arch
6465
return `${platform}-${arch}`
6566
}

packages/package-builder/scripts/generate-socketbin-packages.mjs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,22 @@ const logger = getDefaultLogger()
2222
* Generate a single socketbin package.
2323
*/
2424
async function generatePackage(config) {
25-
const { arch, binExt, cpu, description, libc, os, platform } = config
25+
const { arch, binExt, cpu, description, libc, os, platform, releasePlatform } = config
2626
const muslSuffix = libc === 'musl' ? '-musl' : ''
27-
const packageName = `socketbin-cli-${platform}-${arch}${muslSuffix}`
28-
const packagePath = getSocketbinPackageDir(platform, arch, libc)
27+
const packageName = `socketbin-cli-${releasePlatform}-${arch}${muslSuffix}`
28+
const packagePath = getSocketbinPackageDir(releasePlatform, arch, libc)
2929
const templatePath = SOCKETBIN_TEMPLATE_DIR
3030

3131
// Template context for Handlebars.
32+
// Use releasePlatform for npm package naming (win, not win32).
3233
const context = {
3334
ARCH: arch,
3435
BIN_EXT: binExt,
3536
CPU: cpu,
3637
DESCRIPTION: description,
3738
LIBC_SUFFIX: muslSuffix,
3839
OS: os,
39-
PLATFORM: platform,
40+
PLATFORM: releasePlatform,
4041
}
4142

4243
// Create package directory.

packages/package-builder/scripts/paths.mjs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,33 @@ export function getPackageOutDir(packageName, mode = getBuildMode()) {
7070

7171
/**
7272
* Get the output path for a socketbin package.
73+
* Uses release platform naming (win instead of win32).
7374
*
74-
* @param {string} platform - Platform identifier (darwin, linux, win32).
75+
* @param {string} platform - Platform identifier (darwin, linux, win, or win32).
7576
* @param {string} arch - Architecture identifier (arm64, x64).
7677
* @param {string} [libc] - Linux libc variant ('musl' for Alpine).
7778
* @param {string} [mode] - Build mode (dev/prod), defaults to BUILD_MODE or CI detection.
7879
* @returns {string} Path to socketbin package directory.
7980
*/
8081
export function getSocketbinPackageDir(platform, arch, libc, mode = getBuildMode()) {
82+
// Normalize win32 → win for directory naming.
83+
const releasePlatform = platform === 'win32' ? 'win' : platform
8184
const muslSuffix = libc === 'musl' ? '-musl' : ''
82-
const packageName = `socketbin-cli-${platform}-${arch}${muslSuffix}`
85+
const packageName = `socketbin-cli-${releasePlatform}-${arch}${muslSuffix}`
8386
return getPackageOutDir(packageName, mode)
8487
}
8588

8689
/**
8790
* Get the binary path within a socketbin package.
8891
*
89-
* @param {string} platform - Platform identifier (darwin, linux, win32).
92+
* @param {string} platform - Platform identifier (darwin, linux, win, or win32).
9093
* @param {string} arch - Architecture identifier (arm64, x64).
9194
* @param {string} [libc] - Linux libc variant ('musl' for Alpine).
9295
* @param {string} [mode] - Build mode (dev/prod), defaults to BUILD_MODE or CI detection.
9396
* @returns {string} Path to the socket binary.
9497
*/
9598
export function getSocketbinBinaryPath(platform, arch, libc, mode = getBuildMode()) {
96-
const binaryName = platform === 'win32' ? 'socket.exe' : 'socket'
99+
// Accept both win and win32 for Windows detection.
100+
const binaryName = platform === 'win32' || platform === 'win' ? 'socket.exe' : 'socket'
97101
return join(getSocketbinPackageDir(platform, arch, libc, mode), binaryName)
98102
}

packages/package-builder/templates/socket-package/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"@socketbin/cli-linux-arm64-musl": "0.0.0-replaced-by-publish",
2222
"@socketbin/cli-linux-x64": "0.0.0-replaced-by-publish",
2323
"@socketbin/cli-linux-x64-musl": "0.0.0-replaced-by-publish",
24-
"@socketbin/cli-win32-arm64": "0.0.0-replaced-by-publish",
25-
"@socketbin/cli-win32-x64": "0.0.0-replaced-by-publish"
24+
"@socketbin/cli-win-arm64": "0.0.0-replaced-by-publish",
25+
"@socketbin/cli-win-x64": "0.0.0-replaced-by-publish"
2626
},
2727
"engines": {
2828
"node": ">=18"

scripts/get-platform-matrix.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ const matrix = {
1414
include: PLATFORM_CONFIGS.map(c => ({
1515
arch: c.arch,
1616
libc: c.libc ?? null,
17-
platform: c.platform,
17+
platform: c.platform, // Node.js platform (win32 for Windows)
18+
releasePlatform: c.releasePlatform, // Release naming (win for Windows)
1819
runner: c.runner,
1920
})),
2021
}

0 commit comments

Comments
 (0)