@astryxdesign/cli 0.6.3-canary.f839b67 → 0.6.4-canary.06c8fa3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +194 -0
- package/README.md +64 -66
- package/api/component/_adapter.d.mts +25 -0
- package/api/component/_adapter.mjs +59 -5
- package/api/component/component.d.mts +6 -3
- package/api/component/component.doc.mjs +23 -10
- package/api/component/component.mjs +249 -9
- package/api/component/component.type.d.mts +25 -0
- package/api/component/component.type.mjs +44 -0
- package/api/discover/_adapter.d.mts +114 -6
- package/api/discover/_adapter.mjs +372 -17
- package/api/discover/_adapter.test.mjs +215 -0
- package/api/discover/_catalog-view.d.mts +115 -0
- package/api/discover/_catalog-view.mjs +203 -0
- package/api/discover/_catalog-view.test.mjs +128 -0
- package/api/discover/detail/detail.d.mts +18 -6
- package/api/discover/detail/detail.mjs +67 -13
- package/api/discover/detail/detail.test.mjs +85 -0
- package/api/discover/detail/item/item.d.mts +26 -0
- package/api/discover/detail/item/item.mjs +78 -0
- package/api/discover/detail/item/item.test.mjs +73 -0
- package/api/discover/discover.d.mts +3 -9
- package/api/discover/discover.doc.mjs +61 -18
- package/api/discover/discover.mjs +220 -36
- package/api/discover/discover.test.mjs +11 -2
- package/api/discover/discover.type.d.mts +147 -8
- package/api/discover/discover.type.mjs +102 -12
- package/api/discover/list/list.d.mts +20 -6
- package/api/discover/list/list.mjs +45 -12
- package/api/discover/list/list.test.mjs +46 -0
- package/api/discover/search/search.d.mts +18 -16
- package/api/discover/search/search.mjs +102 -56
- package/api/discover/search/search.test.mjs +144 -10
- package/api/docs/_adapter.d.mts +49 -7
- package/api/docs/_adapter.mjs +284 -33
- package/api/docs/docs.doc.mjs +4 -3
- package/api/docs/docs.test.mjs +2 -0
- package/api/docs/docs.type.d.mts +21 -5
- package/api/docs/docs.type.mjs +21 -5
- package/api/docs/integration-tree.test.mjs +9 -1
- package/api/docs/reference-blocks.test.mjs +406 -0
- package/api/doctor/doctor.d.mts +8 -3
- package/api/doctor/doctor.mjs +95 -10
- package/api/doctor/doctor.test.mjs +122 -10
- package/api/index.d.mts +1 -2
- package/api/index.mjs +4 -4
- package/api/integration/add-helpers.d.mts +5 -2
- package/api/integration/add-helpers.mjs +36 -9
- package/api/integration/authoring-checks.mjs +14 -1
- package/api/integration/pack-check.lifecycle-output.test.mjs +105 -0
- package/api/integration/pack-check.mjs +28 -3
- package/api/json/index.ts +0 -1
- package/api/search/search.test.mjs +18 -0
- package/api/template/table-floating-bulk-actions.test.mjs +66 -0
- package/api/template/template-integration.test.mjs +1 -65
- package/api/template/template.mjs +1 -1
- package/api/theme/add/add.mjs +17 -25
- package/api/theme/add/add.rollback.test.mjs +158 -0
- package/api/theme/add/add.staging.test.mjs +40 -23
- package/api/theme/build/build.family.test.mjs +7 -12
- package/api/theme/build/build.mjs +8 -18
- package/api/theme/build/build.rollback.test.mjs +148 -0
- package/api/upgrade/run/files-changed.test.mjs +111 -0
- package/api/upgrade/run/run.mjs +6 -4
- package/api/upgrade/upgrade.type.mjs +2 -2
- package/assets/codemods/__tests__/registry.test.mjs +1 -0
- package/assets/codemods/__tests__/runner.test.mjs +3 -1
- package/assets/codemods/file-count.test.mjs +163 -0
- package/assets/codemods/integration-runner.mjs +3 -3
- package/assets/codemods/registry.mjs +1 -0
- package/assets/codemods/runner.mjs +5 -4
- package/assets/codemods/transforms/next/index.mjs +1 -19
- package/assets/codemods/transforms/v0.6.4/index.mjs +31 -0
- package/assets/docs/internationalization.doc.mjs +7 -5
- package/assets/docs/styling-libraries.doc.mjs +1 -1
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/component-lookups.doc.mjs +149 -0
- package/assets/docs/tree/integrations.doc.mjs +20 -1
- package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.doc.mjs +1 -1
- package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.tsx +1 -3
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.tsx +1 -1
- package/assets/templates/blocks/components/Table/TableBulkActionsTable.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/TableBulkActionsTable.tsx +71 -0
- package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.doc.mjs +19 -0
- package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.tsx +139 -0
- package/authoring/config/config.doc.mjs +9 -1
- package/authoring/config/parse.d.mts +2 -0
- package/authoring/config/parse.mjs +19 -0
- package/authoring/config/parse.test.mjs +8 -0
- package/authoring/config/type.ts +13 -2
- package/authoring/discover/discover.doc.d.mts +13 -0
- package/authoring/discover/discover.doc.mjs +138 -0
- package/authoring/discover/parse.d.mts +24 -0
- package/authoring/discover/parse.mjs +128 -0
- package/authoring/discover/parse.test.mjs +124 -0
- package/authoring/discover/type.ts +87 -0
- package/authoring/doctypes/_schema.d.mts +72 -0
- package/authoring/doctypes/_schema.mjs +25 -1
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/command/type.ts +1 -1
- package/authoring/doctypes/load-contract.test.mjs +25 -0
- package/authoring/doctypes/reference/reference.doc.mjs +31 -4
- package/authoring/doctypes/reference/type.ts +20 -5
- package/authoring/index.d.mts +1 -0
- package/authoring/index.d.ts +10 -0
- package/authoring/index.mjs +1 -0
- package/clients/cli/command-result-coverage.test.mjs +7 -7
- package/clients/cli/commands/component/index.mjs +152 -55
- package/clients/cli/commands/component-batch.test.mjs +341 -0
- package/clients/cli/commands/component-ownership.test.mjs +89 -0
- package/clients/cli/commands/component.doc.mjs +23 -6
- package/clients/cli/commands/debug-result-summary.test.mjs +2 -2
- package/clients/cli/commands/discover.doc.mjs +53 -9
- package/clients/cli/commands/discover.mjs +393 -118
- package/clients/cli/commands/discover.sources.test.mjs +267 -0
- package/clients/cli/commands/docs.mjs +2 -2
- package/clients/cli/commands/docs.test.mjs +29 -0
- package/clients/cli/commands/doctor-integration-docs.doc.mjs +1 -1
- package/clients/cli/commands/text-json-parity.test.mjs +0 -17
- package/clients/cli/index.mjs +0 -4
- package/clients/cli/lib/exit-codes.test.mjs +1 -8
- package/clients/cli/lib/json-shim.mjs +24 -14
- package/clients/cli/lib/json-shim.test.mjs +6 -20
- package/clients/cli/lib/manifest.mjs +3 -8
- package/clients/cli/lib/manifest.test.mjs +5 -2
- package/clients/cli/lib/parse-error-format.test.mjs +81 -0
- package/foundation/discovery/authoring-self-docs.d.mts +12 -0
- package/foundation/discovery/authoring-self-docs.mjs +21 -8
- package/foundation/discovery/authoring-self-docs.test.mjs +7 -2
- package/foundation/discovery/docs-discovery.d.mts +4 -1
- package/foundation/discovery/docs-discovery.mjs +40 -6
- package/foundation/discovery/docs-discovery.test.mjs +40 -0
- package/foundation/discovery/template-adapter.mjs +1 -1
- package/foundation/doc-compiler/doc-loads.test.mjs +0 -12
- package/foundation/doc-compiler/lenses.d.mts +5 -3
- package/foundation/doc-compiler/lenses.mjs +48 -3
- package/foundation/doc-compiler/links.d.mts +30 -3
- package/foundation/doc-compiler/links.mjs +46 -5
- package/foundation/doc-compiler/links.test.mjs +53 -0
- package/foundation/doc-compiler/tree.test.mjs +9 -1
- package/foundation/integrations/cli-requirement.test.mjs +17 -42
- package/foundation/integrations/integrations.d.mts +14 -1
- package/foundation/integrations/integrations.mjs +41 -1
- package/foundation/integrations/integrations.test.mjs +31 -0
- package/foundation/response/batch.type.d.mts +33 -0
- package/foundation/response/batch.type.mjs +34 -0
- package/foundation/response/response-types.doc.mjs +15 -21
- package/foundation/response/response-types.doc.test.mjs +23 -0
- package/foundation/xle/browser.d.mts +3 -3
- package/foundation/xle/browser.mjs +3 -3
- package/foundation/xle/expand.mjs +2 -2
- package/foundation/xle/parse.mjs +1 -1
- package/foundation/xle/print.mjs +2 -2
- package/foundation/xle/splice.mjs +1 -1
- package/package.json +9 -9
- package/api/layout/_adapter.d.mts +0 -34
- package/api/layout/_adapter.mjs +0 -148
- package/api/layout/check/check.d.mts +0 -16
- package/api/layout/check/check.mjs +0 -40
- package/api/layout/expand/expand.d.mts +0 -22
- package/api/layout/expand/expand.mjs +0 -155
- package/api/layout/expand/expand.path-safety.test.mjs +0 -53
- package/api/layout/grammar/grammar.d.mts +0 -13
- package/api/layout/grammar/grammar.mjs +0 -87
- package/api/layout/layout.d.mts +0 -6
- package/api/layout/layout.mjs +0 -17
- package/api/layout/layout.test.mjs +0 -297
- package/api/layout/layout.type.d.mts +0 -89
- package/api/layout/layout.type.mjs +0 -103
- package/api/layout/layoutCheck.doc.d.mts +0 -11
- package/api/layout/layoutCheck.doc.mjs +0 -85
- package/api/layout/layoutExpand.doc.d.mts +0 -11
- package/api/layout/layoutExpand.doc.mjs +0 -107
- package/api/layout/layoutGrammar.doc.d.mts +0 -11
- package/api/layout/layoutGrammar.doc.mjs +0 -57
- package/clients/cli/commands/layout-check.doc.mjs +0 -65
- package/clients/cli/commands/layout-expand.doc.mjs +0 -83
- package/clients/cli/commands/layout-grammar.doc.mjs +0 -30
- package/clients/cli/commands/layout.doc.mjs +0 -34
- package/clients/cli/commands/layout.error-codes.test.mjs +0 -66
- package/clients/cli/commands/layout.exit-parity.test.mjs +0 -41
- package/clients/cli/commands/layout.mjs +0 -275
- package/clients/cli/commands/layout.path-help.test.mjs +0 -33
- package/clients/cli/commands/layout.stdin-cap.test.mjs +0 -47
- package/clients/cli/commands/layout.text-fields.test.mjs +0 -39
- /package/assets/codemods/transforms/{next → v0.6.4}/__tests__/migrate-native-picker-to-presentation.test.mjs +0 -0
- /package/assets/codemods/transforms/{next → v0.6.4}/__tests__/migrate-theme-catalog-to-descriptors.test.mjs +0 -0
- /package/assets/codemods/transforms/{next → v0.6.4}/migrate-native-picker-to-presentation.mjs +0 -0
- /package/assets/codemods/transforms/{next → v0.6.4}/migrate-theme-catalog-to-descriptors.mjs +0 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file `astryx discover` with a discover source: the list, a package page, a
|
|
5
|
+
* search, and the refused option pair, driven through the real CLI against a
|
|
6
|
+
* hermetic project whose astryx.config sets `discover`. Saved copies go to a
|
|
7
|
+
* temp cache directory, never the project.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {describe, it, expect, beforeEach, afterEach} from 'vitest';
|
|
11
|
+
import * as fs from 'node:fs';
|
|
12
|
+
import * as path from 'node:path';
|
|
13
|
+
import * as os from 'node:os';
|
|
14
|
+
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
15
|
+
|
|
16
|
+
const CONFIG = `
|
|
17
|
+
const packages = [
|
|
18
|
+
{
|
|
19
|
+
package: '@test/kit',
|
|
20
|
+
integration: 'test-kit',
|
|
21
|
+
aliases: [],
|
|
22
|
+
latest: '3.2.0',
|
|
23
|
+
versions: [
|
|
24
|
+
{version: '3.2.0', publishedAt: '2026-09-29T00:00:00.000Z', prerelease: false, status: 'ok'},
|
|
25
|
+
{version: '3.1.4', publishedAt: '2026-09-01T00:00:00.000Z', prerelease: false, status: 'ok'},
|
|
26
|
+
],
|
|
27
|
+
contributions: [{kind: 'component', name: 'Dial'}],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
package: '@test/charts',
|
|
31
|
+
integration: 'test-charts',
|
|
32
|
+
aliases: [],
|
|
33
|
+
latest: '2.0.0',
|
|
34
|
+
versions: [
|
|
35
|
+
{version: '2.1.0-beta.1', publishedAt: '2026-09-25T00:00:00.000Z', prerelease: true, status: 'ok'},
|
|
36
|
+
{version: '2.0.0', publishedAt: '2026-09-20T00:00:00.000Z', prerelease: false, status: 'ok'},
|
|
37
|
+
],
|
|
38
|
+
contributions: [
|
|
39
|
+
{kind: 'component', name: 'Chart'},
|
|
40
|
+
{kind: 'template', name: 'pages/Report'},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
package: '@test/boards',
|
|
45
|
+
integration: 'test-boards',
|
|
46
|
+
aliases: [],
|
|
47
|
+
latest: '1.0.0',
|
|
48
|
+
versions: [
|
|
49
|
+
{version: '1.0.0', publishedAt: '2026-09-10T00:00:00.000Z', prerelease: false, status: 'ok'},
|
|
50
|
+
],
|
|
51
|
+
contributions: [{kind: 'template', name: 'pages/DialBoard'}],
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
export default {
|
|
56
|
+
integrations: ['@test/kit'],
|
|
57
|
+
async discover({package: name}) {
|
|
58
|
+
return {
|
|
59
|
+
schemaVersion: 1,
|
|
60
|
+
source: {name: 'Test catalog', generatedAt: '2026-09-30T00:00:00.000Z', complete: true},
|
|
61
|
+
packages: packages.filter(p => name == null || p.package === name),
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
let tmpDir;
|
|
68
|
+
let project;
|
|
69
|
+
/** @type {Record<string, string | undefined>} */
|
|
70
|
+
let savedEnv;
|
|
71
|
+
|
|
72
|
+
beforeEach(() => {
|
|
73
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-discover-sources-'));
|
|
74
|
+
project = path.join(tmpDir, 'project');
|
|
75
|
+
const pkgDir = path.join(project, 'node_modules', '@test', 'kit');
|
|
76
|
+
fs.mkdirSync(path.join(pkgDir, 'components'), {recursive: true});
|
|
77
|
+
fs.writeFileSync(
|
|
78
|
+
path.join(project, 'package.json'),
|
|
79
|
+
JSON.stringify({
|
|
80
|
+
name: 'proj',
|
|
81
|
+
version: '1.0.0',
|
|
82
|
+
dependencies: {'@test/kit': '3.1.4'},
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
fs.writeFileSync(path.join(project, 'astryx.config.mjs'), CONFIG);
|
|
86
|
+
fs.writeFileSync(
|
|
87
|
+
path.join(pkgDir, 'package.json'),
|
|
88
|
+
JSON.stringify({name: '@test/kit', version: '3.1.4'}),
|
|
89
|
+
);
|
|
90
|
+
fs.writeFileSync(
|
|
91
|
+
path.join(pkgDir, 'astryx.integration.mjs'),
|
|
92
|
+
`export default {components: './components'};\n`,
|
|
93
|
+
);
|
|
94
|
+
fs.writeFileSync(
|
|
95
|
+
path.join(pkgDir, 'components', 'Dial.doc.mjs'),
|
|
96
|
+
`export const docs = {name: 'Dial', usage: {description: 'A dial.'}};\n`,
|
|
97
|
+
);
|
|
98
|
+
fs.writeFileSync(
|
|
99
|
+
path.join(pkgDir, 'components', 'Dial.tsx'),
|
|
100
|
+
`export function Dial() { return null; }\n`,
|
|
101
|
+
);
|
|
102
|
+
// The saved copy lives in the per-user cache; point it at the temp dir.
|
|
103
|
+
savedEnv = {
|
|
104
|
+
HOME: process.env.HOME,
|
|
105
|
+
XDG_CACHE_HOME: process.env.XDG_CACHE_HOME,
|
|
106
|
+
LOCALAPPDATA: process.env.LOCALAPPDATA,
|
|
107
|
+
};
|
|
108
|
+
process.env.HOME = path.join(tmpDir, 'home');
|
|
109
|
+
process.env.XDG_CACHE_HOME = path.join(tmpDir, 'cache');
|
|
110
|
+
process.env.LOCALAPPDATA = path.join(tmpDir, 'localappdata');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
afterEach(() => {
|
|
114
|
+
for (const [key, value] of Object.entries(savedEnv)) {
|
|
115
|
+
if (value === undefined) delete process.env[key];
|
|
116
|
+
else process.env[key] = value;
|
|
117
|
+
}
|
|
118
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
/** The per-user cache directory this platform uses under the redirected env. */
|
|
122
|
+
function userCacheDir() {
|
|
123
|
+
if (process.platform === 'win32') {
|
|
124
|
+
return path.join(tmpDir, 'localappdata', 'astryx', 'Cache');
|
|
125
|
+
}
|
|
126
|
+
if (process.platform === 'darwin') {
|
|
127
|
+
return path.join(tmpDir, 'home', 'Library', 'Caches', 'astryx');
|
|
128
|
+
}
|
|
129
|
+
return path.join(tmpDir, 'cache', 'astryx');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
describe('astryx discover with a discover source', () => {
|
|
133
|
+
it('lists what the project has and what it could add, in --json', async () => {
|
|
134
|
+
const {status, stdout} = await runCli(['discover', '--json'], {
|
|
135
|
+
cwd: project,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
expect(status).toBe(0);
|
|
139
|
+
const {data, meta} = JSON.parse(stdout);
|
|
140
|
+
expect(data).toEqual([
|
|
141
|
+
expect.objectContaining({
|
|
142
|
+
name: '@test/kit',
|
|
143
|
+
components: ['Dial'],
|
|
144
|
+
version: '3.1.4',
|
|
145
|
+
latest: '3.2.0',
|
|
146
|
+
}),
|
|
147
|
+
]);
|
|
148
|
+
expect(meta.available).toEqual([
|
|
149
|
+
{
|
|
150
|
+
name: '@test/charts',
|
|
151
|
+
components: ['Chart'],
|
|
152
|
+
version: '2.0.0',
|
|
153
|
+
templates: ['pages/Report'],
|
|
154
|
+
source: 'Test catalog',
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
name: '@test/boards',
|
|
158
|
+
components: [],
|
|
159
|
+
version: '1.0.0',
|
|
160
|
+
templates: ['pages/DialBoard'],
|
|
161
|
+
source: 'Test catalog',
|
|
162
|
+
},
|
|
163
|
+
]);
|
|
164
|
+
expect(meta.sources).toEqual([
|
|
165
|
+
expect.objectContaining({
|
|
166
|
+
name: 'Test catalog',
|
|
167
|
+
from: 'astryx.config',
|
|
168
|
+
status: 'fresh',
|
|
169
|
+
}),
|
|
170
|
+
]);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('prints both sides as records', async () => {
|
|
174
|
+
const {status, stdout} = await runCli(['discover'], {cwd: project});
|
|
175
|
+
|
|
176
|
+
expect(status).toBe(0);
|
|
177
|
+
expect(stdout).toMatch(/^Installed$/m);
|
|
178
|
+
expect(stdout).toMatch(/^Available$/m);
|
|
179
|
+
expect(stdout).toMatch(/^name:\s+@test\/charts$/m);
|
|
180
|
+
expect(stdout).toMatch(/^latest:\s+3\.2\.0$/m);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('shows a package it does not have with its releases and the command that adds it, and never runs it', async () => {
|
|
184
|
+
const {status, stdout} = await runCli(['discover', '@test/charts'], {
|
|
185
|
+
cwd: project,
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
expect(status).toBe(0);
|
|
189
|
+
expect(stdout).toMatch(/^installed:\s+false$/m);
|
|
190
|
+
expect(stdout).toContain('- 2.0.0 2026-09-20 latest');
|
|
191
|
+
expect(stdout).not.toContain('2.1.0-beta.1 ');
|
|
192
|
+
expect(stdout).toContain('1 prerelease is not listed.');
|
|
193
|
+
// The verb follows the detected package manager.
|
|
194
|
+
expect(stdout).toMatch(
|
|
195
|
+
/^(npm install|pnpm add|yarn add|bun add) @test\/charts$/m,
|
|
196
|
+
);
|
|
197
|
+
expect(
|
|
198
|
+
fs.existsSync(path.join(project, 'node_modules', '@test', 'charts')),
|
|
199
|
+
).toBe(false);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('says which item is missing from a package only a source lists', async () => {
|
|
203
|
+
const {status, stdout} = await runCli(
|
|
204
|
+
['discover', '@test/charts/Nope', '--json'],
|
|
205
|
+
{cwd: project},
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
expect(status).toBe(1);
|
|
209
|
+
const {code, error} = JSON.parse(stdout);
|
|
210
|
+
expect(code).toBe('ERR_UNKNOWN_COMPONENT');
|
|
211
|
+
expect(error).toBe('"Nope" not found in @test/charts');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('searches every kind in every source', async () => {
|
|
215
|
+
const {status, stdout} = await runCli(['discover', 'report', '--json'], {
|
|
216
|
+
cwd: project,
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
expect(status).toBe(0);
|
|
220
|
+
expect(JSON.parse(stdout).data.matches).toEqual([
|
|
221
|
+
{
|
|
222
|
+
package: '@test/charts',
|
|
223
|
+
component: 'pages/Report',
|
|
224
|
+
kind: 'template',
|
|
225
|
+
installed: false,
|
|
226
|
+
},
|
|
227
|
+
]);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('refuses --installed with --available', async () => {
|
|
231
|
+
const {status, stdout} = await runCli(
|
|
232
|
+
['discover', '--installed', '--available', '--json'],
|
|
233
|
+
{cwd: project},
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
expect(status).toBe(1);
|
|
237
|
+
expect(JSON.parse(stdout).code).toBe('ERR_INVALID_OPTION');
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('lists every match for a free-text query, even an exact component name, and opens one by its package path', async () => {
|
|
241
|
+
const exact = await runCli(['discover', 'Dial', '--json'], {cwd: project});
|
|
242
|
+
const {type, data} = JSON.parse(exact.stdout);
|
|
243
|
+
expect(type).toBe('discover.search');
|
|
244
|
+
expect(data.matches.map(m => [m.component, m.installed])).toEqual([
|
|
245
|
+
['Dial', true],
|
|
246
|
+
['pages/DialBoard', false],
|
|
247
|
+
]);
|
|
248
|
+
|
|
249
|
+
const opened = await runCli(['discover', '@test/kit/Dial', '--json'], {
|
|
250
|
+
cwd: project,
|
|
251
|
+
});
|
|
252
|
+
expect(JSON.parse(opened.stdout).type).toBe('discover.detail.doc');
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('saves the answer in the user cache and writes nothing into the project', async () => {
|
|
256
|
+
const before = fs.readdirSync(project).sort();
|
|
257
|
+
await runCli(['discover', '--json'], {cwd: project});
|
|
258
|
+
|
|
259
|
+
expect(fs.readdirSync(project).sort()).toEqual(before);
|
|
260
|
+
expect(fs.existsSync(path.join(project, 'node_modules', '.cache'))).toBe(
|
|
261
|
+
false,
|
|
262
|
+
);
|
|
263
|
+
expect(fs.readdirSync(path.join(userCacheDir(), 'discover'))).toHaveLength(
|
|
264
|
+
1,
|
|
265
|
+
);
|
|
266
|
+
});
|
|
267
|
+
});
|
|
@@ -115,7 +115,7 @@ function formatBlock(block, detail) {
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
|
-
* @param {import('
|
|
118
|
+
* @param {import('../../../api/docs/docs.type.mjs').DocsReadSection} section
|
|
119
119
|
* @param {'full' | 'compact' | 'brief'} detail
|
|
120
120
|
* @returns {string}
|
|
121
121
|
*/
|
|
@@ -135,7 +135,7 @@ function formatSection(section, detail) {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
/**
|
|
138
|
-
* @param {import('
|
|
138
|
+
* @param {import('../../../api/docs/docs.type.mjs').DocsReadDoc} docs
|
|
139
139
|
* @param {'full' | 'compact' | 'brief'} detail
|
|
140
140
|
* @returns {string}
|
|
141
141
|
*/
|
|
@@ -216,6 +216,34 @@ describe('the docs tree, one level at a time', () => {
|
|
|
216
216
|
expect(JSON.parse(both.stdout).code).toBe('ERR_INVALID_ARGUMENT');
|
|
217
217
|
}, SLOW);
|
|
218
218
|
|
|
219
|
+
it('reads the component lookup guide and its output/API examples', async () => {
|
|
220
|
+
const index = await runCli([
|
|
221
|
+
'docs',
|
|
222
|
+
'cli/component-lookups',
|
|
223
|
+
'--index',
|
|
224
|
+
]);
|
|
225
|
+
expect(index.status).toBe(0);
|
|
226
|
+
expect(index.stdout).toContain('several');
|
|
227
|
+
expect(index.stdout).toContain('selectors');
|
|
228
|
+
expect(index.stdout).toContain('output');
|
|
229
|
+
expect(index.stdout).toContain('api');
|
|
230
|
+
|
|
231
|
+
const output = await runCli([
|
|
232
|
+
'docs',
|
|
233
|
+
'cli/component-lookups',
|
|
234
|
+
'output',
|
|
235
|
+
]);
|
|
236
|
+
expect(output.status).toBe(0);
|
|
237
|
+
expect(output.stdout).toContain('component.batch');
|
|
238
|
+
expect(output.stdout).toContain('ERR_UNKNOWN_COMPONENT');
|
|
239
|
+
expect(output.stdout).toContain('exits 1');
|
|
240
|
+
|
|
241
|
+
const api = await runCli(['docs', 'cli/component-lookups', 'api']);
|
|
242
|
+
expect(api.status).toBe(0);
|
|
243
|
+
expect(api.stdout).toContain('component([])');
|
|
244
|
+
expect(api.stdout).toContain("component(['Button'])");
|
|
245
|
+
}, SLOW);
|
|
246
|
+
|
|
219
247
|
it('reads the integration guide by its route, and not by its old name', async () => {
|
|
220
248
|
const guide = await runCli(['docs', 'cli/integrations', '--index']);
|
|
221
249
|
expect(guide.status).toBe(0);
|
|
@@ -252,6 +280,7 @@ describe('the docs tree, one level at a time', () => {
|
|
|
252
280
|
const error = JSON.parse(section.stdout);
|
|
253
281
|
expect(error).toMatchObject({code: 'ERR_UNKNOWN_SECTION'});
|
|
254
282
|
expect(error.suggestions.map(s => s.name)).toEqual([
|
|
283
|
+
'cli/component-lookups',
|
|
255
284
|
'cli/integrations',
|
|
256
285
|
'cli/writing-docs',
|
|
257
286
|
'cli/commands',
|
|
@@ -32,7 +32,7 @@ export const doc = {
|
|
|
32
32
|
],
|
|
33
33
|
exitCodes: [
|
|
34
34
|
{code: 0, when: 'all Core overlaps are explicitly declared or no overlap exists'},
|
|
35
|
-
{code: 1, when: 'an overlap is accidental, a doc is invalid,
|
|
35
|
+
{code: 1, when: 'an overlap is accidental, a doc is invalid, a namespace or placement fails, or a reference block cannot include what it names. A link that names no doc is a warning, and does not change the exit code'},
|
|
36
36
|
],
|
|
37
37
|
related: ['doctor integration validate', 'docs'],
|
|
38
38
|
};
|
|
@@ -377,23 +377,6 @@ const CASES = [
|
|
|
377
377
|
// Needs a packable project; pack itself may exit differently.
|
|
378
378
|
skipFieldChecks: true,
|
|
379
379
|
},
|
|
380
|
-
// ── Layout command: remove these cases when the layout command is deleted ──
|
|
381
|
-
{
|
|
382
|
-
name: 'layout check',
|
|
383
|
-
args: ['layout', 'check', 'Button'],
|
|
384
|
-
skipFieldChecks: true,
|
|
385
|
-
},
|
|
386
|
-
{
|
|
387
|
-
name: 'layout expand',
|
|
388
|
-
args: ['layout', 'expand', 'Button'],
|
|
389
|
-
skipFieldChecks: true,
|
|
390
|
-
},
|
|
391
|
-
{
|
|
392
|
-
name: 'layout grammar',
|
|
393
|
-
args: ['layout', 'grammar'],
|
|
394
|
-
skipFieldChecks: true,
|
|
395
|
-
},
|
|
396
|
-
// ── End layout cases ──
|
|
397
380
|
{
|
|
398
381
|
name: 'manifest',
|
|
399
382
|
args: ['manifest'],
|
package/clients/cli/index.mjs
CHANGED
|
@@ -103,9 +103,6 @@ export const JSON_SUPPORTED = new Set([
|
|
|
103
103
|
'doctor integration templates',
|
|
104
104
|
'doctor integration components',
|
|
105
105
|
'doctor integration docs',
|
|
106
|
-
'layout expand',
|
|
107
|
-
'layout check',
|
|
108
|
-
'layout grammar',
|
|
109
106
|
]);
|
|
110
107
|
|
|
111
108
|
/**
|
|
@@ -264,7 +261,6 @@ const commands = [
|
|
|
264
261
|
{name: 'gap-report', path: './commands/gap-report.mjs', register: 'registerGapReport'},
|
|
265
262
|
// agent-docs folded into init — functions still importable from agent-docs.mjs
|
|
266
263
|
{name: 'template', path: './commands/template.mjs', register: 'registerTemplate'},
|
|
267
|
-
{name: 'layout', path: './commands/layout.mjs', register: 'registerLayout'},
|
|
268
264
|
{name: 'upgrade', path: './commands/upgrade.mjs', register: 'registerUpgrade'},
|
|
269
265
|
{name: 'theme', path: './commands/build-theme.mjs', register: 'registerTheme'},
|
|
270
266
|
{name: 'integration', path: './commands/integration.mjs', register: 'registerIntegration'},
|
|
@@ -34,7 +34,7 @@ manifest.commands.forEach(walk);
|
|
|
34
34
|
|
|
35
35
|
describe('command exit codes', () => {
|
|
36
36
|
it('every CommandDoc documents its exit codes', () => {
|
|
37
|
-
expect(commandDocs.length).toBeGreaterThan(
|
|
37
|
+
expect(commandDocs.length).toBeGreaterThan(25);
|
|
38
38
|
for (const doc of commandDocs) {
|
|
39
39
|
expect(doc.exitCodes?.length, doc.name).toBeGreaterThan(0);
|
|
40
40
|
}
|
|
@@ -54,13 +54,6 @@ describe('command exit codes', () => {
|
|
|
54
54
|
},
|
|
55
55
|
);
|
|
56
56
|
|
|
57
|
-
it('bare `astryx layout` exits 1 in both modes, as documented', async () => {
|
|
58
|
-
const doc = commandDocs.find((d) => d.name === 'layout');
|
|
59
|
-
expect(doc.exitCodes.find((e) => e.code === 1)?.when).toMatch(/^no subcommand/);
|
|
60
|
-
expect((await runCli(['layout'])).status).toBe(1);
|
|
61
|
-
expect((await runCli(['layout', '--json'])).status).toBe(1);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
57
|
it('`astryx discover` with a blank query exits 1 only when packages are discovered', async () => {
|
|
65
58
|
const doc = commandDocs.find((d) => d.name === 'discover');
|
|
66
59
|
expect(doc.exitCodes.find((e) => e.code === 1)?.when).toMatch(/blank query when packages are discovered/);
|
|
@@ -33,10 +33,12 @@
|
|
|
33
33
|
* shows help because the invocation failed (`help <unknown>`, or a
|
|
34
34
|
* command group with no subcommand), which exits 1.
|
|
35
35
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
36
|
+
* Commander writes its own "error: ..." line via configureOutput.writeErr.
|
|
37
|
+
* The shim drops that line in both modes. Under --json the error envelope
|
|
38
|
+
* replaces it; in text mode `handleCommanderError` writes the Astryx line
|
|
39
|
+
* instead (`Error: <message>`, the same message the envelope carries), so
|
|
40
|
+
* a parse failure reads like every other CLI error. Other stderr output,
|
|
41
|
+
* such as help printed as the failure report, still passes through.
|
|
40
42
|
*/
|
|
41
43
|
|
|
42
44
|
import {API_VERSION, isJsonMode, toErrorEnvelope} from '../../../foundation/response/json.mjs';
|
|
@@ -249,11 +251,20 @@ function applyShimRecursively(cmd) {
|
|
|
249
251
|
});
|
|
250
252
|
cmd.configureOutput({
|
|
251
253
|
writeOut: (str) => process.stdout.write(str),
|
|
254
|
+
// Commander's own "error: ..." line never reaches the user. Under --json a
|
|
255
|
+
// consumer parsing both streams must not see it alongside the envelope;
|
|
256
|
+
// in text mode it is Commander's format, not Astryx's, so an invalid
|
|
257
|
+
// global option (`--lang zh-Hans`) printed `error: option '--lang
|
|
258
|
+
// <locale>' argument 'zh-Hans' is invalid…` where every other CLI error
|
|
259
|
+
// prints `Error: …`. handleCommanderError writes the Astryx line below,
|
|
260
|
+
// for both modes, from the same message.
|
|
261
|
+
//
|
|
262
|
+
// ONLY that line. Commander also writes HELP through this channel when it
|
|
263
|
+
// shows help because the invocation failed (a command group with no
|
|
264
|
+
// subcommand), and that output is still wanted in text mode.
|
|
252
265
|
writeErr: (str) => {
|
|
253
|
-
// Suppress Commander's "error: ..." stderr line when --json is
|
|
254
|
-
// active, so a JSON consumer parsing both streams doesn't see
|
|
255
|
-
// it alongside the envelope. Non-JSON callers are unaffected.
|
|
256
266
|
if (jsonActive()) return;
|
|
267
|
+
if (/^error:\s/i.test(str)) return;
|
|
257
268
|
process.stderr.write(str);
|
|
258
269
|
},
|
|
259
270
|
});
|
|
@@ -432,16 +443,15 @@ export function handleCommanderError(err) {
|
|
|
432
443
|
code: commanderCodeToErrorCode(code, message),
|
|
433
444
|
});
|
|
434
445
|
|
|
435
|
-
// Real error paths.
|
|
446
|
+
// Real error paths. Strip Commander's "error: " prefix once: in the envelope
|
|
447
|
+
// the key is already `error`, and in text mode the Astryx prefix replaces it.
|
|
448
|
+
const cleaned = message.replace(/^error:\s*/i, '');
|
|
436
449
|
if (jsonActive()) {
|
|
437
|
-
// Strip Commander's "error: " prefix — the envelope key is `error`
|
|
438
|
-
// already, doubled "error" is noise.
|
|
439
|
-
const cleaned = message.replace(/^error:\s*/i, '');
|
|
440
450
|
emitJsonError(cleaned, undefined, commanderCodeToErrorCode(code, cleaned));
|
|
441
451
|
} else {
|
|
442
|
-
//
|
|
443
|
-
//
|
|
444
|
-
|
|
452
|
+
// Commander's own line was suppressed above, so a parse failure reads the
|
|
453
|
+
// same as every other CLI error — the `Error: …` line cliError prints.
|
|
454
|
+
process.stderr.write(`Error: ${cleaned}\n`);
|
|
445
455
|
}
|
|
446
456
|
process.exit(exitCode || 1);
|
|
447
457
|
}
|
|
@@ -225,23 +225,6 @@ describe('--json shim: help shown for a failed invocation is an error envelope',
|
|
|
225
225
|
expect(parsed.error).toMatch(/bogus/);
|
|
226
226
|
});
|
|
227
227
|
|
|
228
|
-
it('astryx layout --json (group, no subcommand) emits ERR_MISSING_ARGUMENT, exit 1', async () => {
|
|
229
|
-
const {status, stdout, stderr} = await runCli(['layout', '--json']);
|
|
230
|
-
expect(status).toBe(1);
|
|
231
|
-
expect(stderr).toBe('');
|
|
232
|
-
const parsed = parseJson(stdout);
|
|
233
|
-
expect(parsed).not.toHaveProperty('type');
|
|
234
|
-
expect(parsed.code).toBe('ERR_MISSING_ARGUMENT');
|
|
235
|
-
expect(parsed.suggestions.map((s) => s.name)).toContain('layout expand');
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it('astryx layout (no --json) still prints help to stderr, exit 1', async () => {
|
|
239
|
-
const {status, stdout, stderr} = await runCli(['layout']);
|
|
240
|
-
expect(status).toBe(1);
|
|
241
|
-
expect(stdout).toBe('');
|
|
242
|
-
expect(stderr).toMatch(/Usage: astryx layout/);
|
|
243
|
-
});
|
|
244
|
-
|
|
245
228
|
it('the real binary emits the same envelope for help bogus --json', () => {
|
|
246
229
|
// One program per process, so the root's own outputHelp patch is used here.
|
|
247
230
|
const bin = fileURLToPath(new URL('../bin/astryx.mjs', import.meta.url));
|
|
@@ -257,6 +240,9 @@ describe('--json shim: help shown for a failed invocation is an error envelope',
|
|
|
257
240
|
});
|
|
258
241
|
|
|
259
242
|
it('a group added after install gets the same error envelope', () => {
|
|
243
|
+
// This is the only coverage of the no-subcommand path: every group the CLI
|
|
244
|
+
// ships has an action of its own (see command-result-coverage.test.mjs), so
|
|
245
|
+
// a group without one has to be built here.
|
|
260
246
|
const program = new Command('astryx');
|
|
261
247
|
installJsonShim(program);
|
|
262
248
|
// Added later, so only the prototype-level patch covers its outputHelp.
|
|
@@ -282,11 +268,11 @@ describe('--json shim: help shown for a failed invocation is an error envelope',
|
|
|
282
268
|
expect(parsed.suggestions).toEqual([{name: 'late child', reason: 'available subcommand'}]);
|
|
283
269
|
});
|
|
284
270
|
|
|
285
|
-
it('astryx help
|
|
286
|
-
const {status, stdout} = await runCli(['help', '
|
|
271
|
+
it('astryx help theme --json still emits the help envelope, exit 0', async () => {
|
|
272
|
+
const {status, stdout} = await runCli(['help', 'theme', '--json']);
|
|
287
273
|
expect(status).toBe(0);
|
|
288
274
|
const parsed = parseJson(stdout);
|
|
289
275
|
expect(parsed.type).toBe('help');
|
|
290
|
-
expect(parsed.data.command).toBe('astryx
|
|
276
|
+
expect(parsed.data.command).toBe('astryx theme');
|
|
291
277
|
});
|
|
292
278
|
});
|
|
@@ -51,6 +51,7 @@ export const RESPONSE_TYPES = {
|
|
|
51
51
|
init: ['init.run', 'init.remove'],
|
|
52
52
|
component: [
|
|
53
53
|
'component.list',
|
|
54
|
+
'component.batch',
|
|
54
55
|
'component.detail',
|
|
55
56
|
'component.detail.props',
|
|
56
57
|
'component.detail.source',
|
|
@@ -69,6 +70,7 @@ export const RESPONSE_TYPES = {
|
|
|
69
70
|
'discover.list',
|
|
70
71
|
'discover.detail',
|
|
71
72
|
'discover.detail.doc',
|
|
73
|
+
'discover.item',
|
|
72
74
|
'discover.search',
|
|
73
75
|
],
|
|
74
76
|
search: ['search'],
|
|
@@ -98,9 +100,6 @@ export const RESPONSE_TYPES = {
|
|
|
98
100
|
'doctor integration templates': ['integration.template-conflicts'],
|
|
99
101
|
'doctor integration components': ['integration.component-conflicts'],
|
|
100
102
|
'doctor integration docs': ['integration.doc-conflicts'],
|
|
101
|
-
'layout expand': ['layout.expand'],
|
|
102
|
-
'layout check': ['layout.check'],
|
|
103
|
-
'layout grammar': ['layout.grammar'],
|
|
104
103
|
};
|
|
105
104
|
|
|
106
105
|
/**
|
|
@@ -111,6 +110,7 @@ const EXAMPLES = {
|
|
|
111
110
|
component: [
|
|
112
111
|
'astryx component',
|
|
113
112
|
'astryx component XDSButton',
|
|
113
|
+
'astryx component Button Badge Text',
|
|
114
114
|
'astryx component XDSButton --props --json',
|
|
115
115
|
],
|
|
116
116
|
docs: [
|
|
@@ -180,11 +180,6 @@ const EXAMPLES = {
|
|
|
180
180
|
'astryx doctor integration docs @acme/widgets --json',
|
|
181
181
|
],
|
|
182
182
|
init: ['astryx init', 'astryx init --all --json'],
|
|
183
|
-
'layout expand': [
|
|
184
|
-
`astryx layout expand 'V[g6] > C{card-callout}*4' ./src/Page.tsx`,
|
|
185
|
-
],
|
|
186
|
-
'layout check': [`astryx layout check 'A[cp6] > L > LC > S[p6]' --json`],
|
|
187
|
-
'layout grammar': ['astryx layout grammar'],
|
|
188
183
|
};
|
|
189
184
|
|
|
190
185
|
/**
|
|
@@ -156,7 +156,10 @@ describe('manifest: shape', () => {
|
|
|
156
156
|
|
|
157
157
|
it('derives arguments from Commander metadata', () => {
|
|
158
158
|
const component = allEntries.find((c) => c.name === 'component');
|
|
159
|
-
|
|
159
|
+
const names = component.arguments.find((a) => a.name === 'names');
|
|
160
|
+
expect(names.required).toBe(false);
|
|
161
|
+
expect(names.variadic).toBe(true);
|
|
162
|
+
expect(names.description).toContain('Two or more return one ordered batch');
|
|
160
163
|
const themeBuild = allEntries.find((c) => c.name === 'theme build');
|
|
161
164
|
expect(themeBuild.arguments.map((a) => a.name)).toContain('files');
|
|
162
165
|
const files = themeBuild.arguments.find((a) => a.name === 'files');
|
|
@@ -193,7 +196,7 @@ describe('manifest: e2e', () => {
|
|
|
193
196
|
// Enriched: the full structured manifest is embedded.
|
|
194
197
|
expect(parsed.data.manifest).toBeDefined();
|
|
195
198
|
expect(parsed.data.manifest.commands.find((c) => c.name === 'component').responseTypes)
|
|
196
|
-
.
|
|
199
|
+
.toEqual(expect.arrayContaining(['component.list', 'component.batch']));
|
|
197
200
|
});
|
|
198
201
|
});
|
|
199
202
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file A parse failure reads like every other Astryx error in text mode.
|
|
5
|
+
*
|
|
6
|
+
* `astryx theme list --lang zh-Hans` printed Commander's own line —
|
|
7
|
+
* `error: option '--lang <locale>' argument 'zh-Hans' is invalid…` — while
|
|
8
|
+
* every other CLI error prints `Error: …`. `--json` was already correct
|
|
9
|
+
* (ERR_INVALID_LANG), so text and JSON disagreed on everything except the exit
|
|
10
|
+
* code. Commander writes that line before any Astryx code runs, so the shim is
|
|
11
|
+
* the only place that can speak for it.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {describe, it, expect} from 'vitest';
|
|
15
|
+
import {Command} from 'commander';
|
|
16
|
+
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
17
|
+
import {installJsonShim} from './json-shim.mjs';
|
|
18
|
+
|
|
19
|
+
describe('a parse error prints the Astryx error format', () => {
|
|
20
|
+
it.each([
|
|
21
|
+
['invalid --lang value', ['theme', 'list', '--lang', 'zh-Hans'], 'ERR_INVALID_LANG'],
|
|
22
|
+
['invalid --detail value', ['theme', 'list', '--detail', 'nope'], 'ERR_INVALID_DETAIL'],
|
|
23
|
+
['unknown option', ['component', '--bogus-flag'], 'ERR_INVALID_OPTION'],
|
|
24
|
+
['missing argument', ['theme', 'build'], 'ERR_MISSING_ARGUMENT'],
|
|
25
|
+
])('%s', async (_label, args, code) => {
|
|
26
|
+
const human = await runCli(args);
|
|
27
|
+
|
|
28
|
+
expect(human.status).toBe(1);
|
|
29
|
+
expect(human.stderr).toContain('Error: ');
|
|
30
|
+
// Commander's own lowercase line must not reach the user.
|
|
31
|
+
expect(human.stderr).not.toMatch(/(^|\n)error: /);
|
|
32
|
+
|
|
33
|
+
// --json is unchanged, and the two modes agree on the exit code.
|
|
34
|
+
const json = await runCli(['--json', ...args]);
|
|
35
|
+
expect(json.status).toBe(human.status);
|
|
36
|
+
expect(JSON.parse(json.stdout).code).toBe(code);
|
|
37
|
+
expect(json.stderr).toBe('');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('carries Commander\'s explanation, not just a generic line', async () => {
|
|
41
|
+
const {stderr} = await runCli(['theme', 'list', '--lang', 'zh-Hans']);
|
|
42
|
+
expect(stderr).toContain("'zh-Hans' is invalid");
|
|
43
|
+
expect(stderr).toContain('en, zh, dense');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('leaves --help and --version at exit 0 with nothing on stderr', async () => {
|
|
47
|
+
for (const args of [['--help'], ['theme', '--help']]) {
|
|
48
|
+
const r = await runCli(args);
|
|
49
|
+
expect(r.status).toBe(0);
|
|
50
|
+
expect(r.stderr).toBe('');
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Commander writes help through the same stderr channel when it shows help
|
|
55
|
+
// BECAUSE the invocation failed, so suppressing that channel wholesale would
|
|
56
|
+
// have taken the help with it. Driven on a throwaway program rather than a
|
|
57
|
+
// real command, so the guard outlives whichever command happens to have a
|
|
58
|
+
// subcommand group today.
|
|
59
|
+
it('still lets help reach stderr when help IS the failure report', () => {
|
|
60
|
+
const program = new Command('probe');
|
|
61
|
+
const group = program.command('group');
|
|
62
|
+
group.command('leaf').action(() => {});
|
|
63
|
+
installJsonShim(program);
|
|
64
|
+
|
|
65
|
+
/** @type {string[]} */
|
|
66
|
+
const written = [];
|
|
67
|
+
const original = process.stderr.write;
|
|
68
|
+
// @ts-expect-error test double for the write signature
|
|
69
|
+
process.stderr.write = str => {
|
|
70
|
+
written.push(String(str));
|
|
71
|
+
return true;
|
|
72
|
+
};
|
|
73
|
+
try {
|
|
74
|
+
group.outputHelp({error: true});
|
|
75
|
+
} finally {
|
|
76
|
+
process.stderr.write = original;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
expect(written.join('')).toMatch(/Usage: probe group/);
|
|
80
|
+
});
|
|
81
|
+
});
|