feat: refactoring project

This commit is contained in:
Carlos
2024-11-23 14:56:07 -05:00
parent f0c2a50c18
commit 1c6db5818d
2351 changed files with 39323 additions and 60326 deletions

View File

@@ -105,18 +105,24 @@ const handleCache = /*#__PURE__*/function () {
options = {},
cacheIdentifier,
cacheDirectory,
cacheCompression
cacheCompression,
logger
} = params;
const file = path.join(directory, filename(source, cacheIdentifier, options));
try {
// No errors mean that the file was previously cached
// we just need to return it
logger.debug(`reading cache file '${file}'`);
return yield read(file, cacheCompression);
} catch (err) {}
} catch (err) {
// conitnue if cache can't be read
logger.debug(`discarded cache as it can not be read`);
}
const fallback = typeof cacheDirectory !== "string" && directory !== os.tmpdir();
// Make sure the directory exists.
try {
logger.debug(`creating cache folder '${directory}'`);
yield makeDir(directory);
} catch (err) {
if (fallback) {
@@ -127,12 +133,14 @@ const handleCache = /*#__PURE__*/function () {
// Otherwise just transform the file
// return it to the user asap and write it in cache
logger.debug(`applying Babel transform`);
const result = yield transform(source, options);
// Do not cache if there are external dependencies,
// since they might change and we cannot control it.
if (!result.externalDependencies.length) {
try {
logger.debug(`writing result to cache file '${file}'`);
yield write(file, cacheCompression, result);
} catch (err) {
if (fallback) {