https://github.com/nodesource/universal-module-tree
Get a module tree from package-lock.json / yarn.lock / node_modules
https://github.com/nodesource/universal-module-tree
Last synced: 8 months ago
JSON representation
Get a module tree from package-lock.json / yarn.lock / node_modules
- Host: GitHub
- URL: https://github.com/nodesource/universal-module-tree
- Owner: nodesource
- License: mit
- Archived: true
- Created: 2018-09-25T20:18:11.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-01-07T07:08:18.000Z (about 5 years ago)
- Last Synced: 2025-04-19T22:16:54.082Z (9 months ago)
- Language: JavaScript
- Size: 283 KB
- Stars: 11
- Watchers: 18
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# universal-module-tree
[](https://travis-ci.org/nodesource/universal-module-tree)
Get a full module tree from `package-lock.json`, `yarn.lock` or `node_modules/**`.
## Usage
```js
const getTree = require('universal-module-tree')
const tree = await getTree(__dirname)
console.log(JSON.stringify(tree, null, 2))
```
```bash
$ node example.js | head -n25
{
"children": [
{
"data": {
"name": "@yarnpkg/lockfile",
"version": "1.1.0"
},
"children": []
},
{
"data": {
"name": "read-package-tree",
"version": "5.2.1"
},
"children": [
{
"data": {
"name": "debuglog",
"version": "1.0.1"
},
"children": []
},
{
"data": {
"name": "dezalgo",
```
Or with [NSolid](https://nodesource.com/products/nsolid):
```js
const getTree = require('universal-module-tree')
nsolid.packages((err, packages) => {
if (err) throw err
const tree = getTree.fromNSolid(packages)
console.log(JSON.stringify(tree, null, 2))
})
```
## Installation
```bash
$ npm install universal-module-tree
```
## API
### getTree(dir, { noDev = false }) => `Promise`
### getTree.fromPackageLock({ packageLock, packageJSON, noDev = false }) => `Object`
### getTree.fromYarnLock({ yarnLock, packageJSON, noDev = false }) => `Object`
### getTree.fromNodeModules(path, { noDev = false }) => `Promise`
### getTree.fromNSolid(packages) => `Object`
### getTree.flatten(tree) => `Array`
### Options
- `noDev`: exclude `devDependencies`
## License & copyright
Copyright © NodeSource.
Licensed under the MIT open source license, see the LICENSE file for details.