如何获得npm可用但未安装在本地的模块树?

NPM ll负责本地安装的包。但对于未安装的模块或全局安装的模块,它不起作用。

我试过npm列表鲍尔,但那不是它。


可以使用npm-remote-ls模块。你可以全局安装它:

npm install -g npm-remote-ls

然后调用:

npm-remote-ls bower

或者,npm@5.2.0安装后,你可以使用npx,避免全局安装命令-只需调用:

npx npm-remote-ls bower

该站点允许您以2D或3D节点图的形式查看包树。

http://npm.anvaka.com/#/view/2d/waterline

@Avanka干得好!

这是一个没有权力的官方命令:

npm view <PACKAGE> dependencies

它只打印直接依赖项,而不是整个树。

你可以在不需要安装的情况下生成NPM依赖树 使用命令建立依赖关系

npm list

这将在当前目录为项目生成一个依赖树,并将其打印到控制台。

你可以像这样得到特定依赖项的依赖树:

npm list [dependency]

还可以通过执行设置最大深度级别

npm list --depth=[depth]

请注意,您只能查看已全局或本地安装到NPM项目的依赖项的依赖树。

如果你想要得到特定包的实际依赖路径,并想知道为什么你有它,你可以简单地问yarn为什么<MODULE>。 例子:

    $> yarn why mime-db
    yarn why v1.5.1
    [1/4] Why do we have the module "mime-db"...?
    [2/4] Initialising dependency graph...
    [3/4] Finding dependency...
    [4/4] Calculating file sizes...
    => Found "mime-db@1.37.0"
    info Reasons this module exists
       - "coveralls#request#mime-types" depends on it
       - Hoisted from "coveralls#request#mime-types#mime-db"
    info Disk size without dependencies: "196kB"
    info Disk size with unique dependencies: "196kB"
    info Disk size with transitive dependencies: "196kB"
    info Number of shared dependencies: 0
    Done in 0.65s.

查看npm模块的所有元数据

npm view mongoose(module name)

查看模块的所有依赖项

npm view mongoose dependencies

查看所有版本或版本模块

npm view mongoose version
npm view mongoose versions

查看所有关键字

npm view mongoose keywords

你可以使用howfat来显示依赖统计信息:

npx howfat jasmine

还有一个很好的web应用程序,可以在加权地图类的视图中查看依赖关系。

例如:

https://bundlephobia.com/result?p=sanitize-html@1.19.1

获取一个列表:

% npx npm-remote-ls --flatten dugite -d false -o false
[
  'dugite@1.91.3',
  'checksum@0.1.1',
  'progress@2.0.3',
  'mkdirp@0.5.5',
  'rimraf@2.7.1',
  'tar@4.4.13',
  'optimist@0.3.7',
  'got@9.6.0',
  'minimist@1.2.5',
  'chownr@1.1.4',
  'glob@7.1.6',
  'fs-minipass@1.2.7',
  'minizlib@1.3.3',
  'minipass@2.9.0',
  'safe-buffer@5.2.1',
  'yallist@3.1.1',
  'wordwrap@0.0.3',
  '@szmarczak/http-timer@1.1.2',
  'cacheable-request@6.1.0',
  '@sindresorhus/is@0.14.0',
  'decompress-response@3.3.0',
  'duplexer3@0.1.4',
  'lowercase-keys@1.0.1',
  'mimic-response@1.0.1',
  'get-stream@4.1.0',
  'to-readable-stream@1.0.0',
  'p-cancelable@1.1.0',
  'url-parse-lax@3.0.0',
  'fs.realpath@1.0.0',
  'inflight@1.0.6',
  'inherits@2.0.4',
  'once@1.4.0',
  'path-is-absolute@1.0.1',
  'minimatch@3.0.4',
  'defer-to-connect@1.1.3',
  'clone-response@1.0.2',
  'get-stream@5.2.0',
  'http-cache-semantics@4.1.0',
  'lowercase-keys@2.0.0',
  'responselike@1.0.2',
  'keyv@3.1.0',
  'pump@3.0.0',
  'prepend-http@2.0.0',
  'normalize-url@4.5.0',
  'wrappy@1.0.2',
  'brace-expansion@1.1.11',
  'json-buffer@3.0.0',
  'end-of-stream@1.4.4',
  'concat-map@0.0.1',
  'balanced-match@1.0.0'
]

如果你正在使用纱线,那么你可以从项目的根目录中使用纱线列表。它会给你一个所有传递依赖关系的树状结构,如下所示:

├─ @ampproject/toolbox-core@2.7.4
│  ├─ cross-fetch@3.0.6
│  └─ lru-cache@6.0.0
├─ @ampproject/toolbox-optimizer@2.7.0-alpha.1
│  ├─ @ampproject/toolbox-core@^2.6.0
│  ├─ @ampproject/toolbox-runtime-version@^2.7.0-alpha.1
│  ├─ @ampproject/toolbox-script-csp@^2.5.4
│  ├─ @ampproject/toolbox-validator-rules@^2.5.4
│  ├─ abort-controller@3.0.0
│  ├─ cross-fetch@3.0.5
│  ├─ cross-fetch@3.0.5
│  │  └─ node-fetch@2.6.0
│  ├─ cssnano-preset-simple@1.2.0
│  │  ├─ caniuse-lite@^1.0.30001093
│  │  ├─ postcss@^7.0.32
│  │  └─ postcss@7.0.35
│  │     ├─ chalk@^2.4.2
│  │     ├─ source-map@^0.6.1
│  │     └─ supports-color@^6.1.0

这个命令以树形结构输出所有依赖的模块:

npm ls -a