@astryxdesign/cli 0.7.17-canary.g17f7ffc → 0.7.17-canary.g1b6eeb3
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/_adapter.d.mts +7 -5
- package/api/component/_adapter.mjs +49 -10
- package/api/discover/discover.mjs +12 -3
- package/api/doctor/doctor.mjs +1 -1
- package/api/integration/validate-integration.mjs +14 -5
- package/api/integration/validate-integration.type.d.mts +4 -0
- package/api/integration/validate-integration.type.mjs +1 -0
- package/api/template/copy/copy.mjs +4 -6
- package/api/theme/_app-provider.d.mts +31 -0
- package/api/theme/_app-provider.mjs +135 -0
- package/api/theme/add/add.mjs +3 -1
- package/api/theme/build/build.mjs +30 -134
- package/api/theme/remove/remove.mjs +4 -1
- package/api/theme/theme.type.d.mts +28 -0
- package/api/theme/theme.type.mjs +18 -1
- package/api/theme/themeAdd.doc.mjs +1 -1
- package/api/theme/themeRemove.doc.mjs +1 -1
- package/api/theme-edit/_preview-app.mjs +20 -148
- package/assets/codemods/integration-runner.mjs +1 -1
- package/assets/codemods/jscodeshift.d.ts +1 -1
- package/assets/codemods/run-codemod.mjs +71 -18
- package/assets/codemods/runner.mjs +1 -4
- package/assets/component-list.generated.json +1 -1
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs-routes.generated.json +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/search-catalog.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat-landing/page.tsx +31 -4
- package/assets/templates/pages/editor/page.tsx +14 -2
- package/assets/templates/pages/file-explorer/page.tsx +9 -0
- package/assets/templates/pages/form-wizard-vertical/page.tsx +23 -3
- package/assets/templates/pages/kanban-board/page.tsx +11 -1
- package/assets/templates/pages/login-card/page.tsx +16 -0
- package/assets/templates/pages/login-split/page.tsx +19 -6
- package/assets/templates/pages/messaging-shell/template.doc.mjs +6 -0
- package/assets/templates/pages/payment-form/page.tsx +30 -4
- package/assets/templates/pages/product-detail/page.tsx +26 -2
- package/assets/templates/pages/settings-dialog/page.tsx +162 -12
- package/assets/templates/pages/shell-side-nav/page.tsx +11 -3
- package/assets/templates/pages/table-grouped/page.tsx +161 -133
- package/assets/templates/pages/work-item-detail/page.tsx +47 -7
- package/authoring/integration/integration.doc.mjs +4 -3
- package/authoring/integration/schema.d.mts +18 -4
- package/authoring/integration/schema.mjs +93 -15
- package/authoring/integration/type.ts +4 -0
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/theme-add.doc.mjs +1 -1
- package/clients/cli/commands/theme-remove.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +34 -1
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/discovery/core-theme-facts.d.mts +70 -0
- package/foundation/discovery/core-theme-facts.mjs +384 -0
- package/foundation/discovery/hook-discovery.d.mts +10 -0
- package/foundation/discovery/hook-discovery.mjs +77 -40
- package/foundation/discovery/next-routes.d.mts +48 -0
- package/foundation/discovery/next-routes.mjs +181 -0
- package/foundation/discovery/template-destination.d.mts +28 -0
- package/foundation/discovery/template-destination.mjs +104 -0
- package/foundation/discovery/theme-discovery.d.mts +3 -1
- package/foundation/discovery/theme-discovery.mjs +1 -1
- package/foundation/discovery/theming-targets.d.mts +7 -0
- package/foundation/discovery/theming-targets.mjs +11 -1
- package/foundation/fs/gather-cache.mjs +14 -5
- package/foundation/fs/read-record.d.mts +2 -1
- package/foundation/fs/read-record.mjs +18 -1
- package/foundation/integrations/integrations.d.mts +17 -3
- package/foundation/integrations/integrations.mjs +16 -3
- package/foundation/integrations/validate-contributions.mjs +7 -0
- package/foundation/suggest/other-command.d.mts +38 -6
- package/foundation/suggest/other-command.mjs +113 -19
- package/foundation/text/suggest-order.d.mts +10 -0
- package/foundation/text/suggest-order.mjs +14 -0
- package/package.json +6 -6
|
@@ -293,11 +293,13 @@ export function withExampleBlockPointer(error: unknown, dirName: string, { coreD
|
|
|
293
293
|
}): Promise<unknown>;
|
|
294
294
|
/**
|
|
295
295
|
* When `error` is the unknown-component error for a name that matches a hook,
|
|
296
|
-
* template or docs topic (exact, folded or last segment,
|
|
297
|
-
* foundation/suggest/other-command.mjs
|
|
298
|
-
*
|
|
299
|
-
* foundation/suggest/other-command.mjs
|
|
300
|
-
*
|
|
296
|
+
* template or docs topic (exact, folded or last segment, or a hook it nearly
|
|
297
|
+
* spells or whose keyword it is, as foundation/suggest/other-command.mjs
|
|
298
|
+
* ranks it), returns the same error with the command that reads that entry
|
|
299
|
+
* among its suggestions, in the place foundation/suggest/other-command.mjs
|
|
300
|
+
* gives it: a hook keyword hint stays behind a suggested component that
|
|
301
|
+
* declares the same keyword or synonym. Returns `error` unchanged otherwise,
|
|
302
|
+
* and when the check fails.
|
|
301
303
|
* @param {unknown} error
|
|
302
304
|
* @param {string} dirName
|
|
303
305
|
* @param {{coreDir: string, cwd: string, loadedIntegrations: import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]}} context
|
|
@@ -905,11 +905,13 @@ export async function withExampleBlockPointer(error, dirName, {coreDir, cwd}) {
|
|
|
905
905
|
|
|
906
906
|
/**
|
|
907
907
|
* When `error` is the unknown-component error for a name that matches a hook,
|
|
908
|
-
* template or docs topic (exact, folded or last segment,
|
|
909
|
-
* foundation/suggest/other-command.mjs
|
|
910
|
-
*
|
|
911
|
-
* foundation/suggest/other-command.mjs
|
|
912
|
-
*
|
|
908
|
+
* template or docs topic (exact, folded or last segment, or a hook it nearly
|
|
909
|
+
* spells or whose keyword it is, as foundation/suggest/other-command.mjs
|
|
910
|
+
* ranks it), returns the same error with the command that reads that entry
|
|
911
|
+
* among its suggestions, in the place foundation/suggest/other-command.mjs
|
|
912
|
+
* gives it: a hook keyword hint stays behind a suggested component that
|
|
913
|
+
* declares the same keyword or synonym. Returns `error` unchanged otherwise,
|
|
914
|
+
* and when the check fails.
|
|
913
915
|
* @param {unknown} error
|
|
914
916
|
* @param {string} dirName
|
|
915
917
|
* @param {{coreDir: string, cwd: string, loadedIntegrations: import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]}} context
|
|
@@ -928,11 +930,13 @@ export async function withOtherCommandHint(
|
|
|
928
930
|
}
|
|
929
931
|
try {
|
|
930
932
|
// The hint's modules load only on this path.
|
|
931
|
-
const [
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
933
|
+
const [
|
|
934
|
+
{findOtherCommand, withOtherCommand, MATCH_TIER},
|
|
935
|
+
{docsRoutesLazily},
|
|
936
|
+
] = await Promise.all([
|
|
937
|
+
import('../../foundation/suggest/other-command.mjs'),
|
|
938
|
+
import('../docs/_entry-names-lazily.mjs'),
|
|
939
|
+
]);
|
|
936
940
|
const hint = await findOtherCommand(dirName, {
|
|
937
941
|
from: 'component',
|
|
938
942
|
cwd,
|
|
@@ -941,10 +945,15 @@ export async function withOtherCommandHint(
|
|
|
941
945
|
docsRoutes: docsRoutesLazily,
|
|
942
946
|
});
|
|
943
947
|
if (!hint) return error;
|
|
948
|
+
const declared =
|
|
949
|
+
hint.tier === MATCH_TIER.keyword
|
|
950
|
+
? await declaredNames(error.suggestions ?? [], coreDir)
|
|
951
|
+
: new Map();
|
|
944
952
|
return new AstryxError(
|
|
945
953
|
error.message,
|
|
946
954
|
withOtherCommand(error.suggestions, hint, dirName, {
|
|
947
955
|
from: 'component',
|
|
956
|
+
keywordsOf: suggestion => declared.get(suggestion.name) ?? [],
|
|
948
957
|
}),
|
|
949
958
|
ERROR_CODES.ERR_UNKNOWN_COMPONENT,
|
|
950
959
|
);
|
|
@@ -953,6 +962,36 @@ export async function withOtherCommandHint(
|
|
|
953
962
|
}
|
|
954
963
|
}
|
|
955
964
|
|
|
965
|
+
/**
|
|
966
|
+
* The keywords and synonyms each suggested Core component declares: its
|
|
967
|
+
* doc's `keywords` and its search card's `synonyms`.
|
|
968
|
+
* @param {Array<{name: string}>} suggestions
|
|
969
|
+
* @param {string} coreDir
|
|
970
|
+
* @returns {Promise<Map<string, string[]>>}
|
|
971
|
+
*/
|
|
972
|
+
async function declaredNames(suggestions, coreDir) {
|
|
973
|
+
const {readDocView} = await import('../../foundation/doc-compiler/read.mjs');
|
|
974
|
+
/** @type {Map<string, string[]>} */
|
|
975
|
+
const declared = new Map();
|
|
976
|
+
for (const {name} of suggestions) {
|
|
977
|
+
const docPath = findComponentReadme(coreDir, name);
|
|
978
|
+
/** @type {{keywords?: unknown} | null} */
|
|
979
|
+
const doc = docPath
|
|
980
|
+
? await readDocView(docPath, {
|
|
981
|
+
root: 'components',
|
|
982
|
+
loader: 'native',
|
|
983
|
+
exports: ['docs'],
|
|
984
|
+
}).catch(() => null)
|
|
985
|
+
: null;
|
|
986
|
+
const keywords = Array.isArray(doc?.keywords) ? doc.keywords : [];
|
|
987
|
+
declared.set(name, [
|
|
988
|
+
...keywords.filter(keyword => typeof keyword === 'string'),
|
|
989
|
+
...(searchCards()[name]?.synonyms ?? []),
|
|
990
|
+
]);
|
|
991
|
+
}
|
|
992
|
+
return declared;
|
|
993
|
+
}
|
|
994
|
+
|
|
956
995
|
/**
|
|
957
996
|
* A component whose `component <Name> --blocks` listing holds `block`: one of
|
|
958
997
|
* the components the block uses, its own folder's component first, that
|
|
@@ -192,10 +192,19 @@ export async function discover(query, options = {}) {
|
|
|
192
192
|
: undefined;
|
|
193
193
|
|
|
194
194
|
const {packages: scanned, configured, project} = await discoverPackages();
|
|
195
|
-
const integrations = await describeInstalled(project, scanned);
|
|
196
|
-
const declared = declaredDependencies(project);
|
|
197
195
|
// The official list is always read, so discover always has a source.
|
|
198
196
|
const official = officialList({project});
|
|
197
|
+
// The list asks every source for its catalog. A catalog needs nothing the
|
|
198
|
+
// installed packages' descriptions give, so a slow source, such as a remote
|
|
199
|
+
// catalog, answers while they are read.
|
|
200
|
+
const listCatalog = query
|
|
201
|
+
? undefined
|
|
202
|
+
: callSources(project, undefined, {official});
|
|
203
|
+
// Awaited below; a failure reading the installed packages first must not
|
|
204
|
+
// leave it unhandled.
|
|
205
|
+
listCatalog?.catch(() => {});
|
|
206
|
+
const integrations = await describeInstalled(project, scanned);
|
|
207
|
+
const declared = declaredDependencies(project);
|
|
199
208
|
const declarations = officialDeclarations(project, official.packages);
|
|
200
209
|
const add = addCommand(project);
|
|
201
210
|
const addOfficial = addCommand(project, {official: official.packages});
|
|
@@ -221,7 +230,7 @@ export async function discover(query, options = {}) {
|
|
|
221
230
|
// No query, or any query in a project that loads no integration and has no
|
|
222
231
|
// discover source of its own: the list (spec:AST-051 FR1).
|
|
223
232
|
if (!query || (integrations.length === 0 && !hasSources(project))) {
|
|
224
|
-
const catalog = await catalogFor();
|
|
233
|
+
const catalog = await (listCatalog ?? catalogFor());
|
|
225
234
|
const packages = installedFor(catalog);
|
|
226
235
|
// Inside a project, the integrations installed for the computer are
|
|
227
236
|
// available, never loaded (spec AST-081 FR12).
|
package/api/doctor/doctor.mjs
CHANGED
|
@@ -2325,7 +2325,7 @@ export function checkGatherCache() {
|
|
|
2325
2325
|
id: 'gather-cache',
|
|
2326
2326
|
label: 'Kept catalog cache',
|
|
2327
2327
|
status: 'info',
|
|
2328
|
-
message: `search, build, component, template, theme, discover, docs and doctor keep what they gather (search's catalogs, each integration's check results, template discovery's records, the component list, integrations' theme records, the lookup commands' not-found hint's name summaries, the CLI's own docs tree, and doctor's docs checks and theme-wiring scan) in ${summary.dir} (${summary.entries} ${summary.entries === 1 ? 'entry' : 'entries'}, ${size})${summary.pnp ? ", but not in a run under Yarn Plug'n'Play's loader, such as `yarn astryx`, which gathers every time" : ''}; each is used only while nothing it read has changed, the installed CLI's own files judged by its build id (an upgrade or reinstall changes it; in-place edits aren't supported), and deleting the folder clears it. A lookup command's not-found path may also create the folder, for its name index. The folder holds at most ${summary.limitBytes / (1024 * 1024)} MB, dropping oldest entries first, as does the transpile cache in ${summary.jitiDir}, which keeps every copy written, or read where the file system records reads, in the last day.`,
|
|
2328
|
+
message: `search, build, component, template, theme, discover, docs and doctor keep what they gather (search's catalogs, each integration's check results, template discovery's records, the component list, integrations' theme records, what theme build checks a theme against in Core's component docs, the lookup commands' not-found hint's name summaries, the CLI's own docs tree, and doctor's docs checks and theme-wiring scan) in ${summary.dir} (${summary.entries} ${summary.entries === 1 ? 'entry' : 'entries'}, ${size})${summary.pnp ? ", but not in a run under Yarn Plug'n'Play's loader, such as `yarn astryx`, which gathers every time" : ''}; each is used only while nothing it read has changed, the installed CLI's own files judged by its build id (an upgrade or reinstall changes it; in-place edits aren't supported), and deleting the folder clears it. A lookup command's not-found path may also create the folder, for its name index. The folder holds at most ${summary.limitBytes / (1024 * 1024)} MB, dropping oldest entries first, as does the transpile cache in ${summary.jitiDir}, which keeps every copy written, or read where the file system records reads, in the last day.`,
|
|
2329
2329
|
};
|
|
2330
2330
|
}
|
|
2331
2331
|
|
|
@@ -391,6 +391,8 @@ async function validateAtPackageDir(
|
|
|
391
391
|
let manifest;
|
|
392
392
|
/** @type {string[]} */
|
|
393
393
|
let unknownKeys;
|
|
394
|
+
/** @type {Array<{field: string, why: string}>} */
|
|
395
|
+
let ignoredFields;
|
|
394
396
|
/** @type {string[]} */
|
|
395
397
|
let declaredKeys;
|
|
396
398
|
/** @type {string | undefined} */
|
|
@@ -398,11 +400,17 @@ async function validateAtPackageDir(
|
|
|
398
400
|
/** @type {string | undefined} */
|
|
399
401
|
let cliCommandError;
|
|
400
402
|
try {
|
|
401
|
-
({
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
403
|
+
({
|
|
404
|
+
manifest,
|
|
405
|
+
unknownKeys,
|
|
406
|
+
ignoredFields,
|
|
407
|
+
declaredKeys,
|
|
408
|
+
agentDocsError,
|
|
409
|
+
cliCommandError,
|
|
410
|
+
} = await loadManifest(
|
|
411
|
+
manifestFile,
|
|
412
|
+
`Integration manifest (${path.basename(manifestFile)})`,
|
|
413
|
+
));
|
|
406
414
|
} catch (err) {
|
|
407
415
|
issues.push(error('invalid_manifest', /** @type {any} */ (err).message));
|
|
408
416
|
return result;
|
|
@@ -469,6 +477,7 @@ async function validateAtPackageDir(
|
|
|
469
477
|
__cliCommandError: cliCommandError,
|
|
470
478
|
__agentDocsError: agentDocsError,
|
|
471
479
|
__unknownKeys: unknownKeys,
|
|
480
|
+
__ignoredFields: ignoredFields,
|
|
472
481
|
__declaredKeys: declaredKeys,
|
|
473
482
|
__spec: identity.name,
|
|
474
483
|
__declaredProviderId: manifest.providerId,
|
|
@@ -16,6 +16,10 @@ export type LoadedIntegration = {
|
|
|
16
16
|
issuesUrl?: string | undefined;
|
|
17
17
|
__declaredKeys?: string[] | undefined;
|
|
18
18
|
__unknownKeys?: string[] | undefined;
|
|
19
|
+
__ignoredFields?: {
|
|
20
|
+
field: string;
|
|
21
|
+
why: string;
|
|
22
|
+
}[] | undefined;
|
|
19
23
|
__spec: string;
|
|
20
24
|
__packageDir: string;
|
|
21
25
|
__manifestFile: string;
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* @property {string} [issuesUrl]
|
|
21
21
|
* @property {string[]} [__declaredKeys]
|
|
22
22
|
* @property {string[]} [__unknownKeys]
|
|
23
|
+
* @property {Array<{field: string, why: string}>} [__ignoredFields]
|
|
23
24
|
* @property {string} __spec
|
|
24
25
|
* @property {string} __packageDir
|
|
25
26
|
* @property {string} __manifestFile
|
|
@@ -23,6 +23,8 @@ import {
|
|
|
23
23
|
replaceTemplateDemos,
|
|
24
24
|
} from '../../../foundation/discovery/template-adapter.mjs';
|
|
25
25
|
import {analyzeTemplateNeeds} from '../../../foundation/discovery/template-needs.mjs';
|
|
26
|
+
import {templateDestination} from '../../../foundation/discovery/template-destination.mjs';
|
|
27
|
+
import {quoteCommandArgument} from '../../../foundation/env/package-manager.mjs';
|
|
26
28
|
import {
|
|
27
29
|
NO_ICON_SETS,
|
|
28
30
|
mapTemplateIcons,
|
|
@@ -85,17 +87,13 @@ export function templateCopy(
|
|
|
85
87
|
err.code === ERROR_CODES.ERR_PATH_TRAVERSAL &&
|
|
86
88
|
!err.viaSymlink
|
|
87
89
|
) {
|
|
88
|
-
const folder =
|
|
89
|
-
'src',
|
|
90
|
-
match.type === 'block' ? 'components' : 'pages',
|
|
91
|
-
match.dirName,
|
|
92
|
-
);
|
|
90
|
+
const folder = templateDestination(cwd, match.type, match.dirName);
|
|
93
91
|
throw new AstryxError(
|
|
94
92
|
`Invalid template target path "${targetPath}": it is outside the project root (${path.resolve(cwd)}). ` +
|
|
95
93
|
'The template is written only inside the project. Give a path inside it, or print the source.',
|
|
96
94
|
[
|
|
97
95
|
{
|
|
98
|
-
name: `${command} ${folder}`,
|
|
96
|
+
name: `${command} ${quoteCommandArgument(folder)}`,
|
|
99
97
|
reason: `write the ${match.type} inside the project`,
|
|
100
98
|
},
|
|
101
99
|
{name: command, reason: 'print the source and write nothing'},
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {{export: string, from: string, themeProp?: string, modeProp?: string}} AppProvider
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* A receipt with its `appProvider` (theme.type.mjs ThemeAppResponse) when an
|
|
9
|
+
* installed package names a provider and the receipt shows wiring.
|
|
10
|
+
*
|
|
11
|
+
* - First add: `wire` says the app may already get its theme from each such
|
|
12
|
+
* provider, naming the props it takes. With exactly one provider, and that
|
|
13
|
+
* one taking a theme object (`themeProp`), the wiring is that provider
|
|
14
|
+
* with the theme passed (`line`, its opening JSX); otherwise each
|
|
15
|
+
* provider's trade-off follows and the `Theme` wiring stays.
|
|
16
|
+
* - A later add that first lists `themeModes`, or the removal of the last
|
|
17
|
+
* theme: only when that one provider takes the theme, `wire` and `line`
|
|
18
|
+
* say how its wiring changes.
|
|
19
|
+
*
|
|
20
|
+
* @template {import('./theme.type.mjs').ThemeAppResponse} R
|
|
21
|
+
* @param {R} result
|
|
22
|
+
* @param {string} cwd
|
|
23
|
+
* @returns {Promise<R>}
|
|
24
|
+
*/
|
|
25
|
+
export function withAppProvider<R extends import("./theme.type.mjs").ThemeAppResponse>(result: R, cwd: string): Promise<R>;
|
|
26
|
+
export type AppProvider = {
|
|
27
|
+
export: string;
|
|
28
|
+
from: string;
|
|
29
|
+
themeProp?: string;
|
|
30
|
+
modeProp?: string;
|
|
31
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The provider an installed integration names as the one that wires
|
|
5
|
+
* its themes (its manifest's `themeProvider`), on the receipts that show the
|
|
6
|
+
* app's wiring: the first add, a later add that first lists `themeModes`,
|
|
7
|
+
* and the removal of the last theme.
|
|
8
|
+
*
|
|
9
|
+
* Read from the packages' manifests, never from the app's source. The
|
|
10
|
+
* receipt says how Themes nest and never says to replace a provider, which
|
|
11
|
+
* may do more than theming. Shared by `theme add` and `theme remove`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {listAvailableThemeState} from './_adapter.mjs';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {{export: string, from: string, themeProp?: string, modeProp?: string}} AppProvider
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A receipt with its `appProvider` (theme.type.mjs ThemeAppResponse) when an
|
|
22
|
+
* installed package names a provider and the receipt shows wiring.
|
|
23
|
+
*
|
|
24
|
+
* - First add: `wire` says the app may already get its theme from each such
|
|
25
|
+
* provider, naming the props it takes. With exactly one provider, and that
|
|
26
|
+
* one taking a theme object (`themeProp`), the wiring is that provider
|
|
27
|
+
* with the theme passed (`line`, its opening JSX); otherwise each
|
|
28
|
+
* provider's trade-off follows and the `Theme` wiring stays.
|
|
29
|
+
* - A later add that first lists `themeModes`, or the removal of the last
|
|
30
|
+
* theme: only when that one provider takes the theme, `wire` and `line`
|
|
31
|
+
* say how its wiring changes.
|
|
32
|
+
*
|
|
33
|
+
* @template {import('./theme.type.mjs').ThemeAppResponse} R
|
|
34
|
+
* @param {R} result
|
|
35
|
+
* @param {string} cwd
|
|
36
|
+
* @returns {Promise<R>}
|
|
37
|
+
*/
|
|
38
|
+
export async function withAppProvider(result, cwd) {
|
|
39
|
+
const change = result.data.change;
|
|
40
|
+
const kind = change.moduleRemoved
|
|
41
|
+
? 'removed'
|
|
42
|
+
: change.firstAdd
|
|
43
|
+
? 'first'
|
|
44
|
+
: change.wireModes
|
|
45
|
+
? 'modes'
|
|
46
|
+
: null;
|
|
47
|
+
if (!kind) return result;
|
|
48
|
+
const {themes} = await listAvailableThemeState(cwd);
|
|
49
|
+
/** Each provider once, with the package that declares it. @type {Map<string, {provider: AppProvider, owner: string}>} */
|
|
50
|
+
const byProvider = new Map();
|
|
51
|
+
for (const theme of themes)
|
|
52
|
+
if (theme.provider)
|
|
53
|
+
byProvider.set(`${theme.provider.export}\0${theme.provider.from}`, {
|
|
54
|
+
provider: {
|
|
55
|
+
export: theme.provider.export,
|
|
56
|
+
from: theme.provider.from,
|
|
57
|
+
...(theme.provider.themeProp
|
|
58
|
+
? {themeProp: theme.provider.themeProp}
|
|
59
|
+
: {}),
|
|
60
|
+
...(theme.provider.themeProp && theme.provider.modeProp
|
|
61
|
+
? {modeProp: theme.provider.modeProp}
|
|
62
|
+
: {}),
|
|
63
|
+
},
|
|
64
|
+
owner: String(theme.package ?? theme.provider.from),
|
|
65
|
+
});
|
|
66
|
+
const found = [...byProvider.values()];
|
|
67
|
+
// Only one applicable provider gets the provider form: with two, which
|
|
68
|
+
// one wires the app is not ours to say.
|
|
69
|
+
const taking =
|
|
70
|
+
found.length === 1 && found[0].provider.themeProp ? found[0] : null;
|
|
71
|
+
if (!found.length || (kind !== 'first' && !taking)) return result;
|
|
72
|
+
// The wiring passes a mode when the provider takes one and an added theme
|
|
73
|
+
// has one color mode, as the Theme wiring does.
|
|
74
|
+
const oneMode =
|
|
75
|
+
kind === 'modes'
|
|
76
|
+
? true
|
|
77
|
+
: kind === 'removed'
|
|
78
|
+
? Boolean(change.themeModes)
|
|
79
|
+
: result.data.themes.some(t => t.mode);
|
|
80
|
+
const modeProp = oneMode ? taking?.provider.modeProp : undefined;
|
|
81
|
+
const line = taking
|
|
82
|
+
? `<${taking.provider.export} ${taking.provider.themeProp}={themes[defaultThemeSlug]}${modeProp ? ` ${modeProp}={themeModes[defaultThemeSlug]}` : ''}>`
|
|
83
|
+
: null;
|
|
84
|
+
const name = taking?.provider.export;
|
|
85
|
+
let wire;
|
|
86
|
+
if (kind === 'first') {
|
|
87
|
+
const named = found
|
|
88
|
+
.map(({provider, owner}) => {
|
|
89
|
+
const props = [
|
|
90
|
+
...(provider.themeProp ? [`the theme as ${provider.themeProp}`] : []),
|
|
91
|
+
...(provider.modeProp ? [`the mode as ${provider.modeProp}`] : []),
|
|
92
|
+
];
|
|
93
|
+
return `${provider.export} (from ${provider.from}, declared by ${owner}${props.length ? `; it takes ${props.join(' and ')}` : ''})`;
|
|
94
|
+
})
|
|
95
|
+
.join(' or ');
|
|
96
|
+
const from = `This app may already get its theme from ${named}.`;
|
|
97
|
+
wire = taking
|
|
98
|
+
? `${from} Pass this theme to it in the app root:`
|
|
99
|
+
: [
|
|
100
|
+
from,
|
|
101
|
+
...found.map(
|
|
102
|
+
({provider}) =>
|
|
103
|
+
`Replacing ${provider.export} applies this theme everywhere but also drops anything else it sets up; a Theme inside it themes only what it wraps.`,
|
|
104
|
+
),
|
|
105
|
+
].join(' ');
|
|
106
|
+
} else if (kind === 'modes')
|
|
107
|
+
wire = modeProp
|
|
108
|
+
? `The theme module now exports themeModes. Pass the selected theme's mode to ${name} in the app root:`
|
|
109
|
+
: `The theme module now exports themeModes; ${name} (from ${taking?.provider.from}), which takes the theme as ${taking?.provider.themeProp}, takes no mode, so its wiring stays as it is.`;
|
|
110
|
+
else
|
|
111
|
+
wire = `Undo its wiring in the app root: delete the module's import and the props that pass its theme to ${name}, and keep ${name}, which may set up more than the theme:`;
|
|
112
|
+
return {
|
|
113
|
+
...result,
|
|
114
|
+
data: {
|
|
115
|
+
...result.data,
|
|
116
|
+
appProvider: {
|
|
117
|
+
// A later receipt names only the props its wiring uses: a mode prop
|
|
118
|
+
// the line does not pass is left out, as the text leaves it out.
|
|
119
|
+
wiredBy: found.map(({provider}) =>
|
|
120
|
+
kind === 'first' || modeProp
|
|
121
|
+
? provider
|
|
122
|
+
: {
|
|
123
|
+
export: provider.export,
|
|
124
|
+
from: provider.from,
|
|
125
|
+
...(provider.themeProp ? {themeProp: provider.themeProp} : {}),
|
|
126
|
+
},
|
|
127
|
+
),
|
|
128
|
+
wire,
|
|
129
|
+
...(taking && line && (kind !== 'modes' || modeProp)
|
|
130
|
+
? {themeProp: String(taking.provider.themeProp), line}
|
|
131
|
+
: {}),
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
package/api/theme/add/add.mjs
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import {addThemeToApp} from '../_adapter.mjs';
|
|
12
|
+
import {withAppProvider} from '../_app-provider.mjs';
|
|
12
13
|
import {AstryxError} from '../../error.mjs';
|
|
13
14
|
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
14
15
|
|
|
@@ -36,5 +37,6 @@ export async function themeAdd(slug, options = {}) {
|
|
|
36
37
|
ERROR_CODES.ERR_THEME_INVALID,
|
|
37
38
|
);
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
+
const result = await addThemeToApp(slug, options);
|
|
41
|
+
return withAppProvider(result, options.cwd ?? process.cwd());
|
|
40
42
|
}
|
|
@@ -91,16 +91,17 @@ import {validatePrivateVars} from '../../../foundation/config/theme-private-vars
|
|
|
91
91
|
import {AstryxError} from '../../error.mjs';
|
|
92
92
|
import {applyWrites} from '../../integration/add-helpers.mjs';
|
|
93
93
|
import {logger} from '../../logger.mjs';
|
|
94
|
-
import {
|
|
94
|
+
import {
|
|
95
|
+
coreThemeTargets,
|
|
96
|
+
coreThemeValues,
|
|
97
|
+
keepCoreThemeFacts,
|
|
98
|
+
} from '../../../foundation/discovery/core-theme-facts.mjs';
|
|
95
99
|
import {THEME_SOURCE_EXTENSIONS} from '../../../foundation/discovery/theme-module-extensions.mjs';
|
|
96
100
|
import {
|
|
97
101
|
createJiti,
|
|
98
102
|
withEmptyStylesheets,
|
|
99
103
|
} from '../../../foundation/fs/module-loader.mjs';
|
|
100
|
-
import {
|
|
101
|
-
collectThemingTargets,
|
|
102
|
-
targetsByKey,
|
|
103
|
-
} from '../../../foundation/discovery/theming-targets.mjs';
|
|
104
|
+
import {targetsByKey} from '../../../foundation/discovery/theming-targets.mjs';
|
|
104
105
|
import {
|
|
105
106
|
collectUnloadedFonts,
|
|
106
107
|
formatBatchFontLoadingHelp,
|
|
@@ -1697,109 +1698,9 @@ let _knownValuesIndexPromise = null;
|
|
|
1697
1698
|
* guessing is not a valid lookup strategy.
|
|
1698
1699
|
*/
|
|
1699
1700
|
async function loadKnownValuesIndex() {
|
|
1700
|
-
const
|
|
1701
|
-
const coreSrc = coreRoot ? path.join(coreRoot, 'src') : null;
|
|
1701
|
+
const coreSrc = coreSrcPath();
|
|
1702
1702
|
if (!coreSrc || !fs.existsSync(coreSrc)) return {};
|
|
1703
|
-
|
|
1704
|
-
// One malformed or optional doc must not erase validation for the rest.
|
|
1705
|
-
const docs = (await coreComponentDocs(coreSrc)).flatMap(read =>
|
|
1706
|
-
'error' in read ? [] : [read.doc],
|
|
1707
|
-
);
|
|
1708
|
-
|
|
1709
|
-
/** @param {string} value */
|
|
1710
|
-
const targetName = value =>
|
|
1711
|
-
value
|
|
1712
|
-
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
1713
|
-
.replace(/\s+/g, '-')
|
|
1714
|
-
.toLowerCase();
|
|
1715
|
-
/**
|
|
1716
|
-
* @param {any[]} props
|
|
1717
|
-
* @returns {Record<string, Set<string>>}
|
|
1718
|
-
*/
|
|
1719
|
-
const valuesFromProps = props => {
|
|
1720
|
-
/** @type {Record<string, Set<string>>} */
|
|
1721
|
-
const result = {};
|
|
1722
|
-
for (const prop of props ?? []) {
|
|
1723
|
-
if (typeof prop?.name !== 'string' || typeof prop?.type !== 'string') {
|
|
1724
|
-
continue;
|
|
1725
|
-
}
|
|
1726
|
-
/** @type {Set<string>} */
|
|
1727
|
-
const values = new Set();
|
|
1728
|
-
for (const match of prop.type.match(/'([^']+)'/g) ?? []) {
|
|
1729
|
-
values.add(match.slice(1, -1));
|
|
1730
|
-
}
|
|
1731
|
-
for (const part of prop.type
|
|
1732
|
-
.split('|')
|
|
1733
|
-
.map((/** @type {string} */ value) => value.trim())) {
|
|
1734
|
-
if (/^-?\d+(?:\.\d+)?$/.test(part)) values.add(part);
|
|
1735
|
-
}
|
|
1736
|
-
if (values.size > 0) result[prop.name] = values;
|
|
1737
|
-
}
|
|
1738
|
-
return result;
|
|
1739
|
-
};
|
|
1740
|
-
|
|
1741
|
-
// A component can appear in more than one doc: its own doc declares its
|
|
1742
|
-
// props, and a parent doc can list it by name only. Merge every entry, so
|
|
1743
|
-
// the result does not depend on the order the docs load in.
|
|
1744
|
-
/** @type {Record<string, Record<string, Set<string>>>} */
|
|
1745
|
-
const valuesByOwner = {};
|
|
1746
|
-
/**
|
|
1747
|
-
* @param {string} name
|
|
1748
|
-
* @param {any[]} props
|
|
1749
|
-
*/
|
|
1750
|
-
const addOwnerValues = (name, props) => {
|
|
1751
|
-
const owner = (valuesByOwner[targetName(name)] ??= {});
|
|
1752
|
-
for (const [prop, values] of Object.entries(valuesFromProps(props))) {
|
|
1753
|
-
owner[prop] = new Set([...(owner[prop] ?? []), ...values]);
|
|
1754
|
-
}
|
|
1755
|
-
};
|
|
1756
|
-
for (const doc of docs) {
|
|
1757
|
-
if (typeof doc?.name === 'string') {
|
|
1758
|
-
addOwnerValues(doc.name, doc.props);
|
|
1759
|
-
}
|
|
1760
|
-
for (const component of /** @type {any[]} */ (doc?.components ?? [])) {
|
|
1761
|
-
if (typeof component?.name === 'string') {
|
|
1762
|
-
addOwnerValues(component.name, component.props);
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
|
|
1767
|
-
/** @type {Record<string, Record<string, Set<string>>>} */
|
|
1768
|
-
const collected = {};
|
|
1769
|
-
for (const doc of docs) {
|
|
1770
|
-
const localValues = valuesFromProps([
|
|
1771
|
-
...(doc?.props ?? []),
|
|
1772
|
-
...(doc?.components ?? []).flatMap(
|
|
1773
|
-
(/** @type {any} */ component) => component?.props ?? [],
|
|
1774
|
-
),
|
|
1775
|
-
]);
|
|
1776
|
-
for (const target of doc?.theming?.targets ?? []) {
|
|
1777
|
-
if (typeof target?.className !== 'string') continue;
|
|
1778
|
-
const componentName = target.className.replace(/^astryx-/, '');
|
|
1779
|
-
const ownerValues = valuesByOwner[componentName] ?? {};
|
|
1780
|
-
if (!collected[componentName]) collected[componentName] = {};
|
|
1781
|
-
for (const prop of target.visualProps ?? []) {
|
|
1782
|
-
if (!collected[componentName][prop]) {
|
|
1783
|
-
collected[componentName][prop] = new Set();
|
|
1784
|
-
}
|
|
1785
|
-
for (const value of [
|
|
1786
|
-
...(localValues[prop] ?? []),
|
|
1787
|
-
...(ownerValues[prop] ?? []),
|
|
1788
|
-
]) {
|
|
1789
|
-
collected[componentName][prop].add(value);
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
|
|
1795
|
-
return Object.fromEntries(
|
|
1796
|
-
Object.entries(collected).map(([component, props]) => [
|
|
1797
|
-
component,
|
|
1798
|
-
Object.fromEntries(
|
|
1799
|
-
Object.entries(props).map(([prop, values]) => [prop, [...values]]),
|
|
1800
|
-
),
|
|
1801
|
-
]),
|
|
1802
|
-
);
|
|
1703
|
+
return (await coreThemeValues(coreSrc)).knownValues;
|
|
1803
1704
|
}
|
|
1804
1705
|
|
|
1805
1706
|
/**
|
|
@@ -1824,6 +1725,16 @@ function resolveCoreRoot() {
|
|
|
1824
1725
|
return fs.existsSync(coreRoot) ? coreRoot : null;
|
|
1825
1726
|
}
|
|
1826
1727
|
|
|
1728
|
+
/**
|
|
1729
|
+
* The `src` folder of the Core beside the CLI ({@link resolveCoreRoot}), or
|
|
1730
|
+
* null when there is none.
|
|
1731
|
+
* @returns {string | null}
|
|
1732
|
+
*/
|
|
1733
|
+
function coreSrcPath() {
|
|
1734
|
+
const coreRoot = resolveCoreRoot();
|
|
1735
|
+
return coreRoot ? path.join(coreRoot, 'src') : null;
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1827
1738
|
/**
|
|
1828
1739
|
* Read the type declarations `@astryxdesign/core/<Component>` exposes so we can
|
|
1829
1740
|
* check whether a given augmentation-target interface actually exists before
|
|
@@ -1905,8 +1816,7 @@ async function resolveAugmentationTargetCandidates(componentName) {
|
|
|
1905
1816
|
},
|
|
1906
1817
|
];
|
|
1907
1818
|
|
|
1908
|
-
const
|
|
1909
|
-
const coreSrc = coreRoot ? path.join(coreRoot, 'src') : null;
|
|
1819
|
+
const coreSrc = coreSrcPath();
|
|
1910
1820
|
if (!coreSrc || !fs.existsSync(coreSrc)) {
|
|
1911
1821
|
_augmentationTargetCache.set(componentName, fallback);
|
|
1912
1822
|
return fallback;
|
|
@@ -1928,33 +1838,16 @@ async function resolveAugmentationTargetCandidates(componentName) {
|
|
|
1928
1838
|
matches.push({moduleName, interfacePrefix});
|
|
1929
1839
|
}
|
|
1930
1840
|
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
(/** @type {any} */ target) =>
|
|
1936
|
-
typeof target?.className === 'string' &&
|
|
1937
|
-
target.className.replace(/^astryx-/, '') === componentName,
|
|
1938
|
-
);
|
|
1939
|
-
if (!matchesTarget) continue;
|
|
1940
|
-
|
|
1941
|
-
const moduleName =
|
|
1942
|
-
typeof doc?.name === 'string' && doc.name
|
|
1943
|
-
? doc.name
|
|
1944
|
-
: path.basename(path.dirname(file));
|
|
1945
|
-
|
|
1841
|
+
const {owners} = await coreThemeValues(coreSrc);
|
|
1842
|
+
for (const {moduleName, components} of Object.hasOwn(owners, componentName)
|
|
1843
|
+
? owners[componentName]
|
|
1844
|
+
: []) {
|
|
1946
1845
|
// Try the exact rendered token first for documented subtargets such as
|
|
1947
1846
|
// avatar-status-dot → AvatarStatusDotVariantMap, then the owning public
|
|
1948
1847
|
// component name (for example, ProgressBar for progress-bar-fill).
|
|
1949
1848
|
addCandidate(moduleName, toPascalCase(componentName));
|
|
1950
1849
|
addCandidate(moduleName, moduleName);
|
|
1951
|
-
|
|
1952
|
-
for (const comp of doc.components) {
|
|
1953
|
-
if (typeof comp?.name === 'string') {
|
|
1954
|
-
addCandidate(moduleName, comp.name);
|
|
1955
|
-
}
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
1850
|
+
for (const name of components) addCandidate(moduleName, name);
|
|
1958
1851
|
}
|
|
1959
1852
|
// A target documented by a parent component may also have its own public
|
|
1960
1853
|
// subpath and augmentation interface (Heading is documented under Text but
|
|
@@ -3770,11 +3663,10 @@ function builtThemeType(themeDef) {
|
|
|
3770
3663
|
* @returns {Promise<{propsByKey: Record<string, string[]>} | null>}
|
|
3771
3664
|
*/
|
|
3772
3665
|
async function loadKnownComponents() {
|
|
3773
|
-
const
|
|
3774
|
-
const coreSrc = coreRoot ? path.join(coreRoot, 'src') : null;
|
|
3666
|
+
const coreSrc = coreSrcPath();
|
|
3775
3667
|
if (!coreSrc || !fs.existsSync(coreSrc)) return null;
|
|
3776
3668
|
|
|
3777
|
-
const propsByKey = targetsByKey(await
|
|
3669
|
+
const propsByKey = targetsByKey(await coreThemeTargets(coreSrc));
|
|
3778
3670
|
return Object.keys(propsByKey).length > 0 ? {propsByKey} : null;
|
|
3779
3671
|
}
|
|
3780
3672
|
|
|
@@ -4170,6 +4062,10 @@ async function themeBuildInternal(
|
|
|
4170
4062
|
options = {...options, out: options.out.replace(/\\/g, '/')};
|
|
4171
4063
|
const filePath = path.resolve(cwd, file);
|
|
4172
4064
|
|
|
4065
|
+
// Core's facts first, before the build reads the theme: kept facts then do
|
|
4066
|
+
// not depend on it, and a build after an edit to the theme reads them back.
|
|
4067
|
+
await keepCoreThemeFacts(coreSrcPath());
|
|
4068
|
+
|
|
4173
4069
|
{
|
|
4174
4070
|
const problem = buildInputProblem(file, options, cwd);
|
|
4175
4071
|
if (problem) throw problem;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
/** @file `astryx theme remove` — stop importing one app theme. */
|
|
4
4
|
|
|
5
5
|
import {removeThemeFromApp} from '../_adapter.mjs';
|
|
6
|
+
import {withAppProvider} from '../_app-provider.mjs';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Remove one added theme and regenerate the app module, or remove the module
|
|
@@ -12,5 +13,7 @@ import {removeThemeFromApp} from '../_adapter.mjs';
|
|
|
12
13
|
* @returns {Promise<import('../theme.type.mjs').ThemeAppResponse>}
|
|
13
14
|
*/
|
|
14
15
|
export function themeRemove(slug, options = {}) {
|
|
15
|
-
return removeThemeFromApp(slug, options)
|
|
16
|
+
return removeThemeFromApp(slug, options).then(result =>
|
|
17
|
+
withAppProvider(result, options.cwd ?? process.cwd()),
|
|
18
|
+
);
|
|
16
19
|
}
|