Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

require-list

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

require-list - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

.jshintrc

77

bin/rlist.js
#!/usr/bin/env node
var fs = require('fs');
var path = require('path');
var commander = require('commander');
var requireTree = require('../');
var package = require('../package');
var input = process.argv[2];
var version = require('../package').version;
commander
.version(package.version)
.usage('[options] -e <file>')
.option('-e, --entry <file>', 'entry point')
.option('-a, --argv <argv>', 'entry argv')
.option('-w, --wait <time>', 'wait time (ms)')
.parse(process.argv);
if (!input) {
console.error('Error parsing command line: not found option');
console.error('try \'rlist --help\' for more information');
process.exit(1);
}
if (fs.existsSync(path.resolve(input))) {
console.log(requireTree.string(input, true));
process.exit(0);
}
if (!commander.entry) {
console.log('please specify entry point: -e --entry <file>');
process.exit(2);
if (input === '--version' || input === 'version') {
console.log(version);
process.exit(0);
}
commander.argv = commander.argv || '';
commander.wait = commander.wait || 0;
var entry = path.resolve(process.cwd(), commander.entry);
var argv = [ 'node', entry ].concat(commander.argv.split(' '));
var wait = Number(commander.wait);
process.argv = argv;
require(entry);
function output() {
// entry point
var entryDir = path.dirname(entry);
console.log(entry.replace(entryDir, '.'));
function childTree(children, level) {
var i, len;
var space = '';
for (i = 0; i < level; i++) {
space += ' |';
}
space += ' ├─';
for (i = 0, len = children.length; i < len; i++) {
var filePath = children[i].id.replace(entryDir, '.');
if (/node_modules/.test(filePath)) {
continue;
}
console.log(space, filePath);
if (children[i].children.length) {
childTree(children[i].children, level + 1);
}
}
}
var children = require.cache[entry].children;
childTree(children, 0);
if (input === '--help' || input === 'help') {
console.log('Usage: rlist [JavaScript file path in entry-point]');
console.log('Options:');
console.log(' --version, version\tshow version');
process.exit(0);
}
setTimeout(function() {
output();
process.exit(0);
}, wait);
console.error('Error parsing command line: unknown option', input);
console.error('try \'rlist --help\' for more information');
process.exit(1);
{
"name": "require-list",
"version": "0.0.1",
"version": "0.1.0",
"description": "require tree list",
"main": "index.js",
"scripts": {
"test": "mocha --require intelli-espower-loader -R spec --recursive test",
"jshint": "jshint lib/*.js"
},
"bin": {
"rlist": "bin/rlist.js"
},
"directories": {
"test": "test/"
},
"repository": {
"type": "git",
"url": "git://github.com/iyu/require-list.git"
},
"keywords": [
"require",
"tree",
"list",
"rlist",
"require-list"
],
"author": "Yuhei Aihara",
"license": "MIT",
"bugs": {
"url": "https://github.com/iyu/require-list/issues"
},
"dependencies": {
"commander": "~2.2.0"
"esprima": "^1.2.5"
},
"devDependencies": {
"should": "~3.3.1",
"jshint": "~2.5.0",
"mocha": "~1.18.2"
},
"scripts": {
"test": "mocha -r should -R spec --recursive test"
},
"author": "Yuhei Aihara",
"license": "MIT"
"espower-loader": "^0.10.0",
"intelli-espower-loader": "^0.5.0",
"jshint": "^2.6.3",
"mocha": "^2.1.0",
"power-assert": "^0.10.1"
}
}

@@ -11,102 +11,69 @@ Require List

## Command
### rlist
#### Example
##### Case 1
a.js
## Usage
### Command
```
require('./b');
console.log('done: a');
rlist [javascript file path in entry-point]
```
b.js
#### Example
/tmp/a.js
```javascript
var b = require('./b');
var test = require('./test');
```
require('./c');
console.log('done: b');
/tmp/b.js
```javascript
require('./test/c');
module.exports = 'b';
```
c.js
```
console.log('done: c');
```
command
```
$ rlist -e a.js
done: c
done: b
done: a
./a.js
├─ ./b.js
| ├─ ./c.js
```
##### Case 2
a.js
```
setTimeout(function() {
require('./b');
}, 1000);
console.log('done: a');
```
b.js
```
/tmp/test/index.js
```javascript
require('./c');
console.log('done: b');
```
c.js
/tmp/test/c.js
```javascript
module.exports = function() { return 'c' };
```
console.log('done: c');
```
bad command
```
$ rlist -e a.js
done: a
./a.js
$ rlist /tmp/a.js
/tmp/a.js
├─ b.js
| ├─ test/c.js
├─ test/index.js
| ├─ test/c.js
```
good command
```
$ rlist -e a.js -w 1000
done: a
done: c
done: b
./a.js
├─ ./b.js
| ├─ ./c.js
```
##### Case 3
a.js
```
if (process.argv.length < 4) {
console.log('unknown option "-c --config <path>"');
process.exit(1);
}
require('./b');
console.log('done: a');
```
b.js
```
require('./c');
console.log('done: b');
```
c.js
```
console.log('done: c');
```
bad command
### Module API
#### Example
```javascript
var rlist = require('require-list');
console.log('rlist(filepath)');
console.log(rlist('/tmp/a.js'));
console.log('rlist.string(filepath)');
console.log(rlist.string('/tmp/a.js'));
// --output--
// rlist(filepath)
// { '/tmp/b.js': { '/tmp/test/c.js': {} },
// '/tmp/test/index.js': { '/tmp/test/c.js': {} } } }
// rlist.string(filepath)
// /tmp/a.js
// ├─ b.js
// | ├─ test/c.js
// ├─ test/index.js
// | ├─ test/c.js
```
$ rlist -e a.js
unknown option "-c --config <path>"
```
good command
```
$ rlist -e a.js -a '-c conf/local.json'
done: c
done: b
done: a
./a.js
├─ ./b.js
| ├─ ./c.js
```
## Test
Run `npm test` and `npm run-script jshint`
## Contribution
1. Fork it ( [https://github.com/iyu/require-list/fork](https://github.com/iyu/require-list/fork) )
2. Create a feature branch
3. Commit your changes
4. Rebase your local changes against the master branch
5. Run test suite with the `npm test; npm run-script jshint` command and confirm that it passes
5. Create new Pull Request

@@ -1,5 +0,34 @@

var should = require('should');
var path = require('path');
describe('Require List', function() {
var assert = require('power-assert'),
rlist = require('../');
var testEntryPoint = './test/data/index.js';
describe('rlist', function() {
it('#constructor', function() {
var result = rlist(testEntryPoint);
var expect = {};
expect.path = null;
expect.esprima = null;
expect[path.join(__dirname, './data/a.js')] = {};
expect[path.join(__dirname, './data/a.js')][path.join(__dirname, './data/b/index.js')] = {};
expect[path.join(__dirname, './data/a.js')][path.join(__dirname, './data/b/index.js')][path.join(__dirname, './data/c.json')] = null;
expect[path.join(__dirname, './data/a.js')][path.join(__dirname, './data/c.json')] = null;
assert.deepEqual(result, expect);
});
it('#string', function() {
var result = rlist.string(testEntryPoint);
var expect = path.join(__dirname, './data/index.js') + '\n';
expect += ' ├─ path\n';
expect += ' ├─ esprima\n';
expect += ' ├─ a.js\n';
expect += ' | ├─ b/index.js\n';
expect += ' | | ├─ c.json\n';
expect += ' | ├─ c.json\n';
assert.equal(result, expect);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc