Skip to content

Commit

Permalink
fix: crash when filename and algorithm options are functions (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Jan 11, 2021
1 parent 44c16e2 commit f33424a
Show file tree
Hide file tree
Showing 14 changed files with 958 additions and 1,078 deletions.
1,000 changes: 371 additions & 629 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@
"cross-env": "^7.0.2",
"del": "^6.0.0",
"del-cli": "^3.0.1",
"eslint": "^7.16.0",
"eslint": "^7.17.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-import": "^2.22.1",
"file-loader": "^6.2.0",
"husky": "^4.3.6",
"husky": "^4.3.7",
"jest": "^26.6.3",
"lint-staged": "^10.5.1",
"memfs": "^3.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.1.2",
"standard-version": "^9.0.0",
"webpack": "^5.11.0",
"webpack-stats-plugin": "^1.0.2",
"standard-version": "^9.1.0",
"webpack": "^5.12.3",
"webpack-stats-plugin": "^1.0.3",
"workbox-webpack-plugin": "^6.0.2"
},
"keywords": [
Expand Down
27 changes: 20 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import path from "path";
import crypto from "crypto";

import { validate } from "schema-utils";
import serialize from "serialize-javascript";
Expand Down Expand Up @@ -126,15 +127,27 @@ class CompressionPlugin {
let relatedName;

if (typeof this.options.algorithm === "function") {
let filenameForRelatedName = this.options.filename;

const index = filenameForRelatedName.indexOf("?");
if (typeof this.options.filename === "function") {
relatedName = `compression-function-${crypto
.createHash("md5")
.update(serialize(this.options.filename))
.digest("hex")}`;
} else {
let filenameForRelatedName = this.options.filename;

const index = filenameForRelatedName.indexOf("?");

if (index >= 0) {
filenameForRelatedName = filenameForRelatedName.substr(
0,
index
);
}

if (index >= 0) {
filenameForRelatedName = filenameForRelatedName.substr(0, index);
relatedName = `${path
.extname(filenameForRelatedName)
.slice(1)}ed`;
}

relatedName = `${path.extname(filenameForRelatedName).slice(1)}ed`;
} else if (this.options.algorithm === "gzip") {
relatedName = "gzipped";
} else {
Expand Down
Loading

0 comments on commit f33424a

Please sign in to comment.