1
+ // @ts -check
1
2
const fs = require ( "node:fs" ) ;
2
3
const path = require ( "node:path" ) ;
3
4
const archiver = require ( "archiver" ) ;
@@ -7,8 +8,8 @@ const download = require("download");
7
8
const arch =
8
9
( process . env . npm_config_arch || process . env . M_ARCH || process . arch ) ===
9
10
"arm64"
10
- ? [ "arm64" ]
11
- : [ "x64" ] ;
11
+ ? "arm64"
12
+ : "x64" ;
12
13
13
14
const platform = process . platform ;
14
15
const platformMap = { linux : "linux" , win32 : "win" , darwin : "mac" } ;
@@ -88,12 +89,12 @@ const beforePack = async () => {
88
89
}
89
90
}
90
91
if ( process . platform === "win32" && arch === "arm64" ) {
91
- execSync ( "npm i node-screenshots-win32-arm64-msvc" ) ;
92
- execSync ( "npm uninstall node-screenshots-win32-x64-msvc" ) ;
92
+ execSync ( "pnpm i node-screenshots-win32-arm64-msvc" ) ;
93
+ execSync ( "pnpm uninstall node-screenshots-win32-x64-msvc" ) ;
93
94
}
94
95
if ( process . platform === "darwin" && arch === "arm64" ) {
95
- execSync ( "npm i node-screenshots-darwin-arm64" ) ;
96
- execSync ( "npm uninstall node-screenshots-darwin-x64" ) ;
96
+ execSync ( "pnpm i node-screenshots-darwin-arm64" ) ;
97
+ execSync ( "pnpm uninstall node-screenshots-darwin-x64" ) ;
97
98
}
98
99
} ;
99
100
@@ -129,7 +130,7 @@ const build = {
129
130
} ,
130
131
] ,
131
132
asar : false ,
132
- artifactName : `\${productName}-\${version}-\${platform}-${ arch [ 0 ] } .\${ext}` ,
133
+ artifactName : `\${productName}-\${version}-\${platform}-${ arch } .\${ext}` ,
133
134
beforePack : beforePack ,
134
135
linux : {
135
136
category : "Utility" ,
@@ -246,7 +247,7 @@ const build = {
246
247
247
248
const outputFilePath = path . join (
248
249
c . outDir ,
249
- `app-${ process . platform } -${ arch [ 0 ] } ` ,
250
+ `app-${ process . platform } -${ arch } ` ,
250
251
) ;
251
252
252
253
const output = fs . createWriteStream ( outputFilePath ) ;
@@ -261,32 +262,30 @@ const build = {
261
262
return new Promise ( ( rj ) => {
262
263
output . on ( "close" , ( ) => {
263
264
console . log ( "生成核心包" ) ;
264
- rj ( ) ;
265
+ rj ( true ) ;
265
266
} ) ;
266
267
} ) ;
267
268
} ,
268
269
} ;
269
270
270
- const archFilter = arch [ 0 ] === "arm64" ? "x64" : "arm64" ;
271
+ const archFilter = arch === "arm64" ? "x64" : "arm64" ;
271
272
const otherPlatform = Object . keys ( platformMap ) . filter ( ( i ) => i !== platform ) ;
272
273
274
+ /** @type {string[]|undefined } */
275
+ // @ts -ignore
276
+ const files = build [ platform2 ] ?. files ;
277
+
273
278
// 移除 onnxruntime-node/bin/napi-v3/
274
- build [ platform2 ] . files . push (
279
+ files ? .push (
275
280
`!node_modules/onnxruntime-node/bin/napi-v3/${ platform } /${ archFilter } ` ,
276
281
) ;
277
282
278
283
// 移除 uiohook-napi/prebuilds
279
284
for ( const i of otherPlatform ) {
280
- build [ platform2 ] . files . push (
281
- `!node_modules/uiohook-napi/prebuilds/${ i } -arm64` ,
282
- ) ;
283
- build [ platform2 ] . files . push (
284
- `!node_modules/uiohook-napi/prebuilds/${ i } -x64` ,
285
- ) ;
285
+ files ?. push ( `!node_modules/uiohook-napi/prebuilds/${ i } -arm64` ) ;
286
+ files ?. push ( `!node_modules/uiohook-napi/prebuilds/${ i } -x64` ) ;
286
287
}
287
- build [ platform2 ] . files . push (
288
- `!node_modules/uiohook-napi/prebuilds/${ platform } -${ archFilter } ` ,
289
- ) ;
288
+ files ?. push ( `!node_modules/uiohook-napi/prebuilds/${ platform } -${ archFilter } ` ) ;
290
289
291
290
const ignoreDir = [
292
291
".*" ,
@@ -326,7 +325,7 @@ for (const i of ignoreModule) {
326
325
}
327
326
for ( let i of ignoreDir ) {
328
327
i = `!${ i } ` ;
329
- build [ platform2 ] . files . push ( i ) ;
328
+ files ? .push ( i ) ;
330
329
}
331
330
332
331
module . exports = build ;
0 commit comments