Skip to content

feat(ui-codemods): add codemod to support versioned import updates#2513

Merged
joyenjoyer merged 2 commits intomasterfrom
INSTUI-4954-write-codemod-for-automatic-dependency-updates
Apr 23, 2026
Merged

feat(ui-codemods): add codemod to support versioned import updates#2513
joyenjoyer merged 2 commits intomasterfrom
INSTUI-4954-write-codemod-for-automatic-dependency-updates

Conversation

@joyenjoyer
Copy link
Copy Markdown
Contributor

@joyenjoyer joyenjoyer commented Apr 13, 2026

Summary

  • Adds updateInstUIImportVersions jscodeshift codemod that rewrites @instructure/*
    import paths to a specific version subpath (e.g. @instructure/ui-buttons/v11_7)
  • Handles mixed imports (versioned components alongside non-versioned utilities/types) by splitting
    them into two declarations rather than blindly rewriting everything
  • Adds a generateVersionedExports script that reads the latest version summary file in
    @instructure/ui to auto-generate the list of known versioned components; wired
    into prepare-build so it stays up to date

Test Plan

  • Run unit tests with pnpm run test:vitest ui-codemods
  • Check the new section in the upgrade guide to learn how to use the new codemod
  • Test the new commands manually

Either you test the new commands in a chosen path or I recommend using the canvas-lms project. Check out the canvas repo from this link: https://github.com/instructure/canvas-lms

Diagnose command

Diagnose — all versioned components (no files written)

  • Verify output lists @instructure imports with their version ([v11_7 or v11_6] for
    already-migrated files, [oldest] for legacy unversioned JSX files)
  • Verify git status shows no changes
npx jscodeshift@latest -t /instructure-ui/packages/ui-codemods/lib/updateInstUIImportVersions.ts /canvas-lms --extensions=ts,tsx --ignore-pattern="**/node_modules/**" --ignore-pattern="**/*.d.ts" --diagnose=true

Diagnose — filter to specific components:

  • Verify only Button/Alert import lines appear in output
npx jscodeshift@latest -t /instructure-ui/packages/ui-codemods/lib/updateInstUIImportVersions.ts /canvas-lms --extensions=ts,tsx --ignore-pattern="**/node_modules/**" --ignore-pattern="**/*.d.ts" --diagnose=true --components=Button,Alert                                                                          

Update command

Update — all versioned components to v11.7:

  • Spot-check a legacy file whether an unversioned component got updated to v11_7 (for example unversioned @instructure/ui-buttons → @instructure/ui-buttons/v11_7)
npx jscodeshift@latest -t /instructure-ui/packages/ui-codemods/lib/updateInstUIImportVersions.ts /canvas-lms --extensions=ts,tsx --ignore-pattern="**/node_modules/**" --ignore-pattern="**/*.d.ts" --versionTo=v11.7 --usePrettier=false                                                                    

Update — only imports pinned to a specific version (--versionFrom):

  • There is no component imported from v11.6 yet, so change an import path manually in a canvas codebase file (for example import {View} from '@instructure/ui-view' to import {View} from '@instructure/ui-view/v11_6')
  • Check whether the command updates the manually changed line so the version suffix is changed to v11_7
npx jscodeshift@latest -t /instructure-ui/packages/ui-codemods/lib/updateInstUIImportVersions.ts /canvas-lms --extensions=ts,tsx --ignore-pattern="**/node_modules/**" --ignore-pattern="**/*.d.ts" versionFrom=v11.6 --versionTo=v11.7 --usePrettier=false                                                                    

Update — specific components only (--components):

  • Verify only files importing Button or Alert are rewritten; all other packages untouched
npx jscodeshift@latest -t /instructure-ui/packages/ui-codemods/lib/updateInstUIImportVersions.ts /canvas-lms --extensions=ts,tsx --ignore-pattern="**/node_modules/**" --ignore-pattern="**/*.d.ts" --versionTo=v11.7 --components=Button,Alert --usePrettier=false                                                                    

@joyenjoyer joyenjoyer force-pushed the INSTUI-4954-write-codemod-for-automatic-dependency-updates branch 2 times, most recently from 67cd411 to 2800cc5 Compare April 13, 2026 13:43
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 13, 2026

PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-04-23 08:47 UTC

@joyenjoyer joyenjoyer force-pushed the INSTUI-4954-write-codemod-for-automatic-dependency-updates branch from 2800cc5 to a129ec6 Compare April 14, 2026 07:26
Comment thread packages/ui-codemods/lib/updateInstUIImportVersions.ts Fixed
@joyenjoyer joyenjoyer force-pushed the INSTUI-4954-write-codemod-for-automatic-dependency-updates branch from a129ec6 to b2a270a Compare April 14, 2026 07:32
@joyenjoyer joyenjoyer self-assigned this Apr 14, 2026
Comment thread docs/guides/upgrade-guide.md Outdated
@joyenjoyer joyenjoyer force-pushed the INSTUI-4954-write-codemod-for-automatic-dependency-updates branch from b2a270a to 81662ed Compare April 15, 2026 14:21
@matyasf matyasf requested a review from balzss April 17, 2026 08:42
Copy link
Copy Markdown
Collaborator

@matyasf matyasf left a comment

Choose a reason for hiding this comment

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

See my comments. Overall it looks OK

Comment thread scripts/bootstrap.js Outdated
Comment thread packages/ui-codemods/package.json Outdated
Comment thread packages/ui-codemods/scripts/generateVersionedExports.ts Outdated
Comment thread packages/ui-codemods/.gitignore
Comment thread packages/ui-codemods/scripts/generateVersionedExports.ts Outdated
Comment thread packages/ui-codemods/scripts/generateVersionedExports.ts
Comment thread packages/ui-codemods/lib/__node_tests__/updateInstUIImportVersions.test.ts Outdated
Comment thread packages/ui-codemods/lib/__node_tests__/updateInstUIImportVersions.test.ts Outdated
Comment thread packages/ui-codemods/lib/__node_tests__/updateInstUIImportVersions.test.ts Outdated
@joyenjoyer joyenjoyer force-pushed the INSTUI-4954-write-codemod-for-automatic-dependency-updates branch from ce06caa to 7da8378 Compare April 21, 2026 13:40
Comment thread scripts/bootstrap.js
@@ -1,5 +1,4 @@
#! /usr/bin/env node
/* eslint-disable no-console */
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Linter complained about this, I removed it.

@matyasf matyasf self-requested a review April 22, 2026 09:45
Copy link
Copy Markdown
Collaborator

@matyasf matyasf left a comment

Choose a reason for hiding this comment

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

looks good!

@joyenjoyer joyenjoyer merged commit 45b6a0e into master Apr 23, 2026
8 of 9 checks passed
@joyenjoyer joyenjoyer deleted the INSTUI-4954-write-codemod-for-automatic-dependency-updates branch April 23, 2026 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants