Comparing version 1.0.4 to 1.0.5
36
index.js
@@ -22,2 +22,12 @@ 'use strict'; | ||
function suffix_path(p) { | ||
var pt; | ||
var _arr = ['', '.js', '.jsx', '.es6']; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var suffix = _arr[_i]; | ||
var pt = p + suffix; | ||
if (fs.existsSync(pt)) return pt; | ||
} | ||
} | ||
function _resolve(current, relpath) { | ||
@@ -32,15 +42,16 @@ var dirname = path.dirname(current); | ||
var p = parts.join('/'); | ||
if (fs.existsSync(path.join(p, 'node_modules'))) { | ||
nmdir = path.join(p, 'node_modules'); | ||
break; | ||
var temp = suffix_path(path.join(p, 'node_modules', relpath)); | ||
if (temp) { | ||
if (!isdir(temp)) return temp;else { | ||
nmdir = temp; | ||
break; | ||
} | ||
} | ||
parts.pop(); | ||
} | ||
if (!nmdir) throw new Error('cannot find node_modules from ', current, ' when requiring ', relpath); | ||
var file = path.join(nmdir, relpath); | ||
if (!isdir(file)) return file; | ||
var pkg = require(path.join(file, 'package.json')); | ||
if (!nmdir) throw new Error('cannot parse ' + relpath + ' when processing ' + current); | ||
var pkg = require(path.join(nmdir, 'package.json')); | ||
var main = pkg.main || "index"; | ||
return path.join(file, main); | ||
return path.join(nmdir, main); | ||
} | ||
@@ -50,9 +61,4 @@ | ||
var p = _resolve(current, filepath); | ||
var pt; | ||
var _arr = ['', '.js', '.jsx', '.es6']; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var suffix = _arr[_i]; | ||
var pt = p + suffix; | ||
if (fs.existsSync(pt)) return pt; | ||
} | ||
var pt = suffix_path(p); | ||
if (pt) return pt; | ||
throw new Error(p + " not exist when processing " + current + " and requiring " + filepath); | ||
@@ -59,0 +65,0 @@ } |
{ | ||
"name": "es6-deps", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "a simple util to get es6/jsx dependencies", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,2 +17,10 @@ var isdir = require('isdir'); | ||
function suffix_path(p) { | ||
var pt; | ||
for (let suffix of ['', '.js', '.jsx', '.es6']) { | ||
var pt = p + suffix; | ||
if (fs.existsSync(pt)) return pt; | ||
} | ||
} | ||
function _resolve(current, relpath) { | ||
@@ -27,15 +35,17 @@ var dirname = path.dirname(current); | ||
var p = parts.join('/'); | ||
if (fs.existsSync(path.join(p, 'node_modules'))) { | ||
nmdir = path.join(p, 'node_modules'); | ||
break; | ||
var temp = suffix_path(path.join(p, 'node_modules', relpath)); | ||
if (temp) { | ||
if (!isdir(temp)) return temp; | ||
else { | ||
nmdir = temp; | ||
break; | ||
} | ||
} | ||
parts.pop(); | ||
} | ||
if (!nmdir) throw new Error('cannot find node_modules from ', current, ' when requiring ', relpath); | ||
var file = path.join(nmdir, relpath); | ||
if (!isdir(file)) return file; | ||
var pkg = require(path.join(file, 'package.json')); | ||
if (!nmdir) throw new Error('cannot parse ' + relpath + ' when processing ' + current); | ||
var pkg = require(path.join(nmdir, 'package.json')); | ||
var main = pkg.main || "index"; | ||
return path.join(file, main); | ||
return path.join(nmdir, main); | ||
} | ||
@@ -45,7 +55,4 @@ | ||
var p = _resolve(current, filepath); | ||
var pt; | ||
for (let suffix of ['', '.js', '.jsx', '.es6']) { | ||
var pt = p + suffix; | ||
if (fs.existsSync(pt)) return pt; | ||
} | ||
var pt = suffix_path(p); | ||
if (pt) return pt; | ||
throw new Error(p + " not exist when processing " + current + " and requiring " + filepath); | ||
@@ -52,0 +59,0 @@ } |
require('babel/register'); | ||
var assert = require('assert'); | ||
var Dep = require('../'); | ||
var Dep = require('../src'); | ||
var file = function (name) { | ||
@@ -5,0 +5,0 @@ return __dirname + "/files/" + name; |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
11253
256