@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
@@ -11,6 +11,7 @@ import {DOC_EXPORTS} from '../doc-compiler/read.mjs';
11
11
  import {
12
12
  listDir,
13
13
  listDirEntries,
14
+ listingCacheActive,
14
15
  oncePerListing,
15
16
  pathExists,
16
17
  withListingCache,
@@ -511,6 +512,42 @@ export function discoverComponents(coreDir) {
511
512
  return ordered;
512
513
  }
513
514
 
515
+ /**
516
+ * The folders of `srcDir`, in listing order, whose own listing holds one of
517
+ * `names`: the only folders a probe for `<folder>/<name>` can find. Inside an
518
+ * operation each listing is read once, for every name. Outside one, every
519
+ * folder is returned, so each probe reads the disk.
520
+ * @param {string} srcDir
521
+ * @param {fs.Dirent[]} entries `srcDir`'s listing
522
+ * @param {string[]} names
523
+ * @returns {fs.Dirent[]}
524
+ */
525
+ function foldersHolding(srcDir, entries, names) {
526
+ const folders = entries.filter(entry => entry.isDirectory());
527
+ if (!listingCacheActive()) return folders;
528
+ const byName = oncePerListing(`folder-names\0${srcDir}`, () => {
529
+ /** @type {Map<string, Set<string>>} */
530
+ const index = new Map();
531
+ for (const folder of folders) {
532
+ let listed;
533
+ try {
534
+ listed = listDir(path.join(srcDir, folder.name));
535
+ } catch {
536
+ continue;
537
+ }
538
+ for (const name of listed) {
539
+ let holders = index.get(name);
540
+ if (!holders) index.set(name, (holders = new Set()));
541
+ holders.add(folder.name);
542
+ }
543
+ }
544
+ return index;
545
+ });
546
+ return folders.filter(folder =>
547
+ names.some(name => byName.get(name)?.has(folder.name)),
548
+ );
549
+ }
550
+
514
551
  /**
515
552
  * Find the .doc.mjs file for a component.
516
553
  * For sub-components (e.g. StackItem), returns the parent's .doc.mjs
@@ -532,8 +569,7 @@ export function findComponentReadme(coreDir, name) {
532
569
 
533
570
  // Nested match: src/*/{name}/{Name}.doc.mjs or src/*/{name}/Astryx{Name}.doc.mjs
534
571
  const entries = listDirEntries(srcDir);
535
- for (const entry of entries) {
536
- if (!entry.isDirectory()) continue;
572
+ for (const entry of foldersHolding(srcDir, entries, [name])) {
537
573
  const nested = path.join(srcDir, entry.name, name, exactDoc);
538
574
  if (existsCaseExact(nested, srcDir)) return nested;
539
575
  const nestedXds = path.join(srcDir, entry.name, name, xdsDoc);
@@ -541,8 +577,7 @@ export function findComponentReadme(coreDir, name) {
541
577
  }
542
578
 
543
579
  // Per-component doc in a parent directory: src/*/{Name}.doc.mjs or src/*/Astryx{Name}.doc.mjs
544
- for (const entry of entries) {
545
- if (!entry.isDirectory()) continue;
580
+ for (const entry of foldersHolding(srcDir, entries, [exactDoc, xdsDoc])) {
546
581
  const perComp = path.join(srcDir, entry.name, exactDoc);
547
582
  if (existsCaseExact(perComp, srcDir)) return perComp;
548
583
  const perCompXds = path.join(srcDir, entry.name, xdsDoc);
@@ -731,12 +766,7 @@ function caseSpelledComponentSource(srcDir, name) {
731
766
  */
732
767
  export function resolveImportPath(coreDir, componentName) {
733
768
  const srcDir = path.join(coreDir, 'src');
734
- const pkgPath = path.join(coreDir, 'package.json');
735
- const pkg = pathExists(pkgPath)
736
- ? JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
737
- : null;
738
-
739
- const exportKeys = Object.keys(pkg?.exports || {});
769
+ const exportKeys = exportKeysOf(coreDir);
740
770
 
741
771
  // Priority 1: exact subpath export matching the component name (e.g. ./Heading)
742
772
  // This allows convenience re-export directories to win over the source directory.
@@ -764,6 +794,22 @@ export function resolveImportPath(coreDir, componentName) {
764
794
  return '@astryxdesign/core';
765
795
  }
766
796
 
797
+ /**
798
+ * The subpaths the package's `exports` map names, read once per operation:
799
+ * a search resolves the import of every component.
800
+ * @param {string} coreDir
801
+ * @returns {string[]}
802
+ */
803
+ function exportKeysOf(coreDir) {
804
+ const pkgPath = path.join(coreDir, 'package.json');
805
+ return oncePerListing(`export-keys\0${pkgPath}`, () => {
806
+ const pkg = pathExists(pkgPath)
807
+ ? JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
808
+ : null;
809
+ return Object.keys(pkg?.exports || {});
810
+ });
811
+ }
812
+
767
813
  /**
768
814
  * Does a package's `exports` map publish this subpath?
769
815
  *
@@ -7,6 +7,18 @@
7
7
  * @returns {string | null}
8
8
  */
9
9
  export function astryxCliRootOf(file: string): string | null;
10
+ /**
11
+ * The executable files on the search path named one of `names`, in the order
12
+ * a shell tries them. In each folder, it takes the first name that is a file
13
+ * this user may run. Nothing is started.
14
+ * @param {readonly string[]} names
15
+ * @param {{searchPath?: string, platform?: NodeJS.Platform}} [options]
16
+ * @returns {string[]}
17
+ */
18
+ export function executablesOnSearchPath(names: readonly string[], { searchPath, platform, }?: {
19
+ searchPath?: string;
20
+ platform?: NodeJS.Platform;
21
+ }): string[];
10
22
  /**
11
23
  * Every `astryx` command on the search path, in the order a shell tries
12
24
  * them. The first row is the one that runs.
@@ -13,9 +13,10 @@
13
13
  * package folder is read from the shim's text.
14
14
  *
15
15
  * @input the search path and, on Windows, its executable names
16
- * @output one row per `astryx` command found
17
- * @position packages/cli/foundation/env — read by doctor, init --user, and
18
- * the update notices.
16
+ * @output one row per `astryx` command found, and the executable files that
17
+ * any command name finds there
18
+ * @position packages/cli/foundation/env — read by doctor, init --user, the
19
+ * update notices, and swizzle's `gh` lookup.
19
20
  */
20
21
 
21
22
  import * as fs from 'node:fs';
@@ -146,6 +147,53 @@ function namesCliPackage(file) {
146
147
  }
147
148
  }
148
149
 
150
+ /**
151
+ * Whether `file` is a file this user may run. On Windows, any file counts.
152
+ * @param {string} file
153
+ * @param {boolean} windows
154
+ * @returns {boolean}
155
+ */
156
+ function isRunnableFile(file, windows) {
157
+ try {
158
+ if (!fs.statSync(file).isFile()) return false;
159
+ if (!windows) fs.accessSync(file, fs.constants.X_OK);
160
+ return true;
161
+ } catch {
162
+ // The shell skips a candidate the system cannot read: a missing folder, a
163
+ // stale mount, a symlink loop. `which` and execvp read PATH the same way.
164
+ return false;
165
+ }
166
+ }
167
+
168
+ /**
169
+ * The executable files on the search path named one of `names`, in the order
170
+ * a shell tries them. In each folder, it takes the first name that is a file
171
+ * this user may run. Nothing is started.
172
+ * @param {readonly string[]} names
173
+ * @param {{searchPath?: string, platform?: NodeJS.Platform}} [options]
174
+ * @returns {string[]}
175
+ */
176
+ export function executablesOnSearchPath(
177
+ names,
178
+ {
179
+ searchPath = process.env.PATH ?? process.env.Path ?? '',
180
+ platform = process.platform,
181
+ } = {},
182
+ ) {
183
+ const windows = platform === 'win32';
184
+ /** @type {string[]} */
185
+ const files = [];
186
+ for (const dir of searchPath.split(windows ? ';' : path.delimiter)) {
187
+ if (!dir) continue;
188
+ // One command per folder: the shell runs the first name it finds.
189
+ const file = names
190
+ .map(name => path.join(dir, name))
191
+ .find(candidate => isRunnableFile(candidate, windows));
192
+ if (file !== undefined) files.push(file);
193
+ }
194
+ return files;
195
+ }
196
+
149
197
  /**
150
198
  * Every `astryx` command on the search path, in the order a shell tries
151
199
  * them. The first row is the one that runs.
@@ -156,50 +204,30 @@ export function astryxCommandsOnSearchPath({
156
204
  searchPath = process.env.PATH ?? process.env.Path ?? '',
157
205
  platform = process.platform,
158
206
  } = {}) {
159
- const windows = platform === 'win32';
160
- const names = windows
161
- ? ['astryx.cmd', 'astryx.exe', 'astryx.ps1', 'astryx']
162
- : [COMMAND];
207
+ const names =
208
+ platform === 'win32'
209
+ ? ['astryx.cmd', 'astryx.exe', 'astryx.ps1', 'astryx']
210
+ : [COMMAND];
163
211
  /** @type {SearchPathCommand[]} */
164
212
  const rows = [];
165
213
  const seen = new Set();
166
- for (const dir of searchPath.split(windows ? ';' : path.delimiter)) {
167
- if (!dir) continue;
168
- for (const name of names) {
169
- const file = path.join(dir, name);
170
- let stat;
171
- try {
172
- stat = fs.statSync(file);
173
- } catch {
174
- continue;
175
- }
176
- if (!stat.isFile()) continue;
177
- if (!windows) {
178
- try {
179
- fs.accessSync(file, fs.constants.X_OK);
180
- } catch {
181
- continue;
182
- }
183
- }
184
- let key = file;
185
- try {
186
- key = fs.realpathSync(file);
187
- } catch {
188
- // Keep the path as found.
189
- }
190
- if (seen.has(key)) break;
191
- seen.add(key);
192
- const cliRoot = astryxCliRootOf(file);
193
- rows.push({
194
- file,
195
- astryx: cliRoot !== null || namesCliPackage(file),
196
- cliRoot,
197
- version: cliRoot ? cliVersionAt(cliRoot) : null,
198
- handsOff: cliRoot ? handsOffAt(cliRoot) : null,
199
- });
200
- // One command per folder: the shell runs the first name it finds.
201
- break;
214
+ for (const file of executablesOnSearchPath(names, {searchPath, platform})) {
215
+ let key = file;
216
+ try {
217
+ key = fs.realpathSync(file);
218
+ } catch {
219
+ // Keep the path as found.
202
220
  }
221
+ if (seen.has(key)) continue;
222
+ seen.add(key);
223
+ const cliRoot = astryxCliRootOf(file);
224
+ rows.push({
225
+ file,
226
+ astryx: cliRoot !== null || namesCliPackage(file),
227
+ cliRoot,
228
+ version: cliRoot ? cliVersionAt(cliRoot) : null,
229
+ handsOff: cliRoot ? handsOffAt(cliRoot) : null,
230
+ });
203
231
  }
204
232
  return rows;
205
233
  }
@@ -17,11 +17,11 @@ export function findLocalIntegrationManifest(packageDir: string): string;
17
17
  export function unwrapManifestExpression(node: any): any;
18
18
  /**
19
19
  * Find the object literal an integration manifest exports.
20
- * @param {ReturnType<typeof jscodeshift.withParser>} j
21
- * @param {ReturnType<ReturnType<typeof jscodeshift.withParser>>} ast
20
+ * @param {ReturnType<typeof import('jscodeshift').default.withParser>} j
21
+ * @param {ReturnType<ReturnType<typeof import('jscodeshift').default.withParser>>} ast
22
22
  * @returns {any|null}
23
23
  */
24
- export function findManifestObject(j: ReturnType<typeof jscodeshift.withParser>, ast: ReturnType<ReturnType<typeof jscodeshift.withParser>>): any | null;
24
+ export function findManifestObject(j: ReturnType<typeof import("jscodeshift").default.withParser>, ast: ReturnType<ReturnType<typeof import("jscodeshift").default.withParser>>): any | null;
25
25
  /**
26
26
  * Add a contribution root to an integration manifest, creating the manifest
27
27
  * when requested and none exists.
@@ -56,4 +56,3 @@ export class IntegrationRootConflictError extends Error {
56
56
  current: string;
57
57
  requested: string;
58
58
  }
59
- import jscodeshift from 'jscodeshift';
@@ -13,7 +13,6 @@ import * as fs from 'node:fs';
13
13
  import * as path from 'node:path';
14
14
  import {randomUUID} from 'node:crypto';
15
15
  import {publishNewFile} from '../fs/publish-file.mjs';
16
- import jscodeshift from 'jscodeshift';
17
16
  import {assertWithin} from '../fs/path-safety.mjs';
18
17
  import {findManifestPaths, loadManifestObject} from './integrations.mjs';
19
18
 
@@ -97,8 +96,8 @@ function propertyNamed(property, name) {
97
96
 
98
97
  /**
99
98
  * Find the object literal an integration manifest exports.
100
- * @param {ReturnType<typeof jscodeshift.withParser>} j
101
- * @param {ReturnType<ReturnType<typeof jscodeshift.withParser>>} ast
99
+ * @param {ReturnType<typeof import('jscodeshift').default.withParser>} j
100
+ * @param {ReturnType<ReturnType<typeof import('jscodeshift').default.withParser>>} ast
102
101
  * @returns {any|null}
103
102
  */
104
103
  export function findManifestObject(j, ast) {
@@ -290,6 +289,9 @@ export async function patchIntegrationRoot(
290
289
  const source = manifestExists
291
290
  ? fs.readFileSync(manifestFile, 'utf-8')
292
291
  : 'export default {};\n';
292
+ // The code-rewrite toolkit loads only to patch a manifest. Finding one,
293
+ // which many commands do through this module, never needs it.
294
+ const {default: jscodeshift} = await import('jscodeshift');
293
295
  const j = jscodeshift.withParser('tsx');
294
296
  let ast;
295
297
  try {
@@ -199,15 +199,22 @@ export function tryLock(lockDir: string, { now }?: {
199
199
  }): boolean;
200
200
  /**
201
201
  * Whether a process's arguments are this CLI's install of `version`, as
202
- * runNpm starts it: the program (`argv[0]`) is npm, or node running npm's
202
+ * runNpm starts it: the program (`argv[0]`) is npm, or a Node running npm's
203
203
  * entry file `npm-cli.js` (`argv[1]`), each exactly by name, and the arguments
204
- * include `install` and `@astryxdesign/cli@<version>`. A program that only has
205
- * `npm` somewhere in its name or arguments is not.
204
+ * include `install` and `@astryxdesign/cli@<version>`. A Node is one named
205
+ * `node` (with a version, such as `node22`), or one with the same file name
206
+ * as the Node runNpm starts npm with (`node`, by default this one), however
207
+ * it is named, such as `nodejs` or `node-linux-x64`. A program that only
208
+ * has `npm` somewhere in its name or arguments is not.
206
209
  * @param {string[]} argv
207
210
  * @param {string} version
211
+ * @param {{node?: string}} [options] `node`: the Node runNpm starts npm with
212
+ * (npmCommand's `execPath`; default: this one)
208
213
  * @returns {boolean}
209
214
  */
210
- export function isReleaseInstall(argv: string[], version: string): boolean;
215
+ export function isReleaseInstall(argv: string[], version: string, { node }?: {
216
+ node?: string;
217
+ }): boolean;
211
218
  /**
212
219
  * End the npm process group a stale lock records, only when that process is
213
220
  * surely the install the lock was taken for: its command line is this CLI's
@@ -823,15 +823,24 @@ function processFactsOf(pid, procRoot) {
823
823
 
824
824
  /**
825
825
  * Whether a process's arguments are this CLI's install of `version`, as
826
- * runNpm starts it: the program (`argv[0]`) is npm, or node running npm's
826
+ * runNpm starts it: the program (`argv[0]`) is npm, or a Node running npm's
827
827
  * entry file `npm-cli.js` (`argv[1]`), each exactly by name, and the arguments
828
- * include `install` and `@astryxdesign/cli@<version>`. A program that only has
829
- * `npm` somewhere in its name or arguments is not.
828
+ * include `install` and `@astryxdesign/cli@<version>`. A Node is one named
829
+ * `node` (with a version, such as `node22`), or one with the same file name
830
+ * as the Node runNpm starts npm with (`node`, by default this one), however
831
+ * it is named, such as `nodejs` or `node-linux-x64`. A program that only
832
+ * has `npm` somewhere in its name or arguments is not.
830
833
  * @param {string[]} argv
831
834
  * @param {string} version
835
+ * @param {{node?: string}} [options] `node`: the Node runNpm starts npm with
836
+ * (npmCommand's `execPath`; default: this one)
832
837
  * @returns {boolean}
833
838
  */
834
- export function isReleaseInstall(argv, version) {
839
+ export function isReleaseInstall(
840
+ argv,
841
+ version,
842
+ {node = process.execPath} = {},
843
+ ) {
835
844
  const name = (/** @type {string | undefined} */ arg) =>
836
845
  (arg ?? '')
837
846
  .split(/[\\/]/u)
@@ -839,9 +848,8 @@ export function isReleaseInstall(argv, version) {
839
848
  ?.replace(/\.(?:exe|cmd)$/iu, '')
840
849
  .toLowerCase() ?? '';
841
850
  const program = name(argv[0]);
842
- const npm =
843
- program === 'npm' ||
844
- (/^node(?:[-.\d]*)$/u.test(program) && name(argv[1]) === 'npm-cli.js');
851
+ const isNode = /^node(?:[-.\d]*)$/u.test(program) || program === name(node);
852
+ const npm = program === 'npm' || (isNode && name(argv[1]) === 'npm-cli.js');
845
853
  return (
846
854
  npm &&
847
855
  argv.includes('install') &&
@@ -262,7 +262,7 @@ export const doc = {
262
262
  {
263
263
  value: 'swizzle.copy',
264
264
  description:
265
- "An eject receipt: component name, owning package, output directory, files-copied count, the written file names, whether any file uses StyleX, and, when the owner has an issues URL, feedback ({issuesUrl, ghCommand?}): where to report the gap that led to swizzling. The envelope's package names the same owning package.",
265
+ "An eject receipt: component name, owning package, output directory, files-copied count, the copied file names (relative to the component folder; owner modules copied beside it start with ../), whether any file uses StyleX, and, when the owner has an issues URL, feedback ({issuesUrl, ghCommand?}): where to report the gap that led to swizzling. The envelope's package names the same owning package.",
266
266
  },
267
267
 
268
268
  // gap reports
@@ -16,6 +16,9 @@
16
16
  /**
17
17
  * @param {string} a
18
18
  * @param {string} b
19
+ * @param {number} [max] - The largest distance the caller can use. When
20
+ * given, a larger distance answers `max + 1`, and only the cells within
21
+ * `max` of the diagonal are computed.
19
22
  * @returns {number}
20
23
  */
21
- export function levenshteinDistance(a: string, b: string): number;
24
+ export function levenshteinDistance(a: string, b: string, max?: number): number;
@@ -16,9 +16,13 @@
16
16
  /**
17
17
  * @param {string} a
18
18
  * @param {string} b
19
+ * @param {number} [max] - The largest distance the caller can use. When
20
+ * given, a larger distance answers `max + 1`, and only the cells within
21
+ * `max` of the diagonal are computed.
19
22
  * @returns {number}
20
23
  */
21
- export function levenshteinDistance(a, b) {
24
+ export function levenshteinDistance(a, b, max) {
25
+ if (max !== undefined) return distanceWithin(a, b, max);
22
26
  const m = a.length, n = b.length;
23
27
  // Early exit: the distance is always ≥ |m − n|, so once the length gap
24
28
  // exceeds the loosest fuzzy-match threshold any caller uses (the hook
@@ -39,3 +43,42 @@ export function levenshteinDistance(a, b) {
39
43
  }
40
44
  return dp[m][n];
41
45
  }
46
+
47
+ /**
48
+ * The edit distance between `a` and `b` when it is at most `max`, or
49
+ * `max + 1` when it is more. A path through a cell more than `max` from the
50
+ * diagonal costs more than `max`, so only that band is computed.
51
+ * @param {string} a
52
+ * @param {string} b
53
+ * @param {number} max
54
+ * @returns {number}
55
+ */
56
+ function distanceWithin(a, b, max) {
57
+ const over = max + 1;
58
+ if (Math.abs(a.length - b.length) > max) return over;
59
+ let previous = new Array(b.length + 1).fill(over);
60
+ let current = new Array(b.length + 1).fill(over);
61
+ for (let j = 0; j <= Math.min(b.length, max); j++) previous[j] = j;
62
+ for (let i = 1; i <= a.length; i++) {
63
+ current.fill(over);
64
+ const from = Math.max(1, i - max);
65
+ const to = Math.min(b.length, i + max);
66
+ if (i <= max) current[0] = i;
67
+ let rowMin = current[0];
68
+ for (let j = from; j <= to; j++) {
69
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
70
+ const value = Math.min(
71
+ previous[j - 1] + cost,
72
+ previous[j] + 1,
73
+ current[j - 1] + 1,
74
+ over,
75
+ );
76
+ current[j] = value;
77
+ if (value < rowMin) rowMin = value;
78
+ }
79
+ // Every later cell costs at least this row's least.
80
+ if (rowMin >= over) return over;
81
+ [previous, current] = [current, previous];
82
+ }
83
+ return Math.min(previous[b.length], over);
84
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.9-canary.ffa495b",
3
+ "version": "0.7.9",
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,10 +124,10 @@
124
124
  "zod": "^4.4.3"
125
125
  },
126
126
  "peerDependencies": {
127
- "@astryxdesign/charts": "0.7.9-canary.ffa495b",
128
- "@astryxdesign/core": "0.7.9-canary.ffa495b",
129
- "@astryxdesign/lab": "0.7.9-canary.ffa495b",
130
- "@astryxdesign/theme-neutral": "0.7.9-canary.ffa495b"
127
+ "@astryxdesign/charts": "*",
128
+ "@astryxdesign/core": "*",
129
+ "@astryxdesign/lab": "*",
130
+ "@astryxdesign/theme-neutral": "*"
131
131
  },
132
132
  "peerDependenciesMeta": {
133
133
  "@astryxdesign/charts": {
@@ -144,10 +144,10 @@
144
144
  }
145
145
  },
146
146
  "devDependencies": {
147
- "@astryxdesign/charts": "0.7.9-canary.ffa495b",
148
- "@astryxdesign/core": "0.7.9-canary.ffa495b",
149
- "@astryxdesign/lab": "0.7.9-canary.ffa495b",
150
- "@astryxdesign/theme-neutral": "0.7.9-canary.ffa495b",
147
+ "@astryxdesign/charts": "*",
148
+ "@astryxdesign/core": "*",
149
+ "@astryxdesign/lab": "*",
150
+ "@astryxdesign/theme-neutral": "*",
151
151
  "@heroicons/react": "^2.2.0",
152
152
  "@stylexjs/stylex": "^0.19.0",
153
153
  "@types/babel__core": "^7.20.5",
@@ -1,8 +0,0 @@
1
- // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
- // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
-
4
- /**
5
- * Check if `gh` CLI is installed and authenticated.
6
- * Returns true if ready, false otherwise.
7
- */
8
- export function checkGhCli(): boolean;
@@ -1,22 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file GitHub utilities for Astryx CLI
5
- *
6
- * Shared helpers for interacting with the GitHub CLI (`gh`).
7
- */
8
-
9
- import {execFileSync} from 'node:child_process';
10
-
11
- /**
12
- * Check if `gh` CLI is installed and authenticated.
13
- * Returns true if ready, false otherwise.
14
- */
15
- export function checkGhCli() {
16
- try {
17
- execFileSync('gh', ['auth', 'status'], {stdio: 'ignore'});
18
- return true;
19
- } catch {
20
- return false;
21
- }
22
- }