@astryxdesign/cli 0.6.5 → 0.6.6
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 +87 -0
- package/README.md +16 -15
- package/api/build/_adapter.d.mts +50 -2
- package/api/build/_adapter.mjs +98 -10
- package/api/build/build.doc.mjs +2 -2
- package/api/build/build.test.mjs +111 -2
- package/api/build/kit/kit.mjs +98 -22
- package/api/build/kit/rank.d.mts +32 -8
- package/api/build/kit/rank.mjs +291 -97
- package/api/build/kit/rank.test.mjs +231 -48
- package/api/build/kit/weights.d.mts +82 -0
- package/api/build/kit/weights.json +1 -0
- package/api/build/kit/weights.mjs +305 -0
- package/api/build/kit/weights.test.mjs +190 -0
- package/api/docs/docs.d.mts +6 -0
- package/api/docs/docs.depth.test.mjs +132 -0
- package/api/docs/docs.doc.mjs +31 -2
- package/api/docs/docs.mjs +44 -1
- package/api/docs/docs.test.mjs +279 -0
- package/api/docs/docs.type.d.mts +38 -1
- package/api/docs/docs.type.mjs +18 -1
- package/api/docs/integration-tree.test.mjs +572 -0
- package/api/docs/integrationDocs.test.mjs +336 -0
- package/api/docs/node/node.d.mts +28 -3
- package/api/docs/node/node.mjs +146 -23
- package/api/error.d.mts +22 -0
- package/api/error.mjs +42 -0
- package/api/gap-report/gap-report.d.mts +3 -1
- package/api/gap-report/gap-report.mjs +12 -2
- package/api/gap-report/gap-report.test.mjs +106 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/integration/add-contribution.d.mts +2 -1
- package/api/integration/add-contribution.mjs +7 -3
- package/api/integration/add-contribution.test.mjs +3 -3
- package/api/integration/add-theme.mjs +338 -26
- package/api/integration/add-theme.test.mjs +314 -1
- package/api/integration/authoring-checks.mjs +10 -7
- package/api/integration/authoring-checks.type.d.mts +8 -0
- package/api/integration/authoring-checks.type.mjs +7 -3
- package/api/integration/integration-authoring.type.d.mts +4 -1
- package/api/integration/integration-authoring.type.mjs +6 -1
- package/api/integration/integrationAdd.doc.mjs +6 -0
- package/api/integration/integrationAddTheme.doc.mjs +10 -0
- package/api/integration/integrationComponentConflicts.doc.mjs +1 -1
- package/api/integration/integrationDocConflicts.doc.mjs +1 -1
- package/api/integration/integrationTemplateConflicts.doc.mjs +1 -1
- package/api/integration/pack-check.mjs +12 -3
- package/api/integration/pack-check.test.mjs +52 -3
- package/api/integration/validate-integration.d.mts +4 -2
- package/api/integration/validate-integration.mjs +7 -2
- package/api/integration/validate-integration.test.mjs +55 -0
- package/api/integration/validate-integration.type.d.mts +5 -0
- package/api/integration/validate-integration.type.mjs +5 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/layout/expand/expand.mjs +12 -7
- package/api/layout/expand/expand.receipt.test.mjs +74 -0
- package/api/layout/layout.type.d.mts +1 -0
- package/api/layout/layout.type.mjs +1 -0
- package/api/layout/layoutExpand.doc.mjs +1 -1
- package/api/search/search.d.mts +36 -5
- package/api/search/search.doc.mjs +4 -4
- package/api/search/search.mjs +194 -54
- package/api/search/search.test.mjs +825 -0
- package/api/search/search.type.d.mts +5 -5
- package/api/search/search.type.mjs +5 -5
- package/api/swizzle/copy/copy.mjs +66 -3
- package/api/swizzle/swizzle.doc.mjs +4 -0
- package/api/template/copy/copy.mjs +14 -8
- package/api/template/copy/copy.receipt.test.mjs +77 -0
- package/api/template/show/show.mjs +15 -4
- package/api/template/show/show.test.mjs +76 -0
- package/api/template/template-integration.test.mjs +14 -0
- package/api/template/template.d.mts +1 -1
- package/api/template/template.doc.mjs +6 -2
- package/api/template/template.mjs +1 -0
- package/api/template/template.type.d.mts +2 -0
- package/api/template/template.type.mjs +2 -0
- package/api/theme/build/build.d.mts +24 -0
- package/api/theme/build/build.icon-lineage.test.mjs +117 -0
- package/api/theme/build/build.icon-preservation.test.mjs +639 -0
- package/api/theme/build/build.mjs +381 -77
- package/api/theme/build/build.project-core.test.mjs +165 -0
- package/api/theme/build/build.test.mjs +190 -1
- package/api/theme/build/icon-imports.d.mts +47 -0
- package/api/theme/build/icon-imports.mjs +691 -0
- package/api/theme/themeBuild.doc.d.mts +4 -1
- package/api/theme/themeBuild.doc.mjs +14 -3
- package/api/upgrade/run/run.mjs +20 -3
- package/api/upgrade/run/run.test.mjs +45 -1
- package/api/upgrade/upgrade.doc.mjs +1 -1
- package/api/upgrade/upgrade.type.d.mts +1 -0
- package/api/upgrade/upgrade.type.mjs +1 -0
- package/assets/docs/icons.doc.mjs +1 -0
- package/assets/docs/theme.doc.mjs +3 -2
- package/assets/docs/tokens.doc.mjs +3 -3
- package/assets/docs/tree/add-a-theme.doc.mjs +4 -0
- package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
- package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
- package/assets/docs/tree/template-doc-overview.doc.mjs +13 -1
- package/assets/docs/tree/troubleshooting.doc.mjs +9 -5
- package/assets/docs/tree/versioning.doc.mjs +7 -6
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjs +15 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsx +38 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjs +20 -0
- package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsx +48 -0
- package/assets/templates/pages/ai-chat/template.doc.mjs +16 -1
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +9 -1
- package/assets/templates/pages/blank/template.doc.mjs +3 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -1
- package/assets/templates/pages/centered-hero/template.doc.mjs +3 -1
- package/assets/templates/pages/checkout-wizard/template.doc.mjs +1 -0
- package/assets/templates/pages/classic-gallery/template.doc.mjs +3 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +16 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +15 -1
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +23 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +10 -1
- package/assets/templates/pages/dashboard-comparison/template.doc.mjs +9 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +10 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +17 -1
- package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -1
- package/assets/templates/pages/detail-page/template.doc.mjs +8 -0
- package/assets/templates/pages/documentation/template.doc.mjs +10 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +10 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +10 -1
- package/assets/templates/pages/editor/template.doc.mjs +9 -1
- package/assets/templates/pages/file-explorer/template.doc.mjs +3 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +17 -1
- package/assets/templates/pages/form-wizard/template.doc.mjs +14 -1
- package/assets/templates/pages/form-wizard-dialog/template.doc.mjs +1 -0
- package/assets/templates/pages/gallery-hero/template.doc.mjs +10 -1
- package/assets/templates/pages/ide/template.doc.mjs +9 -1
- package/assets/templates/pages/incident-console/template.doc.mjs +10 -1
- package/assets/templates/pages/kanban-board/template.doc.mjs +11 -1
- package/assets/templates/pages/library/template.doc.mjs +15 -1
- package/assets/templates/pages/login/template.doc.mjs +10 -1
- package/assets/templates/pages/login-card/template.doc.mjs +11 -1
- package/assets/templates/pages/login-split/template.doc.mjs +10 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +10 -1
- package/assets/templates/pages/messaging-shell/template.doc.mjs +11 -1
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +10 -1
- package/assets/templates/pages/payment-form/template.doc.mjs +3 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +9 -1
- package/assets/templates/pages/product-gallery/template.doc.mjs +10 -1
- package/assets/templates/pages/settings/template.doc.mjs +3 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +9 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +9 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +10 -1
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +14 -1
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +11 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +3 -1
- package/assets/templates/pages/table/template.doc.mjs +11 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +21 -1
- package/assets/templates/pages/table-grouped/template.doc.mjs +15 -1
- package/assets/templates/pages/table-inbox/template.doc.mjs +18 -6
- package/assets/templates/pages/table-page/template.doc.mjs +20 -1
- package/assets/templates/pages/table-tree/template.doc.mjs +14 -1
- package/assets/templates/pages/theme-showcase/template.doc.mjs +10 -1
- package/assets/templates/pages/work-item-detail/template.doc.mjs +10 -0
- package/assets/templates/themes/butter/icons.tsx +2 -0
- package/assets/templates/themes/chocolate/icons.tsx +2 -0
- package/assets/templates/themes/gothic/icons.tsx +2 -0
- package/assets/templates/themes/matcha/icons.tsx +2 -0
- package/assets/templates/themes/neutral/icons.tsx +2 -0
- package/assets/templates/themes/stone/icons.tsx +2 -0
- package/assets/templates/themes/y2k/icons.tsx +2 -0
- package/authoring/doctypes/template/parse.d.mts +2 -0
- package/authoring/doctypes/template/parse.mjs +1 -0
- package/authoring/doctypes/template/parse.test.mjs +21 -0
- package/authoring/doctypes/template/template.doc.mjs +6 -0
- package/authoring/doctypes/template/type.ts +10 -0
- package/clients/cli/commands/build-theme.mjs +8 -2
- package/clients/cli/commands/discover.mjs +29 -1
- package/clients/cli/commands/discover.no-source.test.mjs +75 -0
- package/clients/cli/commands/docs.depth.test.mjs +219 -0
- package/clients/cli/commands/docs.doc.mjs +15 -2
- package/clients/cli/commands/docs.mjs +222 -5
- package/clients/cli/commands/docs.test.mjs +383 -0
- package/clients/cli/commands/doctor.mjs +4 -4
- package/clients/cli/commands/gap-report.mjs +12 -0
- package/clients/cli/commands/gap-report.test.mjs +63 -0
- package/clients/cli/commands/integration-add.doc.mjs +10 -0
- package/clients/cli/commands/integration-authoring.test.mjs +12 -2
- package/clients/cli/commands/integration.mjs +3 -1
- package/clients/cli/commands/layout-expand.doc.mjs +3 -1
- package/clients/cli/commands/layout.expand-receipt.test.mjs +94 -0
- package/clients/cli/commands/layout.mjs +16 -0
- package/clients/cli/commands/search.doc.mjs +5 -4
- package/clients/cli/commands/search.mjs +30 -6
- package/clients/cli/commands/search.test.mjs +60 -16
- package/clients/cli/commands/template.copy-receipt.test.mjs +60 -0
- package/clients/cli/commands/template.mjs +19 -5
- package/clients/cli/commands/template.show-media.test.mjs +62 -0
- package/clients/cli/commands/theme-list.behavior.test.mjs +41 -0
- package/clients/cli/commands/upgrade.ascii-output.test.mjs +14 -0
- package/clients/cli/commands/write-failure.test.mjs +175 -0
- package/clients/cli/lib/manifest.mjs +44 -165
- package/clients/cli/lib/manifest.test.mjs +98 -7
- package/foundation/agent-docs/agent-docs.mjs +2 -1
- package/foundation/agent-docs/agent-docs.test.mjs +1168 -0
- package/foundation/discovery/template-adapter.d.mts +14 -0
- package/foundation/discovery/template-adapter.fixture-refs.test.mjs +37 -1
- package/foundation/discovery/template-adapter.mjs +21 -1
- package/foundation/discovery/theme-discovery.d.mts +6 -0
- package/foundation/discovery/theme-discovery.mjs +9 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +3 -3
- package/foundation/doc-compiler/inputs.test.mjs +0 -1
- package/foundation/doc-compiler/tree.test.mjs +649 -0
- package/foundation/integrations/cli-requirement.d.mts +57 -13
- package/foundation/integrations/cli-requirement.mjs +84 -22
- package/foundation/integrations/cli-requirement.test.mjs +135 -8
- package/foundation/response/response-types.doc.d.mts +5 -5
- package/foundation/response/response-types.doc.mjs +13 -13
- package/package.json +1 -1
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolve importable icon registries for the selected theme export.
|
|
5
|
+
*
|
|
6
|
+
* @input Loaded theme export identity, plus the caller's source reader and the
|
|
7
|
+
* theme loader's resolver (this module performs no environment access).
|
|
8
|
+
* @output Import bindings and an expression preserving inherited icon registries.
|
|
9
|
+
* @position Private theme-build packaging helper; never evaluates authored source.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import * as path from 'node:path';
|
|
13
|
+
import {fileURLToPath} from 'node:url';
|
|
14
|
+
import {AstryxError} from '../../error.mjs';
|
|
15
|
+
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {object} IconImports
|
|
19
|
+
* @property {{importPath: string, importedName: string, localName: string}[]} imports
|
|
20
|
+
* @property {string} expression
|
|
21
|
+
* @property {string} exportName
|
|
22
|
+
* @property {string} [iconsSpecifierImportPath]
|
|
23
|
+
* @property {string} [iconsSpecifierLocalName]
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** @typedef {{kind: 'reference', module: any, binding: any, members: string[]}} RegistryReference */
|
|
27
|
+
/** @typedef {{kind: 'registry', ref: RegistryReference, preferredName: string, override?: boolean} | {kind: 'merge', base: RegistryPlan, own: RegistryPlan}} RegistryPlan */
|
|
28
|
+
|
|
29
|
+
/** @param {any} node */
|
|
30
|
+
function unwrap(node) {
|
|
31
|
+
while (
|
|
32
|
+
node &&
|
|
33
|
+
[
|
|
34
|
+
'TSAsExpression',
|
|
35
|
+
'TSSatisfiesExpression',
|
|
36
|
+
'TSNonNullExpression',
|
|
37
|
+
'TSTypeAssertion',
|
|
38
|
+
'TypeCastExpression',
|
|
39
|
+
'ParenthesizedExpression',
|
|
40
|
+
].includes(node.type)
|
|
41
|
+
) {
|
|
42
|
+
node = node.expression;
|
|
43
|
+
}
|
|
44
|
+
return node;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @param {any} node */
|
|
48
|
+
function propertyName(node) {
|
|
49
|
+
if (!node) return null;
|
|
50
|
+
if (node.type === 'Identifier') return node.name;
|
|
51
|
+
if (typeof node.value === 'string') return node.value;
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** @param {any} node */
|
|
56
|
+
function rootIdentifier(node) {
|
|
57
|
+
node = unwrap(node);
|
|
58
|
+
while (
|
|
59
|
+
node?.type === 'MemberExpression' ||
|
|
60
|
+
node?.type === 'OptionalMemberExpression'
|
|
61
|
+
) {
|
|
62
|
+
node = unwrap(node.object);
|
|
63
|
+
}
|
|
64
|
+
return node?.type === 'Identifier' ? node.name : null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @param {any} pattern @returns {string[]} */
|
|
68
|
+
function bindingNames(pattern) {
|
|
69
|
+
if (!pattern) return [];
|
|
70
|
+
if (pattern.type === 'Identifier') return [pattern.name];
|
|
71
|
+
if (pattern.type === 'AssignmentPattern') return bindingNames(pattern.left);
|
|
72
|
+
if (pattern.type === 'RestElement') return bindingNames(pattern.argument);
|
|
73
|
+
if (pattern.type === 'ObjectPattern')
|
|
74
|
+
return pattern.properties.flatMap((/** @type {any} */ item) =>
|
|
75
|
+
bindingNames(item.type === 'RestElement' ? item.argument : item.value),
|
|
76
|
+
);
|
|
77
|
+
if (pattern.type === 'ArrayPattern')
|
|
78
|
+
return pattern.elements.flatMap(bindingNames);
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** @param {string} [name] @param {string} [reason] @returns {never} */
|
|
83
|
+
function invalidRegistry(name, reason = '') {
|
|
84
|
+
const registry = name ? `\`icons: ${name}\`` : 'an icon registry';
|
|
85
|
+
throw new AstryxError(
|
|
86
|
+
`Theme sets ${registry} but no import for the registry was found. ` +
|
|
87
|
+
'The generated module cannot preserve inline registries because they ' +
|
|
88
|
+
'may contain React elements, which cannot be serialized. ' +
|
|
89
|
+
(reason ? `${reason} ` : '') +
|
|
90
|
+
'Move the registry to its own module and import it into the theme file.',
|
|
91
|
+
undefined,
|
|
92
|
+
ERROR_CODES.ERR_THEME_INVALID,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Parse only real module declarations and follow the export chosen by the loader.
|
|
98
|
+
* Local base themes are traced to their registry imports. Package bases remain
|
|
99
|
+
* public theme imports, so their implementation and private files stay private.
|
|
100
|
+
*
|
|
101
|
+
* @param {string} filePath
|
|
102
|
+
* @param {string | undefined} exportName
|
|
103
|
+
* @param {{hasIcons: boolean, readSource: (filename: string) => string, resolveModule: (specifier: string, fromFile: string) => string | Promise<string>, reservedNames?: string[], rawInput?: boolean}} options
|
|
104
|
+
* @returns {Promise<IconImports | null>}
|
|
105
|
+
*/
|
|
106
|
+
export async function resolveIconImports(
|
|
107
|
+
filePath,
|
|
108
|
+
exportName,
|
|
109
|
+
{hasIcons, readSource, resolveModule, reservedNames = [], rawInput = false},
|
|
110
|
+
) {
|
|
111
|
+
if (exportName === undefined) {
|
|
112
|
+
if (!hasIcons) return null;
|
|
113
|
+
invalidRegistry(
|
|
114
|
+
undefined,
|
|
115
|
+
'The selected theme export could not be identified.',
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
120
|
+
const entryDirectory = path.dirname(filePath);
|
|
121
|
+
/** @type {Map<string, any>} */
|
|
122
|
+
const modules = new Map();
|
|
123
|
+
const active = new Set();
|
|
124
|
+
let inspectedRegistry = false;
|
|
125
|
+
|
|
126
|
+
/** @param {string} key @param {() => Promise<any>} visit */
|
|
127
|
+
async function guarded(key, visit) {
|
|
128
|
+
if (active.has(key))
|
|
129
|
+
invalidRegistry(undefined, 'The icon reference contains a cycle.');
|
|
130
|
+
active.add(key);
|
|
131
|
+
try {
|
|
132
|
+
return await visit();
|
|
133
|
+
} finally {
|
|
134
|
+
active.delete(key);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** @param {any} module @param {any} node @param {Set<string>} [seen] */
|
|
139
|
+
function isDefineTheme(module, node, seen = new Set()) {
|
|
140
|
+
node = unwrap(node);
|
|
141
|
+
if (node?.type === 'Identifier') {
|
|
142
|
+
if (seen.has(node.name)) return false;
|
|
143
|
+
seen.add(node.name);
|
|
144
|
+
const binding = module.bindings.get(node.name);
|
|
145
|
+
if (binding?.kind === 'const')
|
|
146
|
+
return isDefineTheme(module, binding.node, seen);
|
|
147
|
+
return (
|
|
148
|
+
binding?.kind === 'import' &&
|
|
149
|
+
['@astryxdesign/core', '@astryxdesign/core/theme'].includes(
|
|
150
|
+
binding.source,
|
|
151
|
+
) &&
|
|
152
|
+
binding.importedName === 'defineTheme'
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
if (
|
|
156
|
+
node?.type === 'MemberExpression' &&
|
|
157
|
+
!node.computed &&
|
|
158
|
+
node.property.name === 'defineTheme'
|
|
159
|
+
) {
|
|
160
|
+
const binding = module.bindings.get(node.object?.name);
|
|
161
|
+
return (
|
|
162
|
+
binding?.kind === 'import' &&
|
|
163
|
+
binding.importedName === '*' &&
|
|
164
|
+
['@astryxdesign/core', '@astryxdesign/core/theme'].includes(
|
|
165
|
+
binding.source,
|
|
166
|
+
)
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** @param {string} filename */
|
|
173
|
+
function readModule(filename) {
|
|
174
|
+
if (modules.has(filename)) return modules.get(filename);
|
|
175
|
+
const parser = /\.[cm]?ts$/u.test(filename) ? 'ts' : 'tsx';
|
|
176
|
+
const j = jscodeshift.withParser(parser);
|
|
177
|
+
let root;
|
|
178
|
+
try {
|
|
179
|
+
root = j(readSource(filename));
|
|
180
|
+
} catch {
|
|
181
|
+
invalidRegistry(
|
|
182
|
+
undefined,
|
|
183
|
+
'The selected theme module could not be parsed.',
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
const first = root.nodes()[0];
|
|
187
|
+
const statements = (first.program ?? first).body;
|
|
188
|
+
/** @type {{filename: string, bindings: Map<string, any>, exports: Map<string, any>, stars: string[], mutated: Set<string>, aliases: Map<string, string>}} */
|
|
189
|
+
const module = {
|
|
190
|
+
filename,
|
|
191
|
+
bindings: new Map(),
|
|
192
|
+
exports: new Map(),
|
|
193
|
+
stars: [],
|
|
194
|
+
mutated: new Set(),
|
|
195
|
+
aliases: new Map(),
|
|
196
|
+
};
|
|
197
|
+
modules.set(filename, module);
|
|
198
|
+
|
|
199
|
+
for (const statement of statements) {
|
|
200
|
+
if (
|
|
201
|
+
statement.type === 'ImportDeclaration' &&
|
|
202
|
+
statement.importKind !== 'type'
|
|
203
|
+
) {
|
|
204
|
+
for (const specifier of statement.specifiers ?? []) {
|
|
205
|
+
if (specifier.importKind === 'type') continue;
|
|
206
|
+
module.bindings.set(specifier.local.name, {
|
|
207
|
+
kind: 'import',
|
|
208
|
+
source: statement.source.value,
|
|
209
|
+
importedName:
|
|
210
|
+
specifier.type === 'ImportDefaultSpecifier'
|
|
211
|
+
? 'default'
|
|
212
|
+
: specifier.type === 'ImportNamespaceSpecifier'
|
|
213
|
+
? '*'
|
|
214
|
+
: propertyName(specifier.imported),
|
|
215
|
+
localName: specifier.local.name,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const declaration =
|
|
220
|
+
statement.type === 'ExportNamedDeclaration'
|
|
221
|
+
? statement.declaration
|
|
222
|
+
: statement;
|
|
223
|
+
if (declaration?.type === 'VariableDeclaration') {
|
|
224
|
+
for (const item of declaration.declarations) {
|
|
225
|
+
const original = rootIdentifier(item.init);
|
|
226
|
+
if (original) {
|
|
227
|
+
for (const name of bindingNames(item.id))
|
|
228
|
+
module.aliases.set(name, original);
|
|
229
|
+
}
|
|
230
|
+
if (item.id.type !== 'Identifier') continue;
|
|
231
|
+
module.bindings.set(item.id.name, {
|
|
232
|
+
kind: declaration.kind === 'const' ? 'const' : 'unsupported',
|
|
233
|
+
node: item.init,
|
|
234
|
+
});
|
|
235
|
+
if (statement.type === 'ExportNamedDeclaration') {
|
|
236
|
+
module.exports.set(item.id.name, {node: item.id});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (statement.type === 'ExportDefaultDeclaration') {
|
|
241
|
+
module.exports.set('default', {node: statement.declaration});
|
|
242
|
+
}
|
|
243
|
+
if (
|
|
244
|
+
statement.type === 'ExportNamedDeclaration' &&
|
|
245
|
+
statement.exportKind !== 'type'
|
|
246
|
+
) {
|
|
247
|
+
for (const specifier of statement.specifiers ?? []) {
|
|
248
|
+
if (specifier.exportKind === 'type') continue;
|
|
249
|
+
const exportedName = propertyName(specifier.exported);
|
|
250
|
+
module.exports.set(
|
|
251
|
+
exportedName,
|
|
252
|
+
statement.source
|
|
253
|
+
? {
|
|
254
|
+
binding: {
|
|
255
|
+
kind: 'import',
|
|
256
|
+
source: statement.source.value,
|
|
257
|
+
importedName:
|
|
258
|
+
specifier.type === 'ExportNamespaceSpecifier'
|
|
259
|
+
? '*'
|
|
260
|
+
: propertyName(specifier.local),
|
|
261
|
+
localName: propertyName(specifier.local) ?? exportedName,
|
|
262
|
+
},
|
|
263
|
+
}
|
|
264
|
+
: {node: specifier.local},
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (
|
|
269
|
+
statement.type === 'ExportAllDeclaration' &&
|
|
270
|
+
statement.exportKind !== 'type'
|
|
271
|
+
) {
|
|
272
|
+
module.stars.push(statement.source.value);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** @param {any} node @param {any} nodePath */
|
|
277
|
+
const markMutation = (node, nodePath) => {
|
|
278
|
+
const name = rootIdentifier(node);
|
|
279
|
+
if (name && nodePath.scope.lookup(name)?.path.node.type === 'Program')
|
|
280
|
+
module.mutated.add(name);
|
|
281
|
+
};
|
|
282
|
+
root
|
|
283
|
+
.find(j.AssignmentExpression)
|
|
284
|
+
.forEach((/** @type {any} */ p) => markMutation(p.node.left, p));
|
|
285
|
+
root
|
|
286
|
+
.find(j.UpdateExpression)
|
|
287
|
+
.forEach((/** @type {any} */ p) => markMutation(p.node.argument, p));
|
|
288
|
+
root
|
|
289
|
+
.find(j.UnaryExpression, {operator: 'delete'})
|
|
290
|
+
.forEach((/** @type {any} */ p) => markMutation(p.node.argument, p));
|
|
291
|
+
root.find(j.CallExpression).forEach((/** @type {any} */ p) => {
|
|
292
|
+
if (isDefineTheme(module, p.node.callee)) return;
|
|
293
|
+
if (p.node.callee.type === 'MemberExpression')
|
|
294
|
+
markMutation(p.node.callee.object, p);
|
|
295
|
+
for (const argument of p.node.arguments) markMutation(argument, p);
|
|
296
|
+
});
|
|
297
|
+
// Mutating an alias also mutates the object that supplied its value.
|
|
298
|
+
for (const name of module.mutated) {
|
|
299
|
+
const original = module.aliases.get(name);
|
|
300
|
+
if (original) module.mutated.add(original);
|
|
301
|
+
}
|
|
302
|
+
return module;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** @param {any} module @param {string} name */
|
|
306
|
+
function checkedBinding(module, name) {
|
|
307
|
+
if (module.mutated.has(name))
|
|
308
|
+
invalidRegistry(
|
|
309
|
+
name,
|
|
310
|
+
'The referenced binding is mutated or passed to unsupported code.',
|
|
311
|
+
);
|
|
312
|
+
const binding = module.bindings.get(name);
|
|
313
|
+
if (!binding || binding.kind === 'unsupported') invalidRegistry(name);
|
|
314
|
+
return binding;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** @param {any} module @param {any} binding @param {string[]} [members] @returns {RegistryReference} */
|
|
318
|
+
function importedReference(module, binding, members = []) {
|
|
319
|
+
return {kind: 'reference', module, binding, members};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** @param {any} module @param {any} node @returns {Promise<RegistryReference | null>} */
|
|
323
|
+
async function reference(module, node) {
|
|
324
|
+
node = unwrap(node);
|
|
325
|
+
if (node?.type === 'Identifier') {
|
|
326
|
+
return guarded(`${module.filename}:reference:${node.name}`, async () => {
|
|
327
|
+
const binding = checkedBinding(module, node.name);
|
|
328
|
+
if (binding.kind === 'import')
|
|
329
|
+
return importedReference(module, binding);
|
|
330
|
+
return reference(module, binding.node);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
if (node?.type === 'MemberExpression' && !node.optional) {
|
|
334
|
+
const name = node.computed
|
|
335
|
+
? typeof node.property.value === 'string'
|
|
336
|
+
? node.property.value
|
|
337
|
+
: null
|
|
338
|
+
: propertyName(node.property);
|
|
339
|
+
if (name === null) invalidRegistry();
|
|
340
|
+
const object = await reference(module, node.object);
|
|
341
|
+
if (!object) return null;
|
|
342
|
+
return {...object, members: [...object.members, name]};
|
|
343
|
+
}
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** @param {RegistryReference} ref */
|
|
348
|
+
async function importedExport(ref) {
|
|
349
|
+
if (!ref.binding.source.startsWith('.')) return null;
|
|
350
|
+
let filename;
|
|
351
|
+
try {
|
|
352
|
+
filename = await resolveModule(ref.binding.source, ref.module.filename);
|
|
353
|
+
if (filename.startsWith('file:')) filename = fileURLToPath(filename);
|
|
354
|
+
} catch {
|
|
355
|
+
invalidRegistry(
|
|
356
|
+
ref.binding.localName,
|
|
357
|
+
'The inherited theme module could not be resolved.',
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
let name = ref.binding.importedName;
|
|
361
|
+
const members = [...ref.members];
|
|
362
|
+
if (name === '*') name = members.shift();
|
|
363
|
+
if (!name || members.length > 0)
|
|
364
|
+
invalidRegistry(
|
|
365
|
+
ref.binding.localName,
|
|
366
|
+
'The inherited theme must name a module export.',
|
|
367
|
+
);
|
|
368
|
+
return {module: readModule(filename), name};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** @param {any} module @param {string} name */
|
|
372
|
+
async function selectedExport(module, name) {
|
|
373
|
+
const selected = module.exports.get(name);
|
|
374
|
+
if (selected) return selected;
|
|
375
|
+
// Follow explicit local barrels without choosing another arbitrary theme.
|
|
376
|
+
for (const source of module.stars) {
|
|
377
|
+
if (name === 'default') continue;
|
|
378
|
+
const binding = {source, importedName: name, localName: name};
|
|
379
|
+
const target = await importedExport(importedReference(module, binding));
|
|
380
|
+
if (
|
|
381
|
+
target &&
|
|
382
|
+
(target.module.exports.has(name) || target.module.stars.length > 0)
|
|
383
|
+
)
|
|
384
|
+
return {binding};
|
|
385
|
+
}
|
|
386
|
+
invalidRegistry(
|
|
387
|
+
undefined,
|
|
388
|
+
`The selected export "${name}" has no statically resolved declaration.`,
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** @param {RegistryReference} ref @returns {RegistryPlan} */
|
|
393
|
+
function packageTheme(ref) {
|
|
394
|
+
return {
|
|
395
|
+
kind: 'registry',
|
|
396
|
+
ref: {...ref, members: [...ref.members, 'icons']},
|
|
397
|
+
preferredName: 'themeIcons',
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** @param {any} module @param {string} name @param {boolean} [rejectOpaque] @returns {Promise<RegistryPlan | null>} */
|
|
402
|
+
async function exportedTheme(module, name, rejectOpaque = false) {
|
|
403
|
+
return guarded(`${module.filename}:theme-export:${name}`, async () => {
|
|
404
|
+
const selected = await selectedExport(module, name);
|
|
405
|
+
return selected.binding
|
|
406
|
+
? themeReference(
|
|
407
|
+
importedReference(module, selected.binding),
|
|
408
|
+
rejectOpaque,
|
|
409
|
+
)
|
|
410
|
+
: theme(module, selected.node, rejectOpaque);
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/** @param {RegistryReference} ref @param {boolean} [rejectOpaque] @returns {Promise<RegistryPlan | null>} */
|
|
415
|
+
async function themeReference(ref, rejectOpaque = false) {
|
|
416
|
+
const target = await importedExport(ref);
|
|
417
|
+
if (target) return exportedTheme(target.module, target.name, rejectOpaque);
|
|
418
|
+
if (rejectOpaque)
|
|
419
|
+
invalidRegistry(
|
|
420
|
+
ref.binding.localName,
|
|
421
|
+
'A raw package configuration cannot supply a resolved theme registry.',
|
|
422
|
+
);
|
|
423
|
+
return packageTheme(ref);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** @param {any} module @param {any} node @param {string} [preferredName] @returns {Promise<RegistryPlan | null>} */
|
|
427
|
+
async function registry(module, node, preferredName) {
|
|
428
|
+
inspectedRegistry = true;
|
|
429
|
+
node = unwrap(node);
|
|
430
|
+
if (
|
|
431
|
+
node?.type === 'NullLiteral' ||
|
|
432
|
+
(node?.type === 'Literal' && node.value === null) ||
|
|
433
|
+
(node?.type === 'UnaryExpression' && node.operator === 'void')
|
|
434
|
+
)
|
|
435
|
+
return null;
|
|
436
|
+
if (node?.type === 'Identifier') {
|
|
437
|
+
if (node.name === 'undefined' && !module.bindings.has(node.name))
|
|
438
|
+
return null;
|
|
439
|
+
return guarded(`${module.filename}:registry:${node.name}`, async () => {
|
|
440
|
+
const binding = checkedBinding(module, node.name);
|
|
441
|
+
if (binding.kind === 'const')
|
|
442
|
+
return registry(module, binding.node, preferredName ?? node.name);
|
|
443
|
+
return {
|
|
444
|
+
kind: 'registry',
|
|
445
|
+
ref: importedReference(module, binding),
|
|
446
|
+
preferredName: preferredName ?? node.name,
|
|
447
|
+
override: true,
|
|
448
|
+
};
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
if (node?.type === 'MemberExpression') {
|
|
452
|
+
const ref = await reference(module, node);
|
|
453
|
+
if (ref)
|
|
454
|
+
return {
|
|
455
|
+
kind: 'registry',
|
|
456
|
+
ref,
|
|
457
|
+
preferredName: preferredName ?? 'themeIcons',
|
|
458
|
+
// A namespace's exported registry can be redirected to an icon module;
|
|
459
|
+
// a named theme's .icons cannot be imported from that sidecar.
|
|
460
|
+
override:
|
|
461
|
+
ref.binding.importedName === '*' && ref.members.length === 1,
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
// Spreads merge in order. An object adding no entries, such as `{}`, is no
|
|
465
|
+
// local registry: a child keeps its inherited icons and a root emits none.
|
|
466
|
+
if (
|
|
467
|
+
node?.type === 'ObjectExpression' &&
|
|
468
|
+
node.properties.every((/** @type {any} */ item) =>
|
|
469
|
+
['SpreadElement', 'SpreadProperty'].includes(item.type),
|
|
470
|
+
)
|
|
471
|
+
) {
|
|
472
|
+
/** @type {RegistryPlan | null} */
|
|
473
|
+
let result = null;
|
|
474
|
+
for (const item of node.properties) {
|
|
475
|
+
const next = await registry(module, item.argument);
|
|
476
|
+
if (next)
|
|
477
|
+
result = result ? {kind: 'merge', base: result, own: next} : next;
|
|
478
|
+
}
|
|
479
|
+
return result;
|
|
480
|
+
}
|
|
481
|
+
invalidRegistry(preferredName ?? rootIdentifier(node) ?? undefined);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/** @param {any} module @param {any} node @returns {Promise<Map<string, any>>} */
|
|
485
|
+
async function fields(module, node) {
|
|
486
|
+
node = unwrap(node);
|
|
487
|
+
if (node?.type === 'Identifier') {
|
|
488
|
+
return guarded(`${module.filename}:fields:${node.name}`, async () => {
|
|
489
|
+
const binding = checkedBinding(module, node.name);
|
|
490
|
+
if (binding.kind === 'const') return fields(module, binding.node);
|
|
491
|
+
return referenceFields(importedReference(module, binding));
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
if (node?.type === 'MemberExpression') {
|
|
495
|
+
const ref = await reference(module, node);
|
|
496
|
+
if (ref) return referenceFields(ref);
|
|
497
|
+
}
|
|
498
|
+
if (node?.type === 'CallExpression' && isDefineTheme(module, node.callee)) {
|
|
499
|
+
return new Map([['icons', {plan: await theme(module, node)}]]);
|
|
500
|
+
}
|
|
501
|
+
if (node?.type !== 'ObjectExpression') invalidRegistry();
|
|
502
|
+
const result = new Map();
|
|
503
|
+
for (const item of node.properties) {
|
|
504
|
+
if (item.type === 'SpreadElement' || item.type === 'SpreadProperty') {
|
|
505
|
+
for (const [key, value] of await fields(module, item.argument))
|
|
506
|
+
result.set(key, value);
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
const key = item.computed
|
|
510
|
+
? typeof item.key?.value === 'string'
|
|
511
|
+
? item.key.value
|
|
512
|
+
: null
|
|
513
|
+
: propertyName(item.key);
|
|
514
|
+
if (key === null)
|
|
515
|
+
invalidRegistry(undefined, 'Computed theme keys cannot be resolved.');
|
|
516
|
+
if (!['icons', 'extends'].includes(key)) continue;
|
|
517
|
+
if (
|
|
518
|
+
!['ObjectProperty', 'Property'].includes(item.type) ||
|
|
519
|
+
item.method ||
|
|
520
|
+
(item.kind && item.kind !== 'init')
|
|
521
|
+
)
|
|
522
|
+
invalidRegistry();
|
|
523
|
+
result.set(key, {module, node: item.value});
|
|
524
|
+
}
|
|
525
|
+
return result;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/** @param {RegistryReference} ref @returns {Promise<Map<string, any>>} */
|
|
529
|
+
async function referenceFields(ref) {
|
|
530
|
+
const target = await importedExport(ref);
|
|
531
|
+
if (!target)
|
|
532
|
+
invalidRegistry(
|
|
533
|
+
ref.binding.localName,
|
|
534
|
+
'A package configuration cannot be inspected for inherited registries.',
|
|
535
|
+
);
|
|
536
|
+
return guarded(
|
|
537
|
+
`${target.module.filename}:fields-export:${target.name}`,
|
|
538
|
+
async () => {
|
|
539
|
+
const selected = await selectedExport(target.module, target.name);
|
|
540
|
+
return selected.binding
|
|
541
|
+
? referenceFields(importedReference(target.module, selected.binding))
|
|
542
|
+
: fields(target.module, selected.node);
|
|
543
|
+
},
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/** @param {any} module @param {any} node @param {boolean} [rejectOpaque] @returns {Promise<RegistryPlan | null>} */
|
|
548
|
+
async function theme(module, node, rejectOpaque = false) {
|
|
549
|
+
node = unwrap(node);
|
|
550
|
+
if (node?.type === 'Identifier') {
|
|
551
|
+
return guarded(`${module.filename}:theme:${node.name}`, async () => {
|
|
552
|
+
const binding = checkedBinding(module, node.name);
|
|
553
|
+
return binding.kind === 'const'
|
|
554
|
+
? theme(module, binding.node, rejectOpaque)
|
|
555
|
+
: themeReference(importedReference(module, binding), rejectOpaque);
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
if (node?.type === 'MemberExpression') {
|
|
559
|
+
const ref = await reference(module, node);
|
|
560
|
+
if (ref) return themeReference(ref, rejectOpaque);
|
|
561
|
+
}
|
|
562
|
+
if (node?.type === 'CallExpression') {
|
|
563
|
+
if (!isDefineTheme(module, node.callee) || node.arguments.length !== 1)
|
|
564
|
+
invalidRegistry();
|
|
565
|
+
node = unwrap(node.arguments[0]);
|
|
566
|
+
}
|
|
567
|
+
const config = await fields(module, node);
|
|
568
|
+
const baseField = config.get('extends');
|
|
569
|
+
const iconField = config.get('icons');
|
|
570
|
+
const base = baseField
|
|
571
|
+
? await theme(baseField.module, baseField.node)
|
|
572
|
+
: null;
|
|
573
|
+
const own = iconField
|
|
574
|
+
? 'plan' in iconField
|
|
575
|
+
? iconField.plan
|
|
576
|
+
: await registry(iconField.module, iconField.node)
|
|
577
|
+
: null;
|
|
578
|
+
return base && own ? {kind: 'merge', base, own} : (own ?? base);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
let plan;
|
|
582
|
+
try {
|
|
583
|
+
plan = await exportedTheme(readModule(filePath), exportName, rawInput);
|
|
584
|
+
} catch (error) {
|
|
585
|
+
// No registry needs packaging when the loaded theme has none. This also
|
|
586
|
+
// keeps arbitrary icon-free authoring helpers outside this static resolver.
|
|
587
|
+
if (!hasIcons && !inspectedRegistry && error instanceof AstryxError)
|
|
588
|
+
return null;
|
|
589
|
+
throw error;
|
|
590
|
+
}
|
|
591
|
+
if (!plan) {
|
|
592
|
+
if (hasIcons) invalidRegistry();
|
|
593
|
+
return null;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
const used = new Set(reservedNames);
|
|
597
|
+
/** @type {IconImports['imports']} */
|
|
598
|
+
const imports = [];
|
|
599
|
+
const emitted = new Map();
|
|
600
|
+
|
|
601
|
+
/** @param {string} preferred */
|
|
602
|
+
function allocate(preferred) {
|
|
603
|
+
const stem =
|
|
604
|
+
/^[A-Za-z_$][\w$]*$/u.test(preferred) &&
|
|
605
|
+
!['default', 'await', 'yield'].includes(preferred)
|
|
606
|
+
? preferred
|
|
607
|
+
: 'themeIcons';
|
|
608
|
+
let name = stem;
|
|
609
|
+
let counter = 1;
|
|
610
|
+
while (used.has(name)) name = `${stem}${counter++}`;
|
|
611
|
+
used.add(name);
|
|
612
|
+
return name;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/** @param {any} ref */
|
|
616
|
+
function importPath(ref) {
|
|
617
|
+
const source = ref.binding.source;
|
|
618
|
+
if (
|
|
619
|
+
!source.startsWith('.') ||
|
|
620
|
+
path.dirname(ref.module.filename) === entryDirectory
|
|
621
|
+
)
|
|
622
|
+
return source;
|
|
623
|
+
const relative = path
|
|
624
|
+
.relative(
|
|
625
|
+
entryDirectory,
|
|
626
|
+
path.resolve(path.dirname(ref.module.filename), source),
|
|
627
|
+
)
|
|
628
|
+
.split(path.sep)
|
|
629
|
+
.join('/');
|
|
630
|
+
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/** @param {RegistryPlan} value @returns {{expression: string, preferredName: string, overridePath?: string, overrideLocalName?: string}} */
|
|
634
|
+
function render(value) {
|
|
635
|
+
if (value.kind === 'merge') {
|
|
636
|
+
const base = render(value.base);
|
|
637
|
+
const own = render(value.own);
|
|
638
|
+
return {
|
|
639
|
+
expression: `{...${base.expression}, ...${own.expression}}`,
|
|
640
|
+
preferredName: 'themeIcons',
|
|
641
|
+
overridePath: own.overridePath,
|
|
642
|
+
overrideLocalName: own.overrideLocalName,
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
const {ref} = value;
|
|
646
|
+
const source = importPath(ref);
|
|
647
|
+
const identity = `${source}\0${ref.binding.importedName}\0${JSON.stringify(ref.members)}`;
|
|
648
|
+
let localName = emitted.get(identity);
|
|
649
|
+
if (!localName) {
|
|
650
|
+
localName = allocate(ref.binding.localName);
|
|
651
|
+
emitted.set(identity, localName);
|
|
652
|
+
imports.push({
|
|
653
|
+
importPath: source,
|
|
654
|
+
importedName: ref.binding.importedName,
|
|
655
|
+
localName,
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
const expression = ref.members.reduce(
|
|
659
|
+
(result, member) => `${result}[${JSON.stringify(member)}]`,
|
|
660
|
+
localName,
|
|
661
|
+
);
|
|
662
|
+
return {
|
|
663
|
+
expression,
|
|
664
|
+
preferredName:
|
|
665
|
+
ref.members.length === 0 &&
|
|
666
|
+
value.preferredName === ref.binding.localName
|
|
667
|
+
? localName
|
|
668
|
+
: value.preferredName,
|
|
669
|
+
overridePath: value.override ? source : undefined,
|
|
670
|
+
overrideLocalName: value.override ? localName : undefined,
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
const rendered = render(plan);
|
|
675
|
+
const name =
|
|
676
|
+
rendered.preferredName === rendered.expression &&
|
|
677
|
+
imports.some(item => item.localName === rendered.expression)
|
|
678
|
+
? rendered.expression
|
|
679
|
+
: allocate(rendered.preferredName);
|
|
680
|
+
return {
|
|
681
|
+
imports,
|
|
682
|
+
expression: rendered.expression,
|
|
683
|
+
exportName: name,
|
|
684
|
+
...(rendered.overridePath
|
|
685
|
+
? {
|
|
686
|
+
iconsSpecifierImportPath: rendered.overridePath,
|
|
687
|
+
iconsSpecifierLocalName: rendered.overrideLocalName,
|
|
688
|
+
}
|
|
689
|
+
: {}),
|
|
690
|
+
};
|
|
691
|
+
}
|
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* @file FunctionDoc for `themeBuild()` / `astryx theme build`. Colocated with
|
|
6
6
|
* the API function it documents; the response-shape source of truth stays in
|
|
7
|
-
* `theme.type.mjs`.
|
|
7
|
+
* `theme.type.mjs`. Documents imported/inherited icons and atomic rejection
|
|
8
|
+
* of registries that cannot be preserved in build/check modes.
|
|
9
|
+
* @input themeBuild's build/check and icon-import behavior.
|
|
10
|
+
* @output Consumer API documentation for generated theme artifacts.
|
|
8
11
|
* @position packages/cli/api/theme — function documentation
|
|
9
12
|
*/
|
|
10
13
|
/** @type {import('@astryxdesign/cli/authoring').FunctionDoc} */
|