@astryxdesign/cli 0.7.1 → 0.7.2-canary.151434a
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/component/component.test.mjs +420 -167
- package/api/component/list/list.mjs +42 -4
- package/api/integration/pack-check.mjs +10 -10
- package/api/search/search.mjs +8 -3
- package/api/search/search.test.mjs +36 -0
- 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/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 +2 -2
- 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/theme-build.doc.mjs +2 -2
- package/clients/cli/lib/component-format.mjs +5 -1
- package/foundation/discovery/component-discovery.d.mts +12 -0
- package/foundation/discovery/component-discovery.mjs +211 -0
- package/foundation/discovery/component-discovery.test.mjs +96 -0
- package/foundation/discovery/template-adapter.mjs +74 -5
- package/foundation/doc-compiler/doc-loads.test.mjs +5 -1
- package/foundation/doc-compiler/inputs.mjs +23 -0
- package/foundation/doc-compiler/inputs.test.mjs +0 -1
- package/foundation/xle/registry.mjs +4 -0
- package/foundation/xle/registry.test.mjs +28 -0
- package/package.json +10 -10
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
discoverComponents,
|
|
17
17
|
discoverExternalComponentsGrouped,
|
|
18
18
|
discoverValidIntegrationComponents,
|
|
19
|
+
familyMember,
|
|
19
20
|
findComponentReadme,
|
|
20
21
|
findExternalComponentDoc,
|
|
21
22
|
resolveImportPath,
|
|
@@ -66,6 +67,33 @@ async function legacyImport(ext, name, coreDir, docOpts) {
|
|
|
66
67
|
*/
|
|
67
68
|
const coreEntry = doc => ({name: doc.name, package: CORE_PACKAGE, ...doc});
|
|
68
69
|
|
|
70
|
+
/**
|
|
71
|
+
* The full-level entry for a component documented as a member of its family's
|
|
72
|
+
* doc (VStack in Stack's doc): a component doc built from the member's own
|
|
73
|
+
* entry, under its own name, display name and import, shaped like every other
|
|
74
|
+
* full entry. Null when the doc is the component's own.
|
|
75
|
+
* @param {any} docs
|
|
76
|
+
* @param {string} name
|
|
77
|
+
* @param {string} coreDir
|
|
78
|
+
* @returns {any}
|
|
79
|
+
*/
|
|
80
|
+
function memberEntry(docs, name, coreDir) {
|
|
81
|
+
const member = familyMember(docs, name);
|
|
82
|
+
if (!member) return null;
|
|
83
|
+
return {
|
|
84
|
+
name,
|
|
85
|
+
package: CORE_PACKAGE,
|
|
86
|
+
displayName: member.displayName ?? name,
|
|
87
|
+
...(docs.group ? {group: docs.group} : {}),
|
|
88
|
+
...(docs.category ? {category: docs.category} : {}),
|
|
89
|
+
usage: member.usage ?? {description: member.description ?? ''},
|
|
90
|
+
props: member.props ?? [],
|
|
91
|
+
...(member.examples ? {examples: member.examples} : {}),
|
|
92
|
+
...(docs.theming ? {theming: docs.theming} : {}),
|
|
93
|
+
import: resolveImportPath(coreDir, name),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
69
97
|
/**
|
|
70
98
|
* The entry for a Core slot an integration component replaces
|
|
71
99
|
* (spec:AST-035 FR11), at the list's detail level: the replacement's own name,
|
|
@@ -177,7 +205,11 @@ export async function componentList(
|
|
|
177
205
|
entries.push({
|
|
178
206
|
name: comp,
|
|
179
207
|
package: CORE_PACKAGE,
|
|
180
|
-
description:
|
|
208
|
+
description:
|
|
209
|
+
familyMember(docs, comp)?.description ||
|
|
210
|
+
docs.usage?.description ||
|
|
211
|
+
docs.description ||
|
|
212
|
+
'',
|
|
181
213
|
import: resolveImportPath(coreDir, comp),
|
|
182
214
|
});
|
|
183
215
|
} catch {
|
|
@@ -215,7 +247,8 @@ export async function componentList(
|
|
|
215
247
|
const readme = findComponentReadme(coreDir, comp);
|
|
216
248
|
if (readme && readme.endsWith('.doc.mjs')) {
|
|
217
249
|
try {
|
|
218
|
-
|
|
250
|
+
const docs = await loadComponentDoc(readme, {zh, lang, dense});
|
|
251
|
+
entries.push(memberEntry(docs, comp, coreDir) ?? coreEntry(docs));
|
|
219
252
|
} catch {
|
|
220
253
|
entries.push({name: `XDS${comp}`, package: CORE_PACKAGE, description: ''});
|
|
221
254
|
}
|
|
@@ -269,7 +302,11 @@ export async function componentList(
|
|
|
269
302
|
result[cat].push({
|
|
270
303
|
name: comp,
|
|
271
304
|
package: CORE_PACKAGE,
|
|
272
|
-
description:
|
|
305
|
+
description:
|
|
306
|
+
familyMember(docs, comp)?.description ||
|
|
307
|
+
docs.usage?.description ||
|
|
308
|
+
docs.description ||
|
|
309
|
+
'',
|
|
273
310
|
import: resolveImportPath(coreDir, comp),
|
|
274
311
|
});
|
|
275
312
|
} catch {
|
|
@@ -310,7 +347,8 @@ export async function componentList(
|
|
|
310
347
|
const readme = findComponentReadme(coreDir, comp);
|
|
311
348
|
if (readme && readme.endsWith('.doc.mjs')) {
|
|
312
349
|
try {
|
|
313
|
-
|
|
350
|
+
const docs = await loadComponentDoc(readme, {zh, lang, dense});
|
|
351
|
+
result[cat].push(memberEntry(docs, comp, coreDir) ?? coreEntry(docs));
|
|
314
352
|
} catch {
|
|
315
353
|
result[cat].push({name: `XDS${comp}`, package: CORE_PACKAGE, description: ''});
|
|
316
354
|
}
|
|
@@ -660,11 +660,10 @@ async function validateIncompleteThemeExports(
|
|
|
660
660
|
const expectedCss = path.join(expectedDir, `${localTheme.slug}.css`);
|
|
661
661
|
try {
|
|
662
662
|
if (outputs.some(output => output.kind !== 'font stylesheet')) {
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
);
|
|
663
|
+
// The scratch directory is the write root; the package stays the cwd,
|
|
664
|
+
// so the build selects the package's Core and its paths as before.
|
|
665
|
+
const scratchBuild = {out: expectedCss, __writeRoot: expectedDir};
|
|
666
|
+
const receipt = await themeBuild(source, scratchBuild, {cwd: packageDir});
|
|
668
667
|
if (receipt == null || receipt.type !== 'theme.build') {
|
|
669
668
|
throw new Error('the theme build produced no complete receipt');
|
|
670
669
|
}
|
|
@@ -847,11 +846,12 @@ async function validatePackedThemeExports(
|
|
|
847
846
|
);
|
|
848
847
|
const expectedCss = path.join(expectedDir, `${localTheme.slug}.css`);
|
|
849
848
|
try {
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
849
|
+
// The scratch directory is the write root; the package stays the cwd,
|
|
850
|
+
// so the build selects the package's Core and its paths as before.
|
|
851
|
+
const scratchBuild = {out: expectedCss, __writeRoot: expectedDir};
|
|
852
|
+
const receipt = await themeBuild(source, scratchBuild, {
|
|
853
|
+
cwd: localIntegration.__packageDir,
|
|
854
|
+
});
|
|
855
855
|
if (receipt == null || receipt.type !== 'theme.build') {
|
|
856
856
|
issues.push(
|
|
857
857
|
error(
|
package/api/search/search.mjs
CHANGED
|
@@ -85,6 +85,7 @@ import {findCoreDir} from '../../foundation/fs/paths.mjs';
|
|
|
85
85
|
import {
|
|
86
86
|
discoverComponents,
|
|
87
87
|
discoverValidIntegrationComponents,
|
|
88
|
+
familyMember,
|
|
88
89
|
findComponentReadme,
|
|
89
90
|
resolveImportPath,
|
|
90
91
|
resolveIntegrationImportPath,
|
|
@@ -1079,7 +1080,11 @@ async function gatherCoreComponents(coreDir) {
|
|
|
1079
1080
|
/** @type {string[]} */
|
|
1080
1081
|
let guidance = [];
|
|
1081
1082
|
if (readme && readme.endsWith('.doc.mjs')) {
|
|
1082
|
-
const
|
|
1083
|
+
const loaded = await loadModuleDoc(readme);
|
|
1084
|
+
// A member documented in its family's doc (VStack in Stack's doc) is
|
|
1085
|
+
// indexed from its own entry: the family's keywords and guidance
|
|
1086
|
+
// describe the family, not the member.
|
|
1087
|
+
const doc = familyMember(loaded, comp) ?? loaded;
|
|
1083
1088
|
if (doc) {
|
|
1084
1089
|
keywords = Array.isArray(doc.keywords) ? doc.keywords : [];
|
|
1085
1090
|
description = doc.usage?.description || doc.description || '';
|
|
@@ -1225,11 +1230,11 @@ export async function componentKeywords(coreDir, cwd) {
|
|
|
1225
1230
|
.flat()
|
|
1226
1231
|
.map(async name => {
|
|
1227
1232
|
const readme = findComponentReadme(coreDir, name);
|
|
1228
|
-
const
|
|
1233
|
+
const loaded =
|
|
1229
1234
|
readme && readme.endsWith('.doc.mjs')
|
|
1230
1235
|
? await loadModuleDoc(readme)
|
|
1231
1236
|
: null;
|
|
1232
|
-
return {name, keywords: keywordsOf(
|
|
1237
|
+
return {name, keywords: keywordsOf(familyMember(loaded, name) ?? loaded)};
|
|
1233
1238
|
});
|
|
1234
1239
|
const loadedIntegrations = await loadIntegrationsSafely(cwd);
|
|
1235
1240
|
const replacements = await loadComponentReplacements(
|
|
@@ -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`
|
|
@@ -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
|
+
});
|
|
@@ -163,6 +163,19 @@ export function themeBuildFamily(files: string[], options: {
|
|
|
163
163
|
checked?: undefined;
|
|
164
164
|
};
|
|
165
165
|
}>;
|
|
166
|
+
/**
|
|
167
|
+
* The bindings one Core provides: the namespaces interception spreads, the
|
|
168
|
+
* functions the build calls, and why the import failed, if it did.
|
|
169
|
+
*/
|
|
170
|
+
export type CoreBindings = {
|
|
171
|
+
themeModule: any;
|
|
172
|
+
rootModule: any;
|
|
173
|
+
importError: any;
|
|
174
|
+
defineTheme: any;
|
|
175
|
+
generateThemeRulesSplit: any;
|
|
176
|
+
generateOnMediaCSS: any;
|
|
177
|
+
generateAdaptationCSS: any;
|
|
178
|
+
};
|
|
166
179
|
/**
|
|
167
180
|
* How one `prop:value` pair on a component target is classified — the single
|
|
168
181
|
* vocabulary both the root and adaptation paths reason in.
|
|
@@ -210,16 +223,3 @@ export type ThemeBuildTrailer = {
|
|
|
210
223
|
*/
|
|
211
224
|
fontNotices: string[];
|
|
212
225
|
};
|
|
213
|
-
/**
|
|
214
|
-
* The bindings one Core provides: the namespaces interception spreads, the
|
|
215
|
-
* functions the build calls, and why the import failed, if it did.
|
|
216
|
-
*/
|
|
217
|
-
export type CoreBindings = {
|
|
218
|
-
themeModule: any;
|
|
219
|
-
rootModule: any;
|
|
220
|
-
importError: any;
|
|
221
|
-
defineTheme: any;
|
|
222
|
-
generateThemeRulesSplit: any;
|
|
223
|
-
generateOnMediaCSS: any;
|
|
224
|
-
generateAdaptationCSS: any;
|
|
225
|
-
};
|
|
@@ -252,6 +252,22 @@ describe('themeBuildFamily()', () => {
|
|
|
252
252
|
expect(fs.existsSync(dtsPath)).toBe(false);
|
|
253
253
|
});
|
|
254
254
|
|
|
255
|
+
it('refuses family outputs outside cwd before checking or writing', async () => {
|
|
256
|
+
const dir = makeDir();
|
|
257
|
+
const files = writeFamily(dir).map(file => path.join(dir, file));
|
|
258
|
+
const app = path.join(dir, 'app');
|
|
259
|
+
fs.mkdirSync(app);
|
|
260
|
+
|
|
261
|
+
for (const check of [false, true]) {
|
|
262
|
+
await expect(
|
|
263
|
+
themeBuildFamily(files, {familyKey: FAMILY_KEY, check}, {cwd: app}),
|
|
264
|
+
).rejects.toMatchObject({code: 'ERR_PATH_TRAVERSAL'});
|
|
265
|
+
}
|
|
266
|
+
for (const output of OUTPUTS) {
|
|
267
|
+
expect(fs.existsSync(path.join(dir, 'themes', output))).toBe(false);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
|
|
255
271
|
it('fails without publishing a mixed trio when staging a write fails', async () => {
|
|
256
272
|
const dir = makeDir();
|
|
257
273
|
const files = writeFamily(dir);
|