Skip to main content
Coordinate changes beyond a single file: secondary-file transforms, renames, and repo-scoped matrix runs.

Multi-Repo Orchestration

Use multi-repo orchestration when your codemod must coordinate changes across multiple repositories—such as updating shared libraries, enforcing consistency, or applying repo-specific logic. This approach streamlines large-scale migrations and ensures changes are applied uniformly.

Multi-File Transforms

Sometimes a codemod needs to modify multiple files in a coordinated way. For example, renaming a stylesheet file and updating its import. The example below demonstrates path changes only; it does not convert Less syntax to CSS. JSSG provides two mechanisms for this:

jssgTransform — Transform Secondary Files

Use jssgTransform() to apply a transform function to another file from within your main transform. The secondary file’s changes are collected and applied atomically alongside the primary file’s changes.
jssgTransform is a codemod 1.x API. It runs in standalone transforms (codemod jssg run), in workflow.yaml js-ast-grep steps, and in transforms a workflow.ts runs with jssgFile from codemod/compat, but not elsewhere in a workflow.ts. To type-check it, add "codemod/compat" to compilerOptions.types. See 1.x compatibility APIs.
jssgTransform is a no-op in test mode — it returns null without reading or writing files. This means test cases only verify the primary transform. To test secondary transforms, write separate test cases for them.

root.rename() — Rename the Current File

Use root.rename(newPath) to rename the file currently being processed. This is useful for file extension conversions (.js → .ts, .less → .css, .cjs → .mjs).
Rules:
  • Relative paths resolve against the file’s parent directory.
  • Absolute paths are used as-is.
  • The resolved path must stay within the target directory.
  • rename() can only be called once per file.
See the API Reference for the full behavior matrix.