Skip to content

Commit

Permalink
feat(agoric): make agoric --sdk install use yarn link
Browse files Browse the repository at this point in the history
This makes it possible to have dapp package dependencies diverge
from agoric-sdk's.
  • Loading branch information
michaelfig committed Aug 1, 2020
1 parent 2c7ba13 commit 3a53185
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions packages/agoric-cli/lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,57 @@ export default async function installMain(progname, rawArgs, powers, opts) {
const subdirs = ['.', '_agstate/agoric-servers', 'contract', 'api'].sort();

if (opts.sdk) {
const sdkNodeModules = path.resolve(__dirname, '../../../node_modules');
const sdkPackagesDir = path.resolve(__dirname, '../../../packages');
const allPackages = await fs.readdir(sdkPackagesDir);
const packages = new Map();
for (const pkg of allPackages) {
const dir = `${sdkPackagesDir}/${pkg}`;
let packageJSON;
try {
packageJSON = await fs.readFile(`${dir}/package.json`);
} catch (e) {
continue;
}
if (packageJSON) {
const pj = JSON.parse(packageJSON);
if (!pj.private) {
if (await pspawn('yarn', ['link'], { stdio: 'inherit', cwd: dir })) {
log.error('Cannot yarn link', dir);
return 1;
}
packages.set(pkg, pj.name);
}
}
}
await Promise.all(
subdirs.map(subdir => {
const nm = `${subdir}/node_modules`;
log(chalk.bold.green(`removing ${nm}`));
return rimraf(nm).then(_ => {
log(chalk.bold.green(`link SDK ${nm}`));
return fs.symlink(sdkNodeModules, nm);
});
return rimraf(nm);
}),
);
const sdkPackages = [...packages.values()].sort();
for (const subdir of subdirs) {
if (await pspawn('yarn', ['link', ...sdkPackages], { stdio: 'inherit', cwd: subdir })) {
log.error('Cannot yarn link', ...sdkPackages);
return 1;
}
}
} else {
// Delete any symlinks.
// Delete all old node_modules.
await Promise.all(
subdirs.map(subdir => {
const nm = `${subdir}/node_modules`;
log(chalk.bold.green(`removing ${nm}`));
return fs.unlink(nm).catch(_ => {});
return rimraf(nm);
}),
);
}

if (await pspawn('yarn', ['install'], { stdio: 'inherit' })) {
// Try to install via Yarn.
log.error('Cannot yarn install');
return 1;
}
if (await pspawn('yarn', ['install'], { stdio: 'inherit' })) {
// Try to install via Yarn.
log.error('Cannot yarn install');
return 1;
}

if (await pspawn('yarn', ['install'], { stdio: 'inherit', cwd: 'ui' })) {
Expand Down

0 comments on commit 3a53185

Please sign in to comment.