An open source design system that's fully customizable and agent ready
TypeScript
fix(cli): show a malformed package.json in doctor integration text output (#6559)
Joey496c949e5e57
diff --git a/.changeset/cli-spec-validate-malformed-package-json.md b/.changeset/cli-spec-validate-malformed-package-json.mdnew file mode 100644index 0000000000..d9108fcfb8--- /dev/null+++ b/.changeset/cli-spec-validate-malformed-package-json.md@@ -0,0 +1,7 @@+---+'@astryxdesign/cli': patch+---++[fix] `astryx doctor integration validate`, `templates`, `components`, and `docs` now show the `invalid_package_json` error when a local integration's package.json can't be parsed. Before, the text output said no `astryx.integration.*` file was found and hid the error, because the JSON reported a null `name`, which means no manifest. In that case `data.name` is now `(local package)`.++@josephfarinadiff --git a/packages/cli/api/integration/validate-integration.mjs b/packages/cli/api/integration/validate-integration.mjsindex 5a747cf9f0..f4574a4c85 100644--- a/packages/cli/api/integration/validate-integration.mjs+++ b/packages/cli/api/integration/validate-integration.mjs@@ -400,8 +400,10 @@ export async function validateLocalIntegration(cwd = process.cwd()) {try {pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));} catch (err) {+ // A null name means "no manifest here"; this package has one.return {found: true,+ name: '(local package)',manifestFile: manifests[0],issues: [error(diff --git a/packages/cli/api/integration/validateIntegration.doc.mjs b/packages/cli/api/integration/validateIntegration.doc.mjsindex e7d8a16eb7..037a89148e 100644--- a/packages/cli/api/integration/validateIntegration.doc.mjs+++ b/packages/cli/api/integration/validateIntegration.doc.mjs@@ -45,7 +45,7 @@ export const doc = {{type: 'integration.validate',description:- 'The result envelope: `data.name` and `data.version` of the validated package (both null when no local manifest is found), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message}.',+ 'The result envelope: `data.name` and `data.version` of the validated package (both null only when no local manifest is found; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message}.',},],examples: [diff --git a/packages/cli/clients/cli/commands/doctor-integration.package-json.test.mjs b/packages/cli/clients/cli/commands/doctor-integration.package-json.test.mjsnew file mode 100644index 0000000000..2f7c67cbf6--- /dev/null+++ b/packages/cli/clients/cli/commands/doctor-integration.package-json.test.mjs@@ -0,0 +1,53 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++import {afterEach, beforeEach, describe, expect, it} from 'vitest';+import * as fs from 'node:fs';+import * as path from 'node:path';+import {runCli} from '../../../test-utils/run-cli.mjs';+import {validateIntegration} from '../../../api/integration/validate-integration.mjs';++const NO_MANIFEST = 'No astryx.integration.* found next to package.json.';++let tmpDir;++beforeEach(() => {+ tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-pkgjson-'));+ fs.writeFileSync(path.join(tmpDir, 'package.json'), '{"name": "@acme/widgets",}\n');+ fs.writeFileSync(+ path.join(tmpDir, 'astryx.integration.mjs'),+ "export default {\n templates: './templates',\n};\n",+ );+});++afterEach(() => {+ fs.rmSync(tmpDir, {recursive: true, force: true});+});++describe('doctor integration with a malformed package.json', () => {+ it('keeps a null name for the no-manifest case only', async () => {+ const result = await validateIntegration(undefined, {cwd: tmpDir});++ expect(result.data.name).toBe('(local package)');+ expect(result.data.issues.map(issue => issue.code)).toEqual([+ 'invalid_package_json',+ ]);+ });++ for (const leaf of ['validate', 'templates', 'components', 'docs']) {+ it(`${leaf} prints the package.json error instead of "no manifest"`, async () => {+ const text = await runCli(['doctor', 'integration', leaf], tmpDir);+ const json = await runCli(+ ['doctor', 'integration', leaf, '--json'],+ tmpDir,+ );++ expect(text.status).toBe(1);+ expect(json.status).toBe(1);+ expect(text.stdout).not.toContain(NO_MANIFEST);+ expect(text.stdout).toContain('invalid_package_json');+ expect(JSON.parse(json.stdout).data.issues).toContainEqual(+ expect.objectContaining({code: 'invalid_package_json'}),+ );+ });+ }+});