@beyonk/load-all
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -36,5 +36,5 @@ 'use strict' | ||
return loadFiles(dir, (curr, absolutePath) => { | ||
const exported = proxy.load(absolutePath) | ||
return { ...curr, ...modifier(exported) } | ||
const exported = require(absolutePath) | ||
return { ...curr, ...modifier(exported, curr) } | ||
}, kind, {}) | ||
} |
'use strict' | ||
const fs = require('fs') | ||
const { join, basename } = require('path') | ||
const { join } = require('path') | ||
const { fs: memfs, vol } = require('memfs') | ||
@@ -10,2 +10,4 @@ const sinon = require('sinon') | ||
const proxy = require('./require-proxy') | ||
const { patchRequire } = require('fs-monkey') | ||
const loadAll = require('.') | ||
@@ -20,3 +22,3 @@ | ||
if (usesRequire) { | ||
stub(proxy, 'load').callsFake(arg => ({ [basename(arg)]: 'loaded!' })) | ||
patchRequire(vol) | ||
} else { | ||
@@ -31,3 +33,3 @@ stub(proxy, 'load').callsFake(arg => [ `loaded ${arg}!` ]) | ||
fs.statSync.restore() | ||
proxy.load.restore() | ||
proxy.load.restore && proxy.load.restore() | ||
} | ||
@@ -117,5 +119,5 @@ | ||
root = createFilesystem({ | ||
'./dir1/index.js': '', | ||
'./dir2/index.js': '', | ||
'./dir3/index.js': '', | ||
'./dir1/index.js': 'module.exports={ dir1: "loaded!" }', | ||
'./dir2/index.js': 'module.exports={ dir2: "loaded!" }', | ||
'./dir3/index.js': 'module.exports={ dir3: "loaded!" }', | ||
}, true) | ||
@@ -140,11 +142,2 @@ }) | ||
context('with modifier', () => { | ||
let root | ||
beforeEach(() => { | ||
root = createFilesystem({ | ||
'./dir1/index.js': '', | ||
'./dir2/index.js': '', | ||
'./dir3/index.js': '', | ||
}, true) | ||
}) | ||
afterEach(() => { | ||
@@ -155,2 +148,8 @@ destroyFilesystem() | ||
it('sees dirs', () => { | ||
const root = createFilesystem({ | ||
'./dir1/index.js': 'module.exports={ dir1: "loaded!" }', | ||
'./dir2/index.js': 'module.exports={ dir2: "loaded!" }', | ||
'./dir3/index.js': 'module.exports={ dir3: "loaded!" }', | ||
}, true) | ||
expect( | ||
@@ -167,2 +166,21 @@ loadAll.exportDir(root, undefined, m => { | ||
}) | ||
it('is passed previous', () => { | ||
const root = createFilesystem({ | ||
'./dir1/index.js': 'module.exports={ dir1: "loaded!", sameKey: 1 }', | ||
'./dir2/index.js': 'module.exports={ dir2: "loaded!", sameKey: 1 }', | ||
'./dir3/index.js': 'module.exports={ dir3: "loaded!", sameKey: 1 }', | ||
}, true) | ||
expect( | ||
loadAll.exportDir(root, undefined, (m, prev) => { | ||
return { ...m, sameKey: m.sameKey + (prev.sameKey || 0) } | ||
}) | ||
).to.equal({ | ||
dir1: 'loaded!', | ||
dir2: 'loaded!', | ||
dir3: 'loaded!', | ||
sameKey: 3 | ||
}) | ||
}) | ||
}) | ||
@@ -174,5 +192,5 @@ | ||
root = createFilesystem({ | ||
'./dir1/index.js': '', | ||
'./file2.js': '', | ||
'./dir3/index.js': '', | ||
'./dir1/index.js': 'module.exports={ dir1: "loaded!" }', | ||
'./file2.js': 'module.exports={ dir2: "loaded!" }', | ||
'./dir3/index.js': 'module.exports={ dir3: "loaded!" }', | ||
}, true) | ||
@@ -179,0 +197,0 @@ }) |
{ | ||
"name": "@beyonk/load-all", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Loads all files from within a directory", | ||
@@ -34,2 +34,3 @@ "main": "index.js", | ||
"code": "^5.2.4", | ||
"fs-monkey": "^1.0.1", | ||
"memfs": "^2.14.2", | ||
@@ -36,0 +37,0 @@ "mocha": "^5.2.0", |
@@ -46,3 +46,3 @@ <p align="center"> | ||
// } | ||
`` | ||
``` | ||
@@ -49,0 +49,0 @@ ### includeDir |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24269
12
218
5
5
1