@astryxdesign/cli 0.7.0 → 0.7.1-canary.021f141
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/build/_adapter.d.mts +1 -0
- package/api/build/_adapter.mjs +7 -0
- package/api/build/build.mjs +4 -1
- package/api/search/search.mjs +12 -0
- package/assets/docs/tree/migration-setup.doc.mjs +31 -6
- package/assets/docs/tree/responsive.doc.mjs +37 -0
- package/assets/docs/tree/tailwind.doc.mjs +12 -0
- package/assets/docs/tree/tokens-syntax.doc.mjs +20 -0
- package/assets/docs/tree/tokens.doc.mjs +1 -1
- package/assets/templates/blocks/components/CommandPalette/CommandPaletteAsyncSearch.tsx +6 -1
- package/assets/templates/themes/gothic/gothicTheme.ts +9 -0
- package/assets/templates/themes/stone/stoneTheme.ts +7 -0
- package/assets/templates/themes/y2k/y2kTheme.ts +8 -0
- package/clients/cli/commands/build-theme.mjs +32 -4
- package/clients/cli/commands/build-theme.watch.test.mjs +63 -2
- package/foundation/discovery/component-discovery.mjs +27 -26
- package/foundation/discovery/hook-discovery.mjs +13 -12
- package/foundation/discovery/theming-targets.test.mjs +9 -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/package.json +9 -9
package/api/build/_adapter.d.mts
CHANGED
|
@@ -66,6 +66,7 @@ export function isWeightsFile(file: any): file is import("./kit/weights.mjs").We
|
|
|
66
66
|
* @returns {string[]} Setup notes (empty when the template needs nothing).
|
|
67
67
|
*/
|
|
68
68
|
export function templateSetupNotes(template: PageTemplate, cwd: string): string[];
|
|
69
|
+
export { withListingCache } from "../../foundation/fs/listing-cache.mjs";
|
|
69
70
|
/**
|
|
70
71
|
* A page template the kit can recommend starting from.
|
|
71
72
|
*/
|
package/api/build/_adapter.mjs
CHANGED
|
@@ -23,6 +23,13 @@ import {componentKeywords} from '../search/search.mjs';
|
|
|
23
23
|
import {findCoreDir} from '../../foundation/fs/paths.mjs';
|
|
24
24
|
import {analyzeTemplateNeeds} from '../../foundation/discovery/template-needs.mjs';
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Runs one build with a single directory listing per path: the kit resolves
|
|
28
|
+
* every candidate's source and docs by walking the same tree, which does not
|
|
29
|
+
* change during the call.
|
|
30
|
+
*/
|
|
31
|
+
export {withListingCache} from '../../foundation/fs/listing-cache.mjs';
|
|
32
|
+
|
|
26
33
|
/**
|
|
27
34
|
* A page template the kit can recommend starting from.
|
|
28
35
|
* @typedef {object} PageTemplate
|
package/api/build/build.mjs
CHANGED
|
@@ -17,6 +17,7 @@ import {AstryxError} from '../error.mjs';
|
|
|
17
17
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
18
18
|
import {buildHelp} from './help/help.mjs';
|
|
19
19
|
import {buildKit} from './kit/kit.mjs';
|
|
20
|
+
import {withListingCache} from './_adapter.mjs';
|
|
20
21
|
|
|
21
22
|
// Barrel: surface the leaves alongside the dispatcher for the fractal shape.
|
|
22
23
|
export {buildHelp, buildKit};
|
|
@@ -40,5 +41,7 @@ export async function build(query, options = {}) {
|
|
|
40
41
|
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
41
42
|
);
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
+
// The kit resolves every candidate's source and docs by walking the same
|
|
45
|
+
// tree; read each directory once for this call.
|
|
46
|
+
return withListingCache(() => buildKit(query, options));
|
|
44
47
|
}
|
package/api/search/search.mjs
CHANGED
|
@@ -79,6 +79,7 @@
|
|
|
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
84
|
import {findCoreDir} from '../../foundation/fs/paths.mjs';
|
|
84
85
|
import {
|
|
@@ -1769,6 +1770,17 @@ function toResult(c, score, reason, matchedTerms, queryTerms) {
|
|
|
1769
1770
|
* @returns {Promise<import('./search.type.mjs').SearchResponse>}
|
|
1770
1771
|
*/
|
|
1771
1772
|
export async function search(query, options = {}) {
|
|
1773
|
+
// Every candidate resolves its source and docs by walking the same tree;
|
|
1774
|
+
// read each directory once for this call.
|
|
1775
|
+
return withListingCache(() => searchOnce(query, options));
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1778
|
+
/**
|
|
1779
|
+
* @param {string} query
|
|
1780
|
+
* @param {NonNullable<Parameters<typeof search>[1]>} options
|
|
1781
|
+
* @returns {ReturnType<typeof search>}
|
|
1782
|
+
*/
|
|
1783
|
+
async function searchOnce(query, options) {
|
|
1772
1784
|
const {cwd = process.cwd(), type, limit = 20} = options;
|
|
1773
1785
|
|
|
1774
1786
|
if (!query || !String(query).trim()) {
|
|
@@ -129,15 +129,31 @@ export function AppRoot({children}: {children: React.ReactNode}) {
|
|
|
129
129
|
},
|
|
130
130
|
{
|
|
131
131
|
type: 'prose',
|
|
132
|
-
text: '
|
|
132
|
+
text: 'A layer\'s rank is set by the first stylesheet on the page that names it, so the global CSS file (or a `layers.css` holding only the `@layer` line) must be the first import in the root layout or app entry. Import it before any module that imports Astryx or theme CSS, including the `astryx-themes` module generated by `astryx theme add` and a root component like the `AppRoot` above that imports `theme.css`. If a theme stylesheet loads first, Tailwind preflight overrides Astryx base styles and theme overrides lose.',
|
|
133
133
|
},
|
|
134
134
|
{
|
|
135
135
|
type: 'code',
|
|
136
|
-
lang: '
|
|
137
|
-
label: '
|
|
138
|
-
code:
|
|
136
|
+
lang: 'tsx',
|
|
137
|
+
label: 'Root layout or app entry',
|
|
138
|
+
code: `import './globals.css'; // first: declares the cascade-layer order
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
import {AppRoot} from './AppRoot';`,
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
type: 'prose',
|
|
144
|
+
text: 'On Tailwind v3 there is no preflight.css to import, so wrap the @tailwind base directive in a named layer instead. Keep utilities unlayered so existing app utility classes still win everywhere. Put the `@layer` order line in its own `layers.css` and import it first, before `globals.css`: Next.js (webpack or Turbopack) and other bundlers that hoist CSS imports move the imported files above an inline `@layer` line, so the order would arrive too late.',
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
type: 'code',
|
|
148
|
+
lang: 'css',
|
|
149
|
+
label: 'layers.css (imported first)',
|
|
150
|
+
code: `@layer reset, tw-preflight, astryx-base, astryx-theme;`,
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
type: 'code',
|
|
154
|
+
lang: 'css',
|
|
155
|
+
label: 'globals.css (Tailwind v3 coexistence)',
|
|
156
|
+
code: `@import "@astryxdesign/core/reset.css";
|
|
141
157
|
@import "@astryxdesign/core/astryx.css";
|
|
142
158
|
@import "@astryxdesign/theme-neutral/theme.css";
|
|
143
159
|
|
|
@@ -147,6 +163,15 @@ export function AppRoot({children}: {children: React.ReactNode}) {
|
|
|
147
163
|
@tailwind components;
|
|
148
164
|
@tailwind utilities; /* unlayered: legacy utility classes keep winning */`,
|
|
149
165
|
},
|
|
166
|
+
{
|
|
167
|
+
type: 'code',
|
|
168
|
+
lang: 'tsx',
|
|
169
|
+
label: 'Root layout or app entry (Tailwind v3)',
|
|
170
|
+
code: `import './layers.css'; // first: declares the cascade-layer order
|
|
171
|
+
import './globals.css';
|
|
172
|
+
|
|
173
|
+
import {AppRoot} from './AppRoot';`,
|
|
174
|
+
},
|
|
150
175
|
],
|
|
151
176
|
},
|
|
152
177
|
{
|
|
@@ -186,7 +211,7 @@ export function AppRoot({children}: {children: React.ReactNode}) {
|
|
|
186
211
|
type: 'list',
|
|
187
212
|
style: 'unordered',
|
|
188
213
|
items: [
|
|
189
|
-
'Declare the canonical @layer order once, before any @import. With webpack
|
|
214
|
+
'Declare the canonical @layer order once, before any @import. With Next.js (webpack or Turbopack) and other bundlers that hoist CSS imports, the order declaration must live in its own CSS file imported first, such as layers.css, because the bundler hoists @import content above the inline CSS that follows it.',
|
|
190
215
|
'Audit every pre-existing global or reset stylesheet and assign each one to a layer deliberately. Top-level imports without layer() stay unlayered and beat every layer; imports nested inside a layered file inherit that layer.',
|
|
191
216
|
'Remove or demote the app legacy reset. The design system ships its own :where() reset in the lowest layer, so any app reset belongs in that same reset layer and never in a layer above astryx-base.',
|
|
192
217
|
'Layer Tailwind preflight. On Tailwind v4, import preflight.css with layer(base). On Tailwind v3, wrap the @tailwind base directive in a named layer (see the snippet in Theme and CSS Setup). Unlayered preflight overrides theme CSS silently.',
|
|
@@ -21,6 +21,9 @@ export const docs = {
|
|
|
21
21
|
'Dialog',
|
|
22
22
|
'BottomSheet',
|
|
23
23
|
'contract',
|
|
24
|
+
'Grid',
|
|
25
|
+
'columns',
|
|
26
|
+
'minWidth',
|
|
24
27
|
],
|
|
25
28
|
|
|
26
29
|
sections: [
|
|
@@ -94,5 +97,39 @@ const isNarrow = useMediaQuery('(max-width: 1024px)');
|
|
|
94
97
|
},
|
|
95
98
|
],
|
|
96
99
|
},
|
|
100
|
+
{
|
|
101
|
+
id: 'columns-that-reflow',
|
|
102
|
+
title: 'Columns that reflow',
|
|
103
|
+
content: [
|
|
104
|
+
{
|
|
105
|
+
type: 'prose',
|
|
106
|
+
text: 'For columns that reflow on small screens, use `Grid columns={{minWidth, max}}`. A numeric `columns` is exactly N columns at every width and never reflows: `columns={4}` on a 390px phone renders four tracks under 100px wide, and the row overflows the page as soon as their content cannot shrink to fit. `{minWidth: 240, max: 4}` renders at most four columns, each at least 240px, and drops to one full-width column when the container is narrow; `max` is what lets that last column shrink to the container, and `gap` counts toward the room the columns need.',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: 'code',
|
|
110
|
+
lang: 'tsx',
|
|
111
|
+
label: 'Reflowing stat row versus a fixed week row',
|
|
112
|
+
code: `// Reflows: 4 columns on desktop, 3 in a 768px-wide grid, 1 on a phone.
|
|
113
|
+
<Grid columns={{minWidth: 240, max: 4}} gap={3}>
|
|
114
|
+
{stats.map(stat => <StatCard key={stat.id} {...stat} />)}
|
|
115
|
+
</Grid>
|
|
116
|
+
|
|
117
|
+
// Fixed: exactly 7 columns at every width (a number never reflows).
|
|
118
|
+
<Grid columns={7} gap={1}>
|
|
119
|
+
{days.map(day => <DayCell key={day} day={day} />)}
|
|
120
|
+
</Grid>`,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
type: 'list',
|
|
124
|
+
style: 'unordered',
|
|
125
|
+
items: [
|
|
126
|
+
'`{minWidth}` alone: as many columns as fit at the floor, no cap; a container narrower than `minWidth` overflows, so add `max` for anything that reaches a phone',
|
|
127
|
+
"`{minWidth, repeat: 'fit'}`: empty tracks collapse so present items stretch",
|
|
128
|
+
"A numeric `GridSpan` wider than the grid's current columns adds implicit columns to the whole grid; items placed before and after the span flow into them, and `columns='full'` then covers only the explicit columns. In a reflowing grid keep spans within the smallest count it can reach, or use `'full'`, which adds none",
|
|
129
|
+
'Styling that changes the room columns have to fit changes the count a reflowing shape reaches: a `columnGap` or `gap` step, inline padding on the grid, or `grid-auto-flow: column` through `xstyle`, which places items into extra implicit columns. A `className` rule replaces the computed track list only when it wins the cascade against the generated styles; prefer `xstyle` for overrides',
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
},
|
|
97
134
|
],
|
|
98
135
|
};
|
|
@@ -47,6 +47,18 @@ export const docs = {
|
|
|
47
47
|
type: 'prose',
|
|
48
48
|
text: 'Pre-declare every layer before any imports. This keeps reset lowest, Tailwind preflight above reset, component/theme styles in the middle, and Tailwind utilities last so utility classes on `className` can intentionally override component defaults.',
|
|
49
49
|
},
|
|
50
|
+
{
|
|
51
|
+
type: 'prose',
|
|
52
|
+
text: 'A layer\'s rank is set by the first stylesheet on the page that names it, so this order only holds when `globals.css` loads first. Make it the first import in the root layout or app entry, before any module that imports Astryx or theme CSS. That includes the `astryx-themes` module generated by `astryx theme add` and any root component that imports a theme\'s `theme.css`. If a theme stylesheet loads first, Tailwind preflight overrides Astryx base styles and theme overrides lose. If `globals.css` cannot come first, move the `@layer` line into its own `layers.css` and import that first instead.',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
type: 'code',
|
|
56
|
+
lang: 'tsx',
|
|
57
|
+
label: 'Root layout or app entry',
|
|
58
|
+
code: `import './globals.css'; // first: declares the cascade-layer order
|
|
59
|
+
|
|
60
|
+
import {themes, defaultThemeSlug} from './astryx-themes';`,
|
|
61
|
+
},
|
|
50
62
|
{
|
|
51
63
|
type: 'code',
|
|
52
64
|
lang: 'tsx',
|
|
@@ -88,6 +88,26 @@ export const docs = {
|
|
|
88
88
|
[
|
|
89
89
|
"--color-syntax-background",
|
|
90
90
|
"var(--color-background-muted)"
|
|
91
|
+
],
|
|
92
|
+
[
|
|
93
|
+
"--color-syntax-added",
|
|
94
|
+
"color-mix(in srgb, var(--color-success-muted) 25%, transparent)"
|
|
95
|
+
],
|
|
96
|
+
[
|
|
97
|
+
"--color-syntax-removed",
|
|
98
|
+
"color-mix(in srgb, var(--color-error-muted) 25%, transparent)"
|
|
99
|
+
],
|
|
100
|
+
[
|
|
101
|
+
"--color-syntax-diff-header",
|
|
102
|
+
"var(--color-background-muted)"
|
|
103
|
+
],
|
|
104
|
+
[
|
|
105
|
+
"--color-syntax-added-marker",
|
|
106
|
+
"var(--color-text-green)"
|
|
107
|
+
],
|
|
108
|
+
[
|
|
109
|
+
"--color-syntax-removed-marker",
|
|
110
|
+
"var(--color-text-red)"
|
|
91
111
|
]
|
|
92
112
|
]
|
|
93
113
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// AUTO-GENERATED — do not edit manually.
|
|
4
4
|
// Run: node scripts/generate-token-docs.mjs
|
|
5
|
-
// Total:
|
|
5
|
+
// Total: 263 tokens across 15 categories.
|
|
6
6
|
|
|
7
7
|
/** @type {import('@astryxdesign/cli/authoring').NamespaceDoc} */
|
|
8
8
|
export const docs = {
|
|
@@ -39,7 +39,12 @@ export default function CommandPaletteAsyncSearch() {
|
|
|
39
39
|
isInline
|
|
40
40
|
onOpenChange={() => {}}
|
|
41
41
|
searchSource={source}
|
|
42
|
-
input={
|
|
42
|
+
input={
|
|
43
|
+
<CommandPaletteInput
|
|
44
|
+
label="Search files"
|
|
45
|
+
placeholder="Search files..."
|
|
46
|
+
/>
|
|
47
|
+
}
|
|
43
48
|
emptyBootstrapText="Type a filename to search"
|
|
44
49
|
emptySearchText="No files found"
|
|
45
50
|
/>
|
|
@@ -40,6 +40,15 @@ const gothicSyntax = defineSyntaxTheme({
|
|
|
40
40
|
property: '#7cc5b3', // Verdigris
|
|
41
41
|
punctuation: '#7a8290', // Mid neutral
|
|
42
42
|
background: '#101314',
|
|
43
|
+
// Diff rows on the near-black background: any lighter wash lowers every
|
|
44
|
+
// light token's contrast, so the rows take opaque hues at the
|
|
45
|
+
// background's own luminance — a deep green and a deep red that read as
|
|
46
|
+
// colour, not brightness — and every token keeps the contrast it has on
|
|
47
|
+
// the plain background. Markers: forest moss and blood crimson.
|
|
48
|
+
added: '#081408',
|
|
49
|
+
removed: '#1e0a0a',
|
|
50
|
+
'added-marker': '#a3c987',
|
|
51
|
+
'removed-marker': '#d97580',
|
|
43
52
|
},
|
|
44
53
|
});
|
|
45
54
|
|
|
@@ -56,6 +56,13 @@ const stoneSyntax = defineSyntaxTheme({
|
|
|
56
56
|
property: ['#4e6357', '#94b2a0'], // Teal T40 / T70
|
|
57
57
|
punctuation: ['#5e5e5e', '#ababb0'], // Stone Neutral T40 / T70
|
|
58
58
|
background: ['#f3f3f5', '#171719'],
|
|
59
|
+
// Diff rows: the muted green/red at 25% in light and 20% in dark keep
|
|
60
|
+
// every token at or above 4.5:1 on the tint; the markers are the tinted
|
|
61
|
+
// text tokens (8.1:1 light, 8.8:1 dark on their tints).
|
|
62
|
+
added: ['#d0e9ce40', '#b4cdb233'],
|
|
63
|
+
removed: ['#f9dcd740', '#dcc0bc33'],
|
|
64
|
+
'added-marker': ['#374c36', '#d0e9ce'],
|
|
65
|
+
'removed-marker': ['#58413e', '#f9dcd7'],
|
|
59
66
|
},
|
|
60
67
|
});
|
|
61
68
|
|
|
@@ -29,6 +29,14 @@ const y2kSyntax = defineSyntaxTheme({
|
|
|
29
29
|
property: ['#3c6755', '#87b5a1'],
|
|
30
30
|
punctuation: ['#5e5e5e', '#ababab'],
|
|
31
31
|
background: ['#FFF6ED', '#190f00'],
|
|
32
|
+
// Diff rows: the muted green/red at 25% in light and 20% in dark keep
|
|
33
|
+
// every token at or above 4.5:1 on the tint. Markers: the tinted text
|
|
34
|
+
// tokens in light (7.3:1 / 7.9:1); in dark those tokens are near-black,
|
|
35
|
+
// so the string and tag colours mark the rows (5.1:1 each).
|
|
36
|
+
added: ['#C5E17A40', '#C5E17A33'],
|
|
37
|
+
removed: ['#FFC5C340', '#FFC5C333'],
|
|
38
|
+
'added-marker': ['#3a5500', '#a5af8b'],
|
|
39
|
+
'removed-marker': ['#8b1d24', '#d19f9d'],
|
|
32
40
|
},
|
|
33
41
|
});
|
|
34
42
|
|
|
@@ -112,9 +112,11 @@ function resolveCliBin() {
|
|
|
112
112
|
* @param {{out?: string, iconsSpecifier?: string, detail?: string}} options -
|
|
113
113
|
* Parsed command options that affect generated output, plus the detail
|
|
114
114
|
* level the user chose.
|
|
115
|
+
* @param {(child: import('node:child_process').ChildProcess) => void} [onSpawn] -
|
|
116
|
+
* Receives the child, so a watcher that stops can stop it too.
|
|
115
117
|
* @returns {Promise<number>}
|
|
116
118
|
*/
|
|
117
|
-
function runThemeBuildOnceChild(file, options) {
|
|
119
|
+
function runThemeBuildOnceChild(file, options, onSpawn) {
|
|
118
120
|
const cliBin = resolveCliBin();
|
|
119
121
|
// A detail level the user chose applies to every rebuild.
|
|
120
122
|
const args = options.detail
|
|
@@ -128,6 +130,7 @@ function runThemeBuildOnceChild(file, options) {
|
|
|
128
130
|
stdio: 'inherit',
|
|
129
131
|
env: process.env,
|
|
130
132
|
});
|
|
133
|
+
onSpawn?.(child);
|
|
131
134
|
child.on('close', code => resolve(code ?? 0));
|
|
132
135
|
child.on('error', () => resolve(1));
|
|
133
136
|
});
|
|
@@ -139,7 +142,9 @@ function runThemeBuildOnceChild(file, options) {
|
|
|
139
142
|
* Rebuilds are serialized: one at a time, in the order the changes arrived, so
|
|
140
143
|
* the log stays readable. Each rebuild runs in a child process so a build error
|
|
141
144
|
* (which the single-build path reports via a hard exit) is contained and the
|
|
142
|
-
* watcher keeps running.
|
|
145
|
+
* watcher keeps running. Stopping ends the watch at once: queued changes are
|
|
146
|
+
* dropped, the signal reaches a rebuild in progress, as Ctrl-C in a terminal
|
|
147
|
+
* reaches the whole process group, and "Stopped watching." is the last line.
|
|
143
148
|
*
|
|
144
149
|
* @param {Array<{file: string, filePath: string}>} entries - The theme file
|
|
145
150
|
* arguments as the user passed them, with their resolved absolute paths.
|
|
@@ -159,6 +164,11 @@ async function runThemeBuildWatch(entries, options) {
|
|
|
159
164
|
}
|
|
160
165
|
|
|
161
166
|
let building = false;
|
|
167
|
+
let stopped = false;
|
|
168
|
+
/** @type {import('node:child_process').ChildProcess | null} */
|
|
169
|
+
let rebuildChild = null;
|
|
170
|
+
/** @type {Promise<void> | null} */
|
|
171
|
+
let rebuildDone = null;
|
|
162
172
|
/** @type {Set<{file: string, filePath: string}>} */
|
|
163
173
|
const queued = new Set();
|
|
164
174
|
/** @type {Map<string, ReturnType<typeof setTimeout>>} */
|
|
@@ -166,6 +176,7 @@ async function runThemeBuildWatch(entries, options) {
|
|
|
166
176
|
|
|
167
177
|
/** @param {{file: string, filePath: string}} entry */
|
|
168
178
|
const rebuild = async entry => {
|
|
179
|
+
if (stopped) return;
|
|
169
180
|
if (building) {
|
|
170
181
|
// Coalesce changes that land mid-build into a single follow-up run.
|
|
171
182
|
queued.add(entry);
|
|
@@ -173,8 +184,16 @@ async function runThemeBuildWatch(entries, options) {
|
|
|
173
184
|
}
|
|
174
185
|
building = true;
|
|
175
186
|
emit(text(`\nChange detected — rebuilding ${rel(entry.filePath)}...`));
|
|
176
|
-
|
|
187
|
+
const done = runThemeBuildOnceChild(entry.file, options, child => {
|
|
188
|
+
rebuildChild = child;
|
|
189
|
+
});
|
|
190
|
+
rebuildDone = done.then(() => {});
|
|
191
|
+
await done;
|
|
192
|
+
rebuildChild = null;
|
|
193
|
+
rebuildDone = null;
|
|
177
194
|
building = false;
|
|
195
|
+
// A stop during this build has already ended the watch.
|
|
196
|
+
if (stopped) return;
|
|
178
197
|
emit(text(watchingLine));
|
|
179
198
|
const next = queued.values().next();
|
|
180
199
|
if (!next.done) {
|
|
@@ -205,9 +224,18 @@ async function runThemeBuildWatch(entries, options) {
|
|
|
205
224
|
emit(text(watchingLine));
|
|
206
225
|
|
|
207
226
|
await new Promise((/** @type {(value?: void) => void} */ resolve) => {
|
|
208
|
-
|
|
227
|
+
/** @param {NodeJS.Signals} signal */
|
|
228
|
+
const stop = async signal => {
|
|
229
|
+
process.removeListener('SIGINT', stop);
|
|
230
|
+
process.removeListener('SIGTERM', stop);
|
|
231
|
+
stopped = true;
|
|
232
|
+
queued.clear();
|
|
209
233
|
for (const d of debounces.values()) clearTimeout(d);
|
|
210
234
|
for (const w of watchers) w.close();
|
|
235
|
+
// A rebuild in progress would otherwise keep the process alive after
|
|
236
|
+
// "Stopped watching.". In a terminal, Ctrl-C already reached it.
|
|
237
|
+
rebuildChild?.kill(signal);
|
|
238
|
+
await rebuildDone;
|
|
211
239
|
emit(text('\nStopped watching.'));
|
|
212
240
|
resolve();
|
|
213
241
|
};
|
|
@@ -124,7 +124,8 @@ describe('theme build --watch', () => {
|
|
|
124
124
|
const rebuilt = await waitFor(
|
|
125
125
|
() => {
|
|
126
126
|
try {
|
|
127
|
-
if (fs.readFileSync(cssFile, 'utf-8').includes('#010203'))
|
|
127
|
+
if (fs.readFileSync(cssFile, 'utf-8').includes('#010203'))
|
|
128
|
+
return true;
|
|
128
129
|
} catch {
|
|
129
130
|
// CSS mid-write; fall through to re-touch.
|
|
130
131
|
}
|
|
@@ -157,6 +158,63 @@ describe('theme build --watch', () => {
|
|
|
157
158
|
expect(stdout).toMatch(/Stopped watching/);
|
|
158
159
|
}, 30_000);
|
|
159
160
|
|
|
161
|
+
it('stops at once when interrupted mid-rebuild, and drops a queued change', async () => {
|
|
162
|
+
const themeFile = path.join(tmpDir, 'ws.mjs');
|
|
163
|
+
fs.writeFileSync(
|
|
164
|
+
themeFile,
|
|
165
|
+
`export default { name: 'ws', tokens: { '--color-bg': '#ffffff' } };\n`,
|
|
166
|
+
);
|
|
167
|
+
// Top-level await holds every rebuild of this version in progress for 20 s,
|
|
168
|
+
// far longer than a stop may take.
|
|
169
|
+
const slow =
|
|
170
|
+
`await new Promise(resolve => setTimeout(resolve, 20000));\n` +
|
|
171
|
+
`export default { name: 'ws', tokens: { '--color-bg': '#010203' } };\n`;
|
|
172
|
+
|
|
173
|
+
const child = spawn(
|
|
174
|
+
process.execPath,
|
|
175
|
+
[CLI_BIN, 'theme', 'build', 'ws.mjs', '--watch'],
|
|
176
|
+
{cwd: tmpDir, env: {...process.env, FORCE_COLOR: '0'}},
|
|
177
|
+
);
|
|
178
|
+
let stdout = '';
|
|
179
|
+
child.stdout.on('data', d => (stdout += d.toString()));
|
|
180
|
+
child.stderr.on('data', d => (stdout += d.toString()));
|
|
181
|
+
const exited = new Promise(resolve =>
|
|
182
|
+
child.once('exit', () => resolve(Date.now())),
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
let stoppedAt;
|
|
186
|
+
try {
|
|
187
|
+
expect(await waitFor(() => /Watching/i.test(stdout))).toBe(true);
|
|
188
|
+
// Start the slow rebuild, re-touching in case a watch event is dropped.
|
|
189
|
+
const started = await waitFor(
|
|
190
|
+
() => {
|
|
191
|
+
if (/rebuilding ws\.mjs/.test(stdout)) return true;
|
|
192
|
+
fs.writeFileSync(themeFile, slow);
|
|
193
|
+
return false;
|
|
194
|
+
},
|
|
195
|
+
{timeout: 20000, interval: 200},
|
|
196
|
+
);
|
|
197
|
+
expect(started).toBe(true);
|
|
198
|
+
// Queue a change behind the rebuild in progress (debounce is 100 ms).
|
|
199
|
+
fs.writeFileSync(themeFile, `${slow}// queued\n`);
|
|
200
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
201
|
+
} finally {
|
|
202
|
+
stoppedAt = Date.now();
|
|
203
|
+
child.kill('SIGINT');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const exitedAt = await Promise.race([
|
|
207
|
+
exited,
|
|
208
|
+
new Promise(resolve => setTimeout(() => resolve(null), 15000)),
|
|
209
|
+
]);
|
|
210
|
+
if (exitedAt === null) child.kill('SIGKILL');
|
|
211
|
+
// Finishing the interrupted rebuild, or starting the queued one, takes 20 s.
|
|
212
|
+
expect(exitedAt).not.toBeNull();
|
|
213
|
+
expect(exitedAt - stoppedAt).toBeLessThan(10000);
|
|
214
|
+
expect(stdout.match(/rebuilding/g)).toHaveLength(1);
|
|
215
|
+
expect(stdout.trimEnd().endsWith('Stopped watching.')).toBe(true);
|
|
216
|
+
}, 60_000);
|
|
217
|
+
|
|
160
218
|
it.each([
|
|
161
219
|
[[], false],
|
|
162
220
|
[['--detail', 'full'], true],
|
|
@@ -219,7 +277,10 @@ describe('theme build --watch', () => {
|
|
|
219
277
|
);
|
|
220
278
|
expect(built).toBe(true);
|
|
221
279
|
await waitFor(() => /Watching w1\.mjs, w2\.mjs/.test(stdout));
|
|
222
|
-
const firstCssBefore = fs.readFileSync(
|
|
280
|
+
const firstCssBefore = fs.readFileSync(
|
|
281
|
+
path.join(tmpDir, 'w1.css'),
|
|
282
|
+
'utf-8',
|
|
283
|
+
);
|
|
223
284
|
|
|
224
285
|
const changed = `export default { name: 'w2', tokens: { '--color-bg': '#010203' } };\n`;
|
|
225
286
|
fs.writeFileSync(second, changed);
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import * as fs from 'node:fs';
|
|
8
8
|
import * as path from 'node:path';
|
|
9
|
+
import {listDir, listDirEntries, pathExists} from '../fs/listing-cache.mjs';
|
|
9
10
|
import {existsCaseExact} from '../fs/paths.mjs';
|
|
10
11
|
import {CORE_PROVIDER_ID} from '../identity/providers.mjs';
|
|
11
12
|
import {loadComponentDoc} from './component-loader.mjs';
|
|
@@ -52,8 +53,8 @@ function isComponentSourceFile(fileName, dirPath) {
|
|
|
52
53
|
if (BARE_COMPONENT_FILE_RE.test(fileName)) {
|
|
53
54
|
const base = fileName.replace(/\.tsx$/, '');
|
|
54
55
|
return (
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
pathExists(path.join(dirPath, `${base}.doc.mjs`)) ||
|
|
57
|
+
pathExists(path.join(dirPath, `XDS${base}.doc.mjs`))
|
|
57
58
|
);
|
|
58
59
|
}
|
|
59
60
|
return false;
|
|
@@ -132,8 +133,8 @@ export function discoverComponents(coreDir) {
|
|
|
132
133
|
function collectXDSFiles(dirPath) {
|
|
133
134
|
/** @type {string[]} */
|
|
134
135
|
const results = [];
|
|
135
|
-
if (!
|
|
136
|
-
const entries =
|
|
136
|
+
if (!pathExists(dirPath)) return results;
|
|
137
|
+
const entries = listDirEntries(dirPath);
|
|
137
138
|
for (const entry of entries) {
|
|
138
139
|
if (entry.isDirectory()) {
|
|
139
140
|
results.push(...collectXDSFiles(path.join(dirPath, entry.name)));
|
|
@@ -144,7 +145,7 @@ export function discoverComponents(coreDir) {
|
|
|
144
145
|
return results;
|
|
145
146
|
}
|
|
146
147
|
|
|
147
|
-
const topEntries =
|
|
148
|
+
const topEntries = listDirEntries(srcDir);
|
|
148
149
|
for (const entry of topEntries) {
|
|
149
150
|
if (!entry.isDirectory() || SKIP_DIRS.has(entry.name)) continue;
|
|
150
151
|
|
|
@@ -154,10 +155,10 @@ export function discoverComponents(coreDir) {
|
|
|
154
155
|
// Read the group from the directory's .doc.mjs file (if it exists)
|
|
155
156
|
// Check both {Name}.doc.mjs and Astryx{Name}.doc.mjs naming conventions
|
|
156
157
|
let docFile = path.join(dirPath, `${entry.name}.doc.mjs`);
|
|
157
|
-
if (!
|
|
158
|
+
if (!pathExists(docFile)) {
|
|
158
159
|
docFile = path.join(dirPath, `XDS${entry.name}.doc.mjs`);
|
|
159
160
|
}
|
|
160
|
-
const {group, hiddenComponents, hidden} =
|
|
161
|
+
const {group, hiddenComponents, hidden} = pathExists(docFile)
|
|
161
162
|
? readDocMeta(docFile)
|
|
162
163
|
: {group: null, hiddenComponents: new Set(), hidden: false};
|
|
163
164
|
|
|
@@ -171,10 +172,10 @@ export function discoverComponents(coreDir) {
|
|
|
171
172
|
// Check for a per-component doc file that overrides the directory group
|
|
172
173
|
let compGroup = group;
|
|
173
174
|
let compDoc = path.join(dirPath, `${componentName}.doc.mjs`);
|
|
174
|
-
if (!
|
|
175
|
+
if (!pathExists(compDoc)) {
|
|
175
176
|
compDoc = path.join(dirPath, `XDS${componentName}.doc.mjs`);
|
|
176
177
|
}
|
|
177
|
-
const hasComponentDoc =
|
|
178
|
+
const hasComponentDoc = pathExists(compDoc);
|
|
178
179
|
if (hasComponentDoc) {
|
|
179
180
|
const compMeta = readDocMeta(compDoc);
|
|
180
181
|
if (compMeta.group) compGroup = compMeta.group;
|
|
@@ -183,7 +184,7 @@ export function discoverComponents(coreDir) {
|
|
|
183
184
|
// Skip components without any .doc.mjs file (directory-level or
|
|
184
185
|
// component-level). They can't be documented, so surfacing them in
|
|
185
186
|
// the component list leads to broken docs-site links.
|
|
186
|
-
if (!
|
|
187
|
+
if (!pathExists(docFile) && !hasComponentDoc) continue;
|
|
187
188
|
|
|
188
189
|
if (!componentGroups.has(componentName)) {
|
|
189
190
|
componentGroups.set(componentName, compGroup);
|
|
@@ -251,7 +252,7 @@ export function findComponentReadme(coreDir, name) {
|
|
|
251
252
|
if (existsCaseExact(directXds, srcDir)) return directXds;
|
|
252
253
|
|
|
253
254
|
// Nested match: src/*/{name}/{Name}.doc.mjs or src/*/{name}/Astryx{Name}.doc.mjs
|
|
254
|
-
const entries =
|
|
255
|
+
const entries = listDirEntries(srcDir);
|
|
255
256
|
for (const entry of entries) {
|
|
256
257
|
if (!entry.isDirectory()) continue;
|
|
257
258
|
const nested = path.join(srcDir, entry.name, name, exactDoc);
|
|
@@ -275,7 +276,7 @@ export function findComponentReadme(coreDir, name) {
|
|
|
275
276
|
if (sourcePath) {
|
|
276
277
|
let dir = path.dirname(sourcePath);
|
|
277
278
|
while (dir.startsWith(srcDir)) {
|
|
278
|
-
const dirEntries =
|
|
279
|
+
const dirEntries = listDir(dir);
|
|
279
280
|
for (const f of dirEntries) {
|
|
280
281
|
if (f.endsWith('.doc.mjs')) return path.join(dir, f);
|
|
281
282
|
}
|
|
@@ -318,8 +319,8 @@ export function findComponentSource(coreDir, name) {
|
|
|
318
319
|
* @returns {string | null}
|
|
319
320
|
*/
|
|
320
321
|
function searchDir(dirPath) {
|
|
321
|
-
if (!
|
|
322
|
-
const entries =
|
|
322
|
+
if (!pathExists(dirPath)) return null;
|
|
323
|
+
const entries = listDirEntries(dirPath);
|
|
323
324
|
|
|
324
325
|
// Check for an exact match (prefixed or bare) first
|
|
325
326
|
for (const candidate of candidateFiles) {
|
|
@@ -345,7 +346,7 @@ export function findComponentSource(coreDir, name) {
|
|
|
345
346
|
}
|
|
346
347
|
|
|
347
348
|
// Search nested (component might be under a parent dir)
|
|
348
|
-
const entries =
|
|
349
|
+
const entries = listDirEntries(srcDir);
|
|
349
350
|
for (const entry of entries) {
|
|
350
351
|
if (!entry.isDirectory()) continue;
|
|
351
352
|
const nestedDir = path.join(srcDir, entry.name, name);
|
|
@@ -369,7 +370,7 @@ export function findComponentSource(coreDir, name) {
|
|
|
369
370
|
export function resolveImportPath(coreDir, componentName) {
|
|
370
371
|
const srcDir = path.join(coreDir, 'src');
|
|
371
372
|
const pkgPath = path.join(coreDir, 'package.json');
|
|
372
|
-
const pkg =
|
|
373
|
+
const pkg = pathExists(pkgPath)
|
|
373
374
|
? JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
|
|
374
375
|
: null;
|
|
375
376
|
|
|
@@ -522,14 +523,14 @@ function readPackageExports(packageDir) {
|
|
|
522
523
|
* @returns {Record<string, string[]>}
|
|
523
524
|
*/
|
|
524
525
|
export function discoverExternalComponentsGrouped(docsDir) {
|
|
525
|
-
if (!
|
|
526
|
+
if (!pathExists(docsDir)) return {};
|
|
526
527
|
|
|
527
528
|
/** @type {Map<string, string|null>} componentName → group */
|
|
528
529
|
const componentGroups = new Map();
|
|
529
530
|
|
|
530
531
|
/** @param {string} dirPath */
|
|
531
532
|
function scanDir(dirPath) {
|
|
532
|
-
const entries =
|
|
533
|
+
const entries = listDirEntries(dirPath);
|
|
533
534
|
for (const entry of entries) {
|
|
534
535
|
if (entry.name === 'node_modules' || entry.name === '__tests__') continue;
|
|
535
536
|
const fullPath = path.join(dirPath, entry.name);
|
|
@@ -593,7 +594,7 @@ export function discoverExternalComponentsGrouped(docsDir) {
|
|
|
593
594
|
* @returns {string | null}
|
|
594
595
|
*/
|
|
595
596
|
export function findExternalComponentDoc(docsDir, name) {
|
|
596
|
-
if (!
|
|
597
|
+
if (!pathExists(docsDir)) return null;
|
|
597
598
|
const target = `${name}.doc.mjs`;
|
|
598
599
|
|
|
599
600
|
/**
|
|
@@ -601,7 +602,7 @@ export function findExternalComponentDoc(docsDir, name) {
|
|
|
601
602
|
* @returns {string | null}
|
|
602
603
|
*/
|
|
603
604
|
function scanDir(dirPath) {
|
|
604
|
-
const entries =
|
|
605
|
+
const entries = listDirEntries(dirPath);
|
|
605
606
|
for (const entry of entries) {
|
|
606
607
|
if (entry.name === 'node_modules' || entry.name === '__tests__') continue;
|
|
607
608
|
const fullPath = path.join(dirPath, entry.name);
|
|
@@ -642,7 +643,7 @@ function integrationSourceForDoc(docPath) {
|
|
|
642
643
|
const dir = path.dirname(docPath);
|
|
643
644
|
const base = path.basename(docPath).replace(/\.doc\.(ts|mjs|js)$/, '');
|
|
644
645
|
const candidate = path.join(dir, `${base}.tsx`);
|
|
645
|
-
return
|
|
646
|
+
return pathExists(candidate) ? candidate : null;
|
|
646
647
|
}
|
|
647
648
|
|
|
648
649
|
/**
|
|
@@ -656,14 +657,14 @@ function integrationSourceForDoc(docPath) {
|
|
|
656
657
|
*/
|
|
657
658
|
export function discoverIntegrationComponents(integration) {
|
|
658
659
|
const componentsDir = integration?.components;
|
|
659
|
-
if (!componentsDir || !
|
|
660
|
+
if (!componentsDir || !pathExists(componentsDir)) return [];
|
|
660
661
|
|
|
661
662
|
/** @type {Map<string, {name: string, package: string, docPath: string, sourcePath: string|null, issuesUrl: string|undefined, group: string|null}>} */
|
|
662
663
|
const byName = new Map();
|
|
663
664
|
|
|
664
665
|
/** @param {string} dirPath */
|
|
665
666
|
function scanDir(dirPath) {
|
|
666
|
-
const entries =
|
|
667
|
+
const entries = listDirEntries(dirPath);
|
|
667
668
|
for (const entry of entries) {
|
|
668
669
|
if (entry.name === 'node_modules' || entry.name === '__tests__') continue;
|
|
669
670
|
const fullPath = path.join(dirPath, entry.name);
|
|
@@ -757,18 +758,18 @@ export async function discoverValidIntegrationComponents(integration) {
|
|
|
757
758
|
*/
|
|
758
759
|
export function findIntegrationComponentDoc(integration, name) {
|
|
759
760
|
const componentsDir = integration?.components;
|
|
760
|
-
if (!componentsDir || !
|
|
761
|
+
if (!componentsDir || !pathExists(componentsDir)) return null;
|
|
761
762
|
|
|
762
763
|
/**
|
|
763
764
|
* @param {string} dirPath
|
|
764
765
|
* @returns {string | null}
|
|
765
766
|
*/
|
|
766
767
|
function scanDir(dirPath) {
|
|
767
|
-
const entries =
|
|
768
|
+
const entries = listDirEntries(dirPath);
|
|
768
769
|
// Exact same-stem match (precedence order) first in this dir.
|
|
769
770
|
for (const suffix of INTEGRATION_DOC_SUFFIXES) {
|
|
770
771
|
const candidate = path.join(dirPath, `${name}${suffix}`);
|
|
771
|
-
if (
|
|
772
|
+
if (pathExists(candidate)) return candidate;
|
|
772
773
|
}
|
|
773
774
|
for (const entry of entries) {
|
|
774
775
|
if (entry.name === 'node_modules' || entry.name === '__tests__') continue;
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import * as fs from 'node:fs';
|
|
8
8
|
import * as path from 'node:path';
|
|
9
|
+
import {listDir, listDirEntries, pathExists} from '../fs/listing-cache.mjs';
|
|
9
10
|
import {existsCaseExact} from '../fs/paths.mjs';
|
|
10
11
|
import {levenshteinDistance} from '../text/string-utils.mjs';
|
|
11
12
|
|
|
@@ -57,8 +58,8 @@ export function discoverHooks(coreDir) {
|
|
|
57
58
|
const hookCategories = new Map();
|
|
58
59
|
|
|
59
60
|
// 1. Scan src/hooks/ for *.doc.mjs files
|
|
60
|
-
if (
|
|
61
|
-
const entries =
|
|
61
|
+
if (pathExists(hooksDir)) {
|
|
62
|
+
const entries = listDirEntries(hooksDir);
|
|
62
63
|
for (const entry of entries) {
|
|
63
64
|
if (!entry.isFile()) continue;
|
|
64
65
|
if (!entry.name.endsWith('.doc.mjs')) continue;
|
|
@@ -70,8 +71,8 @@ export function discoverHooks(coreDir) {
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
// 2. Scan ALL component directories for files matching use*.doc.mjs
|
|
73
|
-
if (
|
|
74
|
-
const topEntries =
|
|
74
|
+
if (pathExists(srcDir)) {
|
|
75
|
+
const topEntries = listDirEntries(srcDir);
|
|
75
76
|
for (const entry of topEntries) {
|
|
76
77
|
if (!entry.isDirectory() || SKIP_DIRS.has(entry.name) || entry.name === 'hooks') continue;
|
|
77
78
|
const dirPath = path.join(srcDir, entry.name);
|
|
@@ -114,8 +115,8 @@ export function discoverHooks(coreDir) {
|
|
|
114
115
|
* @param {Map<string, string>} hookCategories
|
|
115
116
|
*/
|
|
116
117
|
function scanDirForHookDocs(dirPath, hookCategories) {
|
|
117
|
-
if (!
|
|
118
|
-
const entries =
|
|
118
|
+
if (!pathExists(dirPath)) return;
|
|
119
|
+
const entries = listDirEntries(dirPath);
|
|
119
120
|
for (const entry of entries) {
|
|
120
121
|
if (entry.isDirectory() && !SKIP_DIRS.has(entry.name)) {
|
|
121
122
|
scanDirForHookDocs(path.join(dirPath, entry.name), hookCategories);
|
|
@@ -162,8 +163,8 @@ export function findHookDoc(coreDir, name) {
|
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
// 2. Case-insensitive search in hooks directory
|
|
165
|
-
if (
|
|
166
|
-
const entries =
|
|
166
|
+
if (pathExists(hooksDir)) {
|
|
167
|
+
const entries = listDir(hooksDir);
|
|
167
168
|
for (const entry of entries) {
|
|
168
169
|
if (!entry.endsWith('.doc.mjs')) continue;
|
|
169
170
|
const hookName = hookNameFromFile(entry);
|
|
@@ -175,8 +176,8 @@ export function findHookDoc(coreDir, name) {
|
|
|
175
176
|
}
|
|
176
177
|
|
|
177
178
|
// 3. Check all component dirs for {name}.doc.mjs or use{Name}.doc.mjs
|
|
178
|
-
if (
|
|
179
|
-
const topEntries =
|
|
179
|
+
if (pathExists(srcDir)) {
|
|
180
|
+
const topEntries = listDirEntries(srcDir);
|
|
180
181
|
for (const entry of topEntries) {
|
|
181
182
|
if (!entry.isDirectory() || SKIP_DIRS.has(entry.name) || entry.name === 'hooks') continue;
|
|
182
183
|
const found = searchDirForHookDoc(path.join(srcDir, entry.name), uniqueCandidates);
|
|
@@ -213,8 +214,8 @@ export function findHookDoc(coreDir, name) {
|
|
|
213
214
|
* @returns {string | null}
|
|
214
215
|
*/
|
|
215
216
|
function searchDirForHookDoc(dirPath, candidates) {
|
|
216
|
-
if (!
|
|
217
|
-
const entries =
|
|
217
|
+
if (!pathExists(dirPath)) return null;
|
|
218
|
+
const entries = listDirEntries(dirPath);
|
|
218
219
|
for (const entry of entries) {
|
|
219
220
|
if (entry.isDirectory() && !SKIP_DIRS.has(entry.name)) {
|
|
220
221
|
const found = searchDirForHookDoc(path.join(dirPath, entry.name), candidates);
|
|
@@ -25,7 +25,15 @@ import {describe, it, expect} from 'vitest';
|
|
|
25
25
|
import * as fs from 'node:fs';
|
|
26
26
|
import * as path from 'node:path';
|
|
27
27
|
import {findCoreDir} from '../fs/paths.mjs';
|
|
28
|
-
|
|
28
|
+
const promotedThemeSurfaceTransform = new URL(
|
|
29
|
+
'../../assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs',
|
|
30
|
+
import.meta.url,
|
|
31
|
+
);
|
|
32
|
+
const {DEPRECATED_THEME_TARGETS} = await import(
|
|
33
|
+
fs.existsSync(promotedThemeSurfaceTransform)
|
|
34
|
+
? promotedThemeSurfaceTransform.href
|
|
35
|
+
: '../../assets/codemods/transforms/next/migrate-deprecated-theme-surface.mjs'
|
|
36
|
+
);
|
|
29
37
|
import {
|
|
30
38
|
discoverComponents,
|
|
31
39
|
findComponentReadme,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Run `fn` with a listing cache. A nested call shares the outer cache. Only
|
|
6
|
+
* wrap operations that do not change the files they list.
|
|
7
|
+
* @template T
|
|
8
|
+
* @param {() => T} fn
|
|
9
|
+
* @returns {T}
|
|
10
|
+
*/
|
|
11
|
+
export function withListingCache<T>(fn: () => T): T;
|
|
12
|
+
/**
|
|
13
|
+
* `fs.readdirSync(dir)`, read once per operation. Returns a fresh array, so a
|
|
14
|
+
* caller that sorts it cannot reorder another caller's listing.
|
|
15
|
+
* @param {string} dir
|
|
16
|
+
* @returns {string[]}
|
|
17
|
+
*/
|
|
18
|
+
export function listDir(dir: string): string[];
|
|
19
|
+
/**
|
|
20
|
+
* `fs.readdirSync(dir, {withFileTypes: true})`, read once per operation.
|
|
21
|
+
* @param {string} dir
|
|
22
|
+
* @returns {fs.Dirent[]}
|
|
23
|
+
*/
|
|
24
|
+
export function listDirEntries(dir: string): fs.Dirent[];
|
|
25
|
+
/**
|
|
26
|
+
* `fs.existsSync(target)`, probed once per operation.
|
|
27
|
+
* @param {string} target
|
|
28
|
+
* @returns {boolean}
|
|
29
|
+
*/
|
|
30
|
+
export function pathExists(target: string): boolean;
|
|
31
|
+
export type ListingCache = {
|
|
32
|
+
names: Map<string, string[]>;
|
|
33
|
+
entries: Map<string, fs.Dirent[]>;
|
|
34
|
+
exists: Map<string, boolean>;
|
|
35
|
+
};
|
|
36
|
+
import * as fs from 'node:fs';
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file One directory listing per path for the duration of one read-only
|
|
5
|
+
* operation.
|
|
6
|
+
*
|
|
7
|
+
* @input A read-only operation (`withListingCache(fn)`), and directory paths
|
|
8
|
+
* its discovery helpers list or probe.
|
|
9
|
+
* @output The same answers `fs.readdirSync` / `fs.existsSync` give, read from
|
|
10
|
+
* disk once per path while the operation runs.
|
|
11
|
+
* @position Used by the name resolvers in foundation/discovery and by
|
|
12
|
+
* `existsCaseExact`. A search or build resolves ~160 components and their
|
|
13
|
+
* hooks, and each resolution walks the same source tree again; inside one
|
|
14
|
+
* operation the tree does not change, so each directory is read once.
|
|
15
|
+
* Outside `withListingCache` every helper reads the disk directly, exactly
|
|
16
|
+
* as before, so long-lived callers never see a stale listing.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import {AsyncLocalStorage} from 'node:async_hooks';
|
|
20
|
+
import * as fs from 'node:fs';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {{
|
|
24
|
+
* names: Map<string, string[]>,
|
|
25
|
+
* entries: Map<string, fs.Dirent[]>,
|
|
26
|
+
* exists: Map<string, boolean>,
|
|
27
|
+
* }} ListingCache
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/** @type {AsyncLocalStorage<ListingCache>} */
|
|
31
|
+
const scope = new AsyncLocalStorage();
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Run `fn` with a listing cache. A nested call shares the outer cache. Only
|
|
35
|
+
* wrap operations that do not change the files they list.
|
|
36
|
+
* @template T
|
|
37
|
+
* @param {() => T} fn
|
|
38
|
+
* @returns {T}
|
|
39
|
+
*/
|
|
40
|
+
export function withListingCache(fn) {
|
|
41
|
+
if (scope.getStore()) return fn();
|
|
42
|
+
return scope.run(
|
|
43
|
+
{names: new Map(), entries: new Map(), exists: new Map()},
|
|
44
|
+
fn,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* `fs.readdirSync(dir)`, read once per operation. Returns a fresh array, so a
|
|
50
|
+
* caller that sorts it cannot reorder another caller's listing.
|
|
51
|
+
* @param {string} dir
|
|
52
|
+
* @returns {string[]}
|
|
53
|
+
*/
|
|
54
|
+
export function listDir(dir) {
|
|
55
|
+
const cache = scope.getStore();
|
|
56
|
+
if (!cache) return fs.readdirSync(dir);
|
|
57
|
+
let names = cache.names.get(dir);
|
|
58
|
+
if (!names) {
|
|
59
|
+
names = fs.readdirSync(dir);
|
|
60
|
+
cache.names.set(dir, names);
|
|
61
|
+
}
|
|
62
|
+
return names.slice();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* `fs.readdirSync(dir, {withFileTypes: true})`, read once per operation.
|
|
67
|
+
* @param {string} dir
|
|
68
|
+
* @returns {fs.Dirent[]}
|
|
69
|
+
*/
|
|
70
|
+
export function listDirEntries(dir) {
|
|
71
|
+
const cache = scope.getStore();
|
|
72
|
+
if (!cache) return fs.readdirSync(dir, {withFileTypes: true});
|
|
73
|
+
let entries = cache.entries.get(dir);
|
|
74
|
+
if (!entries) {
|
|
75
|
+
entries = fs.readdirSync(dir, {withFileTypes: true});
|
|
76
|
+
cache.entries.set(dir, entries);
|
|
77
|
+
}
|
|
78
|
+
return entries.slice();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* `fs.existsSync(target)`, probed once per operation.
|
|
83
|
+
* @param {string} target
|
|
84
|
+
* @returns {boolean}
|
|
85
|
+
*/
|
|
86
|
+
export function pathExists(target) {
|
|
87
|
+
const cache = scope.getStore();
|
|
88
|
+
if (!cache) return fs.existsSync(target);
|
|
89
|
+
let exists = cache.exists.get(target);
|
|
90
|
+
if (exists === undefined) {
|
|
91
|
+
exists = fs.existsSync(target);
|
|
92
|
+
cache.exists.set(target, exists);
|
|
93
|
+
}
|
|
94
|
+
return exists;
|
|
95
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import * as os from 'node:os';
|
|
6
|
+
import * as path from 'node:path';
|
|
7
|
+
import {
|
|
8
|
+
listDir,
|
|
9
|
+
listDirEntries,
|
|
10
|
+
pathExists,
|
|
11
|
+
withListingCache,
|
|
12
|
+
} from './listing-cache.mjs';
|
|
13
|
+
import {existsCaseExact} from './paths.mjs';
|
|
14
|
+
|
|
15
|
+
let dir;
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-listing-cache-'));
|
|
19
|
+
fs.writeFileSync(path.join(dir, 'b.txt'), '');
|
|
20
|
+
fs.writeFileSync(path.join(dir, 'a.txt'), '');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('listing cache', () => {
|
|
28
|
+
it('reads the disk directly outside an operation', () => {
|
|
29
|
+
expect(listDir(dir).sort()).toEqual(['a.txt', 'b.txt']);
|
|
30
|
+
fs.writeFileSync(path.join(dir, 'c.txt'), '');
|
|
31
|
+
expect(listDir(dir).sort()).toEqual(['a.txt', 'b.txt', 'c.txt']);
|
|
32
|
+
expect(pathExists(path.join(dir, 'c.txt'))).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('answers from one read for the rest of an operation', async () => {
|
|
36
|
+
await withListingCache(async () => {
|
|
37
|
+
expect(listDir(dir).sort()).toEqual(['a.txt', 'b.txt']);
|
|
38
|
+
expect(pathExists(path.join(dir, 'c.txt'))).toBe(false);
|
|
39
|
+
fs.writeFileSync(path.join(dir, 'c.txt'), '');
|
|
40
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
41
|
+
expect(listDir(dir).sort()).toEqual(['a.txt', 'b.txt']);
|
|
42
|
+
expect(pathExists(path.join(dir, 'c.txt'))).toBe(false);
|
|
43
|
+
expect(
|
|
44
|
+
listDirEntries(dir)
|
|
45
|
+
.map(entry => entry.name)
|
|
46
|
+
.sort(),
|
|
47
|
+
).toEqual(['a.txt', 'b.txt', 'c.txt']);
|
|
48
|
+
});
|
|
49
|
+
// The operation's snapshot does not outlive it.
|
|
50
|
+
expect(listDir(dir).sort()).toEqual(['a.txt', 'b.txt', 'c.txt']);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('shares one cache with nested operations', () => {
|
|
54
|
+
withListingCache(() => {
|
|
55
|
+
listDir(dir);
|
|
56
|
+
fs.writeFileSync(path.join(dir, 'c.txt'), '');
|
|
57
|
+
withListingCache(() => {
|
|
58
|
+
expect(listDir(dir).sort()).toEqual(['a.txt', 'b.txt']);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('hands every caller its own array', () => {
|
|
64
|
+
withListingCache(() => {
|
|
65
|
+
listDir(dir).reverse().push('mutated');
|
|
66
|
+
expect(listDir(dir)).not.toContain('mutated');
|
|
67
|
+
listDirEntries(dir).length = 0;
|
|
68
|
+
expect(listDirEntries(dir)).toHaveLength(2);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('does not remember a failed read', () => {
|
|
73
|
+
const missing = path.join(dir, 'later');
|
|
74
|
+
withListingCache(() => {
|
|
75
|
+
expect(() => listDir(missing)).toThrow();
|
|
76
|
+
fs.mkdirSync(missing);
|
|
77
|
+
expect(listDir(missing)).toEqual([]);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('keeps existsCaseExact exact-case inside an operation', () => {
|
|
82
|
+
fs.mkdirSync(path.join(dir, 'Button'));
|
|
83
|
+
withListingCache(() => {
|
|
84
|
+
expect(existsCaseExact(path.join(dir, 'Button'), dir)).toBe(true);
|
|
85
|
+
expect(existsCaseExact(path.join(dir, 'button'), dir)).toBe(false);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
package/foundation/fs/paths.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import * as fs from 'node:fs';
|
|
|
10
10
|
import {createRequire} from 'node:module';
|
|
11
11
|
import * as path from 'node:path';
|
|
12
12
|
import {fileURLToPath} from 'node:url';
|
|
13
|
+
import {listDir, pathExists} from './listing-cache.mjs';
|
|
13
14
|
|
|
14
15
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
16
|
|
|
@@ -231,7 +232,7 @@ export function listComponents(coreDir) {
|
|
|
231
232
|
* @returns {boolean}
|
|
232
233
|
*/
|
|
233
234
|
export function existsCaseExact(targetPath, rootDir) {
|
|
234
|
-
if (!
|
|
235
|
+
if (!pathExists(targetPath)) return false;
|
|
235
236
|
|
|
236
237
|
const rel = path.relative(rootDir, targetPath);
|
|
237
238
|
if (rel === '') return true;
|
|
@@ -241,7 +242,7 @@ export function existsCaseExact(targetPath, rootDir) {
|
|
|
241
242
|
for (const segment of rel.split(path.sep)) {
|
|
242
243
|
let entries;
|
|
243
244
|
try {
|
|
244
|
-
entries =
|
|
245
|
+
entries = listDir(dir);
|
|
245
246
|
} catch {
|
|
246
247
|
return false;
|
|
247
248
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1-canary.021f141",
|
|
4
4
|
"displayName": "CLI",
|
|
5
5
|
"description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
@@ -101,10 +101,10 @@
|
|
|
101
101
|
"zod": "^4.4.3"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
|
-
"@astryxdesign/charts": "
|
|
105
|
-
"@astryxdesign/core": "
|
|
106
|
-
"@astryxdesign/lab": "
|
|
107
|
-
"@astryxdesign/theme-neutral": "
|
|
104
|
+
"@astryxdesign/charts": "0.7.1-canary.021f141",
|
|
105
|
+
"@astryxdesign/core": "0.7.1-canary.021f141",
|
|
106
|
+
"@astryxdesign/lab": "0.7.1-canary.021f141",
|
|
107
|
+
"@astryxdesign/theme-neutral": "0.7.1-canary.021f141"
|
|
108
108
|
},
|
|
109
109
|
"peerDependenciesMeta": {
|
|
110
110
|
"@astryxdesign/charts": {
|
|
@@ -121,10 +121,10 @@
|
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
123
|
"devDependencies": {
|
|
124
|
-
"@astryxdesign/charts": "
|
|
125
|
-
"@astryxdesign/core": "
|
|
126
|
-
"@astryxdesign/lab": "
|
|
127
|
-
"@astryxdesign/theme-neutral": "
|
|
124
|
+
"@astryxdesign/charts": "0.7.1-canary.021f141",
|
|
125
|
+
"@astryxdesign/core": "0.7.1-canary.021f141",
|
|
126
|
+
"@astryxdesign/lab": "0.7.1-canary.021f141",
|
|
127
|
+
"@astryxdesign/theme-neutral": "0.7.1-canary.021f141",
|
|
128
128
|
"@heroicons/react": "^2.2.0",
|
|
129
129
|
"@stylexjs/stylex": "^0.19.0",
|
|
130
130
|
"@types/babel__core": "^7.20.5",
|