-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: change isDataEmpty, add codemod, fix codemod
- Loading branch information
Showing
8 changed files
with
121 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/codemods/src/codemods/v5.x.x/detectEmptyCells/detectEmptyCells.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
findCells, | ||
fileToAst, | ||
getCellGqlQuery, | ||
parseGqlQueryToAst, | ||
} from '../../../lib/cells' | ||
|
||
async function detectEmptyCells() { | ||
const cellPaths = findCells() | ||
|
||
const susceptibleCells = cellPaths.filter((cellPath) => { | ||
const fileContents = fileToAst(cellPath) | ||
const cellQuery = getCellGqlQuery(fileContents) | ||
|
||
if (!cellQuery) { | ||
return false | ||
} | ||
|
||
const { fields } = parseGqlQueryToAst(cellQuery)[0] | ||
|
||
return fields.length > 1 | ||
}) | ||
|
||
if (susceptibleCells.length > 0) { | ||
console.log( | ||
[ | ||
'You have Cells that are susceptible to the new isDataEmpty behavior:', | ||
'', | ||
susceptibleCells.map((c) => `• ${c}`).join('\n'), | ||
'', | ||
"The new behavior is documented in detail here. It's most likely what you want, but consider whether it affects you.", | ||
"If you'd like to revert to the old behavior, you can override the `isDataEmpty` function.", | ||
].join('\n') | ||
) | ||
} | ||
} | ||
|
||
export default detectEmptyCells |
17 changes: 17 additions & 0 deletions
17
packages/codemods/src/codemods/v5.x.x/detectEmptyCells/detectEmptyCells.yargs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import task, { TaskInnerAPI } from 'tasuku' | ||
|
||
import detectEmptyCells from './detectEmptyCells' | ||
|
||
export const command = 'detect-empty-cells' | ||
export const description = '(v4.x.x->v5.0.0) Detects empty cells and warns' | ||
|
||
export const handler = () => { | ||
task('detectEmptyCells', async ({ setError }: TaskInnerAPI) => { | ||
try { | ||
await detectEmptyCells() | ||
console.log() | ||
} catch (e: any) { | ||
setError('Failed to detect empty cells in your project \n' + e?.message) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters