66// - Runs it (when invoked as CLI)
77// - Validates the installation (when invoked via postinstall)
88
9- ' use strict' ;
9+ " use strict" ;
1010
11- const { execFileSync, spawnSync } = require ( ' child_process' ) ;
12- const path = require ( ' path' ) ;
13- const fs = require ( 'fs' ) ;
14- const os = require ( 'os' ) ;
11+ const { execFileSync, spawnSync } = require ( " child_process" ) ;
12+ const path = require ( " path" ) ;
13+ const fs = require ( "fs" ) ;
14+ const os = require ( "os" ) ;
1515
1616// ---------------------------------------------------------------------------
1717// Platform detection
@@ -23,41 +23,41 @@ const os = require('os');
2323 */
2424function getPlatformPackageSuffix ( ) {
2525 const platform = process . platform ; // 'darwin' | 'linux' | 'win32'
26- const arch = process . arch ; // 'x64' | 'arm64' | 'arm' | 'ia32'
26+ const arch = process . arch ; // 'x64' | 'arm64' | 'arm' | 'ia32'
2727
2828 // ARM sub-arch detection (armv5/armv6/armv7)
2929 // process.config.variables.arm_version is available in some Node builds
30- const armVersion = ( process . config && process . config . variables && process . config . variables . arm_version ) || '' ;
30+ const armVersion = ( process . config && process . config . variables && process . config . variables . arm_version ) || "" ;
3131
32- if ( platform === ' darwin' ) {
33- if ( arch === ' arm64' ) return ' darwin-arm64' ;
34- if ( arch === ' x64' ) return ' darwin-x64' ;
32+ if ( platform === " darwin" ) {
33+ if ( arch === " arm64" ) return " darwin-arm64" ;
34+ if ( arch === " x64" ) return " darwin-x64" ;
3535 }
3636
37- if ( platform === ' linux' ) {
38- if ( arch === ' x64' ) return ' linux-x64' ;
39- if ( arch === ' arm64' ) return ' linux-arm64' ;
40- if ( arch === ' ia32' ) return ' linux-ia32' ;
41- if ( arch === ' arm' ) {
42- if ( armVersion === '5' ) return ' linux-arm-5' ;
43- if ( armVersion === '6' ) return ' linux-arm-6' ;
44- return ' linux-arm' ; // armv7 default
37+ if ( platform === " linux" ) {
38+ if ( arch === " x64" ) return " linux-x64" ;
39+ if ( arch === " arm64" ) return " linux-arm64" ;
40+ if ( arch === " ia32" ) return " linux-ia32" ;
41+ if ( arch === " arm" ) {
42+ if ( armVersion === "5" ) return " linux-arm-5" ;
43+ if ( armVersion === "6" ) return " linux-arm-6" ;
44+ return " linux-arm" ; // armv7 default
4545 }
46- if ( arch === ' loong64' ) return ' linux-loong64' ;
47- if ( arch === ' ppc64' ) return ' linux-ppc64le' ;
48- if ( arch === ' riscv64' ) return ' linux-riscv64' ;
49- if ( arch === ' s390x' ) return ' linux-s390x' ;
46+ if ( arch === " loong64" ) return " linux-loong64" ;
47+ if ( arch === " ppc64" ) return " linux-ppc64le" ;
48+ if ( arch === " riscv64" ) return " linux-riscv64" ;
49+ if ( arch === " s390x" ) return " linux-s390x" ;
5050 }
5151
52- if ( platform === ' win32' ) {
53- if ( arch === ' x64' ) return ' windows-x64' ;
54- if ( arch === ' arm64' ) return ' windows-arm64' ;
55- if ( arch === ' ia32' ) return ' windows-ia32' ;
52+ if ( platform === " win32" ) {
53+ if ( arch === " x64" ) return " windows-x64" ;
54+ if ( arch === " arm64" ) return " windows-arm64" ;
55+ if ( arch === " ia32" ) return " windows-ia32" ;
5656 }
5757
5858 throw new Error (
5959 `Unsupported platform: ${ platform } -${ arch } \n` +
60- ' Please open an issue at https://github.com/snowdreamtech/unirtm/issues'
60+ " Please open an issue at https://github.com/snowdreamtech/unirtm/issues"
6161 ) ;
6262}
6363
@@ -72,13 +72,13 @@ function getPlatformPackageSuffix() {
7272 */
7373function resolveBinary ( suffix ) {
7474 const pkgName = `@snowdreamtech/unirtm-${ suffix } ` ;
75- const binaryName = process . platform === ' win32' ? ' unirtm.exe' : ' unirtm' ;
75+ const binaryName = process . platform === " win32" ? " unirtm.exe" : " unirtm" ;
7676
7777 // Strategy 1: resolve via require.resolve (works when package is installed)
7878 try {
7979 const pkgJsonPath = require . resolve ( `${ pkgName } /package.json` ) ;
8080 const pkgDir = path . dirname ( pkgJsonPath ) ;
81- const binPath = path . join ( pkgDir , ' bin' , binaryName ) ;
81+ const binPath = path . join ( pkgDir , " bin" , binaryName ) ;
8282 if ( fs . existsSync ( binPath ) ) {
8383 return binPath ;
8484 }
@@ -89,7 +89,7 @@ function resolveBinary(suffix) {
8989 // Strategy 2: walk up node_modules hierarchy
9090 let dir = __dirname ;
9191 for ( let i = 0 ; i < 10 ; i ++ ) {
92- const candidate = path . join ( dir , ' node_modules' , pkgName , ' bin' , binaryName ) ;
92+ const candidate = path . join ( dir , " node_modules" , pkgName , " bin" , binaryName ) ;
9393 if ( fs . existsSync ( candidate ) ) {
9494 return candidate ;
9595 }
@@ -100,24 +100,24 @@ function resolveBinary(suffix) {
100100
101101 throw new Error (
102102 `Could not find binary for ${ pkgName } .\n` +
103- ' Try reinstalling @snowdreamtech/unirtm:\n' +
104- ' npm install @snowdreamtech/unirtm\n\n' +
105- `Platform: ${ process . platform } -${ process . arch } `
103+ " Try reinstalling @snowdreamtech/unirtm:\n" +
104+ " npm install @snowdreamtech/unirtm\n\n" +
105+ `Platform: ${ process . platform } -${ process . arch } `
106106 ) ;
107107}
108108
109109// ---------------------------------------------------------------------------
110110// Entry point
111111// ---------------------------------------------------------------------------
112112
113- const isPostInstall = process . env . npm_lifecycle_event === ' postinstall' ;
113+ const isPostInstall = process . env . npm_lifecycle_event === " postinstall" ;
114114
115115if ( isPostInstall ) {
116116 // Postinstall: just validate that the binary can be found
117117 try {
118118 const suffix = getPlatformPackageSuffix ( ) ;
119119 const binPath = resolveBinary ( suffix ) ;
120- const result = spawnSync ( binPath , [ ' --version' ] , { encoding : ' utf8' } ) ;
120+ const result = spawnSync ( binPath , [ " --version" ] , { encoding : " utf8" } ) ;
121121 if ( result . status === 0 ) {
122122 process . stdout . write ( `✅ unirtm installed successfully (${ binPath } )\n` ) ;
123123 }
@@ -133,7 +133,7 @@ if (isPostInstall) {
133133 const args = process . argv . slice ( 2 ) ;
134134
135135 const result = spawnSync ( binPath , args , {
136- stdio : ' inherit' ,
136+ stdio : " inherit" ,
137137 windowsHide : false ,
138138 } ) ;
139139
0 commit comments