@@ -11,7 +11,7 @@ import { promisify } from 'util';
11
11
import { promises as fs , createReadStream , createWriteStream } from 'fs' ;
12
12
import { AddonConfig , loadGYPConfig , storeGYPConfig , modifyAddonGyp } from './native-addons' ;
13
13
import { ExecutableMetadata , generateRCFile } from './executable-metadata' ;
14
- import { spawnBuildCommand , ProcessEnv , pipeline } from './helpers' ;
14
+ import { spawnBuildCommand , ProcessEnv , pipeline , createCppJsStringDefinition } from './helpers' ;
15
15
import { Readable } from 'stream' ;
16
16
import nv from '@pkgjs/nv' ;
17
17
@@ -209,6 +209,8 @@ async function compileJSFileAsBinaryImpl (options: CompilationOptions, logger: L
209
209
const extraJSSourceFiles : string [ ] = [ ] ;
210
210
const enableBindingsPatch = options . enableBindingsPatch ?? options . addons ?. length > 0 ;
211
211
212
+ const jsMainSource = await fs . readFile ( options . sourceFile , 'utf8' ) ;
213
+
212
214
// We use the official embedder API for stability, which is available in all
213
215
// supported versions of Node.js.
214
216
{
@@ -250,32 +252,26 @@ async function compileJSFileAsBinaryImpl (options: CompilationOptions, logger: L
250
252
registerFunctions . map ( ( fn ) => `void ${ fn } (const void**,const void**);\n` ) . join ( '' ) ) ;
251
253
mainSource = mainSource . replace ( / \b R E P L A C E _ D E F I N E _ L I N K E D _ M O D U L E S \b / g,
252
254
registerFunctions . map ( ( fn ) => `${ fn } ,` ) . join ( '' ) ) ;
255
+ mainSource = mainSource . replace ( / \b R E P L A C E _ W I T H _ M A I N _ S C R I P T _ S O U R C E _ G E T T E R \b / g,
256
+ createCppJsStringDefinition ( 'GetBoxednodeMainScriptSource' , jsMainSource ) ) ;
253
257
await fs . writeFile ( path . join ( nodeSourcePath , 'src' , 'node_main.cc' ) , mainSource ) ;
254
258
logger . stepCompleted ( ) ;
255
259
}
256
260
257
261
logger . stepStarting ( 'Inserting custom code into Node.js source' ) ;
258
262
await fs . mkdir ( path . join ( nodeSourcePath , 'lib' , namespace ) , { recursive : true } ) ;
259
- const source = await fs . readFile ( options . sourceFile , 'utf8' ) ;
260
- await fs . writeFile (
261
- path . join ( nodeSourcePath , 'lib' , namespace , `${ namespace } _src.js` ) ,
262
- `module.exports = ${ JSON . stringify ( source ) } ` ) ;
263
263
let entryPointTrampolineSource = await fs . readFile (
264
264
path . join ( __dirname , '..' , 'resources' , 'entry-point-trampoline.js' ) , 'utf8' ) ;
265
265
entryPointTrampolineSource = entryPointTrampolineSource . replace (
266
266
/ \b R E P L A C E _ W I T H _ B O X E D N O D E _ C O N F I G \b / g,
267
267
JSON . stringify ( {
268
- srcMod : `${ namespace } /${ namespace } _src` ,
269
268
requireMappings : requireMappings . map ( ( [ re , linked ] ) => [ re . source , re . flags , linked ] ) ,
270
269
enableBindingsPatch
271
270
} ) ) ;
272
271
await fs . writeFile (
273
272
path . join ( nodeSourcePath , 'lib' , namespace , `${ namespace } .js` ) ,
274
273
entryPointTrampolineSource ) ;
275
- extraJSSourceFiles . push (
276
- `./lib/${ namespace } /${ namespace } .js` ,
277
- `./lib/${ namespace } /${ namespace } _src.js`
278
- ) ;
274
+ extraJSSourceFiles . push ( `./lib/${ namespace } /${ namespace } .js` ) ;
279
275
logger . stepCompleted ( ) ;
280
276
281
277
logger . stepStarting ( 'Storing executable metadata' ) ;
0 commit comments