Skip to content

Commit

Permalink
chore(repo): format
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed May 24, 2022
1 parent 4632b24 commit bd19008
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 55 deletions.
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 {}
}
7 changes: 3 additions & 4 deletions packages/nx/src/utils/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,16 @@ export const registerTsProject = (
const tsNodeInstalled = packageIsInstalled('ts-node/register');
if (tsNodeInstalled) {
warnTsNodeUsage();
const { register } =
require('ts-node') as typeof import('ts-node');
const { register } = require('ts-node') as typeof import('ts-node');

// ts-node doesn't provide a cleanup method
registerTranspiler = () => {
register({
project: tsConfigPath,
transpileOnly: true,
compilerOptions: {
module: 'commonjs'
}
module: 'commonjs',
},
});
return () => {};
};
Expand Down

0 comments on commit bd19008

Please sign in to comment.