Skip to content

Commit

Permalink
Upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 4, 2018
1 parent 1d55336 commit a578078
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 49 deletions.
7 changes: 2 additions & 5 deletions cleanup.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/usr/bin/env node
'use strict';
const execa = require('execa');
const npmRunPath = require('npm-run-path');

const env = npmRunPath.env({cwd: __dirname});

execa('alfred-unlink', {env}).catch(err => {
console.error(err);
execa('alfred-unlink', {localDir: __dirname}).catch(error => {
console.error(error);
process.exit(1);
});
38 changes: 19 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ alfy.alfred = {

alfy.input = process.argv[2];

alfy.output = arr => {
console.log(JSON.stringify({items: arr}, null, '\t'));
alfy.output = items => {
console.log(JSON.stringify({items}, null, '\t'));
};

alfy.matches = (input, list, item) => {
Expand All @@ -63,12 +63,12 @@ alfy.matches = (input, list, item) => {

alfy.inputMatches = (list, item) => alfy.matches(alfy.input, list, item);

alfy.log = str => {
console.error(str);
alfy.log = text => {
console.error(text);
};

alfy.error = err => {
const stack = cleanStack(err.stack || err);
alfy.error = error => {
const stack = cleanStack(error.stack || error);

const copy = `
\`\`\`
Expand All @@ -82,7 +82,7 @@ ${process.platform} ${process.arch} ${os.release()}
`.trim();

alfy.output([{
title: err.stack ? `${err.name}: ${err.message}` : err,
title: error.stack ? `${error.name}: ${error.message}` : error,
subtitle: 'Press ⌘L to see the full error and ⌘C to copy it.',
valid: false,
text: {
Expand All @@ -105,42 +105,42 @@ alfy.cache = new CacheConf({
version: alfy.meta.version
});

alfy.fetch = (url, opts) => {
opts = Object.assign({
alfy.fetch = (url, options) => {
options = Object.assign({
json: true
}, opts);
}, options);

if (typeof url !== 'string') {
return Promise.reject(new TypeError(`Expected \`url\` to be a \`string\`, got \`${typeof url}\``));
}

if (opts.transform && typeof opts.transform !== 'function') {
return Promise.reject(new TypeError(`Expected \`transform\` to be a \`function\`, got \`${typeof opts.transform}\``));
if (options.transform && typeof options.transform !== 'function') {
return Promise.reject(new TypeError(`Expected \`transform\` to be a \`function\`, got \`${typeof options.transform}\``));
}

const rawKey = url + JSON.stringify(opts);
const rawKey = url + JSON.stringify(options);
const key = rawKey.replace(/\./g, '\\.');
const cachedResponse = alfy.cache.get(key, {ignoreMaxAge: true});

if (cachedResponse && !alfy.cache.isExpired(key)) {
return Promise.resolve(cachedResponse);
}

return got(url, opts)
.then(res => opts.transform ? opts.transform(res.body) : res.body)
return got(url, options)
.then(response => options.transform ? options.transform(response.body) : response.body)
.then(data => {
if (opts.maxAge) {
alfy.cache.set(key, data, {maxAge: opts.maxAge});
if (options.maxAge) {
alfy.cache.set(key, data, {maxAge: options.maxAge});
}

return data;
})
.catch(err => {
.catch(error => {
if (cachedResponse) {
return cachedResponse;
}

throw err;
throw error;
});
};

Expand Down
7 changes: 2 additions & 5 deletions init.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/usr/bin/env node
'use strict';
const execa = require('execa');
const npmRunPath = require('npm-run-path');

const env = npmRunPath.env({cwd: __dirname});

execa('alfred-link', {env}).catch(err => {
console.error(err);
execa('alfred-link', {localDir: __dirname}).catch(error => {
console.error(error);
process.exit(1);
});
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,20 @@
"alfred-link": "^0.3.0",
"alfred-notifier": "^0.2.0",
"cache-conf": "^0.6.0",
"clean-stack": "^1.0.0",
"conf": "^1.1.2",
"clean-stack": "^2.0.0",
"conf": "^2.0.0",
"dot-prop": "^4.0.0",
"execa": "^0.10.0",
"execa": "^1.0.0",
"got": "^8.0.1",
"hook-std": "^0.4.0",
"hook-std": "^1.1.0",
"loud-rejection": "^1.6.0",
"npm-run-path": "^2.0.2",
"read-pkg-up": "^3.0.0"
"read-pkg-up": "^4.0.0"
},
"devDependencies": {
"ava": "*",
"delay": "^2.0.0",
"nock": "^9.0.2",
"ava": "^0.25.0",
"delay": "^4.1.0",
"nock": "^10.0.2",
"tempfile": "^2.0.0",
"xo": "*"
"xo": "^0.23.0"
}
}
4 changes: 1 addition & 3 deletions test/_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
const path = require('path');
const tempfile = require('tempfile');

exports.alfy = options => {
options = options || {};

exports.alfy = (options = {}) => {
delete require.cache[path.resolve(__dirname, '../index.js')];

process.env.alfred_workflow_cache = options.cache || tempfile();
Expand Down
6 changes: 3 additions & 3 deletions test/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ test('transform not a function', async t => {
test('transform', async t => {
const m = alfy();
const result = await m.fetch(`${URL}/no-cache`, {
transform: res => {
res.unicorn = 'rainbow';
return res;
transform: response => {
response.unicorn = 'rainbow';
return response;
}
});

Expand Down
9 changes: 5 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ test('default', t => {
t.is(typeof m.icon.error, 'string');
});

test.serial.cb('.error()', t => {
const unhook = hookStd.stdout({silent: true}, output => {
unhook();
test.serial('.error()', async t => {
const promise = hookStd.stdout(output => {
promise.unhook();
t.is(JSON.parse(output).items[0].title, 'Error: foo');
t.end();
});

m.error(new Error('foo'));

await promise;
});

test('.matches()', t => {
Expand Down

0 comments on commit a578078

Please sign in to comment.