@astryxdesign/cli 0.6.6-canary.fb78fa1 → 0.6.6-canary.ffa4f72
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/component/component-replacement.test.mjs +12 -0
- package/api/component/component.doc.mjs +5 -2
- package/api/docs/_adapter.mjs +48 -1
- package/api/docs/compiled-topics.test.mjs +1 -1
- package/api/docs/detail/section/section.d.mts +44 -0
- package/api/docs/detail/section/section.mjs +164 -13
- package/api/docs/detail/section/section.test.mjs +4 -4
- package/api/docs/docOverlays.test.mjs +28 -17
- package/api/docs/docs.doc.mjs +3 -3
- package/api/docs/docs.mjs +11 -16
- package/api/docs/docs.test.mjs +9 -10
- package/api/docs/integration-tree.test.mjs +26 -26
- package/api/docs/integrationDocs.test.mjs +2 -2
- package/api/docs/namespace-section.test.mjs +260 -0
- package/api/docs/token-tables.test.mjs +93 -0
- package/api/doctor/doctor.d.mts +6 -0
- package/api/doctor/doctor.mjs +149 -40
- package/api/doctor/doctor.test.mjs +104 -0
- package/api/gap-report/gap-report.doc.mjs +2 -1
- package/api/integration/validate-integration.mjs +20 -4
- package/api/integration/validate-integration.test.mjs +73 -0
- package/api/search/search.d.mts +3 -2
- package/api/search/search.domain-priority.test.mjs +35 -21
- package/api/search/search.mjs +30 -9
- package/api/swizzle/swizzle.doc.mjs +5 -2
- package/assets/docs/author-a-theme.doc.mjs +4 -4
- package/assets/docs/getting-started.doc.mjs +2 -2
- package/assets/docs/principles.doc.dense.mjs +3 -3
- package/assets/docs/principles.doc.mjs +4 -4
- package/assets/docs/principles.doc.zh.mjs +3 -3
- package/assets/docs/styling-overview.doc.mjs +5 -5
- package/assets/docs/tree/component-migration.doc.mjs +107 -0
- package/assets/docs/tree/css-and-stylex.doc.mjs +150 -0
- package/assets/docs/tree/font-setup.doc.mjs +122 -0
- package/assets/docs/tree/headers-and-footers.doc.mjs +0 -1
- package/assets/docs/tree/i18n-library-integration.doc.mjs +167 -0
- package/assets/docs/tree/i18n-quick-start.doc.mjs +101 -0
- package/assets/docs/{internationalization.doc.mjs → tree/i18n-rtl-and-testing.doc.mjs} +17 -223
- package/assets/docs/tree/internationalization.doc.mjs +29 -0
- package/assets/docs/tree/layout.doc.mjs +3 -0
- package/assets/docs/{migration.doc.mjs → tree/migration-setup.doc.mjs} +24 -129
- package/assets/docs/tree/migration-verification.doc.mjs +67 -0
- package/assets/docs/tree/migration.doc.mjs +28 -0
- package/assets/docs/tree/non-css-processing.doc.mjs +112 -0
- package/assets/docs/tree/other-libraries.doc.mjs +218 -0
- package/assets/docs/tree/responsive.doc.mjs +0 -4
- package/assets/docs/tree/scaffold.doc.mjs +0 -5
- package/assets/docs/tree/side-panels.doc.mjs +0 -1
- package/assets/docs/tree/structure.doc.mjs +0 -4
- package/assets/docs/tree/styling-advanced.doc.mjs +159 -0
- package/assets/docs/tree/styling-basics.doc.mjs +181 -0
- package/assets/docs/tree/styling-libraries.doc.mjs +30 -0
- package/assets/docs/tree/styling.doc.mjs +29 -0
- package/assets/docs/tree/tailwind.doc.mjs +65 -0
- package/assets/docs/tree/tokens-and-setup.doc.mjs +128 -0
- package/assets/docs/tree/tokens-border.doc.mjs +46 -0
- package/assets/docs/tree/tokens-color.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-color.doc.mjs +438 -0
- package/assets/docs/tree/tokens-color.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens-data.doc.mjs +323 -0
- package/assets/docs/tree/tokens-duration.doc.mjs +78 -0
- package/assets/docs/tree/tokens-ease.doc.mjs +46 -0
- package/assets/docs/tree/tokens-focus.doc.mjs +57 -0
- package/assets/docs/tree/tokens-font-weight.doc.mjs +58 -0
- package/assets/docs/tree/tokens-radius.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-radius.doc.mjs +70 -0
- package/assets/docs/tree/tokens-radius.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens-shadow.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-shadow.doc.mjs +74 -0
- package/assets/docs/tree/tokens-shadow.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens-size.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-size.doc.mjs +54 -0
- package/assets/docs/tree/tokens-size.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens-spacing.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-spacing.doc.mjs +102 -0
- package/assets/docs/tree/tokens-spacing.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens-syntax.doc.mjs +98 -0
- package/assets/docs/tree/tokens-text-size.doc.mjs +90 -0
- package/assets/docs/tree/tokens-type-scale.doc.mjs +210 -0
- package/assets/docs/tree/tokens-typography.doc.mjs +54 -0
- package/assets/docs/tree/tokens-usage.doc.dense.mjs +10 -0
- package/assets/docs/tree/tokens-usage.doc.mjs +36 -0
- package/assets/docs/tree/tokens-usage.doc.zh.mjs +10 -0
- package/assets/docs/tree/tokens.doc.mjs +28 -0
- package/assets/docs/tree/type-scale.doc.mjs +147 -0
- package/assets/docs/tree/typography-best-practices.doc.mjs +55 -0
- package/assets/docs/tree/typography.doc.mjs +29 -0
- package/assets/theme.template.ts +4 -3
- package/clients/cli/commands/component/index.mjs +4 -1
- package/clients/cli/commands/component-replacement.text.test.mjs +45 -0
- package/clients/cli/commands/docs.doc.mjs +2 -1
- package/clients/cli/commands/docs.test.mjs +13 -11
- package/clients/cli/commands/doctor-integration-components.doc.mjs +1 -1
- package/clients/cli/commands/doctor.test.mjs +33 -0
- package/clients/cli/lib/component-format.mjs +13 -3
- package/foundation/agent-docs/agent-docs.mjs +14 -1
- package/foundation/config/project.test.mjs +1 -1
- package/foundation/discovery/docs-discovery.test.mjs +1 -1
- package/foundation/doc-compiler/bundle.mjs +52 -1
- package/foundation/doc-compiler/split-topic-keywords.test.mjs +73 -0
- package/foundation/doc-compiler/tree.d.mts +10 -0
- package/foundation/doc-compiler/tree.mjs +22 -0
- package/foundation/doc-compiler/tree.test.mjs +3 -2
- package/foundation/env/package-manager.d.mts +3 -0
- package/foundation/env/package-manager.mjs +71 -3
- package/foundation/env/package-manager.test.mjs +82 -1
- package/foundation/integrations/validate-contributions.d.mts +16 -0
- package/foundation/integrations/validate-contributions.mjs +56 -8
- package/package.json +9 -9
- package/assets/docs/styling-libraries.doc.mjs +0 -469
- package/assets/docs/styling.doc.mjs +0 -412
- package/assets/docs/tokens.doc.dense.mjs +0 -15
- package/assets/docs/tokens.doc.mjs +0 -1491
- package/assets/docs/tokens.doc.zh.mjs +0 -15
- package/assets/docs/typography.doc.mjs +0 -286
|
@@ -65,7 +65,7 @@ describe('discoverBuiltinTopics', () => {
|
|
|
65
65
|
it("finds the CLI's own topics and not their localization overlays", () => {
|
|
66
66
|
const topics = discoverBuiltinTopics();
|
|
67
67
|
expect(Object.keys(topics).length).toBeGreaterThan(0);
|
|
68
|
-
expect(topics.
|
|
68
|
+
expect(topics.color).toMatch(/assets[/\\]docs[/\\]color\.doc\.mjs$/);
|
|
69
69
|
for (const name of Object.keys(topics)) {
|
|
70
70
|
expect(name).not.toMatch(/\.(zh|dense)$/);
|
|
71
71
|
}
|
|
@@ -118,10 +118,61 @@ export async function compileDocs(project, {lang = null} = {}) {
|
|
|
118
118
|
);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
+
// Guides placed in a namespace, lowered, so a token reference to the
|
|
122
|
+
// namespace (a flat topic split into guides, such as `tokens`) reads them
|
|
123
|
+
// in placement order as one topic, as the docs API does.
|
|
124
|
+
/** @type {Map<string, Array<{order: number, node: CompiledReferenceNode}>>} */
|
|
125
|
+
const placedGuides = new Map();
|
|
126
|
+
for (const input of inputs) {
|
|
127
|
+
if (
|
|
128
|
+
input.root !== 'tree' ||
|
|
129
|
+
(await treeDocType(input.file)) !== 'generic'
|
|
130
|
+
) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const topic = await loadTopicInput(
|
|
134
|
+
{
|
|
135
|
+
name: input.name,
|
|
136
|
+
package: input.owner,
|
|
137
|
+
path: input.file,
|
|
138
|
+
extensions: [],
|
|
139
|
+
tree: true,
|
|
140
|
+
},
|
|
141
|
+
lang,
|
|
142
|
+
);
|
|
143
|
+
if ('error' in topic.base || 'overlayError' in topic.base) continue;
|
|
144
|
+
const parent = /^namespace:(.+)$/u.exec(
|
|
145
|
+
topic.base.doc?.placement?.parent ?? '',
|
|
146
|
+
)?.[1];
|
|
147
|
+
if (!parent) continue;
|
|
148
|
+
try {
|
|
149
|
+
const node = lowerReferenceTopic(topic);
|
|
150
|
+
const list = placedGuides.get(parent.toLowerCase()) ?? [];
|
|
151
|
+
list.push({order: topic.base.doc.placement.order ?? 0, node});
|
|
152
|
+
placedGuides.set(parent.toLowerCase(), list);
|
|
153
|
+
} catch {
|
|
154
|
+
// Reported where the guide itself is compiled below.
|
|
155
|
+
}
|
|
156
|
+
}
|
|
121
157
|
/** @param {string} name */
|
|
122
158
|
const lowerTarget = async name => {
|
|
123
159
|
const target = catalog.resolve(name);
|
|
124
|
-
|
|
160
|
+
if (target) return topics.get(target.name.toLowerCase()) ?? null;
|
|
161
|
+
const guides = placedGuides.get(name.toLowerCase());
|
|
162
|
+
if (!guides) return null;
|
|
163
|
+
const ordered = [...guides].sort((a, b) => a.order - b.order);
|
|
164
|
+
/** @type {Record<string, string>} */
|
|
165
|
+
const sourceTitles = {};
|
|
166
|
+
for (const {node} of ordered) {
|
|
167
|
+
for (const [key, title] of Object.entries(node.sourceTitles)) {
|
|
168
|
+
sourceTitles[key] ??= title;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return /** @type {any} */ ({
|
|
172
|
+
id: name,
|
|
173
|
+
doc: {sections: ordered.flatMap(({node}) => node.doc.sections)},
|
|
174
|
+
sourceTitles,
|
|
175
|
+
});
|
|
125
176
|
};
|
|
126
177
|
|
|
127
178
|
/** @type {Array<CompiledDocNode | CompiledReferenceNode>} */
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file A topic split into a namespace of guides indexes each term once, a
|
|
5
|
+
* policy of the docs split itself (no spec clause states it). Below the CLI's own
|
|
6
|
+
* root namespaces (every one but `cli`, its command and API reference), a
|
|
7
|
+
* guide's search keywords are its own: none repeats a keyword its namespace,
|
|
8
|
+
* a sibling, or a guide of another split topic declares. A term several
|
|
9
|
+
* guides share belongs to their namespace, or to none.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import {fileURLToPath} from 'node:url';
|
|
15
|
+
import {describe, expect, it} from 'vitest';
|
|
16
|
+
|
|
17
|
+
const TREE_DIR = path.resolve(
|
|
18
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
19
|
+
'../../assets/docs/tree',
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
/** @returns {Promise<Map<string, any>>} every CLI tree doc, by name */
|
|
23
|
+
async function treeDocs() {
|
|
24
|
+
/** @type {Map<string, any>} */
|
|
25
|
+
const docs = new Map();
|
|
26
|
+
for (const file of fs.readdirSync(TREE_DIR)) {
|
|
27
|
+
if (!/^[\w-]+\.doc\.mjs$/.test(file)) continue;
|
|
28
|
+
const {docs: doc} = await import(path.join(TREE_DIR, file));
|
|
29
|
+
docs.set(doc.name, doc);
|
|
30
|
+
}
|
|
31
|
+
return docs;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @param {any} doc @returns {string | null} */
|
|
35
|
+
const parentOf = doc =>
|
|
36
|
+
/^namespace:(.+)$/.exec(doc.placement?.parent ?? '')?.[1] ?? null;
|
|
37
|
+
|
|
38
|
+
describe('the keywords of a split topic', () => {
|
|
39
|
+
it("are each declared once, and a guide's are its own", async () => {
|
|
40
|
+
const docs = await treeDocs();
|
|
41
|
+
/** @param {string} name */
|
|
42
|
+
const rootOf = name => {
|
|
43
|
+
let doc = docs.get(name);
|
|
44
|
+
while (doc && parentOf(doc)) doc = docs.get(parentOf(doc));
|
|
45
|
+
return doc?.name;
|
|
46
|
+
};
|
|
47
|
+
const roots = [...docs.values()]
|
|
48
|
+
.filter(doc => doc.type === 'namespace' && !parentOf(doc) && doc.name !== 'cli')
|
|
49
|
+
.map(doc => doc.name);
|
|
50
|
+
expect(roots).toContain('layout');
|
|
51
|
+
|
|
52
|
+
/** @type {Map<string, any[]>} */
|
|
53
|
+
const owners = new Map();
|
|
54
|
+
for (const doc of docs.values()) {
|
|
55
|
+
if (!roots.includes(rootOf(doc.name))) continue;
|
|
56
|
+
const own = new Set((doc.keywords ?? []).map(k => String(k).toLowerCase()));
|
|
57
|
+
for (const keyword of own) {
|
|
58
|
+
owners.set(keyword, [...(owners.get(keyword) ?? []), doc]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const repeats = [...owners]
|
|
62
|
+
.filter(([, holders]) => holders.length > 1 && holders.some(d => d.type !== 'namespace'))
|
|
63
|
+
.map(([keyword, holders]) => `${keyword}: ${holders.map(d => d.name).join(', ')}`);
|
|
64
|
+
expect(repeats).toEqual([]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('are not repeated inside one doc', async () => {
|
|
68
|
+
for (const doc of (await treeDocs()).values()) {
|
|
69
|
+
const keywords = (doc.keywords ?? []).map(k => String(k).toLowerCase());
|
|
70
|
+
expect(new Set(keywords).size, doc.name).toBe(keywords.length);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -26,6 +26,16 @@ export function buildDocsTree({ namespaces, docs, topics }: {
|
|
|
26
26
|
* @returns {string[]}
|
|
27
27
|
*/
|
|
28
28
|
export function treeDocFiles(dir?: string): string[];
|
|
29
|
+
/**
|
|
30
|
+
* The names of the CLI's own root namespaces (spec:AST-046 FR7): each is read
|
|
31
|
+
* with `astryx docs <name>`, as a flat topic is, though no topic file has its
|
|
32
|
+
* name. Read from the namespace files' text, without loading them, so a
|
|
33
|
+
* synchronous caller (the agent docs block) lists them beside the flat topics.
|
|
34
|
+
* A topic split into a namespace keeps its name in every such list.
|
|
35
|
+
* @param {string} [dir]
|
|
36
|
+
* @returns {string[]}
|
|
37
|
+
*/
|
|
38
|
+
export function cliRootNamespaceNames(dir?: string): string[];
|
|
29
39
|
/**
|
|
30
40
|
* The CLI's own tree inputs: the namespace docs and guides under
|
|
31
41
|
* assets/docs/tree, and, unless left out, every typed self-doc with its
|
|
@@ -744,6 +744,28 @@ export function treeDocFiles(dir = TREE_DOCS_DIR) {
|
|
|
744
744
|
.map(file => path.join(dir, file));
|
|
745
745
|
}
|
|
746
746
|
|
|
747
|
+
/**
|
|
748
|
+
* The names of the CLI's own root namespaces (spec:AST-046 FR7): each is read
|
|
749
|
+
* with `astryx docs <name>`, as a flat topic is, though no topic file has its
|
|
750
|
+
* name. Read from the namespace files' text, without loading them, so a
|
|
751
|
+
* synchronous caller (the agent docs block) lists them beside the flat topics.
|
|
752
|
+
* A topic split into a namespace keeps its name in every such list.
|
|
753
|
+
* @param {string} [dir]
|
|
754
|
+
* @returns {string[]}
|
|
755
|
+
*/
|
|
756
|
+
export function cliRootNamespaceNames(dir = TREE_DOCS_DIR) {
|
|
757
|
+
/** @type {string[]} */
|
|
758
|
+
const names = [];
|
|
759
|
+
for (const file of treeDocFiles(dir)) {
|
|
760
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
761
|
+
if (!/["']?type["']?\s*:\s*["']namespace["']/u.test(text)) continue;
|
|
762
|
+
if (/["']?placement["']?\s*:/u.test(text)) continue;
|
|
763
|
+
const name = /["']?name["']?\s*:\s*["']([\w-]+)["']/u.exec(text)?.[1];
|
|
764
|
+
if (name) names.push(name);
|
|
765
|
+
}
|
|
766
|
+
return names.sort(byText);
|
|
767
|
+
}
|
|
768
|
+
|
|
747
769
|
/**
|
|
748
770
|
* The CLI's own tree inputs: the namespace docs and guides under
|
|
749
771
|
* assets/docs/tree, and, unless left out, every typed self-doc with its
|
|
@@ -495,7 +495,7 @@ describe("the CLI's own docs tree", () => {
|
|
|
495
495
|
async () => {
|
|
496
496
|
const tree = await loadDocsTree({fresh: true});
|
|
497
497
|
expect(tree.diagnostics).toEqual([]);
|
|
498
|
-
expect(tree.roots().map(node => node.route)).toEqual(['cli', 'layout']);
|
|
498
|
+
expect(tree.roots().map(node => node.route)).toEqual(['cli', 'internationalization', 'layout', 'migration', 'styling', 'styling-libraries', 'tokens', 'typography']);
|
|
499
499
|
// Every slot child is a node one level below the namespace that places
|
|
500
500
|
// it, and every node but the root is placed. Read from the tree, so a
|
|
501
501
|
// restructure of the guides does not need this test edited.
|
|
@@ -518,10 +518,11 @@ describe("the CLI's own docs tree", () => {
|
|
|
518
518
|
}
|
|
519
519
|
}
|
|
520
520
|
expect(misplaced).toEqual([]);
|
|
521
|
+
const roots = new Set(tree.roots().map(node => node.route));
|
|
521
522
|
expect(
|
|
522
523
|
nodes
|
|
523
524
|
.map(node => node.route)
|
|
524
|
-
.filter(route => route
|
|
525
|
+
.filter(route => !roots.has(route) && !placed.has(route)),
|
|
525
526
|
).toEqual([]);
|
|
526
527
|
// The reference groups the CLI generates from its own typed docs.
|
|
527
528
|
expect(
|
|
@@ -80,6 +80,9 @@ export function getRunPrefix(targetDir?: string): string;
|
|
|
80
80
|
* {@link CLI_PACKAGE}, never the bare `astryx` bin. Running bare `npx astryx`
|
|
81
81
|
* without the CLI installed resolves to an unrelated package on the registry.
|
|
82
82
|
*
|
|
83
|
+
* Classic Yarn (1.x) has no `dlx`, so its projects get `npx`, which every
|
|
84
|
+
* Node install carries.
|
|
85
|
+
*
|
|
83
86
|
* @param {string} [targetDir]
|
|
84
87
|
* @returns {string} e.g. 'npx', 'pnpm dlx', 'yarn dlx', 'bunx'
|
|
85
88
|
*/
|
|
@@ -301,13 +301,16 @@ export const CLI_BIN = 'astryx';
|
|
|
301
301
|
* {@link CLI_PACKAGE}, never the bare `astryx` bin. Running bare `npx astryx`
|
|
302
302
|
* without the CLI installed resolves to an unrelated package on the registry.
|
|
303
303
|
*
|
|
304
|
+
* Classic Yarn (1.x) has no `dlx`, so its projects get `npx`, which every
|
|
305
|
+
* Node install carries.
|
|
306
|
+
*
|
|
304
307
|
* @param {string} [targetDir]
|
|
305
308
|
* @returns {string} e.g. 'npx', 'pnpm dlx', 'yarn dlx', 'bunx'
|
|
306
309
|
*/
|
|
307
310
|
export function getDlxPrefix(targetDir) {
|
|
308
|
-
const
|
|
309
|
-
switch (pm) {
|
|
310
|
-
case 'yarn': return 'yarn dlx';
|
|
311
|
+
const resolution = explainPackageManager(targetDir);
|
|
312
|
+
switch (resolution.pm) {
|
|
313
|
+
case 'yarn': return isYarnClassic(resolution) ? 'npx' : 'yarn dlx';
|
|
311
314
|
case 'pnpm': return 'pnpm dlx';
|
|
312
315
|
case 'bun': return 'bunx';
|
|
313
316
|
case 'npm':
|
|
@@ -315,6 +318,71 @@ export function getDlxPrefix(targetDir) {
|
|
|
315
318
|
}
|
|
316
319
|
}
|
|
317
320
|
|
|
321
|
+
/**
|
|
322
|
+
* Is the project's Yarn the classic line (1.x), which has no `dlx`?
|
|
323
|
+
*
|
|
324
|
+
* Read from the signals detection trusts, in the same order: the declared
|
|
325
|
+
* `packageManager` version, then the lockfile header (`# yarn lockfile v1`
|
|
326
|
+
* is classic; Berry's lockfile carries `__metadata:`), then a committed
|
|
327
|
+
* config (`.yarnrc.yml` is Berry, a lone `.yarnrc` classic), then the
|
|
328
|
+
* runner's user agent (`yarn/1.22.21 …`). With none of them it is Berry.
|
|
329
|
+
*
|
|
330
|
+
* @param {PackageManagerResolution} resolution
|
|
331
|
+
* @returns {boolean}
|
|
332
|
+
*/
|
|
333
|
+
function isYarnClassic({dir}) {
|
|
334
|
+
if (dir) {
|
|
335
|
+
const declared = declaredYarnMajor(dir);
|
|
336
|
+
if (declared !== null) return declared === 1;
|
|
337
|
+
const lockfile = path.join(dir, 'yarn.lock');
|
|
338
|
+
if (fs.existsSync(lockfile)) {
|
|
339
|
+
const head = readHead(lockfile);
|
|
340
|
+
if (/^# yarn lockfile v1\b/m.test(head)) return true;
|
|
341
|
+
if (/^__metadata:/m.test(head)) return false;
|
|
342
|
+
}
|
|
343
|
+
if (fs.existsSync(path.join(dir, '.yarnrc.yml'))) return false;
|
|
344
|
+
if (fs.existsSync(path.join(dir, '.yarnrc'))) return true;
|
|
345
|
+
}
|
|
346
|
+
const agent = /^yarn\/(\d+)\./.exec(String(process.env.npm_config_user_agent ?? ''));
|
|
347
|
+
return agent ? agent[1] === '1' : false;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* The major version in a directory's `packageManager: "yarn@<version>"`.
|
|
352
|
+
* @param {string} dir
|
|
353
|
+
* @returns {number | null}
|
|
354
|
+
*/
|
|
355
|
+
function declaredYarnMajor(dir) {
|
|
356
|
+
try {
|
|
357
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf-8'));
|
|
358
|
+
const match = /^yarn@(\d+)(?:[.+]|$)/.exec(String(pkg.packageManager ?? ''));
|
|
359
|
+
return match ? Number(match[1]) : null;
|
|
360
|
+
} catch {
|
|
361
|
+
// Best-effort: no package.json, or an unreadable one.
|
|
362
|
+
return null;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* The first bytes of a file — enough for a lockfile's header.
|
|
368
|
+
* @param {string} file
|
|
369
|
+
* @returns {string}
|
|
370
|
+
*/
|
|
371
|
+
function readHead(file) {
|
|
372
|
+
try {
|
|
373
|
+
const fd = fs.openSync(file, 'r');
|
|
374
|
+
try {
|
|
375
|
+
const buffer = Buffer.alloc(512);
|
|
376
|
+
const bytes = fs.readSync(fd, buffer, 0, buffer.length, 0);
|
|
377
|
+
return buffer.toString('utf-8', 0, bytes);
|
|
378
|
+
} finally {
|
|
379
|
+
fs.closeSync(fd);
|
|
380
|
+
}
|
|
381
|
+
} catch {
|
|
382
|
+
return '';
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
318
386
|
/**
|
|
319
387
|
* Heuristic: was the running CLI launched one-off via a package runner
|
|
320
388
|
* (npx / pnpm dlx / yarn dlx / bunx) rather than from an installed dependency?
|
|
@@ -39,6 +39,14 @@ function linkCliBin(dir, name = 'astryx') {
|
|
|
39
39
|
fs.writeFileSync(path.join(binDir, name), '');
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/** The header a classic Yarn (1.x) lockfile starts with. */
|
|
43
|
+
const YARN_V1_LOCK =
|
|
44
|
+
'# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n# yarn lockfile v1\n\n';
|
|
45
|
+
|
|
46
|
+
/** The header a Berry (Yarn 2+) lockfile starts with. */
|
|
47
|
+
const YARN_BERRY_LOCK =
|
|
48
|
+
'# This file is generated by running "yarn install" inside your project.\n# Manual changes might be lost - proceed with caution!\n\n__metadata:\n version: 8\n';
|
|
49
|
+
|
|
42
50
|
/** An installed CLI's entry, outside any runner cache (a global or workspace install). */
|
|
43
51
|
const INSTALLED_ENTRY = '/usr/local/lib/node_modules/@astryxdesign/cli/clients/cli/bin/astryx.mjs';
|
|
44
52
|
|
|
@@ -325,6 +333,78 @@ describe('getDlxPrefix', () => {
|
|
|
325
333
|
expect(getDlxPrefix(dir)).toBe('yarn dlx');
|
|
326
334
|
});
|
|
327
335
|
|
|
336
|
+
// Classic Yarn (1.x) has no `dlx`; `yarn dlx …` fails there, so its one-off
|
|
337
|
+
// form is `npx`. Berry (2+) keeps `yarn dlx`.
|
|
338
|
+
it('returns "npx" for a classic Yarn lockfile', () => {
|
|
339
|
+
const dir = makeTmpDir();
|
|
340
|
+
fs.writeFileSync(path.join(dir, 'yarn.lock'), YARN_V1_LOCK);
|
|
341
|
+
expect(getDlxPrefix(dir)).toBe('npx');
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it('returns "yarn dlx" for a Berry lockfile', () => {
|
|
345
|
+
const dir = makeTmpDir();
|
|
346
|
+
fs.writeFileSync(path.join(dir, 'yarn.lock'), YARN_BERRY_LOCK);
|
|
347
|
+
expect(getDlxPrefix(dir)).toBe('yarn dlx');
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it('reads the declared packageManager version first', () => {
|
|
351
|
+
const classic = makeTmpDir();
|
|
352
|
+
fs.writeFileSync(
|
|
353
|
+
path.join(classic, 'package.json'),
|
|
354
|
+
JSON.stringify({packageManager: 'yarn@1.22.19'}),
|
|
355
|
+
);
|
|
356
|
+
// A Berry-looking lockfile does not outrank the declaration.
|
|
357
|
+
fs.writeFileSync(path.join(classic, 'yarn.lock'), YARN_BERRY_LOCK);
|
|
358
|
+
expect(getDlxPrefix(classic)).toBe('npx');
|
|
359
|
+
fs.rmSync(classic, {recursive: true, force: true});
|
|
360
|
+
|
|
361
|
+
const berry = makeTmpDir();
|
|
362
|
+
fs.writeFileSync(
|
|
363
|
+
path.join(berry, 'package.json'),
|
|
364
|
+
JSON.stringify({packageManager: 'yarn@4.5.0'}),
|
|
365
|
+
);
|
|
366
|
+
fs.writeFileSync(path.join(berry, 'yarn.lock'), YARN_V1_LOCK);
|
|
367
|
+
expect(getDlxPrefix(berry)).toBe('yarn dlx');
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('reads a bare major version in the declaration', () => {
|
|
371
|
+
const classic = makeTmpDir();
|
|
372
|
+
fs.writeFileSync(
|
|
373
|
+
path.join(classic, 'package.json'),
|
|
374
|
+
JSON.stringify({packageManager: 'yarn@1'}),
|
|
375
|
+
);
|
|
376
|
+
expect(getDlxPrefix(classic)).toBe('npx');
|
|
377
|
+
fs.rmSync(classic, {recursive: true, force: true});
|
|
378
|
+
|
|
379
|
+
const berry = makeTmpDir();
|
|
380
|
+
fs.writeFileSync(
|
|
381
|
+
path.join(berry, 'package.json'),
|
|
382
|
+
JSON.stringify({packageManager: 'yarn@4'}),
|
|
383
|
+
);
|
|
384
|
+
expect(getDlxPrefix(berry)).toBe('yarn dlx');
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it('reads a committed Yarn config when the lockfile has no header', () => {
|
|
388
|
+
const classic = makeTmpDir();
|
|
389
|
+
fs.writeFileSync(path.join(classic, 'yarn.lock'), '');
|
|
390
|
+
fs.writeFileSync(path.join(classic, '.yarnrc'), '');
|
|
391
|
+
expect(getDlxPrefix(classic)).toBe('npx');
|
|
392
|
+
fs.rmSync(classic, {recursive: true, force: true});
|
|
393
|
+
|
|
394
|
+
const berry = makeTmpDir();
|
|
395
|
+
fs.writeFileSync(path.join(berry, 'yarn.lock'), '');
|
|
396
|
+
fs.writeFileSync(path.join(berry, '.yarnrc.yml'), '');
|
|
397
|
+
expect(getDlxPrefix(berry)).toBe('yarn dlx');
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
it('reads the runner version when nothing on disk names Yarn', () => {
|
|
401
|
+
makeTmpDir();
|
|
402
|
+
process.env.npm_config_user_agent = 'yarn/1.22.21 npm/? node/v22.0.0';
|
|
403
|
+
expect(getDlxPrefix(tmpDir)).toBe('npx');
|
|
404
|
+
process.env.npm_config_user_agent = 'yarn/4.5.0 npm/? node/v22.0.0';
|
|
405
|
+
expect(getDlxPrefix(tmpDir)).toBe('yarn dlx');
|
|
406
|
+
});
|
|
407
|
+
|
|
328
408
|
it('returns "bunx" for bun projects', () => {
|
|
329
409
|
const dir = makeTmpDir();
|
|
330
410
|
fs.writeFileSync(path.join(dir, 'bun.lockb'), '');
|
|
@@ -428,7 +508,8 @@ describe('getCliInvocation', () => {
|
|
|
428
508
|
it.each([
|
|
429
509
|
['package-lock.json', '{}', 'npx @astryxdesign/cli'],
|
|
430
510
|
['pnpm-lock.yaml', '', 'pnpm dlx @astryxdesign/cli'],
|
|
431
|
-
['yarn.lock',
|
|
511
|
+
['yarn.lock', YARN_BERRY_LOCK, 'yarn dlx @astryxdesign/cli'],
|
|
512
|
+
['yarn.lock', YARN_V1_LOCK, 'npx @astryxdesign/cli'],
|
|
432
513
|
['bun.lockb', '', 'bunx @astryxdesign/cli'],
|
|
433
514
|
])(
|
|
434
515
|
'prints the scoped package for a project with no local CLI (%s), launched from an installed path',
|
|
@@ -5,6 +5,22 @@
|
|
|
5
5
|
export function issueError(code: string, message: string): Issue;
|
|
6
6
|
/** @param {string} code @param {string} message @returns {Issue} */
|
|
7
7
|
export function issueWarning(code: string, message: string): Issue;
|
|
8
|
+
/**
|
|
9
|
+
* Why a declared root cannot be read as a folder, or null when it can.
|
|
10
|
+
* A missing root keeps its own issue; a root that is a file or that the
|
|
11
|
+
* user running astryx cannot read used to surface as a raw errno from
|
|
12
|
+
* whichever check touched it first, or end validation outright.
|
|
13
|
+
* @param {string} root
|
|
14
|
+
* @returns {{kind: 'missing'} | {kind: 'not-a-folder'} | {kind: 'unreadable', code: string} | null}
|
|
15
|
+
*/
|
|
16
|
+
export function rootProblem(root: string): {
|
|
17
|
+
kind: "missing";
|
|
18
|
+
} | {
|
|
19
|
+
kind: "not-a-folder";
|
|
20
|
+
} | {
|
|
21
|
+
kind: "unreadable";
|
|
22
|
+
code: string;
|
|
23
|
+
} | null;
|
|
8
24
|
/**
|
|
9
25
|
* Validate an already-LOADED integration (as produced by `loadIntegrations` —
|
|
10
26
|
* absolute contribution roots plus identity) and return its issues. This is the
|
|
@@ -99,8 +99,40 @@ function checkUnknownKeys(integration, issues) {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
|
-
*
|
|
103
|
-
* root is a
|
|
102
|
+
* Why a declared root cannot be read as a folder, or null when it can.
|
|
103
|
+
* A missing root keeps its own issue; a root that is a file or that the
|
|
104
|
+
* user running astryx cannot read used to surface as a raw errno from
|
|
105
|
+
* whichever check touched it first, or end validation outright.
|
|
106
|
+
* @param {string} root
|
|
107
|
+
* @returns {{kind: 'missing'} | {kind: 'not-a-folder'} | {kind: 'unreadable', code: string} | null}
|
|
108
|
+
*/
|
|
109
|
+
export function rootProblem(root) {
|
|
110
|
+
let stat;
|
|
111
|
+
try {
|
|
112
|
+
stat = fs.statSync(root);
|
|
113
|
+
} catch (err) {
|
|
114
|
+
const code = /** @type {any} */ (err)?.code;
|
|
115
|
+
return code === 'ENOENT' || code === 'ENOTDIR'
|
|
116
|
+
? {kind: 'missing'}
|
|
117
|
+
: {kind: 'unreadable', code: String(code ?? 'unknown error')};
|
|
118
|
+
}
|
|
119
|
+
if (!stat.isDirectory()) return {kind: 'not-a-folder'};
|
|
120
|
+
try {
|
|
121
|
+
fs.accessSync(root, fs.constants.R_OK | fs.constants.X_OK);
|
|
122
|
+
} catch (err) {
|
|
123
|
+
return {
|
|
124
|
+
kind: 'unreadable',
|
|
125
|
+
code: String(/** @type {any} */ (err)?.code ?? 'unknown error'),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Verify each declared contribution root is a folder Astryx can read. A
|
|
133
|
+
* declared-but-missing root is a `missing_root` error, a file is an
|
|
134
|
+
* `invalid_root` error, and a folder that cannot be read is an
|
|
135
|
+
* `unreadable_root` error. The contribution checks skip all three.
|
|
104
136
|
* @param {{components?: string, templates?: string, codemods?: string, docs?: string, themes?: string}} resolved
|
|
105
137
|
* absolute resolved roots (undefined when not declared)
|
|
106
138
|
* @param {Issue[]} issues
|
|
@@ -116,13 +148,29 @@ function checkRoots(resolved, issues) {
|
|
|
116
148
|
for (const kind of kinds) {
|
|
117
149
|
const root = resolved[kind];
|
|
118
150
|
if (root == null) continue;
|
|
119
|
-
|
|
151
|
+
const problem = rootProblem(root);
|
|
152
|
+
if (problem == null) continue;
|
|
153
|
+
if (problem.kind === 'missing') {
|
|
120
154
|
issues.push(
|
|
121
155
|
issueError(
|
|
122
156
|
'missing_root',
|
|
123
157
|
`Declared ${kind} root does not exist on disk: ${root}`,
|
|
124
158
|
),
|
|
125
159
|
);
|
|
160
|
+
} else if (problem.kind === 'not-a-folder') {
|
|
161
|
+
issues.push(
|
|
162
|
+
issueError(
|
|
163
|
+
'invalid_root',
|
|
164
|
+
`Declared ${kind} root is a file, not a folder: ${root}. Fix: point "${kind}" in the manifest at the folder that holds them.`,
|
|
165
|
+
),
|
|
166
|
+
);
|
|
167
|
+
} else {
|
|
168
|
+
issues.push(
|
|
169
|
+
issueError(
|
|
170
|
+
'unreadable_root',
|
|
171
|
+
`Declared ${kind} root cannot be read (${problem.code}): ${root}. Fix: make it readable by the user running astryx.`,
|
|
172
|
+
),
|
|
173
|
+
);
|
|
126
174
|
}
|
|
127
175
|
}
|
|
128
176
|
}
|
|
@@ -135,7 +183,7 @@ function checkRoots(resolved, issues) {
|
|
|
135
183
|
* @param {Issue[]} issues
|
|
136
184
|
*/
|
|
137
185
|
async function checkCodemods(integration, issues) {
|
|
138
|
-
if (!integration.codemods ||
|
|
186
|
+
if (!integration.codemods || rootProblem(integration.codemods)) return;
|
|
139
187
|
const context = integration.__packageDir
|
|
140
188
|
? createFixContext(integration.__packageDir, integration)
|
|
141
189
|
: null;
|
|
@@ -232,7 +280,7 @@ async function checkCodemods(integration, issues) {
|
|
|
232
280
|
* @param {Issue[]} issues
|
|
233
281
|
*/
|
|
234
282
|
async function checkTemplates(integration, issues) {
|
|
235
|
-
if (!integration.templates ||
|
|
283
|
+
if (!integration.templates || rootProblem(integration.templates)) return;
|
|
236
284
|
try {
|
|
237
285
|
const {errors} = await discoverIntegrationTemplatesForOne(integration);
|
|
238
286
|
for (const e of errors) {
|
|
@@ -257,7 +305,7 @@ async function checkTemplates(integration, issues) {
|
|
|
257
305
|
* @param {Issue[]} issues
|
|
258
306
|
*/
|
|
259
307
|
async function checkComponents(integration, issues) {
|
|
260
|
-
if (!integration.components ||
|
|
308
|
+
if (!integration.components || rootProblem(integration.components)) return;
|
|
261
309
|
const discover = componentDiscovery.discoverValidIntegrationComponents;
|
|
262
310
|
if (typeof discover !== 'function') return; // feature not present yet
|
|
263
311
|
try {
|
|
@@ -330,7 +378,7 @@ async function checkComponents(integration, issues) {
|
|
|
330
378
|
* @param {Issue[]} issues
|
|
331
379
|
*/
|
|
332
380
|
async function checkDocs(integration, issues) {
|
|
333
|
-
if (!integration.docs ||
|
|
381
|
+
if (!integration.docs || rootProblem(integration.docs)) return;
|
|
334
382
|
try {
|
|
335
383
|
const {errors} = await discoverIntegrationDocs(integration);
|
|
336
384
|
for (const e of errors) {
|
|
@@ -349,7 +397,7 @@ async function checkDocs(integration, issues) {
|
|
|
349
397
|
* @param {Issue[]} issues
|
|
350
398
|
*/
|
|
351
399
|
async function checkThemes(integration, issues) {
|
|
352
|
-
if (!integration.themes ||
|
|
400
|
+
if (!integration.themes || rootProblem(integration.themes)) return;
|
|
353
401
|
try {
|
|
354
402
|
await discoverIntegrationThemes(integration);
|
|
355
403
|
} catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.6.6-canary.
|
|
3
|
+
"version": "0.6.6-canary.ffa4f72",
|
|
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",
|
|
@@ -101,10 +101,10 @@
|
|
|
101
101
|
"zod": "^4.4.3"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
|
-
"@astryxdesign/charts": "0.6.6-canary.
|
|
105
|
-
"@astryxdesign/core": "0.6.6-canary.
|
|
106
|
-
"@astryxdesign/lab": "0.6.6-canary.
|
|
107
|
-
"@astryxdesign/theme-neutral": "0.6.6-canary.
|
|
104
|
+
"@astryxdesign/charts": "0.6.6-canary.ffa4f72",
|
|
105
|
+
"@astryxdesign/core": "0.6.6-canary.ffa4f72",
|
|
106
|
+
"@astryxdesign/lab": "0.6.6-canary.ffa4f72",
|
|
107
|
+
"@astryxdesign/theme-neutral": "0.6.6-canary.ffa4f72"
|
|
108
108
|
},
|
|
109
109
|
"peerDependenciesMeta": {
|
|
110
110
|
"@astryxdesign/charts": {
|
|
@@ -121,10 +121,10 @@
|
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
123
|
"devDependencies": {
|
|
124
|
-
"@astryxdesign/charts": "0.6.6-canary.
|
|
125
|
-
"@astryxdesign/core": "0.6.6-canary.
|
|
126
|
-
"@astryxdesign/lab": "0.6.6-canary.
|
|
127
|
-
"@astryxdesign/theme-neutral": "0.6.6-canary.
|
|
124
|
+
"@astryxdesign/charts": "0.6.6-canary.ffa4f72",
|
|
125
|
+
"@astryxdesign/core": "0.6.6-canary.ffa4f72",
|
|
126
|
+
"@astryxdesign/lab": "0.6.6-canary.ffa4f72",
|
|
127
|
+
"@astryxdesign/theme-neutral": "0.6.6-canary.ffa4f72",
|
|
128
128
|
"@heroicons/react": "^2.2.0",
|
|
129
129
|
"@stylexjs/stylex": "^0.19.0",
|
|
130
130
|
"@types/babel__core": "^7.20.5",
|