Skip to content

Commit

Permalink
Upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 30, 2022
1 parent 1bf01cf commit e2c9751
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 34 deletions.
2 changes: 1 addition & 1 deletion cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Conf from 'conf';
import {Options} from 'got';

export interface FetchOptions extends Options {
export interface FetchOptions extends Partial<Options> {
// Deprecated, but left for backwards-compatibility.
/**
URL search parameters.
*/
readonly query?: string | Record<string, string | number | boolean | null | undefined> | URLSearchParams | undefined;
readonly query?: string | Record<string, string | number | boolean | undefined> | URLSearchParams | undefined;

/**
Number of milliseconds this request should be cached.
Expand Down
23 changes: 14 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -180,6 +185,6 @@ alfy.icon = {

loudRejection(alfy.error);
process.on('uncaughtException', alfy.error);
hookStd.stderr(alfy.error);
hookStderr(alfy.error);

export default alfy;
1 change: 0 additions & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-confusing-void-expression */
import {expectType} from 'tsd';
import alfy, {ScriptFilterItem} from './index.js';

Expand Down
2 changes: 1 addition & 1 deletion init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
4 changes: 2 additions & 2 deletions lib/update-notification.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
8 changes: 4 additions & 4 deletions test/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand All @@ -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 => {
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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');
});
Expand Down

0 comments on commit e2c9751

Please sign in to comment.