An open source design system that's fully customizable and agent ready
TypeScript
fix(release): a stable package may not name a canary-only package (#10391)
Cindy Zhanga2973ccacc33
diff --git a/.github/scripts/release-publish-workflow.test.mjs b/.github/scripts/release-publish-workflow.test.mjsindex 75971f4660..e3988fba94 100644--- a/.github/scripts/release-publish-workflow.test.mjs+++ b/.github/scripts/release-publish-workflow.test.mjs@@ -210,6 +210,12 @@ function runStablePublish({dependencies: {'@astryxdesign/core': '0.7.7'},...(cliPeers ? {peerDependencies: cliPeers} : {}),});+ writeJson(root, 'packages/lab/package.json', {+ name: '@astryxdesign/lab',+ version: '0.1.7',+ private: true,+ astryx: {canaryOnly: true},+ });// Publishes after core in the loop and peers on it.writeJson(root, 'packages/themes/stone/package.json', {name: '@astryxdesign/theme-stone',@@ -993,6 +999,19 @@ describe('stable publish requires the cut commit release-check (spec:AST-030 FR1expect(result.published).toContain('publish ./packages/core');});+ it('never publishes a stable package that names a canary-only one', () => {+ const result = runStablePublish({+ cliPeers: {'@astryxdesign/lab': '0.1.7'},+ verifyExit: 0,+ });++ expect(result.status).toBe(1);+ expect(result.stderr).toContain(+ '@astryxdesign/cli: peerDependencies names @astryxdesign/lab, which only the canary channel publishes',+ );+ expect(result.published).not.toContain('publish ./packages/cli');+ });+it('publishes a package whose @astryxdesign peers name this release', () => {const result = runStablePublish({cliPeers: {'@astryxdesign/core': '0.7.7'},diff --git a/scripts/npm/publish-package.mjs b/scripts/npm/publish-package.mjsindex 01bb43dc41..a17bf25875 100644--- a/scripts/npm/publish-package.mjs+++ b/scripts/npm/publish-package.mjs@@ -44,7 +44,11 @@ import fs from 'node:fs';import path from 'node:path';import {pathToFileURL} from 'node:url';-import {alignmentProblems, releaseVersions} from './published-manifests.mjs';+import {+ alignmentProblems,+ canaryOnlyNames,+ releaseVersions,+} from './published-manifests.mjs';import {DEFAULT_REGISTRY, fetchVersionDocument} from './registry.mjs';const DEFAULT_ATTEMPTS = 3;@@ -214,9 +218,11 @@ async function main() {);const {name, version} = manifest;// Run from the repository root, as both publish jobs do.+ const root = process.cwd();const misaligned = alignmentProblems(manifest,- releaseVersions(process.cwd()),+ releaseVersions(root),+ canaryOnlyNames(root),);if (misaligned.length > 0) {for (const problem of misaligned) console.error(problem);diff --git a/scripts/npm/published-manifests.mjs b/scripts/npm/published-manifests.mjsindex 4118991994..390696cd0b 100644--- a/scripts/npm/published-manifests.mjs+++ b/scripts/npm/published-manifests.mjs@@ -93,13 +93,25 @@ export function releaseVersions(root) {);}+/** The names of the packages only the canary channel publishes. */+export function canaryOnlyNames(root) {+ return new Set(+ publishedPackages(root)+ .filter(({manifest}) => manifest.astryx?.canaryOnly)+ .map(({manifest}) => manifest.name),+ );+}+/*** The problems in one manifest: each `@astryxdesign` entry in its* dependencies, peers or optional dependencies that does not name the- * release version of that package (`versions`, by name).+ * release version of that package (`versions`, by name). A package that the+ * stable channel publishes must not name one that only the canary channel+ * publishes (`canaryOnly`), because no stable version of it exists.*/-export function alignmentProblems(manifest, versions) {+export function alignmentProblems(manifest, versions, canaryOnly = new Set()) {const problems = [];+ const stable = !manifest.astryx?.canaryOnly;for (const field of FIELDS) {for (const [name, spec] of Object.entries(manifest[field] ?? {})) {if (!name.startsWith('@astryxdesign/')) continue;@@ -108,6 +120,10 @@ export function alignmentProblems(manifest, versions) {problems.push(`${manifest.name}: ${field} names ${name}, which npm does not receive in this release`,);+ } else if (stable && canaryOnly.has(name)) {+ problems.push(+ `${manifest.name}: ${field} names ${name}, which only the canary channel publishes`,+ );} else if (spec !== version &&!isPending(manifest.name, field, name, spec)@@ -124,13 +140,14 @@ export function alignmentProblems(manifest, versions) {function main() {const root = process.cwd();const versions = releaseVersions(root);+ const canaryOnly = canaryOnlyNames(root);const dirs = process.argv.slice(2);const manifests =dirs.length > 0? dirs.map(readManifest).filter(isPublished): publishedPackages(root).map(({manifest}) => manifest);const problems = manifests.flatMap(manifest =>- alignmentProblems(manifest, versions),+ alignmentProblems(manifest, versions, canaryOnly),);for (const problem of problems) console.error(problem);if (problems.length > 0) process.exit(1);diff --git a/scripts/npm/published-manifests.test.mjs b/scripts/npm/published-manifests.test.mjsindex 80072988f6..fe6a7dff8a 100644--- a/scripts/npm/published-manifests.test.mjs+++ b/scripts/npm/published-manifests.test.mjs@@ -13,6 +13,7 @@ import {afterEach, describe, expect, it} from 'vitest';import {alignmentProblems,+ canaryOnlyNames,isPublished,PENDING_ALIGNMENT,publishedPackages,@@ -137,6 +138,47 @@ describe('the pending exception', () => {});});+describe('canary-only packages', () => {+ const release = new Map([...versions, ['@astryxdesign/lab', '0.1.9']]);+ const canaryOnly = new Set(['@astryxdesign/lab']);++ it('refuses a stable package that names one', () => {+ expect(+ alignmentProblems(+ {+ name: '@astryxdesign/cli',+ peerDependencies: {'@astryxdesign/lab': '0.1.9'},+ },+ release,+ canaryOnly,+ ),+ ).toEqual([+ '@astryxdesign/cli: peerDependencies names @astryxdesign/lab, which only the canary channel publishes',+ ]);+ });++ it('lets a canary-only package name another at its version', () => {+ expect(+ alignmentProblems(+ {+ name: '@astryxdesign/charts',+ private: true,+ astryx: {canaryOnly: true},+ peerDependencies: {'@astryxdesign/lab': '0.1.9'},+ },+ release,+ canaryOnly,+ ),+ ).toEqual([]);+ });++ it("lists this repository's canary-only packages", () => {+ const names = canaryOnlyNames(ROOT);+ expect(names.has('@astryxdesign/lab')).toBe(true);+ expect(names.has('@astryxdesign/core')).toBe(false);+ });+});+describe('releaseVersions', () => {it('counts only packages npm receives, so naming a private one fails', () => {const versions = releaseVersions(ROOT);