@travetto/base
Advanced tools
Comparing version 0.0.83 to 0.0.84
@@ -10,4 +10,23 @@ #!/usr/bin/env node | ||
const CACHE_DIR = `${process.cwd()}/build`; | ||
// Delete old cached files | ||
for (const f of fs.readdirSync(CACHE_DIR)) { | ||
const full = f.replace(/~/g, '/'); | ||
if (fs.statSync(`${CACHE_DIR}/${f}`).ctimeMs < fs.statSync(full).ctimeMs) { | ||
console.debug('Removing stale cached file', full); | ||
fs.unlinkSync(`${CACHE_DIR}/${f}`); | ||
} | ||
} | ||
// Cache on require | ||
require.extensions['.ts'] = function load(m, tsf) { | ||
const content = ts.transpile(fs.readFileSync(tsf, 'utf-8'), opts); | ||
const name = `${CACHE_DIR}/${tsf.replace(/[\/\\]/g, '~')}`; | ||
let content; | ||
if (!fs.existsSync(name)) { | ||
content = ts.transpile(fs.readFileSync(tsf, 'utf-8'), opts); | ||
fs.writeFileSync(name, content); | ||
} else { | ||
content = fs.readFileSync(name).toString(); | ||
} | ||
return m._compile(content, tsf.replace(/\.ts$/, '.js')); | ||
@@ -14,0 +33,0 @@ }; |
@@ -22,3 +22,3 @@ { | ||
"scripts": {}, | ||
"version": "0.0.83" | ||
"version": "0.0.84" | ||
} |
@@ -11,6 +11,7 @@ import * as fs from 'fs'; | ||
testDir: x => { | ||
return !x.includes('node_modules') || ( | ||
x.endsWith('node_modules') || | ||
x.includes('@travetto') | ||
) | ||
return x !== 'build' && | ||
(!x.includes('node_modules') || ( | ||
x.endsWith('node_modules') || | ||
x.includes('@travetto')) | ||
) | ||
} | ||
@@ -17,0 +18,0 @@ }, process.cwd()) |
31788
947