From e2c9751984a4003b917dd5a849d1845f87e4f8f6 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 30 Mar 2022 12:29:22 +0700 Subject: [PATCH] Upgrade dependencies --- cleanup.js | 2 +- index.d.ts | 4 ++-- index.js | 23 ++++++++++++++--------- index.test-d.ts | 1 - init.js | 2 +- lib/update-notification.js | 4 ++-- package.json | 24 ++++++++++++------------ test/fetch.js | 8 ++++---- test/test.js | 4 ++-- 9 files changed, 38 insertions(+), 34 deletions(-) diff --git a/cleanup.js b/cleanup.js index ecb4bcc..955fe2b 100755 --- a/cleanup.js +++ b/cleanup.js @@ -2,7 +2,7 @@ import process from 'node:process'; import {fileURLToPath} from 'node:url'; import path from 'node:path'; -import execa from 'execa'; +import {execa} from 'execa'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); diff --git a/index.d.ts b/index.d.ts index 7c87e9e..fca5115 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,12 +1,12 @@ import Conf from 'conf'; import {Options} from 'got'; -export interface FetchOptions extends Options { +export interface FetchOptions extends Partial { // Deprecated, but left for backwards-compatibility. /** URL search parameters. */ - readonly query?: string | Record | URLSearchParams | undefined; + readonly query?: string | Record | URLSearchParams | undefined; /** Number of milliseconds this request should be cached. diff --git a/index.js b/index.js index 370c8b1..4955897 100644 --- a/index.js +++ b/index.js @@ -3,10 +3,10 @@ import process from 'node:process'; import {createRequire} from 'node:module'; import Conf from 'conf'; import got from 'got'; -import hookStd from 'hook-std'; +import {hookStderr} from 'hook-std'; import loudRejection from 'loud-rejection'; import cleanStack from 'clean-stack'; -import dotProp from 'dot-prop'; +import {getProperty} from 'dot-prop'; import AlfredConfig from 'alfred-config'; import updateNotification from './lib/update-notification.js'; @@ -50,7 +50,7 @@ alfy.matches = (input, list, item) => { return list.filter(listItem => { if (typeof item === 'string') { - listItem = dotProp.get(listItem, item); + listItem = getProperty(listItem, item); } if (typeof listItem === 'string') { @@ -116,17 +116,22 @@ alfy.fetch = async (url, options) => { ...options, }; + const {transform, maxAge} = options; + delete options.transform; + delete options.maxAge; + // Deprecated, but left for backwards-compatibility. if (options.query) { options.searchParams = options.query; + delete options.query; } if (typeof url !== 'string') { throw new TypeError(`Expected \`url\` to be a \`string\`, got \`${typeof url}\``); } - if (options.transform && typeof options.transform !== 'function') { - throw new TypeError(`Expected \`transform\` to be a \`function\`, got \`${typeof options.transform}\``); + if (transform && typeof transform !== 'function') { + throw new TypeError(`Expected \`transform\` to be a \`function\`, got \`${typeof transform}\``); } const rawKey = url + JSON.stringify(options); @@ -157,10 +162,10 @@ alfy.fetch = async (url, options) => { throw error; } - const data = options.transform ? options.transform(response) : response; + const data = transform ? transform(response) : response; - if (options.maxAge) { - alfy.cache.set(key, data, {maxAge: options.maxAge}); + if (maxAge) { + alfy.cache.set(key, data, {maxAge}); } return data; @@ -180,6 +185,6 @@ alfy.icon = { loudRejection(alfy.error); process.on('uncaughtException', alfy.error); -hookStd.stderr(alfy.error); +hookStderr(alfy.error); export default alfy; diff --git a/index.test-d.ts b/index.test-d.ts index 2026af5..010bac5 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-confusing-void-expression */ import {expectType} from 'tsd'; import alfy, {ScriptFilterItem} from './index.js'; diff --git a/init.js b/init.js index 313b38e..ff02152 100755 --- a/init.js +++ b/init.js @@ -2,7 +2,7 @@ import process from 'node:process'; import path from 'node:path'; import {fileURLToPath} from 'node:url'; -import execa from 'execa'; +import {execa} from 'execa'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); diff --git a/lib/update-notification.js b/lib/update-notification.js index a7958e2..162d99b 100644 --- a/lib/update-notification.js +++ b/lib/update-notification.js @@ -1,8 +1,8 @@ -import {readPackageUpAsync} from 'read-pkg-up'; +import {readPackageUp} from 'read-pkg-up'; import alfredNotifier from 'alfred-notifier'; export default async function updateNotification() { - const {package: pkg} = await readPackageUpAsync(); + const {package: pkg} = await readPackageUp(); const alfy = (pkg || {}).alfy || {}; if (alfy.updateNotification !== false) { diff --git a/package.json b/package.json index 64515fd..abe2876 100644 --- a/package.json +++ b/package.json @@ -37,26 +37,26 @@ "mac" ], "dependencies": { - "alfred-config": "^0.2.2", + "alfred-config": "^0.2.3", "alfred-link": "^0.3.1", "alfred-notifier": "^0.2.3", "cache-conf": "^0.6.0", "clean-stack": "^4.1.0", - "conf": "^10.0.1", - "dot-prop": "^6.0.1", - "execa": "^5.1.1", - "got": "^11.8.2", - "hook-std": "^2.0.0", + "conf": "^10.1.1", + "dot-prop": "^7.2.0", + "execa": "^6.1.0", + "got": "^12.0.3", + "hook-std": "^3.0.0", "loud-rejection": "^2.2.0", - "read-pkg-up": "^8.0.0" + "read-pkg-up": "^9.1.0" }, "devDependencies": { - "ava": "^3.15.0", + "ava": "^4.1.0", "delay": "^5.0.0", - "nock": "^13.1.1", + "nock": "^13.2.4", "tempfile": "^4.0.0", - "tsd": "^0.17.0", - "typescript": "^4.3.5", - "xo": "^0.43.0" + "tsd": "^0.19.1", + "typescript": "^4.6.3", + "xo": "^0.48.0" } } diff --git a/test/fetch.js b/test/fetch.js index 24dd188..e3a15c8 100644 --- a/test/fetch.js +++ b/test/fetch.js @@ -30,7 +30,7 @@ test('transform not a function', async t => { test('transform', async t => { const alfy = createAlfy(); const result = await alfy.fetch(`${URL}/no-cache`, { - transform: response => { + transform(response) { response.unicorn = 'rainbow'; return response; }, @@ -45,12 +45,12 @@ test('transform', async t => { test('cache', async t => { const alfy = createAlfy(); - t.deepEqual(await alfy.fetch(`${URL}/cache`, {maxAge: 5000}), {hello: 'world'}); - t.deepEqual(await alfy.fetch(`${URL}/cache`, {maxAge: 5000}), {hello: 'world'}); + t.deepEqual(await alfy.fetch(`${URL}/cache`, {maxAge: 5000, retry: {}}), {hello: 'world'}); + t.deepEqual(await alfy.fetch(`${URL}/cache`, {maxAge: 5000, retry: {}}), {hello: 'world'}); await delay(5000); - t.deepEqual(await alfy.fetch(`${URL}/cache`, {maxAge: 5000}), {hello: 'world!'}); + t.deepEqual(await alfy.fetch(`${URL}/cache`, {maxAge: 5000, retry: {}}), {hello: 'world!'}); }); test('cache key', async t => { diff --git a/test/test.js b/test/test.js index da0ca92..3349dbd 100644 --- a/test/test.js +++ b/test/test.js @@ -1,5 +1,5 @@ import test from 'ava'; -import hookStd from 'hook-std'; +import {hookStdout} from 'hook-std'; import {alfy} from './_utils.js'; const alfyInstance = alfy(); @@ -12,7 +12,7 @@ test('default', t => { }); test.serial('.error()', async t => { - const promise = hookStd.stdout(output => { + const promise = hookStdout(output => { promise.unhook(); t.is(JSON.parse(output).items[0].title, 'Error: foo'); });