Repository navigation
fix(cli): skip non-codemod modules during integration codemod discovery (#4975) - #4989
gunjanjaswal wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report
The exact-head preview is not available yet. Generated by PR Enrichment workflow | View current CI run |
060cf35 to
347b0bb
Compare
There was a problem hiding this comment.
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
.tshelper with only named exports, and a CommonJS.jshelper, still fail discovery, becauseintegration-discovery.mjs:175reads the loader's interopdefault, 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.tsand CommonJS helpers. - The description lists skipping
__tests__/,*.test.*and*.spec.*as part of this change, but the base already does that (#6230) and the newskips co-located test and spec files without loading themtest passes without this change, so please drop that claim and the redundant test. - Miss: the change alters shipped
@astryxdesign/clibehavior 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; |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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
347b0bb to
5c9b48a
Compare
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
discoverIntegrationCodemodswalkscodemods/<version>/and feeds every module toparseCodemod, so a single non-codemod module in that tree throws and drops the whole integration's codemods. A shared*.transform.mjshelper with named exports only has no codemod default export, soparseCodemodthrows on it.The test/spec/fixture half of this (
__tests__/,*.test.*,*.spec.*,*.fixture.*) is already handled onmainby #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
hasCodemodDefaultkeys on whether the default is an object. That holds for.mjs, but a helper written in.tsor CommonJS can still slip through: jiti synthesizes a namespace object as the default for a named-export.tsfile, and the CJS loader setsdefaulttomodule.exports. Either one looks like an object, so the helper reachesparseCodemodand throws anyway.The obvious tightening is to require the codemod
typediscriminator on the default. But that contradicts the existing test "object default that isn't an envelope → throws": a{title, transform}with notypewould then be skipped rather than a hard error, and that strictness is itself one of the choices #4975 is deciding. So I've lefthasCodemodDefaulton 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
Added a changeset (
@astryxdesign/clipatch). Monorepo install is heavy locally, so the fullvitestsuite runs in CI.