Skip to content

Commit

Permalink
Minimize dependency footprint
Browse files Browse the repository at this point in the history
Removing progress (replacing it with an easier progress indicator)
Removing camelcase (replacing it with a simple regexp)
  • Loading branch information
kristian committed Dec 3, 2023
1 parent c88d0cc commit eefabe8
Show file tree
Hide file tree
Showing 6 changed files with 565 additions and 667 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## `HEAD`

No changes yet
- Back to the roots, minimize dependency footprint, similar to how Mathias Bynens handled the library
- Minimum required node version to execute tests is now 16.7.0, due to the use of `node:stream/consumers`

## 4.2.0

Expand Down
14 changes: 4 additions & 10 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import constants from "buffer";
const { MAX_STRING_LENGTH } = constants;

import meow from "meow";
import { default as camelCase } from "camelcase";
import ProgressBar from "progress";

import { default as minify, defaultOptions, minifyStream, defaultStreamOptions, debug as debugMinify } from "./index.js";

Expand Down Expand Up @@ -158,19 +156,15 @@ if (debug) {
// if the debug flag is a string and doesn't contain --debug=true, only debug the single option(s) specified
debugMinify(input && fs.readFileSync(input, "utf8"), !cli.flags.debug.includes("true") ? {
...Object.fromEntries(Object.keys(defaultOptions).map(option => [option, false])), // set all to false
...Object.fromEntries(cli.flags.debug.map(camelCase).map(option => [option, true])), // set options specified to true
...Object.fromEntries(cli.flags.debug.map(option => option.replace(/[-_.\s](.)?/g, // set (camel cased) options specified to true
(match, char) => char?.toUpperCase() ?? String())).map(option => [option, true])),
...options(defaultOptions) // override any other given options, e.g. --debug=remove-whitespace-between-tags --remove-whitespace-between-tags=strict
} : options(defaultOptions));
} else if (cli.flags.stream) {
const stream = fs.createReadStream(input, "utf8");
if (output && size) {
const bar = new ProgressBar(` minify ${ path.basename(input) } [:bar] :percent ETA: :etas`, {
incomplete: " ",
width: 20,
total: size
});
stream.on("data", chunk =>
bar.tick(chunk.length));
let received = 0; stream.on("data", chunk => process.stdout.write(
`\rMinifying ${(received += chunk.length) / size * 100 | 0}% ...`));
}

stream.pipe(minifyStream(options(defaultStreamOptions)))
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export function minify(xml, options) {
return xml.trim ? xml.trim() : trim(xml);
}; export default minify;

import pumpify from "pumpify";
import pumpify from "pumpify"; // XXX: to be replaced by node:stream compose as soon as it is stable
import replaceStream from "replacestream"; // note that replacestream does NOT support zero-length regex matches!
import { PassThrough } from "node:stream";

Expand Down
Loading

0 comments on commit eefabe8

Please sign in to comment.