@@ -12,7 +12,9 @@ import { readdir } from 'node:fs/promises';
1212import { dirname , join } from 'node:path' ;
1313import { fileURLToPath } from 'node:url' ;
1414
15- import { NapiCli } from '@napi-rs/cli' ;
15+ import { NapiCli , parseTriple } from '@napi-rs/cli' ;
16+
17+ import pkg from './package.json' with { type : 'json' } ;
1618
1719const cli = new NapiCli ( ) ;
1820
@@ -40,17 +42,6 @@ await cli.prePublish({
4042 skipOptionalPublish : true ,
4143} ) ;
4244
43- // Mapping from npm platform directory names to Rust target triples
44- const RUST_TARGETS : Record < string , string > = {
45- 'darwin-arm64' : 'aarch64-apple-darwin' ,
46- 'darwin-x64' : 'x86_64-apple-darwin' ,
47- 'linux-arm64-gnu' : 'aarch64-unknown-linux-gnu' ,
48- 'linux-arm64-musl' : 'aarch64-unknown-linux-musl' ,
49- 'linux-x64-gnu' : 'x86_64-unknown-linux-gnu' ,
50- 'linux-x64-musl' : 'x86_64-unknown-linux-musl' ,
51- 'win32-arm64-msvc' : 'aarch64-pc-windows-msvc' ,
52- 'win32-x64-msvc' : 'x86_64-pc-windows-msvc' ,
53- } ;
5445const npmDir = join ( currentDir , 'npm' ) ;
5546const platformDirs = await readdir ( npmDir ) ;
5647
@@ -77,46 +68,28 @@ for (const file of platformDirs) {
7768 }
7869}
7970
80- // Platform metadata for CLI packages
81- const PLATFORM_META : Record < string , { os : string ; cpu : string ; libc ?: string } > = {
82- 'darwin-arm64' : { os : 'darwin' , cpu : 'arm64' } ,
83- 'darwin-x64' : { os : 'darwin' , cpu : 'x64' } ,
84- 'linux-arm64-gnu' : { os : 'linux' , cpu : 'arm64' , libc : 'glibc' } ,
85- 'linux-arm64-musl' : { os : 'linux' , cpu : 'arm64' , libc : 'musl' } ,
86- 'linux-x64-gnu' : { os : 'linux' , cpu : 'x64' , libc : 'glibc' } ,
87- 'linux-x64-musl' : { os : 'linux' , cpu : 'x64' , libc : 'musl' } ,
88- 'win32-arm64-msvc' : { os : 'win32' , cpu : 'arm64' } ,
89- 'win32-x64-msvc' : { os : 'win32' , cpu : 'x64' } ,
90- } ;
91-
9271// Read version from packages/cli/package.json for lockstep versioning
9372const cliPackageJson = JSON . parse ( readFileSync ( join ( currentDir , 'package.json' ) , 'utf-8' ) ) ;
9473const cliVersion = cliPackageJson . version ;
9574
9675// Create and publish separate @voidzero -dev/vite-plus-cli-{platform} packages
9776const cliNpmDir = join ( currentDir , 'cli-npm' ) ;
98- for ( const [ platform , rustTarget ] of Object . entries ( RUST_TARGETS ) ) {
99- const meta = PLATFORM_META [ platform ] ;
100- if ( ! meta ) {
101- // eslint-disable-next-line no-console
102- console . log ( `Skipping CLI package for ${ platform } : no platform metadata` ) ;
103- continue ;
104- }
105-
106- const isWindows = platform . startsWith ( 'win32' ) ;
77+ for ( const napiTarget of pkg . napi . targets ) {
78+ const { platform, arch, abi, platformArchABI } = parseTriple ( napiTarget ) ;
79+ const isWindows = platform === 'win32' ;
10780 const binaryName = isWindows ? 'vp.exe' : 'vp' ;
108- const rustBinarySource = join ( repoRoot , 'target' , rustTarget , 'release' , binaryName ) ;
81+ const rustBinarySource = join ( repoRoot , 'target' , napiTarget , 'release' , binaryName ) ;
10982
11083 if ( ! existsSync ( rustBinarySource ) ) {
11184 // eslint-disable-next-line no-console
11285 console . warn (
113- `Warning: Rust binary not found at ${ rustBinarySource } , skipping CLI package for ${ platform } ` ,
86+ `Warning: Rust binary not found at ${ rustBinarySource } , skipping CLI package for ${ platformArchABI } ` ,
11487 ) ;
11588 continue ;
11689 }
11790
11891 // Create temp directory for CLI package
119- const platformCliDir = join ( cliNpmDir , platform ) ;
92+ const platformCliDir = join ( cliNpmDir , platformArchABI ) ;
12093 mkdirSync ( platformCliDir , { recursive : true } ) ;
12194
12295 // Copy binary
@@ -131,10 +104,10 @@ for (const [platform, rustTarget] of Object.entries(RUST_TARGETS)) {
131104 const shimName = 'vp-shim.exe' ;
132105 const files = [ binaryName ] ;
133106 if ( isWindows ) {
134- const shimSource = join ( repoRoot , 'target' , rustTarget , 'release' , shimName ) ;
107+ const shimSource = join ( repoRoot , 'target' , napiTarget , 'release' , shimName ) ;
135108 if ( ! existsSync ( shimSource ) ) {
136109 console . error (
137- `Error: ${ shimName } not found at ${ shimSource } . Run "cargo build -p vite_trampoline --release --target ${ rustTarget } " first.` ,
110+ `Error: ${ shimName } not found at ${ shimSource } . Run "cargo build -p vite_trampoline --release --target ${ napiTarget } " first.` ,
138111 ) ;
139112 process . exit ( 1 ) ;
140113 }
@@ -144,13 +117,13 @@ for (const [platform, rustTarget] of Object.entries(RUST_TARGETS)) {
144117
145118 // Generate package.json
146119 const cliPackage = {
147- name : `@voidzero-dev/vite-plus-cli-${ platform } ` ,
120+ name : `@voidzero-dev/vite-plus-cli-${ platformArchABI } ` ,
148121 version : cliVersion ,
149- os : [ meta . os ] ,
150- cpu : [ meta . cpu ] ,
151- ...( meta . libc ? { libc : [ meta . libc ] } : { } ) ,
122+ os : [ platform ] ,
123+ cpu : [ arch ] ,
124+ ...( abi ? { libc : [ abi ] } : { } ) ,
152125 files,
153- description : `Vite+ CLI binary for ${ platform } ` ,
126+ description : `Vite+ CLI binary for ${ platformArchABI } ` ,
154127 repository : cliPackageJson . repository ,
155128 } ;
156129 writeFileSync ( join ( platformCliDir , 'package.json' ) , JSON . stringify ( cliPackage , null , 2 ) + '\n' ) ;
0 commit comments