@astryxdesign/cli 0.7.6-canary.844f28b → 0.7.6-canary.8835dec
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.
|
@@ -31,7 +31,9 @@ export function gatherCandidates(options: {
|
|
|
31
31
|
* folder, for the same `type`, ranks the candidates an earlier search
|
|
32
32
|
* gathered when none of the files that gather read, and none of the folders
|
|
33
33
|
* it listed or probed, changed since (each is checked by its change time and
|
|
34
|
-
* size, so an edited doc in a linked package is seen on the next call).
|
|
34
|
+
* size, so an edited doc in a linked package is seen on the next call). That
|
|
35
|
+
* holds for a gather that is still running too, so searches that start
|
|
36
|
+
* together (a docs site's search right after it starts) share one gather. A
|
|
35
37
|
* long-running caller (a docs site's search, an agent harness) then pays the
|
|
36
38
|
* gather once. A one-shot `astryx search` gathers once, as before.
|
|
37
39
|
* @param {{cwd?: string, type?: string}} options
|
package/api/search/_adapter.mjs
CHANGED
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
import {readFileSync} from 'node:fs';
|
|
10
10
|
import * as path from 'node:path';
|
|
11
11
|
import {requireCoreDir} from '../../foundation/fs/paths.mjs';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
reusedWhileUnchanged,
|
|
14
|
+
unchangedSince,
|
|
15
|
+
} from '../../foundation/fs/read-record.mjs';
|
|
13
16
|
import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
|
|
14
17
|
import {coreDirOrThrow} from '../error.mjs';
|
|
15
18
|
import {CORELESS_DOMAINS} from './_query.mjs';
|
|
@@ -95,7 +98,7 @@ export async function gatherCandidates(options) {
|
|
|
95
98
|
|
|
96
99
|
/**
|
|
97
100
|
* @typedef {Awaited<ReturnType<typeof gatherCandidates>>} Gathered
|
|
98
|
-
* @type {Map<string, {
|
|
101
|
+
* @type {Map<string, (options?: {fresh?: boolean}) => Promise<Gathered>>}
|
|
99
102
|
*/
|
|
100
103
|
const gathered = new Map();
|
|
101
104
|
|
|
@@ -104,30 +107,27 @@ const gathered = new Map();
|
|
|
104
107
|
* folder, for the same `type`, ranks the candidates an earlier search
|
|
105
108
|
* gathered when none of the files that gather read, and none of the folders
|
|
106
109
|
* it listed or probed, changed since (each is checked by its change time and
|
|
107
|
-
* size, so an edited doc in a linked package is seen on the next call).
|
|
110
|
+
* size, so an edited doc in a linked package is seen on the next call). That
|
|
111
|
+
* holds for a gather that is still running too, so searches that start
|
|
112
|
+
* together (a docs site's search right after it starts) share one gather. A
|
|
108
113
|
* long-running caller (a docs site's search, an agent harness) then pays the
|
|
109
114
|
* gather once. A one-shot `astryx search` gathers once, as before.
|
|
110
115
|
* @param {{cwd?: string, type?: string}} options
|
|
111
116
|
* @returns {Promise<Gathered>}
|
|
112
117
|
*/
|
|
113
|
-
export
|
|
118
|
+
export function gatherCandidatesReused(options) {
|
|
114
119
|
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (gathered.get(key)?.value === value) gathered.delete(key);
|
|
125
|
-
throw error;
|
|
120
|
+
const type = options.type;
|
|
121
|
+
const key = `${cwd}\0${type ?? ''}`;
|
|
122
|
+
let gather = gathered.get(key);
|
|
123
|
+
if (!gather) {
|
|
124
|
+
gather = reusedWhileUnchanged(
|
|
125
|
+
() => gatherCandidates({cwd, type}),
|
|
126
|
+
unchangedSince,
|
|
127
|
+
);
|
|
128
|
+
gathered.set(key, gather);
|
|
126
129
|
}
|
|
127
|
-
|
|
128
|
-
// the gather ran shows as a change on the next call.
|
|
129
|
-
gathered.set(key, {reads: seen, value});
|
|
130
|
-
return value;
|
|
130
|
+
return gather();
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
/**
|
|
@@ -26,6 +26,16 @@
|
|
|
26
26
|
|
|
27
27
|
import * as fs from 'node:fs';
|
|
28
28
|
import * as path from 'node:path';
|
|
29
|
+
import {fileStamp, recordContentRead} from '../fs/read-record.mjs';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* What `isAmbient` found for each file, per TypeScript, kept while the
|
|
33
|
+
* file's stamp (`fileStamp`) is the same. A process that compares a package
|
|
34
|
+
* more than once reads the same config each time, and reading a file the way
|
|
35
|
+
* TypeScript does costs far more than a stat.
|
|
36
|
+
* @type {WeakMap<object, Map<string, {stamp: string, ambient: boolean}>>}
|
|
37
|
+
*/
|
|
38
|
+
const ambientByFile = new WeakMap();
|
|
29
39
|
|
|
30
40
|
/**
|
|
31
41
|
* Whether a file the config includes declares types every file sees: a
|
|
@@ -36,6 +46,30 @@ import * as path from 'node:path';
|
|
|
36
46
|
*/
|
|
37
47
|
function isAmbient(ts, file) {
|
|
38
48
|
if (/\.d\.[cm]?ts$/.test(file)) return true;
|
|
49
|
+
// A kept answer still counts as reading the file, so an operation that
|
|
50
|
+
// keeps its own result while what it read is unchanged sees a change to it.
|
|
51
|
+
recordContentRead(file);
|
|
52
|
+
const stamp = fileStamp(file);
|
|
53
|
+
if (stamp === '-') return false;
|
|
54
|
+
let known = ambientByFile.get(ts);
|
|
55
|
+
if (known == null) {
|
|
56
|
+
known = new Map();
|
|
57
|
+
ambientByFile.set(ts, known);
|
|
58
|
+
}
|
|
59
|
+
const key = path.resolve(file);
|
|
60
|
+
const seen = known.get(key);
|
|
61
|
+
if (seen && seen.stamp === stamp) return seen.ambient;
|
|
62
|
+
const ambient = readAmbient(ts, file);
|
|
63
|
+
known.set(key, {stamp, ambient});
|
|
64
|
+
return ambient;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* `isAmbient` for a file that is not a declaration file, read afresh.
|
|
69
|
+
* @param {any} ts
|
|
70
|
+
* @param {string} file
|
|
71
|
+
*/
|
|
72
|
+
function readAmbient(ts, file) {
|
|
39
73
|
let text;
|
|
40
74
|
try {
|
|
41
75
|
text = fs.readFileSync(file, 'utf8');
|
|
@@ -38,8 +38,11 @@ export function recordReads<T>(seen: Map<string, string>, fn: () => T): T;
|
|
|
38
38
|
* read counts as read by the operation that asks for it.
|
|
39
39
|
* @template T
|
|
40
40
|
* @param {() => Promise<T>} load
|
|
41
|
+
* @param {(recorded: Map<string, string>) => boolean} [isUnchanged] - Whether
|
|
42
|
+
* recorded paths are unchanged; `unchangedSince` unless a caller passes the
|
|
43
|
+
* one it imports (so a test of that caller can hold the answer).
|
|
41
44
|
* @returns {(options?: {fresh?: boolean}) => Promise<T>}
|
|
42
45
|
*/
|
|
43
|
-
export function reusedWhileUnchanged<T>(load: () => Promise<T>): (options?: {
|
|
46
|
+
export function reusedWhileUnchanged<T>(load: () => Promise<T>, isUnchanged?: (recorded: Map<string, string>) => boolean): (options?: {
|
|
44
47
|
fresh?: boolean;
|
|
45
48
|
}) => Promise<T>;
|
|
@@ -170,19 +170,23 @@ export function recordReads(seen, fn) {
|
|
|
170
170
|
* read counts as read by the operation that asks for it.
|
|
171
171
|
* @template T
|
|
172
172
|
* @param {() => Promise<T>} load
|
|
173
|
+
* @param {(recorded: Map<string, string>) => boolean} [isUnchanged] - Whether
|
|
174
|
+
* recorded paths are unchanged; `unchangedSince` unless a caller passes the
|
|
175
|
+
* one it imports (so a test of that caller can hold the answer).
|
|
173
176
|
* @returns {(options?: {fresh?: boolean}) => Promise<T>}
|
|
174
177
|
*/
|
|
175
|
-
export function reusedWhileUnchanged(load) {
|
|
178
|
+
export function reusedWhileUnchanged(load, isUnchanged = unchangedSince) {
|
|
176
179
|
/** @type {{reads: Map<string, string>, value: Promise<T>} | undefined} */
|
|
177
180
|
let last;
|
|
178
181
|
return ({fresh = false} = {}) => {
|
|
179
|
-
if (!fresh && last &&
|
|
182
|
+
if (!fresh && last && isUnchanged(last.reads)) {
|
|
180
183
|
const {reads: recorded, value} = last;
|
|
181
184
|
return value.then(result => {
|
|
182
185
|
const runs = reads.getStore();
|
|
183
|
-
if (runs)
|
|
184
|
-
for (const
|
|
185
|
-
|
|
186
|
+
if (runs)
|
|
187
|
+
for (const [file, state] of recorded) {
|
|
188
|
+
for (const seen of runs) if (!seen.has(file)) seen.set(file, state);
|
|
189
|
+
}
|
|
186
190
|
return result;
|
|
187
191
|
});
|
|
188
192
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.6-canary.
|
|
3
|
+
"version": "0.7.6-canary.8835dec",
|
|
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",
|
|
@@ -124,10 +124,10 @@
|
|
|
124
124
|
"zod": "^4.4.3"
|
|
125
125
|
},
|
|
126
126
|
"peerDependencies": {
|
|
127
|
-
"@astryxdesign/charts": "0.7.6-canary.
|
|
128
|
-
"@astryxdesign/core": "0.7.6-canary.
|
|
129
|
-
"@astryxdesign/lab": "0.7.6-canary.
|
|
130
|
-
"@astryxdesign/theme-neutral": "0.7.6-canary.
|
|
127
|
+
"@astryxdesign/charts": "0.7.6-canary.8835dec",
|
|
128
|
+
"@astryxdesign/core": "0.7.6-canary.8835dec",
|
|
129
|
+
"@astryxdesign/lab": "0.7.6-canary.8835dec",
|
|
130
|
+
"@astryxdesign/theme-neutral": "0.7.6-canary.8835dec"
|
|
131
131
|
},
|
|
132
132
|
"peerDependenciesMeta": {
|
|
133
133
|
"@astryxdesign/charts": {
|
|
@@ -144,10 +144,10 @@
|
|
|
144
144
|
}
|
|
145
145
|
},
|
|
146
146
|
"devDependencies": {
|
|
147
|
-
"@astryxdesign/charts": "0.7.6-canary.
|
|
148
|
-
"@astryxdesign/core": "0.7.6-canary.
|
|
149
|
-
"@astryxdesign/lab": "0.7.6-canary.
|
|
150
|
-
"@astryxdesign/theme-neutral": "0.7.6-canary.
|
|
147
|
+
"@astryxdesign/charts": "0.7.6-canary.8835dec",
|
|
148
|
+
"@astryxdesign/core": "0.7.6-canary.8835dec",
|
|
149
|
+
"@astryxdesign/lab": "0.7.6-canary.8835dec",
|
|
150
|
+
"@astryxdesign/theme-neutral": "0.7.6-canary.8835dec",
|
|
151
151
|
"@heroicons/react": "^2.2.0",
|
|
152
152
|
"@stylexjs/stylex": "^0.19.0",
|
|
153
153
|
"@types/babel__core": "^7.20.5",
|