Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/twenty-teeth-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"debarrel": minor
---

Multiple workflows in debarreling codemod
11 changes: 10 additions & 1 deletion codemods/debarrel/codemod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ version: "0.6.1"
description: "Debarrel JS/TS codebases. Removing barrel files and replacing import statements."
author: "Mo Mohebifar <mo@codemod.com>"
license: "MIT"
workflow: "workflow.yaml"
repository: https://github.com/codemod/useful-codemods

targets:
Expand All @@ -18,3 +17,13 @@ registry:
visibility: "public"

capabilities: ["fs"]

workflows:
- name: regular
description: "Just debarrel the whole codebase at once!"
default: true
path: workflow.yaml
- name: sharded
description: "A sharded version of the main workflow, which can be used to break down the migration into parallel tasks."
default: false
path: workflow-sharded.yaml
122 changes: 122 additions & 0 deletions codemods/debarrel/workflow-sharded.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/codemod/codemod/refs/heads/main/schemas/workflow.json

version: "1"

state:
schema:
shards:
type: array
items:
type: object
properties:
name:
type: string
team:
type: string
directory:
type: string
_meta_shard:
type: number
_meta_files:
type: array
items:
type: string

params:
schema:
shardingMethod:
name: "Sharding Method"
description: "The method to use for sharding"
type: string
default: "codeowner"
oneOf:
- type: string
enum:
- "codeowner"
- "directory"
shardingDirectoryTarget:
name: "Sharding Directory Target"
description: "When sharding by directory, the directory to target for the codemod"
type: string
default: "./src"
pr_size:
name: "PR Size"
description: "The maximum number of files to include in each PR"
type: number
default: 20

nodes:
- id: evaluate-shards
name: Evaluate Shards
trigger:
type: automatic
steps:
- name: "Evaluate shards by directory"
if: params.shardingMethod == "directory"
shard:
method:
type: directory
max_files_per_shard: ${{ params.pr_size }}
target: ${{ params.shardingDirectoryTarget }}
output_state: shards
js-ast-grep:
js_file: scripts/codemod.ts
language: "tsx"
semantic_analysis: workspace
include:
- "**/*.ts"
- "**/*.tsx"
- "**/*.jsx"
- "**/*.js"
- "**/*.mjs"
- name: "Evaluate shards by codeowner"
if: params.shardingMethod == "codeowner"
shard:
method:
type: codeowner
max_files_per_shard: ${{ params.pr_size }}
target: "."
output_state: shards
js-ast-grep:
js_file: scripts/codemod.ts
language: "tsx"
semantic_analysis: workspace
include:
- "**/*.ts"
- "**/*.tsx"
- "**/*.jsx"
- "**/*.js"
- "**/*.mjs"

- id: apply-transforms
name: Apply AST Transformations
trigger:
type: manual
depends_on:
- evaluate-shards
strategy:
type: matrix
from_state: shards
pull_request:
title: "[DRAFT] refactor: Run debarrel shard ${{ matrix.name }}"
body: "This pull request runs debarrel for shard ${{ matrix.name }}."
draft: true
steps:
- id: debarrel-js-ast-grep
name: "Debarrel: rewrite imports and clean up barrels"
js-ast-grep:
js_file: scripts/codemod.ts
language: "tsx"
semantic_analysis: workspace

- id: install-skill
name: Install Skill
trigger:
type: manual
depends_on:
- apply-transforms
steps:
- name: "Install debarrel skill"
install-skill:
package: "debarrel"
path: "./agents/skill/SKILL.md"
108 changes: 0 additions & 108 deletions codemods/debarrel/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,121 +2,13 @@

version: "1"

state:
schema:
shards:
type: array
items:
type: object
properties:
name:
type: string
team:
type: string
directory:
type: string
_meta_shard:
type: number
_meta_files:
type: array
items:
type: string

params:
schema:
shardingMethod:
name: "Sharding Method"
description: "The method to use for sharding"
type: string
default: "codeowner"
oneOf:
- type: string
enum:
- "codeowner"
- "directory"
shardingDirectoryTarget:
name: "Sharding Directory Target"
description: "When sharding by directory, the directory to target for the codemod"
type: string
default: "./src"
pr_size:
name: "PR Size"
description: "The maximum number of files to include in each PR"
type: number
default: 20

nodes:
- id: evaluate-shards
name: Evaluate Shards
trigger:
type: automatic
steps:
- name: "Evaluate shards by directory"
if: params.shardingMethod == "directory"
shard:
method:
type: directory
max_files_per_shard: ${{ params.pr_size }}
target: ${{ params.shardingDirectoryTarget }}
output_state: shards
js-ast-grep:
js_file: scripts/codemod.ts
language: "tsx"
semantic_analysis: workspace
include:
- "**/*.ts"
- "**/*.tsx"
- "**/*.jsx"
- "**/*.js"
- "**/*.mjs"
- name: "Evaluate shards by codeowner"
if: params.shardingMethod == "codeowner"
shard:
method:
type: codeowner
max_files_per_shard: ${{ params.pr_size }}
target: "."
output_state: shards
js-ast-grep:
js_file: scripts/codemod.ts
language: "tsx"
semantic_analysis: workspace
include:
- "**/*.ts"
- "**/*.tsx"
- "**/*.jsx"
- "**/*.js"
- "**/*.mjs"

- id: apply-transforms
name: Apply AST Transformations
trigger:
type: manual
depends_on:
- evaluate-shards
strategy:
type: matrix
from_state: shards
pull_request:
title: "[DRAFT] refactor: Run debarrel shard ${{ matrix.name }}"
body: "This pull request runs debarrel for shard ${{ matrix.name }}."
draft: true
steps:
- id: debarrel-js-ast-grep
name: "Debarrel: rewrite imports and clean up barrels"
js-ast-grep:
js_file: scripts/codemod.ts
language: "tsx"
semantic_analysis: workspace

- id: install-skill
name: Install Skill
trigger:
type: manual
depends_on:
- apply-transforms
steps:
- name: "Install debarrel skill"
install-skill:
package: "debarrel"
path: "./agents/skill/SKILL.md"
Loading