Skip to content

Commit 76c5419

Browse files
author
Adam Hines
committed
chore(cache): cache tsconfig parsing to avoid the cost per vue file / interpolated string
1 parent 0fb2493 commit 76c5419

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

packages/vue2-jest/lib/utils.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,18 @@ const getBabelOptions = function loadBabelOptions(filename, options = {}) {
7070
return loadPartialConfig(opts).options
7171
}
7272

73+
const tsConfigCache = new Map()
74+
7375
/**
7476
* Load TypeScript config from tsconfig.json.
7577
* @param {string | undefined} path tsconfig.json file path (default: root)
7678
* @returns {import('typescript').TranspileOptions | null} TypeScript compilerOptions or null
7779
*/
7880
const getTypeScriptConfig = function getTypeScriptConfig(path) {
81+
if (tsConfigCache.has(path)) {
82+
return tsConfigCache.get(path)
83+
}
84+
7985
ensureRequire('typescript', ['typescript'])
8086
const typescript = require('typescript')
8187

@@ -103,12 +109,16 @@ const getTypeScriptConfig = function getTypeScriptConfig(path) {
103109

104110
const compilerOptions = parsedConfig ? parsedConfig.options : {}
105111

106-
return {
112+
const transpileConfig = {
107113
compilerOptions: {
108114
...compilerOptions,
109115
module: typescript.ModuleKind.CommonJS
110116
}
111117
}
118+
119+
tsConfigCache.set(path, transpileConfig)
120+
121+
return transpileConfig
112122
}
113123

114124
function isValidTransformer(transformer) {

packages/vue3-jest/lib/utils.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,18 @@ const getBabelOptions = function loadBabelOptions(filename, options = {}) {
7070
return loadPartialConfig(opts).options
7171
}
7272

73+
const tsConfigCache = new Map()
74+
7375
/**
7476
* Load TypeScript config from tsconfig.json.
7577
* @param {string | undefined} path tsconfig.json file path (default: root)
7678
* @returns {import('typescript').TranspileOptions | null} TypeScript compilerOptions or null
7779
*/
7880
const getTypeScriptConfig = function getTypeScriptConfig(path) {
81+
if (tsConfigCache.has(path)) {
82+
return tsConfigCache.get(path)
83+
}
84+
7985
ensureRequire('typescript', ['typescript'])
8086
const typescript = require('typescript')
8187

@@ -103,15 +109,18 @@ const getTypeScriptConfig = function getTypeScriptConfig(path) {
103109

104110
const compilerOptions = parsedConfig ? parsedConfig.options : {}
105111

106-
// Force es5 to prevent const vue_1 = require('vue') from conflicting
107-
return {
112+
const transpileConfig = {
108113
compilerOptions: {
109114
...compilerOptions,
110115
// Force es5 to prevent const vue_1 = require('vue') from conflicting
111116
target: typescript.ScriptTarget.ES5,
112117
module: typescript.ModuleKind.CommonJS
113118
}
114119
}
120+
121+
tsConfigCache.set(path, transpileConfig)
122+
123+
return transpileConfig
115124
}
116125

117126
function isValidTransformer(transformer) {

0 commit comments

Comments
 (0)