@astryxdesign/cli 0.7.15 → 0.7.16-canary.g3aa244b

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 (163) hide show
  1. package/README.md +5 -3
  2. package/api/build/_adapter.d.mts +1 -0
  3. package/api/build/blocks/blocks.d.mts +1 -0
  4. package/api/build/blocks/blocks.mjs +18 -1
  5. package/api/component/_adapter.d.mts +1 -1
  6. package/api/component/_adapter.mjs +28 -1
  7. package/api/doctor/_adapter.d.mts +35 -0
  8. package/api/doctor/_adapter.mjs +69 -0
  9. package/api/doctor/built-checks.mjs +1 -1
  10. package/api/doctor/doctor.d.mts +18 -0
  11. package/api/doctor/doctor.doc.mjs +1 -1
  12. package/api/doctor/doctor.mjs +104 -4
  13. package/api/doctor/theme-checks.mjs +6 -10
  14. package/api/integration/add-contribution.mjs +3 -3
  15. package/api/integration/pack-check.mjs +14 -8
  16. package/api/integration/validate-integration.mjs +1 -1
  17. package/api/search/_adapter.mjs +15 -16
  18. package/api/search/_entries.d.mts +2 -1
  19. package/api/search/_entries.mjs +28 -1
  20. package/api/swizzle/_moduleGraph.mjs +1 -1
  21. package/api/theme/_adapter.d.mts +5 -2
  22. package/api/theme/_adapter.mjs +43 -12
  23. package/api/theme/_fork.mjs +1 -1
  24. package/api/theme/build/build.d.mts +116 -32
  25. package/api/theme/build/build.mjs +449 -102
  26. package/api/theme/eject/eject.mjs +22 -1
  27. package/api/theme/template/template.d.mts +19 -0
  28. package/api/theme/template/template.mjs +102 -25
  29. package/api/theme/theme.type.d.mts +5 -1
  30. package/api/theme/theme.type.mjs +2 -1
  31. package/api/theme/themeBuild.doc.mjs +3 -3
  32. package/api/theme/themeEject.doc.mjs +1 -1
  33. package/api/theme/themeTemplate.doc.mjs +9 -3
  34. package/api/theme-edit/_adapter.d.mts +32 -2
  35. package/api/theme-edit/_adapter.mjs +264 -40
  36. package/api/theme-edit/_check.d.mts +93 -4
  37. package/api/theme-edit/_check.mjs +1727 -223
  38. package/api/theme-edit/_color.d.mts +2 -8
  39. package/api/theme-edit/_color.mjs +292 -219
  40. package/api/theme-edit/_compiler.d.mts +1 -0
  41. package/api/theme-edit/_compiler.mjs +20 -1
  42. package/api/theme-edit/_context.d.mts +31 -1
  43. package/api/theme-edit/_context.mjs +445 -41
  44. package/api/theme-edit/_css.d.mts +60 -1
  45. package/api/theme-edit/_css.mjs +404 -28
  46. package/api/theme-edit/_edit.d.mts +25 -0
  47. package/api/theme-edit/_edit.mjs +1532 -149
  48. package/api/theme-edit/_how-commands.d.mts +11 -26
  49. package/api/theme-edit/_how-commands.mjs +30 -2
  50. package/api/theme-edit/_how-question.d.mts +7 -0
  51. package/api/theme-edit/_how-question.mjs +1304 -176
  52. package/api/theme-edit/_how.mjs +144 -30
  53. package/api/theme-edit/_overview.mjs +2 -0
  54. package/api/theme-edit/_palette.d.mts +38 -0
  55. package/api/theme-edit/_palette.mjs +305 -71
  56. package/api/theme-edit/_parts.d.mts +33 -0
  57. package/api/theme-edit/_parts.mjs +138 -9
  58. package/api/theme-edit/_png.d.mts +18 -0
  59. package/api/theme-edit/_png.mjs +95 -14
  60. package/api/theme-edit/_preview-app.d.mts +36 -1
  61. package/api/theme-edit/_preview-app.mjs +1415 -96
  62. package/api/theme-edit/_preview.d.mts +64 -3
  63. package/api/theme-edit/_preview.mjs +514 -31
  64. package/api/theme-edit/_project.d.mts +11 -0
  65. package/api/theme-edit/_project.mjs +46 -12
  66. package/api/theme-edit/_settings.d.mts +278 -5
  67. package/api/theme-edit/_settings.mjs +2741 -195
  68. package/api/theme-edit/_tables.d.mts +24 -0
  69. package/api/theme-edit/_tables.mjs +211 -149
  70. package/api/theme-edit/_vet.d.mts +42 -0
  71. package/api/theme-edit/_vet.mjs +144 -0
  72. package/api/theme-edit/theme-edit.type.d.mts +20 -2
  73. package/api/theme-edit/theme-edit.type.mjs +6 -2
  74. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  75. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  76. package/api/theme-edit/themeEditShow.doc.mjs +11 -3
  77. package/api/upgrade/registry/registry.mjs +6 -1
  78. package/assets/codemods/parse.mjs +2 -2
  79. package/assets/docs/tree/single-component.doc.mjs +11 -2
  80. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  81. package/assets/docs.generated.json +2 -2
  82. package/assets/preview-app/next.config.mjs +7 -1
  83. package/assets/preview-app/package.json +1 -0
  84. package/assets/preview-app/src/app/globals.css +1 -0
  85. package/assets/self-audit.generated.json +1 -1
  86. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
  87. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
  88. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
  89. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
  90. package/assets/templates/components.generated.json +1 -1
  91. package/assets/templates/pages/dashboard/page.tsx +1 -1
  92. package/authoring/doctypes/_schema.d.mts +52 -5
  93. package/authoring/doctypes/_schema.mjs +62 -7
  94. package/authoring/doctypes/base/type.ts +10 -0
  95. package/authoring/doctypes/component/component.doc.mjs +1 -1
  96. package/authoring/doctypes/function/function.doc.mjs +6 -0
  97. package/authoring/doctypes/function/type.ts +3 -0
  98. package/authoring/doctypes/legacy.mjs +5 -1
  99. package/authoring/index.d.ts +1 -0
  100. package/authoring/shadcn/source-variants.d.mts +1 -1
  101. package/authoring/shadcn/source-variants.mjs +32 -10
  102. package/clients/cli/build-id.generated.json +1 -1
  103. package/clients/cli/commands/doctor.doc.mjs +2 -2
  104. package/clients/cli/commands/experimental/theme.mjs +239 -45
  105. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  106. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
  107. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
  108. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +3 -3
  109. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  110. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  111. package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
  112. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  113. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  114. package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
  115. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  116. package/clients/cli/commands/theme-eject.doc.mjs +1 -1
  117. package/clients/cli/commands/theme-template.doc.mjs +3 -1
  118. package/clients/cli/commands/theme.mjs +190 -46
  119. package/clients/cli/formatters/index.mjs +7 -4
  120. package/clients/cli/lib/cli-error.mjs +9 -3
  121. package/clients/cli/lib/component-format.mjs +27 -9
  122. package/clients/cli/lib/json-shim.mjs +72 -2
  123. package/clients/cli/manifest.generated.json +1 -1
  124. package/clients/cli/run.mjs +49 -0
  125. package/foundation/agent-docs/agent-docs-target.d.mts +2 -6
  126. package/foundation/agent-docs/agent-docs-target.mjs +9 -17
  127. package/foundation/agent-docs/agent-docs.mjs +3 -2
  128. package/foundation/config/config-writer.mjs +2 -2
  129. package/foundation/config/project.mjs +60 -14
  130. package/foundation/discovery/component-discovery.mjs +5 -17
  131. package/foundation/discovery/icon-set-writer.mjs +1 -1
  132. package/foundation/discovery/module-exports.mjs +1 -15
  133. package/foundation/discovery/template-adapter.mjs +44 -19
  134. package/foundation/discovery/template-source-tree.mjs +3 -16
  135. package/foundation/discovery/theme-discovery.d.mts +5 -1
  136. package/foundation/discovery/theme-discovery.mjs +61 -43
  137. package/foundation/fs/exact-codec.d.mts +35 -0
  138. package/foundation/fs/exact-codec.mjs +148 -0
  139. package/foundation/fs/gather-cache.d.mts +15 -5
  140. package/foundation/fs/gather-cache.mjs +129 -31
  141. package/foundation/fs/paths.d.mts +39 -0
  142. package/foundation/fs/paths.mjs +44 -11
  143. package/foundation/fs/read-record.mjs +11 -1
  144. package/foundation/integrations/contribution-fixes.mjs +1 -16
  145. package/foundation/integrations/may-have-integrations.mjs +3 -2
  146. package/foundation/integrations/public-imports.mjs +1 -1
  147. package/foundation/render/embedded-imports.mjs +1 -1
  148. package/foundation/render/host-exit.d.mts +8 -0
  149. package/foundation/render/host-exit.mjs +11 -0
  150. package/foundation/render/page-host.mjs +56 -10
  151. package/foundation/render/page-worker.mjs +14 -0
  152. package/foundation/render/render-page.mjs +37 -2
  153. package/foundation/response/error-codes.d.mts +2 -1
  154. package/foundation/response/error-codes.d.ts +1 -0
  155. package/foundation/response/error-codes.doc.mjs +5 -0
  156. package/foundation/response/error-codes.mjs +3 -0
  157. package/foundation/response/json.d.mts +15 -0
  158. package/foundation/response/json.mjs +52 -1
  159. package/foundation/response/response-types.doc.mjs +1 -1
  160. package/foundation/runtime/lazy-dependencies.d.mts +14 -0
  161. package/foundation/runtime/lazy-dependencies.mjs +82 -0
  162. package/foundation/xle/browser.d.mts +2 -2
  163. package/package.json +7 -6
@@ -13,7 +13,7 @@
13
13
 
14
14
  import * as fs from 'node:fs';
15
15
  import * as path from 'node:path';
16
- import jscodeshift from 'jscodeshift';
16
+ import {jscodeshift as loadJscodeshift} from '../../foundation/runtime/lazy-dependencies.mjs';
17
17
  import {AstryxError} from '../error.mjs';
18
18
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
19
19
  import {
@@ -928,8 +928,8 @@ async function addAgentDoc(line, options) {
928
928
  const source = manifestExists
929
929
  ? fs.readFileSync(manifestFile, 'utf-8')
930
930
  : 'export default {};\n';
931
- const j = jscodeshift.withParser('tsx');
932
- /** @type {ReturnType<ReturnType<typeof jscodeshift.withParser>>} */
931
+ const j = loadJscodeshift().withParser('tsx');
932
+ /** @type {ReturnType<ReturnType<ReturnType<typeof loadJscodeshift>['withParser']>>} */
933
933
  let ast;
934
934
  try {
935
935
  ast = j(source);
@@ -49,7 +49,7 @@ import {
49
49
  } from '../../foundation/discovery/docs-discovery.mjs';
50
50
  import {discoverIntegrationThemes} from '../../foundation/discovery/theme-discovery.mjs';
51
51
  import {inspectPackageExport} from '../../foundation/discovery/package-exports.mjs';
52
- import {parse as parseModule} from '@babel/parser';
52
+ import {babelParse as parseModule} from '../../foundation/runtime/lazy-dependencies.mjs';
53
53
  import {moduleExportsName} from '../../foundation/discovery/module-exports.mjs';
54
54
  import {
55
55
  ThemeImportError,
@@ -57,7 +57,7 @@ import {
57
57
  } from '../../foundation/discovery/theme-imports.mjs';
58
58
  import {
59
59
  normalizeThemeBuildForCompare,
60
- themeBuild,
60
+ themeBuildWithHandOff,
61
61
  } from '../theme/build/build.mjs';
62
62
  import {
63
63
  discoverIntegrationComponents,
@@ -641,8 +641,12 @@ async function validateIncompleteThemeExports(
641
641
  if (outputs.some(output => output.kind !== 'font stylesheet')) {
642
642
  // The scratch directory is the write root; the package stays the cwd,
643
643
  // so the build selects the package's Core and its paths as before.
644
- const scratchBuild = {out: expectedCss, __writeRoot: expectedDir};
645
- const receipt = await themeBuild(source, scratchBuild, {cwd: packageDir});
644
+ const receipt = await themeBuildWithHandOff(
645
+ source,
646
+ {out: expectedCss},
647
+ {cwd: packageDir},
648
+ {writeRoot: expectedDir},
649
+ );
646
650
  if (receipt == null || receipt.type !== 'theme.build') {
647
651
  throw new Error('the theme build produced no complete receipt');
648
652
  }
@@ -1079,10 +1083,12 @@ async function validatePackedThemeExports(
1079
1083
  try {
1080
1084
  // The scratch directory is the write root; the package stays the cwd,
1081
1085
  // so the build selects the package's Core and its paths as before.
1082
- const scratchBuild = {out: expectedCss, __writeRoot: expectedDir};
1083
- const receipt = await themeBuild(source, scratchBuild, {
1084
- cwd: localIntegration.__packageDir,
1085
- });
1086
+ const receipt = await themeBuildWithHandOff(
1087
+ source,
1088
+ {out: expectedCss},
1089
+ {cwd: localIntegration.__packageDir},
1090
+ {writeRoot: expectedDir},
1091
+ );
1086
1092
  if (receipt == null || receipt.type !== 'theme.build') {
1087
1093
  issues.push(
1088
1094
  error(
@@ -293,7 +293,7 @@ async function findUnreachableContributionIssues(
293
293
  issues.push(
294
294
  warning(
295
295
  'unreachable_contribution',
296
- `Found contribution metadata "${path.relative(packageDir, full)}" outside every declared integration root, so it contributes nothing. ${unreachableFix(context, full, stamp)}`,
296
+ `Found contribution metadata "${path.relative(packageDir, full).split(path.sep).join('/')}" outside every declared integration root, so it contributes nothing. ${unreachableFix(context, full, stamp)}`,
297
297
  ),
298
298
  );
299
299
  }
@@ -6,9 +6,9 @@
6
6
  * domain, _gather-*.mjs) and loads the tree's static data before it runs.
7
7
  */
8
8
 
9
- import {readFileSync, realpathSync} from 'node:fs';
9
+ import {readFileSync} from 'node:fs';
10
10
  import * as path from 'node:path';
11
- import {requireCoreDir} from '../../foundation/fs/paths.mjs';
11
+ import {realDir, requireCoreDir} from '../../foundation/fs/paths.mjs';
12
12
  import {withListingCache} from '../../foundation/fs/listing-cache.mjs';
13
13
  import {persistedGather} from '../../foundation/fs/gather-cache.mjs';
14
14
  import {
@@ -130,19 +130,6 @@ async function gatherDomains(options) {
130
130
  };
131
131
  }
132
132
 
133
- /**
134
- * The folder's real path, so a link and its target share a kept gather.
135
- * @param {string} dir
136
- * @returns {string}
137
- */
138
- function realFolder(dir) {
139
- try {
140
- return realpathSync(dir);
141
- } catch {
142
- return dir;
143
- }
144
- }
145
-
146
133
  /**
147
134
  * A gathered catalog as plain JSON and back, for a gather kept between runs
148
135
  * (persistedGather). A template's derived component names are read once and
@@ -150,6 +137,18 @@ function realFolder(dir) {
150
137
  * objects it shares.
151
138
  */
152
139
  const GATHER_CODEC = {
140
+ /**
141
+ * The shape a read-back gather needs: its candidates and components.
142
+ * @param {any} gathered
143
+ */
144
+ valid: gathered =>
145
+ gathered != null &&
146
+ Array.isArray(gathered.all) &&
147
+ Array.isArray(gathered.components) &&
148
+ gathered.all.every(
149
+ (/** @type {any} */ c) => c != null && typeof c === 'object',
150
+ ) &&
151
+ gathered.components.every((/** @type {any} */ c) => c != null),
153
152
  /**
154
153
  * @param {any} gathered
155
154
  * @returns {any}
@@ -264,7 +263,7 @@ export function gatherCandidatesReused(options) {
264
263
  gather = reusedWhileUnchanged(
265
264
  () =>
266
265
  persistedGather(
267
- [realFolder(cwd), type ?? null],
266
+ [realDir(cwd), type ?? null],
268
267
  () => gatherCandidates({cwd, type}),
269
268
  GATHER_CODEC,
270
269
  // A gather that skipped Core (a failed install still in its
@@ -17,11 +17,12 @@ export function entryTable(all: any[], cards: Record<string, {
17
17
  * A table's plain-JSON form and back. Candidates are kept as their place in
18
18
  * `all`, maps as their entries in order, so the table reads back the same.
19
19
  * @param {any[]} all
20
- * @returns {{encode: (table: EntryTable) => any, decode: (stored: any) => EntryTable}}
20
+ * @returns {{encode: (table: EntryTable) => any, decode: (stored: any) => EntryTable, valid: (table: any) => boolean}}
21
21
  */
22
22
  export function tableCodec(all: any[]): {
23
23
  encode: (table: EntryTable) => any;
24
24
  decode: (stored: any) => EntryTable;
25
+ valid: (table: any) => boolean;
25
26
  };
26
27
  /**
27
28
  * @param {any[]} all
@@ -97,10 +97,37 @@ let last = null;
97
97
  * A table's plain-JSON form and back. Candidates are kept as their place in
98
98
  * `all`, maps as their entries in order, so the table reads back the same.
99
99
  * @param {any[]} all
100
- * @returns {{encode: (table: EntryTable) => any, decode: (stored: any) => EntryTable}}
100
+ * @returns {{encode: (table: EntryTable) => any, decode: (stored: any) => EntryTable, valid: (table: any) => boolean}}
101
101
  */
102
102
  export function tableCodec(all) {
103
103
  return {
104
+ /**
105
+ * The shape a read-back table needs: a candidate for every id, and its
106
+ * fields.
107
+ * @param {any} table
108
+ */
109
+ valid: table =>
110
+ table != null &&
111
+ Array.isArray(table.ids) &&
112
+ Array.isArray(table.candidate) &&
113
+ table.candidate.length === table.ids.length &&
114
+ table.candidate.every((/** @type {any} */ c) => c != null) &&
115
+ Array.isArray(table.domain) &&
116
+ table.domain.length === table.ids.length &&
117
+ Array.isArray(table.name) &&
118
+ table.name.length === table.ids.length &&
119
+ table.fields != null &&
120
+ ['name', 'desc', 'card'].every(f => {
121
+ const field = table.fields[f];
122
+ return (
123
+ field != null &&
124
+ field.post instanceof Map &&
125
+ field.idf instanceof Map &&
126
+ Array.isArray(field.len) &&
127
+ field.len.length === table.ids.length &&
128
+ typeof field.avg === 'number'
129
+ );
130
+ }),
104
131
  encode(table) {
105
132
  const place = new Map(all.map((c, k) => [c, k]));
106
133
  const t = /** @type {any} */ (table);
@@ -15,7 +15,7 @@ import * as path from 'node:path';
15
15
  import {isBuiltin} from 'node:module';
16
16
  import {packageOf} from '../../foundation/render/served-packages.mjs';
17
17
  import {resolveInstalledPackageDir} from '../../foundation/integrations/installed-package.mjs';
18
- import {parse} from '@babel/parser';
18
+ import {babelParse as parse} from '../../foundation/runtime/lazy-dependencies.mjs';
19
19
  import {
20
20
  inspectPackageExport,
21
21
  sourceExportTarget,
@@ -78,8 +78,10 @@ export function listUnmigratedThemeCopies(cwd: string): import("../../foundation
78
78
  * @param {{cwd: string, targetPath?: string, overwrite?: boolean, takenSlugs?: Set<string>}} options
79
79
  * `takenSlugs`: the slugs of the themes the project can use, which a fork's
80
80
  * new folder name may not take
81
- * @returns {{outputDir: string, files: string[]}} the project-relative output
82
- * directory and the files written, named as the fork names them
81
+ * @returns {{outputDir: string, files: string[], editorFolder: string | null}}
82
+ * the output directory relative to the working folder, the files written,
83
+ * named as the fork names them, and the folder the theme editor made that
84
+ * holds the fork, relative to the working folder, or null
83
85
  */
84
86
  export function ejectThemeFiles(theme: import("../../foundation/discovery/theme-discovery.mjs").DiscoveredTheme, { cwd, targetPath: typedPath, overwrite, takenSlugs }: {
85
87
  cwd: string;
@@ -89,6 +91,7 @@ export function ejectThemeFiles(theme: import("../../foundation/discovery/theme-
89
91
  }): {
90
92
  outputDir: string;
91
93
  files: string[];
94
+ editorFolder: string | null;
92
95
  };
93
96
  /**
94
97
  * The packages the fork imports that the app does not declare. A fork that
@@ -16,6 +16,7 @@ import {createRequire} from 'node:module';
16
16
  import {
17
17
  findCarriedCoreDir,
18
18
  findPackageRoot,
19
+ projectWritePath,
19
20
  requireCoreDir,
20
21
  } from '../../foundation/fs/paths.mjs';
21
22
  import {tryLock, userCacheDir} from '../../foundation/release/cache.mjs';
@@ -645,8 +646,10 @@ function themeDescriptorName(file) {
645
646
  * @param {{cwd: string, targetPath?: string, overwrite?: boolean, takenSlugs?: Set<string>}} options
646
647
  * `takenSlugs`: the slugs of the themes the project can use, which a fork's
647
648
  * new folder name may not take
648
- * @returns {{outputDir: string, files: string[]}} the project-relative output
649
- * directory and the files written, named as the fork names them
649
+ * @returns {{outputDir: string, files: string[], editorFolder: string | null}}
650
+ * the output directory relative to the working folder, the files written,
651
+ * named as the fork names them, and the folder the theme editor made that
652
+ * holds the fork, relative to the working folder, or null
650
653
  */
651
654
  export function ejectThemeFiles(
652
655
  theme,
@@ -655,15 +658,17 @@ export function ejectThemeFiles(
655
658
  // The fork lands in the project, as list and add read it: the default root
656
659
  // is the project's, and a relative [path] is read from the working folder
657
660
  // but must stay inside the project.
658
- const projectDir = findPackageRoot(cwd) ?? path.resolve(cwd);
659
- // A Windows-style path names the same folders on every platform, as
660
- // compile reads it; a folder name with a backslash in it is never meant.
661
- const targetPath = typedPath?.replace(/\\/g, '/');
662
- const target = !targetPath
663
- ? defaultEjectTarget(theme.slug)
664
- : path.isAbsolute(targetPath)
665
- ? targetPath
666
- : path.relative(projectDir, path.resolve(cwd, targetPath)) || '.';
661
+ // Read as every theme command reads a path it writes; a backslash
662
+ // separates folders on every platform.
663
+ const {
664
+ projectDir,
665
+ typed: targetPath,
666
+ relative: target,
667
+ } = projectWritePath(
668
+ cwd,
669
+ typedPath || undefined,
670
+ defaultEjectTarget(theme.slug),
671
+ );
667
672
  let resolvedDir;
668
673
  try {
669
674
  resolvedDir = assertWithin(target, projectDir, {
@@ -830,7 +835,33 @@ export function ejectThemeFiles(
830
835
  throw new AstryxError(message, undefined, ERROR_CODES.ERR_WRITE_FAILED);
831
836
  }
832
837
 
833
- return {outputDir: path.relative(cwd, resolvedDir) || '.', files: names};
838
+ const editorDir = enclosingEditorFolder(resolvedDir, projectDir);
839
+ return {
840
+ outputDir: path.relative(cwd, resolvedDir) || '.',
841
+ files: names,
842
+ editorFolder:
843
+ editorDir == null ? null : path.relative(cwd, editorDir) || '.',
844
+ };
845
+ }
846
+
847
+ /**
848
+ * The nearest folder above `dir`, up to the project root, that the theme
849
+ * editor made, or null. Eject refuses the editor's folder itself; a subfolder
850
+ * of it is written as released CLIs did, with a warning.
851
+ * @param {string} dir
852
+ * @param {string} projectDir
853
+ * @returns {string | null}
854
+ */
855
+ function enclosingEditorFolder(dir, projectDir) {
856
+ const root = path.resolve(projectDir);
857
+ let current = path.resolve(dir);
858
+ while (current !== root) {
859
+ const parent = path.dirname(current);
860
+ if (parent === current) return null;
861
+ current = parent;
862
+ if (editorThemeRecord(current)) return current;
863
+ }
864
+ return null;
834
865
  }
835
866
 
836
867
  /**
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import * as path from 'node:path';
14
- import {parse} from '@babel/parser';
14
+ import {babelParse as parse} from '../../foundation/runtime/lazy-dependencies.mjs';
15
15
  import {AstryxError} from '../error.mjs';
16
16
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
17
17
  import {
@@ -68,6 +68,46 @@ export function themeSourceFiles(filePath: string): string[];
68
68
  * @returns {string[]} at most three paths
69
69
  */
70
70
  export function themeSourceGuesses(file: string, cwd: string): string[];
71
+ /**
72
+ * Hand the theme editor warnings of the builds in this process to
73
+ * `listener` instead of the logger. CLI-internal: the watch child's
74
+ * hand-off to its parent.
75
+ * @param {((warning: string) => void) | null} listener
76
+ */
77
+ export function setEditorFolderListener(listener: ((warning: string) => void) | null): void;
78
+ /**
79
+ * Tell `listener` when a build in this process finds private var errors.
80
+ * CLI-internal.
81
+ * @param {(() => void) | null} listener
82
+ */
83
+ export function setPrivateVarErrorListener(listener: (() => void) | null): void;
84
+ /**
85
+ * A build's mode flags: what it does (`--check` compares, never writes) and
86
+ * where (`--out`), carried into every build command a refusal suggests.
87
+ * @typedef {{check?: boolean, out?: string, iconsSpecifier?: string}} BuildMode
88
+ */
89
+ /**
90
+ * How a suggested build writes its source: `glob` leaves a pattern as typed
91
+ * (unquoted, so the shell expands it); `family` makes it a --family run,
92
+ * and `familyKey` names its key (a family run never takes --out).
93
+ * @typedef {{glob?: boolean, family?: boolean, familyKey?: string}} SuggestionShape
94
+ */
95
+ /**
96
+ * The `theme build` command for `source` with the caller's mode flags, so a
97
+ * suggestion never turns a check into a write or moves the outputs.
98
+ * @param {string | string[]} source as the user types it, from cwd; several
99
+ * for a family (with `shape.familyKey`)
100
+ * @param {BuildMode} mode
101
+ * @param {string} cwd
102
+ * @param {{group: string, build: string}} [words] the command's own words
103
+ * (`experimental theme compile`), else `theme build`
104
+ * @param {SuggestionShape} [shape]
105
+ * @returns {string}
106
+ */
107
+ export function buildSuggestion(source: string | string[], mode: BuildMode, cwd: string, words?: {
108
+ group: string;
109
+ build: string;
110
+ }, shape?: SuggestionShape): string;
71
111
  /**
72
112
  * Publish the outputs a batch deferred, one theme at a time, in build order.
73
113
  * @param {Array<Array<{dest: string, content: string}>>} deferred
@@ -77,11 +117,12 @@ export function writeDeferredBuildOutputs(deferred: Array<Array<{
77
117
  content: string;
78
118
  }>>): void;
79
119
  /**
80
- * Import specifier for install/scaffold instructions. Drops a leading `src/`
81
- * from the cwd-relative dir (most consumers import from a file under src/) but
82
- * keeps the rest of the path (e.g. `themes/gothic`). Callers note the path is
83
- * relative to the consumer's file.
84
- * @param {string} relDir
120
+ * Import specifier for install/scaffold instructions, from a file directly
121
+ * in the project's src/ (the file the printed snippet says it is relative
122
+ * to; callers pass the output folder from the outputs' project root): an output
123
+ * under src/ is `./themes/gothic/gothic`, one beside src/ is
124
+ * `../themes/gothic/gothic`.
125
+ * @param {string} relDir the output folder, relative to the outputs' project root
85
126
  * @param {string} base
86
127
  * @returns {string}
87
128
  */
@@ -155,6 +196,7 @@ export function printCompactTrailer(trailers: ThemeBuildTrailer[], { hint }?: {
155
196
  * @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options]
156
197
  * @param {{cwd?: string}} [ctx]
157
198
  * @param {{compact?: boolean}} [report]
199
+ * @param {ThemeBuildHandOff} [handOff]
158
200
  * @returns {Promise<{receipt: import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null, trailer: ThemeBuildTrailer | null}>}
159
201
  */
160
202
  export function themeBuildForReport(file: string, options?: {
@@ -165,7 +207,7 @@ export function themeBuildForReport(file: string, options?: {
165
207
  cwd?: string;
166
208
  }, { compact }?: {
167
209
  compact?: boolean;
168
- }): Promise<{
210
+ }, handOff?: ThemeBuildHandOff): Promise<{
169
211
  receipt: import("../theme.type.mjs").ThemeBuildResponse | import("../theme.type.mjs").ThemeBuildCheckResponse | null;
170
212
  trailer: ThemeBuildTrailer | null;
171
213
  }>;
@@ -178,36 +220,37 @@ export function themeBuild(file: string, options?: {
178
220
  cwd?: string;
179
221
  projectCore?: boolean;
180
222
  }): Promise<import("../theme.type.mjs").ThemeBuildResponse | import("../theme.type.mjs").ThemeBuildCheckResponse | null>;
181
- /** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __onPrivateVarError?: () => void, __commandWords?: {group: string, build: string}}} options @param {{cwd?: string}} [ctx] */
223
+ /**
224
+ * {@link themeBuild} with the CLI's hand-off: the same build, outputs, and
225
+ * receipt, plus what only the CLI's batch and scratch builds pass.
226
+ * CLI-internal: not exported from the API entry.
227
+ * @param {string} file
228
+ * @param {{out?: string, check?: boolean, iconsSpecifier?: string}} options
229
+ * @param {{cwd?: string, projectCore?: boolean}} ctx
230
+ * @param {ThemeBuildHandOff} handOff
231
+ * @returns {Promise<import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null>}
232
+ */
233
+ export function themeBuildWithHandOff(file: string, options: {
234
+ out?: string;
235
+ check?: boolean;
236
+ iconsSpecifier?: string;
237
+ }, ctx: {
238
+ cwd?: string;
239
+ projectCore?: boolean;
240
+ }, handOff: ThemeBuildHandOff): Promise<import("../theme.type.mjs").ThemeBuildResponse | import("../theme.type.mjs").ThemeBuildCheckResponse | null>;
241
+ /** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string}} options @param {{cwd?: string}} [ctx] @param {{commandWords?: {group: string, build: string}}} [handOff] - the CLI's words for the rebuild hint */
182
242
  export function themeBuildFamily(files: string[], options: {
183
243
  familyKey: string;
184
244
  check?: boolean;
185
245
  iconsSpecifier?: string;
186
- __onPrivateVarError?: () => void;
187
- __commandWords?: {
188
- group: string;
189
- build: string;
190
- };
191
246
  }, { cwd }?: {
192
247
  cwd?: string;
193
- }): Promise<{
194
- type: string;
195
- data: {
196
- name: any;
197
- upToDate: boolean;
198
- stale: {
199
- path: string;
200
- reason: "missing" | "outdated";
201
- }[];
202
- checked: string[];
203
- tokenCount?: undefined;
204
- componentCount?: undefined;
205
- sizeKB?: undefined;
206
- outputs?: undefined;
207
- warnings?: undefined;
208
- notices?: undefined;
248
+ }, handOff?: {
249
+ commandWords?: {
250
+ group: string;
251
+ build: string;
209
252
  };
210
- } | {
253
+ }): Promise<import("../theme.type.mjs").ThemeBuildCheckResponse | {
211
254
  type: string;
212
255
  data: {
213
256
  name: any;
@@ -222,9 +265,6 @@ export function themeBuildFamily(files: string[], options: {
222
265
  };
223
266
  warnings: any[];
224
267
  notices: string[];
225
- upToDate?: undefined;
226
- stale?: undefined;
227
- checked?: undefined;
228
268
  };
229
269
  }>;
230
270
  /**
@@ -240,6 +280,25 @@ export type CoreBindings = {
240
280
  generateOnMediaCSS: any;
241
281
  generateAdaptationCSS: any;
242
282
  };
283
+ /**
284
+ * A build's mode flags: what it does (`--check` compares, never writes) and
285
+ * where (`--out`), carried into every build command a refusal suggests.
286
+ */
287
+ export type BuildMode = {
288
+ check?: boolean;
289
+ out?: string;
290
+ iconsSpecifier?: string;
291
+ };
292
+ /**
293
+ * How a suggested build writes its source: `glob` leaves a pattern as typed
294
+ * (unquoted, so the shell expands it); `family` makes it a --family run,
295
+ * and `familyKey` names its key (a family run never takes --out).
296
+ */
297
+ export type SuggestionShape = {
298
+ glob?: boolean;
299
+ family?: boolean;
300
+ familyKey?: string;
301
+ };
243
302
  /**
244
303
  * How one `prop:value` pair on a component target is classified — the single
245
304
  * vocabulary both the root and adaptation paths reason in.
@@ -287,3 +346,28 @@ export type ThemeBuildTrailer = {
287
346
  */
288
347
  fontNotices: string[];
289
348
  };
349
+ /**
350
+ * What the CLI hands a build beyond themeBuild's options. CLI-internal, never
351
+ * a themeBuild option: `claimedOutputs` records the outputs earlier builds in
352
+ * one run wrote, so a later theme cannot replace them; with `deferredWrites`
353
+ * the build adds its outputs to that list instead of writing them, for
354
+ * writeDeferredBuildOutputs; `writeRoot` replaces `cwd` as the directory every
355
+ * output must stay inside, for a scratch build; `commandWords` names the
356
+ * command in the rebuild hint; `prepareFamily`, `familyLoader`, and
357
+ * `familyInterception` make the build a family member's plan.
358
+ */
359
+ export type ThemeBuildHandOff = {
360
+ prepareFamily?: boolean;
361
+ familyLoader?: any;
362
+ familyInterception?: any;
363
+ writeRoot?: string;
364
+ claimedOutputs?: Map<string, string>;
365
+ deferredWrites?: Array<Array<{
366
+ dest: string;
367
+ content: string;
368
+ }>>;
369
+ commandWords?: {
370
+ group: string;
371
+ build: string;
372
+ };
373
+ };