Codemods that automate the mechanical parts of migrating an app across
@wraith-protocol/sdk major versions -- so upgrading doesn't mean
grep-and-sed by hand.
npx @wraith-protocol/codemod <version> [path] [options]version-- which transform set to run (currentlyv1), matching a folder undertransforms/.path-- file or directory to transform. Defaults to the current directory.
# Preview the diff without writing anything
npx @wraith-protocol/codemod v1 ./src --dry --print
# Apply it
npx @wraith-protocol/codemod v1 ./srcIt's safe to run more than once: every transform in this package is idempotent, and files that don't match a known pattern are left untouched.
| Flag | Description |
|---|---|
--dry |
Run without writing any changes to disk. |
--print |
Print transformed output to stdout. |
--extensions |
Comma-separated file extensions to process. Defaults to ts,tsx,js,jsx. |
--ignore |
Glob to skip. Can be passed more than once. node_modules is always ignored. |
Each transform in transforms/v1/ corresponds to one breaking change
documented in MIGRATING.md:
-
typed-error-catch.cjs-- rewritescatch (e) { if (e.message.includes('...')) }message-matching intoe instanceof <TypedError>checks, against a table of known, stable message fragments sourced directly fromsrc/errors.ts. It also adds/merges the required named import from@wraith-protocol/sdk. Only recognized fragments are rewritten -- anything else is left alone. -
install-react-native-polyfills.cjs-- detects React Native entry files (files importing from bothreact-nativeand@wraith-protocol/sdk) and inserts the now-requiredinstallReactNativePolyfills()call and import, if one isn't already present.
Every transform has a fixture pair under fixtures/ (an
input.* / output.* file), plus a no-op-file fixture used to confirm each
transform leaves non-matching code untouched. See test/ for the
snapshot-style tests that run each transform against its fixtures, plus an
end-to-end test that runs the same jscodeshift Runner the CLI uses against
a temp fixture app and checks idempotency across two full passes.
import { runCodemod, listTransformSets, listTransforms } from '@wraith-protocol/codemod';
const results = await runCodemod({ version: 'v1', target: './src' });- Create
transforms/v<N>/your-transform.cjs, exporting a standard jscodeshift transform function (module.exports = function (fileInfo, api, options) { ... }). - Add an
input.*/output.*fixture pair underfixtures/your-transform-name/. - Add a test in
test/asserting the transform matches the fixture output and is idempotent when run against its own output a second time. - Document the change in the root
MIGRATING.md, and link to it from the "Automated Migration" section at the top.