@astryxdesign/cli 0.7.2-canary.4932317 → 0.7.2-canary.4a2f608
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/README.md +62 -62
- package/api/discover/_adapter.d.mts +119 -12
- package/api/discover/_adapter.mjs +449 -10
- package/api/discover/_adapter.test.mjs +599 -17
- package/api/discover/_catalog-view.d.mts +16 -5
- package/api/discover/_catalog-view.mjs +32 -8
- package/api/discover/discover.d.mts +11 -0
- package/api/discover/discover.doc.mjs +7 -6
- package/api/discover/discover.mjs +107 -19
- package/api/discover/discover.type.d.mts +18 -7
- package/api/discover/discover.type.mjs +15 -7
- package/api/discover/list/list.d.mts +4 -3
- package/api/discover/list/list.mjs +17 -10
- package/api/doctor/theme-checks.test.mjs +136 -0
- package/api/gap-report/gap-report.d.mts +3 -0
- package/api/gap-report/gap-report.doc.mjs +11 -3
- package/api/gap-report/gap-report.mjs +152 -48
- package/api/gap-report/gap-report.test.mjs +233 -0
- package/api/gap-report/gap-report.type.d.mts +41 -0
- package/api/gap-report/gap-report.type.mjs +18 -0
- package/api/integration/_adapter.d.mts +20 -0
- package/api/integration/_adapter.mjs +26 -0
- package/api/integration/authoring-checks.mjs +34 -3
- package/api/integration/authoring-checks.test.mjs +476 -0
- package/api/integration/authoring-checks.type.d.mts +86 -0
- package/api/integration/authoring-checks.type.mjs +39 -1
- package/api/integration/integrationComponentConflicts.doc.mjs +9 -3
- package/api/integration/integrationDocConflicts.doc.mjs +19 -5
- package/api/integration/pack-check.mjs +292 -7
- package/api/integration/pack-check.test.mjs +341 -0
- package/api/integration/validateIntegration.doc.mjs +3 -1
- package/api/search/search.d.mts +9 -7
- package/api/search/search.mjs +90 -42
- package/api/search/search.test.mjs +11 -0
- package/api/upgrade/_adapter.d.mts +40 -2
- package/api/upgrade/_adapter.mjs +117 -4
- package/api/upgrade/run/cli-behind-core.test.mjs +438 -0
- package/api/upgrade/run/run.mjs +30 -1
- package/api/upgrade/status/status.d.mts +21 -5
- package/api/upgrade/status/status.mjs +45 -8
- package/api/upgrade/upgrade.doc.mjs +5 -3
- package/api/upgrade/upgrade.type.d.mts +23 -0
- package/api/upgrade/upgrade.type.mjs +16 -1
- package/assets/codemods/runner.mjs +7 -1
- package/assets/discover/official-packages.json +367 -0
- package/assets/docs/author-a-theme.doc.mjs +2 -2
- package/assets/docs/browser-support.doc.mjs +1 -1
- package/assets/docs/styling-overview.doc.mjs +1 -1
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
- package/assets/docs/tree/check-the-props.doc.mjs +2 -2
- package/assets/docs/tree/check-your-docs.doc.mjs +11 -3
- package/assets/docs/tree/checks.doc.mjs +4 -4
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +25 -5
- package/assets/docs/tree/layout-spacing.doc.mjs +2 -3
- package/assets/docs/tree/layout.doc.mjs +6 -6
- package/assets/docs/tree/migration-setup.doc.mjs +2 -2
- package/assets/docs/tree/publishing.doc.mjs +3 -3
- package/assets/docs/tree/quick-start.doc.mjs +3 -3
- package/assets/docs/tree/sections-and-placement.doc.mjs +2 -2
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/troubleshooting.doc.mjs +5 -5
- package/assets/docs/tree/upgrading.doc.mjs +1 -1
- package/authoring/discover/discover.doc.mjs +1 -1
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/clients/cli/commands/discover.broken-integration.test.mjs +4 -1
- package/clients/cli/commands/discover.doc.mjs +1 -1
- package/clients/cli/commands/discover.mjs +144 -93
- package/clients/cli/commands/discover.no-source.test.mjs +447 -33
- package/clients/cli/commands/discover.sources.test.mjs +20 -1
- package/clients/cli/commands/doctor-integration-components.doc.mjs +3 -1
- package/clients/cli/commands/doctor-integration-docs.doc.mjs +18 -5
- package/clients/cli/commands/doctor-integration-validate.doc.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +60 -3
- package/clients/cli/commands/gap-report.doc.mjs +14 -2
- package/clients/cli/commands/gap-report.mjs +24 -2
- package/clients/cli/commands/gap-report.test.mjs +79 -0
- package/clients/cli/commands/integration-check.test.mjs +103 -0
- package/clients/cli/commands/integration.mjs +2 -3
- package/clients/cli/commands/json-contract.test.mjs +5 -1
- package/clients/cli/commands/upgrade.doc.mjs +14 -0
- package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
- package/foundation/discovery/copied-passages.d.mts +216 -0
- package/foundation/discovery/copied-passages.mjs +720 -0
- package/foundation/discovery/copied-passages.test.mjs +124 -0
- package/foundation/discovery/doc-fluff.d.mts +112 -0
- package/foundation/discovery/doc-fluff.mjs +328 -0
- package/foundation/discovery/doc-fluff.test.mjs +142 -0
- package/foundation/discovery/doc-types.d.mts +1 -1
- package/foundation/discovery/doc-types.mjs +3 -3
- package/foundation/discovery/doc-types.test.mjs +48 -0
- package/foundation/discovery/docs-discovery.d.mts +7 -0
- package/foundation/discovery/docs-discovery.mjs +26 -2
- package/foundation/discovery/project-typescript.d.mts +11 -2
- package/foundation/discovery/project-typescript.mjs +32 -4
- package/foundation/discovery/prop-drift.d.mts +1 -1
- package/foundation/discovery/prop-drift.mjs +2 -2
- package/foundation/discovery/prop-drift.test.mjs +55 -2
- package/foundation/discovery/type-text.mjs +1 -1
- package/foundation/discovery/type-text.test.mjs +1 -1
- package/foundation/doc-compiler/doc-loads.test.mjs +14 -2
- package/foundation/env/package-manager.d.mts +32 -0
- package/foundation/env/package-manager.mjs +47 -0
- package/foundation/env/package-manager.test.mjs +194 -7
- package/foundation/fs/module-loader.d.mts +2 -1
- package/foundation/fs/module-loader.mjs +60 -4
- package/foundation/fs/module-loader.test.mjs +194 -0
- package/foundation/response/response-types.doc.mjs +7 -6
- package/package.json +11 -11
|
@@ -358,7 +358,8 @@ function printComponentConflicts(data) {
|
|
|
358
358
|
// An [ok] after a failed check reads as a pass: say nothing it could not check.
|
|
359
359
|
const failed = data.issues.some(issue => issue.severity === 'error');
|
|
360
360
|
if (data.conflicts.length === 0) {
|
|
361
|
-
if (!failed)
|
|
361
|
+
if (!failed)
|
|
362
|
+
output.push(text('[ok] No component names conflict with Core.'));
|
|
362
363
|
} else {
|
|
363
364
|
output.push(
|
|
364
365
|
records(data.conflicts, {
|
|
@@ -389,7 +390,13 @@ function printDocConflicts(data) {
|
|
|
389
390
|
section(
|
|
390
391
|
`Checking integration docs: ${integrationLabel(data) ?? '(local package)'}`,
|
|
391
392
|
),
|
|
392
|
-
|
|
393
|
+
// A copied passage or fluff is listed below with its detail, so its
|
|
394
|
+
// issue is not printed twice.
|
|
395
|
+
...issueBlocks(
|
|
396
|
+
data.issues.filter(
|
|
397
|
+
issue => issue.code !== 'copied_passage' && issue.code !== 'doc_fluff',
|
|
398
|
+
),
|
|
399
|
+
),
|
|
393
400
|
];
|
|
394
401
|
if (
|
|
395
402
|
!data.issues.some(
|
|
@@ -412,6 +419,56 @@ function printDocConflicts(data) {
|
|
|
412
419
|
}),
|
|
413
420
|
);
|
|
414
421
|
}
|
|
422
|
+
const copied = data.copiedPassages ?? [];
|
|
423
|
+
if (copied.length === 0) {
|
|
424
|
+
if (!data.issues.some(issue => issue.severity === 'error')) {
|
|
425
|
+
output.push(text('[ok] No topic copies a passage from another.'));
|
|
426
|
+
}
|
|
427
|
+
} else {
|
|
428
|
+
output.push(
|
|
429
|
+
text(
|
|
430
|
+
`[warn] ${copied.length} copied passage(s) (copied_passage): two topics say the same thing word for word. Keep the text in one and link to it from the other.`,
|
|
431
|
+
),
|
|
432
|
+
records(copied, {
|
|
433
|
+
fields: [
|
|
434
|
+
'topic',
|
|
435
|
+
'section',
|
|
436
|
+
'line',
|
|
437
|
+
'otherTopic',
|
|
438
|
+
'otherOwner',
|
|
439
|
+
'owner',
|
|
440
|
+
'text',
|
|
441
|
+
'words',
|
|
442
|
+
'passages',
|
|
443
|
+
'message',
|
|
444
|
+
],
|
|
445
|
+
}),
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
const fluff = data.fluff ?? [];
|
|
449
|
+
if (fluff.length === 0) {
|
|
450
|
+
if (!data.issues.some(issue => issue.severity === 'error')) {
|
|
451
|
+
output.push(text('[ok] No filler phrases or low-density topics.'));
|
|
452
|
+
}
|
|
453
|
+
} else {
|
|
454
|
+
output.push(
|
|
455
|
+
text(
|
|
456
|
+
`[warn] ${fluff.length} fluff finding(s) (doc_fluff): words that add length, not meaning. Cut each one.`,
|
|
457
|
+
),
|
|
458
|
+
records(fluff, {
|
|
459
|
+
fields: [
|
|
460
|
+
'topic',
|
|
461
|
+
'kind',
|
|
462
|
+
'phrase',
|
|
463
|
+
'section',
|
|
464
|
+
'file',
|
|
465
|
+
'line',
|
|
466
|
+
'density',
|
|
467
|
+
'message',
|
|
468
|
+
],
|
|
469
|
+
}),
|
|
470
|
+
);
|
|
471
|
+
}
|
|
415
472
|
emit(...output);
|
|
416
473
|
}
|
|
417
474
|
|
|
@@ -455,7 +512,7 @@ async function runIntegrationValidation(program, pkg) {
|
|
|
455
512
|
noPackage
|
|
456
513
|
? 'Nothing was validated: no package.json found. Run this command inside a package directory.'
|
|
457
514
|
: 'Nothing was validated: no astryx.integration.* found next to package.json. ' +
|
|
458
|
-
|
|
515
|
+
'To validate an installed integration: astryx doctor integration validate <package>',
|
|
459
516
|
),
|
|
460
517
|
);
|
|
461
518
|
} else printIntegrationValidation(result.data);
|
|
@@ -16,6 +16,8 @@ export const doc = {
|
|
|
16
16
|
'Reports a missing component, variant, layout, styling, accessibility, API, or documentation capability to the package that owns it: the --package you name, else the integration whose component replaces it, else the one package that provides the component, else Core. ' +
|
|
17
17
|
'Every configured handler receives the report: the project config handler first, then each integration handler in config order. Public handlers run only with --confirm-public; internal handlers always run. A failing handler does not stop the others. ' +
|
|
18
18
|
"With no handler it files a GitHub issue for the owning package, only with --confirm-public (without it nothing is sent), or returns the package's issues URL when that is not on GitHub. " +
|
|
19
|
+
"With --to <package>, the report goes only to that integration's issues URL instead, under the same --confirm-public rule. " +
|
|
20
|
+
'When loaded integrations name their own issues URLs, the output lists every destination: an agent asks the person where to file and passes their choice with --to; it never picks a package itself, and without a choice the default is used. ' +
|
|
19
21
|
'The report records whether an agent or a person ran it.',
|
|
20
22
|
fn: 'gapReport',
|
|
21
23
|
args: [
|
|
@@ -55,13 +57,19 @@ export const doc = {
|
|
|
55
57
|
flag: '--confirm-public',
|
|
56
58
|
param: 'options.confirmPublic',
|
|
57
59
|
description:
|
|
58
|
-
'Allow public delivery: public handlers run, and
|
|
60
|
+
'Allow public delivery: public handlers run, and a GitHub issues URL gets an issue filed with your gh login',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
flag: '--to <package>',
|
|
64
|
+
param: 'options.to',
|
|
65
|
+
description:
|
|
66
|
+
"Send the report only to this loaded integration's issues URL, as the person chose; the destinations the output lists are the choices",
|
|
59
67
|
},
|
|
60
68
|
{
|
|
61
69
|
flag: '--list-categories',
|
|
62
70
|
param: 'options.listCategories',
|
|
63
71
|
description:
|
|
64
|
-
'List valid report categories without filing; the component and the other gap-report options are refused with ERR_INVALID_ARGUMENT',
|
|
72
|
+
'List valid report categories, and the destinations when there is more than one, without filing; the component and the other gap-report options are refused with ERR_INVALID_ARGUMENT',
|
|
65
73
|
},
|
|
66
74
|
],
|
|
67
75
|
examples: [
|
|
@@ -70,6 +78,10 @@ export const doc = {
|
|
|
70
78
|
label: 'Prepare a report (nothing public happens without --confirm-public)',
|
|
71
79
|
cli: "astryx gap-report Button --category missing_variant --reason 'Need a compact size'",
|
|
72
80
|
},
|
|
81
|
+
{
|
|
82
|
+
label: 'File where the person chose',
|
|
83
|
+
cli: "astryx gap-report Button --category missing_variant --reason 'Need a compact size' --to @acme/widgets",
|
|
84
|
+
},
|
|
73
85
|
],
|
|
74
86
|
exitCodes: [
|
|
75
87
|
{
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import {gapReport as gapReportApi} from '../../../api/gap-report/gap-report.mjs';
|
|
8
8
|
import {NO_RESULT_SET, resultSet} from '../../../foundation/debug/index.mjs';
|
|
9
9
|
import {jsonOut} from '../../../foundation/response/json.mjs';
|
|
10
|
-
import {emit, record, records, section} from '../formatters/index.mjs';
|
|
10
|
+
import {emit, record, records, section, text} from '../formatters/index.mjs';
|
|
11
11
|
import {cliError} from '../lib/cli-error.mjs';
|
|
12
12
|
import {defineCommand} from '../lib/define-command.mjs';
|
|
13
13
|
import {doc as gapReportCommand} from './gap-report.doc.mjs';
|
|
@@ -19,7 +19,7 @@ export function registerGapReport(program) {
|
|
|
19
19
|
fn: gapReportFn,
|
|
20
20
|
action: async (
|
|
21
21
|
/** @type {string|undefined} */ component,
|
|
22
|
-
/** @type {{category?: string, reason?: string, additionalContext?: string, package?: string, confirmPublic?: boolean, listCategories?: boolean}} */ options,
|
|
22
|
+
/** @type {{category?: string, reason?: string, additionalContext?: string, package?: string, confirmPublic?: boolean, listCategories?: boolean, to?: string}} */ options,
|
|
23
23
|
) => {
|
|
24
24
|
/** @type {Awaited<ReturnType<typeof gapReportApi>>} */
|
|
25
25
|
let result;
|
|
@@ -35,6 +35,7 @@ export function registerGapReport(program) {
|
|
|
35
35
|
package: options.package,
|
|
36
36
|
confirmPublic: options.confirmPublic,
|
|
37
37
|
listCategories: options.listCategories,
|
|
38
|
+
to: options.to,
|
|
38
39
|
});
|
|
39
40
|
} catch (error) {
|
|
40
41
|
const err =
|
|
@@ -78,6 +79,9 @@ export function registerGapReport(program) {
|
|
|
78
79
|
section('Gap report categories'),
|
|
79
80
|
records(result.data, {fields: ['value', 'label']}),
|
|
80
81
|
);
|
|
82
|
+
if (result.meta) {
|
|
83
|
+
emit(...destinationBlocks(result.meta.destinations, result.meta.ask));
|
|
84
|
+
}
|
|
81
85
|
return answered;
|
|
82
86
|
}
|
|
83
87
|
|
|
@@ -119,8 +123,26 @@ export function registerGapReport(program) {
|
|
|
119
123
|
);
|
|
120
124
|
}
|
|
121
125
|
|
|
126
|
+
if (result.data.destinations && result.data.ask) {
|
|
127
|
+
emit(...destinationBlocks(result.data.destinations, result.data.ask));
|
|
128
|
+
}
|
|
129
|
+
|
|
122
130
|
if (isFailure) process.exitCode = 1;
|
|
123
131
|
return answered;
|
|
124
132
|
},
|
|
125
133
|
});
|
|
126
134
|
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The destinations a report can go to, then the line telling an agent to ask
|
|
138
|
+
* the person (architecture:cli-surface INV36).
|
|
139
|
+
* @param {import('../../../api/gap-report/gap-report.type.mjs').GapReportDestination[]} destinations
|
|
140
|
+
* @param {string} ask
|
|
141
|
+
*/
|
|
142
|
+
function destinationBlocks(destinations, ask) {
|
|
143
|
+
return [
|
|
144
|
+
section('Destinations'),
|
|
145
|
+
records(destinations, {fields: ['to', 'default', 'issuesUrl']}),
|
|
146
|
+
text(ask),
|
|
147
|
+
];
|
|
148
|
+
}
|
|
@@ -331,3 +331,82 @@ describe('gap-report control docs', () => {
|
|
|
331
331
|
).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
|
|
332
332
|
});
|
|
333
333
|
});
|
|
334
|
+
|
|
335
|
+
describe('gap-report destinations in text', () => {
|
|
336
|
+
it('lists the destinations and tells the agent to ask the person', async () => {
|
|
337
|
+
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-gap-dest-'));
|
|
338
|
+
try {
|
|
339
|
+
fs.writeFileSync(
|
|
340
|
+
path.join(cwd, 'package.json'),
|
|
341
|
+
JSON.stringify({name: 'fixture-app'}),
|
|
342
|
+
);
|
|
343
|
+
const pkg = path.join(cwd, 'node_modules', '@test', 'widgets');
|
|
344
|
+
fs.mkdirSync(pkg, {recursive: true});
|
|
345
|
+
fs.writeFileSync(
|
|
346
|
+
path.join(pkg, 'package.json'),
|
|
347
|
+
JSON.stringify({name: '@test/widgets', version: '1.0.0'}),
|
|
348
|
+
);
|
|
349
|
+
fs.writeFileSync(
|
|
350
|
+
path.join(pkg, 'astryx.integration.mjs'),
|
|
351
|
+
"export default {issuesUrl: 'https://tracker.example/widgets'};\n",
|
|
352
|
+
);
|
|
353
|
+
fs.writeFileSync(
|
|
354
|
+
path.join(cwd, 'astryx.config.mjs'),
|
|
355
|
+
`export default {
|
|
356
|
+
integrations: ['@test/widgets'],
|
|
357
|
+
gapReport: {audience: 'internal', handle: () => ({status: 'filed', message: 'shared'})},
|
|
358
|
+
};\n`,
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
const listed = await runCli(['gap-report', '--list-categories'], {cwd});
|
|
362
|
+
expect(listed.status).toBe(0);
|
|
363
|
+
expect(listed.stdout).toContain('Destinations');
|
|
364
|
+
expect(listed.stdout).toMatch(/^default:\s+true$/m);
|
|
365
|
+
expect(listed.stdout).toMatch(/^to:\s+@test\/widgets$/m);
|
|
366
|
+
expect(listed.stdout).toMatch(
|
|
367
|
+
/^issuesUrl:\s+https:\/\/tracker\.example\/widgets$/m,
|
|
368
|
+
);
|
|
369
|
+
expect(listed.stdout).toMatch(/ask the person/i);
|
|
370
|
+
|
|
371
|
+
const filed = await runCli(
|
|
372
|
+
[
|
|
373
|
+
'gap-report',
|
|
374
|
+
'Button',
|
|
375
|
+
'--category',
|
|
376
|
+
'docs_gap',
|
|
377
|
+
'--reason',
|
|
378
|
+
'Need a keyboard example',
|
|
379
|
+
],
|
|
380
|
+
{cwd},
|
|
381
|
+
);
|
|
382
|
+
expect(filed.status).toBe(0);
|
|
383
|
+
expect(filed.stdout).toContain('Destinations');
|
|
384
|
+
expect(filed.stdout).toMatch(/ask the person/i);
|
|
385
|
+
|
|
386
|
+
const chosen = await runCli(
|
|
387
|
+
[
|
|
388
|
+
'gap-report',
|
|
389
|
+
'Button',
|
|
390
|
+
'--category',
|
|
391
|
+
'docs_gap',
|
|
392
|
+
'--reason',
|
|
393
|
+
'Need a keyboard example',
|
|
394
|
+
'--to',
|
|
395
|
+
'@test/widgets',
|
|
396
|
+
'--json',
|
|
397
|
+
],
|
|
398
|
+
{cwd},
|
|
399
|
+
);
|
|
400
|
+
expect(chosen.status).toBe(0);
|
|
401
|
+
expect(JSON.parse(chosen.stdout).data.deliveries).toEqual([
|
|
402
|
+
expect.objectContaining({
|
|
403
|
+
handler: 'issuesUrl',
|
|
404
|
+
status: 'routed_only',
|
|
405
|
+
url: 'https://tracker.example/widgets',
|
|
406
|
+
}),
|
|
407
|
+
]);
|
|
408
|
+
} finally {
|
|
409
|
+
fs.rmSync(cwd, {recursive: true, force: true});
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
});
|
|
@@ -117,6 +117,23 @@ describe('astryx integration check', () => {
|
|
|
117
117
|
expect(run.status).toBe(1);
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
+
it('--strict prints each finding once: its message above, its code in the failing list', async () => {
|
|
121
|
+
const id = await coreTemplateId();
|
|
122
|
+
writePackage({id});
|
|
123
|
+
|
|
124
|
+
const run = await runCli(['integration', 'check', '--strict'], tmpDir);
|
|
125
|
+
const json = await runCli(
|
|
126
|
+
['integration', 'check', '--strict', '--json'],
|
|
127
|
+
tmpDir,
|
|
128
|
+
);
|
|
129
|
+
const [failure] = JSON.parse(json.stdout.trim()).data.failures;
|
|
130
|
+
|
|
131
|
+
expect(run.stdout.split(failure.message).length - 1).toBe(1);
|
|
132
|
+
expect(
|
|
133
|
+
run.stdout.slice(run.stdout.indexOf('Failing under --strict')),
|
|
134
|
+
).toContain('template_id_conflict');
|
|
135
|
+
});
|
|
136
|
+
|
|
120
137
|
it('--json carries each check with its own envelope, the --strict failures, and exits as the text does', async () => {
|
|
121
138
|
const id = await coreTemplateId();
|
|
122
139
|
writePackage({id});
|
|
@@ -265,3 +282,89 @@ describe('astryx integration check', () => {
|
|
|
265
282
|
expect(run.status).toBe(1);
|
|
266
283
|
});
|
|
267
284
|
});
|
|
285
|
+
|
|
286
|
+
describe('a copied passage', () => {
|
|
287
|
+
const passage =
|
|
288
|
+
'Themes cannot style the layer that holds a menu or a popover, so a menu ' +
|
|
289
|
+
'keeps the default surface color until the next release adds a token for it.';
|
|
290
|
+
|
|
291
|
+
function writeCopiedDocs() {
|
|
292
|
+
fs.writeFileSync(
|
|
293
|
+
path.join(tmpDir, 'package.json'),
|
|
294
|
+
JSON.stringify({name: '@acme/widgets', version: '1.2.3'}),
|
|
295
|
+
);
|
|
296
|
+
fs.writeFileSync(
|
|
297
|
+
path.join(tmpDir, 'astryx.integration.mjs'),
|
|
298
|
+
`export default {docs: './docs'};\n`,
|
|
299
|
+
);
|
|
300
|
+
fs.mkdirSync(path.join(tmpDir, 'docs'));
|
|
301
|
+
for (const name of ['acme-setup', 'acme-menus']) {
|
|
302
|
+
const doc = {
|
|
303
|
+
type: 'generic',
|
|
304
|
+
name,
|
|
305
|
+
title: 'Fixture',
|
|
306
|
+
description: 'Fixture topic.',
|
|
307
|
+
sections: [
|
|
308
|
+
{title: 'Overview', content: [{type: 'prose', text: passage}]},
|
|
309
|
+
],
|
|
310
|
+
};
|
|
311
|
+
fs.writeFileSync(
|
|
312
|
+
path.join(tmpDir, 'docs', `${name}.doc.mjs`),
|
|
313
|
+
`export default ${JSON.stringify(doc)};\n`,
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
it('keeps doctor integration docs at exit 0, and fails integration check --strict', async () => {
|
|
319
|
+
writeCopiedDocs();
|
|
320
|
+
|
|
321
|
+
const doctor = await runCli(['doctor', 'integration', 'docs'], tmpDir);
|
|
322
|
+
expect(doctor.status).toBe(0);
|
|
323
|
+
expect(doctor.stdout).toContain('1 copied passage(s)');
|
|
324
|
+
|
|
325
|
+
const loose = await runCli(['integration', 'check'], tmpDir);
|
|
326
|
+
expect(loose.status).toBe(0);
|
|
327
|
+
|
|
328
|
+
const strict = await runCli(['integration', 'check', '--strict'], tmpDir);
|
|
329
|
+
expect(strict.status).toBe(1);
|
|
330
|
+
expect(strict.stdout).toContain('copied_passage');
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
describe('a padding phrase', () => {
|
|
335
|
+
it('keeps doctor integration docs at exit 0, and fails integration check --strict', async () => {
|
|
336
|
+
fs.writeFileSync(
|
|
337
|
+
path.join(tmpDir, 'package.json'),
|
|
338
|
+
JSON.stringify({name: '@acme/widgets', version: '1.2.3'}),
|
|
339
|
+
);
|
|
340
|
+
fs.writeFileSync(
|
|
341
|
+
path.join(tmpDir, 'astryx.integration.mjs'),
|
|
342
|
+
`export default {docs: './docs'};\n`,
|
|
343
|
+
);
|
|
344
|
+
fs.mkdirSync(path.join(tmpDir, 'docs'));
|
|
345
|
+
const doc = {
|
|
346
|
+
type: 'generic',
|
|
347
|
+
name: 'acme-setup',
|
|
348
|
+
title: 'Fixture',
|
|
349
|
+
description: 'Fixture topic.',
|
|
350
|
+
sections: [
|
|
351
|
+
{
|
|
352
|
+
title: 'Overview',
|
|
353
|
+
content: [{type: 'prose', text: 'In order to start, run the setup.'}],
|
|
354
|
+
},
|
|
355
|
+
],
|
|
356
|
+
};
|
|
357
|
+
fs.writeFileSync(
|
|
358
|
+
path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'),
|
|
359
|
+
`export default ${JSON.stringify(doc)};\n`,
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
const doctor = await runCli(['doctor', 'integration', 'docs'], tmpDir);
|
|
363
|
+
expect(doctor.status).toBe(0);
|
|
364
|
+
expect(doctor.stdout).toContain('1 fluff finding(s)');
|
|
365
|
+
|
|
366
|
+
const strict = await runCli(['integration', 'check', '--strict'], tmpDir);
|
|
367
|
+
expect(strict.status).toBe(1);
|
|
368
|
+
expect(strict.stdout).toContain('doc_fluff');
|
|
369
|
+
});
|
|
370
|
+
});
|
|
@@ -155,7 +155,8 @@ async function checkPackage(program, options) {
|
|
|
155
155
|
: data.name;
|
|
156
156
|
emit(
|
|
157
157
|
// --strict lists each warning and each skipped check again, as the
|
|
158
|
-
// error it now is,
|
|
158
|
+
// error it now is: by check, code and place only, since the check's own
|
|
159
|
+
// output above already printed its message and fix once.
|
|
159
160
|
...(data.failures.length > 0
|
|
160
161
|
? [
|
|
161
162
|
section('Failing under --strict'),
|
|
@@ -166,8 +167,6 @@ async function checkPackage(program, options) {
|
|
|
166
167
|
'code',
|
|
167
168
|
'component',
|
|
168
169
|
'prop',
|
|
169
|
-
'message',
|
|
170
|
-
'fix',
|
|
171
170
|
'file',
|
|
172
171
|
'line',
|
|
173
172
|
],
|
|
@@ -143,7 +143,11 @@ describe('--json contract: supported commands emit valid envelopes', () => {
|
|
|
143
143
|
const parsed = parseJson(stdout);
|
|
144
144
|
expect(parsed.type).toBe('discover.list');
|
|
145
145
|
expect(parsed.data).toEqual([]);
|
|
146
|
-
expect(parsed.meta).
|
|
146
|
+
expect(parsed.meta.configured).toBe(false);
|
|
147
|
+
// The official list the CLI carries is always a source.
|
|
148
|
+
expect(parsed.meta.sources).toEqual([
|
|
149
|
+
expect.objectContaining({name: 'Astryx', status: 'fresh'}),
|
|
150
|
+
]);
|
|
147
151
|
});
|
|
148
152
|
|
|
149
153
|
it('astryx template --json emits a typed envelope', async () => {
|
|
@@ -116,6 +116,20 @@ export const doc = {
|
|
|
116
116
|
],
|
|
117
117
|
related: ['init', 'doctor'],
|
|
118
118
|
notes: [
|
|
119
|
+
{type: 'heading', level: 3, text: 'A CLI older than your Core'},
|
|
120
|
+
{
|
|
121
|
+
type: 'prose',
|
|
122
|
+
text:
|
|
123
|
+
'Core codemods ship inside the CLI, so a CLI older than the installed @astryxdesign/core has none for ' +
|
|
124
|
+
'the releases after its own version. upgrade then says it cannot finish, never reports your code as up to date, ' +
|
|
125
|
+
'and prints the same upgrade pinned to the CLI release that matches your Core, such as ' +
|
|
126
|
+
'`cd <project> && npx @astryxdesign/cli@<core-version> upgrade --from <old-version> --path <source-dir> --apply`. ' +
|
|
127
|
+
'It changes to the folder this run used and names the directory it scanned as an absolute path, both with ' +
|
|
128
|
+
'symbolic links resolved, so pasted from any folder it upgrades the same code. It is written for a POSIX shell (sh, bash, zsh), or for PowerShell on Windows, ' +
|
|
129
|
+
'with each argument quoted for that shell; cmd.exe is not a target. The codemods this CLI has still run. ' +
|
|
130
|
+
'It exits 0, so a script checks the JSON: the result carries `cliBehindCore` with `cliVersion` (the newest release ' +
|
|
131
|
+
'this CLI has codemods for) and `command`.',
|
|
132
|
+
},
|
|
119
133
|
{type: 'heading', level: 3, text: 'Protected files'},
|
|
120
134
|
{
|
|
121
135
|
type: 'prose',
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file `astryx upgrade` with a CLI older than the installed Core: the human
|
|
5
|
+
* output never says the code is up to date, warns once with the same upgrade
|
|
6
|
+
* pinned to the CLI release that matches the Core, and keeps the exit status;
|
|
7
|
+
* `--json` carries the same facts in `cliBehindCore`. Pasted anywhere, the
|
|
8
|
+
* printed command runs that upgrade in the same project.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {describe, it, expect, beforeEach, afterEach} from 'vitest';
|
|
12
|
+
import {spawnSync} from 'node:child_process';
|
|
13
|
+
import * as fs from 'node:fs';
|
|
14
|
+
import * as os from 'node:os';
|
|
15
|
+
import * as path from 'node:path';
|
|
16
|
+
import {runCli} from '../../../test-utils/run-cli.mjs';
|
|
17
|
+
import {CLI_ROOT} from '../../../foundation/fs/paths.mjs';
|
|
18
|
+
import {
|
|
19
|
+
commandInFolder,
|
|
20
|
+
getDlxPrefix,
|
|
21
|
+
quoteCommandArgument,
|
|
22
|
+
} from '../../../foundation/env/package-manager.mjs';
|
|
23
|
+
|
|
24
|
+
const CLI_VERSION = JSON.parse(
|
|
25
|
+
fs.readFileSync(path.join(CLI_ROOT, 'package.json'), 'utf8'),
|
|
26
|
+
).version;
|
|
27
|
+
const [MAJOR, MINOR] = CLI_VERSION.split('.').map(Number);
|
|
28
|
+
const NEWER_CORE = `${MAJOR}.${MINOR + 1}.0`;
|
|
29
|
+
const NON_ASCII = /[\u0080-\uFFFF]/;
|
|
30
|
+
|
|
31
|
+
let tmpDir;
|
|
32
|
+
|
|
33
|
+
/** @param {string} rel @param {string} body */
|
|
34
|
+
function write(rel, body) {
|
|
35
|
+
const file = path.join(tmpDir, rel);
|
|
36
|
+
fs.mkdirSync(path.dirname(file), {recursive: true});
|
|
37
|
+
fs.writeFileSync(file, body);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-upgrade-older-cli-'));
|
|
42
|
+
write('package.json', JSON.stringify({name: 'consumer', private: true}));
|
|
43
|
+
write(
|
|
44
|
+
'node_modules/@astryxdesign/core/package.json',
|
|
45
|
+
JSON.stringify({name: '@astryxdesign/core', version: NEWER_CORE}),
|
|
46
|
+
);
|
|
47
|
+
write('src/index.ts', 'export const x = 1;\n');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
afterEach(() => {
|
|
51
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The pinned command the CLI prints for this project. It names the folder the
|
|
56
|
+
* CLI ran in and the source directory as the CLI resolved them.
|
|
57
|
+
* @param {...string} rest the arguments after `--path <dir>`
|
|
58
|
+
*/
|
|
59
|
+
function pinned(...rest) {
|
|
60
|
+
const project = fs.realpathSync(tmpDir);
|
|
61
|
+
return commandInFolder(
|
|
62
|
+
project,
|
|
63
|
+
[
|
|
64
|
+
getDlxPrefix(tmpDir),
|
|
65
|
+
`@astryxdesign/cli@${NEWER_CORE}`,
|
|
66
|
+
'upgrade',
|
|
67
|
+
'--from',
|
|
68
|
+
CLI_VERSION,
|
|
69
|
+
'--path',
|
|
70
|
+
quoteCommandArgument(path.join(project, 'src')),
|
|
71
|
+
...rest,
|
|
72
|
+
].join(' '),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Stand-ins for the package runners: each drops its own words and the pinned
|
|
78
|
+
* package, then runs this CLI with the rest of the command.
|
|
79
|
+
*/
|
|
80
|
+
const RUNS_THIS_CLI = [
|
|
81
|
+
['npx', 1],
|
|
82
|
+
['bunx', 1],
|
|
83
|
+
['pnpm', 2],
|
|
84
|
+
['yarn', 2],
|
|
85
|
+
]
|
|
86
|
+
.map(
|
|
87
|
+
([name, words]) =>
|
|
88
|
+
`${name}() { shift ${words}; "$0" ${quoteCommandArgument(path.join(CLI_ROOT, 'clients', 'cli', 'bin', 'astryx.mjs'))} "$@"; }`,
|
|
89
|
+
)
|
|
90
|
+
.join('; ');
|
|
91
|
+
|
|
92
|
+
describe('astryx upgrade with a CLI older than the installed Core', () => {
|
|
93
|
+
it('says it cannot finish and prints the upgrade pinned to the matching CLI', async () => {
|
|
94
|
+
const r = await runCli(['upgrade', '--from', CLI_VERSION, '--apply'], {
|
|
95
|
+
cwd: tmpDir,
|
|
96
|
+
});
|
|
97
|
+
const output = `${r.stdout}\n${r.stderr}`;
|
|
98
|
+
|
|
99
|
+
expect(r.status).toBe(0);
|
|
100
|
+
expect(output).not.toMatch(/up to date/i);
|
|
101
|
+
expect(output).not.toContain('No codemods available');
|
|
102
|
+
expect(r.stderr).toContain(
|
|
103
|
+
`This CLI (${CLI_VERSION}) is older than the installed @astryxdesign/core (${NEWER_CORE})`,
|
|
104
|
+
);
|
|
105
|
+
// The command has a line of its own, so it copies exactly.
|
|
106
|
+
expect(r.stderr).toContain(
|
|
107
|
+
`the CLI that matches your Core:\n ${pinned('--apply')}\n`,
|
|
108
|
+
);
|
|
109
|
+
expect(r.stdout.trim().split('\n').at(-1)).toBe('Upgrade incomplete');
|
|
110
|
+
expect(output.split('\n').filter(line => NON_ASCII.test(line))).toEqual([]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('carries cliBehindCore in --json with the same exit status', async () => {
|
|
114
|
+
const r = await runCli(['--json', 'upgrade', '--from', CLI_VERSION], {
|
|
115
|
+
cwd: tmpDir,
|
|
116
|
+
});
|
|
117
|
+
const parsed = JSON.parse(r.stdout);
|
|
118
|
+
|
|
119
|
+
expect(r.status).toBe(0);
|
|
120
|
+
expect(parsed.type).toBe('upgrade.status');
|
|
121
|
+
expect(parsed.data.status).toBe('no_codemods');
|
|
122
|
+
expect(parsed.data.cliBehindCore).toEqual({
|
|
123
|
+
cliVersion: CLI_VERSION,
|
|
124
|
+
command: pinned(),
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Where an upgrade runs decides what it finds: the installed Core is read
|
|
129
|
+
// from that folder, and --path must stay inside it. Printed without its
|
|
130
|
+
// folder, the command exited 1 when pasted in a subfolder
|
|
131
|
+
// (ERR_PATH_TRAVERSAL) or in the folder above (ERR_VERSION_DETECT).
|
|
132
|
+
it.skipIf(process.platform === 'win32')(
|
|
133
|
+
'prints a command that upgrades the same project wherever it is pasted',
|
|
134
|
+
async () => {
|
|
135
|
+
write('src/deep/index.ts', 'export const y = 2;\n');
|
|
136
|
+
const r = await runCli(['--json', 'upgrade', '--from', CLI_VERSION], {
|
|
137
|
+
cwd: tmpDir,
|
|
138
|
+
});
|
|
139
|
+
const {command} = JSON.parse(r.stdout).data.cliBehindCore;
|
|
140
|
+
|
|
141
|
+
for (const pastedIn of [
|
|
142
|
+
path.join(tmpDir, 'src', 'deep'),
|
|
143
|
+
path.dirname(tmpDir),
|
|
144
|
+
]) {
|
|
145
|
+
const ran = spawnSync(
|
|
146
|
+
'/bin/sh',
|
|
147
|
+
['-c', `${RUNS_THIS_CLI}; ${command}`, process.execPath],
|
|
148
|
+
{cwd: pastedIn, encoding: 'utf8'},
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
expect(ran.status, ran.stderr).toBe(0);
|
|
152
|
+
expect(ran.stdout).toContain(`Installed target: ${NEWER_CORE}`);
|
|
153
|
+
expect(ran.stdout).toContain(
|
|
154
|
+
`Scanning ${path.join(fs.realpathSync(tmpDir), 'src')} `,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
30_000,
|
|
159
|
+
);
|
|
160
|
+
});
|