@@ -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
@@ -138,12 +142,22 @@ port.on('message', (message) => {
138142 port . postMessage ( { type : UP_AND_RUNNING } ) ;
139143 if ( doEval ) {
140144 const { evalScript } = require ( 'internal/process/execution' ) ;
141- evalScript ( '[worker eval]' , filename ) ;
145+ const name = '[worker eval]' ;
146+ // This is necessary for CJS module compilation.
147+ // TODO: pass this with something really internal.
148+ ObjectDefineProperty ( process , '_eval' , {
149+ configurable : true ,
150+ enumerable : true ,
151+ value : filename ,
152+ } ) ;
153+ process . argv . splice ( 1 , 0 , name ) ;
154+ evalScript ( name , filename ) ;
142155 } else {
143156 // script filename
144157 // runMain here might be monkey-patched by users in --require.
145158 // XXX: the monkey-patchability here should probably be deprecated.
146- CJSLoader . Module . runMain ( process . argv [ 1 ] = filename ) ;
159+ process . argv . splice ( 1 , 0 , filename ) ;
160+ CJSLoader . Module . runMain ( filename ) ;
147161 }
148162 } else if ( message . type === STDIO_PAYLOAD ) {
149163 const { stream, chunk, encoding } = message ;
0 commit comments