Skip to content

Commit 7a564e6

Browse files
committed
Revert, 4.8.12
1 parent 38303a1 commit 7a564e6

File tree

4 files changed

+36
-23
lines changed

4 files changed

+36
-23
lines changed

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.11",
3+
"version": "4.8.12",
44
"type": "module",
55
"author": "Casey Foster <c@sey.me>",
66
"description": "The fast file transform pipeline.",

src/bust-cache.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import fileHasDependency from './file-has-dependency.js';
55
export default ({ config, path }) =>
66
Promise.all(
77
_.map(config, async ({ cache }) => {
8-
delete cache[path];
8+
const { buffers, files } = cache;
9+
delete buffers[path];
10+
delete files[path];
911
await Promise.all(
10-
_.map(cache, async (file, key) => {
11-
if (fileHasDependency({ file: await file, path })) delete cache[key];
12+
_.map(files, async (file, key) => {
13+
if (fileHasDependency({ file: await file, path })) delete files[key];
1214
})
1315
);
1416
})

src/get-file.js

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

3-
import _ from 'underscore';
4-
53
import applyTransformers from './apply-transformers.js';
64

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 });
5+
const getOrSet = async (cache, key, fn) => {
6+
try {
7+
return await (cache[key] ??= fn());
8+
} catch (er) {
9+
delete cache[key];
10+
throw er;
11+
}
12+
};
1813

19-
if (_.isEqual(file, transformed)) delete cache[path];
14+
const readFile = ({ cache, path }) =>
15+
getOrSet(cache.buffers, path, () => fs.readFile(path));
2016

21-
return transformed;
22-
})()).catch(er => {
23-
delete cache[path];
24-
throw er;
17+
export default ({ env: { cache, transformers }, path }) =>
18+
getOrSet(cache.files, path, async () => {
19+
try {
20+
return await applyTransformers({
21+
file: {
22+
buffer: await readFile({ cache, path }),
23+
builds: [],
24+
links: [],
25+
path,
26+
requires: [path]
27+
},
28+
transformers
29+
});
30+
} catch (er) {
31+
er.message += `\n ${path}`;
32+
throw er;
33+
}
2534
});

src/normalize-config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const asyncMapObj = async (obj, fn) =>
1212
);
1313

1414
export default async config => {
15+
const buffers = {};
16+
1517
config = await asyncMapObj(
1618
config,
1719
async ({ builds, transformers, manifestPath, requires }, name) => ({
@@ -21,7 +23,7 @@ export default async config => {
2123
toArray(target.transformers).map(normalizeTransformer)
2224
)
2325
})),
24-
cache: {},
26+
cache: { buffers, files: {} },
2527
manifestPath,
2628
name,
2729
requires: toArray(requires),

0 commit comments

Comments
 (0)