Skip to content

Commit cc10026

Browse files
committed
refactor(releases): use process.platform verbatim (win32) in asset names
Previously socket-btm asset names used 'win' instead of 'win32' for the OS segment, with the rest of the ecosystem — process.platform, npm manifest os/cpu/libc filters, pnpm's --os and supportedArchitectures.os, pack-app target strings, and @pnpm/exe.<triple> package names — all using 'win32' unabbreviated. The mismatch forced callers constructing npm install filters or pack-app targets to remember which naming layer they were in. No current published @socketbin/* consumer depends on the 'win' form yet, so realign to the unabbreviated identifier now while the blast radius is bounded. Caller-visible shape change: - getPlatformArch('win32', <arch>) now returns 'win32-<arch>' (was 'win-<arch>'). - getBinaryAssetName(base, 'win32', arch, ...) now returns 'base-win32-<arch>.exe' (was 'base-win-<arch>.exe'). - PLATFORM_MAP.win32 is 'win32' (was 'win'), making the map pure identity — kept for the symmetric darwin/linux/win32 API surface and because future platforms may still need a translation. Docstring for getPlatformArch expanded to spell out the rationale: why win32 over win, why -musl is the suffix (and glibc is unsuffixed), why libc is linux-only, and why the function exists as a central triple-construction helper. The goal is that a future reader reaching for this function doesn't have to re-derive the compatibility web between npm manifest filters, pnpm target strings, and Node.js tarball naming from first principles. Tests updated to expect the new strings (8 assertions across getBinaryAssetName + getPlatformArch).
1 parent c418eb8 commit cc10026

2 files changed

Lines changed: 75 additions & 16 deletions

File tree

src/releases/socket-btm.ts

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,16 @@ export type SocketBtmReleaseConfig =
9090

9191
/**
9292
* Map Node.js platform to socket-btm asset platform naming.
93-
* Uses 'win' instead of 'win32' for file/folder names.
93+
* Identity mapping: asset names use `process.platform` verbatim
94+
* (`darwin`, `linux`, `win32`) to align with pnpm's pack-app, the
95+
* `--os` / `supportedArchitectures.os` config keys, and the
96+
* `@pnpm/exe.<os>-<arch>` package convention.
9497
*/
9598
const PLATFORM_MAP = {
9699
__proto__: null,
97100
darwin: 'darwin',
98101
linux: 'linux',
99-
win32: 'win',
102+
win32: 'win32',
100103
} as unknown as Record<string, string>
101104

102105
/**
@@ -355,7 +358,7 @@ export function getBinaryAssetName(
355358
return `${binaryBaseName}-linux-${mappedArch}${muslSuffix}${ext}`
356359
}
357360
if (platform === 'win32') {
358-
return `${binaryBaseName}-win-${mappedArch}${ext}`
361+
return `${binaryBaseName}-win32-${mappedArch}${ext}`
359362
}
360363

361364
throw new Error(`Unsupported platform: ${platform}`)
@@ -382,18 +385,74 @@ export function getBinaryName(
382385
}
383386

384387
/**
385-
* Get platform-arch identifier for directory structure.
386-
* Uses 'win' instead of 'win32' for file/folder names.
388+
* Get platform-arch identifier for directory structure and asset names.
389+
*
390+
* # Format: `<os>-<arch>[-<libc>]`
391+
*
392+
* The OS segment is `process.platform` verbatim: `darwin` / `linux` /
393+
* `win32`. The arch segment is `process.arch` verbatim: `x64` / `arm64`.
394+
* The optional libc suffix is `-musl` (Linux only; the glibc default is
395+
* unsuffixed to match Node.js's own linuxstatic convention).
396+
*
397+
* # Why these specific conventions
398+
*
399+
* ## Why `win32`, not `win`
400+
*
401+
* `win32` is what `process.platform` returns on every Windows host. Every
402+
* npm package whose install-time platform filter uses the standard
403+
* `os` / `cpu` / `libc` manifest fields must match `process.platform`
404+
* strings exactly (npm compares them verbatim — there's no shorthand
405+
* layer). Using `win` internally here would have forced a translation
406+
* every time we constructed an install filter or a target triple, and
407+
* reviewers would have to remember "we abbreviate on disk but not in
408+
* package filters." Since the two now match, there's no translation
409+
* step to get wrong.
410+
*
411+
* pnpm's pack-app (v11+) accepts `<os>-<arch>[-<libc>]` target strings
412+
* and its shards are `@pnpm/exe.<os>-<arch>` (with `win32`, not `win` —
413+
* see pnpm#11314). Our naming matches so asset names we emit can flow
414+
* directly into pack-app's `--target` arg, `pnpm.app.targets` config,
415+
* and sibling-package-name construction without a translation map.
416+
*
417+
* ## Why `-musl` is the suffix (and glibc is unsuffixed)
418+
*
419+
* Node.js's own linuxstatic tarballs historically used the unqualified
420+
* `linux` for glibc and a separate download channel for musl. The pnpm
421+
* ecosystem codified that as `linux-<arch>` (glibc, default) and
422+
* `linux-<arch>-musl` (the libc outlier), matching the asymmetric
423+
* reality of Linux distros — glibc is the majority case, musl is
424+
* Alpine-and-similar. Adding `-glibc` for the default would be
425+
* redundant noise in the name.
426+
*
427+
* ## Why libc is only appended for Linux
428+
*
429+
* macOS and Windows have exactly one system libc each (Apple libSystem,
430+
* Microsoft UCRT). A hypothetical `darwin-arm64-libsystem` conveys no
431+
* information. Node.js, npm, and pnpm all treat libc as a Linux-only
432+
* axis; we follow the same convention so callers don't have to special-
433+
* case `'darwin-arm64'.startsWith('darwin-arm64')` style matches.
434+
*
435+
* ## Why this function exists at all (vs. inlining)
436+
*
437+
* Two upstream APIs that socket-btm consumers end up calling — the
438+
* npm manifest filter (`os`/`cpu`/`libc`) and pnpm's pack-app
439+
* `--target` — both need the exact same triple format. Centralizing
440+
* the construction here means a future schema change (e.g. Node
441+
* introducing `riscv64`) gets one edit, and the error message for an
442+
* unsupported platform is uniform across downloaders, pack-app
443+
* invocations, and the `@socketbin/*` resolver logic.
387444
*
388445
* @param platform - Target platform
389446
* @param arch - Target architecture
390-
* @param libc - Linux libc variant (optional)
391-
* @returns Platform-arch identifier (e.g., 'darwin-arm64', 'linux-x64-musl', 'win-x64')
447+
* @param libc - Linux libc variant (optional; non-linux platforms ignore)
448+
* @returns Platform-arch identifier (e.g., 'darwin-arm64', 'linux-x64-musl', 'win32-x64')
392449
*
393450
* @example
394451
* ```typescript
395452
* getPlatformArch('linux', 'x64', 'musl') // 'linux-x64-musl'
396-
* getPlatformArch('darwin', 'arm64') // 'darwin-arm64'
453+
* getPlatformArch('darwin', 'arm64') // 'darwin-arm64'
454+
* getPlatformArch('win32', 'x64') // 'win32-x64'
455+
* getPlatformArch('darwin', 'x64', 'musl') // 'darwin-x64' — libc ignored
397456
* ```
398457
*/
399458
export function getPlatformArch(

test/unit/releases-socket-btm.test.mts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ describe('releases/socket-btm', () => {
7575

7676
it('should return correct asset name for win32-x64', () => {
7777
expect(getBinaryAssetName('binject', 'win32', 'x64')).toBe(
78-
'binject-win-x64.exe',
78+
'binject-win32-x64.exe',
7979
)
8080
})
8181

8282
it('should return correct asset name for win32-arm64', () => {
8383
expect(getBinaryAssetName('node', 'win32', 'arm64')).toBe(
84-
'node-win-arm64.exe',
84+
'node-win32-arm64.exe',
8585
)
8686
})
8787

@@ -123,13 +123,13 @@ describe('releases/socket-btm', () => {
123123
expect(getPlatformArch('linux', 'arm64', 'musl')).toBe('linux-arm64-musl')
124124
})
125125

126-
it('should return correct identifier for win-x64', () => {
127-
expect(getPlatformArch('win32', 'x64')).toBe('win-x64')
126+
it('should return correct identifier for win32-x64', () => {
127+
expect(getPlatformArch('win32', 'x64')).toBe('win32-x64')
128128
})
129129

130130
it('should ignore libc for non-linux platforms', () => {
131131
expect(getPlatformArch('darwin', 'arm64', 'musl')).toBe('darwin-arm64')
132-
expect(getPlatformArch('win32', 'x64', 'musl')).toBe('win-x64')
132+
expect(getPlatformArch('win32', 'x64', 'musl')).toBe('win32-x64')
133133
})
134134

135135
it('should throw for unsupported architecture', () => {
@@ -230,7 +230,7 @@ describe('releases/socket-btm', () => {
230230

231231
it('should use .exe binary name on windows', async () => {
232232
vi.mocked(downloadGitHubRelease).mockResolvedValueOnce(
233-
'C:\\dl\\node-win-x64\\node.exe',
233+
'C:\\dl\\node-win32-x64\\node.exe',
234234
)
235235

236236
await downloadSocketBtmRelease('node', {
@@ -241,9 +241,9 @@ describe('releases/socket-btm', () => {
241241

242242
const cfg = vi.mocked(downloadGitHubRelease).mock.lastCall![0]
243243
expect(cfg).toMatchObject({
244-
assetName: 'node-win-x64.exe',
244+
assetName: 'node-win32-x64.exe',
245245
binaryName: 'node.exe',
246-
platformArch: 'win-x64',
246+
platformArch: 'win32-x64',
247247
})
248248
})
249249

0 commit comments

Comments
 (0)