@astryxdesign/cli 0.7.10 → 0.7.11-canary.a888b3d
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/blocks/blocks.weights.json +1 -1
- package/api/build/build.doc.mjs +1 -1
- package/api/build/kit/signals.mjs +9 -3
- package/api/build/kit/start.d.mts +19 -0
- package/api/build/kit/start.mjs +49 -2
- package/api/build/kit/weights.d.mts +12 -0
- package/api/build/kit/weights.mjs +52 -16
- package/api/docs/_adapter.mjs +2 -1
- package/api/doctor/_adapter.d.mts +28 -1
- package/api/doctor/_adapter.mjs +39 -2
- package/api/doctor/doctor.doc.mjs +1 -1
- package/api/doctor/doctor.mjs +9 -2
- package/api/doctor/theme-checks.d.mts +44 -3
- package/api/doctor/theme-checks.mjs +273 -6
- package/api/hook/hook.mjs +13 -0
- package/api/integration/pack-check.d.mts +8 -6
- package/api/integration/pack-check.mjs +16 -6
- package/api/render/_adapter.mjs +47 -1
- package/api/render/render.doc.mjs +2 -1
- package/api/search/_gather-components.mjs +2 -1
- package/api/swizzle/copy/copy.mjs +5 -1
- package/api/theme/build/build.mjs +15 -4
- package/assets/docs/author-a-theme.doc.mjs +2 -0
- package/assets/docs/getting-started.doc.mjs +20 -0
- package/assets/docs/tree/building-blocks.doc.mjs +1 -0
- package/assets/docs/tree/global-integrations.doc.mjs +1 -0
- package/assets/docs/tree/help.doc.mjs +1 -1
- package/assets/docs/tree/quick-start.doc.mjs +1 -0
- package/assets/docs/tree/render-pages.doc.mjs +1 -1
- package/assets/docs/tree/ship.doc.mjs +1 -1
- package/assets/docs/tree/tokens-color.doc.mjs +2 -2
- package/clients/cli/commands/build.doc.mjs +3 -2
- package/foundation/discovery/authoring-self-docs.mjs +8 -3
- package/foundation/discovery/cli-self-docs.mjs +2 -1
- package/foundation/discovery/component-discovery.mjs +16 -0
- package/foundation/discovery/docs-discovery.mjs +6 -4
- package/foundation/discovery/icon-definition-discovery.mjs +3 -3
- package/foundation/discovery/module-exports.d.mts +30 -1
- package/foundation/discovery/module-exports.mjs +82 -4
- package/foundation/discovery/template-adapter.mjs +5 -7
- package/foundation/discovery/theme-discovery.mjs +8 -10
- package/foundation/doc-compiler/tree.mjs +2 -2
- package/foundation/fs/listing-cache.d.mts +3 -1
- package/foundation/fs/listing-cache.mjs +63 -11
- package/foundation/fs/paths.mjs +2 -1
- package/foundation/render/embedded-imports.d.mts +7 -0
- package/foundation/render/embedded-imports.mjs +1 -1
- package/foundation/render/page-worker.mjs +109 -4
- package/foundation/render/render-page.d.mts +16 -1
- package/foundation/render/render-page.mjs +25 -18
- package/foundation/render/served-packages.d.mts +33 -0
- package/foundation/render/served-packages.mjs +75 -0
- package/foundation/render/single-copy-hooks.d.mts +18 -0
- package/foundation/render/single-copy-hooks.mjs +44 -0
- package/foundation/text/string-utils.mjs +25 -25
- package/package.json +6 -6
|
@@ -9,7 +9,7 @@ export const docs = {
|
|
|
9
9
|
placement: {parent: 'namespace:authoring', slot: 'guides', order: 30},
|
|
10
10
|
title: 'Ship',
|
|
11
11
|
summary: 'Test, publish, and upgrade your package.',
|
|
12
|
-
keywords: ['ship', 'publish', 'release', 'upgrade'],
|
|
12
|
+
keywords: ['authoring', 'ship', 'publish', 'release', 'upgrade'],
|
|
13
13
|
slots: {
|
|
14
14
|
guides: {title: 'Ship', accepts: {kinds: ['generic']}},
|
|
15
15
|
},
|
|
@@ -45,7 +45,7 @@ export const docs = {
|
|
|
45
45
|
],
|
|
46
46
|
[
|
|
47
47
|
"--color-icon-<status>",
|
|
48
|
-
"Status icons on the page or a card. Defaults to the text colour.",
|
|
48
|
+
"Status icons and marks on the page or a card, such as a StatusDot. Defaults to the text colour.",
|
|
49
49
|
"—"
|
|
50
50
|
],
|
|
51
51
|
[
|
|
@@ -55,7 +55,7 @@ export const docs = {
|
|
|
55
55
|
],
|
|
56
56
|
[
|
|
57
57
|
"--color-<status>",
|
|
58
|
-
"Strong status fill, such as a Badge
|
|
58
|
+
"Strong status fill, such as a Badge.",
|
|
59
59
|
"--color-on-<status>"
|
|
60
60
|
],
|
|
61
61
|
[
|
|
@@ -26,8 +26,9 @@ export const doc = {
|
|
|
26
26
|
{
|
|
27
27
|
flag: '--type <domain>',
|
|
28
28
|
param: 'options.type',
|
|
29
|
-
choices: ['component', 'hook', 'template'],
|
|
30
|
-
description:
|
|
29
|
+
choices: ['component', 'hook', 'doc', 'template', 'theme'],
|
|
30
|
+
description:
|
|
31
|
+
'Filter the kit to one domain (component|hook|doc|template|theme); doc and theme give an empty kit',
|
|
31
32
|
},
|
|
32
33
|
{
|
|
33
34
|
flag: '--limit <n>',
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
* the self-doc tests fail.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import * as fs from 'node:fs';
|
|
19
18
|
import * as path from 'node:path';
|
|
20
19
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
20
|
+
import {listDirEntries} from '../fs/listing-cache.mjs';
|
|
21
21
|
import {readDocView} from '../doc-compiler/read.mjs';
|
|
22
22
|
import {
|
|
23
23
|
DOC_OUTPUT_BUDGET_BYTES,
|
|
@@ -75,7 +75,7 @@ export function discoverAuthoringSelfDocSources(root = AUTHORING_ROOT) {
|
|
|
75
75
|
const found = [];
|
|
76
76
|
/** @param {string} dir */
|
|
77
77
|
const walk = dir => {
|
|
78
|
-
for (const entry of
|
|
78
|
+
for (const entry of listDirEntries(dir)) {
|
|
79
79
|
if (entry.name === 'node_modules' || entry.name.startsWith('__'))
|
|
80
80
|
continue;
|
|
81
81
|
const full = path.join(dir, entry.name);
|
|
@@ -229,7 +229,12 @@ export function buildAuthoringReferenceDoc(docs) {
|
|
|
229
229
|
placement: {parent: 'namespace:authoring', slot: 'reference', order: 10},
|
|
230
230
|
title: 'Field reference',
|
|
231
231
|
category: 'guide',
|
|
232
|
-
keywords: [
|
|
232
|
+
keywords: [
|
|
233
|
+
'authoring',
|
|
234
|
+
'authoring reference',
|
|
235
|
+
'field reference',
|
|
236
|
+
'every field',
|
|
237
|
+
],
|
|
233
238
|
description:
|
|
234
239
|
'Every file an integration author writes, field by field: the integration manifest, astryx.config, codemods, identity, and each doc type. The guides that use them are the rest of {@link namespace:authoring}.',
|
|
235
240
|
sections: docs
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import * as fs from 'node:fs';
|
|
19
19
|
import * as path from 'node:path';
|
|
20
20
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
21
|
+
import {listDirEntries} from '../fs/listing-cache.mjs';
|
|
21
22
|
import {readDocView} from '../doc-compiler/read.mjs';
|
|
22
23
|
import {AUTHORING_SELF_DOCS, selfDocSection} from './authoring-self-docs.mjs';
|
|
23
24
|
import {
|
|
@@ -66,7 +67,7 @@ export function discoverCliSelfDocSources(root = CLI_ROOT) {
|
|
|
66
67
|
/** @param {string} dir */
|
|
67
68
|
const walk = dir => {
|
|
68
69
|
if (!fs.existsSync(dir)) return;
|
|
69
|
-
for (const entry of
|
|
70
|
+
for (const entry of listDirEntries(dir)) {
|
|
70
71
|
if (
|
|
71
72
|
entry.name === 'node_modules' ||
|
|
72
73
|
entry.name.startsWith('__') ||
|
|
@@ -381,6 +381,22 @@ export function familyMember(docs, name) {
|
|
|
381
381
|
* @returns {Record<string, string[]>}
|
|
382
382
|
*/
|
|
383
383
|
export function discoverComponents(coreDir) {
|
|
384
|
+
// The component matcher calls this for each name it resolves, so one
|
|
385
|
+
// operation reads the docs once. Each caller gets its own copy to change.
|
|
386
|
+
const found = oncePerListing(`components\0${coreDir}`, () =>
|
|
387
|
+
readComponentGroups(coreDir),
|
|
388
|
+
);
|
|
389
|
+
return Object.fromEntries(
|
|
390
|
+
Object.entries(found).map(([key, names]) => [key, [...names]]),
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* The component groups under `coreDir`, read from disk.
|
|
396
|
+
* @param {string} coreDir
|
|
397
|
+
* @returns {Record<string, string[]>}
|
|
398
|
+
*/
|
|
399
|
+
function readComponentGroups(coreDir) {
|
|
384
400
|
const srcDir = path.join(coreDir, 'src');
|
|
385
401
|
/** @type {Map<string, string|null>} componentName → group */
|
|
386
402
|
const componentGroups = new Map();
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
import * as fs from 'node:fs';
|
|
33
33
|
import * as path from 'node:path';
|
|
34
34
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
35
|
+
import {listDir, listDirEntries} from '../fs/listing-cache.mjs';
|
|
35
36
|
import {importDocModule} from '../doc-compiler/import.mjs';
|
|
36
37
|
import {CLI_PROVIDER_ID} from '../identity/providers.mjs';
|
|
37
38
|
import {parseReadableDoc} from '../doc-compiler/parse-readable.mjs';
|
|
@@ -135,7 +136,7 @@ export function discoverBuiltinTopics() {
|
|
|
135
136
|
/** @type {Record<string, string>} */
|
|
136
137
|
const topics = Object.create(null);
|
|
137
138
|
if (!fs.existsSync(BUILTIN_DOCS_DIR)) return topics;
|
|
138
|
-
for (const file of
|
|
139
|
+
for (const file of listDir(BUILTIN_DOCS_DIR)) {
|
|
139
140
|
const match = file.match(BUILTIN_TOPIC_FILE_RE);
|
|
140
141
|
if (match) topics[match[1]] = path.join(BUILTIN_DOCS_DIR, file);
|
|
141
142
|
}
|
|
@@ -152,7 +153,7 @@ export function builtinGuideFiles() {
|
|
|
152
153
|
const files = Object.values(discoverBuiltinTopics());
|
|
153
154
|
const tree = path.join(BUILTIN_DOCS_DIR, 'tree');
|
|
154
155
|
if (fs.existsSync(tree)) {
|
|
155
|
-
for (const file of
|
|
156
|
+
for (const file of listDir(tree).sort()) {
|
|
156
157
|
if (BUILTIN_TOPIC_FILE_RE.test(file)) files.push(path.join(tree, file));
|
|
157
158
|
}
|
|
158
159
|
}
|
|
@@ -524,7 +525,7 @@ export async function discoverIntegrationDocs(integration) {
|
|
|
524
525
|
const files = [];
|
|
525
526
|
/** @param {string} dirPath */
|
|
526
527
|
function scanDir(dirPath) {
|
|
527
|
-
for (const entry of
|
|
528
|
+
for (const entry of listDirEntries(dirPath)) {
|
|
528
529
|
if (entry.name === 'node_modules' || entry.name === '__tests__') continue;
|
|
529
530
|
const full = path.join(dirPath, entry.name);
|
|
530
531
|
if (entry.isDirectory()) {
|
|
@@ -737,7 +738,8 @@ export function mergeTopicReport(base, overlay) {
|
|
|
737
738
|
// It also keeps the place an earlier `after` gave the one it replaces,
|
|
738
739
|
// so sections placed after that key later still follow it.
|
|
739
740
|
if (replaced[PLACED_AFTER] != null) {
|
|
740
|
-
const placed =
|
|
741
|
+
const placed =
|
|
742
|
+
replacing === section ? withoutPosition({...section}) : replacing;
|
|
741
743
|
for (const symbol of Object.getOwnPropertySymbols(section)) {
|
|
742
744
|
if (!(symbol in placed)) {
|
|
743
745
|
Object.defineProperty(
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
* surface reads
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import * as fs from 'node:fs';
|
|
19
18
|
import * as path from 'node:path';
|
|
20
19
|
import {parseIconDefinition} from '../../authoring/doctypes/icon-definition/parse.mjs';
|
|
21
20
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
21
|
+
import {listDirEntries} from '../fs/listing-cache.mjs';
|
|
22
22
|
import {readStaticDescriptorValue} from './theme-discovery.mjs';
|
|
23
23
|
|
|
24
24
|
/** @typedef {import('../../authoring/doctypes/icon-definition/type').IconDefinitionDoc} IconDefinitionDoc */
|
|
@@ -53,10 +53,10 @@ export function readDefinitionsDir(dir, owner) {
|
|
|
53
53
|
const definitions = [];
|
|
54
54
|
/** @type {Array<{file: string, message: string}>} */
|
|
55
55
|
const errors = [];
|
|
56
|
-
/** @type {fs.Dirent[]} */
|
|
56
|
+
/** @type {import('node:fs').Dirent[]} */
|
|
57
57
|
let entries;
|
|
58
58
|
try {
|
|
59
|
-
entries =
|
|
59
|
+
entries = listDirEntries(dir);
|
|
60
60
|
} catch {
|
|
61
61
|
return {definitions, errors};
|
|
62
62
|
}
|
|
@@ -146,17 +146,46 @@ export function exportScalarType(file: string, exportName: string): "string" | "
|
|
|
146
146
|
* then have the same final origin. Null when an alias cannot be followed (to
|
|
147
147
|
* a default or namespace import, a member such as `Icons.X`, or an import
|
|
148
148
|
* that does not resolve), so a caller leaves the comparison unchecked.
|
|
149
|
+
* `unwrap`, when given, names a value a declaration stands for besides a
|
|
150
|
+
* plain alias (a theme made by `defineTheme({extends: base})` stands for
|
|
151
|
+
* `base`): it receives the declaration's initializer and returns the
|
|
152
|
+
* expression to follow, or null for none. A followed expression that is not
|
|
153
|
+
* an identifier makes the origin unknown.
|
|
149
154
|
* @param {{file: string, name: string}} origin
|
|
150
155
|
* @param {Set<string>} [seen]
|
|
156
|
+
* @param {(init: any) => any} [unwrap]
|
|
151
157
|
* @returns {{file: string, name: string} | null}
|
|
152
158
|
*/
|
|
153
159
|
export function aliasedOrigin(origin: {
|
|
154
160
|
file: string;
|
|
155
161
|
name: string;
|
|
156
|
-
}, seen?: Set<string
|
|
162
|
+
}, seen?: Set<string>, unwrap?: (init: any) => any): {
|
|
157
163
|
file: string;
|
|
158
164
|
name: string;
|
|
159
165
|
} | null;
|
|
166
|
+
/**
|
|
167
|
+
* Where the value each `<Name prop={value}>` element of a module passes is
|
|
168
|
+
* declared, one entry per element, read without running anything. `Name` is
|
|
169
|
+
* a runtime import of `name` from one of `sources` (renames included). The
|
|
170
|
+
* value is followed with {@link aliasedOrigin} (passing `unwrap`) from the
|
|
171
|
+
* module-scope binding it names, through local files and installed packages.
|
|
172
|
+
* An entry is null when the value is not an identifier or its origin cannot
|
|
173
|
+
* be proved (a parameter or an import that does not resolve gives the
|
|
174
|
+
* module's own name, and a member or a default import gives null). An element
|
|
175
|
+
* without `prop` gives no entry.
|
|
176
|
+
* @param {string} file
|
|
177
|
+
* @param {{sources: ReadonlySet<string>, name: string, prop: string, unwrap?: (init: any) => any}} element
|
|
178
|
+
* @returns {Array<{file: string, name: string} | null>}
|
|
179
|
+
*/
|
|
180
|
+
export function elementPropOrigins(file: string, { sources, name, prop, unwrap }: {
|
|
181
|
+
sources: ReadonlySet<string>;
|
|
182
|
+
name: string;
|
|
183
|
+
prop: string;
|
|
184
|
+
unwrap?: (init: any) => any;
|
|
185
|
+
}): Array<{
|
|
186
|
+
file: string;
|
|
187
|
+
name: string;
|
|
188
|
+
} | null>;
|
|
160
189
|
/**
|
|
161
190
|
* The object a module exports under `exportName`, read without running it:
|
|
162
191
|
* each property's key and the binding its value names (an identifier, or the
|
|
@@ -1317,11 +1317,17 @@ export function exportScalarType(file, exportName) {
|
|
|
1317
1317
|
* then have the same final origin. Null when an alias cannot be followed (to
|
|
1318
1318
|
* a default or namespace import, a member such as `Icons.X`, or an import
|
|
1319
1319
|
* that does not resolve), so a caller leaves the comparison unchecked.
|
|
1320
|
+
* `unwrap`, when given, names a value a declaration stands for besides a
|
|
1321
|
+
* plain alias (a theme made by `defineTheme({extends: base})` stands for
|
|
1322
|
+
* `base`): it receives the declaration's initializer and returns the
|
|
1323
|
+
* expression to follow, or null for none. A followed expression that is not
|
|
1324
|
+
* an identifier makes the origin unknown.
|
|
1320
1325
|
* @param {{file: string, name: string}} origin
|
|
1321
1326
|
* @param {Set<string>} [seen]
|
|
1327
|
+
* @param {(init: any) => any} [unwrap]
|
|
1322
1328
|
* @returns {{file: string, name: string} | null}
|
|
1323
1329
|
*/
|
|
1324
|
-
export function aliasedOrigin(origin, seen = new Set()) {
|
|
1330
|
+
export function aliasedOrigin(origin, seen = new Set(), unwrap) {
|
|
1325
1331
|
const identity = `${origin.file}\0${origin.name}`;
|
|
1326
1332
|
if (seen.has(identity)) return null;
|
|
1327
1333
|
seen.add(identity);
|
|
@@ -1344,16 +1350,88 @@ export function aliasedOrigin(origin, seen = new Set()) {
|
|
|
1344
1350
|
) {
|
|
1345
1351
|
continue;
|
|
1346
1352
|
}
|
|
1347
|
-
const
|
|
1353
|
+
const declared = withoutTypeWrappers(declarator.init);
|
|
1354
|
+
const followed = declared && unwrap ? unwrap(declared) : null;
|
|
1355
|
+
const init = followed ? withoutTypeWrappers(followed) : declared;
|
|
1348
1356
|
if (init?.type === 'MemberExpression') return null;
|
|
1349
|
-
if (init?.type !== 'Identifier') return origin;
|
|
1357
|
+
if (init?.type !== 'Identifier') return followed ? null : origin;
|
|
1350
1358
|
const next = bindingOrigin(ast, origin.file, init.name, new Set());
|
|
1351
|
-
return next ? aliasedOrigin(next, seen) : null;
|
|
1359
|
+
return next ? aliasedOrigin(next, seen, unwrap) : null;
|
|
1352
1360
|
}
|
|
1353
1361
|
}
|
|
1354
1362
|
return origin;
|
|
1355
1363
|
}
|
|
1356
1364
|
|
|
1365
|
+
/**
|
|
1366
|
+
* Where the value each `<Name prop={value}>` element of a module passes is
|
|
1367
|
+
* declared, one entry per element, read without running anything. `Name` is
|
|
1368
|
+
* a runtime import of `name` from one of `sources` (renames included). The
|
|
1369
|
+
* value is followed with {@link aliasedOrigin} (passing `unwrap`) from the
|
|
1370
|
+
* module-scope binding it names, through local files and installed packages.
|
|
1371
|
+
* An entry is null when the value is not an identifier or its origin cannot
|
|
1372
|
+
* be proved (a parameter or an import that does not resolve gives the
|
|
1373
|
+
* module's own name, and a member or a default import gives null). An element
|
|
1374
|
+
* without `prop` gives no entry.
|
|
1375
|
+
* @param {string} file
|
|
1376
|
+
* @param {{sources: ReadonlySet<string>, name: string, prop: string, unwrap?: (init: any) => any}} element
|
|
1377
|
+
* @returns {Array<{file: string, name: string} | null>}
|
|
1378
|
+
*/
|
|
1379
|
+
export function elementPropOrigins(file, {sources, name, prop, unwrap}) {
|
|
1380
|
+
let ast;
|
|
1381
|
+
try {
|
|
1382
|
+
ast = parseModule(file);
|
|
1383
|
+
} catch {
|
|
1384
|
+
return [];
|
|
1385
|
+
}
|
|
1386
|
+
/** @type {Set<string>} */
|
|
1387
|
+
const locals = new Set();
|
|
1388
|
+
for (const node of ast.program.body) {
|
|
1389
|
+
if (
|
|
1390
|
+
node.type !== 'ImportDeclaration' ||
|
|
1391
|
+
node.importKind === 'type' ||
|
|
1392
|
+
!sources.has(node.source?.value)
|
|
1393
|
+
) {
|
|
1394
|
+
continue;
|
|
1395
|
+
}
|
|
1396
|
+
for (const specifier of node.specifiers ?? []) {
|
|
1397
|
+
if (
|
|
1398
|
+
specifier.type === 'ImportSpecifier' &&
|
|
1399
|
+
specifier.importKind !== 'type' &&
|
|
1400
|
+
(specifier.imported?.name ?? specifier.imported?.value) === name
|
|
1401
|
+
) {
|
|
1402
|
+
locals.add(specifier.local.name);
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
if (locals.size === 0) return [];
|
|
1407
|
+
/** @type {Array<{file: string, name: string} | null>} */
|
|
1408
|
+
const origins = [];
|
|
1409
|
+
for (const element of nodesOfType(ast.program, 'JSXOpeningElement')) {
|
|
1410
|
+
if (
|
|
1411
|
+
element.name?.type !== 'JSXIdentifier' ||
|
|
1412
|
+
!locals.has(element.name.name)
|
|
1413
|
+
) {
|
|
1414
|
+
continue;
|
|
1415
|
+
}
|
|
1416
|
+
const attribute = (element.attributes ?? []).find(
|
|
1417
|
+
(/** @type {any} */ item) =>
|
|
1418
|
+
item.type === 'JSXAttribute' && item.name?.name === prop,
|
|
1419
|
+
);
|
|
1420
|
+
if (!attribute) continue;
|
|
1421
|
+
const value =
|
|
1422
|
+
attribute.value?.type === 'JSXExpressionContainer'
|
|
1423
|
+
? withoutTypeWrappers(attribute.value.expression)
|
|
1424
|
+
: null;
|
|
1425
|
+
if (value?.type !== 'Identifier') {
|
|
1426
|
+
origins.push(null);
|
|
1427
|
+
continue;
|
|
1428
|
+
}
|
|
1429
|
+
const binding = bindingOrigin(ast, file, value.name, new Set());
|
|
1430
|
+
origins.push(binding ? aliasedOrigin(binding, new Set(), unwrap) : null);
|
|
1431
|
+
}
|
|
1432
|
+
return origins;
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1357
1435
|
/**
|
|
1358
1436
|
* Where a top-level binding of a parsed module comes from: an import from a
|
|
1359
1437
|
* local module is followed to its origin; anything else is declared here.
|
|
@@ -28,6 +28,7 @@ import {createRequire} from 'node:module';
|
|
|
28
28
|
import {readDocView} from '../doc-compiler/read.mjs';
|
|
29
29
|
import {importDocModule} from '../doc-compiler/import.mjs';
|
|
30
30
|
import {CLI_ROOT, discoverExternalPackages} from '../fs/paths.mjs';
|
|
31
|
+
import {listDirEntries} from '../fs/listing-cache.mjs';
|
|
31
32
|
import {CORE_PROVIDER_ID} from '../identity/providers.mjs';
|
|
32
33
|
import {Project} from '../config/project.mjs';
|
|
33
34
|
import {
|
|
@@ -1115,8 +1116,7 @@ export function listTemplates() {
|
|
|
1115
1116
|
const all = [];
|
|
1116
1117
|
if (fs.existsSync(PAGES_DIR)) {
|
|
1117
1118
|
all.push(
|
|
1118
|
-
...
|
|
1119
|
-
.readdirSync(PAGES_DIR, {withFileTypes: true})
|
|
1119
|
+
...listDirEntries(PAGES_DIR)
|
|
1120
1120
|
.filter(e => e.isDirectory())
|
|
1121
1121
|
.map(e => e.name),
|
|
1122
1122
|
);
|
|
@@ -1133,7 +1133,7 @@ function findDocFiles(dir, pattern) {
|
|
|
1133
1133
|
/** @type {string[]} */
|
|
1134
1134
|
const results = [];
|
|
1135
1135
|
if (!fs.existsSync(dir)) return results;
|
|
1136
|
-
for (const entry of
|
|
1136
|
+
for (const entry of listDirEntries(dir)) {
|
|
1137
1137
|
const full = path.join(dir, entry.name);
|
|
1138
1138
|
if (entry.isDirectory()) {
|
|
1139
1139
|
results.push(...findDocFiles(full, pattern));
|
|
@@ -1160,9 +1160,7 @@ export function findPageDocFile(dirPath) {
|
|
|
1160
1160
|
|
|
1161
1161
|
async function discoverPages() {
|
|
1162
1162
|
if (!fs.existsSync(PAGES_DIR)) return [];
|
|
1163
|
-
const dirs =
|
|
1164
|
-
.readdirSync(PAGES_DIR, {withFileTypes: true})
|
|
1165
|
-
.filter(e => e.isDirectory());
|
|
1163
|
+
const dirs = listDirEntries(PAGES_DIR).filter(e => e.isDirectory());
|
|
1166
1164
|
|
|
1167
1165
|
/** @type {DiscoveredTemplate[]} */
|
|
1168
1166
|
const templates = [];
|
|
@@ -1602,7 +1600,7 @@ function findIntegrationDocFiles(root) {
|
|
|
1602
1600
|
if (!fs.existsSync(root)) return results;
|
|
1603
1601
|
/** @param {string} dir */
|
|
1604
1602
|
const walk = dir => {
|
|
1605
|
-
for (const entry of
|
|
1603
|
+
for (const entry of listDirEntries(dir)) {
|
|
1606
1604
|
const full = path.join(dir, entry.name);
|
|
1607
1605
|
if (entry.isDirectory()) {
|
|
1608
1606
|
walk(full);
|
|
@@ -22,6 +22,7 @@ import * as path from 'node:path';
|
|
|
22
22
|
import {lowerDoc} from '../doc-compiler/compile.mjs';
|
|
23
23
|
import {packageSource} from '../doc-compiler/source.mjs';
|
|
24
24
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
25
|
+
import {listDirEntries} from '../fs/listing-cache.mjs';
|
|
25
26
|
import {formatCliCommand} from '../env/package-manager.mjs';
|
|
26
27
|
import {LOCAL_THEME_ROOT} from '../config/theme-state.mjs';
|
|
27
28
|
import {assertWithin, PathSafetyError} from '../fs/path-safety.mjs';
|
|
@@ -1187,7 +1188,7 @@ function listThemeFolder(folder) {
|
|
|
1187
1188
|
const symlinks = [];
|
|
1188
1189
|
/** @param {string} directory */
|
|
1189
1190
|
function walk(directory) {
|
|
1190
|
-
for (const entry of
|
|
1191
|
+
for (const entry of listDirEntries(directory)) {
|
|
1191
1192
|
if (isIgnoredThemeEntry(entry.name)) continue;
|
|
1192
1193
|
const full = path.join(directory, entry.name);
|
|
1193
1194
|
const relative = path.relative(folder, full).split(path.sep).join('/');
|
|
@@ -1291,8 +1292,7 @@ export function discoverUnmigratedThemeCopies(
|
|
|
1291
1292
|
) {
|
|
1292
1293
|
const root = path.resolve(projectDir, owner);
|
|
1293
1294
|
if (!fs.existsSync(root) || !fs.statSync(root).isDirectory()) return [];
|
|
1294
|
-
return
|
|
1295
|
-
.readdirSync(root, {withFileTypes: true})
|
|
1295
|
+
return listDirEntries(root)
|
|
1296
1296
|
.filter(entry => entry.isDirectory() && !isIgnoredThemeEntry(entry.name))
|
|
1297
1297
|
.map(entry => unmigratedThemeCopy(path.join(root, entry.name)))
|
|
1298
1298
|
.filter(copy => copy !== null)
|
|
@@ -1369,9 +1369,9 @@ export function discoverThemeDirectory(
|
|
|
1369
1369
|
/** @type {DiscoveredTheme[]} */
|
|
1370
1370
|
const themes = [];
|
|
1371
1371
|
const slugs = new Set();
|
|
1372
|
-
const rootEntries =
|
|
1373
|
-
|
|
1374
|
-
|
|
1372
|
+
const rootEntries = listDirEntries(themeRoot).filter(
|
|
1373
|
+
entry => !isIgnoredThemeEntry(entry.name),
|
|
1374
|
+
);
|
|
1375
1375
|
const rootDescriptor = rootEntries.find(
|
|
1376
1376
|
entry => entry.isFile() && entry.name.endsWith(THEME_DOC_SUFFIX),
|
|
1377
1377
|
);
|
|
@@ -1614,8 +1614,7 @@ export function unreadThemeFolders(themeRoot, {packageDir, packageName} = {}) {
|
|
|
1614
1614
|
if (!fs.existsSync(themeRoot) || !fs.statSync(themeRoot).isDirectory()) {
|
|
1615
1615
|
return [];
|
|
1616
1616
|
}
|
|
1617
|
-
const folders =
|
|
1618
|
-
.readdirSync(themeRoot, {withFileTypes: true})
|
|
1617
|
+
const folders = listDirEntries(themeRoot)
|
|
1619
1618
|
.filter(entry => entry.isDirectory() && !isIgnoredThemeEntry(entry.name))
|
|
1620
1619
|
.map(entry => path.join(themeRoot, entry.name))
|
|
1621
1620
|
.sort();
|
|
@@ -1630,8 +1629,7 @@ export function unreadThemeFolders(themeRoot, {packageDir, packageName} = {}) {
|
|
|
1630
1629
|
if (unread.length === 0) return [];
|
|
1631
1630
|
|
|
1632
1631
|
const modules = [
|
|
1633
|
-
...
|
|
1634
|
-
.readdirSync(themeRoot, {withFileTypes: true})
|
|
1632
|
+
...listDirEntries(themeRoot)
|
|
1635
1633
|
.filter(
|
|
1636
1634
|
entry =>
|
|
1637
1635
|
entry.isFile() &&
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
import * as fs from 'node:fs';
|
|
21
21
|
import * as path from 'node:path';
|
|
22
22
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
23
|
+
import {listDir} from '../fs/listing-cache.mjs';
|
|
23
24
|
import {loadCliSelfDocs} from '../discovery/cli-self-docs.mjs';
|
|
24
25
|
import {astryxIconDefinitions} from '../discovery/icon-definition-discovery.mjs';
|
|
25
26
|
import {routeSegment} from '../discovery/docs-section-key.mjs';
|
|
@@ -812,8 +813,7 @@ function adoptionsFor(doc, declared, routeOf) {
|
|
|
812
813
|
*/
|
|
813
814
|
export function treeDocFiles(dir = TREE_DOCS_DIR) {
|
|
814
815
|
if (!fs.existsSync(dir)) return [];
|
|
815
|
-
return
|
|
816
|
-
.readdirSync(dir)
|
|
816
|
+
return listDir(dir)
|
|
817
817
|
.filter(file => /^[\w-]+\.doc\.mjs$/u.test(file))
|
|
818
818
|
.sort(byText)
|
|
819
819
|
.map(file => path.join(dir, file));
|
|
@@ -25,7 +25,9 @@ export function oncePerListing<T>(key: string, compute: () => T): T;
|
|
|
25
25
|
export function listingCacheActive(): boolean;
|
|
26
26
|
/**
|
|
27
27
|
* `fs.readdirSync(dir)`, read once per operation. Returns a fresh array, so a
|
|
28
|
-
* caller that sorts it cannot reorder another caller's listing.
|
|
28
|
+
* caller that sorts it cannot reorder another caller's listing. The names come
|
|
29
|
+
* from the same read as {@link listDirEntries}, so a folder listed both ways
|
|
30
|
+
* is read once.
|
|
29
31
|
* @param {string} dir
|
|
30
32
|
* @returns {string[]}
|
|
31
33
|
*/
|
|
@@ -2,23 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @file One directory listing per path for the duration of one read-only
|
|
5
|
-
* operation.
|
|
5
|
+
* operation, kept for later operations while the folder is unchanged.
|
|
6
6
|
*
|
|
7
7
|
* @input A read-only operation (`withListingCache(fn)`), and directory paths
|
|
8
8
|
* its discovery helpers list or probe.
|
|
9
9
|
* @output The same answers `fs.readdirSync` / `fs.existsSync` give, read from
|
|
10
10
|
* disk once per path while the operation runs, and `oncePerListing`, a
|
|
11
|
-
* value computed once per operation.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
11
|
+
* value computed once per operation. A later operation in the same process
|
|
12
|
+
* reuses a listing while its folder's stamp is unchanged.
|
|
13
|
+
* @position Used by the name resolvers and doc walkers in
|
|
14
|
+
* foundation/discovery and by `existsCaseExact`. A search or build resolves
|
|
15
|
+
* ~160 components and their hooks, and each resolution walks the same
|
|
16
|
+
* source tree again. Inside one operation the tree does not change, so each
|
|
17
|
+
* directory is read once. Outside `withListingCache` every helper reads the
|
|
18
|
+
* disk directly, exactly as before.
|
|
18
19
|
*/
|
|
19
20
|
|
|
20
21
|
import {AsyncLocalStorage} from 'node:async_hooks';
|
|
21
22
|
import * as fs from 'node:fs';
|
|
23
|
+
import * as path from 'node:path';
|
|
24
|
+
import {performance} from 'node:perf_hooks';
|
|
25
|
+
import {fileStamp, recordContentRead} from './read-record.mjs';
|
|
22
26
|
|
|
23
27
|
/**
|
|
24
28
|
* @typedef {{
|
|
@@ -33,6 +37,24 @@ import * as fs from 'node:fs';
|
|
|
33
37
|
/** @type {AsyncLocalStorage<ListingCache>} */
|
|
34
38
|
const scope = new AsyncLocalStorage();
|
|
35
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Listings kept for later operations in this process, by folder. Each holds
|
|
42
|
+
* the folder's stamp (`fileStamp`: size, times and inode) and when this
|
|
43
|
+
* process first saw it. Once the stamp has held for {@link SETTLE_MS}, it
|
|
44
|
+
* holds the entries too. Adding, removing or renaming an entry changes the
|
|
45
|
+
* stamp.
|
|
46
|
+
* @type {Map<string, {stamp: string, since: number, entries: fs.Dirent[] | null}>}
|
|
47
|
+
*/
|
|
48
|
+
const kept = new Map();
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* How long a folder's stamp must hold, by this process's clock, before its
|
|
52
|
+
* listing is kept. A file system can store times as coarsely as 2 s. So a
|
|
53
|
+
* change within one tick of the last can leave the stamp as it was. After the
|
|
54
|
+
* stamp has held this long, a new change falls in a later tick.
|
|
55
|
+
*/
|
|
56
|
+
const SETTLE_MS = 2000;
|
|
57
|
+
|
|
36
58
|
/**
|
|
37
59
|
* Run `fn` with a listing cache. A nested call shares the outer cache. Only
|
|
38
60
|
* wrap operations that do not change the files they list.
|
|
@@ -79,7 +101,9 @@ export function listingCacheActive() {
|
|
|
79
101
|
|
|
80
102
|
/**
|
|
81
103
|
* `fs.readdirSync(dir)`, read once per operation. Returns a fresh array, so a
|
|
82
|
-
* caller that sorts it cannot reorder another caller's listing.
|
|
104
|
+
* caller that sorts it cannot reorder another caller's listing. The names come
|
|
105
|
+
* from the same read as {@link listDirEntries}, so a folder listed both ways
|
|
106
|
+
* is read once.
|
|
83
107
|
* @param {string} dir
|
|
84
108
|
* @returns {string[]}
|
|
85
109
|
*/
|
|
@@ -88,7 +112,7 @@ export function listDir(dir) {
|
|
|
88
112
|
if (!cache) return fs.readdirSync(dir);
|
|
89
113
|
let names = cache.names.get(dir);
|
|
90
114
|
if (!names) {
|
|
91
|
-
names =
|
|
115
|
+
names = listDirEntries(dir).map(entry => entry.name);
|
|
92
116
|
cache.names.set(dir, names);
|
|
93
117
|
}
|
|
94
118
|
return names.slice();
|
|
@@ -104,12 +128,40 @@ export function listDirEntries(dir) {
|
|
|
104
128
|
if (!cache) return fs.readdirSync(dir, {withFileTypes: true});
|
|
105
129
|
let entries = cache.entries.get(dir);
|
|
106
130
|
if (!entries) {
|
|
107
|
-
entries =
|
|
131
|
+
entries = keptOrRead(dir);
|
|
108
132
|
cache.entries.set(dir, entries);
|
|
109
133
|
}
|
|
110
134
|
return entries.slice();
|
|
111
135
|
}
|
|
112
136
|
|
|
137
|
+
/**
|
|
138
|
+
* `dir`'s entries for an operation. They are the kept listing while the
|
|
139
|
+
* folder's stamp is the one it was kept with. Otherwise they are a new read,
|
|
140
|
+
* kept once the stamp has held for {@link SETTLE_MS}.
|
|
141
|
+
* @param {string} dir
|
|
142
|
+
* @returns {fs.Dirent[]}
|
|
143
|
+
*/
|
|
144
|
+
function keptOrRead(dir) {
|
|
145
|
+
const folder = path.resolve(dir);
|
|
146
|
+
// A reuse check (read-record.mjs) records the folder's state before the
|
|
147
|
+
// stamp below is taken. So a change between the two shows as a change.
|
|
148
|
+
recordContentRead(folder);
|
|
149
|
+
const before = performance.now();
|
|
150
|
+
const stamp = fileStamp(folder);
|
|
151
|
+
const held = kept.get(folder);
|
|
152
|
+
if (held?.entries && held.stamp === stamp) return held.entries;
|
|
153
|
+
const entries = fs.readdirSync(dir, {withFileTypes: true});
|
|
154
|
+
if (held?.stamp !== stamp) {
|
|
155
|
+
// Taken after the stamp, so the stamp's times are no later than this.
|
|
156
|
+
kept.set(folder, {stamp, since: performance.now(), entries: null});
|
|
157
|
+
} else if (before - held.since >= SETTLE_MS) {
|
|
158
|
+
// Read after the stamp held for the settle time: a later change gets a
|
|
159
|
+
// new stamp.
|
|
160
|
+
kept.set(folder, {stamp, since: held.since, entries});
|
|
161
|
+
}
|
|
162
|
+
return entries;
|
|
163
|
+
}
|
|
164
|
+
|
|
113
165
|
/**
|
|
114
166
|
* The entry named exactly `name` in `dir`'s listing, or null when the folder
|
|
115
167
|
* holds no such name or cannot be read. Inside an operation, a name the
|
package/foundation/fs/paths.mjs
CHANGED
|
@@ -16,6 +16,7 @@ import {fileURLToPath} from 'node:url';
|
|
|
16
16
|
import {
|
|
17
17
|
findEntry,
|
|
18
18
|
listDir,
|
|
19
|
+
listDirEntries,
|
|
19
20
|
listingCacheActive,
|
|
20
21
|
pathExists,
|
|
21
22
|
} from './listing-cache.mjs';
|
|
@@ -811,7 +812,7 @@ export function discoverExternalPackages(startDir = process.cwd()) {
|
|
|
811
812
|
/** @param {string} searchDir */
|
|
812
813
|
const scanDir = searchDir => {
|
|
813
814
|
if (!fs.existsSync(searchDir)) return;
|
|
814
|
-
const entries =
|
|
815
|
+
const entries = listDirEntries(searchDir);
|
|
815
816
|
|
|
816
817
|
for (const entry of entries) {
|
|
817
818
|
if (!entry.isDirectory()) continue;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* What a stylesheet's `@import` rules load, read with postcss so comments
|
|
6
|
+
* are ignored.
|
|
7
|
+
* @param {string} css
|
|
8
|
+
* @returns {string[]}
|
|
9
|
+
*/
|
|
10
|
+
export function cssImports(css: string): string[];
|
|
4
11
|
/**
|
|
5
12
|
* The string specifiers one module imports.
|
|
6
13
|
* @param {string} source
|