commonjs-walker
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "commonjs-walker", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Analyzer and tree walker for commonjs.", | ||
@@ -9,2 +9,10 @@ "main": "index.js", | ||
}, | ||
"kewords": [ | ||
"analyzer", | ||
"commonjs", | ||
"dependencies", | ||
"parser", | ||
"walker", | ||
"tree" | ||
], | ||
"repository": { | ||
@@ -17,3 +25,3 @@ "type": "git", | ||
], | ||
"engines": { | ||
"engines": { | ||
"node": ">=0.8.0" | ||
@@ -29,3 +37,8 @@ }, | ||
"chai": "~1.8.0" | ||
}, | ||
"dependencies": { | ||
"esprima": "^1.2.0", | ||
"semver": "^2.2.1", | ||
"async": "^0.8.0" | ||
} | ||
} |
134
README.md
@@ -1,1 +0,133 @@ | ||
# commonjs-walker [![NPM version](https://badge.fury.io/js/commonjs-walker.png)](http://badge.fury.io/js/commonjs-walker) [![Build Status](https://travis-ci.org/kaelzhang/node-commonjs-walker.png?branch=master)](https://travis-ci.org/kaelzhang/node-commonjs-walker) [![Dependency Status](https://gemnasium.com/kaelzhang/node-commonjs-walker.png)](https://gemnasium.com/kaelzhang/node-commonjs-walker) | ||
# commonjs-walker [![NPM version](https://badge.fury.io/js/commonjs-walker.png)](http://badge.fury.io/js/commonjs-walker) [![Build Status](https://travis-ci.org/kaelzhang/node-commonjs-walker.png?branch=master)](https://travis-ci.org/kaelzhang/node-commonjs-walker) | ||
Analyzes and walks down the dependencies from a commonjs entry and creates a walking tree. | ||
```js | ||
var walker = require('commonjs-walker'); | ||
``` | ||
**NOTICE** that it will not walk down `node_modules` and any foreign packages. | ||
## walker(entry, [options,] callback) | ||
```js | ||
walker('/path/to/entry.js', options, function(err, tree, nodes){ | ||
// ... | ||
}); | ||
``` | ||
If the file structure of your project is: | ||
``` | ||
/path/to | ||
|--- index.js | ||
|--- a.js | ||
``` | ||
index.js: | ||
```js | ||
require('./a'); | ||
``` | ||
a.js | ||
```js | ||
// there's nothing. | ||
``` | ||
Then | ||
```js | ||
walker('/path/to/index.js', function(err, tree, nodes){ | ||
console.log(tree); | ||
}) | ||
``` | ||
The `tree` object will be something like: | ||
```json | ||
{ | ||
id: '/path/to/index.js', | ||
dependents: [], | ||
isEntryPoint: true, | ||
unsolvedDependencies: ['./a'], | ||
dependencies: [ | ||
{ | ||
id: '/path/to/a.js', | ||
dependents: [ | ||
tree // points to `index.js` | ||
], | ||
dependencies: [], | ||
unsolvedDependencies: [], | ||
code: <Buffer> | ||
} | ||
], | ||
code: <Buffer> | ||
} | ||
``` | ||
The `nodes` object is the `path->node` hashmap. | ||
```json | ||
{ | ||
'/path/to/index.js': tree, | ||
'/path/to/a.js': tree.dependencies[0] | ||
} | ||
``` | ||
Walks down from a entry point, such as `package.main` of commonjs, and tries to create a `walker.Module` instance of the top level. | ||
- entry `Path` the absolute path of the entry point. | ||
- tree `walker.Module` tree of `walker.Module` | ||
- nodes `Object` the hashmap of `<path>: <walker.Module>` | ||
#### options | ||
All options are optional. By default, `walker` works in a very strict mode. | ||
Option | Type | Default | Description | ||
------ | ---- | ------- | ------------ | ||
pkg | `Object` | undefined | the object of package.json | ||
noCheckDepVersion | `Boolean` | false | whether should check the version of foreign packages. If `options.pkg` is not specified, walker will not check versions. | ||
noCheckCircular | `Boolean` | false | whether should check circular dependencies | ||
noStrictRequire | `Boolean` | false | whether should check the usage of method `require()` | ||
#### Example | ||
## Struct: walker.Module | ||
Actually, there is no `walker.Module` exists. We only use it to declare and describe the structure of the module. | ||
Property | Type | Description | ||
-------- | ---- | ----------- | ||
id | `String` | the id of the module | ||
isEntryPoint | `Boolean` | whether the current module is the entry point | ||
dependents | `Array.<walker.module>` | the dependent modules. If there's no dependents, it will be `[]` | ||
version | `semver` | the version of the current module. | ||
isForeign | `Boolean` | whether the current module is from a foreign package. | ||
**Properties only if `isForeign` is false: ** | ||
Property | Type | Description | ||
-------- | ---- | ----------- | ||
code | `Buffer` | the file content of the current module. | ||
dependencies | `Array.<walker.Module>` | the dependencies of the current module. If the module has no dependencies, it will be `[]` | ||
unsolvedDependencies | `Array.<String>` | the array contains the items `require()`d by the module. | ||
## Class: walker.Error | ||
- code `String` the enum type of the error | ||
- message `String` error messages | ||
- stack `String` the origin error.stack | ||
- data `Object` the object of the major information of the error, this is useful for i18n. | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
19215
18
499
134
3
1
+ Addedasync@^0.8.0
+ Addedesprima@^1.2.0
+ Addedsemver@^2.2.1
+ Addedasync@0.8.0(transitive)
+ Addedesprima@1.2.5(transitive)
+ Addedsemver@2.3.2(transitive)