1 | import { promises as fs } from 'fs';
|
2 |
|
3 | import applyTransformers from './apply-transformers.js';
|
4 | import getOrSet from './get-or-set.js';
|
5 |
|
6 | const readFile = ({ cache, path }) =>
|
7 | getOrSet(cache.buffers, path, () => fs.readFile(path));
|
8 |
|
9 | export default ({ env: { cache, transformers }, path }) =>
|
10 | getOrSet(cache.files, path, async () => {
|
11 | try {
|
12 | return await applyTransformers({
|
13 | file: {
|
14 | buffer: await readFile({ cache, path }),
|
15 | builds: [],
|
16 | links: [],
|
17 | path,
|
18 | requires: [path]
|
19 | },
|
20 | transformers
|
21 | });
|
22 | } catch (er) {
|
23 | er.message += `\n ${path}`;
|
24 | throw er;
|
25 | }
|
26 | });
|