Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(cli): drop the CLI's unused theme, Lab and Charts peers, and check published @astryxdesign versions (#10232)

Cindy Zhang128e2180fcb5
diff --git a/.changeset/cli-core-only-peer.md b/.changeset/cli-core-only-peer.md
new file mode 100644
index 0000000000..7ef3e505cf
--- /dev/null
+++ b/.changeset/cli-core-only-peer.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[fix] The CLI no longer lists `@astryxdesign/theme-neutral`, `@astryxdesign/lab` or `@astryxdesign/charts` as optional peers. Before, a package manager could keep a theme from an older release as the CLI's peer after an app removed the theme and upgraded Core, and then warn that the theme's Core peer was not met. `@astryxdesign/core` stays the CLI's one optional peer. In a Yarn Plug'n'Play workspace member, or a pnpm workspace member with `hoist: false`, a legacy `package.json#astryx.theme` of `neutral` now makes `astryx component` warn that it cannot resolve the theme. Add the theme to the app with `astryx theme add neutral` instead.
+
+@cixzhang
diff --git a/.github/scripts/release-publish-workflow.test.mjs b/.github/scripts/release-publish-workflow.test.mjs
index dff6ae158b..75971f4660 100644
--- a/.github/scripts/release-publish-workflow.test.mjs
+++ b/.github/scripts/release-publish-workflow.test.mjs
@@ -45,6 +45,7 @@ function withPublisher(root) {
'canary-pending.mjs',
'publish-order.mjs',
'publish-package.mjs',
+ 'published-manifests.mjs',
'registry.mjs',
]) {
const target = path.join(root, 'scripts/npm', file);
@@ -189,6 +190,7 @@ function runStablePublish({
failingPackage = '',
failOnce = '',
verifyExit = null,
+ cliPeers = null,
} = {}) {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-stable-publish-'));
const publishLog = path.join(root, 'publish.log');
@@ -206,6 +208,7 @@ function runStablePublish({
name: '@astryxdesign/cli',
version: '0.7.7',
dependencies: {'@astryxdesign/core': '0.7.7'},
+ ...(cliPeers ? {peerDependencies: cliPeers} : {}),
});
// Publishes after core in the loop and peers on it.
writeJson(root, 'packages/themes/stone/package.json', {
@@ -303,6 +306,7 @@ server.listen(0, '127.0.0.1', () => console.log(server.address().port));`,
for (const file of [
'canary-pending.mjs',
'publish-package.mjs',
+ 'published-manifests.mjs',
'registry.mjs',
]) {
const target = path.join(root, 'scripts/npm', file);
@@ -974,4 +978,28 @@ describe('stable publish requires the cut commit release-check (spec:AST-030 FR1
expect(publish.output).toContain('verified=pending');
expect(first.output).toContain('verified=pending');
});
+
+ it('never publishes a package whose @astryxdesign peers do not name this release', () => {
+ const result = runStablePublish({
+ cliPeers: {'@astryxdesign/theme-neutral': '*'},
+ verifyExit: 0,
+ });
+
+ expect(result.status).toBe(1);
+ expect(result.stderr).toContain(
+ '@astryxdesign/cli: peerDependencies @astryxdesign/theme-neutral is "*"; name this release\'s version, "0.7.7"',
+ );
+ expect(result.published).not.toContain('publish ./packages/cli');
+ expect(result.published).toContain('publish ./packages/core');
+ });
+
+ it('publishes a package whose @astryxdesign peers name this release', () => {
+ const result = runStablePublish({
+ cliPeers: {'@astryxdesign/core': '0.7.7'},
+ verifyExit: 0,
+ });
+
+ expect(result.status).toBe(0);
+ expect(result.published).toContain('publish ./packages/cli');
+ });
});
diff --git a/package.json b/package.json
index cda8fd854e..f5acf18de2 100644
--- a/package.json
+++ b/package.json
@@ -36,7 +36,7 @@
"storyboards": "playwright test --config playwright.interaction.config.ts --grep @storyboard",
"typecheck": "pnpm -r --no-bail --workspace-concurrency=1 --if-present --filter \"!@astryxdesign/docsite\" --filter \"!@astryxdesign/sandbox\" run typecheck",
"check:package-boundaries": "node scripts/check-package-boundaries.js",
- "check:repo": "pnpm check:visual-owner && pnpm check:sync && pnpm check:neutral-palette-refs && pnpm check:stone-palette-refs && pnpm check:gothic-palette-refs && pnpm check:matcha-palette-refs && pnpm check:butter-palette-refs && pnpm check:y2k-palette-refs && pnpm check:data-tokens && pnpm check:token-docs && pnpm check:motion-roles && pnpm check:knowledge && pnpm check:package-boundaries && pnpm check:changesets && pnpm check:demo-media && pnpm check:executable-bits && pnpm check:cli-structure && pnpm check:use-client && pnpm check:portable-scripts && pnpm check:i18n-runtime && pnpm check:i18n-catalog && pnpm check:cldr-weekdays && pnpm check:cldr-month-capitals && pnpm check:fixtures && pnpm check:setup-contract",
+ "check:repo": "pnpm check:visual-owner && pnpm check:published-manifests && pnpm check:sync && pnpm check:neutral-palette-refs && pnpm check:stone-palette-refs && pnpm check:gothic-palette-refs && pnpm check:matcha-palette-refs && pnpm check:butter-palette-refs && pnpm check:y2k-palette-refs && pnpm check:data-tokens && pnpm check:token-docs && pnpm check:motion-roles && pnpm check:knowledge && pnpm check:package-boundaries && pnpm check:changesets && pnpm check:demo-media && pnpm check:executable-bits && pnpm check:cli-structure && pnpm check:use-client && pnpm check:portable-scripts && pnpm check:i18n-runtime && pnpm check:i18n-catalog && pnpm check:cldr-weekdays && pnpm check:cldr-month-capitals && pnpm check:fixtures && pnpm check:setup-contract",
"check:visual-owner": "node scripts/check-visual-workflow-owner.mjs",
"check:fixtures": "node internal/vibe-tests/scripts/fixture-suite.mjs verify",
"generate:cldr-weekdays": "node scripts/generate-cldr-weekdays.mjs",
@@ -100,7 +100,8 @@
"npm:prune-canaries": "node scripts/npm/prune-canaries.mjs",
"check:knowledge": "node scripts/check-knowledge.mjs",
"review:pre": "node scripts/pre-review.mjs",
- "specs:for": "node scripts/specs-for-file.mjs"
+ "specs:for": "node scripts/specs-for-file.mjs",
+ "check:published-manifests": "node scripts/npm/published-manifests.mjs"
},
"devDependencies": {
"@axe-core/playwright": "^4.12.1",
diff --git a/packages/cli/foundation/render/component-map.test.mjs b/packages/cli/foundation/render/component-map.test.mjs
new file mode 100644
index 0000000000..03eaeca6c2
--- /dev/null
+++ b/packages/cli/foundation/render/component-map.test.mjs
@@ -0,0 +1,51 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file The component map tolerates Astryx packages the project does not
+ * install, so the CLI needs no peer on Lab or Charts.
+ */
+
+import * as fs from 'node:fs';
+import * as os from 'node:os';
+import * as path from 'node:path';
+import {afterEach, describe, expect, it} from 'vitest';
+
+import {componentMap} from './component-map.mjs';
+import {rebuildPage} from './rebuild.mjs';
+
+const roots = [];
+afterEach(() => {
+ for (const root of roots.splice(0)) {
+ fs.rmSync(root, {recursive: true, force: true});
+ }
+});
+
+/** A project with a package.json and no Astryx packages installed. */
+function emptyProject() {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-component-map-'));
+ roots.push(root);
+ fs.writeFileSync(
+ path.join(root, 'package.json'),
+ '{"name":"app","private":true}',
+ );
+ fs.mkdirSync(path.join(root, 'node_modules'));
+ return root;
+}
+
+describe('componentMap without the package installed', () => {
+ it('returns an empty map for Lab and Charts, without an error', () => {
+ const root = emptyProject();
+ for (const pkg of ['@astryxdesign/lab', '@astryxdesign/charts']) {
+ const map = componentMap(pkg, root);
+ expect(map).toBeInstanceOf(Map);
+ expect(map.size).toBe(0);
+ }
+ });
+
+ it('lets a page rebuild in a project with neither installed', () => {
+ const root = emptyProject();
+ expect(() =>
+ rebuildPage('<html><body><p>Hello</p></body></html>', root),
+ ).not.toThrow();
+ });
+});
diff --git a/packages/cli/package.json b/packages/cli/package.json
index ea5f020c80..b674f72238 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -140,23 +140,11 @@
"zod": "^4.4.3"
},
"peerDependencies": {
- "@astryxdesign/charts": "*",
- "@astryxdesign/core": "*",
- "@astryxdesign/lab": "*",
- "@astryxdesign/theme-neutral": "*"
+ "@astryxdesign/core": "*"
},
"peerDependenciesMeta": {
- "@astryxdesign/charts": {
- "optional": true
- },
"@astryxdesign/core": {
"optional": true
- },
- "@astryxdesign/lab": {
- "optional": true
- },
- "@astryxdesign/theme-neutral": {
- "optional": true
}
},
"devDependencies": {
diff --git a/scripts/npm/canary-pending.mjs b/scripts/npm/canary-pending.mjs
index 915292cb0a..1cc6428057 100644
--- a/scripts/npm/canary-pending.mjs
+++ b/scripts/npm/canary-pending.mjs
@@ -19,10 +19,10 @@
*/
import fs from 'node:fs';
-import path from 'node:path';
import {pathToFileURL} from 'node:url';
import {packageExists, registryHas} from './publish-package.mjs';
+import {publishedPackages} from './published-manifests.mjs';
/**
* The packages the canary loop publishes: public `@astryxdesign` packages,
@@ -30,31 +30,11 @@ import {packageExists, registryHas} from './publish-package.mjs';
* which the loop skips while their npm name does not exist.
*/
export function canaryPackages(root) {
- const dirs = ['packages', 'packages/themes'].flatMap(parent =>
- fs
- .readdirSync(path.join(root, parent), {withFileTypes: true})
- .filter(entry => entry.isDirectory())
- .map(entry => `${parent}/${entry.name}`)
- .sort(),
- );
- return dirs
- .filter(dir => fs.existsSync(path.join(root, dir, 'package.json')))
- .map(dir => ({
- dir,
- manifest: JSON.parse(
- fs.readFileSync(path.join(root, dir, 'package.json'), 'utf8'),
- ),
- }))
- .filter(
- ({manifest}) =>
- manifest.name?.startsWith('@astryxdesign/') &&
- (!manifest.private || manifest.astryx?.canaryOnly),
- )
- .map(({dir, manifest}) => ({
- dir,
- name: manifest.name,
- privateCanary: Boolean(manifest.private),
- }));
+ return publishedPackages(root).map(({dir, manifest}) => ({
+ dir,
+ name: manifest.name,
+ privateCanary: Boolean(manifest.private),
+ }));
}
/**
diff --git a/scripts/npm/publish-order.test.mjs b/scripts/npm/publish-order.test.mjs
index 679a3157e7..5723b07b45 100644
--- a/scripts/npm/publish-order.test.mjs
+++ b/scripts/npm/publish-order.test.mjs
@@ -45,7 +45,7 @@ describe('publishOrder', () => {
).toThrow('dependency cycle among: a, b');
});
- it("orders this repository's packages so the CLI comes after Core and its theme", () => {
+ it("orders this repository's packages so the CLI and the theme come after Core", () => {
const result = spawnSync(
process.execPath,
[
@@ -57,10 +57,12 @@ describe('publishOrder', () => {
{cwd: ROOT, encoding: 'utf8'},
);
expect(result.status).toBe(0);
- expect(result.stdout.trim().split('\n')).toEqual([
- 'packages/core',
- 'packages/themes/neutral',
+ const order = result.stdout.trim().split('\n');
+ expect(order).toHaveLength(3);
+ expect(order[0]).toBe('packages/core');
+ expect(order.slice(1).sort()).toEqual([
'packages/cli',
+ 'packages/themes/neutral',
]);
});
});
diff --git a/scripts/npm/publish-package.mjs b/scripts/npm/publish-package.mjs
index f1eff6d31b..01bb43dc41 100644
--- a/scripts/npm/publish-package.mjs
+++ b/scripts/npm/publish-package.mjs
@@ -35,6 +35,8 @@
* document, which grows with every canary and can outlast a read's time
* limit. (A missing scoped package's dist-tags answer 401, not 404.) An
* unknown answer is asked again and never skips.
+ * - A package whose `@astryxdesign` dependencies or peers do not name this
+ * release's versions is never published (see published-manifests.mjs).
*/
import {spawnSync} from 'node:child_process';
@@ -42,6 +44,7 @@ import fs from 'node:fs';
import path from 'node:path';
import {pathToFileURL} from 'node:url';
+import {alignmentProblems, releaseVersions} from './published-manifests.mjs';
import {DEFAULT_REGISTRY, fetchVersionDocument} from './registry.mjs';
const DEFAULT_ATTEMPTS = 3;
@@ -210,6 +213,16 @@ async function main() {
fs.readFileSync(path.join(dir, 'package.json'), 'utf8'),
);
const {name, version} = manifest;
+ // Run from the repository root, as both publish jobs do.
+ const misaligned = alignmentProblems(
+ manifest,
+ releaseVersions(process.cwd()),
+ );
+ if (misaligned.length > 0) {
+ for (const problem of misaligned) console.error(problem);
+ console.error(`${name}@${version} is not published.`);
+ process.exit(1);
+ }
const registry = process.env.ASTRYX_PUBLISH_REGISTRY || DEFAULT_REGISTRY;
const attempts = Number(
process.env.ASTRYX_PUBLISH_ATTEMPTS || DEFAULT_ATTEMPTS,
diff --git a/scripts/npm/published-manifests.mjs b/scripts/npm/published-manifests.mjs
new file mode 100644
index 0000000000..4118991994
--- /dev/null
+++ b/scripts/npm/published-manifests.mjs
@@ -0,0 +1,147 @@
+#!/usr/bin/env node
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Check that every published package names the other `@astryxdesign`
+ * packages it needs at their release version.
+ * @input Optional package directories; with none, every package npm receives
+ * from `packages/` and `packages/themes/` (public ones, and private ones
+ * marked canary-only, which the canary job publishes).
+ * @output Prints each problem and exits 1 when there is one.
+ * @position `pnpm check:published-manifests` runs it on every change,
+ * scripts/npm/publish-package.mjs runs `alignmentProblems` on each package
+ * just before it publishes, and the canary loops publish `publishedPackages`.
+ * A dependency, peer or optional dependency on an `@astryxdesign` package
+ * must name that package's exact version in the same release, the only
+ * spec the release's version sync moves. `*` and other ranges let a package
+ * manager keep an older release next to the new one: an app that upgraded
+ * Core could keep a theme from the release before, whose exact Core peer then
+ * no longer matches.
+ */
+
+import fs from 'node:fs';
+import path from 'node:path';
+import {pathToFileURL} from 'node:url';
+
+const FIELDS = ['dependencies', 'peerDependencies', 'optionalDependencies'];
+const PACKAGE_PARENTS = ['packages', 'packages/themes'];
+
+// Entries that may keep another spec until a minor release. Narrowing a
+// published range is a breaking change, so the CLI keeps its optional `*`
+// peer on Core until the next minor release pins it to the release version.
+export const PENDING_ALIGNMENT = [
+ {
+ name: '@astryxdesign/cli',
+ field: 'peerDependencies',
+ dependency: '@astryxdesign/core',
+ spec: '*',
+ },
+];
+
+function isPending(name, field, dependency, spec) {
+ return PENDING_ALIGNMENT.some(
+ entry =>
+ entry.name === name &&
+ entry.field === field &&
+ entry.dependency === dependency &&
+ entry.spec === spec,
+ );
+}
+
+/** Each package under `root`, as its directory relative to `root` and its manifest. */
+function workspacePackages(root) {
+ return PACKAGE_PARENTS.flatMap(parent => {
+ const parentDir = path.join(root, parent);
+ if (!fs.existsSync(parentDir)) return [];
+ return fs
+ .readdirSync(parentDir, {withFileTypes: true})
+ .filter(entry => entry.isDirectory())
+ .map(entry => `${parent}/${entry.name}`)
+ .sort();
+ })
+ .filter(dir => fs.existsSync(path.join(root, dir, 'package.json')))
+ .map(dir => ({dir, manifest: readManifest(path.join(root, dir))}));
+}
+
+function readManifest(dir) {
+ return JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
+}
+
+/** Whether npm receives this package: public, or private and canary-only. */
+export function isPublished(manifest) {
+ return (
+ Boolean(manifest.name?.startsWith('@astryxdesign/')) &&
+ (!manifest.private || Boolean(manifest.astryx?.canaryOnly))
+ );
+}
+
+/**
+ * The packages npm receives from `root`: public `@astryxdesign` packages and
+ * private canary-only ones. The canary loops publish exactly this list.
+ */
+export function publishedPackages(root) {
+ return workspacePackages(root).filter(({manifest}) => isPublished(manifest));
+}
+
+/** Each package npm receives from `root`, by name, with its version. */
+export function releaseVersions(root) {
+ return new Map(
+ publishedPackages(root).map(({manifest}) => [
+ manifest.name,
+ manifest.version,
+ ]),
+ );
+}
+
+/**
+ * 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).
+ */
+export function alignmentProblems(manifest, versions) {
+ const problems = [];
+ for (const field of FIELDS) {
+ for (const [name, spec] of Object.entries(manifest[field] ?? {})) {
+ if (!name.startsWith('@astryxdesign/')) continue;
+ const version = versions.get(name);
+ if (version == null) {
+ problems.push(
+ `${manifest.name}: ${field} names ${name}, which npm does not receive in this release`,
+ );
+ } else if (
+ spec !== version &&
+ !isPending(manifest.name, field, name, spec)
+ ) {
+ problems.push(
+ `${manifest.name}: ${field} ${name} is "${spec}"; name this release's version, "${version}"`,
+ );
+ }
+ }
+ }
+ return problems;
+}
+
+function main() {
+ const root = process.cwd();
+ const versions = releaseVersions(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),
+ );
+ for (const problem of problems) console.error(problem);
+ if (problems.length > 0) process.exit(1);
+ console.log(
+ `${manifests.length} published package manifests name their @astryxdesign packages at this release's version.`,
+ );
+}
+
+if (
+ process.argv[1] &&
+ import.meta.url === pathToFileURL(process.argv[1]).href
+) {
+ main();
+}
diff --git a/scripts/npm/published-manifests.test.mjs b/scripts/npm/published-manifests.test.mjs
new file mode 100644
index 0000000000..80072988f6
--- /dev/null
+++ b/scripts/npm/published-manifests.test.mjs
@@ -0,0 +1,250 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Published packages name their @astryxdesign packages at this
+ * release's version (scripts/npm/published-manifests.mjs).
+ */
+
+import {spawnSync} from 'node:child_process';
+import fs from 'node:fs';
+import os from 'node:os';
+import path from 'node:path';
+import {afterEach, describe, expect, it} from 'vitest';
+
+import {
+ alignmentProblems,
+ isPublished,
+ PENDING_ALIGNMENT,
+ publishedPackages,
+ releaseVersions,
+} from './published-manifests.mjs';
+
+const ROOT = path.resolve(import.meta.dirname, '../..');
+const versions = new Map([
+ ['@astryxdesign/core', '0.7.9'],
+ ['@astryxdesign/theme-neutral', '0.7.9'],
+]);
+const roots = [];
+afterEach(() => {
+ for (const root of roots.splice(0)) {
+ fs.rmSync(root, {recursive: true, force: true});
+ }
+});
+
+describe('alignmentProblems', () => {
+ it("accepts this release's exact version", () => {
+ for (const spec of ['0.7.9']) {
+ expect(
+ alignmentProblems(
+ {
+ name: '@astryxdesign/cli',
+ peerDependencies: {'@astryxdesign/core': spec},
+ },
+ versions,
+ ),
+ ).toEqual([]);
+ }
+ });
+
+ it('refuses "*", another release and any other range', () => {
+ for (const spec of [
+ '*',
+ '0.7.0',
+ '>=0.7.0',
+ '^0.7.0',
+ '^0.7.9',
+ 'workspace:*',
+ ]) {
+ expect(
+ alignmentProblems(
+ {
+ name: '@astryxdesign/theme-neutral',
+ peerDependencies: {'@astryxdesign/core': spec},
+ },
+ versions,
+ ),
+ ).toEqual([
+ `@astryxdesign/theme-neutral: peerDependencies @astryxdesign/core is "${spec}"; name this release's version, "0.7.9"`,
+ ]);
+ }
+ });
+
+ it('checks dependencies and optional dependencies too, but not devDependencies', () => {
+ const problems = alignmentProblems(
+ {
+ name: '@astryxdesign/x',
+ dependencies: {'@astryxdesign/core': '*'},
+ optionalDependencies: {'@astryxdesign/theme-neutral': '*'},
+ devDependencies: {'@astryxdesign/core': '*'},
+ },
+ versions,
+ );
+ expect(problems).toHaveLength(2);
+ expect(problems[0]).toContain('dependencies @astryxdesign/core');
+ expect(problems[1]).toContain(
+ 'optionalDependencies @astryxdesign/theme-neutral',
+ );
+ });
+
+ it('refuses an @astryxdesign package that is not in this release, and ignores other scopes', () => {
+ expect(
+ alignmentProblems(
+ {
+ name: '@astryxdesign/cli',
+ peerDependencies: {'@astryxdesign/gone': '1.0.0', react: '*'},
+ },
+ versions,
+ ),
+ ).toEqual([
+ '@astryxdesign/cli: peerDependencies names @astryxdesign/gone, which npm does not receive in this release',
+ ]);
+ });
+});
+
+describe('the pending exception', () => {
+ it('lets only the CLI\'s optional Core peer stay "*"', () => {
+ expect(PENDING_ALIGNMENT).toHaveLength(1);
+ expect(
+ alignmentProblems(
+ {
+ name: '@astryxdesign/cli',
+ peerDependencies: {'@astryxdesign/core': '*'},
+ },
+ versions,
+ ),
+ ).toEqual([]);
+ });
+
+ it('does not cover another spec, field, dependency or package', () => {
+ const cases = [
+ {
+ name: '@astryxdesign/cli',
+ peerDependencies: {'@astryxdesign/core': '>=0.6.0'},
+ },
+ {name: '@astryxdesign/cli', dependencies: {'@astryxdesign/core': '*'}},
+ {
+ name: '@astryxdesign/cli',
+ peerDependencies: {'@astryxdesign/theme-neutral': '*'},
+ },
+ {
+ name: '@astryxdesign/theme-neutral',
+ peerDependencies: {'@astryxdesign/core': '*'},
+ },
+ ];
+ for (const manifest of cases) {
+ expect(alignmentProblems(manifest, versions)).toHaveLength(1);
+ }
+ });
+});
+
+describe('releaseVersions', () => {
+ it('counts only packages npm receives, so naming a private one fails', () => {
+ const versions = releaseVersions(ROOT);
+ expect(versions.get('@astryxdesign/core')).toBeDefined();
+ expect(versions.has('@astryxdesign/theme-probe')).toBe(false);
+ expect(
+ alignmentProblems(
+ {
+ name: '@astryxdesign/x',
+ peerDependencies: {'@astryxdesign/theme-probe': '0.5.0'},
+ },
+ versions,
+ ),
+ ).toEqual([
+ '@astryxdesign/x: peerDependencies names @astryxdesign/theme-probe, which npm does not receive in this release',
+ ]);
+ });
+});
+
+describe('publishedPackages', () => {
+ it("lists the canary loops' packages: public ones and private canary-only ones", () => {
+ const byName = new Map(
+ publishedPackages(ROOT).map(pkg => [pkg.manifest.name, pkg.dir]),
+ );
+ expect(byName.get('@astryxdesign/core')).toBe('packages/core');
+ expect(byName.get('@astryxdesign/theme-neutral')).toBe(
+ 'packages/themes/neutral',
+ );
+ expect(byName.has('@astryxdesign/vega')).toBe(true);
+ expect(byName.has('@astryxdesign/theme-probe')).toBe(false);
+ });
+});
+
+describe('isPublished', () => {
+ it('counts public packages and private canary-only ones', () => {
+ expect(isPublished({name: '@astryxdesign/core'})).toBe(true);
+ expect(
+ isPublished({
+ name: '@astryxdesign/lab',
+ private: true,
+ astryx: {canaryOnly: true},
+ }),
+ ).toBe(true);
+ expect(
+ isPublished({name: '@astryxdesign/theme-probe', private: true}),
+ ).toBe(false);
+ expect(isPublished({name: 'astryx-docsite'})).toBe(false);
+ });
+});
+
+describe('this repository', () => {
+ it('publishes every package with aligned @astryxdesign versions', () => {
+ const result = spawnSync(
+ process.execPath,
+ ['scripts/npm/published-manifests.mjs'],
+ {cwd: ROOT, encoding: 'utf8'},
+ );
+ expect(result.stderr).toBe('');
+ expect(result.status).toBe(0);
+ });
+
+ it('gives the CLI one optional peer, Core, kept at "*" until the next minor', () => {
+ const cli = JSON.parse(
+ fs.readFileSync(path.join(ROOT, 'packages/cli/package.json'), 'utf8'),
+ );
+ expect(cli.peerDependencies).toEqual({'@astryxdesign/core': '*'});
+ expect(cli.peerDependenciesMeta).toEqual({
+ '@astryxdesign/core': {optional: true},
+ });
+ });
+
+ it('fails the check, naming the package, when a manifest drifts', () => {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-manifests-'));
+ roots.push(root);
+ const write = (dir, manifest) => {
+ fs.mkdirSync(path.join(root, dir), {recursive: true});
+ fs.writeFileSync(
+ path.join(root, dir, 'package.json'),
+ JSON.stringify(manifest),
+ );
+ };
+ write('packages/core', {name: '@astryxdesign/core', version: '0.7.9'});
+ write('packages/cli', {
+ name: '@astryxdesign/cli',
+ version: '0.7.9',
+ peerDependencies: {'@astryxdesign/theme-neutral': '*'},
+ });
+ write('packages/themes/neutral', {
+ name: '@astryxdesign/theme-neutral',
+ version: '0.7.9',
+ });
+ write('packages/themes/probe', {
+ name: '@astryxdesign/theme-probe',
+ version: '0.5.0',
+ private: true,
+ });
+ expect(releaseVersions(root).has('@astryxdesign/theme-probe')).toBe(false);
+ expect(releaseVersions(root).get('@astryxdesign/theme-neutral')).toBe(
+ '0.7.9',
+ );
+ const result = spawnSync(
+ process.execPath,
+ [path.join(ROOT, 'scripts/npm/published-manifests.mjs')],
+ {cwd: root, encoding: 'utf8'},
+ );
+ expect(result.status).toBe(1);
+ expect(result.stderr).toContain(
+ '@astryxdesign/cli: peerDependencies @astryxdesign/theme-neutral is "*"',
+ );
+ });
+});