@@ -156,17 +156,17 @@ export class NodeModulesBuilder implements INodeModulesBuilder {
156
156
}
157
157
158
158
public getProductionDependencies ( projectPath : string ) {
159
- var deps : any = [ ] ;
160
- var seen : any = { } ;
159
+ let deps : any = [ ] ;
160
+ let seen : any = { } ;
161
161
162
- var pJson = path . join ( projectPath , "package.json" ) ;
163
- var nodeModulesDir = path . join ( projectPath , "node_modules" ) ;
162
+ let pJson = path . join ( projectPath , "package.json" ) ;
163
+ let nodeModulesDir = path . join ( projectPath , "node_modules" ) ;
164
164
165
- var content = require ( pJson ) ;
165
+ let content = require ( pJson ) ;
166
166
167
167
Object . keys ( content . dependencies ) . forEach ( ( key ) => {
168
- var depth = 0 ;
169
- var directory = path . join ( nodeModulesDir , key ) ;
168
+ let depth = 0 ;
169
+ let directory = path . join ( nodeModulesDir , key ) ;
170
170
171
171
// find and traverse child with name `key`, parent's directory -> dep.directory
172
172
traverseChild ( key , directory , depth ) ;
@@ -176,66 +176,59 @@ export class NodeModulesBuilder implements INodeModulesBuilder {
176
176
177
177
function traverseChild ( name : string , currentModulePath : string , depth : number ) {
178
178
// check if key appears in a scoped module dependency
179
- var isScoped = name . indexOf ( '@' ) === 0 ;
179
+ let isScoped = name . indexOf ( '@' ) === 0 ;
180
180
181
181
if ( ! isScoped ) {
182
182
// Check if child has been extracted in the parent's node modules, AND THEN in `node_modules`
183
183
// Slower, but prevents copying wrong versions if multiple of the same module are installed
184
184
// Will also prevent copying project's devDependency's version if current module depends on another version
185
- var modulePath = path . join ( currentModulePath , "node_modules" , name ) ; // /node_modules/parent/node_modules/<package>
186
- var exists = ensureModuleExists ( modulePath ) ;
185
+ let modulePath = path . join ( currentModulePath , "node_modules" , name ) ; // /node_modules/parent/node_modules/<package>
186
+ let exists = ensureModuleExists ( modulePath ) ;
187
187
188
188
if ( exists ) {
189
- var dep = addDependency ( deps , name , modulePath , depth + 1 ) ;
190
-
189
+ let dep = addDependency ( deps , name , modulePath , depth + 1 ) ;
191
190
traverseModule ( modulePath , depth + 1 , dep ) ;
192
191
} else {
193
192
modulePath = path . join ( nodeModulesDir , name ) ; // /node_modules/<package>
194
193
exists = ensureModuleExists ( modulePath ) ;
195
194
196
- if ( ! exists ) {
195
+ if ( ! exists ) {
197
196
return ;
198
197
}
199
198
200
- var dep = addDependency ( deps , name , modulePath , 0 ) ;
201
-
199
+ let dep = addDependency ( deps , name , modulePath , 0 ) ;
202
200
traverseModule ( modulePath , 0 , dep ) ;
203
201
}
202
+ } else { // module is scoped
203
+ let scopeSeparatorIndex = name . indexOf ( '/' ) ;
204
+ let scope = name . substring ( 0 , scopeSeparatorIndex ) ;
205
+ let moduleName = name . substring ( scopeSeparatorIndex + 1 , name . length ) ;
206
+ let scopedModulePath = path . join ( nodeModulesDir , scope , moduleName ) ;
204
207
205
- }
206
- // module is scoped
207
- else {
208
- var scopeSeparatorIndex = name . indexOf ( '/' ) ;
209
- var scope = name . substring ( 0 , scopeSeparatorIndex ) ;
210
- var moduleName = name . substring ( scopeSeparatorIndex + 1 , name . length ) ;
211
- var scopedModulePath = path . join ( nodeModulesDir , scope , moduleName ) ;
212
-
213
- var exists = ensureModuleExists ( scopedModulePath ) ;
208
+ let exists = ensureModuleExists ( scopedModulePath ) ;
214
209
215
210
if ( exists ) {
216
- var dep = addDependency ( deps , name , scopedModulePath , 0 ) ;
211
+ let dep = addDependency ( deps , name , scopedModulePath , 0 ) ;
217
212
traverseModule ( scopedModulePath , depth , dep ) ;
218
- }
219
- else {
213
+ } else {
220
214
scopedModulePath = path . join ( currentModulePath , "node_modules" , scope , moduleName ) ;
221
-
222
215
exists = ensureModuleExists ( scopedModulePath ) ;
223
216
224
217
if ( ! exists ) {
225
218
return ;
226
219
}
227
220
228
- var dep = addDependency ( deps , name , scopedModulePath , depth + 1 ) ;
221
+ let dep = addDependency ( deps , name , scopedModulePath , depth + 1 ) ;
229
222
traverseModule ( scopedModulePath , depth + 1 , dep ) ;
230
223
}
231
224
}
232
225
233
226
function traverseModule ( modulePath : string , depth : number , currentDependency : any ) {
234
- var packageJsonPath = path . join ( modulePath , 'package.json' ) ;
235
- var packageJsonExists = fs . lstatSync ( packageJsonPath ) . isFile ( ) ;
227
+ let packageJsonPath = path . join ( modulePath , 'package.json' ) ;
228
+ let packageJsonExists = fs . lstatSync ( packageJsonPath ) . isFile ( ) ;
236
229
237
230
if ( packageJsonExists ) {
238
- var packageJsonContents = require ( packageJsonPath ) ;
231
+ let packageJsonContents = require ( packageJsonPath ) ;
239
232
240
233
if ( ! ! packageJsonContents . nativescript ) {
241
234
// add `nativescript` property, necessary for resolving plugins
@@ -244,27 +237,25 @@ export class NodeModulesBuilder implements INodeModulesBuilder {
244
237
245
238
if ( packageJsonContents . dependencies ) {
246
239
Object . keys ( packageJsonContents . dependencies ) . forEach ( ( key ) => {
247
-
248
240
traverseChild ( key , modulePath , depth ) ;
249
241
} ) ;
250
242
}
251
243
}
252
244
}
253
245
254
246
function addDependency ( deps : any [ ] , name : string , directory : string , depth : number ) {
255
- var dep : any = { } ;
247
+ let dep : any = { } ;
256
248
dep . name = name ;
257
249
dep . directory = directory ;
258
250
dep . depth = depth ;
259
-
260
251
deps . push ( dep ) ;
261
252
262
253
return dep ;
263
254
}
264
255
265
256
function ensureModuleExists ( modulePath : string ) : boolean {
266
257
try {
267
- var exists = fs . lstatSync ( modulePath ) ;
258
+ let exists = fs . lstatSync ( modulePath ) ;
268
259
return exists . isDirectory ( ) ;
269
260
} catch ( e ) {
270
261
return false ;
@@ -273,10 +264,10 @@ export class NodeModulesBuilder implements INodeModulesBuilder {
273
264
}
274
265
275
266
function filterUniqueDirectories ( dependencies : any ) {
276
- var unique : any = [ ] ;
277
- var distinct : any = [ ] ;
278
- for ( var i in dependencies ) {
279
- var dep = dependencies [ i ] ;
267
+ let unique : any = [ ] ;
268
+ let distinct : any = [ ] ;
269
+ for ( let i in dependencies ) {
270
+ let dep = dependencies [ i ] ;
280
271
if ( distinct . indexOf ( dep . directory ) > - 1 ) {
281
272
continue ;
282
273
}
0 commit comments