-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 6c03630
Showing
4 changed files
with
110 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
index.js | ||
package-lock.json | ||
node_modules |
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,18 @@ | ||
# babel-plugin-module-deps | ||
|
||
This Babel plugin redefines `require` within all (CJS) modules to record any | ||
required modules in an array of resolved filenames called `module.deps`. | ||
(Note that the array may have duplicates.) | ||
|
||
This lets a tool later discover what other modules this module depends on, | ||
by inspecting `require.cache[filename].deps`. | ||
|
||
## Usage | ||
|
||
Babel configuration: | ||
|
||
```json | ||
{ | ||
"plugins": ["babel-plugin-module-deps"] | ||
} | ||
``` |
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,63 @@ | ||
module.exports = ({types}) -> | ||
program = null | ||
visitor: | ||
Program: (path) -> | ||
program = path | ||
undefined | ||
post: -> | ||
program.unshiftContainer 'body', | ||
types.expressionStatement types.assignmentExpression( | ||
'=' | ||
types.identifier 'require' | ||
types.callExpression( | ||
types.arrowFunctionExpression( | ||
[types.identifier 'r'] | ||
types.arrowFunctionExpression( | ||
[types.identifier 'id'] | ||
types.sequenceExpression [ | ||
types.callExpression( | ||
types.memberExpression( | ||
types.identifier 'console' | ||
types.identifier 'log' | ||
) | ||
[ | ||
types.identifier '__filename' | ||
types.identifier 'id' | ||
] | ||
) | ||
types.callExpression( | ||
types.memberExpression( | ||
types.memberExpression( | ||
types.identifier 'module' | ||
types.identifier 'deps' | ||
) | ||
types.identifier 'push' | ||
) | ||
[types.callExpression( | ||
types.memberExpression( | ||
types.identifier 'r' | ||
types.identifier 'resolve' | ||
) | ||
[types.identifier 'id'] | ||
)] | ||
) | ||
types.callExpression( | ||
types.identifier 'r' | ||
[types.identifier 'id'] | ||
) | ||
] | ||
) | ||
) | ||
[types.identifier 'require'] | ||
) | ||
) | ||
program.unshiftContainer 'body', | ||
types.expressionStatement types.assignmentExpression( | ||
'=' | ||
types.memberExpression( | ||
types.identifier 'module' | ||
types.identifier 'deps' | ||
) | ||
types.arrayExpression() | ||
) | ||
undefined |
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,26 @@ | ||
{ | ||
"name": "babel-plugin-module-deps", | ||
"version": "0.0.0", | ||
"description": "Babel plugin to annotate CJS modules with what they require", | ||
"main": "index.js", | ||
"scripts": { | ||
"prepare": "coffee --bare -c index.coffee" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/edemaine/babel-plugin-module-deps.git" | ||
}, | ||
"author": { | ||
"name": "Erik Demaine", | ||
"email": "[email protected]", | ||
"url": "http://erikdemaine.org/" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/edemaine/babel-plugin-module-deps/issues" | ||
}, | ||
"homepage": "https://github.com/edemaine/babel-plugin-module-deps#readme", | ||
"devDependencies": { | ||
"coffeescript": "^2.7.0" | ||
} | ||
} |