-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4632b24
commit bd19008
Showing
2 changed files
with
49 additions
and
55 deletions.
There are no files selected for viewing
97 changes: 46 additions & 51 deletions
97
packages/linter/src/migrations/update-14-1-9/add-swc-deps-if-needed.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 |
---|---|---|
@@ -1,52 +1,47 @@ | ||
import { | ||
formatFiles, | ||
installPackagesTask, | ||
Tree, | ||
} from '@nrwl/devkit'; | ||
|
||
export default async function addSwcNodeIfNeeded(tree: Tree) { | ||
try { | ||
const existingJestConfigPath = normalizePath( | ||
'tools/eslint-rules/jest.config.js' | ||
); | ||
|
||
// Add extra config to the jest.config.js file to allow ESLint 8 exports mapping to work with jest | ||
addPropertyToJestConfig(tree, existingJestConfigPath, 'moduleNameMapper', { | ||
'@eslint/eslintrc': '@eslint/eslintrc/dist/eslintrc-universal.cjs', | ||
}); | ||
|
||
visitNotIgnoredFiles(tree, 'tools/eslint-rules', (path) => { | ||
if (!path.endsWith('.ts')) { | ||
return; | ||
} | ||
const fileContents = tree.read(path).toString('utf-8'); | ||
const fileAst = tsquery.ast(fileContents); | ||
const isESLintRuleFile = | ||
tsquery( | ||
fileAst, | ||
'PropertyAccessExpression[expression.escapedText=ESLintUtils][name.escapedText=RuleCreator]' | ||
).length > 0; | ||
if (!isESLintRuleFile) { | ||
return; | ||
} | ||
const categoryPropertyAssignmentNode = tsquery( | ||
import { formatFiles, installPackagesTask, Tree } from '@nrwl/devkit'; | ||
|
||
export default async function addSwcNodeIfNeeded(tree: Tree) { | ||
try { | ||
const existingJestConfigPath = normalizePath( | ||
'tools/eslint-rules/jest.config.js' | ||
); | ||
|
||
// Add extra config to the jest.config.js file to allow ESLint 8 exports mapping to work with jest | ||
addPropertyToJestConfig(tree, existingJestConfigPath, 'moduleNameMapper', { | ||
'@eslint/eslintrc': '@eslint/eslintrc/dist/eslintrc-universal.cjs', | ||
}); | ||
|
||
visitNotIgnoredFiles(tree, 'tools/eslint-rules', (path) => { | ||
if (!path.endsWith('.ts')) { | ||
return; | ||
} | ||
const fileContents = tree.read(path).toString('utf-8'); | ||
const fileAst = tsquery.ast(fileContents); | ||
const isESLintRuleFile = | ||
tsquery( | ||
fileAst, | ||
'PropertyAssignment[name.escapedText=meta] PropertyAssignment[name.escapedText=docs] PropertyAssignment[name.escapedText=category]' | ||
)[0]; | ||
if (!categoryPropertyAssignmentNode) { | ||
return; | ||
} | ||
let end = categoryPropertyAssignmentNode.getEnd(); | ||
if (fileContents.substring(end, end + 1) === ',') { | ||
end++; | ||
} | ||
const updatedContents = | ||
fileContents.slice(0, categoryPropertyAssignmentNode.getFullStart()) + | ||
fileContents.slice(end); | ||
tree.write(path, updatedContents); | ||
}); | ||
|
||
await formatFiles(tree); | ||
} catch {} | ||
} | ||
|
||
'PropertyAccessExpression[expression.escapedText=ESLintUtils][name.escapedText=RuleCreator]' | ||
).length > 0; | ||
if (!isESLintRuleFile) { | ||
return; | ||
} | ||
const categoryPropertyAssignmentNode = tsquery( | ||
fileAst, | ||
'PropertyAssignment[name.escapedText=meta] PropertyAssignment[name.escapedText=docs] PropertyAssignment[name.escapedText=category]' | ||
)[0]; | ||
if (!categoryPropertyAssignmentNode) { | ||
return; | ||
} | ||
let end = categoryPropertyAssignmentNode.getEnd(); | ||
if (fileContents.substring(end, end + 1) === ',') { | ||
end++; | ||
} | ||
const updatedContents = | ||
fileContents.slice(0, categoryPropertyAssignmentNode.getFullStart()) + | ||
fileContents.slice(end); | ||
tree.write(path, updatedContents); | ||
}); | ||
|
||
await formatFiles(tree); | ||
} catch {} | ||
} |
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