fix(linter): fix update to using module node16 (#20004)
This commit is contained in:
parent
d1042cd194
commit
32ff9c80b1
@ -8,7 +8,7 @@
|
||||
* This configuration is intended to be combined with other configs from this
|
||||
* package.
|
||||
*/
|
||||
import * as restrictedGlobals from 'confusing-browser-globals';
|
||||
import restrictedGlobals from 'confusing-browser-globals';
|
||||
|
||||
/**
|
||||
* Rule set originally adapted from:
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"moduleResolution": "node16",
|
||||
"module": "node16",
|
||||
"types": ["node", "jest"]
|
||||
},
|
||||
"include": [],
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"outDir": "../../dist/out-tsc",
|
||||
"declaration": true,
|
||||
"types": ["node"]
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist/out-tsc",
|
||||
"module": "commonjs",
|
||||
"types": ["jest", "node"]
|
||||
},
|
||||
"include": [
|
||||
|
||||
@ -36,7 +36,7 @@ exports[`@nx/eslint:workspace-rules-project should generate the required files 2
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"moduleResolution": "node16",
|
||||
"module": "commonjs"
|
||||
"module": "node16"
|
||||
},
|
||||
"files": [],
|
||||
"include": [],
|
||||
@ -70,7 +70,6 @@ exports[`@nx/eslint:workspace-rules-project should generate the required files 4
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist/out-tsc",
|
||||
"module": "commonjs",
|
||||
"types": ["jest", "node"]
|
||||
},
|
||||
"include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
"extends": "<%= rootTsConfigPath %>",
|
||||
"compilerOptions": {
|
||||
"moduleResolution": "node16",
|
||||
"module": "commonjs"
|
||||
"module": "node16"
|
||||
},
|
||||
"files": [],
|
||||
"include": [],
|
||||
|
||||
@ -87,6 +87,8 @@ export async function lintWorkspaceRulesProjectGenerator(
|
||||
tree,
|
||||
join(workspaceLintPluginDir, 'tsconfig.spec.json'),
|
||||
(json) => {
|
||||
delete json.compilerOptions?.module;
|
||||
|
||||
if (json.include) {
|
||||
json.include = json.include.map((v) => {
|
||||
if (v.startsWith('src/**')) {
|
||||
|
||||
@ -59,9 +59,34 @@ export const rule = ESLintUtils.RuleCreator(() => __filename)({
|
||||
exports[`update-typescript-eslint migration should update the tsconfig.json 1`] = `
|
||||
"{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"module": "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"
|
||||
]
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
@ -14,6 +14,28 @@ describe('update-typescript-eslint migration', () => {
|
||||
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(
|
||||
'tools/eslint-rules/jest.config.ts',
|
||||
@ -82,6 +104,9 @@ export const rule = ESLintUtils.RuleCreator(() => __filename)({
|
||||
expect(
|
||||
tree.read('tools/eslint-rules/tsconfig.json', 'utf-8')
|
||||
).toMatchSnapshot();
|
||||
expect(
|
||||
tree.read('tools/eslint-rules/tsconfig.spec.json', 'utf-8')
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should update the jest.config.ts', async () => {
|
||||
|
||||
@ -34,15 +34,24 @@ function updateJestConfig(tree: Tree) {
|
||||
}
|
||||
}
|
||||
|
||||
function updateTsConfig(tree: Tree) {
|
||||
function updateTsConfigs(tree: Tree) {
|
||||
const tsConfigPath = 'tools/eslint-rules/tsconfig.json';
|
||||
if (tree.exists(tsConfigPath)) {
|
||||
updateJson(tree, tsConfigPath, (tsConfig) => {
|
||||
tsConfig.compilerOptions ??= {};
|
||||
tsConfig.compilerOptions.moduleResolution = 'node16';
|
||||
tsConfig.compilerOptions.module = 'node16';
|
||||
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) {
|
||||
@ -91,7 +100,7 @@ function updateRecommended(tree: Tree) {
|
||||
|
||||
export default async function update(tree: Tree) {
|
||||
updateJestConfig(tree);
|
||||
updateTsConfig(tree);
|
||||
updateTsConfigs(tree);
|
||||
updateRecommended(tree);
|
||||
|
||||
await formatFiles(tree);
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"moduleResolution": "node16",
|
||||
"module": "commonjs"
|
||||
"module": "node16"
|
||||
},
|
||||
"files": [],
|
||||
"include": [],
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist/out-tsc",
|
||||
"module": "commonjs",
|
||||
"types": ["jest", "node"]
|
||||
},
|
||||
"include": ["**/*.test.ts", "**/*.spec.ts", "**/*.d.ts", "jest.config.ts"]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user