Skip to content

Commit

Permalink
fix: honor .minify.json when reading input from stdin (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmaldi committed Jan 20, 2023
1 parent 107f008 commit 04be2ee
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions bin/minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ process.on('uncaughtException', (error) => {

minify();

function readStd(callback) {
function readStd(callback, options) {
const {stdin} = process;
let chunks = '';
const read = () => {
Expand All @@ -39,7 +39,7 @@ function readStd(callback) {
return chunks += chunk;

stdin.removeListener('readable', read);
callback(chunks);
callback(chunks, options);
};

stdin.setEncoding('utf8');
Expand All @@ -50,9 +50,6 @@ async function minify() {
if (!In || /^(-h|--help)$/.test(In))
return help();

if (/^--(js|css|html)$/.test(In))
return readStd(processStream);

if (/^(-v|--version)$/.test(In))
return log('v' + Version);

Expand All @@ -62,18 +59,21 @@ async function minify() {
if (optionsError)
return log.error(optionsError.message);

if (/^--(js|css|html)$/.test(In))
return readStd(processStream, options);

await uglifyFiles(files, options);
}

async function processStream(chunks) {
async function processStream(chunks, options) {
const {minify} = await import('../lib/minify.js');

if (!chunks || !In)
return;

const name = In.replace('--', '');

const [e, data] = await tryToCatch(minify[name], chunks);
const [e, data] = await tryToCatch(minify[name], chunks, options);

if (e)
return log.error(e);
Expand Down

0 comments on commit 04be2ee

Please sign in to comment.