{"id":15290179,"url":"https://github.com/npm/logical-tree","last_synced_at":"2025-10-07T03:31:30.239Z","repository":{"id":57742116,"uuid":"106120044","full_name":"npm/logical-tree","owner":"npm","description":"Calculates a nested logical tree using a package.json and a package lock.","archived":true,"fork":false,"pushed_at":"2018-03-30T12:47:48.000Z","size":69,"stargazers_count":44,"open_issues_count":1,"forks_count":10,"subscribers_count":13,"default_branch":"latest","last_synced_at":"2024-09-23T14:50:40.770Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/npm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-07T18:15:31.000Z","updated_at":"2023-01-28T07:18:10.000Z","dependencies_parsed_at":"2022-09-05T17:00:38.365Z","dependency_job_id":null,"html_url":"https://github.com/npm/logical-tree","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Flogical-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Flogical-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Flogical-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Flogical-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/npm","download_url":"https://codeload.github.com/npm/logical-tree/tar.gz/refs/heads/latest","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219877414,"owners_count":16554881,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-30T16:06:08.287Z","updated_at":"2025-10-07T03:31:24.953Z","avatar_url":"https://github.com/npm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# npm-logical-tree [![npm version](https://img.shields.io/npm/v/npm-logical-tree.svg)](https://npm.im/npm-logical-tree) [![license](https://img.shields.io/npm/l/npm-logical-tree.svg)](https://npm.im/npm-logical-tree) [![Travis](https://img.shields.io/travis/npm/logical-tree.svg)](https://travis-ci.org/npm/logical-tree) [![AppVeyor](https://ci.appveyor.com/api/projects/status/github/npm/logical-tree?svg=true)](https://ci.appveyor.com/project/npm/logical-tree) [![Coverage Status](https://coveralls.io/repos/github/npm/logical-tree/badge.svg?branch=latest)](https://coveralls.io/github/npm/logical-tree?branch=latest)\n\n[`npm-logical-tree`](https://github.com/npm/npm-logical-tree) is a Node.js\nlibrary that takes the contents of a `package.json` and `package-lock.json` (or\n`npm-shrinkwrap.json`) and returns a nested tree data structure representing the\nlogical relationships between the different dependencies.\n\n## Install\n\n`$ npm install npm-logical-tree`\n\n## Table of Contents\n\n* [Example](#example)\n* [Contributing](#contributing)\n* [API](#api)\n  * [`logicalTree`](#logical-tree)\n  * [`logicalTree.node`](#make-node)\n  * [`tree.isRoot`](#is-root)\n  * [`tree.addDep`](#add-dep)\n  * [`tree.delDep`](#del-dep)\n  * [`tree.getDep`](#get-dep)\n  * [`tree.path`](#path)\n  * [`tree.hasCycle`](#has-cycle)\n  * [`tree.forEach`](#for-each)\n  * [`tree.forEachAsync`](#for-each-async)\n\n### Example\n\n```javascript\nconst fs = require('fs')\nconst logicalTree = require('npm-logical-tree')\n\nconst pkg = require('./package.json')\nconst pkgLock = require('./package-lock.json')\n\nlogicalTree(pkg, pkgLock)\n// returns:\nLogicalTree {\n  name: 'npm-logical-tree',\n  version: '1.0.0',\n  address: null,\n  optional: false,\n  dev: false,\n  bundled: false,\n  resolved: undefined,\n  integrity: undefined,\n  requiredBy: Set { },\n  dependencies:\n   Map {\n     'foo' =\u003e LogicalTree {\n       name: 'foo',\n       version: '1.2.3',\n       address: 'foo',\n       optional: false,\n       dev: true,\n       bundled: false,\n       resolved: 'https://registry.npmjs.org/foo/-/foo-1.2.3.tgz',\n       integrity: 'sha1-rYUK/p261/SXByi0suR/7Rw4chw=',\n       dependencies: Map { ... },\n       requiredBy: Set { ... },\n     },\n     ...\n  }\n}\n```\n\n### Contributing\n\nThe npm team enthusiastically welcomes contributions and project participation!\nThere's a bunch of things you can do if you want to contribute! The [Contributor\nGuide](CONTRIBUTING.md) has all the information you need for everything from\nreporting bugs to contributing entire new features. Please don't hesitate to\njump in if you'd like to, or even ask us questions if something isn't clear.\n\nAll participants and maintainers in this project are expected to follow [Code of\nConduct](CODE_OF_CONDUCT.md), and just generally be excellent to each other.\n\nPlease refer to the [Changelog](CHANGELOG.md) for project history details, too.\n\nHappy hacking!\n\n### API\n\n#### \u003ca name=\"logical-tree\"\u003e\u003c/a\u003e `\u003e logicalTree(pkg, lock) -\u003e LogicalTree`\n\nCalculates a logical tree based on a matching `package.json` and\n`package-lock.json` pair. A \"logical tree\" is a fully-nested dependency graph\nfor an npm package, as opposed to a physical tree which might be flattened.\n\n`logical-tree` will represent deduplicated/flattened nodes using the same object\nthroughout the tree, so duplication can be checked by object identity.\n\n##### Example\n\n```javascript\nconst pkg = require('./package.json')\nconst pkgLock = require('./package-lock.json')\n\nlogicalTree(pkg, pkgLock)\n// returns:\nLogicalTree {\n  name: 'npm-logical-tree',\n  version: '1.0.0',\n  address: null,\n  optional: false,\n  dev: false,\n  bundled: false,\n  resolved: undefined,\n  integrity: undefined,\n  requiredBy: Set { },\n  dependencies:\n   Map {\n     'foo' =\u003e LogicalTree {\n       name: 'foo',\n       version: '1.2.3',\n       address: 'foo',\n       optional: false,\n       dev: true,\n       bundled: false,\n       resolved: 'https://registry.npmjs.org/foo/-/foo-1.2.3.tgz',\n       integrity: 'sha1-rYUK/p261/SXByi0suR/7Rw4chw=',\n       requiredBy: Set { ... },\n       dependencies: Map { ... }\n     },\n     ...\n  }\n}\n```\n\n#### \u003ca name=\"make-node\"\u003e\u003c/a\u003e `\u003e logicalTree.node(name, [address, [opts]]) -\u003e LogicalTree`\n\nManually creates a new LogicalTree node.\n\n##### Options\n\n* `opts.version` - version of the node.\n* `opts.optional` - is this node an optionalDep?\n* `opts.dev` - is this node a devDep?\n* `opts.bundled` - is this bundled?\n* `opts.resolved` - resolved address.\n* `opts.integrity` - SRI string.\n\n##### Example\n```javascript\nlogicalTree.node('hello', 'subpath:to:@foo/bar', {dev: true})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm%2Flogical-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnpm%2Flogical-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm%2Flogical-tree/lists"}