2016-11-27 128 views
1

查看本地NPM包我得到一個特定NPM包一些node-gyp警告,在這種情況下,這個包是「獲取光標位置」。我想知道我的本地node_modules目錄中的哪些軟件包取決於此軟件包。 (這可能是不是很容易做到)。依賴於包X

如果我運行:

$ npm view get-cursor-position 

我得到:

{ name: 'get-cursor-position', 
    description: 'Get the cursor\'s current position in your terminal.', 
    'dist-tags': { latest: '1.0.3' }, 
    versions: 
    [ '0.0.1', 
    '0.0.2', 
    '0.0.4', 
    '0.0.5', 
    '1.0.0', 
    '1.0.1', 
    '1.0.2', 
    '1.0.3' ], 
    maintainers: [ 'bubkoo <[email protected]>' ], 
    time: 
    { modified: '2016-11-01T02:36:07.728Z', 
    created: '2016-03-05T03:42:31.517Z', 
    '0.0.1': '2016-03-05T03:42:31.517Z', 
    '0.0.2': '2016-03-07T00:35:36.627Z', 
    '0.0.4': '2016-03-10T07:21:21.364Z', 
    '0.0.5': '2016-03-10T07:25:04.846Z', 
    '1.0.0': '2016-04-16T08:11:34.546Z', 
    '1.0.1': '2016-06-03T15:57:55.767Z', 
    '1.0.2': '2016-06-13T14:19:32.966Z', 
    '1.0.3': '2016-11-01T02:36:07.728Z' }, 
    homepage: 'https://github.com/bubkoo/get-cursor-position', 
    keywords: [ 'terminal', 'console', 'cursor', 'position', 'ansi', 'escape' ], 
    repository: 
    { type: 'git', 
    url: 'git+https://github.com/bubkoo/get-cursor-position.git' }, 
    author: 'bubkoo <[email protected]>', 
    bugs: { url: 'https://github.com/bubkoo/get-cursor-position/issues' }, 
    license: 'MIT', 
    readmeFilename: 'README.md', 
    version: '1.0.3', 
    main: 'index.js', 
    scripts: 
    { test: 'echo "Error: no test specified" && exit 1', 
    install: 'node-gyp rebuild' }, 
    gypfile: true, 
    gitHead: '56d403bb0e554532d17c403c47421ce8d2db2dec', 
    dist: 
    { shasum: '0e41d60343b705836a528d69a5e099e2c5108d63', 
    tarball: 'https://registry.npmjs.org/get-cursor-position/-/get-cursor-position-1.0.3.tgz' }, 
    directories: {} } 

我相信故宮視圖只會查找遠程數據包,我很樂意用在NPM彙總數據顯示所有依賴於get-cursor-position的軟件包,並且我可以在我的結尾做一些手動工作以與本地軟件包進行比較。

我也試過:

npm ls foo 

在我的情況,我想:

npm ls suman-events 

,它似乎並沒有拿起我的預期是回暖。我希望它能在我的案例中找到「suman-example-reporter」=>

正如您在下圖中看到的,「suman-example-reporter」是我項目中的一個直接依賴項(它在的package.json)和蘇曼 - 例如,記者取決於「蘇曼的事件」(和「蘇曼事件」是的package.json爲好,因爲它也是我的項目的直接依賴關係)。

enter image description here

任何人都知道如何做到這一點嗎?

+1

https://www.npmjs.com/browse/depended/get-cursor-position – thgaskell

+2

'npm ls get-cursor-position'是否工作?我不記得了。 – Ryan

回答

2

瑞安在評論中建議,npm ls <package>將顯示有關指定軟件包的依賴關係樹,所以你可以看到,直接/間接地要求它的包。

例如,如果安裝rimrafonce是一個依賴,並且可以查看哪個包使其與被安裝:

$ npm ls once 
[email protected] /path/to/pkg 
└─┬ [email protected] 
    └─┬ [email protected] 
    └── [email protected] 

因此,可以看到,once安裝因爲glob需要它和(我在我的package.json指定)rimraf取決於glob

在需要擴展的信息,請使用npm ls --long(或者它的簡寫語法,npm la/npm ll)。 擴展輸出也將包含模塊描述,Git repo鏈接,README,並且肯定會在樹中包含每個模塊(有些可能會跳過基本的npm ls)。

+1

讓我試一試,以確保它的工作將接受答案後,我驗證 –

+0

這是好的,但它似乎並沒有很好地工作,我已經看到了一些實驗中,它沒有拿起它的實例它可能應該 –

+0

好吧,所以它看起來像你真的想要「npm la once」,這將顯示一個擴展列表 –

0

的頁面上npmjs.com列出了所有的依賴包。在這種情況下,只有5個。

+1

OP似乎已經知道了這一點,他們並不真正需要它 - 他們想在本地爲*他們的package.json做這件事。 – Aurora0001

+0

對,如果這是一個程序化的解決方案,更喜歡 –

1

npm ls <options>命令絕對是你想要的。

@極光的答案基本上是正確的

以下是該命令的文檔:

https://docs.npmjs.com/cli/ls

它說

「當爲L1或La運行,它顯示擴展信息默認情況下。「

因此,要獲得在您的項目依賴於x的依賴性的完整列表,請嘗試:

$ npm la x 

,而不是

$ npm ls x