Skip to content

Commit 38303a1

Browse files
committed
Only cache transformed files, 4.8.11
1 parent 04fc9b9 commit 38303a1

3 files changed

Lines changed: 21 additions & 27 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cogs",
3-
"version": "4.8.10",
3+
"version": "4.8.11",
44
"type": "module",
55
"author": "Casey Foster <c@sey.me>",
66
"description": "The fast file transform pipeline.",

src/get-file.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import { promises as fs } from 'fs';
22

3+
import _ from 'underscore';
4+
35
import applyTransformers from './apply-transformers.js';
4-
import getOrSet from './get-or-set.js';
56

6-
export default ({ env: { cache, transformers }, path }) =>
7-
getOrSet(cache, path, async () => {
8-
try {
9-
return await applyTransformers({
10-
file: {
11-
buffer: await fs.readFile(path),
12-
builds: [],
13-
links: [],
14-
path,
15-
requires: [path]
16-
},
17-
transformers
18-
});
19-
} catch (er) {
20-
er.message += `\n ${path}`;
21-
throw er;
22-
}
7+
export default async ({ env: { cache, transformers }, path }) =>
8+
(cache[path] ??= (async () => {
9+
const file = {
10+
buffer: await fs.readFile(path),
11+
builds: [],
12+
links: [],
13+
path,
14+
requires: [path]
15+
};
16+
17+
const transformed = await applyTransformers({ file, transformers });
18+
19+
if (_.isEqual(file, transformed)) delete cache[path];
20+
21+
return transformed;
22+
})()).catch(er => {
23+
delete cache[path];
24+
throw er;
2325
});

src/get-or-set.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)