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 */
103116export 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 */
110134export 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 */
140174export 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 */
187226export 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
0 commit comments