Skip to content

Commit

Permalink
Require Node.js 18
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 4, 2023
1 parent 1da2609 commit 277214c
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 76 deletions.
20 changes: 9 additions & 11 deletions cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import {execa} from 'execa';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

(async () => {
try {
await execa('alfred-unlink', {
preferLocal: true,
localDir: __dirname,
});
} catch (error) {
console.error(error);
process.exit(1);
}
})();
try {
await execa('alfred-unlink', {
preferLocal: true,
localDir: __dirname,
});
} catch (error) {
console.error(error);
process.exit(1);
}
54 changes: 27 additions & 27 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Conf from 'conf';
import {Options} from 'got';
import type Conf from 'conf';
import {type Options} from 'got';

export interface FetchOptions extends Partial<Options> {
export type FetchOptions = {
/**
Number of milliseconds this request should be cached.
*/
Expand All @@ -11,33 +11,33 @@ export interface FetchOptions extends Partial<Options> {
Transform the response before it gets cached.
*/
readonly transform?: (body: unknown) => unknown;
}
} & Partial<Options>;

export interface OutputOptions {
export type OutputOptions = {
/**
A script can be set to re-run automatically after some interval.
The script will only be re-run if the script filter is still active and the user hasn't changed the state of the filter by typing and triggering a re-run. For example, it could be used to update the progress of a particular task:
*/
readonly rerunInterval?: number;
}
};

export interface CacheConfGetOptions {
export type CacheConfGetOptions = {
/**
Get the item for the key provided without taking the `maxAge` of the item into account.
*/
readonly ignoreMaxAge?: boolean;
}
};

export interface CacheConfSetOptions {
export type CacheConfSetOptions = {
/**
Number of milliseconds the cached value is valid.
*/
readonly maxAge?: number;
}
};

export interface CacheConf<T> extends Conf<T> {
isExpired: (key: T) => boolean;
export type CacheConf<T extends Record<string, any> = Record<string, unknown>> = {
isExpired: (key: keyof T) => boolean;

get<Key extends keyof T>(key: Key, options?: CacheConfGetOptions): T[Key];
get<Key extends keyof T>(key: Key, defaultValue: Required<T>[Key], options?: CacheConfGetOptions): Required<T>[Key];
Expand All @@ -48,7 +48,7 @@ export interface CacheConf<T> extends Conf<T> {
set(key: string, value: unknown, options: CacheConfSetOptions): void;
set(object: Partial<T>, options: CacheConfSetOptions): void;
set<Key extends keyof T>(key: Partial<T> | Key | string, value?: T[Key] | unknown, options?: CacheConfSetOptions): void;
}
} & Conf<T>;

/**
The icon displayed in the result row. Workflows are run from their workflow folder, so you can reference icons stored in your workflow relatively.
Expand All @@ -59,17 +59,17 @@ By using `{type: 'fileicon}`, Alfred will get the icon for the specified path.
Finally, by using `{type: 'filetype'}`, you can get the icon of a specific file. For example, `{path: 'public.png'}`.
*/
export interface IconElement {
export type IconElement = {
readonly path?: string;
readonly type?: 'fileicon' | 'filetype';
}
};

/**
The text element defines the text the user will get when copying the selected result row with `⌘C` or displaying large type with `⌘L`.
If these are not defined, you will inherit Alfred's standard behaviour where the argument is copied to the Clipboard or used for Large Type.
*/
export interface TextElement {
export type TextElement = {
/**
User will get when copying the selected result row with `⌘C`.
*/
Expand All @@ -79,28 +79,28 @@ export interface TextElement {
User will get displaying large type with `⌘L`.
*/
readonly largetype?: string;
}
};

/**
Defines what to change when the modifier key is pressed.
When you release the modifier key, it returns to the original item.
*/
export interface ModifierKeyItem {
export type ModifierKeyItem = {
readonly valid?: boolean;
readonly title?: string;
readonly subtitle?: string;
readonly arg?: string;
readonly icon?: string;
readonly variables?: Record<string, string>;
}
};

/**
This element defines the Universal Action items used when actioning the result, and overrides arg being used for actioning.
The action key can take a string or array for simple types, and the content type will automatically be derived by Alfred to file, URL or text.
*/
export interface ActionElement {
export type ActionElement = {
/**
Forward text to Alfred.
*/
Expand All @@ -120,14 +120,14 @@ export interface ActionElement {
Forward some value and let the value type be infered from Alfred.
*/
readonly auto?: string | string[];
}
};

type PossibleModifiers = 'fn' | 'ctrl' | 'opt' | 'cmd' | 'shift';

/**
Each item describes a result row displayed in Alfred.
*/
export interface ScriptFilterItem {
export type ScriptFilterItem = {
/**
This is a unique identifier for the item which allows help Alfred to learn about this item for subsequent sorting and ordering of the user's actioned results.
Expand Down Expand Up @@ -289,7 +289,7 @@ export interface ScriptFilterItem {
Variables can be passed out of the script filter within a variables object.
*/
readonly variables?: Record<string, string>;
}
};

/**
Create Alfred workflows with ease
Expand All @@ -311,7 +311,7 @@ const items = alfy
alfy.output(items);
```
*/
export interface Alfy {
export type Alfy = {
/**
Return output to Alfred.
Expand Down Expand Up @@ -433,7 +433,7 @@ export interface Alfy {
//=> '🦄'
```
*/
config: Conf<Record<string, unknown>>;
config: Conf;

/**
Persist cache data.
Expand All @@ -450,7 +450,7 @@ export interface Alfy {
//=> '🦄'
```
*/
cache: CacheConf<unknown>;
cache: CacheConf;

/**
Get various default system icons.
Expand Down Expand Up @@ -542,7 +542,7 @@ export interface Alfy {
```
*/
userConfig: Map<string, string>;
}
};

declare const alfy: Alfy;

Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import loudRejection from 'loud-rejection';
import cleanStack from 'clean-stack';
import {getProperty} from 'dot-prop';
import AlfredConfig from 'alfred-config';
import updateNotification from './lib/update-notification.js';
import updateNotification from './lib/update-notification.js'; // eslint-disable-line import/order

const require = createRequire(import.meta.url);
const CacheConf = require('cache-conf');
Expand Down Expand Up @@ -100,6 +100,7 @@ ${process.platform} ${os.release()}
};

alfy.config = new Conf({
projectName: 'alfy',
cwd: alfy.alfred.data,
});

Expand Down Expand Up @@ -137,7 +138,7 @@ alfy.fetch = async (url, options) => {
delete options.transform;
delete options.maxAge;

const key = rawKey.replace(/\./g, '\\.');
const key = rawKey.replaceAll('.', '\\.');
const cachedResponse = alfy.cache.get(key, {ignoreMaxAge: true});

if (cachedResponse && !alfy.cache.isExpired(key)) {
Expand Down
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import alfy, {ScriptFilterItem} from './index.js';
import alfy, {type ScriptFilterItem} from './index.js';

const mockItems: ScriptFilterItem[] = [
{
Expand All @@ -25,5 +25,5 @@ expectType<void>(alfy.error(new Error('some error')));
expectType<void>(alfy.log('some message'));

expectType<Promise<unknown>>(alfy.fetch('https://foo.bar', {
transform: body => body,
transform: body => body, // eslint-disable-line @typescript-eslint/no-unsafe-return
}));
31 changes: 14 additions & 17 deletions init.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@ import {execa} from 'execa';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

(async () => {
try {
await execa('alfred-link', {
preferLocal: true,
localDir: __dirname,
});

await execa('alfred-config', {
preferLocal: true,
localDir: __dirname,
stdio: 'inherit',
});
} catch (error) {
console.error(error);
process.exit(1);
}
})();
try {
await execa('alfred-link', {
preferLocal: true,
localDir: __dirname,
});

await execa('alfred-config', {
preferLocal: true,
localDir: __dirname,
stdio: 'inherit',
});
} catch (error) {
console.error(error);
process.exit(1);
}
2 changes: 1 addition & 1 deletion lib/update-notification.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {readPackageUp} from 'read-pkg-up';
import {readPackageUp} from 'read-package-up';
import alfredNotifier from 'alfred-notifier';

export default async function updateNotification() {
Expand Down
37 changes: 22 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
"license": "MIT",
"repository": "sindresorhus/alfy",
"type": "module",
"exports": "./index.js",
"bin": {
"run-node": "./run-node.sh",
"alfy-init": "./init.js",
"alfy-cleanup": "./cleanup.js"
},
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"engines": {
"node": ">=14.13.1"
"node": ">=18"
},
"scripts": {
"test": "xo && ava && tsd"
Expand Down Expand Up @@ -41,22 +44,26 @@
"alfred-link": "^0.3.1",
"alfred-notifier": "^0.2.3",
"cache-conf": "^0.6.0",
"clean-stack": "^4.1.0",
"conf": "^10.1.1",
"dot-prop": "^7.2.0",
"execa": "^6.1.0",
"got": "^12.0.3",
"clean-stack": "^5.2.0",
"conf": "^12.0.0",
"dot-prop": "^8.0.2",
"execa": "^8.0.1",
"got": "^13.0.0",
"hook-std": "^3.0.0",
"loud-rejection": "^2.2.0",
"read-pkg-up": "^9.1.0"
"read-package-up": "^11.0.0"
},
"devDependencies": {
"ava": "^4.1.0",
"delay": "^5.0.0",
"nock": "^13.2.4",
"tempfile": "^4.0.0",
"tsd": "^0.19.1",
"typescript": "^4.6.3",
"xo": "^0.48.0"
"ava": "^5.3.1",
"delay": "^6.0.0",
"nock": "^13.3.8",
"tempfile": "^5.0.0",
"tsd": "^0.29.0",
"xo": "^0.56.0"
},
"tsd": {
"compilerOptions": {
"module": "node16"
}
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

## Prerequisites

You need [Node.js 14+](https://nodejs.org) and [Alfred 4 or later](https://www.alfredapp.com) with the paid [Powerpack](https://www.alfredapp.com/powerpack/) upgrade.
You need [Node.js 18+](https://nodejs.org) and [Alfred 4 or later](https://www.alfredapp.com) with the paid [Powerpack](https://www.alfredapp.com/powerpack/) upgrade.

## Install

Expand Down

0 comments on commit 277214c

Please sign in to comment.