An open source design system that's fully customizable and agent ready
TypeScript
perf(cli): a project with no integration skips its issue passes (#9965)
Christopher Chedeaue2b522f83daf
diff --git a/.changeset/cli-issues-without-integrations.md b/.changeset/cli-issues-without-integrations.mdnew file mode 100644index 0000000000..1e0fef595d--- /dev/null+++ b/.changeset/cli-issues-without-integrations.md@@ -0,0 +1,7 @@+---+'@astryxdesign/cli': patch+---++[perf] With no integration loaded, the integration-issue check no longer imports every Core template doc. `astryx discover`, and `astryx component` without `--showcase` or `--blocks`, now import none of them.++@vjeuxdiff --git a/packages/cli/api/doctor/doctor.test.mjs b/packages/cli/api/doctor/doctor.test.mjsindex bbc9fecb9b..8de100b86d 100644--- a/packages/cli/api/doctor/doctor.test.mjs+++ b/packages/cli/api/doctor/doctor.test.mjs@@ -102,11 +102,15 @@ describe('doctor never reads the carried Core (spec AST-081 FR3)', () => {const load = vi.spyOn(Project, 'load');const coreDir = vi.spyOn(Project.prototype, 'coreDir');try {- await doctor({cwd: dir});+ const r = await doctor({cwd: dir});// Doctor's own project reads only the installed Core, and no Core a// project read during the run is the carried one.expect(load.mock.calls.some(([, options]) => options?.core === 'project')).toBe(true);- expect(coreDir).toHaveBeenCalled();+ // Nothing is installed, so the Core check fails. The carried Core would+ // pass it.+ expect(+ r.data.checks.find(check => check.id === 'core-installed'),+ ).toMatchObject({status: 'fail'});for (const result of coreDir.mock.results) expect(result.value).toBeNull();} finally {load.mockRestore();diff --git a/packages/cli/foundation/config/project.issues.test.mjs b/packages/cli/foundation/config/project.issues.test.mjsnew file mode 100644index 0000000000..3f40c78c36--- /dev/null+++ b/packages/cli/foundation/config/project.issues.test.mjs@@ -0,0 +1,100 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file project.issues.test.mjs+ * @input A consumer project with no integration, and one with an integration+ * whose template has no source, each under a repo-local temp dir+ * @output Proves that Project.issues() reads no template doc when no+ * integration is loaded, and still finds an integration's template issue+ * @position Beside project.test.mjs, in its own file because it replaces+ * the doc compiler's import module to count template doc imports+ */++import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';+import * as fs from 'node:fs';+import * as path from 'node:path';++const templateImports = vi.hoisted(() => ({count: 0}));++vi.mock('../doc-compiler/import.mjs', async importOriginal => {+ /** @type {typeof import('../doc-compiler/import.mjs')} */+ const original = await importOriginal();+ return {+ ...original,+ importTemplateModule: (/** @type {string} */ file) => {+ templateImports.count += 1;+ return original.importTemplateModule(file);+ },+ };+});++/** @type {typeof import('./project.mjs').Project} */+let Project;+/** @type {string} */+let tmpDir;+/** @type {string} */+let originalCwd;++beforeEach(async () => {+ // Fresh modules for each case, so no template discovery that an earlier+ // case ran can answer from memory and hide the imports.+ vi.resetModules();+ ({Project} = await import('./project.mjs'));+ originalCwd = process.cwd();+ // Repo-local, because Vite blocks the dynamic import of modules under /tmp.+ tmpDir = fs.mkdtempSync(+ path.join(process.cwd(), '.astryx-project-issues-test-'),+ );+ process.chdir(tmpDir);+ fs.writeFileSync(+ path.join(tmpDir, 'package.json'),+ JSON.stringify({name: 'consumer'}),+ );+ templateImports.count = 0;+});++afterEach(() => {+ process.chdir(originalCwd);+ fs.rmSync(tmpDir, {recursive: true, force: true});+});++describe('Project.issues()', () => {+ it('reads no template doc for a project with no integration', async () => {+ const project = await Project.load(tmpDir);+ expect(project.loadedIntegrations).toEqual([]);+ expect(await project.issues()).toEqual([]);+ expect(templateImports.count).toBe(0);+ });++ it("still finds an integration's template issue when nothing discovered templates first", async () => {+ fs.writeFileSync(+ path.join(tmpDir, 'astryx.config.mjs'),+ `export default ${JSON.stringify({integrations: ['@acme/widgets']})};\n`,+ );+ const pkgDir = path.join(tmpDir, 'node_modules', '@acme', 'widgets');+ fs.mkdirSync(path.join(pkgDir, 'templates'), {recursive: true});+ fs.writeFileSync(+ path.join(pkgDir, 'package.json'),+ JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),+ );+ fs.writeFileSync(+ path.join(pkgDir, 'astryx.integration.mjs'),+ `export default ${JSON.stringify({templates: './templates'})};\n`,+ );+ // A template doc with no source file beside it.+ fs.writeFileSync(+ path.join(pkgDir, 'templates', 'broken.template.mjs'),+ `export default {type: 'block', name: 'Broken', description: 'Missing source'};\n`,+ );+ const project = await Project.load(tmpDir);+ expect(await project.issues()).toEqual(+ expect.arrayContaining([+ expect.objectContaining({+ package: '@acme/widgets',+ code: 'invalid_template',+ }),+ ]),+ );+ expect(templateImports.count).toBeGreaterThan(0);+ });+});diff --git a/packages/cli/foundation/config/project.mjs b/packages/cli/foundation/config/project.mjsindex 1dd0f3a818..1745945b66 100644--- a/packages/cli/foundation/config/project.mjs+++ b/packages/cli/foundation/config/project.mjs@@ -1259,15 +1259,20 @@ export class Project {* @returns {Promise<ProjectIntegrationIssue[]>}*/async issues() {- // Template replacement validity depends on the combined Core + integration- // catalog. Resolve it first so issue results never depend on which discovery- // method the caller happened to invoke earlier.- await this.templates();- // Component replacement validity likewise depends on Core plus every- // integration's components.- await this.componentReplacements();- for (const integration of this.#loadedIntegrations) {- await this.#collectIssues(integration);+ // Each issue these passes find belongs to an integration, because Core's+ // templates and components declare no replacement. A project with no+ // integration skips them.+ if (this.#loadedIntegrations.length > 0) {+ // Template replacement validity depends on the combined Core ++ // integration catalog. Resolve it first so issue results never depend+ // on which discovery method the caller happened to invoke earlier.+ await this.templates();+ // Component replacement validity likewise depends on Core plus every+ // integration's components.+ await this.componentReplacements();+ for (const integration of this.#loadedIntegrations) {+ await this.#collectIssues(integration);+ }}// Return a stable copy so callers can't mutate internal state.return this.#issues.map(i => ({...i}));