@astryxdesign/cli 0.7.14 → 0.7.15-canary.g06b7e61

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 (203) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/README.md +63 -63
  3. package/api/build/_adapter.d.mts +4 -0
  4. package/api/build/_adapter.mjs +28 -2
  5. package/api/build/blocks/blocks.d.mts +10 -1
  6. package/api/build/blocks/blocks.mjs +84 -7
  7. package/api/build/build.mjs +6 -1
  8. package/api/build/tree.d.mts +4 -0
  9. package/api/build/tree.mjs +9 -2
  10. package/api/doctor/_adapter.d.mts +3 -1
  11. package/api/doctor/_adapter.mjs +14 -1
  12. package/api/doctor/_authoring-audit.d.mts +42 -0
  13. package/api/doctor/_authoring-audit.mjs +106 -0
  14. package/api/doctor/doctor.d.mts +7 -0
  15. package/api/doctor/doctor.mjs +24 -39
  16. package/api/doctor/theme-checks.mjs +56 -21
  17. package/api/integration/add-helpers.mjs +5 -0
  18. package/api/integration/add-theme.mjs +15 -110
  19. package/api/integration/validate-integration.mjs +17 -3
  20. package/api/integration/validateIntegration.doc.mjs +1 -1
  21. package/api/search/_adapter.mjs +124 -3
  22. package/api/search/_candidate-score.mjs +63 -9
  23. package/api/search/_entries.d.mts +10 -0
  24. package/api/search/_entries.mjs +68 -1
  25. package/api/search/_gather-templates.d.mts +11 -0
  26. package/api/search/_gather-templates.mjs +22 -2
  27. package/api/search/_words.mjs +26 -6
  28. package/api/swizzle/copy/copy.mjs +1 -1
  29. package/api/theme/_adapter.d.mts +37 -5
  30. package/api/theme/_adapter.mjs +381 -57
  31. package/api/theme/_fork.d.mts +90 -0
  32. package/api/theme/_fork.mjs +246 -0
  33. package/api/theme/build/build.d.mts +40 -2
  34. package/api/theme/build/build.mjs +477 -66
  35. package/api/theme/eject/eject.mjs +36 -15
  36. package/api/theme/list/list.mjs +3 -6
  37. package/api/theme/palette/generate/generator.d.mts +13 -0
  38. package/api/theme/palette/generate/generator.mjs +32 -2
  39. package/api/theme/targets/targets.d.mts +8 -0
  40. package/api/theme/targets/targets.mjs +24 -4
  41. package/api/theme/template/template.mjs +48 -2
  42. package/api/theme/theme.type.d.mts +8 -0
  43. package/api/theme/theme.type.mjs +5 -1
  44. package/api/theme/themeBuild.doc.mjs +7 -4
  45. package/api/theme/themeEject.doc.mjs +3 -3
  46. package/api/theme/themeRemove.doc.mjs +5 -2
  47. package/api/theme/themeTargets.doc.mjs +1 -1
  48. package/api/theme/themeTemplate.doc.mjs +2 -2
  49. package/api/theme/themeUse.doc.mjs +8 -2
  50. package/api/theme-edit/_adapter.d.mts +46 -3
  51. package/api/theme-edit/_adapter.mjs +496 -112
  52. package/api/theme-edit/_catalog.d.mts +1 -6
  53. package/api/theme-edit/_catalog.mjs +5 -268
  54. package/api/theme-edit/_check.d.mts +9 -4
  55. package/api/theme-edit/_check.mjs +1232 -229
  56. package/api/theme-edit/_color.d.mts +19 -0
  57. package/api/theme-edit/_color.mjs +280 -34
  58. package/api/theme-edit/_compiler.d.mts +3 -1
  59. package/api/theme-edit/_compiler.mjs +52 -13
  60. package/api/theme-edit/_context.d.mts +4 -1
  61. package/api/theme-edit/_context.mjs +126 -13
  62. package/api/theme-edit/_css.d.mts +84 -0
  63. package/api/theme-edit/_css.mjs +700 -0
  64. package/api/theme-edit/_edit.d.mts +9 -3
  65. package/api/theme-edit/_edit.mjs +806 -103
  66. package/api/theme-edit/_how-commands.d.mts +38 -7
  67. package/api/theme-edit/_how-commands.mjs +64 -45
  68. package/api/theme-edit/_how-question.d.mts +33 -0
  69. package/api/theme-edit/_how-question.mjs +2553 -381
  70. package/api/theme-edit/_how.mjs +402 -31
  71. package/api/theme-edit/_overview.mjs +2 -7
  72. package/api/theme-edit/_palette.d.mts +60 -13
  73. package/api/theme-edit/_palette.mjs +826 -295
  74. package/api/theme-edit/_parts.d.mts +42 -10
  75. package/api/theme-edit/_parts.mjs +280 -69
  76. package/api/theme-edit/_png.d.mts +4 -4
  77. package/api/theme-edit/_png.mjs +4 -2
  78. package/api/theme-edit/_preview-app.d.mts +14 -0
  79. package/api/theme-edit/_preview-app.mjs +1675 -235
  80. package/api/theme-edit/_preview.d.mts +7 -16
  81. package/api/theme-edit/_preview.mjs +79 -86
  82. package/api/theme-edit/_project.d.mts +32 -2
  83. package/api/theme-edit/_project.mjs +80 -19
  84. package/api/theme-edit/_settings.d.mts +199 -52
  85. package/api/theme-edit/_settings.mjs +1422 -217
  86. package/api/theme-edit/_tables.d.mts +19 -6
  87. package/api/theme-edit/_tables.mjs +150 -92
  88. package/api/theme-edit/theme-edit.type.d.mts +20 -1
  89. package/api/theme-edit/theme-edit.type.mjs +6 -3
  90. package/api/theme-edit/themeEditHow.doc.mjs +6 -0
  91. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  92. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
  93. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  94. package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
  95. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
  96. package/api/theme-edit/themeEditSet.doc.mjs +1 -1
  97. package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
  98. package/api/upgrade/_adapter.d.mts +1 -0
  99. package/assets/codemods/run-codemod.mjs +61 -0
  100. package/assets/codemods/runner.mjs +5 -4
  101. package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
  102. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
  103. package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
  104. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
  105. package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
  106. package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
  107. package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
  108. package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
  109. package/assets/docs/tree/calendars.doc.mjs +1 -3
  110. package/assets/docs/tree/checks.doc.mjs +22 -1
  111. package/assets/docs/tree/publishing.doc.mjs +1 -0
  112. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  113. package/assets/docs.generated.json +2 -1
  114. package/assets/preview-app/next.config.mjs +7 -1
  115. package/assets/self-audit.generated.json +1 -0
  116. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
  117. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
  118. package/assets/templates/components.generated.json +1 -1
  119. package/authoring/integration/integration.doc.mjs +8 -0
  120. package/authoring/integration/schema.d.mts +8 -0
  121. package/authoring/integration/schema.mjs +1 -0
  122. package/authoring/integration/type.ts +9 -0
  123. package/clients/cli/bin/astryx.mjs +19 -15
  124. package/clients/cli/build-id.generated.json +1 -0
  125. package/clients/cli/commands/ensure-core-built.mjs +12 -5
  126. package/clients/cli/commands/experimental/index.mjs +10 -10
  127. package/clients/cli/commands/experimental/theme.mjs +200 -81
  128. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  129. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
  130. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
  131. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
  132. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  133. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  134. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  135. package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
  136. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  137. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  138. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
  139. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
  140. package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
  141. package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
  142. package/clients/cli/commands/integration.mjs +8 -0
  143. package/clients/cli/commands/manifest.mjs +5 -2
  144. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  145. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  146. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  147. package/clients/cli/commands/theme.mjs +439 -66
  148. package/clients/cli/index.mjs +27 -6
  149. package/clients/cli/lib/cli-error.mjs +118 -3
  150. package/clients/cli/lib/manifest.mjs +37 -0
  151. package/clients/cli/lib/resolve-theme.mjs +2 -1
  152. package/clients/cli/manifest.generated.json +1 -0
  153. package/foundation/config/project.mjs +34 -8
  154. package/foundation/config/theme-state.d.mts +16 -0
  155. package/foundation/config/theme-state.mjs +84 -13
  156. package/foundation/discovery/module-exports.mjs +16 -2
  157. package/foundation/discovery/stored-self-audit.d.mts +31 -0
  158. package/foundation/discovery/stored-self-audit.mjs +119 -0
  159. package/foundation/discovery/template-adapter.d.mts +48 -2
  160. package/foundation/discovery/template-adapter.mjs +51 -19
  161. package/foundation/discovery/template-needs.d.mts +19 -0
  162. package/foundation/discovery/template-needs.mjs +50 -16
  163. package/foundation/discovery/template-source-tree.d.mts +7 -0
  164. package/foundation/discovery/template-source-tree.mjs +15 -0
  165. package/foundation/discovery/theme-discovery.d.mts +2 -1
  166. package/foundation/discovery/theme-discovery.mjs +16 -10
  167. package/foundation/discovery/theme-imports.d.mts +16 -0
  168. package/foundation/discovery/theme-imports.mjs +30 -2
  169. package/foundation/discovery/theme-module-extensions.d.mts +18 -0
  170. package/foundation/discovery/theme-module-extensions.mjs +30 -0
  171. package/foundation/doc-compiler/import.mjs +22 -15
  172. package/foundation/doc-compiler/stored-docs.d.mts +18 -12
  173. package/foundation/doc-compiler/stored-docs.mjs +52 -19
  174. package/foundation/env/private-dir.d.mts +17 -0
  175. package/foundation/env/private-dir.mjs +42 -0
  176. package/foundation/fs/gather-cache.d.mts +108 -0
  177. package/foundation/fs/gather-cache.mjs +783 -0
  178. package/foundation/fs/jiti-cache.d.mts +21 -0
  179. package/foundation/fs/jiti-cache.mjs +66 -0
  180. package/foundation/fs/module-loader.mjs +14 -3
  181. package/foundation/fs/read-record.d.mts +31 -1
  182. package/foundation/fs/read-record.mjs +100 -7
  183. package/foundation/integrations/autolink.d.mts +1 -24
  184. package/foundation/integrations/autolink.mjs +7 -60
  185. package/foundation/integrations/declared-dependencies.d.mts +27 -0
  186. package/foundation/integrations/declared-dependencies.mjs +73 -0
  187. package/foundation/integrations/integrations.d.mts +8 -0
  188. package/foundation/integrations/integrations.mjs +4 -0
  189. package/foundation/integrations/may-have-integrations.d.mts +8 -0
  190. package/foundation/integrations/may-have-integrations.mjs +47 -0
  191. package/foundation/integrations/validate-contributions.d.mts +62 -1
  192. package/foundation/integrations/validate-contributions.mjs +476 -40
  193. package/foundation/release/cache.d.mts +32 -4
  194. package/foundation/release/cache.mjs +105 -16
  195. package/foundation/release/folder-lock.d.mts +28 -0
  196. package/foundation/release/folder-lock.mjs +205 -0
  197. package/foundation/release/lock-lease.d.mts +2 -1
  198. package/foundation/release/lock-lease.mjs +7 -2
  199. package/foundation/response/error-codes.doc.mjs +1 -1
  200. package/foundation/response/response-types.doc.mjs +5 -5
  201. package/package.json +8 -6
  202. package/api/theme-edit/_css-properties.d.mts +0 -10
  203. package/api/theme-edit/_css-properties.mjs +0 -556
@@ -0,0 +1,21 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * The per-user folder for jiti's transpiled code.
6
+ * @returns {string}
7
+ */
8
+ export function jitiCacheDir(): string;
9
+ /**
10
+ * The `fsCache` option for a jiti loader: the per-user folder, made (0700)
11
+ * on first use and used at once, while it is a real folder the user owns and
12
+ * no one else can reach (the kept catalogs' check). A folder that fails the
13
+ * check, or cannot be made, is not used and nothing is cached on disk. Where
14
+ * the system has no user ids (Windows) ownership cannot be checked, and jiti
15
+ * keeps its default, the user's own temp folder there. Worked out once per
16
+ * process.
17
+ * @returns {{fsCache?: string | false}}
18
+ */
19
+ export function jitiCacheOptions(): {
20
+ fsCache?: string | false;
21
+ };
@@ -0,0 +1,66 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Where jiti keeps the code it transpiles from TypeScript (integration
5
+ * manifests, config files, codemods, TypeScript template docs).
6
+ * @input The per-user cache folder (foundation/env/user-dirs.mjs) and the
7
+ * private-folder check (foundation/env/private-dir.mjs).
8
+ * @output `jitiCacheOptions()`: the `fsCache` option for the CLI's jiti
9
+ * loaders: `{fsCache: <user cache>/jiti}` when that folder is the user's
10
+ * own and no one else can reach it; `{fsCache: false}` (transpiled in
11
+ * memory only) when it is not; `{}` (jiti's own default) where the system
12
+ * has no user ids (Windows), whose temp folder is the user's own.
13
+ * @position Read by module-loader.mjs, doc-compiler/import.mjs and
14
+ * gather-cache.mjs. jiti's default is a `jiti` folder in the system temp
15
+ * folder, which on Linux every account on a machine shares, and which the
16
+ * system empties from time to time: another account could leave transpiled
17
+ * code there under the name jiti looks for,
18
+ * and after each emptying every TypeScript file is transpiled again. jiti
19
+ * names each cached file for its source's path and checks a hash of its
20
+ * source content before using it, so an edited, upgraded or downgraded
21
+ * file is transpiled again wherever the cache is. A set JITI_FS_CACHE is
22
+ * jiti's own setting and left to jiti.
23
+ */
24
+
25
+ import * as fs from 'node:fs';
26
+ import * as path from 'node:path';
27
+ import {currentUid, isPrivateDir} from '../env/private-dir.mjs';
28
+ import {userCacheDir} from '../env/user-dirs.mjs';
29
+
30
+ /** @type {{fsCache?: string | false} | undefined} */
31
+ let options;
32
+
33
+ /**
34
+ * The per-user folder for jiti's transpiled code.
35
+ * @returns {string}
36
+ */
37
+ export function jitiCacheDir() {
38
+ return path.join(userCacheDir(), 'jiti');
39
+ }
40
+
41
+ /**
42
+ * The `fsCache` option for a jiti loader: the per-user folder, made (0700)
43
+ * on first use and used at once, while it is a real folder the user owns and
44
+ * no one else can reach (the kept catalogs' check). A folder that fails the
45
+ * check, or cannot be made, is not used and nothing is cached on disk. Where
46
+ * the system has no user ids (Windows) ownership cannot be checked, and jiti
47
+ * keeps its default, the user's own temp folder there. Worked out once per
48
+ * process.
49
+ * @returns {{fsCache?: string | false}}
50
+ */
51
+ export function jitiCacheOptions() {
52
+ if (options) return options;
53
+ options = {};
54
+ if (process.env.JITI_FS_CACHE !== undefined || currentUid() == null) {
55
+ return options;
56
+ }
57
+ options = {fsCache: false};
58
+ try {
59
+ const dir = jitiCacheDir();
60
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, {recursive: true, mode: 0o700});
61
+ if (isPrivateDir(dir)) options = {fsCache: dir};
62
+ } catch {
63
+ // No disk cache: every TypeScript file is transpiled in memory.
64
+ }
65
+ return options;
66
+ }
@@ -24,9 +24,9 @@ import {AsyncLocalStorage} from 'node:async_hooks';
24
24
  import {createRequire} from 'node:module';
25
25
  import {pathToFileURL} from 'node:url';
26
26
  import * as fs from 'node:fs';
27
- import {createJiti} from 'jiti';
28
27
  import {findPresentFiles} from './present-files.mjs';
29
28
  import {importUrl} from './import-url.mjs';
29
+ import {jitiCacheOptions} from './jiti-cache.mjs';
30
30
 
31
31
  export {findPresentFiles};
32
32
 
@@ -34,9 +34,16 @@ export {findPresentFiles};
34
34
  let jitiInstance;
35
35
  let freshImportNonce = 0;
36
36
  const requireFromHere = createRequire(import.meta.url);
37
+
38
+ /**
39
+ * jiti, loaded on first use: only TypeScript files and built theme modules
40
+ * need it, so a run that reads neither never loads it.
41
+ * @type {typeof import('jiti').createJiti}
42
+ */
43
+ const createJiti = (...args) => requireFromHere('jiti').createJiti(...args);
37
44
  function getJiti() {
38
45
  if (!jitiInstance) {
39
- jitiInstance = createJiti(import.meta.url);
46
+ jitiInstance = createJiti(import.meta.url, jitiCacheOptions());
40
47
  }
41
48
  return jitiInstance;
42
49
  }
@@ -195,6 +202,7 @@ function isMissingPackageExport(error) {
195
202
  export async function importThemeArtifact(specifier, cwd) {
196
203
  let themeModule = path.join(cwd, 'package.json');
197
204
  const loader = createJiti(path.join(cwd, 'package.json'), {
205
+ ...jitiCacheOptions(),
198
206
  moduleCache: false,
199
207
  jsx: true,
200
208
  interopDefault: true,
@@ -226,7 +234,10 @@ export async function importThemeArtifact(specifier, cwd) {
226
234
  */
227
235
  async function importModule(file, fresh) {
228
236
  if (fresh && file.endsWith('.ts')) {
229
- return await createJiti(import.meta.url, {moduleCache: false}).import(file);
237
+ return await createJiti(import.meta.url, {
238
+ ...jitiCacheOptions(),
239
+ moduleCache: false,
240
+ }).import(file);
230
241
  }
231
242
  if (file.endsWith('.ts')) {
232
243
  return await getJiti().import(file);
@@ -9,6 +9,14 @@
9
9
  * @returns {string}
10
10
  */
11
11
  export function fileStamp(file: string): string;
12
+ /**
13
+ * Whether a recorded path is still in the state recorded for it, by the kind
14
+ * of state that was recorded.
15
+ * @param {string} file
16
+ * @param {string} state
17
+ * @returns {boolean}
18
+ */
19
+ export function stillInState(file: string, state: string): boolean;
12
20
  /**
13
21
  * Whether every recorded path is still in the state it had when it was read.
14
22
  * @param {Map<string, string>} recorded - From recordReads.
@@ -22,15 +30,37 @@ export function unchangedSince(recorded: Map<string, string>): boolean;
22
30
  * @param {string} file
23
31
  */
24
32
  export function recordContentRead(file: string): void;
33
+ /**
34
+ * Run `fn` with nothing it reads recorded: a cache's own bookkeeping, which
35
+ * is not an input of what it keeps.
36
+ * @template T
37
+ * @param {() => T} fn
38
+ * @returns {T}
39
+ */
40
+ export function withoutRecording<T>(fn: () => T): T;
41
+ /**
42
+ * Count paths as read by the running operations, each with the state given:
43
+ * what a value kept from an earlier read read. Outside `recordReads` it does
44
+ * nothing.
45
+ * @param {Iterable<[string, string]>} states
46
+ */
47
+ export function recordStates(states: Iterable<[string, string]>): void;
25
48
  /**
26
49
  * Run `fn`, adding to `seen` each path it reads, with that path's state when
27
50
  * it was first read (see the file header).
28
51
  * @template T
29
52
  * @param {Map<string, string>} seen
30
53
  * @param {() => T} fn
54
+ * @param {{exact?: boolean}} [options] - `exact`: record a probe (an
55
+ * existence check, a stat, a real path) by the path probed, with its state,
56
+ * instead of by its folder; a listing and a content read are recorded as
57
+ * ever. A folder's time changes whenever any entry in it is added or
58
+ * renamed, so a record kept between runs stays valid longer this way.
31
59
  * @returns {T}
32
60
  */
33
- export function recordReads<T>(seen: Map<string, string>, fn: () => T): T;
61
+ export function recordReads<T>(seen: Map<string, string>, fn: () => T, { exact }?: {
62
+ exact?: boolean;
63
+ }): T;
34
64
  /**
35
65
  * A loader whose value is kept while every file and folder it read is
36
66
  * unchanged, and loaded again after a change, so a long-running process sees
@@ -34,15 +34,41 @@ const reads = new AsyncLocalStorage();
34
34
  * Add `file` to every running operation's map, with its state now, unless it
35
35
  * is there already.
36
36
  * @param {Map<string, string>[]} runs
37
- * @param {string} file
37
+ * @param {string} file - What a run checks: the file read, or the folder of
38
+ * the path probed.
39
+ * @param {string} [probed] - The path itself, which an exact run checks.
38
40
  */
39
- function note(runs, file) {
41
+ function note(runs, file, probed = file) {
40
42
  let state;
43
+ let probedState;
41
44
  for (const seen of runs) {
42
- if (!seen.has(file)) seen.set(file, (state ??= stateOf(file)));
45
+ if (exactRuns.has(seen)) {
46
+ const had = seen.get(probed);
47
+ if (had === undefined) {
48
+ seen.set(
49
+ probed,
50
+ (probedState ??=
51
+ probed === file ? stateOf(probed) : probeStamp(probed)),
52
+ );
53
+ } else if (probed === file && had.startsWith('dir:')) {
54
+ // A folder first only probed, now listed: its listing counts, so it
55
+ // is checked by its full stamp from here on.
56
+ seen.set(probed, (state ??= stateOf(file)));
57
+ }
58
+ } else if (!seen.has(file)) {
59
+ seen.set(file, (state ??= stateOf(file)));
60
+ }
43
61
  }
44
62
  }
45
63
 
64
+ /**
65
+ * The runs that record a probe by the path probed, not by its folder: a
66
+ * record kept across processes, whose folders change for reasons that do not
67
+ * touch the path (see `recordReads`).
68
+ * @type {WeakSet<Map<string, string>>}
69
+ */
70
+ const exactRuns = new WeakSet();
71
+
46
72
  /** node:fs's module object, whose functions every import of it shares. */
47
73
  const fs = createRequire(import.meta.url)('node:fs');
48
74
 
@@ -98,7 +124,7 @@ function installRecorder() {
98
124
  : path.dirname(file);
99
125
  // Its state is taken when it is first read, before the read, so a
100
126
  // change made while the operation runs shows as a change afterwards.
101
- note(runs, checked);
127
+ note(runs, checked, file);
102
128
  }
103
129
  return original.apply(this, args);
104
130
  };
@@ -118,7 +144,12 @@ function installRecorder() {
118
144
  */
119
145
  export function fileStamp(file) {
120
146
  try {
121
- const {size, mtimeMs, ctimeMs, ino} = statSyncRaw(file);
147
+ // An absent path answers without an error: thousands of paths a kept
148
+ // catalog checks are absent, and building an error costs more than the
149
+ // stat.
150
+ const stat = statSyncRaw(file, {throwIfNoEntry: false});
151
+ if (!stat) return '-';
152
+ const {size, mtimeMs, ctimeMs, ino} = stat;
122
153
  return `${size}:${mtimeMs}:${ctimeMs}:${ino}`;
123
154
  } catch {
124
155
  return '-';
@@ -127,6 +158,37 @@ export function fileStamp(file) {
127
158
 
128
159
  const stateOf = fileStamp;
129
160
 
161
+ /**
162
+ * A probed path's state for an exact run: a folder's identity alone (a probe
163
+ * reads whether it is there and what it is, not what it holds, and its time
164
+ * changes whenever an entry in it changes), a file's full stamp, or absent.
165
+ * @param {string} file
166
+ * @returns {string}
167
+ */
168
+ function probeStamp(file) {
169
+ try {
170
+ const stat = statSyncRaw(file, {throwIfNoEntry: false});
171
+ if (!stat) return '-';
172
+ if (stat.isDirectory()) return `dir:${stat.ino}`;
173
+ return `${stat.size}:${stat.mtimeMs}:${stat.ctimeMs}:${stat.ino}`;
174
+ } catch {
175
+ return '-';
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Whether a recorded path is still in the state recorded for it, by the kind
181
+ * of state that was recorded.
182
+ * @param {string} file
183
+ * @param {string} state
184
+ * @returns {boolean}
185
+ */
186
+ export function stillInState(file, state) {
187
+ return (
188
+ (state.startsWith('dir:') ? probeStamp(file) : stateOf(file)) === state
189
+ );
190
+ }
191
+
130
192
  /**
131
193
  * Whether every recorded path is still in the state it had when it was read.
132
194
  * @param {Map<string, string>} recorded - From recordReads.
@@ -134,7 +196,7 @@ const stateOf = fileStamp;
134
196
  */
135
197
  export function unchangedSince(recorded) {
136
198
  for (const [file, state] of recorded) {
137
- if (stateOf(file) !== state) return false;
199
+ if (!stillInState(file, state)) return false;
138
200
  }
139
201
  return true;
140
202
  }
@@ -150,16 +212,47 @@ export function recordContentRead(file) {
150
212
  if (runs) note(runs, path.resolve(file));
151
213
  }
152
214
 
215
+ /**
216
+ * Run `fn` with nothing it reads recorded: a cache's own bookkeeping, which
217
+ * is not an input of what it keeps.
218
+ * @template T
219
+ * @param {() => T} fn
220
+ * @returns {T}
221
+ */
222
+ export function withoutRecording(fn) {
223
+ return reads.exit(fn);
224
+ }
225
+
226
+ /**
227
+ * Count paths as read by the running operations, each with the state given:
228
+ * what a value kept from an earlier read read. Outside `recordReads` it does
229
+ * nothing.
230
+ * @param {Iterable<[string, string]>} states
231
+ */
232
+ export function recordStates(states) {
233
+ const runs = reads.getStore();
234
+ if (!runs) return;
235
+ for (const [file, state] of states) {
236
+ for (const seen of runs) if (!seen.has(file)) seen.set(file, state);
237
+ }
238
+ }
239
+
153
240
  /**
154
241
  * Run `fn`, adding to `seen` each path it reads, with that path's state when
155
242
  * it was first read (see the file header).
156
243
  * @template T
157
244
  * @param {Map<string, string>} seen
158
245
  * @param {() => T} fn
246
+ * @param {{exact?: boolean}} [options] - `exact`: record a probe (an
247
+ * existence check, a stat, a real path) by the path probed, with its state,
248
+ * instead of by its folder; a listing and a content read are recorded as
249
+ * ever. A folder's time changes whenever any entry in it is added or
250
+ * renamed, so a record kept between runs stays valid longer this way.
159
251
  * @returns {T}
160
252
  */
161
- export function recordReads(seen, fn) {
253
+ export function recordReads(seen, fn, {exact = false} = {}) {
162
254
  installRecorder();
255
+ if (exact) exactRuns.add(seen);
163
256
  return reads.run([...(reads.getStore() ?? []), seen], fn);
164
257
  }
165
258
 
@@ -1,20 +1,6 @@
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 dependency names this project declares, in field then declaration order,
6
- * each tagged with the field that declared it. A name declared twice keeps the
7
- * first field it appeared in.
8
- *
9
- * Only keys are read. See the file header for why values are never parsed.
10
- *
11
- * @param {string} projectDir directory holding the project's package.json
12
- * @returns {Array<{name: string, field: string}>}
13
- */
14
- export function readDeclaredDependencies(projectDir: string): Array<{
15
- name: string;
16
- field: string;
17
- }>;
18
4
  /**
19
5
  * @typedef {object} AutolinkCandidate
20
6
  * @property {string} spec
@@ -111,16 +97,6 @@ export function autolinkIntegrations({ projectDir, loaded, fresh, }: {
111
97
  fresh?: boolean | undefined;
112
98
  }): Promise<import("./integrations.mjs").LoadedIntegration[]>;
113
99
  export { resolveInstalledPackageDir };
114
- /**
115
- * package.json fields whose keys name a dependency this project installs.
116
- *
117
- * `peerDependencies` is deliberately absent: a peer is a requirement the
118
- * CONSUMER must satisfy, not something this project's install brings in, so a
119
- * peer that happens to be present is not a declaration that it belongs here.
120
- *
121
- * @type {readonly string[]}
122
- */
123
- export const DEPENDENCY_FIELDS: readonly string[];
124
100
  export type AutolinkCandidate = {
125
101
  spec: string;
126
102
  field: string;
@@ -133,3 +109,4 @@ export type AutolinkCandidate = {
133
109
  repeat?: boolean | undefined;
134
110
  };
135
111
  import { resolveInstalledPackageDir } from './installed-package.mjs';
112
+ export { DEPENDENCY_FIELDS, readDeclaredDependencies } from "./declared-dependencies.mjs";
@@ -41,68 +41,15 @@ import * as fs from 'node:fs';
41
41
  import * as path from 'node:path';
42
42
  import {findManifestPaths, loadIntegrations} from './integrations.mjs';
43
43
  import {resolveProviders} from './provider-resolution.mjs';
44
- import {
45
- isBarePackageName,
46
- resolveInstalledPackageDir,
47
- } from './installed-package.mjs';
44
+ import {resolveInstalledPackageDir} from './installed-package.mjs';
45
+ import {readDeclaredDependencies} from './declared-dependencies.mjs';
48
46
 
49
- export {resolveInstalledPackageDir};
50
-
51
- /**
52
- * package.json fields whose keys name a dependency this project installs.
53
- *
54
- * `peerDependencies` is deliberately absent: a peer is a requirement the
55
- * CONSUMER must satisfy, not something this project's install brings in, so a
56
- * peer that happens to be present is not a declaration that it belongs here.
57
- *
58
- * @type {readonly string[]}
59
- */
60
- export const DEPENDENCY_FIELDS = Object.freeze([
61
- 'dependencies',
62
- 'devDependencies',
63
- 'optionalDependencies',
64
- ]);
65
-
66
-
67
- /**
68
- * The dependency names this project declares, in field then declaration order,
69
- * each tagged with the field that declared it. A name declared twice keeps the
70
- * first field it appeared in.
71
- *
72
- * Only keys are read. See the file header for why values are never parsed.
73
- *
74
- * @param {string} projectDir directory holding the project's package.json
75
- * @returns {Array<{name: string, field: string}>}
76
- */
77
- export function readDeclaredDependencies(projectDir) {
78
- /** @type {Record<string, unknown>} */
79
- let pkg;
80
- try {
81
- pkg = JSON.parse(
82
- fs.readFileSync(path.join(projectDir, 'package.json'), 'utf-8'),
83
- );
84
- } catch {
85
- // No package.json, or unreadable/malformed — nothing is declared.
86
- return [];
87
- }
88
-
89
- /** @type {Array<{name: string, field: string}>} */
90
- const declared = [];
91
- const seen = new Set();
92
- for (const field of DEPENDENCY_FIELDS) {
93
- const entry = pkg?.[field];
94
- if (entry == null || typeof entry !== 'object' || Array.isArray(entry)) {
95
- continue;
96
- }
97
- for (const name of Object.keys(entry)) {
98
- if (seen.has(name) || !isBarePackageName(name)) continue;
99
- seen.add(name);
100
- declared.push({name, field});
101
- }
102
- }
103
- return declared;
104
- }
47
+ export {
48
+ DEPENDENCY_FIELDS,
49
+ readDeclaredDependencies,
50
+ } from './declared-dependencies.mjs';
105
51
 
52
+ export {resolveInstalledPackageDir};
106
53
 
107
54
  /**
108
55
  * Resolve a path through symlinks for identity comparison. pnpm links every
@@ -0,0 +1,27 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * The dependency names this project declares, in field then declaration order,
6
+ * each tagged with the field that declared it. A name declared twice keeps the
7
+ * first field it appeared in.
8
+ *
9
+ * Only keys are read; the file header says why values are never parsed.
10
+ *
11
+ * @param {string} projectDir directory holding the project's package.json
12
+ * @returns {Array<{name: string, field: string}>}
13
+ */
14
+ export function readDeclaredDependencies(projectDir: string): Array<{
15
+ name: string;
16
+ field: string;
17
+ }>;
18
+ /**
19
+ * package.json fields whose keys name a dependency this project installs.
20
+ *
21
+ * `peerDependencies` is deliberately absent: a peer is a requirement the
22
+ * CONSUMER must satisfy, not something this project's install brings in, so a
23
+ * peer that happens to be present is not a declaration that it belongs here.
24
+ *
25
+ * @type {readonly string[]}
26
+ */
27
+ export const DEPENDENCY_FIELDS: readonly string[];
@@ -0,0 +1,73 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The dependencies a project's package.json declares, as autolinking
5
+ * (autolink.mjs) and the recorder's cheap integration check
6
+ * (may-have-integrations.mjs) read them. Built-ins and path helpers only,
7
+ * so it loads before anything heavy.
8
+ *
9
+ * The KEY, never the VALUE: `"@acme/legacy-ui": "npm:@acme/ui@0.1.22"` is a
10
+ * real, installed shape; so are `workspace:*`, `file:../lib`, `link:` and
11
+ * `catalog:`. None of them is a semver range, and none of them has to be
12
+ * parsed: the key is the directory name under node_modules, which is the only
13
+ * thing resolution needs. Identity still comes from the resolved package's own
14
+ * package.json `name`.
15
+ */
16
+
17
+ import * as fs from 'node:fs';
18
+ import * as path from 'node:path';
19
+ import {isBarePackageName} from './installed-package.mjs';
20
+
21
+ /**
22
+ * package.json fields whose keys name a dependency this project installs.
23
+ *
24
+ * `peerDependencies` is deliberately absent: a peer is a requirement the
25
+ * CONSUMER must satisfy, not something this project's install brings in, so a
26
+ * peer that happens to be present is not a declaration that it belongs here.
27
+ *
28
+ * @type {readonly string[]}
29
+ */
30
+ export const DEPENDENCY_FIELDS = Object.freeze([
31
+ 'dependencies',
32
+ 'devDependencies',
33
+ 'optionalDependencies',
34
+ ]);
35
+
36
+ /**
37
+ * The dependency names this project declares, in field then declaration order,
38
+ * each tagged with the field that declared it. A name declared twice keeps the
39
+ * first field it appeared in.
40
+ *
41
+ * Only keys are read; the file header says why values are never parsed.
42
+ *
43
+ * @param {string} projectDir directory holding the project's package.json
44
+ * @returns {Array<{name: string, field: string}>}
45
+ */
46
+ export function readDeclaredDependencies(projectDir) {
47
+ /** @type {Record<string, unknown>} */
48
+ let pkg;
49
+ try {
50
+ pkg = JSON.parse(
51
+ fs.readFileSync(path.join(projectDir, 'package.json'), 'utf-8'),
52
+ );
53
+ } catch {
54
+ // No package.json, or unreadable/malformed — nothing is declared.
55
+ return [];
56
+ }
57
+
58
+ /** @type {Array<{name: string, field: string}>} */
59
+ const declared = [];
60
+ const seen = new Set();
61
+ for (const field of DEPENDENCY_FIELDS) {
62
+ const entry = pkg?.[field];
63
+ if (entry == null || typeof entry !== 'object' || Array.isArray(entry)) {
64
+ continue;
65
+ }
66
+ for (const name of Object.keys(entry)) {
67
+ if (seen.has(name) || !isBarePackageName(name)) continue;
68
+ seen.add(name);
69
+ declared.push({name, field});
70
+ }
71
+ }
72
+ return declared;
73
+ }
@@ -137,6 +137,14 @@ export type LoadedIntegration = {
137
137
  */
138
138
  iconSets?: string | undefined;
139
139
  issuesUrl?: string | undefined;
140
+ /**
141
+ * the manifest's logo
142
+ * paths as written, relative to the package root
143
+ */
144
+ logo?: {
145
+ light: string;
146
+ dark?: string;
147
+ } | undefined;
140
148
  agentDocs?: {
141
149
  append?: readonly string[];
142
150
  } | undefined;
@@ -58,6 +58,8 @@ import {resolveProviders} from './provider-resolution.mjs';
58
58
  * @property {string} [themes]
59
59
  * @property {string} [iconSets] the manifest's `experimental.iconSets` root
60
60
  * @property {string} [issuesUrl]
61
+ * @property {{light: string, dark?: string}} [logo] the manifest's logo
62
+ * paths as written, relative to the package root
61
63
  * @property {{append?: readonly string[]}} [agentDocs]
62
64
  * @property {string} [cliCommand] the command this package's users run the
63
65
  * CLI with; read by the picker in foundation/env (see cli-command.mjs)
@@ -501,6 +503,7 @@ export async function loadLocalIntegration(packageDir, {fresh = false} = {}) {
501
503
  themes: resolveRoot(manifest.themes),
502
504
  iconSets: resolveRoot(manifest.experimental?.iconSets),
503
505
  issuesUrl: manifest.issuesUrl,
506
+ logo: manifest.logo,
504
507
  agentDocs: manifest.agentDocs,
505
508
  cliCommand: manifest.cliCommand,
506
509
  __cliCommandError: cliCommandError,
@@ -629,6 +632,7 @@ export async function loadIntegrations(
629
632
  themes: resolveRoot(manifest.themes),
630
633
  iconSets: resolveRoot(manifest.experimental?.iconSets),
631
634
  issuesUrl: manifest.issuesUrl,
635
+ logo: manifest.logo,
632
636
  agentDocs: manifest.agentDocs,
633
637
  cliCommand: manifest.cliCommand,
634
638
  __cliCommandError: cliCommandError,
@@ -0,0 +1,8 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * @param {string} cwd
6
+ * @returns {boolean}
7
+ */
8
+ export function mayHaveIntegrations(cwd: string): boolean;
@@ -0,0 +1,47 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Whether a project may load an integration, decided from a few file
5
+ * checks before anything heavy loads.
6
+ * @input The working folder.
7
+ * @output `mayHaveIntegrations(cwd)`: false only when the project root (the
8
+ * nearest package.json's folder, else `cwd`) has no Astryx config, is no
9
+ * integration itself, declares no installed dependency that ships an
10
+ * integration manifest, and the run is inside a project (outside one, the
11
+ * integrations installed beside the running CLI load, spec AST-081 FR12),
12
+ * so no configured, self-resolved, autolinked or computer-level integration
13
+ * can load.
14
+ * @position Read by foundation/fs/gather-cache.mjs: `component`, `template`,
15
+ * `theme` and `discover` record a run only for their integrations' kept
16
+ * check results, so a project with none skips the recorder entirely. A true
17
+ * answer only means the run records, so a check that says true too often
18
+ * costs time, never an answer.
19
+ */
20
+
21
+ import {CONFIG_BASENAMES} from '../config/config-path.mjs';
22
+ import {isOutsideProject} from '../env/project-scope.mjs';
23
+ import {findPackageRoot} from '../fs/paths.mjs';
24
+ import {findPresentFiles} from '../fs/present-files.mjs';
25
+ import {readDeclaredDependencies} from './declared-dependencies.mjs';
26
+ import {resolveInstalledPackageDir} from './installed-package.mjs';
27
+ import {MANIFEST_BASENAMES} from './manifest-paths.mjs';
28
+
29
+ /**
30
+ * @param {string} cwd
31
+ * @returns {boolean}
32
+ */
33
+ export function mayHaveIntegrations(cwd) {
34
+ const root = findPackageRoot(cwd) ?? cwd;
35
+ if (findPresentFiles(root, CONFIG_BASENAMES).length > 0) return true;
36
+ if (findPresentFiles(root, MANIFEST_BASENAMES).length > 0) return true;
37
+ for (const {name} of readDeclaredDependencies(root)) {
38
+ const installed = resolveInstalledPackageDir(name, root);
39
+ if (
40
+ installed &&
41
+ findPresentFiles(installed.packageDir, MANIFEST_BASENAMES).length > 0
42
+ ) {
43
+ return true;
44
+ }
45
+ }
46
+ return isOutsideProject(cwd);
47
+ }