Created
July 25, 2018 21:40
-
-
Save DrewML/d43e8628f7eb2846ea069cc321fe6eeb to your computer and use it in GitHub Desktop.
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
module.exports = function transformer(file, api) { | |
const j = api.jscodeshift; | |
const ast = j(file.source); | |
ast.find(j.CallExpression, { | |
callee: { | |
name: 'require' | |
} | |
}).forEach(path => { | |
const args = path.node.arguments; | |
if (!args.length) return; | |
const [firstArg] = args; | |
if (firstArg.type !== 'ArrayExpression') return; | |
firstArg.elements.forEach(element => { | |
if (element.type === 'StringLiteral') return; | |
api.stats(`Dynamic dependency found in require() call. File: ${file.path}`); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment