@astryxdesign/cli 0.7.1-canary.ff40b78 → 0.7.2-canary.01eab6a
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 +35 -0
- package/README.md +7 -7
- package/api/build/_adapter.d.mts +1 -0
- package/api/build/_adapter.mjs +7 -0
- package/api/build/build.mjs +4 -1
- package/api/component/_adapter.d.mts +41 -1
- package/api/component/_adapter.mjs +93 -7
- package/api/component/component.mjs +22 -5
- package/api/component/component.test.mjs +420 -167
- package/api/component/integration-export-name.test.mjs +644 -0
- package/api/component/list/list.mjs +42 -4
- package/api/gap-report/gap-report.mjs +67 -4
- package/api/integration/_adapter.d.mts +12 -0
- package/api/integration/_adapter.mjs +54 -0
- package/api/integration/add-contribution.component-names.test.mjs +66 -0
- package/api/integration/add-contribution.mjs +7 -3
- package/api/integration/authoring-checks.mjs +11 -2
- package/api/integration/authoring-checks.test.mjs +39 -0
- package/api/integration/authoring-checks.type.d.mts +9 -0
- package/api/integration/authoring-checks.type.mjs +14 -1
- package/api/integration/integrationComponentConflicts.doc.mjs +21 -5
- package/api/integration/pack-check.mjs +61 -107
- package/api/integration/pack-check.test.mjs +359 -0
- package/api/search/search.d.mts +9 -0
- package/api/search/search.mjs +120 -16
- package/api/search/search.test.mjs +36 -0
- package/api/swizzle/copy/copy.mjs +28 -14
- package/api/template/table-filter-view-tabs.test.mjs +45 -0
- package/api/template/template.test.mjs +120 -3
- package/api/theme/build/build.core-on-demand.test.mjs +113 -0
- package/api/theme/build/build.d.mts +13 -13
- package/api/theme/build/build.family.test.mjs +16 -0
- package/api/theme/build/build.mjs +149 -55
- package/api/theme/themeBuild.doc.mjs +3 -3
- package/assets/codemods/transforms/next/__tests__/migrate-list-edge-compensation-to-edge.test.mjs +120 -0
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-list-edge-compensation-to-edge.mjs +198 -0
- package/assets/docs/getting-started.doc.mjs +0 -10
- package/assets/docs/styling-overview.doc.mjs +54 -15
- package/assets/docs/tree/add-a-component.doc.mjs +10 -0
- package/assets/docs/tree/check-the-props.doc.mjs +145 -0
- package/assets/docs/tree/checks.doc.mjs +4 -4
- package/assets/docs/tree/component-family.doc.mjs +5 -1
- package/assets/docs/tree/component-imports.doc.mjs +8 -0
- package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
- package/assets/docs/tree/migration-setup.doc.mjs +31 -6
- package/assets/docs/tree/responsive.doc.mjs +37 -0
- package/assets/docs/tree/single-component.doc.mjs +3 -2
- package/assets/docs/tree/tailwind.doc.mjs +12 -0
- package/assets/docs/tree/tokens-and-setup.doc.mjs +3 -2
- package/assets/docs/tree/tokens-syntax.doc.mjs +20 -0
- package/assets/docs/tree/tokens.doc.mjs +1 -1
- package/assets/docs/tree/troubleshooting.doc.mjs +9 -1
- package/assets/docs/tree/versioning.doc.mjs +1 -0
- package/assets/docs/working-with-ai.doc.mjs +43 -4
- package/assets/templates/blocks/components/CommandPalette/CommandPaletteAsyncSearch.tsx +6 -1
- package/assets/templates/blocks/components/Drawer/DrawerForm.doc.mjs +24 -0
- package/assets/templates/blocks/components/Drawer/DrawerForm.tsx +62 -0
- package/assets/templates/blocks/components/Drawer/DrawerScrim.doc.mjs +22 -0
- package/assets/templates/blocks/components/Drawer/DrawerScrim.tsx +68 -0
- package/assets/templates/blocks/components/Drawer/DrawerShowcase.doc.mjs +22 -0
- package/assets/templates/blocks/components/Drawer/DrawerShowcase.tsx +41 -0
- package/assets/templates/blocks/components/Drawer/DrawerStart.doc.mjs +21 -0
- package/assets/templates/blocks/components/Drawer/DrawerStart.tsx +41 -0
- package/assets/templates/blocks/components/Drawer/DrawerWidths.doc.mjs +22 -0
- package/assets/templates/blocks/components/Drawer/DrawerWidths.tsx +54 -0
- package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderShowcase.doc.mjs +15 -0
- package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderShowcase.tsx +73 -0
- package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderSubtitleEndContent.doc.mjs +22 -0
- package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderSubtitleEndContent.tsx +49 -0
- package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderWithCloseButton.doc.mjs +21 -0
- package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderWithCloseButton.tsx +42 -0
- package/assets/templates/pages/detail-page/page.tsx +3 -3
- package/assets/templates/pages/table-filter/page.tsx +3 -2
- package/assets/templates/pages/table-inbox/page.tsx +10 -8
- package/assets/templates/themes/butter/butterTheme.ts +53 -11
- package/assets/templates/themes/chocolate/chocolateTheme.ts +29 -5
- package/assets/templates/themes/gothic/gothicTheme.ts +44 -9
- package/assets/templates/themes/stone/stoneTheme.ts +58 -11
- package/assets/templates/themes/y2k/y2kTheme.ts +60 -10
- package/authoring/doctypes/base/type.ts +6 -0
- package/authoring/doctypes/component/component.doc.mjs +4 -4
- package/authoring/doctypes/component/type.ts +6 -3
- package/clients/cli/commands/build-theme.mjs +32 -4
- package/clients/cli/commands/build-theme.path-safety.test.mjs +84 -0
- package/clients/cli/commands/build-theme.registry.test.mjs +5 -2
- package/clients/cli/commands/build-theme.watch.test.mjs +63 -2
- package/clients/cli/commands/doctor-integration-components.doc.mjs +9 -3
- package/clients/cli/commands/doctor-integration.test.mjs +327 -0
- package/clients/cli/commands/doctor.mjs +74 -0
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/lib/component-format.mjs +5 -1
- package/foundation/discovery/component-discovery.d.mts +190 -10
- package/foundation/discovery/component-discovery.export-names.test.mjs +760 -0
- package/foundation/discovery/component-discovery.mjs +889 -80
- package/foundation/discovery/component-discovery.test.mjs +96 -0
- package/foundation/discovery/component-replacement.mjs +18 -0
- package/foundation/discovery/component-replacement.test.mjs +40 -0
- package/foundation/discovery/hook-discovery.mjs +13 -12
- package/foundation/discovery/module-exports.d.mts +27 -0
- package/foundation/discovery/module-exports.mjs +356 -31
- package/foundation/discovery/module-exports.test.mjs +172 -0
- package/foundation/discovery/package-tsconfig.d.mts +14 -0
- package/foundation/discovery/package-tsconfig.mjs +228 -0
- package/foundation/discovery/package-tsconfig.test.mjs +210 -0
- package/foundation/discovery/project-typescript.d.mts +23 -0
- package/foundation/discovery/project-typescript.mjs +61 -0
- package/foundation/discovery/prop-drift.d.mts +220 -0
- package/foundation/discovery/prop-drift.mjs +1765 -0
- package/foundation/discovery/prop-drift.test.mjs +1197 -0
- package/foundation/discovery/template-adapter.mjs +74 -5
- package/foundation/discovery/unresolved-references.d.mts +62 -0
- package/foundation/discovery/unresolved-references.mjs +790 -0
- package/foundation/discovery/unresolved-references.test.mjs +567 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +9 -1
- package/foundation/doc-compiler/inputs.mjs +23 -0
- package/foundation/doc-compiler/inputs.test.mjs +0 -1
- package/foundation/fs/listing-cache.d.mts +36 -0
- package/foundation/fs/listing-cache.mjs +95 -0
- package/foundation/fs/listing-cache.test.mjs +88 -0
- package/foundation/fs/paths.mjs +3 -2
- package/foundation/integrations/contribution-inventory.mjs +6 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/foundation/xle/registry.mjs +4 -0
- package/foundation/xle/registry.test.mjs +28 -0
- package/package.json +10 -10
package/api/search/search.mjs
CHANGED
|
@@ -79,12 +79,22 @@
|
|
|
79
79
|
* queries they have nothing to do with.
|
|
80
80
|
*/
|
|
81
81
|
|
|
82
|
+
import {withListingCache} from '../../foundation/fs/listing-cache.mjs';
|
|
82
83
|
import {readDocView} from '../../foundation/doc-compiler/read.mjs';
|
|
83
|
-
import {
|
|
84
|
+
import {
|
|
85
|
+
discoverExternalPackages,
|
|
86
|
+
findCoreDir,
|
|
87
|
+
} from '../../foundation/fs/paths.mjs';
|
|
84
88
|
import {
|
|
85
89
|
discoverComponents,
|
|
86
90
|
discoverValidIntegrationComponents,
|
|
91
|
+
docStem,
|
|
92
|
+
familyMember,
|
|
87
93
|
findComponentReadme,
|
|
94
|
+
forEachIntegrationDoc,
|
|
95
|
+
integrationMemberEntry,
|
|
96
|
+
integrationRecordHold,
|
|
97
|
+
isIntegrationMember,
|
|
88
98
|
resolveImportPath,
|
|
89
99
|
resolveIntegrationImportPath,
|
|
90
100
|
CORE_PACKAGE,
|
|
@@ -96,6 +106,7 @@ import {
|
|
|
96
106
|
import {
|
|
97
107
|
loadComponentReplacements,
|
|
98
108
|
loadIntegrationsSafely,
|
|
109
|
+
resolveLegacyExternalDoc,
|
|
99
110
|
} from '../component/_adapter.mjs';
|
|
100
111
|
import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
|
|
101
112
|
import {discoverTemplates, extractComponents} from '../template/template.mjs';
|
|
@@ -148,6 +159,9 @@ import {setResultCoverage} from './coverage.mjs';
|
|
|
148
159
|
* @property {'page'|'block'} [_kind]
|
|
149
160
|
* @property {string} [_resultName]
|
|
150
161
|
* @property {string} [_commandName]
|
|
162
|
+
* @property {'file'|'doc'} [_hold] - How an integration component holds its
|
|
163
|
+
* name, for the owner rule.
|
|
164
|
+
* @property {string} [_docPath] - An integration component's doc.
|
|
151
165
|
*/
|
|
152
166
|
|
|
153
167
|
/**
|
|
@@ -1078,7 +1092,11 @@ async function gatherCoreComponents(coreDir) {
|
|
|
1078
1092
|
/** @type {string[]} */
|
|
1079
1093
|
let guidance = [];
|
|
1080
1094
|
if (readme && readme.endsWith('.doc.mjs')) {
|
|
1081
|
-
const
|
|
1095
|
+
const loaded = await loadModuleDoc(readme);
|
|
1096
|
+
// A member documented in its family's doc (VStack in Stack's doc) is
|
|
1097
|
+
// indexed from its own entry: the family's keywords and guidance
|
|
1098
|
+
// describe the family, not the member.
|
|
1099
|
+
const doc = familyMember(loaded, comp) ?? loaded;
|
|
1082
1100
|
if (doc) {
|
|
1083
1101
|
keywords = Array.isArray(doc.keywords) ? doc.keywords : [];
|
|
1084
1102
|
description = doc.usage?.description || doc.description || '';
|
|
@@ -1104,20 +1122,57 @@ async function gatherCoreComponents(coreDir) {
|
|
|
1104
1122
|
* usage/description from each component's .doc.mjs, same as core. Without
|
|
1105
1123
|
* this, an integration component is invisible to `search`/`build` even
|
|
1106
1124
|
* though `component --list`/`component <Name>` already resolve it — the two
|
|
1107
|
-
* discovery paths silently disagreed.
|
|
1125
|
+
* discovery paths silently disagreed. Also returns, per name, the docs that
|
|
1126
|
+
* hold it by their file name and the loadable docs that only record it.
|
|
1108
1127
|
* @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]} loadedIntegrations
|
|
1109
|
-
* @returns {Promise<Candidate[]>}
|
|
1128
|
+
* @returns {Promise<{candidates: Candidate[], fileNamed: Map<string, Set<string>>, documented: Map<string, Set<string>>}>}
|
|
1110
1129
|
*/
|
|
1111
1130
|
async function gatherIntegrationComponents(loadedIntegrations) {
|
|
1112
1131
|
/** @type {Candidate[]} */
|
|
1113
1132
|
const candidates = [];
|
|
1133
|
+
// What the owner rule reads: the docs that hold a name by their file name,
|
|
1134
|
+
// loadable or not and hidden ones too, and the loadable docs that only
|
|
1135
|
+
// record it.
|
|
1136
|
+
/** @type {Map<string, Set<string>>} */
|
|
1137
|
+
const fileNamed = new Map();
|
|
1138
|
+
/** @type {Map<string, Set<string>>} */
|
|
1139
|
+
const documented = new Map();
|
|
1140
|
+
/** @param {Map<string, Set<string>>} map @param {string} name @param {string} docPath */
|
|
1141
|
+
const hold = (map, name, docPath) =>
|
|
1142
|
+
map.set(name, (map.get(name) ?? new Set()).add(docPath));
|
|
1114
1143
|
for (const integration of loadedIntegrations) {
|
|
1115
|
-
const {components} =
|
|
1144
|
+
const {components, discovered} =
|
|
1145
|
+
await discoverValidIntegrationComponents(integration);
|
|
1146
|
+
const renamed = new Set(
|
|
1147
|
+
discovered
|
|
1148
|
+
.filter(rec => integrationRecordHold(rec) === 'doc')
|
|
1149
|
+
.filter(rec => !isIntegrationMember(rec))
|
|
1150
|
+
.map(rec => rec.docPath),
|
|
1151
|
+
);
|
|
1152
|
+
forEachIntegrationDoc(integration.components, (docPath, stem) => {
|
|
1153
|
+
if (!renamed.has(docPath)) hold(fileNamed, stem, docPath);
|
|
1154
|
+
});
|
|
1116
1155
|
for (const rec of components) {
|
|
1117
|
-
const
|
|
1156
|
+
const loaded = await loadModuleDoc(rec.docPath);
|
|
1157
|
+
// A family member is indexed from its own entry: the family's keywords
|
|
1158
|
+
// and guidance describe the family.
|
|
1159
|
+
const member = isIntegrationMember(rec);
|
|
1160
|
+
const doc = member ? integrationMemberEntry(loaded, rec) : loaded;
|
|
1161
|
+
// A doc that names another export of its file still answers to the
|
|
1162
|
+
// file's name, as `component <file name>` does.
|
|
1163
|
+
const fileName = docStem(rec.docPath);
|
|
1164
|
+
if (integrationRecordHold(rec) === 'doc') {
|
|
1165
|
+
hold(documented, rec.name, rec.docPath);
|
|
1166
|
+
}
|
|
1167
|
+
if (renamed.has(rec.docPath) && !member) {
|
|
1168
|
+
hold(documented, fileName, rec.docPath);
|
|
1169
|
+
}
|
|
1118
1170
|
candidates.push({
|
|
1119
1171
|
domain: 'component',
|
|
1120
1172
|
name: rec.name,
|
|
1173
|
+
aliases: !member && fileName !== rec.name ? [fileName] : [],
|
|
1174
|
+
_hold: integrationRecordHold(rec),
|
|
1175
|
+
_docPath: rec.docPath,
|
|
1121
1176
|
keywords: doc && Array.isArray(doc.keywords) ? doc.keywords : [],
|
|
1122
1177
|
description: doc ? doc.usage?.description || doc.description || '' : '',
|
|
1123
1178
|
guidance: guidanceFrom(doc),
|
|
@@ -1137,12 +1192,12 @@ async function gatherIntegrationComponents(loadedIntegrations) {
|
|
|
1137
1192
|
packageName: rec.package,
|
|
1138
1193
|
},
|
|
1139
1194
|
rec.name,
|
|
1140
|
-
|
|
1195
|
+
loaded?.import,
|
|
1141
1196
|
),
|
|
1142
1197
|
});
|
|
1143
1198
|
}
|
|
1144
1199
|
}
|
|
1145
|
-
return candidates;
|
|
1200
|
+
return {candidates, fileNamed, documented};
|
|
1146
1201
|
}
|
|
1147
1202
|
|
|
1148
1203
|
/**
|
|
@@ -1154,11 +1209,12 @@ async function gatherIntegrationComponents(loadedIntegrations) {
|
|
|
1154
1209
|
*/
|
|
1155
1210
|
async function gatherComponents(coreDir, cwd) {
|
|
1156
1211
|
const loadedIntegrations = await loadIntegrationsSafely(cwd);
|
|
1157
|
-
const [core,
|
|
1212
|
+
const [core, gathered, replacements] = await Promise.all([
|
|
1158
1213
|
gatherCoreComponents(coreDir),
|
|
1159
1214
|
gatherIntegrationComponents(loadedIntegrations),
|
|
1160
1215
|
loadComponentReplacements(coreDir, loadedIntegrations),
|
|
1161
1216
|
]);
|
|
1217
|
+
const {candidates: integrations, fileNamed, documented} = gathered;
|
|
1162
1218
|
// An active replacement answers to the Core name it replaces, so a search
|
|
1163
1219
|
// for that name finds the replacement and not the Core original
|
|
1164
1220
|
// (spec:AST-035 FR11).
|
|
@@ -1169,9 +1225,43 @@ async function gatherComponents(coreDir, cwd) {
|
|
|
1169
1225
|
active.target,
|
|
1170
1226
|
]),
|
|
1171
1227
|
);
|
|
1228
|
+
// The owner rule, as component detail applies it: a candidate `component
|
|
1229
|
+
// <name>` does not open names its package and follows the owner, and a
|
|
1230
|
+
// file-name alias that opens another owner is dropped.
|
|
1231
|
+
const coreNames = new Set(core.map(candidate => candidate.name));
|
|
1232
|
+
/** @param {string} name @param {Candidate} candidate */
|
|
1233
|
+
const opens = (name, candidate) =>
|
|
1234
|
+
!coreNames.has(name) &&
|
|
1235
|
+
findComponentReadme(coreDir, name) == null &&
|
|
1236
|
+
[...(fileNamed.get(name) ?? [])].every(doc => doc === candidate._docPath) &&
|
|
1237
|
+
[...(documented.get(name) ?? [])].every(doc => doc === candidate._docPath);
|
|
1238
|
+
// A legacy docs package keeps an exact name over an export name a doc records.
|
|
1239
|
+
/** @type {ReturnType<typeof discoverExternalPackages> | undefined} */
|
|
1240
|
+
let externals;
|
|
1241
|
+
/** @param {string} name */
|
|
1242
|
+
const legacyDocuments = name =>
|
|
1243
|
+
(externals ??= discoverExternalPackages(cwd)).some(
|
|
1244
|
+
ext => resolveLegacyExternalDoc(ext, name) != null,
|
|
1245
|
+
);
|
|
1246
|
+
const ruled = integrations.map(candidate => {
|
|
1247
|
+
const aliases = (candidate.aliases ?? []).filter(alias =>
|
|
1248
|
+
opens(alias, candidate),
|
|
1249
|
+
);
|
|
1250
|
+
return candidate._hold === 'doc' &&
|
|
1251
|
+
(!opens(candidate.name, candidate) || legacyDocuments(candidate.name))
|
|
1252
|
+
? {
|
|
1253
|
+
...candidate,
|
|
1254
|
+
aliases,
|
|
1255
|
+
_command: `astryx component ${candidate.name} --package ${candidate._package}`,
|
|
1256
|
+
}
|
|
1257
|
+
: {...candidate, aliases};
|
|
1258
|
+
});
|
|
1172
1259
|
return [
|
|
1173
1260
|
...core.filter(candidate => !replacements.forTarget(candidate.name)),
|
|
1174
|
-
...
|
|
1261
|
+
...[
|
|
1262
|
+
...ruled.filter(candidate => !candidate._command),
|
|
1263
|
+
...ruled.filter(candidate => candidate._command),
|
|
1264
|
+
].map(candidate => {
|
|
1175
1265
|
const target = targetOf.get(`${candidate._package}\0${candidate.name}`);
|
|
1176
1266
|
if (target != null) {
|
|
1177
1267
|
return {...candidate, aliases: [...(candidate.aliases ?? []), target]};
|
|
@@ -1224,11 +1314,11 @@ export async function componentKeywords(coreDir, cwd) {
|
|
|
1224
1314
|
.flat()
|
|
1225
1315
|
.map(async name => {
|
|
1226
1316
|
const readme = findComponentReadme(coreDir, name);
|
|
1227
|
-
const
|
|
1317
|
+
const loaded =
|
|
1228
1318
|
readme && readme.endsWith('.doc.mjs')
|
|
1229
1319
|
? await loadModuleDoc(readme)
|
|
1230
1320
|
: null;
|
|
1231
|
-
return {name, keywords: keywordsOf(
|
|
1321
|
+
return {name, keywords: keywordsOf(familyMember(loaded, name) ?? loaded)};
|
|
1232
1322
|
});
|
|
1233
1323
|
const loadedIntegrations = await loadIntegrationsSafely(cwd);
|
|
1234
1324
|
const replacements = await loadComponentReplacements(
|
|
@@ -1238,10 +1328,13 @@ export async function componentKeywords(coreDir, cwd) {
|
|
|
1238
1328
|
const integrations = loadedIntegrations.map(async integration => {
|
|
1239
1329
|
const {components} = await discoverValidIntegrationComponents(integration);
|
|
1240
1330
|
return Promise.all(
|
|
1241
|
-
components.map(async rec =>
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1331
|
+
components.map(async rec => {
|
|
1332
|
+
const loaded = await loadModuleDoc(rec.docPath);
|
|
1333
|
+
return {
|
|
1334
|
+
name: rec.name,
|
|
1335
|
+
keywords: keywordsOf(integrationMemberEntry(loaded, rec) ?? loaded),
|
|
1336
|
+
};
|
|
1337
|
+
}),
|
|
1245
1338
|
);
|
|
1246
1339
|
});
|
|
1247
1340
|
return [
|
|
@@ -1769,6 +1862,17 @@ function toResult(c, score, reason, matchedTerms, queryTerms) {
|
|
|
1769
1862
|
* @returns {Promise<import('./search.type.mjs').SearchResponse>}
|
|
1770
1863
|
*/
|
|
1771
1864
|
export async function search(query, options = {}) {
|
|
1865
|
+
// Every candidate resolves its source and docs by walking the same tree;
|
|
1866
|
+
// read each directory once for this call.
|
|
1867
|
+
return withListingCache(() => searchOnce(query, options));
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
/**
|
|
1871
|
+
* @param {string} query
|
|
1872
|
+
* @param {NonNullable<Parameters<typeof search>[1]>} options
|
|
1873
|
+
* @returns {ReturnType<typeof search>}
|
|
1874
|
+
*/
|
|
1875
|
+
async function searchOnce(query, options) {
|
|
1772
1876
|
const {cwd = process.cwd(), type, limit = 20} = options;
|
|
1773
1877
|
|
|
1774
1878
|
if (!query || !String(query).trim()) {
|
|
@@ -616,6 +616,42 @@ describe('search leaf — a theme is found by its names; its description is pros
|
|
|
616
616
|
);
|
|
617
617
|
});
|
|
618
618
|
|
|
619
|
+
describe('search leaf — components whose docs live in a family folder', () => {
|
|
620
|
+
it("indexes a family member from its own entry, not the family's keywords", async () => {
|
|
621
|
+
// HStack and VStack are documented in Stack's doc, whose keywords
|
|
622
|
+
// (horizontal, vertical, row, column, ...) describe Stack.
|
|
623
|
+
const reasons = async (/** @type {string} */ query) =>
|
|
624
|
+
Object.fromEntries(
|
|
625
|
+
(await search(query, {cwd, type: 'component'})).data.results.map(r => [
|
|
626
|
+
r.name,
|
|
627
|
+
r.reason,
|
|
628
|
+
]),
|
|
629
|
+
);
|
|
630
|
+
const column = await reasons('column');
|
|
631
|
+
expect(column.HStack ?? '').not.toMatch(/keyword/);
|
|
632
|
+
expect(column.VStack ?? '').not.toMatch(/keyword/);
|
|
633
|
+
expect(column.Stack).toMatch(/keyword/);
|
|
634
|
+
const vertical = (await search('vertical', {cwd, type: 'component'})).data.results.map(
|
|
635
|
+
r => r.name,
|
|
636
|
+
);
|
|
637
|
+
expect(vertical.indexOf('VStack')).toBeGreaterThanOrEqual(0);
|
|
638
|
+
if (vertical.includes('HStack')) {
|
|
639
|
+
expect(vertical.indexOf('VStack')).toBeLessThan(vertical.indexOf('HStack'));
|
|
640
|
+
}
|
|
641
|
+
}, SLOW);
|
|
642
|
+
|
|
643
|
+
it('ranks VStack, HStack and Heading first for their own names, with their own import', async () => {
|
|
644
|
+
for (const name of ['VStack', 'HStack', 'Heading']) {
|
|
645
|
+
const r = await search(name.toLowerCase(), {cwd, type: 'component'});
|
|
646
|
+
expect(r.data.results[0]).toMatchObject({
|
|
647
|
+
domain: 'component',
|
|
648
|
+
name,
|
|
649
|
+
import: `@astryxdesign/core/${name}`,
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
}, SLOW);
|
|
653
|
+
});
|
|
654
|
+
|
|
619
655
|
describe('search leaf — integration components', () => {
|
|
620
656
|
/**
|
|
621
657
|
* A minimal consumer project: a stub `@astryxdesign/core` (so `findCoreDir`
|
|
@@ -21,8 +21,10 @@ import {checkGhCli} from '../_github.mjs';
|
|
|
21
21
|
import {Project} from '../../../foundation/config/project.mjs';
|
|
22
22
|
import {
|
|
23
23
|
CORE_PACKAGE,
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
docStem,
|
|
25
|
+
findComponentReadme,
|
|
26
|
+
findIntegrationComponent,
|
|
27
|
+
unscopedComponentOwners,
|
|
26
28
|
} from '../../../foundation/discovery/component-discovery.mjs';
|
|
27
29
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
28
30
|
import {AstryxError, writeFailed} from '../../error.mjs';
|
|
@@ -126,33 +128,38 @@ async function loadConfigSafely(cwd) {
|
|
|
126
128
|
|
|
127
129
|
/**
|
|
128
130
|
* Build the set of OWNER packages that provide a component named `name` across
|
|
129
|
-
* core + every loaded integration.
|
|
131
|
+
* core + every loaded integration. Core holds every name it documents, but has
|
|
132
|
+
* source to copy (`sourceDir`) only for a name with its own folder.
|
|
130
133
|
* @param {string} coreDir
|
|
131
134
|
* @param {Array<{name: string, components?: string, issuesUrl?: string}>} loadedIntegrations
|
|
132
135
|
* @param {string} name
|
|
133
136
|
* @param {string|undefined} coreIssuesUrl
|
|
134
|
-
* @returns {Array<{package: string, sourceDir: string|null, ownerPackage: string, issuesUrl: string|undefined}>}
|
|
137
|
+
* @returns {Array<{package: string, sourceDir: string|null, docPath: string|null, ownerPackage: string, issuesUrl: string|undefined, hold: string}>}
|
|
135
138
|
*/
|
|
136
139
|
function resolveOwners(coreDir, loadedIntegrations, name, coreIssuesUrl) {
|
|
137
140
|
const owners = [];
|
|
138
141
|
const coreComponentDir = path.join(coreDir, 'src', name);
|
|
139
|
-
|
|
142
|
+
const coreFolder = fs.existsSync(coreComponentDir);
|
|
143
|
+
if (coreFolder || findComponentReadme(coreDir, name)) {
|
|
140
144
|
owners.push({
|
|
141
145
|
package: CORE_PACKAGE,
|
|
142
|
-
sourceDir: coreComponentDir,
|
|
146
|
+
sourceDir: coreFolder ? coreComponentDir : null,
|
|
147
|
+
docPath: null,
|
|
143
148
|
ownerPackage: CORE_PACKAGE,
|
|
144
149
|
issuesUrl: coreIssuesUrl || DEFAULT_ISSUES_URL,
|
|
150
|
+
hold: 'core',
|
|
145
151
|
});
|
|
146
152
|
}
|
|
147
153
|
for (const integration of loadedIntegrations) {
|
|
148
|
-
const
|
|
149
|
-
if (!
|
|
150
|
-
const sourcePath = findIntegrationComponentSource(integration, name);
|
|
154
|
+
const found = findIntegrationComponent(integration, name);
|
|
155
|
+
if (!found) continue;
|
|
151
156
|
owners.push({
|
|
152
157
|
package: integration.name,
|
|
153
|
-
sourceDir: sourcePath ? path.dirname(sourcePath) : null,
|
|
158
|
+
sourceDir: found.sourcePath ? path.dirname(found.sourcePath) : null,
|
|
159
|
+
docPath: found.docPath,
|
|
154
160
|
ownerPackage: integration.name,
|
|
155
161
|
issuesUrl: integration.issuesUrl,
|
|
162
|
+
hold: found.hold,
|
|
156
163
|
});
|
|
157
164
|
}
|
|
158
165
|
return owners;
|
|
@@ -222,25 +229,32 @@ export async function swizzleCopy(component, options = {}) {
|
|
|
222
229
|
: undefined;
|
|
223
230
|
// An active integration replacement answers to the Core name it replaces,
|
|
224
231
|
// bare or qualified by its own package (spec:AST-035 FR11): copy it under its
|
|
225
|
-
//
|
|
232
|
+
// doc's file name, the folder it has always gone to. `--package
|
|
233
|
+
// @astryxdesign/core` still copies the Core original.
|
|
226
234
|
if (pkg !== CORE_PACKAGE) {
|
|
227
235
|
const replacement = await resolveComponentReplacement(
|
|
228
236
|
coreDir,
|
|
229
237
|
loadedIntegrations,
|
|
230
238
|
dirName,
|
|
231
239
|
);
|
|
240
|
+
const copyName = replacement ? docStem(replacement.docPath) : null;
|
|
232
241
|
if (
|
|
233
242
|
replacement &&
|
|
234
|
-
|
|
243
|
+
copyName &&
|
|
244
|
+
(!pkg || (pkg === replacement.package && copyName !== dirName))
|
|
235
245
|
) {
|
|
236
|
-
return swizzleCopy(
|
|
246
|
+
return swizzleCopy(copyName, {
|
|
237
247
|
...options,
|
|
238
248
|
package: replacement.package,
|
|
239
249
|
});
|
|
240
250
|
}
|
|
241
251
|
}
|
|
242
252
|
|
|
243
|
-
const
|
|
253
|
+
const found = resolveOwners(coreDir, loadedIntegrations, dirName, coreIssuesUrl);
|
|
254
|
+
// The owner rule, then a Core name without its own folder drops out.
|
|
255
|
+
const allOwners = (pkg ? found : unscopedComponentOwners(found)).filter(
|
|
256
|
+
owner => owner.package !== CORE_PACKAGE || owner.sourceDir != null,
|
|
257
|
+
);
|
|
244
258
|
|
|
245
259
|
if (allOwners.length === 0) {
|
|
246
260
|
throw new AstryxError(
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Regression coverage for the table-filter page's compact view-options tabs.
|
|
5
|
+
* @input The shipped table-filter page template source.
|
|
6
|
+
* @output Assertions that the shared tabpanel is labelled by its selected tab.
|
|
7
|
+
* @position Template contract test for the tabs relationship in the narrow-view sheet.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import {fileURLToPath} from 'node:url';
|
|
13
|
+
import {describe, expect, it} from 'vitest';
|
|
14
|
+
|
|
15
|
+
const sourcePath = path.resolve(
|
|
16
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
17
|
+
'../../assets/templates/pages/table-filter/page.tsx',
|
|
18
|
+
);
|
|
19
|
+
const source = fs.readFileSync(sourcePath, 'utf8');
|
|
20
|
+
const sheet = source.match(
|
|
21
|
+
/const viewOptionsSheet = \(([\s\S]*?)\n {2}\);/,
|
|
22
|
+
)?.[1];
|
|
23
|
+
const tab = sheet?.match(/<Tab\b([\s\S]*?)\/>/)?.[1];
|
|
24
|
+
const panel = sheet?.match(/<VStack\b([^>]*?role="tabpanel"[^>]*?)>/)?.[1];
|
|
25
|
+
|
|
26
|
+
describe('table-filter view-options tabs', () => {
|
|
27
|
+
it('finds the compact sheet, its tab and its panel', () => {
|
|
28
|
+
expect(sheet).toBeDefined();
|
|
29
|
+
expect(tab).toBeDefined();
|
|
30
|
+
expect(panel).toBeDefined();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('gives every tab an id derived from the panel id and its section', () => {
|
|
34
|
+
expect(tab).toContain('id={`${viewPanelId}-tab-${section.key}`}');
|
|
35
|
+
expect(tab).toContain('panelId={viewPanelId}');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('labels the shared panel by the selected tab, not a fixed string', () => {
|
|
39
|
+
expect(panel).toContain('id={viewPanelId}');
|
|
40
|
+
expect(panel).toContain(
|
|
41
|
+
'aria-labelledby={`${viewPanelId}-tab-${viewSection}`}',
|
|
42
|
+
);
|
|
43
|
+
expect(panel).not.toContain('aria-label=');
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
|
+
import * as fs from 'node:fs';
|
|
4
|
+
import * as os from 'node:os';
|
|
5
|
+
import * as path from 'node:path';
|
|
3
6
|
import {describe, it, expect} from 'vitest';
|
|
4
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
stripTemplateAssetRefs,
|
|
9
|
+
template,
|
|
10
|
+
extractComponents,
|
|
11
|
+
} from './template.mjs';
|
|
5
12
|
|
|
6
13
|
describe('stripTemplateAssetRefs', () => {
|
|
7
14
|
it('replaces a /template-assets image path with an inline data URI', () => {
|
|
@@ -31,8 +38,7 @@ describe('stripTemplateAssetRefs', () => {
|
|
|
31
38
|
});
|
|
32
39
|
|
|
33
40
|
it('preserves surrounding source structure', () => {
|
|
34
|
-
const src =
|
|
35
|
-
"const data = [{src: '/template-assets/x.png', alt: 'X'}];";
|
|
41
|
+
const src = "const data = [{src: '/template-assets/x.png', alt: 'X'}];";
|
|
36
42
|
const out = stripTemplateAssetRefs(src);
|
|
37
43
|
expect(out).toContain("alt: 'X'");
|
|
38
44
|
expect(out).toContain('const data = [{src:');
|
|
@@ -102,4 +108,115 @@ describe('template --skeleton component extraction (prefix-agnostic)', () => {
|
|
|
102
108
|
|
|
103
109
|
expect(result.data.skeleton).toContain('columns={{minWidth: 200}}');
|
|
104
110
|
});
|
|
111
|
+
|
|
112
|
+
it('filters out local helper components declared in the same file', () => {
|
|
113
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-test-'));
|
|
114
|
+
const pagePath = path.join(tmpDir, 'page.tsx');
|
|
115
|
+
fs.writeFileSync(
|
|
116
|
+
pagePath,
|
|
117
|
+
`
|
|
118
|
+
import {Card} from '@astryxdesign/core/Layout';
|
|
119
|
+
|
|
120
|
+
function TimelineSection() {
|
|
121
|
+
return <div />;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export default function Page() {
|
|
125
|
+
return (
|
|
126
|
+
<Card>
|
|
127
|
+
<TimelineSection />
|
|
128
|
+
</Card>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
`,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
const components = extractComponents(pagePath);
|
|
136
|
+
expect(components).toContain('Card');
|
|
137
|
+
expect(components).not.toContain('Timeline');
|
|
138
|
+
} finally {
|
|
139
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('filters out a type-annotated local helper', () => {
|
|
144
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-test-'));
|
|
145
|
+
const pagePath = path.join(tmpDir, 'page.tsx');
|
|
146
|
+
fs.writeFileSync(
|
|
147
|
+
pagePath,
|
|
148
|
+
`
|
|
149
|
+
import type {FC} from 'react';
|
|
150
|
+
import {Card} from '@astryxdesign/core/Layout';
|
|
151
|
+
|
|
152
|
+
const TimelineSection: FC = () => <div />;
|
|
153
|
+
|
|
154
|
+
export default function Page() {
|
|
155
|
+
return (
|
|
156
|
+
<Card>
|
|
157
|
+
<TimelineSection />
|
|
158
|
+
</Card>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
`,
|
|
162
|
+
);
|
|
163
|
+
try {
|
|
164
|
+
const components = extractComponents(pagePath);
|
|
165
|
+
expect(components).toContain('Card');
|
|
166
|
+
expect(components).not.toContain('Timeline');
|
|
167
|
+
} finally {
|
|
168
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('keeps an imported component when declaration-like text appears in a comment or string', () => {
|
|
173
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-test-'));
|
|
174
|
+
const pagePath = path.join(tmpDir, 'page.tsx');
|
|
175
|
+
fs.writeFileSync(
|
|
176
|
+
pagePath,
|
|
177
|
+
`
|
|
178
|
+
import {Card} from '@astryxdesign/core/Layout';
|
|
179
|
+
|
|
180
|
+
// const Card = () => null;
|
|
181
|
+
const note = 'function Card() {}';
|
|
182
|
+
|
|
183
|
+
export default function Page() {
|
|
184
|
+
return <Card>{note}</Card>;
|
|
185
|
+
}
|
|
186
|
+
`,
|
|
187
|
+
);
|
|
188
|
+
try {
|
|
189
|
+
expect(extractComponents(pagePath)).toContain('Card');
|
|
190
|
+
} finally {
|
|
191
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('keeps a bare imported component whose name is itself a stripped suffix', () => {
|
|
196
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-test-'));
|
|
197
|
+
const pagePath = path.join(tmpDir, 'page.tsx');
|
|
198
|
+
fs.writeFileSync(
|
|
199
|
+
pagePath,
|
|
200
|
+
`
|
|
201
|
+
import {Section} from '@astryxdesign/core/Section';
|
|
202
|
+
|
|
203
|
+
function SectionHeading() {
|
|
204
|
+
return <div />;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export default function Page() {
|
|
208
|
+
return (
|
|
209
|
+
<Section>
|
|
210
|
+
<SectionHeading />
|
|
211
|
+
</Section>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
`,
|
|
215
|
+
);
|
|
216
|
+
try {
|
|
217
|
+
expect(extractComponents(pagePath)).toContain('Section');
|
|
218
|
+
} finally {
|
|
219
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
220
|
+
}
|
|
221
|
+
});
|
|
105
222
|
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The theme build imports Core when a build runs, not when the CLI starts.
|
|
5
|
+
*
|
|
6
|
+
* The CLI loads the theme build module for every command, and Core's root
|
|
7
|
+
* entry pulls in all of Core and React. So a command that builds no theme must
|
|
8
|
+
* not ask for either, or `astryx --version` pays for them whenever a Core is
|
|
9
|
+
* installed. A resolve hook in a real subprocess records every request for
|
|
10
|
+
* Core or React and the module that made it, whether or not the request
|
|
11
|
+
* resolves.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {afterAll, beforeAll, describe, expect, it} from 'vitest';
|
|
15
|
+
import {spawnSync} from 'node:child_process';
|
|
16
|
+
import * as fs from 'node:fs';
|
|
17
|
+
import * as os from 'node:os';
|
|
18
|
+
import * as path from 'node:path';
|
|
19
|
+
import {fileURLToPath, pathToFileURL} from 'node:url';
|
|
20
|
+
|
|
21
|
+
const BIN = fileURLToPath(
|
|
22
|
+
new URL('../../../clients/cli/bin/astryx.mjs', import.meta.url),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
/** @type {string} */
|
|
26
|
+
let dir;
|
|
27
|
+
/** @type {string} */
|
|
28
|
+
let register;
|
|
29
|
+
/** @type {string} */
|
|
30
|
+
let log;
|
|
31
|
+
|
|
32
|
+
beforeAll(() => {
|
|
33
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-core-on-demand-'));
|
|
34
|
+
log = path.join(dir, 'requests.jsonl');
|
|
35
|
+
const hooks = path.join(dir, 'hooks.mjs');
|
|
36
|
+
fs.writeFileSync(
|
|
37
|
+
hooks,
|
|
38
|
+
[
|
|
39
|
+
"import {appendFileSync} from 'node:fs';",
|
|
40
|
+
`const LOG = ${JSON.stringify(log)};`,
|
|
41
|
+
'const WATCHED = /^(?:@astryxdesign\\/core|react|react-dom)(?:\\/|$)/;',
|
|
42
|
+
'export async function resolve(specifier, context, nextResolve) {',
|
|
43
|
+
' if (WATCHED.test(specifier)) {',
|
|
44
|
+
' const parent = context.parentURL ?? null;',
|
|
45
|
+
" appendFileSync(LOG, JSON.stringify({specifier, parent}) + '\\n');",
|
|
46
|
+
' }',
|
|
47
|
+
' return nextResolve(specifier, context);',
|
|
48
|
+
'}',
|
|
49
|
+
'',
|
|
50
|
+
].join('\n'),
|
|
51
|
+
);
|
|
52
|
+
register = path.join(dir, 'register.mjs');
|
|
53
|
+
fs.writeFileSync(
|
|
54
|
+
register,
|
|
55
|
+
`import {register} from 'node:module';\nregister(${JSON.stringify(pathToFileURL(hooks).href)});\n`,
|
|
56
|
+
);
|
|
57
|
+
// A plain theme object: the file itself never imports Core, so a request for
|
|
58
|
+
// Core can only come from the build.
|
|
59
|
+
fs.writeFileSync(
|
|
60
|
+
path.join(dir, 'ocean.mjs'),
|
|
61
|
+
"export default {name: 'ocean', tokens: {'--color-bg': '#0a0a0a'}};\n",
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
afterAll(() => {
|
|
66
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Run the CLI and return each Core or React specifier it asked for, mapped to
|
|
71
|
+
* the first module that asked.
|
|
72
|
+
* @param {string[]} args
|
|
73
|
+
* @returns {{status: number | null, requested: Record<string, string | null>}}
|
|
74
|
+
*/
|
|
75
|
+
function run(args) {
|
|
76
|
+
fs.rmSync(log, {force: true});
|
|
77
|
+
const res = spawnSync(
|
|
78
|
+
process.execPath,
|
|
79
|
+
['--import', pathToFileURL(register).href, BIN, ...args],
|
|
80
|
+
{cwd: dir, encoding: 'utf-8', timeout: 20_000},
|
|
81
|
+
);
|
|
82
|
+
/** @type {Record<string, string | null>} */
|
|
83
|
+
const requested = {};
|
|
84
|
+
const lines = fs.existsSync(log)
|
|
85
|
+
? fs.readFileSync(log, 'utf-8').split('\n').filter(Boolean)
|
|
86
|
+
: [];
|
|
87
|
+
for (const line of lines) {
|
|
88
|
+
const {specifier, parent} = JSON.parse(line);
|
|
89
|
+
if (!(specifier in requested)) requested[specifier] = parent;
|
|
90
|
+
}
|
|
91
|
+
return {status: res.status, requested};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
describe('theme build imports Core on demand', () => {
|
|
95
|
+
it('astryx --version asks for neither Core nor React', () => {
|
|
96
|
+
const {status, requested} = run(['--version']);
|
|
97
|
+
expect(status).toBe(0);
|
|
98
|
+
expect(requested).toEqual({});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('theme build imports Core from the theme build module', () => {
|
|
102
|
+
const {requested} = run([
|
|
103
|
+
'theme',
|
|
104
|
+
'build',
|
|
105
|
+
'ocean.mjs',
|
|
106
|
+
'--check',
|
|
107
|
+
'--json',
|
|
108
|
+
]);
|
|
109
|
+
expect(requested['@astryxdesign/core/theme']).toMatch(
|
|
110
|
+
/\/api\/theme\/build\/build\.mjs$/,
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
});
|