Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = tab
insert_final_newline = true
max_line_length = 100
trim_trailing_whitespace = true

[*.json]
indent_style = space

[*.{yaml,yml}]
indent_style = space
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
File renamed without changes.
41 changes: 41 additions & 0 deletions .github/workflows/ci-legacy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI - Legacy

on:
push:
pull_request:

permissions:
contents: read

jobs:
build-test-legacy:
runs-on: ubuntu-latest
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0

- uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
name: Install pnpm
with:
version: 10
run_install: false

- name: Install Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version-file: ".nvmrc"
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Build legacy
run: pnpm build:legacy

- name: Run legacy tests
run: pnpm test:legacy
30 changes: 30 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Code quality

on:
push:
pull_request:

permissions:
contents: read

jobs:
quality:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Setup Biome
uses: biomejs/setup-biome@454fa0d884737805f48d7dc236c1761a0ac3cc13 # v2.6.0
with:
version: latest
- name: Run Biome
run: biome ci .
2 changes: 1 addition & 1 deletion .github/workflows/publish-legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
node-version-file: ".nvmrc"

- name: Install dependencies
run: |
Expand Down
4 changes: 0 additions & 4 deletions .husky/pre-commit

This file was deleted.

1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24
131 changes: 109 additions & 22 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,123 @@ Please [chat with us](https://go.codemod.com/community) before making any major
To run the transform scripts use [`codemod`](https://go.codemod.com/github) command below:

```console
$ npx codemod <transform> --target <path> [...options]
$ npx codemod <package-name>
```

- `transform` - name of transform. see available transforms below.
- `path` - directory to transform. defaults to the current directory.

The `package-name` is name of transform. see available transforms below.
See the [codemod CLI doc](https://go.codemod.com/cli-docs) for a full list of available commands.

All codemods are also available in the [Codemod Registry](https://go.codemod.com/registry).

## GitHub Action
## Development

Project structures:

```txt
codemods/
├─ project/
│ ├─ recipes/
│ │ ├─ src/
│ │ │ ├─ feature.ts
│ │ ├─ tests/
│ │ │ ├─ input/
│ │ │ │ ├─ case-1.js
│ │ │ │ ├─ case-2.js
│ │ │ │ ├─ case-x.js
│ │ │ ├─ expected/
│ │ │ │ ├─ case-1.js
│ │ │ │ ├─ case-2.js
│ │ │ │ ├─ case-x.js
│ │ ├─ codemod.yaml
│ │ ├─ package.json
│ │ ├─ README.md
│ │ ├─ workflow.yaml
│ ├─ vx-to-vx/
│ │ ├─ codemod.yaml
│ │ ├─ package.json
│ │ ├─ README.md
│ │ ├─ workflow.yaml
utilities/
├─ src/
│ ├─ node-utilisies.ts
├─ package.json
package.json
README.md
```

- `codemods` dir represents the collection of projects
- `project` is a placeholder for a project name (eg: `react`, `angular`, `vue`, etc)
- `recipes` is a collection of related codemods (eg: `v18-to-v19`, `react-class-to-function`)
- `utilities` is a internal package that provides shared utilities for codemods (eg: ast-grep queries)

Use the composite action in this repository to run the Codemod CLI in GitHub Actions:
### `codemod.yaml` example

```yaml
name: Codemod
on:
workflow_dispatch:
jobs:
run-codemod:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run codemod (dry run)
uses: codemod-com/commons@v0
with:
args: "@codemod-com/your-codemod --dry-run"
schema_version: "1.0"
name: "<project>/<codemod-name>"
version: 1.0.0
description: <Your codemod description>
author: <Your Name>
license: MIT
workflow: workflow.yaml
category: migration

targets:
languages:
- javascript
- typescript

keywords:
- transformation
- migration

registry:
access: public
visibility: public
```

Notes:
- `inputs.args` is passed to `npx codemod` and defaults to `--version`.
- The Action wraps `npx -y codemod`; no install needed.
- To publish on Marketplace, create a tagged release (e.g., `v0.0.1`) and select "Publish this Action to Marketplace" when drafting the release.
### `package.json` example

```json
{
"name": "@<project-name>/<migration-name>",
"version": "0.0.1",
"private": true,
"devDependencies": {
"@codemod.com/jssg-types": "catalog:"
},
"scripts": {
"test": "npx codemod jssg test -l typescript ./src/workflow.ts ./"
}
}
```

### `workflow.yaml` example

```yaml
# yaml-language-server: $schema=https://raw.githubusercontent.com/codemod/codemod/refs/heads/main/schemas/workflow.json

version: "1"

nodes:
- id: apply-transforms
name: Apply AST Transformations
type: automatic
steps:
- name: Handle DEP0147 via transforming `fs.rmdir` to `fs.rm`.
js-ast-grep:
js_file: src/workflow.ts
base_path: .
include:
- "**/*.js"
- "**/*.jsx"
- "**/*.mjs"
- "**/*.cjs"
- "**/*.cts"
- "**/*.mts"
- "**/*.ts"
- "**/*.tsx"
exclude:
- "**/node_modules/**"
language: typescript
```
23 changes: 0 additions & 23 deletions action.yml

This file was deleted.

Loading