@astryxdesign/cli 0.6.1 → 0.6.2-canary.2414712
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/CHANGELOG.md +35 -1
- package/README.md +1 -1
- package/api/component/_adapter.mjs +64 -23
- package/api/component/component.doc.mjs +1 -1
- package/api/component/component.type.d.mts +8 -2
- package/api/component/component.type.mjs +5 -2
- package/api/component/integration-import-agreement.test.mjs +162 -6
- package/api/component/list/list.mjs +91 -15
- package/api/doctor/doctor.mjs +5 -16
- package/api/init/init.doc.mjs +2 -2
- package/api/init/init.type.d.mts +1 -1
- package/api/init/init.type.mjs +1 -1
- package/api/init/run/run.mjs +1 -1
- package/api/integration/add-helpers.mjs +2 -1
- package/api/integration/pack-check.mjs +9 -3
- package/api/search/search.d.mts +1 -1
- package/api/search/search.mjs +135 -41
- package/api/theme/build/build.d.mts +45 -17
- package/api/theme/build/build.family.test.mjs +435 -0
- package/api/theme/build/build.mjs +681 -121
- package/api/theme/build/build.packed-old-core.test.mjs +25 -9
- package/api/theme/build/build.test.mjs +142 -0
- package/api/theme/build/core-interception.d.mts +14 -2
- package/api/theme/build/core-interception.mjs +38 -14
- package/api/theme/build/family.d.mts +15 -0
- package/api/theme/build/family.mjs +442 -0
- package/api/theme/palette/generate/generate.mjs +2 -1
- package/assets/docs/theme.doc.dense.mjs +12 -0
- package/assets/docs/theme.doc.mjs +37 -0
- package/assets/docs/working-with-ai.doc.mjs +2 -1
- package/clients/cli/commands/build-theme.mjs +63 -5
- package/clients/cli/commands/component/index.mjs +4 -1
- package/clients/cli/commands/init.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +28 -10
- package/foundation/agent-docs/agent-doc-state.mjs +1 -1
- package/foundation/agent-docs/agent-docs.d.mts +2 -2
- package/foundation/agent-docs/agent-docs.mjs +8 -6
- package/foundation/agent-docs/agent-docs.test.mjs +14 -0
- package/foundation/discovery/__fixtures__/component-both-exports.doc.d.mts +24 -0
- package/foundation/discovery/__fixtures__/component-both-exports.doc.mjs +19 -0
- package/foundation/discovery/__fixtures__/component-default-export.doc.d.mts +14 -0
- package/foundation/discovery/__fixtures__/component-default-export.doc.mjs +13 -0
- package/foundation/discovery/__fixtures__/component-named-export.doc.d.mts +13 -0
- package/foundation/discovery/__fixtures__/component-named-export.doc.mjs +11 -0
- package/foundation/discovery/component-discovery.d.mts +5 -3
- package/foundation/discovery/component-discovery.mjs +25 -9
- package/foundation/discovery/component-loader.mjs +4 -1
- package/foundation/discovery/component-loader.test.mjs +48 -0
- package/foundation/discovery/theming-targets.test.mjs +29 -0
- package/foundation/fs/paths.d.mts +19 -0
- package/foundation/fs/paths.mjs +54 -0
- package/foundation/fs/paths.test.mjs +102 -1
- package/foundation/fs/publish-file-eperm-mutation.test.mjs +62 -0
- package/foundation/fs/publish-file-hardlink-unavailable.test.mjs +107 -0
- package/foundation/fs/publish-file.d.mts +22 -0
- package/foundation/fs/publish-file.mjs +68 -0
- package/foundation/fs/publish-file.test.mjs +136 -0
- package/foundation/integrations/manifest-writer.mjs +2 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +15 -10
|
@@ -14,19 +14,32 @@ export const doc = {
|
|
|
14
14
|
name: 'theme build',
|
|
15
15
|
displayName: 'astryx theme build',
|
|
16
16
|
namespace: 'cli',
|
|
17
|
-
summary: 'Compile
|
|
17
|
+
summary: 'Compile standalone themes or one keyed theme family',
|
|
18
18
|
description:
|
|
19
|
-
'Compiles
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'fully specified module path that the generated JS should import.',
|
|
19
|
+
'Compiles defineTheme() sources through the same theme pipeline into scoped CSS, ' +
|
|
20
|
+
'standard ESM, and type declarations. Ordinary mode writes one complete set per ' +
|
|
21
|
+
'theme. --family combines one selected extension tree into the three files named by ' +
|
|
22
|
+
'the required --family-key, ready for one CSS load and identity-only switching. ' +
|
|
23
|
+
'With --check it writes nothing and reports source drift. --icons-specifier keeps ' +
|
|
24
|
+
'its existing generated-module behavior.',
|
|
26
25
|
fn: 'themeBuild',
|
|
27
26
|
args: [{name: 'files', param: 'file', required: true, variadic: true}],
|
|
28
27
|
options: [
|
|
29
|
-
{
|
|
28
|
+
{
|
|
29
|
+
flag: '--family',
|
|
30
|
+
description:
|
|
31
|
+
'Build the selected extension family into one keyed CSS, JS, and declaration set',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
flag: '--family-key <key>',
|
|
35
|
+
description:
|
|
36
|
+
'Lower-kebab filename stem required with --family; must differ from every member name',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
flag: '-o, --out <path>',
|
|
40
|
+
param: 'options.out',
|
|
41
|
+
description: 'Output CSS file path (single theme only)',
|
|
42
|
+
},
|
|
30
43
|
{
|
|
31
44
|
flag: '--icons-specifier <specifier>',
|
|
32
45
|
param: 'options.iconsSpecifier',
|
|
@@ -35,7 +48,8 @@ export const doc = {
|
|
|
35
48
|
},
|
|
36
49
|
{
|
|
37
50
|
flag: '-w, --watch',
|
|
38
|
-
description:
|
|
51
|
+
description:
|
|
52
|
+
'Rebuild automatically when a theme file changes (Ctrl-C to stop)',
|
|
39
53
|
},
|
|
40
54
|
{
|
|
41
55
|
flag: '-c, --check',
|
|
@@ -49,6 +63,10 @@ export const doc = {
|
|
|
49
63
|
label: 'Build to a CSS file',
|
|
50
64
|
cli: 'astryx theme build ./src/themes/ocean.ts --out ./dist/ocean.css',
|
|
51
65
|
},
|
|
66
|
+
{
|
|
67
|
+
label: 'Build one related family for attribute-only switching',
|
|
68
|
+
cli: 'astryx theme build --family ./themes/ocean.mjs ./themes/ocean-calm.mjs --family-key ocean-family',
|
|
69
|
+
},
|
|
52
70
|
{
|
|
53
71
|
label: 'Build every theme in a directory',
|
|
54
72
|
cli: 'astryx theme build ./src/themes/*.ts',
|
|
@@ -47,7 +47,7 @@ export const LEGACY_MARKER_END = '<!-- XDS:END -->';
|
|
|
47
47
|
* targets are user-chosen and not enumerable here.)
|
|
48
48
|
*/
|
|
49
49
|
export const AGENT_DOC_PATHS = [
|
|
50
|
-
AGENTS_MD, // Codex / ChatGPT / generic
|
|
50
|
+
AGENTS_MD, // Codex / ChatGPT / Muse / generic
|
|
51
51
|
CLAUDE_MD, // Claude Code (root)
|
|
52
52
|
CLAUDE_DIR_MD, // Claude Code (.claude/CLAUDE.md)
|
|
53
53
|
CURSOR_RULES, // Cursor
|
|
@@ -53,7 +53,7 @@ export function inspectAgentDocs(targetDir: string, installedVersion?: string, e
|
|
|
53
53
|
* Searches for existing files first, falls back to default creation path.
|
|
54
54
|
*
|
|
55
55
|
* @param {string} targetDir
|
|
56
|
-
* @param {string} agent - Preset name: 'claude', 'cursor', 'codex', 'hermes', 'all'
|
|
56
|
+
* @param {string} agent - Preset name: 'claude', 'cursor', 'codex', 'hermes', 'muse', 'all'
|
|
57
57
|
* @returns {{inject: string[], create: string[]}} Files to inject into vs create fresh
|
|
58
58
|
*/
|
|
59
59
|
export function resolveAgentPaths(targetDir: string, agent: string): {
|
|
@@ -199,7 +199,7 @@ export function removeAgentDocs(targetDir: string): void;
|
|
|
199
199
|
* @param {object} [options]
|
|
200
200
|
* @param {boolean} [options.zh]
|
|
201
201
|
* @param {string} [options.lang]
|
|
202
|
-
* @param {string} [options.agent] - Tool preset: 'claude', 'cursor', 'codex', 'hermes', 'all'
|
|
202
|
+
* @param {string} [options.agent] - Tool preset: 'claude', 'cursor', 'codex', 'hermes', 'muse', 'all'
|
|
203
203
|
* @param {string[]} [options.paths] - Explicit paths (overrides agent/auto-detect)
|
|
204
204
|
* @param {boolean} [options.onlyReplace] - Only update files that already have Astryx markers (for upgrades)
|
|
205
205
|
* @param {string[]} [options.topics] - Doc topics to list in the block; defaults
|
|
@@ -9,12 +9,13 @@
|
|
|
9
9
|
* - Claude Code: CLAUDE.md (root) or .claude/CLAUDE.md
|
|
10
10
|
* - Cursor: .cursorrules
|
|
11
11
|
* - Codex/generic: AGENTS.md
|
|
12
|
+
* - Muse: AGENTS.md
|
|
12
13
|
* - Hermes Agent: .hermes.md or HERMES.md (existing), else AGENTS.md
|
|
13
14
|
*
|
|
14
15
|
* Auto-detect: discovers existing files and updates them in place.
|
|
15
16
|
* Default (no existing files): creates AGENTS.md (the tool-agnostic standard).
|
|
16
17
|
*
|
|
17
|
-
* --agent <tool>: target a specific tool preset (claude, cursor, codex, hermes, all)
|
|
18
|
+
* --agent <tool>: target a specific tool preset (claude, cursor, codex, hermes, muse, all)
|
|
18
19
|
* --agent-docs-path <path>: explicit file path(s)
|
|
19
20
|
*/
|
|
20
21
|
|
|
@@ -181,6 +182,7 @@ const AGENT_PRESETS = {
|
|
|
181
182
|
cursor: [CURSOR_RULES, AGENTS_MD],
|
|
182
183
|
codex: [AGENTS_MD],
|
|
183
184
|
hermes: [HERMES_DOT_MD, HERMES_MD, AGENTS_MD],
|
|
185
|
+
muse: [AGENTS_MD],
|
|
184
186
|
};
|
|
185
187
|
|
|
186
188
|
/**
|
|
@@ -280,7 +282,7 @@ export function inspectAgentDocs(targetDir, installedVersion, expectedBlock) {
|
|
|
280
282
|
* Searches for existing files first, falls back to default creation path.
|
|
281
283
|
*
|
|
282
284
|
* @param {string} targetDir
|
|
283
|
-
* @param {string} agent - Preset name: 'claude', 'cursor', 'codex', 'hermes', 'all'
|
|
285
|
+
* @param {string} agent - Preset name: 'claude', 'cursor', 'codex', 'hermes', 'muse', 'all'
|
|
284
286
|
* @returns {{inject: string[], create: string[]}} Files to inject into vs create fresh
|
|
285
287
|
*/
|
|
286
288
|
export function resolveAgentPaths(targetDir, agent) {
|
|
@@ -739,7 +741,7 @@ export function removeAgentDocs(targetDir) {
|
|
|
739
741
|
* @param {object} [options]
|
|
740
742
|
* @param {boolean} [options.zh]
|
|
741
743
|
* @param {string} [options.lang]
|
|
742
|
-
* @param {string} [options.agent] - Tool preset: 'claude', 'cursor', 'codex', 'hermes', 'all'
|
|
744
|
+
* @param {string} [options.agent] - Tool preset: 'claude', 'cursor', 'codex', 'hermes', 'muse', 'all'
|
|
743
745
|
* @param {string[]} [options.paths] - Explicit paths (overrides agent/auto-detect)
|
|
744
746
|
* @param {boolean} [options.onlyReplace] - Only update files that already have Astryx markers (for upgrades)
|
|
745
747
|
* @param {string[]} [options.topics] - Doc topics to list in the block; defaults
|
|
@@ -852,9 +854,9 @@ export function installAgentDocs(
|
|
|
852
854
|
}
|
|
853
855
|
|
|
854
856
|
// Nothing exists — create root AGENTS.md as the default (skip if onlyReplace).
|
|
855
|
-
// AGENTS.md is the tool-agnostic standard (Codex/Copilot, Cursor, and
|
|
856
|
-
// agents read it), so it's the safe default. Claude-specific output is
|
|
857
|
-
// via `--agent claude` (→ .claude/CLAUDE.md); `--agent all` writes both.
|
|
857
|
+
// AGENTS.md is the tool-agnostic standard (Codex/Copilot, Cursor, Muse, and
|
|
858
|
+
// most agents read it), so it's the safe default. Claude-specific output is
|
|
859
|
+
// opt-in via `--agent claude` (→ .claude/CLAUDE.md); `--agent all` writes both.
|
|
858
860
|
if (onlyReplace) return written;
|
|
859
861
|
|
|
860
862
|
const defaultPath = AGENTS_MD;
|
|
@@ -793,6 +793,15 @@ describe('installAgentDocs', () => {
|
|
|
793
793
|
expect(fs.existsSync(path.join(tmpDir, '.claude'))).toBe(false);
|
|
794
794
|
});
|
|
795
795
|
|
|
796
|
+
it('respects --agent muse preset: creates AGENTS.md', () => {
|
|
797
|
+
setupCorePackage(tmpDir);
|
|
798
|
+
|
|
799
|
+
const written = installAgentDocs(tmpDir, {agent: 'muse'});
|
|
800
|
+
|
|
801
|
+
expect(written).toEqual(['AGENTS.md']);
|
|
802
|
+
expect(fs.existsSync(path.join(tmpDir, 'AGENTS.md'))).toBe(true);
|
|
803
|
+
});
|
|
804
|
+
|
|
796
805
|
it('respects explicit --paths', () => {
|
|
797
806
|
setupCorePackage(tmpDir);
|
|
798
807
|
|
|
@@ -911,6 +920,11 @@ describe('resolveAgentPaths', () => {
|
|
|
911
920
|
expect(result).toEqual({inject: ['HERMES.md'], create: []});
|
|
912
921
|
});
|
|
913
922
|
|
|
923
|
+
it('muse preset creates AGENTS.md when nothing exists', () => {
|
|
924
|
+
const result = resolveAgentPaths(tmpDir, 'muse');
|
|
925
|
+
expect(result).toEqual({inject: [], create: ['AGENTS.md']});
|
|
926
|
+
});
|
|
927
|
+
|
|
914
928
|
it('claude preset still creates .claude/CLAUDE.md when nothing exists (hermes is additive)', () => {
|
|
915
929
|
const result = resolveAgentPaths(tmpDir, 'claude');
|
|
916
930
|
expect(result).toEqual({inject: [], create: ['.claude/CLAUDE.md']});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
declare namespace _default {
|
|
5
|
+
let type: string;
|
|
6
|
+
let name: string;
|
|
7
|
+
let description: string;
|
|
8
|
+
let props: {
|
|
9
|
+
name: string;
|
|
10
|
+
type: string;
|
|
11
|
+
description: string;
|
|
12
|
+
}[];
|
|
13
|
+
}
|
|
14
|
+
export default _default;
|
|
15
|
+
export namespace docs {
|
|
16
|
+
let type_1: string;
|
|
17
|
+
export { type_1 as type };
|
|
18
|
+
let name_1: string;
|
|
19
|
+
export { name_1 as name };
|
|
20
|
+
let description_1: string;
|
|
21
|
+
export { description_1 as description };
|
|
22
|
+
let props_1: never[];
|
|
23
|
+
export { props_1 as props };
|
|
24
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Fixture: a component doc that has BOTH a default export and a named `docs`
|
|
5
|
+
* export. The default export must win (same precedence as loadComponentDoc).
|
|
6
|
+
*/
|
|
7
|
+
export default {
|
|
8
|
+
type: 'component',
|
|
9
|
+
name: 'DefaultWinsCard',
|
|
10
|
+
description: 'From the default export.',
|
|
11
|
+
props: [{name: 'priority', type: 'number', description: 'Priority level.'}],
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const docs = {
|
|
15
|
+
type: 'component',
|
|
16
|
+
name: 'NamedLosesCard',
|
|
17
|
+
description: 'From the named export — must NOT be returned.',
|
|
18
|
+
props: [],
|
|
19
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
declare namespace _default {
|
|
5
|
+
let type: string;
|
|
6
|
+
let name: string;
|
|
7
|
+
let description: string;
|
|
8
|
+
let props: {
|
|
9
|
+
name: string;
|
|
10
|
+
type: string;
|
|
11
|
+
description: string;
|
|
12
|
+
}[];
|
|
13
|
+
}
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Fixture: a component doc using the stamped default export convention
|
|
5
|
+
* (what `integration add component` generates). loadDocs must read this
|
|
6
|
+
* shape identically to the legacy named `export const docs` form.
|
|
7
|
+
*/
|
|
8
|
+
export default {
|
|
9
|
+
type: 'component',
|
|
10
|
+
name: 'DefaultExportCard',
|
|
11
|
+
description: 'A card written with default export.',
|
|
12
|
+
props: [{name: 'title', type: 'string', description: 'Card title.'}],
|
|
13
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
export namespace docs {
|
|
5
|
+
let type: string;
|
|
6
|
+
let name: string;
|
|
7
|
+
let description: string;
|
|
8
|
+
let props: {
|
|
9
|
+
name: string;
|
|
10
|
+
type: string;
|
|
11
|
+
description: string;
|
|
12
|
+
}[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Fixture: a component doc using the legacy named export convention.
|
|
5
|
+
*/
|
|
6
|
+
export const docs = {
|
|
7
|
+
type: 'component',
|
|
8
|
+
name: 'NamedExportCard',
|
|
9
|
+
description: 'A card written with named export.',
|
|
10
|
+
props: [{name: 'title', type: 'string', description: 'Card title.'}],
|
|
11
|
+
};
|
|
@@ -47,8 +47,9 @@ export function findComponentSource(coreDir: string, name: string): string | nul
|
|
|
47
47
|
*/
|
|
48
48
|
export function resolveImportPath(coreDir: string, componentName: string): string;
|
|
49
49
|
/**
|
|
50
|
-
* Resolve the specifier an integration component is imported from
|
|
51
|
-
* owning package's
|
|
50
|
+
* Resolve the specifier an integration component is imported from. An authored
|
|
51
|
+
* doc import is canonical; otherwise resolve against the owning package's
|
|
52
|
+
* `exports` map.
|
|
52
53
|
*
|
|
53
54
|
* A component lives in a directory that need not share its name — several
|
|
54
55
|
* components can be exported from one entry point — so the specifier has to
|
|
@@ -74,6 +75,7 @@ export function resolveImportPath(coreDir: string, componentName: string): strin
|
|
|
74
75
|
*
|
|
75
76
|
* @param {{exportsMap?: Record<string, unknown>|null, packageDir?: string, docPath?: string|null, packageName: string}} owner
|
|
76
77
|
* @param {string} componentName
|
|
78
|
+
* @param {string|null} [authoredImport]
|
|
77
79
|
* @returns {string}
|
|
78
80
|
*/
|
|
79
81
|
export function resolveIntegrationImportPath(owner: {
|
|
@@ -81,7 +83,7 @@ export function resolveIntegrationImportPath(owner: {
|
|
|
81
83
|
packageDir?: string;
|
|
82
84
|
docPath?: string | null;
|
|
83
85
|
packageName: string;
|
|
84
|
-
}, componentName: string): string;
|
|
86
|
+
}, componentName: string, authoredImport?: string | null): string;
|
|
85
87
|
/**
|
|
86
88
|
* Discover components from an external package's docs directory,
|
|
87
89
|
* reading `group:` fields from each .doc.mjs for subcategories.
|
|
@@ -375,7 +375,9 @@ export function resolveImportPath(coreDir, componentName) {
|
|
|
375
375
|
|
|
376
376
|
// Priority 1: exact subpath export matching the component name (e.g. ./Heading)
|
|
377
377
|
// This allows convenience re-export directories to win over the source directory.
|
|
378
|
-
const exactMatch = exportKeys.find(
|
|
378
|
+
const exactMatch = exportKeys.find(
|
|
379
|
+
k => k.toLowerCase() === `./${componentName}`.toLowerCase(),
|
|
380
|
+
);
|
|
379
381
|
if (exactMatch) {
|
|
380
382
|
return `@astryxdesign/core/${exactMatch.slice(2)}`;
|
|
381
383
|
}
|
|
@@ -387,7 +389,9 @@ export function resolveImportPath(coreDir, componentName) {
|
|
|
387
389
|
const relToSrc = path.relative(srcDir, sourcePath);
|
|
388
390
|
const topDir = relToSrc.split(path.sep)[0];
|
|
389
391
|
|
|
390
|
-
const topMatch = exportKeys.find(
|
|
392
|
+
const topMatch = exportKeys.find(
|
|
393
|
+
k => k.toLowerCase() === `./${topDir}`.toLowerCase(),
|
|
394
|
+
);
|
|
391
395
|
if (topMatch) {
|
|
392
396
|
return `@astryxdesign/core/${topMatch.slice(2)}`;
|
|
393
397
|
}
|
|
@@ -434,8 +438,9 @@ function exportsPublish(exportsMap, subpath) {
|
|
|
434
438
|
}
|
|
435
439
|
|
|
436
440
|
/**
|
|
437
|
-
* Resolve the specifier an integration component is imported from
|
|
438
|
-
* owning package's
|
|
441
|
+
* Resolve the specifier an integration component is imported from. An authored
|
|
442
|
+
* doc import is canonical; otherwise resolve against the owning package's
|
|
443
|
+
* `exports` map.
|
|
439
444
|
*
|
|
440
445
|
* A component lives in a directory that need not share its name — several
|
|
441
446
|
* components can be exported from one entry point — so the specifier has to
|
|
@@ -461,13 +466,24 @@ function exportsPublish(exportsMap, subpath) {
|
|
|
461
466
|
*
|
|
462
467
|
* @param {{exportsMap?: Record<string, unknown>|null, packageDir?: string, docPath?: string|null, packageName: string}} owner
|
|
463
468
|
* @param {string} componentName
|
|
469
|
+
* @param {string|null} [authoredImport]
|
|
464
470
|
* @returns {string}
|
|
465
471
|
*/
|
|
466
|
-
export function resolveIntegrationImportPath(
|
|
472
|
+
export function resolveIntegrationImportPath(
|
|
473
|
+
owner,
|
|
474
|
+
componentName,
|
|
475
|
+
authoredImport,
|
|
476
|
+
) {
|
|
477
|
+
if (authoredImport) return authoredImport;
|
|
467
478
|
const {exportsMap, packageDir, docPath, packageName} = owner;
|
|
468
|
-
const map =
|
|
469
|
-
|
|
470
|
-
|
|
479
|
+
const map =
|
|
480
|
+
exportsMap === undefined ? readPackageExports(packageDir) : exportsMap;
|
|
481
|
+
const directory = docPath
|
|
482
|
+
? path.basename(path.dirname(docPath))
|
|
483
|
+
: componentName;
|
|
484
|
+
return exportsPublish(map, `./${directory}`)
|
|
485
|
+
? `${packageName}/${directory}`
|
|
486
|
+
: packageName;
|
|
471
487
|
}
|
|
472
488
|
|
|
473
489
|
/**
|
|
@@ -783,4 +799,4 @@ export function discoverOwnedComponents(coreDir, loadedIntegrations = []) {
|
|
|
783
799
|
/**
|
|
784
800
|
* Minimal cleanup for full docs (default mode).
|
|
785
801
|
* Strips SYNC comments, rewrites title, collapses blank lines.
|
|
786
|
-
*/
|
|
802
|
+
*/
|
|
@@ -140,7 +140,10 @@ export function mergeTranslation(docs, translation) {
|
|
|
140
140
|
*/
|
|
141
141
|
export async function loadDocs(readmePath, {zh = false, dense = false, lang} = {}) {
|
|
142
142
|
const mod = await import(pathToFileURL(readmePath).href);
|
|
143
|
-
|
|
143
|
+
// Support both the new stamped default export (`export default {type: 'component', …}`)
|
|
144
|
+
// and the legacy named export (`export const docs = {…}`). Default wins when both
|
|
145
|
+
// are present, matching loadComponentDoc's precedence.
|
|
146
|
+
const docs = mod?.default ?? mod.docs;
|
|
144
147
|
|
|
145
148
|
// Resolve which translation to use (--lang takes priority over legacy flags)
|
|
146
149
|
const locale = lang || (dense ? 'dense' : zh ? 'zh' : null);
|
|
@@ -107,6 +107,54 @@ describe('mergeTranslation — component prop descriptions (regression)', () =>
|
|
|
107
107
|
});
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
+
describe('loadDocs — default vs named export resolution', () => {
|
|
111
|
+
const fixtureDir = path.join(import.meta.dirname, '__fixtures__');
|
|
112
|
+
|
|
113
|
+
it('reads a default-export .doc.mjs (the shape integration add component writes)', async () => {
|
|
114
|
+
const docs = await loadDocs(path.join(fixtureDir, 'component-default-export.doc.mjs'));
|
|
115
|
+
expect(docs).toBeDefined();
|
|
116
|
+
expect(docs.name).toBe('DefaultExportCard');
|
|
117
|
+
expect(docs.description).toBe('A card written with default export.');
|
|
118
|
+
expect(docs.props).toHaveLength(1);
|
|
119
|
+
expect(docs.props[0].name).toBe('title');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('still reads a named-export .doc.mjs (legacy shape)', async () => {
|
|
123
|
+
const docs = await loadDocs(path.join(fixtureDir, 'component-named-export.doc.mjs'));
|
|
124
|
+
expect(docs).toBeDefined();
|
|
125
|
+
expect(docs.name).toBe('NamedExportCard');
|
|
126
|
+
expect(docs.props).toHaveLength(1);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('default export agrees with loadComponentDoc', async () => {
|
|
130
|
+
const docPath = path.join(fixtureDir, 'component-default-export.doc.mjs');
|
|
131
|
+
const fromLoadDocs = await loadDocs(docPath);
|
|
132
|
+
const fromLoadComponentDoc = await loadComponentDoc(docPath);
|
|
133
|
+
expect(fromLoadDocs).toEqual(fromLoadComponentDoc);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('named export agrees with loadComponentDoc', async () => {
|
|
137
|
+
const docPath = path.join(fixtureDir, 'component-named-export.doc.mjs');
|
|
138
|
+
const fromLoadDocs = await loadDocs(docPath);
|
|
139
|
+
const fromLoadComponentDoc = await loadComponentDoc(docPath);
|
|
140
|
+
expect(fromLoadDocs).toEqual(fromLoadComponentDoc);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('default export wins when both default and named exports are present', async () => {
|
|
144
|
+
const docPath = path.join(fixtureDir, 'component-both-exports.doc.mjs');
|
|
145
|
+
const fromLoadDocs = await loadDocs(docPath);
|
|
146
|
+
const fromLoadComponentDoc = await loadComponentDoc(docPath);
|
|
147
|
+
|
|
148
|
+
// Default export must win at both loaders
|
|
149
|
+
expect(fromLoadDocs.name).toBe('DefaultWinsCard');
|
|
150
|
+
expect(fromLoadDocs.description).toBe('From the default export.');
|
|
151
|
+
expect(fromLoadDocs.props).toHaveLength(1);
|
|
152
|
+
expect(fromLoadComponentDoc.name).toBe('DefaultWinsCard');
|
|
153
|
+
// And the two must agree
|
|
154
|
+
expect(fromLoadDocs).toEqual(fromLoadComponentDoc);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
110
158
|
describe('loadComponentDoc — full localized doc overlays', () => {
|
|
111
159
|
it('inherits canonical anatomy when docsZh omits it and matches loadDocs', async () => {
|
|
112
160
|
const docPath = path.join(
|
|
@@ -258,6 +258,35 @@ describe('collectThemingTargets', () => {
|
|
|
258
258
|
},
|
|
259
259
|
);
|
|
260
260
|
|
|
261
|
+
it('keeps DialogHeader theming metadata available in its direct doc', async () => {
|
|
262
|
+
const doc = await loadComponentDoc(
|
|
263
|
+
path.join(coreSrc, 'Dialog', 'DialogHeader.doc.mjs'),
|
|
264
|
+
);
|
|
265
|
+
expect(doc.subComponentOf).toBe('Dialog');
|
|
266
|
+
expect(doc.theming.targets).toEqual([
|
|
267
|
+
{className: 'astryx-dialog-header'},
|
|
268
|
+
{className: 'astryx-dialog-header-title-block'},
|
|
269
|
+
{className: 'astryx-dialog-header-close-icon'},
|
|
270
|
+
]);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it.each([
|
|
274
|
+
'dialog-header',
|
|
275
|
+
'dialog-header-title-block',
|
|
276
|
+
'dialog-header-close-icon',
|
|
277
|
+
])('enumerates %s once under its canonical Dialog owner', async key => {
|
|
278
|
+
const matches = (await enumerated).filter(target => target.key === key);
|
|
279
|
+
expect(matches).toEqual([
|
|
280
|
+
{
|
|
281
|
+
key,
|
|
282
|
+
className: `astryx-${key}`,
|
|
283
|
+
component: 'Dialog',
|
|
284
|
+
props: [],
|
|
285
|
+
states: [],
|
|
286
|
+
},
|
|
287
|
+
]);
|
|
288
|
+
});
|
|
289
|
+
|
|
261
290
|
it.each(['table-header', 'table-body', 'table-footer'])(
|
|
262
291
|
'enumerates %s once under its canonical Table owner',
|
|
263
292
|
async key => {
|
|
@@ -6,6 +6,25 @@
|
|
|
6
6
|
* Also checks node_modules/@astryxdesign/core for installed usage.
|
|
7
7
|
*/
|
|
8
8
|
export function findCoreDir(startDir?: string): string | null;
|
|
9
|
+
/**
|
|
10
|
+
* Locate a package the project at `startDir` actually installed.
|
|
11
|
+
*
|
|
12
|
+
* Deliberately not `require.resolve`: Node folds NODE_PATH and the global
|
|
13
|
+
* folders into resolution even when `paths` is given, so a package merely
|
|
14
|
+
* reachable from the ambient environment reads as installed here. pnpm's
|
|
15
|
+
* isolated layout puts every package in `node_modules/.pnpm/node_modules`,
|
|
16
|
+
* and Vitest puts that directory on NODE_PATH, so the gap is not theoretical.
|
|
17
|
+
* Reading package.json off disk also sidesteps packages that don't export it,
|
|
18
|
+
* so the version is always available to range-check.
|
|
19
|
+
*
|
|
20
|
+
* Walks the node_modules chain first, then asks PnP, which covers the Yarn
|
|
21
|
+
* default layout where that chain does not exist.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} startDir
|
|
24
|
+
* @param {string} name
|
|
25
|
+
* @returns {string|null} the package directory, or null when not installed
|
|
26
|
+
*/
|
|
27
|
+
export function findInstalledPackage(startDir: string, name: string): string | null;
|
|
9
28
|
/**
|
|
10
29
|
* Find the monorepo root by looking for the root package.json
|
|
11
30
|
* that has workspaces defined.
|
package/foundation/fs/paths.mjs
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import * as fs from 'node:fs';
|
|
10
|
+
import {createRequire} from 'node:module';
|
|
10
11
|
import * as path from 'node:path';
|
|
11
12
|
import {fileURLToPath} from 'node:url';
|
|
12
13
|
|
|
@@ -41,6 +42,59 @@ export function findCoreDir(startDir = process.cwd()) {
|
|
|
41
42
|
return null;
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Where Yarn's Plug'n'Play runtime says a package lives.
|
|
47
|
+
*
|
|
48
|
+
* A PnP project has no node_modules for the walk below to find. PnP answers
|
|
49
|
+
* from the project's own dependency graph and ignores NODE_PATH, so asking it
|
|
50
|
+
* keeps the lookup project-local. Outside a PnP process there is nothing to ask.
|
|
51
|
+
*
|
|
52
|
+
* @param {string} startDir
|
|
53
|
+
* @param {string} name
|
|
54
|
+
* @returns {string|null}
|
|
55
|
+
*/
|
|
56
|
+
function findPnpPackage(startDir, name) {
|
|
57
|
+
if (!process.versions.pnp) return null;
|
|
58
|
+
try {
|
|
59
|
+
const api = createRequire(path.join(startDir, 'noop.js'))('pnpapi');
|
|
60
|
+
const dir = api.resolveToUnqualified(name, path.join(startDir, '/'));
|
|
61
|
+
return dir && fs.existsSync(path.join(dir, 'package.json')) ? dir : null;
|
|
62
|
+
} catch {
|
|
63
|
+
// The project does not declare it, or this is not a PnP process after all.
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Locate a package the project at `startDir` actually installed.
|
|
70
|
+
*
|
|
71
|
+
* Deliberately not `require.resolve`: Node folds NODE_PATH and the global
|
|
72
|
+
* folders into resolution even when `paths` is given, so a package merely
|
|
73
|
+
* reachable from the ambient environment reads as installed here. pnpm's
|
|
74
|
+
* isolated layout puts every package in `node_modules/.pnpm/node_modules`,
|
|
75
|
+
* and Vitest puts that directory on NODE_PATH, so the gap is not theoretical.
|
|
76
|
+
* Reading package.json off disk also sidesteps packages that don't export it,
|
|
77
|
+
* so the version is always available to range-check.
|
|
78
|
+
*
|
|
79
|
+
* Walks the node_modules chain first, then asks PnP, which covers the Yarn
|
|
80
|
+
* default layout where that chain does not exist.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} startDir
|
|
83
|
+
* @param {string} name
|
|
84
|
+
* @returns {string|null} the package directory, or null when not installed
|
|
85
|
+
*/
|
|
86
|
+
export function findInstalledPackage(startDir, name) {
|
|
87
|
+
let dir = startDir;
|
|
88
|
+
for (let i = 0; i < 6; i++) {
|
|
89
|
+
const candidate = path.join(dir, 'node_modules', ...name.split('/'));
|
|
90
|
+
if (fs.existsSync(path.join(candidate, 'package.json'))) return candidate;
|
|
91
|
+
const parent = path.dirname(dir);
|
|
92
|
+
if (parent === dir) break;
|
|
93
|
+
dir = parent;
|
|
94
|
+
}
|
|
95
|
+
return findPnpPackage(startDir, name);
|
|
96
|
+
}
|
|
97
|
+
|
|
44
98
|
/**
|
|
45
99
|
* Find the monorepo root by looking for the root package.json
|
|
46
100
|
* that has workspaces defined.
|