@@ -4,9 +4,16 @@ var path = require('path');
44var assert = require ( 'assert' ) ;
55var mockery = require ( 'mockery' ) ;
66
7+ function globalPathsContainPnpm ( ) {
8+ return undefined !== require ( 'module' ) . globalPaths . find ( function ( e ) {
9+ return e . indexOf ( '.pnpm' ) !== - 1
10+ } ) ;
11+ }
12+
713describe ( 'The path resolution method' , function ( ) {
814 var resolve = require ( '../lib/resolve.js' ) ;
915 var originalReqMainFilename = require . main . filename ;
16+ const isPnpm = globalPathsContainPnpm ( ) ;
1017
1118 // Make sure env variable isn't set for tests
1219 if ( process . env . APP_ROOT_PATH ) {
@@ -21,14 +28,53 @@ describe('The path resolution method', function() {
2128 require . main . filename = originalReqMainFilename ;
2229 } ) ;
2330
24- // Check global paths
25- it ( 'should use require.main.filename if the path is in the globalPaths array' , function ( ) {
26- var expected = path . dirname ( require . main . filename ) ;
27- require ( 'module' ) . globalPaths . forEach ( function ( globalPath ) {
28- var testPath = globalPath + path . sep + 'node-app-root-path' ;
29- assert . equal ( resolve ( testPath ) , expected ) ;
31+ if ( isPnpm ) {
32+ it ( 'should use require.main.filename if the path is in the globalPaths array (PNPM)' , function ( ) {
33+ var expected = path . dirname ( require . main . filename ) ;
34+ var root = path . resolve ( __dirname , '..' ) ;
35+
36+ require ( 'module' ) . globalPaths . forEach ( function ( globalPath ) {
37+ var testPath = globalPath + path . sep + 'node-app-root-path' ;
38+
39+ if ( - 1 !== testPath . indexOf ( '.pnpm' ) ) {
40+ assert . equal ( resolve ( testPath ) , root ) ;
41+ } else {
42+ assert . equal ( resolve ( testPath ) , expected ) ;
43+ }
44+ } ) ;
45+ } ) ;
46+
47+ // Check pnpm
48+ it ( 'should use String.split() if installed with pnpm' , function ( ) {
49+ var cases = [
50+ '/var/www/node_modules/.pnpm/node_modules/node-app-root-path' ,
51+ '/var/www/node_modules/.pnpm/custom_registry/node-app-root-path' ,
52+ ] ;
53+ var expected = '/var/www' ;
54+
55+ cases . forEach ( function ( testPath ) {
56+ assert . equal ( resolve ( testPath ) , expected ) ;
57+ } ) ;
3058 } ) ;
31- } ) ;
59+
60+ // Check root path
61+ it ( 'should still use String.split() in the root directory (PNPM)' , function ( ) {
62+ assert . equal ( resolve ( '/node_modules' ) , path . dirname ( require . main . filename ) ) ;
63+ } ) ;
64+ } else {
65+ it ( 'should use require.main.filename if the path is in the globalPaths array' , function ( ) {
66+ var expected = path . dirname ( require . main . filename ) ;
67+ require ( 'module' ) . globalPaths . forEach ( function ( globalPath ) {
68+ var testPath = globalPath + path . sep + 'node-app-root-path' ;
69+ assert . equal ( resolve ( testPath ) , expected ) ;
70+ } ) ;
71+ } ) ;
72+
73+ // Check root path
74+ it ( 'should still use String.split() in the root directory' , function ( ) {
75+ assert . equal ( resolve ( '/node_modules' ) , '' ) ;
76+ } ) ;
77+ }
3278
3379 // Check bin/ dir in global path
3480 it ( 'should correctly handle the global bin/ edge case' , function ( ) {
@@ -54,11 +100,6 @@ describe('The path resolution method', function() {
54100 } ) ;
55101 } ) ;
56102
57- // Check root path
58- it ( 'should still use String.split() in the root directory' , function ( ) {
59- assert . equal ( resolve ( '/node_modules' ) , '' ) ;
60- } ) ;
61-
62103 // Check unexpected path
63104 it ( 'should use require.main.filename on unexpected input' , function ( ) {
64105 var cases = [
0 commit comments