@@ -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
@@ -69,54 +60,38 @@ for (const file of platformDirs) {
6960 e instanceof Error &&
7061 e . message . includes ( 'You cannot publish over the previously published versions' )
7162 ) {
63+ // eslint-disable-next-line no-console
7264 console . info ( e . message ) ;
65+ // eslint-disable-next-line no-console
7366 console . warn ( `${ file } has been published, skipping` ) ;
7467 } else {
7568 throw e ;
7669 }
7770 }
7871}
7972
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-
9273// Read version from packages/cli/package.json for lockstep versioning
9374const cliPackageJson = JSON . parse ( readFileSync ( join ( currentDir , 'package.json' ) , 'utf-8' ) ) ;
9475const cliVersion = cliPackageJson . version ;
9576
9677// Create and publish separate @voidzero -dev/vite-plus-cli-{platform} packages
9778const 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' ) ;
79+ for ( const napiTarget of pkg . napi . targets ) {
80+ const { platform, arch, abi, platformArchABI } = parseTriple ( napiTarget ) ;
81+ const isWindows = platform === 'win32' ;
10782 const binaryName = isWindows ? 'vp.exe' : 'vp' ;
108- const rustBinarySource = join ( repoRoot , 'target' , rustTarget , 'release' , binaryName ) ;
83+ const rustBinarySource = join ( repoRoot , 'target' , napiTarget , 'release' , binaryName ) ;
10984
11085 if ( ! existsSync ( rustBinarySource ) ) {
11186 // eslint-disable-next-line no-console
11287 console . warn (
113- `Warning: Rust binary not found at ${ rustBinarySource } , skipping CLI package for ${ platform } ` ,
88+ `Warning: Rust binary not found at ${ rustBinarySource } , skipping CLI package for ${ platformArchABI } ` ,
11489 ) ;
11590 continue ;
11691 }
11792
11893 // Create temp directory for CLI package
119- const platformCliDir = join ( cliNpmDir , platform ) ;
94+ const platformCliDir = join ( cliNpmDir , platformArchABI ) ;
12095 mkdirSync ( platformCliDir , { recursive : true } ) ;
12196
12297 // Copy binary
@@ -131,10 +106,10 @@ for (const [platform, rustTarget] of Object.entries(RUST_TARGETS)) {
131106 const shimName = 'vp-shim.exe' ;
132107 const files = [ binaryName ] ;
133108 if ( isWindows ) {
134- const shimSource = join ( repoRoot , 'target' , rustTarget , 'release' , shimName ) ;
109+ const shimSource = join ( repoRoot , 'target' , napiTarget , 'release' , shimName ) ;
135110 if ( ! existsSync ( shimSource ) ) {
136111 console . error (
137- `Error: ${ shimName } not found at ${ shimSource } . Run "cargo build -p vite_trampoline --release --target ${ rustTarget } " first.` ,
112+ `Error: ${ shimName } not found at ${ shimSource } . Run "cargo build -p vite_trampoline --release --target ${ napiTarget } " first.` ,
138113 ) ;
139114 process . exit ( 1 ) ;
140115 }
@@ -144,13 +119,13 @@ for (const [platform, rustTarget] of Object.entries(RUST_TARGETS)) {
144119
145120 // Generate package.json
146121 const cliPackage = {
147- name : `@voidzero-dev/vite-plus-cli-${ platform } ` ,
122+ name : `@voidzero-dev/vite-plus-cli-${ platformArchABI } ` ,
148123 version : cliVersion ,
149- os : [ meta . os ] ,
150- cpu : [ meta . cpu ] ,
151- ...( meta . libc ? { libc : [ meta . libc ] } : { } ) ,
124+ os : [ platform ] ,
125+ cpu : [ arch ] ,
126+ ...( abi ? { libc : [ abi ] } : { } ) ,
152127 files,
153- description : `Vite+ CLI binary for ${ platform } ` ,
128+ description : `Vite+ CLI binary for ${ platformArchABI } ` ,
154129 repository : cliPackageJson . repository ,
155130 } ;
156131 writeFileSync ( join ( platformCliDir , 'package.json' ) , JSON . stringify ( cliPackage , null , 2 ) + '\n' ) ;
0 commit comments