File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed
Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,7 @@ export default autoTrace(
165165 } as NodeJS . ProcessEnv ,
166166 } ;
167167
168+ spawnOpts . env . NODE_OPTIONS = removePnpLoaderArguments ( spawnOpts . env . NODE_OPTIONS ) ;
168169 if ( runAsNode ) {
169170 spawnOpts . env . ELECTRON_RUN_AS_NODE = 'true' ;
170171 } else {
@@ -231,3 +232,11 @@ export default autoTrace(
231232 return spawned ;
232233 }
233234) ;
235+
236+ function removePnpLoaderArguments ( input : string | undefined ) : string | undefined {
237+ if ( ! input ) return input ;
238+ return input . replace (
239+ / ( ( - - r e q u i r e \s + [ ^ " ] .+ \. p n p \. c j s ) | ( - - e x p e r i m e n t a l - l o a d e r \s + [ ^ " ] .+ \. p n p \. l o a d e r \. m j s ) | ( - - r e q u i r e \s + " .+ \. p n p \. c j s " ) | ( - - e x p e r i m e n t a l - l o a d e r \s + " .+ \. p n p \. l o a d e r \. m j s " ) ) ? / g,
240+ ''
241+ ) ;
242+ }
Original file line number Diff line number Diff line change @@ -207,4 +207,41 @@ describe('start', () => {
207207 } )
208208 ) . to . eventually . equal ( fakeChild ) ;
209209 } ) ;
210+
211+ it ( `should spawn remove pnp environment variable in NODE_OPTIONS` , async ( ) => {
212+ resolveStub . returnsArg ( 0 ) ;
213+ const oldNodeOptions = process . env . NODE_OPTIONS ;
214+ try {
215+ process . env . NODE_OPTIONS = '--require /some/workspace/.pnp.cjs --experimental-loader file:///some/workspace/.pnp.loader.mjs' ;
216+ await start ( {
217+ dir : __dirname ,
218+ interactive : false ,
219+ } ) ;
220+ expect ( spawnStub . firstCall . args [ 2 ] . env . NODE_OPTIONS ) . to . equal ( '' ) ;
221+ } finally {
222+ process . env . NODE_OPTIONS = oldNodeOptions ;
223+ }
224+ } ) ;
225+
226+ const testNodeOptions = [
227+ '--hello --require /some/workspace/.pnp.cjs --experimental-loader file:///some/workspace/.pnp.loader.mjs --require /some/debugConnector.js --world --some args' ,
228+ '--hello --require "/some/space path/.pnp.cjs" --experimental-loader "file:///some/space path/.pnp.loader.mjs" --require /some/debugConnector.js --world --some args' ,
229+ '--hello --require "C:\\\\some space path\\\\.pnp.cjs" --experimental-loader "file:///c:/some space path/.pnp.loader.mjs" --require /some/debugConnector.js --world --some args' ,
230+ ] ;
231+ for ( let i = 0 ; i < testNodeOptions . length ; i ++ ) {
232+ it ( `should spawn remove pnp environment variable in NODE_OPTIONS case ${ i } ` , async ( ) => {
233+ resolveStub . returnsArg ( 0 ) ;
234+ const oldNodeOptions = process . env . NODE_OPTIONS ;
235+ try {
236+ process . env . NODE_OPTIONS = testNodeOptions [ i ] ;
237+ await start ( {
238+ dir : __dirname ,
239+ interactive : false ,
240+ } ) ;
241+ expect ( spawnStub . lastCall . args [ 2 ] . env . NODE_OPTIONS ) . to . equal ( '--hello --require /some/debugConnector.js --world --some args' ) ;
242+ } finally {
243+ process . env . NODE_OPTIONS = oldNodeOptions ;
244+ }
245+ } ) ;
246+ }
210247} ) ;
Original file line number Diff line number Diff line change @@ -66,6 +66,13 @@ function getElectronModuleName(packageJSON: PackageJSONWithDeps): string {
6666async function getElectronPackageJSONPath ( dir : string , packageName : string ) : Promise < string | undefined > {
6767 const nodeModulesPath = await determineNodeModulesPath ( dir , packageName ) ;
6868 if ( ! nodeModulesPath ) {
69+ try {
70+ // Yarn PnP
71+ // eslint-disable-next-line node/no-missing-require
72+ return require . resolve ( 'electron/package.json' ) ;
73+ } catch ( e ) {
74+ // Ignore
75+ }
6976 throw new PackageNotFoundError ( packageName , dir ) ;
7077 }
7178
You can’t perform that action at this time.
0 commit comments