Skip to content

Commit a2e4afe

Browse files
πŸ› bug: support no have tsconfig (#51)
* πŸ› bug: support no have tsconfig * add commet * fix test
1 parent 9220d1d commit a2e4afe

File tree

3 files changed

+54
-11
lines changed

3 files changed

+54
-11
lines changed

β€Žsrc/eslint.ts

+25-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
/** @format */
22

33
import * as path from 'path';
4+
import * as fs from 'fs';
45

5-
const eslintFolder = path.join(path.dirname(require.resolve('eslint')), '..');
6-
7-
const moduleResolverPath = path.join(eslintFolder, 'lib/shared/relative-module-resolver');
8-
const ModuleResolver = require(moduleResolverPath);
9-
10-
ModuleResolver.resolve = function(moduleName: string) {
11-
return require.resolve(moduleName);
6+
let parserOptions: {
7+
tsconfigRootDir?: string;
8+
project?: string;
9+
createDefaultProgram?: boolean;
10+
} = {
11+
project: './tsconfig.json',
1212
};
1313

14+
if (!fs.existsSync(path.join(process.env.PWD || '.', './tsconfig.json'))) {
15+
parserOptions = {
16+
tsconfigRootDir: __dirname,
17+
project: './tsconfig.json',
18+
/**
19+
* parserOptions.createDefaultProgram
20+
* Default .false
21+
* This option allows you to request that when the setting is specified,
22+
* files will be allowed when not included in the projects defined by the provided files.
23+
* Using this option will incur significant performance costs.
24+
* This option is primarily included for backwards-compatibility.
25+
* See the project section above for more information.projecttsconfig.json
26+
*/
27+
createDefaultProgram: true,
28+
};
29+
}
30+
1431
module.exports = {
1532
extends: [
1633
'airbnb',
@@ -115,7 +132,5 @@ module.exports = {
115132
'import/resolver': { node: { extensions: ['.js', '.jsx', '.ts', '.tsx', '.d.ts'] } },
116133
polyfills: ['fetch', 'Promise', 'URL', 'object-assign'],
117134
},
118-
parserOptions: {
119-
project: './tsconfig.json',
120-
},
135+
parserOptions,
121136
};

β€Žsrc/tsconfig.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "build/dist",
4+
"module": "esnext",
5+
"target": "esnext",
6+
"lib": ["esnext", "dom"],
7+
"sourceMap": true,
8+
"baseUrl": ".",
9+
"jsx": "react",
10+
"allowSyntheticDefaultImports": true,
11+
"moduleResolution": "node",
12+
"forceConsistentCasingInFileNames": true,
13+
"noImplicitReturns": true,
14+
"suppressImplicitAnyIndexErrors": true,
15+
"noUnusedLocals": true,
16+
"allowJs": true,
17+
"skipLibCheck": true,
18+
"experimentalDecorators": true,
19+
"strict": true,
20+
"paths": {
21+
"@/*": ["./src/*"],
22+
"@@/*": ["./src/.umi/*"]
23+
}
24+
},
25+
"exclude": ["node_modules", "build", "dist", "scripts", "src/.umi/*", "webpack", "jest"]
26+
}

β€Žtsconfig.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"lib": ["esnext", "dom"],
77
"baseUrl": ".",
88
"jsx": "react",
9+
"resolveJsonModule": true,
910
"allowSyntheticDefaultImports": true,
1011
"moduleResolution": "node",
1112
"forceConsistentCasingInFileNames": true,
@@ -29,5 +30,6 @@
2930
"tslint:latest",
3031
"tslint-config-prettier",
3132
"example/**"
32-
]
33+
],
34+
"include": ["src/*.json", "src/*.ts"]
3335
}

0 commit comments

Comments
Β (0)