Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 61a57b3

Browse filesBrowse files
author
Adam Hines
committed
chore(cache): cache tsconfig parsing to avoid the cost per vue file / interpolated string
1 parent fe6745c commit 61a57b3
Copy full SHA for 61a57b3

File tree

Expand file treeCollapse file tree

2 files changed

+22
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-3
lines changed

‎packages/vue2-jest/lib/utils.js

Copy file name to clipboardExpand all lines: packages/vue2-jest/lib/utils.js
+11-1Lines 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

Copy file name to clipboardExpand all lines: packages/vue3-jest/lib/utils.js
+11-2Lines 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,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[path] = transpileConfig
122+
123+
return transpileConfig
115124
}
116125

117126
function isValidTransformer(transformer) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.