11const { notarize} = require ( "@electron/notarize" ) ;
2- const { execSync} = require ( "node:child_process" ) ;
3- const { readdirSync, lstatSync} = require ( "node:fs" ) ;
4- const { resolve, join} = require ( "node:path" ) ;
52const common = require ( './common.cjs' )
63
7- /**
8- * Walk a directory recursively, yielding absolute paths.
9- */
10- function walkDir ( dir ) {
11- const results = [ ] ;
12- if ( ! common . exists ( dir ) ) return results ;
13- for ( const entry of readdirSync ( dir ) ) {
14- const full = join ( dir , entry ) ;
15- const stat = lstatSync ( full ) ;
16- if ( stat . isDirectory ( ) ) {
17- results . push ( ...walkDir ( full ) ) ;
18- } else {
19- results . push ( full ) ;
20- }
21- }
22- return results ;
23- }
24-
25- /**
26- * Sign every .node file inside the .app bundle using the first available
27- * Developer ID certificate. This avoids Gatekeeper errors on quarantined
28- * apps for unsigned native addons (rollup, fsevents, etc.).
29- */
30- function signNodeModules ( appPath ) {
31- const identity = execSync (
32- `security find-identity -v -p codesigning | grep "Developer ID Application" | head -1 | sed 's/.*"\\(.*\\)"/\\1/'` ,
33- { encoding : "utf8" }
34- ) . trim ( ) ;
35- if ( ! identity ) {
36- console . warn ( " • [WARN] No Developer ID Application certificate found, skipping .node signing" ) ;
37- return ;
38- }
39- const contents = resolve ( appPath , "Contents" ) ;
40- if ( ! common . exists ( contents ) ) {
41- console . warn ( " • [WARN] .app/Contents not found, skipping .node signing" ) ;
42- return ;
43- }
44- const allFiles = walkDir ( contents ) ;
45- const nodeFiles = allFiles . filter ( f => f . endsWith ( ".node" ) ) ;
46- if ( nodeFiles . length === 0 ) {
47- console . log ( " • No .node files found, skipping code signing" ) ;
48- return ;
49- }
50- console . log ( ` • Signing ${ nodeFiles . length } .node file(s) with identity: ${ identity } ` ) ;
51- for ( const file of nodeFiles ) {
52- try {
53- execSync (
54- `codesign --sign "${ identity } " --force --options runtime --timestamp "${ file } " 2>&1` ,
55- { stdio : [ "ignore" , "pipe" , "pipe" ] , timeout : 30000 }
56- ) ;
57- console . log ( ` ✓ ${ file } ` ) ;
58- } catch ( err ) {
59- console . warn ( ` ⚠ Failed to sign ${ file } : ${ err . stderr || err . message } ` ) ;
60- }
61- }
62- }
63-
644exports . default = async function notarizing ( context ) {
655 const appName = context . packager . appInfo . productFilename ;
666 const { electronPlatformName, appOutDir} = context ;
@@ -82,9 +22,6 @@ exports.default = async function notarizing(context) {
8222
8323 let appPath = `${ appOutDir } /${ appName } .app` ;
8424
85- // ── Sign all .node files before notarization ───────────────────
86- signNodeModules ( appPath ) ;
87-
8825 let { APPLE_ID , APPLE_ID_PASSWORD , APPLE_TEAM_ID } = process . env ;
8926 if ( ! APPLE_ID ) {
9027 console . info ( " • Notarization ignore: APPLE_ID is empty" ) ;
0 commit comments