From 219802cff002ac4e47746f7dfbaa37d3b56aad3a Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 26 Jul 2024 17:17:26 +0200 Subject: [PATCH] Update dependencies --- package.json | 52 +++++++++++++++++++++++++------------------------ source/index.ts | 22 ++++++++++----------- test/_server.ts | 4 ++-- test/cookie.ts | 2 +- test/test.ts | 9 ++++----- 5 files changed, 45 insertions(+), 44 deletions(-) diff --git a/package.json b/package.json index f70ae43..0b90d23 100644 --- a/package.json +++ b/package.json @@ -61,44 +61,44 @@ "dependencies": { "array-differ": "^4.0.0", "array-uniq": "^3.0.0", - "capture-website": "^4.0.0", - "date-fns": "^2.30.0", + "capture-website": "^4.1.0", + "date-fns": "^3.6.0", "filenamify": "^6.0.0", - "filenamify-url": "^3.0.0", + "filenamify-url": "^3.1.0", "get-res": "^3.0.0", "lodash.template": "^4.5.0", "log-symbols": "^6.0.0", - "make-dir": "^4.0.0", - "p-map": "^6.0.0", + "make-dir": "^5.0.0", + "p-map": "^7.0.2", "p-memoize": "^7.1.1", "plur": "^5.1.0", - "type-fest": "^4.6.0", + "type-fest": "^4.23.0", "unused-filename": "^4.0.1", "viewport-list": "^5.1.1" }, "devDependencies": { - "@sindresorhus/tsconfig": "^5.0.0", - "@types/cookie": "^0.5.3", - "@types/get-res": "^3.0.2", - "@types/lodash.template": "^4.5.2", - "@types/node": "^20.8.10", - "@types/png.js": "^0.2.2", - "@types/sinon": "^17.0.0", - "@types/viewport-list": "^5.1.2", - "ava": "^5.3.1", - "cookie": "^0.5.0", + "@sindresorhus/tsconfig": "^6.0.0", + "@types/cookie": "^0.6.0", + "@types/get-res": "^3.0.3", + "@types/lodash.template": "^4.5.3", + "@types/node": "^20.14.12", + "@types/png.js": "^0.2.3", + "@types/sinon": "^17.0.3", + "@types/viewport-list": "^5.1.3", + "ava": "^6.1.3", + "cookie": "^0.6.0", "del-cli": "^5.1.0", - "file-type": "^18.6.0", - "get-port": "^7.0.0", - "image-dimensions": "^2.1.0", - "nyc": "^15.1.0", + "file-type": "^19.3.0", + "get-port": "^7.1.0", + "image-dimensions": "^2.3.0", + "nyc": "^17.0.0", "path-exists": "^5.0.0", "pify": "^6.1.0", "png.js": "^0.2.1", - "sinon": "^17.0.1", - "ts-node": "^10.9.1", - "typescript": "^5.2.2", - "xo": "^0.56.0" + "sinon": "^18.0.0", + "ts-node": "^10.9.2", + "typescript": "^5.5.4", + "xo": "^0.59.2" }, "ava": { "workerThreads": false, @@ -119,7 +119,9 @@ "@typescript-eslint/no-unsafe-assignment": "off", "@typescript-eslint/no-unsafe-return": "off", "@typescript-eslint/no-unsafe-call": "off", - "unicorn/prefer-event-target": "off" + "unicorn/prefer-event-target": "off", + "n/file-extension-in-import": "off", + "@typescript-eslint/no-unsafe-argument": "off" } }, "nyc": { diff --git a/source/index.ts b/source/index.ts index a7774b8..30a92ce 100644 --- a/source/index.ts +++ b/source/index.ts @@ -15,10 +15,10 @@ import filenamify from 'filenamify'; import {unusedFilename} from 'unused-filename'; import arrayUniq from 'array-uniq'; import arrayDiffer from 'array-differ'; -import dateFns from 'date-fns'; +import {format as formatDate} from 'date-fns'; import getResolutions from 'get-res'; import logSymbols from 'log-symbols'; -import makeDir from 'make-dir'; +import {makeDirectory} from 'make-dir'; import viewportList from 'viewport-list'; import template from 'lodash.template'; import plur from 'plur'; @@ -257,10 +257,10 @@ export default class Pageres extends EventEmitter { this.setMaxListeners(Number.POSITIVE_INFINITY); this.#options = {...options}; - this.#options.filename = this.#options.filename ?? '<%= url %>-<%= size %><%= crop %>'; - this.#options.format = this.#options.format ?? 'png'; - this.#options.incrementalName = this.#options.incrementalName ?? false; - this.#options.launchOptions = this.#options.launchOptions ?? {}; + this.#options.filename ??= '<%= url %>-<%= size %><%= crop %>'; + this.#options.format ??= 'png'; + this.#options.incrementalName ??= false; + this.#options.launchOptions ??= {}; } /** @@ -452,9 +452,9 @@ export default class Pageres extends EventEmitter { async #save(screenshots: Screenshot[]): Promise { await Promise.all(screenshots.map(async screenshot => { - await makeDir(this.destination()); - const dest = path.join(this.destination(), screenshot.filename); - await fsPromises.writeFile(dest, screenshot); + await makeDirectory(this.destination()); + const destination = path.join(this.destination(), screenshot.filename); + await fsPromises.writeFile(destination, screenshot); })); } @@ -474,8 +474,8 @@ export default class Pageres extends EventEmitter { const now = Date.now(); let filename = filenameTemplate({ crop: options.crop ? '-cropped' : '', - date: dateFns.format(now, 'yyyy-MM-dd'), - time: dateFns.format(now, 'HH-mm-ss'), + date: formatDate(now, 'yyyy-MM-dd'), + time: formatDate(now, 'HH-mm-ss'), size, width, height, diff --git a/test/_server.ts b/test/_server.ts index 0bc30e1..9f32a81 100644 --- a/test/_server.ts +++ b/test/_server.ts @@ -17,9 +17,9 @@ export type TestServer = { protocol: string; } & http.Server; -const baseCreateServer = (fn: http.RequestListener): (() => Promise) => async (): Promise => { +const baseCreateServer = (function_: http.RequestListener): (() => Promise) => async (): Promise => { const port = await getPort(); - const server = http.createServer(fn) as unknown as TestServer; + const server = http.createServer(function_) as unknown as TestServer; server.host = host; server.port = port; diff --git a/test/cookie.ts b/test/cookie.ts index e096035..43d60b0 100644 --- a/test/cookie.ts +++ b/test/cookie.ts @@ -15,7 +15,7 @@ async function cookieTest(input: string | Cookie, t: ExecutionContext): Promise< server.close(); - const png = new PNG(screenshots[0]!); + const png = new PNG(screenshots[0]); const {pixels} = await pify(png.parse.bind(png))(); t.is(pixels[0], 0); diff --git a/test/test.ts b/test/test.ts index 229b34c..fe63c6a 100644 --- a/test/test.ts +++ b/test/test.ts @@ -5,15 +5,14 @@ import {fileURLToPath} from 'node:url'; import path from 'node:path'; import test from 'ava'; import {imageDimensionsFromData} from 'image-dimensions'; -import dateFns from 'date-fns'; +import {format as formatDate} from 'date-fns'; import PNG from 'png.js'; import pify from 'pify'; import {pathExists} from 'path-exists'; import {stub as sinonStub} from 'sinon'; import {fileTypeFromBuffer} from 'file-type'; import Pageres, {type Screenshot} from '../source/index.js'; -import type {TestServer} from './_server.js'; -import {createServer} from './_server.js'; +import {type TestServer, createServer} from './_server.js'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -113,7 +112,7 @@ test.serial('success message', async t => { await pageres.run(); pageres.successMessage(); const [message] = stub.firstCall.args; - t.true(message.includes('Generated 3 screenshots from 1 url and 1 size'), message); // eslint-disable-line ava/assertion-arguments, @typescript-eslint/no-unsafe-argument + t.true(message.includes('Generated 3 screenshots from 1 url and 1 size'), message); // eslint-disable-line ava/assertion-arguments stub.restore(); }); @@ -164,7 +163,7 @@ test('`filename` option', async t => { .run(); t.is(screenshots.length, 1); - t.regex(screenshots[0].filename, new RegExp(`${dateFns.format(Date.now(), 'yyyy-MM-dd')} - \\d{2}-\\d{2}-\\d{2} - ${server.host}!${server.port}.png`)); + t.regex(screenshots[0].filename, new RegExp(`${formatDate(Date.now(), 'yyyy-MM-dd')} - \\d{2}-\\d{2}-\\d{2} - ${server.host}!${server.port}.png`)); }); test('`selector` option', async t => {