Skip to content

feat(codemods): move mobile-to-root to @react-simplikit/codemods on jscodeshift - #617

Merged
mnxmnz merged 10 commits into
mainfrom
feat/codemod-jscodeshift
Nov 30, 2026
Merged

mnxmnz merged 10 commits into
mainfrom
feat/codemod-jscodeshift

Conversation

@mnxmnz

@mnxmnz mnxmnz commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Overview

react-simplikit-codemod carried its own file walker, report format and TypeScript-compiler parser for its one transform, mobile-to-root. A second transform would have had to plug into all three. This PR renames the package to @react-simplikit/codemods and runs transforms through jscodeshift, so a transform is one file under src/transforms and the CLI only picks it and hands it to jscodeshift.

# before
npx react-simplikit-codemod mobile-to-root --dry-run

# after
npx @react-simplikit/codemods mobile-to-root . --dry
  • The CLI takes [codemod] [path]. In a terminal it asks for a missing argument; anywhere else it exits 1, because an unanswered prompt would otherwise end with 0 having changed nothing. --help lists the transforms.
  • Outside a dry run, it stops on uncommitted git changes or a git status it cannot read, since the files are rewritten in place. --force skips the check, and a folder outside a git repository is not checked.
  • jscodeshift runs from inside the target. Its ignore patterns match the whole path, so a project under a build or dist folder would otherwise have every file ignored.
  • mobile-to-root keeps its rewrite and merge rules and still edits by offset, so formatting, comments, quote style and CRLF line endings survive. It now parses with Babel through jscodeshift, with a Flow fallback for .js files. package.json handling is unchanged, and a manifest with a byte order mark now parses.
  • A mention of @react-simplikit/mobile left after the rewrite, such as a subpath import, is now reported even when the file had other imports to rewrite. Before, only a file with nothing to rewrite was reported.
  • An import with a line comment such as // @ts-expect-error right above it is left on its own line and reported, so the comment does not end up on another statement.
  • The version is fixed to react-simplikit through the changeset fixed group, and Node 22 or later is required, the oldest version CI runs.
  • The README, the agent skill and the repository docs use the new name and flags.
Before After
--dry-run --dry
--json Removed. Manual follow-ups print as jscodeshift REP lines
--ignore <glob> --jscodeshift="--ignore-pattern=<glob>"
--no-package-json Removed. Narrow the path instead
--debug Removed. jscodeshift prints the error for each file
The path defaults to . The path is asked for in a terminal and required elsewhere

Tests

  • 144 unit tests at 100% coverage, each testing one behaviour with literal expectations. The existing mobile-to-root cases run on the new parser; only the cases that relied on the TypeScript parser accepting invalid code changed.
  • 20 fixture pairs cover merges, commented imports, tabs, CRLF, BOM, declare module, Flow and sloppy-mode .js, .cjs/.mjs/.d.ts, and package.json with workspace:*, peer ranges and resolutions. The expected files are the old CLI's output, compared byte for byte without trimming. Each test also runs the transform again on the expected file and counts the REP reports. Inputs that must stay unchanged and an input that cannot parse have their own fixtures.
  • 25 e2e tests run the built bin with real git and jscodeshift: a dirty, clean, forced, dry-run, unreadable and missing git repository, a project under a build folder, a single file, a missing path, a run outside a terminal, --dry, --print, --jscodeshift, and the packed tarball. Only the interactive prompts keep mocked unit tests.
  • 137,541 files from internal repositories parse with the new parser, except files the TypeScript parser also reports a syntax error for, and one readonly Array<…> that tsc rejects too.

Limits:

  • A file that imports one name twice, once from each package, no longer parses, because Babel rejects the duplicate binding. It is reported as an error instead of being left on its own line. TypeScript rejects that file as well.
  • A .js file that uses Flow syntax and sloppy-mode syntax together still fails to parse.

Checklist

  • Did you write the test code?
  • Have you run yarn run fix to format and lint the code and docs? (yarn test passes)
  • Have you run yarn run test:coverage to make sure there is no uncovered line?
  • Did you write the JSDoc? (bin-only package, no public API)

…scodeshift

Follow the toss/suspensive codemods layout: a commander bin that prompts for
missing arguments in a terminal and spawns jscodeshift, with one file per
transform under src/transforms.

- mobile-to-root keeps its offset-based edits, now on Babel through
  jscodeshift's parsers (Flow fallback for .js, sloppy-mode scripts)
- jscodeshift runs from inside the target so ignore patterns never match
  a parent folder, and a missing path exits 1
- git-dirty check with --force, --jscodeshift passthrough, --fail-on-error
- --help lists the transforms; a run that wrote files prints next steps
- version fixed to react-simplikit, Node 20+
@codecov-commenter

codecov-commenter commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7f6b0ac) to head (2f7baaf).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              main      #617    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           70        67     -3     
  Lines         2364      2171   -193     
  Branches       763       692    -71     
==========================================
- Hits          2364      2171   -193     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Size Change: -6.47 kB (-5.16%) ✅

Total Size: 119 kB

📦 View Changed
Filename Size Change
packages/codemod/dist/cli.mjs 0 B -6.47 kB (removed) 🏆
ℹ️ View Unchanged
Filename Size
packages/codemods/dist/bin/codemods.cjs 2.75 kB
packages/codemods/dist/transforms/mobile-to-root.cjs 5.2 kB
packages/react-simplikit/dist/components/ImpressionArea/ImpressionArea.cjs 1.01 kB
packages/react-simplikit/dist/components/ImpressionArea/ImpressionArea.mjs 984 B
packages/react-simplikit/dist/components/Separated/Separated.cjs 686 B
packages/react-simplikit/dist/components/Separated/Separated.mjs 684 B
packages/react-simplikit/dist/components/SwitchCase/SwitchCase.cjs 778 B
packages/react-simplikit/dist/components/SwitchCase/SwitchCase.mjs 777 B
packages/react-simplikit/dist/hooks/useAsyncEffect/useAsyncEffect.cjs 625 B
packages/react-simplikit/dist/hooks/useAsyncEffect/useAsyncEffect.mjs 614 B
packages/react-simplikit/dist/hooks/useAvoidKeyboard/useAvoidKeyboard.cjs 985 B
packages/react-simplikit/dist/hooks/useAvoidKeyboard/useAvoidKeyboard.mjs 963 B
packages/react-simplikit/dist/hooks/useBodyScrollLock/useBodyScrollLock.cjs 975 B
packages/react-simplikit/dist/hooks/useBodyScrollLock/useBodyScrollLock.mjs 951 B
packages/react-simplikit/dist/hooks/useBooleanState/useBooleanState.cjs 546 B
packages/react-simplikit/dist/hooks/useBooleanState/useBooleanState.mjs 536 B
packages/react-simplikit/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.cjs 815 B
packages/react-simplikit/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.mjs 786 B
packages/react-simplikit/dist/hooks/useConditionalEffect/useConditionalEffect.cjs 980 B
packages/react-simplikit/dist/hooks/useConditionalEffect/useConditionalEffect.mjs 959 B
packages/react-simplikit/dist/hooks/useControlledState/useControlledState.cjs 1.04 kB
packages/react-simplikit/dist/hooks/useControlledState/useControlledState.mjs 1.03 kB
packages/react-simplikit/dist/hooks/useCounter/useCounter.cjs 1.03 kB
packages/react-simplikit/dist/hooks/useCounter/useCounter.mjs 1.01 kB
packages/react-simplikit/dist/hooks/useDebounce/debounce.cjs 463 B
packages/react-simplikit/dist/hooks/useDebounce/debounce.mjs 462 B
packages/react-simplikit/dist/hooks/useDebounce/useDebounce.cjs 1.28 kB
packages/react-simplikit/dist/hooks/useDebounce/useDebounce.mjs 1.26 kB
packages/react-simplikit/dist/hooks/useDebouncedCallback/useDebouncedCallback.cjs 1.15 kB
packages/react-simplikit/dist/hooks/useDebouncedCallback/useDebouncedCallback.mjs 1.12 kB
packages/react-simplikit/dist/hooks/useDebouncedValue/useDebouncedValue.cjs 1.21 kB
packages/react-simplikit/dist/hooks/useDebouncedValue/useDebouncedValue.mjs 1.18 kB
packages/react-simplikit/dist/hooks/useDoubleClick/useDoubleClick.cjs 1.11 kB
packages/react-simplikit/dist/hooks/useDoubleClick/useDoubleClick.mjs 1.1 kB
packages/react-simplikit/dist/hooks/useGeolocation/useGeolocation.cjs 2.04 kB
packages/react-simplikit/dist/hooks/useGeolocation/useGeolocation.mjs 2.04 kB
packages/react-simplikit/dist/hooks/useImpressionRef/useImpressionRef.cjs 1.25 kB
packages/react-simplikit/dist/hooks/useImpressionRef/useImpressionRef.mjs 1.22 kB
packages/react-simplikit/dist/hooks/useInputState/useInputState.cjs 728 B
packages/react-simplikit/dist/hooks/useInputState/useInputState.mjs 718 B
packages/react-simplikit/dist/hooks/useIntersectionObserver/useIntersectionObserver.cjs 1.11 kB
packages/react-simplikit/dist/hooks/useIntersectionObserver/useIntersectionObserver.mjs 1.08 kB
packages/react-simplikit/dist/hooks/useInterval/useInterval.cjs 837 B
packages/react-simplikit/dist/hooks/useInterval/useInterval.mjs 811 B
packages/react-simplikit/dist/hooks/useIsClient/useIsClient.cjs 585 B
packages/react-simplikit/dist/hooks/useIsClient/useIsClient.mjs 574 B
packages/react-simplikit/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs 646 B
packages/react-simplikit/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs 642 B
packages/react-simplikit/dist/hooks/useKeyboardHeight/useKeyboardHeight.cjs 736 B
packages/react-simplikit/dist/hooks/useKeyboardHeight/useKeyboardHeight.mjs 717 B
packages/react-simplikit/dist/hooks/useList/useList.cjs 945 B
packages/react-simplikit/dist/hooks/useList/useList.mjs 927 B
packages/react-simplikit/dist/hooks/useLoading/useLoading.cjs 961 B
packages/react-simplikit/dist/hooks/useLoading/useLoading.mjs 953 B
packages/react-simplikit/dist/hooks/useLongPress/useLongPress.cjs 1.83 kB
packages/react-simplikit/dist/hooks/useLongPress/useLongPress.mjs 1.8 kB
packages/react-simplikit/dist/hooks/useMap/useMap.cjs 752 B
packages/react-simplikit/dist/hooks/useMap/useMap.mjs 734 B
packages/react-simplikit/dist/hooks/useNetworkStatus/useNetworkStatus.cjs 1.61 kB
packages/react-simplikit/dist/hooks/useNetworkStatus/useNetworkStatus.mjs 1.59 kB
packages/react-simplikit/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.cjs 931 B
packages/react-simplikit/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.mjs 905 B
packages/react-simplikit/dist/hooks/usePageVisibility/usePageVisibility.cjs 1.28 kB
packages/react-simplikit/dist/hooks/usePageVisibility/usePageVisibility.mjs 1.25 kB
packages/react-simplikit/dist/hooks/usePreservedCallback/usePreservedCallback.cjs 751 B
packages/react-simplikit/dist/hooks/usePreservedCallback/usePreservedCallback.mjs 733 B
packages/react-simplikit/dist/hooks/usePreservedReference/usePreservedReference.cjs 805 B
packages/react-simplikit/dist/hooks/usePreservedReference/usePreservedReference.mjs 789 B
packages/react-simplikit/dist/hooks/usePrevious/usePrevious.cjs 643 B
packages/react-simplikit/dist/hooks/usePrevious/usePrevious.mjs 635 B
packages/react-simplikit/dist/hooks/useRefEffect/useRefEffect.cjs 836 B
packages/react-simplikit/dist/hooks/useRefEffect/useRefEffect.mjs 820 B
packages/react-simplikit/dist/hooks/useSafeAreaInset/useSafeAreaInset.cjs 942 B
packages/react-simplikit/dist/hooks/useSafeAreaInset/useSafeAreaInset.mjs 927 B
packages/react-simplikit/dist/hooks/useScrollDirection/useScrollDirection.cjs 1.3 kB
packages/react-simplikit/dist/hooks/useScrollDirection/useScrollDirection.mjs 1.28 kB
packages/react-simplikit/dist/hooks/useSet/useSet.cjs 1 kB
packages/react-simplikit/dist/hooks/useSet/useSet.mjs 974 B
packages/react-simplikit/dist/hooks/useStorageState/storage.cjs 543 B
packages/react-simplikit/dist/hooks/useStorageState/storage.mjs 527 B
packages/react-simplikit/dist/hooks/useStorageState/useStorageState.cjs 1.05 kB
packages/react-simplikit/dist/hooks/useStorageState/useStorageState.mjs 1.03 kB
packages/react-simplikit/dist/hooks/useThrottle/throttle.cjs 431 B
packages/react-simplikit/dist/hooks/useThrottle/throttle.mjs 422 B
packages/react-simplikit/dist/hooks/useThrottle/useThrottle.cjs 868 B
packages/react-simplikit/dist/hooks/useThrottle/useThrottle.mjs 841 B
packages/react-simplikit/dist/hooks/useThrottledCallback/useThrottledCallback.cjs 1.02 kB
packages/react-simplikit/dist/hooks/useThrottledCallback/useThrottledCallback.mjs 993 B
packages/react-simplikit/dist/hooks/useThrottledValue/useThrottledValue.cjs 1.15 kB
packages/react-simplikit/dist/hooks/useThrottledValue/useThrottledValue.mjs 1.12 kB
packages/react-simplikit/dist/hooks/useTimeout/useTimeout.cjs 627 B
packages/react-simplikit/dist/hooks/useTimeout/useTimeout.mjs 600 B
packages/react-simplikit/dist/hooks/useToggle/useToggle.cjs 524 B
packages/react-simplikit/dist/hooks/useToggle/useToggle.mjs 506 B
packages/react-simplikit/dist/hooks/useVisibilityEvent/useVisibilityEvent.cjs 738 B
packages/react-simplikit/dist/hooks/useVisibilityEvent/useVisibilityEvent.mjs 706 B
packages/react-simplikit/dist/hooks/useVisualViewport/useVisualViewport.cjs 1.54 kB
packages/react-simplikit/dist/hooks/useVisualViewport/useVisualViewport.mjs 1.53 kB
packages/react-simplikit/dist/index.cjs 1.39 kB
packages/react-simplikit/dist/index.mjs 1.01 kB
packages/react-simplikit/dist/utils/buildContext/buildContext.cjs 864 B
packages/react-simplikit/dist/utils/buildContext/buildContext.mjs 844 B
packages/react-simplikit/dist/utils/disableBodyScrollLock/disableBodyScrollLock.cjs 1.02 kB
packages/react-simplikit/dist/utils/disableBodyScrollLock/disableBodyScrollLock.mjs 1.01 kB
packages/react-simplikit/dist/utils/enableBodyScrollLock/enableBodyScrollLock.cjs 939 B
packages/react-simplikit/dist/utils/enableBodyScrollLock/enableBodyScrollLock.mjs 932 B
packages/react-simplikit/dist/utils/getKeyboardHeight/getKeyboardHeight.cjs 609 B
packages/react-simplikit/dist/utils/getKeyboardHeight/getKeyboardHeight.mjs 602 B
packages/react-simplikit/dist/utils/getSafeAreaInset/getSafeAreaInset.cjs 902 B
packages/react-simplikit/dist/utils/getSafeAreaInset/getSafeAreaInset.mjs 893 B
packages/react-simplikit/dist/utils/isAndroid/isAndroid.cjs 543 B
packages/react-simplikit/dist/utils/isAndroid/isAndroid.mjs 534 B
packages/react-simplikit/dist/utils/isIOS/isIOS.cjs 753 B
packages/react-simplikit/dist/utils/isIOS/isIOS.mjs 746 B
packages/react-simplikit/dist/utils/isKeyboardVisible/isKeyboardVisible.cjs 431 B
packages/react-simplikit/dist/utils/isKeyboardVisible/isKeyboardVisible.mjs 419 B
packages/react-simplikit/dist/utils/isServer/isServer.cjs 381 B
packages/react-simplikit/dist/utils/isServer/isServer.mjs 379 B
packages/react-simplikit/dist/utils/mergeProps/mergeProps.cjs 645 B
packages/react-simplikit/dist/utils/mergeProps/mergeProps.mjs 643 B
packages/react-simplikit/dist/utils/mergeRefs/mergeRefs.cjs 790 B
packages/react-simplikit/dist/utils/mergeRefs/mergeRefs.mjs 787 B
packages/react-simplikit/dist/utils/subscribeKeyboardHeight/subscribeKeyboardHeight.cjs 1.15 kB
packages/react-simplikit/dist/utils/subscribeKeyboardHeight/subscribeKeyboardHeight.mjs 1.14 kB

compressed-size-action

Each fixture pair comes from a real-world case, with the old CLI's output
as the expected file. Tests compare bytes without trimming, run the
transform again on the output, and count the REP reports. Inputs that must
not change and an input that cannot parse have their own fixtures.
.gitattributes keeps the CRLF and BOM fixtures byte for byte.
@changeset-bot

changeset-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2f7baaf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@react-simplikit/codemods Patch
react-simplikit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

…git errors

- Report a mention of @react-simplikit/mobile left after the rewrite, not
  only when nothing in the file could be rewritten; package.json reports a
  mention outside the dependency fields
- Leave an import on its own line when a line comment such as
  `// @ts-expect-error` sits right above it
- Join merged bindings with the file's own line ending
- Read a package.json that starts with a byte order mark
- Find jest.setMock, createMockFromModule, genMockFromModule, deepUnmock
  and vi.doUnmock
- Stop when git cannot read the status, instead of only skipping a
  folder outside a repository
- Drop the change records only the old --json report read
- Require Node 22, the oldest version CI runs; build in prepack

Tests now read arrange, act, assert with one behaviour each and literal
expectations. CLI behaviour that a pipe can drive moves from mocked unit
tests to the e2e suite with real git and jscodeshift.
tsdown runs publint on CI, publint packs the package, and packing ran
prepack, which built again. The loop ran until the runner shut down.
Release builds before publishing, so the package needs no lifecycle script.
@mnxmnz
mnxmnz marked this pull request as ready for review November 29, 2026 08:50
@mnxmnz
mnxmnz requested a review from hyesungoh as a code owner November 29, 2026 08:50

@hyesungoh hyesungoh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

great! LGTM 👍 👍

(just keep the first manual publish in mind 🙏 )

@mnxmnz
mnxmnz merged commit 359d4cb into main Nov 30, 2026
19 checks passed
@mnxmnz
mnxmnz deleted the feat/codemod-jscodeshift branch November 30, 2026 12:42
@github-actions github-actions Bot mentioned this pull request Nov 30, 2026
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.

3 participants