Skip to content

fix(cli): skip non-codemod modules during integration codemod discovery (#4975) - #4989

Draft
gunjanjaswal wants to merge 1 commit into
meta:mainfrom
gunjanjaswal:fix/4975-discovery-skip-non-codemods
Draft

gunjanjaswal wants to merge 1 commit into
meta:mainfrom
gunjanjaswal:fix/4975-discovery-skip-non-codemods

Conversation

@gunjanjaswal

@gunjanjaswal gunjanjaswal commented Aug 13, 2026 •

Copy link
Copy Markdown

Draft, for discussion. Refs #4975.

#4975 is filed as a team decision rather than a fix, so this is one concrete take on option 1 (identify codemods by shape, skip non-codemods) to react to, not a claim that it's the chosen contract.

The problem

discoverIntegrationCodemods walks codemods/<version>/ and feeds every module to parseCodemod, so a single non-codemod module in that tree throws and drops the whole integration's codemods. A shared *.transform.mjs helper with named exports only has no codemod default export, so parseCodemod throws on it.

The test/spec/fixture half of this (__tests__/, *.test.*, *.spec.*, *.fixture.*) is already handled on main by #6230. This PR sits on top of that and does not touch the walk's path filtering.

This change

A module counts as a codemod only when it default-exports an object. That module is validated as before, so a genuinely broken codemod still fails loudly. A module with no object default export (a named-export helper, or one that default-exports a function) is treated as a co-located helper and skipped instead of failing discovery.

The contract change worth your call

This flips one deliberately strict behavior: a module with no codemod default export used to be a hard error, and it's now skipped. That's the exact line #4975 asks about. I kept it as narrow as I could, so only "no codemod-shaped default at all" is skipped, but it is a contract change, and the issue's other options (a documented helper suffix, a manifest-driven entry list) are still open.

Known limitation, tied to the same call

hasCodemodDefault keys on whether the default is an object. That holds for .mjs, but a helper written in .ts or CommonJS can still slip through: jiti synthesizes a namespace object as the default for a named-export .ts file, and the CJS loader sets default to module.exports. Either one looks like an object, so the helper reaches parseCodemod and throws anyway.

The obvious tightening is to require the codemod type discriminator on the default. But that contradicts the existing test "object default that isn't an envelope → throws": a {title, transform} with no type would then be skipped rather than a hard error, and that strictness is itself one of the choices #4975 is deciding. So I've left hasCodemodDefault on the object check rather than flip that test on my own. If the team wants type-gated detection, that test moves with it and I'll fold both into this PR.

Tests

  • renamed the existing "no default export → hard error" test to assert the helper is now skipped, with a real codemod alongside so the codemod is shown to survive;
  • kept the "object default that isn't an envelope → throws" and "missing transform → throws" tests, which still pass and pin the loud-failure contract.

Added a changeset (@astryxdesign/cli patch). Monorepo install is heavy locally, so the full vitest suite runs in CI.

@vercel

vercel Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 13, 2026 7:54am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 13, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Aug 13, 2026
github-actions Bot added a commit that referenced this pull request Sep 12, 2026
@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Current run: The current CI run concluded failure. Current analysis is unavailable.

The exact-head preview is not available yet.


Generated by PR Enrichment workflow | View current CI run

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs an engineering owner's decision before it can be approved, and it has three fixes to make whatever that decision is.

Decision needed: no current spec says which files under an integration's codemods/<version>/ folder are codemods, or whether a module without an object default export may be skipped instead of failing discovery. An engineering owner needs to provide or identify the governing spec for that rule (shape detection as here, or strict loading until there is a helper suffix or manifest list), and record the decision by commenting /approve-spec followed by the full head SHA on this pull request; the author may do so if they are an engineering owner.

Blocking:

  • Miss: a .ts helper with only named exports, and a CommonJS .js helper, still fail discovery, because integration-discovery.mjs:175 reads the loader's interop default, which jiti and CommonJS fill with the exports object, so the check should look at the module's own exports and the tests should cover .ts and CommonJS helpers.
  • The description lists skipping __tests__/, *.test.* and *.spec.* as part of this change, but the base already does that (#6230) and the new skips co-located test and spec files without loading them test passes without this change, so please drop that claim and the redundant test.
  • Miss: the change alters shipped @astryxdesign/cli behavior without a Changeset, which AST-017 FR7 requires for anything other than documentation, test or private-package changes.

If the shape rule is chosen, also update the strict wording in packages/cli/authoring/integration/type.ts and the integrations guide.

[Automated review]

// an object is still validated below and fails loudly if it is not a
// valid codemod envelope.
const mod = await importUserModule(file);
if (!hasCodemodDefault(mod?.default)) continue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mod.default is the loader's interop value, not proof of a default export: a .ts file loaded through jiti with only export const helper gives Object.keys(mod) of ['helper'] but mod.default of {helper}, and a CommonJS .js file's module.exports is always its default. Both cases still reach parseCodemod and throw, exactly as before this change. Consider checking the module's own exports, and add .ts and CommonJS helper cases to the tests.

).rejects.toThrow(/across versions/i);
});

it('skips co-located test and spec files without loading them', async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test passes against the base implementation: __tests__/ and *.test.*/*.spec.* files are already skipped by the existing walk (see the test files beside a codemod suite below). Consider dropping it or folding it into that suite, and dropping the matching item from the description.

Proposes RFC option 1 from meta#4975: identify codemods by shape rather than
treating every module under codemods/<version>/ as a codemod.

Builds on meta#6230, which already skips test/spec/fixture paths in the walk. On
top of that, a module counts as a codemod only when it default-exports an
object; a co-located helper (named exports only, or a default-exported
function) is skipped instead of being fed to parseCodemod. A module that does
default-export an object is still validated at the load boundary, so a
genuinely broken codemod (missing field, no type) still fails loudly.

Contract change: a module with no codemod default export was previously a hard
error; it is now treated as a co-located helper and skipped. This is the crux
meta#4975 defers to the team, so this stays a draft for discussion.

Refs meta#4975

This branch was successfully deployed

1 active deployment
Preview — 5c9b48a9 Deployed Nov 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant