fix(linter): fix update to using module node16 (#20004)

This commit is contained in:
Jason Jean 2023-11-02 14:52:44 -04:00 committed by GitHub
parent d1042cd194
commit 32ff9c80b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 69 additions and 11 deletions

View File

@ -8,7 +8,7 @@
* This configuration is intended to be combined with other configs from this * This configuration is intended to be combined with other configs from this
* package. * package.
*/ */
import * as restrictedGlobals from 'confusing-browser-globals'; import restrictedGlobals from 'confusing-browser-globals';
/** /**
* Rule set originally adapted from: * Rule set originally adapted from:

View File

@ -2,6 +2,7 @@
"extends": "../../tsconfig.base.json", "extends": "../../tsconfig.base.json",
"compilerOptions": { "compilerOptions": {
"moduleResolution": "node16", "moduleResolution": "node16",
"module": "node16",
"types": ["node", "jest"] "types": ["node", "jest"]
}, },
"include": [], "include": [],

View File

@ -1,7 +1,6 @@
{ {
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"compilerOptions": { "compilerOptions": {
"module": "commonjs",
"outDir": "../../dist/out-tsc", "outDir": "../../dist/out-tsc",
"declaration": true, "declaration": true,
"types": ["node"] "types": ["node"]

View File

@ -2,7 +2,6 @@
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "../../dist/out-tsc", "outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"] "types": ["jest", "node"]
}, },
"include": [ "include": [

View File

@ -36,7 +36,7 @@ exports[`@nx/eslint:workspace-rules-project should generate the required files 2
"extends": "../../tsconfig.base.json", "extends": "../../tsconfig.base.json",
"compilerOptions": { "compilerOptions": {
"moduleResolution": "node16", "moduleResolution": "node16",
"module": "commonjs" "module": "node16"
}, },
"files": [], "files": [],
"include": [], "include": [],
@ -70,7 +70,6 @@ exports[`@nx/eslint:workspace-rules-project should generate the required files 4
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "../../dist/out-tsc", "outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"] "types": ["jest", "node"]
}, },
"include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"] "include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]

View File

@ -2,7 +2,7 @@
"extends": "<%= rootTsConfigPath %>", "extends": "<%= rootTsConfigPath %>",
"compilerOptions": { "compilerOptions": {
"moduleResolution": "node16", "moduleResolution": "node16",
"module": "commonjs" "module": "node16"
}, },
"files": [], "files": [],
"include": [], "include": [],

View File

@ -87,6 +87,8 @@ export async function lintWorkspaceRulesProjectGenerator(
tree, tree,
join(workspaceLintPluginDir, 'tsconfig.spec.json'), join(workspaceLintPluginDir, 'tsconfig.spec.json'),
(json) => { (json) => {
delete json.compilerOptions?.module;
if (json.include) { if (json.include) {
json.include = json.include.map((v) => { json.include = json.include.map((v) => {
if (v.startsWith('src/**')) { if (v.startsWith('src/**')) {

View File

@ -59,9 +59,34 @@ export const rule = ESLintUtils.RuleCreator(() => __filename)({
exports[`update-typescript-eslint migration should update the tsconfig.json 1`] = ` exports[`update-typescript-eslint migration should update the tsconfig.json 1`] = `
"{ "{
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "module": "node16",
"moduleResolution": "node16" "moduleResolution": "node16"
} }
} }
" "
`; `;
exports[`update-typescript-eslint migration should update the tsconfig.json 2`] = `
"{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": ["jest", "node"]
},
"include": [
"**/*.spec.ts",
"**/*.test.ts",
"**/*_spec.ts",
"**/*_test.ts",
"**/*.spec.tsx",
"**/*.test.tsx",
"**/*.spec.js",
"**/*.test.js",
"**/*.spec.jsx",
"**/*.test.jsx",
"**/*.d.ts",
"jest.config.ts"
]
}
"
`;

View File

@ -14,6 +14,28 @@ describe('update-typescript-eslint migration', () => {
module: 'commonjs', module: 'commonjs',
}, },
}); });
writeJson(tree, 'tools/eslint-rules/tsconfig.spec.json', {
extends: './tsconfig.json',
compilerOptions: {
outDir: '../../dist/out-tsc',
module: 'commonjs',
types: ['jest', 'node'],
},
include: [
'**/*.spec.ts',
'**/*.test.ts',
'**/*_spec.ts',
'**/*_test.ts',
'**/*.spec.tsx',
'**/*.test.tsx',
'**/*.spec.js',
'**/*.test.js',
'**/*.spec.jsx',
'**/*.test.jsx',
'**/*.d.ts',
'jest.config.ts',
],
});
tree.write( tree.write(
'tools/eslint-rules/jest.config.ts', 'tools/eslint-rules/jest.config.ts',
@ -82,6 +104,9 @@ export const rule = ESLintUtils.RuleCreator(() => __filename)({
expect( expect(
tree.read('tools/eslint-rules/tsconfig.json', 'utf-8') tree.read('tools/eslint-rules/tsconfig.json', 'utf-8')
).toMatchSnapshot(); ).toMatchSnapshot();
expect(
tree.read('tools/eslint-rules/tsconfig.spec.json', 'utf-8')
).toMatchSnapshot();
}); });
it('should update the jest.config.ts', async () => { it('should update the jest.config.ts', async () => {

View File

@ -34,15 +34,24 @@ function updateJestConfig(tree: Tree) {
} }
} }
function updateTsConfig(tree: Tree) { function updateTsConfigs(tree: Tree) {
const tsConfigPath = 'tools/eslint-rules/tsconfig.json'; const tsConfigPath = 'tools/eslint-rules/tsconfig.json';
if (tree.exists(tsConfigPath)) { if (tree.exists(tsConfigPath)) {
updateJson(tree, tsConfigPath, (tsConfig) => { updateJson(tree, tsConfigPath, (tsConfig) => {
tsConfig.compilerOptions ??= {}; tsConfig.compilerOptions ??= {};
tsConfig.compilerOptions.moduleResolution = 'node16'; tsConfig.compilerOptions.moduleResolution = 'node16';
tsConfig.compilerOptions.module = 'node16';
return tsConfig; return tsConfig;
}); });
} }
const tsConfigSpec = 'tools/eslint-rules/tsconfig.spec.json';
if (tree.exists(tsConfigSpec)) {
updateJson(tree, tsConfigSpec, (tsConfigSpec) => {
delete tsConfigSpec.compilerOptions?.module;
delete tsConfigSpec.compilerOptions?.moduleResolution;
return tsConfigSpec;
});
}
} }
function updateRecommended(tree: Tree) { function updateRecommended(tree: Tree) {
@ -91,7 +100,7 @@ function updateRecommended(tree: Tree) {
export default async function update(tree: Tree) { export default async function update(tree: Tree) {
updateJestConfig(tree); updateJestConfig(tree);
updateTsConfig(tree); updateTsConfigs(tree);
updateRecommended(tree); updateRecommended(tree);
await formatFiles(tree); await formatFiles(tree);

View File

@ -2,7 +2,7 @@
"extends": "../../tsconfig.base.json", "extends": "../../tsconfig.base.json",
"compilerOptions": { "compilerOptions": {
"moduleResolution": "node16", "moduleResolution": "node16",
"module": "commonjs" "module": "node16"
}, },
"files": [], "files": [],
"include": [], "include": [],

View File

@ -2,7 +2,6 @@
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "../../dist/out-tsc", "outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"] "types": ["jest", "node"]
}, },
"include": ["**/*.test.ts", "**/*.spec.ts", "**/*.d.ts", "jest.config.ts"] "include": ["**/*.test.ts", "**/*.spec.ts", "**/*.d.ts", "jest.config.ts"]