From 627af6039973ae9d23ace83a9cd03ddb256e7d5a Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 22 Mar 2019 00:17:20 +0700 Subject: [PATCH] Upgrade dependencies --- package.json | 12 ++++++------ source/index.ts | 40 ++++++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 3f824ed..df3913b 100644 --- a/package.json +++ b/package.json @@ -55,9 +55,9 @@ "dependencies": { "array-differ": "^2.0.3", "array-uniq": "^2.0.0", - "capture-website": "^0.1.2", + "capture-website": "^0.3.0", "date-fns": "^1.30.1", - "filenamify": "^2.0.0", + "filenamify": "^3.0.0", "filenamify-url": "^1.0.0", "get-res": "^3.0.0", "lodash.template": "^4.0.1", @@ -65,19 +65,19 @@ "make-dir": "^2.0.0", "mem": "^4.1.0", "plur": "^3.0.1", - "unused-filename": "^1.0.0", + "unused-filename": "^2.0.0", "viewport-list": "^5.0.1" }, "devDependencies": { - "@sindresorhus/tsconfig": "^0.2.0", + "@sindresorhus/tsconfig": "^0.3.0", "@types/image-size": "^0.7.0", - "@types/node": "^10.12.23", + "@types/node": "^11.11.4", "@typescript-eslint/eslint-plugin": "^1.3.0", "ava": "^1.2.0", "cookie": "^0.3.1", "coveralls": "^3.0.0", "del-cli": "^1.1.0", - "eslint-config-xo-typescript": "^0.7.0", + "eslint-config-xo-typescript": "^0.9.0", "file-type": "^10.7.1", "get-port": "^4.1.0", "image-size": "^0.7.1", diff --git a/source/index.ts b/source/index.ts index 6650404..5b7c806 100644 --- a/source/index.ts +++ b/source/index.ts @@ -140,25 +140,29 @@ export default class Pageres extends EventEmitter { } async run(): Promise { - await Promise.all(this.src().map(async (src: Source): Promise => { - const options = {...this.options, ...src.options}; - const sizes = arrayUniq(src.sizes.filter(/./.test, /^\d{2,4}x\d{2,4}$/i)); - const keywords = arrayDiffer(src.sizes, sizes); + await Promise.all(this.src().map(async (source: Source): Promise => { + const options = { + ...this.options, + ...source.options + }; + + const sizes = arrayUniq(source.sizes.filter(/./.test, /^\d{2,4}x\d{2,4}$/i)); + const keywords = arrayDiffer(source.sizes, sizes); - this.urls.push(src.url); + this.urls.push(source.url); - if (sizes.length === 0 && keywords.indexOf('w3counter') !== -1) { - return this.resolution(src.url, options); + if (sizes.length === 0 && keywords.includes('w3counter')) { + return this.resolution(source.url, options); } if (keywords.length > 0) { - return this.viewport({url: src.url, sizes, keywords}, options); + return this.viewport({url: source.url, sizes, keywords}, options); } for (const size of sizes) { this.sizes.push(size); // TODO: Make this concurrent - this.items.push(await this.create(src.url, size, options)); + this.items.push(await this.create(source.url, size, options)); } return undefined; @@ -195,14 +199,14 @@ export default class Pageres extends EventEmitter { } } - private async viewport(obj: Viewport, options: Options): Promise { - for (const item of await viewportListMem(obj.keywords) as {size: string}[]) { + private async viewport(viewport: Viewport, options: Options): Promise { + for (const item of await viewportListMem(viewport.keywords) as {size: string}[]) { this.sizes.push(item.size); - obj.sizes.push(item.size); + viewport.sizes.push(item.size); } - for (const size of arrayUniq(obj.sizes)) { - this.items.push(await this.create(obj.url, size, options)); + for (const size of arrayUniq(viewport.sizes)) { + this.items.push(await this.create(viewport.url, size, options)); } } @@ -214,10 +218,10 @@ export default class Pageres extends EventEmitter { })); } - private async create(uri: string, size: string, options: Options): Promise { - const basename = path.isAbsolute(uri) ? path.basename(uri) : uri; + private async create(url: string, size: string, options: Options): Promise { + const basename = path.isAbsolute(url) ? path.basename(url) : url; - let hash = parseUrl(uri).hash || ''; + let hash = parseUrl(url).hash || ''; // Strip empty hash fragments: `#` `#/` `#!/` if (/^#!?\/?$/.test(hash)) { hash = ''; @@ -266,7 +270,7 @@ export default class Pageres extends EventEmitter { }; } - const screenshot = await captureWebsite.buffer(uri, finalOptions); + const screenshot = await captureWebsite.buffer(url, finalOptions) as any; screenshot.filename = filename; return screenshot; }