@stylable/core
Version:
CSS for Components
50 lines • 1.59 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.cachedProcessFile = void 0;
function cachedProcessFile(processor, fs, resolvePath) {
const cache = {};
const postProcessors = [];
function process(fullpath, ignoreCache = false, context) {
const resolvedPath = resolvePath(fullpath, context);
const stat = fs.statSync(resolvedPath);
const cached = cache[resolvedPath];
if (ignoreCache ||
!cached ||
(cached && cached.stat.mtime.valueOf() !== stat.mtime.valueOf())) {
const content = fs.readFileSync(resolvedPath, 'utf8');
const value = processContent(content, resolvedPath);
cache[resolvedPath] = { value, stat: { mtime: stat.mtime } };
}
return cache[resolvedPath].value;
}
function processContent(content, filePath) {
return postProcessors.reduce((value, postProcessor) => {
return postProcessor(value, filePath);
}, processor(filePath, content));
}
function add(fullpath, value) {
let mtime;
try {
mtime = fs.statSync(fullpath).mtime;
}
catch (e) {
mtime = new Date();
}
cache[fullpath] = {
value,
stat: {
mtime,
},
};
}
return {
processContent,
postProcessors,
cache,
process,
add,
resolvePath,
};
}
exports.cachedProcessFile = cachedProcessFile;
//# sourceMappingURL=cached-process-file.js.map
;