Skip to content

Codemod

Terminal window
npm install -D @rep-protocol/codemod
# or
npx @rep-protocol/codemod [options] [files...]
Terminal window
rep-codemod [options] [files or directories...]
FlagDefaultDescription
-f, --framework <name>viteFramework preset: vite, cra, next
--dry-runfalsePreview changes without writing files
--extensions <list>ts,tsx,js,jsxComma-separated file extensions to process

Transforms import.meta.env.VITE_* to rep.get('*'):

// Before
const apiUrl = import.meta.env.VITE_API_URL;
// After
import { rep } from '@rep-protocol/sdk';
const apiUrl = rep.get('API_URL');

Vite built-ins (MODE, DEV, PROD, SSR, BASE_URL) are left untouched.

Transforms process.env.REACT_APP_* to rep.get('*'):

// Before
const apiUrl = process.env.REACT_APP_API_URL;
// After
import { rep } from '@rep-protocol/sdk';
const apiUrl = rep.get('API_URL');

Transforms process.env.NEXT_PUBLIC_* to rep.get('*'):

// Before
const apiUrl = process.env.NEXT_PUBLIC_API_URL;
// After
import { rep } from '@rep-protocol/sdk';
const apiUrl = rep.get('API_URL');
Terminal window
# Transform Vite project
rep-codemod --framework vite src/
# Dry run — preview changes
rep-codemod --framework cra --dry-run src/components/
# Specific files
rep-codemod --framework next src/app/page.tsx src/lib/api.ts
# JavaScript files only
rep-codemod --framework vite --extensions js,jsx src/
  • Idempotent — running twice produces the same result
  • Import management — adds import { rep } from '@rep-protocol/sdk' if absent
  • Non-destructive — only prefixed variables are transformed
  • Format-preserving — original formatting and comments are preserved (via jscodeshift/recast)
  1. Remove framework-specific type augmentations (e.g., vite-env.d.ts)
  2. Run rep typegen to generate typed overloads
  3. Update container config to set REP_PUBLIC_* environment variables