Split into modules and reorganize

This commit is contained in:
Stéphan Kochen
2020-08-25 18:55:38 +02:00
parent 708e36eaf4
commit 5d3ed3c119
10 changed files with 241 additions and 225 deletions
+52
View File
@@ -0,0 +1,52 @@
import { Command } from "clipanion";
import {
Cache,
CommandContext,
Configuration,
LocatorHash,
Project,
StreamReport,
} from "@yarnpkg/core";
// Internal command that fetches a single locator.
// Used from within Nix to build the cache for the project.
export default class FetchOneCommand extends Command<CommandContext> {
@Command.String()
locatorHash: string = ``;
@Command.Path(`nixify`, `fetch-one`)
async execute() {
const configuration = await Configuration.find(
this.context.cwd,
this.context.plugins
);
const { project } = await Project.find(configuration, this.context.cwd);
const cache = await Cache.find(configuration);
const fetcher = configuration.makeFetcher();
const report = await StreamReport.start(
{ configuration, stdout: this.context.stdout },
async (report) => {
const pkg = project.originalPackages.get(
this.locatorHash as LocatorHash
);
if (!pkg) {
report.reportError(0, `Invalid locator hash`);
return;
}
await fetcher.fetch(pkg, {
checksums: project.storedChecksums,
project,
cache,
fetcher,
report,
});
}
);
return report.exitCode();
}
}