0

I'm using the shelljs npm package for file traversal:

var shell = require('shelljs');
cFilesOnly = function (file, idx) { return (file.includes('.c')); }
excludeIrrelevantDir = function (file, idx) { return !file.includes('DDD'); }
var files = shell.find('.').filter(cFilesOnly).filter(excludeIrrelevantDir);
console.log(files);

The package works great:

$ tree
.
├── AAA
│   └── main.c
├── BBB
│   ├── README.md
│   ├── go.c
│   └── run.c
├── DDD
│   └── bad.c
└── main.js

4 directories, 6 files
$ node main.js
[ 'AAA/main.c', 'BBB/go.c', 'BBB/run.c' ]
  • npm reported 1 high severity vulnerability in that package, so
  • I want to replace that package with a native node os alternative.
  • I looked (here) but didn't get very far - what am I missing?
OrenIshShalom
  • 5,974
  • 9
  • 37
  • 87
  • https://nodejs.org/docs/latest-v18.x/api/fs.html readDir, stat – Cody G May 15 '23 at 05:19
  • 1
    However, I will tell you that `node.js` in my experience has been slower than using `execFile` to run powershell or linux commands for the same thing. I'd run your own tests if you're working with more than ~100 nested directories (e.g. making a drive scan) – Cody G May 15 '23 at 05:21
  • @CodyG it seems the `readdir` is *not* recursive, so unless I'm missing something (?) this os needs to be wrapped and managed – OrenIshShalom May 15 '23 at 07:18
  • 1
    Yes, I mean... if you want native there is quite a bit of work to do. Perhaps a different package meets your need? https://www.npmjs.com/package/glob – Cody G May 15 '23 at 16:24

0 Answers0