An open source design system that's fully customizable and agent ready
TypeScript
perf(cli): the manifest writer loads jscodeshift only to patch (#10051)
Christopher Chedeau35bbaee4feab
diff --git a/.changeset/cli-manifest-writer-lazy-codemod.md b/.changeset/cli-manifest-writer-lazy-codemod.mdnew file mode 100644index 0000000000..736f8b9d9e--- /dev/null+++ b/.changeset/cli-manifest-writer-lazy-codemod.md@@ -0,0 +1,7 @@+---+'@astryxdesign/cli': patch+---++[perf] The integration manifest writer loads the code-rewrite toolkit only when it patches a manifest. `astryx component`, `astryx theme list` and `astryx doctor` outside a project no longer load it, and a component lookup loads about 70 fewer modules.++@vjeuxdiff --git a/packages/cli/clients/cli/startup-imports.test.mjs b/packages/cli/clients/cli/startup-imports.test.mjsindex 3dcd195e73..adad00e699 100644--- a/packages/cli/clients/cli/startup-imports.test.mjs+++ b/packages/cli/clients/cli/startup-imports.test.mjs@@ -5,8 +5,9 @@* the version, in a folder with no project, loads none of the large parser,* schema and module-loader packages, and none of the CLI's own doc, discovery,* project and integration modules. The project, integration and contribution- * modules use them. A module hook in the child records every module that the- * run resolves.+ * modules use them. A component lookup loads no code-rewrite package, which+ * only patching an integration manifest uses. A module hook in the child+ * records every module that the run resolves.*/import {spawnSync} from 'node:child_process';@@ -169,3 +170,18 @@ describe('a run of the bin that prints the version', () => {},);});++describe('a component lookup in a folder with no project', () => {+ it('loads no code-rewrite package (astryx component Buttn)', () => {+ const {status, packages, cliModules} = modulesLoadedBy([+ 'component',+ 'Buttn',+ ]);+ // No component has that name, so the run ends with its suggestions.+ expect(status).toBe(1);+ expect(cliModules.has('clients/cli/commands/component.mjs')).toBe(true);+ expect(+ ['jscodeshift', 'recast'].filter(name => packages.has(name)),+ ).toEqual([]);+ });+});diff --git a/packages/cli/foundation/integrations/manifest-writer.mjs b/packages/cli/foundation/integrations/manifest-writer.mjsindex 8d0aa469c1..8d119e80fb 100644--- a/packages/cli/foundation/integrations/manifest-writer.mjs+++ b/packages/cli/foundation/integrations/manifest-writer.mjs@@ -13,7 +13,6 @@ import * as fs from 'node:fs';import * as path from 'node:path';import {randomUUID} from 'node:crypto';import {publishNewFile} from '../fs/publish-file.mjs';-import jscodeshift from 'jscodeshift';import {assertWithin} from '../fs/path-safety.mjs';import {findManifestPaths, loadManifestObject} from './integrations.mjs';@@ -97,8 +96,8 @@ function propertyNamed(property, name) {/*** Find the object literal an integration manifest exports.- * @param {ReturnType<typeof jscodeshift.withParser>} j- * @param {ReturnType<ReturnType<typeof jscodeshift.withParser>>} ast+ * @param {ReturnType<typeof import('jscodeshift').default.withParser>} j+ * @param {ReturnType<ReturnType<typeof import('jscodeshift').default.withParser>>} ast* @returns {any|null}*/export function findManifestObject(j, ast) {@@ -290,6 +289,9 @@ export async function patchIntegrationRoot(const source = manifestExists? fs.readFileSync(manifestFile, 'utf-8'): 'export default {};\n';+ // The code-rewrite toolkit loads only to patch a manifest. Finding one,+ // which many commands do through this module, never needs it.+ const {default: jscodeshift} = await import('jscodeshift');const j = jscodeshift.withParser('tsx');let ast;try {