@astryxdesign/cli 0.7.10 → 0.7.11-canary.3bbab18
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/rank.mjs +21 -4
- 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/build/kit/words.d.mts +1 -0
- package/api/build/kit/words.mjs +1 -1
- 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/icon/_adapter.d.mts +3 -2
- package/api/icon/_adapter.mjs +8 -2
- package/api/icon/_authoring.d.mts +1 -0
- package/api/icon/_authoring.mjs +362 -38
- package/api/icon/_default-look.d.mts +155 -0
- package/api/icon/_default-look.mjs +474 -0
- package/api/icon/_records.d.mts +1 -1
- package/api/icon/_records.mjs +1 -0
- package/api/icon/add/add.mjs +224 -38
- package/api/icon/icon.type.d.mts +7 -2
- package/api/icon/icon.type.mjs +4 -2
- package/api/icon/iconAdd.doc.mjs +2 -2
- package/api/icon/iconNewDefinition.doc.mjs +3 -2
- package/api/icon/iconNewSet.doc.mjs +4 -4
- package/api/icon/search/search.mjs +10 -9
- package/api/integration/add-helpers.d.mts +2 -1
- package/api/integration/add-helpers.mjs +5 -2
- package/api/integration/authoring-checks.d.mts +0 -2
- package/api/integration/authoring-checks.mjs +1 -6
- package/api/integration/pack-check.d.mts +8 -6
- package/api/integration/pack-check.mjs +16 -6
- package/api/logger.mjs +2 -1
- 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/icon-sets.doc.mjs +9 -3
- 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/assets/templates/blocks/components/Table/TableLeadingMarkSelection.doc.mjs +15 -0
- package/assets/templates/blocks/components/Table/TableLeadingMarkSelection.tsx +134 -0
- package/assets/templates/pages/theme-showcase/page.tsx +724 -792
- package/assets/templates/pages/theme-showcase/template.doc.mjs +4 -5
- package/authoring/doctypes/_schema.d.mts +1 -1
- package/clients/cli/commands/build.doc.mjs +3 -2
- package/clients/cli/commands/build.mjs +34 -5
- package/clients/cli/commands/experimental/icon.mjs +31 -10
- package/clients/cli/commands/experimental-icon-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +2 -1
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +2 -2
- package/clients/cli/index.mjs +36 -7
- 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/doc-types.mjs +9 -2
- package/foundation/discovery/docs-discovery.mjs +6 -4
- package/foundation/discovery/icon-definition-discovery.mjs +3 -3
- package/foundation/discovery/icon-ranking.d.mts +27 -3
- package/foundation/discovery/icon-ranking.mjs +125 -8
- package/foundation/discovery/icon-set-checks.mjs +40 -20
- package/foundation/discovery/icon-set-writer.d.mts +210 -16
- package/foundation/discovery/icon-set-writer.mjs +619 -79
- package/foundation/discovery/module-exports.d.mts +92 -4
- package/foundation/discovery/module-exports.mjs +410 -61
- 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/env/package-manager.d.mts +12 -4
- package/foundation/env/package-manager.mjs +15 -6
- package/foundation/env/semver.mjs +41 -9
- 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/release/notices.d.mts +16 -0
- package/foundation/release/notices.mjs +27 -6
- 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/shell-arg.d.mts +14 -0
- package/foundation/text/shell-arg.mjs +17 -0
- package/foundation/text/string-utils.mjs +25 -25
- package/package.json +6 -6
|
@@ -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));
|
|
@@ -159,16 +159,24 @@ export function cliBinResolves(targetDir?: string): boolean;
|
|
|
159
159
|
*
|
|
160
160
|
* With `installed`, the line follows a step that installs the project's own
|
|
161
161
|
* CLI (an update notice, the hint that matches a project's CLI to its Core),
|
|
162
|
-
* so the guess is that CLI: `<run-prefix> astryx`.
|
|
163
|
-
*
|
|
162
|
+
* so the guess is that CLI: `<run-prefix> astryx`. With `release`, the line
|
|
163
|
+
* runs in another project's folder than the run's, so the guess names that
|
|
164
|
+
* project's release instead of the one that answered: its own CLI when it
|
|
165
|
+
* installs one and the bin resolves there, otherwise the package runner
|
|
166
|
+
* pinned to that release. A declared `cliCommand` and a host's door still
|
|
167
|
+
* come first.
|
|
164
168
|
*
|
|
165
169
|
* @param {string} [targetDir] the project the printed command runs in;
|
|
166
170
|
* defaults to the working directory
|
|
167
|
-
* @param {{installed?: boolean}} [options]
|
|
171
|
+
* @param {{installed?: boolean, release?: {version: string, own: boolean} | null}} [options]
|
|
168
172
|
* @returns {string}
|
|
169
173
|
*/
|
|
170
|
-
export function getCliInvocation(targetDir?: string, { installed }?: {
|
|
174
|
+
export function getCliInvocation(targetDir?: string, { installed, release }?: {
|
|
171
175
|
installed?: boolean;
|
|
176
|
+
release?: {
|
|
177
|
+
version: string;
|
|
178
|
+
own: boolean;
|
|
179
|
+
} | null;
|
|
172
180
|
}): string;
|
|
173
181
|
/**
|
|
174
182
|
* The package-manager guess alone, without any integration's `cliCommand` or
|
|
@@ -509,21 +509,30 @@ export function cliBinResolves(targetDir = process.cwd()) {
|
|
|
509
509
|
*
|
|
510
510
|
* With `installed`, the line follows a step that installs the project's own
|
|
511
511
|
* CLI (an update notice, the hint that matches a project's CLI to its Core),
|
|
512
|
-
* so the guess is that CLI: `<run-prefix> astryx`.
|
|
513
|
-
*
|
|
512
|
+
* so the guess is that CLI: `<run-prefix> astryx`. With `release`, the line
|
|
513
|
+
* runs in another project's folder than the run's, so the guess names that
|
|
514
|
+
* project's release instead of the one that answered: its own CLI when it
|
|
515
|
+
* installs one and the bin resolves there, otherwise the package runner
|
|
516
|
+
* pinned to that release. A declared `cliCommand` and a host's door still
|
|
517
|
+
* come first.
|
|
514
518
|
*
|
|
515
519
|
* @param {string} [targetDir] the project the printed command runs in;
|
|
516
520
|
* defaults to the working directory
|
|
517
|
-
* @param {{installed?: boolean}} [options]
|
|
521
|
+
* @param {{installed?: boolean, release?: {version: string, own: boolean} | null}} [options]
|
|
518
522
|
* @returns {string}
|
|
519
523
|
*/
|
|
520
|
-
export function getCliInvocation(
|
|
524
|
+
export function getCliInvocation(
|
|
525
|
+
targetDir,
|
|
526
|
+
{installed = false, release = null} = {},
|
|
527
|
+
) {
|
|
521
528
|
const declared = declaredCliCommand(targetDir);
|
|
522
529
|
if (declared.command) return declared.command;
|
|
523
530
|
const guess = () =>
|
|
524
|
-
installed
|
|
531
|
+
installed || (release?.own && cliBinResolves(targetDir))
|
|
525
532
|
? `${getRunPrefix(targetDir)} ${CLI_BIN}`
|
|
526
|
-
:
|
|
533
|
+
: release
|
|
534
|
+
? `${getDlxPrefix(targetDir)} ${CLI_PACKAGE}@${release.version}`
|
|
535
|
+
: guessCliInvocation(targetDir);
|
|
527
536
|
if (declared.conflict) return guess();
|
|
528
537
|
return cliDoor() ?? guess();
|
|
529
538
|
}
|
|
@@ -80,7 +80,10 @@ export function semverGt(a, b) {
|
|
|
80
80
|
* @returns {{major: number, minor: number, patch: number, count: number}}
|
|
81
81
|
*/
|
|
82
82
|
function parseVersionParts(value) {
|
|
83
|
-
const core = String(value)
|
|
83
|
+
const core = String(value)
|
|
84
|
+
.trim()
|
|
85
|
+
.replace(/^[v=]+/, '')
|
|
86
|
+
.split(/[-+]/)[0];
|
|
84
87
|
const nums = core.split('.').map(n => parseInt(n, 10));
|
|
85
88
|
return {
|
|
86
89
|
major: Number.isFinite(nums[0]) ? nums[0] : 0,
|
|
@@ -105,7 +108,8 @@ function satisfiesComparator(version, token) {
|
|
|
105
108
|
if (!m) return true;
|
|
106
109
|
const op = m[1] || '=';
|
|
107
110
|
const target = m[2].trim();
|
|
108
|
-
if (target === '' || target === '*' || target.toLowerCase() === 'x')
|
|
111
|
+
if (target === '' || target === '*' || target.toLowerCase() === 'x')
|
|
112
|
+
return true;
|
|
109
113
|
const t = parseVersionParts(target);
|
|
110
114
|
// No numeric component (e.g. `workspace:*`, a git/url spec) — can't model it,
|
|
111
115
|
// so treat as unconstrained rather than emit a false mismatch.
|
|
@@ -123,16 +127,22 @@ function satisfiesComparator(version, token) {
|
|
|
123
127
|
case '<':
|
|
124
128
|
return cmp < 0;
|
|
125
129
|
case '^':
|
|
126
|
-
|
|
127
|
-
|
|
130
|
+
// A partial target widens the range to the parts given: `^0` is any
|
|
131
|
+
// 0.x.y, `^0.0` is any 0.0.y, while `^0.0.3` is locked to the patch.
|
|
132
|
+
if (t.major > 0 || t.count === 1) return below(`${t.major + 1}.0.0`);
|
|
133
|
+
if (t.minor > 0 || t.count === 2) return below(`0.${t.minor + 1}.0`);
|
|
128
134
|
return below(`0.0.${t.patch + 1}`);
|
|
129
135
|
case '~':
|
|
130
|
-
return below(
|
|
136
|
+
return below(
|
|
137
|
+
t.count >= 2 ? `${t.major}.${t.minor + 1}.0` : `${t.major + 1}.0.0`,
|
|
138
|
+
);
|
|
131
139
|
case '=':
|
|
132
140
|
default:
|
|
133
141
|
// A full version is exact; a partial (`1`, `1.2`) behaves like a range.
|
|
134
142
|
if (t.count >= 3) return cmp === 0;
|
|
135
|
-
return below(
|
|
143
|
+
return below(
|
|
144
|
+
t.count === 2 ? `${t.major}.${t.minor + 1}.0` : `${t.major + 1}.0.0`,
|
|
145
|
+
);
|
|
136
146
|
}
|
|
137
147
|
}
|
|
138
148
|
|
|
@@ -154,11 +164,33 @@ function satisfiesComparator(version, token) {
|
|
|
154
164
|
export function satisfiesRange(version, range) {
|
|
155
165
|
if (!isValidSemver(version)) return true;
|
|
156
166
|
const r = String(range ?? '').trim();
|
|
157
|
-
if (
|
|
167
|
+
if (
|
|
168
|
+
r === '' ||
|
|
169
|
+
r === '*' ||
|
|
170
|
+
r.toLowerCase() === 'x' ||
|
|
171
|
+
r.toLowerCase() === 'latest'
|
|
172
|
+
) {
|
|
158
173
|
return true;
|
|
159
174
|
}
|
|
160
175
|
return r.split('||').some(union => {
|
|
161
|
-
|
|
162
|
-
|
|
176
|
+
// A hyphen range `A - B` is the inclusive intersection `>=A <=B`; left
|
|
177
|
+
// as-is its two bare versions would each read as an exact match that
|
|
178
|
+
// can never both hold. A partial upper bound covers its whole series, as
|
|
179
|
+
// npm reads it: `1.0.0 - 2` is `>=1.0.0 <3.0.0`.
|
|
180
|
+
const normalized = union
|
|
181
|
+
.trim()
|
|
182
|
+
.replace(/^(\S+)\s+-\s+(\S+)$/, (_, low, high) => {
|
|
183
|
+
const h = parseVersionParts(high);
|
|
184
|
+
if (h.count === 0) return `>=${low}`;
|
|
185
|
+
if (h.count >= 3) return `>=${low} <=${high}`;
|
|
186
|
+
const next =
|
|
187
|
+
h.count === 2 ? `${h.major}.${h.minor + 1}.0` : `${h.major + 1}.0.0`;
|
|
188
|
+
return `>=${low} <${next}`;
|
|
189
|
+
});
|
|
190
|
+
const tokens = normalized.split(/\s+/).filter(Boolean);
|
|
191
|
+
return (
|
|
192
|
+
tokens.length === 0 ||
|
|
193
|
+
tokens.every(tok => satisfiesComparator(version, tok))
|
|
194
|
+
);
|
|
163
195
|
});
|
|
164
196
|
}
|
|
@@ -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;
|
|
@@ -132,6 +132,17 @@ export function installFolder(cwd: string): {
|
|
|
132
132
|
dir: string;
|
|
133
133
|
moved: boolean;
|
|
134
134
|
} | null;
|
|
135
|
+
/**
|
|
136
|
+
* The release of the project at `dir`, for a command that runs in its folder
|
|
137
|
+
* from a folder below it: its own CLI's version when it installs one, else
|
|
138
|
+
* the Core it records; null when it records neither.
|
|
139
|
+
* @param {string} dir
|
|
140
|
+
* @returns {{version: string, own: boolean} | null}
|
|
141
|
+
*/
|
|
142
|
+
export function projectRelease(dir: string): {
|
|
143
|
+
version: string;
|
|
144
|
+
own: boolean;
|
|
145
|
+
} | null;
|
|
135
146
|
/**
|
|
136
147
|
* The command that adds the CLI at Core's version, for a run in `cwd` whose
|
|
137
148
|
* Core is `core`, with the project's package manager in the project root.
|
|
@@ -255,6 +266,11 @@ export function noticeLines({ cwd, self, choice, json, stateDir, cacheDir, now,
|
|
|
255
266
|
}): string[];
|
|
256
267
|
/** A notice prints at most once in this long. */
|
|
257
268
|
export const NOTICE_INTERVAL_MS: number;
|
|
269
|
+
/**
|
|
270
|
+
* The key prefix of the once-a-day setup reminder. It is no update notice, so
|
|
271
|
+
* no skip is recorded for it and doctor's update line never names it.
|
|
272
|
+
*/
|
|
273
|
+
export const SETUP_REMINDER_KEY: "setup:";
|
|
258
274
|
/**
|
|
259
275
|
* What to tell a run in a folder inside a project whose package.json is not
|
|
260
276
|
* the project's: run from the project's folder, since adding there would make
|
|
@@ -81,6 +81,12 @@ const FORGET_AFTER_MS = 30 * 24 * 60 * 60_000;
|
|
|
81
81
|
*/
|
|
82
82
|
const LATEST = '@astryxdesign/cli@latest';
|
|
83
83
|
|
|
84
|
+
/**
|
|
85
|
+
* The key prefix of the once-a-day setup reminder. It is no update notice, so
|
|
86
|
+
* no skip is recorded for it and doctor's update line never names it.
|
|
87
|
+
*/
|
|
88
|
+
export const SETUP_REMINDER_KEY = 'setup:';
|
|
89
|
+
|
|
84
90
|
/**
|
|
85
91
|
* Whether notice `key` may print now; when it may, its time is recorded
|
|
86
92
|
* first, and a time that cannot be recorded keeps it from printing.
|
|
@@ -104,7 +110,9 @@ export function takeNotice(
|
|
|
104
110
|
const shown = state.notifiedAt ?? {};
|
|
105
111
|
const last = shown[key];
|
|
106
112
|
if (typeof last === 'number' && now - last < NOTICE_INTERVAL_MS) {
|
|
107
|
-
const skips =
|
|
113
|
+
const skips = key.startsWith(SETUP_REMINDER_KEY)
|
|
114
|
+
? null
|
|
115
|
+
: withSkip(state.noticeSkips, key, 'already-shown', now);
|
|
108
116
|
if (skips) writeGlobalState({...state, noticeSkips: skips}, stateDir);
|
|
109
117
|
return /** @type {const} */ ('already-shown');
|
|
110
118
|
}
|
|
@@ -198,6 +206,7 @@ export function lastNoticeSkip({stateDir = userConfigDir()} = {}) {
|
|
|
198
206
|
readGlobalState(stateDir).noticeSkips ?? {},
|
|
199
207
|
)) {
|
|
200
208
|
if (
|
|
209
|
+
!key.startsWith(SETUP_REMINDER_KEY) &&
|
|
201
210
|
skip &&
|
|
202
211
|
typeof skip.at === 'number' &&
|
|
203
212
|
(!newest || skip.at > newest.at)
|
|
@@ -459,6 +468,19 @@ export function installFolder(cwd) {
|
|
|
459
468
|
export const RUN_FROM_PROJECT =
|
|
460
469
|
"Run this from the Astryx project's folder, or declare an Astryx package in this folder's package.json to make it a project of its own.";
|
|
461
470
|
|
|
471
|
+
/**
|
|
472
|
+
* The release of the project at `dir`, for a command that runs in its folder
|
|
473
|
+
* from a folder below it: its own CLI's version when it installs one, else
|
|
474
|
+
* the Core it records; null when it records neither.
|
|
475
|
+
* @param {string} dir
|
|
476
|
+
* @returns {{version: string, own: boolean} | null}
|
|
477
|
+
*/
|
|
478
|
+
export function projectRelease(dir) {
|
|
479
|
+
const facts = readReleaseFacts(dir);
|
|
480
|
+
const version = facts.cli?.version ?? coreVersionOf(facts);
|
|
481
|
+
return version ? {version, own: Boolean(facts.cli)} : null;
|
|
482
|
+
}
|
|
483
|
+
|
|
462
484
|
/**
|
|
463
485
|
* The command that adds the CLI at Core's version, for a run in `cwd` whose
|
|
464
486
|
* Core is `core`, with the project's package manager in the project root.
|
|
@@ -534,11 +556,10 @@ export function projectLag({cwd, current: given, stateDir = userConfigDir()}) {
|
|
|
534
556
|
const target = installFolder(cwd);
|
|
535
557
|
if (target == null) return null;
|
|
536
558
|
const root = target.moved ? target.dir : (projectRootOf(facts) ?? cwd);
|
|
537
|
-
// From a folder inside the project, the project's own release
|
|
538
|
-
//
|
|
539
|
-
const
|
|
540
|
-
|
|
541
|
-
? (projectFacts.cli?.version ?? coreVersionOf(projectFacts) ?? given)
|
|
559
|
+
// From a folder inside the project, the project's own release, as the
|
|
560
|
+
// setup reminder names it, so the project gets one notice and one --from.
|
|
561
|
+
const current = target.moved
|
|
562
|
+
? (projectRelease(root)?.version ?? given)
|
|
542
563
|
: given;
|
|
543
564
|
if (!isBehind(current, latest.version)) return null;
|
|
544
565
|
const newest = latest.version;
|
|
@@ -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
|