This commit is contained in:
tatianamac
2019-11-26 14:50:43 -08:00
parent 8a55660ed0
commit 6d5445ecc5
13894 changed files with 2233957 additions and 0 deletions

103
node_modules/detective-amd/Readme.md generated vendored Normal file
View File

@ -0,0 +1,103 @@
# Detective-AMD [![npm](http://img.shields.io/npm/v/detective-amd.svg)](https://npmjs.org/package/detective-amd) [![npm](http://img.shields.io/npm/dm/detective-amd.svg)](https://npmjs.org/package/detective-amd)
Returns a list of dependencies for a given JavaScript file or AST using any of the AMD module syntaxes.
*Inspired by substack/node-detective but built for AMD.*
`npm install --save detective-amd`
* Supports JSX code via [node-source-walk](https://github.com/mrjoelkemp/node-source-walk).
### Usage
Let's say we have the following file definitions:
```javascript
// a.js
define(['./b', './c'], function (b, c) {
console.log(b, c);
});
// b.js
define({
name: 'foo'
});
// c.js
define(function () {
return 'bar';
});
```
Here's how you can grab the list of dependencies of `a.js` **synchronously**.
```javascript
var detective = require('detective-amd');
var srca = fs.readFileSync('a.js', 'utf8');
// Pass in the source code or an AST (if you've already parsed the file)
console.log(detective(srca)); // prints ['./b', './c']
```
You may also (optionally) configure the detective via a second object argument `detective(src, options)` that supports the following options:
* `skipLazyLoaded`: (Boolean) whether or not to omit inner requires in the list of extracted dependencies.
- Note: this does not affect the REM form since those inner requires are not "lazily" fetched.
### Syntax Support
**Supports the 4 forms of AMD module syntax:**
* "named": `define('name', [deps], func)`
* "dependency list": `define([deps], func)`
* "factory": `define(func(require))`
* "no dependencies": `define({})`
**Extra forms:**
* "driver script" (or entry-point) syntax: `require([deps], func)`
* "REM" (or CommonJS-like) form: `define(function(require, exports, module) {})`.
Also handles dynamically loaded dependencies (ex: inner requires).
**Supports driver scripts**
You can also find the dependencies from a script that has a top-level require (an app initialization/driver/entry-point script):
```javascript
require([
'./a'
], function (a) {
// My app will get booted up from here
});
```
**Expression-based requires**
If there's a require call that doesn't have a string literal but an expression,
a string (escodegen-generated) representation will be returned.
For example, if `a.js` was of the "factory" form and contained a dynamic module name:
```javascript
// a.js
define(function (require) {
// Assume str is some variable that gets set to a string dynamically
// var str = ...
var b = require('./' + str),
c = require('./c');
console.log(b, c);
});
```
The dependency list will be: `[ '\'./\' + str', './c' ]`
* Even though that string representation isn't incredibly useful, it's
still added to the list to represent/count that dependency

19
node_modules/detective-amd/bin/detective-amd.js generated vendored Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env node
'use strict';
var getDependencies = require('../');
var filename = process.argv[2];
var fs = require('fs');
if (!filename) {
console.log('Filename not supplied');
console.log('Usage: detective-amd <filename>');
} else {
var deps = getDependencies(fs.readFileSync(filename));
deps.forEach(function(dep) {
console.log(dep);
});
}

123
node_modules/detective-amd/index.js generated vendored Normal file
View File

@ -0,0 +1,123 @@
'use strict';
const Walker = require('node-source-walk');
const types = require('ast-module-types');
const escodegen = require('escodegen');
const getModuleType = require('get-amd-module-type');
/**
* @param {String} src - the string content or AST of an AMD module
* @param {Object} [options]
* @param {Object} [options.skipLazyLoaded] - whether or not to omit inner (non-REM) required dependencies
* @return {String[]} List of partials/dependencies referenced in the given file
*/
module.exports = function(src, options = {}) {
let dependencies = [];
const walker = new Walker();
if (typeof src === 'undefined') { throw new Error('src not given'); }
if (src === '') { return dependencies; }
walker.walk(src, function(node) {
if (!types.isTopLevelRequire(node) &&
!types.isDefine(node) &&
!types.isRequire(node)) {
return;
}
const type = getModuleType.fromAST(node);
if (!types.isTopLevelRequire(node) && types.isRequire(node) && type !== 'rem' && options.skipLazyLoaded) {
return;
}
const deps = getDependencies(node, type, options);
if (deps.length) {
dependencies = dependencies.concat(deps);
}
});
// Avoid duplicates
return dependencies.filter(function(dep, idx) {
return dependencies.indexOf(dep) === idx;
});
};
/**
* @param {Object} node - AST node
* @param {String} type - sniffed type of the module
* @param {Object} options - detective configuration
* @returns {String[]} A list of file dependencies or an empty list if the type is unsupported
*/
function getDependencies(node, type, options) {
// Note: No need to handle nodeps since there won't be any dependencies
switch (type) {
case 'named':
var args = node.arguments || [];
return getElementValues(args[1]).concat(options.skipLazyLoaded ? [] : getLazyLoadedDeps(node));
case 'deps':
case 'driver':
var args = node.arguments || [];
return getElementValues(args[0]).concat(options.skipLazyLoaded ? [] : getLazyLoadedDeps(node));
case 'factory':
case 'rem':
// REM inner requires aren't really "lazy loaded," but the form is the same
return getLazyLoadedDeps(node);
}
return [];
}
/**
* Looks for dynamic module loading
*
* @param {AST} node
* @return {String[]} List of dynamically required dependencies
*/
function getLazyLoadedDeps(node) {
// Use logic from node-detective to find require calls
const walker = new Walker();
let dependencies = [];
walker.traverse(node, function(innerNode) {
if (types.isRequire(innerNode)) {
const requireArgs = innerNode.arguments;
if (!requireArgs.length) { return; }
// Either require('x') or require(['x'])
const deps = requireArgs[0];
if (deps.type === 'ArrayExpression') {
dependencies = dependencies.concat(getElementValues(deps));
} else {
dependencies.push(getEvaluatedValue(deps));
}
}
});
return dependencies;
}
/**
* @param {Object} nodeArguments
* @returns {String[]} the literal values from the passed array
*/
function getElementValues(nodeArguments) {
const elements = nodeArguments.elements || [];
return elements.map(function(el) {
return getEvaluatedValue(el);
}).filter(Boolean);
}
/**
* @param {AST} node
* @returns {String} the statement represented by AST node
*/
function getEvaluatedValue(node) {
if (node.type === 'Literal' || node.type === 'StringLiteral') { return node.value; }
if (node.type === 'CallExpression') { return ''; }
return escodegen.generate(node);
}

81
node_modules/detective-amd/package.json generated vendored Normal file
View File

@ -0,0 +1,81 @@
{
"_args": [
[
"detective-amd@3.0.0",
"/Users/tatiana/selfdefined"
]
],
"_from": "detective-amd@3.0.0",
"_id": "detective-amd@3.0.0",
"_inBundle": false,
"_integrity": "sha512-kOpKHyabdSKF9kj7PqYHLeHPw+TJT8q2u48tZYMkIcas28el1CYeLEJ42Nm+563/Fq060T5WknfwDhdX9+kkBQ==",
"_location": "/detective-amd",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "detective-amd@3.0.0",
"name": "detective-amd",
"escapedName": "detective-amd",
"rawSpec": "3.0.0",
"saveSpec": null,
"fetchSpec": "3.0.0"
},
"_requiredBy": [
"/precinct"
],
"_resolved": "https://registry.npmjs.org/detective-amd/-/detective-amd-3.0.0.tgz",
"_spec": "3.0.0",
"_where": "/Users/tatiana/selfdefined",
"author": {
"name": "Joel Kemp",
"email": "joel@mrjoelkemp.com",
"url": "http://www.mrjoelkemp.com/"
},
"bin": {
"detective-amd": "bin/detective-amd.js"
},
"bugs": {
"url": "https://github.com/mrjoelkemp/node-detective-amd/issues"
},
"dependencies": {
"ast-module-types": "^2.3.1",
"escodegen": "^1.8.0",
"get-amd-module-type": "^3.0.0",
"node-source-walk": "^4.0.0"
},
"description": "Find all dependencies within a JavaScript file using AMD module syntax",
"devDependencies": {
"jscs": "~2.11.0",
"jscs-preset-mrjoelkemp": "~1.0.0",
"mocha": "^5.2.0"
},
"directories": {
"test": "test"
},
"engines": {
"node": ">= 6.0"
},
"homepage": "https://github.com/mrjoelkemp/node-detective-amd",
"keywords": [
"amd",
"detective",
"dependencies",
"ast",
"static analysis",
"requirejs",
"jsx",
"module"
],
"license": "MIT",
"main": "index.js",
"name": "detective-amd",
"repository": {
"type": "git",
"url": "git+https://github.com/mrjoelkemp/node-detective-amd.git"
},
"scripts": {
"test": "jscs index.js test/**/*.js bin/*.js && mocha"
},
"version": "3.0.0"
}