resolve-dependency-path
Advanced tools
Comparing version 3.0.0 to 3.0.1
34
index.js
@@ -12,9 +12,9 @@ 'use strict'; | ||
*/ | ||
module.exports = function({ dependency: dep, filename, directory } = {}) { | ||
if (!dep) throw new Error('dependency path not given'); | ||
module.exports = function({ dependency, filename, directory } = {}) { | ||
if (!dependency) throw new Error('dependency path not given'); | ||
if (!filename) throw new Error('filename not given'); | ||
if (!directory) throw new Error('directory not given'); | ||
const filepath = getDependencyPath(dep, filename, directory); | ||
const ext = getDependencyExtension(dep, filename); | ||
const filepath = getDependencyPath(dependency, filename, directory); | ||
const ext = getDependencyExtension(dependency, filename); | ||
@@ -25,11 +25,3 @@ return filepath + ext; | ||
/** | ||
* @param {String} dep | ||
* @return {Boolean} | ||
*/ | ||
function isRelative(dep) { | ||
return dep.indexOf('..') === 0 || dep.indexOf('.') === 0; | ||
} | ||
/** | ||
* @param {String} dep | ||
* @param {String} dependency | ||
* @param {String} filename | ||
@@ -39,17 +31,17 @@ * @param {String} directory | ||
*/ | ||
function getDependencyPath(dep, filename, directory) { | ||
if (isRelative(dep)) { | ||
return path.resolve(path.dirname(filename), dep); | ||
function getDependencyPath(dependency, filename, directory) { | ||
if (dependency.indexOf('..') === 0 || dependency.indexOf('.') === 0) { | ||
return path.resolve(path.dirname(filename), dependency); | ||
} | ||
return path.resolve(directory, dep); | ||
return path.resolve(directory, dependency); | ||
} | ||
/** | ||
* @param {String} dep | ||
* @param {String} dependency | ||
* @param {String} filename | ||
* @return {String} The determined extension for the dependency (or empty if already supplied) | ||
*/ | ||
function getDependencyExtension(dep, filename) { | ||
const depExt = path.extname(dep); | ||
function getDependencyExtension(dependency, filename) { | ||
const depExt = path.extname(dependency); | ||
const fileExt = path.extname(filename); | ||
@@ -63,3 +55,3 @@ | ||
// in .js AND doesn't use a custom plugin, add .js back to path | ||
if (fileExt === '.js' && depExt !== '.js' && !dep.includes('!')) { | ||
if (fileExt === '.js' && depExt !== '.js' && !dependency.includes('!')) { | ||
return fileExt; | ||
@@ -66,0 +58,0 @@ } |
{ | ||
"name": "resolve-dependency-path", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Convert a dependency path into a filepath", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
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
0
6871
51