@astryxdesign/cli 0.6.5-canary.197cb5e → 0.6.5-canary.1bbbf63
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/README.md +2 -2
- package/api/build/_adapter.d.mts +0 -14
- package/api/build/_adapter.mjs +1 -58
- package/api/build/build.test.mjs +1 -74
- package/api/build/kit/kit.mjs +7 -39
- package/api/build/kit/rank.d.mts +0 -8
- package/api/build/kit/rank.mjs +0 -14
- package/api/docs/docs.d.mts +0 -6
- package/api/docs/docs.doc.mjs +2 -31
- package/api/docs/docs.mjs +1 -44
- package/api/docs/docs.type.d.mts +1 -38
- package/api/docs/docs.type.mjs +1 -18
- package/api/docs/node/node.d.mts +3 -28
- package/api/docs/node/node.mjs +23 -146
- package/api/gap-report/gap-report.d.mts +1 -3
- package/api/gap-report/gap-report.mjs +2 -12
- package/api/gap-report/gap-report.test.mjs +0 -106
- package/api/hook/list/list.d.mts +1 -1
- package/api/integration/add-theme.mjs +3 -93
- package/api/integration/add-theme.test.mjs +0 -100
- package/api/integration/integrationAddTheme.doc.mjs +1 -1
- package/api/search/search.d.mts +5 -12
- package/api/search/search.doc.mjs +4 -4
- package/api/search/search.mjs +53 -123
- package/api/search/search.test.mjs +8 -123
- package/api/search/search.type.d.mts +5 -5
- package/api/search/search.type.mjs +5 -5
- package/assets/docs/theme.doc.mjs +1 -2
- package/assets/docs/tokens.doc.mjs +3 -3
- package/assets/docs/tree/add-a-theme.doc.mjs +0 -4
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
- package/clients/cli/commands/build-theme.mjs +2 -8
- package/clients/cli/commands/discover.mjs +1 -29
- package/clients/cli/commands/docs.doc.mjs +2 -15
- package/clients/cli/commands/docs.mjs +5 -222
- package/clients/cli/commands/gap-report.mjs +0 -12
- package/clients/cli/commands/gap-report.test.mjs +0 -63
- package/clients/cli/commands/integration-add.doc.mjs +1 -1
- package/clients/cli/commands/search.doc.mjs +4 -5
- package/clients/cli/commands/search.mjs +6 -30
- package/clients/cli/commands/search.test.mjs +16 -60
- package/foundation/agent-docs/agent-docs.mjs +1 -2
- package/foundation/agent-docs/agent-docs.test.mjs +0 -8
- package/foundation/discovery/theme-discovery.d.mts +0 -6
- package/foundation/discovery/theme-discovery.mjs +0 -9
- package/package.json +9 -9
- package/api/build/kit/weights.d.mts +0 -82
- package/api/build/kit/weights.json +0 -1
- package/api/build/kit/weights.mjs +0 -305
- package/api/build/kit/weights.test.mjs +0 -190
- package/api/docs/docs.depth.test.mjs +0 -132
- package/clients/cli/commands/discover.no-source.test.mjs +0 -75
- package/clients/cli/commands/docs.depth.test.mjs +0 -219
- package/clients/cli/commands/theme-list.behavior.test.mjs +0 -41
package/api/docs/node/node.mjs
CHANGED
|
@@ -7,18 +7,14 @@
|
|
|
7
7
|
* typed doc such as `cli/api/functions/search`, plus {cwd}.
|
|
8
8
|
* @output { type: 'docs.node', data: DocsNode } — the node's identity, title
|
|
9
9
|
* and summary, the namespaces above it, and either its slots with their
|
|
10
|
-
* children (a namespace) or its content (a typed doc).
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* text (compact, full). Matches `astryx --json docs <route> [--depth <n>]`.
|
|
10
|
+
* children (a namespace) or its content (a typed doc). A namespace never
|
|
11
|
+
* lists its grandchildren, so a reader goes down one level at a time.
|
|
12
|
+
* Matches `astryx --json docs <route>`.
|
|
14
13
|
* @position Leaf under api/docs, beside the topic leaves. A guide the tree
|
|
15
14
|
* places is a topic: the detail leaf reads it by its route.
|
|
16
15
|
*/
|
|
17
16
|
|
|
18
|
-
import {detailView} from '../../../foundation/doc-compiler/lenses.mjs';
|
|
19
17
|
import {
|
|
20
|
-
compileTopic,
|
|
21
|
-
guideEntry,
|
|
22
18
|
nodeContent,
|
|
23
19
|
placeLinks,
|
|
24
20
|
resolveDocsArgument,
|
|
@@ -28,34 +24,18 @@ import {
|
|
|
28
24
|
/**
|
|
29
25
|
* @typedef {import('../../../foundation/doc-compiler/tree.mjs').DocsTree} DocsTree
|
|
30
26
|
* @typedef {import('../../../foundation/doc-compiler/tree.mjs').TreeNode} TreeNode
|
|
31
|
-
* @typedef {import('../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} DocsCatalog
|
|
32
27
|
*/
|
|
33
28
|
|
|
34
29
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* identity), or compact or full (with its text: a namespace's intro, a guide's
|
|
38
|
-
* sections, a typed doc's content). `lang` selects the guides' language.
|
|
39
|
-
* @typedef {object} DepthRead
|
|
40
|
-
* @property {number} depth
|
|
41
|
-
* @property {'brief' | 'compact' | 'full'} detail
|
|
42
|
-
* @property {string | null} lang
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The docs.node view of one tree node. Without a depth read, a namespace lists
|
|
47
|
-
* its children one level down.
|
|
48
|
-
* @param {DocsCatalog} catalog
|
|
30
|
+
* The docs.node view of one tree node.
|
|
31
|
+
* @param {import('../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} catalog
|
|
49
32
|
* @param {DocsTree} tree
|
|
50
33
|
* @param {TreeNode} node
|
|
51
|
-
* @param {DepthRead} [read] how far down to go, and how much of each doc below
|
|
52
34
|
* @returns {Promise<import('../docs.type.mjs').DocsNode>}
|
|
53
35
|
*/
|
|
54
|
-
export async function nodeView(catalog, tree, node
|
|
36
|
+
export async function nodeView(catalog, tree, node) {
|
|
55
37
|
const {content} = await nodeContent(catalog, tree, node);
|
|
56
|
-
|
|
57
|
-
/** @type {import('../docs.type.mjs').DocsNode} */
|
|
58
|
-
const view = {
|
|
38
|
+
return {
|
|
59
39
|
id: node.id,
|
|
60
40
|
route: node.route,
|
|
61
41
|
kind: node.kind,
|
|
@@ -65,128 +45,25 @@ export async function nodeView(catalog, tree, node, read) {
|
|
|
65
45
|
breadcrumb: tree
|
|
66
46
|
.ancestors(node)
|
|
67
47
|
.map(ancestor => ({route: ancestor.route, title: ancestor.title})),
|
|
68
|
-
slots:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
48
|
+
slots: node.slots
|
|
49
|
+
.filter(slot => slot.children.length > 0)
|
|
50
|
+
.map(slot => ({
|
|
51
|
+
name: slot.name,
|
|
52
|
+
title: slot.title,
|
|
53
|
+
children: slot.children.map(route => {
|
|
54
|
+
const child = /** @type {TreeNode} */ (tree.get(route));
|
|
55
|
+
return {
|
|
56
|
+
route: child.route,
|
|
57
|
+
name: child.route.slice(child.route.lastIndexOf('/') + 1),
|
|
58
|
+
kind: child.kind,
|
|
59
|
+
title: child.title,
|
|
60
|
+
summary: child.summary,
|
|
61
|
+
};
|
|
62
|
+
}),
|
|
63
|
+
})),
|
|
79
64
|
content,
|
|
80
65
|
links: nodeLinks(tree, node),
|
|
81
66
|
};
|
|
82
|
-
if (read && read.depth < 1 && slots.length > 0) {
|
|
83
|
-
view.childCount = countChildren(slots);
|
|
84
|
-
}
|
|
85
|
-
return view;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* The fields every child carries: what it is, and the route that opens it.
|
|
90
|
-
* @param {TreeNode} child
|
|
91
|
-
* @returns {import('../docs.type.mjs').DocsNodeChild}
|
|
92
|
-
*/
|
|
93
|
-
function childIdentity(child) {
|
|
94
|
-
return {
|
|
95
|
-
route: child.route,
|
|
96
|
-
name: child.route.slice(child.route.lastIndexOf('/') + 1),
|
|
97
|
-
kind: child.kind,
|
|
98
|
-
title: child.title,
|
|
99
|
-
summary: child.summary,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* @param {TreeNode['slots']} slots
|
|
105
|
-
* @returns {number}
|
|
106
|
-
*/
|
|
107
|
-
function countChildren(slots) {
|
|
108
|
-
return slots.reduce((count, slot) => count + slot.children.length, 0);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Slots read `level` levels below the named node: each child at the read's
|
|
113
|
-
* detail, and its own slots while the read goes deeper.
|
|
114
|
-
* @param {DocsCatalog} catalog
|
|
115
|
-
* @param {DocsTree} tree
|
|
116
|
-
* @param {TreeNode['slots']} slots
|
|
117
|
-
* @param {number} level
|
|
118
|
-
* @param {DepthRead} read
|
|
119
|
-
* @returns {Promise<import('../docs.type.mjs').DocsNodeSlot[]>}
|
|
120
|
-
*/
|
|
121
|
-
async function slotsBelow(catalog, tree, slots, level, read) {
|
|
122
|
-
return Promise.all(
|
|
123
|
-
slots.map(async slot => ({
|
|
124
|
-
name: slot.name,
|
|
125
|
-
title: slot.title,
|
|
126
|
-
children: await Promise.all(
|
|
127
|
-
slot.children.map(route =>
|
|
128
|
-
childBelow(
|
|
129
|
-
catalog,
|
|
130
|
-
tree,
|
|
131
|
-
/** @type {TreeNode} */ (tree.get(route)),
|
|
132
|
-
level,
|
|
133
|
-
read,
|
|
134
|
-
),
|
|
135
|
-
),
|
|
136
|
-
),
|
|
137
|
-
})),
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* One child of a depth read. Where the read stops, a child with docs below it
|
|
143
|
-
* says how many, so a reader knows to go deeper.
|
|
144
|
-
* @param {DocsCatalog} catalog
|
|
145
|
-
* @param {DocsTree} tree
|
|
146
|
-
* @param {TreeNode} child
|
|
147
|
-
* @param {number} level
|
|
148
|
-
* @param {DepthRead} read
|
|
149
|
-
* @returns {Promise<import('../docs.type.mjs').DocsNodeChild>}
|
|
150
|
-
*/
|
|
151
|
-
async function childBelow(catalog, tree, child, level, read) {
|
|
152
|
-
const view = childIdentity(child);
|
|
153
|
-
if (read.detail !== 'brief') {
|
|
154
|
-
Object.assign(view, await childText(catalog, tree, child, read.lang));
|
|
155
|
-
}
|
|
156
|
-
const slots = child.slots.filter(slot => slot.children.length > 0);
|
|
157
|
-
if (slots.length > 0) {
|
|
158
|
-
if (level < read.depth) {
|
|
159
|
-
view.slots = await slotsBelow(catalog, tree, slots, level + 1, read);
|
|
160
|
-
} else {
|
|
161
|
-
view.childCount = countChildren(slots);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return view;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* A child's text: a guide's compiled sections, or the content of a namespace
|
|
169
|
-
* or typed doc.
|
|
170
|
-
* @param {DocsCatalog} catalog
|
|
171
|
-
* @param {DocsTree} tree
|
|
172
|
-
* @param {TreeNode} child
|
|
173
|
-
* @param {string | null} lang
|
|
174
|
-
* @returns {Promise<{content?: any[], sections?: any[]}>}
|
|
175
|
-
*/
|
|
176
|
-
async function childText(catalog, tree, child, lang) {
|
|
177
|
-
if (child.kind === 'generic') {
|
|
178
|
-
const entry = child.ref?.topicFile
|
|
179
|
-
? guideEntry(child)
|
|
180
|
-
: child.ref?.flatTopic
|
|
181
|
-
? catalog.resolve(child.ref.flatTopic)
|
|
182
|
-
: null;
|
|
183
|
-
if (!entry) return {};
|
|
184
|
-
return {
|
|
185
|
-
sections: detailView(await compileTopic(catalog, entry, lang)).sections,
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
const {content} = await nodeContent(catalog, tree, child);
|
|
189
|
-
return {content};
|
|
190
67
|
}
|
|
191
68
|
|
|
192
69
|
/**
|
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* Collect the effective handler set in delivery order: project config first,
|
|
6
6
|
* then integrations in config order. Valid handlers dedupe by handle identity;
|
|
7
|
-
* malformed integration exports
|
|
8
|
-
* their position as failed deliveries. An unloadable integration may export a
|
|
9
|
-
* handler, so it never counts as an empty set that enables the fallback.
|
|
7
|
+
* malformed integration exports retain their position as failed deliveries.
|
|
10
8
|
*
|
|
11
9
|
* @param {Project} project
|
|
12
10
|
* @returns {HandlerEntry[]}
|
|
@@ -189,9 +189,7 @@ async function selectTarget(project, component, packageName) {
|
|
|
189
189
|
/**
|
|
190
190
|
* Collect the effective handler set in delivery order: project config first,
|
|
191
191
|
* then integrations in config order. Valid handlers dedupe by handle identity;
|
|
192
|
-
* malformed integration exports
|
|
193
|
-
* their position as failed deliveries. An unloadable integration may export a
|
|
194
|
-
* handler, so it never counts as an empty set that enables the fallback.
|
|
192
|
+
* malformed integration exports retain their position as failed deliveries.
|
|
195
193
|
*
|
|
196
194
|
* @param {Project} project
|
|
197
195
|
* @returns {HandlerEntry[]}
|
|
@@ -216,15 +214,7 @@ export function collectGapReportHandlers(project) {
|
|
|
216
214
|
}
|
|
217
215
|
|
|
218
216
|
for (const integration of project.loadedIntegrations) {
|
|
219
|
-
if (integration.__loadError)
|
|
220
|
-
entries.push({
|
|
221
|
-
kind: 'malformed',
|
|
222
|
-
handlerType: 'integration',
|
|
223
|
-
handlerName: integration.name,
|
|
224
|
-
error: `Integration failed to load, so it could not receive this report: ${integration.__loadError}. Fix the package or remove it from integrations in astryx.config, then rerun.`,
|
|
225
|
-
});
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
217
|
+
if (integration.__loadError) continue;
|
|
228
218
|
if (integration.__gapReportError) {
|
|
229
219
|
entries.push({
|
|
230
220
|
kind: 'malformed',
|
|
@@ -105,45 +105,6 @@ function addIntegration({
|
|
|
105
105
|
return {dir};
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
/**
|
|
109
|
-
* Add an integration whose module throws on import, so it never loads.
|
|
110
|
-
* @param {string} name
|
|
111
|
-
*/
|
|
112
|
-
function addBrokenIntegration(name) {
|
|
113
|
-
const dir = packageDir(name);
|
|
114
|
-
fs.mkdirSync(dir, {recursive: true});
|
|
115
|
-
fs.writeFileSync(
|
|
116
|
-
path.join(dir, 'package.json'),
|
|
117
|
-
JSON.stringify({name, version: '1.0.0', type: 'module'}),
|
|
118
|
-
);
|
|
119
|
-
fs.writeFileSync(
|
|
120
|
-
path.join(dir, 'astryx.integration.mjs'),
|
|
121
|
-
"throw new Error('intentional integration load failure');\n",
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Put a fake `gh` first on PATH that records its arguments if it is called.
|
|
127
|
-
* @returns {string} the file the fake writes when invoked
|
|
128
|
-
*/
|
|
129
|
-
function stubGh() {
|
|
130
|
-
const binDir = path.join(projectDir, 'bin');
|
|
131
|
-
const argsFile = path.join(projectDir, 'gh-args.json');
|
|
132
|
-
fs.mkdirSync(binDir, {recursive: true});
|
|
133
|
-
fs.writeFileSync(
|
|
134
|
-
path.join(binDir, 'gh'),
|
|
135
|
-
`#!/usr/bin/env node
|
|
136
|
-
import fs from 'node:fs';
|
|
137
|
-
fs.writeFileSync(${JSON.stringify(argsFile)}, JSON.stringify(process.argv.slice(2)));
|
|
138
|
-
console.log('https://github.com/acme/core/issues/42');
|
|
139
|
-
`,
|
|
140
|
-
{mode: 0o755},
|
|
141
|
-
);
|
|
142
|
-
fs.chmodSync(path.join(binDir, 'gh'), 0o755);
|
|
143
|
-
vi.stubEnv('PATH', `${binDir}${path.delimiter}${process.env.PATH ?? ''}`);
|
|
144
|
-
return argsFile;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
108
|
const reportOptions = {
|
|
148
109
|
category: 'missing_variant',
|
|
149
110
|
reason: 'Need a compact size',
|
|
@@ -720,73 +681,6 @@ describe('gapReport handler isolation', () => {
|
|
|
720
681
|
});
|
|
721
682
|
});
|
|
722
683
|
|
|
723
|
-
it('an integration that fails to load is a failed delivery, not a missing handler', async () => {
|
|
724
|
-
addBrokenIntegration('@test/broken');
|
|
725
|
-
configure(['@test/broken'], {
|
|
726
|
-
issuesUrl: 'https://github.com/acme/core/issues/new',
|
|
727
|
-
});
|
|
728
|
-
|
|
729
|
-
const result = await gapReport('General', {
|
|
730
|
-
...reportOptions,
|
|
731
|
-
cwd: projectDir,
|
|
732
|
-
});
|
|
733
|
-
|
|
734
|
-
expect(result.data.status).toBe('failed');
|
|
735
|
-
expect(result.data.deliveries).toEqual([
|
|
736
|
-
{
|
|
737
|
-
handlerType: 'integration',
|
|
738
|
-
handler: '@test/broken',
|
|
739
|
-
audience: null,
|
|
740
|
-
status: 'failed',
|
|
741
|
-
url: null,
|
|
742
|
-
message: expect.stringContaining(
|
|
743
|
-
'intentional integration load failure',
|
|
744
|
-
),
|
|
745
|
-
},
|
|
746
|
-
]);
|
|
747
|
-
});
|
|
748
|
-
|
|
749
|
-
it('an integration that fails to load keeps the public fallback off, even with consent', async () => {
|
|
750
|
-
addBrokenIntegration('@test/broken');
|
|
751
|
-
configure(['@test/broken'], {
|
|
752
|
-
issuesUrl: 'https://github.com/acme/core/issues/new',
|
|
753
|
-
});
|
|
754
|
-
const argsFile = stubGh();
|
|
755
|
-
|
|
756
|
-
const result = await gapReport('General', {
|
|
757
|
-
...reportOptions,
|
|
758
|
-
confirmPublic: true,
|
|
759
|
-
cwd: projectDir,
|
|
760
|
-
});
|
|
761
|
-
|
|
762
|
-
expect(result.data.status).toBe('failed');
|
|
763
|
-
expect(result.data.deliveries.map(d => d.handlerType)).toEqual([
|
|
764
|
-
'integration',
|
|
765
|
-
]);
|
|
766
|
-
expect(fs.existsSync(argsFile)).toBe(false);
|
|
767
|
-
});
|
|
768
|
-
|
|
769
|
-
it('an integration that fails to load keeps its place beside working handlers', async () => {
|
|
770
|
-
addBrokenIntegration('@test/broken');
|
|
771
|
-
addIntegration({
|
|
772
|
-
name: '@test/valid',
|
|
773
|
-
audience: 'internal',
|
|
774
|
-
handleBody: "return {status: 'filed', message: 'ok'};",
|
|
775
|
-
});
|
|
776
|
-
configure(['@test/broken', '@test/valid']);
|
|
777
|
-
|
|
778
|
-
const result = await gapReport('General', {
|
|
779
|
-
...reportOptions,
|
|
780
|
-
cwd: projectDir,
|
|
781
|
-
});
|
|
782
|
-
|
|
783
|
-
expect(result.data.status).toBe('partial');
|
|
784
|
-
expect(result.data.deliveries.map(d => [d.handler, d.status])).toEqual([
|
|
785
|
-
['@test/broken', 'failed'],
|
|
786
|
-
['@test/valid', 'filed'],
|
|
787
|
-
]);
|
|
788
|
-
});
|
|
789
|
-
|
|
790
684
|
it('invalid handler receipt is recorded as failed delivery', async () => {
|
|
791
685
|
addIntegration({
|
|
792
686
|
name: '@test/bad-receipt',
|
package/api/hook/list/list.d.mts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
export function list({ cwd, category, detail, zh, lang, }?: {
|
|
14
14
|
cwd?: string | undefined;
|
|
15
15
|
category?: string | undefined;
|
|
16
|
-
detail?: "compact" | "full" | "
|
|
16
|
+
detail?: "compact" | "full" | "names" | "brief" | undefined;
|
|
17
17
|
zh?: boolean | undefined;
|
|
18
18
|
lang?: string | null | undefined;
|
|
19
19
|
}): Promise<import("../hook.type.mjs").HookListResponse>;
|
|
@@ -10,10 +10,8 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import * as fs from 'node:fs';
|
|
13
|
-
import {isBuiltin} from 'node:module';
|
|
14
13
|
import * as path from 'node:path';
|
|
15
14
|
import {AstryxError} from '../error.mjs';
|
|
16
|
-
import {CLI_ROOT} from '../../foundation/fs/paths.mjs';
|
|
17
15
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
18
16
|
import {
|
|
19
17
|
assertWithin,
|
|
@@ -23,7 +21,6 @@ import {
|
|
|
23
21
|
import {
|
|
24
22
|
discoverBundledThemes,
|
|
25
23
|
discoverThemeDirectory,
|
|
26
|
-
themeFileImports,
|
|
27
24
|
} from '../../foundation/discovery/theme-discovery.mjs';
|
|
28
25
|
import {
|
|
29
26
|
findLocalIntegrationManifestOrNull,
|
|
@@ -217,77 +214,6 @@ function escapeRegExp(s) {
|
|
|
217
214
|
return s.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
|
|
218
215
|
}
|
|
219
216
|
|
|
220
|
-
/** What every app that uses Astryx already has: Core, and React through Core's peers. */
|
|
221
|
-
const APP_PROVIDED = new Set(['@astryxdesign/core', 'react', 'react-dom']);
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* The npm package a module specifier names, or null for a relative path, an
|
|
225
|
-
* absolute path, or a Node built-in.
|
|
226
|
-
* @param {string} specifier
|
|
227
|
-
* @returns {string | null}
|
|
228
|
-
*/
|
|
229
|
-
function packageOfSpecifier(specifier) {
|
|
230
|
-
if (specifier.startsWith('.') || specifier.startsWith('/')) return null;
|
|
231
|
-
if (isBuiltin(specifier)) return null;
|
|
232
|
-
const parts = specifier.split('/');
|
|
233
|
-
return specifier.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* The npm packages a fork's copied files import that its package does not
|
|
238
|
-
* declare yet, each at the range the bundled themes are built against (the
|
|
239
|
-
* CLI's own package.json). The fork depends on them at runtime, so an app that
|
|
240
|
-
* installs the package needs them too. Derived from the imports, not copied
|
|
241
|
-
* from a base's whole dependency list. Core and React are left out, since every
|
|
242
|
-
* Astryx app has them; so is a fork of the package's own theme, whose imports
|
|
243
|
-
* the package already resolves.
|
|
244
|
-
*
|
|
245
|
-
* @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme} base
|
|
246
|
-
* @param {Record<string, any>} pkg - The package's package.json.
|
|
247
|
-
* @returns {Record<string, string>} package name to range
|
|
248
|
-
*/
|
|
249
|
-
function forkDependencies(base, pkg) {
|
|
250
|
-
if (!base.bundled) return {};
|
|
251
|
-
/** @type {Record<string, any>} */
|
|
252
|
-
let cli;
|
|
253
|
-
try {
|
|
254
|
-
cli = JSON.parse(
|
|
255
|
-
fs.readFileSync(path.join(CLI_ROOT, 'package.json'), 'utf-8'),
|
|
256
|
-
);
|
|
257
|
-
} catch {
|
|
258
|
-
return {};
|
|
259
|
-
}
|
|
260
|
-
/** @type {Record<string, string>} */
|
|
261
|
-
const ranges = {
|
|
262
|
-
...cli.devDependencies,
|
|
263
|
-
...cli.peerDependencies,
|
|
264
|
-
...cli.dependencies,
|
|
265
|
-
};
|
|
266
|
-
const declared = {
|
|
267
|
-
...pkg.devDependencies,
|
|
268
|
-
...pkg.peerDependencies,
|
|
269
|
-
...pkg.dependencies,
|
|
270
|
-
};
|
|
271
|
-
/** @type {Record<string, string>} */
|
|
272
|
-
const needed = {};
|
|
273
|
-
for (const file of base.files) {
|
|
274
|
-
const code = /\.(?:[cm]?[jt]sx?)$/u.test(file);
|
|
275
|
-
if (!code || file.endsWith('.doc.mjs')) continue;
|
|
276
|
-
let specifiers;
|
|
277
|
-
try {
|
|
278
|
-
specifiers = themeFileImports(path.join(base.sourceDir, file));
|
|
279
|
-
} catch {
|
|
280
|
-
continue; // discovery already refuses a theme whose source does not parse
|
|
281
|
-
}
|
|
282
|
-
for (const specifier of specifiers) {
|
|
283
|
-
const name = packageOfSpecifier(specifier);
|
|
284
|
-
if (name == null || APP_PROVIDED.has(name) || name in declared) continue;
|
|
285
|
-
if (typeof ranges[name] === 'string') needed[name] = ranges[name];
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return needed;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
217
|
/**
|
|
292
218
|
* Build the write plans for a forked theme.
|
|
293
219
|
* @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme} base
|
|
@@ -541,27 +467,11 @@ export async function integrationAddTheme(name, options = {}) {
|
|
|
541
467
|
packageUpdate?.expectedOriginal ?? fs.readFileSync(packageFile);
|
|
542
468
|
const text = packageUpdate?.contents ?? expectedOriginal.toString('utf-8');
|
|
543
469
|
const current = JSON.parse(text);
|
|
544
|
-
|
|
545
|
-
themesCliProblem(current) != null
|
|
546
|
-
? withCliPeer(current, THEMES_CLI)
|
|
547
|
-
: current;
|
|
548
|
-
// A fork runs the base's imports: declare the packages they come from.
|
|
549
|
-
const forked = baseTheme ? forkDependencies(baseTheme, next) : {};
|
|
550
|
-
if (Object.keys(forked).length > 0) {
|
|
551
|
-
const dependencies = {...next.dependencies, ...forked};
|
|
552
|
-
next = {
|
|
553
|
-
...next,
|
|
554
|
-
dependencies: Object.fromEntries(
|
|
555
|
-
Object.keys(dependencies)
|
|
556
|
-
.sort()
|
|
557
|
-
.map(name => [name, dependencies[name]]),
|
|
558
|
-
),
|
|
559
|
-
};
|
|
560
|
-
}
|
|
561
|
-
if (next !== current) {
|
|
470
|
+
if (themesCliProblem(current) != null) {
|
|
562
471
|
packageUpdate = {
|
|
563
472
|
contents:
|
|
564
|
-
JSON.stringify(
|
|
473
|
+
JSON.stringify(withCliPeer(current, THEMES_CLI), null, 2) +
|
|
474
|
+
(text.endsWith('\n') ? '\n' : ''),
|
|
565
475
|
expectedOriginal,
|
|
566
476
|
};
|
|
567
477
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
4
|
-
import {execFileSync} from 'node:child_process';
|
|
5
4
|
import * as fs from 'node:fs';
|
|
6
5
|
import * as path from 'node:path';
|
|
7
|
-
import {CLI_ROOT, findInstalledPackage} from '../../foundation/fs/paths.mjs';
|
|
8
6
|
import {integrationAddTheme} from './add-theme.mjs';
|
|
9
7
|
import {validateLocalIntegration} from './validate-integration.mjs';
|
|
10
8
|
|
|
@@ -475,104 +473,6 @@ describe('integrationAddTheme --from', () => {
|
|
|
475
473
|
).rejects.toMatchObject({code: 'ERR_FILE_EXISTS'});
|
|
476
474
|
});
|
|
477
475
|
|
|
478
|
-
it('declares the npm packages the forked files import, at the range the bundled themes use', async () => {
|
|
479
|
-
setup({includeFiles: false});
|
|
480
|
-
await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
|
|
481
|
-
const pkg = JSON.parse(
|
|
482
|
-
fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
|
|
483
|
-
);
|
|
484
|
-
const cli = JSON.parse(
|
|
485
|
-
fs.readFileSync(path.join(CLI_ROOT, 'package.json'), 'utf-8'),
|
|
486
|
-
);
|
|
487
|
-
// The copied icons.tsx imports lucide-react; Core and React are every
|
|
488
|
-
// app's own, so the fork does not declare them.
|
|
489
|
-
expect(pkg.dependencies).toEqual({
|
|
490
|
-
'lucide-react': cli.devDependencies['lucide-react'],
|
|
491
|
-
});
|
|
492
|
-
expect(pkg.peerDependencies).toEqual({'@astryxdesign/cli': '>=0.6.4'});
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
it('keeps a dependency the package already declares', async () => {
|
|
496
|
-
setup({includeFiles: false});
|
|
497
|
-
const file = path.join(tmpDir, 'package.json');
|
|
498
|
-
const pkg = JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
499
|
-
fs.writeFileSync(
|
|
500
|
-
file,
|
|
501
|
-
`${JSON.stringify({...pkg, dependencies: {'lucide-react': '^1.0.0'}}, null, 2)}\n`,
|
|
502
|
-
);
|
|
503
|
-
await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
|
|
504
|
-
expect(JSON.parse(fs.readFileSync(file, 'utf-8')).dependencies).toEqual({
|
|
505
|
-
'lucide-react': '^1.0.0',
|
|
506
|
-
});
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
it('declares nothing for a fork of a theme the package owns', async () => {
|
|
510
|
-
setup({includeFiles: false});
|
|
511
|
-
await integrationAddTheme('base', {cwd: tmpDir});
|
|
512
|
-
await integrationAddTheme('variant', {cwd: tmpDir, from: 'base'});
|
|
513
|
-
const pkg = JSON.parse(
|
|
514
|
-
fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
|
|
515
|
-
);
|
|
516
|
-
expect(pkg.dependencies).toBeUndefined();
|
|
517
|
-
});
|
|
518
|
-
|
|
519
|
-
it('builds a forked neutral theme once the package installs what --from declared', async () => {
|
|
520
|
-
setup({includeFiles: false});
|
|
521
|
-
await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
|
|
522
|
-
const pkg = JSON.parse(
|
|
523
|
-
fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
|
|
524
|
-
);
|
|
525
|
-
// Install exactly what the package declares, plus what every Astryx
|
|
526
|
-
// project has: Core and React.
|
|
527
|
-
for (const name of [
|
|
528
|
-
...Object.keys(pkg.dependencies ?? {}),
|
|
529
|
-
'@astryxdesign/core',
|
|
530
|
-
'react',
|
|
531
|
-
]) {
|
|
532
|
-
const installed = findInstalledPackage(CLI_ROOT, name);
|
|
533
|
-
expect(installed, name).not.toBeNull();
|
|
534
|
-
const link = path.join(tmpDir, 'node_modules', ...name.split('/'));
|
|
535
|
-
fs.mkdirSync(path.dirname(link), {recursive: true});
|
|
536
|
-
fs.symlinkSync(
|
|
537
|
-
fs.realpathSync(/** @type {string} */ (installed)),
|
|
538
|
-
link,
|
|
539
|
-
'dir',
|
|
540
|
-
);
|
|
541
|
-
}
|
|
542
|
-
// A separate process without NODE_PATH, so only what the package
|
|
543
|
-
// installed can resolve.
|
|
544
|
-
let status = 0;
|
|
545
|
-
let output = '';
|
|
546
|
-
try {
|
|
547
|
-
execFileSync(
|
|
548
|
-
process.execPath,
|
|
549
|
-
[
|
|
550
|
-
path.join(CLI_ROOT, 'clients/cli/bin/astryx.mjs'),
|
|
551
|
-
'theme',
|
|
552
|
-
'build',
|
|
553
|
-
'themes/ocean/oceanTheme.ts',
|
|
554
|
-
],
|
|
555
|
-
{
|
|
556
|
-
cwd: tmpDir,
|
|
557
|
-
env: {...process.env, NODE_PATH: ''},
|
|
558
|
-
encoding: 'utf-8',
|
|
559
|
-
stdio: 'pipe',
|
|
560
|
-
},
|
|
561
|
-
);
|
|
562
|
-
} catch (error) {
|
|
563
|
-
const failure = /** @type {any} */ (error);
|
|
564
|
-
status = failure.status ?? 1;
|
|
565
|
-
output = `${failure.stdout ?? ''}${failure.stderr ?? ''}`;
|
|
566
|
-
}
|
|
567
|
-
expect({status, output: status === 0 ? '' : output}).toEqual({
|
|
568
|
-
status: 0,
|
|
569
|
-
output: '',
|
|
570
|
-
});
|
|
571
|
-
expect(fs.existsSync(path.join(tmpDir, 'themes/ocean/ocean.css'))).toBe(
|
|
572
|
-
true,
|
|
573
|
-
);
|
|
574
|
-
});
|
|
575
|
-
|
|
576
476
|
it('works with different bundled themes', async () => {
|
|
577
477
|
setup();
|
|
578
478
|
const result = await integrationAddTheme('dusk', {
|
|
@@ -37,7 +37,7 @@ export const doc = {
|
|
|
37
37
|
name: 'options.from',
|
|
38
38
|
type: 'string',
|
|
39
39
|
description:
|
|
40
|
-
'Slug of an existing theme to fork as the starting point. The new theme copies the base and has no link back
|
|
40
|
+
'Slug of an existing theme to fork as the starting point. The new theme copies the base and has no link back.',
|
|
41
41
|
},
|
|
42
42
|
],
|
|
43
43
|
returns: [
|
package/api/search/search.d.mts
CHANGED
|
@@ -66,7 +66,6 @@ export function scoreQuery(term: string, tokens: string[], candidate: Candidate)
|
|
|
66
66
|
* @param {string} term - Lowercased search term.
|
|
67
67
|
* @param {object} candidate
|
|
68
68
|
* @param {string} candidate.name - Primary identifier (component/hook name, topic, template name).
|
|
69
|
-
* @param {string[]} [candidate.aliases] - Other names, scored like the name (a theme's display name).
|
|
70
69
|
* @param {string} [candidate.domain] - A component, hook, or template name
|
|
71
70
|
* also matches typed as words: `command palette` is CommandPalette.
|
|
72
71
|
* @param {string[]} [candidate.keywords] - Authored intent (componentsUsed, category words).
|
|
@@ -77,9 +76,8 @@ export function scoreQuery(term: string, tokens: string[], candidate: Candidate)
|
|
|
77
76
|
* @param {{fuzzy?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false.
|
|
78
77
|
* @returns {{score: number, reason: string} | null}
|
|
79
78
|
*/
|
|
80
|
-
export function scoreCandidate(term: string, { name,
|
|
79
|
+
export function scoreCandidate(term: string, { name, domain, keywords, weakKeywords, description, prose, guidance, }: {
|
|
81
80
|
name: string;
|
|
82
|
-
aliases?: string[] | undefined;
|
|
83
81
|
domain?: string | undefined;
|
|
84
82
|
keywords?: string[] | undefined;
|
|
85
83
|
weakKeywords?: string[] | undefined;
|
|
@@ -117,18 +115,18 @@ export function componentKeywords(coreDir: string, cwd: string): Promise<{
|
|
|
117
115
|
keywords: string[];
|
|
118
116
|
}[]>;
|
|
119
117
|
/**
|
|
120
|
-
* Unified ranked search across components, hooks, docs,
|
|
118
|
+
* Unified ranked search across components, hooks, docs, and templates.
|
|
121
119
|
*
|
|
122
120
|
* @param {string} query - Free-text search term.
|
|
123
121
|
* @param {object} [options]
|
|
124
122
|
* @param {string} [options.cwd]
|
|
125
|
-
* @param {'component'|'hook'|'doc'|'template'
|
|
123
|
+
* @param {'component'|'hook'|'doc'|'template'} [options.type] - Restrict to one domain.
|
|
126
124
|
* @param {number} [options.limit] - Max results (default 20).
|
|
127
125
|
* @returns {Promise<import('./search.type.mjs').SearchResponse>}
|
|
128
126
|
*/
|
|
129
127
|
export function search(query: string, options?: {
|
|
130
128
|
cwd?: string | undefined;
|
|
131
|
-
type?: "
|
|
129
|
+
type?: "component" | "hook" | "template" | "doc" | undefined;
|
|
132
130
|
limit?: number | undefined;
|
|
133
131
|
}): Promise<import("./search.type.mjs").SearchResponse>;
|
|
134
132
|
export namespace SYNONYMS {
|
|
@@ -161,13 +159,8 @@ export const STOPWORDS: Set<string>;
|
|
|
161
159
|
* prefixed fields carry domain-specific payload used only by {@link toResult}.
|
|
162
160
|
*/
|
|
163
161
|
export type Candidate = {
|
|
164
|
-
domain: "component" | "hook" | "doc" | "template"
|
|
162
|
+
domain: "component" | "hook" | "doc" | "template";
|
|
165
163
|
name: string;
|
|
166
|
-
/**
|
|
167
|
-
* - Other names the candidate answers to, scored
|
|
168
|
-
* with the same name signals: a theme's display name.
|
|
169
|
-
*/
|
|
170
|
-
aliases?: string[] | undefined;
|
|
171
164
|
keywords?: string[] | undefined;
|
|
172
165
|
weakKeywords?: string[] | undefined;
|
|
173
166
|
description?: string | undefined;
|