@astryxdesign/cli 0.1.2-canary.41cdf33 → 0.1.2-canary.4497b08
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/docs/layout.doc.dense.mjs +90 -0
- package/docs/layout.doc.mjs +160 -0
- package/docs/principles.doc.dense.mjs +2 -2
- package/docs/principles.doc.mjs +4 -0
- package/docs/principles.doc.zh.mjs +2 -2
- package/package.json +7 -7
- package/src/commands/agent-docs.mjs +3 -0
- package/src/commands/build-theme.import-path.test.mjs +2 -12
- package/src/commands/build-theme.prose.test.mjs +5 -15
- package/src/commands/build-theme.watch.test.mjs +5 -13
- package/src/commands/ensure-core-built.mjs +120 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/** @type {import('../../core/src/docs-types').ReferenceTranslationDoc} */
|
|
4
|
+
|
|
5
|
+
export const docsDense = {
|
|
6
|
+
description:
|
|
7
|
+
'frame-first app layout: shell choice, region budgets, cards vs rows',
|
|
8
|
+
sections: [
|
|
9
|
+
{
|
|
10
|
+
title: 'Frame First',
|
|
11
|
+
content: [
|
|
12
|
+
{
|
|
13
|
+
type: 'prose',
|
|
14
|
+
text: 'decide frame before content. content-first (Card-wrapped sections in a scroll column) = prototype look.',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
type: 'list',
|
|
18
|
+
items: [
|
|
19
|
+
'pick frame: AppShell (nav apps) | Layout+LayoutPanel+LayoutContent (multi-pane tools) | plain column (docs/forms)',
|
|
20
|
+
'budget regions in px first: side nav 240-280, rail 64-72, inspector 340-420, facet rail 220-260',
|
|
21
|
+
'container policy per region: dense data = rows; dashboards/galleries = card grids',
|
|
22
|
+
'write responsive contract up front',
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
null,
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
title: 'App Archetypes',
|
|
30
|
+
content: [
|
|
31
|
+
{
|
|
32
|
+
type: 'prose',
|
|
33
|
+
text: 'container choice tracks archetype, not preference.',
|
|
34
|
+
},
|
|
35
|
+
null,
|
|
36
|
+
{
|
|
37
|
+
type: 'prose',
|
|
38
|
+
text: 'start from matching template (astryx template --list), study with --skeleton.',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
title: 'Cards vs Rows',
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
type: 'prose',
|
|
47
|
+
text: 'Card = widget container, NOT list-item wrapper. dense/scannable/selectable data = rows: Table (columnar) or List/Item (single-line), edge-to-edge, 32-40px rows, dividers.',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: 'list',
|
|
51
|
+
items: [
|
|
52
|
+
'Table+plugins: hosts, deployments, monitors, users',
|
|
53
|
+
'List/Item rows: issues, files, conversations',
|
|
54
|
+
'Card: KPI tiles, chart panels, gallery entries, settings groups',
|
|
55
|
+
'EmptyState for zero-match',
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: 'list',
|
|
60
|
+
items: [
|
|
61
|
+
'no Card-wrapped list items (card soup)',
|
|
62
|
+
'no stacked full-width Cards as page structure',
|
|
63
|
+
'no Cards in Cards',
|
|
64
|
+
'no decorative Badge — counts/enums only; StatusDot/Token for status',
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
title: 'Panels and Inspectors',
|
|
71
|
+
content: [
|
|
72
|
+
{
|
|
73
|
+
type: 'prose',
|
|
74
|
+
text: 'master-detail: row select opens fixed-width inspector (LayoutPanel end slot + width budget + resizable/useResizable). overlay content <=1024px, do not compress.',
|
|
75
|
+
},
|
|
76
|
+
null,
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
title: 'Responsive Contract',
|
|
81
|
+
content: [
|
|
82
|
+
{
|
|
83
|
+
type: 'prose',
|
|
84
|
+
text: 'declare breakpoint behavior as comment at frame root: which regions collapse/overlay/drop at which widths.',
|
|
85
|
+
},
|
|
86
|
+
null,
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/** @type {import('../../core/src/docs-types').ReferenceDoc} */
|
|
4
|
+
|
|
5
|
+
export const docs = {
|
|
6
|
+
name: 'layout',
|
|
7
|
+
title: 'Layout',
|
|
8
|
+
category: 'guide',
|
|
9
|
+
description:
|
|
10
|
+
'Frame-first app layout: choosing a shell, budgeting regions, and when to use cards vs rows.',
|
|
11
|
+
|
|
12
|
+
sections: [
|
|
13
|
+
{
|
|
14
|
+
title: 'Frame First',
|
|
15
|
+
content: [
|
|
16
|
+
{
|
|
17
|
+
type: 'prose',
|
|
18
|
+
text: 'Decide the frame before writing any content. Real applications are built top-down: pick the shell, name its regions, give each region an explicit size budget, then fill regions with content. Content-first layout (writing sections and wrapping each one in a Card) produces a padded scroll column that reads as a prototype, not a product.',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
type: 'list',
|
|
22
|
+
style: 'ordered',
|
|
23
|
+
items: [
|
|
24
|
+
'Pick the frame: AppShell (top nav and/or side nav apps), Layout + LayoutPanel + LayoutContent (multi-pane tools like explorers and consoles), or a plain content column (documents, marketing, forms)',
|
|
25
|
+
'Budget regions in px before filling them: side nav 240–280, icon rail 64–72, detail/inspector panel 340–420, filter/facet rail 220–260',
|
|
26
|
+
'Decide the container policy per region: dense data renders as rows; widget dashboards and galleries render as card grids (see Cards vs Rows)',
|
|
27
|
+
'Write the responsive contract up front: which regions collapse, overlay, or drop at which breakpoints (see Responsive Contract)',
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
type: 'code',
|
|
32
|
+
lang: 'tsx',
|
|
33
|
+
label: 'A three-region tool frame',
|
|
34
|
+
code: `// Frame: nav 256 | content flex | inspector 380 (resizable)
|
|
35
|
+
<AppShell sideNav={<SideNav>{/* nav items */}</SideNav>} contentPadding={0}>
|
|
36
|
+
<Layout>
|
|
37
|
+
<LayoutContent>{/* dense list or table, edge-to-edge */}</LayoutContent>
|
|
38
|
+
<LayoutPanel width={380} resizable={{minSizePx: 320, maxSizePx: 480}} hasDivider>
|
|
39
|
+
{/* inspector for the selected row */}
|
|
40
|
+
</LayoutPanel>
|
|
41
|
+
</Layout>
|
|
42
|
+
</AppShell>`,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
title: 'App Archetypes',
|
|
48
|
+
content: [
|
|
49
|
+
{
|
|
50
|
+
type: 'prose',
|
|
51
|
+
text: 'Match the frame and container policy to the kind of app you are building. These recipes are distilled from product-scale apps built with the design system; container choice tracks the archetype, not personal preference.',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: 'table',
|
|
55
|
+
headers: ['Archetype', 'Frame', 'Container policy'],
|
|
56
|
+
rows: [
|
|
57
|
+
[
|
|
58
|
+
'Tracker / work tool (issues, tickets, CRM)',
|
|
59
|
+
'AppShell + SideNav; inspector LayoutPanel on select',
|
|
60
|
+
'Rows only. Grouped edge-to-edge lists, zero cards',
|
|
61
|
+
],
|
|
62
|
+
[
|
|
63
|
+
'Console / observability (metrics, logs, deploys)',
|
|
64
|
+
'AppShell + SideNav or TopNav + TabList',
|
|
65
|
+
'Card grid for dashboard widgets; Table for everything else',
|
|
66
|
+
],
|
|
67
|
+
[
|
|
68
|
+
'Messaging / feed',
|
|
69
|
+
'Column frame: rail + sidebar + stream + panel',
|
|
70
|
+
'Rows and bubbles. No cards in the stream',
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
'Media library / gallery',
|
|
74
|
+
'AppShell + TopNav; grid content',
|
|
75
|
+
'Card grid (ClickableCard) with dense metadata rows in detail views',
|
|
76
|
+
],
|
|
77
|
+
[
|
|
78
|
+
'Settings / forms',
|
|
79
|
+
'AppShell + SideNav or settings template',
|
|
80
|
+
'Sections with FormLayout; Card only to group dangerous or billing actions',
|
|
81
|
+
],
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
type: 'prose',
|
|
86
|
+
text: 'Start from a template that matches the archetype (`npx astryx template --list`), then study its structure with `--skeleton` before customizing.',
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
title: 'Cards vs Rows',
|
|
92
|
+
content: [
|
|
93
|
+
{
|
|
94
|
+
type: 'prose',
|
|
95
|
+
text: 'Card is a widget container, not a list-item wrapper. The fastest way to make an app look like a generic AI prototype is to wrap every record in a Card with a Badge. Dense data — anything the user scans, filters, or selects — belongs in rows: Table for columnar data, List/Item for single-line records, edge-to-edge with dividers and 32–40px row height.',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
type: 'list',
|
|
99
|
+
style: 'do',
|
|
100
|
+
items: [
|
|
101
|
+
'Table (with selection/sorting plugins) for columnar records: hosts, deployments, monitors, users',
|
|
102
|
+
'List/Item rows for scannable single-line records: issues, files, conversations',
|
|
103
|
+
'Card for self-contained widgets: KPI tiles, chart panels, gallery entries, settings groups',
|
|
104
|
+
'EmptyState inside the region when a filter matches nothing',
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
type: 'list',
|
|
109
|
+
style: 'dont',
|
|
110
|
+
items: [
|
|
111
|
+
'Wrapping each list item in a Card (card soup)',
|
|
112
|
+
'Stacking full-width Cards as a substitute for page structure',
|
|
113
|
+
'Nesting Cards inside Cards',
|
|
114
|
+
'Using Badge as decoration — reserve it for counts and enumerated states; use StatusDot or Token for status and metadata',
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
title: 'Panels and Inspectors',
|
|
121
|
+
content: [
|
|
122
|
+
{
|
|
123
|
+
type: 'prose',
|
|
124
|
+
text: 'Master-detail is the backbone of tool UIs: selecting a row opens a fixed-width inspector panel rather than navigating away. Use LayoutPanel in the end slot with an explicit width budget; add resizable (useResizable) for user control, and let the panel overlay the content region below ~1024px instead of compressing it.',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
type: 'code',
|
|
128
|
+
lang: 'tsx',
|
|
129
|
+
label: 'Inspector that overlays at narrow widths',
|
|
130
|
+
code: `<LayoutPanel
|
|
131
|
+
width={380}
|
|
132
|
+
hasDivider
|
|
133
|
+
isScrollable
|
|
134
|
+
label="Details"
|
|
135
|
+
resizable={{minSizePx: 320, maxSizePx: 480, autoSaveId: 'inspector'}}>
|
|
136
|
+
{selected ? <DetailFields item={selected} /> : <EmptyState title="Nothing selected" />}
|
|
137
|
+
</LayoutPanel>`,
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
title: 'Responsive Contract',
|
|
143
|
+
content: [
|
|
144
|
+
{
|
|
145
|
+
type: 'prose',
|
|
146
|
+
text: 'Declare breakpoint behavior as a contract before building, and keep it in a comment at the frame root. A typical contract: full frame above 1024px; inspector panels overlay the content column at 1024px and below; the side nav collapses into MobileNav at 768px and below. Deciding this up front keeps every region change intentional instead of emergent.',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
type: 'code',
|
|
150
|
+
lang: 'tsx',
|
|
151
|
+
label: 'Contract comment at the frame root',
|
|
152
|
+
code: `// Responsive contract:
|
|
153
|
+
// > 1024px nav 256 | content | inspector 380
|
|
154
|
+
// <= 1024px inspector overlays content (position: absolute, end-aligned)
|
|
155
|
+
// <= 768px nav collapses into MobileNav drawer; toolbar actions wrap`,
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
};
|
|
@@ -6,9 +6,9 @@ export const docsDense = {
|
|
|
6
6
|
description: 'core design principles + rules for the design system',
|
|
7
7
|
sections: [
|
|
8
8
|
{ title: 'Philosophy', content: [{ type: 'list', items: ['components over primitives', 'semantic tokens over hardcoded values', 'theme-agnostic code', 'open internals'] }] },
|
|
9
|
-
{ title: 'Rules', content: [{ type: 'list', items: ['use components', 'StyleX or Tailwind for styling', 'semantic tokens only', 'CSS vars for colors', 'controlled form inputs', 'useLinkComponent() for navigation'] }] },
|
|
9
|
+
{ title: 'Rules', content: [{ type: 'list', items: ['use components', 'frame-first layout: shell + region budgets before content (astryx docs layout)', 'dense data = rows (Table, List/Item) not Cards; Card = widgets/galleries/settings groups', 'StyleX or Tailwind for styling', 'semantic tokens only', 'CSS vars for colors', 'controlled form inputs', 'useLinkComponent() for navigation'] }] },
|
|
10
10
|
{ title: 'Styling', content: [{ type: 'prose', text: 'xstyle prop for component overrides. StyleX or Tailwind for layout. See astryx docs styling.' }] },
|
|
11
|
-
{ title: 'Anti-Patterns', content: [{ type: 'list', items: ['no inline styles on raw elements', 'no hardcoded colors — use tokens or Tailwind semantic classes', 'no hardcoded spacing', 'no hardcoded <a> — use useLinkComponent()', 'read docs before inventing props'] }] },
|
|
11
|
+
{ title: 'Anti-Patterns', content: [{ type: 'list', items: ['no inline styles on raw elements', 'no hardcoded colors — use tokens or Tailwind semantic classes', 'no hardcoded spacing', 'no hardcoded <a> — use useLinkComponent()', 'no Card-wrapped list items — frame first, rows for dense data (astryx docs layout)', 'no decorative Badge — StatusDot/Token for status', 'read docs before inventing props'] }] },
|
|
12
12
|
{ title: 'Tokens', content: [{ type: 'prose', text: 'run npx astryx docs tokens for full reference' }] },
|
|
13
13
|
],
|
|
14
14
|
};
|
package/docs/principles.doc.mjs
CHANGED
|
@@ -39,6 +39,8 @@ export const docs = {
|
|
|
39
39
|
style: 'ordered',
|
|
40
40
|
items: [
|
|
41
41
|
'Use components for everything they cover',
|
|
42
|
+
'Layout is frame-first: pick the shell and budget regions before writing content (see \`npx astryx docs layout\`)',
|
|
43
|
+
'Dense data renders as rows (Table, List/Item), edge-to-edge with dividers; Card is for widgets, galleries, and settings groups',
|
|
42
44
|
'StyleX or Tailwind for custom styling; both are first-class (see \`npx astryx docs styling\`)',
|
|
43
45
|
'Semantic tokens, not hardcoded values (see \`npx astryx docs tokens\`)',
|
|
44
46
|
'CSS custom properties for colors, not hex values',
|
|
@@ -74,6 +76,8 @@ export const docs = {
|
|
|
74
76
|
'Hardcoded colors (#fff). Use var(--color-*) or Tailwind semantic classes (text-primary, bg-surface)',
|
|
75
77
|
'Hardcoded spacing (16px). Use spacing tokens or Tailwind spacing utilities',
|
|
76
78
|
'Hardcoded <a> elements. Use useLinkComponent() so consumers can swap in their framework router via LinkProvider',
|
|
79
|
+
'Wrapping every list item or page section in a Card. Decide the frame first; dense data renders as rows (see \`npx astryx docs layout\`)',
|
|
80
|
+
'Badge as decoration. Reserve Badge for counts and enumerated states; use StatusDot or Token for status',
|
|
77
81
|
'Inventing props. Read component docs first',
|
|
78
82
|
],
|
|
79
83
|
},
|
|
@@ -6,9 +6,9 @@ export const docsZh = {
|
|
|
6
6
|
description: 'XDS 核心设计原则和规则。',
|
|
7
7
|
sections: [
|
|
8
8
|
{ title: '设计哲学', content: [{ type: 'list', items: ['组件优于原始元素 — 优先使用 XDS 组件', '语义化令牌优于硬编码值', '主题无关的代码 — 深色模式自动生效', '开放的内部机制 — 所有基础组件均可导出和组合'] }] },
|
|
9
|
-
{ title: '规则', content: [{ type: 'list', items: ['所有支持的场景都使用 XDS 组件', '使用 StyleX 或 Tailwind 进行样式设置', '使用语义化令牌,不使用硬编码值', '使用 CSS 变量设置颜色,不使用十六进制值', '表单输入为受控组件(value + onChange)', '使用 useLinkComponent() 进行导航'] }] },
|
|
9
|
+
{ title: '规则', content: [{ type: 'list', items: ['所有支持的场景都使用 XDS 组件', '布局采用框架优先:先选定外壳并规划区域尺寸,再编写内容(见 astryx docs layout)', '密集数据使用行(Table、List/Item)通栏渲染;Card 用于小部件、画廊和设置分组', '使用 StyleX 或 Tailwind 进行样式设置', '使用语义化令牌,不使用硬编码值', '使用 CSS 变量设置颜色,不使用十六进制值', '表单输入为受控组件(value + onChange)', '使用 useLinkComponent() 进行导航'] }] },
|
|
10
10
|
{ title: '样式方法', content: [{ type: 'prose', text: '组件覆盖使用 xstyle 属性。布局使用 StyleX 或 Tailwind。详见 astryx docs styling。' }] },
|
|
11
|
-
{ title: '反模式', content: [{ type: 'list', items: ['不要在原始元素上使用内联样式', '不要硬编码颜色 — 使用令牌或 Tailwind 语义类', '不要硬编码间距', '不要硬编码 <a> 元素 — 使用 useLinkComponent()', '不要自创属性。先阅读组件文档'] }] },
|
|
11
|
+
{ title: '反模式', content: [{ type: 'list', items: ['不要在原始元素上使用内联样式', '不要硬编码颜色 — 使用令牌或 Tailwind 语义类', '不要硬编码间距', '不要硬编码 <a> 元素 — 使用 useLinkComponent()', '不要把每个列表项都包在 Card 里 — 先定框架,密集数据用行渲染(见 astryx docs layout)', '不要把 Badge 当装饰 — 状态请使用 StatusDot 或 Token', '不要自创属性。先阅读组件文档'] }] },
|
|
12
12
|
{ title: '设计令牌', content: [{ type: 'prose', text: '运行 npx astryx docs tokens 查看完整参考' }] },
|
|
13
13
|
],
|
|
14
14
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.1.2-canary.
|
|
3
|
+
"version": "0.1.2-canary.4497b08",
|
|
4
4
|
"displayName": "CLI",
|
|
5
5
|
"description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
@@ -75,9 +75,9 @@
|
|
|
75
75
|
"zod": "^4.4.3"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
|
-
"@astryxdesign/core": "0.1.2-canary.
|
|
79
|
-
"@astryxdesign/lab": "0.1.2-canary.
|
|
80
|
-
"@astryxdesign/theme-neutral": "0.1.2-canary.
|
|
78
|
+
"@astryxdesign/core": "0.1.2-canary.4497b08",
|
|
79
|
+
"@astryxdesign/lab": "0.1.2-canary.4497b08",
|
|
80
|
+
"@astryxdesign/theme-neutral": "0.1.2-canary.4497b08",
|
|
81
81
|
"gpt-tokenizer": "^2.0.0"
|
|
82
82
|
},
|
|
83
83
|
"peerDependenciesMeta": {
|
|
@@ -92,9 +92,9 @@
|
|
|
92
92
|
}
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
95
|
-
"@astryxdesign/core": "0.1.2-canary.
|
|
96
|
-
"@astryxdesign/lab": "0.1.2-canary.
|
|
97
|
-
"@astryxdesign/theme-neutral": "0.1.2-canary.
|
|
95
|
+
"@astryxdesign/core": "0.1.2-canary.4497b08",
|
|
96
|
+
"@astryxdesign/lab": "0.1.2-canary.4497b08",
|
|
97
|
+
"@astryxdesign/theme-neutral": "0.1.2-canary.4497b08",
|
|
98
98
|
"gpt-tokenizer": "^2.0.0"
|
|
99
99
|
},
|
|
100
100
|
"scripts": {
|
|
@@ -180,6 +180,9 @@ export function generateCompressedIndex(version, {coreDir, runPrefix = getRunPre
|
|
|
180
180
|
// Rules — the top error-preventers.
|
|
181
181
|
lines.push('RULES:');
|
|
182
182
|
lines.push('- No <div> — components do all layout/spacing. Full page → AppShell; sidebar nav → SideNav.');
|
|
183
|
+
lines.push('- Frame first: pick the shell (AppShell / Layout+LayoutPanel) and budget regions in px BEFORE writing content (`astryx docs layout`).');
|
|
184
|
+
lines.push('- Dense data = rows (Table, List/Item) edge-to-edge — never Card-wrapped list items. Card = dashboard widgets, galleries, settings groups only.');
|
|
185
|
+
lines.push('- Status → StatusDot/Token; Badge only for counts and enumerated states, never decoration.');
|
|
183
186
|
// Styling guidance tailored to the project's configured system — never
|
|
184
187
|
// recommend a path that isn't compiled here (xstyle needs the StyleX compiler;
|
|
185
188
|
// utilities need Tailwind). Tokens are always the source of truth.
|
|
@@ -18,14 +18,10 @@ import * as fs from 'node:fs';
|
|
|
18
18
|
import * as path from 'node:path';
|
|
19
19
|
import * as os from 'node:os';
|
|
20
20
|
import {fileURLToPath} from 'node:url';
|
|
21
|
+
import {ensureCoreBuilt} from './ensure-core-built.mjs';
|
|
21
22
|
|
|
22
23
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
23
24
|
const CLI_BIN = path.resolve(__dirname, '../../bin/astryx.mjs');
|
|
24
|
-
const REPO_ROOT = path.resolve(__dirname, '../../../..');
|
|
25
|
-
const CORE_THEME_ENTRY = path.join(
|
|
26
|
-
REPO_ROOT,
|
|
27
|
-
'packages/core/dist/theme/index.js',
|
|
28
|
-
);
|
|
29
25
|
|
|
30
26
|
function runCli(args, cwd) {
|
|
31
27
|
try {
|
|
@@ -59,13 +55,7 @@ function writeTheme(dir, name) {
|
|
|
59
55
|
// in-CLI fallback generator). Build core once if it isn't already present so
|
|
60
56
|
// the suite works in any CI job, regardless of job ordering.
|
|
61
57
|
beforeAll(() => {
|
|
62
|
-
|
|
63
|
-
execFileSync('pnpm', ['-F', '@astryxdesign/core', 'build'], {
|
|
64
|
-
cwd: REPO_ROOT,
|
|
65
|
-
stdio: 'pipe',
|
|
66
|
-
timeout: 180_000,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
58
|
+
ensureCoreBuilt();
|
|
69
59
|
}, 200_000);
|
|
70
60
|
|
|
71
61
|
let tmpDir;
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
* - paragraphs use the body font, not the heading font.
|
|
19
19
|
*
|
|
20
20
|
* Building `astryx theme build` requires a compiled @astryxdesign/core (there is no in-CLI
|
|
21
|
-
* fallback generator), so this suite builds core once in beforeAll
|
|
22
|
-
*
|
|
23
|
-
* ordering.
|
|
21
|
+
* fallback generator), so this suite builds core once in beforeAll via the
|
|
22
|
+
* shared ensureCoreBuilt() helper — which serializes concurrent Vitest workers
|
|
23
|
+
* behind a lock — to stay self-sufficient regardless of CI job ordering.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import {describe, it, expect, beforeAll, beforeEach, afterEach} from 'vitest';
|
|
@@ -29,14 +29,10 @@ import * as fs from 'node:fs';
|
|
|
29
29
|
import * as path from 'node:path';
|
|
30
30
|
import * as os from 'node:os';
|
|
31
31
|
import {fileURLToPath} from 'node:url';
|
|
32
|
+
import {ensureCoreBuilt} from './ensure-core-built.mjs';
|
|
32
33
|
|
|
33
34
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
34
35
|
const CLI_BIN = path.resolve(__dirname, '../../bin/astryx.mjs');
|
|
35
|
-
const REPO_ROOT = path.resolve(__dirname, '../../../..');
|
|
36
|
-
const CORE_THEME_ENTRY = path.join(
|
|
37
|
-
REPO_ROOT,
|
|
38
|
-
'packages/core/dist/theme/index.js',
|
|
39
|
-
);
|
|
40
36
|
|
|
41
37
|
function runCli(args, cwd) {
|
|
42
38
|
try {
|
|
@@ -71,13 +67,7 @@ function writeTheme(dir, name) {
|
|
|
71
67
|
// `astryx theme build` imports the compiled @astryxdesign/core/theme entry. Build core
|
|
72
68
|
// once if it isn't already present so the suite works in any CI job.
|
|
73
69
|
beforeAll(() => {
|
|
74
|
-
|
|
75
|
-
execFileSync('pnpm', ['-F', '@astryxdesign/core', 'build'], {
|
|
76
|
-
cwd: REPO_ROOT,
|
|
77
|
-
stdio: 'pipe',
|
|
78
|
-
timeout: 180_000,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
70
|
+
ensureCoreBuilt();
|
|
81
71
|
}, 200_000);
|
|
82
72
|
|
|
83
73
|
let tmpDir;
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
* the watcher keeps running.
|
|
10
10
|
*
|
|
11
11
|
* Building `astryx theme build` requires a compiled @astryxdesign/core, so this
|
|
12
|
-
* suite builds core once in beforeAll (
|
|
12
|
+
* suite builds core once in beforeAll via the shared ensureCoreBuilt() helper —
|
|
13
|
+
* which serializes concurrent Vitest workers behind a lock — to stay
|
|
14
|
+
* self-sufficient regardless of CI job ordering.
|
|
13
15
|
*/
|
|
14
16
|
|
|
15
17
|
import {describe, it, expect, beforeAll, beforeEach, afterEach} from 'vitest';
|
|
@@ -18,14 +20,10 @@ import * as fs from 'node:fs';
|
|
|
18
20
|
import * as path from 'node:path';
|
|
19
21
|
import * as os from 'node:os';
|
|
20
22
|
import {fileURLToPath} from 'node:url';
|
|
23
|
+
import {ensureCoreBuilt} from './ensure-core-built.mjs';
|
|
21
24
|
|
|
22
25
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
23
26
|
const CLI_BIN = path.resolve(__dirname, '../../bin/astryx.mjs');
|
|
24
|
-
const REPO_ROOT = path.resolve(__dirname, '../../../..');
|
|
25
|
-
const CORE_THEME_ENTRY = path.join(
|
|
26
|
-
REPO_ROOT,
|
|
27
|
-
'packages/core/dist/theme/index.js',
|
|
28
|
-
);
|
|
29
27
|
|
|
30
28
|
function runCli(args, cwd) {
|
|
31
29
|
try {
|
|
@@ -56,13 +54,7 @@ async function waitFor(predicate, {timeout = 8000, interval = 50} = {}) {
|
|
|
56
54
|
}
|
|
57
55
|
|
|
58
56
|
beforeAll(() => {
|
|
59
|
-
|
|
60
|
-
execFileSync('pnpm', ['-F', '@astryxdesign/core', 'build'], {
|
|
61
|
-
cwd: REPO_ROOT,
|
|
62
|
-
stdio: 'pipe',
|
|
63
|
-
timeout: 180_000,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
57
|
+
ensureCoreBuilt();
|
|
66
58
|
}, 200_000);
|
|
67
59
|
|
|
68
60
|
let tmpDir;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Shared test helper: build @astryxdesign/core once, race-free.
|
|
5
|
+
*
|
|
6
|
+
* `astryx theme build` imports the compiled @astryxdesign/core/theme entry
|
|
7
|
+
* (there is no in-CLI fallback generator), so any test exercising it needs a
|
|
8
|
+
* built core. The CI `test` job runs `pnpm test` without a prior core build,
|
|
9
|
+
* and Vitest runs test files in parallel worker forks. When two build-theme
|
|
10
|
+
* suites each ran `if (!exists) pnpm -F @astryxdesign/core build` in their own
|
|
11
|
+
* beforeAll, both workers saw dist missing and launched concurrent builds that
|
|
12
|
+
* collided on the shared packages/core/dist (core's build starts with
|
|
13
|
+
* `rimraf dist`): one worker wiped dist while the other was mid-write, failing
|
|
14
|
+
* nondeterministically ("Could not resolve dist/index.js" / "ENOTEMPTY rmdir
|
|
15
|
+
* dist/hooks").
|
|
16
|
+
*
|
|
17
|
+
* This serializes the build behind a filesystem lock so exactly one worker
|
|
18
|
+
* builds and the rest wait for it to finish before reading dist.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import {execFileSync} from 'node:child_process';
|
|
22
|
+
import * as fs from 'node:fs';
|
|
23
|
+
import * as os from 'node:os';
|
|
24
|
+
import * as path from 'node:path';
|
|
25
|
+
import {fileURLToPath} from 'node:url';
|
|
26
|
+
|
|
27
|
+
const REPO_ROOT = path.resolve(
|
|
28
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
29
|
+
'../../../..',
|
|
30
|
+
);
|
|
31
|
+
const CORE_THEME_ENTRY = path.join(
|
|
32
|
+
REPO_ROOT,
|
|
33
|
+
'packages/core/dist/theme/index.js',
|
|
34
|
+
);
|
|
35
|
+
// A lock directory (mkdir is atomic across processes) guards the build.
|
|
36
|
+
const LOCK_DIR = path.join(os.tmpdir(), 'astryx-core-build.lock');
|
|
37
|
+
|
|
38
|
+
const BUILD_TIMEOUT_MS = 180_000;
|
|
39
|
+
// A lock older than this is assumed abandoned by a crashed/killed worker.
|
|
40
|
+
const STALE_LOCK_MS = BUILD_TIMEOUT_MS + 20_000;
|
|
41
|
+
const POLL_MS = 250;
|
|
42
|
+
|
|
43
|
+
function sleepSync(ms) {
|
|
44
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function buildCore() {
|
|
48
|
+
execFileSync('pnpm', ['-F', '@astryxdesign/core', 'build'], {
|
|
49
|
+
cwd: REPO_ROOT,
|
|
50
|
+
stdio: 'pipe',
|
|
51
|
+
timeout: BUILD_TIMEOUT_MS,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function lockIsStale() {
|
|
56
|
+
try {
|
|
57
|
+
return Date.now() - fs.statSync(LOCK_DIR).mtimeMs > STALE_LOCK_MS;
|
|
58
|
+
} catch {
|
|
59
|
+
// Vanished between the exists check and stat — treat as released.
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Try to acquire the lock. Returns true if this worker now holds it. */
|
|
65
|
+
function tryAcquire() {
|
|
66
|
+
try {
|
|
67
|
+
fs.mkdirSync(LOCK_DIR);
|
|
68
|
+
return true;
|
|
69
|
+
} catch (err) {
|
|
70
|
+
if (err.code !== 'EEXIST') {
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
73
|
+
if (lockIsStale()) {
|
|
74
|
+
fs.rmSync(LOCK_DIR, {recursive: true, force: true});
|
|
75
|
+
try {
|
|
76
|
+
fs.mkdirSync(LOCK_DIR);
|
|
77
|
+
return true;
|
|
78
|
+
} catch (retryErr) {
|
|
79
|
+
if (retryErr.code !== 'EEXIST') {
|
|
80
|
+
throw retryErr;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Ensure packages/core/dist is built exactly once, even when called
|
|
90
|
+
* concurrently from parallel Vitest workers. Safe to call from every
|
|
91
|
+
* build-theme suite's beforeAll.
|
|
92
|
+
*/
|
|
93
|
+
export function ensureCoreBuilt() {
|
|
94
|
+
if (fs.existsSync(CORE_THEME_ENTRY)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const deadline = Date.now() + STALE_LOCK_MS;
|
|
99
|
+
while (Date.now() < deadline) {
|
|
100
|
+
if (fs.existsSync(CORE_THEME_ENTRY)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (tryAcquire()) {
|
|
104
|
+
try {
|
|
105
|
+
if (!fs.existsSync(CORE_THEME_ENTRY)) {
|
|
106
|
+
buildCore();
|
|
107
|
+
}
|
|
108
|
+
} finally {
|
|
109
|
+
fs.rmSync(LOCK_DIR, {recursive: true, force: true});
|
|
110
|
+
}
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
// Another worker is building; wait for it to finish and release the lock.
|
|
114
|
+
sleepSync(POLL_MS);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Waited past the stale threshold without the artifact appearing — build it
|
|
118
|
+
// ourselves rather than let the suite fail on a missing entry.
|
|
119
|
+
buildCore();
|
|
120
|
+
}
|