Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

require-tree

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

require-tree - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

test/lib/fake-env.js

25

index.js

@@ -32,11 +32,28 @@ // require-tree

var baseDir = process.env.NODE_PATH || path.dirname(module.parent.filename)
, dir = path.resolve(baseDir, directory)
var parentDir = path.dirname(module.parent.filename)
, baseDirs = [parentDir]
, forbidden = ['.json', '.node']
, filter = getFilter(options.filter) || Boolean
, tree = {}
, files = fs.readdirSync(dir)
, dir = null
, files = null
files.filter(filter).forEach(function(file){
if (process.env.NODE_PATH) {
Array.prototype.unshift.apply(baseDirs, process.env.NODE_PATH.split(';'));
}
var exists = baseDirs.some(function(baseDir){
try {
dir = path.resolve(baseDir, directory)
fs.accessSync ? fs.accessSync(dir) : fs.existsSync(dir)
return true
} catch (err) {}
})
if (exists === false) {
throw new Error('Cannot find directory ' + directory + ' in paths ' + baseDirs.join(';'))
}
fs.readdirSync(dir).filter(filter).forEach(function(file){
var ext = path.extname(file)

@@ -43,0 +60,0 @@ , name = path.basename(file, ext)

2

package.json
{
"name": "require-tree",
"description": "Batch module loader, require() for directories",
"version": "1.0.1",
"version": "1.1.0",
"main": "index.js",

@@ -6,0 +6,0 @@ "dependencies": {

@@ -121,3 +121,3 @@ require-tree

#### index
#### { index: 'merge', 'ignore', 'preserve' }

@@ -124,0 +124,0 @@ * `merge` (default): merges the `index.js` exports at the root of it's parent

var assert = require('assert')
, path = require('path')
, env = require('./lib/fake-env')
, require_tree = require('../')

@@ -69,2 +71,24 @@

describe('NODE PATH', function (){
it('should be used for lookup if present', function () {
env.set('NODE_PATH', path.join(process.cwd(), 'test/node_path'))
var hippo = require_tree('hippo')
assert.deepEqual(hippo, { hippo: 1 })
env.restore()
})
it('should accept multiple paths', function () {
env.set('NODE_PATH', [
path.join(process.cwd(), 'test/not_a_path'),
path.join(process.cwd(), 'test/node_path')
].join(';')
)
var hippo = require_tree('hippo')
assert.deepEqual(hippo, { hippo: 1 })
env.restore()
})
})
})

@@ -71,0 +95,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc