diff --git a/.travis.yml b/.travis.yml index d9e77a9..d6af21b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,7 @@ sudo: false language: node_js node_js: - '4' - - '5' - '6' - - '7' + - '8' script: - npm test diff --git a/CHANGELOG.md b/CHANGELOG.md index 87986e6..c6b3bcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +3.0.0 / 2017-08-06 +------------------ + +### Changed +- `graceful-fs` is now a regular dependency, and is always loaded. This should speed up `require` time. + 2.1.0 / 2017-04-25 ------------------ diff --git a/appveyor.yml b/appveyor.yml index 8e30f28..8aeb13b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,9 +3,7 @@ environment: matrix: # node.js - nodejs_version: "4" - - nodejs_version: "5" - nodejs_version: "6" - - nodejs_version: "7" # Install scripts. (runs after repo cloning) install: diff --git a/klaw-sync.js b/klaw-sync.js index 12fbecb..d66c3da 100644 --- a/klaw-sync.js +++ b/klaw-sync.js @@ -1,27 +1,36 @@ 'use strict' +const fs = require('graceful-fs') const path = require('path') -let fs -try { - fs = require('graceful-fs') -} catch (e) { - fs = require('fs') -} function klawSync (dir, opts, ls) { - function procPath (pathItem) { - const stat = fs.lstatSync(pathItem) - const item = {path: pathItem, stats: stat} - if (stat.isDirectory()) { + opts = opts || {} + ls = ls || [] + dir = path.resolve(dir) + const files = fs.readdirSync(dir) + for (let i = 0; i < files.length; i += 1) { + // here dir already resolved, we use string concatenation since + // showed better performance than path.join() and path.resolve() + let pathItem + if (path.sep === '/') pathItem = dir + '/' + files[i] + else pathItem = dir + '\\' + files[i] + procPath(pathItem) + } + return ls + + function procPath (pi) { + const st = fs.lstatSync(pi) + const item = {path: pi, stats: st} + if (st.isDirectory()) { if (opts.filter) { if (opts.filter(item) && !opts.nodir) { ls.push(item) - ls = klawSync(pathItem, opts, ls) + ls = klawSync(pi, opts, ls) } else { - if (!opts.noRecurseOnFailedFilter) ls = klawSync(pathItem, opts, ls) + if (!opts.noRecurseOnFailedFilter) ls = klawSync(pi, opts, ls) } } else { if (!opts.nodir) ls.push(item) - ls = klawSync(pathItem, opts, ls) + ls = klawSync(pi, opts, ls) } } else { if (opts.filter) { @@ -31,20 +40,6 @@ function klawSync (dir, opts, ls) { } } } - - opts = opts || {} - ls = ls || [] - dir = path.resolve(dir) - const files = fs.readdirSync(dir) - for (let i = 0; i < files.length; i += 1) { - // here dir already resolved, we use string concatenation since - // showed better performance than path.join() and path.resolve() - let pathItem - if (path.sep === '/') pathItem = dir + '/' + files[i] - else pathItem = dir + '\\' + files[i] - procPath(pathItem) - } - return ls } module.exports = klawSync diff --git a/package.json b/package.json index 4c7532b..ea170ca 100644 --- a/package.json +++ b/package.json @@ -21,17 +21,17 @@ "url": "https://github.com/manidlou/node-klaw-sync/issues" }, "homepage": "https://github.com/manidlou/node-klaw-sync#readme", + "dependencies": { + "graceful-fs": "^4.1.11" + }, "devDependencies": { "benchmark": "^2.1.4", "fs-extra": "^1.0.0", - "glob": "^7.1.1", + "glob": "^7.1.2", "minimist": "^1.2.0", - "mocha": "^3.2.0", + "mocha": "^3.5.0", "standard": "^8.6.0", - "walk-sync": "^0.3.1" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.11" + "walk-sync": "^0.3.2" }, "standard": { "env": [