Skip to content

Commit

Permalink
feat: fix types and use tsd
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowgate15 committed Apr 30, 2024
1 parent f2dc40d commit 78b1e09
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 226 deletions.
34 changes: 20 additions & 14 deletions .xo-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,34 @@ module.exports = {
'unicorn/prefer-logical-operator-over-ternary': 'warn'
},
overrides: [
{
files: '**/*.mjs',
parserOptions: {
sourceType: 'module'
}
},
{
files: 'test/jobs/*.js',
rules: {
'unicorn/no-process-exit': 'off'
}
},
{
files: ['*.ts', '**/*.ts'],
parserOptions: {
project: 'types/tsconfig.json'
},
files: ['**/*.d.ts'],
rules: {
'no-unused-vars': 'off',
'@typescript-eslint/naming-convention': 'off',
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': 'off'
}
},
{
files: ['**/*.test-d.ts'],
rules: {
'no-redeclare': 'warn',
'no-unused-vars': 'warn',
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-unsafe-call': 'warn',
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/no-empty-function': 'warn',
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/consistent-type-imports': 'off'
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-confusing-void-expression': 'off', // Conflicts with `expectError` assertion.
'@typescript-eslint/no-unsafe-assignment': 'off'
}
}
],
parser: '@typescript-eslint/parser'
]
};
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
"node": ">=12.17.0 <13.0.0-0||>=13.2.0"
},
"files": [
"src",
"types"
"src"
],
"homepage": "https://github.com/breejs/bree",
"keywords": [
Expand Down Expand Up @@ -157,5 +156,5 @@
"test": "npm run ava && tsd",
"test-coverage": "cross-env NODE_ENV=test nyc npm run test"
},
"types": "types"
"types": "src/index.d.ts"
}
16 changes: 8 additions & 8 deletions types/index.d.ts → src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Definitions by: Taylor Schley <https://github.com/shadowgate15>

import { EventEmitter } from 'node:events';
import { WorkerOptions, Worker } from 'node:worker_threads';
import { Timeout, Interval } from 'safe-timers';
import { type WorkerOptions, type Worker } from 'node:worker_threads';
import { type Timeout, type Interval } from 'safe-timers';

export = Bree;

Expand Down Expand Up @@ -68,7 +68,7 @@ declare class Bree extends EventEmitter {
}

declare namespace Bree {
interface Job {
type Job = {
name: string;
path: string | (() => void);
timeout: number | string | boolean;
Expand All @@ -81,11 +81,11 @@ declare namespace Bree {
worker?: Partial<WorkerOptions>;
outputWorkerMetadata?: boolean;
timezone?: string;
}
};

type JobOptions = Required<Pick<Job, 'name'>> & Partial<Omit<Job, 'name'>>;

interface BreeConfigs {
type BreeConfigs = {
logger: BreeLogger | boolean;
root: string | boolean;
silenceRootCheckError: boolean;
Expand All @@ -105,7 +105,7 @@ declare namespace Bree {
errorHandler?: (error: any, workerMetadata: any) => void;
workerMessageHandler?: (message: any, workerMetadata: any) => void;
outputWorkerMetadata: boolean;
}
};

type BreeOptions = Partial<Omit<BreeConfigs, 'jobs'>> & {
jobs?: Array<string | (() => void) | JobOptions>;
Expand All @@ -115,9 +115,9 @@ declare namespace Bree {

function extend<T = unknown>(plugin: PluginFunc<T>, options?: T): Bree;

interface BreeLogger {
type BreeLogger = {
info: (...args: any[]) => any;
warn: (...args: any[]) => any;
error: (...args: any[]) => any;
}
};
}
14 changes: 10 additions & 4 deletions test-d/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { expectType, expectNotType } from 'tsd';
import Bree from '..';
import { expectType } from 'tsd';
import Bree from '../src';

const bree = new Bree({});

expectType<Bree.Constructor>(Bree);
expectType<Bree.Bree>(bree);
expectType<Bree>(bree);

expectType<Bree['start']>(bree.start);
expectType<Bree['stop']>(bree.stop);
expectType<Bree['run']>(bree.run);
expectType<Bree['add']>(bree.add);
expectType<Bree['remove']>(bree.remove);
expectType<Bree['createWorker']>(bree.createWorker);
171 changes: 0 additions & 171 deletions types/tests.ts

This file was deleted.

19 changes: 0 additions & 19 deletions types/tsconfig.json

This file was deleted.

7 changes: 0 additions & 7 deletions types/tslint.json

This file was deleted.

0 comments on commit 78b1e09

Please sign in to comment.