/
index.ts
33 lines (27 loc) Β· 871 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { spawn } from 'child_process';
import { collectStream } from '@minification-benchmarks/utils/collect-stream';
import { createMinifier } from '../../utils/create-minifier.js';
const jshrinkPath = new URL('jshrink.php', import.meta.url).pathname;
export default createMinifier(
'tedivm/jshrink',
{
default: async ({ code }) => {
const minify = spawn('php', [jshrinkPath], {
// Needs to be context of composer install
cwd: new URL('..', import.meta.url).pathname,
});
minify.stdin.end(code);
const [error, minified] = await Promise.all([
collectStream(minify.stderr),
collectStream(minify.stdout),
]);
if (error) {
const [message, ...stackLines] = error.split('\n');
const errorObject = new Error(message);
errorObject.stack = stackLines.join('\n');
throw errorObject;
}
return minified;
},
},
);