forked from yarnpkg/berry
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
69 changed files
with
3,148 additions
and
8,880 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,72 @@ | ||
import Joi = require('joi'); | ||
|
||
import {Configuration, Project, Workspace, Cache, Locator, Manifest} from '@berry/core'; | ||
// @ts-ignore: Need to write the definition file | ||
import {UsageError} from '@manaflair/concierge'; | ||
import {resolve} from 'path'; | ||
import {Readable, Writable} from 'stream'; | ||
|
||
import {plugins} from '../plugins'; | ||
|
||
export async function getDependencyBinaries({configuration, project, workspace, cache}: {configuration: Configuration, project: Project, workspace: Workspace, cache: Cache}) { | ||
const fetcher = configuration.makeFetcher(); | ||
const binaries: Map<string, [Locator, string]> = new Map(); | ||
|
||
const descriptors = [ | ||
... workspace.manifest.dependencies.values(), | ||
... workspace.manifest.devDependencies.values(), | ||
... workspace.manifest.peerDependencies.values(), | ||
]; | ||
|
||
for (const descriptor of descriptors) { | ||
const resolution = project.storedResolutions.get(descriptor.descriptorHash); | ||
|
||
if (!resolution) | ||
continue; | ||
|
||
const pkg = project.storedPackages.get(resolution); | ||
|
||
if (!pkg) | ||
continue; | ||
|
||
const pkgFs = await fetcher.fetch(pkg, {cache, fetcher, project}); | ||
|
||
const manifest = new Manifest(); | ||
manifest.loadFile(pkgFs); | ||
|
||
for (const [binName, file] of manifest.bin.entries()) { | ||
binaries.set(binName, [pkg, file]); | ||
} | ||
} | ||
|
||
return binaries; | ||
} | ||
|
||
export default (concierge: any) => concierge | ||
|
||
.command(`bin <name> [--cwd PATH]`) | ||
.describe(`get the path to a binary script`) | ||
|
||
.validate(Joi.object().unknown().keys({ | ||
cwd: Joi.string().default(process.cwd()), | ||
})) | ||
|
||
.action(async ({cwd, stdin, stdout, stderr, name}: {cwd: string, stdin: Readable, stdout: Writable, stderr: Writable, name: string}) => { | ||
const configuration = await Configuration.find(cwd, plugins); | ||
const {project, workspace} = await Project.find(configuration, cwd); | ||
const cache = await Cache.find(configuration); | ||
|
||
const binaries = await getDependencyBinaries({configuration, project, workspace, cache}); | ||
const binary = binaries.get(name); | ||
|
||
if (!binary) | ||
throw new UsageError(`Couldn't find a binary named "${name}"`); | ||
|
||
const [pkg, file] = binary; | ||
|
||
const fetcher = configuration.makeFetcher(); | ||
const pkgFs = await fetcher.fetch(pkg, {cache, fetcher, project}); | ||
const target = resolve(pkgFs.getRealPath(), file); | ||
|
||
stdout.write(`${target}\n`); | ||
}); |
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
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 |
---|---|---|
@@ -1,19 +1,21 @@ | ||
import {Archive} from './Archive'; | ||
import {FakeFS} from '@berry/zipfs'; | ||
|
||
import {Cache} from './Cache'; | ||
import {Manifest} from './Manifest'; | ||
import {Project} from './Project'; | ||
import {Locator} from './types'; | ||
|
||
export type FetchOptions = { | ||
cache: Cache, | ||
fetcher: Fetcher, | ||
export type MinimalFetchOptions = { | ||
project: Project, | ||
fetcher: Fetcher, | ||
}; | ||
|
||
export interface Fetcher { | ||
supports(locator: Locator): boolean; | ||
export type FetchOptions = MinimalFetchOptions & { | ||
cache: Cache, | ||
}; | ||
|
||
fetchManifest(locator: Locator, opts: FetchOptions): Promise<Manifest>; | ||
export interface Fetcher { | ||
supports(locator: Locator, opts: MinimalFetchOptions): boolean; | ||
|
||
fetch(locator: Locator, opts: FetchOptions): Promise<any>; | ||
fetch(locator: Locator, opts: FetchOptions): Promise<FakeFS>; | ||
} |
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
Oops, something went wrong.