Skip to content

Commit

Permalink
refactor: code (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito authored Mar 4, 2021
1 parent d68a8eb commit 9e12a33
Showing 1 changed file with 24 additions and 30 deletions.
54 changes: 24 additions & 30 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,7 @@ class CopyPlugin {
}

if (!result.source) {
let startTime;

if (cache) {
startTime = Date.now();
}
const startTime = Date.now();

logger.debug(`reading '${absoluteFilename}'...`);

Expand All @@ -424,40 +420,38 @@ class CopyPlugin {

result.source = new RawSource(data);

if (cache) {
let snapshot;
let snapshot;

logger.debug(`creating snapshot for '${absoluteFilename}'...`);

try {
snapshot = await CopyPlugin.createSnapshot(
compilation,
startTime,
absoluteFilename
);
} catch (error) {
compilation.errors.push(error);

return;
}

logger.debug(`creating snapshot for '${absoluteFilename}'...`);
if (snapshot) {
logger.debug(`created snapshot for '${absoluteFilename}'`);
logger.debug(`storing cache for '${absoluteFilename}'...`);

try {
snapshot = await CopyPlugin.createSnapshot(
compilation,
startTime,
absoluteFilename
);
await cache.storePromise(`${sourceFilename}|${index}`, null, {
source: result.source,
snapshot,
});
} catch (error) {
compilation.errors.push(error);

return;
}

if (snapshot) {
logger.debug(`created snapshot for '${absoluteFilename}'`);
logger.debug(`storing cache for '${absoluteFilename}'...`);

try {
await cache.storePromise(`${sourceFilename}|${index}`, null, {
source: result.source,
snapshot,
});
} catch (error) {
compilation.errors.push(error);

return;
}

logger.debug(`stored cache for '${absoluteFilename}'`);
}
logger.debug(`stored cache for '${absoluteFilename}'`);
}
}

Expand Down

0 comments on commit 9e12a33

Please sign in to comment.