Upgrade to Yarn v3

This commit is contained in:
Stéphan Kochen
2021-08-15 21:00:54 +02:00
parent 47e5ae1b79
commit 2757cfd115
14 changed files with 1871 additions and 1167 deletions
+3 -4
View File
@@ -1,4 +1,4 @@
import { Command } from "clipanion";
import { Command, Option } from "clipanion";
import {
Cache,
@@ -12,10 +12,9 @@ import {
// 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()
locator: string = ``;
static paths = [[`nixify`, `fetch-one`]];
locator = Option.String();
@Command.Path(`nixify`, `fetch-one`)
async execute() {
const configuration = await Configuration.find(
this.context.cwd,
+7 -14
View File
@@ -1,4 +1,4 @@
import { Command } from "clipanion";
import { Command, Option } from "clipanion";
import { PortablePath, ppath, xfs } from "@yarnpkg/fslib";
import { createHash } from "crypto";
import { parseSyml, stringifySyml } from "@yarnpkg/parsers";
@@ -16,14 +16,11 @@ import {
// Internal command that injects an isolated build inside a Nix build.
export default class InjectBuildCommand extends Command<CommandContext> {
@Command.String()
locator: string = ``;
@Command.String()
source: string = ``;
@Command.String()
installLocation: string = ``;
static paths = [[`nixify`, `inject-build`]];
locator = Option.String();
source = Option.String();
installLocation = Option.String();
@Command.Path(`nixify`, `inject-build`)
async execute() {
const configuration = await Configuration.find(
this.context.cwd,
@@ -132,12 +129,8 @@ export default class InjectBuildCommand extends Command<CommandContext> {
// Update build state. The way we do this is crude, but we run
// `yarn install` later, which should clean it up again.
const bstatePath: PortablePath = configuration.get(`bstatePath`);
const bstate: { [key: string]: string } = xfs.existsSync(bstatePath)
? parseSyml(await xfs.readFilePromise(bstatePath, `utf8`))
: {};
bstate[pkg.locatorHash] = buildHash;
await xfs.writeFilePromise(bstatePath, stringifySyml(bstate));
project.storedBuildState.set(pkg.locatorHash, buildHash);
await project.persistInstallStateFile();
}
);
+4 -5
View File
@@ -1,4 +1,4 @@
import { Command } from "clipanion";
import { Command, Option } from "clipanion";
import { Filename, npath, ppath, xfs } from "@yarnpkg/fslib";
import { getPnpPath } from "@yarnpkg/plugin-pnp";
@@ -18,10 +18,9 @@ const supportedLinkers = [`pnp`, `node-modules`];
// Internal command that creates wrappers for binaries.
// Used inside the Nix install phase.
export default class InstallBinCommand extends Command<CommandContext> {
@Command.String()
binDir: string = ``;
static paths = [[`nixify`, `install-bin`]];
binDir = Option.String();
@Command.Path(`nixify`, `install-bin`)
async execute() {
const configuration = await Configuration.find(
this.context.cwd,
@@ -49,7 +48,7 @@ export default class InstallBinCommand extends Command<CommandContext> {
}
const binDir = npath.toPortablePath(this.binDir);
const pnpPath = getPnpPath(project).main;
const pnpPath = getPnpPath(project).cjs;
for (const [name, scriptInput] of workspace.manifest.bin) {
const binPath = ppath.join(binDir, name as Filename);
const scriptPath = ppath.join(
+2 -6
View File
@@ -117,17 +117,13 @@ export default async (project: Project, cache: Cache, report: Report) => {
cacheEntriesCode += `};`;
// Generate Nix code for isolated builds.
const isolatedBuilds: string[] = configuration.get(`isolatedNixBuilds`);
const isolatedBuilds = configuration.get(`isolatedNixBuilds`);
let isolatedPackages = new Set<Package>();
let isolatedIntegration = [];
let isolatedCode = [];
const nodeLinker = configuration.get(`nodeLinker`);
const pnpUnpluggedFolder = configuration.get(`pnpUnpluggedFolder`);
const bstatePath: PortablePath = configuration.get(`bstatePath`);
const bstate: { [key: string]: string } = xfs.existsSync(bstatePath)
? parseSyml(await xfs.readFilePromise(bstatePath, `utf8`))
: {};
const collectTree = (pkg: Package, out: Set<string> = new Set()) => {
const locatorStr = structUtils.stringifyLocator(pkg);
@@ -184,7 +180,7 @@ export default async (project: Project, cache: Cache, report: Report) => {
return out;
};
for (const locatorHash of Object.keys(bstate)) {
for (const locatorHash of project.storedBuildState.keys()) {
const pkg = project.storedPackages.get(locatorHash as LocatorHash);
if (!pkg) {
throw Error(`Assertion failed: The locator should have been registered`);
+11
View File
@@ -1,10 +1,21 @@
import { Hooks, Plugin, SettingsType } from "@yarnpkg/core";
import { PortablePath } from "@yarnpkg/fslib";
import FetchOneCommand from "./FetchOneCommand";
import InjectBuildCommand from "./InjectBuildCommand";
import InstallBinCommand from "./InstallBinCommand";
import generate from "./generate";
declare module "@yarnpkg/core" {
interface ConfigurationValueMap {
enableNixify: boolean;
nixExprPath: PortablePath;
generateDefaultNix: boolean;
enableNixPreload: boolean;
isolatedNixBuilds: string[];
}
}
const plugin: Plugin<Hooks> = {
commands: [FetchOneCommand, InjectBuildCommand, InstallBinCommand],
hooks: {
+5
View File
@@ -75,6 +75,8 @@ let
echo '{ "dependencies": { "${pname}": "${version}" } }' > package.json
install -m 0600 ${lockfile} ./yarn.lock
export yarn_global_folder="$TMP"
export YARN_ENABLE_IMMUTABLE_INSTALLS=false
yarn --immutable-cache
'';
@@ -107,6 +109,9 @@ let
source ${mkCacheBuilderForDrvs (lib.attrValues cacheDrvs)}
popd > /dev/null
# Yarn may need a writable home directory.
export yarn_global_folder="$TMP"
@@ISOLATED_INTEGRATION@@
# Run normal Yarn install to complete dependency installation.