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

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

我试过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 ls -a

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

├─ @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

如果你想要得到特定包的实际依赖路径,并想知道为什么你有它,你可以简单地问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.

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

npx howfat jasmine

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

npm view <PACKAGE> dependencies

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