Skip to content

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

TypeScript

fix(cli): name the scoped package in hints when the astryx bin is not installed (#7208)

Joey1afd1fcb44d7
diff --git a/.changeset/cli-hints-scoped-package.md b/.changeset/cli-hints-scoped-package.md
new file mode 100644
index 0000000000..5c9f1579fb
--- /dev/null
+++ b/.changeset/cli-hints-scoped-package.md
@@ -0,0 +1,12 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[fix] Printed commands name the scoped `@astryxdesign/cli` package whenever the `astryx` bin is not installed for the project
+@josephfarina
+
+- A hint uses `npx astryx …` (or `pnpm exec`, `yarn`, `bunx`) only when the `astryx` bin is in `node_modules/.bin`, in the project or a folder above it. Otherwise it prints `npx @astryxdesign/cli …` (`pnpm dlx`, `yarn dlx`, `bunx`), as it already did when the CLI ran from an npx or dlx cache.
+- A global install, or a workspace install used in a fresh package, used to print `npx astryx …`. The npm package named `astryx` is not this CLI, so following that hint fetched an unrelated package.
+- `astryx blog` follows the same rule, and the incident console template names the scoped package.
+
+Classification: contract-restoring. JSON shapes are unchanged; only hint text changes, and projects with the CLI installed keep `npx astryx …`.
diff --git a/.changeset/core-docs-scoped-cli.md b/.changeset/core-docs-scoped-cli.md
new file mode 100644
index 0000000000..4d79e572ee
--- /dev/null
+++ b/.changeset/core-docs-scoped-cli.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[docs] The README's CDN template command and the icon and token hints in the DropdownMenu item and Indicator docs name the scoped `npx @astryxdesign/cli`, which runs this CLI whether or not it is installed. Bare `npx astryx` fetches an unrelated npm package until the CLI is a dependency.
+@josephfarina
diff --git a/apps/docsite/src/content/blog/posts/astryx-v0-5-0.md b/apps/docsite/src/content/blog/posts/astryx-v0-5-0.md
index a94f431a5c..e0547a04c4 100644
--- a/apps/docsite/src/content/blog/posts/astryx-v0-5-0.md
+++ b/apps/docsite/src/content/blog/posts/astryx-v0-5-0.md
@@ -24,7 +24,7 @@ Every stable `@astryxdesign/*` package ships at the same version, so bump them a
Preview the migration first:
```bash
-npx astryx upgrade --from <your-version>
+npx @astryxdesign/cli upgrade --from <your-version>
```
That is a dry run. Add `--apply` to write the changes to disk.
diff --git a/packages/cli/assets/templates/pages/incident-console/page.tsx b/packages/cli/assets/templates/pages/incident-console/page.tsx
index 0410db28e2..7a649c7726 100644
--- a/packages/cli/assets/templates/pages/incident-console/page.tsx
+++ b/packages/cli/assets/templates/pages/incident-console/page.tsx
@@ -5,7 +5,7 @@
/**
* Incident Console — an on-call incident response tool.
*
- * Frame-first layout (see `npx astryx docs layout`), distilled from
+ * Frame-first layout (see `npx @astryxdesign/cli docs layout`), distilled from
* product-scale apps built with the design system:
*
* Frame: header | grouped incident rows (fill) | inspector 380 (resizable)
diff --git a/packages/cli/clients/cli/commands/blog.mjs b/packages/cli/clients/cli/commands/blog.mjs
index 6a0adf3ea5..1e5f036576 100644
--- a/packages/cli/clients/cli/commands/blog.mjs
+++ b/packages/cli/clients/cli/commands/blog.mjs
@@ -14,7 +14,7 @@
* astryx blog --json Structured list/detail envelope
*/
-import {getRunPrefix} from '../../../foundation/env/package-manager.mjs';
+import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
import {jsonOut} from '../../../foundation/response/json.mjs';
import {emit, section, text, record, records, code} from '../formatters/index.mjs';
import {cliError} from '../lib/cli-error.mjs';
@@ -43,7 +43,7 @@ export function registerBlog(program) {
defineCommand(program, blogCommand, {
fn: blogFn,
action: async (/** @type {string | undefined} */ slug) => {
- const run = getRunPrefix();
+ const run = getCliInvocation();
/** @type {import('../../../api/blog/blog.type.mjs').BlogListResponse | import('../../../api/blog/blog.type.mjs').BlogDetailResponse} */
let result;
try {
@@ -84,7 +84,7 @@ export function registerBlog(program) {
section('Astryx blog'),
record({feedUrl}),
records(posts, {fields: POST_FIELDS}),
- text(`Read one: ${run} astryx blog <slug>`),
+ text(`Read one: ${run} blog <slug>`),
);
} else {
// blog.detail — the post's fields and the feed URL, then the body
diff --git a/packages/cli/clients/cli/commands/docs.test.mjs b/packages/cli/clients/cli/commands/docs.test.mjs
index c3746f457e..f4a5abfe8b 100644
--- a/packages/cli/clients/cli/commands/docs.test.mjs
+++ b/packages/cli/clients/cli/commands/docs.test.mjs
@@ -113,7 +113,8 @@ describe('progressive reads', () => {
expect(status).toBe(0);
expect(stdout).toMatch(/^principles +\S/m);
expect(widest(stdout)).toBeLessThanOrEqual(120);
- expect(stdout).toContain('Usage: pnpm exec astryx docs <topic>');
+ // The repo root has no `astryx` bin, so the CLI names the scoped package.
+ expect(stdout).toMatch(/Usage: \S+(?: dlx)? (?:astryx|@astryxdesign\/cli) docs <topic>/);
}, SLOW);
it("prints a topic's section index with the keys to read by", async () => {
diff --git a/packages/cli/clients/cli/commands/doctor.test.mjs b/packages/cli/clients/cli/commands/doctor.test.mjs
index 7265e4d199..2d371ac93f 100644
--- a/packages/cli/clients/cli/commands/doctor.test.mjs
+++ b/packages/cli/clients/cli/commands/doctor.test.mjs
@@ -168,7 +168,23 @@ describe('doctor — individual checks', () => {
it('agent-docs: INFO when no docs present', () => {
const res = checkAgentDocs({cwd: tmpDir});
expect(res.status).toBe('info');
- expect(res.fix).toContain('astryx init');
+ expect(res.fix).toContain('init --features agents');
+ });
+
+ // The npm package named `astryx` is not this CLI: a project without the
+ // `astryx` bin gets the scoped package in the fix, one with it keeps the bin.
+ it('agent-docs: the fix names the scoped package when the project has no local CLI', () => {
+ fs.writeFileSync(path.join(tmpDir, 'package-lock.json'), '{}');
+ const res = checkAgentDocs({cwd: tmpDir});
+ expect(res.fix).toContain('`npx @astryxdesign/cli init --features agents`');
+ });
+
+ it('agent-docs: the fix keeps `npx astryx` when the project has a local CLI', () => {
+ fs.writeFileSync(path.join(tmpDir, 'package-lock.json'), '{}');
+ fs.mkdirSync(path.join(tmpDir, 'node_modules', '.bin'), {recursive: true});
+ fs.writeFileSync(path.join(tmpDir, 'node_modules', '.bin', 'astryx'), '');
+ const res = checkAgentDocs({cwd: tmpDir});
+ expect(res.fix).toContain('`npx astryx init --features agents`');
});
it('agent-docs: WARN when docs exist without XDS markers', () => {
diff --git a/packages/cli/clients/cli/commands/search.test.mjs b/packages/cli/clients/cli/commands/search.test.mjs
index f145389613..e411ad3095 100644
--- a/packages/cli/clients/cli/commands/search.test.mjs
+++ b/packages/cli/clients/cli/commands/search.test.mjs
@@ -53,7 +53,11 @@ function asText(value) {
* @param {unknown} value
*/
function printsField(lines, key, value) {
- const shown = asText(value).split('\n')[0].trimEnd();
+ // The text prefixes a command (`command`, `parent`) with the project's
+ // invocation (`pnpm exec astryx`, or `pnpm dlx @astryxdesign/cli` where no
+ // `astryx` bin is installed), so compare the part after `astryx`.
+ const text = asText(value).split('\n')[0].trimEnd();
+ const shown = text.replace(/^astryx /, '');
return lines.some(line => line.startsWith(`${key}:`) && line.trimEnd().endsWith(shown));
}
@@ -282,7 +286,7 @@ describe('search CLI — exit codes + JSON contract', () => {
it('renders each result as a greppable key: value record', async () => {
const r = await runCli(['search', 'button'], REPO_ROOT);
- expect(r.stdout).toContain('astryx component Button');
+ expect(r.stdout).toMatch(/^command:\s+\S.*(?:astryx|@astryxdesign\/cli) component Button$/m);
// Fields mirror the JSON object and are line-greppable.
expect(r.stdout).toMatch(/^name:\s+Button$/m);
expect(r.stdout).toMatch(/^domain:\s+component$/m);
diff --git a/packages/cli/clients/cli/commands/swizzle.routing.test.mjs b/packages/cli/clients/cli/commands/swizzle.routing.test.mjs
index 15ca52e914..ec246be890 100644
--- a/packages/cli/clients/cli/commands/swizzle.routing.test.mjs
+++ b/packages/cli/clients/cli/commands/swizzle.routing.test.mjs
@@ -305,7 +305,8 @@ describe('swizzle — StyleX build setup note (#3373)', () => {
expect(humanResult.stdout).toMatch(/StyleX compiler/i);
expect(humanResult.stdout).toMatch(/unstyled/i);
expect(humanResult.stdout).toMatch(/next\/font/i);
- expect(humanResult.stdout).toMatch(/astryx docs styling/);
+ // The fixture has no `astryx` bin installed, so the note names the scoped package.
+ expect(humanResult.stdout).toMatch(/@astryxdesign\/cli docs styling/);
});
it('does not print the StyleX note for components without StyleX', async () => {
diff --git a/packages/cli/clients/cli/commands/theme-add-lifecycle.test.mjs b/packages/cli/clients/cli/commands/theme-add-lifecycle.test.mjs
index e3d90885a2..7717beab97 100644
--- a/packages/cli/clients/cli/commands/theme-add-lifecycle.test.mjs
+++ b/packages/cli/clients/cli/commands/theme-add-lifecycle.test.mjs
@@ -7,6 +7,7 @@ import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import {runCli} from '../../../test-utils/run-cli.mjs';
+import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
let tmpDir;
@@ -35,10 +36,11 @@ describe('theme add compatibility lifecycle', () => {
expect(result.stderr.match(/source copying is deprecated/g)).toHaveLength(
1,
);
- expect(result.stderr).toContain('pnpm exec astryx theme eject neutral');
- expect(result.stderr).toContain(
- 'pnpm exec astryx theme add neutral --import',
- );
+ // The app has no CLI installed, so the commands name the scoped package.
+ const run = getCliInvocation(tmpDir);
+ expect(run).toMatch(/ @astryxdesign\/cli$/);
+ expect(result.stderr).toContain(`${run} theme eject neutral`);
+ expect(result.stderr).toContain(`${run} theme add neutral --import`);
expect(fs.existsSync(path.join(tmpDir, 'src/themes/neutral'))).toBe(true);
expect(fs.existsSync(path.join(tmpDir, 'src/astryx-themes.ts'))).toBe(
false,
@@ -77,11 +79,12 @@ describe('theme add compatibility lifecycle', () => {
const textResult = await runCli(['theme', 'add', '--list'], tmpDir);
expect(textResult.status, textResult.stderr).toBe(0);
+ const run = getCliInvocation(tmpDir);
expect(textResult.stdout).toContain(
- 'Import one: pnpm exec astryx theme add <slug> --import [--package <package>]',
+ `Import one: ${run} theme add <slug> --import [--package <package>]`,
);
expect(textResult.stdout).toContain(
- 'Fork source: pnpm exec astryx theme eject <slug> [target-path]',
+ `Fork source: ${run} theme eject <slug> [target-path]`,
);
expect(textResult.stdout).not.toContain('theme add <slug> [target-path]');
expect(textResult.stderr).not.toContain('deprecated');
diff --git a/packages/cli/clients/cli/commands/upgrade.config-ordering.test.mjs b/packages/cli/clients/cli/commands/upgrade.config-ordering.test.mjs
index 12f0b1200c..9a9819da11 100644
--- a/packages/cli/clients/cli/commands/upgrade.config-ordering.test.mjs
+++ b/packages/cli/clients/cli/commands/upgrade.config-ordering.test.mjs
@@ -187,8 +187,9 @@ describe('upgrade — core codemods run before config load', () => {
const out = await runHuman(['upgrade', '--from', '0.1.2', '--path', 'src']);
expect(out).toMatch(/fails strict validation/i);
+ // The fixture has no `astryx` bin installed, so the command names the scoped package.
expect(out).toContain(
- 'astryx upgrade --from 0.1.2 --codemod migrate-layout-components-to-experimental --apply',
+ '@astryxdesign/cli upgrade --from 0.1.2 --codemod migrate-layout-components-to-experimental --apply',
);
expect(exitCode).not.toBe(1);
});
diff --git a/packages/cli/clients/cli/lib/component-format.test.mjs b/packages/cli/clients/cli/lib/component-format.test.mjs
index 3756a2eb97..5bf87830b0 100644
--- a/packages/cli/clients/cli/lib/component-format.test.mjs
+++ b/packages/cli/clients/cli/lib/component-format.test.mjs
@@ -56,7 +56,7 @@ describe('formatFull sub-component rendering', () => {
expect(out).toContain('### XDSRadioListItem');
expect(out).not.toContain('undefined');
// Points the reader at the sub-component's own docs instead of a blank.
- expect(out).toContain('astryx component XDSRadioListItem');
+ expect(out).toMatch(/(?:astryx|@astryxdesign\/cli) component XDSRadioListItem/);
});
it('renders a full props table for a sub-component that has inline props', () => {
diff --git a/packages/cli/foundation/env/package-manager.mjs b/packages/cli/foundation/env/package-manager.mjs
index 453c80c7a0..7a00f16eee 100644
--- a/packages/cli/foundation/env/package-manager.mjs
+++ b/packages/cli/foundation/env/package-manager.mjs
@@ -6,7 +6,9 @@
* The order is: the `packageManager` field a project DECLARES, then the
* lockfiles it happens to have, then a committed package-manager config, then
* the runner that launched us. Returns the correct command prefix for running
- * package binaries (e.g. 'npx astryx', 'yarn astryx', 'pnpm exec astryx').
+ * package binaries (e.g. 'npx astryx', 'yarn astryx', 'pnpm exec astryx'), and
+ * the scoped one-off form ('npx @astryxdesign/cli') when the `astryx` bin does
+ * not resolve from the project.
*/
import * as fs from 'node:fs';
@@ -319,8 +321,8 @@ export function getDlxPrefix(targetDir) {
*
* We sniff the entry path (`process.argv[1]`) for well-known runner-cache
* markers. This errs safe in both directions: a false negative falls back to
- * the installed form (`<prefix> astryx`, the historical behavior), and a false
- * positive emits the always-valid scoped form (`<dlx> @astryxdesign/cli`).
+ * {@link getCliInvocation}'s on-disk check, and a false positive emits the
+ * always-valid scoped form (`<dlx> @astryxdesign/cli`).
*
* @returns {boolean}
*/
@@ -329,20 +331,57 @@ export function isCliOneOff() {
return /\/_npx\/|\/dlx[-/]|\/\.bun\/install\/cache\/|\/bunx-/.test(entry);
}
+/** The `astryx` bin as package managers link it, including the Windows shims. */
+const CLI_BIN_LINKS = [CLI_BIN, `${CLI_BIN}.cmd`, `${CLI_BIN}.ps1`];
+
+/**
+ * Does the bare `astryx` bin resolve from `targetDir`?
+ *
+ * A package runner finds an installed bin in `node_modules/.bin`, in the
+ * project or in a folder above it (a workspace root). When no such link
+ * exists, `npx astryx` and `bunx astryx` fetch the unrelated registry package
+ * named `astryx` instead of running this CLI, and `pnpm exec astryx` or
+ * `yarn astryx` fail. A global install, or a workspace install running in a
+ * fresh package, is exactly that case.
+ *
+ * A false negative (a layout without `node_modules/.bin`, such as Yarn Plug'n'Play)
+ * is safe: the caller suggests the scoped package, which always resolves.
+ *
+ * @param {string} [targetDir=process.cwd()]
+ * @returns {boolean}
+ */
+export function cliBinResolves(targetDir = process.cwd()) {
+ let dir = path.resolve(targetDir);
+ for (;;) {
+ const binDir = path.join(dir, 'node_modules', '.bin');
+ if (CLI_BIN_LINKS.some(name => fs.existsSync(path.join(binDir, name)))) {
+ return true;
+ }
+ const parent = path.dirname(dir);
+ if (parent === dir) return false;
+ dir = parent;
+ }
+}
+
/**
* The safe, install-aware CLI invocation stem to suggest to users.
*
- * - Installed / global / dev: `<run-prefix> astryx` (e.g. `pnpm exec astryx`).
- * Bare `astryx` resolves to the local (or global) binary.
- * - One-off (npx/dlx cache): `<dlx-prefix> @astryxdesign/cli` — the bare
- * `astryx` name isn't on disk, so npm would fetch an unrelated registry
- * package; the scoped package always resolves to us.
+ * - The `astryx` bin resolves from `targetDir`: `<run-prefix> astryx`
+ * (e.g. `pnpm exec astryx`).
+ * - Launched one-off (npx/dlx cache), or the bin does not resolve from
+ * `targetDir` (a global install, a fresh package in a workspace):
+ * `<dlx-prefix> @astryxdesign/cli`. The bare `astryx` name would make npm
+ * fetch an unrelated registry package; the scoped package always resolves
+ * to this CLI.
*
- * @param {string} [targetDir]
+ * @param {string} [targetDir] the project the printed command runs in;
+ * defaults to the working directory
* @returns {string}
*/
export function getCliInvocation(targetDir) {
- if (isCliOneOff()) return `${getDlxPrefix(targetDir)} ${CLI_PACKAGE}`;
+ if (isCliOneOff() || !cliBinResolves(targetDir)) {
+ return `${getDlxPrefix(targetDir)} ${CLI_PACKAGE}`;
+ }
return `${getRunPrefix(targetDir)} ${CLI_BIN}`;
}
diff --git a/packages/cli/foundation/env/package-manager.test.mjs b/packages/cli/foundation/env/package-manager.test.mjs
index 6ba445a259..a7ff957924 100644
--- a/packages/cli/foundation/env/package-manager.test.mjs
+++ b/packages/cli/foundation/env/package-manager.test.mjs
@@ -9,6 +9,7 @@ import {
explainPackageManager,
getDlxPrefix,
isCliOneOff,
+ cliBinResolves,
getCliInvocation,
formatCliCommand,
} from './package-manager.mjs';
@@ -31,6 +32,16 @@ function makeTmpDir() {
return tmpDir;
}
+/** Install the CLI's bin link in `dir`, the way a package manager does. */
+function linkCliBin(dir, name = 'astryx') {
+ const binDir = path.join(dir, 'node_modules', '.bin');
+ fs.mkdirSync(binDir, {recursive: true});
+ fs.writeFileSync(path.join(binDir, name), '');
+}
+
+/** An installed CLI's entry, outside any runner cache (a global or workspace install). */
+const INSTALLED_ENTRY = '/usr/local/lib/node_modules/@astryxdesign/cli/clients/cli/bin/astryx.mjs';
+
describe('detectPackageManager', () => {
it('detects yarn from yarn.lock', () => {
const dir = makeTmpDir();
@@ -79,6 +90,7 @@ describe('detectPackageManager', () => {
const dir = makeTmpDir();
fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
fs.writeFileSync(path.join(dir, 'yarn.lock'), '');
+ linkCliBin(dir);
process.env.npm_config_user_agent = 'yarn/1.22.21 npm/? node/v22.0.0';
expect(detectPackageManager(dir)).not.toBe('yarn');
expect(getCliInvocation(dir)).toBe('npx astryx');
@@ -90,6 +102,7 @@ describe('detectPackageManager', () => {
try {
fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
fs.writeFileSync(path.join(dir, 'yarn.lock'), '');
+ linkCliBin(dir);
process.env.npm_config_user_agent = 'yarn/1.22.21 npm/? node/v22.0.0';
process.argv[1] = path.join(dir, 'node_modules/.bin/astryx');
expect(getCliInvocation(dir)).toBe('npx astryx');
@@ -198,6 +211,7 @@ describe('detectPackageManager', () => {
path.join(dir, 'package.json'),
JSON.stringify({packageManager: '[email protected]'}),
);
+ linkCliBin(dir);
expect(detectPackageManager(dir)).toBe('pnpm');
expect(getCliInvocation(dir)).toBe('pnpm exec astryx');
});
@@ -351,14 +365,90 @@ describe('isCliOneOff', () => {
});
});
+describe('cliBinResolves', () => {
+ it('finds the bin link in the project', () => {
+ const dir = makeTmpDir();
+ linkCliBin(dir);
+ expect(cliBinResolves(dir)).toBe(true);
+ });
+
+ it('finds it in a folder above the project (a workspace root)', () => {
+ const root = makeTmpDir();
+ linkCliBin(root);
+ const pkg = path.join(root, 'packages', 'app');
+ fs.mkdirSync(pkg, {recursive: true});
+ expect(cliBinResolves(pkg)).toBe(true);
+ });
+
+ it('finds a Windows shim', () => {
+ const dir = makeTmpDir();
+ linkCliBin(dir, 'astryx.cmd');
+ expect(cliBinResolves(dir)).toBe(true);
+ });
+
+ it('is false when no bin link exists up the tree', () => {
+ const dir = makeTmpDir();
+ fs.mkdirSync(path.join(dir, 'node_modules', '.bin'), {recursive: true});
+ expect(cliBinResolves(dir)).toBe(false);
+ });
+});
+
describe('getCliInvocation', () => {
- it('uses the run-prefix + bare bin when installed (not one-off)', () => {
+ it('uses the run-prefix + bare bin when the bin resolves from the project', () => {
process.argv[1] = '/proj/node_modules/@astryxdesign/cli/bin/astryx.mjs';
const dir = makeTmpDir();
fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
+ linkCliBin(dir);
expect(getCliInvocation(dir)).toBe('pnpm exec astryx');
});
+ it('keeps `npx astryx` for a project with a local CLI', () => {
+ process.argv[1] = INSTALLED_ENTRY;
+ const dir = makeTmpDir();
+ fs.writeFileSync(path.join(dir, 'package-lock.json'), '{}');
+ linkCliBin(dir);
+ expect(getCliInvocation(dir)).toBe('npx astryx');
+ });
+
+ it('keeps the installed form in a workspace package when the root has the bin', () => {
+ process.argv[1] = INSTALLED_ENTRY;
+ const root = makeTmpDir();
+ fs.writeFileSync(path.join(root, 'pnpm-lock.yaml'), '');
+ linkCliBin(root);
+ const pkg = path.join(root, 'packages', 'app');
+ fs.mkdirSync(pkg, {recursive: true});
+ fs.writeFileSync(path.join(pkg, 'package.json'), '{"name":"app"}');
+ expect(getCliInvocation(pkg)).toBe('pnpm exec astryx');
+ });
+
+ // The hazard: the npm package named `astryx` is not this CLI. Launched from
+ // an installed path (a global install, or a workspace install running in a
+ // fresh package), the CLI used to print `npx astryx` for a project where that
+ // bin does not resolve, so following the hint fetched someone else's package.
+ it.each([
+ ['package-lock.json', '{}', 'npx @astryxdesign/cli'],
+ ['pnpm-lock.yaml', '', 'pnpm dlx @astryxdesign/cli'],
+ ['yarn.lock', '', 'yarn dlx @astryxdesign/cli'],
+ ['bun.lockb', '', 'bunx @astryxdesign/cli'],
+ ])(
+ 'prints the scoped package for a project with no local CLI (%s), launched from an installed path',
+ (lockfile, contents, expected) => {
+ process.argv[1] = INSTALLED_ENTRY;
+ const dir = makeTmpDir();
+ fs.writeFileSync(path.join(dir, lockfile), contents);
+ expect(isCliOneOff()).toBe(false);
+ expect(getCliInvocation(dir)).toBe(expected);
+ },
+ );
+
+ it('prints the scoped package for a fresh package with no lockfile or install', () => {
+ process.argv[1] = INSTALLED_ENTRY;
+ const dir = makeTmpDir();
+ delete process.env.npm_config_user_agent;
+ fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"fresh"}');
+ expect(getCliInvocation(dir)).toBe('npx @astryxdesign/cli');
+ });
+
it('uses the dlx runner + scoped package when run one-off', () => {
process.argv[1] = '/home/u/.npm/_npx/a1b2/node_modules/.bin/astryx';
const dir = makeTmpDir();
@@ -379,6 +469,7 @@ describe('formatCliCommand', () => {
process.argv[1] = '/proj/node_modules/@astryxdesign/cli/bin/astryx.mjs';
const dir = makeTmpDir();
fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
+ linkCliBin(dir);
expect(formatCliCommand('astryx component Button', dir)).toBe('pnpm exec astryx component Button');
});
@@ -386,6 +477,7 @@ describe('formatCliCommand', () => {
process.argv[1] = '/proj/node_modules/@astryxdesign/cli/bin/astryx.mjs';
const dir = makeTmpDir();
fs.writeFileSync(path.join(dir, 'package-lock.json'), '{}');
+ linkCliBin(dir);
expect(formatCliCommand('docs tokens', dir)).toBe('npx astryx docs tokens');
});
diff --git a/packages/cli/test/golden-reads.test.mjs b/packages/cli/test/golden-reads.test.mjs
index 7c8e061faa..023467ddb5 100644
--- a/packages/cli/test/golden-reads.test.mjs
+++ b/packages/cli/test/golden-reads.test.mjs
@@ -72,6 +72,10 @@ beforeAll(() => {
dependencies: {'@acme/kit': '^1.0.0'},
}),
);
+ // The consumer has the CLI installed, so the reads' hints run its `astryx`
+ // bin; a project without one gets the scoped package instead.
+ fs.mkdirSync(path.join(project, 'node_modules', '.bin'), {recursive: true});
+ fs.writeFileSync(path.join(project, 'node_modules', '.bin', 'astryx'), '');
write('package.json', JSON.stringify({name: '@acme/kit', version: '1.2.3'}));
write(
'astryx.integration.mjs',
diff --git a/packages/core/README.md b/packages/core/README.md
index 2d88444c75..f1c6d44bc0 100644
--- a/packages/core/README.md
+++ b/packages/core/README.md
@@ -261,7 +261,7 @@ The CLI writes this page for you, annotated and pinned to the version you have
installed:
```bash
-npx astryx template --cdn # writes cdn.template.html
+npx @astryxdesign/cli template --cdn # writes cdn.template.html
```
```html
diff --git a/packages/core/src/DropdownMenu/DropdownMenuCheckboxItem.doc.mjs b/packages/core/src/DropdownMenu/DropdownMenuCheckboxItem.doc.mjs
index b0d389588f..efbf99ee2a 100644
--- a/packages/core/src/DropdownMenu/DropdownMenuCheckboxItem.doc.mjs
+++ b/packages/core/src/DropdownMenu/DropdownMenuCheckboxItem.doc.mjs
@@ -24,7 +24,7 @@ export const docs = {
name: 'icon',
type: 'IconType',
description:
- 'Icon to display before the label. See `npx astryx docs icons` for valid semantic names.',
+ 'Icon to display before the label. See `npx @astryxdesign/cli docs icons` for valid semantic names.',
},
{
name: 'value',
diff --git a/packages/core/src/DropdownMenu/DropdownMenuCheckboxItem.tsx b/packages/core/src/DropdownMenu/DropdownMenuCheckboxItem.tsx
index aa6793adf5..aaa7fe78e5 100644
--- a/packages/core/src/DropdownMenu/DropdownMenuCheckboxItem.tsx
+++ b/packages/core/src/DropdownMenu/DropdownMenuCheckboxItem.tsx
@@ -93,7 +93,7 @@ export interface DropdownMenuCheckboxItemProps extends Omit<
description?: ReactNode;
/**
* Icon to display before the label. Accepts a semantic icon name (see
- * `npx astryx docs icons`) or a rendered node.
+ * `npx @astryxdesign/cli docs icons`) or a rendered node.
*/
icon?: ReactNode | IconType;
/**
diff --git a/packages/core/src/DropdownMenu/DropdownMenuRadioItem.doc.mjs b/packages/core/src/DropdownMenu/DropdownMenuRadioItem.doc.mjs
index d663848762..315769d4a2 100644
--- a/packages/core/src/DropdownMenu/DropdownMenuRadioItem.doc.mjs
+++ b/packages/core/src/DropdownMenu/DropdownMenuRadioItem.doc.mjs
@@ -43,7 +43,7 @@ export const docs = {
name: 'icon',
type: 'IconType',
description:
- 'Icon to display before the label. See `npx astryx docs icons` for valid semantic names.',
+ 'Icon to display before the label. See `npx @astryxdesign/cli docs icons` for valid semantic names.',
},
{
name: 'isDisabled',
diff --git a/packages/core/src/DropdownMenu/DropdownMenuRadioItem.tsx b/packages/core/src/DropdownMenu/DropdownMenuRadioItem.tsx
index 8e6c2dad1a..5e9cb08015 100644
--- a/packages/core/src/DropdownMenu/DropdownMenuRadioItem.tsx
+++ b/packages/core/src/DropdownMenu/DropdownMenuRadioItem.tsx
@@ -93,7 +93,7 @@ export interface DropdownMenuRadioItemProps extends Omit<
description?: ReactNode;
/**
* Icon to display before the label. Accepts a semantic icon name (see
- * `npx astryx docs icons`) or a rendered node.
+ * `npx @astryxdesign/cli docs icons`) or a rendered node.
*/
icon?: ReactNode | IconType;
/**
diff --git a/packages/core/src/Indicator/Indicator.doc.mjs b/packages/core/src/Indicator/Indicator.doc.mjs
index 8096466788..e49310afe3 100644
--- a/packages/core/src/Indicator/Indicator.doc.mjs
+++ b/packages/core/src/Indicator/Indicator.doc.mjs
@@ -191,7 +191,7 @@ defineTheme({
code: `// When the shape itself is wrong, hand the theme a component. It receives
// {state, size, isDisabled, children} and nothing else.
//
-// Use theme tokens, never raw values — run \`npx astryx docs tokens\` for the
+// Use theme tokens, never raw values — run \`npx @astryxdesign/cli docs tokens\` for the
// full set. Color: --color-accent, --color-on-accent, --color-border,
// --color-border-emphasized, --color-background-surface,
// --color-background-muted. Radius: --radius-inner, --radius-full.
@@ -256,7 +256,7 @@ defineTheme({name: 'brand', indicators: {check: RadioIndicator}});`,
{
guidance: true,
description:
- 'Use theme tokens for every color, radius, and border width in a replacement. Run `npx astryx docs tokens` for the set.',
+ 'Use theme tokens for every color, radius, and border width in a replacement. Run `npx @astryxdesign/cli docs tokens` for the set.',
},
{
guidance: true,
@@ -302,7 +302,7 @@ export const docsDense = {
{ guidance: true, description: "Prefer the canonical `components['checkbox-indicator']` override first. Replacing the component is the heavier path, for when the shape itself is wrong." },
{ guidance: true, description: 'Match the shipped replacement-content branch with `isRenderable(children)`, not `children != null` or `children ?? mark`. The helper is shallow: it excludes nullish values, booleans, and the empty string, while React elements and containers take the replacement path even when their descendants render nothing. The owner passes `children={isBusy && <Spinner/>}`, so a nullish check deletes the state mark whenever the value is `false` (#4893).' },
{ guidance: true, description: 'A replacement must set aria-hidden. The owner supplies role and accessible name; a visible indicator would be announced twice.' },
- { guidance: true, description: 'Use theme tokens for every color, radius, and border width in a replacement. Run `npx astryx docs tokens` for the set.' },
+ { guidance: true, description: 'Use theme tokens for every color, radius, and border width in a replacement. Run `npx @astryxdesign/cli docs tokens` for the set.' },
{ guidance: true, description: 'Render a single root ELEMENT with the border-radius the focus ring should follow. The owner paints the standard ring onto the indicator at focus time (useIndicatorFocusRing) and outline picks up its radius; the ring is never missing (WCAG 2.4.7), only mis-shaped if the root lacks a radius. Do not draw a focus ring yourself.' },
{ guidance: false, description: 'Thread hover or pressed state in as props. Interaction state reaches an indicator through the owner\'s CSS ancestor marker.' },
{ guidance: false, description: 'Assume you are only mounted when selected. The host renders the indicator unconditionally and passes `state` in every state; that is what lets a replacement draw where the default draws nothing (a radio\'s empty circle on an unchosen row).' },