Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (typeof condition === 'function') {
return condition(filepath, ctx)
}
return false
})
}
for (const filepath of ctx.fileList) {
const content = ctx.fileContents(filepath)
if (shouldSkip && shouldSkip(filepath, content)) {
continue
}
// Skip binary files
if (isBinaryPath(filepath)) {
continue
}
const absolutePath = ctx.files[filepath].path
ctx.writeContents(
filepath,
render(absolutePath, content, ctx.meta.merged)
)
}
}
}
function returnCached() {
log.info(`returning cached file for ${urlStr}`);
return fs.readFile(cachedPath);
}
const modifiedTime = await getFileModifiedTime(cachedPath, urlStr);
const maxCacheAge = config.maxCacheAge;
const isCachedFileValid = modifiedTime && (modifiedTime > Date.now() - (maxCacheAge * 1000));
if (maxCacheAge === -1 || isCachedFileValid) {
return returnCached();
}
const options = {
url: urlStr,
// returns body as a buffer instead of string if its a binary file
encoding: isBinaryPath(urlStr) ? null : 'utf-8',
retries(retry) {
if (retry >= RETRIES) return 0; // Cancels retry
return 1000 * (retry ** 2);
},
};
if (modifiedTime) {
options.headers = config.headers || {};
const modifedTimeString = (new Date(modifiedTime)).toUTCString();
options.headers['if-modified-since'] = modifedTimeString;
}
try {
const response = await got(urlStr, options);
let body = response.body;
if (response.headers['content-type'] === 'text/html') {
// Serializes the parsed document
async normalizeFile(input: string, outFile: string): Promise {
if (isBinaryPath(input)) {
const buffer = await fs.readFile(input)
return this.writeBinary(buffer, {
filename: input,
outFile
})
}
let source = await fs.readFile(input, 'utf8')
source = replaceContants(source, this.options.constants)
const ctx = {
filename: input,
outFile,
modern: this.options.modern,
babelrc: this.options.babelrc
}