Skip to content

Commit

Permalink
fix: open-code the yarn link operation for silence and speed
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Aug 12, 2020
1 parent d75e37a commit 3b2671e
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions packages/agoric-cli/lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,44 @@ export default async function installMain(progname, rawArgs, powers, opts) {
const versions = new Map();
log('removing', linkFolder);
await rimraf(linkFolder);
for (const pkg of allPackages) {
const dir = `${sdkPackagesDir}/${pkg}`;
let packageJSON;
try {
// eslint-disable-next-line no-await-in-loop
packageJSON = await fs.readFile(`${dir}/package.json`);
} catch (e) {
// eslint-disable-next-line no-continue
continue;
}
if (packageJSON) {
await Promise.all(
allPackages.map(async pkg => {
const dir = `${sdkPackagesDir}/${pkg}`;
const packageJSON = await fs
.readFile(`${dir}/package.json`)
.catch(_ => undefined);
if (!packageJSON) {
return undefined;
}

const pj = JSON.parse(packageJSON);
if (!pj.private) {
if (
// eslint-disable-next-line no-await-in-loop
await pspawn('yarn', linkFlags, {
stdio: 'inherit',
cwd: dir,
})
) {
log.error('Cannot yarn link', dir);
return 1;
}
packages.set(pkg, pj.name);
versions.set(pj.name, pj.version);
if (pj.private) {
log('not linking private package', pj.name);
return undefined;
}
}
}

// Save our metadata.
packages.set(pkg, pj.name);
versions.set(pj.name, pj.version);

// eslint-disable-next-line no-constant-condition
if (false) {
// This use of yarn is noisy and slow.
return pspawn('yarn', linkFlags, {
stdio: 'inherit',
cwd: dir,
});
}

// This open-coding of the above yarn command is quiet and fast.
const linkName = `${linkFolder}/${pj.name}`;
const linkDir = path.dirname(linkName);
log('linking', linkName);
return fs
.mkdir(linkDir, { recursive: true })
.then(_ => fs.symlink(path.relative(linkDir, dir), linkName));
}),
);
await Promise.all(
subdirs.map(async subdir => {
const nm = `${subdir}/node_modules`;
Expand Down

0 comments on commit 3b2671e

Please sign in to comment.