@astryxdesign/cli 0.7.11-canary.3df65bf → 0.7.11-canary.4e6e67d

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 (33) hide show
  1. package/api/icon/_authoring.mjs +228 -32
  2. package/api/icon/icon.type.d.mts +15 -0
  3. package/api/icon/icon.type.mjs +2 -0
  4. package/api/integration/add-helpers.d.mts +10 -1
  5. package/api/integration/add-helpers.mjs +1 -1
  6. package/api/swizzle/_adapter.d.mts +1 -0
  7. package/api/swizzle/_adapter.mjs +4 -1
  8. package/api/swizzle/_moduleGraph.d.mts +162 -0
  9. package/api/swizzle/_moduleGraph.mjs +754 -0
  10. package/api/swizzle/copy/copy.d.mts +2 -43
  11. package/api/swizzle/copy/copy.mjs +194 -314
  12. package/api/swizzle/swizzle.d.mts +0 -2
  13. package/api/swizzle/swizzle.doc.mjs +8 -4
  14. package/api/swizzle/swizzle.mjs +3 -7
  15. package/api/swizzle/swizzle.type.d.mts +1 -1
  16. package/api/swizzle/swizzle.type.mjs +2 -2
  17. package/assets/discover/official-packages.json +12 -0
  18. package/assets/docs/tree/icon-sets.doc.mjs +2 -2
  19. package/assets/templates/pages/file-explorer/page.tsx +103 -79
  20. package/assets/templates/pages/theme-showcase/page.tsx +724 -792
  21. package/assets/templates/pages/theme-showcase/template.doc.mjs +4 -5
  22. package/clients/cli/commands/swizzle.doc.mjs +6 -3
  23. package/clients/cli/commands/swizzle.mjs +8 -9
  24. package/foundation/discovery/component-loader.d.mts +1 -1
  25. package/foundation/discovery/icon-set-checks.mjs +4 -15
  26. package/foundation/discovery/icon-set-discovery.d.mts +13 -0
  27. package/foundation/discovery/icon-set-discovery.mjs +25 -0
  28. package/foundation/discovery/icon-set-writer.d.mts +28 -0
  29. package/foundation/discovery/icon-set-writer.mjs +57 -0
  30. package/foundation/discovery/module-exports.mjs +57 -2
  31. package/foundation/fs/paths.d.mts +2 -1
  32. package/foundation/fs/paths.mjs +3 -4
  33. package/package.json +6 -6
@@ -6,7 +6,8 @@ export const doc = {
6
6
  name: 'Theme Showcase',
7
7
  displayName: 'Theme Showcase',
8
8
  description:
9
- 'Several unrelated product surfaces rendered together on one canvas so a token change can be judged across contexts at once. A comparison harness rather than a layout to ship.',
9
+ 'Multi-surface comparison shell: preview palettes, typography, icons and control states across a storefront, checkout, chat and inventory on one responsive canvas. A theme preview and design-system showcase, with an embeddable content view for an existing app shell.',
10
+ category: 'Shell - Top Nav',
10
11
  keywords: [
11
12
  'theme',
12
13
  'tokens',
@@ -16,10 +17,8 @@ export const doc = {
16
17
  'design system preview',
17
18
  ],
18
19
  isReady: true,
19
- // Surfaced via the Themes page "Open in Playground" action, not the
20
- // Templates gallery, so keep it out of the overview + playground menu.
21
- // No `category` — it's hidden from the overview gallery (the only consumer
22
- // of `category`), and 'Showcase' isn't part of the TemplateCategory taxonomy.
20
+ // The standalone entry demonstrates an application shell; the named preview
21
+ // composes into its host without nesting AppShell. Keep it out of the gallery.
23
22
  isHiddenFromOverview: true,
24
23
  icons: {
25
24
  Banknote: 'money',
@@ -16,8 +16,11 @@ export const doc = {
16
16
  summary: 'Copy component source for customization',
17
17
  description:
18
18
  "Ejects a component's source from the resolved @astryxdesign/core (or its owning " +
19
- 'integration) into your project for deep customization, rewriting imports that ' +
20
- 'escape the component directory. With no name it lists the swizzlable components. ' +
19
+ 'integration) into your project for deep customization. Every import in the copy ' +
20
+ 'names a file the copy holds or a path the package exports: names the package ' +
21
+ 'exports come from the package, and every internal module the component needs ' +
22
+ "is copied beside it in the package's folder layout. " +
23
+ 'Tests, stories and docs are not copied. With no name it lists the swizzlable components. ' +
21
24
  'An integration component that replaces a Core component is what that Core name ' +
22
25
  'copies; --package @astryxdesign/core copies the original. --list lists Core ' +
23
26
  'components, including one an integration replaces.',
@@ -46,7 +49,7 @@ export const doc = {
46
49
  flag: '-f, --overwrite',
47
50
  param: 'options.overwrite',
48
51
  description:
49
- 'Replace existing files. Without it, existing files fail the command with ERR_FILE_EXISTS and nothing is written',
52
+ "Replace the component's existing files. Without it, existing files fail the command with ERR_FILE_EXISTS and nothing is written. A helper an earlier swizzle wrote is reused when it is the same and is never replaced by a copy that carries it: a different one stays, and this copy writes its own under a version-suffixed name. Swizzling the component whose folder holds that helper counts it as one of that component's own files. A changed private attribute owner module, or a style module it imports, fails the command without --overwrite and is replaced with it",
50
53
  },
51
54
  ],
52
55
  examples: [
@@ -3,11 +3,10 @@
3
3
  /**
4
4
  * @file swizzle command — thin wrapper around api/swizzle.
5
5
  *
6
- * Copies a component's source into the consumer project for customization
7
- * (imports rewritten to the owner package's subpaths). All logic — owner
8
- * resolution, copy, import rewriting, StyleX detection, maintainer feedback —
9
- * lives in api/swizzle; this file only parses flags, prints, and prefixes
10
- * commands for the caller's package manager.
6
+ * Copies a component's source into the consumer project for customization,
7
+ * with the internal modules it needs. All logic — owner resolution, the copy,
8
+ * StyleX detection, maintainer feedback — lives in api/swizzle; this file only
9
+ * parses flags, prints, and prefixes commands for the caller's package manager.
11
10
  */
12
11
 
13
12
  import {jsonOut} from '../../../foundation/response/json.mjs';
@@ -85,18 +84,18 @@ export function registerSwizzle(program) {
85
84
  text(`[ok] Copied ${filesCopied} files to ${outputDir}/`),
86
85
  text(
87
86
  [
88
- `Relative imports have been rewritten to use ${ownerPackage}.`,
87
+ `What ${ownerPackage} exports is imported from ${ownerPackage}; the internal modules the component needs are copied beside it.`,
89
88
  'You can now customize the component source freely.',
90
89
  ].join('\n'),
91
90
  ),
92
91
  ];
93
- // Files the copy wrote outside the component folder: the owner modules
94
- // and their unexported style modules (spec:AST-110 FR4).
92
+ // Files the copy wrote outside the component folder: the internal
93
+ // modules it needs, in the package's folder layout.
95
94
  const shared = (result.data.files ?? []).filter(f => f.startsWith('../'));
96
95
  if (shared.length > 0) {
97
96
  out.push(
98
97
  text(
99
- `Shared modules: ${shared.join(', ')} (copied whole; their imports between each other stay relative)`,
98
+ `Copied beside it: ${shared.join(', ')} (in the package's folder layout; imported by relative path)`,
100
99
  ),
101
100
  );
102
101
  }
@@ -43,5 +43,5 @@ export type LoadDocOptions = {
43
43
  * which root reads the doc
44
44
  * (default: components)
45
45
  */
46
- root?: "hooks" | "components" | undefined;
46
+ root?: "components" | "hooks" | undefined;
47
47
  };
@@ -44,8 +44,9 @@ import * as path from 'node:path';
44
44
  import {findInstalledPackage} from '../fs/paths.mjs';
45
45
  import {satisfiesRange} from '../env/semver.mjs';
46
46
  import {
47
- NOTICE_FILE_RE,
48
47
  discoverIconSetDirectory,
48
+ hasLicenseNotice,
49
+ licenseNoticeFix,
49
50
  resolveIconModule,
50
51
  splitSpecifier,
51
52
  } from './icon-set-discovery.mjs';
@@ -1003,14 +1004,11 @@ function checkUpstream(set, packageDir, pkg) {
1003
1004
  ),
1004
1005
  );
1005
1006
  }
1006
- const rootNotices = safeList(packageDir).filter(name =>
1007
- NOTICE_FILE_RE.test(name),
1008
- );
1009
- if (set.notices.length === 0 && rootNotices.length === 0) {
1007
+ if (!hasLicenseNotice(set.dir) && !hasLicenseNotice(packageDir)) {
1010
1008
  issues.push(
1011
1009
  issueWarning(
1012
1010
  ICON_LICENSE_NOTICE_MISSING,
1013
- `${label} is generated from ${source.package} but ships no license notice. Copy the library's LICENSE (and NOTICE, if any) into the set directory or the package root.`,
1011
+ `${label} is generated from ${source.package}@${source.version} but ships no license notice. ${licenseNoticeFix(path.relative(packageDir, set.dir).split(path.sep).join('/'), `${source.package}@${source.version}`)} If the library ships a LICENSE or NOTICE file, copy that file there instead.`,
1014
1012
  ),
1015
1013
  );
1016
1014
  }
@@ -1026,12 +1024,3 @@ function safeSatisfies(version, range) {
1026
1024
  return true;
1027
1025
  }
1028
1026
  }
1029
-
1030
- /** @param {string} dir */
1031
- function safeList(dir) {
1032
- try {
1033
- return fs.readdirSync(dir);
1034
- } catch {
1035
- return [];
1036
- }
1037
- }
@@ -1,6 +1,19 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * What to add when a set wraps a library and has no license notice: a
6
+ * NOTICE file in the set directory, with the file names that count. The
7
+ * CLI never writes it, because the license text is the author's to state.
8
+ * @param {string} setDir the set directory, from the package root
9
+ * @param {string} library the library as `name@version`
10
+ */
11
+ export function licenseNoticeFix(setDir: string, library: string): string;
12
+ /**
13
+ * Whether a directory has a license or notice file ({@link NOTICE_FILE_RE}).
14
+ * @param {string} dir
15
+ */
16
+ export function hasLicenseNotice(dir: string): boolean;
4
17
  /**
5
18
  * One installed icon set: its descriptor, its data, and where it came from.
6
19
  * @typedef {object} DiscoveredIconSet
@@ -43,6 +43,31 @@ const SET_NAME_RE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
43
43
  /** A license or notice file a set ships beside its data (FR15). */
44
44
  export const NOTICE_FILE_RE = /^(?:licen[cs]e|notice|copying)(?:[.-].*)?$/iu;
45
45
 
46
+ /**
47
+ * What to add when a set wraps a library and has no license notice: a
48
+ * NOTICE file in the set directory, with the file names that count. The
49
+ * CLI never writes it, because the license text is the author's to state.
50
+ * @param {string} setDir the set directory, from the package root
51
+ * @param {string} library the library as `name@version`
52
+ */
53
+ export function licenseNoticeFix(setDir, library) {
54
+ return `Add a NOTICE (or LICENSE) file to ${setDir} that names ${library} and its license: \`${setDir}/NOTICE\`. A file named LICENSE, LICENCE, NOTICE, or COPYING, in any case and with an optional suffix such as NOTICE.md or LICENSE-MIT, counts in the set directory or the package root.`;
55
+ }
56
+
57
+ /**
58
+ * Whether a directory has a license or notice file ({@link NOTICE_FILE_RE}).
59
+ * @param {string} dir
60
+ */
61
+ export function hasLicenseNotice(dir) {
62
+ try {
63
+ return fs
64
+ .readdirSync(dir, {withFileTypes: true})
65
+ .some(file => file.isFile() && NOTICE_FILE_RE.test(file.name));
66
+ } catch {
67
+ return false;
68
+ }
69
+ }
70
+
46
71
  /**
47
72
  * One installed icon set: its descriptor, its data, and where it came from.
48
73
  * @typedef {object} DiscoveredIconSet
@@ -461,6 +461,34 @@ export function sameIconModule(a: string, b: string): boolean;
461
461
  * @param {string} specifier
462
462
  */
463
463
  export function iconModulePackage(specifier: string): string;
464
+ /**
465
+ * The set's exports that read one file of a package, where a refresh from
466
+ * that package's root can read them from the root instead. An export moves
467
+ * when the root exports the same icon: an export that resolves to the same
468
+ * file and binding. When the subpath export cannot be resolved, a root
469
+ * export of the same name counts. Each maps to the root's
470
+ * export and the module it reads now. Empty unless `root` is a package
471
+ * root, not a subpath or a ./ path.
472
+ * @param {Map<string, {module: string, source: string}>} origins the
473
+ * set's exports ({@link generatedOrigins})
474
+ * @param {{file: string, module: string}} root the refreshed module
475
+ * @param {string[]} rootExports the root's icon exports
476
+ * @param {{packageDir: string, pkg: Record<string, any>}} where
477
+ * @returns {Map<string, {source: string, from: string}>}
478
+ */
479
+ export function packageRootMoves(origins: Map<string, {
480
+ module: string;
481
+ source: string;
482
+ }>, root: {
483
+ file: string;
484
+ module: string;
485
+ }, rootExports: string[], where: {
486
+ packageDir: string;
487
+ pkg: Record<string, any>;
488
+ }): Map<string, {
489
+ source: string;
490
+ from: string;
491
+ }>;
464
492
  /**
465
493
  * Write the set's generated module and its declaration file
466
494
  * ({@link generatedModuleText}). Returns whether either changed, and a
@@ -1898,6 +1898,63 @@ export function iconModulePackage(specifier) {
1898
1898
  return specifier.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
1899
1899
  }
1900
1900
 
1901
+ /**
1902
+ * The set's exports that read one file of a package, where a refresh from
1903
+ * that package's root can read them from the root instead. An export moves
1904
+ * when the root exports the same icon: an export that resolves to the same
1905
+ * file and binding. When the subpath export cannot be resolved, a root
1906
+ * export of the same name counts. Each maps to the root's
1907
+ * export and the module it reads now. Empty unless `root` is a package
1908
+ * root, not a subpath or a ./ path.
1909
+ * @param {Map<string, {module: string, source: string}>} origins the
1910
+ * set's exports ({@link generatedOrigins})
1911
+ * @param {{file: string, module: string}} root the refreshed module
1912
+ * @param {string[]} rootExports the root's icon exports
1913
+ * @param {{packageDir: string, pkg: Record<string, any>}} where
1914
+ * @returns {Map<string, {source: string, from: string}>}
1915
+ */
1916
+ export function packageRootMoves(origins, root, rootExports, where) {
1917
+ /** @type {Map<string, {source: string, from: string}>} */
1918
+ const moves = new Map();
1919
+ if (iconModulePackage(root.module) !== root.module) return moves;
1920
+ if (root.module.startsWith('.')) return moves;
1921
+ const subpaths = [...origins].filter(
1922
+ ([, origin]) =>
1923
+ !origin.module.startsWith('.') &&
1924
+ origin.module !== root.module &&
1925
+ iconModulePackage(origin.module) === root.module,
1926
+ );
1927
+ if (subpaths.length === 0) return moves;
1928
+ /** @param {{file: string, name: string}} origin */
1929
+ const keyOf = origin => `${origin.file}\0${origin.name}`;
1930
+ /** @type {Map<string, string>} */
1931
+ const byOrigin = new Map();
1932
+ for (const name of rootExports) {
1933
+ const origin = moduleExportOrigin(root.file, name);
1934
+ if (origin && !byOrigin.has(keyOf(origin))) {
1935
+ byOrigin.set(keyOf(origin), name);
1936
+ }
1937
+ }
1938
+ const names = new Set(rootExports);
1939
+ const self = {
1940
+ name: typeof where.pkg.name === 'string' ? where.pkg.name : '',
1941
+ dir: where.packageDir,
1942
+ };
1943
+ for (const [name, origin] of subpaths) {
1944
+ const file = resolveIconModule(origin.module, where.packageDir, self);
1945
+ const resolved = file ? moduleExportOrigin(file, origin.source) : null;
1946
+ // A name match counts only when the subpath export cannot be resolved.
1947
+ // A resolved export is the same icon only when it reads the same file.
1948
+ const source = resolved
1949
+ ? byOrigin.get(keyOf(resolved))
1950
+ : names.has(origin.source)
1951
+ ? origin.source
1952
+ : undefined;
1953
+ if (source) moves.set(name, {source, from: origin.module});
1954
+ }
1955
+ return moves;
1956
+ }
1957
+
1901
1958
  /**
1902
1959
  * Write the set's generated module and its declaration file
1903
1960
  * ({@link generatedModuleText}). Returns whether either changed, and a
@@ -707,7 +707,12 @@ function exportOriginsOf(file, read) {
707
707
  for (const node of declarations) {
708
708
  for (const name of declaredNames(node.declaration, types)) {
709
709
  named.add(name);
710
- if (!origins.has(name)) origins.set(name, {file, name});
710
+ if (!origins.has(name)) {
711
+ origins.set(
712
+ name,
713
+ declaredOrigin(ast, file, node.declaration, name, types),
714
+ );
715
+ }
711
716
  }
712
717
  }
713
718
  for (const [exportName, entries] of specifiers) {
@@ -1211,7 +1216,15 @@ function exportOrigin(file, exportName, seen, read, types = false) {
1211
1216
  const {declarations, specifiers} = namedExportIndex(ast.program, types, read);
1212
1217
  for (const node of declarations) {
1213
1218
  if (declarationExports(node.declaration, exportName, types)) {
1214
- return {file, name: exportName};
1219
+ return declaredOrigin(
1220
+ ast,
1221
+ file,
1222
+ node.declaration,
1223
+ exportName,
1224
+ types,
1225
+ seen,
1226
+ read,
1227
+ );
1215
1228
  }
1216
1229
  }
1217
1230
  for (const {node, specifier} of specifiers.get(exportName) ?? []) {
@@ -1690,6 +1703,48 @@ export function elementPropOrigins(file, {sources, name, prop, unwrap}) {
1690
1703
  return origins;
1691
1704
  }
1692
1705
 
1706
+ /**
1707
+ * Where a declared export is defined. An `export const X = Y` whose value is
1708
+ * another binding is that binding, so an alias of an imported value has the
1709
+ * imported value's origin.
1710
+ * @param {any} ast
1711
+ * @param {string} file
1712
+ * @param {any} declaration
1713
+ * @param {string} name
1714
+ * @param {boolean} types
1715
+ * @param {Set<string>} [seen]
1716
+ * @param {(node: any, type: string) => readonly any[]} [read]
1717
+ * @returns {{file: string, name: string}}
1718
+ */
1719
+ function declaredOrigin(
1720
+ ast,
1721
+ file,
1722
+ declaration,
1723
+ name,
1724
+ types,
1725
+ seen = new Set(),
1726
+ read = nodesOfType,
1727
+ ) {
1728
+ if (
1729
+ declaration?.type === 'VariableDeclaration' &&
1730
+ declaration.kind === 'const'
1731
+ ) {
1732
+ for (const declarator of declaration.declarations) {
1733
+ if (
1734
+ declarator.id?.type === 'Identifier' &&
1735
+ declarator.id.name === name &&
1736
+ declarator.init?.type === 'Identifier'
1737
+ ) {
1738
+ const init = declarator.init.name;
1739
+ return (
1740
+ bindingOrigin(ast, file, init, seen, types, read) ?? {file, name}
1741
+ );
1742
+ }
1743
+ }
1744
+ }
1745
+ return {file, name};
1746
+ }
1747
+
1693
1748
  /**
1694
1749
  * Where a top-level binding of a parsed module comes from: an import from a
1695
1750
  * local module is followed to its origin; anything else is declared here.
@@ -166,7 +166,8 @@ export function discoverExternalPackages(startDir?: string): {
166
166
  }[];
167
167
  /**
168
168
  * List available component directories in packages/core/src.
169
- * Returns directory names that contain Astryx*.tsx files.
169
+ * Component directories are capitalized (`Button`, `Dialog`); lowercase
170
+ * directories hold shared infrastructure and are never listed.
170
171
  * @param {string} coreDir
171
172
  */
172
173
  export function listComponents(coreDir: string): string[];
@@ -854,7 +854,8 @@ export function discoverExternalPackages(startDir = process.cwd()) {
854
854
 
855
855
  /**
856
856
  * List available component directories in packages/core/src.
857
- * Returns directory names that contain Astryx*.tsx files.
857
+ * Component directories are capitalized (`Button`, `Dialog`); lowercase
858
+ * directories hold shared infrastructure and are never listed.
858
859
  * @param {string} coreDir
859
860
  */
860
861
  export function listComponents(coreDir) {
@@ -865,9 +866,7 @@ export function listComponents(coreDir) {
865
866
  return entries
866
867
  .filter(e => {
867
868
  if (!e.isDirectory()) return false;
868
- // Skip non-component dirs
869
- if (['hooks', 'theme', 'utils'].includes(e.name)) return false;
870
- return true;
869
+ return /^[A-Z]/.test(e.name);
871
870
  })
872
871
  .map(e => e.name)
873
872
  .sort();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.11-canary.3df65bf",
3
+ "version": "0.7.11-canary.4e6e67d",
4
4
  "displayName": "CLI",
5
5
  "description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
6
6
  "author": "Meta Open Source",
@@ -124,7 +124,7 @@
124
124
  "zod": "^4.4.3"
125
125
  },
126
126
  "peerDependencies": {
127
- "@astryxdesign/core": "0.7.11-canary.3df65bf"
127
+ "@astryxdesign/core": "0.7.11-canary.4e6e67d"
128
128
  },
129
129
  "peerDependenciesMeta": {
130
130
  "@astryxdesign/core": {
@@ -132,10 +132,10 @@
132
132
  }
133
133
  },
134
134
  "devDependencies": {
135
- "@astryxdesign/charts": "0.7.11-canary.3df65bf",
136
- "@astryxdesign/core": "0.7.11-canary.3df65bf",
137
- "@astryxdesign/lab": "0.7.11-canary.3df65bf",
138
- "@astryxdesign/theme-neutral": "0.7.11-canary.3df65bf",
135
+ "@astryxdesign/charts": "0.7.11-canary.4e6e67d",
136
+ "@astryxdesign/core": "0.7.11-canary.4e6e67d",
137
+ "@astryxdesign/lab": "0.7.11-canary.4e6e67d",
138
+ "@astryxdesign/theme-neutral": "0.7.11-canary.4e6e67d",
139
139
  "@heroicons/react": "^2.2.0",
140
140
  "@stylexjs/stylex": "^0.19.0",
141
141
  "@types/babel__core": "^7.20.5",