Comparing version 1.1.8 to 1.1.9
21
index.js
@@ -14,3 +14,2 @@ 'use strict'; | ||
var path = require('path'); | ||
var strip = require('strip-comments'); | ||
var _resolve = require('resolve'); | ||
@@ -39,11 +38,17 @@ | ||
} | ||
/* | ||
* 消除所有带*的字符串,保证不会因为*而破坏strip-comments | ||
* remove star and comments | ||
*/ | ||
function rm_star(str) { | ||
return str.split('\n').map(function (line) { | ||
return line.replace(/'[^']+\*[^']*'/g, "''").replace(/"[^"]+\*[^"]*"/g, '""') | ||
// .replace(/\/\*+\//, '') | ||
.replace(/\/\S*\*+\S*\/[a-z]*/g, ''); | ||
function removeStarAndComments(str) { | ||
var text = str.split('\n').map(function (line) { | ||
line = line.replace(/'[^']+\*[^']*'/g, "''").replace(/"[^"]+\*[^"]*"/g, '""') | ||
// remove line comment | ||
.replace(/^\/\/.*$/gm, '').replace(/(?:[^\\])\/\/.*$/gm, ''); | ||
return line; | ||
}).join('\n'); | ||
// remove block comment | ||
text = text.replace(/^\/\*[\S\s]*?\*\//g, '').replace(/(?:[^\\])\/\*[\S\s]*?\*\//g, ''); | ||
console.log(text); | ||
return text; | ||
} | ||
@@ -83,3 +88,3 @@ | ||
var deps = []; | ||
strip(rm_star(content)).split('\n').filter(function (line) { | ||
removeStarAndComments(content).split('\n').filter(function (line) { | ||
return line.indexOf('require') > -1 || line.indexOf('from') > -1 || line.indexOf('import') > -1; | ||
@@ -86,0 +91,0 @@ }).forEach(function (line) { |
{ | ||
"name": "es6-deps", | ||
"version": "1.1.8", | ||
"version": "1.1.9", | ||
"description": "a simple util to get es6/jsx dependencies", | ||
@@ -12,4 +12,3 @@ "main": "index.js", | ||
"isdir": "^2.0.1", | ||
"resolve": "^1.1.6", | ||
"strip-comments": "^0.3.2" | ||
"resolve": "^1.1.6" | ||
}, | ||
@@ -16,0 +15,0 @@ "devDependencies": { |
var isdir = require('isdir'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var strip = require('strip-comments'); | ||
var resolve = require('resolve'); | ||
@@ -33,16 +32,26 @@ | ||
} | ||
/* | ||
* 消除所有带*的字符串,保证不会因为*而破坏strip-comments | ||
* remove star and comments | ||
*/ | ||
function rm_star(str) { | ||
return str.split('\n') | ||
.map(line => { | ||
return line | ||
function removeStarAndComments(str) { | ||
var text = str.split('\n') | ||
.map(function (line) { | ||
line = line | ||
.replace(/'[^']+\*[^']*'/g, "''") | ||
.replace(/"[^"]+\*[^"]*"/g, '""') | ||
// .replace(/\/\*+\//, '') | ||
.replace(/\/\S*\*+\S*\/[a-z]*/g, '') | ||
// remove line comment | ||
.replace(/^\/\/.*$/gm, '') | ||
.replace(/(?:[^\\])\/\/.*$/gm, '') | ||
return line | ||
}) | ||
.join('\n'); | ||
// remove block comment | ||
text = text | ||
.replace(/^\/\*[\S\s]*?\*\//g, '') | ||
.replace(/(?:[^\\])\/\*[\S\s]*?\*\//g, '') | ||
console.log(text) | ||
return text | ||
} | ||
export default class { | ||
@@ -74,3 +83,3 @@ constructor(opt) { | ||
var deps = []; | ||
strip(rm_star(content)) | ||
removeStarAndComments(content) | ||
.split('\n') | ||
@@ -77,0 +86,0 @@ .filter(line => line.indexOf('require') > -1 || line.indexOf('from') > -1 || line.indexOf('import') > -1) |
@@ -11,5 +11,5 @@ require('babel/register'); | ||
describe('should get deps', function () { | ||
before(function() { | ||
dep.clearCache(); | ||
}); | ||
before(function() { | ||
dep.clearCache(); | ||
}); | ||
@@ -22,2 +22,12 @@ it('basic', function() { | ||
it('complex deps', function () { | ||
var data = deps(file('complex.js')); | ||
assert.ok(data.length === 4); | ||
}) | ||
it('comment deps', function () { | ||
var data = deps(file('comment.js')); | ||
assert.ok(data.length === 0); | ||
}) | ||
it('require b', function () { | ||
@@ -24,0 +34,0 @@ var data = deps(file('r-b.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
69975
3
26
365
- Removedstrip-comments@^0.3.2
- Removedstrip-comments@0.3.4(transitive)