Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit 37dc1d5

Browse files
stoffeastromaxelssonHakan
authored andcommitted
feat: cache transformed files (#236)
1 parent ce98987 commit 37dc1d5

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/transform.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ function tryRequire(name) {
1515
const babel = tryRequire('babel-core');
1616
const babelPluginIstanbul = tryRequire('babel-plugin-istanbul').default;
1717
const tsc = tryRequire('typescript');
18-
const virtualSourceMap = new Map();
18+
const cacheSourceMap = new Map();
19+
const cacheTransform = new Map();
1920

2021
function readFile(filePath) {
2122
return new Promise((resolve, reject) => {
@@ -66,9 +67,13 @@ function transformTypescript(filePath, sourceRoot, tsContent, argv) {
6667
}
6768
async function transformFile(filePath, argv) {
6869
if (isSourceMap(filePath)) {
69-
return virtualSourceMap.get(filePath);
70+
return cacheSourceMap.get(filePath);
7071
}
7172
filePath = ensureFilePath(filePath);
73+
const cache = cacheTransform.get(filePath);
74+
if (cache) {
75+
return cache;
76+
}
7277
let content = await readFile(filePath);
7378
let babelOpts = getBabelOpts(filePath, argv);
7479
if (isTypescript(filePath)) {
@@ -80,8 +85,9 @@ async function transformFile(filePath, argv) {
8085

8186
if (map) {
8287
const key = getPathWithExt(filePath, 'js.map');
83-
virtualSourceMap.set(key, map);
88+
cacheSourceMap.set(key, map);
8489
}
90+
cacheTransform.set(filePath, code);
8591
return code;
8692
}
8793

0 commit comments

Comments
 (0)