-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for #322 - require wrapper now serves only to check against depen…
…dency whitelist
- Loading branch information
Matthew Davidson
committed
Dec 20, 2016
1 parent
a61c22d
commit 952ea1a
Showing
10 changed files
with
339 additions
and
370 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,33 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var fs = require('fs-extra'); | ||
var _ = require('underscore'); | ||
var requirePackageName = require('require-package-name'); | ||
|
||
var strings = require('../../resources'); | ||
|
||
module.exports = function(injectedDependencies){ | ||
return function(moduleName){ | ||
if(!!injectedDependencies && _.has(injectedDependencies, moduleName)){ | ||
return injectedDependencies[moduleName]; | ||
} else { | ||
return function(requirePath){ | ||
var moduleName = requirePackageName(requirePath); | ||
|
||
if(!_.contains(injectedDependencies, moduleName)){ | ||
throw { | ||
code: strings.errors.registry.DEPENDENCY_NOT_FOUND_CODE, | ||
missing: [moduleName] | ||
}; | ||
}; | ||
} | ||
|
||
var nodeModulesPath = path.resolve('.', 'node_modules'); | ||
var modulePath = path.resolve(nodeModulesPath, requirePath); | ||
|
||
try { | ||
return require(modulePath); | ||
} catch (e) { | ||
throw { | ||
code: strings.errors.registry.DEPENDENCY_NOT_FOUND_CODE, | ||
missing: [modulePath] | ||
}; | ||
} | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters