@astryxdesign/cli 0.7.9-canary.ffa495b → 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.
Files changed (70) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.md +1 -1
  3. package/api/component/__fixtures__/resolutions/modules.txt +5 -5
  4. package/api/search/_candidate-score.mjs +25 -23
  5. package/api/search/_words.d.mts +44 -7
  6. package/api/search/_words.mjs +113 -21
  7. package/api/swizzle/_adapter.d.mts +10 -0
  8. package/api/swizzle/_adapter.mjs +24 -1
  9. package/api/swizzle/copy/copy.d.mts +17 -1
  10. package/api/swizzle/copy/copy.mjs +249 -9
  11. package/api/swizzle/swizzle.doc.mjs +1 -1
  12. package/api/swizzle/swizzle.type.mjs +1 -1
  13. package/api/theme/build/build.mjs +363 -73
  14. package/api/theme/build/core-interception.mjs +92 -29
  15. package/api/theme/build/icon-imports.d.mts +35 -4
  16. package/api/theme/build/icon-imports.mjs +299 -38
  17. package/assets/discover/official-packages.json +12 -0
  18. package/assets/docs/author-a-theme.doc.mjs +3 -1
  19. package/assets/docs/icons.doc.mjs +29 -0
  20. package/assets/docs/motion.doc.mjs +1 -1
  21. package/assets/docs/tree/calendar-systems.doc.mjs +146 -0
  22. package/assets/docs/tree/calendars.doc.mjs +46 -0
  23. package/assets/docs/tree/i18n-calendars.doc.mjs +51 -0
  24. package/assets/docs/tree/internationalization.doc.mjs +3 -3
  25. package/assets/templates/blocks/components/Calendar/useCalendarDaysHookUsage.doc.mjs +14 -0
  26. package/assets/templates/blocks/components/Calendar/useCalendarDaysHookUsage.tsx +71 -0
  27. package/assets/templates/blocks/components/Hooks/useInputContainerHookUsage.doc.mjs +15 -0
  28. package/assets/templates/blocks/components/Hooks/useInputContainerHookUsage.tsx +93 -0
  29. package/assets/templates/blocks/components/Hooks/useMergedRefsHookUsage.doc.mjs +14 -0
  30. package/assets/templates/blocks/components/Hooks/useMergedRefsHookUsage.tsx +78 -0
  31. package/assets/templates/blocks/components/Hooks/useScrollLockHookUsage.doc.mjs +14 -0
  32. package/assets/templates/blocks/components/Hooks/useScrollLockHookUsage.tsx +80 -0
  33. package/assets/templates/blocks/components/Hooks/useScrollOverflowHookUsage.doc.mjs +14 -0
  34. package/assets/templates/blocks/components/Hooks/useScrollOverflowHookUsage.tsx +94 -0
  35. package/assets/templates/blocks/components/Icon/useIconHookUsage.doc.mjs +19 -0
  36. package/assets/templates/blocks/components/Icon/useIconHookUsage.tsx +68 -0
  37. package/assets/templates/blocks/components/Link/useLinkComponentHookUsage.doc.mjs +14 -0
  38. package/assets/templates/blocks/components/Link/useLinkComponentHookUsage.tsx +89 -0
  39. package/assets/templates/blocks/components/Overlay/useOverlayHookUsage.doc.mjs +21 -0
  40. package/assets/templates/blocks/components/Overlay/useOverlayHookUsage.tsx +49 -0
  41. package/assets/templates/blocks/components/Table/useTableSortableStateHookUsage.doc.mjs +14 -0
  42. package/assets/templates/blocks/components/Table/useTableSortableStateHookUsage.tsx +61 -0
  43. package/assets/templates/blocks/components/usePanGesture/PanDraggableBox.doc.mjs +15 -0
  44. package/assets/templates/blocks/components/usePanGesture/PanDraggableBox.tsx +98 -0
  45. package/assets/templates/blocks/components/usePanGesture/PanPlayingCard.doc.mjs +14 -0
  46. package/assets/templates/blocks/components/usePanGesture/PanPlayingCard.tsx +147 -0
  47. package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +2 -2
  48. package/assets/templates/themes/neutral/neutralTheme.ts +30 -4
  49. package/assets/theme.template.ts +14 -2
  50. package/authoring/doctypes/base/type.ts +41 -0
  51. package/authoring/doctypes/component/component.doc.mjs +7 -1
  52. package/authoring/doctypes/component/type.ts +5 -0
  53. package/authoring/index.d.ts +2 -0
  54. package/clients/cli/commands/ensure-core-built.mjs +399 -43
  55. package/clients/cli/commands/swizzle.mjs +10 -0
  56. package/clients/cli/lib/component-format.mjs +49 -0
  57. package/foundation/config/project.mjs +27 -9
  58. package/foundation/discovery/component-discovery.mjs +56 -10
  59. package/foundation/env/search-path.d.mts +12 -0
  60. package/foundation/env/search-path.mjs +71 -43
  61. package/foundation/integrations/manifest-writer.d.mts +3 -4
  62. package/foundation/integrations/manifest-writer.mjs +5 -3
  63. package/foundation/release/cache.d.mts +11 -4
  64. package/foundation/release/cache.mjs +15 -7
  65. package/foundation/response/response-types.doc.mjs +1 -1
  66. package/foundation/text/levenshtein.d.mts +4 -1
  67. package/foundation/text/levenshtein.mjs +44 -1
  68. package/package.json +9 -9
  69. package/api/swizzle/_github.d.mts +0 -8
  70. package/api/swizzle/_github.mjs +0 -22
@@ -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
- const root =
303
- typeof coreRootModule === 'function'
304
- ? coreRootModule()
305
- : coreRootModule;
306
- // Falls back to the theme namespace only when the root could not be
307
- // imported at all; a partial root is better than none, and a core
308
- // missing its own root entry is already broken.
309
- wrappedRoot ??= wrapNamespace(root ?? coreThemeModule);
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
- for (const specifier of [
473
- '@astryxdesign/core/theme',
474
- '@astryxdesign/core',
475
- ]) {
476
- /** @type {any} */
477
- let cjs;
478
- try {
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') continue;
484
+ if (typeof real !== 'function') return true;
488
485
  const descriptor = Object.getOwnPropertyDescriptor(cjs, 'defineTheme');
489
486
  if (!descriptor || !(descriptor.writable || descriptor.configurable)) {
490
- covered = false;
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
- covered = false;
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
- covered,
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
- * `entries` marks a package theme read for its icon entries: its node-valued
45
- * `icons` merged with the `__icons` that hold its function entries, if any.
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
  };