Skip to content

Commit

Permalink
=! compression is now done using Node's native zlib module, this requ…
Browse files Browse the repository at this point in the history
…ires Node v12 at least

! `--glob-skip-br-extension` option not working
! some compression crashes on newer Node versions
= default window size (compression option) set to 24 (was 0)
~ huge deps upgrade
~ huge cleanup
  • Loading branch information
dzek69 committed Jan 25, 2024
1 parent c5a8250 commit fbfd2bf
Show file tree
Hide file tree
Showing 30 changed files with 5,669 additions and 5,265 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
/*.tgz
*.log
*.tsbuildinfo

/test/words/*
!/test/words/generate.py
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/build-scripts/
/test/

/babel.config.js
/jest.config.cjs
/yarn.lock
/*.tgz
Expand Down
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.js
*.ts
*.tsx
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [UNRELEASED]
(nothing yet)
## [2.0.0] - 2024-01-25
### Breaking
- compression is now done using Node's native zlib module, this requires Node v12 at least
### Fixed
- `--glob-skip-br-extension` option not working
- some compression crashes on newer Node versions
### Changed
- default window size (compression option) set to 24 (was 0)
### Dev
- huge deps upgrade
- huge cleanup

## [1.0.4] - 2023-01-07
### Dev
Expand Down
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
# brotli-cli

Brotli files compressor.
Decompression feature will come.

Based on `brotli` npm module.
Brotli files compressor, now from 10 times faster! ⚡

## Usage

### Global install
1. Install globally `npm i -g brotli-cli`
1. No install: `npx brotli-cli ... (other params)`

1. `npm i -g brotli-cli`
### Compressing given files:
1. `brotli-cli compress file1.txt file2.svg file3.js`
1. (see Detailed Usage for glob support)

### Local install / no install
> You need npm 5.2+ for this
1. `npm i brotli-cli`
1. `npx brotli-cli compress file1.txt file2.svg file3.js`
1. (see Detailed Usage for glob support)
### Compressing by glob pattern:
1. `brotli-cli compress --glob "public/*.html"`
### Printing to stdout:
> To do this, you can only specify one file to compress, and you have to add `-` at the end of the command.
1. `brotli-cli compress index.html -`
1. `brotli-cli compress index.html - > compressed.html`

Files will be created in the same directory, but with `.br` extension appended. Overwriting will occur without asking.

Expand All @@ -33,7 +29,7 @@ Options:
--version Show version number [boolean]
-m, --mode Brotli compression mode [generic, text, font] [default: "generic"]
-q, --quality Brotli compression quality [0-11] [default: 11]
-l, --lgwin Brotli compression window size [0, 10-24] [default: 0]
-l, --lgwin Brotli compression window size [0, 10-24] [default: 24]
-b, --bail Stop execution on first error [boolean] [default: true]
--add-extension, --br Add .br extension to compressed files [boolean] [default: true]
-g, --glob Use glob pattern when matching files [boolean] [default: false]
Expand All @@ -44,8 +40,8 @@ Examples:
brotli-cli compress -q 5 image.jpg Compress `image.jpg` file with generic compression level 5 and save to image.jpg.br
brotli-cli compress -q 5 -br false image.jpg Compress `image.jpg` file and overwrite it
brotli-cli compress -mode text index.html - Compress `index.html` file with text mode max compression (level 11) and print to stdout
brotli-cli compress --glob "images/*.jpg Compress all jpg files from `images` directory, stop on first error.
brotli-cli compress --glob --bail false "images/*.jpg" Compress all jpg files from `images` directory, do not stop on first error (will still print errors to std err and exit with error code).
brotli-cli compress --glob "images/*.jpg" Compress all jpg files from `images` directory, stop on first error.
brotli-cli compress --glob --bail false "images/*.jpg" Compress all jpg files from `images` directory, do not stop on first error (will still print errors to stderr and exit with error code).
```

## License
Expand Down
3 changes: 3 additions & 0 deletions build-scripts/compile.cjs.after.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import fs from "fs-extra";
import { run } from "./utils.mjs";

const contents = `{"type": "commonjs"}`;

(async () => {
console.info("[CJS compile post-processing started]");
await fs.writeFile("./dist/package.json", contents);
console.info("Written dist/package.json with commonjs type fix");
await run("resolve-tspaths", ["--project", "tsconfig.cjs.json"]);
console.info("Resolved TypeScript import paths");
console.info("[CJS compile post-processing ended]");
})();
26 changes: 26 additions & 0 deletions build-scripts/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { spawn } from "child_process";

const run = (command, args) => {
return new Promise((resolve, reject) => {
const cmd = spawn(command, args, {
stdio: ["ignore", "inherit", "inherit"],
});

cmd.on("close", (code) => {
if (!code) {
resolve();
return;
}

reject(new Error(`Program exited with code ${code}`));
});

cmd.on("error", () => {
reject(new Error(`Can't start program`));
});
});
};

export {
run
}
35 changes: 21 additions & 14 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
module.exports = {
// testMatch: [],
collectCoverageFrom: [
'src/**/*.{mjs,js,jsx,ts,tsx}',
'!**/*.d.ts'
],
setupFiles: [
'<rootDir>/test/bootstrap.cjs'
],
testURL: 'http://localhost:8080',
moduleNameMapper: {
'^(.*)\.js$': '$1',
},
"collectCoverageFrom": [
"src/**/*.{mjs,js,jsx,ts,tsx}",
"!**/*.d.ts"
],
"setupFiles": [
"<rootDir>/test/bootstrap.cjs"
],
"moduleNameMapper": {
"^(.*).js$": "$1"
},
"testEnvironmentOptions": {
"url": "http://localhost:8080"
},
"transform": {
"\\.[jt]sx?$": [
"babel-jest",
{
"configFile": "./test/babel.config.cjs"
}
]
}
};


82 changes: 47 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,68 +1,80 @@
{
"name": "brotli-cli",
"version": "1.0.4",
"version": "2.0.0",
"repository": "[email protected]:dzek69/brotli-cli.git",
"homepage": "https://github.com/dzek69/brotli-cli",
"author": "Jacek Nowacki",
"license": "MIT",
"scripts": {
"test": "NODE_ENV=test jest",
"docs": "typedoc src/index.ts --skipErrorChecking --out docs --includeVersion --pluginPages ./pagesconfig.json",
"compile": "yarn compile:cjs",
"docs": "typedoc src/index.ts --skipErrorChecking --out docs --includeVersion",
"compile": "pnpm run compile:cjs",
"compile:cjs": "rm -rf dist && tsc --project tsconfig.cjs.json && node ./build-scripts/compile.cjs.after.mjs",
"typecheck": "tsc --noEmit",
"lint": "eslint src --ext .ts,.tsx,.js,.jsx,.mjs",
"lint:fix": "yarn lint --fix",
"prepack": "yarn compile",
"prepublishOnly": "yarn audit && yarn lint && yarn test && yarn docs",
"lint:fix": "pnpm run lint --fix",
"prepack": "pnpm run compile",
"prepublishOnly": "pnpm audit && pnpm run lint && pnpm run test && pnpm run docs",
"start:dev": "nodemon",
"start:dev:compatibility": "TS_NODE_FILES=true yarn start:dev",
"start:dev:compatibility": "TS_NODE_FILES=true pnpm run start:dev",
"prepare": "husky install",
"updates": "npx --yes npm-check-updates --dep prod",
"updates:dev": "npx --yes npm-check-updates --dep dev",
"updates:all": "npx --yes npm-check-updates"
"updates": "pnpm dlx npm-check-updates --dep prod",
"updates:dev": "pnpm dlx npm-check-updates --dep dev",
"updates:all": "pnpm dlx npm-check-updates"
},
"bin": "./dist/index.js",
"type": "module",
"dependencies": {
"better-custom-error": "^4.0.5",
"brotli": "^1.3.3",
"@ezez/errors": "^6.0.2",
"fast-glob": "^3.2.12",
"yargs": "^16.2.0"
"queue-system": "^4.1.1",
"yargs": "^17.7.2"
},
"devDependencies": {
"@babel/core": "^7.19.3",
"@babel/preset-env": "^7.19.3",
"@babel/preset-typescript": "^7.18.6",
"@dzek69/eslint-config-base": "^2.3.0",
"@dzek69/eslint-config-typescript": "^1.0.2",
"@babel/core": "^7.22.20",
"@babel/preset-env": "^7.22.20",
"@babel/preset-typescript": "^7.22.15",
"@dzek69/eslint-config-base": "^2.5.0",
"@dzek69/eslint-config-import": "^1.3.0",
"@dzek69/eslint-config-import-typescript": "^1.0.1",
"@dzek69/eslint-config-typescript": "^1.1.1",
"@knodes/typedoc-plugin-pages": "^0.23.4",
"@types/brotli": "^1.3.0",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
"eslint": "^8.24.0",
"fs-extra": "^10.1.0",
"husky": "^8.0.1",
"jest": "^29.1.1",
"@types/jest": "^29.5.5",
"@types/yargs": "^17.0.32",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0",
"babel-plugin-module-extension": "^0.1.3",
"eslint": "^8.44.0",
"eslint-plugin-import": "^2.28.1",
"fs-extra": "^11.1.1",
"husky": "^8.0.3",
"jest": "^29.7.0",
"must": "^0.13.4",
"nodemon": "^2.0.20",
"nodemon": "^3.0.1",
"prettier": "^2.8.8",
"resolve-tspaths": "^0.8.15",
"ts-node": "^10.9.1",
"typedoc": "^0.23.15",
"typescript": "^4.7.4",
"babel-plugin-module-extension": "^0.1.3",
"@types/jest": "^29.0.3",
"eslint-plugin-import": "^2.26.0",
"@dzek69/eslint-config-import": "^1.0.0",
"@dzek69/eslint-config-import-typescript": "^1.0.0",
"@knodes/typedoc-plugin-pages": "^0.23.1"
"typedoc": "^0.23.0",
"typescript": "^5.2.2"
},
"husky": {
"hooks": {
"pre-push": "yarn prepublishOnly && yarn compile"
"pre-push": "pnpm run prepublishOnly && pnpm run compile"
}
},
"libraryTemplate": {
"version": "3.6.0",
"version": "3.11.2",
"language": "typescript",
"fixDefaultForCommonJS": true,
"jsx": false
},
"exports": {
".": {
"types": "./esm/index.d.ts"
}
},
"engines": {
"node": ">=12.0.0"
}
}
Loading

0 comments on commit fbfd2bf

Please sign in to comment.