@astryxdesign/cli 0.7.0-canary.19b1c00 → 0.7.0-canary.1bd7016
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/api/doctor/doctor.d.mts +30 -2
- package/api/doctor/doctor.doc.mjs +2 -1
- package/api/doctor/doctor.mjs +153 -3
- package/api/doctor/doctor.test.mjs +250 -4
- package/assets/codemods/transforms/next/__tests__/rename-empty-search-results-text.test.mjs +202 -0
- package/assets/codemods/transforms/next/index.mjs +8 -0
- package/assets/codemods/transforms/next/rename-empty-search-results-text.mjs +254 -0
- package/clients/cli/commands/doctor.doc.mjs +1 -1
- package/clients/cli/commands/doctor.test.mjs +33 -0
- package/package.json +9 -9
package/api/doctor/doctor.d.mts
CHANGED
|
@@ -49,6 +49,25 @@ export function checkConfig(ctx: DoctorContext): Promise<DoctorCheck>;
|
|
|
49
49
|
* @returns {DoctorCheck}
|
|
50
50
|
*/
|
|
51
51
|
export function checkImplicitIntegrations(ctx: DoctorContext): DoctorCheck;
|
|
52
|
+
/**
|
|
53
|
+
* Every integration named in astryx.config loads.
|
|
54
|
+
*
|
|
55
|
+
* A configured integration that cannot be loaded (not installed, no
|
|
56
|
+
* manifest, or a manifest that throws or fails its schema) is withdrawn
|
|
57
|
+
* whole, because none of its contribution roots is trustworthy
|
|
58
|
+
* (spec:AST-035 FR9). The project then runs without something it asked
|
|
59
|
+
* for, so this fails the CI gate.
|
|
60
|
+
*
|
|
61
|
+
* Two neighbours stay as they were. A problem inside one contribution kind
|
|
62
|
+
* leaves the rest of the integration working, so `integration-issues` keeps
|
|
63
|
+
* warning about it (spec:AST-035 FR9). An autolinked dependency that cannot
|
|
64
|
+
* be loaded stays informational in `implicit-integrations`: the project did
|
|
65
|
+
* not ask for it.
|
|
66
|
+
*
|
|
67
|
+
* @param {DoctorContext} ctx
|
|
68
|
+
* @returns {DoctorCheck}
|
|
69
|
+
*/
|
|
70
|
+
export function checkConfiguredIntegrations(ctx: DoctorContext): DoctorCheck;
|
|
52
71
|
/**
|
|
53
72
|
* Check 7 — agent docs exist and contain the Astryx section markers.
|
|
54
73
|
* @param {DoctorContext} ctx
|
|
@@ -253,13 +272,22 @@ export type DoctorContext = {
|
|
|
253
272
|
severity: "warning" | "error";
|
|
254
273
|
message: string;
|
|
255
274
|
}[] | null | undefined;
|
|
275
|
+
autolinkFailures?: {
|
|
276
|
+
spec: string;
|
|
277
|
+
error: string;
|
|
278
|
+
}[] | null | undefined;
|
|
256
279
|
/**
|
|
280
|
+
* Every name astryx.config lists, from the provider ledger: the package it
|
|
281
|
+
* reached (or failed to reach) and why loading failed, if it did. Set aside
|
|
282
|
+
* for a provider conflict, replaced by the package being authored, or
|
|
283
|
+
* repeated under another name all still count as configured.
|
|
257
284
|
* installed dependencies whose integration manifest could not be loaded
|
|
258
285
|
* Combined project-level integration issues, including cross-package template replacement warnings.
|
|
259
286
|
*/
|
|
260
|
-
|
|
287
|
+
configuredIntegrations?: {
|
|
261
288
|
spec: string;
|
|
262
|
-
|
|
289
|
+
label: string;
|
|
290
|
+
error: string | null;
|
|
263
291
|
}[] | null | undefined;
|
|
264
292
|
/**
|
|
265
293
|
* - Error thrown while resolving the config
|
|
@@ -18,7 +18,8 @@ export const doc = {
|
|
|
18
18
|
description:
|
|
19
19
|
'Runs a series of diagnostics: Node version, ' +
|
|
20
20
|
'@astryxdesign/core install and version alignment with the CLI, installed ' +
|
|
21
|
-
'themes and wiring, astryx.config validity,
|
|
21
|
+
'themes and wiring, astryx.config validity, whether every integration ' +
|
|
22
|
+
'astryx.config names loads (a failed one fails the run), integrations linked from ' +
|
|
22
23
|
'package.json without a config entry, core peer dependencies, ' +
|
|
23
24
|
'integration provider identity and contribution issues, agent docs, the ' +
|
|
24
25
|
'detected package manager, and the health of the docs the CLI reads (authoring ' +
|
package/api/doctor/doctor.mjs
CHANGED
|
@@ -82,6 +82,11 @@ import {checkAppThemes, checkThemes} from './theme-checks.mjs';
|
|
|
82
82
|
* could not be built, when it could not.
|
|
83
83
|
* @property {Array<{package: string, code: string, severity: 'warning'|'error', message: string}>|null} [integrationIssues]
|
|
84
84
|
* @property {Array<{spec: string, error: string}>|null} [autolinkFailures]
|
|
85
|
+
* @property {Array<{spec: string, label: string, error: string|null}>|null} [configuredIntegrations]
|
|
86
|
+
* Every name astryx.config lists, from the provider ledger: the package it
|
|
87
|
+
* reached (or failed to reach) and why loading failed, if it did. Set aside
|
|
88
|
+
* for a provider conflict, replaced by the package being authored, or
|
|
89
|
+
* repeated under another name all still count as configured.
|
|
85
90
|
* installed dependencies whose integration manifest could not be loaded
|
|
86
91
|
* Combined project-level integration issues, including cross-package template replacement warnings.
|
|
87
92
|
* @property {Error|null} [configError] - Error thrown while resolving the config
|
|
@@ -319,12 +324,12 @@ export async function checkConfig(ctx) {
|
|
|
319
324
|
}
|
|
320
325
|
// Importing is not the whole test: the CLI also validates the config, and
|
|
321
326
|
// a config it rejects leaves every project-aware command without the
|
|
322
|
-
// project.
|
|
327
|
+
// project. Doctor is the CI gate, so that fails.
|
|
323
328
|
if (ctx.projectError) {
|
|
324
329
|
return {
|
|
325
330
|
id: 'config',
|
|
326
331
|
label: 'astryx.config.mjs',
|
|
327
|
-
status: '
|
|
332
|
+
status: 'fail',
|
|
328
333
|
message: `astryx.config.mjs loads, but the CLI could not load the project from it: ${firstLine(ctx.projectError)}`,
|
|
329
334
|
fix: 'Fix what the message names. `astryx docs authoring config` lists every field astryx.config accepts.',
|
|
330
335
|
};
|
|
@@ -475,6 +480,88 @@ function describeUnreadableManifests(failures) {
|
|
|
475
480
|
);
|
|
476
481
|
}
|
|
477
482
|
|
|
483
|
+
/**
|
|
484
|
+
* Every integration named in astryx.config loads.
|
|
485
|
+
*
|
|
486
|
+
* A configured integration that cannot be loaded (not installed, no
|
|
487
|
+
* manifest, or a manifest that throws or fails its schema) is withdrawn
|
|
488
|
+
* whole, because none of its contribution roots is trustworthy
|
|
489
|
+
* (spec:AST-035 FR9). The project then runs without something it asked
|
|
490
|
+
* for, so this fails the CI gate.
|
|
491
|
+
*
|
|
492
|
+
* Two neighbours stay as they were. A problem inside one contribution kind
|
|
493
|
+
* leaves the rest of the integration working, so `integration-issues` keeps
|
|
494
|
+
* warning about it (spec:AST-035 FR9). An autolinked dependency that cannot
|
|
495
|
+
* be loaded stays informational in `implicit-integrations`: the project did
|
|
496
|
+
* not ask for it.
|
|
497
|
+
*
|
|
498
|
+
* @param {DoctorContext} ctx
|
|
499
|
+
* @returns {DoctorCheck}
|
|
500
|
+
*/
|
|
501
|
+
export function checkConfiguredIntegrations(ctx) {
|
|
502
|
+
const id = 'configured-integrations';
|
|
503
|
+
const label = 'Configured integrations';
|
|
504
|
+
if (ctx.integrations == null) {
|
|
505
|
+
// The config check reports a config the CLI cannot load.
|
|
506
|
+
return {
|
|
507
|
+
id,
|
|
508
|
+
label,
|
|
509
|
+
status: 'info',
|
|
510
|
+
message: skippedBecause(ctx, 'the project configuration could not be read'),
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
// What counts as configured is what astryx.config names, read from the
|
|
514
|
+
// provider ledger so a package set aside for a provider conflict, or the
|
|
515
|
+
// package being authored when its own config names it, still counts.
|
|
516
|
+
const configured =
|
|
517
|
+
ctx.configuredIntegrations ??
|
|
518
|
+
ctx.integrations
|
|
519
|
+
.filter(integration => !integration.__autolinked && !integration.__local)
|
|
520
|
+
.map(integration => ({
|
|
521
|
+
spec: integration.__spec,
|
|
522
|
+
label: integration.name ?? integration.__spec,
|
|
523
|
+
error:
|
|
524
|
+
integration.__loadError == null
|
|
525
|
+
? null
|
|
526
|
+
: String(integration.__loadError),
|
|
527
|
+
}));
|
|
528
|
+
if (configured.length === 0) {
|
|
529
|
+
return {
|
|
530
|
+
id,
|
|
531
|
+
label,
|
|
532
|
+
status: 'info',
|
|
533
|
+
message: 'No integration is named in astryx.config.',
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
const plural = configured.length === 1 ? '' : 's';
|
|
537
|
+
const withdrawn = configured.filter(entry => entry.error != null);
|
|
538
|
+
if (withdrawn.length > 0) {
|
|
539
|
+
const listed = withdrawn
|
|
540
|
+
.map(
|
|
541
|
+
entry =>
|
|
542
|
+
`${entry.label} (${firstLine(String(entry.error)).slice(0, 160)})`,
|
|
543
|
+
)
|
|
544
|
+
.join('; ');
|
|
545
|
+
return {
|
|
546
|
+
id,
|
|
547
|
+
label,
|
|
548
|
+
status: 'fail',
|
|
549
|
+
message:
|
|
550
|
+
`${withdrawn.length} of ${configured.length} integration${plural} named in astryx.config could not be loaded, ` +
|
|
551
|
+
`so ${withdrawn.length === 1 ? 'it contributes' : 'they contribute'} nothing: ${listed}.`,
|
|
552
|
+
fix:
|
|
553
|
+
'Install each one, fix its astryx.integration.* manifest (`astryx doctor integration validate <package>` says what is wrong), ' +
|
|
554
|
+
'or remove it from `integrations` in astryx.config.',
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
return {
|
|
558
|
+
id,
|
|
559
|
+
label,
|
|
560
|
+
status: 'pass',
|
|
561
|
+
message: `${configured.length} integration${plural} named in astryx.config loaded: ${configured.map(entry => entry.label).join(', ')}.`,
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
|
|
478
565
|
/**
|
|
479
566
|
* Check 7 — agent docs exist and contain the Astryx section markers.
|
|
480
567
|
* @param {DoctorContext} ctx
|
|
@@ -1201,6 +1288,7 @@ export const SYNC_CHECKS = [
|
|
|
1201
1288
|
checkCoreInstalled,
|
|
1202
1289
|
checkVersionAlignment,
|
|
1203
1290
|
checkImplicitIntegrations,
|
|
1291
|
+
checkConfiguredIntegrations,
|
|
1204
1292
|
checkProviderIdentity,
|
|
1205
1293
|
checkIntegrationIssues,
|
|
1206
1294
|
checkAgentDocs,
|
|
@@ -1244,6 +1332,8 @@ export async function runChecks(options = {}) {
|
|
|
1244
1332
|
let integrationIssues = null;
|
|
1245
1333
|
/** @type {Array<{spec: string, error: string}>|null} */
|
|
1246
1334
|
let autolinkFailures = null;
|
|
1335
|
+
/** @type {Array<{spec: string, label: string, error: string|null}>|null} */
|
|
1336
|
+
let configuredIntegrations = null;
|
|
1247
1337
|
/** @type {string|null} */
|
|
1248
1338
|
let projectError = null;
|
|
1249
1339
|
/** @type {import('../../foundation/config/project.mjs').Project | null} */
|
|
@@ -1261,7 +1351,66 @@ export async function runChecks(options = {}) {
|
|
|
1261
1351
|
integrations = project.loadedIntegrations;
|
|
1262
1352
|
// An installed dependency whose manifest cannot be loaded is kept out of
|
|
1263
1353
|
// loadedIntegrations on purpose. The provider ledger still records it.
|
|
1264
|
-
|
|
1354
|
+
const ledgerMap = providerLedgerOf(project);
|
|
1355
|
+
const ledger = [...ledgerMap.values()];
|
|
1356
|
+
// The package that stands for a configured name: when the package
|
|
1357
|
+
// being authored replaces the configured copy, the authored package's
|
|
1358
|
+
// outcome is the one that matters, so a broken authored manifest fails
|
|
1359
|
+
// the check even though the configured copy itself loaded. A package
|
|
1360
|
+
// set aside for a provider conflict keeps its own outcome.
|
|
1361
|
+
/** @param {import('../../foundation/integrations/provider-resolution.mjs').ProviderLedgerEntry} entry */
|
|
1362
|
+
const standsFor = entry => {
|
|
1363
|
+
let current = entry;
|
|
1364
|
+
const seen = new Set();
|
|
1365
|
+
while (
|
|
1366
|
+
current.outcome === 'set-aside' &&
|
|
1367
|
+
current.reason === 'replaced-by-authored' &&
|
|
1368
|
+
current.winner != null &&
|
|
1369
|
+
!seen.has(current.winner) &&
|
|
1370
|
+
ledgerMap.has(current.winner)
|
|
1371
|
+
) {
|
|
1372
|
+
seen.add(current.winner);
|
|
1373
|
+
current = /** @type {typeof entry} */ (ledgerMap.get(current.winner));
|
|
1374
|
+
}
|
|
1375
|
+
return current;
|
|
1376
|
+
};
|
|
1377
|
+
// Every package a configured name reached, however it was resolved.
|
|
1378
|
+
configuredIntegrations = ledger
|
|
1379
|
+
.filter(entry =>
|
|
1380
|
+
entry.refs.some(
|
|
1381
|
+
ref => ref.source === 'configured' && ref.repeat !== true,
|
|
1382
|
+
),
|
|
1383
|
+
)
|
|
1384
|
+
.map(entry => {
|
|
1385
|
+
const ref = entry.refs.find(
|
|
1386
|
+
candidate => candidate.source === 'configured',
|
|
1387
|
+
);
|
|
1388
|
+
const effective = standsFor(entry);
|
|
1389
|
+
// When node_modules/<name> links back to the package being authored,
|
|
1390
|
+
// the configured and local candidates share one real path and one
|
|
1391
|
+
// entry whose outcome is the set-aside; the authored (`local`)
|
|
1392
|
+
// candidate on that entry carries the load error, so it is the
|
|
1393
|
+
// outcome that counts. Reading it from the ref, not by comparing
|
|
1394
|
+
// paths, holds whether or not the working directory is itself a
|
|
1395
|
+
// symlink.
|
|
1396
|
+
const authored = effective.refs.find(
|
|
1397
|
+
candidate => candidate.source === 'local',
|
|
1398
|
+
);
|
|
1399
|
+
const authoredError =
|
|
1400
|
+
authored?.integration?.__loadError ?? authored?.error ?? null;
|
|
1401
|
+
const loadError =
|
|
1402
|
+
effective.outcome === 'load-failed'
|
|
1403
|
+
? (effective.error ?? 'its manifest could not be loaded')
|
|
1404
|
+
: authoredError != null
|
|
1405
|
+
? String(authoredError)
|
|
1406
|
+
: null;
|
|
1407
|
+
return {
|
|
1408
|
+
spec: ref?.spec ?? entry.label,
|
|
1409
|
+
label: entry.integration?.name ?? ref?.spec ?? entry.label,
|
|
1410
|
+
error: loadError,
|
|
1411
|
+
};
|
|
1412
|
+
});
|
|
1413
|
+
autolinkFailures = ledger
|
|
1265
1414
|
.filter(
|
|
1266
1415
|
entry =>
|
|
1267
1416
|
entry.outcome === 'load-failed' &&
|
|
@@ -1300,6 +1449,7 @@ export async function runChecks(options = {}) {
|
|
|
1300
1449
|
docsCatalogError,
|
|
1301
1450
|
integrationIssues,
|
|
1302
1451
|
autolinkFailures,
|
|
1452
|
+
configuredIntegrations,
|
|
1303
1453
|
configError,
|
|
1304
1454
|
projectError,
|
|
1305
1455
|
};
|
|
@@ -1042,7 +1042,7 @@ describe('doctor says why it skipped and what it checked', () => {
|
|
|
1042
1042
|
}
|
|
1043
1043
|
|
|
1044
1044
|
it(
|
|
1045
|
-
'
|
|
1045
|
+
'fails, and quotes the reason, when the CLI cannot load the project from a config that imports',
|
|
1046
1046
|
async () => {
|
|
1047
1047
|
const dir = cwdProject({
|
|
1048
1048
|
'package.json': '{"name":"app"}',
|
|
@@ -1051,7 +1051,7 @@ describe('doctor says why it skipped and what it checked', () => {
|
|
|
1051
1051
|
});
|
|
1052
1052
|
const {checks, summary} = (await doctor({cwd: dir})).data;
|
|
1053
1053
|
const by = Object.fromEntries(checks.map(c => [c.id, c]));
|
|
1054
|
-
expect(by.config.status).toBe('
|
|
1054
|
+
expect(by.config.status).toBe('fail');
|
|
1055
1055
|
expect(by.config.message).toMatch(
|
|
1056
1056
|
/^astryx\.config\.mjs loads, but the CLI could not load the project from it: .*integrations/,
|
|
1057
1057
|
);
|
|
@@ -1064,8 +1064,8 @@ describe('doctor says why it skipped and what it checked', () => {
|
|
|
1064
1064
|
expect(by['integration-issues'].message).toMatch(
|
|
1065
1065
|
/^Skipped — the project integration graph could not be loaded: .*integrations/,
|
|
1066
1066
|
);
|
|
1067
|
-
//
|
|
1068
|
-
expect(summary.fail).toBe(
|
|
1067
|
+
// The config check is the one failure; the skipped checks stay info.
|
|
1068
|
+
expect(summary.fail).toBe(1);
|
|
1069
1069
|
},
|
|
1070
1070
|
SLOW,
|
|
1071
1071
|
);
|
|
@@ -1123,6 +1123,252 @@ describe('doctor says why it skipped and what it checked', () => {
|
|
|
1123
1123
|
});
|
|
1124
1124
|
});
|
|
1125
1125
|
|
|
1126
|
+
describe('a configured integration that cannot load fails the gate', () => {
|
|
1127
|
+
const CORE_STUB = {
|
|
1128
|
+
'node_modules/@astryxdesign/core/package.json': JSON.stringify({
|
|
1129
|
+
name: '@astryxdesign/core',
|
|
1130
|
+
version: '0.6.3',
|
|
1131
|
+
}),
|
|
1132
|
+
};
|
|
1133
|
+
const WIDGETS = 'node_modules/@acme/widgets';
|
|
1134
|
+
/** @param {string} [manifest] */
|
|
1135
|
+
const widgets = (
|
|
1136
|
+
manifest = "export default {components: './components'};\n",
|
|
1137
|
+
) => ({
|
|
1138
|
+
[`${WIDGETS}/package.json`]: JSON.stringify({
|
|
1139
|
+
name: '@acme/widgets',
|
|
1140
|
+
version: '1.0.0',
|
|
1141
|
+
}),
|
|
1142
|
+
[`${WIDGETS}/astryx.integration.mjs`]: manifest,
|
|
1143
|
+
[`${WIDGETS}/components/AcmeCard.doc.mjs`]:
|
|
1144
|
+
"export default {type: 'component', name: 'AcmeCard', displayName: 'AcmeCard', description: 'Fixture.', props: []};\n",
|
|
1145
|
+
[`${WIDGETS}/components/AcmeCard.tsx`]:
|
|
1146
|
+
'export default function AcmeCard() { return null; }\n',
|
|
1147
|
+
});
|
|
1148
|
+
const APP = {
|
|
1149
|
+
'package.json': '{"name":"app"}',
|
|
1150
|
+
...CORE_STUB,
|
|
1151
|
+
'astryx.config.mjs': "export default { integrations: ['@acme/widgets'] };\n",
|
|
1152
|
+
};
|
|
1153
|
+
|
|
1154
|
+
/** Run doctor on a project under the working directory. */
|
|
1155
|
+
async function report(files) {
|
|
1156
|
+
const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-gate-'));
|
|
1157
|
+
tmpDirs.push(dir);
|
|
1158
|
+
for (const [rel, content] of Object.entries(files)) {
|
|
1159
|
+
const abs = path.join(dir, rel);
|
|
1160
|
+
fs.mkdirSync(path.dirname(abs), {recursive: true});
|
|
1161
|
+
fs.writeFileSync(abs, content);
|
|
1162
|
+
}
|
|
1163
|
+
const {checks, summary} = (await doctor({cwd: dir})).data;
|
|
1164
|
+
return {by: Object.fromEntries(checks.map(c => [c.id, c])), summary};
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
it.each([
|
|
1168
|
+
['not installed', {}, /Could not find installed integration package "@acme\/widgets"/],
|
|
1169
|
+
[
|
|
1170
|
+
'installed without a manifest',
|
|
1171
|
+
{[`${WIDGETS}/package.json`]: JSON.stringify({name: '@acme/widgets', version: '1.0.0'})},
|
|
1172
|
+
/no conventional root manifest/,
|
|
1173
|
+
],
|
|
1174
|
+
['installed with a manifest that throws', widgets('export default { not valid ((\n'), /Unexpected/],
|
|
1175
|
+
])(
|
|
1176
|
+
'fails when a configured integration is %s, and names it',
|
|
1177
|
+
async (_shape, extra, reason) => {
|
|
1178
|
+
const {by, summary} = await report({...APP, ...extra});
|
|
1179
|
+
const check = by['configured-integrations'];
|
|
1180
|
+
expect(check.status).toBe('fail');
|
|
1181
|
+
expect(check.message).toMatch(
|
|
1182
|
+
/^1 of 1 integration named in astryx\.config could not be loaded, so it contributes nothing: @acme\/widgets \(/,
|
|
1183
|
+
);
|
|
1184
|
+
expect(check.message).toMatch(reason);
|
|
1185
|
+
expect(check.fix).toContain('astryx doctor integration validate <package>');
|
|
1186
|
+
expect(summary.fail).toBe(1);
|
|
1187
|
+
},
|
|
1188
|
+
SLOW,
|
|
1189
|
+
);
|
|
1190
|
+
|
|
1191
|
+
it(
|
|
1192
|
+
'counts the package being authored when its own config names it',
|
|
1193
|
+
async () => {
|
|
1194
|
+
const {by} = await report({
|
|
1195
|
+
...CORE_STUB,
|
|
1196
|
+
'package.json': JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
|
|
1197
|
+
'astryx.integration.mjs': "export default {components: './components'};\n",
|
|
1198
|
+
'components/AcmeCard.doc.mjs':
|
|
1199
|
+
"export default {type: 'component', name: 'AcmeCard', displayName: 'AcmeCard', description: 'Fixture.', props: []};\n",
|
|
1200
|
+
'components/AcmeCard.tsx': 'export default function AcmeCard() { return null; }\n',
|
|
1201
|
+
'astryx.config.mjs': "export default { integrations: ['@acme/widgets'] };\n",
|
|
1202
|
+
});
|
|
1203
|
+
expect(by['configured-integrations'].status).toBe('pass');
|
|
1204
|
+
expect(by['configured-integrations'].message).toBe(
|
|
1205
|
+
'1 integration named in astryx.config loaded: @acme/widgets.',
|
|
1206
|
+
);
|
|
1207
|
+
},
|
|
1208
|
+
SLOW,
|
|
1209
|
+
);
|
|
1210
|
+
|
|
1211
|
+
it(
|
|
1212
|
+
'fails when the package being authored is named by its own config and its manifest throws',
|
|
1213
|
+
async () => {
|
|
1214
|
+
const {by, summary} = await report({
|
|
1215
|
+
...CORE_STUB,
|
|
1216
|
+
'package.json': JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
|
|
1217
|
+
'astryx.integration.mjs': 'export default { not valid ((\n',
|
|
1218
|
+
'astryx.config.mjs': "export default { integrations: ['@acme/widgets'] };\n",
|
|
1219
|
+
});
|
|
1220
|
+
const check = by['configured-integrations'];
|
|
1221
|
+
expect(check.status).toBe('fail');
|
|
1222
|
+
expect(check.message).toMatch(
|
|
1223
|
+
/^1 of 1 integration named in astryx\.config could not be loaded, so it contributes nothing: @acme\/widgets \(/,
|
|
1224
|
+
);
|
|
1225
|
+
expect(summary.fail).toBe(1);
|
|
1226
|
+
},
|
|
1227
|
+
SLOW,
|
|
1228
|
+
);
|
|
1229
|
+
|
|
1230
|
+
it(
|
|
1231
|
+
'fails when node_modules links the configured name back to the authored package and its manifest throws',
|
|
1232
|
+
async () => {
|
|
1233
|
+
const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-gate-'));
|
|
1234
|
+
tmpDirs.push(dir);
|
|
1235
|
+
const files = {
|
|
1236
|
+
...CORE_STUB,
|
|
1237
|
+
'package.json': JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
|
|
1238
|
+
'astryx.integration.mjs': 'export default { not valid ((\n',
|
|
1239
|
+
'astryx.config.mjs': "export default { integrations: ['@acme/widgets'] };\n",
|
|
1240
|
+
};
|
|
1241
|
+
for (const [rel, content] of Object.entries(files)) {
|
|
1242
|
+
const abs = path.join(dir, rel);
|
|
1243
|
+
fs.mkdirSync(path.dirname(abs), {recursive: true});
|
|
1244
|
+
fs.writeFileSync(abs, content);
|
|
1245
|
+
}
|
|
1246
|
+
fs.mkdirSync(path.join(dir, 'node_modules/@acme'), {recursive: true});
|
|
1247
|
+
fs.symlinkSync(dir, path.join(dir, 'node_modules/@acme/widgets'), 'dir');
|
|
1248
|
+
const {checks, summary} = (await doctor({cwd: dir})).data;
|
|
1249
|
+
const by = Object.fromEntries(checks.map(c => [c.id, c]));
|
|
1250
|
+
expect(by['configured-integrations'].status).toBe('fail');
|
|
1251
|
+
expect(by['configured-integrations'].message).toMatch(
|
|
1252
|
+
/^1 of 1 integration named in astryx\.config could not be loaded/,
|
|
1253
|
+
);
|
|
1254
|
+
expect(summary.fail).toBe(1);
|
|
1255
|
+
},
|
|
1256
|
+
SLOW,
|
|
1257
|
+
);
|
|
1258
|
+
|
|
1259
|
+
it(
|
|
1260
|
+
'fails for the self-linked authored package when the working directory is itself a symlink',
|
|
1261
|
+
async () => {
|
|
1262
|
+
const real = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-gate-'));
|
|
1263
|
+
tmpDirs.push(real);
|
|
1264
|
+
const linkParent = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-gate-'));
|
|
1265
|
+
tmpDirs.push(linkParent);
|
|
1266
|
+
const cwd = path.join(linkParent, 'link');
|
|
1267
|
+
fs.symlinkSync(real, cwd, 'dir');
|
|
1268
|
+
const files = {
|
|
1269
|
+
...CORE_STUB,
|
|
1270
|
+
'package.json': JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
|
|
1271
|
+
'astryx.integration.mjs': 'export default { not valid ((\n',
|
|
1272
|
+
'astryx.config.mjs': "export default { integrations: ['@acme/widgets'] };\n",
|
|
1273
|
+
};
|
|
1274
|
+
for (const [rel, content] of Object.entries(files)) {
|
|
1275
|
+
const abs = path.join(real, rel);
|
|
1276
|
+
fs.mkdirSync(path.dirname(abs), {recursive: true});
|
|
1277
|
+
fs.writeFileSync(abs, content);
|
|
1278
|
+
}
|
|
1279
|
+
fs.mkdirSync(path.join(real, 'node_modules/@acme'), {recursive: true});
|
|
1280
|
+
fs.symlinkSync(real, path.join(real, 'node_modules/@acme/widgets'), 'dir');
|
|
1281
|
+
const {checks, summary} = (await doctor({cwd})).data;
|
|
1282
|
+
const by = Object.fromEntries(checks.map(c => [c.id, c]));
|
|
1283
|
+
expect(by['configured-integrations'].status).toBe('fail');
|
|
1284
|
+
expect(summary.fail).toBe(1);
|
|
1285
|
+
},
|
|
1286
|
+
SLOW,
|
|
1287
|
+
);
|
|
1288
|
+
|
|
1289
|
+
it(
|
|
1290
|
+
'still counts a configured package that was set aside for a provider conflict',
|
|
1291
|
+
async () => {
|
|
1292
|
+
const CHARTS = 'node_modules/@acme/charts';
|
|
1293
|
+
const {by} = await report({
|
|
1294
|
+
...APP,
|
|
1295
|
+
'astryx.config.mjs':
|
|
1296
|
+
"export default { integrations: ['@acme/widgets', '@acme/charts'] };\n",
|
|
1297
|
+
...widgets("export default {providerId: 'acme', components: './components'};\n"),
|
|
1298
|
+
[`${CHARTS}/package.json`]: JSON.stringify({name: '@acme/charts', version: '1.0.0'}),
|
|
1299
|
+
[`${CHARTS}/astryx.integration.mjs`]:
|
|
1300
|
+
"export default {providerId: 'acme', components: './components'};\n",
|
|
1301
|
+
[`${CHARTS}/components/AcmeChart.doc.mjs`]:
|
|
1302
|
+
"export default {type: 'component', name: 'AcmeChart', displayName: 'AcmeChart', description: 'Fixture.', props: []};\n",
|
|
1303
|
+
[`${CHARTS}/components/AcmeChart.tsx`]: 'export default function AcmeChart() { return null; }\n',
|
|
1304
|
+
});
|
|
1305
|
+
expect(by['configured-integrations'].status).toBe('pass');
|
|
1306
|
+
expect(by['configured-integrations'].message).toMatch(/^2 integrations named in astryx\.config loaded: /);
|
|
1307
|
+
expect(by['configured-integrations'].message).toContain('@acme/charts');
|
|
1308
|
+
},
|
|
1309
|
+
SLOW,
|
|
1310
|
+
);
|
|
1311
|
+
|
|
1312
|
+
it(
|
|
1313
|
+
'passes, naming each one, when every configured integration loads',
|
|
1314
|
+
async () => {
|
|
1315
|
+
const {by, summary} = await report({...APP, ...widgets()});
|
|
1316
|
+
expect(by['configured-integrations']).toEqual({
|
|
1317
|
+
id: 'configured-integrations',
|
|
1318
|
+
label: 'Configured integrations',
|
|
1319
|
+
status: 'pass',
|
|
1320
|
+
message: '1 integration named in astryx.config loaded: @acme/widgets.',
|
|
1321
|
+
});
|
|
1322
|
+
expect(summary.fail).toBe(0);
|
|
1323
|
+
},
|
|
1324
|
+
SLOW,
|
|
1325
|
+
);
|
|
1326
|
+
|
|
1327
|
+
it.each([
|
|
1328
|
+
[
|
|
1329
|
+
'an invalid component doc',
|
|
1330
|
+
{[`${WIDGETS}/components/AcmeCard.doc.mjs`]: 'export default {;\n'},
|
|
1331
|
+
],
|
|
1332
|
+
[
|
|
1333
|
+
'a declared root missing on disk',
|
|
1334
|
+
{
|
|
1335
|
+
[`${WIDGETS}/astryx.integration.mjs`]:
|
|
1336
|
+
"export default {components: './components', templates: './templates'};\n",
|
|
1337
|
+
},
|
|
1338
|
+
],
|
|
1339
|
+
])(
|
|
1340
|
+
'keeps %s a warning, because the rest of the integration still loads (spec:AST-035 FR9)',
|
|
1341
|
+
async (_shape, extra) => {
|
|
1342
|
+
const {by, summary} = await report({...APP, ...widgets(), ...extra});
|
|
1343
|
+
expect(by['configured-integrations'].status).toBe('pass');
|
|
1344
|
+
expect(by['integration-issues'].status).toBe('warn');
|
|
1345
|
+
expect(summary.fail).toBe(0);
|
|
1346
|
+
},
|
|
1347
|
+
SLOW,
|
|
1348
|
+
);
|
|
1349
|
+
|
|
1350
|
+
it(
|
|
1351
|
+
'leaves an autolinked dependency that cannot load informational',
|
|
1352
|
+
async () => {
|
|
1353
|
+
const {by, summary} = await report({
|
|
1354
|
+
'package.json': JSON.stringify({
|
|
1355
|
+
name: 'app',
|
|
1356
|
+
dependencies: {'@acme/widgets': '1.0.0'},
|
|
1357
|
+
}),
|
|
1358
|
+
...CORE_STUB,
|
|
1359
|
+
...widgets('export default { not valid ((\n'),
|
|
1360
|
+
});
|
|
1361
|
+
expect(by['configured-integrations']).toMatchObject({
|
|
1362
|
+
status: 'info',
|
|
1363
|
+
message: 'No integration is named in astryx.config.',
|
|
1364
|
+
});
|
|
1365
|
+
expect(by['implicit-integrations'].status).toBe('info');
|
|
1366
|
+
expect(summary.fail).toBe(0);
|
|
1367
|
+
},
|
|
1368
|
+
SLOW,
|
|
1369
|
+
);
|
|
1370
|
+
});
|
|
1371
|
+
|
|
1126
1372
|
describe('no Astryx-owned environment variables (spec:AST-017 FR14)', () => {
|
|
1127
1373
|
it('no source file reads an ASTRYX_* env var', () => {
|
|
1128
1374
|
const cliDir = path.resolve(REPO, 'packages/cli');
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it} from 'vitest';
|
|
4
|
+
import transform from '../rename-empty-search-results-text.mjs';
|
|
5
|
+
import manifest from '../index.mjs';
|
|
6
|
+
|
|
7
|
+
async function applyTransform(source) {
|
|
8
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
9
|
+
const j = jscodeshift.withParser('tsx');
|
|
10
|
+
const api = {jscodeshift: j, stats: () => {}, report: () => {}};
|
|
11
|
+
return transform({source, path: 'test.tsx'}, api) ?? source;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe('rename-empty-search-results-text', () => {
|
|
15
|
+
it('is staged in the next-release manifest', () => {
|
|
16
|
+
expect(manifest.map(entry => entry.name)).toContain(
|
|
17
|
+
'rename-empty-search-results-text',
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('JSX props', () => {
|
|
22
|
+
it('renames the prop on Tokenizer, Typeahead, and BaseTypeahead', async () => {
|
|
23
|
+
const output =
|
|
24
|
+
await applyTransform(`import {BaseTypeahead, Tokenizer, Typeahead} from '@astryxdesign/core';
|
|
25
|
+
const a = <Tokenizer label="People" emptySearchResultsText="Nobody found" />;
|
|
26
|
+
const b = <Typeahead label="Fruit" emptySearchResultsText={copy.empty} />;
|
|
27
|
+
const c = <BaseTypeahead emptySearchResultsText={'None'} />;`);
|
|
28
|
+
|
|
29
|
+
expect(output).toContain(
|
|
30
|
+
'<Tokenizer label="People" emptySearchText="Nobody found" />',
|
|
31
|
+
);
|
|
32
|
+
expect(output).toContain(
|
|
33
|
+
'<Typeahead label="Fruit" emptySearchText={copy.empty} />',
|
|
34
|
+
);
|
|
35
|
+
expect(output).toContain("<BaseTypeahead emptySearchText={'None'} />");
|
|
36
|
+
expect(output).not.toContain('emptySearchResultsText');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('follows aliases, namespaces, and subpath default imports', async () => {
|
|
40
|
+
const output =
|
|
41
|
+
await applyTransform(`import {Tokenizer as People} from '@astryxdesign/core';
|
|
42
|
+
import * as Astryx from '@astryxdesign/core';
|
|
43
|
+
import Typeahead from '@astryxdesign/core/Typeahead';
|
|
44
|
+
const a = <People emptySearchResultsText="x" />;
|
|
45
|
+
const b = <Astryx.BaseTypeahead emptySearchResultsText="y" />;
|
|
46
|
+
const c = <Typeahead emptySearchResultsText="z" />;`);
|
|
47
|
+
|
|
48
|
+
expect(output).not.toContain('emptySearchResultsText');
|
|
49
|
+
expect(output.match(/emptySearchText=/g)).toHaveLength(3);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('renames the value as written, whatever shape it has', async () => {
|
|
53
|
+
const output =
|
|
54
|
+
await applyTransform(`import {Tokenizer} from '@astryxdesign/core';
|
|
55
|
+
const a = <Tokenizer emptySearchResultsText={compact ? 'None' : 'No matches'} />;
|
|
56
|
+
const b = <Tokenizer emptySearchResultsText={props.text ?? null} />;
|
|
57
|
+
const c = <Tokenizer {...props} emptySearchResultsText="After a spread" />;`);
|
|
58
|
+
|
|
59
|
+
expect(output).toContain(
|
|
60
|
+
"emptySearchText={compact ? 'None' : 'No matches'}",
|
|
61
|
+
);
|
|
62
|
+
expect(output).toContain('emptySearchText={props.text ?? null}');
|
|
63
|
+
// A spread may carry either name, so the element gets a TODO instead.
|
|
64
|
+
expect(output).toContain('{...props} /* TODO(astryx upgrade)');
|
|
65
|
+
expect(output).toContain('emptySearchResultsText="After a spread"');
|
|
66
|
+
expect(output).toContain('spreads props that may carry either name');
|
|
67
|
+
expect(output.match(/emptySearchResultsText/g)).toHaveLength(2);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('leaves a TODO instead of choosing when emptySearchText is already set', async () => {
|
|
71
|
+
const output =
|
|
72
|
+
await applyTransform(`import {Typeahead} from '@astryxdesign/core';
|
|
73
|
+
const a = <Typeahead emptySearchResultsText="Old copy" emptySearchText="New copy" />;`);
|
|
74
|
+
|
|
75
|
+
expect(output).toContain('TODO(astryx upgrade)');
|
|
76
|
+
expect(output).toContain('emptySearchResultsText="Old copy"');
|
|
77
|
+
expect(output).toContain('emptySearchText="New copy"');
|
|
78
|
+
expect(await applyTransform(output)).toBe(output);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('leaves other packages, other components, and shadowed names alone', async () => {
|
|
82
|
+
const source = `import {MobileTokenizer} from '@astryxdesign/lab';
|
|
83
|
+
import {Selector} from '@astryxdesign/core';
|
|
84
|
+
import {Tokenizer} from './my-tokenizer';
|
|
85
|
+
const a = <MobileTokenizer emptySearchResultsText="kept" />;
|
|
86
|
+
const b = <Selector emptySearchResultsText="kept" />;
|
|
87
|
+
const c = <Tokenizer emptySearchResultsText="kept" />;`;
|
|
88
|
+
expect(await applyTransform(source)).toBe(source);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('is idempotent', async () => {
|
|
92
|
+
const once =
|
|
93
|
+
await applyTransform(`import {Tokenizer} from '@astryxdesign/core';
|
|
94
|
+
const a = <Tokenizer emptySearchResultsText="Nobody found" />;`);
|
|
95
|
+
expect(await applyTransform(once)).toBe(once);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('ChatComposerInput trigger objects', () => {
|
|
100
|
+
it('renames the key on triggers written inline, in an array or alone', async () => {
|
|
101
|
+
const output =
|
|
102
|
+
await applyTransform(`import {ChatComposerInput} from '@astryxdesign/core';
|
|
103
|
+
const a = (
|
|
104
|
+
<ChatComposerInput
|
|
105
|
+
triggers={[
|
|
106
|
+
{char: '@', searchSource, onSelect, emptySearchResultsText: 'Nobody found'},
|
|
107
|
+
{char: '#', emptySearchResultsText: 'No tags'} as ChatComposerTrigger,
|
|
108
|
+
]}
|
|
109
|
+
/>
|
|
110
|
+
);
|
|
111
|
+
const b = <ChatComposerInput triggers={{char: '/', emptySearchResultsText: 'No commands'}} />;`);
|
|
112
|
+
|
|
113
|
+
expect(output).toContain("emptySearchText: 'Nobody found'");
|
|
114
|
+
expect(output).toContain("emptySearchText: 'No tags'");
|
|
115
|
+
expect(output).toContain("emptySearchText: 'No commands'");
|
|
116
|
+
expect(output).not.toContain('emptySearchResultsText');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('leaves a TODO on a trigger with a spread or computed key, or one that already sets the new name', async () => {
|
|
120
|
+
const output =
|
|
121
|
+
await applyTransform(`import {ChatComposerInput} from '@astryxdesign/core';
|
|
122
|
+
const a = (
|
|
123
|
+
<ChatComposerInput
|
|
124
|
+
triggers={[
|
|
125
|
+
{...base, emptySearchResultsText: 'Nobody'},
|
|
126
|
+
{[key]: 1, emptySearchResultsText: 'Nobody'},
|
|
127
|
+
{char: '@', emptySearchText: 'New', emptySearchResultsText: 'Old'},
|
|
128
|
+
]}
|
|
129
|
+
/>
|
|
130
|
+
);`);
|
|
131
|
+
|
|
132
|
+
expect(output.match(/TODO\(astryx upgrade\)/g)).toHaveLength(3);
|
|
133
|
+
expect(output.match(/emptySearchResultsText:/g)).toHaveLength(3);
|
|
134
|
+
expect(await applyTransform(output)).toBe(output);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('leaves a TODO on triggers it cannot read instead of following them', async () => {
|
|
138
|
+
const output =
|
|
139
|
+
await applyTransform(`import {ChatComposerInput} from '@astryxdesign/core';
|
|
140
|
+
import {mentionTrigger} from './triggers';
|
|
141
|
+
const local = {char: '@', emptySearchResultsText: 'Nobody'};
|
|
142
|
+
const a = <ChatComposerInput triggers={[local, mentionTrigger]} />;
|
|
143
|
+
const b = <ChatComposerInput triggers={buildTriggers()} />;
|
|
144
|
+
const c = <ChatComposerInput triggers={useMemo(() => [t], [t])} />;
|
|
145
|
+
const d = <ChatComposerInput {...props} triggers={[{char: '#', emptySearchResultsText: 'No tags'}]} />;`);
|
|
146
|
+
|
|
147
|
+
expect(output.match(/These triggers are built elsewhere/g)).toHaveLength(
|
|
148
|
+
4,
|
|
149
|
+
);
|
|
150
|
+
// The inline object beside a spread is still renamed; the spread is flagged.
|
|
151
|
+
expect(output).toContain("emptySearchText: 'No tags'");
|
|
152
|
+
expect(output).toContain("emptySearchResultsText: 'Nobody'");
|
|
153
|
+
expect(await applyTransform(output)).toBe(output);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('marks every spread onto these elements, even when the element writes neither name', async () => {
|
|
157
|
+
const output =
|
|
158
|
+
await applyTransform(`import {Tokenizer, Typeahead, ChatComposerInput} from '@astryxdesign/core';
|
|
159
|
+
import {Selector} from '@astryxdesign/core';
|
|
160
|
+
const people = {emptySearchResultsText: 'No people match'};
|
|
161
|
+
export function Wrappers(props) {
|
|
162
|
+
return (
|
|
163
|
+
<>
|
|
164
|
+
<Tokenizer {...people} />
|
|
165
|
+
<Typeahead {...{emptySearchResultsText: 'Inline'}} />
|
|
166
|
+
<Tokenizer {...props} label="x" />
|
|
167
|
+
<ChatComposerInput {...props} />
|
|
168
|
+
<Selector {...props} />
|
|
169
|
+
<Tokenizer {...props} emptySearchText="already new" />
|
|
170
|
+
</>
|
|
171
|
+
);
|
|
172
|
+
}`);
|
|
173
|
+
|
|
174
|
+
expect(
|
|
175
|
+
output.match(/spreads props that may carry either name/g),
|
|
176
|
+
).toHaveLength(4);
|
|
177
|
+
expect(output.match(/These triggers are built elsewhere/g)).toHaveLength(
|
|
178
|
+
1,
|
|
179
|
+
);
|
|
180
|
+
expect(output).toContain('<Selector {...props} />');
|
|
181
|
+
expect(await applyTransform(output)).toBe(output);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('marks an inline trigger object whose keys come only from a spread, once across runs', async () => {
|
|
185
|
+
const once =
|
|
186
|
+
await applyTransform(`import {ChatComposerInput} from '@astryxdesign/core';
|
|
187
|
+
const a = <ChatComposerInput triggers={[{...baseMention, onSelect}, {[key]: 1, onSelect}]} />;`);
|
|
188
|
+
|
|
189
|
+
expect(once.match(/has a spread or computed key/g)).toHaveLength(2);
|
|
190
|
+
const twice = await applyTransform(once);
|
|
191
|
+
expect(twice).toBe(once);
|
|
192
|
+
expect(twice.match(/TODO\(astryx upgrade\)/g)).toHaveLength(2);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('leaves a file with no runtime core import alone', async () => {
|
|
196
|
+
const source = `import {MobileTokenizer} from '@astryxdesign/lab';
|
|
197
|
+
const copy = {emptySearchResultsText: 'kept'};
|
|
198
|
+
const a = <MobileTokenizer {...copy} />;`;
|
|
199
|
+
expect(await applyTransform(source)).toBe(source);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
});
|
|
@@ -16,6 +16,9 @@ import migrateFieldInputStyling, {
|
|
|
16
16
|
import preserveBottomSheetContentPadding, {
|
|
17
17
|
meta as preserveBottomSheetContentPaddingMeta,
|
|
18
18
|
} from './preserve-bottom-sheet-content-padding.mjs';
|
|
19
|
+
import renameEmptySearchResultsText, {
|
|
20
|
+
meta as renameEmptySearchResultsTextMeta,
|
|
21
|
+
} from './rename-empty-search-results-text.mjs';
|
|
19
22
|
import validateDataTokenOwnership, {
|
|
20
23
|
meta as validateDataTokenOwnershipMeta,
|
|
21
24
|
} from './validate-data-token-ownership.mjs';
|
|
@@ -41,4 +44,9 @@ export default [
|
|
|
41
44
|
transform: preserveBottomSheetContentPadding,
|
|
42
45
|
meta: preserveBottomSheetContentPaddingMeta,
|
|
43
46
|
},
|
|
47
|
+
{
|
|
48
|
+
name: 'rename-empty-search-results-text',
|
|
49
|
+
transform: renameEmptySearchResultsText,
|
|
50
|
+
meta: renameEmptySearchResultsTextMeta,
|
|
51
|
+
},
|
|
44
52
|
];
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Codemod: rename emptySearchResultsText to emptySearchText
|
|
5
|
+
*
|
|
6
|
+
* `emptySearchResultsText` was renamed to `emptySearchText` (`spec:AST-056`
|
|
7
|
+
* FR1) and the old name is removed in a minor release. The new prop takes a
|
|
8
|
+
* `ReactNode`, so every old `string` value stays valid and the rename never
|
|
9
|
+
* changes a value.
|
|
10
|
+
*
|
|
11
|
+
* A straight rename at the JSX boundary, through the shared `transformProp`
|
|
12
|
+
* helper: the prop on an imported `Tokenizer`, `Typeahead`, or `BaseTypeahead`
|
|
13
|
+
* element, and the key on `ChatComposerInput` trigger objects written inline
|
|
14
|
+
* in its `triggers` prop. Like every transform built on the helper it does
|
|
15
|
+
* not follow variables, helpers, spreads, wrappers, or types. Where it cannot
|
|
16
|
+
* attribute the value it leaves a TODO instead of choosing a winner: the new
|
|
17
|
+
* name already set, any spread onto one of these elements (whether or not the
|
|
18
|
+
* element writes the old name itself — a spread may carry either name or the
|
|
19
|
+
* triggers), a `triggers` value that is not an inline object or array, or a
|
|
20
|
+
* trigger object with a spread or computed key. A value forwarded through a
|
|
21
|
+
* spread is the one case the type checker cannot report after the removal,
|
|
22
|
+
* which is why every spread gets the TODO.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import {transformProp} from '../../transform-prop.mjs';
|
|
26
|
+
|
|
27
|
+
export const meta = {
|
|
28
|
+
title: 'Rename emptySearchResultsText to emptySearchText',
|
|
29
|
+
description:
|
|
30
|
+
'Renames the removed `emptySearchResultsText` prop to `emptySearchText` ' +
|
|
31
|
+
'on imported Tokenizer, Typeahead, and BaseTypeahead elements, and the ' +
|
|
32
|
+
"same key on trigger objects written inline in ChatComposerInput's " +
|
|
33
|
+
'`triggers`. Leaves a TODO where the new name is already set, on every ' +
|
|
34
|
+
'spread onto these elements, where the triggers value is not written ' +
|
|
35
|
+
'inline, and on a trigger object with a spread or computed key.',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const OLD_NAME = 'emptySearchResultsText';
|
|
39
|
+
const NEW_NAME = 'emptySearchText';
|
|
40
|
+
const CORE_IMPORT_RE = /^@(astryxdesign|xds)\/core(?:\/|$)/;
|
|
41
|
+
|
|
42
|
+
const COMPONENTS = new Map([
|
|
43
|
+
['Tokenizer', new Set([OLD_NAME])],
|
|
44
|
+
['Typeahead', new Set([OLD_NAME])],
|
|
45
|
+
['BaseTypeahead', new Set([OLD_NAME])],
|
|
46
|
+
['ChatComposerInput', new Set(['triggers'])],
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
const BOTH_SET_COMMENT =
|
|
50
|
+
' TODO(astryx upgrade): emptySearchResultsText was removed and ' +
|
|
51
|
+
'emptySearchText is already set here; delete the old one if the new value ' +
|
|
52
|
+
'is what you want. ';
|
|
53
|
+
const UNREADABLE_OBJECT_COMMENT =
|
|
54
|
+
' TODO(astryx upgrade): emptySearchResultsText was removed. Rename it to ' +
|
|
55
|
+
'emptySearchText by hand; this object has a spread or computed key. ';
|
|
56
|
+
const SPREAD_COMMENT =
|
|
57
|
+
' TODO(astryx upgrade): emptySearchResultsText was removed. This element ' +
|
|
58
|
+
'spreads props that may carry either name; rename to emptySearchText ' +
|
|
59
|
+
'where the props are built and delete the old one. ';
|
|
60
|
+
const OPAQUE_TRIGGERS_COMMENT =
|
|
61
|
+
' TODO(astryx upgrade): emptySearchResultsText was removed. These triggers ' +
|
|
62
|
+
'are built elsewhere; rename the key to emptySearchText where they are ' +
|
|
63
|
+
'built. ';
|
|
64
|
+
|
|
65
|
+
const TYPE_WRAPPERS = new Set([
|
|
66
|
+
'TSAsExpression',
|
|
67
|
+
'TSSatisfiesExpression',
|
|
68
|
+
'TSTypeAssertion',
|
|
69
|
+
'TSNonNullExpression',
|
|
70
|
+
'TypeCastExpression',
|
|
71
|
+
'ParenthesizedExpression',
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
/** @param {any} node */
|
|
75
|
+
function unwrap(node) {
|
|
76
|
+
let current = node;
|
|
77
|
+
while (current && TYPE_WRAPPERS.has(current.type)) {
|
|
78
|
+
current = current.expression;
|
|
79
|
+
}
|
|
80
|
+
return current;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** @param {any} property */
|
|
84
|
+
function staticPropertyName(property) {
|
|
85
|
+
if (property.computed) return null;
|
|
86
|
+
const key = property.key;
|
|
87
|
+
if (key?.type === 'Identifier') return key.name;
|
|
88
|
+
if (key?.type === 'StringLiteral' || key?.type === 'Literal') {
|
|
89
|
+
return typeof key.value === 'string' ? key.value : null;
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Attach a comment to a node once (re-running the codemod adds nothing).
|
|
96
|
+
* @param {any} j @param {any} node @param {string} text
|
|
97
|
+
*/
|
|
98
|
+
function addComment(j, node, text) {
|
|
99
|
+
node.comments ??= [];
|
|
100
|
+
if (node.comments.some((/** @type {any} */ c) => c.value === text)) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
node.comments.push(j.commentBlock(text, true, false));
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Rename the key on one trigger object literal.
|
|
109
|
+
* @param {any} j @param {any} object @returns {boolean}
|
|
110
|
+
*/
|
|
111
|
+
function renameTriggerKey(j, object) {
|
|
112
|
+
const old = object.properties.find(
|
|
113
|
+
(/** @type {any} */ property) => staticPropertyName(property) === OLD_NAME,
|
|
114
|
+
);
|
|
115
|
+
const unreadable = object.properties.find(
|
|
116
|
+
(/** @type {any} */ property) =>
|
|
117
|
+
property.type === 'SpreadElement' ||
|
|
118
|
+
property.type === 'SpreadProperty' ||
|
|
119
|
+
property.computed,
|
|
120
|
+
);
|
|
121
|
+
// A spread or computed key may carry the removed key itself, so the
|
|
122
|
+
// object gets the TODO whether or not it writes the old name.
|
|
123
|
+
if (unreadable) {
|
|
124
|
+
return addComment(j, old ?? unreadable, UNREADABLE_OBJECT_COMMENT);
|
|
125
|
+
}
|
|
126
|
+
if (!old) return false;
|
|
127
|
+
const already = object.properties.some(
|
|
128
|
+
(/** @type {any} */ property) => staticPropertyName(property) === NEW_NAME,
|
|
129
|
+
);
|
|
130
|
+
if (already) return addComment(j, old, BOTH_SET_COMMENT);
|
|
131
|
+
old.key = j.identifier(NEW_NAME);
|
|
132
|
+
if (old.shorthand) old.shorthand = false;
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** @param {any} fileInfo @param {any} api */
|
|
137
|
+
export default function transform(fileInfo, api) {
|
|
138
|
+
const j = api.jscodeshift;
|
|
139
|
+
const root = j(fileInfo.source);
|
|
140
|
+
let changed = false;
|
|
141
|
+
|
|
142
|
+
transformProp(
|
|
143
|
+
root,
|
|
144
|
+
j,
|
|
145
|
+
{
|
|
146
|
+
matchesImport: source => CORE_IMPORT_RE.test(source),
|
|
147
|
+
components: COMPONENTS,
|
|
148
|
+
},
|
|
149
|
+
(propPath, {component}) => {
|
|
150
|
+
const prop = propPath.node;
|
|
151
|
+
const attributes = propPath.parent.node.attributes ?? [];
|
|
152
|
+
const hasSpread = attributes.some(
|
|
153
|
+
(/** @type {any} */ attribute) =>
|
|
154
|
+
attribute.type === 'JSXSpreadAttribute',
|
|
155
|
+
);
|
|
156
|
+
if (component === 'ChatComposerInput') {
|
|
157
|
+
// `triggers={[{...}, {...}]}` or `triggers={{...}}`: rename the key
|
|
158
|
+
// on each object written inline; a value built elsewhere, or an
|
|
159
|
+
// element whose spread may carry triggers, gets a TODO.
|
|
160
|
+
const value =
|
|
161
|
+
prop.value?.type === 'JSXExpressionContainer'
|
|
162
|
+
? unwrap(prop.value.expression)
|
|
163
|
+
: null;
|
|
164
|
+
const items =
|
|
165
|
+
value?.type === 'ArrayExpression'
|
|
166
|
+
? value.elements.map((/** @type {any} */ e) => unwrap(e))
|
|
167
|
+
: [value];
|
|
168
|
+
let opaque = hasSpread;
|
|
169
|
+
for (const item of items) {
|
|
170
|
+
if (item?.type === 'ObjectExpression') {
|
|
171
|
+
changed = renameTriggerKey(j, item) || changed;
|
|
172
|
+
} else {
|
|
173
|
+
opaque = true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (opaque) {
|
|
177
|
+
changed = addComment(j, prop, OPAQUE_TRIGGERS_COMMENT) || changed;
|
|
178
|
+
}
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (hasSpread) {
|
|
182
|
+
changed = addComment(j, prop, SPREAD_COMMENT) || changed;
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const already = attributes.some(
|
|
186
|
+
(/** @type {any} */ attribute) =>
|
|
187
|
+
attribute.type === 'JSXAttribute' &&
|
|
188
|
+
attribute.name?.name === NEW_NAME,
|
|
189
|
+
);
|
|
190
|
+
if (already) {
|
|
191
|
+
changed = addComment(j, prop, BOTH_SET_COMMENT) || changed;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
prop.name.name = NEW_NAME;
|
|
195
|
+
changed = true;
|
|
196
|
+
},
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
// Every spread onto one of these elements that the prop pass did not reach
|
|
200
|
+
// (the element writes neither the old name nor, for ChatComposerInput,
|
|
201
|
+
// `triggers`): the spread may carry the removed key, so it gets the TODO.
|
|
202
|
+
for (const [component, props] of COMPONENTS) {
|
|
203
|
+
const sentinel = `__astryx_spread_${component}`;
|
|
204
|
+
root
|
|
205
|
+
.find(j.JSXOpeningElement)
|
|
206
|
+
.filter((/** @type {any} */ path) =>
|
|
207
|
+
(path.node.attributes ?? []).some(
|
|
208
|
+
(/** @type {any} */ attribute) =>
|
|
209
|
+
attribute.type === 'JSXSpreadAttribute',
|
|
210
|
+
),
|
|
211
|
+
)
|
|
212
|
+
.forEach((/** @type {any} */ path) => {
|
|
213
|
+
const attributes = path.node.attributes ?? [];
|
|
214
|
+
const names = new Set(
|
|
215
|
+
attributes
|
|
216
|
+
.filter((/** @type {any} */ a) => a.type === 'JSXAttribute')
|
|
217
|
+
.map((/** @type {any} */ a) => a.name?.name),
|
|
218
|
+
);
|
|
219
|
+
if ([...props].some(name => names.has(name))) return;
|
|
220
|
+
// Let the shared helper decide whether this element is the imported
|
|
221
|
+
// component: give it a sentinel prop to find, then take it back.
|
|
222
|
+
const marker = j.jsxAttribute(j.jsxIdentifier(sentinel));
|
|
223
|
+
path.node.attributes = [...attributes, marker];
|
|
224
|
+
let matched = false;
|
|
225
|
+
transformProp(
|
|
226
|
+
root,
|
|
227
|
+
j,
|
|
228
|
+
{
|
|
229
|
+
matchesImport: source => CORE_IMPORT_RE.test(source),
|
|
230
|
+
components: new Map([[component, new Set([sentinel])]]),
|
|
231
|
+
},
|
|
232
|
+
propPath => {
|
|
233
|
+
if (propPath.node === marker) matched = true;
|
|
234
|
+
},
|
|
235
|
+
);
|
|
236
|
+
path.node.attributes = attributes;
|
|
237
|
+
if (!matched) return;
|
|
238
|
+
const spread = attributes.find(
|
|
239
|
+
(/** @type {any} */ attribute) =>
|
|
240
|
+
attribute.type === 'JSXSpreadAttribute',
|
|
241
|
+
);
|
|
242
|
+
changed =
|
|
243
|
+
addComment(
|
|
244
|
+
j,
|
|
245
|
+
spread,
|
|
246
|
+
component === 'ChatComposerInput'
|
|
247
|
+
? OPAQUE_TRIGGERS_COMMENT
|
|
248
|
+
: SPREAD_COMMENT,
|
|
249
|
+
) || changed;
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return changed ? root.toSource({quote: 'single'}) : null;
|
|
254
|
+
}
|
|
@@ -16,7 +16,7 @@ export const doc = {
|
|
|
16
16
|
summary: 'Diagnose Astryx projects and integration packages',
|
|
17
17
|
description:
|
|
18
18
|
'Runs read-only project health diagnostics by default: Node version, @astryxdesign/core ' +
|
|
19
|
-
'install and version alignment, theme packages, generated app themes when present, earlier copied-theme migration, config, integrations (linked without a config entry, ' +
|
|
19
|
+
'install and version alignment, theme packages, generated app themes when present, earlier copied-theme migration, config, integrations (every one astryx.config names must load, linked without a config entry, ' +
|
|
20
20
|
'provider identity, contribution issues), agent docs, core peer dependencies, package manager, ' +
|
|
21
21
|
"and the docs the CLI reads. It writes nothing, but loading astryx.config runs that file's code. " +
|
|
22
22
|
'The `integration` subcommands provide authoring checks for one integration package.',
|
|
@@ -403,3 +403,36 @@ describe('doctor — text output mirrors the JSON', () => {
|
|
|
403
403
|
}
|
|
404
404
|
}, 60_000);
|
|
405
405
|
});
|
|
406
|
+
|
|
407
|
+
describe('doctor — a configured integration that cannot load', () => {
|
|
408
|
+
it('sets exit code 1 and reports it in the JSON', async () => {
|
|
409
|
+
const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-exit-'));
|
|
410
|
+
const prevCwd = process.cwd();
|
|
411
|
+
const prevExit = process.exitCode;
|
|
412
|
+
process.exitCode = undefined;
|
|
413
|
+
try {
|
|
414
|
+
fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"app"}');
|
|
415
|
+
fs.writeFileSync(
|
|
416
|
+
path.join(dir, 'astryx.config.mjs'),
|
|
417
|
+
"export default { integrations: ['@acme/missing'] };\n",
|
|
418
|
+
);
|
|
419
|
+
const coreDir = path.join(dir, 'node_modules', '@astryxdesign', 'core');
|
|
420
|
+
fs.mkdirSync(coreDir, {recursive: true});
|
|
421
|
+
fs.writeFileSync(
|
|
422
|
+
path.join(coreDir, 'package.json'),
|
|
423
|
+
JSON.stringify({name: '@astryxdesign/core', version: '0.6.3'}),
|
|
424
|
+
);
|
|
425
|
+
process.chdir(dir);
|
|
426
|
+
await createProgram().parseAsync(['node', 'astryx', '--json', 'doctor']);
|
|
427
|
+
expect(process.exitCode).toBe(1);
|
|
428
|
+
const {data} = JSON.parse(logCalls.join('\n'));
|
|
429
|
+
expect(
|
|
430
|
+
data.checks.find(c => c.id === 'configured-integrations'),
|
|
431
|
+
).toMatchObject({status: 'fail'});
|
|
432
|
+
} finally {
|
|
433
|
+
process.chdir(prevCwd);
|
|
434
|
+
process.exitCode = prevExit;
|
|
435
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
436
|
+
}
|
|
437
|
+
}, 60_000);
|
|
438
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.0-canary.
|
|
3
|
+
"version": "0.7.0-canary.1bd7016",
|
|
4
4
|
"displayName": "CLI",
|
|
5
5
|
"description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
@@ -101,10 +101,10 @@
|
|
|
101
101
|
"zod": "^4.4.3"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
|
-
"@astryxdesign/charts": "0.7.0-canary.
|
|
105
|
-
"@astryxdesign/core": "0.7.0-canary.
|
|
106
|
-
"@astryxdesign/lab": "0.7.0-canary.
|
|
107
|
-
"@astryxdesign/theme-neutral": "0.7.0-canary.
|
|
104
|
+
"@astryxdesign/charts": "0.7.0-canary.1bd7016",
|
|
105
|
+
"@astryxdesign/core": "0.7.0-canary.1bd7016",
|
|
106
|
+
"@astryxdesign/lab": "0.7.0-canary.1bd7016",
|
|
107
|
+
"@astryxdesign/theme-neutral": "0.7.0-canary.1bd7016"
|
|
108
108
|
},
|
|
109
109
|
"peerDependenciesMeta": {
|
|
110
110
|
"@astryxdesign/charts": {
|
|
@@ -121,10 +121,10 @@
|
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
123
|
"devDependencies": {
|
|
124
|
-
"@astryxdesign/charts": "0.7.0-canary.
|
|
125
|
-
"@astryxdesign/core": "0.7.0-canary.
|
|
126
|
-
"@astryxdesign/lab": "0.7.0-canary.
|
|
127
|
-
"@astryxdesign/theme-neutral": "0.7.0-canary.
|
|
124
|
+
"@astryxdesign/charts": "0.7.0-canary.1bd7016",
|
|
125
|
+
"@astryxdesign/core": "0.7.0-canary.1bd7016",
|
|
126
|
+
"@astryxdesign/lab": "0.7.0-canary.1bd7016",
|
|
127
|
+
"@astryxdesign/theme-neutral": "0.7.0-canary.1bd7016",
|
|
128
128
|
"@heroicons/react": "^2.2.0",
|
|
129
129
|
"@stylexjs/stylex": "^0.19.0",
|
|
130
130
|
"@types/babel__core": "^7.20.5",
|