Skip to content

Commit

Permalink
Merge pull request #162 from electron/malept/refactor/filenamify
Browse files Browse the repository at this point in the history
refactor(Cache): replace sanitize-filename with filenamify
  • Loading branch information
ckerr authored Jun 8, 2020
2 parents 8e287c2 + 68b879c commit 9034cc4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 30 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
"dependencies": {
"debug": "^4.1.1",
"env-paths": "^2.2.0",
"filenamify": "^4.1.0",
"fs-extra": "^8.1.0",
"got": "^9.6.0",
"progress": "^2.0.3",
"sanitize-filename": "^1.6.2",
"sumchecker": "^3.0.1"
},
"devDependencies": {
Expand All @@ -40,7 +40,6 @@
"@types/jest": "^24.0.13",
"@types/node": "^12.0.2",
"@types/progress": "^2.0.3",
"@types/sanitize-filename": "^1.1.28",
"husky": "^2.3.0",
"jest": "^24.8.0",
"lint-staged": "^8.1.7",
Expand Down
4 changes: 2 additions & 2 deletions src/Cache.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import debug from 'debug';
import envPaths from 'env-paths';
import * as filenamify from 'filenamify';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as url from 'url';
import * as sanitize from 'sanitize-filename';

const d = debug('@electron/get:cache');

Expand All @@ -18,7 +18,7 @@ export class Cache {
const { search, hash, ...rest } = url.parse(downloadUrl);
const strippedUrl = url.format(rest);

const sanitizedUrl = sanitize(strippedUrl);
const sanitizedUrl = filenamify(strippedUrl, { maxLength: 255, replacement: '' });
return path.resolve(this.cacheRoot, sanitizedUrl, fileName);
}

Expand Down
3 changes: 1 addition & 2 deletions test/Cache.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as fs from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
import * as sanitize from 'sanitize-filename';

import { Cache } from '../src/Cache';

Expand All @@ -10,7 +9,7 @@ describe('Cache', () => {
let cache: Cache;

const dummyUrl = 'dummy://';
const sanitizedDummyUrl = sanitize(dummyUrl);
const sanitizedDummyUrl = 'dummy';

beforeEach(async () => {
cacheDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-download-spec-'));
Expand Down
52 changes: 28 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,6 @@
dependencies:
"@types/node" "*"

"@types/sanitize-filename@^1.1.28":
version "1.1.28"
resolved "https://registry.yarnpkg.com/@types/sanitize-filename/-/sanitize-filename-1.1.28.tgz#baa18f5ce4330fcbb3ea7b62f65550963d9aaa07"
integrity sha1-uqGPXOQzD8uz6nti9lVQlj2aqgc=

"@types/stack-utils@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
Expand Down Expand Up @@ -2224,6 +2219,20 @@ figures@^2.0.0:
dependencies:
escape-string-regexp "^1.0.5"

filename-reserved-regex@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/filename-reserved-regex/-/filename-reserved-regex-2.0.0.tgz#abf73dfab735d045440abfea2d91f389ebbfa229"
integrity sha1-q/c9+rc10EVECr/qLZHzieu/oik=

filenamify@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/filenamify/-/filenamify-4.1.0.tgz#54d110810ae74eebfe115c1b995bd07e03cf2184"
integrity sha512-KQV/uJDI9VQgN7sHH1Zbk6+42cD6mnQ2HONzkXUfPJ+K2FC8GZ1dpewbbHw0Sz8Tf5k3EVdHVayM4DoAwWlmtg==
dependencies:
filename-reserved-regex "^2.0.0"
strip-outer "^1.0.1"
trim-repeated "^1.0.0"

fill-range@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-4.0.0.tgz#d544811d428f98eb06a63dc402d2403c328c38f7"
Expand Down Expand Up @@ -6118,13 +6127,6 @@ sane@^4.0.3:
minimist "^1.1.1"
walker "~1.0.5"

sanitize-filename@^1.6.2:
version "1.6.2"
resolved "https://registry.yarnpkg.com/sanitize-filename/-/sanitize-filename-1.6.2.tgz#01b4fc8809f14e9d22761fe70380fe7f3f902185"
integrity sha512-cmTzND7RMxUB+f7gI+4+KAVHWEg0lfXvQJdko+FXDP5bNbGIdx4KMP5pX6lv5jfT9jSf6OBbjyxjFtZQwYA/ig==
dependencies:
truncate-utf8-bytes "^1.0.0"

sax@^1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
Expand Down Expand Up @@ -6685,6 +6687,13 @@ strip-json-comments@~2.0.1:
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo=

strip-outer@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/strip-outer/-/strip-outer-1.0.1.tgz#b2fd2abf6604b9d1e6013057195df836b8a9d631"
integrity sha512-k55yxKHwaXnpYGsOzg4Vl8+tDrWylxDEpknGjhTiZB8dFRU5rTo9CAzeycivxV3s+zlTKwrs6WxMxR95n26kwg==
dependencies:
escape-string-regexp "^1.0.2"

sumchecker@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/sumchecker/-/sumchecker-3.0.1.tgz#6377e996795abb0b6d348e9b3e1dfb24345a8e42"
Expand Down Expand Up @@ -6885,18 +6894,18 @@ trim-off-newlines@^1.0.0:
resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3"
integrity sha1-n5up2e+odkw4dpi8v+sshI8RrbM=

trim-repeated@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/trim-repeated/-/trim-repeated-1.0.0.tgz#e3646a2ea4e891312bf7eace6cfb05380bc01c21"
integrity sha1-42RqLqTokTEr9+rObPsFOAvAHCE=
dependencies:
escape-string-regexp "^1.0.2"

trim-right@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"
integrity sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=

truncate-utf8-bytes@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz#405923909592d56f78a5818434b0b78489ca5f2b"
integrity sha1-QFkjkJWS1W94pYGENLC3hInKXys=
dependencies:
utf8-byte-length "^1.0.1"

ts-jest@^24.0.0:
version "24.0.2"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-24.0.2.tgz#8dde6cece97c31c03e80e474c749753ffd27194d"
Expand Down Expand Up @@ -7120,11 +7129,6 @@ use@^3.1.0:
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==

utf8-byte-length@^1.0.1:
version "1.0.4"
resolved "https://registry.yarnpkg.com/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz#f45f150c4c66eee968186505ab93fcbb8ad6bf61"
integrity sha1-9F8VDExm7uloGGUFq5P8u4rWv2E=

util-deprecate@^1.0.1, util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
Expand Down

0 comments on commit 9034cc4

Please sign in to comment.