UNPKG

@stylable/core

Version:

CSS for Components

41 lines 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cachedProcessFile = void 0; function cachedProcessFile(processor, readFileSync, postProcessors = [], cache = {}) { function process(filePath, invalidateCache = false) { const content = readFileSync(filePath, 'utf8'); const cached = cache[filePath]; if (invalidateCache || !cached || (cached && cached.content !== content)) { cache[filePath] = { value: processContent(content, filePath), content, }; } return cache[filePath].value; } function processContent(content, filePath) { return postProcessors.reduce((value, postProcessor) => postProcessor(value, filePath), processor(filePath, content)); } function add(filePath, value) { let content; try { content = readFileSync(filePath, 'utf8'); } catch (e) { content = ''; } cache[filePath] = { value, content, }; } return { processContent, postProcessors, cache, process, add, }; } exports.cachedProcessFile = cachedProcessFile; //# sourceMappingURL=cached-process-file.js.map