@@ -92,6 +92,7 @@ if (process.env.NODE_CHANNEL_FD) {
9292port . on ( 'message' , ( message ) => {
9393 if ( message . type === LOAD_SCRIPT ) {
9494 const {
95+ argv,
9596 cwdCounter,
9697 filename,
9798 doEval,
@@ -115,6 +116,9 @@ port.on('message', (message) => {
115116 assert ( ! CJSLoader . hasLoadedAnyUserCJSModule ) ;
116117 loadPreloadModules ( ) ;
117118 initializeFrozenIntrinsics ( ) ;
119+ if ( argv !== undefined ) {
120+ process . argv = process . argv . concat ( argv ) ;
121+ }
118122 publicWorker . parentPort = publicPort ;
119123 publicWorker . workerData = workerData ;
120124
@@ -143,12 +147,22 @@ port.on('message', (message) => {
143147 port . postMessage ( { type : UP_AND_RUNNING } ) ;
144148 if ( doEval ) {
145149 const { evalScript } = require ( 'internal/process/execution' ) ;
146- evalScript ( '[worker eval]' , filename ) ;
150+ const name = '[worker eval]' ;
151+ // This is necessary for CJS module compilation.
152+ // TODO: pass this with something really internal.
153+ ObjectDefineProperty ( process , '_eval' , {
154+ configurable : true ,
155+ enumerable : true ,
156+ value : filename ,
157+ } ) ;
158+ process . argv . splice ( 1 , 0 , name ) ;
159+ evalScript ( name , filename ) ;
147160 } else {
148161 // script filename
149162 // runMain here might be monkey-patched by users in --require.
150163 // XXX: the monkey-patchability here should probably be deprecated.
151- CJSLoader . Module . runMain ( process . argv [ 1 ] = filename ) ;
164+ process . argv . splice ( 1 , 0 , filename ) ;
165+ CJSLoader . Module . runMain ( filename ) ;
152166 }
153167 } else if ( message . type === STDIO_PAYLOAD ) {
154168 const { stream, chunk, encoding } = message ;
0 commit comments