@astryxdesign/cli 0.7.4-canary.1b56e00 → 0.7.4-canary.20230c6

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.
@@ -17,7 +17,7 @@
17
17
  * @param {string} [candidate.description]
18
18
  * @param {string[]} [candidate.prose] - Extra free-text blobs (doc section text, best practices).
19
19
  * @param {string[]} [candidate.guidance] - Usage guidance (features, best practices) — scored a tier below description.
20
- * @param {{fuzzy?: boolean, joins?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false. `joins`: read a spaced query joined into a name or keyword (default true); off when the query names an entry outright.
20
+ * @param {{fuzzy?: boolean, joins?: boolean, part?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false. `joins`: read a spaced query joined into a name or keyword (default true); off when the query names an entry outright. `part`: the term is one word of a longer query, so a name's head word after single letters (Stack in VStack) does not count as a keyword hit for it.
21
21
  * @returns {{score: number, reason: string, alias?: 'partial' | 'keyword'} | null}
22
22
  * `alias` marks a hit that read the query's words joined.
23
23
  */
@@ -30,9 +30,10 @@ export function scoreCandidate(term: string, { name, aliases, domain, keywords,
30
30
  description?: string | undefined;
31
31
  prose?: string[] | undefined;
32
32
  guidance?: string[] | undefined;
33
- }, { fuzzy, joins }?: {
33
+ }, { fuzzy, joins, part }?: {
34
34
  fuzzy?: boolean;
35
35
  joins?: boolean;
36
+ part?: boolean;
36
37
  }): {
37
38
  score: number;
38
39
  reason: string;
@@ -41,11 +41,56 @@ import {
41
41
  wordForms,
42
42
  sameWord,
43
43
  startsAWordOf,
44
+ wordsOf,
44
45
  joined,
45
46
  isTypo,
46
47
  } from './_words.mjs';
47
48
  import {pluralOf} from './_query.mjs';
48
49
 
50
+ /**
51
+ * Whether a multi-word term spells out a name word by word: as many words as
52
+ * the name, each the name's word in order or, for a single-letter word, a word
53
+ * starting with that letter ("vertical" for V) that the entry's own
54
+ * description names. `vertical stack` spells out VStack when its description says
55
+ * "vertical"; `visual stack` does not.
56
+ * @param {string} term
57
+ * @param {string} name
58
+ * @param {string} description
59
+ */
60
+ function spellsOut(term, name, description) {
61
+ const words = term.split(/\s+/).filter(Boolean);
62
+ const parts = wordsOf(name);
63
+ if (words.length < 2 || words.length !== parts.length) return false;
64
+ const described = wordsOf(description);
65
+ let expanded = false;
66
+ for (let i = 0; i < words.length; i++) {
67
+ const w = words[i];
68
+ const p = parts[i];
69
+ if (sameWord(w, p)) continue;
70
+ // Only a single-letter word is an abbreviation to spell out: "With" in a
71
+ // name is not spelled out by "without".
72
+ if (p.length !== 1 || !w.startsWith(p)) return false;
73
+ if (!described.some(d => sameWord(d, w))) return false;
74
+ expanded = true;
75
+ }
76
+ return expanded;
77
+ }
78
+
79
+ /**
80
+ * Whether a one-word term is a name's last word and every word before it is a
81
+ * single letter: Stack in VStack and HStack.
82
+ * @param {string} term
83
+ * @param {string} name
84
+ */
85
+ function headOfLetters(term, name) {
86
+ const parts = wordsOf(name);
87
+ return (
88
+ parts.length >= 2 &&
89
+ sameWord(term, parts[parts.length - 1]) &&
90
+ parts.slice(0, -1).every(p => p.length === 1)
91
+ );
92
+ }
93
+
49
94
  /**
50
95
  * Score a single candidate against the search term across name, keywords,
51
96
  * and prose signals. Returns the best (highest) score plus a human reason,
@@ -62,7 +107,7 @@ import {pluralOf} from './_query.mjs';
62
107
  * @param {string} [candidate.description]
63
108
  * @param {string[]} [candidate.prose] - Extra free-text blobs (doc section text, best practices).
64
109
  * @param {string[]} [candidate.guidance] - Usage guidance (features, best practices) — scored a tier below description.
65
- * @param {{fuzzy?: boolean, joins?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false. `joins`: read a spaced query joined into a name or keyword (default true); off when the query names an entry outright.
110
+ * @param {{fuzzy?: boolean, joins?: boolean, part?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false. `joins`: read a spaced query joined into a name or keyword (default true); off when the query names an entry outright. `part`: the term is one word of a longer query, so a name's head word after single letters (Stack in VStack) does not count as a keyword hit for it.
66
111
  * @returns {{score: number, reason: string, alias?: 'partial' | 'keyword'} | null}
67
112
  * `alias` marks a hit that read the query's words joined.
68
113
  */
@@ -78,7 +123,7 @@ export function scoreCandidate(
78
123
  prose = [],
79
124
  guidance = [],
80
125
  },
81
- {fuzzy = true, joins = true} = {},
126
+ {fuzzy = true, joins = true, part = false} = {},
82
127
  ) {
83
128
  let best = 0;
84
129
  let reason = '';
@@ -128,6 +173,15 @@ export function scoreCandidate(
128
173
  // Most of the name typed as words, cut short: `complex select` is
129
174
  // ComplexSelector, ahead of a one-word keyword elsewhere.
130
175
  consider(95, `name "${candidateName}" spelled`, 'partial');
176
+ } else if (
177
+ domain !== 'doc' &&
178
+ domain !== 'theme' &&
179
+ spellsOut(term, candidateName, description)
180
+ ) {
181
+ // The name's short words spelled out, in order, as the entry's own
182
+ // description spells them: `vertical stack` is VStack ("Vertical stack
183
+ // for arranging items top-to-bottom").
184
+ consider(95, `name "${candidateName}" spelled out`);
131
185
  } else if (pluralOf(nameLower, term) || pluralOf(term, nameLower)) {
132
186
  // One point under the exact spelling, so the doc named `tokens` still
133
187
  // outranks the Token component for `tokens`.
@@ -135,7 +189,16 @@ export function scoreCandidate(
135
189
  } else {
136
190
  if (sameWord(term, nameLower)) consider(95, `name "${candidateName}"`);
137
191
  // The term is a word of the name, or starts one: "input" in TextInput.
138
- else if (startsAWordOf(term, candidateName)) {
192
+ else if (
193
+ !part &&
194
+ domain !== 'doc' &&
195
+ domain !== 'theme' &&
196
+ headOfLetters(term, candidateName)
197
+ ) {
198
+ // The whole query is the name's head word after single letters (Stack
199
+ // in VStack, HStack): a variant named by its head, as a keyword is.
200
+ consider(90, `name "${candidateName}" ends in "${term}"`);
201
+ } else if (startsAWordOf(term, candidateName)) {
139
202
  consider(60, `name contains "${term}"`);
140
203
  }
141
204
  if (fuzzy) {
@@ -132,7 +132,8 @@ export function domainPriority(
132
132
  const fuzzy = tokens.length <= 1;
133
133
  return words.some(
134
134
  w =>
135
- (bestForToken(w, candidate, {fuzzy})?.score ?? 0) >= STRONG_TOKEN_SCORE,
135
+ (bestForToken(w, candidate, {fuzzy, part: words.length > 1})?.score ??
136
+ 0) >= STRONG_TOKEN_SCORE,
136
137
  )
137
138
  ? 1
138
139
  : 0;
@@ -6,11 +6,12 @@
6
6
  * (synonym hits are discounted so a direct hit always wins).
7
7
  * @param {string} tok
8
8
  * @param {Candidate} candidate
9
- * @param {{fuzzy?: boolean}} [opts]
9
+ * @param {{fuzzy?: boolean, part?: boolean}} [opts] - see scoreCandidate
10
10
  * @returns {{score: number, reason: string} | null}
11
11
  */
12
12
  export function bestForToken(tok: string, candidate: Candidate, opts?: {
13
13
  fuzzy?: boolean;
14
+ part?: boolean;
14
15
  }): {
15
16
  score: number;
16
17
  reason: string;
@@ -39,7 +39,7 @@ const MIN_TOKEN_SCORE = 50;
39
39
  * (synonym hits are discounted so a direct hit always wins).
40
40
  * @param {string} tok
41
41
  * @param {Candidate} candidate
42
- * @param {{fuzzy?: boolean}} [opts]
42
+ * @param {{fuzzy?: boolean, part?: boolean}} [opts] - see scoreCandidate
43
43
  * @returns {{score: number, reason: string} | null}
44
44
  */
45
45
  export function bestForToken(tok, candidate, opts = {}) {
@@ -187,7 +187,7 @@ export function scoreQuery(
187
187
  let alias = false;
188
188
  let aliasWords = 0;
189
189
  for (const tok of tokens) {
190
- let h = bestForToken(tok, candidate, {fuzzy});
190
+ let h = bestForToken(tok, candidate, {fuzzy, part: true});
191
191
  if (
192
192
  compound?.covered.has(joined(tok)) &&
193
193
  compound.score > (h?.score ?? 0)
@@ -0,0 +1,124 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file A family member named by short words is found by them spelled out:
5
+ * "vertical stack" is VStack, whose own description says so, and a member whose
6
+ * name is its head word after single letters is a match for that head word.
7
+ * The same holds for any integration's members, which no learned weights know.
8
+ */
9
+
10
+ import fs from 'node:fs';
11
+ import os from 'node:os';
12
+ import path from 'node:path';
13
+ import {afterAll, beforeAll, describe, expect, it} from 'vitest';
14
+ import {search} from './search.mjs';
15
+
16
+ const SLOW = 60_000;
17
+
18
+ describe('family members found by their spelled-out names', () => {
19
+ it.each([
20
+ ['vertical stack', 'VStack'],
21
+ ['horizontal stack', 'HStack'],
22
+ ])('`%s` ranks %s first', async (query, name) => {
23
+ const {results} = (await search(query)).data;
24
+ expect(results[0], JSON.stringify(results.slice(0, 3))).toMatchObject({
25
+ domain: 'component',
26
+ name,
27
+ });
28
+ });
29
+
30
+ it('`stack` keeps Stack first and lists VStack and HStack', async () => {
31
+ const {results} = (await search('stack')).data;
32
+ expect(results[0]).toMatchObject({domain: 'component', name: 'Stack'});
33
+ const top = results.slice(0, 8).map(r => r.name);
34
+ expect(top).toContain('VStack');
35
+ expect(top).toContain('HStack');
36
+ });
37
+
38
+ it('only a single-letter word is spelled out', async () => {
39
+ // "without" begins with "With" but spells out no letter of the name.
40
+ const {results} = (await search('checkbox list without end content')).data;
41
+ expect(results[0]?.reason).not.toMatch(/spelled out/);
42
+ });
43
+
44
+ it('a longer query keeps Stack first', async () => {
45
+ // Stack in VStack counts as a keyword hit only when it is the whole query.
46
+ const {results} = (await search('vertical stack of cards')).data;
47
+ expect(results[0]).toMatchObject({domain: 'component', name: 'Stack'});
48
+ });
49
+
50
+ it("a longer query does not lift a head word's members", async () => {
51
+ const {results} = (await search('stack direction')).data;
52
+ const top = results.slice(0, 3).map(r => r.name);
53
+ expect(top).not.toContain('VStack');
54
+ expect(top).not.toContain('HStack');
55
+ });
56
+
57
+ it('a word the description does not spell out is no name', async () => {
58
+ const {results} = (await search('visual stack')).data;
59
+ expect(results[0]?.name).not.toBe('VStack');
60
+ });
61
+ });
62
+
63
+ describe("an integration's family members (cold start)", () => {
64
+ /** @type {string} */
65
+ let dir;
66
+ beforeAll(() => {
67
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-family-members-'));
68
+ const pkg = path.join(dir, 'node_modules', '@acme', 'grids');
69
+ fs.mkdirSync(path.join(pkg, 'components'), {recursive: true});
70
+ fs.mkdirSync(
71
+ path.join(dir, 'node_modules', '@astryxdesign', 'core', 'src'),
72
+ {
73
+ recursive: true,
74
+ },
75
+ );
76
+ fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"consumer"}');
77
+ fs.writeFileSync(
78
+ path.join(dir, 'astryx.config.mjs'),
79
+ "export default { integrations: ['@acme/grids'] };\n",
80
+ );
81
+ fs.writeFileSync(
82
+ path.join(pkg, 'package.json'),
83
+ '{"name":"@acme/grids","version":"1.0.0"}',
84
+ );
85
+ fs.writeFileSync(
86
+ path.join(pkg, 'astryx.integration.mjs'),
87
+ "export default { components: './components' };\n",
88
+ );
89
+ for (const [name, description] of [
90
+ ['VGrid', 'Vertical grid for arranging tiles in columns.'],
91
+ ['HGrid', 'Horizontal grid for arranging tiles in rows.'],
92
+ ]) {
93
+ fs.writeFileSync(
94
+ path.join(pkg, 'components', `${name}.doc.mjs`),
95
+ `export default {
96
+ type: 'component',
97
+ name: '${name}',
98
+ usage: {description: '${description}'},
99
+ props: [],
100
+ };\n`,
101
+ );
102
+ fs.writeFileSync(
103
+ path.join(pkg, 'components', `${name}.tsx`),
104
+ `export function ${name}() { return null; }\n`,
105
+ );
106
+ }
107
+ });
108
+ afterAll(() => fs.rmSync(dir, {recursive: true, force: true}));
109
+
110
+ it.each([
111
+ ['vertical grid', 'VGrid'],
112
+ ['horizontal grid', 'HGrid'],
113
+ ])(
114
+ '`%s` ranks %s first',
115
+ async (query, name) => {
116
+ const {results} = (await search(query, {cwd: dir, type: 'component'}))
117
+ .data;
118
+ expect(results[0], JSON.stringify(results.slice(0, 3))).toMatchObject({
119
+ name,
120
+ });
121
+ },
122
+ SLOW,
123
+ );
124
+ });
@@ -243,6 +243,22 @@
243
243
  {
244
244
  "kind": "template",
245
245
  "name": "EmojiPickerShowcase"
246
+ },
247
+ {
248
+ "kind": "template",
249
+ "name": "ListInputBudgetAllocation"
250
+ },
251
+ {
252
+ "kind": "template",
253
+ "name": "ListInputFamilyMembers"
254
+ },
255
+ {
256
+ "kind": "template",
257
+ "name": "ListInputMailingList"
258
+ },
259
+ {
260
+ "kind": "template",
261
+ "name": "ListInputShowcase"
246
262
  }
247
263
  ]
248
264
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.4-canary.1b56e00",
3
+ "version": "0.7.4-canary.20230c6",
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",
@@ -106,10 +106,10 @@
106
106
  "zod": "^4.4.3"
107
107
  },
108
108
  "peerDependencies": {
109
- "@astryxdesign/charts": "0.7.4-canary.1b56e00",
110
- "@astryxdesign/core": "0.7.4-canary.1b56e00",
111
- "@astryxdesign/lab": "0.7.4-canary.1b56e00",
112
- "@astryxdesign/theme-neutral": "0.7.4-canary.1b56e00"
109
+ "@astryxdesign/charts": "0.7.4-canary.20230c6",
110
+ "@astryxdesign/core": "0.7.4-canary.20230c6",
111
+ "@astryxdesign/lab": "0.7.4-canary.20230c6",
112
+ "@astryxdesign/theme-neutral": "0.7.4-canary.20230c6"
113
113
  },
114
114
  "peerDependenciesMeta": {
115
115
  "@astryxdesign/charts": {
@@ -126,10 +126,10 @@
126
126
  }
127
127
  },
128
128
  "devDependencies": {
129
- "@astryxdesign/charts": "0.7.4-canary.1b56e00",
130
- "@astryxdesign/core": "0.7.4-canary.1b56e00",
131
- "@astryxdesign/lab": "0.7.4-canary.1b56e00",
132
- "@astryxdesign/theme-neutral": "0.7.4-canary.1b56e00",
129
+ "@astryxdesign/charts": "0.7.4-canary.20230c6",
130
+ "@astryxdesign/core": "0.7.4-canary.20230c6",
131
+ "@astryxdesign/lab": "0.7.4-canary.20230c6",
132
+ "@astryxdesign/theme-neutral": "0.7.4-canary.20230c6",
133
133
  "@heroicons/react": "^2.2.0",
134
134
  "@stylexjs/stylex": "^0.19.0",
135
135
  "@types/babel__core": "^7.20.5",