-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
173 additions
and
14 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
var fs = require('fs'), | ||
path = require('path'), | ||
util = require('util'), | ||
detective = require('detective-es6'), | ||
colors = require('colors'), | ||
Base = require('./base'); | ||
|
||
/** | ||
* This class will parse the ES6 module format. | ||
* @see http://nodejs.org/api/modules.html | ||
* @constructor | ||
*/ | ||
var ES6 = module.exports = function () { | ||
Base.apply(this, arguments); | ||
}; | ||
|
||
/** | ||
* Inherit from `Base`. | ||
*/ | ||
util.inherits(ES6, Base); | ||
|
||
/** | ||
* Parse the given file and return all found dependencies. | ||
* @param {String} filename | ||
* @return {Array} | ||
*/ | ||
ES6.prototype.parseFile = function (filename) { | ||
try { | ||
if (fs.existsSync(filename)) { | ||
var dependencies = [], | ||
src = this.getFileSource(filename); | ||
|
||
var fileData = {filename: filename, src: src}; | ||
this.emit('parseFile', fileData); | ||
|
||
if (/import.*from/m.test(fileData.src)) { | ||
detective(fileData.src).map(function (id) { | ||
var depFilename = this.resolve(path.dirname(fileData.filename), id); | ||
if (depFilename) { | ||
return this.normalize(depFilename); | ||
} | ||
}, this).filter(function (id) { | ||
if (!this.isExcluded(id) && dependencies.indexOf(id) < 0) { | ||
dependencies.push(id); | ||
} | ||
}, this); | ||
|
||
return dependencies; | ||
} | ||
} | ||
} catch (e) { | ||
if (this.opts.breakOnError) { | ||
console.log(String('\nError while parsing file: ' + filename).red); | ||
throw e; | ||
} | ||
} | ||
|
||
return []; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
var should = require('should'), | ||
madge = require('../lib/madge'); | ||
|
||
describe('module format (ES6)', function () { | ||
|
||
it('should behave as expected on ok files', function () { | ||
madge([__dirname + '/files/es6/normal'], { | ||
format: 'es6' | ||
}).obj().should.eql({ 'a': [ 'sub/b' ], 'fancy-main/not-index': [], 'd': [], 'sub/b': [ 'sub/c' ], 'sub/c': [ 'd' ] }); | ||
}); | ||
|
||
it('should tackle errors in files', function () { | ||
madge([__dirname + '/files/es6/error.js'], { | ||
format: 'es6' | ||
}).obj().should.eql({ 'error': [] }); | ||
}); | ||
|
||
it('should be able to exclude modules', function () { | ||
madge([__dirname + '/files/es6/normal'], { | ||
exclude: '^sub', | ||
format: 'es6' | ||
}).obj().should.eql({ 'a': [], 'd': [], 'fancy-main/not-index': [] }); | ||
|
||
madge([__dirname + '/files/es6/normal'], { | ||
exclude: '.*\/c$', | ||
format: 'es6' | ||
}).obj().should.eql({ 'a': [ 'sub/b' ], 'd': [], 'sub/b': [], 'fancy-main/not-index': [], }); | ||
}); | ||
|
||
it('should find circular dependencies', function () { | ||
madge([__dirname + '/files/es6/circular'], { | ||
format: 'es6' | ||
}).circular().getArray().should.eql([ ['a', 'b', 'c'] ]); | ||
}); | ||
|
||
it('should find absolute imports from the root', function () { | ||
madge([__dirname + '/files/es6/absolute.js', __dirname + '/files/es6/absolute'], { | ||
format: 'es6' | ||
}).obj().should.eql({ 'absolute': [ 'absolute/a' ], 'absolute/a': [ 'absolute/b' ], 'absolute/b': [] }); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var b = require('./b'); | ||
|
||
module.exports = 'A'; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = 'B'; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
import {A} from 'test/files/es6/absolute/a'; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {B} from 'test/files/es6/absolute/b'; | ||
|
||
export const A = 'A'; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export const B = 'B'; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
import * as B from './b'; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
import * as C from './c'; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
import * as A from './a'; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
if (x) { | ||
return; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {B} from './sub/b'; | ||
|
||
export const A = 'A'; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export const D = 'D'; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export constant Dt = new Date(); |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"main": "not-index.js" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {C} from './c'; | ||
|
||
export const B = 'B'; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {D} from '../d'; | ||
|
||
export const C = 'C'; |
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
d5b0b60
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No support for
export * from 'path'
, which we need to use this for Angulard5b0b60
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please create an issue at https://github.com/mrjoelkemp/node-detective-es6 @alexeagle ?