11
2- const { log, download, upload, fetch, mkdirp, rmrf, copyFileAsync, runCommand, renameAsync } = require ( './util' ) ;
2+ const { log, download, upload, fetch, mkdirp, rmrf, copyFileAsync, runCommand, renameAsync, patchFile } = require ( './util' ) ;
33const { gzipSync, createGunzip } = require ( 'zlib' ) ;
44const { join, dirname, basename, resolve } = require ( 'path' ) ;
5- const { execSync } = require ( 'child_process' ) ;
65const fs = require ( 'fs' ) ;
76const path = require ( 'path' ) ;
87const os = require ( 'os' ) ;
@@ -43,8 +42,7 @@ function buildName(platform, arch, placeHolderSizeMB, version) {
4342}
4443
4544class NodeJsBuilder {
46- constructor ( cwd , version , mainAppFile , appName ) {
47-
45+ constructor ( cwd , version , mainAppFile , appName , patchDir ) {
4846 this . version = version ;
4947 this . appFile = resolve ( mainAppFile ) ;
5048 this . appName = appName ;
@@ -61,6 +59,7 @@ class NodeJsBuilder {
6159 this . make = isWindows ? 'vcbuild.bat' : isBsd ? 'gmake' : 'make' ;
6260 this . configure = isWindows ? 'configure' : './configure' ;
6361 this . srcDir = join ( __dirname ) ;
62+ this . patchDir = patchDir || join ( this . srcDir , 'patch' , version ) ;
6463 this . buildDir = join ( cwd || process . cwd ( ) , 'build' ) ;
6564 this . nodeSrcFile = join ( this . buildDir , `node-v${ version } .tar.gz` ) ;
6665 this . nodeSrcDir = join ( this . buildDir , `node-v${ version } ` ) ;
@@ -190,6 +189,15 @@ class NodeJsBuilder {
190189 } ) ;
191190 }
192191
192+ async patchThirdPartyMain ( ) {
193+ await patchFile (
194+ this . nodePath ( 'lib' , 'internal' , 'main' , 'run_third_party_main.js' ) ,
195+ join ( this . patchDir , 'run_third_party_main.js.patch' ) ) ;
196+ await patchFile (
197+ this . nodePath ( 'src' , 'node.cc' ) ,
198+ join ( this . patchDir , 'node.cc.patch' ) ) ;
199+ }
200+
193201 printDiskUsage ( ) {
194202 if ( isWindows ) { return runCommand ( 'fsutil' , [ 'volume' , 'diskfree' , 'd:' ] ) ; }
195203 return runCommand ( 'df' , [ '-h' ] ) ;
@@ -234,6 +242,7 @@ class NodeJsBuilder {
234242 return this . printDiskUsage ( )
235243 . then ( ( ) => this . downloadExpandNodeSource ( ) )
236244 . then ( ( ) => this . prepareNodeJsBuild ( ) )
245+ . then ( ( ) => this . version . split ( '.' ) [ 0 ] >= 15 ? this . patchThirdPartyMain ( ) : Promise . resolve ( ) )
237246 . then ( ( ) => {
238247 if ( isWindows ) { return runCommand ( this . make , makeArgs , this . nodeSrcDir ) ; }
239248 if ( isDarwin ) {
0 commit comments