File tree 3 files changed +53
-0
lines changed
3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,7 @@ export default autoTrace(
165
165
} as NodeJS . ProcessEnv ,
166
166
} ;
167
167
168
+ spawnOpts . env . NODE_OPTIONS = removePnpLoaderArguments ( spawnOpts . env . NODE_OPTIONS ) ;
168
169
if ( runAsNode ) {
169
170
spawnOpts . env . ELECTRON_RUN_AS_NODE = 'true' ;
170
171
} else {
@@ -231,3 +232,11 @@ export default autoTrace(
231
232
return spawned ;
232
233
}
233
234
) ;
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', () => {
207
207
} )
208
208
) . to . eventually . equal ( fakeChild ) ;
209
209
} ) ;
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
+ }
210
247
} ) ;
Original file line number Diff line number Diff line change @@ -66,6 +66,13 @@ function getElectronModuleName(packageJSON: PackageJSONWithDeps): string {
66
66
async function getElectronPackageJSONPath ( dir : string , packageName : string ) : Promise < string | undefined > {
67
67
const nodeModulesPath = await determineNodeModulesPath ( dir , packageName ) ;
68
68
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
+ }
69
76
throw new PackageNotFoundError ( packageName , dir ) ;
70
77
}
71
78
You can’t perform that action at this time.
0 commit comments