breadboard
Advanced tools
Comparing version
@@ -20,2 +20,9 @@ 'use strict'; | ||
if (!containerRoot) { | ||
return Promise.reject(new Error('Expected container root to be specified')); | ||
} | ||
if (!options.entry) { | ||
return Promise.reject(new Error('Expected application entry point to be specified')); | ||
} | ||
return Promise | ||
@@ -30,3 +37,3 @@ .all([ | ||
initialState: options.initialState, | ||
substitutes: options.substitutes | ||
substitutes: substitutes | ||
})) | ||
@@ -33,0 +40,0 @@ .catch((err) => { |
@@ -5,2 +5,3 @@ 'use strict'; | ||
const stat = require('fs').statSync; | ||
const resolvePath = require('path').resolve; | ||
const includes = require('lodash/includes'); | ||
@@ -10,3 +11,3 @@ const d = debug('breadboard:setup'); | ||
module.exports = (packageDir, blacklist, substitutes) => { | ||
const packageJsonPath = `${packageDir}/package.json`; | ||
const absolutePackageJsonPath = resolvePath(process.cwd(), `${packageDir}/package.json`); | ||
@@ -18,5 +19,4 @@ return new Promise((resolve, reject) => { | ||
try { | ||
stat(packageJsonPath); | ||
packageJsonModuleNames = Object.keys(require(packageJsonPath).dependencies); | ||
stat(absolutePackageJsonPath); | ||
packageJsonModuleNames = Object.keys(require(absolutePackageJsonPath).dependencies); | ||
d('package.json modules', Object.keys(packageJsonModules)); | ||
@@ -23,0 +23,0 @@ } |
@@ -5,24 +5,26 @@ 'use strict'; | ||
const d = debug('breadboard:setup'); | ||
const loadSanitisedNativeModules = (modules, nativeModuleName) => { | ||
const excludedNativesRegExp = /^internal\/|_|v8\//; | ||
if (!excludedNativesRegExp.test(nativeModuleName)) { | ||
Object.defineProperty(modules, nativeModuleName, { | ||
enumerable: true, | ||
get: () => { | ||
d(`Requiring ${nativeModuleName}`); | ||
return require(nativeModuleName); | ||
} | ||
}); | ||
} | ||
return modules; | ||
}; | ||
const excludeSubstitutes = (modules, substitutes) => { | ||
return modules.filter(module => !substitutes.some(substitute => substitute === module)); | ||
}; | ||
module.exports = (substitutes) => { | ||
const natives = Object.keys(process.binding('natives')); | ||
const natives = excludeSubstitutes(Object.keys(process.binding('natives')), substitutes); | ||
return new Promise((resolve) => { | ||
const nativeModules = natives.reduce((nms, nativeModuleName) => { | ||
if (substitutes.some(substituteName => substituteName === nativeModuleName)) { | ||
return nms; | ||
} | ||
if (!/^internal\/|_/.test(nativeModuleName)) { | ||
Object.defineProperty(nms, nativeModuleName, { | ||
enumerable: true, | ||
get: () => { | ||
d(`Requiring ${nativeModuleName}`); | ||
return require(nativeModuleName); | ||
} | ||
}); | ||
} | ||
return nms; | ||
}, {}); | ||
const nativeModules = natives.reduce(loadSanitisedNativeModules, {}); | ||
d('Native modules', Object.keys(nativeModules)); | ||
@@ -29,0 +31,0 @@ |
{ | ||
"name": "breadboard", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Lightweight IOC container for Node.js", | ||
"main": "index.js", | ||
"engines": { | ||
"node": "~4.4" | ||
}, | ||
"repository": "notonthehighstreet/breadboard", | ||
"scripts": { | ||
"test": "./node_modules/ava/cli.js", | ||
"test": "./node_modules/ava/cli.js --serial", | ||
"coverage": "./node_modules/.bin/nyc ./node_modules/ava/cli.js --all", | ||
@@ -34,3 +37,4 @@ "report": "npm run coverage && ./node_modules/.bin/nyc report --reporter=html", | ||
"include": [ | ||
"lib/**/*.js" | ||
"lib/**/*.js", | ||
"index.js" | ||
], | ||
@@ -37,0 +41,0 @@ "exclude": [ |
 | ||
# Breadboard | ||
[](https://codeclimate.com/repos/56e00704db68c03776006380/coverage) | ||
[](https://codeclimate.com/github/notonthehighstreet/breadboard) | ||
[](https://codeclimate.com/github/notonthehighstreet/breadboard/coverage) | ||
[](https://travis-ci.org/notonthehighstreet/breadboard) | ||
@@ -60,3 +61,3 @@ | ||
server.listen(80, () => { | ||
debug('Server listening on port 80'); | ||
d('Server listening on port 80'); | ||
}); | ||
@@ -98,2 +99,5 @@ | ||
## Prerequisites | ||
Node.js ~4.4 | ||
## API | ||
@@ -100,0 +104,0 @@ `breadboard(options)` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
34395
10.86%37
2.78%587
13.98%242
1.68%1
Infinity%