diff --git a/codemods/debarrel/scripts/codemod.ts b/codemods/debarrel/scripts/codemod.ts index 725e7ef..c6df173 100644 --- a/codemods/debarrel/scripts/codemod.ts +++ b/codemods/debarrel/scripts/codemod.ts @@ -1,4 +1,4 @@ -import type { Transform, Edit, SgNode } from "codemod:ast-grep"; +import type { Transform, Edit, SgNode, GetSelector } from "codemod:ast-grep"; import type TSX from "codemod:ast-grep/langs/tsx"; import type TypeScript from "codemod:ast-grep/langs/typescript"; import type JavaScript from "codemod:ast-grep/langs/javascript"; @@ -432,4 +432,12 @@ const transform: Transform = async (root) => { return rootNode.commitEdits(edits); }; +export const getSelector: GetSelector = () => { + return { + rule: { + any: [{ kind: "import_statement" }, { kind: "export_statement" }], + }, + }; +}; + export default transform; diff --git a/codemods/debarrel/tsconfig.json b/codemods/debarrel/tsconfig.json index 469fc5a..bb7ca7b 100644 --- a/codemods/debarrel/tsconfig.json +++ b/codemods/debarrel/tsconfig.json @@ -5,13 +5,14 @@ "types": ["@codemod.com/jssg-types"], "allowImportingTsExtensions": true, "noEmit": true, - "verbatimModuleSyntax": true, - "erasableSyntaxOnly": true, "strict": true, "strictNullChecks": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, - "noUncheckedIndexedAccess": true + "noUncheckedIndexedAccess": true, + // Keep this until the LLRT ambient declarations in @codemod.com/jssg-types + // stop conflicting with TypeScript's standard library declarations. + "skipLibCheck": true }, "exclude": ["tests"] } diff --git a/codemods/debarrel/workflow.yaml b/codemods/debarrel/workflow.yaml index 7273972..8c37d7c 100644 --- a/codemods/debarrel/workflow.yaml +++ b/codemods/debarrel/workflow.yaml @@ -2,10 +2,86 @@ 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" + 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: 30 + target: ${{ params.shardingDirectoryTarget }} + output_state: shards + js-ast-grep: + js_file: scripts/codemod.ts + language: "typescript" + - name: "Evaluate shards by codeowner" + if: params.shardingMethod == "codeowner" + shard: + method: + type: codeowner + max_files_per_shard: 30 + target: "." + output_state: shards + js-ast-grep: + js_file: scripts/codemod.ts + language: "typescript" + - id: apply-transforms name: Apply AST Transformations - type: automatic + 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" @@ -13,8 +89,15 @@ nodes: js_file: scripts/codemod.ts language: "typescript" semantic_analysis: workspace - - id: install-package-skill - name: Install package skill + + - 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" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f6d30f9..c753089 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -22,7 +22,7 @@ importers: devDependencies: '@changesets/cli': specifier: ^2.30.0 - version: 2.30.0 + version: 2.30.0(@types/node@25.5.2) codemods/debarrel: dependencies: @@ -134,6 +134,9 @@ packages: '@types/node@12.20.55': resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==} + '@types/node@25.5.2': + resolution: {integrity: sha512-tO4ZIRKNC+MDWV4qKVZe3Ql/woTnmHDr5JD8UI5hn2pwBrHEwOEMZK7WlNb5RKB6EoJ02gwmQS9OrjuFnZYdpg==} + ansi-colors@4.1.3: resolution: {integrity: sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==} engines: {node: '>=6'} @@ -412,6 +415,9 @@ packages: engines: {node: '>=14.17'} hasBin: true + undici-types@7.18.2: + resolution: {integrity: sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==} + universalify@0.1.2: resolution: {integrity: sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==} engines: {node: '>= 4.0.0'} @@ -454,7 +460,7 @@ snapshots: dependencies: '@changesets/types': 6.1.0 - '@changesets/cli@2.30.0': + '@changesets/cli@2.30.0(@types/node@25.5.2)': dependencies: '@changesets/apply-release-plan': 7.1.0 '@changesets/assemble-release-plan': 6.0.9 @@ -470,7 +476,7 @@ snapshots: '@changesets/should-skip-package': 0.1.2 '@changesets/types': 6.1.0 '@changesets/write': 0.4.0 - '@inquirer/external-editor': 1.0.3 + '@inquirer/external-editor': 1.0.3(@types/node@25.5.2) '@manypkg/get-packages': 1.1.3 ansi-colors: 4.1.3 enquirer: 2.4.1 @@ -570,10 +576,12 @@ snapshots: '@codemod.com/jssg-types@1.5.1': {} - '@inquirer/external-editor@1.0.3': + '@inquirer/external-editor@1.0.3(@types/node@25.5.2)': dependencies: chardet: 2.1.1 iconv-lite: 0.7.2 + optionalDependencies: + '@types/node': 25.5.2 '@jssg/utils@0.0.2': {} @@ -607,6 +615,11 @@ snapshots: '@types/node@12.20.55': {} + '@types/node@25.5.2': + dependencies: + undici-types: 7.18.2 + optional: true + ansi-colors@4.1.3: {} ansi-regex@5.0.1: {} @@ -840,6 +853,9 @@ snapshots: typescript@6.0.2: {} + undici-types@7.18.2: + optional: true + universalify@0.1.2: {} which@2.0.2: