module-definition
Advanced tools
Comparing version 2.2.1 to 2.2.2
@@ -5,5 +5,5 @@ #!/usr/bin/env node | ||
var getModuleType = require('../'), | ||
filename = process.argv[2]; | ||
var getModuleType = require('../'); | ||
var filename = process.argv[2]; | ||
console.log(getModuleType.sync(filename)); |
43
index.js
@@ -1,4 +0,4 @@ | ||
var Walker = require('node-source-walk'), | ||
types = require('ast-module-types'), | ||
fs = require('fs'); | ||
var Walker = require('node-source-walk'); | ||
var types = require('ast-module-types'); | ||
var fs = require('fs'); | ||
@@ -12,14 +12,16 @@ /** | ||
function fromSource(source) { | ||
if (typeof source === 'undefined') throw new Error('source not supplied'); | ||
if (typeof source === 'undefined') { | ||
throw new Error('source not supplied'); | ||
} | ||
var walker = new Walker({ | ||
ecmaVersion: 6 | ||
}), | ||
hasDefine = false, | ||
hasAMDTopLevelRequire = false, | ||
hasRequire = false, | ||
hasExports = false, | ||
hasES6Import = false, | ||
hasES6Export = false, | ||
isAMD, isCommonJS, isES6; | ||
var walker = new Walker(); | ||
var hasDefine = false; | ||
var hasAMDTopLevelRequire = false; | ||
var hasRequire = false; | ||
var hasExports = false; | ||
var hasES6Import = false; | ||
var hasES6Export = false; | ||
var isAMD; | ||
var isCommonJS; | ||
var isES6; | ||
@@ -57,4 +59,3 @@ // Walker accepts as AST to avoid reparsing | ||
// ES6 features are so unique that we can | ||
// eagerly exit. (#19) | ||
// ES6 features are so unique that we can eagerly exit. (#19) | ||
if (isES6) { | ||
@@ -82,5 +83,7 @@ return 'es6'; | ||
function sync(file) { | ||
if (!file) throw new Error('filename missing'); | ||
if (!file) { | ||
throw new Error('filename missing'); | ||
} | ||
var data = fs.readFileSync(file); | ||
var data = fs.readFileSync(file, 'utf8'); | ||
return fromSource(data.toString()); | ||
@@ -104,3 +107,5 @@ } | ||
fs.readFile(filepath, { encoding: 'utf8' }, function(err, data) { | ||
var opts = {encoding: 'utf8'}; | ||
fs.readFile(filepath, opts, function(err, data) { | ||
if (err) { | ||
@@ -107,0 +112,0 @@ return cb(err); |
{ | ||
"name": "module-definition", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "Determines if a file is using a CommonJS or AMD module definition", | ||
@@ -10,3 +10,3 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "jscs test/test.js index.js bin/module-definition.js -p airbnb && mocha test/test.js" | ||
"test": "jscs test/test.js index.js bin/module-definition.js -p google && mocha test/test.js" | ||
}, | ||
@@ -21,9 +21,9 @@ "repository": { | ||
"dependencies": { | ||
"ast-module-types": "~2.2.2", | ||
"node-source-walk": "~1.4.0" | ||
"ast-module-types": "^2.3.0", | ||
"node-source-walk": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"jscs": "~1.7.3", | ||
"jscs": "~1.13.1", | ||
"mocha": "~2.0.1" | ||
} | ||
} |
@@ -1,6 +0,6 @@ | ||
var getModuleType = require('../'), | ||
path = require('path'), | ||
fs = require('fs'), | ||
assert = require('assert'), | ||
amdAST = require('./amdAST'); | ||
var getModuleType = require('../'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var assert = require('assert'); | ||
var amdAST = require('./amdAST'); | ||
@@ -48,4 +48,5 @@ describe('module-definition', function() { | ||
it('should return `' + result + '` as type of ' + filename, function() { | ||
var source = fs.readFileSync(path.resolve(__dirname, filename), 'utf8'), | ||
type = getModuleType.fromSource(source); | ||
var source = fs.readFileSync(path.resolve(__dirname, filename), 'utf8'); | ||
var type = getModuleType.fromSource(source); | ||
assert.equal(type, result); | ||
@@ -52,0 +53,0 @@ }); |
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
9112
264
+ Addedacorn@2.7.0(transitive)
+ Addedacorn-jsx@2.0.1(transitive)
+ Addedast-module-types@2.7.1(transitive)
+ Addednode-source-walk@2.1.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
- Removedacorn@1.2.2(transitive)
- Removedast-module-types@2.2.2(transitive)
- Removednode-source-walk@1.4.2(transitive)
Updatedast-module-types@^2.3.0
Updatednode-source-walk@^2.0.0