@@ -125,7 +125,7 @@ const { Console } = require('console');
125
125
const CJSModule = require ( 'internal/modules/cjs/loader' ) . Module ;
126
126
let _builtinLibs = ArrayPrototypeFilter (
127
127
CJSModule . builtinModules ,
128
- ( e ) => ! StringPrototypeStartsWith ( e , '_' ) && ! StringPrototypeIncludes ( e , '/' )
128
+ ( e ) => ! StringPrototypeStartsWith ( e , '_' ) ,
129
129
) ;
130
130
const nodeSchemeBuiltinLibs = ArrayPrototypeMap (
131
131
_builtinLibs , ( lib ) => `node:${ lib } ` ) ;
@@ -1285,135 +1285,133 @@ function complete(line, callback) {
1285
1285
if ( completeOn . length ) {
1286
1286
filter = completeOn ;
1287
1287
}
1288
- } else if ( RegExpPrototypeTest ( requireRE , line ) &&
1289
- this . allowBlockingCompletions ) {
1288
+ } else if ( RegExpPrototypeTest ( requireRE , line ) ) {
1290
1289
// require('...<Tab>')
1291
- const extensions = ObjectKeys ( this . context . require . extensions ) ;
1292
- const indexes = ArrayPrototypeMap ( extensions ,
1293
- ( extension ) => `index${ extension } ` ) ;
1294
- ArrayPrototypePush ( indexes , 'package.json' , 'index' ) ;
1295
-
1296
1290
const match = StringPrototypeMatch ( line , requireRE ) ;
1297
1291
completeOn = match [ 1 ] ;
1298
- const subdir = match [ 2 ] || '' ;
1299
1292
filter = completeOn ;
1300
- group = [ ] ;
1301
- let paths = [ ] ;
1302
-
1303
- if ( completeOn === '.' ) {
1304
- group = [ './' , '../' ] ;
1305
- } else if ( completeOn === '..' ) {
1306
- group = [ '../' ] ;
1307
- } else if ( RegExpPrototypeTest ( / ^ \. \. ? \/ / , completeOn ) ) {
1308
- paths = [ process . cwd ( ) ] ;
1309
- } else {
1310
- paths = ArrayPrototypeConcat ( module . paths , CJSModule . globalPaths ) ;
1311
- }
1293
+ if ( this . allowBlockingCompletions ) {
1294
+ const subdir = match [ 2 ] || '' ;
1295
+ const extensions = ObjectKeys ( this . context . require . extensions ) ;
1296
+ const indexes = ArrayPrototypeMap ( extensions ,
1297
+ ( extension ) => `index${ extension } ` ) ;
1298
+ ArrayPrototypePush ( indexes , 'package.json' , 'index' ) ;
1299
+
1300
+ group = [ ] ;
1301
+ let paths = [ ] ;
1302
+
1303
+ if ( completeOn === '.' ) {
1304
+ group = [ './' , '../' ] ;
1305
+ } else if ( completeOn === '..' ) {
1306
+ group = [ '../' ] ;
1307
+ } else if ( RegExpPrototypeTest ( / ^ \. \. ? \/ / , completeOn ) ) {
1308
+ paths = [ process . cwd ( ) ] ;
1309
+ } else {
1310
+ paths = ArrayPrototypeConcat ( module . paths , CJSModule . globalPaths ) ;
1311
+ }
1312
1312
1313
- ArrayPrototypeForEach ( paths , ( dir ) => {
1314
- dir = path . resolve ( dir , subdir ) ;
1315
- const dirents = gracefulReaddir ( dir , { withFileTypes : true } ) || [ ] ;
1316
- ArrayPrototypeForEach ( dirents , ( dirent ) => {
1317
- if ( RegExpPrototypeTest ( versionedFileNamesRe , dirent . name ) ||
1318
- dirent . name === '.npm' ) {
1319
- // Exclude versioned names that 'npm' installs.
1320
- return ;
1321
- }
1322
- const extension = path . extname ( dirent . name ) ;
1323
- const base = StringPrototypeSlice ( dirent . name , 0 , - extension . length ) ;
1324
- if ( ! dirent . isDirectory ( ) ) {
1325
- if ( StringPrototypeIncludes ( extensions , extension ) &&
1326
- ( ! subdir || base !== 'index' ) ) {
1327
- ArrayPrototypePush ( group , `${ subdir } ${ base } ` ) ;
1313
+ ArrayPrototypeForEach ( paths , ( dir ) => {
1314
+ dir = path . resolve ( dir , subdir ) ;
1315
+ const dirents = gracefulReaddir ( dir , { withFileTypes : true } ) || [ ] ;
1316
+ ArrayPrototypeForEach ( dirents , ( dirent ) => {
1317
+ if ( RegExpPrototypeTest ( versionedFileNamesRe , dirent . name ) ||
1318
+ dirent . name === '.npm' ) {
1319
+ // Exclude versioned names that 'npm' installs.
1320
+ return ;
1328
1321
}
1329
- return ;
1330
- }
1331
- ArrayPrototypePush ( group , `${ subdir } ${ dirent . name } /` ) ;
1332
- const absolute = path . resolve ( dir , dirent . name ) ;
1333
- if ( ArrayPrototypeSome (
1334
- gracefulReaddir ( absolute ) || [ ] ,
1335
- ( subfile ) => ArrayPrototypeIncludes ( indexes , subfile )
1336
- ) ) {
1337
- ArrayPrototypePush ( group , `${ subdir } ${ dirent . name } ` ) ;
1338
- }
1322
+ const extension = path . extname ( dirent . name ) ;
1323
+ const base = StringPrototypeSlice ( dirent . name , 0 , - extension . length ) ;
1324
+ if ( ! dirent . isDirectory ( ) ) {
1325
+ if ( StringPrototypeIncludes ( extensions , extension ) &&
1326
+ ( ! subdir || base !== 'index' ) ) {
1327
+ ArrayPrototypePush ( group , `${ subdir } ${ base } ` ) ;
1328
+ }
1329
+ return ;
1330
+ }
1331
+ ArrayPrototypePush ( group , `${ subdir } ${ dirent . name } /` ) ;
1332
+ const absolute = path . resolve ( dir , dirent . name ) ;
1333
+ if ( ArrayPrototypeSome (
1334
+ gracefulReaddir ( absolute ) || [ ] ,
1335
+ ( subfile ) => ArrayPrototypeIncludes ( indexes , subfile )
1336
+ ) ) {
1337
+ ArrayPrototypePush ( group , `${ subdir } ${ dirent . name } ` ) ;
1338
+ }
1339
+ } ) ;
1339
1340
} ) ;
1340
- } ) ;
1341
- if ( group . length ) {
1342
- ArrayPrototypePush ( completionGroups , group ) ;
1341
+ if ( group . length ) {
1342
+ ArrayPrototypePush ( completionGroups , group ) ;
1343
+ }
1343
1344
}
1344
1345
1345
- if ( ! subdir ) {
1346
- ArrayPrototypePush ( completionGroups , _builtinLibs , nodeSchemeBuiltinLibs ) ;
1347
- }
1348
- } else if ( RegExpPrototypeTest ( importRE , line ) &&
1349
- this . allowBlockingCompletions ) {
1346
+ ArrayPrototypePush ( completionGroups , _builtinLibs , nodeSchemeBuiltinLibs ) ;
1347
+ } else if ( RegExpPrototypeTest ( importRE , line ) ) {
1350
1348
// import('...<Tab>')
1351
- // File extensions that can be imported:
1352
- const extensions = ObjectKeys (
1353
- getOptionValue ( '--experimental-specifier-resolution' ) === 'node' ?
1354
- legacyExtensionFormatMap :
1355
- extensionFormatMap ) ;
1356
-
1357
- // Only used when loading bare module specifiers from `node_modules`:
1358
- const indexes = ArrayPrototypeMap ( extensions , ( ext ) => `index${ ext } ` ) ;
1359
- ArrayPrototypePush ( indexes , 'package.json' ) ;
1360
-
1361
1349
const match = StringPrototypeMatch ( line , importRE ) ;
1362
1350
completeOn = match [ 1 ] ;
1363
- const subdir = match [ 2 ] || '' ;
1364
1351
filter = completeOn ;
1365
- group = [ ] ;
1366
- let paths = [ ] ;
1367
- if ( completeOn === '.' ) {
1368
- group = [ './' , '../' ] ;
1369
- } else if ( completeOn === '..' ) {
1370
- group = [ '../' ] ;
1371
- } else if ( RegExpPrototypeTest ( / ^ \. \. ? \/ / , completeOn ) ) {
1372
- paths = [ process . cwd ( ) ] ;
1373
- } else {
1374
- paths = ArrayPrototypeSlice ( module . paths ) ;
1375
- }
1352
+ if ( this . allowBlockingCompletions ) {
1353
+ const subdir = match [ 2 ] || '' ;
1354
+ // File extensions that can be imported:
1355
+ const extensions = ObjectKeys (
1356
+ getOptionValue ( '--experimental-specifier-resolution' ) === 'node' ?
1357
+ legacyExtensionFormatMap :
1358
+ extensionFormatMap ) ;
1359
+
1360
+ // Only used when loading bare module specifiers from `node_modules`:
1361
+ const indexes = ArrayPrototypeMap ( extensions , ( ext ) => `index${ ext } ` ) ;
1362
+ ArrayPrototypePush ( indexes , 'package.json' ) ;
1363
+
1364
+ group = [ ] ;
1365
+ let paths = [ ] ;
1366
+ if ( completeOn === '.' ) {
1367
+ group = [ './' , '../' ] ;
1368
+ } else if ( completeOn === '..' ) {
1369
+ group = [ '../' ] ;
1370
+ } else if ( RegExpPrototypeTest ( / ^ \. \. ? \/ / , completeOn ) ) {
1371
+ paths = [ process . cwd ( ) ] ;
1372
+ } else {
1373
+ paths = ArrayPrototypeSlice ( module . paths ) ;
1374
+ }
1376
1375
1377
- ArrayPrototypeForEach ( paths , ( dir ) => {
1378
- dir = path . resolve ( dir , subdir ) ;
1379
- const isInNodeModules = path . basename ( dir ) === 'node_modules' ;
1380
- const dirents = gracefulReaddir ( dir , { withFileTypes : true } ) || [ ] ;
1381
- ArrayPrototypeForEach ( dirents , ( dirent ) => {
1382
- const { name } = dirent ;
1383
- if ( RegExpPrototypeTest ( versionedFileNamesRe , name ) ||
1384
- name === '.npm' ) {
1385
- // Exclude versioned names that 'npm' installs.
1386
- return ;
1387
- }
1376
+ ArrayPrototypeForEach ( paths , ( dir ) => {
1377
+ dir = path . resolve ( dir , subdir ) ;
1378
+ const isInNodeModules = path . basename ( dir ) === 'node_modules' ;
1379
+ const dirents = gracefulReaddir ( dir , { withFileTypes : true } ) || [ ] ;
1380
+ ArrayPrototypeForEach ( dirents , ( dirent ) => {
1381
+ const { name } = dirent ;
1382
+ if ( RegExpPrototypeTest ( versionedFileNamesRe , name ) ||
1383
+ name === '.npm' ) {
1384
+ // Exclude versioned names that 'npm' installs.
1385
+ return ;
1386
+ }
1388
1387
1389
- if ( ! dirent . isDirectory ( ) ) {
1390
- const extension = path . extname ( name ) ;
1391
- if ( StringPrototypeIncludes ( extensions , extension ) ) {
1392
- ArrayPrototypePush ( group , `${ subdir } ${ name } ` ) ;
1388
+ if ( ! dirent . isDirectory ( ) ) {
1389
+ const extension = path . extname ( name ) ;
1390
+ if ( StringPrototypeIncludes ( extensions , extension ) ) {
1391
+ ArrayPrototypePush ( group , `${ subdir } ${ name } ` ) ;
1392
+ }
1393
+ return ;
1393
1394
}
1394
- return ;
1395
- }
1396
1395
1397
- ArrayPrototypePush ( group , `${ subdir } ${ name } /` ) ;
1398
- if ( ! subdir && isInNodeModules ) {
1399
- const absolute = path . resolve ( dir , name ) ;
1400
- const subfiles = gracefulReaddir ( absolute ) || [ ] ;
1401
- if ( ArrayPrototypeSome ( subfiles , ( subfile ) => {
1402
- return ArrayPrototypeIncludes ( indexes , subfile ) ;
1403
- } ) ) {
1404
- ArrayPrototypePush ( group , `${ subdir } ${ name } ` ) ;
1396
+ ArrayPrototypePush ( group , `${ subdir } ${ name } /` ) ;
1397
+ if ( ! subdir && isInNodeModules ) {
1398
+ const absolute = path . resolve ( dir , name ) ;
1399
+ const subfiles = gracefulReaddir ( absolute ) || [ ] ;
1400
+ if ( ArrayPrototypeSome ( subfiles , ( subfile ) => {
1401
+ return ArrayPrototypeIncludes ( indexes , subfile ) ;
1402
+ } ) ) {
1403
+ ArrayPrototypePush ( group , `${ subdir } ${ name } ` ) ;
1404
+ }
1405
1405
}
1406
- }
1406
+ } ) ;
1407
1407
} ) ;
1408
- } ) ;
1409
1408
1410
- if ( group . length ) {
1411
- ArrayPrototypePush ( completionGroups , group ) ;
1409
+ if ( group . length ) {
1410
+ ArrayPrototypePush ( completionGroups , group ) ;
1411
+ }
1412
1412
}
1413
1413
1414
- if ( ! subdir ) {
1415
- ArrayPrototypePush ( completionGroups , _builtinLibs , nodeSchemeBuiltinLibs ) ;
1416
- }
1414
+ ArrayPrototypePush ( completionGroups , _builtinLibs , nodeSchemeBuiltinLibs ) ;
1417
1415
} else if ( RegExpPrototypeTest ( fsAutoCompleteRE , line ) &&
1418
1416
this . allowBlockingCompletions ) {
1419
1417
( { 0 : completionGroups , 1 : completeOn } = completeFSFunctions ( line ) ) ;
0 commit comments