@astryxdesign/cli 0.6.4-canary.505e3d8 → 0.6.4-canary.5bb03cf

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 (71) hide show
  1. package/README.md +6 -10
  2. package/api/doctor/doctor.d.mts +8 -3
  3. package/api/doctor/doctor.mjs +90 -9
  4. package/api/doctor/doctor.test.mjs +122 -10
  5. package/api/index.d.mts +0 -2
  6. package/api/index.mjs +0 -2
  7. package/api/integration/pack-check.lifecycle-output.test.mjs +105 -0
  8. package/api/integration/pack-check.mjs +28 -3
  9. package/api/json/index.ts +0 -1
  10. package/api/template/template-integration.test.mjs +1 -65
  11. package/api/template/template.mjs +1 -1
  12. package/api/upgrade/run/files-changed.test.mjs +111 -0
  13. package/api/upgrade/run/run.mjs +6 -4
  14. package/api/upgrade/upgrade.type.mjs +2 -2
  15. package/assets/codemods/__tests__/runner.test.mjs +3 -1
  16. package/assets/codemods/file-count.test.mjs +163 -0
  17. package/assets/codemods/integration-runner.mjs +3 -3
  18. package/assets/codemods/runner.mjs +5 -4
  19. package/authoring/config/config.doc.mjs +1 -1
  20. package/authoring/config/type.ts +2 -2
  21. package/authoring/doctypes/command/command.doc.mjs +1 -1
  22. package/authoring/doctypes/command/type.ts +1 -1
  23. package/clients/cli/command-result-coverage.test.mjs +7 -7
  24. package/clients/cli/commands/debug-result-summary.test.mjs +2 -2
  25. package/clients/cli/commands/text-json-parity.test.mjs +0 -17
  26. package/clients/cli/index.mjs +0 -4
  27. package/clients/cli/lib/exit-codes.test.mjs +1 -8
  28. package/clients/cli/lib/json-shim.mjs +24 -14
  29. package/clients/cli/lib/json-shim.test.mjs +6 -20
  30. package/clients/cli/lib/manifest.mjs +0 -8
  31. package/clients/cli/lib/parse-error-format.test.mjs +81 -0
  32. package/foundation/discovery/template-adapter.mjs +1 -1
  33. package/foundation/doc-compiler/doc-loads.test.mjs +0 -12
  34. package/foundation/response/response-types.doc.mjs +0 -17
  35. package/foundation/xle/browser.d.mts +3 -3
  36. package/foundation/xle/browser.mjs +3 -3
  37. package/foundation/xle/expand.mjs +2 -2
  38. package/foundation/xle/parse.mjs +1 -1
  39. package/foundation/xle/print.mjs +2 -2
  40. package/foundation/xle/splice.mjs +1 -1
  41. package/package.json +9 -9
  42. package/api/layout/_adapter.d.mts +0 -34
  43. package/api/layout/_adapter.mjs +0 -148
  44. package/api/layout/check/check.d.mts +0 -16
  45. package/api/layout/check/check.mjs +0 -40
  46. package/api/layout/expand/expand.d.mts +0 -22
  47. package/api/layout/expand/expand.mjs +0 -155
  48. package/api/layout/expand/expand.path-safety.test.mjs +0 -53
  49. package/api/layout/grammar/grammar.d.mts +0 -13
  50. package/api/layout/grammar/grammar.mjs +0 -87
  51. package/api/layout/layout.d.mts +0 -6
  52. package/api/layout/layout.mjs +0 -17
  53. package/api/layout/layout.test.mjs +0 -297
  54. package/api/layout/layout.type.d.mts +0 -89
  55. package/api/layout/layout.type.mjs +0 -103
  56. package/api/layout/layoutCheck.doc.d.mts +0 -11
  57. package/api/layout/layoutCheck.doc.mjs +0 -85
  58. package/api/layout/layoutExpand.doc.d.mts +0 -11
  59. package/api/layout/layoutExpand.doc.mjs +0 -107
  60. package/api/layout/layoutGrammar.doc.d.mts +0 -11
  61. package/api/layout/layoutGrammar.doc.mjs +0 -57
  62. package/clients/cli/commands/layout-check.doc.mjs +0 -65
  63. package/clients/cli/commands/layout-expand.doc.mjs +0 -83
  64. package/clients/cli/commands/layout-grammar.doc.mjs +0 -30
  65. package/clients/cli/commands/layout.doc.mjs +0 -34
  66. package/clients/cli/commands/layout.error-codes.test.mjs +0 -66
  67. package/clients/cli/commands/layout.exit-parity.test.mjs +0 -41
  68. package/clients/cli/commands/layout.mjs +0 -275
  69. package/clients/cli/commands/layout.path-help.test.mjs +0 -33
  70. package/clients/cli/commands/layout.stdin-cap.test.mjs +0 -47
  71. package/clients/cli/commands/layout.text-fields.test.mjs +0 -39
package/README.md CHANGED
@@ -89,7 +89,6 @@ Options:
89
89
  | `hook` | List hooks or print hook docs |
90
90
  | `init` | Initialize the design system in your project |
91
91
  | `integration` | Author and verify an Astryx integration package |
92
- | `layout` | Generate XDS layouts from compressed expressions (XLE/XLO) |
93
92
  | `search` | Search components, hooks, docs, and templates in one ranked list |
94
93
  | `swizzle` | Copy component source for customization |
95
94
  | `template` | Inject a page or block template |
@@ -475,9 +474,6 @@ Every response has a `type` discriminant. The full set is below (generated from
475
474
  | `integration.template-conflicts` | The integration identity, structural issues, and non-blocking Core template-id conflicts as {id, severity: warning, integrationPackage, integrationType, integrationName, coreMatches, message, command}. |
476
475
  | `integration.component-conflicts` | The integration identity, structural issues, and non-blocking conflicts where an integration component name is also owned by Core; each conflict includes the exact package-qualified command. |
477
476
  | `integration.doc-conflicts` | The integration identity, structural issues, and Core doc overlaps. Each finding includes `severity` (`info` \| `error`) and `relationship` (`replaces` \| `extends` \| `accidental`). |
478
- | `layout.expand` | The expansion: parsed form, generated TSX code, componentsUsed, states (count of useState hooks scaffolded), todos, blocksReferenced (each {name, mode}), warnings, and written (the output path, or null when nothing was written). |
479
- | `layout.check` | The validation result: a valid flag, the detected form, errors (each with line/col, message, formatted text, and suggestions), warnings, and the expression re-printed in both canonical surfaces (compact and outline). |
480
- | `layout.grammar` | The XLE/XLO grammar cheatsheet: a text field with the full reference plus an aliases map (short name → canonical component) generated from this install's registry. |
481
477
 
482
478
  <!-- END GENERATED: response-types -->
483
479
  <!-- Generated by scripts/generate-cli-readme.mjs from the response-types EnumDoc. Run `pnpm -F @astryxdesign/cli readme`. -->
@@ -578,12 +574,12 @@ There is no factory: write a plain object. For editor autocomplete and
578
574
  type-checking, annotate it with the `AstryxConfig` type exported from
579
575
  `@astryxdesign/cli/authoring`.
580
576
 
581
- | Field | Type | Purpose |
582
- | ----------------------------- | ------------------------------ | ----------------------------------------------------------------------------------------------- |
583
- | `integrations` | `string[]` | Integration package names to load (see [Integrations](#integrations)). |
584
- | `issuesUrl` | `string` | Where "report an issue" links point for your project. Defaults to the core issue tracker. |
585
- | `hooks.postCodemod` | `PostCodemodHook[]` | Commands to run after `astryx upgrade` applies codemods (e.g. reinstall, rebuild, reformat). |
586
- | `experimental.xle.components` | `Record<string, XleComponent>` | Register app-local components so layout (XLE) expressions can reference them by name. Unstable. |
577
+ | Field | Type | Purpose |
578
+ | ----------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------ |
579
+ | `integrations` | `string[]` | Integration package names to load (see [Integrations](#integrations)). |
580
+ | `issuesUrl` | `string` | Where "report an issue" links point for your project. Defaults to the core issue tracker. |
581
+ | `hooks.postCodemod` | `PostCodemodHook[]` | Commands to run after `astryx upgrade` applies codemods (e.g. reinstall, rebuild, reformat). |
582
+ | `experimental.xle.components` | `Record<string, XleComponent>` | No effect. Its only reader was the removed `layout` command. Still accepted so existing configs keep loading; delete it. |
587
583
 
588
584
  The config is validated against a strict schema when the CLI loads it, so an
589
585
  unknown field is a hard error rather than a silent no-op. `astryx doctor`
@@ -257,15 +257,20 @@ export type DoctorContext = {
257
257
  * could not be built, when it could not.
258
258
  */
259
259
  docsCatalogError?: string | null | undefined;
260
- /**
261
- * Combined project-level integration issues, including cross-package template replacement warnings.
262
- */
263
260
  integrationIssues?: {
264
261
  package: string;
265
262
  code: string;
266
263
  severity: "warning" | "error";
267
264
  message: string;
268
265
  }[] | null | undefined;
266
+ /**
267
+ * installed dependencies whose integration manifest could not be loaded
268
+ * Combined project-level integration issues, including cross-package template replacement warnings.
269
+ */
270
+ autolinkFailures?: {
271
+ spec: string;
272
+ error: string;
273
+ }[] | null | undefined;
269
274
  /**
270
275
  * - Error thrown while resolving the config
271
276
  * path (e.g. multiple config files present), surfaced by checkConfig as a FAIL.
@@ -26,7 +26,11 @@ import * as path from 'node:path';
26
26
  import {MIN_NODE_VERSION, isNodeVersionSupported} from '../../foundation/env/node-version.mjs';
27
27
  import {CLI_ROOT, findCoreDir, findInstalledPackage} from '../../foundation/fs/paths.mjs';
28
28
  import {explainPackageManager, getCliInvocation} from '../../foundation/env/package-manager.mjs';
29
- import {findConfigPath, Project} from '../../foundation/config/project.mjs';
29
+ import {
30
+ findConfigPath,
31
+ Project,
32
+ providerLedgerOf,
33
+ } from '../../foundation/config/project.mjs';
30
34
  import {DocsCatalog} from '../../foundation/discovery/docs-discovery.mjs';
31
35
  import {buildDocsIndexData} from '../../foundation/discovery/docs-section-key.mjs';
32
36
  import {
@@ -76,6 +80,8 @@ import {semverCompare, isValidSemver, satisfiesRange} from '../../foundation/env
76
80
  * @property {string|null} [docsCatalogError] - Why the project's docs catalog
77
81
  * could not be built, when it could not.
78
82
  * @property {Array<{package: string, code: string, severity: 'warning'|'error', message: string}>|null} [integrationIssues]
83
+ * @property {Array<{spec: string, error: string}>|null} [autolinkFailures]
84
+ * installed dependencies whose integration manifest could not be loaded
79
85
  * Combined project-level integration issues, including cross-package template replacement warnings.
80
86
  * @property {Error|null} [configError] - Error thrown while resolving the config
81
87
  * path (e.g. multiple config files present), surfaced by checkConfig as a FAIL.
@@ -417,6 +423,9 @@ export function checkImplicitIntegrations(ctx) {
417
423
  const implicit = ctx.integrations.filter(
418
424
  integration => integration.__autolinked,
419
425
  );
426
+ // A dependency whose manifest cannot be loaded leaves no loaded record, so
427
+ // without this line doctor would say no dependency ships a manifest at all.
428
+ const unreadable = describeUnreadableManifests(ctx.autolinkFailures ?? []);
420
429
 
421
430
  if (implicit.length === 0) {
422
431
  return {
@@ -424,9 +433,12 @@ export function checkImplicitIntegrations(ctx) {
424
433
  label,
425
434
  status: 'info',
426
435
  message:
427
- ctx.integrations.length > 0
436
+ (ctx.integrations.length > 0
428
437
  ? 'None — every loaded integration is named in astryx.config.'
429
- : 'None — no installed dependency ships an astryx.integration.* manifest.',
438
+ : unreadable
439
+ ? 'None loaded.'
440
+ : 'None — no installed dependency ships an astryx.integration.* manifest.') +
441
+ unreadable,
430
442
  };
431
443
  }
432
444
 
@@ -439,11 +451,25 @@ export function checkImplicitIntegrations(ctx) {
439
451
  integration.__spec && integration.__spec !== integration.name
440
452
  ? ` (declared as "${integration.__spec}")`
441
453
  : '';
442
- const roots = ['components', 'templates', 'themes', 'docs', 'codemods'].filter(
454
+ // A declared root counts only when it exists: the manifest's keys are a
455
+ // claim, and `integration-issues` reports the ones that are not true.
456
+ const declared = ['components', 'templates', 'themes', 'docs', 'codemods'].filter(
443
457
  root => integration[/** @type {'components'} */ (root)],
444
458
  );
459
+ const missing = declared.filter(root => {
460
+ const dir = integration[/** @type {'components'} */ (root)];
461
+ if (typeof dir !== 'string') return false;
462
+ const base =
463
+ typeof integration.__packageDir === 'string'
464
+ ? integration.__packageDir
465
+ : (ctx.cwd ?? process.cwd());
466
+ return !fs.existsSync(path.isAbsolute(dir) ? dir : path.resolve(base, dir));
467
+ });
468
+ const roots = declared.filter(root => !missing.includes(root));
445
469
  const contributes = roots.length > 0 ? roots.join(', ') : 'nothing';
446
- return `${integration.name}${version}${alias} from ${integration.__dependencyField}, contributing ${contributes}`;
470
+ const absent =
471
+ missing.length > 0 ? ` (declared ${missing.join(', ')} missing on disk)` : '';
472
+ return `${integration.name}${version}${alias} from ${integration.__dependencyField}, contributing ${contributes}${absent}`;
447
473
  });
448
474
 
449
475
  const plural = implicit.length === 1 ? '' : 's';
@@ -453,7 +479,8 @@ export function checkImplicitIntegrations(ctx) {
453
479
  status: 'info',
454
480
  message:
455
481
  `${implicit.length} integration${plural} loaded from installed ` +
456
- `dependencies with no astryx.config entry: ${described.join('; ')}.`,
482
+ `dependencies with no astryx.config entry: ${described.join('; ')}.` +
483
+ unreadable,
457
484
  fix:
458
485
  'Nothing to fix. Keep these dependencies installed. The CLI links them ' +
459
486
  'from package.json, so an unused-dependency check that looks only for ' +
@@ -462,6 +489,30 @@ export function checkImplicitIntegrations(ctx) {
462
489
  };
463
490
  }
464
491
 
492
+ /**
493
+ * The sentence `implicit-integrations` adds for dependencies whose manifest
494
+ * could not be loaded, or '' when there are none. Still informational: the
495
+ * package is a dependency's own bug, which `doctor integration validate`
496
+ * diagnoses, but doctor must not report it as absent.
497
+ * @param {Array<{spec: string, error: string}>} failures
498
+ * @returns {string}
499
+ */
500
+ function describeUnreadableManifests(failures) {
501
+ if (failures.length === 0) return '';
502
+ const one = failures.length === 1;
503
+ const listed = failures
504
+ .map(({spec, error}) => {
505
+ const reason = String(error).split('\n')[0].slice(0, 160);
506
+ return `${spec} (${reason})`;
507
+ })
508
+ .join('; ');
509
+ return (
510
+ ` ${failures.length} installed ${one ? 'dependency ships' : 'dependencies ship'} ` +
511
+ `an astryx.integration.* manifest that could not be loaded, so ${one ? 'it contributes' : 'they contribute'} ` +
512
+ `nothing: ${listed}. Run \`astryx doctor integration validate <package>\` for details.`
513
+ );
514
+ }
515
+
465
516
  /**
466
517
  * Check 7 — agent docs exist and contain the Astryx section markers.
467
518
  * @param {DoctorContext} ctx
@@ -738,12 +789,26 @@ export function checkProviderIdentity(ctx) {
738
789
  integration =>
739
790
  integration.providerId != null && integration.__loadError == null,
740
791
  ).length;
792
+ // An integration that could not be read has no provider ID to check, so the
793
+ // count above is not a complete survey. Say so instead of counting silently.
794
+ const unread = ctx.integrations.filter(
795
+ integration => integration.__loadError != null,
796
+ ).length;
797
+ const unreadNote =
798
+ unread === 0
799
+ ? ''
800
+ : unread === 1
801
+ ? ' 1 loaded integration could not be read, so its provider ID is unknown.'
802
+ : ` ${unread} loaded integrations could not be read, so their provider IDs are unknown.`;
741
803
  if (count === 0) {
742
804
  return {
743
805
  id,
744
806
  label,
745
807
  status: 'info',
746
- message: 'None — no loaded integration has a provider identity.',
808
+ message:
809
+ (unread === 0
810
+ ? 'None — no loaded integration has a provider identity.'
811
+ : 'No readable integration has a provider identity.') + unreadNote,
747
812
  };
748
813
  }
749
814
  return {
@@ -751,9 +816,10 @@ export function checkProviderIdentity(ctx) {
751
816
  label,
752
817
  status: 'pass',
753
818
  message:
754
- count === 1
819
+ (count === 1
755
820
  ? '1 loaded integration has its own provider ID.'
756
- : `${count} loaded integrations each have their own provider ID.`,
821
+ : `${count} loaded integrations each have their own provider ID.`) +
822
+ unreadNote,
757
823
  };
758
824
  }
759
825
 
@@ -1198,11 +1264,25 @@ export async function runChecks(options = {}) {
1198
1264
  let docsCatalogError = null;
1199
1265
  /** @type {Array<{package: string, code: string, severity: 'warning'|'error', message: string}>|null} */
1200
1266
  let integrationIssues = null;
1267
+ /** @type {Array<{spec: string, error: string}>|null} */
1268
+ let autolinkFailures = null;
1201
1269
  try {
1202
1270
  const project = await Project.load(cwd);
1203
1271
  configTheme =
1204
1272
  /** @type {{theme?: string}} */ (project.config ?? {}).theme ?? null;
1205
1273
  integrations = project.loadedIntegrations;
1274
+ // An installed dependency whose manifest cannot be loaded is kept out of
1275
+ // loadedIntegrations on purpose. The provider ledger still records it.
1276
+ autolinkFailures = [...providerLedgerOf(project).values()]
1277
+ .filter(
1278
+ entry =>
1279
+ entry.outcome === 'load-failed' &&
1280
+ entry.candidate.source === 'autolinked',
1281
+ )
1282
+ .map(entry => ({
1283
+ spec: entry.candidate.spec ?? entry.label,
1284
+ error: entry.error ?? 'its manifest could not be loaded',
1285
+ }));
1206
1286
  try {
1207
1287
  docsCatalog = await project.docs();
1208
1288
  docsCatalogIssues = (await project.issues()).filter(
@@ -1229,6 +1309,7 @@ export async function runChecks(options = {}) {
1229
1309
  docsCatalogIssues,
1230
1310
  docsCatalogError,
1231
1311
  integrationIssues,
1312
+ autolinkFailures,
1232
1313
  configError,
1233
1314
  };
1234
1315
 
@@ -354,16 +354,31 @@ describe('checkImplicitIntegrations', () => {
354
354
  });
355
355
 
356
356
  it('names the package, the field, and what it contributes', () => {
357
- const c = checkImplicitIntegrations({
358
- integrations: [
359
- autolinked({templates: '/abs/templates', themes: '/abs/themes'}),
360
- ],
361
- });
362
- expect(c.message).toContain('@acme/widgets@1.0.0');
363
- expect(c.message).toContain('from dependencies');
364
- expect(c.message).toContain(
365
- 'contributing components, templates, themes',
366
- );
357
+ // Roots count only when they exist, so this one gives them real folders.
358
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-implicit-'));
359
+ try {
360
+ const dir = name => {
361
+ fs.mkdirSync(path.join(root, name));
362
+ return path.join(root, name);
363
+ };
364
+ const c = checkImplicitIntegrations({
365
+ integrations: [
366
+ autolinked({
367
+ components: dir('components'),
368
+ templates: dir('templates'),
369
+ themes: dir('themes'),
370
+ }),
371
+ ],
372
+ });
373
+ expect(c.message).toContain('@acme/widgets@1.0.0');
374
+ expect(c.message).toContain('from dependencies');
375
+ expect(c.message).toContain(
376
+ 'contributing components, templates, themes',
377
+ );
378
+ expect(c.message).not.toContain('missing on disk');
379
+ } finally {
380
+ fs.rmSync(root, {recursive: true, force: true});
381
+ }
367
382
  });
368
383
 
369
384
  it('names the declared key too when an npm alias makes them differ', () => {
@@ -906,3 +921,100 @@ describe('checkDocsProgressiveDisclosure languages', () => {
906
921
  expect(c.message).not.toMatch(/deploying overview:/);
907
922
  });
908
923
  });
924
+
925
+ describe('doctor says what it could not check', () => {
926
+ const CORE = {
927
+ 'node_modules/@astryxdesign/core/package.json': JSON.stringify({
928
+ name: '@astryxdesign/core',
929
+ version: '0.6.3',
930
+ }),
931
+ };
932
+
933
+ /** Installed dependency whose manifest declares roots that do not exist. */
934
+ const dangling = {
935
+ 'node_modules/@acme/dangling/package.json': JSON.stringify({
936
+ name: '@acme/dangling',
937
+ version: '2.0.0',
938
+ }),
939
+ 'node_modules/@acme/dangling/astryx.integration.mjs':
940
+ "export default {providerId: 'acme-dangling', components: './components', templates: './templates', docs: './docs'};\n",
941
+ };
942
+
943
+ /** Installed dependency whose manifest cannot be parsed at all. */
944
+ const broken = {
945
+ 'node_modules/@acme/broken/package.json': JSON.stringify({
946
+ name: '@acme/broken',
947
+ version: '1.0.0',
948
+ }),
949
+ 'node_modules/@acme/broken/astryx.integration.mjs':
950
+ 'export default { this is not valid javascript ((\n',
951
+ };
952
+
953
+ /** @param {Record<string, string>} extra @param {string[]} deps */
954
+ const project = (extra, deps) =>
955
+ mkProject({
956
+ 'package.json': JSON.stringify({
957
+ name: 'consumer',
958
+ version: '1.0.0',
959
+ dependencies: Object.fromEntries(
960
+ ['@astryxdesign/core', ...deps].map(d => [d, '1.0.0']),
961
+ ),
962
+ }),
963
+ ...CORE,
964
+ ...extra,
965
+ });
966
+
967
+ // An unparseable manifest is kept out of the loaded set on purpose, and
968
+ // doctor used to report that no installed dependency ships a manifest.
969
+ it('names an installed dependency whose manifest cannot be loaded', async () => {
970
+ const report = (await doctor({cwd: project(broken, ['@acme/broken'])})).data;
971
+ const check = report.checks.find(c => c.id === 'implicit-integrations');
972
+
973
+ expect(check.status).toBe('info');
974
+ expect(check.message).toContain('@acme/broken');
975
+ expect(check.message).toContain('could not be loaded');
976
+ expect(check.message).not.toContain('no installed dependency ships');
977
+ expect(report.summary.fail).toBe(0);
978
+ }, SLOW);
979
+
980
+ it('does not claim contributions from roots that are missing on disk', async () => {
981
+ const report = (await doctor({cwd: project(dangling, ['@acme/dangling'])}))
982
+ .data;
983
+ const implicit = report.checks.find(c => c.id === 'implicit-integrations');
984
+ const issues = report.checks.find(c => c.id === 'integration-issues');
985
+
986
+ expect(implicit.message).toContain('contributing nothing');
987
+ expect(implicit.message).toContain('missing on disk');
988
+ expect(implicit.message).not.toContain('contributing components');
989
+ expect(issues.status).toBe('warn');
990
+ expect(issues.message).toContain('@acme/dangling');
991
+ }, SLOW);
992
+
993
+ it('still says no dependency ships a manifest when none does', async () => {
994
+ const report = (await doctor({cwd: project({}, [])})).data;
995
+ const check = report.checks.find(c => c.id === 'implicit-integrations');
996
+
997
+ expect(check.message).toBe(
998
+ 'None — no installed dependency ships an astryx.integration.* manifest.',
999
+ );
1000
+ }, SLOW);
1001
+
1002
+ it('says how many integrations could not be read, rather than counting silently', () => {
1003
+ /** @type {any} */
1004
+ const ctx = {
1005
+ cwd: '/x',
1006
+ nodeVersion: process.versions.node,
1007
+ coreDir: null,
1008
+ configPath: null,
1009
+ configTheme: null,
1010
+ integrations: [
1011
+ {name: '@acme/ok', __spec: '@acme/ok', providerId: 'ok'},
1012
+ {name: '@acme/bad', __spec: '@acme/bad', __loadError: 'boom'},
1013
+ ],
1014
+ };
1015
+ const check = checkProviderIdentity(ctx);
1016
+
1017
+ expect(check.message).toContain('1 loaded integration has its own provider ID.');
1018
+ expect(check.message).toContain('could not be read');
1019
+ });
1020
+ });
package/api/index.d.mts CHANGED
@@ -33,14 +33,12 @@ export * from "./gap-report/gap-report.type.mjs";
33
33
  export * from "./upgrade/upgrade.type.mjs";
34
34
  export * from "./init/init.type.mjs";
35
35
  export * from "./doctor/doctor.type.mjs";
36
- export * from "./layout/layout.type.mjs";
37
36
  export * from "./integration/integration-authoring.type.mjs";
38
37
  export * from "./integration/pack-check.type.mjs";
39
38
  export * from "./integration/validate-integration.type.mjs";
40
39
  export * from "./integration/authoring-checks.type.mjs";
41
40
  export type Logger = import("./logger.mjs").Logger;
42
41
  export { themeBuild, themeAdd, themeTemplate, themeList, themeListAvailable, themeTargets, themePaletteGenerate, generateTonalPalette, listThemes } from "./theme/theme.mjs";
43
- export { layoutExpand, layoutCheck, layoutGrammar } from "./layout/layout.mjs";
44
42
  export { integrationAdd, integrationAddAgentDoc, integrationAddCodemod, integrationAddComponent, integrationAddDoc, integrationAddTemplate } from "./integration/add-contribution.mjs";
45
43
  export { validateIntegration, summarizeIssues } from "./integration/validate-integration.mjs";
46
44
  export { integrationTemplateConflicts, integrationComponentConflicts, integrationDocConflicts } from "./integration/authoring-checks.mjs";
package/api/index.mjs CHANGED
@@ -44,7 +44,6 @@ export {gapReport} from './gap-report/gap-report.mjs';
44
44
  export {upgrade} from './upgrade/upgrade.mjs';
45
45
  export {init} from './init/init.mjs';
46
46
  export {doctor} from './doctor/doctor.mjs';
47
- export {layoutExpand, layoutCheck, layoutGrammar} from './layout/layout.mjs';
48
47
  export {
49
48
  integrationAdd,
50
49
  integrationAddAgentDoc,
@@ -93,7 +92,6 @@ export * from './gap-report/gap-report.type.mjs';
93
92
  export * from './upgrade/upgrade.type.mjs';
94
93
  export * from './init/init.type.mjs';
95
94
  export * from './doctor/doctor.type.mjs';
96
- export * from './layout/layout.type.mjs';
97
95
  export * from './integration/integration-authoring.type.mjs';
98
96
  export * from './integration/pack-check.type.mjs';
99
97
  export * from './integration/validate-integration.type.mjs';
@@ -0,0 +1,105 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {afterEach, beforeEach, describe, expect, it} from 'vitest';
4
+ import * as fs from 'node:fs';
5
+ import * as path from 'node:path';
6
+ import {integrationPackCheck} from './pack-check.mjs';
7
+
8
+ let tmpDir;
9
+
10
+ beforeEach(() => {
11
+ tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-pack-check-'));
12
+ });
13
+
14
+ afterEach(() => {
15
+ fs.rmSync(tmpDir, {recursive: true, force: true});
16
+ });
17
+
18
+ /** @param {Record<string, string>} scripts */
19
+ function writeThemePackage(scripts) {
20
+ fs.writeFileSync(
21
+ path.join(tmpDir, 'package.json'),
22
+ `${JSON.stringify(
23
+ {
24
+ name: '@acme/widgets',
25
+ version: '1.0.0',
26
+ files: ['astryx.integration.mjs', 'themes'],
27
+ scripts,
28
+ },
29
+ null,
30
+ 2,
31
+ )}\n`,
32
+ );
33
+ fs.writeFileSync(
34
+ path.join(tmpDir, 'astryx.integration.mjs'),
35
+ "export default {themes: './themes'};\n",
36
+ );
37
+ const root = path.join(tmpDir, 'themes');
38
+ fs.mkdirSync(path.join(root, 'ocean'), {recursive: true});
39
+ fs.writeFileSync(
40
+ path.join(root, 'ocean', 'oceanTheme.ts'),
41
+ "import {defineTheme} from '@astryxdesign/core/theme';\n\nexport const oceanTheme = defineTheme({name: 'ocean'});\n",
42
+ );
43
+ fs.writeFileSync(
44
+ path.join(root, 'ocean', 'oceanTheme.doc.mjs'),
45
+ `/** @type {import('@astryxdesign/cli/authoring').ThemeDoc} */
46
+ export default {type: 'theme', name: 'ocean', displayName: 'Ocean', description: 'Ocean theme.', maintained: true};
47
+ `,
48
+ );
49
+ }
50
+
51
+ describe('integrationPackCheck with lifecycle script output', () => {
52
+ it('checks the tarball when lifecycle scripts print to stdout', async () => {
53
+ writeThemePackage({
54
+ prepack: 'node -e "console.log(\'building the package\')"',
55
+ prepare: 'node -e "console.log(\'preparing\')"',
56
+ postpack: 'node -e "console.log(\'packed\')"',
57
+ });
58
+
59
+ const result = await integrationPackCheck({cwd: tmpDir});
60
+
61
+ expect(result.data.issues).toEqual([]);
62
+ expect(result.data.packable).toBe(true);
63
+ expect(result.data.tarball?.filename).toBe('acme-widgets-1.0.0.tgz');
64
+ expect(result.data.contributions.packed).toEqual(
65
+ result.data.contributions.local,
66
+ );
67
+ });
68
+
69
+ it('still runs a chatty lifecycle script and compares what it packed', async () => {
70
+ const renameTheme = [
71
+ "console.log('renaming ocean to storm')",
72
+ "const fs=require('fs')",
73
+ "fs.renameSync('themes/ocean','themes/storm')",
74
+ "const p='themes/storm/oceanTheme.doc.mjs'",
75
+ "let x=fs.readFileSync(p,'utf8')",
76
+ "x=x.replace(/name: 'ocean'/, 'name: '+String.fromCharCode(39)+'storm'+String.fromCharCode(39))",
77
+ 'fs.writeFileSync(p,x)',
78
+ ].join(';');
79
+ writeThemePackage({prepack: `node -e "${renameTheme}"`});
80
+
81
+ const result = await integrationPackCheck({cwd: tmpDir});
82
+ const codes = result.data.issues.map(issue => issue.code);
83
+
84
+ expect(codes).not.toContain('pack_failed');
85
+ expect(codes).toContain('identity_not_packed');
86
+ expect(codes).toContain('packed_identity_unexpected');
87
+ expect(result.data.packable).toBe(false);
88
+ });
89
+
90
+ it('keeps a failing lifecycle script output in the pack_failed issue', async () => {
91
+ writeThemePackage({
92
+ prepack:
93
+ 'node -e "console.error(\'prepack exploded\'); process.exit(3)"',
94
+ });
95
+
96
+ const result = await integrationPackCheck({cwd: tmpDir});
97
+ const failure = result.data.issues.find(
98
+ issue => issue.code === 'pack_failed',
99
+ );
100
+
101
+ expect(result.data.packable).toBe(false);
102
+ expect(failure?.message).toContain('npm pack failed (exit 3)');
103
+ expect(failure?.message).toContain('prepack exploded');
104
+ });
105
+ });
@@ -162,6 +162,22 @@ export function parseNpmPackOutput(output) {
162
162
  };
163
163
  }
164
164
 
165
+ /**
166
+ * Summarize the JSON error npm prints on stdout when `--json` pack fails.
167
+ * @param {string} output
168
+ * @returns {string}
169
+ */
170
+ function npmPackErrorDetail(output) {
171
+ try {
172
+ const error = JSON.parse(output)?.error;
173
+ return [error?.summary, error?.detail]
174
+ .filter(part => typeof part === 'string' && part.trim() !== '')
175
+ .join(': ');
176
+ } catch {
177
+ return (output || '').trim();
178
+ }
179
+ }
180
+
165
181
  /**
166
182
  * Run `npm pack --json` with output directed to `destDir` so no preexisting
167
183
  * tgz is overwritten. This intentionally runs the package lifecycle, matching
@@ -175,16 +191,25 @@ export function parseNpmPackOutput(output) {
175
191
  function runNpmPack(packageDir, destDir) {
176
192
  const result = spawnSync(
177
193
  'npm',
178
- ['pack', '--json', '--silent', `--pack-destination=${destDir}`],
194
+ [
195
+ 'pack',
196
+ '--json',
197
+ '--silent',
198
+ // Lifecycle scripts still run; background mode keeps their output off
199
+ // the stdout that carries the JSON result.
200
+ '--foreground-scripts=false',
201
+ `--pack-destination=${destDir}`,
202
+ ],
179
203
  {cwd: packageDir, encoding: 'utf-8', timeout: 60_000},
180
204
  );
181
205
  if (result.error) {
182
206
  throw new Error(`Could not start npm pack: ${result.error.message}`);
183
207
  }
184
208
  if (result.status !== 0) {
185
- const stderr = (result.stderr || '').trim();
209
+ const detail =
210
+ (result.stderr || '').trim() || npmPackErrorDetail(result.stdout);
186
211
  throw new Error(
187
- `npm pack failed (exit ${result.status})${stderr ? `: ${stderr}` : ''}.`,
212
+ `npm pack failed (exit ${result.status})${detail ? `: ${detail}` : ''}.`,
188
213
  );
189
214
  }
190
215
  return parseNpmPackOutput(result.stdout);
package/api/json/index.ts CHANGED
@@ -26,7 +26,6 @@ export type * from '../gap-report/gap-report.type.mjs';
26
26
  export type * from '../upgrade/upgrade.type.mjs';
27
27
  export type * from '../init/init.type.mjs';
28
28
  export type * from '../doctor/doctor.type.mjs';
29
- export type * from '../layout/layout.type.mjs';
30
29
  export type * from '../integration/validate-integration.type.mjs';
31
30
  export type * from '../integration/authoring-checks.type.mjs';
32
31
  export type * from '../integration/pack-check.type.mjs';