Skip to content

Commit 6f7d17e

Browse files
author
Adam Hines
committed
chore(cache): cache tsconfig parsing to avoid the cost per vue file / interpolated string
1 parent e7f4571 commit 6f7d17e

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 = {}
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 (path in tsConfigCache) {
82+
return tsConfigCache[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[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 = {}
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 (path in tsConfigCache) {
82+
return tsConfigCache[path]
83+
}
84+
7985
ensureRequire('typescript', ['typescript'])
8086
const typescript = require('typescript')
8187

@@ -103,14 +109,17 @@ 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
target: typescript.ScriptTarget.ES5,
111116
module: typescript.ModuleKind.CommonJS
112117
}
113118
}
119+
120+
tsConfigCache[path] = transpileConfig
121+
122+
return transpileConfig
114123
}
115124

116125
function isValidTransformer(transformer) {

0 commit comments

Comments
 (0)