-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathload-typescript-config.js
79 lines (72 loc) · 2.27 KB
/
load-typescript-config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const tsconfig = require('tsconfig')
const cache = require('./cache')
const deprecate = require('./deprecate')
const logger = require('./logger')
const defaultTypescriptConfig = {
'compilerOptions': {
'target': 'es5',
'lib': [
'dom',
'es6'
],
'module': 'es2015',
'moduleResolution': 'node',
'types': ['vue-typescript-import-dts', 'jest', 'node'],
'isolatedModules': false,
'experimentalDecorators': true,
'noImplicitAny': true,
'noImplicitThis': true,
'strictNullChecks': true,
'removeComments': true,
'emitDecoratorMetadata': true,
'suppressImplicitAnyIndexErrors': true,
'allowSyntheticDefaultImports': true,
'sourceMap': true,
'allowJs': true
}
}
module.exports.loadTypescriptConfig = function loadTypescriptConfig (vueJestConfig) {
const find = () => {
const { path, config } = tsconfig.loadSync(process.cwd())
if (!path) {
logger.info('no tsconfig.json found, defaulting to default typescript options')
}
return path ? config : defaultTypescriptConfig
}
const cachedConfig = cache.get('typescript-config')
if (cachedConfig) {
return cachedConfig
} else {
let typescriptConfig
if (vueJestConfig.tsConfigFile) {
deprecate.replace('tsConfigFile', 'tsConfig')
typescriptConfig = tsconfig.readFileSync(vueJestConfig.tsConfigFile)
} else if (vueJestConfig.hasOwnProperty('tsConfig')) {
switch (typeof vueJestConfig.tsConfig) {
case 'string':
// a path to a config file is being passed in; load it
typescriptConfig = tsconfig.readFileSync(vueJestConfig.tsConfig)
break
case 'boolean':
// if tsConfig is true, search for it
if (vueJestConfig.tsConfig === true) {
typescriptConfig = find()
} else {
// use default typescript options
typescriptConfig = defaultTypescriptConfig
}
break
case 'object':
default:
// support for inline typescript options
typescriptConfig = vueJestConfig.tsConfig
break
}
} else {
typescriptConfig = find()
}
cache.set('typescript-config', typescriptConfig)
return typescriptConfig
}
}
module.exports.defaultConfig = defaultTypescriptConfig