Skip to content

Commit b672b8c

Browse files
committed
Stable
1 parent 52808ba commit b672b8c

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

Readme.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Determines the module definition type (CommonJS, AMD, or none) for a given JavaScript file
2+
by walking through the AST.
3+
4+
`npm install module-definition`
5+
6+
### Usage
7+
8+
```javascript
9+
var getModuleType = require('module-definition');
10+
11+
getModuleType('myscript.js', function (type) {
12+
console.log(type);
13+
});
14+
```
15+
16+
Passes one of the following strings to the given callback:
17+
18+
* amd
19+
* commonjs
20+
* none

index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var esprima = require('esprima'),
2-
q = require('q'),
32
fs = require('fs');
43

54
// From node-detective
@@ -48,9 +47,7 @@ function isDefine(node) {
4847
c.name === 'define';
4948
}
5049

51-
module.exports = function (file) {
52-
var deferred = q.defer();
53-
50+
module.exports = function (file, cb) {
5451
if (! file) throw new Error('filename missing');
5552

5653
// Read file
@@ -83,8 +80,6 @@ module.exports = function (file) {
8380
}
8481
});
8582

86-
deferred.resolve(type);
83+
cb(type);
8784
});
88-
89-
return deferred.promise;
9085
};

package.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
{
2-
"name": "node-detect-module-format",
3-
"version": "0.0.0",
4-
"description": "Determines if a file is using the CommonJS or AMD module formats",
2+
"name": "module-definition",
3+
"version": "1.0.0",
4+
"description": "Determines if a file is using a CommonJS or AMD module definition",
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},
99
"repository": {
1010
"type": "git",
11-
"url": "https://github.com/mrjoelkemp/node-detect-module-format"
11+
"url": "https://github.com/mrjoelkemp/module-definition"
1212
},
1313
"author": "Joel Kemp <joel@mrjoelkemp.com> (http://www.mrjoelkemp.com/)",
1414
"license": "MIT",
15-
"bugs": {
16-
"url": "https://github.com/mrjoelkemp/node-detect-module-format/issues"
17-
},
18-
"homepage": "https://github.com/mrjoelkemp/node-detect-module-format",
15+
"homepage": "https://github.com/mrjoelkemp/module-definition",
1916
"dependencies": {
20-
"detective": "^3.0.0",
21-
"q": "^1.0.1",
2217
"esprima": "^1.0.4"
2318
}
2419
}

0 commit comments

Comments
 (0)