@astryxdesign/cli 0.7.15 → 0.7.16-canary.g22213fd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/api/build/_adapter.d.mts +10 -0
- package/api/build/_adapter.mjs +24 -0
- package/api/build/blocks/blocks.d.mts +1 -0
- package/api/build/blocks/blocks.mjs +18 -1
- package/api/build/kit/shell.weights.json +1 -0
- package/api/build/kit/shellcall.d.mts +26 -0
- package/api/build/kit/shellcall.mjs +87 -0
- package/api/build/kit/start.mjs +67 -4
- package/api/build/kit/weights.d.mts +15 -0
- package/api/build/kit/weights.mjs +27 -0
- package/api/component/__fixtures__/resolutions/modules.txt +1 -1
- package/api/component/_adapter.d.mts +1 -1
- package/api/component/_adapter.mjs +28 -1
- package/api/doctor/_adapter.d.mts +38 -2
- package/api/doctor/_adapter.mjs +76 -1
- package/api/doctor/built-checks.mjs +1 -1
- package/api/doctor/doctor.d.mts +26 -0
- package/api/doctor/doctor.doc.mjs +1 -1
- package/api/doctor/doctor.mjs +156 -11
- package/api/doctor/theme-checks.mjs +163 -18
- package/api/icon/_adapter.d.mts +7 -3
- package/api/icon/_adapter.mjs +12 -3
- package/api/icon/icon.type.d.mts +15 -0
- package/api/icon/icon.type.mjs +10 -3
- package/api/icon/iconUse.doc.mjs +19 -5
- package/api/icon/list/list.mjs +7 -1
- package/api/icon/use/use.d.mts +8 -5
- package/api/icon/use/use.mjs +95 -13
- package/api/init/run/run.mjs +1 -0
- package/api/integration/add-contribution.mjs +3 -3
- package/api/integration/pack-check.mjs +14 -8
- package/api/integration/validate-integration.mjs +1 -1
- package/api/search/_adapter.mjs +15 -16
- package/api/search/_entries.d.mts +2 -1
- package/api/search/_entries.mjs +28 -1
- package/api/swizzle/_moduleGraph.mjs +1 -1
- package/api/template/template.type.d.mts +6 -2
- package/api/template/template.type.mjs +2 -1
- package/api/theme/_adapter.d.mts +5 -2
- package/api/theme/_adapter.mjs +59 -14
- package/api/theme/_fork.mjs +1 -1
- package/api/theme/build/build.d.mts +120 -32
- package/api/theme/build/build.mjs +471 -111
- package/api/theme/eject/eject.mjs +22 -1
- package/api/theme/generateTonalPalette.doc.mjs +2 -2
- package/api/theme/palette/generate/generator.mjs +141 -2
- package/api/theme/template/template.d.mts +19 -0
- package/api/theme/template/template.mjs +102 -25
- package/api/theme/theme.type.d.mts +44 -1
- package/api/theme/theme.type.mjs +23 -1
- package/api/theme/themeBuild.doc.mjs +4 -4
- package/api/theme/themeEject.doc.mjs +1 -1
- package/api/theme/themePaletteGenerate.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +9 -3
- package/api/theme-edit/_adapter.d.mts +33 -2
- package/api/theme-edit/_adapter.mjs +276 -41
- package/api/theme-edit/_check.d.mts +93 -4
- package/api/theme-edit/_check.mjs +1712 -223
- package/api/theme-edit/_color.d.mts +2 -8
- package/api/theme-edit/_color.mjs +292 -219
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +20 -1
- package/api/theme-edit/_context.d.mts +31 -1
- package/api/theme-edit/_context.mjs +445 -41
- package/api/theme-edit/_css.d.mts +60 -1
- package/api/theme-edit/_css.mjs +404 -28
- package/api/theme-edit/_edit.d.mts +25 -0
- package/api/theme-edit/_edit.mjs +1620 -154
- package/api/theme-edit/_how-commands.d.mts +11 -26
- package/api/theme-edit/_how-commands.mjs +30 -2
- package/api/theme-edit/_how-question.d.mts +15 -0
- package/api/theme-edit/_how-question.mjs +1469 -194
- package/api/theme-edit/_how.mjs +144 -30
- package/api/theme-edit/_marks.d.mts +13 -0
- package/api/theme-edit/_marks.mjs +15 -0
- package/api/theme-edit/_overview.mjs +2 -0
- package/api/theme-edit/_palette.d.mts +38 -0
- package/api/theme-edit/_palette.mjs +306 -73
- package/api/theme-edit/_parts.d.mts +33 -0
- package/api/theme-edit/_parts.mjs +138 -9
- package/api/theme-edit/_png.d.mts +18 -0
- package/api/theme-edit/_png.mjs +95 -14
- package/api/theme-edit/_preview-app.d.mts +55 -1
- package/api/theme-edit/_preview-app.mjs +1552 -101
- package/api/theme-edit/_preview.d.mts +71 -3
- package/api/theme-edit/_preview.mjs +565 -35
- package/api/theme-edit/_project.d.mts +15 -0
- package/api/theme-edit/_project.mjs +68 -13
- package/api/theme-edit/_settings.d.mts +299 -5
- package/api/theme-edit/_settings.mjs +2806 -158
- package/api/theme-edit/_tables.d.mts +24 -0
- package/api/theme-edit/_tables.mjs +212 -150
- package/api/theme-edit/_vet.d.mts +42 -0
- package/api/theme-edit/_vet.mjs +144 -0
- package/api/theme-edit/theme-edit.type.d.mts +31 -2
- package/api/theme-edit/theme-edit.type.mjs +10 -2
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/api/theme-edit/themeEditShow.doc.mjs +11 -3
- package/api/upgrade/registry/registry.mjs +6 -1
- package/assets/codemods/parse.mjs +2 -2
- package/assets/docs/author-a-theme.doc.mjs +1 -1
- package/assets/docs/theme.doc.dense.mjs +1 -1
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/theme.doc.zh.mjs +4 -3
- package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/icon-sets.doc.mjs +63 -8
- package/assets/docs/tree/single-component.doc.mjs +11 -2
- package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
- package/assets/docs.generated.json +2 -2
- package/assets/preview-app/next.config.mjs +7 -1
- package/assets/preview-app/package.json +1 -0
- package/assets/preview-app/src/app/globals.css +1 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.doc.mjs +21 -0
- package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.tsx +62 -0
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/page.tsx +20 -2
- package/assets/templates/pages/dashboard/page.tsx +1 -1
- package/assets/templates/themes/neutral/neutralPalettes.generated.receipt.json +2 -0
- package/authoring/config/config.doc.mjs +8 -0
- package/authoring/config/parse.d.mts +1 -0
- package/authoring/config/parse.mjs +12 -0
- package/authoring/config/type.ts +8 -0
- package/authoring/doctypes/_schema.d.mts +52 -5
- package/authoring/doctypes/_schema.mjs +62 -7
- package/authoring/doctypes/base/type.ts +10 -0
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/function/function.doc.mjs +6 -0
- package/authoring/doctypes/function/type.ts +3 -0
- package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +3 -3
- package/authoring/doctypes/legacy.mjs +5 -1
- package/authoring/index.d.ts +1 -0
- package/authoring/shadcn/source-variants.d.mts +1 -1
- package/authoring/shadcn/source-variants.mjs +32 -10
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/doctor.doc.mjs +2 -2
- package/clients/cli/commands/experimental/icon.mjs +61 -6
- package/clients/cli/commands/experimental/theme.mjs +244 -45
- package/clients/cli/commands/experimental-icon-use.doc.mjs +12 -5
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +3 -1
- package/clients/cli/commands/theme.doc.mjs +7 -2
- package/clients/cli/commands/theme.mjs +222 -55
- package/clients/cli/commands.generated.json +1 -1
- package/clients/cli/formatters/index.mjs +7 -4
- package/clients/cli/index.mjs +25 -5
- package/clients/cli/lib/cli-error.mjs +9 -3
- package/clients/cli/lib/component-format.mjs +27 -9
- package/clients/cli/lib/json-shim.mjs +72 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/clients/cli/run.mjs +49 -0
- package/foundation/agent-docs/agent-docs-target.d.mts +2 -6
- package/foundation/agent-docs/agent-docs-target.mjs +9 -17
- package/foundation/agent-docs/agent-docs.mjs +4 -3
- package/foundation/config/config-writer.d.mts +23 -0
- package/foundation/config/config-writer.mjs +152 -58
- package/foundation/config/project.mjs +103 -16
- package/foundation/discovery/component-discovery.mjs +11 -22
- package/foundation/discovery/icon-set-checks.mjs +164 -48
- package/foundation/discovery/icon-set-discovery.d.mts +38 -5
- package/foundation/discovery/icon-set-discovery.mjs +50 -6
- package/foundation/discovery/icon-set-theme-maps.d.mts +59 -0
- package/foundation/discovery/icon-set-theme-maps.mjs +95 -0
- package/foundation/discovery/icon-set-writer.d.mts +2 -3
- package/foundation/discovery/icon-set-writer.mjs +58 -17
- package/foundation/discovery/module-exports.mjs +1 -15
- package/foundation/discovery/template-adapter.mjs +44 -19
- package/foundation/discovery/template-icons.d.mts +27 -10
- package/foundation/discovery/template-icons.mjs +142 -26
- package/foundation/discovery/template-source-tree.mjs +3 -16
- package/foundation/discovery/theme-discovery.d.mts +30 -1
- package/foundation/discovery/theme-discovery.mjs +109 -50
- package/foundation/fs/exact-codec.d.mts +35 -0
- package/foundation/fs/exact-codec.mjs +148 -0
- package/foundation/fs/gather-cache.d.mts +15 -5
- package/foundation/fs/gather-cache.mjs +129 -31
- package/foundation/fs/paths.d.mts +39 -0
- package/foundation/fs/paths.mjs +44 -11
- package/foundation/fs/read-record.mjs +11 -1
- package/foundation/integrations/autolink.d.mts +4 -2
- package/foundation/integrations/autolink.mjs +4 -2
- package/foundation/integrations/cli-requirement.d.mts +16 -5
- package/foundation/integrations/cli-requirement.mjs +27 -6
- package/foundation/integrations/contribution-fixes.mjs +1 -16
- package/foundation/integrations/may-have-integrations.mjs +7 -3
- package/foundation/integrations/missing-dependency.d.mts +9 -0
- package/foundation/integrations/missing-dependency.mjs +100 -0
- package/foundation/integrations/public-imports.mjs +1 -1
- package/foundation/render/embedded-imports.mjs +1 -1
- package/foundation/render/host-exit.d.mts +8 -0
- package/foundation/render/host-exit.mjs +11 -0
- package/foundation/render/page-host.mjs +56 -10
- package/foundation/render/page-worker.mjs +14 -0
- package/foundation/render/render-page.mjs +37 -2
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +5 -0
- package/foundation/response/error-codes.mjs +3 -0
- package/foundation/response/json.d.mts +15 -0
- package/foundation/response/json.mjs +52 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/foundation/runtime/lazy-dependencies.d.mts +14 -0
- package/foundation/runtime/lazy-dependencies.mjs +82 -0
- package/foundation/xle/browser.d.mts +2 -2
- package/package.json +7 -6
|
@@ -32,7 +32,12 @@
|
|
|
32
32
|
* would collide with another binding in the file; a mapped default import
|
|
33
33
|
* becomes the set's named import aliased to its local name. An icon from an
|
|
34
34
|
* installed set that draws a variant (such as solid) maps to the target's
|
|
35
|
-
* variant of that name, else its default.
|
|
35
|
+
* variant of that name, else its default. When the project names a variant
|
|
36
|
+
* (`experimental.iconVariant`), every mapped icon asks for that look
|
|
37
|
+
* instead; an icon from the library the main set wraps maps to the main
|
|
38
|
+
* set's icon, and an icon from a set in the list in another look moves to
|
|
39
|
+
* that icon's export for the variant, so each draws the project's look
|
|
40
|
+
* where its set has it. With a project icon set, every
|
|
36
41
|
* declared key ends up mapped, a placeholder, or kept (FR10): an icon that
|
|
37
42
|
* draws no Astryx definition and has no match keeps its original import, and
|
|
38
43
|
* a key bound only by a namespace import, a type-only import, a re-export, an
|
|
@@ -53,8 +58,9 @@ import {
|
|
|
53
58
|
walk,
|
|
54
59
|
writtenNames,
|
|
55
60
|
} from './template-source-tree.mjs';
|
|
56
|
-
import {definitionsByIcon} from './icon-set-discovery.mjs';
|
|
61
|
+
import {definitionsByIcon, iconUseCommand} from './icon-set-discovery.mjs';
|
|
57
62
|
import {astryxDefinitionsByName} from './icon-definition-discovery.mjs';
|
|
63
|
+
import {generatedOrigins} from './icon-set-writer.mjs';
|
|
58
64
|
|
|
59
65
|
/** @typedef {import('./icon-set-discovery.mjs').DiscoveredIconSet} DiscoveredIconSet */
|
|
60
66
|
/** @typedef {import('./icon-set-discovery.mjs').IconSetChoice} IconSetChoice */
|
|
@@ -81,13 +87,16 @@ import {astryxDefinitionsByName} from './icon-definition-discovery.mjs';
|
|
|
81
87
|
* @property {string[]} [dropped] the library's sizing props (`size`,
|
|
82
88
|
* `strokeWidth`, `absoluteStrokeWidth`) removed from its elements: an icon
|
|
83
89
|
* set's icons take their size from CSS
|
|
84
|
-
* @property {'match' | 'definition'} by `match`: a reviewed
|
|
90
|
+
* @property {'match' | 'definition' | 'variant'} by `match`: a reviewed
|
|
85
91
|
* `exact` or `strong` match in the project set's data names the source
|
|
86
92
|
* icon; `definition`: the target's `map` names it for the Astryx icon
|
|
87
|
-
* definition the source draws
|
|
93
|
+
* definition the source draws; `variant`: the source is already this icon
|
|
94
|
+
* of a set in the project's list, in another look, and moves to the look
|
|
95
|
+
* the project names
|
|
88
96
|
* @property {{asked: string, used: string | null}} [variant] present when the
|
|
89
|
-
*
|
|
90
|
-
*
|
|
97
|
+
* look asked for, the project's variant or else the look the source draws,
|
|
98
|
+
* is one the target set's icon does not have: that look, and the look used
|
|
99
|
+
* (the set's default look)
|
|
91
100
|
*/
|
|
92
101
|
|
|
93
102
|
/**
|
|
@@ -135,6 +144,8 @@ import {astryxDefinitionsByName} from './icon-definition-discovery.mjs';
|
|
|
135
144
|
* @property {string[]} [order] the main set and each backup, as
|
|
136
145
|
* `<package>/<set>`, in the order icons are looked up; present when the
|
|
137
146
|
* project lists backups
|
|
147
|
+
* @property {string} [variant] the look the project's icons draw, as
|
|
148
|
+
* `experimental.iconVariant` names it; present when it is set
|
|
138
149
|
* @property {string} reason
|
|
139
150
|
* @property {MappedIcon[]} mapped
|
|
140
151
|
* @property {PlaceholderIcon[]} placeholder
|
|
@@ -316,15 +327,19 @@ function specifierText(entry) {
|
|
|
316
327
|
}
|
|
317
328
|
|
|
318
329
|
/**
|
|
319
|
-
* The commands that give a placeholder icon a real one.
|
|
330
|
+
* The commands that give a placeholder icon a real one. The `use` command
|
|
331
|
+
* keeps the list's backups and the project's look, and adds a backup after
|
|
332
|
+
* them.
|
|
320
333
|
* @param {string[]} definitions
|
|
321
334
|
* @param {string} main the main set's name as the list writes it
|
|
335
|
+
* @param {readonly string[]} [backups] the list's backups as it writes them
|
|
336
|
+
* @param {string | null} [variant] the project's look
|
|
322
337
|
* @returns {string[]}
|
|
323
338
|
*/
|
|
324
|
-
export function placeholderFixes(definitions, main) {
|
|
339
|
+
export function placeholderFixes(definitions, main, backups = [], variant) {
|
|
325
340
|
return [
|
|
326
341
|
`astryx experimental icon map ${definitions[0] ?? '<definition>'} <icon> --set ${main}`,
|
|
327
|
-
|
|
342
|
+
iconUseCommand(main, [...backups, '<set>'], variant),
|
|
328
343
|
];
|
|
329
344
|
}
|
|
330
345
|
|
|
@@ -435,8 +450,9 @@ export function matchIcon(source, target) {
|
|
|
435
450
|
}
|
|
436
451
|
|
|
437
452
|
/**
|
|
438
|
-
* The export a mapped icon uses: the target's variant of the
|
|
439
|
-
* variant
|
|
453
|
+
* The export a mapped icon uses: the target's variant of the name asked for
|
|
454
|
+
* (the project's variant, else the source's) when it has one, else the
|
|
455
|
+
* default.
|
|
440
456
|
* @param {IconSetIcon} icon
|
|
441
457
|
* @param {DiscoveredIconSet} set
|
|
442
458
|
* @param {string | undefined} variant
|
|
@@ -453,9 +469,10 @@ function targetExport(icon, set, variant) {
|
|
|
453
469
|
}
|
|
454
470
|
|
|
455
471
|
/**
|
|
456
|
-
* The look a mapped icon draws when the
|
|
457
|
-
*
|
|
458
|
-
*
|
|
472
|
+
* The look a mapped icon draws when the look asked for (the project's
|
|
473
|
+
* variant, else the source's) is one the target's icon does not have: what
|
|
474
|
+
* was asked for and the target's default look. Undefined when the look is
|
|
475
|
+
* kept, or when no look is asked for.
|
|
459
476
|
* @param {IconSetIcon} icon
|
|
460
477
|
* @param {DiscoveredIconSet} set
|
|
461
478
|
* @param {string | undefined} variant
|
|
@@ -471,6 +488,53 @@ function lookChange(icon, set, variant) {
|
|
|
471
488
|
return {asked: variant, used: fallback};
|
|
472
489
|
}
|
|
473
490
|
|
|
491
|
+
/**
|
|
492
|
+
* Whether an icon draws a look: its own export draws the set's default
|
|
493
|
+
* variant, and each of its `variants` one more.
|
|
494
|
+
* @param {IconSetIcon} icon
|
|
495
|
+
* @param {DiscoveredIconSet} set
|
|
496
|
+
* @param {string} variant
|
|
497
|
+
*/
|
|
498
|
+
function hasLook(icon, set, variant) {
|
|
499
|
+
return (
|
|
500
|
+
variant === set.data.default?.variant ||
|
|
501
|
+
(icon.variants ?? []).some(each => each.variant === variant)
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* The icon of a set whose export re-exports a library export, read from the
|
|
507
|
+
* set's generated module: the same artwork, in one of the set's looks.
|
|
508
|
+
* @param {DiscoveredIconSet} set
|
|
509
|
+
* @param {string} module the library module the template imports from
|
|
510
|
+
* @param {string} imported the export it imports
|
|
511
|
+
* @param {Map<DiscoveredIconSet, Map<string, string>>} read each set's
|
|
512
|
+
* exports by the library export they re-export, read once per mapping
|
|
513
|
+
* @returns {IconSetIcon | undefined}
|
|
514
|
+
*/
|
|
515
|
+
function wrappedIcon(set, module, imported, read) {
|
|
516
|
+
let byOrigin = read.get(set);
|
|
517
|
+
if (!byOrigin) {
|
|
518
|
+
byOrigin = new Map();
|
|
519
|
+
if (set.packageDir && set.data.generated) {
|
|
520
|
+
const origins = generatedOrigins(set.packageDir, set.data.generated);
|
|
521
|
+
for (const [exported, origin] of origins) {
|
|
522
|
+
if (!origin.adapt) {
|
|
523
|
+
byOrigin.set(`${origin.module}\0${origin.source}`, exported);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
read.set(set, byOrigin);
|
|
528
|
+
}
|
|
529
|
+
const exported = byOrigin.get(`${module}\0${imported}`);
|
|
530
|
+
if (!exported) return undefined;
|
|
531
|
+
return set.data.icons.find(
|
|
532
|
+
icon =>
|
|
533
|
+
icon.export === exported ||
|
|
534
|
+
(icon.variants ?? []).some(each => each.export === exported),
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
|
|
474
538
|
/**
|
|
475
539
|
* Whether a module is one of Astryx's own packages (`@astryxdesign/core`,
|
|
476
540
|
* its subpaths, and every other `@astryxdesign/` package).
|
|
@@ -835,6 +899,7 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
835
899
|
...(targets.length > 1
|
|
836
900
|
? {order: targets.map(each => `${each.package}/${each.name}`)}
|
|
837
901
|
: {}),
|
|
902
|
+
...(choice.variant ? {variant: choice.variant} : {}),
|
|
838
903
|
reason: choice.reason,
|
|
839
904
|
mapped: [],
|
|
840
905
|
placeholder: [],
|
|
@@ -843,6 +908,13 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
843
908
|
};
|
|
844
909
|
if (!target) return {source, icons};
|
|
845
910
|
const main = choice.configured ?? target.name;
|
|
911
|
+
/** The look every icon draws, when the project names one. */
|
|
912
|
+
const lookVariant = choice.variant;
|
|
913
|
+
const listedBackups = (choice.backups ?? []).map(each => each.selector);
|
|
914
|
+
/** @type {Map<DiscoveredIconSet, Map<string, string>>} */
|
|
915
|
+
const wrappedRead = new Map();
|
|
916
|
+
/** @param {SourceIcon} record the look a mapped icon asks for */
|
|
917
|
+
const askedLook = record => lookVariant ?? record.variant;
|
|
846
918
|
|
|
847
919
|
/** @type {any} */
|
|
848
920
|
let ast;
|
|
@@ -885,7 +957,7 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
885
957
|
/**
|
|
886
958
|
* The source record of each mapped import specifier, the first set in the
|
|
887
959
|
* list that matches it, and the match.
|
|
888
|
-
* @type {Map<any, {record: SourceIcon, set: DiscoveredIconSet, match:
|
|
960
|
+
* @type {Map<any, {record: SourceIcon, set: DiscoveredIconSet, match: {icon: IconSetIcon, by: 'match' | 'definition' | 'variant'} | null}>}
|
|
889
961
|
*/
|
|
890
962
|
const planned = new Map();
|
|
891
963
|
/**
|
|
@@ -894,11 +966,41 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
894
966
|
* @type {Map<any, DiscoveredIconSet>}
|
|
895
967
|
*/
|
|
896
968
|
const wrapped = new Map();
|
|
969
|
+
/**
|
|
970
|
+
* Plan each icon a template imports from a set in the list in another look
|
|
971
|
+
* than the project's variant: it moves to that icon's export for the
|
|
972
|
+
* variant, when the icon has one, and otherwise keeps its import.
|
|
973
|
+
* @param {any} node an import declaration from a set in the list
|
|
974
|
+
* @param {string} module
|
|
975
|
+
*/
|
|
976
|
+
const planLookMoves = (node, module) => {
|
|
977
|
+
for (const specifier of node.specifiers) {
|
|
978
|
+
if (
|
|
979
|
+
specifier.type === 'ImportNamespaceSpecifier' ||
|
|
980
|
+
specifier.importKind === 'type'
|
|
981
|
+
) {
|
|
982
|
+
continue;
|
|
983
|
+
}
|
|
984
|
+
const record = index.get(`${module}\0${importedName(specifier)}`);
|
|
985
|
+
const set = record?.set;
|
|
986
|
+
if (!record || !set || !targets.includes(set)) continue;
|
|
987
|
+
if (record.variant === lookVariant) continue;
|
|
988
|
+
const icon = set.data.icons.find(each => each.id === record.id);
|
|
989
|
+
if (!icon || !hasLook(icon, set, /** @type {string} */ (lookVariant))) {
|
|
990
|
+
continue;
|
|
991
|
+
}
|
|
992
|
+
planned.set(specifier, {record, set, match: {icon, by: 'variant'}});
|
|
993
|
+
freed.add(specifier.local.name);
|
|
994
|
+
}
|
|
995
|
+
};
|
|
897
996
|
for (const node of ast.program.body) {
|
|
898
997
|
if (node.type !== 'ImportDeclaration' || node.importKind === 'type')
|
|
899
998
|
continue;
|
|
900
999
|
const module = node.source.value;
|
|
901
|
-
if (targetModules.has(module))
|
|
1000
|
+
if (targetModules.has(module)) {
|
|
1001
|
+
if (lookVariant) planLookMoves(node, module);
|
|
1002
|
+
continue;
|
|
1003
|
+
}
|
|
902
1004
|
for (const specifier of node.specifiers) {
|
|
903
1005
|
if (
|
|
904
1006
|
specifier.type === 'ImportNamespaceSpecifier' ||
|
|
@@ -937,21 +1039,31 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
937
1039
|
if (!record || (record.set && targets.includes(record.set))) continue;
|
|
938
1040
|
// An import from the library a listed set wraps is already an icon
|
|
939
1041
|
// the project chose. The main set's own library keeps its icons as
|
|
940
|
-
// written; another set's library keeps an icon that no set maps.
|
|
1042
|
+
// written; another set's library keeps an icon that no set maps. With
|
|
1043
|
+
// a project variant, an icon from the main set's library maps to the
|
|
1044
|
+
// main set's icon, so it draws that look: the icon its `map` names, or
|
|
1045
|
+
// else the icon that re-exports the same library export when that icon
|
|
1046
|
+
// draws the look. Otherwise it keeps its import.
|
|
941
1047
|
const wrapper = targets.find(each => wrapsModule(each, module));
|
|
942
|
-
if (wrapper === target) {
|
|
1048
|
+
if (wrapper === target && !lookVariant) {
|
|
943
1049
|
wrapped.set(specifier, wrapper);
|
|
944
1050
|
continue;
|
|
945
1051
|
}
|
|
946
|
-
/** @type {{set: DiscoveredIconSet, match:
|
|
1052
|
+
/** @type {{set: DiscoveredIconSet, match: {icon: IconSetIcon, by: 'match' | 'definition' | 'variant'} | null}} */
|
|
947
1053
|
let found = {set: target, match: null};
|
|
948
|
-
for (const each of targets) {
|
|
1054
|
+
for (const each of wrapper === target ? [target] : targets) {
|
|
949
1055
|
const match = matchIcon(record, each);
|
|
950
1056
|
if (match) {
|
|
951
1057
|
found = {set: each, match};
|
|
952
1058
|
break;
|
|
953
1059
|
}
|
|
954
1060
|
}
|
|
1061
|
+
if (!found.match && wrapper === target && lookVariant) {
|
|
1062
|
+
const icon = wrappedIcon(target, module, record.export, wrappedRead);
|
|
1063
|
+
if (icon && hasLook(icon, target, lookVariant)) {
|
|
1064
|
+
found = {set: target, match: {icon, by: 'variant'}};
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
955
1067
|
if (!found.match && wrapper) {
|
|
956
1068
|
wrapped.set(specifier, wrapper);
|
|
957
1069
|
continue;
|
|
@@ -975,7 +1087,6 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
975
1087
|
if (node.type !== 'ImportDeclaration') continue;
|
|
976
1088
|
if (node.importKind === 'type') continue;
|
|
977
1089
|
const module = node.source.value;
|
|
978
|
-
if (targetModules.has(module)) continue;
|
|
979
1090
|
if (!node.specifiers.some((/** @type {any} */ each) => planned.has(each))) {
|
|
980
1091
|
continue;
|
|
981
1092
|
}
|
|
@@ -1012,13 +1123,18 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
1012
1123
|
source: {module, export: imported},
|
|
1013
1124
|
target: {local: placeholderName},
|
|
1014
1125
|
definitions: record.definitions,
|
|
1015
|
-
fixes: placeholderFixes(
|
|
1126
|
+
fixes: placeholderFixes(
|
|
1127
|
+
record.definitions,
|
|
1128
|
+
main,
|
|
1129
|
+
listedBackups,
|
|
1130
|
+
lookVariant,
|
|
1131
|
+
),
|
|
1016
1132
|
...(likely
|
|
1017
1133
|
? {
|
|
1018
1134
|
suggestion: {
|
|
1019
1135
|
set: target.name,
|
|
1020
1136
|
id: likely.id,
|
|
1021
|
-
...targetExport(likely, target, record
|
|
1137
|
+
...targetExport(likely, target, askedLook(record)),
|
|
1022
1138
|
confidence: /** @type {const} */ ('likely'),
|
|
1023
1139
|
},
|
|
1024
1140
|
}
|
|
@@ -1043,7 +1159,7 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
1043
1159
|
suggestion: {
|
|
1044
1160
|
set: target.name,
|
|
1045
1161
|
id: likely.id,
|
|
1046
|
-
...targetExport(likely, target, record
|
|
1162
|
+
...targetExport(likely, target, askedLook(record)),
|
|
1047
1163
|
confidence: /** @type {const} */ ('likely'),
|
|
1048
1164
|
},
|
|
1049
1165
|
}
|
|
@@ -1051,8 +1167,8 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
1051
1167
|
});
|
|
1052
1168
|
continue;
|
|
1053
1169
|
}
|
|
1054
|
-
const chosen = targetExport(match.icon, set, record
|
|
1055
|
-
const look = lookChange(match.icon, set, record
|
|
1170
|
+
const chosen = targetExport(match.icon, set, askedLook(record));
|
|
1171
|
+
const look = lookChange(match.icon, set, askedLook(record));
|
|
1056
1172
|
const key = `${chosen.module}\0${chosen.export}`;
|
|
1057
1173
|
let entry = added.get(key);
|
|
1058
1174
|
if (!entry) {
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
* the demo-content replacement in template-adapter, and by template-needs
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {createRequire} from 'node:module';
|
|
15
14
|
import * as path from 'node:path';
|
|
16
15
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
16
|
+
import {babelCore, babelParser} from '../runtime/lazy-dependencies.mjs';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Where what parsing returns for each template Astryx ships is stored at
|
|
@@ -28,13 +28,6 @@ export const TEMPLATE_COMPONENTS_FILE = path.join(
|
|
|
28
28
|
'components.generated.json',
|
|
29
29
|
);
|
|
30
30
|
|
|
31
|
-
const require = createRequire(import.meta.url);
|
|
32
|
-
|
|
33
|
-
/** @type {typeof import('@babel/parser') | undefined} */
|
|
34
|
-
let babelParser;
|
|
35
|
-
/** @type {typeof import('@babel/core') | undefined} */
|
|
36
|
-
let babelCore;
|
|
37
|
-
|
|
38
31
|
/**
|
|
39
32
|
* Parse template source as TSX. Babel loads on first use, so a command that
|
|
40
33
|
* only lists templates never pays for it.
|
|
@@ -44,10 +37,7 @@ let babelCore;
|
|
|
44
37
|
* @returns {any} The file node.
|
|
45
38
|
*/
|
|
46
39
|
export function parseTemplateSource(source, {errorRecovery = false} = {}) {
|
|
47
|
-
babelParser
|
|
48
|
-
require('@babel/parser')
|
|
49
|
-
);
|
|
50
|
-
return babelParser.parse(source, {
|
|
40
|
+
return babelParser().parse(source, {
|
|
51
41
|
sourceType: 'module',
|
|
52
42
|
plugins: ['jsx', 'typescript'],
|
|
53
43
|
errorRecovery,
|
|
@@ -79,10 +69,7 @@ export function programPath(file) {
|
|
|
79
69
|
* @param {import('@babel/core').Visitor} visitor
|
|
80
70
|
*/
|
|
81
71
|
export function traverseTemplateSource(file, visitor) {
|
|
82
|
-
babelCore
|
|
83
|
-
require('@babel/core')
|
|
84
|
-
);
|
|
85
|
-
babelCore.traverse(file, visitor);
|
|
72
|
+
babelCore().traverse(file, visitor);
|
|
86
73
|
}
|
|
87
74
|
|
|
88
75
|
/**
|
|
@@ -30,9 +30,13 @@ export function themeImportPackage(theme: DiscoveredTheme): string;
|
|
|
30
30
|
/**
|
|
31
31
|
* Every module a theme source file imports or re-exports, as written.
|
|
32
32
|
* @param {string} file
|
|
33
|
+
* @param {{withRequire?: boolean}} [options] `withRequire`: also
|
|
34
|
+
* `require('./x')` and TypeScript `import x = require('./x')`.
|
|
33
35
|
* @returns {string[]}
|
|
34
36
|
*/
|
|
35
|
-
export function themeFileImports(file: string
|
|
37
|
+
export function themeFileImports(file: string, options?: {
|
|
38
|
+
withRequire?: boolean;
|
|
39
|
+
}): string[];
|
|
36
40
|
/**
|
|
37
41
|
* How messages about a theme descriptor name it.
|
|
38
42
|
* @param {string} docPath
|
|
@@ -63,6 +67,25 @@ export function readThemeDescriptorValue(docPath: string, label: string): Record
|
|
|
63
67
|
export function readStaticDescriptorValue(docPath: string, label: string, typeName: string, { data }?: {
|
|
64
68
|
data?: boolean;
|
|
65
69
|
}): Record<string, any>;
|
|
70
|
+
/**
|
|
71
|
+
* Where a descriptor's statically read value is stored at publish: by the
|
|
72
|
+
* hash of its text, the type it is read as, and whether plain data counts.
|
|
73
|
+
* @param {string} source
|
|
74
|
+
* @param {string} typeName
|
|
75
|
+
* @param {boolean} data
|
|
76
|
+
* @returns {string}
|
|
77
|
+
*/
|
|
78
|
+
export function descriptorStoreKey(source: string, typeName: string, data: boolean): string;
|
|
79
|
+
/**
|
|
80
|
+
* The static value a descriptor's source default-exports (see
|
|
81
|
+
* {@link readStaticDescriptorValue}); throws when it is not one.
|
|
82
|
+
* @param {string} source
|
|
83
|
+
* @param {string} label
|
|
84
|
+
* @param {string} typeName
|
|
85
|
+
* @param {boolean} [data]
|
|
86
|
+
* @returns {Record<string, any>}
|
|
87
|
+
*/
|
|
88
|
+
export function readDescriptorSource(source: string, label: string, typeName: string, data?: boolean): Record<string, any>;
|
|
66
89
|
/**
|
|
67
90
|
* Whether an entry at any depth of a themes root is outside every theme: a dot
|
|
68
91
|
* entry, or a name npm never publishes (npm-packlist's defaults).
|
|
@@ -150,6 +173,12 @@ export const THEME_DOC_SUFFIX: ".doc.mjs";
|
|
|
150
173
|
export { THEME_MODULE_EXTENSIONS };
|
|
151
174
|
/** A theme directory's name: lower-kebab, starting with a letter. */
|
|
152
175
|
export const THEME_SLUG_RE: RegExp;
|
|
176
|
+
/**
|
|
177
|
+
* The typed descriptors read statically, each with whether plain data is
|
|
178
|
+
* accepted: what scripts/generate-stored-docs.mjs reads at publish.
|
|
179
|
+
* @type {ReadonlyArray<[string, boolean]>}
|
|
180
|
+
*/
|
|
181
|
+
export const STATIC_DESCRIPTOR_TYPES: ReadonlyArray<[string, boolean]>;
|
|
153
182
|
export type DiscoveredTheme = {
|
|
154
183
|
slug: string;
|
|
155
184
|
displayName: string;
|
|
@@ -17,47 +17,28 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import * as fs from 'node:fs';
|
|
20
|
-
import {createRequire} from 'node:module';
|
|
21
20
|
import * as path from 'node:path';
|
|
22
21
|
import {lowerDoc} from '../doc-compiler/compile.mjs';
|
|
23
22
|
import {packageSource} from '../doc-compiler/source.mjs';
|
|
24
|
-
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
23
|
+
import {CLI_ROOT, realDir} from '../fs/paths.mjs';
|
|
24
|
+
import {persistedGather} from '../fs/gather-cache.mjs';
|
|
25
|
+
import {EXACT_CODEC} from '../fs/exact-codec.mjs';
|
|
25
26
|
import {listDirEntries} from '../fs/listing-cache.mjs';
|
|
26
27
|
import {formatCliCommand} from '../env/package-manager.mjs';
|
|
27
28
|
import {LOCAL_THEME_ROOT} from '../config/theme-state.mjs';
|
|
28
29
|
import {assertWithin, PathSafetyError} from '../fs/path-safety.mjs';
|
|
29
30
|
import {THEME_MODULE_EXTENSIONS} from './theme-module-extensions.mjs';
|
|
31
|
+
import {babelParser, jscodeshift} from '../runtime/lazy-dependencies.mjs';
|
|
32
|
+
import {
|
|
33
|
+
readStore,
|
|
34
|
+
storedKey,
|
|
35
|
+
STORED_DOCS_FILE,
|
|
36
|
+
} from '../doc-compiler/stored-docs.mjs';
|
|
30
37
|
|
|
31
38
|
export const BUNDLED_THEME_PACKAGE = '@astryxdesign/cli';
|
|
32
39
|
export const THEMES_DIR = path.join(CLI_ROOT, 'assets', 'templates', 'themes');
|
|
33
40
|
export const THEME_DOC_SUFFIX = '.doc.mjs';
|
|
34
41
|
|
|
35
|
-
const require = createRequire(import.meta.url);
|
|
36
|
-
|
|
37
|
-
/** @type {typeof import('@babel/parser') | undefined} */
|
|
38
|
-
let babelParser;
|
|
39
|
-
/** @type {any} */
|
|
40
|
-
let jscodeshiftApi;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* The descriptor parser, loaded when the first descriptor is read.
|
|
44
|
-
* @returns {typeof import('@babel/parser')}
|
|
45
|
-
*/
|
|
46
|
-
function descriptorParser() {
|
|
47
|
-
babelParser ??= require('@babel/parser');
|
|
48
|
-
return /** @type {typeof import('@babel/parser')} */ (babelParser);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* The theme source parser, loaded when the first integration theme source is
|
|
53
|
-
* checked. Bundled themes never need it.
|
|
54
|
-
* @returns {any}
|
|
55
|
-
*/
|
|
56
|
-
function sourceParser() {
|
|
57
|
-
jscodeshiftApi ??= require('jscodeshift');
|
|
58
|
-
return jscodeshiftApi;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
42
|
/**
|
|
62
43
|
* @typedef {object} DiscoveredTheme
|
|
63
44
|
* @property {string} slug
|
|
@@ -169,9 +150,11 @@ class ThemeRuntimeExportError extends Error {}
|
|
|
169
150
|
* Every string specifier a module imports, re-exports, or imports dynamically.
|
|
170
151
|
* @param {string} file
|
|
171
152
|
* @param {any} jscodeshift
|
|
153
|
+
* @param {{withRequire?: boolean}} [options] `withRequire`: also
|
|
154
|
+
* `require('./x')` and TypeScript `import x = require('./x')`
|
|
172
155
|
* @returns {string[]}
|
|
173
156
|
*/
|
|
174
|
-
function moduleSpecifiers(file, jscodeshift) {
|
|
157
|
+
function moduleSpecifiers(file, jscodeshift, {withRequire = false} = {}) {
|
|
175
158
|
const parser = /\.(?:ts|tsx|mts|cts)$/u.test(file) ? 'tsx' : 'babel';
|
|
176
159
|
const j = jscodeshift.withParser(parser);
|
|
177
160
|
const root = j(fs.readFileSync(file, 'utf-8'));
|
|
@@ -207,6 +190,23 @@ function moduleSpecifiers(file, jscodeshift) {
|
|
|
207
190
|
specifiers.push(importPath.node.source.value);
|
|
208
191
|
}
|
|
209
192
|
});
|
|
193
|
+
if (withRequire) {
|
|
194
|
+
// CommonJS `require('./x')` and TypeScript `import x = require('./x')`.
|
|
195
|
+
root.find(j.CallExpression).forEach((/** @type {any} */ callPath) => {
|
|
196
|
+
const {callee, arguments: args} = callPath.node;
|
|
197
|
+
if (
|
|
198
|
+
callee?.type === 'Identifier' &&
|
|
199
|
+
callee.name === 'require' &&
|
|
200
|
+
typeof args?.[0]?.value === 'string'
|
|
201
|
+
)
|
|
202
|
+
specifiers.push(args[0].value);
|
|
203
|
+
});
|
|
204
|
+
root.find(j.TSImportEqualsDeclaration).forEach((/** @type {any} */ p) => {
|
|
205
|
+
const ref = p.node.moduleReference;
|
|
206
|
+
const value = ref?.expression?.value ?? ref?.argument?.value;
|
|
207
|
+
if (typeof value === 'string') specifiers.push(value);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
210
|
|
|
211
211
|
return specifiers;
|
|
212
212
|
}
|
|
@@ -214,10 +214,12 @@ function moduleSpecifiers(file, jscodeshift) {
|
|
|
214
214
|
/**
|
|
215
215
|
* Every module a theme source file imports or re-exports, as written.
|
|
216
216
|
* @param {string} file
|
|
217
|
+
* @param {{withRequire?: boolean}} [options] `withRequire`: also
|
|
218
|
+
* `require('./x')` and TypeScript `import x = require('./x')`.
|
|
217
219
|
* @returns {string[]}
|
|
218
220
|
*/
|
|
219
|
-
export function themeFileImports(file) {
|
|
220
|
-
return moduleSpecifiers(file,
|
|
221
|
+
export function themeFileImports(file, options = {}) {
|
|
222
|
+
return moduleSpecifiers(file, jscodeshift(), options);
|
|
221
223
|
}
|
|
222
224
|
|
|
223
225
|
/**
|
|
@@ -680,13 +682,24 @@ export function readStaticDescriptorValue(
|
|
|
680
682
|
/** @type {{value: Record<string, any>} | {error: unknown}} */
|
|
681
683
|
let read;
|
|
682
684
|
try {
|
|
685
|
+
const source = fs.readFileSync(docPath, 'utf-8');
|
|
686
|
+
// A descriptor Astryx ships was read at publish, by the hash of its
|
|
687
|
+
// text (scripts/generate-stored-docs.mjs): the same text reads the
|
|
688
|
+
// same value without parsing. Any other text, or a store that cannot
|
|
689
|
+
// be read, is parsed.
|
|
690
|
+
let stored;
|
|
691
|
+
try {
|
|
692
|
+
stored = readStore(STORED_DOCS_FILE).get(
|
|
693
|
+
descriptorStoreKey(source, typeName, data),
|
|
694
|
+
);
|
|
695
|
+
} catch {
|
|
696
|
+
stored = undefined;
|
|
697
|
+
}
|
|
683
698
|
read = {
|
|
684
|
-
value:
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
data,
|
|
689
|
-
),
|
|
699
|
+
value:
|
|
700
|
+
stored != null && typeof stored === 'object'
|
|
701
|
+
? stored
|
|
702
|
+
: readDescriptorSource(source, label, typeName, data),
|
|
690
703
|
};
|
|
691
704
|
} catch (error) {
|
|
692
705
|
read = {error};
|
|
@@ -699,17 +712,42 @@ export function readStaticDescriptorValue(
|
|
|
699
712
|
}
|
|
700
713
|
|
|
701
714
|
/**
|
|
715
|
+
* The typed descriptors read statically, each with whether plain data is
|
|
716
|
+
* accepted: what scripts/generate-stored-docs.mjs reads at publish.
|
|
717
|
+
* @type {ReadonlyArray<[string, boolean]>}
|
|
718
|
+
*/
|
|
719
|
+
export const STATIC_DESCRIPTOR_TYPES = [
|
|
720
|
+
['ThemeDoc', false],
|
|
721
|
+
['IconSetDoc', false],
|
|
722
|
+
['IconDefinitionDoc', true],
|
|
723
|
+
];
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* Where a descriptor's statically read value is stored at publish: by the
|
|
727
|
+
* hash of its text, the type it is read as, and whether plain data counts.
|
|
728
|
+
* @param {string} source
|
|
729
|
+
* @param {string} typeName
|
|
730
|
+
* @param {boolean} data
|
|
731
|
+
* @returns {string}
|
|
732
|
+
*/
|
|
733
|
+
export function descriptorStoreKey(source, typeName, data) {
|
|
734
|
+
return `descriptor:${typeName}:${data ? 'data' : 'object'}:${storedKey(source)}`;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* The static value a descriptor's source default-exports (see
|
|
739
|
+
* {@link readStaticDescriptorValue}); throws when it is not one.
|
|
702
740
|
* @param {string} source
|
|
703
741
|
* @param {string} label
|
|
704
742
|
* @param {string} typeName
|
|
705
743
|
* @param {boolean} [data]
|
|
706
744
|
* @returns {Record<string, any>}
|
|
707
745
|
*/
|
|
708
|
-
function readDescriptorSource(source, label, typeName, data = false) {
|
|
746
|
+
export function readDescriptorSource(source, label, typeName, data = false) {
|
|
709
747
|
/** @type {any} */
|
|
710
748
|
let ast;
|
|
711
749
|
try {
|
|
712
|
-
ast =
|
|
750
|
+
ast = babelParser().parse(source, {
|
|
713
751
|
sourceType: 'module',
|
|
714
752
|
tokens: true,
|
|
715
753
|
createParenthesizedExpressions: true,
|
|
@@ -1514,11 +1552,11 @@ export function discoverThemeDirectory(
|
|
|
1514
1552
|
)
|
|
1515
1553
|
.filter(file => file !== docPath),
|
|
1516
1554
|
);
|
|
1517
|
-
const
|
|
1555
|
+
const codeshift = jscodeshift();
|
|
1518
1556
|
try {
|
|
1519
1557
|
validateThemeModuleGraph(
|
|
1520
1558
|
entryPath,
|
|
1521
|
-
|
|
1559
|
+
codeshift,
|
|
1522
1560
|
sourceDir,
|
|
1523
1561
|
allowedFiles,
|
|
1524
1562
|
owner,
|
|
@@ -1529,7 +1567,7 @@ export function discoverThemeDirectory(
|
|
|
1529
1567
|
!moduleExportsName(
|
|
1530
1568
|
entryPath,
|
|
1531
1569
|
exportName,
|
|
1532
|
-
|
|
1570
|
+
codeshift,
|
|
1533
1571
|
sourceDir,
|
|
1534
1572
|
allowedFiles,
|
|
1535
1573
|
)
|
|
@@ -1660,7 +1698,7 @@ export function unreadThemeFolders(themeRoot, {packageDir, packageName} = {}) {
|
|
|
1660
1698
|
for (const file of modules) {
|
|
1661
1699
|
let specifiers;
|
|
1662
1700
|
try {
|
|
1663
|
-
specifiers = moduleSpecifiers(file,
|
|
1701
|
+
specifiers = moduleSpecifiers(file, jscodeshift());
|
|
1664
1702
|
} catch {
|
|
1665
1703
|
continue;
|
|
1666
1704
|
}
|
|
@@ -1745,18 +1783,39 @@ export function discoverLocalThemes(
|
|
|
1745
1783
|
}));
|
|
1746
1784
|
}
|
|
1747
1785
|
|
|
1786
|
+
/** An integration's discovered themes, kept exactly, with the shape they need. */
|
|
1787
|
+
const THEMES_CODEC = {
|
|
1788
|
+
...EXACT_CODEC,
|
|
1789
|
+
valid: (/** @type {any} */ themes) =>
|
|
1790
|
+
Array.isArray(themes) &&
|
|
1791
|
+
themes.every(
|
|
1792
|
+
theme =>
|
|
1793
|
+
theme != null &&
|
|
1794
|
+
typeof theme.slug === 'string' &&
|
|
1795
|
+
typeof theme.exportName === 'string',
|
|
1796
|
+
),
|
|
1797
|
+
};
|
|
1798
|
+
|
|
1748
1799
|
/**
|
|
1749
1800
|
* @param {import('../integrations/integrations.mjs').LoadedIntegration} integration
|
|
1750
1801
|
* @returns {Promise<DiscoveredTheme[]>}
|
|
1751
1802
|
*/
|
|
1752
1803
|
export async function discoverIntegrationThemes(integration) {
|
|
1753
1804
|
if (!integration.themes) return [];
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1805
|
+
const themesDir = integration.themes;
|
|
1806
|
+
// Kept between runs while every file and module it read is unchanged; the
|
|
1807
|
+
// live fields below are added after, as on a fresh read.
|
|
1808
|
+
const found = /** @type {DiscoveredTheme[]} */ (
|
|
1809
|
+
await persistedGather(
|
|
1810
|
+
['integration-themes', realDir(themesDir), integration.name ?? null],
|
|
1811
|
+
async () => discoverThemeDirectory(themesDir, integration.name),
|
|
1812
|
+
THEMES_CODEC,
|
|
1813
|
+
)
|
|
1761
1814
|
);
|
|
1815
|
+
return found.map(theme => ({
|
|
1816
|
+
...theme,
|
|
1817
|
+
packageDir: integration.__packageDir,
|
|
1818
|
+
packageExports: integration.__packageExports,
|
|
1819
|
+
source: /** @type {const} */ ('package'),
|
|
1820
|
+
}));
|
|
1762
1821
|
}
|