Skip to content

Commit

Permalink
chore: compat with Berry workspace list results
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Dec 13, 2023
1 parent df1609e commit 835ed0c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 53 deletions.
38 changes: 8 additions & 30 deletions packages/agoric-cli/scripts/get-sdk-package-names.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,18 @@
#! /usr/bin/env node
/* global process, Buffer */
import { spawn } from 'child_process';
/* eslint-env node */
import { basename } from 'path';
import { listWorkspaces } from '../src/lib/yarn.js';

const ps = spawn('yarn', ['workspaces', 'list', '--json'], {
stdio: ['ignore', 'pipe', 'inherit'],
shell: true,
});
const workspaces = listWorkspaces();

// Get Buffers of output.
const chunks = [];
ps.stdout.on('data', data => chunks.push(data));
const packageNames = workspaces.map(w => w.name);

// Wait for the process to exit.
ps.on('close', code => {
if (code !== 0) {
throw Error(`yarn info exited with code ${code}`);
}

// Get the output.
const ndjson = Buffer.concat(chunks).toString('utf8');
// process.stderr.write(json);

const packageNames = ndjson
.trim()
.split('\n')
.map(line => JSON.parse(line).name)
.filter(n => n !== '@agoric/sdk');

// Write the module.
process.stdout.write(`\
// Write the module.
process.stdout.write(`\
// DO NOT EDIT - automatically generated by ${basename(
new URL(import.meta.url).pathname,
)}
new URL(import.meta.url).pathname,
)}
/* eslint-disable comma-dangle,quotes */
// prettier-ignore
export default ${JSON.stringify(packageNames.sort(), null, 2)};
`);
});
19 changes: 5 additions & 14 deletions packages/agoric-cli/src/install.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* global process AggregateError Buffer */
/* eslint-env node */
import path from 'path';
import chalk from 'chalk';
import { makePspawn } from './helpers.js';
import DEFAULT_SDK_PACKAGE_NAMES from './sdk-package-names.js';
import { listWorkspaces } from './lib/yarn.js';

const REQUIRED_AGORIC_START_PACKAGES = [
'@agoric/solo',
Expand Down Expand Up @@ -31,19 +32,9 @@ export default async function installMain(progname, rawArgs, powers, opts) {
const rimraf = file => pspawn('rm', ['-rf', file]);

async function getWorktreePackagePaths(cwd = '.', map = new Map()) {
// 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'], {
cwd,
stdio: ['inherit', 'pipe', 'inherit'],
});
const stdout = [];
p.childProcess.stdout.on('data', out => stdout.push(out));
await p;
const d = JSON.parse(Buffer.concat(stdout).toString('utf-8'));
Object.entries(d).forEach(([name, { location }]) =>
map.set(name, path.resolve(cwd, location)),
);
for (const { name, location } of listWorkspaces()) {
map.set(name, path.resolve(cwd, location));
}
return map;
}

Expand Down
20 changes: 20 additions & 0 deletions packages/agoric-cli/src/lib/yarn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @ts-check
import { execFileSync } from 'child_process';

/**
* Omits the root
*
* @returns {Array<{ location: string, name: string }>}
*/
export const listWorkspaces = () => {
const ndjson = execFileSync('yarn', ['workspaces', 'list', '--json'], {
stdio: ['ignore', 'pipe', 'inherit'],
shell: true,
encoding: 'utf-8',
});
return ndjson
.trim()
.split('\n')
.map(line => JSON.parse(line))
.filter(({ location }) => location !== '.');
};
11 changes: 2 additions & 9 deletions scripts/check-untested-packages.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
#! /usr/bin/env node
import fs from 'fs';
import path from 'path';
import { execFileSync } from 'child_process';
import { listWorkspaces } from '../packages/agoric-cli/src/lib/yarn.js';

const parent = new URL('..', import.meta.url).pathname;
const yarnCmd = ['yarn', '--silent', 'workspaces', 'info'];
console.log('Getting', yarnCmd.join(' '));
const workspacesInfo = execFileSync(yarnCmd[0], yarnCmd.slice(1), {
cwd: parent,
encoding: 'utf8',
});
const workspacesInfoJson = JSON.parse(workspacesInfo);

const testYaml = path.resolve(
parent,
Expand All @@ -21,7 +14,7 @@ const testYamlContent = fs.readFileSync(testYaml, 'utf-8');

console.log('Searching for "cd <location> && yarn test"...');
let status = 0;
for (const [pkg, { location }] of Object.entries(workspacesInfoJson)) {
for (const { name: pkg, location } of listWorkspaces()) {
const cmd = `cd ${location} && yarn \${{ steps.vars.outputs.test }}`;
if (!testYamlContent.includes(cmd)) {
console.error(`Cannot find ${location} (${pkg})`);
Expand Down

0 comments on commit 835ed0c

Please sign in to comment.