@astryxdesign/cli 0.7.11-canary.ed0adf3 → 0.7.11

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 CHANGED
@@ -1,5 +1,56 @@
1
1
  # @xds/cli
2
2
 
3
+ # 0.7.11
4
+
5
+ #### New Features
6
+
7
+ - `astryx build` ranks Core blocks of component families its picker was not fitted with somewhat better: the block picker's doc-side word weights are refitted from paraphrases of each block's own source. (#10355)
8
+
9
+ #### Fixes
10
+
11
+ - `astryx build` names its two alternative page templates in the same order it chooses the start from, so the three templates it shows for a whole page are its best three. The start, the number of alternatives, the blocks and the JSON shape are unchanged. (#10357)
12
+ - `astryx build --type doc` and `--type theme` now point to `astryx search <query> --type doc` or `--type theme`: a build kit has no docs or themes, so build says so once on stderr and names the search that finds them. Stdout, JSON output and exit codes are unchanged. (#10401)
13
+ - `astryx doctor` no longer warns that no theme is wired in an app that imports its themes itself. Without a generated theme module or a package.json `astryx.theme`, the `themes` check now passes when the source of the app imports a theme's built module or stylesheet (the imports `theme add` writes) or passes a theme to `Theme`, followed through module-scope variables, `defineTheme({extends})`, re-exports and installed packages to its package, and names the file. Only a theme whose package is installed, or a local theme, counts. A theme passed to `Theme` that doctor cannot trace (a prop, a function result, a variable declared inside a component) is reported as not confirmed (info), not as missing. (#10353)
14
+ - The CLI's semver range check reads `^0` as any 0.x.y and `^0.0` as any 0.0.y, and reads a hyphen range (`1.0.0 - 2.0.0`) as inclusive bounds, with a partial upper bound (`1.0.0 - 2`) covering its whole series as npm does. Before, `^0` and `^0.0` were locked to a single patch version and a hyphen range could never match, so `astryx doctor` and the peer-version checks reported a false mismatch for projects that declare those ranges. (#10184)
15
+ - The reminder to run `astryx init` in a project that has not run it no longer prints before every command. It now prints after a command that succeeds, at most once a day per project, recorded in the per-user state as the daily hints are. It does not print with `--json`, after a command that fails, or when `CI` is set. `astryx doctor` still reports the missing setup in its agent-docs check every time. No JSON shape or exit code changes. (#10343)
16
+ - In a folder inside an Astryx project whose own `package.json` declares no Astryx package, such as a tool folder that installs its own `@astryxdesign/core`, the setup reminder's `init` command now names the project's release, as run from the project's folder: the project's own CLI when it installs one, otherwise the package runner pinned to the project's Core, such as `npx @astryxdesign/cli@0.7.3 init`. It used to pin the release of the CLI that answered the run, whatever the project records. No JSON shape or exit code changes. (#10343)
17
+ - `astryx experimental render`: a page outside a project now renders. Outside a project (no Core or CLI the folder reads, and no package.json that declares one), the page takes the `@astryxdesign/*` packages its folder lacks, and the integrations a host approves, from the copy the CLI itself runs with, instead of failing with ERR_RENDER_MISSING_DEPENDENCY. React and StyleX come from that copy too, so the page loads one copy of each, even in a React app that installs its own. When that copy's Core cannot be downloaded, a page that needs it fails with ERR_VERSIONS_UNAVAILABLE, as other commands that read Core do. Inside a project, the page uses only the project's own packages. (#10362)
18
+ - A link to a topic that an integration replaces under the same name opens the replacement. In an app whose integration replaced `theme` or `getting-started`, `doctor` reported Core's links to them as naming no doc. (#10342)
19
+ - `swizzle` no longer copies a component's browser test harnesses (`*.spec.ts`, `*.spec.tsx`, such as Item's `ItemMarkerColumns.a11y.chromium.spec.ts`) when the installed Core source holds them: `@astryxdesign/core` 0.7.5 and earlier, or Core's repository source. They import Playwright and an unpublished test package, so a project that swizzled such a component failed to type-check or build. Core 0.7.6 and later ship no harnesses, so swizzling from them is unchanged. (#10230)
20
+ - `astryx theme build` no longer depends on the order it loads the core component docs. A parent doc that lists a sub-component by name only, such as `Avatar.doc.mjs` listing `AvatarStatusDot`, erased the values the sub-component's own doc declares when it loaded after that doc; when `Avatar.doc.mjs` loaded last, `avatar-status-dot` `variant:success` counted as a custom value. The build now merges every doc's entry for a component. (#10288)
21
+ - `astryx integration verify` no longer reports `theme_module_stale` for a theme whose built module differs only in the command its comment says built it, such as a theme built with `yarn astryx` and verified where `pnpm exec astryx` runs. Any other difference still fails. (#10344)
22
+
23
+ #### Performance
24
+
25
+ - A compact or full hook list, and the suggestions for an unknown hook name, list each of Core's folders once. Before, they listed a folder again for each hook they looked up. (#10324)
26
+ - A search, build or component read lists each folder once. A process that runs several reads, such as a docs site's search or an agent harness, reuses a folder's listing once the folder has stayed unchanged for two seconds. A later read lists the folder again after an entry is added, removed or renamed. (#10274)
27
+ - Within one operation, component discovery reads each component doc once, and the component matcher looks for each component's doc once, not once for each name they resolve. Resolving 30 names that only the matcher finds, such as names in another case, makes 14,794 file-system calls instead of 305,108. Results are unchanged. (#10277)
28
+
29
+ #### Documentation
30
+
31
+ - The Authoring guides (Quick Start, Field reference, Building Blocks, Ship, Help, and Make your integration work globally) now carry the keyword "authoring", so `astryx search authoring` lists them right after the Authoring overview instead of after API function pages. (#10354)
32
+ - `astryx build --help` lists every value `--type` accepts (component, hook, doc, template, theme), matching the invalid-type error and what build actually runs, and says that `doc` and `theme` give an empty kit, since the kit has no doc or theme group. A test keeps the help text, the choices, the API doc and the error message on build and search naming the same set, and checks what each value returns. (#10361)
33
+ - Getting Started has an Upgrade section: upgrade every Astryx package your app lists in one command, to the same release, then run `astryx upgrade`. If your package manager holds new releases back, exempt the whole `@astryxdesign/*` scope, not only some of its packages. (#10241)
34
+ - The custom theme guide names the files of a local theme, including the same-stem descriptor `theme add` reads. (#10347)
35
+ - The CLI's bundled colour token docs say the status icon colours (`--color-icon-<status>`) paint status marks on the page or a card, such as a StatusDot. (#10204)
36
+ - New block, "Table — Selection in the Leading Mark": row selection with no checkbox column. Each row shows its avatar, and the checkbox takes the avatar's slot while a mouse is over it, on keyboard focus, and on every row once anything is selected. On touch screens the checkbox always shows. It uses the existing `useTableSelectionState` and renders the checkboxes in the name column, so no new Table API is involved. (#10395)
37
+
38
+ #### Other Changes
39
+
40
+ - Internal: the export reader can report type-only exports and map a module's whole public surface in one pass. No change to any command's output. (#10365)
41
+
42
+ #### Contributors
43
+
44
+ Thanks to everyone who contributed to this release:
45
+
46
+ - @cixzhang
47
+ - @josephfarina
48
+ - @thecodebasedot
49
+ - @utsavo-afk
50
+ - @vjeux
51
+
52
+ ---
53
+
3
54
  # 0.7.10
4
55
 
5
56
  #### New Features
@@ -0,0 +1,15 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ exampleFor: 'useTableSelectionState',
7
+ alsoExampleFor: ['Table'],
8
+ name: 'Table — Selection in the Leading Mark',
9
+ displayName: 'Table — Selection in the Leading Mark',
10
+ description:
11
+ 'Selection without a checkbox column: each item shows its avatar, and the checkbox takes the avatar slot while a mouse is over it, on keyboard focus, and everywhere once anything is selected; on touch screens it always shows. The state comes from useTableSelectionState, and the checkboxes render in the name column instead of the useTableSelection column, so checked items get no aria-selected or highlight; add them if needed.',
12
+ isReady: true,
13
+ aspectRatio: 16 / 9,
14
+ componentsUsed: ['Table', 'CheckboxInput', 'Avatar'],
15
+ };
@@ -0,0 +1,134 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {useState} from 'react';
6
+ import * as stylex from '@stylexjs/stylex';
7
+ import {Avatar} from '@astryxdesign/core/Avatar';
8
+ import {CheckboxInput} from '@astryxdesign/core/CheckboxInput';
9
+ import {HStack} from '@astryxdesign/core/HStack';
10
+ import {useContainerReveal} from '@astryxdesign/core/hooks';
11
+ import {
12
+ Table,
13
+ proportional,
14
+ useTableSelectionState,
15
+ } from '@astryxdesign/core/Table';
16
+ import type {TableColumn} from '@astryxdesign/core/Table';
17
+ import {colorVars, spacingVars} from '@astryxdesign/core/theme/tokens.stylex';
18
+ import {mergeProps} from '@astryxdesign/core/utils';
19
+
20
+ interface Automation extends Record<string, unknown> {
21
+ id: string;
22
+ name: string;
23
+ owner: string;
24
+ schedule: string;
25
+ }
26
+
27
+ const automations: Automation[] = [
28
+ {id: '1', name: 'Nightly backup', owner: 'Alice', schedule: 'Daily, 2:00'},
29
+ {id: '2', name: 'Weekly digest', owner: 'Bob', schedule: 'Mondays, 9:00'},
30
+ {id: '3', name: 'Cache warmup', owner: 'Diana', schedule: 'Hourly'},
31
+ {id: '4', name: 'Usage report', owner: 'Eve', schedule: 'Monthly, 1st'},
32
+ ];
33
+
34
+ const styles = stylex.create({
35
+ mark: {
36
+ display: 'grid',
37
+ placeItems: 'center',
38
+ flexShrink: 0,
39
+ },
40
+ // A flex layer is exactly as tall as the 24px avatar; a block layer
41
+ // follows the taller line box and lets the avatar's edge show under the
42
+ // checkbox.
43
+ layer: {
44
+ gridArea: '1 / 1',
45
+ display: 'flex',
46
+ },
47
+ // The checkbox covers the avatar while it shows, so the two never read as
48
+ // one mark.
49
+ checkbox: {
50
+ borderRadius: '50%',
51
+ backgroundColor: colorVars['--color-background-surface'],
52
+ },
53
+ name: {
54
+ paddingInlineStart: spacingVars['--spacing-1'],
55
+ },
56
+ });
57
+
58
+ export default function TableLeadingMarkSelection() {
59
+ const [selectedKeys, setSelectedKeys] = useState<Set<string>>(new Set());
60
+ // The mark reveals its checkbox on hover and keyboard focus, and always
61
+ // shows it on touch.
62
+ const {getContainerProps, getContentRevealProps} = useContainerReveal();
63
+ const {selectionConfig, selectionState} = useTableSelectionState<Automation>({
64
+ data: automations,
65
+ idKey: 'id',
66
+ selectedKeys,
67
+ setSelectedKeys,
68
+ });
69
+
70
+ const columns: TableColumn<Automation>[] = [
71
+ {
72
+ key: 'name',
73
+ header: (
74
+ <HStack gap={2} vAlign="center">
75
+ <CheckboxInput
76
+ label="Select all automations"
77
+ isLabelHidden
78
+ value={
79
+ selectionConfig.getIsAllSelected()
80
+ ? true
81
+ : selectionConfig.getIsIndeterminate?.()
82
+ ? 'indeterminate'
83
+ : false
84
+ }
85
+ onChange={checked =>
86
+ selectionConfig.onSelectAll({isAllSelected: checked})
87
+ }
88
+ />
89
+ Automation
90
+ </HStack>
91
+ ),
92
+ width: proportional(2),
93
+ renderCell: item => {
94
+ const isSelected = selectionConfig.getIsItemSelected(item);
95
+ return (
96
+ <HStack gap={2} vAlign="center">
97
+ <span
98
+ {...mergeProps(stylex.props(styles.mark), getContainerProps())}>
99
+ {selectionState.hasSelection ? null : (
100
+ <span {...stylex.props(styles.layer)}>
101
+ <Avatar name={item.owner} size="sm" tooltip={false} />
102
+ </span>
103
+ )}
104
+ <span
105
+ {...mergeProps(
106
+ stylex.props(styles.layer, styles.checkbox),
107
+ getContentRevealProps({
108
+ isLayoutPreserved: true,
109
+ forceVisibility: selectionState.hasSelection
110
+ ? 'shown'
111
+ : undefined,
112
+ }),
113
+ )}>
114
+ <CheckboxInput
115
+ label={`Select ${item.name}`}
116
+ isLabelHidden
117
+ value={isSelected}
118
+ onChange={checked =>
119
+ selectionConfig.onSelectItem({item, isSelected: checked})
120
+ }
121
+ />
122
+ </span>
123
+ </span>
124
+ <span {...stylex.props(styles.name)}>{item.name}</span>
125
+ </HStack>
126
+ );
127
+ },
128
+ },
129
+ {key: 'owner', header: 'Owner', width: proportional(1)},
130
+ {key: 'schedule', header: 'Schedule', width: proportional(1)},
131
+ ];
132
+
133
+ return <Table data={automations} columns={columns} idKey="id" />;
134
+ }
@@ -510,9 +510,9 @@ export const CommandDocKindSchema: z.ZodObject<{
510
510
  when: z.ZodString;
511
511
  }, z.core.$loose>>>;
512
512
  outsideProject: z.ZodOptional<z.ZodEnum<{
513
+ own: "own";
513
514
  same: "same";
514
515
  refuse: "refuse";
515
- own: "own";
516
516
  }>>;
517
517
  related: z.ZodOptional<z.ZodArray<z.ZodString>>;
518
518
  notes: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -66,6 +66,24 @@ function printPlaybook(playbook) {
66
66
  );
67
67
  }
68
68
 
69
+ /** The domains search finds that a build kit has no group for. */
70
+ const SEARCH_ONLY_TYPES = ['doc', 'theme'];
71
+
72
+ /**
73
+ * In text mode, say once on stderr that a kit has no docs or themes and name
74
+ * the search that finds them, as other command notes do (`search`,
75
+ * `integration pack --check`). Stdout, the JSON envelope and the exit status
76
+ * stay as they are.
77
+ * @param {string | undefined} type
78
+ * @param {boolean} json
79
+ */
80
+ function pointToSearch(type, json) {
81
+ if (json || !type || !SEARCH_ONLY_TYPES.includes(type)) return;
82
+ console.error(
83
+ `Note: a build kit has no ${type}s. Find them with \`${formatCliCommand(`search <query> --type ${type}`)}\`.`,
84
+ );
85
+ }
86
+
69
87
  /**
70
88
  * @param {import('commander').Command} program
71
89
  */
@@ -89,6 +107,7 @@ export function registerBuild(program) {
89
107
  // one. Counting it as a result keeps "what did this run answer with"
90
108
  // true for the no-argument form too.
91
109
  const playbook = resultSet({count: 1, resultKind: 'doc'});
110
+ pointToSearch(options.type, json);
92
111
  if (json) {
93
112
  jsonOut(result);
94
113
  return playbook;
@@ -101,8 +120,7 @@ export function registerBuild(program) {
101
120
  // Parse --limit to a number; the API validates it (positive integer) and
102
121
  // throws ERR_INVALID_ARGUMENT, so we pass NaN through rather than
103
122
  // pre-rejecting with a generic code here (parity with `search`).
104
- const limit =
105
- options.limit != null ? Number(options.limit) : 60;
123
+ const limit = options.limit != null ? Number(options.limit) : 60;
106
124
 
107
125
  /** @type {import('../../../api/build/build.type.mjs').BuildKitResponse} */
108
126
  let result;
@@ -151,6 +169,7 @@ export function registerBuild(program) {
151
169
  jsonOut(result);
152
170
  return answered;
153
171
  }
172
+ pointToSearch(options.type, json);
154
173
 
155
174
  if (!hasResults && !start) {
156
175
  emit(
@@ -227,7 +246,13 @@ export function registerBuild(program) {
227
246
  start,
228
247
  verbose
229
248
  ? {
230
- fields: ['name', 'package', 'displayName', 'description', 'command'],
249
+ fields: [
250
+ 'name',
251
+ 'package',
252
+ 'displayName',
253
+ 'description',
254
+ 'command',
255
+ ],
231
256
  format: {command: formatCliCommand},
232
257
  }
233
258
  : brief(['name', 'package', 'description', 'command']),
@@ -242,7 +267,9 @@ export function registerBuild(program) {
242
267
  ),
243
268
  records(
244
269
  start.alternatives,
245
- verbose ? full : brief(['name', 'package', 'description', 'command']),
270
+ verbose
271
+ ? full
272
+ : brief(['name', 'package', 'description', 'command']),
246
273
  ),
247
274
  );
248
275
  }
@@ -283,7 +310,9 @@ export function registerBuild(program) {
283
310
  ? [
284
311
  records(
285
312
  shown(domain),
286
- verbose ? full : brief(['name', 'package', 'deprecated', 'description']),
313
+ verbose
314
+ ? full
315
+ : brief(['name', 'package', 'deprecated', 'description']),
287
316
  ),
288
317
  ]
289
318
  : []),
@@ -22,7 +22,8 @@ import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
22
22
  import {findConfigPath} from '../../foundation/config/config-path.mjs';
23
23
  import {API_VERSION, setJsonMode} from '../../foundation/response/json.mjs';
24
24
  import {answeredBy, runChoice} from '../../foundation/release/run-context.mjs';
25
- import {cliInstallAdvice, installFolder} from '../../foundation/release/notices.mjs';
25
+ import {cliInstallAdvice, installFolder, projectRelease, SETUP_REMINDER_KEY, takeNotice} from '../../foundation/release/notices.mjs';
26
+ import {isCi} from '../../foundation/release/update-notice-env.mjs';
26
27
  import {buildManifest} from './lib/manifest.mjs';
27
28
  import {cliError} from './lib/cli-error.mjs';
28
29
  import {section, text, records} from './formatters/index.mjs';
@@ -683,8 +684,11 @@ export async function createProgram({argv} = {}) {
683
684
  * repository root — see isAstryxPromptInReach), remind the user/agent that
684
685
  * setup is missing.
685
686
  *
686
- * Uses `preAction` (not postAction) so it fires for EVERY valid command — even
687
- * ones whose action errors or calls process.exit (postAction is skipped then).
687
+ * `preAction` decides the line; `postAction` prints it after a command that
688
+ * succeeds, at most once a day per project, recorded in the per-user state
689
+ * as the daily hint is, and never under CI. An agent that leaves `init` to
690
+ * its person then sees it once, not before every command. Doctor reports
691
+ * the missing setup in its own check every time.
688
692
  *
689
693
  * Suppressed in --json: that is machine output with a strict clean stdout+stderr
690
694
  * contract (json-shim.test: "error envelopes have empty stderr"), and --json
@@ -695,8 +699,29 @@ export async function createProgram({argv} = {}) {
695
699
  * or one that neither installs nor declares Astryx), and inside the CLI's own
696
700
  * source checkout when it runs from there.
697
701
  */
702
+ /** @type {{root: string, line: string} | null} */
703
+ let setupReminder = null;
704
+ /**
705
+ * Keep the reminder for `root` until the command ends.
706
+ * @param {string} root
707
+ * @param {string} line
708
+ */
709
+ const remindSetup = (root, line) => {
710
+ setupReminder = {root, line};
711
+ };
712
+ program.hook('postAction', () => {
713
+ try {
714
+ const reminder = setupReminder;
715
+ setupReminder = null;
716
+ if (reminder == null || process.exitCode || isCi(process.env)) return;
717
+ if (takeNotice(`${SETUP_REMINDER_KEY}${reminder.root}`)) console.error(reminder.line);
718
+ } catch {
719
+ // Never let the nudge break a command.
720
+ }
721
+ });
698
722
  program.hook('preAction', (thisCommand, actionCommand) => {
699
723
  try {
724
+ setupReminder = null;
700
725
  if (program.opts().json) return; // machine mode — keep --json output clean
701
726
  if (SETUP_NUDGE_EXEMPT.has(actionCommand.name())) return;
702
727
  const cwd = process.cwd();
@@ -738,9 +763,12 @@ export async function createProgram({argv} = {}) {
738
763
  // before it, so the command is the picker's for that folder, never the
739
764
  // bare `astryx` name a package runner would fetch from the registry
740
765
  // (spec AST-081 FR5).
766
+ // The command names the project's release, as run from its folder,
767
+ // never the Core this folder installs for itself.
741
768
  if (target.moved) {
742
- console.error(
743
- setupNudge(getCliInvocation(target.dir), {before: `cd ${quoteCommandArgument(target.dir)}`}).trimEnd(),
769
+ remindSetup(
770
+ target.dir,
771
+ setupNudge(getCliInvocation(target.dir, {release: projectRelease(target.dir)}), {before: `cd ${quoteCommandArgument(target.dir)}`}).trimEnd(),
744
772
  );
745
773
  return;
746
774
  }
@@ -750,13 +778,14 @@ export async function createProgram({argv} = {}) {
750
778
  // version, then run that CLI's init.
751
779
  const add = cliInstallAdvice({cwd, core: choice.coreVersion});
752
780
  if (add?.command) {
753
- console.error(
781
+ remindSetup(
782
+ add.root,
754
783
  setupNudge(getCliInvocation(add.root, {installed: true}), {before: add.command}).trimEnd(),
755
784
  );
756
785
  return;
757
786
  }
758
787
  }
759
- console.error(setupNudge(getCliInvocation(cwd)).trimEnd());
788
+ remindSetup(agentDocsTargetDir(cwd), setupNudge(getCliInvocation(cwd)).trimEnd());
760
789
  } catch {
761
790
  // Never let the nudge break a command.
762
791
  }
@@ -1,6 +1,14 @@
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
+ * The file a relative import names: the path itself, then each module
6
+ * extension, then a folder's index. Null for a bare specifier or no file.
7
+ * @param {unknown} specifier
8
+ * @param {string} fromFile absolute path of the importing file
9
+ * @returns {string|null}
10
+ */
11
+ export function resolveLocalModule(specifier: unknown, fromFile: string): string | null;
4
12
  /**
5
13
  * The first module, from `file` through its relative re-exports, that does
6
14
  * not parse, with the parser's message; null when every one parses.
@@ -43,6 +51,28 @@ export function moduleExportSource(file: string, exportName: string, seen?: Set<
43
51
  * @returns {string[] | null}
44
52
  */
45
53
  export function moduleExportNames(file: string): string[] | null;
54
+ /**
55
+ * Every export of a module with where it is declared, in one pass: the same
56
+ * answers as {@link moduleExportOrigin} for each name, read once per module.
57
+ * Pass one `memo` to calls that read the same package, so a module behind
58
+ * many barrels is read once; a memo keeps value and type reads apart, and
59
+ * nothing is kept between memos. One difference follows ESM where
60
+ * {@link moduleExportOrigin} does not: a name re-exported by name from a
61
+ * module that cannot be followed is absent, never filled from `export *`.
62
+ * @param {string} file
63
+ * @param {{types?: boolean, memo?: Map<string, Map<string, {file: string, name: string}>>}} [options]
64
+ * @returns {Map<string, {file: string, name: string}>}
65
+ */
66
+ export function moduleExportOrigins(file: string, { types, memo }?: {
67
+ types?: boolean;
68
+ memo?: Map<string, Map<string, {
69
+ file: string;
70
+ name: string;
71
+ }>>;
72
+ }): Map<string, {
73
+ file: string;
74
+ name: string;
75
+ }>;
46
76
  /**
47
77
  * @typedef {{verdict: 'exports'} | {verdict: 'lacks'} | {verdict: 'unknown', reason: string}} ExportVerdict
48
78
  */
@@ -84,12 +114,16 @@ export function staticExportObject(file: string, exportNames: readonly string[])
84
114
  * has there, without executing anything: local re-exports, renames, and
85
115
  * imported bindings a module exports again are followed. Two exports are the
86
116
  * same value when their origins are equal. Null when it cannot be proved.
117
+ * With `types`, type-only exports and type declarations are followed too.
87
118
  * @param {string} file
88
119
  * @param {string} exportName
89
120
  * @param {Set<string>} [seen]
121
+ * @param {{types?: boolean}} [options]
90
122
  * @returns {{file: string, name: string} | null}
91
123
  */
92
- export function moduleExportOrigin(file: string, exportName: string, seen?: Set<string>): {
124
+ export function moduleExportOrigin(file: string, exportName: string, seen?: Set<string>, { types }?: {
125
+ types?: boolean;
126
+ }): {
93
127
  file: string;
94
128
  name: string;
95
129
  } | null;
@@ -114,12 +148,16 @@ export function exportOriginVerdict(file: string, exportName: string): ExportOri
114
148
  * named exports and, through `export *` from local files and installed
115
149
  * packages, theirs. Unlike {@link moduleExportNames}, it never gives up on an
116
150
  * `export *`: what it cannot read is left out. Type-only
117
- * exports and `default` are left out. Sorted.
151
+ * exports are left out unless `types` asks for them; `default` always is.
152
+ * Sorted.
118
153
  * @param {string} file
119
154
  * @param {Set<string>} [seen]
155
+ * @param {{types?: boolean}} [options]
120
156
  * @returns {string[]}
121
157
  */
122
- export function followedExportNames(file: string, seen?: Set<string>): string[];
158
+ export function followedExportNames(file: string, seen?: Set<string>, { types }?: {
159
+ types?: boolean;
160
+ }): string[];
123
161
  /**
124
162
  * What a module's runtime export is, read without running it: `component`
125
163
  * for a function, a class, or a value a call returns (`forwardRef(...)`);
@@ -207,6 +245,26 @@ export function staticExportBindings(file: string, exportName: string): Map<stri
207
245
  * enumerable, so the object compares and serializes as its literal properties.
208
246
  */
209
247
  export const HAS_COMPUTED: unique symbol;
248
+ export type OriginsRead = {
249
+ types: boolean;
250
+ /**
251
+ * finished maps, keyed by read mode and file
252
+ */
253
+ memo: Map<string, Map<string, {
254
+ file: string;
255
+ name: string;
256
+ }>>;
257
+ /**
258
+ * the modules being read now, by memo key
259
+ */
260
+ reading: Map<string, {
261
+ depth: number;
262
+ origins: Map<string, {
263
+ file: string;
264
+ name: string;
265
+ }>;
266
+ }>;
267
+ };
210
268
  export type ExportVerdict = {
211
269
  verdict: "exports";
212
270
  } | {
@@ -198,8 +198,14 @@ function collectNodesOfType(node, type, found) {
198
198
  return found;
199
199
  }
200
200
 
201
- /** @param {unknown} specifier @param {string} fromFile */
202
- function resolveLocalModule(specifier, fromFile) {
201
+ /**
202
+ * The file a relative import names: the path itself, then each module
203
+ * extension, then a folder's index. Null for a bare specifier or no file.
204
+ * @param {unknown} specifier
205
+ * @param {string} fromFile absolute path of the importing file
206
+ * @returns {string|null}
207
+ */
208
+ export function resolveLocalModule(specifier, fromFile) {
203
209
  if (typeof specifier !== 'string' || !specifier.startsWith('.')) return null;
204
210
  const base = path.resolve(path.dirname(fromFile), specifier);
205
211
  const candidates = [
@@ -347,17 +353,43 @@ export function unfollowedReexports(file) {
347
353
  return [...missing].sort();
348
354
  }
349
355
 
350
- /** @param {any} declaration @param {string} exportName */
351
- function declarationExports(declaration, exportName) {
352
- if (!declaration || declaration.declare === true) return false;
353
- if (['FunctionDeclaration', 'ClassDeclaration'].includes(declaration.type)) {
354
- return declaration.id?.name === exportName;
356
+ /** Declarations that name a type, which a type-aware read also follows. */
357
+ const TYPE_DECLARATIONS = [
358
+ 'TSInterfaceDeclaration',
359
+ 'TSTypeAliasDeclaration',
360
+ 'TSEnumDeclaration',
361
+ 'TSModuleDeclaration',
362
+ 'TSDeclareFunction',
363
+ ];
364
+
365
+ /**
366
+ * @param {any} declaration
367
+ * @param {string} exportName
368
+ * @param {boolean} [types] also count type declarations and `declare` ones
369
+ */
370
+ function declarationExports(declaration, exportName, types = false) {
371
+ return declaredNames(declaration, types).includes(exportName);
372
+ }
373
+
374
+ /**
375
+ * The names an exported declaration binds.
376
+ * @param {any} declaration
377
+ * @param {boolean} [types] also count type declarations and `declare` ones
378
+ * @returns {string[]}
379
+ */
380
+ function declaredNames(declaration, types = false) {
381
+ if (!declaration || (declaration.declare === true && !types)) return [];
382
+ if (
383
+ ['FunctionDeclaration', 'ClassDeclaration'].includes(declaration.type) ||
384
+ (types && TYPE_DECLARATIONS.includes(declaration.type))
385
+ ) {
386
+ const name = declaration.id?.name;
387
+ return typeof name === 'string' ? [name] : [];
355
388
  }
356
- if (declaration.type !== 'VariableDeclaration') return false;
357
- return declaration.declarations.some(
358
- (/** @type {any} */ item) =>
359
- item.id?.type === 'Identifier' && item.id.name === exportName,
360
- );
389
+ if (declaration.type !== 'VariableDeclaration') return [];
390
+ return declaration.declarations
391
+ .filter((/** @type {any} */ item) => item.id?.type === 'Identifier')
392
+ .map((/** @type {any} */ item) => item.id.name);
361
393
  }
362
394
 
363
395
  /** @param {any} declaration */
@@ -574,6 +606,139 @@ export function moduleExportNames(file) {
574
606
  return [...names].sort();
575
607
  }
576
608
 
609
+ /**
610
+ * Every export of a module with where it is declared, in one pass: the same
611
+ * answers as {@link moduleExportOrigin} for each name, read once per module.
612
+ * Pass one `memo` to calls that read the same package, so a module behind
613
+ * many barrels is read once; a memo keeps value and type reads apart, and
614
+ * nothing is kept between memos. One difference follows ESM where
615
+ * {@link moduleExportOrigin} does not: a name re-exported by name from a
616
+ * module that cannot be followed is absent, never filled from `export *`.
617
+ * @param {string} file
618
+ * @param {{types?: boolean, memo?: Map<string, Map<string, {file: string, name: string}>>}} [options]
619
+ * @returns {Map<string, {file: string, name: string}>}
620
+ */
621
+ export function moduleExportOrigins(
622
+ file,
623
+ {types = false, memo = new Map()} = {},
624
+ ) {
625
+ return exportOriginsOf(file, {types, memo, reading: new Map()}).origins;
626
+ }
627
+
628
+ /**
629
+ * @typedef {object} OriginsRead
630
+ * @property {boolean} types
631
+ * @property {Map<string, Map<string, {file: string, name: string}>>} memo
632
+ * finished maps, keyed by read mode and file
633
+ * @property {Map<string, {depth: number, origins: Map<string, {file: string, name: string}>}>} reading
634
+ * the modules being read now, by memo key
635
+ */
636
+
637
+ /**
638
+ * One module's export map, and the shallowest module still being read that
639
+ * it depends on (`low`). A map that depends on a module above it in an
640
+ * `export *` cycle is incomplete until that module finishes, so only a map
641
+ * whose `low` is its own depth goes in the memo.
642
+ * @param {string} file
643
+ * @param {OriginsRead} read
644
+ * @returns {{origins: Map<string, {file: string, name: string}>, low: number}}
645
+ */
646
+ function exportOriginsOf(file, read) {
647
+ const key = `${read.types ? 'type' : 'value'}\0${file}`;
648
+ const known = read.memo.get(key);
649
+ if (known) return {origins: known, low: Infinity};
650
+ const open = read.reading.get(key);
651
+ // A module reached again through a cycle reads as what is known so far.
652
+ if (open) return {origins: open.origins, low: open.depth};
653
+ const depth = read.reading.size;
654
+ /** @type {Map<string, {file: string, name: string}>} */
655
+ const origins = new Map();
656
+ let low = Infinity;
657
+ read.reading.set(key, {depth, origins});
658
+ /** @param {string} target */
659
+ const originsOf = target => {
660
+ const result = exportOriginsOf(target, read);
661
+ low = Math.min(low, result.low);
662
+ return result.origins;
663
+ };
664
+ try {
665
+ let ast;
666
+ try {
667
+ if (!fs.statSync(file).isFile()) return {origins, low};
668
+ ast = parseModule(file);
669
+ } catch {
670
+ return {origins, low};
671
+ }
672
+ const {types} = read;
673
+ // A name the module exports by name shadows every `export *`, even when
674
+ // its binding cannot be followed.
675
+ const named = new Set();
676
+ const {declarations, specifiers} = namedExportIndex(ast.program, types);
677
+ for (const node of declarations) {
678
+ for (const name of declaredNames(node.declaration, types)) {
679
+ named.add(name);
680
+ if (!origins.has(name)) origins.set(name, {file, name});
681
+ }
682
+ }
683
+ for (const [exportName, entries] of specifiers) {
684
+ named.add(exportName);
685
+ if (origins.has(exportName)) continue;
686
+ for (const {node, specifier} of entries) {
687
+ const local =
688
+ specifier.local?.name ?? specifier.local?.value ?? exportName;
689
+ let origin = null;
690
+ if (node.source) {
691
+ const target = resolveModuleOrPackage(node.source.value, file);
692
+ if (target) {
693
+ const result = exportOriginsOf(target, read);
694
+ low = Math.min(low, result.low);
695
+ // A map that depends on a module still being read is partial, so
696
+ // a name missing from it is followed on its own.
697
+ origin =
698
+ result.origins.get(local) ??
699
+ (result.low < Infinity
700
+ ? moduleExportOrigin(target, local, new Set(), {types})
701
+ : null);
702
+ }
703
+ } else {
704
+ origin = bindingOrigin(ast, file, local, new Set(), types);
705
+ }
706
+ if (origin) {
707
+ origins.set(exportName, origin);
708
+ break;
709
+ }
710
+ if (!node.source) break;
711
+ }
712
+ }
713
+ for (const node of nodesOfType(ast.program, 'ExportDefaultDeclaration')) {
714
+ named.add('default');
715
+ if (origins.has('default')) break;
716
+ const declaration = node.declaration;
717
+ if (!types && !runtimeDefault(declaration)) continue;
718
+ const origin =
719
+ declaration.type === 'Identifier'
720
+ ? bindingOrigin(ast, file, declaration.name, new Set(), types)
721
+ : {file, name: 'default'};
722
+ if (origin) origins.set('default', origin);
723
+ break;
724
+ }
725
+ for (const node of nodesOfType(ast.program, 'ExportAllDeclaration')) {
726
+ if ((node.exportKind === 'type' && !types) || node.exported) continue;
727
+ const target = resolveModuleOrPackage(node.source?.value, file);
728
+ if (!target) continue;
729
+ for (const [name, origin] of originsOf(target)) {
730
+ if (name !== 'default' && !named.has(name) && !origins.has(name)) {
731
+ origins.set(name, origin);
732
+ }
733
+ }
734
+ }
735
+ return {origins, low};
736
+ } finally {
737
+ read.reading.delete(key);
738
+ if (low >= depth) read.memo.set(key, origins);
739
+ }
740
+ }
741
+
577
742
  /**
578
743
  * @typedef {{verdict: 'exports'} | {verdict: 'lacks'} | {verdict: 'unknown', reason: string}} ExportVerdict
579
744
  */
@@ -926,22 +1091,25 @@ export function staticExportObject(file, exportNames) {
926
1091
  * @type {WeakMap<object, {declarations: any[], specifiers: Map<string, Array<{node: any, specifier: any}>>}>}
927
1092
  */
928
1093
  const namedExportIndexes = new WeakMap();
1094
+ /** The same index with type-only exports included. */
1095
+ const typedExportIndexes = new WeakMap();
929
1096
 
930
- /** @param {any} program */
931
- function namedExportIndex(program) {
932
- const cached = namedExportIndexes.get(program);
1097
+ /** @param {any} program @param {boolean} [types] include type-only exports */
1098
+ function namedExportIndex(program, types = false) {
1099
+ const indexes = types ? typedExportIndexes : namedExportIndexes;
1100
+ const cached = indexes.get(program);
933
1101
  if (cached) return cached;
934
1102
  /** @type {any[]} */
935
1103
  const declarations = [];
936
1104
  /** @type {Map<string, Array<{node: any, specifier: any}>>} */
937
1105
  const specifiers = new Map();
938
1106
  for (const node of nodesOfType(program, 'ExportNamedDeclaration')) {
939
- if (node.exportKind === 'type') continue;
1107
+ if (node.exportKind === 'type' && !types) continue;
940
1108
  if (node.declaration) declarations.push(node);
941
1109
  for (const specifier of node.specifiers ?? []) {
942
1110
  if (
943
1111
  specifier.type !== 'ExportSpecifier' ||
944
- specifier.exportKind === 'type'
1112
+ (specifier.exportKind === 'type' && !types)
945
1113
  ) {
946
1114
  continue;
947
1115
  }
@@ -952,7 +1120,7 @@ function namedExportIndex(program) {
952
1120
  }
953
1121
  }
954
1122
  const index = {declarations, specifiers};
955
- namedExportIndexes.set(program, index);
1123
+ indexes.set(program, index);
956
1124
  return index;
957
1125
  }
958
1126
 
@@ -961,12 +1129,19 @@ function namedExportIndex(program) {
961
1129
  * has there, without executing anything: local re-exports, renames, and
962
1130
  * imported bindings a module exports again are followed. Two exports are the
963
1131
  * same value when their origins are equal. Null when it cannot be proved.
1132
+ * With `types`, type-only exports and type declarations are followed too.
964
1133
  * @param {string} file
965
1134
  * @param {string} exportName
966
1135
  * @param {Set<string>} [seen]
1136
+ * @param {{types?: boolean}} [options]
967
1137
  * @returns {{file: string, name: string} | null}
968
1138
  */
969
- export function moduleExportOrigin(file, exportName, seen = new Set()) {
1139
+ export function moduleExportOrigin(
1140
+ file,
1141
+ exportName,
1142
+ seen = new Set(),
1143
+ {types = false} = {},
1144
+ ) {
970
1145
  const identity = `${file}\0${exportName}`;
971
1146
  if (seen.has(identity)) return null;
972
1147
  seen.add(identity);
@@ -977,9 +1152,9 @@ export function moduleExportOrigin(file, exportName, seen = new Set()) {
977
1152
  } catch {
978
1153
  return null;
979
1154
  }
980
- const {declarations, specifiers} = namedExportIndex(ast.program);
1155
+ const {declarations, specifiers} = namedExportIndex(ast.program, types);
981
1156
  for (const node of declarations) {
982
- if (declarationExports(node.declaration, exportName)) {
1157
+ if (declarationExports(node.declaration, exportName, types)) {
983
1158
  return {file, name: exportName};
984
1159
  }
985
1160
  }
@@ -987,26 +1162,30 @@ export function moduleExportOrigin(file, exportName, seen = new Set()) {
987
1162
  const local = specifier.local?.name ?? specifier.local?.value ?? exportName;
988
1163
  if (node.source) {
989
1164
  const target = resolveModuleOrPackage(node.source.value, file);
990
- const origin = target ? moduleExportOrigin(target, local, seen) : null;
1165
+ const origin = target
1166
+ ? moduleExportOrigin(target, local, seen, {types})
1167
+ : null;
991
1168
  if (origin) return origin;
992
1169
  continue;
993
1170
  }
994
- return bindingOrigin(ast, file, local, seen);
1171
+ return bindingOrigin(ast, file, local, seen, types);
995
1172
  }
996
1173
  if (exportName === 'default') {
997
1174
  for (const node of nodesOfType(ast.program, 'ExportDefaultDeclaration')) {
998
1175
  const declaration = node.declaration;
999
- if (!runtimeDefault(declaration)) continue;
1176
+ if (!types && !runtimeDefault(declaration)) continue;
1000
1177
  if (declaration.type === 'Identifier') {
1001
- return bindingOrigin(ast, file, declaration.name, seen);
1178
+ return bindingOrigin(ast, file, declaration.name, seen, types);
1002
1179
  }
1003
1180
  return {file, name: 'default'};
1004
1181
  }
1005
1182
  }
1006
1183
  for (const node of nodesOfType(ast.program, 'ExportAllDeclaration')) {
1007
- if (node.exportKind === 'type' || node.exported) continue;
1184
+ if ((node.exportKind === 'type' && !types) || node.exported) continue;
1008
1185
  const target = resolveModuleOrPackage(node.source?.value, file);
1009
- const origin = target ? moduleExportOrigin(target, exportName, seen) : null;
1186
+ const origin = target
1187
+ ? moduleExportOrigin(target, exportName, seen, {types})
1188
+ : null;
1010
1189
  if (origin) return origin;
1011
1190
  }
1012
1191
  return null;
@@ -1128,12 +1307,18 @@ function originGapReason(file, exportName, seen = new Set()) {
1128
1307
  * named exports and, through `export *` from local files and installed
1129
1308
  * packages, theirs. Unlike {@link moduleExportNames}, it never gives up on an
1130
1309
  * `export *`: what it cannot read is left out. Type-only
1131
- * exports and `default` are left out. Sorted.
1310
+ * exports are left out unless `types` asks for them; `default` always is.
1311
+ * Sorted.
1132
1312
  * @param {string} file
1133
1313
  * @param {Set<string>} [seen]
1314
+ * @param {{types?: boolean}} [options]
1134
1315
  * @returns {string[]}
1135
1316
  */
1136
- export function followedExportNames(file, seen = new Set()) {
1317
+ export function followedExportNames(
1318
+ file,
1319
+ seen = new Set(),
1320
+ {types = false} = {},
1321
+ ) {
1137
1322
  if (seen.has(file)) return [];
1138
1323
  seen.add(file);
1139
1324
  let ast;
@@ -1146,11 +1331,14 @@ export function followedExportNames(file, seen = new Set()) {
1146
1331
  /** @type {Set<string>} */
1147
1332
  const names = new Set();
1148
1333
  for (const node of nodesOfType(ast.program, 'ExportNamedDeclaration')) {
1149
- if (node.exportKind === 'type') continue;
1334
+ if (node.exportKind === 'type' && !types) continue;
1150
1335
  const declaration = node.declaration;
1151
- if (declaration && declaration.declare !== true) {
1336
+ if (declaration && (declaration.declare !== true || types)) {
1152
1337
  if (
1153
- ['FunctionDeclaration', 'ClassDeclaration'].includes(declaration.type)
1338
+ ['FunctionDeclaration', 'ClassDeclaration'].includes(
1339
+ declaration.type,
1340
+ ) ||
1341
+ (types && TYPE_DECLARATIONS.includes(declaration.type))
1154
1342
  ) {
1155
1343
  if (declaration.id?.name) names.add(declaration.id.name);
1156
1344
  } else if (declaration.type === 'VariableDeclaration') {
@@ -1162,7 +1350,7 @@ export function followedExportNames(file, seen = new Set()) {
1162
1350
  for (const specifier of node.specifiers ?? []) {
1163
1351
  if (
1164
1352
  specifier.type !== 'ExportSpecifier' ||
1165
- specifier.exportKind === 'type'
1353
+ (specifier.exportKind === 'type' && !types)
1166
1354
  ) {
1167
1355
  continue;
1168
1356
  }
@@ -1173,10 +1361,12 @@ export function followedExportNames(file, seen = new Set()) {
1173
1361
  }
1174
1362
  }
1175
1363
  for (const node of nodesOfType(ast.program, 'ExportAllDeclaration')) {
1176
- if (node.exportKind === 'type' || node.exported) continue;
1364
+ if ((node.exportKind === 'type' && !types) || node.exported) continue;
1177
1365
  const target = resolveModuleOrPackage(node.source?.value, file);
1178
1366
  if (target) {
1179
- for (const name of followedExportNames(target, seen)) names.add(name);
1367
+ for (const name of followedExportNames(target, seen, {types})) {
1368
+ names.add(name);
1369
+ }
1180
1370
  }
1181
1371
  }
1182
1372
  return [...names].sort();
@@ -1439,11 +1629,15 @@ export function elementPropOrigins(file, {sources, name, prop, unwrap}) {
1439
1629
  * @param {string} file
1440
1630
  * @param {string} local
1441
1631
  * @param {Set<string>} seen
1632
+ * @param {boolean} [types] also follow `import type`
1442
1633
  * @returns {{file: string, name: string} | null}
1443
1634
  */
1444
- function bindingOrigin(ast, file, local, seen) {
1635
+ function bindingOrigin(ast, file, local, seen, types = false) {
1445
1636
  for (const node of ast.program.body) {
1446
- if (node.type !== 'ImportDeclaration' || node.importKind === 'type') {
1637
+ if (
1638
+ node.type !== 'ImportDeclaration' ||
1639
+ (node.importKind === 'type' && !types)
1640
+ ) {
1447
1641
  continue;
1448
1642
  }
1449
1643
  for (const specifier of node.specifiers ?? []) {
@@ -1452,7 +1646,9 @@ function bindingOrigin(ast, file, local, seen) {
1452
1646
  const imported =
1453
1647
  specifier.imported?.name ?? specifier.imported?.value ?? local;
1454
1648
  const target = resolveModuleOrPackage(node.source.value, file);
1455
- return target ? moduleExportOrigin(target, imported, seen) : null;
1649
+ return target
1650
+ ? moduleExportOrigin(target, imported, seen, {types})
1651
+ : null;
1456
1652
  }
1457
1653
  }
1458
1654
  return {file, name: local};
@@ -159,16 +159,24 @@ export function cliBinResolves(targetDir?: string): boolean;
159
159
  *
160
160
  * With `installed`, the line follows a step that installs the project's own
161
161
  * CLI (an update notice, the hint that matches a project's CLI to its Core),
162
- * so the guess is that CLI: `<run-prefix> astryx`. A declared `cliCommand`
163
- * and a host's door still come first.
162
+ * so the guess is that CLI: `<run-prefix> astryx`. With `release`, the line
163
+ * runs in another project's folder than the run's, so the guess names that
164
+ * project's release instead of the one that answered: its own CLI when it
165
+ * installs one and the bin resolves there, otherwise the package runner
166
+ * pinned to that release. A declared `cliCommand` and a host's door still
167
+ * come first.
164
168
  *
165
169
  * @param {string} [targetDir] the project the printed command runs in;
166
170
  * defaults to the working directory
167
- * @param {{installed?: boolean}} [options]
171
+ * @param {{installed?: boolean, release?: {version: string, own: boolean} | null}} [options]
168
172
  * @returns {string}
169
173
  */
170
- export function getCliInvocation(targetDir?: string, { installed }?: {
174
+ export function getCliInvocation(targetDir?: string, { installed, release }?: {
171
175
  installed?: boolean;
176
+ release?: {
177
+ version: string;
178
+ own: boolean;
179
+ } | null;
172
180
  }): string;
173
181
  /**
174
182
  * The package-manager guess alone, without any integration's `cliCommand` or
@@ -509,21 +509,30 @@ export function cliBinResolves(targetDir = process.cwd()) {
509
509
  *
510
510
  * With `installed`, the line follows a step that installs the project's own
511
511
  * CLI (an update notice, the hint that matches a project's CLI to its Core),
512
- * so the guess is that CLI: `<run-prefix> astryx`. A declared `cliCommand`
513
- * and a host's door still come first.
512
+ * so the guess is that CLI: `<run-prefix> astryx`. With `release`, the line
513
+ * runs in another project's folder than the run's, so the guess names that
514
+ * project's release instead of the one that answered: its own CLI when it
515
+ * installs one and the bin resolves there, otherwise the package runner
516
+ * pinned to that release. A declared `cliCommand` and a host's door still
517
+ * come first.
514
518
  *
515
519
  * @param {string} [targetDir] the project the printed command runs in;
516
520
  * defaults to the working directory
517
- * @param {{installed?: boolean}} [options]
521
+ * @param {{installed?: boolean, release?: {version: string, own: boolean} | null}} [options]
518
522
  * @returns {string}
519
523
  */
520
- export function getCliInvocation(targetDir, {installed = false} = {}) {
524
+ export function getCliInvocation(
525
+ targetDir,
526
+ {installed = false, release = null} = {},
527
+ ) {
521
528
  const declared = declaredCliCommand(targetDir);
522
529
  if (declared.command) return declared.command;
523
530
  const guess = () =>
524
- installed
531
+ installed || (release?.own && cliBinResolves(targetDir))
525
532
  ? `${getRunPrefix(targetDir)} ${CLI_BIN}`
526
- : guessCliInvocation(targetDir);
533
+ : release
534
+ ? `${getDlxPrefix(targetDir)} ${CLI_PACKAGE}@${release.version}`
535
+ : guessCliInvocation(targetDir);
527
536
  if (declared.conflict) return guess();
528
537
  return cliDoor() ?? guess();
529
538
  }
@@ -80,7 +80,10 @@ export function semverGt(a, b) {
80
80
  * @returns {{major: number, minor: number, patch: number, count: number}}
81
81
  */
82
82
  function parseVersionParts(value) {
83
- const core = String(value).trim().replace(/^[v=]+/, '').split(/[-+]/)[0];
83
+ const core = String(value)
84
+ .trim()
85
+ .replace(/^[v=]+/, '')
86
+ .split(/[-+]/)[0];
84
87
  const nums = core.split('.').map(n => parseInt(n, 10));
85
88
  return {
86
89
  major: Number.isFinite(nums[0]) ? nums[0] : 0,
@@ -105,7 +108,8 @@ function satisfiesComparator(version, token) {
105
108
  if (!m) return true;
106
109
  const op = m[1] || '=';
107
110
  const target = m[2].trim();
108
- if (target === '' || target === '*' || target.toLowerCase() === 'x') return true;
111
+ if (target === '' || target === '*' || target.toLowerCase() === 'x')
112
+ return true;
109
113
  const t = parseVersionParts(target);
110
114
  // No numeric component (e.g. `workspace:*`, a git/url spec) — can't model it,
111
115
  // so treat as unconstrained rather than emit a false mismatch.
@@ -123,16 +127,22 @@ function satisfiesComparator(version, token) {
123
127
  case '<':
124
128
  return cmp < 0;
125
129
  case '^':
126
- if (t.major > 0) return below(`${t.major + 1}.0.0`);
127
- if (t.minor > 0) return below(`0.${t.minor + 1}.0`);
130
+ // A partial target widens the range to the parts given: `^0` is any
131
+ // 0.x.y, `^0.0` is any 0.0.y, while `^0.0.3` is locked to the patch.
132
+ if (t.major > 0 || t.count === 1) return below(`${t.major + 1}.0.0`);
133
+ if (t.minor > 0 || t.count === 2) return below(`0.${t.minor + 1}.0`);
128
134
  return below(`0.0.${t.patch + 1}`);
129
135
  case '~':
130
- return below(t.count >= 2 ? `${t.major}.${t.minor + 1}.0` : `${t.major + 1}.0.0`);
136
+ return below(
137
+ t.count >= 2 ? `${t.major}.${t.minor + 1}.0` : `${t.major + 1}.0.0`,
138
+ );
131
139
  case '=':
132
140
  default:
133
141
  // A full version is exact; a partial (`1`, `1.2`) behaves like a range.
134
142
  if (t.count >= 3) return cmp === 0;
135
- return below(t.count === 2 ? `${t.major}.${t.minor + 1}.0` : `${t.major + 1}.0.0`);
143
+ return below(
144
+ t.count === 2 ? `${t.major}.${t.minor + 1}.0` : `${t.major + 1}.0.0`,
145
+ );
136
146
  }
137
147
  }
138
148
 
@@ -154,11 +164,33 @@ function satisfiesComparator(version, token) {
154
164
  export function satisfiesRange(version, range) {
155
165
  if (!isValidSemver(version)) return true;
156
166
  const r = String(range ?? '').trim();
157
- if (r === '' || r === '*' || r.toLowerCase() === 'x' || r.toLowerCase() === 'latest') {
167
+ if (
168
+ r === '' ||
169
+ r === '*' ||
170
+ r.toLowerCase() === 'x' ||
171
+ r.toLowerCase() === 'latest'
172
+ ) {
158
173
  return true;
159
174
  }
160
175
  return r.split('||').some(union => {
161
- const tokens = union.trim().split(/\s+/).filter(Boolean);
162
- return tokens.length === 0 || tokens.every(tok => satisfiesComparator(version, tok));
176
+ // A hyphen range `A - B` is the inclusive intersection `>=A <=B`; left
177
+ // as-is its two bare versions would each read as an exact match that
178
+ // can never both hold. A partial upper bound covers its whole series, as
179
+ // npm reads it: `1.0.0 - 2` is `>=1.0.0 <3.0.0`.
180
+ const normalized = union
181
+ .trim()
182
+ .replace(/^(\S+)\s+-\s+(\S+)$/, (_, low, high) => {
183
+ const h = parseVersionParts(high);
184
+ if (h.count === 0) return `>=${low}`;
185
+ if (h.count >= 3) return `>=${low} <=${high}`;
186
+ const next =
187
+ h.count === 2 ? `${h.major}.${h.minor + 1}.0` : `${h.major + 1}.0.0`;
188
+ return `>=${low} <${next}`;
189
+ });
190
+ const tokens = normalized.split(/\s+/).filter(Boolean);
191
+ return (
192
+ tokens.length === 0 ||
193
+ tokens.every(tok => satisfiesComparator(version, tok))
194
+ );
163
195
  });
164
196
  }
@@ -132,6 +132,17 @@ export function installFolder(cwd: string): {
132
132
  dir: string;
133
133
  moved: boolean;
134
134
  } | null;
135
+ /**
136
+ * The release of the project at `dir`, for a command that runs in its folder
137
+ * from a folder below it: its own CLI's version when it installs one, else
138
+ * the Core it records; null when it records neither.
139
+ * @param {string} dir
140
+ * @returns {{version: string, own: boolean} | null}
141
+ */
142
+ export function projectRelease(dir: string): {
143
+ version: string;
144
+ own: boolean;
145
+ } | null;
135
146
  /**
136
147
  * The command that adds the CLI at Core's version, for a run in `cwd` whose
137
148
  * Core is `core`, with the project's package manager in the project root.
@@ -255,6 +266,11 @@ export function noticeLines({ cwd, self, choice, json, stateDir, cacheDir, now,
255
266
  }): string[];
256
267
  /** A notice prints at most once in this long. */
257
268
  export const NOTICE_INTERVAL_MS: number;
269
+ /**
270
+ * The key prefix of the once-a-day setup reminder. It is no update notice, so
271
+ * no skip is recorded for it and doctor's update line never names it.
272
+ */
273
+ export const SETUP_REMINDER_KEY: "setup:";
258
274
  /**
259
275
  * What to tell a run in a folder inside a project whose package.json is not
260
276
  * the project's: run from the project's folder, since adding there would make
@@ -81,6 +81,12 @@ const FORGET_AFTER_MS = 30 * 24 * 60 * 60_000;
81
81
  */
82
82
  const LATEST = '@astryxdesign/cli@latest';
83
83
 
84
+ /**
85
+ * The key prefix of the once-a-day setup reminder. It is no update notice, so
86
+ * no skip is recorded for it and doctor's update line never names it.
87
+ */
88
+ export const SETUP_REMINDER_KEY = 'setup:';
89
+
84
90
  /**
85
91
  * Whether notice `key` may print now; when it may, its time is recorded
86
92
  * first, and a time that cannot be recorded keeps it from printing.
@@ -104,7 +110,9 @@ export function takeNotice(
104
110
  const shown = state.notifiedAt ?? {};
105
111
  const last = shown[key];
106
112
  if (typeof last === 'number' && now - last < NOTICE_INTERVAL_MS) {
107
- const skips = withSkip(state.noticeSkips, key, 'already-shown', now);
113
+ const skips = key.startsWith(SETUP_REMINDER_KEY)
114
+ ? null
115
+ : withSkip(state.noticeSkips, key, 'already-shown', now);
108
116
  if (skips) writeGlobalState({...state, noticeSkips: skips}, stateDir);
109
117
  return /** @type {const} */ ('already-shown');
110
118
  }
@@ -198,6 +206,7 @@ export function lastNoticeSkip({stateDir = userConfigDir()} = {}) {
198
206
  readGlobalState(stateDir).noticeSkips ?? {},
199
207
  )) {
200
208
  if (
209
+ !key.startsWith(SETUP_REMINDER_KEY) &&
201
210
  skip &&
202
211
  typeof skip.at === 'number' &&
203
212
  (!newest || skip.at > newest.at)
@@ -459,6 +468,19 @@ export function installFolder(cwd) {
459
468
  export const RUN_FROM_PROJECT =
460
469
  "Run this from the Astryx project's folder, or declare an Astryx package in this folder's package.json to make it a project of its own.";
461
470
 
471
+ /**
472
+ * The release of the project at `dir`, for a command that runs in its folder
473
+ * from a folder below it: its own CLI's version when it installs one, else
474
+ * the Core it records; null when it records neither.
475
+ * @param {string} dir
476
+ * @returns {{version: string, own: boolean} | null}
477
+ */
478
+ export function projectRelease(dir) {
479
+ const facts = readReleaseFacts(dir);
480
+ const version = facts.cli?.version ?? coreVersionOf(facts);
481
+ return version ? {version, own: Boolean(facts.cli)} : null;
482
+ }
483
+
462
484
  /**
463
485
  * The command that adds the CLI at Core's version, for a run in `cwd` whose
464
486
  * Core is `core`, with the project's package manager in the project root.
@@ -534,11 +556,10 @@ export function projectLag({cwd, current: given, stateDir = userConfigDir()}) {
534
556
  const target = installFolder(cwd);
535
557
  if (target == null) return null;
536
558
  const root = target.moved ? target.dir : (projectRootOf(facts) ?? cwd);
537
- // From a folder inside the project, the project's own release: its CLI's,
538
- // else its Core's, so the project gets one notice and one --from.
539
- const projectFacts = target.moved ? readReleaseFacts(root) : null;
540
- const current = projectFacts
541
- ? (projectFacts.cli?.version ?? coreVersionOf(projectFacts) ?? given)
559
+ // From a folder inside the project, the project's own release, as the
560
+ // setup reminder names it, so the project gets one notice and one --from.
561
+ const current = target.moved
562
+ ? (projectRelease(root)?.version ?? given)
542
563
  : given;
543
564
  if (!isBehind(current, latest.version)) return null;
544
565
  const newest = latest.version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.11-canary.ed0adf3",
3
+ "version": "0.7.11",
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.ed0adf3"
127
+ "@astryxdesign/core": "*"
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.ed0adf3",
136
- "@astryxdesign/core": "0.7.11-canary.ed0adf3",
137
- "@astryxdesign/lab": "0.7.11-canary.ed0adf3",
138
- "@astryxdesign/theme-neutral": "0.7.11-canary.ed0adf3",
135
+ "@astryxdesign/charts": "*",
136
+ "@astryxdesign/core": "*",
137
+ "@astryxdesign/lab": "*",
138
+ "@astryxdesign/theme-neutral": "*",
139
139
  "@heroicons/react": "^2.2.0",
140
140
  "@stylexjs/stylex": "^0.19.0",
141
141
  "@types/babel__core": "^7.20.5",