Skip to content

Commit 0bf94b3

Browse files
committed
Restructure the error thrown
1 parent e9c1116 commit 0bf94b3

3 files changed

Lines changed: 28 additions & 27 deletions

File tree

packages/code-infra/src/cli/cmdPublish.mjs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,19 +313,12 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
313313
if (filter.length > 0) {
314314
console.log('🔍 Validating workspace dependencies for filtered packages...');
315315

316-
const { privateButRequired, missingFromPublish } =
317-
await validatePublishDependencies(allPackages);
316+
const { issues } = await validatePublishDependencies(allPackages);
318317

319-
if (privateButRequired.size > 0) {
320-
throw new Error(
321-
`The following private workspace packages are required as dependencies but cannot be published: ${[...privateButRequired].join(', ')}`,
322-
);
323-
}
324-
325-
if (missingFromPublish.size > 0) {
326-
throw new Error(
327-
`The following workspace packages are required as dependencies but are not included in the publish set: ${[...missingFromPublish].join(', ')}. Add them to the --filter list.`,
328-
);
318+
if (issues.length > 0) {
319+
throw new Error('Invalid dependencies structure of packages to be published.', {
320+
cause: issues,
321+
});
329322
}
330323

331324
console.log('✅ All workspace dependency requirements satisfied');

packages/code-infra/src/cli/cmdPublishCanary.mjs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -517,19 +517,12 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
517517
if (filter.length > 0) {
518518
console.log('🔍 Validating workspace dependencies for filtered packages...');
519519

520-
const { privateButRequired, missingFromPublish } =
521-
await validatePublishDependencies(filteredPackages);
520+
const { issues } = await validatePublishDependencies(filteredPackages);
522521

523-
if (privateButRequired.size > 0) {
524-
throw new Error(
525-
`The following private workspace packages are required as dependencies but cannot be published: ${[...privateButRequired].join(', ')}`,
526-
);
527-
}
528-
529-
if (missingFromPublish.size > 0) {
530-
throw new Error(
531-
`The following workspace packages are required as dependencies but are not included in the publish set: ${[...missingFromPublish].join(', ')}. Add them to the --filter list.`,
532-
);
522+
if (issues.length > 0) {
523+
throw new Error('Invalid dependencies structure of packages to be published.', {
524+
cause: issues,
525+
});
533526
}
534527

535528
console.log('✅ All workspace dependency requirements satisfied');

packages/code-infra/src/utils/pnpm.mjs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ export async function getTransitiveDependencies(packageNames, options = {}) {
252252
* and that none of those dependencies are private (which would make them unpublishable).
253253
*
254254
* @param {PublicPackage[]} packages - The packages intended for publishing
255-
* @returns {Promise<{privateButRequired: Set<string>, missingFromPublish: Set<string>}>}
256-
* Sets of package names that violate the requirements. Both sets are empty when valid.
255+
* @returns {Promise<{issues: string[]}>}
256+
* List of human-readable issue strings. Empty when the dependency set is valid.
257257
*/
258258
export async function validatePublishDependencies(packages) {
259259
const allWorkspacePackages = await getWorkspacePackages();
@@ -289,7 +289,22 @@ export async function validatePublishDependencies(packages) {
289289
}
290290
}
291291

292-
return { privateButRequired, missingFromPublish };
292+
/** @type {string[]} */
293+
const issues = [];
294+
295+
if (privateButRequired.size > 0) {
296+
issues.push(
297+
`The following private workspace packages are required as dependencies but cannot be published: ${[...privateButRequired].join(', ')}`,
298+
);
299+
}
300+
301+
if (missingFromPublish.size > 0) {
302+
issues.push(
303+
`The following workspace packages are required as dependencies but are not included in the publish set: ${[...missingFromPublish].join(', ')}. Add them to the --filter list.`,
304+
);
305+
}
306+
307+
return { issues };
293308
}
294309

295310
/**

0 commit comments

Comments
 (0)