@@ -460,6 +460,108 @@ module.exports = makeTemporaryEnv => {
460460 ) ,
461461 ) ;
462462
463+ test (
464+ `it should support the 'paths' option from require.resolve (same dependency tree)` ,
465+ makeTemporaryEnv (
466+ {
467+ private : true ,
468+ workspaces : [ `workspace-*` ] ,
469+ } ,
470+ {
471+ plugNPlay : true ,
472+ } ,
473+ async ( { path, run, source} ) => {
474+ await writeJson ( `${ path } /workspace-a/package.json` , {
475+ name : `workspace-a` ,
476+ version : `1.0.0` ,
477+ dependencies : { [ `no-deps` ] : `1.0.0` } ,
478+ } ) ;
479+
480+ await writeJson ( `${ path } /workspace-b/package.json` , {
481+ name : `workspace-b` ,
482+ version : `1.0.0` ,
483+ dependencies : { [ `no-deps` ] : `2.0.0` , [ `one-fixed-dep` ] : `1.0.0` } ,
484+ } ) ;
485+
486+ await run ( `install` ) ;
487+
488+ await expect (
489+ source (
490+ `require(require.resolve('no-deps', {paths: ${ JSON . stringify ( [
491+ `${ path } /workspace-a` ,
492+ `${ path } /workspace-b` ,
493+ ] ) } }))`,
494+ ) ,
495+ ) . resolves . toMatchObject ( {
496+ name : `no-deps` ,
497+ version : `1.0.0` ,
498+ } ) ;
499+ } ,
500+ ) ,
501+ ) ;
502+
503+ // Skipped because not supported (we can't require files from within other dependency trees, since we couldn't
504+ // reconcile them together: dependency tree A could think that package X has deps Y@1 while dependency tree B
505+ // could think that X has deps Y@2 instead. Since they would share the same location on the disk, PnP wouldn't
506+ // be able to tell which one should be used)
507+ test . skip (
508+ `it should support the 'paths' option from require.resolve (different dependency trees)` ,
509+ makeTemporaryEnv (
510+ {
511+ dependencies : { } ,
512+ } ,
513+ {
514+ plugNPlay : true ,
515+ } ,
516+ async ( { path, run, source} ) => {
517+ await run ( `install` ) ;
518+
519+ const tmpA = await createTemporaryFolder ( ) ;
520+ const tmpB = await createTemporaryFolder ( ) ;
521+
522+ await writeJson ( `${ tmpA } /package.json` , {
523+ dependencies : { [ `no-deps` ] : `1.0.0` } ,
524+ } ) ;
525+
526+ await writeJson ( `${ tmpB } /package.json` , {
527+ dependencies : { [ `no-deps` ] : `2.0.0` , [ `one-fixed-dep` ] : `1.0.0` } ,
528+ } ) ;
529+
530+ await run ( `install` , {
531+ cwd : tmpA ,
532+ } ) ;
533+
534+ await run ( `install` , {
535+ cwd : tmpB ,
536+ } ) ;
537+
538+ await expect (
539+ source ( `require(require.resolve('no-deps', {paths: ${ JSON . stringify ( [ tmpA , tmpB ] ) } }))` ) ,
540+ ) . resolves . toMatchObject ( {
541+ name : `no-deps` ,
542+ version : `1.0.0` ,
543+ } ) ;
544+ } ,
545+ ) ,
546+ ) ;
547+
548+ test (
549+ `using require.resolve with unsupported options should throw` ,
550+ makeTemporaryEnv (
551+ {
552+ dependencies : { [ `no-deps` ] : `1.0.0` } ,
553+ } ,
554+ {
555+ plugNPlay : true ,
556+ } ,
557+ async ( { path, run, source} ) => {
558+ await run ( `install` ) ;
559+
560+ await expect ( source ( `require.resolve('no-deps', {foobar: 42})` ) ) . rejects . toBeTruthy ( ) ;
561+ } ,
562+ ) ,
563+ ) ;
564+
463565 test (
464566 `it should load the index.js file when loading from a folder` ,
465567 makeTemporaryEnv ( { } , { plugNPlay : true } , async ( { path, run, source} ) => {
0 commit comments