Skip to content

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

TypeScript

fix(cli): themes and section ids need CLI 0.6.4, not 0.7.0 (#6949)

Joey2ad3b835a2a5
diff --git a/.changeset/theme-and-section-id-cli-floor.md b/.changeset/theme-and-section-id-cli-floor.md
new file mode 100644
index 0000000000..9f96ef11b7
--- /dev/null
+++ b/.changeset/theme-and-section-id-cli-floor.md
@@ -0,0 +1,9 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[fix] A package that ships a theme or a doc section `id` needs `@astryxdesign/cli` 0.6.4, not 0.7.0.
+
+Published 0.6.4 reads typed theme descriptors and section ids; 0.6.3 rejects both and hides the package's themes or doc topics. The 0.6.5 notes said a stable CLI before 0.7.0 rejects them, so `integration add theme` wrote `"@astryxdesign/cli": ">=0.7.0"`, a range no released CLI satisfies, and `integration verify` failed a theme or section-id package whose CLI peer started at 0.6.4. `integration add theme` now writes `">=0.6.4"`, marked optional, and `integration verify` accepts it for themes and section ids. A namespace doc, a placed guide, and a template that sets `replaces` still need `">=0.7.0"`.
+
+@josephfarina
diff --git a/packages/cli/api/integration/add-theme.mjs b/packages/cli/api/integration/add-theme.mjs
index 0e0031b694..d26fba974a 100644
--- a/packages/cli/api/integration/add-theme.mjs
+++ b/packages/cli/api/integration/add-theme.mjs
@@ -25,8 +25,9 @@ import {loadManifestObject} from '../../foundation/integrations/integrations.mjs
import {themeDescriptorSource} from '../../foundation/integrations/theme-descriptor.mjs';
import {assertContributionVisible} from '../../foundation/integrations/contribution-inventory.mjs';
import {
+ THEMES_CLI,
themesCliProblem,
- withDocsTreeCli,
+ withCliPeer,
} from '../../foundation/integrations/cli-requirement.mjs';
import {
applyWrites,
@@ -253,7 +254,7 @@ export async function integrationAddTheme(name, options = {}) {
if (themesCliProblem(current) != null) {
packageUpdate = {
contents:
- JSON.stringify(withDocsTreeCli(current), null, 2) +
+ JSON.stringify(withCliPeer(current, THEMES_CLI), null, 2) +
(text.endsWith('\n') ? '\n' : ''),
expectedOriginal,
};
diff --git a/packages/cli/api/integration/add-theme.test.mjs b/packages/cli/api/integration/add-theme.test.mjs
index e36602d522..d64444bb5b 100644
--- a/packages/cli/api/integration/add-theme.test.mjs
+++ b/packages/cli/api/integration/add-theme.test.mjs
@@ -84,7 +84,7 @@ describe('integrationAddTheme', () => {
const pkg = JSON.parse(
fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
);
- expect(pkg.peerDependencies).toEqual({'@astryxdesign/cli': '>=0.7.0'});
+ expect(pkg.peerDependencies).toEqual({'@astryxdesign/cli': '>=0.6.4'});
expect(pkg.peerDependenciesMeta).toEqual({
'@astryxdesign/cli': {optional: true},
});
diff --git a/packages/cli/api/integration/pack-check.mjs b/packages/cli/api/integration/pack-check.mjs
index 38a343776d..3ed753abef 100644
--- a/packages/cli/api/integration/pack-check.mjs
+++ b/packages/cli/api/integration/pack-check.mjs
@@ -663,7 +663,7 @@ export async function integrationPackCheck(options = {}) {
])
) {
// A section `id` is also a field an older CLI rejects, hiding the
- // package's doc topics; the same peer range fixes both.
+ // package's doc topics. It needs an older CLI than the docs tree does.
const idProblem = sectionIdsCliProblem(pkg);
if (idProblem != null) {
issues.push(error('section_ids_need_cli', idProblem));
diff --git a/packages/cli/api/integration/pack-check.test.mjs b/packages/cli/api/integration/pack-check.test.mjs
index 7144a88f4b..8806626ff4 100644
--- a/packages/cli/api/integration/pack-check.test.mjs
+++ b/packages/cli/api/integration/pack-check.test.mjs
@@ -37,7 +37,7 @@ function writePackage({
} = {}) {
const pkg = {name, version};
// A theme needs a CLI that reads typed theme descriptors.
- if (themes) pkg.peerDependencies = {'@astryxdesign/cli': '>=0.7.0'};
+ if (themes) pkg.peerDependencies = {'@astryxdesign/cli': '>=0.6.4'};
if (files !== undefined) pkg.files = files;
if (scripts !== undefined) pkg.scripts = scripts;
fs.writeFileSync(
@@ -118,6 +118,14 @@ describe('integrationPackCheck', () => {
expect(old.data.issues).toContainEqual(
expect.objectContaining({code: 'themes_need_cli'}),
);
+
+ // Published 0.6.4 reads typed theme descriptors.
+ pkg.peerDependencies = {'@astryxdesign/cli': '>=0.6.4'};
+ fs.writeFileSync(pkgFile, `${JSON.stringify(pkg, null, 2)}\n`);
+ const current = await integrationPackCheck({cwd: tmpDir});
+ expect(current.data.issues).not.toContainEqual(
+ expect.objectContaining({code: 'themes_need_cli'}),
+ );
});
it('fails when a theme entry omits its inferred runtime export', async () => {
@@ -421,7 +429,11 @@ describe('integrationPackCheck', () => {
expect(await codes()).toContain('section_ids_need_cli');
const pkgFile = path.join(tmpDir, 'package.json');
const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf-8'));
- pkg.peerDependencies = {'@astryxdesign/cli': '>=0.7.0'};
+ pkg.peerDependencies = {'@astryxdesign/cli': '^0.6.3'};
+ fs.writeFileSync(pkgFile, `${JSON.stringify(pkg, null, 2)}\n`);
+ expect(await codes()).toContain('section_ids_need_cli');
+ // Published 0.6.4 reads a section id.
+ pkg.peerDependencies = {'@astryxdesign/cli': '>=0.6.4'};
fs.writeFileSync(pkgFile, `${JSON.stringify(pkg, null, 2)}\n`);
expect(await codes()).not.toContain('section_ids_need_cli');
}, 120_000);
diff --git a/packages/cli/assets/docs/tree/add-a-topic.doc.mjs b/packages/cli/assets/docs/tree/add-a-topic.doc.mjs
index 6edd4e39b4..b7342f2e9d 100644
--- a/packages/cli/assets/docs/tree/add-a-topic.doc.mjs
+++ b/packages/cli/assets/docs/tree/add-a-topic.doc.mjs
@@ -64,7 +64,7 @@ export const docs = {
style: 'unordered',
items: [
'Content blocks are `prose`, `code`, `list`, and `table`, as shown; `heading`, with a `level` from 3 to 6 and a `text`; and `token-ref`, which inlines a token table from another topic.',
- '`id` is optional: a stable key for the section. Without it, the key comes from the title. A stable CLI before 0.7.0 cannot read `id`; see {@link generic:versioning}.',
+ '`id` is optional: a stable key for the section. Without it, the key comes from the title. A stable CLI before 0.6.4 cannot read `id`; see {@link generic:versioning}.',
'Replace the `Overview` placeholder that `integration add` writes. Every field is in {@link generic:authoring}.',
],
},
diff --git a/packages/cli/assets/docs/tree/check-your-docs.doc.mjs b/packages/cli/assets/docs/tree/check-your-docs.doc.mjs
index 50ac6f94e6..db05e652e1 100644
--- a/packages/cli/assets/docs/tree/check-your-docs.doc.mjs
+++ b/packages/cli/assets/docs/tree/check-your-docs.doc.mjs
@@ -110,7 +110,7 @@ export const docs = {
content: [
{
type: 'prose',
- text: '`integration verify` fails a package that ships a docs section, a placed guide, or a doc section with an `id` without an `@astryxdesign/cli` peer of `>=0.7.0`. It does not run the docs check, so run both.',
+ text: '`integration verify` fails a package that ships a docs section or a placed guide without an `@astryxdesign/cli` peer of `>=0.7.0`, or a doc section with an `id` without one of `>=0.6.4`. It does not run the docs check, so run both.',
},
{
type: 'code',
diff --git a/packages/cli/assets/docs/tree/checks.doc.mjs b/packages/cli/assets/docs/tree/checks.doc.mjs
index e0c0dae122..a22a0a5a4e 100644
--- a/packages/cli/assets/docs/tree/checks.doc.mjs
+++ b/packages/cli/assets/docs/tree/checks.doc.mjs
@@ -106,7 +106,7 @@ export const docs = {
'It checks that every contribution file is in the `.tgz` file. A root missing from `files` fails with `Add "templates" to "files" in package.json.`',
'It lists the components, templates, themes, docs, and codemods the temporary app sees, and compares them with your source.',
"It resolves each component's `import`, and each template's public import, the way Node does, and checks that the module exports the component, or a default export for a template.",
- 'It fails a package that ships a docs section, a placed guide, a template `replaces`, a doc section with an `id`, or a theme without an `@astryxdesign/cli` peer of `>=0.7.0`.',
+ 'It fails a package that needs an `@astryxdesign/cli` peer and lacks it: `>=0.7.0` for a docs section, a placed guide, or a template `replaces`, and `>=0.6.4` for a doc section with an `id` or a theme.',
],
},
{
diff --git a/packages/cli/assets/docs/tree/define-the-theme.doc.mjs b/packages/cli/assets/docs/tree/define-the-theme.doc.mjs
index 25b0a7b0f2..7c99cd0c5d 100644
--- a/packages/cli/assets/docs/tree/define-the-theme.doc.mjs
+++ b/packages/cli/assets/docs/tree/define-the-theme.doc.mjs
@@ -106,7 +106,7 @@ export const oceanContrastTheme = defineTheme({
lang: 'json',
code: `"peerDependencies": {
"@astryxdesign/core": "^0.7.0",
- "@astryxdesign/cli": ">=0.7.0"
+ "@astryxdesign/cli": ">=0.6.4"
},
"peerDependenciesMeta": {
"@astryxdesign/cli": {"optional": true}
diff --git a/packages/cli/assets/docs/tree/troubleshooting.doc.mjs b/packages/cli/assets/docs/tree/troubleshooting.doc.mjs
index 34ec5e751a..fc6cd21c34 100644
--- a/packages/cli/assets/docs/tree/troubleshooting.doc.mjs
+++ b/packages/cli/assets/docs/tree/troubleshooting.doc.mjs
@@ -95,11 +95,11 @@ export const docs = {
],
[
'`themes_need_cli`: The package ships a theme but declares no @astryxdesign/cli peer.',
- 'Same fix: an older CLI cannot read typed theme descriptors, so it drops your themes and can hide your doc topics.',
+ "Run `npm pkg set 'peerDependencies.@astryxdesign/cli=>=0.6.4'` and `npm pkg set 'peerDependenciesMeta.@astryxdesign/cli.optional=true' --json`. A stable CLI before 0.6.4 cannot read typed theme descriptors, so it drops your themes and can hide your doc topics.",
],
[
'`section_ids_need_cli`: The package has a doc section that sets `id` but declares no @astryxdesign/cli peer.',
- 'Same fix, or drop the section `id`s: an older CLI rejects them and hides your doc topics.',
+ 'The same fix as `themes_need_cli`, or drop the section `id`s: a stable CLI before 0.6.4 rejects them and hides your doc topics.',
],
],
},
@@ -135,7 +135,7 @@ export const docs = {
],
[
'Your docs section, templates, or themes are missing only in some apps',
- 'Those apps run a stable CLI before 0.7.0. Update `@astryxdesign/cli` there, and keep your optional `@astryxdesign/cli` peer so npm warns about an old CLI.',
+ 'Those apps run a CLI too old to read them: a stable CLI before 0.7.0 for a docs section or a template that sets `replaces`, or before 0.6.4 for a theme. Update `@astryxdesign/cli` there, and keep your optional `@astryxdesign/cli` peer so npm warns about an old CLI.',
],
],
},
diff --git a/packages/cli/assets/docs/tree/versioning.doc.mjs b/packages/cli/assets/docs/tree/versioning.doc.mjs
index 6493de4def..5b8cd88bfe 100644
--- a/packages/cli/assets/docs/tree/versioning.doc.mjs
+++ b/packages/cli/assets/docs/tree/versioning.doc.mjs
@@ -107,7 +107,7 @@ export const docs = {
[
'`@astryxdesign/cli`',
'You ship a docs section, a placed guide, a template that sets `replaces`, a doc section with an `id`, or a theme',
- '`>=0.7.0`, optional in `peerDependenciesMeta`',
+ '`>=0.7.0` for a docs section, a placed guide, or `replaces`; `>=0.6.4` when you ship only a theme or a section `id`. Optional in `peerDependenciesMeta`',
],
],
},
@@ -118,7 +118,7 @@ export const docs = {
},
{
type: 'prose',
- text: '`integration verify` fails a package that needs the CLI peer and lacks it, or whose range admits a stable CLI before 0.7.0. `integration add doc --parent` and `integration add theme` write the peer for you.',
+ text: '`integration verify` fails a package that needs the CLI peer and lacks it, or whose range admits a stable CLI too old for what it ships. `integration add doc --parent` and `integration add theme` write the peer for you.',
},
],
},
@@ -137,13 +137,14 @@ export const docs = {
'An unknown field in `astryx.integration.mjs` is ignored with an `unknown_manifest_key` warning, and the rest of the manifest still loads.',
'A named export that the CLI does not know is ignored with no warning, so `debug` and `gapReport` are safe to add.',
'A stable CLI before 0.7.0 prints each `{@link ...}` as written.',
- 'A stable CLI before 0.7.0 cannot read a docs section, a section `id`, a template that sets `replaces`, or a theme folder that `integration add theme` writes. It can then hide every doc topic your package ships.',
+ 'A stable CLI before 0.7.0 cannot read a docs section or a template that sets `replaces`. It can then hide every doc topic your package ships.',
+ 'A stable CLI before 0.6.4 cannot read a section `id` or a theme folder that `integration add theme` writes. It can then hide every doc topic your package ships.',
'Stable 0.6.3 still loads your components, but 0.6.0 cannot read the component docs that `integration add component` writes: `component AcmeCarousel` fails there.',
],
},
{
type: 'prose',
- text: '`integration verify` requires the CLI peer for a docs section, a placed guide, a template `replaces`, a doc section with an `id`, and a theme. A stable CLI before 0.7.0 cannot read any of them, and when it hides your topics, `docs` gives no warning.',
+ text: '`integration verify` requires the CLI peer for a docs section, a placed guide, a template `replaces`, a doc section with an `id`, and a theme. A CLI too old for one of them cannot read it, and when it hides your topics, `docs` gives no warning.',
},
],
},
diff --git a/packages/cli/foundation/integrations/cli-requirement.mjs b/packages/cli/foundation/integrations/cli-requirement.mjs
index b70ac949dd..90370b927d 100644
--- a/packages/cli/foundation/integrations/cli-requirement.mjs
+++ b/packages/cli/foundation/integrations/cli-requirement.mjs
@@ -1,11 +1,13 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.
/**
- * @file The CLI an integration's namespace docs need (spec:AST-046 FR11).
+ * @file The CLI release an integration's newer contributions need
+ * (spec:AST-046 FR11).
*
* @input A package.json object.
* @output Whether its `peerDependencies` range for `@astryxdesign/cli` admits
- * only CLIs that read namespace docs, and the package.json that declares it.
+ * only CLIs that read what the package ships, and the package.json that
+ * declares that range.
* @position foundation/integrations; read by `integration add doc --parent`
* and `integration add theme`, which declare the peer, and
* `integration verify`, which requires it.
@@ -17,15 +19,28 @@ export const CLI_PACKAGE = '@astryxdesign/cli';
/**
* The first CLI release that reads an integration's docs tree (namespace docs
- * and placed guides), its templates' `replaces`, and its typed theme
- * descriptors. A release before it can hide every doc topic a package with a
- * namespace doc or a placed guide ships, with no warning; it rejects
- * `replaces`, drops that template, and hides the package's doc topics; and it
- * rejects a themes root without the `manifest.json` catalog the CLI no longer
- * writes, withholding the package's themes and doc topics.
+ * and placed guides) and its templates' `replaces`. A release before it can
+ * hide every doc topic a package with a namespace doc or a placed guide ships,
+ * with no warning; and it rejects `replaces`, drops that template, and hides
+ * the package's doc topics.
*/
export const DOCS_TREE_CLI = '0.7.0';
+/**
+ * The first stable CLI release that reads typed theme descriptors, the theme
+ * folder `integration add theme` writes. Published 0.6.3 rejects a themes root
+ * with no `manifest.json` catalog and withholds the package's themes and doc
+ * topics; published 0.6.4 lists the themes.
+ */
+export const THEMES_CLI = '0.6.4';
+
+/**
+ * The first stable CLI release that reads a doc section's `id`. Published
+ * 0.6.3 rejects the field and hides every doc topic the package ships;
+ * published 0.6.4 reads the section by its id.
+ */
+export const SECTION_IDS_CLI = '0.6.4';
+
const VERSION_RE = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
/**
@@ -89,17 +104,26 @@ export function lowestAdmitted(range) {
* @param {any} pkg package.json
* @param {string} feature what the package does, e.g. "ships a namespace doc"
* @param {string} loss what an older CLI does with it
+ * @param {string} [floor] the first stable CLI release that reads it; the
+ * docs tree's by default, so a caller that names none keeps the strictest
+ * floor
* @returns {string | null}
*/
-function cliRangeProblem(pkg, feature, loss) {
+export function cliRangeProblem(pkg, feature, loss, floor = DOCS_TREE_CLI) {
+ // A floor that is not a version means the arguments are out of order, as
+ // after a merge with a caller written for another parameter order. Fail
+ // loudly rather than compare a range against feature text.
+ if (lowerVersion(floor) == null) {
+ throw new TypeError(`cliRangeProblem: floor "${floor}" is not a version`);
+ }
const range = pkg?.peerDependencies?.[CLI_PACKAGE];
- const fix = `"${CLI_PACKAGE}": ">=${DOCS_TREE_CLI}" in peerDependencies (optional in peerDependenciesMeta, if the CLI is not required)`;
+ const fix = `"${CLI_PACKAGE}": ">=${floor}" in peerDependencies (optional in peerDependenciesMeta, if the CLI is not required)`;
if (typeof range !== 'string') {
- return `The package ${feature} but declares no ${CLI_PACKAGE} peer. A stable CLI before ${DOCS_TREE_CLI} ${loss}. Declare ${fix}.`;
+ return `The package ${feature} but declares no ${CLI_PACKAGE} peer. A stable CLI before ${floor} ${loss}. Declare ${fix}.`;
}
const lowest = lowestAdmitted(range);
- if (lowest == null || semverCompare(lowest, DOCS_TREE_CLI) < 0) {
- return `The package ${feature}, but its ${CLI_PACKAGE} peer range "${range}" admits a stable CLI before ${DOCS_TREE_CLI}, which ${loss}. Declare ${fix}.`;
+ if (lowest == null || semverCompare(lowest, floor) < 0) {
+ return `The package ${feature}, but its ${CLI_PACKAGE} peer range "${range}" admits a stable CLI before ${floor}, which ${loss}. Declare ${fix}.`;
}
return null;
}
@@ -118,6 +142,7 @@ export function docsTreeCliProblem(pkg) {
pkg,
'ships a namespace doc or a placed guide',
'does not read the docs tree, and can hide every doc topic the package ships',
+ DOCS_TREE_CLI,
);
}
@@ -133,6 +158,7 @@ export function replacesCliProblem(pkg) {
pkg,
'has a template that sets `replaces`',
"rejects the field, drops that template, and hides the package's doc topics",
+ DOCS_TREE_CLI,
);
}
@@ -140,7 +166,7 @@ export function replacesCliProblem(pkg) {
* Why a package with a doc section that sets `id` would lose its doc topics on
* an older CLI, or null when its declared CLI range admits only CLIs that read
* the field. Published 0.6.3 rejects a section `id` and hides every doc topic
- * the package ships.
+ * the package ships; published 0.6.4 reads it.
* @param {any} pkg package.json
* @returns {string | null}
*/
@@ -149,6 +175,7 @@ export function sectionIdsCliProblem(pkg) {
pkg,
'has a doc section that sets `id`',
'rejects the field, and can hide every doc topic the package ships',
+ SECTION_IDS_CLI,
);
}
@@ -156,7 +183,8 @@ export function sectionIdsCliProblem(pkg) {
* Why a package that ships a theme would lose its themes and doc topics on an
* older CLI, or null when its declared CLI range admits only CLIs that read
* typed theme descriptors. Published 0.6.3 rejects a themes root with no
- * `manifest.json` catalog, which `integration add theme` no longer writes.
+ * `manifest.json` catalog, which `integration add theme` no longer writes;
+ * published 0.6.4 reads the descriptors.
* @param {any} pkg package.json
* @returns {string | null}
*/
@@ -165,25 +193,37 @@ export function themesCliProblem(pkg) {
pkg,
'ships a theme',
"cannot read typed theme descriptors, and can drop the package's themes and hide its doc topics",
+ THEMES_CLI,
);
}
/**
- * The package.json with a CLI peer that reads namespace docs: optional, unless
- * the package already says otherwise.
+ * The package.json with a CLI peer of `>=floor`: optional, unless the package
+ * already says otherwise. Call it only when the package's range admits a CLI
+ * before `floor`, so a stricter range is never lowered.
* @param {any} pkg package.json
+ * @param {string} floor the first stable CLI release the package needs
* @returns {any}
*/
-export function withDocsTreeCli(pkg) {
+export function withCliPeer(pkg, floor) {
const meta = pkg.peerDependenciesMeta ?? {};
return {
...pkg,
peerDependencies: {
...(pkg.peerDependencies ?? {}),
- [CLI_PACKAGE]: `>=${DOCS_TREE_CLI}`,
+ [CLI_PACKAGE]: `>=${floor}`,
},
peerDependenciesMeta: meta[CLI_PACKAGE]
? meta
: {...meta, [CLI_PACKAGE]: {optional: true}},
};
}
+
+/**
+ * The package.json with a CLI peer that reads namespace docs.
+ * @param {any} pkg package.json
+ * @returns {any}
+ */
+export function withDocsTreeCli(pkg) {
+ return withCliPeer(pkg, DOCS_TREE_CLI);
+}
diff --git a/packages/cli/foundation/integrations/cli-requirement.test.mjs b/packages/cli/foundation/integrations/cli-requirement.test.mjs
index 54f24cbf20..38b4307bb6 100644
--- a/packages/cli/foundation/integrations/cli-requirement.test.mjs
+++ b/packages/cli/foundation/integrations/cli-requirement.test.mjs
@@ -1,11 +1,19 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.
+import fs from 'node:fs';
import {describe, expect, it} from 'vitest';
+import {semverCompare} from '../env/semver.mjs';
import {
DOCS_TREE_CLI,
+ SECTION_IDS_CLI,
+ cliRangeProblem,
+ THEMES_CLI,
lowestAdmitted,
docsTreeCliProblem,
replacesCliProblem,
+ sectionIdsCliProblem,
+ themesCliProblem,
+ withCliPeer,
withDocsTreeCli,
} from './cli-requirement.mjs';
@@ -87,3 +95,71 @@ describe('replacesCliProblem', () => {
).toBeNull();
});
});
+
+describe('themesCliProblem and sectionIdsCliProblem', () => {
+ // Published 0.6.4 reads typed theme descriptors and section ids. Published
+ // 0.6.3 rejects both and hides the package's doc topics.
+ it.each([
+ ['a theme', themesCliProblem, 'ships a theme'],
+ ['a section id', sectionIdsCliProblem, 'sets `id`'],
+ ])('asks for a CLI from 0.6.4 for %s', (_name, problem, feature) => {
+ expect(problem({name: '@acme/kit'})).toContain(feature);
+ expect(problem({name: '@acme/kit'})).toContain('A stable CLI before 0.6.4');
+ for (const range of ['>=0.6.4', '^0.6.4', '>=0.6.5', '>=0.7.0']) {
+ expect(
+ problem({peerDependencies: {'@astryxdesign/cli': range}}),
+ ).toBeNull();
+ }
+ for (const range of ['^0.6.0', '>=0.6.3', '*']) {
+ expect(
+ problem({peerDependencies: {'@astryxdesign/cli': range}}),
+ ).toContain('admits a stable CLI before 0.6.4');
+ }
+ });
+
+ it('keeps 0.7.0 for the docs tree and for replaces', () => {
+ const pkg = {peerDependencies: {'@astryxdesign/cli': '>=0.6.4'}};
+ expect(docsTreeCliProblem(pkg)).toContain(
+ 'admits a stable CLI before 0.7.0',
+ );
+ expect(replacesCliProblem(pkg)).toContain(
+ 'admits a stable CLI before 0.7.0',
+ );
+ });
+
+ it('names a released CLI for a feature that already shipped', () => {
+ const {version} = JSON.parse(
+ fs.readFileSync(new URL('../../package.json', import.meta.url), 'utf-8'),
+ );
+ for (const floor of [THEMES_CLI, SECTION_IDS_CLI]) {
+ expect(semverCompare(floor, version.split('-')[0])).toBeLessThanOrEqual(
+ 0,
+ );
+ }
+ });
+
+ it('declares the floor a theme needs as an optional peer', () => {
+ const declared = withCliPeer({name: '@acme/kit'}, THEMES_CLI);
+ expect(declared.peerDependencies).toEqual({
+ '@astryxdesign/cli': '>=0.6.4',
+ });
+ expect(declared.peerDependenciesMeta).toEqual({
+ '@astryxdesign/cli': {optional: true},
+ });
+ expect(themesCliProblem(declared)).toBeNull();
+ });
+});
+
+describe('cliRangeProblem', () => {
+ it('uses the docs-tree floor when a caller names none', () => {
+ expect(
+ cliRangeProblem({name: '@acme/kit'}, 'ships x', 'drops x'),
+ ).toContain('A stable CLI before 0.7.0');
+ });
+
+ it('fails loudly when the floor is not a version', () => {
+ expect(() =>
+ cliRangeProblem({name: '@acme/kit'}, '0.6.4', 'ships x', 'drops x'),
+ ).toThrow(TypeError);
+ });
+});