Skip to content

Commit

Permalink
fix(agoric-cli): yarn link after yarn install
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Aug 21, 2020
1 parent 53b3e2e commit aea7f93
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions packages/agoric-cli/lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ export default async function installMain(progname, rawArgs, powers, opts) {
['.', '_agstate/agoric-servers', 'contract', 'api']
.sort()
.map(async subd => {
const exists = await fs.stat(subd).catch(_ => false);
const exists = await fs.stat(`${subd}/package.json`).catch(_ => false);
return exists && subd;
}),
);
const subdirs = existingSubdirs.filter(subd => subd);

const linkFolder = path.resolve(`_agstate/yarn-links`);
const linkFlags = [`--link-folder=${linkFolder}`, 'link'];
const linkFlags = [`--link-folder=${linkFolder}`];
let packages;

if (opts.sdk) {
const sdkPackagesDir = path.resolve(__dirname, '../../../packages');
const allPackages = await fs.readdir(sdkPackagesDir);
const packages = new Map();
packages = new Map();
const versions = new Map();
log('removing', linkFolder);
await rimraf(linkFolder);
Expand All @@ -59,7 +60,7 @@ export default async function installMain(progname, rawArgs, powers, opts) {
// eslint-disable-next-line no-constant-condition
if (false) {
// This use of yarn is noisy and slow.
return pspawn('yarn', linkFlags, {
return pspawn('yarn', [...linkFlags, 'link'], {
stdio: 'inherit',
cwd: dir,
});
Expand All @@ -80,7 +81,7 @@ export default async function installMain(progname, rawArgs, powers, opts) {
log(chalk.bold.green(`removing ${nm} link`));
await fs.unlink(nm).catch(_ => {});

// Update all the package dependencies according to the SDK.
// Mark all the SDK package dependencies as wildcards.
const pjson = `${subdir}/package.json`;
const packageJSON = await fs.readFile(pjson).catch(_ => undefined);
if (!packageJSON) {
Expand All @@ -93,7 +94,7 @@ export default async function installMain(progname, rawArgs, powers, opts) {
for (const pkg of Object.keys(deps)) {
const latest = versions.get(pkg);
if (latest) {
deps[pkg] = `^${latest}`;
deps[pkg] = `*`;
}
}
}
Expand All @@ -102,19 +103,6 @@ export default async function installMain(progname, rawArgs, powers, opts) {
await fs.writeFile(pjson, `${JSON.stringify(pj, null, 2)}\n`);
}),
);
const sdkPackages = [...packages.values()].sort();
for (const subdir of subdirs) {
if (
// eslint-disable-next-line no-await-in-loop
await pspawn('yarn', [...linkFlags, ...sdkPackages], {
stdio: 'inherit',
cwd: subdir,
})
) {
log.error('Cannot yarn link', ...sdkPackages);
return 1;
}
}
} else {
// Delete all old node_modules.
await Promise.all(
Expand All @@ -126,7 +114,7 @@ export default async function installMain(progname, rawArgs, powers, opts) {
);
}

const yarnInstall = await pspawn('yarn', [linkFlags[0], 'install'], {
const yarnInstall = await pspawn('yarn', [...linkFlags, 'install'], {
stdio: 'inherit',
});
if (yarnInstall) {
Expand All @@ -135,9 +123,25 @@ export default async function installMain(progname, rawArgs, powers, opts) {
return 1;
}

if (packages) {
const sdkPackages = [...packages.values()].sort();
for (const subdir of subdirs) {
if (
// eslint-disable-next-line no-await-in-loop
await pspawn('yarn', [...linkFlags, 'link', ...sdkPackages], {
stdio: 'inherit',
cwd: subdir,
})
) {
log.error('Cannot yarn link', ...sdkPackages);
return 1;
}
}
}

// Try to install via Yarn.
const yarnInstallUi = await (subdirs.includes('ui') &&
pspawn('yarn', [linkFlags[0], 'install'], {
pspawn('yarn', [...linkFlags, 'install'], {
stdio: 'inherit',
cwd: 'ui',
}));
Expand Down

0 comments on commit aea7f93

Please sign in to comment.