@astryxdesign/cli 0.7.9-canary.f9281ef → 0.7.9
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 +80 -0
- package/README.md +1 -1
- package/api/component/__fixtures__/resolutions/modules.txt +5 -5
- package/api/swizzle/copy/copy.d.mts +17 -1
- package/api/swizzle/copy/copy.mjs +240 -5
- package/api/swizzle/swizzle.doc.mjs +1 -1
- package/api/swizzle/swizzle.type.mjs +1 -1
- package/api/theme/build/build.mjs +342 -72
- package/api/theme/build/core-interception.mjs +92 -29
- package/api/theme/build/icon-imports.d.mts +35 -4
- package/api/theme/build/icon-imports.mjs +299 -38
- package/assets/discover/official-packages.json +8 -0
- package/assets/docs/author-a-theme.doc.mjs +3 -1
- package/assets/docs/icons.doc.mjs +29 -0
- package/assets/docs/motion.doc.mjs +1 -1
- package/assets/templates/blocks/components/Calendar/useCalendarDaysHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Calendar/useCalendarDaysHookUsage.tsx +71 -0
- package/assets/templates/blocks/components/Hooks/useInputContainerHookUsage.doc.mjs +15 -0
- package/assets/templates/blocks/components/Hooks/useInputContainerHookUsage.tsx +93 -0
- package/assets/templates/blocks/components/Hooks/useMergedRefsHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useMergedRefsHookUsage.tsx +78 -0
- package/assets/templates/blocks/components/Hooks/useScrollLockHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useScrollLockHookUsage.tsx +80 -0
- package/assets/templates/blocks/components/Hooks/useScrollOverflowHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useScrollOverflowHookUsage.tsx +94 -0
- package/assets/templates/blocks/components/Icon/useIconHookUsage.doc.mjs +19 -0
- package/assets/templates/blocks/components/Icon/useIconHookUsage.tsx +68 -0
- package/assets/templates/blocks/components/Link/useLinkComponentHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Link/useLinkComponentHookUsage.tsx +89 -0
- package/assets/templates/blocks/components/Overlay/useOverlayHookUsage.doc.mjs +21 -0
- package/assets/templates/blocks/components/Overlay/useOverlayHookUsage.tsx +49 -0
- package/assets/templates/blocks/components/Table/useTableSortableStateHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/useTableSortableStateHookUsage.tsx +61 -0
- package/assets/templates/blocks/components/usePanGesture/PanDraggableBox.doc.mjs +15 -0
- package/assets/templates/blocks/components/usePanGesture/PanDraggableBox.tsx +98 -0
- package/assets/templates/blocks/components/usePanGesture/PanPlayingCard.doc.mjs +14 -0
- package/assets/templates/blocks/components/usePanGesture/PanPlayingCard.tsx +147 -0
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +2 -2
- package/assets/templates/themes/neutral/neutralTheme.ts +30 -4
- package/assets/theme.template.ts +14 -2
- package/authoring/doctypes/base/type.ts +41 -0
- package/authoring/doctypes/component/component.doc.mjs +7 -1
- package/authoring/doctypes/component/type.ts +5 -0
- package/authoring/index.d.ts +2 -0
- package/clients/cli/commands/swizzle.mjs +10 -0
- package/clients/cli/lib/component-format.mjs +49 -0
- package/foundation/discovery/component-discovery.mjs +17 -6
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +9 -9
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
* SYNC: packages/cli/api/theme/build/build.mjs (importThemeModule)
|
|
68
68
|
*/
|
|
69
69
|
|
|
70
|
-
import {createRequire} from 'node:module';
|
|
70
|
+
import Module, {createRequire} from 'node:module';
|
|
71
71
|
import * as path from 'node:path';
|
|
72
72
|
|
|
73
73
|
import {findInstalledPackage} from '../../../foundation/fs/paths.mjs';
|
|
@@ -293,20 +293,24 @@ export function interceptCore(coreThemeModule, coreRootModule) {
|
|
|
293
293
|
};
|
|
294
294
|
/** @type {any} */
|
|
295
295
|
let wrappedRoot;
|
|
296
|
+
let rootRead = false;
|
|
296
297
|
// jiti reads a virtual module only when a theme imports its specifier. So
|
|
297
298
|
// the root, which loads all of Core, loads only for a theme that asks.
|
|
298
299
|
Object.defineProperty(modules, '@astryxdesign/core', {
|
|
299
300
|
enumerable: true,
|
|
300
301
|
configurable: true,
|
|
301
302
|
get() {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
303
|
+
if (!rootRead) {
|
|
304
|
+
const root =
|
|
305
|
+
typeof coreRootModule === 'function'
|
|
306
|
+
? coreRootModule()
|
|
307
|
+
: coreRootModule;
|
|
308
|
+
// Falls back to the theme namespace only when the root could not be
|
|
309
|
+
// imported at all; a partial root is better than none, and a core
|
|
310
|
+
// missing its own root entry is already broken.
|
|
311
|
+
wrappedRoot = wrapNamespace(root ?? coreThemeModule);
|
|
312
|
+
rootRead = true;
|
|
313
|
+
}
|
|
310
314
|
return wrappedRoot;
|
|
311
315
|
},
|
|
312
316
|
});
|
|
@@ -469,28 +473,19 @@ export function interceptCore(coreThemeModule, coreRootModule) {
|
|
|
469
473
|
return {covered, undo: () => {}};
|
|
470
474
|
}
|
|
471
475
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
cjs = createRequire(fromFile)(specifier);
|
|
480
|
-
} catch {
|
|
481
|
-
// A specifier that CommonJS cannot resolve cannot be used by a `.cjs`
|
|
482
|
-
// source dependency either, so it creates no unobserved path.
|
|
483
|
-
continue;
|
|
484
|
-
}
|
|
485
|
-
|
|
476
|
+
const requireFromTheme = createRequire(fromFile);
|
|
477
|
+
/**
|
|
478
|
+
* Wraps `defineTheme` on a CommonJS exports object in place, so a call
|
|
479
|
+
* from a `.cjs` dependency is recorded. False when it cannot be wrapped.
|
|
480
|
+
* @param {any} cjs
|
|
481
|
+
*/
|
|
482
|
+
const wrap = cjs => {
|
|
486
483
|
const real = cjs?.defineTheme;
|
|
487
|
-
if (typeof real !== 'function')
|
|
484
|
+
if (typeof real !== 'function') return true;
|
|
488
485
|
const descriptor = Object.getOwnPropertyDescriptor(cjs, 'defineTheme');
|
|
489
486
|
if (!descriptor || !(descriptor.writable || descriptor.configurable)) {
|
|
490
|
-
|
|
491
|
-
continue;
|
|
487
|
+
return false;
|
|
492
488
|
}
|
|
493
|
-
|
|
494
489
|
try {
|
|
495
490
|
Object.defineProperty(cjs, 'defineTheme', {
|
|
496
491
|
...descriptor,
|
|
@@ -503,16 +498,84 @@ export function interceptCore(coreThemeModule, coreRootModule) {
|
|
|
503
498
|
undo.push(() =>
|
|
504
499
|
Object.defineProperty(cjs, 'defineTheme', descriptor),
|
|
505
500
|
);
|
|
501
|
+
return true;
|
|
506
502
|
} catch {
|
|
507
503
|
// ESM namespace exotic objects may report a writable descriptor but
|
|
508
504
|
// still reject redefinition. This is a real coverage failure, not an
|
|
509
505
|
// absent CommonJS entry: a `.cjs` dependency can call the function
|
|
510
506
|
// while the recorder cannot wrap it.
|
|
511
|
-
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
// An entry that CommonJS cannot resolve or load cannot be used by a
|
|
512
|
+
// `.cjs` source dependency either, so it creates no unobserved path. It
|
|
513
|
+
// is skipped, as are the entries of a package config CommonJS cannot
|
|
514
|
+
// read. Throwing instead would fail every theme beside such an install.
|
|
515
|
+
/** @param {string} specifier @returns {string | null} */
|
|
516
|
+
const resolveEntry = specifier => {
|
|
517
|
+
try {
|
|
518
|
+
return requireFromTheme.resolve(specifier);
|
|
519
|
+
} catch {
|
|
520
|
+
return null;
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
const themeFile = resolveEntry('@astryxdesign/core/theme');
|
|
524
|
+
const rootFile = resolveEntry('@astryxdesign/core');
|
|
525
|
+
|
|
526
|
+
// The theme subpath is small, so it is wrapped now.
|
|
527
|
+
if (themeFile) {
|
|
528
|
+
/** @type {any} */
|
|
529
|
+
let themeExports = null;
|
|
530
|
+
try {
|
|
531
|
+
themeExports = requireFromTheme(themeFile);
|
|
532
|
+
} catch {
|
|
533
|
+
// A dependency that requires it fails the same way.
|
|
534
|
+
}
|
|
535
|
+
if (themeExports && !wrap(themeExports)) covered = false;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// The root loads all of Core, so it is wrapped only once this load
|
|
539
|
+
// requires it. Every CommonJS require goes through `Module._load`,
|
|
540
|
+
// which is watched for the load's duration. The watch reads the require
|
|
541
|
+
// cache, where the root's file is keyed by its real path. So any
|
|
542
|
+
// request that loads that file counts, however it is spelled. A load
|
|
543
|
+
// that never requires the root leaves no path through it to observe.
|
|
544
|
+
if (rootFile) {
|
|
545
|
+
/** @type {any} */
|
|
546
|
+
const loader = Module;
|
|
547
|
+
/** Wraps the root once its file has run; false until then. */
|
|
548
|
+
const wrapLoadedRoot = () => {
|
|
549
|
+
const loaded = loader._cache[rootFile];
|
|
550
|
+
// A CommonJS module is cached before its body runs, so a require
|
|
551
|
+
// inside the root's own body sees it partly built.
|
|
552
|
+
if (!loaded?.loaded) return false;
|
|
553
|
+
if (!wrap(loaded.exports)) covered = false;
|
|
554
|
+
return true;
|
|
555
|
+
};
|
|
556
|
+
if (!wrapLoadedRoot()) {
|
|
557
|
+
const load = loader._load;
|
|
558
|
+
/** @this {any} @param {...any} args */
|
|
559
|
+
const watch = function (...args) {
|
|
560
|
+
const exports = load.apply(this, args);
|
|
561
|
+
if (loader._load === watch && wrapLoadedRoot()) {
|
|
562
|
+
loader._load = load;
|
|
563
|
+
}
|
|
564
|
+
return exports;
|
|
565
|
+
};
|
|
566
|
+
loader._load = watch;
|
|
567
|
+
// Theme loads never overlap: each caller awaits one at a time. The
|
|
568
|
+
// watch is still removed only while it is the one installed.
|
|
569
|
+
undo.push(() => {
|
|
570
|
+
if (loader._load === watch) loader._load = load;
|
|
571
|
+
});
|
|
512
572
|
}
|
|
513
573
|
}
|
|
514
574
|
return {
|
|
515
|
-
|
|
575
|
+
/** Read after the load: a root required during it counts. */
|
|
576
|
+
get covered() {
|
|
577
|
+
return covered;
|
|
578
|
+
},
|
|
516
579
|
undo() {
|
|
517
580
|
for (const restore of undo.reverse()) {
|
|
518
581
|
try {
|
|
@@ -10,14 +10,23 @@
|
|
|
10
10
|
* base is read for its entries (`__icons`) as well as its node-valued `icons`,
|
|
11
11
|
* and a built base module's `__icons` field is followed instead of `icons`.
|
|
12
12
|
*
|
|
13
|
+
* With `field: 'componentIcons'`, the same tracing carries a theme's slot
|
|
14
|
+
* values: a slot function must come from an import, and an inline object may
|
|
15
|
+
* also hold static values (names, `null`, requests), written as JSON. A built
|
|
16
|
+
* base module is read through its export, like a package theme. A theme's own
|
|
17
|
+
* slots merge over its base's through `mergeName`, which skips an
|
|
18
|
+
* `undefined` slot as `defineTheme` does.
|
|
19
|
+
*
|
|
13
20
|
* @param {string} filePath
|
|
14
21
|
* @param {string | undefined} exportName
|
|
15
|
-
* @param {{hasIcons: boolean, functionEntries?: boolean, readSource: (filename: string) => string, resolveModule: (specifier: string, fromFile: string) => string | Promise<string>, reservedNames?: string[], rawInput?: boolean}} options
|
|
22
|
+
* @param {{hasIcons: boolean, functionEntries?: boolean, field?: 'icons' | 'componentIcons', mergeName?: string, readSource: (filename: string) => string, resolveModule: (specifier: string, fromFile: string) => string | Promise<string>, reservedNames?: string[], rawInput?: boolean}} options
|
|
16
23
|
* @returns {Promise<IconImports | null>}
|
|
17
24
|
*/
|
|
18
|
-
export function resolveIconImports(filePath: string, exportName: string | undefined, { hasIcons, functionEntries, readSource, resolveModule, reservedNames, rawInput, }: {
|
|
25
|
+
export function resolveIconImports(filePath: string, exportName: string | undefined, { hasIcons, functionEntries, field, mergeName, readSource, resolveModule, reservedNames, rawInput, }: {
|
|
19
26
|
hasIcons: boolean;
|
|
20
27
|
functionEntries?: boolean;
|
|
28
|
+
field?: "icons" | "componentIcons";
|
|
29
|
+
mergeName?: string;
|
|
21
30
|
readSource: (filename: string) => string;
|
|
22
31
|
resolveModule: (specifier: string, fromFile: string) => string | Promise<string>;
|
|
23
32
|
reservedNames?: string[];
|
|
@@ -33,6 +42,11 @@ export type IconImports = {
|
|
|
33
42
|
exportName: string;
|
|
34
43
|
iconsSpecifierImportPath?: string | undefined;
|
|
35
44
|
iconsSpecifierLocalName?: string | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* - Set when `expression` calls the slot merge
|
|
47
|
+
* function, which the module must declare under this name.
|
|
48
|
+
*/
|
|
49
|
+
mergeName?: string | undefined;
|
|
36
50
|
};
|
|
37
51
|
export type RegistryReference = {
|
|
38
52
|
kind: "reference";
|
|
@@ -41,8 +55,21 @@ export type RegistryReference = {
|
|
|
41
55
|
members: string[];
|
|
42
56
|
};
|
|
43
57
|
/**
|
|
44
|
-
* `
|
|
45
|
-
*
|
|
58
|
+
* A `merge` with `theme` set merges a theme's own values over its base's;
|
|
59
|
+
* any other merge is a spread inside one object.
|
|
60
|
+
*/
|
|
61
|
+
export type SlotData = {
|
|
62
|
+
json: unknown;
|
|
63
|
+
} | {
|
|
64
|
+
ref: RegistryReference;
|
|
65
|
+
} | {
|
|
66
|
+
object: Array<[string, SlotData]>;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* `entries` marks a package theme read for its entries: its public field
|
|
70
|
+
* (node-valued `icons`, or the static `componentIcons` view) merged with the
|
|
71
|
+
* `__` field that holds its functions, if any. `object` is an inline
|
|
72
|
+
* `componentIcons` object: each slot is a static value or an imported one.
|
|
46
73
|
*/
|
|
47
74
|
export type RegistryPlan = {
|
|
48
75
|
kind: "registry";
|
|
@@ -54,4 +81,8 @@ export type RegistryPlan = {
|
|
|
54
81
|
kind: "merge";
|
|
55
82
|
base: RegistryPlan;
|
|
56
83
|
own: RegistryPlan;
|
|
84
|
+
theme?: boolean;
|
|
85
|
+
} | {
|
|
86
|
+
kind: "object";
|
|
87
|
+
entries: Array<[string, SlotData]>;
|
|
57
88
|
};
|