@astryxdesign/cli 0.7.14 → 0.7.15-canary.g47f884a
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 +4 -0
- package/api/build/_adapter.mjs +28 -2
- package/api/build/blocks/blocks.d.mts +10 -1
- package/api/build/blocks/blocks.mjs +84 -7
- package/api/build/build.mjs +6 -1
- package/api/build/tree.d.mts +4 -0
- package/api/build/tree.mjs +9 -2
- package/api/doctor/_adapter.d.mts +1 -0
- package/api/doctor/_adapter.mjs +8 -0
- package/api/doctor/_authoring-audit.d.mts +42 -0
- package/api/doctor/_authoring-audit.mjs +106 -0
- package/api/doctor/doctor.d.mts +7 -0
- package/api/doctor/doctor.mjs +24 -39
- package/api/search/_adapter.mjs +124 -3
- package/api/search/_candidate-score.mjs +63 -9
- package/api/search/_entries.d.mts +10 -0
- package/api/search/_entries.mjs +68 -1
- package/api/search/_gather-templates.d.mts +11 -0
- package/api/search/_gather-templates.mjs +22 -2
- package/api/search/_words.mjs +26 -6
- package/api/swizzle/copy/copy.mjs +1 -1
- package/api/theme/_adapter.mjs +20 -9
- package/api/theme/build/build.d.mts +15 -1
- package/api/theme/build/build.mjs +132 -32
- package/api/theme/targets/targets.d.mts +8 -0
- package/api/theme/targets/targets.mjs +14 -1
- package/api/theme/themeBuild.doc.mjs +6 -3
- package/api/theme/themeEject.doc.mjs +3 -3
- package/api/theme/themeTargets.doc.mjs +1 -1
- package/api/theme-edit/_adapter.d.mts +46 -3
- package/api/theme-edit/_adapter.mjs +372 -109
- package/api/theme-edit/_check.d.mts +6 -3
- package/api/theme-edit/_check.mjs +665 -87
- package/api/theme-edit/_color.mjs +4 -2
- package/api/theme-edit/_compiler.d.mts +2 -1
- package/api/theme-edit/_compiler.mjs +27 -13
- package/api/theme-edit/_context.d.mts +2 -1
- package/api/theme-edit/_context.mjs +47 -8
- package/api/theme-edit/_edit.d.mts +9 -3
- package/api/theme-edit/_edit.mjs +484 -66
- package/api/theme-edit/_how-commands.d.mts +33 -7
- package/api/theme-edit/_how-commands.mjs +57 -45
- package/api/theme-edit/_how-question.d.mts +4 -0
- package/api/theme-edit/_how-question.mjs +1004 -223
- package/api/theme-edit/_how.mjs +96 -9
- package/api/theme-edit/_palette.d.mts +38 -13
- package/api/theme-edit/_palette.mjs +620 -223
- package/api/theme-edit/_parts.mjs +63 -7
- package/api/theme-edit/_png.d.mts +4 -4
- package/api/theme-edit/_png.mjs +4 -2
- package/api/theme-edit/_preview-app.d.mts +6 -0
- package/api/theme-edit/_preview-app.mjs +1194 -207
- package/api/theme-edit/_preview.mjs +2 -2
- package/api/theme-edit/_project.d.mts +12 -1
- package/api/theme-edit/_project.mjs +37 -6
- package/api/theme-edit/_settings.d.mts +104 -33
- package/api/theme-edit/_settings.mjs +818 -118
- package/api/theme-edit/_tables.d.mts +7 -0
- package/api/theme-edit/_tables.mjs +61 -0
- package/api/theme-edit/theme-edit.type.d.mts +11 -1
- package/api/theme-edit/theme-edit.type.mjs +4 -3
- package/api/theme-edit/themeEditHow.doc.mjs +6 -0
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewList.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/api/upgrade/_adapter.d.mts +1 -0
- package/assets/codemods/run-codemod.mjs +61 -0
- package/assets/codemods/runner.mjs +5 -4
- package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
- package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
- package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
- package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
- package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
- package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
- package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
- package/assets/docs/tree/calendars.doc.mjs +1 -3
- package/assets/docs.generated.json +2 -1
- package/assets/self-audit.generated.json +1 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
- package/assets/templates/components.generated.json +1 -1
- package/clients/cli/bin/astryx.mjs +19 -15
- package/clients/cli/build-id.generated.json +1 -0
- package/clients/cli/commands/ensure-core-built.mjs +12 -5
- package/clients/cli/commands/experimental/theme.mjs +178 -78
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
- package/clients/cli/commands/manifest.mjs +5 -2
- package/clients/cli/commands/theme.mjs +118 -22
- package/clients/cli/index.mjs +9 -3
- package/clients/cli/lib/manifest.mjs +37 -0
- package/clients/cli/lib/resolve-theme.mjs +2 -1
- package/clients/cli/manifest.generated.json +1 -0
- package/foundation/discovery/module-exports.mjs +16 -2
- package/foundation/discovery/stored-self-audit.d.mts +31 -0
- package/foundation/discovery/stored-self-audit.mjs +119 -0
- package/foundation/discovery/template-adapter.d.mts +48 -2
- package/foundation/discovery/template-adapter.mjs +51 -19
- package/foundation/discovery/template-needs.d.mts +6 -0
- package/foundation/discovery/template-needs.mjs +20 -1
- package/foundation/discovery/template-source-tree.d.mts +7 -0
- package/foundation/discovery/template-source-tree.mjs +15 -0
- package/foundation/discovery/theme-discovery.d.mts +2 -1
- package/foundation/discovery/theme-discovery.mjs +2 -8
- package/foundation/discovery/theme-module-extensions.d.mts +18 -0
- package/foundation/discovery/theme-module-extensions.mjs +30 -0
- package/foundation/doc-compiler/import.mjs +12 -11
- package/foundation/doc-compiler/stored-docs.d.mts +18 -12
- package/foundation/doc-compiler/stored-docs.mjs +52 -19
- package/foundation/env/private-dir.d.mts +17 -0
- package/foundation/env/private-dir.mjs +42 -0
- package/foundation/fs/gather-cache.d.mts +108 -0
- package/foundation/fs/gather-cache.mjs +724 -0
- package/foundation/fs/module-loader.mjs +7 -1
- package/foundation/fs/read-record.d.mts +31 -1
- package/foundation/fs/read-record.mjs +100 -7
- package/foundation/integrations/validate-contributions.mjs +24 -11
- package/foundation/release/cache.d.mts +11 -2
- package/foundation/release/cache.mjs +59 -10
- package/foundation/release/folder-lock.d.mts +21 -0
- package/foundation/release/folder-lock.mjs +171 -0
- package/package.json +8 -6
package/api/search/_adapter.mjs
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
* domain, _gather-*.mjs) and loads the tree's static data before it runs.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {readFileSync} from 'node:fs';
|
|
9
|
+
import {readFileSync, realpathSync} from 'node:fs';
|
|
10
10
|
import * as path from 'node:path';
|
|
11
11
|
import {requireCoreDir} from '../../foundation/fs/paths.mjs';
|
|
12
12
|
import {withListingCache} from '../../foundation/fs/listing-cache.mjs';
|
|
13
|
+
import {persistedGather} from '../../foundation/fs/gather-cache.mjs';
|
|
13
14
|
import {
|
|
14
15
|
reusedWhileUnchanged,
|
|
15
16
|
unchangedSince,
|
|
@@ -21,7 +22,12 @@ import {CORELESS_DOMAINS} from './_query.mjs';
|
|
|
21
22
|
import {gatherComponents} from './_gather-components.mjs';
|
|
22
23
|
import {gatherHooks} from './_gather-hooks.mjs';
|
|
23
24
|
import {gatherDocs} from './_gather-docs.mjs';
|
|
24
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
derivedFromSource,
|
|
27
|
+
gatherTemplates,
|
|
28
|
+
gatherThemes,
|
|
29
|
+
} from './_gather-templates.mjs';
|
|
30
|
+
import {componentsInSource} from '../../foundation/discovery/template-adapter.mjs';
|
|
25
31
|
|
|
26
32
|
export {componentKeywords} from './_gather-components.mjs';
|
|
27
33
|
|
|
@@ -124,6 +130,112 @@ async function gatherDomains(options) {
|
|
|
124
130
|
};
|
|
125
131
|
}
|
|
126
132
|
|
|
133
|
+
/**
|
|
134
|
+
* The folder's real path, so a link and its target share a kept gather.
|
|
135
|
+
* @param {string} dir
|
|
136
|
+
* @returns {string}
|
|
137
|
+
*/
|
|
138
|
+
function realFolder(dir) {
|
|
139
|
+
try {
|
|
140
|
+
return realpathSync(dir);
|
|
141
|
+
} catch {
|
|
142
|
+
return dir;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* A gathered catalog as plain JSON and back, for a gather kept between runs
|
|
148
|
+
* (persistedGather). A template's derived component names are read once and
|
|
149
|
+
* stored as their value; `components` is stored by position in `all`, whose
|
|
150
|
+
* objects it shares.
|
|
151
|
+
*/
|
|
152
|
+
const GATHER_CODEC = {
|
|
153
|
+
/**
|
|
154
|
+
* @param {any} gathered
|
|
155
|
+
* @returns {any}
|
|
156
|
+
*/
|
|
157
|
+
encode(gathered) {
|
|
158
|
+
const position = new Map(
|
|
159
|
+
gathered.all.map((/** @type {any} */ c, /** @type {number} */ i) => [
|
|
160
|
+
c,
|
|
161
|
+
i,
|
|
162
|
+
]),
|
|
163
|
+
);
|
|
164
|
+
return {
|
|
165
|
+
...gathered,
|
|
166
|
+
all: gathered.all.map((/** @type {any} */ c) => {
|
|
167
|
+
if (!Object.getOwnPropertyDescriptor(c, 'weakKeywords')?.get) return c;
|
|
168
|
+
// The names come from the source file, read again when first asked
|
|
169
|
+
// for (its content is one of the stored inputs); a source that could
|
|
170
|
+
// not be read derives none.
|
|
171
|
+
const from = derivedFromSource.get(c);
|
|
172
|
+
const names = from?.derivedSoFar();
|
|
173
|
+
/** @type {Record<string, unknown>} */
|
|
174
|
+
const out = {};
|
|
175
|
+
for (const k of Object.keys(c)) {
|
|
176
|
+
out[k] =
|
|
177
|
+
k === 'weakKeywords'
|
|
178
|
+
? {[DERIVED]: names ?? from?.file ?? null}
|
|
179
|
+
: c[k];
|
|
180
|
+
}
|
|
181
|
+
return out;
|
|
182
|
+
}),
|
|
183
|
+
components: gathered.components.map((/** @type {any} */ c) =>
|
|
184
|
+
position.get(c),
|
|
185
|
+
),
|
|
186
|
+
};
|
|
187
|
+
},
|
|
188
|
+
/**
|
|
189
|
+
* @param {any} stored
|
|
190
|
+
* @returns {any}
|
|
191
|
+
*/
|
|
192
|
+
decode(stored) {
|
|
193
|
+
const all = stored.all.map((/** @type {any} */ c) => {
|
|
194
|
+
const stored = c.weakKeywords?.[DERIVED];
|
|
195
|
+
if (stored === undefined) return c;
|
|
196
|
+
// Names read by the run that stored them, or the file to read them from.
|
|
197
|
+
const file = typeof stored === 'string' ? stored : null;
|
|
198
|
+
/** @type {string[] | undefined} */
|
|
199
|
+
let derived = Array.isArray(stored) ? stored : undefined;
|
|
200
|
+
const derive = () => {
|
|
201
|
+
if (derived === undefined) {
|
|
202
|
+
try {
|
|
203
|
+
derived =
|
|
204
|
+
file == null
|
|
205
|
+
? []
|
|
206
|
+
: componentsInSource(readFileSync(file, 'utf-8'));
|
|
207
|
+
} catch {
|
|
208
|
+
derived = [];
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return derived;
|
|
212
|
+
};
|
|
213
|
+
/** @type {Record<string, unknown>} */
|
|
214
|
+
const out = {};
|
|
215
|
+
for (const k of Object.keys(c)) {
|
|
216
|
+
if (k === 'weakKeywords') {
|
|
217
|
+
Object.defineProperty(out, k, {
|
|
218
|
+
get: derive,
|
|
219
|
+
enumerable: true,
|
|
220
|
+
configurable: true,
|
|
221
|
+
});
|
|
222
|
+
} else {
|
|
223
|
+
out[k] = c[k];
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return out;
|
|
227
|
+
});
|
|
228
|
+
return {
|
|
229
|
+
...stored,
|
|
230
|
+
all,
|
|
231
|
+
components: stored.components.map((/** @type {number} */ i) => all[i]),
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
/** The key a stored template's derived component names sit under. */
|
|
237
|
+
const DERIVED = '\0derived';
|
|
238
|
+
|
|
127
239
|
/**
|
|
128
240
|
* @typedef {Awaited<ReturnType<typeof gatherCandidates>>} Gathered
|
|
129
241
|
* @type {Map<string, (options?: {fresh?: boolean}) => Promise<Gathered>>}
|
|
@@ -150,7 +262,16 @@ export function gatherCandidatesReused(options) {
|
|
|
150
262
|
let gather = gathered.get(key);
|
|
151
263
|
if (!gather) {
|
|
152
264
|
gather = reusedWhileUnchanged(
|
|
153
|
-
() =>
|
|
265
|
+
() =>
|
|
266
|
+
persistedGather(
|
|
267
|
+
[realFolder(cwd), type ?? null],
|
|
268
|
+
() => gatherCandidates({cwd, type}),
|
|
269
|
+
GATHER_CODEC,
|
|
270
|
+
// A gather that skipped Core (a failed install still in its
|
|
271
|
+
// backoff, spec:AST-081 FR2) is not kept: once the backoff ends,
|
|
272
|
+
// the next run must try again.
|
|
273
|
+
value => value.coreSkipped == null,
|
|
274
|
+
),
|
|
154
275
|
unchangedSince,
|
|
155
276
|
);
|
|
156
277
|
gathered.set(key, gather);
|
|
@@ -94,6 +94,65 @@ function headOfLetters(t, name) {
|
|
|
94
94
|
/** How many of a family's members a query naming the family lists. */
|
|
95
95
|
const FAMILY_MEMBERS = 3;
|
|
96
96
|
|
|
97
|
+
/**
|
|
98
|
+
* The pattern that finds any form of a term as a whole word in prose, with
|
|
99
|
+
* any common suffix, built once per term: a search tests it against every
|
|
100
|
+
* candidate's description.
|
|
101
|
+
* @type {Map<string, RegExp>}
|
|
102
|
+
*/
|
|
103
|
+
const mentionPatterns = new Map();
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* How many terms' patterns are kept before the cache starts over. A compiled
|
|
107
|
+
* pattern is several kilobytes and a long-running caller sees ever new
|
|
108
|
+
* terms, so this cache stays small; one search uses a handful of terms.
|
|
109
|
+
*/
|
|
110
|
+
const MENTION_LIMIT = 1_000;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @param {string} term
|
|
114
|
+
* @param {ReturnType<typeof termWords>} t - the term's words
|
|
115
|
+
* @returns {RegExp}
|
|
116
|
+
*/
|
|
117
|
+
function mentionPattern(term, t) {
|
|
118
|
+
let re = mentionPatterns.get(term);
|
|
119
|
+
if (!re) {
|
|
120
|
+
if (mentionPatterns.size >= MENTION_LIMIT) mentionPatterns.clear();
|
|
121
|
+
// Any form of the term, with any common suffix: `spacing` finds
|
|
122
|
+
// "space" and "spaces", `tables` finds "table".
|
|
123
|
+
const roots = [...new Set([stem(term), ...t.forms])]
|
|
124
|
+
.filter(f => f.length >= 3)
|
|
125
|
+
.map(f => f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
126
|
+
re = new RegExp(`\\b(?:${roots.join('|')})(s|es|ing|ed|ies)?\\b`);
|
|
127
|
+
mentionPatterns.set(term, re);
|
|
128
|
+
}
|
|
129
|
+
return re;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Each prose text lowercased once per process: a search reads every
|
|
134
|
+
* candidate's description for every term.
|
|
135
|
+
* @type {Map<string, string>}
|
|
136
|
+
*/
|
|
137
|
+
const lowered = new Map();
|
|
138
|
+
|
|
139
|
+
/** How many texts are kept lowercased before the cache starts over. */
|
|
140
|
+
const CACHE_LIMIT = 100_000;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @param {string} text
|
|
144
|
+
* @returns {string}
|
|
145
|
+
*/
|
|
146
|
+
function lower(text) {
|
|
147
|
+
let out = lowered.get(text);
|
|
148
|
+
if (out === undefined) {
|
|
149
|
+
if (lowered.size >= CACHE_LIMIT) lowered.clear();
|
|
150
|
+
out = text.toLowerCase();
|
|
151
|
+
lowered.set(text, out);
|
|
152
|
+
}
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
|
|
97
156
|
/**
|
|
98
157
|
* A derived name's score for a term: 60 for the same word, 40 for a word the
|
|
99
158
|
* term starts, else 0.
|
|
@@ -308,18 +367,13 @@ export function scoreCandidate(
|
|
|
308
367
|
// Match the term's stem as a whole word, tolerating plural/gerund suffixes
|
|
309
368
|
// so "chart" matches "charts" and "filter" matches "filtering".
|
|
310
369
|
if (term.length >= 3) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const roots = [...new Set([stem(term), ...t.forms])]
|
|
314
|
-
.filter(f => f.length >= 3)
|
|
315
|
-
.map(f => f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
316
|
-
const re = new RegExp(`\\b(?:${roots.join('|')})(s|es|ing|ed|ies)?\\b`);
|
|
317
|
-
if (description && re.test(description.toLowerCase())) {
|
|
370
|
+
const re = mentionPattern(term, t);
|
|
371
|
+
if (description && re.test(lower(description))) {
|
|
318
372
|
consider(50, `description mentions "${term}"`);
|
|
319
373
|
} else {
|
|
320
374
|
let matchedProse = false;
|
|
321
375
|
for (const blob of prose) {
|
|
322
|
-
if (blob && re.test(String(blob)
|
|
376
|
+
if (blob && re.test(lower(String(blob)))) {
|
|
323
377
|
consider(50, `docs mention "${term}"`);
|
|
324
378
|
matchedProse = true;
|
|
325
379
|
break;
|
|
@@ -330,7 +384,7 @@ export function scoreCandidate(
|
|
|
330
384
|
// summary. Only consulted when nothing stronger matched.
|
|
331
385
|
if (!matchedProse) {
|
|
332
386
|
for (const blob of guidance) {
|
|
333
|
-
if (blob && re.test(String(blob)
|
|
387
|
+
if (blob && re.test(lower(String(blob)))) {
|
|
334
388
|
consider(45, `guidance mentions "${term}"`);
|
|
335
389
|
break;
|
|
336
390
|
}
|
|
@@ -13,6 +13,16 @@ export function entryTable(all: any[], cards: Record<string, {
|
|
|
13
13
|
synonyms?: string[];
|
|
14
14
|
props?: string[];
|
|
15
15
|
}>): EntryTable;
|
|
16
|
+
/**
|
|
17
|
+
* A table's plain-JSON form and back. Candidates are kept as their place in
|
|
18
|
+
* `all`, maps as their entries in order, so the table reads back the same.
|
|
19
|
+
* @param {any[]} all
|
|
20
|
+
* @returns {{encode: (table: EntryTable) => any, decode: (stored: any) => EntryTable}}
|
|
21
|
+
*/
|
|
22
|
+
export function tableCodec(all: any[]): {
|
|
23
|
+
encode: (table: EntryTable) => any;
|
|
24
|
+
decode: (stored: any) => EntryTable;
|
|
25
|
+
};
|
|
16
26
|
/**
|
|
17
27
|
* @param {any[]} all
|
|
18
28
|
* @param {Record<string, {what?: string, synonyms?: string[], props?: string[]}>} cards
|
package/api/search/_entries.mjs
CHANGED
|
@@ -8,6 +8,16 @@
|
|
|
8
8
|
|
|
9
9
|
import {createHash} from 'node:crypto';
|
|
10
10
|
import {DOMAINS, words, fold, nameWords} from './_query-words.mjs';
|
|
11
|
+
import {fileURLToPath} from 'node:url';
|
|
12
|
+
import {persistedDerived} from '../../foundation/fs/gather-cache.mjs';
|
|
13
|
+
|
|
14
|
+
/** This module and the word rules it builds entries with, by path. */
|
|
15
|
+
const ENTRIES_FILE = fileURLToPath(import.meta.url);
|
|
16
|
+
const QUERY_WORDS_FILE = fileURLToPath(
|
|
17
|
+
new URL('./_query-words.mjs', import.meta.url),
|
|
18
|
+
);
|
|
19
|
+
/** The cards search reads (./_adapter.mjs), by path. */
|
|
20
|
+
const CARDS_FILE = fileURLToPath(new URL('./_cards.json', import.meta.url));
|
|
11
21
|
|
|
12
22
|
/** @param {string[]} list @returns {Map<string, number>} */
|
|
13
23
|
const counts = list => {
|
|
@@ -65,7 +75,16 @@ export function entryTable(all, cards) {
|
|
|
65
75
|
tables.set(all, last.table);
|
|
66
76
|
return last.table;
|
|
67
77
|
}
|
|
68
|
-
|
|
78
|
+
// The table is a function of the text it is built from: kept beside the
|
|
79
|
+
// catalog, a later run with the same catalog reads it back.
|
|
80
|
+
const built = persistedDerived(
|
|
81
|
+
['entry-table', key],
|
|
82
|
+
() => buildTable(all, cards),
|
|
83
|
+
tableCodec(all),
|
|
84
|
+
// The code that builds it, loaded or not when the table is kept, and the
|
|
85
|
+
// cards it reads, which search reads after the catalog is kept.
|
|
86
|
+
[ENTRIES_FILE, QUERY_WORDS_FILE, CARDS_FILE],
|
|
87
|
+
);
|
|
69
88
|
last = {key, table: built};
|
|
70
89
|
tables.set(all, built);
|
|
71
90
|
return built;
|
|
@@ -73,6 +92,54 @@ export function entryTable(all, cards) {
|
|
|
73
92
|
|
|
74
93
|
/** @type {{key: string, table: EntryTable} | null} */
|
|
75
94
|
let last = null;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A table's plain-JSON form and back. Candidates are kept as their place in
|
|
98
|
+
* `all`, maps as their entries in order, so the table reads back the same.
|
|
99
|
+
* @param {any[]} all
|
|
100
|
+
* @returns {{encode: (table: EntryTable) => any, decode: (stored: any) => EntryTable}}
|
|
101
|
+
*/
|
|
102
|
+
export function tableCodec(all) {
|
|
103
|
+
return {
|
|
104
|
+
encode(table) {
|
|
105
|
+
const place = new Map(all.map((c, k) => [c, k]));
|
|
106
|
+
const t = /** @type {any} */ (table);
|
|
107
|
+
return {
|
|
108
|
+
ids: t.ids,
|
|
109
|
+
candidate: t.candidate.map((/** @type {any} */ c) => place.get(c)),
|
|
110
|
+
domain: t.domain,
|
|
111
|
+
name: t.name,
|
|
112
|
+
fields: Object.fromEntries(
|
|
113
|
+
Object.entries(t.fields).map(([f, {post, idf, len, avg}]) => [
|
|
114
|
+
f,
|
|
115
|
+
{post: [...post], idf: [...idf], len, avg},
|
|
116
|
+
]),
|
|
117
|
+
),
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
decode(stored) {
|
|
121
|
+
return /** @type {EntryTable} */ (
|
|
122
|
+
/** @type {unknown} */ ({
|
|
123
|
+
ids: stored.ids,
|
|
124
|
+
index: new Map(
|
|
125
|
+
stored.ids.map(
|
|
126
|
+
(/** @type {string} */ id, /** @type {number} */ k) => [id, k],
|
|
127
|
+
),
|
|
128
|
+
),
|
|
129
|
+
candidate: stored.candidate.map((/** @type {number} */ k) => all[k]),
|
|
130
|
+
domain: stored.domain,
|
|
131
|
+
name: stored.name,
|
|
132
|
+
fields: Object.fromEntries(
|
|
133
|
+
Object.entries(stored.fields).map(([f, {post, idf, len, avg}]) => [
|
|
134
|
+
f,
|
|
135
|
+
{post: new Map(post), idf: new Map(idf), len, avg},
|
|
136
|
+
]),
|
|
137
|
+
),
|
|
138
|
+
})
|
|
139
|
+
);
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
76
143
|
/** @type {WeakMap<object, number>} */
|
|
77
144
|
const cardIds = new WeakMap();
|
|
78
145
|
let nextCardId = 0;
|
|
@@ -21,4 +21,15 @@ export function gatherTemplates(cwd: string): Promise<Candidate[]>;
|
|
|
21
21
|
* @returns {Promise<Candidate[]>}
|
|
22
22
|
*/
|
|
23
23
|
export function gatherThemes(cwd: string): Promise<Candidate[]>;
|
|
24
|
+
/**
|
|
25
|
+
* The source file each template candidate's `weakKeywords` are read from,
|
|
26
|
+
* when it could be read, and the names if this run already read them: a
|
|
27
|
+
* gather kept between runs stores the names it has and the file for the rest
|
|
28
|
+
* (api/search/_adapter.mjs), so storing costs no parse.
|
|
29
|
+
* @type {WeakMap<object, {file: string, derivedSoFar: () => string[] | undefined}>}
|
|
30
|
+
*/
|
|
31
|
+
export const derivedFromSource: WeakMap<object, {
|
|
32
|
+
file: string;
|
|
33
|
+
derivedSoFar: () => string[] | undefined;
|
|
34
|
+
}>;
|
|
24
35
|
export type Candidate = import("./_lexical.mjs").Candidate;
|
|
@@ -15,6 +15,14 @@ import {
|
|
|
15
15
|
} from '../../foundation/discovery/template-adapter.mjs';
|
|
16
16
|
import {sameWord, wordsOf} from './_words.mjs';
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* The source file each template candidate's `weakKeywords` are read from,
|
|
20
|
+
* when it could be read, and the names if this run already read them: a
|
|
21
|
+
* gather kept between runs stores the names it has and the file for the rest
|
|
22
|
+
* (api/search/_adapter.mjs), so storing costs no parse.
|
|
23
|
+
* @type {WeakMap<object, {file: string, derivedSoFar: () => string[] | undefined}>}
|
|
24
|
+
*/
|
|
25
|
+
export const derivedFromSource = new WeakMap();
|
|
18
26
|
/** @typedef {import('./_lexical.mjs').Candidate} Candidate */
|
|
19
27
|
|
|
20
28
|
/**
|
|
@@ -75,14 +83,20 @@ export async function gatherTemplates(cwd) {
|
|
|
75
83
|
let derive = () => [];
|
|
76
84
|
/** @type {string[] | null} */
|
|
77
85
|
let weakKeywordBound = null;
|
|
86
|
+
/** @type {string | null} */
|
|
87
|
+
let readSource = null;
|
|
88
|
+
/** @type {(() => string[] | undefined) | undefined} */
|
|
89
|
+
let derivedNow;
|
|
78
90
|
if (t.type === 'page') {
|
|
79
91
|
if (t.filePath) {
|
|
80
92
|
try {
|
|
81
93
|
const source = fs.readFileSync(t.filePath, 'utf-8');
|
|
94
|
+
readSource = t.filePath;
|
|
82
95
|
// Parsing the source costs more than the rest of the page's gather.
|
|
83
96
|
// It waits until a term could match a name the source can yield.
|
|
84
97
|
/** @type {string[] | undefined} */
|
|
85
98
|
let derived;
|
|
99
|
+
derivedNow = () => derived;
|
|
86
100
|
derive = () => {
|
|
87
101
|
if (derived === undefined) {
|
|
88
102
|
try {
|
|
@@ -101,8 +115,8 @@ export async function gatherTemplates(cwd) {
|
|
|
101
115
|
if (t.category)
|
|
102
116
|
keywords.push(...t.category.split(/[^A-Za-z0-9]+/).filter(Boolean));
|
|
103
117
|
}
|
|
104
|
-
|
|
105
|
-
domain: 'template',
|
|
118
|
+
const candidate = {
|
|
119
|
+
domain: /** @type {const} */ ('template'),
|
|
106
120
|
name: commandName,
|
|
107
121
|
keywords,
|
|
108
122
|
get weakKeywords() {
|
|
@@ -123,6 +137,12 @@ export async function gatherTemplates(cwd) {
|
|
|
123
137
|
_resultName: t.dirName,
|
|
124
138
|
_commandName: commandName,
|
|
125
139
|
};
|
|
140
|
+
if (readSource)
|
|
141
|
+
derivedFromSource.set(candidate, {
|
|
142
|
+
file: readSource,
|
|
143
|
+
derivedSoFar: () => derivedNow?.(),
|
|
144
|
+
});
|
|
145
|
+
return candidate;
|
|
126
146
|
});
|
|
127
147
|
}
|
|
128
148
|
|
package/api/search/_words.mjs
CHANGED
|
@@ -136,14 +136,34 @@ export function sameTermWord(t, w) {
|
|
|
136
136
|
* @returns {string[]}
|
|
137
137
|
*/
|
|
138
138
|
export function wordsOf(text) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
.
|
|
143
|
-
.
|
|
144
|
-
.
|
|
139
|
+
const key = String(text);
|
|
140
|
+
let words = splitWords.get(key);
|
|
141
|
+
if (words === undefined) {
|
|
142
|
+
// A long-running caller ranks many queries; start over rather than grow.
|
|
143
|
+
if (splitWords.size >= SPLIT_WORDS_LIMIT) splitWords.clear();
|
|
144
|
+
words = Object.freeze(
|
|
145
|
+
key
|
|
146
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
147
|
+
.replace(/([A-Z])([A-Z][a-z])/g, '$1 $2')
|
|
148
|
+
.toLowerCase()
|
|
149
|
+
.split(/[^a-z0-9]+/)
|
|
150
|
+
.filter(Boolean),
|
|
151
|
+
);
|
|
152
|
+
splitWords.set(key, words);
|
|
153
|
+
}
|
|
154
|
+
return /** @type {string[]} */ (words);
|
|
145
155
|
}
|
|
146
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Each text's words, split once per process: a search splits the same names
|
|
159
|
+
* and keywords for every term of every query.
|
|
160
|
+
* @type {Map<string, readonly string[]>}
|
|
161
|
+
*/
|
|
162
|
+
const splitWords = new Map();
|
|
163
|
+
|
|
164
|
+
/** How many texts' words are kept before the cache starts over. */
|
|
165
|
+
const SPLIT_WORDS_LIMIT = 100_000;
|
|
166
|
+
|
|
147
167
|
/**
|
|
148
168
|
* Whether a term is found inside a name or keyword: it is one of its words, or
|
|
149
169
|
* the start of one (a truncation), and covers at least half of the whole
|
|
@@ -554,7 +554,7 @@ export async function swizzleCopy(component, options = {}) {
|
|
|
554
554
|
for (const dir of [...createdDirs].reverse()) {
|
|
555
555
|
fs.rmSync(dir, {recursive: true, force: true});
|
|
556
556
|
}
|
|
557
|
-
if (!outputDirExisted) {
|
|
557
|
+
if (!outputDirExisted && fs.existsSync(outputDir)) {
|
|
558
558
|
fs.rmSync(outputDir, {recursive: true, force: true});
|
|
559
559
|
}
|
|
560
560
|
throw writeFailed(output.dest, cwd, err, unrestored);
|
package/api/theme/_adapter.mjs
CHANGED
|
@@ -403,8 +403,9 @@ export default {
|
|
|
403
403
|
* @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme} theme
|
|
404
404
|
* @param {string} dir
|
|
405
405
|
* @param {string} cwd
|
|
406
|
+
* @param {string} projectDir the project root the default target is in
|
|
406
407
|
*/
|
|
407
|
-
function assertEjectTargetFree(theme, dir, cwd) {
|
|
408
|
+
function assertEjectTargetFree(theme, dir, cwd, projectDir) {
|
|
408
409
|
/** @type {string[]} */
|
|
409
410
|
let entries;
|
|
410
411
|
try {
|
|
@@ -415,7 +416,8 @@ function assertEjectTargetFree(theme, dir, cwd) {
|
|
|
415
416
|
}
|
|
416
417
|
const rel = path.relative(cwd, dir) || '.';
|
|
417
418
|
const isDefault =
|
|
418
|
-
path.resolve(
|
|
419
|
+
path.resolve(projectDir, defaultEjectTarget(theme.slug)) ===
|
|
420
|
+
path.resolve(dir);
|
|
419
421
|
const suggestion = isDefault
|
|
420
422
|
? undefined
|
|
421
423
|
: [
|
|
@@ -472,17 +474,26 @@ function themeDescriptorName(file) {
|
|
|
472
474
|
* @returns {string} project-relative output directory
|
|
473
475
|
*/
|
|
474
476
|
export function ejectThemeFiles(theme, {cwd, targetPath, overwrite = false}) {
|
|
477
|
+
// The fork lands in the project, as list and add read it: the default root
|
|
478
|
+
// is the project's, and a relative [path] is read from the working folder
|
|
479
|
+
// but must stay inside the project.
|
|
480
|
+
const projectDir = findPackageRoot(cwd) ?? path.resolve(cwd);
|
|
481
|
+
const target = !targetPath
|
|
482
|
+
? defaultEjectTarget(theme.slug)
|
|
483
|
+
: path.isAbsolute(targetPath)
|
|
484
|
+
? targetPath
|
|
485
|
+
: path.relative(projectDir, path.resolve(cwd, targetPath)) || '.';
|
|
475
486
|
let resolvedDir;
|
|
476
487
|
try {
|
|
477
|
-
resolvedDir = assertWithin(
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
{label: 'theme target path'},
|
|
481
|
-
);
|
|
488
|
+
resolvedDir = assertWithin(target, projectDir, {
|
|
489
|
+
label: 'theme target path',
|
|
490
|
+
});
|
|
482
491
|
} catch (error) {
|
|
483
492
|
if (error instanceof PathSafetyError) {
|
|
484
493
|
throw new AstryxError(
|
|
485
|
-
|
|
494
|
+
targetPath
|
|
495
|
+
? error.message.replace(`"${target}"`, `"${targetPath}"`)
|
|
496
|
+
: error.message,
|
|
486
497
|
undefined,
|
|
487
498
|
ERROR_CODES.ERR_PATH_TRAVERSAL,
|
|
488
499
|
);
|
|
@@ -521,7 +532,7 @@ export function ejectThemeFiles(theme, {cwd, targetPath, overwrite = false}) {
|
|
|
521
532
|
}
|
|
522
533
|
}
|
|
523
534
|
|
|
524
|
-
assertEjectTargetFree(theme, resolvedDir, cwd);
|
|
535
|
+
assertEjectTargetFree(theme, resolvedDir, cwd, projectDir);
|
|
525
536
|
|
|
526
537
|
if (!overwrite) {
|
|
527
538
|
const existing = writes.find(write => fs.existsSync(write.dest));
|
|
@@ -48,6 +48,16 @@ export function coreUnavailableMessage(cwd: string, importError: any): string;
|
|
|
48
48
|
* @returns {string}
|
|
49
49
|
*/
|
|
50
50
|
export function normalizeThemeBuildForCompare(content: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Theme sources a missing build input probably meant, relative to `cwd`: the
|
|
53
|
+
* same path with `/` for `\`; or, for a bare theme name, the theme sources in
|
|
54
|
+
* `themes/<name>/` and `src/themes/<name>/` of the project, and `<name>` with a
|
|
55
|
+
* theme source extension. A build output is never offered.
|
|
56
|
+
* @param {string} file the input as given
|
|
57
|
+
* @param {string} cwd
|
|
58
|
+
* @returns {string[]} at most three paths
|
|
59
|
+
*/
|
|
60
|
+
export function themeSourceGuesses(file: string, cwd: string): string[];
|
|
51
61
|
/**
|
|
52
62
|
* Import specifier for install/scaffold instructions. Drops a leading `src/`
|
|
53
63
|
* from the cwd-relative dir (most consumers import from a file under src/) but
|
|
@@ -144,12 +154,16 @@ export function themeBuild(file: string, options?: {
|
|
|
144
154
|
cwd?: string;
|
|
145
155
|
projectCore?: boolean;
|
|
146
156
|
}): Promise<import("../theme.type.mjs").ThemeBuildResponse | import("../theme.type.mjs").ThemeBuildCheckResponse | null>;
|
|
147
|
-
/** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __onPrivateVarError?: () => void}} options @param {{cwd?: string}} [ctx] */
|
|
157
|
+
/** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __onPrivateVarError?: () => void, __commandWords?: {group: string, build: string}}} options @param {{cwd?: string}} [ctx] */
|
|
148
158
|
export function themeBuildFamily(files: string[], options: {
|
|
149
159
|
familyKey: string;
|
|
150
160
|
check?: boolean;
|
|
151
161
|
iconsSpecifier?: string;
|
|
152
162
|
__onPrivateVarError?: () => void;
|
|
163
|
+
__commandWords?: {
|
|
164
|
+
group: string;
|
|
165
|
+
build: string;
|
|
166
|
+
};
|
|
153
167
|
}, { cwd }?: {
|
|
154
168
|
cwd?: string;
|
|
155
169
|
}): Promise<{
|