Comparing version 0.1.5 to 0.1.6
@@ -15,3 +15,3 @@ | ||
var resolve = require('path').resolve; | ||
var existsSync = require('path').existsSync; | ||
var existsSync = require('fs').existsSync || require('path').existsSync; | ||
var realpathSync = require('fs').realpathSync; | ||
@@ -40,5 +40,3 @@ var packagePathCache = {}; | ||
if (plugin.hasOwnProperty("packagePath") && !plugin.hasOwnProperty("setup")) { | ||
plugin.packagePath = resolvePackageSync(base, plugin.packagePath); | ||
var packageConf = require(plugin.packagePath); | ||
var defaults = packageConf.plugin || {}; | ||
var defaults = resolveModule(base, plugin.packagePath); | ||
Object.keys(defaults).forEach(function (key) { | ||
@@ -49,6 +47,5 @@ if (!plugin.hasOwnProperty(key)) { | ||
}); | ||
plugin.setup = require(dirname(plugin.packagePath)); | ||
plugin.packagePath = defaults.packagePath; | ||
plugin.setup = require(plugin.packagePath); | ||
} | ||
plugin.consumes = plugin.consumes || []; | ||
plugin.provides = plugin.provides || []; | ||
}); | ||
@@ -58,2 +55,25 @@ return config; | ||
// Loads a module, getting metadata from either it's package.json or export | ||
// object. | ||
function resolveModule(base, modulePath) { | ||
var packagePath; | ||
try { | ||
packagePath = resolvePackageSync(base, modulePath + "/package.json"); | ||
} | ||
catch (err) { | ||
if (err.code !== "ENOENT") throw err; | ||
} | ||
var metadata = packagePath && require(packagePath).plugin || {}; | ||
if (packagePath) { | ||
modulePath = dirname(packagePath); | ||
} else { | ||
modulePath = resolvePackageSync(base, modulePath); | ||
} | ||
var module = require(modulePath); | ||
metadata.provides = metadata.provides || module.provides || []; | ||
metadata.consumes = metadata.consumes || module.consumes || []; | ||
metadata.packagePath = modulePath; | ||
return metadata; | ||
} | ||
// Node style package resolving so that plugins' package.json can be found relative to the config file | ||
@@ -64,7 +84,7 @@ // It's not the full node require system algorithm, but it's the 99% case | ||
var originalBase = base; | ||
if (!packagePathCache.hasOwnProperty(base)) { | ||
if (!(base in packagePathCache)) { | ||
packagePathCache[base] = {}; | ||
} | ||
var cache = packagePathCache[base]; | ||
if (cache.hasOwnProperty(packagePath)) { | ||
if (packagePath in cache) { | ||
return cache[packagePath]; | ||
@@ -74,3 +94,3 @@ } | ||
if (packagePath[0] === "." || packagePath[0] === "/") { | ||
newPath = resolve(base, packagePath, "package.json"); | ||
newPath = resolve(base, packagePath); | ||
if (existsSync(newPath)) { | ||
@@ -84,3 +104,3 @@ newPath = realpathSync(newPath); | ||
while (base) { | ||
newPath = resolve(base, "node_modules", packagePath, "package.json"); | ||
newPath = resolve(base, "node_modules", packagePath); | ||
if (existsSync(newPath)) { | ||
@@ -87,0 +107,0 @@ newPath = realpathSync(newPath); |
{ | ||
"name": "architect", | ||
"description": "A Simple yet powerful plugin system for node applications", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"author": "ajax.org B.V. <info@ajax.org>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
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
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
294
0
16734
5
8