@astryxdesign/cli 0.7.1 → 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/README.md +7 -7
- 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 +108 -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/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/single-component.doc.mjs +3 -2
- 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/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/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.path-safety.test.mjs +84 -0
- package/clients/cli/commands/build-theme.registry.test.mjs +5 -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 +864 -56
- 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/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/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
|
@@ -24,7 +24,6 @@ import * as path from 'node:path';
|
|
|
24
24
|
import * as os from 'node:os';
|
|
25
25
|
import {fileURLToPath} from 'node:url';
|
|
26
26
|
import {spawnSync} from 'node:child_process';
|
|
27
|
-
import jscodeshift from 'jscodeshift';
|
|
28
27
|
import {assertWithin} from '../../foundation/fs/path-safety.mjs';
|
|
29
28
|
import {resolvePackageDir} from '../../foundation/integrations/integrations.mjs';
|
|
30
29
|
import {
|
|
@@ -41,6 +40,7 @@ import {
|
|
|
41
40
|
} from '../../foundation/discovery/docs-discovery.mjs';
|
|
42
41
|
import {discoverIntegrationThemes} from '../../foundation/discovery/theme-discovery.mjs';
|
|
43
42
|
import {inspectPackageExport} from '../../foundation/discovery/package-exports.mjs';
|
|
43
|
+
import {moduleExportsName} from '../../foundation/discovery/module-exports.mjs';
|
|
44
44
|
import {
|
|
45
45
|
ThemeImportError,
|
|
46
46
|
resolveThemeImports,
|
|
@@ -51,6 +51,9 @@ import {
|
|
|
51
51
|
} from '../theme/build/build.mjs';
|
|
52
52
|
import {
|
|
53
53
|
discoverIntegrationComponents,
|
|
54
|
+
docStem,
|
|
55
|
+
familyImports,
|
|
56
|
+
isIntegrationMember,
|
|
54
57
|
resolveIntegrationImportPath,
|
|
55
58
|
} from '../../foundation/discovery/component-discovery.mjs';
|
|
56
59
|
import {loadComponentReplacements} from '../component/_adapter.mjs';
|
|
@@ -307,98 +310,6 @@ function extractTarball(tgzPath, extractDir) {
|
|
|
307
310
|
}
|
|
308
311
|
}
|
|
309
312
|
|
|
310
|
-
const MODULE_EXTENSIONS = ['.mjs', '.js', '.mts', '.ts', '.tsx', '.jsx'];
|
|
311
|
-
const moduleParser = jscodeshift.withParser('tsx');
|
|
312
|
-
|
|
313
|
-
/** @param {unknown} specifier @param {string} fromFile */
|
|
314
|
-
function resolveLocalModule(specifier, fromFile) {
|
|
315
|
-
if (typeof specifier !== 'string' || !specifier.startsWith('.')) return null;
|
|
316
|
-
const base = path.resolve(path.dirname(fromFile), specifier);
|
|
317
|
-
const candidates = [
|
|
318
|
-
base,
|
|
319
|
-
...MODULE_EXTENSIONS.map(extension => `${base}${extension}`),
|
|
320
|
-
...MODULE_EXTENSIONS.map(extension => path.join(base, `index${extension}`)),
|
|
321
|
-
];
|
|
322
|
-
return candidates.find(candidate => fs.existsSync(candidate)) ?? null;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/** @param {any} declaration @param {string} exportName */
|
|
326
|
-
function declarationExports(declaration, exportName) {
|
|
327
|
-
if (!declaration) return false;
|
|
328
|
-
if (['FunctionDeclaration', 'ClassDeclaration'].includes(declaration.type)) {
|
|
329
|
-
return declaration.id?.name === exportName;
|
|
330
|
-
}
|
|
331
|
-
if (declaration.type !== 'VariableDeclaration') return false;
|
|
332
|
-
return declaration.declarations.some(
|
|
333
|
-
(/** @type {any} */ item) =>
|
|
334
|
-
item.id?.type === 'Identifier' && item.id.name === exportName,
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* Check one resolved module's static export surface without executing package
|
|
340
|
-
* code. Local ESM re-exports are followed recursively.
|
|
341
|
-
*
|
|
342
|
-
* @param {string} file
|
|
343
|
-
* @param {string} exportName
|
|
344
|
-
* @param {Set<string>} [seen]
|
|
345
|
-
*/
|
|
346
|
-
function moduleExportsName(file, exportName, seen = new Set()) {
|
|
347
|
-
const identity = `${file}\0${exportName}`;
|
|
348
|
-
if (seen.has(identity) || !fs.existsSync(file)) return false;
|
|
349
|
-
seen.add(identity);
|
|
350
|
-
|
|
351
|
-
let root;
|
|
352
|
-
try {
|
|
353
|
-
root = moduleParser(fs.readFileSync(file, 'utf-8'));
|
|
354
|
-
} catch {
|
|
355
|
-
return false;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
let found = false;
|
|
359
|
-
root
|
|
360
|
-
.find(moduleParser.ExportNamedDeclaration)
|
|
361
|
-
.forEach((/** @type {any} */ exportPath) => {
|
|
362
|
-
if (found) return;
|
|
363
|
-
const node = exportPath.node;
|
|
364
|
-
if (declarationExports(node.declaration, exportName)) {
|
|
365
|
-
found = true;
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
for (const specifier of node.specifiers ?? []) {
|
|
369
|
-
const exported = specifier.exported?.name ?? specifier.exported?.value;
|
|
370
|
-
if (exported !== exportName) continue;
|
|
371
|
-
if (!node.source) {
|
|
372
|
-
found = true;
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
const target = resolveLocalModule(node.source.value, file);
|
|
376
|
-
const imported =
|
|
377
|
-
specifier.local?.name ?? specifier.local?.value ?? exportName;
|
|
378
|
-
if (target && moduleExportsName(target, imported, seen)) {
|
|
379
|
-
found = true;
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
if (found) return true;
|
|
385
|
-
if (
|
|
386
|
-
exportName === 'default' &&
|
|
387
|
-
root.find(moduleParser.ExportDefaultDeclaration).size() > 0
|
|
388
|
-
) {
|
|
389
|
-
return true;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
root
|
|
393
|
-
.find(moduleParser.ExportAllDeclaration)
|
|
394
|
-
.forEach((/** @type {any} */ exportPath) => {
|
|
395
|
-
if (found) return;
|
|
396
|
-
const target = resolveLocalModule(exportPath.node.source?.value, file);
|
|
397
|
-
if (target && moduleExportsName(target, exportName, seen)) found = true;
|
|
398
|
-
});
|
|
399
|
-
return found;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
313
|
/**
|
|
403
314
|
* Whether any of these doc files has a section that sets `id`.
|
|
404
315
|
* @param {string[]} files
|
|
@@ -472,15 +383,20 @@ async function validatePackedComponentExports(integration, scratchBase) {
|
|
|
472
383
|
const issues = [];
|
|
473
384
|
/** @type {Array<{name: string, specifier: string}>} */
|
|
474
385
|
const components = [];
|
|
386
|
+
// A family doc backs several records: load it, and report it, once.
|
|
387
|
+
const loads = new Map();
|
|
475
388
|
for (const record of records) {
|
|
389
|
+
const first = !loads.has(record.docPath);
|
|
390
|
+
if (first) loads.set(record.docPath, loadComponentDoc(record.docPath));
|
|
476
391
|
let docs;
|
|
477
392
|
try {
|
|
478
|
-
docs = await
|
|
393
|
+
docs = await loads.get(record.docPath);
|
|
479
394
|
} catch (err) {
|
|
395
|
+
if (!first) continue;
|
|
480
396
|
issues.push(
|
|
481
397
|
error(
|
|
482
398
|
'component_doc_unloadable',
|
|
483
|
-
`Component "${record.
|
|
399
|
+
`Component "${docStem(record.docPath)}" doc at "${record.docPath}" could not be loaded: ${err instanceof Error ? err.message : String(err)}`,
|
|
484
400
|
),
|
|
485
401
|
);
|
|
486
402
|
continue;
|
|
@@ -660,11 +576,10 @@ async function validateIncompleteThemeExports(
|
|
|
660
576
|
const expectedCss = path.join(expectedDir, `${localTheme.slug}.css`);
|
|
661
577
|
try {
|
|
662
578
|
if (outputs.some(output => output.kind !== 'font stylesheet')) {
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
);
|
|
579
|
+
// The scratch directory is the write root; the package stays the cwd,
|
|
580
|
+
// so the build selects the package's Core and its paths as before.
|
|
581
|
+
const scratchBuild = {out: expectedCss, __writeRoot: expectedDir};
|
|
582
|
+
const receipt = await themeBuild(source, scratchBuild, {cwd: packageDir});
|
|
668
583
|
if (receipt == null || receipt.type !== 'theme.build') {
|
|
669
584
|
throw new Error('the theme build produced no complete receipt');
|
|
670
585
|
}
|
|
@@ -847,11 +762,12 @@ async function validatePackedThemeExports(
|
|
|
847
762
|
);
|
|
848
763
|
const expectedCss = path.join(expectedDir, `${localTheme.slug}.css`);
|
|
849
764
|
try {
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
765
|
+
// The scratch directory is the write root; the package stays the cwd,
|
|
766
|
+
// so the build selects the package's Core and its paths as before.
|
|
767
|
+
const scratchBuild = {out: expectedCss, __writeRoot: expectedDir};
|
|
768
|
+
const receipt = await themeBuild(source, scratchBuild, {
|
|
769
|
+
cwd: localIntegration.__packageDir,
|
|
770
|
+
});
|
|
855
771
|
if (receipt == null || receipt.type !== 'theme.build') {
|
|
856
772
|
issues.push(
|
|
857
773
|
error(
|
|
@@ -1085,6 +1001,24 @@ export async function integrationPackCheck(options = {}) {
|
|
|
1085
1001
|
const fileInv = computeRequiredFiles(loaded);
|
|
1086
1002
|
const {identities: localIdentities, errors: localDiscoveryErrors} =
|
|
1087
1003
|
await collectIdentities(loaded);
|
|
1004
|
+
// A family lists its members from the module its import names, which the
|
|
1005
|
+
// pack lifecycle may build or rebuild, so they are compared as local
|
|
1006
|
+
// discovery lists them after the pack.
|
|
1007
|
+
const familiesBefore = familyImports(loaded).map(family => family.docPath);
|
|
1008
|
+
/**
|
|
1009
|
+
* @param {Array<{name: string, docPath: string|null}>} records
|
|
1010
|
+
* @param {Set<string>} families
|
|
1011
|
+
*/
|
|
1012
|
+
const membersOf = (records, families) =>
|
|
1013
|
+
records
|
|
1014
|
+
.filter(
|
|
1015
|
+
r =>
|
|
1016
|
+
r.docPath != null &&
|
|
1017
|
+
families.has(r.docPath) &&
|
|
1018
|
+
isIntegrationMember(r),
|
|
1019
|
+
)
|
|
1020
|
+
.map(r => r.name);
|
|
1021
|
+
const recordsBefore = discoverIntegrationComponents(loaded);
|
|
1088
1022
|
for (const discoveryError of localDiscoveryErrors) {
|
|
1089
1023
|
issues.push(
|
|
1090
1024
|
error(
|
|
@@ -1345,7 +1279,27 @@ export async function integrationPackCheck(options = {}) {
|
|
|
1345
1279
|
);
|
|
1346
1280
|
}
|
|
1347
1281
|
|
|
1348
|
-
|
|
1282
|
+
const families = new Set([
|
|
1283
|
+
...familiesBefore,
|
|
1284
|
+
...familyImports(loaded).map(family => family.docPath),
|
|
1285
|
+
]);
|
|
1286
|
+
let localComponents = localIdentities.components;
|
|
1287
|
+
if (families.size > 0) {
|
|
1288
|
+
const stale = new Set(membersOf(recordsBefore, families));
|
|
1289
|
+
const built = new Set(
|
|
1290
|
+
membersOf(discoverIntegrationComponents(loaded), families),
|
|
1291
|
+
);
|
|
1292
|
+
const {identities: afterPack} = await collectIdentities(loaded);
|
|
1293
|
+
localComponents = [
|
|
1294
|
+
...new Set([
|
|
1295
|
+
...localComponents.filter(name => !stale.has(name)),
|
|
1296
|
+
...afterPack.components.filter(name => built.has(name)),
|
|
1297
|
+
]),
|
|
1298
|
+
].sort();
|
|
1299
|
+
}
|
|
1300
|
+
// The receipt reports the local inventory that was compared.
|
|
1301
|
+
const comparedLocal = {...localIdentities, components: localComponents};
|
|
1302
|
+
issues.push(...compareIdentities(comparedLocal, packedIdentities));
|
|
1349
1303
|
issues.push(
|
|
1350
1304
|
...(await validatePackedThemeExports(
|
|
1351
1305
|
loaded,
|
|
@@ -1367,7 +1321,7 @@ export async function integrationPackCheck(options = {}) {
|
|
|
1367
1321
|
pkgVersion,
|
|
1368
1322
|
fileInv,
|
|
1369
1323
|
packResult,
|
|
1370
|
-
|
|
1324
|
+
comparedLocal,
|
|
1371
1325
|
packedIdentities,
|
|
1372
1326
|
issues,
|
|
1373
1327
|
);
|
|
@@ -754,6 +754,285 @@ describe('integrationPackCheck', () => {
|
|
|
754
754
|
);
|
|
755
755
|
});
|
|
756
756
|
|
|
757
|
+
it('checks the export a component doc names when its file is named otherwise', async () => {
|
|
758
|
+
fs.writeFileSync(
|
|
759
|
+
path.join(tmpDir, 'package.json'),
|
|
760
|
+
`${JSON.stringify({
|
|
761
|
+
name: '@acme/widgets',
|
|
762
|
+
version: '1.0.0',
|
|
763
|
+
files: ['astryx.integration.mjs', 'components'],
|
|
764
|
+
exports: {'./components/Slides': './components/Slides.tsx'},
|
|
765
|
+
})}\n`,
|
|
766
|
+
);
|
|
767
|
+
fs.writeFileSync(
|
|
768
|
+
path.join(tmpDir, 'astryx.integration.mjs'),
|
|
769
|
+
"export default {components: './components'};\n",
|
|
770
|
+
);
|
|
771
|
+
fs.mkdirSync(path.join(tmpDir, 'components'));
|
|
772
|
+
// Slides.tsx exports AcmeCarousel and nothing named Slides.
|
|
773
|
+
fs.writeFileSync(
|
|
774
|
+
path.join(tmpDir, 'components', 'Slides.tsx'),
|
|
775
|
+
'export function AcmeCarousel() { return null; }\n',
|
|
776
|
+
);
|
|
777
|
+
fs.writeFileSync(
|
|
778
|
+
path.join(tmpDir, 'components', 'Slides.doc.mjs'),
|
|
779
|
+
"export default {type: 'component', name: 'AcmeCarousel', import: '@acme/widgets/components/Slides', description: 'x', props: []};\n",
|
|
780
|
+
);
|
|
781
|
+
|
|
782
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
783
|
+
expect(result.data.packable).toBe(true);
|
|
784
|
+
expect(result.data.contributions.packed.components).toEqual([
|
|
785
|
+
'AcmeCarousel',
|
|
786
|
+
]);
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
it('checks each family member against the module its family doc imports', async () => {
|
|
790
|
+
fs.writeFileSync(
|
|
791
|
+
path.join(tmpDir, 'package.json'),
|
|
792
|
+
`${JSON.stringify({
|
|
793
|
+
name: '@acme/widgets',
|
|
794
|
+
version: '1.0.0',
|
|
795
|
+
files: ['astryx.integration.mjs', 'components'],
|
|
796
|
+
exports: {'./tabs': './components/tabs/index.ts'},
|
|
797
|
+
})}\n`,
|
|
798
|
+
);
|
|
799
|
+
fs.writeFileSync(
|
|
800
|
+
path.join(tmpDir, 'astryx.integration.mjs'),
|
|
801
|
+
"export default {components: './components'};\n",
|
|
802
|
+
);
|
|
803
|
+
const dir = path.join(tmpDir, 'components', 'tabs');
|
|
804
|
+
fs.mkdirSync(dir, {recursive: true});
|
|
805
|
+
fs.writeFileSync(
|
|
806
|
+
path.join(dir, 'AcmeTabs.tsx'),
|
|
807
|
+
'export function AcmeTabs() { return null; }\nexport function AcmeTabsLegacy() { return null; }\n',
|
|
808
|
+
);
|
|
809
|
+
fs.writeFileSync(
|
|
810
|
+
path.join(dir, 'tab.tsx'),
|
|
811
|
+
'export function AcmeTab() { return null; }\n',
|
|
812
|
+
);
|
|
813
|
+
// The module apps import exports AcmeTabs and AcmeTab, not AcmeTabsLegacy.
|
|
814
|
+
fs.writeFileSync(
|
|
815
|
+
path.join(dir, 'index.ts'),
|
|
816
|
+
"export {AcmeTabs} from './AcmeTabs';\nexport {AcmeTab} from './tab';\n",
|
|
817
|
+
);
|
|
818
|
+
fs.writeFileSync(
|
|
819
|
+
path.join(dir, 'AcmeTabs.doc.mjs'),
|
|
820
|
+
"export default {type: 'component', name: 'AcmeTabs', import: '@acme/widgets/tabs', description: 'x', components: [{name: 'AcmeTabs', description: 'x', props: []}, {name: 'AcmeTab', description: 'x', props: []}, {name: 'AcmeTabsLegacy', description: 'x', props: []}]};\n",
|
|
821
|
+
);
|
|
822
|
+
|
|
823
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
824
|
+
|
|
825
|
+
expect(result.data.issues).toEqual([]);
|
|
826
|
+
expect(result.data.packable).toBe(true);
|
|
827
|
+
expect(result.data.contributions.packed.components).toEqual([
|
|
828
|
+
'AcmeTab',
|
|
829
|
+
'AcmeTabs',
|
|
830
|
+
]);
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
it.each([
|
|
834
|
+
'a clean checkout',
|
|
835
|
+
'a stale build',
|
|
836
|
+
'a stale build that exports more',
|
|
837
|
+
])(
|
|
838
|
+
'reads members a family imports from output its pack lifecycle builds, from %s',
|
|
839
|
+
async start => {
|
|
840
|
+
fs.writeFileSync(
|
|
841
|
+
path.join(tmpDir, 'package.json'),
|
|
842
|
+
`${JSON.stringify({
|
|
843
|
+
name: '@acme/widgets',
|
|
844
|
+
version: '1.0.0',
|
|
845
|
+
files: ['astryx.integration.mjs', 'components', 'dist'],
|
|
846
|
+
exports: {'./tabs': './dist/tabs/index.mjs'},
|
|
847
|
+
scripts: {prepack: 'node build.mjs'},
|
|
848
|
+
})}\n`,
|
|
849
|
+
);
|
|
850
|
+
fs.writeFileSync(
|
|
851
|
+
path.join(tmpDir, 'astryx.integration.mjs'),
|
|
852
|
+
"export default {components: './components'};\n",
|
|
853
|
+
);
|
|
854
|
+
// The build writes the module the family imports; a clean checkout has none.
|
|
855
|
+
fs.writeFileSync(
|
|
856
|
+
path.join(tmpDir, 'build.mjs'),
|
|
857
|
+
"import fs from 'node:fs';\nfs.mkdirSync('dist/tabs', {recursive: true});\nfs.writeFileSync('dist/tabs/index.mjs', \"export {AcmeTabs, AcmeTab} from '../../components/tabs/AcmeTabs.tsx';\\n\");\n",
|
|
858
|
+
);
|
|
859
|
+
const dir = path.join(tmpDir, 'components', 'tabs');
|
|
860
|
+
fs.mkdirSync(dir, {recursive: true});
|
|
861
|
+
fs.writeFileSync(
|
|
862
|
+
path.join(dir, 'AcmeTabs.tsx'),
|
|
863
|
+
'export function AcmeTabs() { return null; }\nexport function AcmeTab() { return null; }\nexport function AcmeTabLegacy() { return null; }\n',
|
|
864
|
+
);
|
|
865
|
+
fs.writeFileSync(
|
|
866
|
+
path.join(dir, 'AcmeTabs.doc.mjs'),
|
|
867
|
+
"export default {type: 'component', name: 'AcmeTabs', import: '@acme/widgets/tabs', description: 'x', components: [{name: 'AcmeTabs', description: 'x', props: []}, {name: 'AcmeTab', description: 'x', props: []}, {name: 'AcmeTabLegacy', description: 'x', props: []}]};\n",
|
|
868
|
+
);
|
|
869
|
+
|
|
870
|
+
if (start !== 'a clean checkout') {
|
|
871
|
+
// An earlier build: before AcmeTab was exported, or while AcmeTabLegacy
|
|
872
|
+
// still was.
|
|
873
|
+
const names =
|
|
874
|
+
start === 'a stale build'
|
|
875
|
+
? 'AcmeTabs'
|
|
876
|
+
: 'AcmeTabs, AcmeTab, AcmeTabLegacy';
|
|
877
|
+
fs.mkdirSync(path.join(tmpDir, 'dist', 'tabs'), {recursive: true});
|
|
878
|
+
fs.writeFileSync(
|
|
879
|
+
path.join(tmpDir, 'dist', 'tabs', 'index.mjs'),
|
|
880
|
+
`export {${names}} from '../../components/tabs/AcmeTabs.tsx';\n`,
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
885
|
+
|
|
886
|
+
expect(result.data.issues).toEqual([]);
|
|
887
|
+
expect(result.data.packable).toBe(true);
|
|
888
|
+
expect(result.data.contributions.local.components).toEqual(
|
|
889
|
+
result.data.contributions.packed.components,
|
|
890
|
+
);
|
|
891
|
+
},
|
|
892
|
+
);
|
|
893
|
+
|
|
894
|
+
it.each(['a clean checkout', 'an incremental build'])(
|
|
895
|
+
'reads members built output re-exports from compiled files, from %s',
|
|
896
|
+
async start => {
|
|
897
|
+
fs.writeFileSync(
|
|
898
|
+
path.join(tmpDir, 'package.json'),
|
|
899
|
+
`${JSON.stringify({
|
|
900
|
+
name: '@acme/widgets',
|
|
901
|
+
version: '1.0.0',
|
|
902
|
+
files: ['astryx.integration.mjs', 'components', 'dist'],
|
|
903
|
+
exports: {'./tabs': './dist/tabs/index.mjs'},
|
|
904
|
+
scripts: {prepack: 'node build.mjs'},
|
|
905
|
+
})}\n`,
|
|
906
|
+
);
|
|
907
|
+
fs.writeFileSync(
|
|
908
|
+
path.join(tmpDir, 'astryx.integration.mjs'),
|
|
909
|
+
"export default {components: './components'};\n",
|
|
910
|
+
);
|
|
911
|
+
// The build compiles each source to its own file and, like an
|
|
912
|
+
// incremental build, rewrites only the files whose output changed.
|
|
913
|
+
const output = {
|
|
914
|
+
'index.mjs':
|
|
915
|
+
"export {AcmeTabs} from './tabs.mjs';\nexport * from './tab.mjs';\n",
|
|
916
|
+
'tabs.mjs': 'export function AcmeTabs() { return null; }\n',
|
|
917
|
+
'tab.mjs': 'export function AcmeTab() { return null; }\n',
|
|
918
|
+
};
|
|
919
|
+
fs.writeFileSync(
|
|
920
|
+
path.join(tmpDir, 'build.mjs'),
|
|
921
|
+
`import fs from 'node:fs';\nconst output = ${JSON.stringify(output)};\nfs.mkdirSync('dist/tabs', {recursive: true});\nfor (const [file, text] of Object.entries(output)) {\n const target = 'dist/tabs/' + file;\n if (!fs.existsSync(target) || fs.readFileSync(target, 'utf-8') !== text) fs.writeFileSync(target, text);\n}\n`,
|
|
922
|
+
);
|
|
923
|
+
const dir = path.join(tmpDir, 'components', 'tabs');
|
|
924
|
+
fs.mkdirSync(dir, {recursive: true});
|
|
925
|
+
fs.writeFileSync(
|
|
926
|
+
path.join(dir, 'AcmeTabs.tsx'),
|
|
927
|
+
'export function AcmeTabs() { return null; }\n',
|
|
928
|
+
);
|
|
929
|
+
fs.writeFileSync(
|
|
930
|
+
path.join(dir, 'AcmeTab.tsx'),
|
|
931
|
+
'export function AcmeTab() { return null; }\n',
|
|
932
|
+
);
|
|
933
|
+
fs.writeFileSync(
|
|
934
|
+
path.join(dir, 'AcmeTabs.doc.mjs'),
|
|
935
|
+
"export default {type: 'component', name: 'AcmeTabs', import: '@acme/widgets/tabs', description: 'x', components: [{name: 'AcmeTabs', description: 'x', props: []}, {name: 'AcmeTab', description: 'x', props: []}]};\n",
|
|
936
|
+
);
|
|
937
|
+
if (start === 'an incremental build') {
|
|
938
|
+
// An earlier build from before AcmeTab existed: the file the import
|
|
939
|
+
// names is already current, so the build leaves it untouched.
|
|
940
|
+
fs.mkdirSync(path.join(tmpDir, 'dist', 'tabs'), {recursive: true});
|
|
941
|
+
for (const [file, text] of Object.entries({...output, 'tab.mjs': ''})) {
|
|
942
|
+
fs.writeFileSync(path.join(tmpDir, 'dist', 'tabs', file), text);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
947
|
+
|
|
948
|
+
expect(result.data.issues).toEqual([]);
|
|
949
|
+
expect(result.data.packable).toBe(true);
|
|
950
|
+
expect(result.data.contributions.packed.components).toEqual([
|
|
951
|
+
'AcmeTab',
|
|
952
|
+
'AcmeTabs',
|
|
953
|
+
]);
|
|
954
|
+
expect(result.data.contributions.local.components).toEqual(
|
|
955
|
+
result.data.contributions.packed.components,
|
|
956
|
+
);
|
|
957
|
+
},
|
|
958
|
+
);
|
|
959
|
+
|
|
960
|
+
it('passes a member another folder declares, which has no source', async () => {
|
|
961
|
+
fs.writeFileSync(
|
|
962
|
+
path.join(tmpDir, 'package.json'),
|
|
963
|
+
`${JSON.stringify({
|
|
964
|
+
name: '@acme/widgets',
|
|
965
|
+
version: '1.0.0',
|
|
966
|
+
files: ['astryx.integration.mjs', 'components'],
|
|
967
|
+
exports: {'./menu': './components/menu/index.ts'},
|
|
968
|
+
})}\n`,
|
|
969
|
+
);
|
|
970
|
+
fs.writeFileSync(
|
|
971
|
+
path.join(tmpDir, 'astryx.integration.mjs'),
|
|
972
|
+
"export default {components: './components'};\n",
|
|
973
|
+
);
|
|
974
|
+
const menu = path.join(tmpDir, 'components', 'menu');
|
|
975
|
+
const shared = path.join(tmpDir, 'components', 'shared');
|
|
976
|
+
fs.mkdirSync(menu, {recursive: true});
|
|
977
|
+
fs.mkdirSync(shared, {recursive: true});
|
|
978
|
+
fs.writeFileSync(
|
|
979
|
+
path.join(menu, 'AcmeMenu.doc.mjs'),
|
|
980
|
+
"export default {type: 'component', name: 'AcmeMenu', import: '@acme/widgets/menu', description: 'x', components: [{name: 'AcmeMenuItem', description: 'x', props: []}]};\n",
|
|
981
|
+
);
|
|
982
|
+
fs.writeFileSync(
|
|
983
|
+
path.join(menu, 'AcmeMenu.tsx'),
|
|
984
|
+
'export function AcmeMenu() { return null; }\n',
|
|
985
|
+
);
|
|
986
|
+
fs.writeFileSync(
|
|
987
|
+
path.join(menu, 'index.ts'),
|
|
988
|
+
"export {AcmeMenu} from './AcmeMenu';\nexport {AcmeMenuItem} from '../shared/AcmeMenuItem';\n",
|
|
989
|
+
);
|
|
990
|
+
fs.writeFileSync(
|
|
991
|
+
path.join(shared, 'AcmeMenuItem.tsx'),
|
|
992
|
+
'export function AcmeMenuItem() { return null; }\n',
|
|
993
|
+
);
|
|
994
|
+
|
|
995
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
996
|
+
|
|
997
|
+
expect(result.data.issues).toEqual([]);
|
|
998
|
+
expect(result.data.packable).toBe(true);
|
|
999
|
+
expect(result.data.contributions.packed.components).toEqual([
|
|
1000
|
+
'AcmeMenu',
|
|
1001
|
+
'AcmeMenuItem',
|
|
1002
|
+
]);
|
|
1003
|
+
});
|
|
1004
|
+
|
|
1005
|
+
it('reports a family doc the loader rejects once, not once per member', async () => {
|
|
1006
|
+
fs.writeFileSync(
|
|
1007
|
+
path.join(tmpDir, 'package.json'),
|
|
1008
|
+
`${JSON.stringify({
|
|
1009
|
+
name: '@acme/widgets',
|
|
1010
|
+
version: '1.0.0',
|
|
1011
|
+
files: ['astryx.integration.mjs', 'components'],
|
|
1012
|
+
})}\n`,
|
|
1013
|
+
);
|
|
1014
|
+
fs.writeFileSync(
|
|
1015
|
+
path.join(tmpDir, 'astryx.integration.mjs'),
|
|
1016
|
+
"export default {components: './components'};\n",
|
|
1017
|
+
);
|
|
1018
|
+
fs.mkdirSync(path.join(tmpDir, 'components'));
|
|
1019
|
+
fs.writeFileSync(
|
|
1020
|
+
path.join(tmpDir, 'components', 'AcmeTabs.tsx'),
|
|
1021
|
+
'export function AcmeTabs() { return null; }\nexport function AcmeTab() { return null; }\nexport function AcmeTabPanel() { return null; }\n',
|
|
1022
|
+
);
|
|
1023
|
+
// A displayName that is not a string makes the loader reject the doc.
|
|
1024
|
+
fs.writeFileSync(
|
|
1025
|
+
path.join(tmpDir, 'components', 'AcmeTabs.doc.mjs'),
|
|
1026
|
+
"export default {type: 'component', name: 'AcmeTabs', displayName: 1, description: 'x', components: [{name: 'AcmeTab', description: 'x', props: []}, {name: 'AcmeTabPanel', description: 'x', props: []}]};\n",
|
|
1027
|
+
);
|
|
1028
|
+
|
|
1029
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
1030
|
+
const codes = result.data.issues.map(issue => issue.code);
|
|
1031
|
+
|
|
1032
|
+
expect(codes).toContain('component_doc_unloadable');
|
|
1033
|
+
expect(codes.length).toBe(new Set(codes).size);
|
|
1034
|
+
});
|
|
1035
|
+
|
|
757
1036
|
it('passes a generated component through its exact packed export', async () => {
|
|
758
1037
|
fs.writeFileSync(
|
|
759
1038
|
path.join(tmpDir, 'package.json'),
|
|
@@ -811,6 +1090,86 @@ describe('integrationPackCheck', () => {
|
|
|
811
1090
|
);
|
|
812
1091
|
});
|
|
813
1092
|
|
|
1093
|
+
it('does not count a type-only re-export as the component', async () => {
|
|
1094
|
+
fs.writeFileSync(
|
|
1095
|
+
path.join(tmpDir, 'package.json'),
|
|
1096
|
+
`${JSON.stringify({
|
|
1097
|
+
name: '@acme/widgets',
|
|
1098
|
+
version: '1.0.0',
|
|
1099
|
+
files: ['astryx.integration.mjs', 'src'],
|
|
1100
|
+
exports: {'.': './src/index.ts'},
|
|
1101
|
+
})}\n`,
|
|
1102
|
+
);
|
|
1103
|
+
fs.writeFileSync(
|
|
1104
|
+
path.join(tmpDir, 'astryx.integration.mjs'),
|
|
1105
|
+
"export default {components: './src'};\n",
|
|
1106
|
+
);
|
|
1107
|
+
fs.mkdirSync(path.join(tmpDir, 'src'));
|
|
1108
|
+
fs.writeFileSync(
|
|
1109
|
+
path.join(tmpDir, 'src', 'index.ts'),
|
|
1110
|
+
"export type {AcmeWidget} from './AcmeWidget';\n",
|
|
1111
|
+
);
|
|
1112
|
+
fs.writeFileSync(
|
|
1113
|
+
path.join(tmpDir, 'src', 'AcmeWidget.tsx'),
|
|
1114
|
+
'export function AcmeWidget() { return null; }\n',
|
|
1115
|
+
);
|
|
1116
|
+
fs.writeFileSync(
|
|
1117
|
+
path.join(tmpDir, 'src', 'AcmeWidget.doc.mjs'),
|
|
1118
|
+
"export default {type: 'component', name: 'AcmeWidget', import: '@acme/widgets', description: 'Widget.', props: []};\n",
|
|
1119
|
+
);
|
|
1120
|
+
|
|
1121
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
1122
|
+
|
|
1123
|
+
expect(result.data.issues).toContainEqual(
|
|
1124
|
+
expect.objectContaining({code: 'component_export_missing'}),
|
|
1125
|
+
);
|
|
1126
|
+
});
|
|
1127
|
+
|
|
1128
|
+
it('follows a re-export of a folder to its index file', async () => {
|
|
1129
|
+
// `./primitives` names a folder: TypeScript and bundlers load its index file.
|
|
1130
|
+
fs.writeFileSync(
|
|
1131
|
+
path.join(tmpDir, 'package.json'),
|
|
1132
|
+
`${JSON.stringify({
|
|
1133
|
+
name: '@acme/widgets',
|
|
1134
|
+
version: '1.0.0',
|
|
1135
|
+
files: ['astryx.integration.mjs', 'src'],
|
|
1136
|
+
exports: {'.': './src/index.ts'},
|
|
1137
|
+
})}\n`,
|
|
1138
|
+
);
|
|
1139
|
+
fs.writeFileSync(
|
|
1140
|
+
path.join(tmpDir, 'astryx.integration.mjs'),
|
|
1141
|
+
"export default {components: './src'};\n",
|
|
1142
|
+
);
|
|
1143
|
+
const primitives = path.join(tmpDir, 'src', 'primitives');
|
|
1144
|
+
fs.mkdirSync(primitives, {recursive: true});
|
|
1145
|
+
fs.writeFileSync(
|
|
1146
|
+
path.join(tmpDir, 'src', 'index.ts'),
|
|
1147
|
+
"export * from './primitives';\n",
|
|
1148
|
+
);
|
|
1149
|
+
fs.writeFileSync(
|
|
1150
|
+
path.join(primitives, 'index.ts'),
|
|
1151
|
+
"export * from './AcmeWidget';\n",
|
|
1152
|
+
);
|
|
1153
|
+
fs.writeFileSync(
|
|
1154
|
+
path.join(primitives, 'AcmeWidget.tsx'),
|
|
1155
|
+
'export function AcmeWidget() { return null; }\n',
|
|
1156
|
+
);
|
|
1157
|
+
fs.writeFileSync(
|
|
1158
|
+
path.join(primitives, 'AcmeWidget.doc.mjs'),
|
|
1159
|
+
"export default {type: 'component', name: 'AcmeWidget', import: '@acme/widgets', description: 'Widget.', props: []};\n",
|
|
1160
|
+
);
|
|
1161
|
+
|
|
1162
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
1163
|
+
|
|
1164
|
+
expect(result.data.issues).not.toContainEqual(
|
|
1165
|
+
expect.objectContaining({code: 'component_export_missing'}),
|
|
1166
|
+
);
|
|
1167
|
+
expect(
|
|
1168
|
+
result.data.packable,
|
|
1169
|
+
JSON.stringify(result.data.issues, null, 2),
|
|
1170
|
+
).toBe(true);
|
|
1171
|
+
});
|
|
1172
|
+
|
|
814
1173
|
it('fails when packed template source is hidden by package exports', async () => {
|
|
815
1174
|
writePackage({
|
|
816
1175
|
manifest: "export default {templates: './templates'};\n",
|
package/api/search/search.d.mts
CHANGED
|
@@ -252,4 +252,13 @@ export type Candidate = {
|
|
|
252
252
|
_kind?: "page" | "block" | undefined;
|
|
253
253
|
_resultName?: string | undefined;
|
|
254
254
|
_commandName?: string | undefined;
|
|
255
|
+
/**
|
|
256
|
+
* - How an integration component holds its
|
|
257
|
+
* name, for the owner rule.
|
|
258
|
+
*/
|
|
259
|
+
_hold?: "file" | "doc" | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* - An integration component's doc.
|
|
262
|
+
*/
|
|
263
|
+
_docPath?: string | undefined;
|
|
255
264
|
};
|