Skip to content

Commit

Permalink
feat(install)!: drop link-folder requiring Yarn v1
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed May 2, 2024
1 parent 1cbf722 commit 527fd03
Showing 1 changed file with 15 additions and 40 deletions.
55 changes: 15 additions & 40 deletions packages/agoric-cli/src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default async function installMain(progname, rawArgs, powers, opts) {
const { anylogger, fs, spawn } = powers;
const log = anylogger('agoric:install');

const forceSdkVersion = rawArgs[1];
const forceSdkVersion = !!rawArgs[1];

// Notify the preinstall guard that we are running.
process.env.AGORIC_INSTALL = 'true';
Expand All @@ -28,9 +28,8 @@ export default async function installMain(progname, rawArgs, powers, opts) {

const pspawn = makePspawn({ log, spawn, chalk });

const rimraf = file => pspawn('rm', ['-rf', file]);

async function getWorktreePackagePaths(cwd = '.', map = new Map()) {
// TODO use Arborist like get-sdk-package-names.js does
// run `yarn workspaces info` to get the list of directories to
// use, instead of a hard-coded list
const p = pspawn('yarn', ['workspaces', '--silent', 'info'], {
Expand All @@ -52,29 +51,23 @@ export default async function installMain(progname, rawArgs, powers, opts) {
let sdkWorktree;
/** @type {Map<string, string>} */
const sdkPackageToPath = new Map();
const linkFolder = path.resolve(`_agstate/yarn-links`);
const linkFlags = [];
if (opts.sdk) {
linkFlags.push(`--link-folder=${linkFolder}`);
}

const yarnInstallEachWorktree = async (phase, ...flags) => {
for await (const workTree of workTrees) {
log.info(`yarn install ${phase} in ${workTree}`);
const yarnInstall = await pspawn(
'yarn',
[...linkFlags, 'install', ...flags],
{
stdio: 'inherit',
cwd: workTree,
},
);
const yarnInstall = await pspawn('yarn', ['install', ...flags], {
stdio: 'inherit',
cwd: workTree,
});
if (yarnInstall) {
throw Error(`yarn install ${phase} failed in ${workTree}`);
}
}
};

/**
* @param {boolean} forceVersion
*/
const updateSdkVersion = async forceVersion => {
// Prune the old version (removing potentially stale on-disk and yarn.lock
// packages), and update on-disk and yarn.lock packages to the new version.
Expand Down Expand Up @@ -238,11 +231,6 @@ export default async function installMain(progname, rawArgs, powers, opts) {
const sdkRoot = path.resolve(dirname, `../../..`);
await getWorktreePackagePaths(sdkRoot, sdkPackageToPath);

// We remove all the links to prevent `yarn install` below from corrupting
// them.
log('removing', linkFolder);
await rimraf(linkFolder);

// Link the SDK.
if (sdkWorktree) {
await fs.unlink(sdkWorktree).catch(_ => {});
Expand Down Expand Up @@ -285,32 +273,19 @@ export default async function installMain(progname, rawArgs, powers, opts) {
// Create symlinks to the SDK packages.
await Promise.all(
[...sdkPackageToPath.entries()].map(async ([pjName, dir]) => {
const SUBOPTIMAL = false;
await null;
if (SUBOPTIMAL) {
// This use of yarn is noisy and slow.
await pspawn('yarn', [...linkFlags, 'unlink', pjName]);
return pspawn('yarn', [...linkFlags, 'link'], {
stdio: 'inherit',
cwd: dir,
});
}

// This open-coding of the above yarn command is quiet and fast.
const linkName = `${linkFolder}/${pjName}`;
const linkDir = path.dirname(linkName);
log('linking', linkName);
return fs
.mkdir(linkDir, { recursive: true })
.then(_ => fs.symlink(path.relative(linkDir, dir), linkName));
await pspawn('yarn', ['unlink', pjName]);
return pspawn('yarn', ['link'], {
stdio: 'inherit',
cwd: dir,
});
}),
);

const sdkPackages = [...sdkPackageToPath.keys()].sort();
for await (const subdir of subdirs) {
const exists = await fs.stat(`${subdir}/package.json`).catch(_ => false);
const exitStatus = await (exists &&
pspawn('yarn', [...linkFlags, 'link', ...sdkPackages], {
pspawn('yarn', ['link', ...sdkPackages], {
stdio: 'inherit',
cwd: subdir,
}));
Expand Down

0 comments on commit 527fd03

Please sign in to comment.