-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ad6714
commit 8b38173
Showing
4 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import spawn from 'spawn-please' | ||
import keyValueBy from '../lib/keyValueBy' | ||
import { Index } from '../types/IndexType' | ||
import { Options } from '../types/Options' | ||
import { Version } from '../types/Version' | ||
import { list as npmList } from './npm' | ||
|
||
// return type of pnpm ls --json | ||
type PnpmList = { | ||
path: string | ||
private: boolean | ||
dependencies: Index<{ | ||
from: string | ||
version: Version | ||
resolved: string | ||
}> | ||
}[] | ||
|
||
/** Fetches the list of all installed packages. */ | ||
export const list = async (options: Options = {}): Promise<Index<string | undefined>> => { | ||
// use npm for local ls | ||
if (!options.global) return npmList(options) | ||
|
||
const cmd = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm' | ||
const result = JSON.parse(await spawn(cmd, ['ls', '-g', '--json'])) as PnpmList | ||
const list = keyValueBy(result[0].dependencies || {}, (name, { version }) => ({ | ||
[name]: version, | ||
})) | ||
return list | ||
} | ||
|
||
export { | ||
defaultPrefix, | ||
distTag, | ||
getPeerDependencies, | ||
greatest, | ||
latest, | ||
minor, | ||
newest, | ||
packageAuthorChanged, | ||
} from './npm' |