Skip to content

Commit 322ae0b

Browse files
committed
test: fix transformer for backslashes
Injecting the path into the "code" was causing the backslashes to be interpreted as escape characters instead of path separators. I could have escaped them, but this approach is more similar to what Webpack does with `arraybuffer-loader` and (IMO) easier to read.
1 parent a799982 commit 322ae0b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
const fs = require('fs');
2+
13
module.exports = {
24
process (_sourceText, sourcePath) {
5+
const buffer = fs.readFileSync(sourcePath);
6+
const array = buffer.toJSON().data;
37
return {
4-
code: [
5-
'const fs = require("fs");',
6-
`module.exports = fs.readFileSync('${sourcePath}');`
7-
].join('\n')
8+
code: `module.exports = Buffer.from([${array}]);`
89
};
910
}
1011
};

0 commit comments

Comments
 (0)