Skip to content

Commit

Permalink
require graceful-fs as a regular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
manidlou committed Aug 6, 2017
1 parent 6cb227b commit a58c042
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 37 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ sudo: false
language: node_js
node_js:
- '4'
- '5'
- '6'
- '7'
- '8'
script:
- npm test
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
------------------

Expand Down
2 changes: 0 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
49 changes: 22 additions & 27 deletions klaw-sync.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down

0 comments on commit a58c042

Please sign in to comment.