diff --git a/packages/agoric-cli/lib/install.js b/packages/agoric-cli/lib/install.js index 5add1f35151..6e973ecddf2 100644 --- a/packages/agoric-cli/lib/install.js +++ b/packages/agoric-cli/lib/install.js @@ -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' })) {