@@ -5,12 +5,21 @@ var resolve = require('../');
5
5
6
6
var symlinkDir = path . join ( __dirname , 'resolver' , 'symlinked' , 'symlink' ) ;
7
7
var packageDir = path . join ( __dirname , 'resolver' , 'symlinked' , '_' , 'node_modules' , 'package' ) ;
8
+ var modADir = path . join ( __dirname , 'symlinks' , 'source' , 'node_modules' , 'mod-a' ) ;
9
+ var symlinkModADir = path . join ( __dirname , 'symlinks' , 'dest' , 'node_modules' , 'mod-a' ) ;
8
10
try {
9
11
fs . unlinkSync ( symlinkDir ) ;
10
12
} catch ( err ) { }
11
13
try {
12
14
fs . unlinkSync ( packageDir ) ;
13
15
} catch ( err ) { }
16
+ try {
17
+ fs . unlinkSync ( modADir ) ;
18
+ } catch ( err ) { }
19
+ try {
20
+ fs . unlinkSync ( symlinkModADir ) ;
21
+ } catch ( err ) { }
22
+
14
23
try {
15
24
fs . symlinkSync ( './_/symlink_target' , symlinkDir , 'dir' ) ;
16
25
} catch ( err ) {
23
32
// if fails then it is probably on Windows and lets try to create a junction
24
33
fs . symlinkSync ( path . join ( __dirname , '..' , '..' , 'package' ) + '\\' , packageDir , 'junction' ) ;
25
34
}
35
+ try {
36
+ fs . symlinkSync ( '../../source/node_modules/mod-a' , symlinkModADir , 'dir' ) ;
37
+ } catch ( err ) {
38
+ // if fails then it is probably on Windows and lets try to create a junction
39
+ fs . symlinkSync ( path . join ( __dirname , '..' , '..' , 'source' , 'node_modules' , 'mod-a' ) + '\\' , symlinkModADir , 'junction' ) ;
40
+ }
26
41
27
42
test ( 'symlink' , function ( t ) {
28
43
t . plan ( 2 ) ;
@@ -79,6 +94,106 @@ test('async symlink from node_modules to other dir when preserveSymlinks = false
79
94
resolve ( 'package' , { basedir : basedir , preserveSymlinks : false } , function ( err , result ) {
80
95
t . notOk ( err , 'no error' ) ;
81
96
t . equal ( result , path . resolve ( __dirname , 'resolver/symlinked/package/bar.js' ) ) ;
82
- t . end ( ) ;
83
97
} ) ;
84
98
} ) ;
99
+
100
+ test ( 'packageFilter' , function ( t ) {
101
+ t . test ( 'preserveSymlinks: false' , function ( st ) {
102
+ st . plan ( 5 ) ;
103
+
104
+ var basedir = path . join ( __dirname , 'symlinks' , 'dest' ) ;
105
+ var packageFilterPath ;
106
+ var actualPath = resolve . sync ( 'mod-a' , {
107
+ basedir : basedir ,
108
+ preserveSymlinks : false ,
109
+ packageFilter : function ( pkg , pkgfile ) {
110
+ packageFilterPath = pkgfile ;
111
+ }
112
+ } ) ;
113
+ st . equal (
114
+ actualPath ,
115
+ path . join ( __dirname , 'symlinks/source/node_modules/mod-a/index.js' ) ,
116
+ 'sync: actual path is correct'
117
+ ) ;
118
+ st . equal (
119
+ packageFilterPath ,
120
+ path . join ( __dirname , 'symlinks/source/node_modules/mod-a/package.json' ) ,
121
+ 'sync: packageFilter pkgfile arg is correct'
122
+ ) ;
123
+
124
+ resolve (
125
+ 'mod-a' ,
126
+ {
127
+ basedir : basedir ,
128
+ preserveSymlinks : false ,
129
+ packageFilter : function ( pkg , pkgfile ) {
130
+ packageFilterPath = pkgfile ;
131
+ }
132
+ } ,
133
+ function ( err , actualPath ) {
134
+ st . error ( err , 'no error' ) ;
135
+ st . equal (
136
+ actualPath ,
137
+ path . join ( __dirname , 'symlinks/source/node_modules/mod-a/index.js' ) ,
138
+ 'async: actual path is correct'
139
+ ) ;
140
+ st . equal (
141
+ packageFilterPath ,
142
+ path . join ( __dirname , 'symlinks/dest/node_modules/mod-a/package.json' ) ,
143
+ 'async: packageFilter pkgfile arg is correct'
144
+ ) ;
145
+ }
146
+ ) ;
147
+ } ) ;
148
+
149
+ t . test ( 'preserveSymlinks: true' , function ( st ) {
150
+ st . plan ( 5 ) ;
151
+
152
+ var basedir = path . join ( __dirname , 'symlinks' , 'dest' ) ;
153
+ var packageFilterPath ;
154
+ var actualPath = resolve . sync ( 'mod-a' , {
155
+ basedir : basedir ,
156
+ preserveSymlinks : true ,
157
+ packageFilter : function ( pkg , pkgfile ) {
158
+ packageFilterPath = pkgfile ;
159
+ }
160
+ } ) ;
161
+ st . equal (
162
+ actualPath ,
163
+ path . join ( __dirname , 'symlinks/dest/node_modules/mod-a/index.js' ) ,
164
+ 'sync: actual path is correct'
165
+ ) ;
166
+ st . equal (
167
+ packageFilterPath ,
168
+ path . join ( __dirname , 'symlinks/dest/node_modules/mod-a/package.json' ) ,
169
+ 'sync: packageFilter pkgfile arg is correct'
170
+ ) ;
171
+
172
+ var packageFilterPath ;
173
+ resolve (
174
+ 'mod-a' ,
175
+ {
176
+ basedir : basedir ,
177
+ preserveSymlinks : true ,
178
+ packageFilter : function ( pkg , pkgfile ) {
179
+ packageFilterPath = pkgfile ;
180
+ }
181
+ } ,
182
+ function ( err , actualPath ) {
183
+ st . error ( err , 'no error' ) ;
184
+ st . equal (
185
+ actualPath ,
186
+ path . join ( __dirname , 'symlinks/dest/node_modules/mod-a/index.js' ) ,
187
+ 'async: actual path is correct'
188
+ ) ;
189
+ st . equal (
190
+ packageFilterPath ,
191
+ path . join ( __dirname , 'symlinks/dest/node_modules/mod-a/package.json' ) ,
192
+ 'async: packageFilter pkgfile arg is correct'
193
+ ) ;
194
+ }
195
+ ) ;
196
+ } ) ;
197
+
198
+ t . end ( ) ;
199
+ } ) ;
0 commit comments