Skip to content

Commit

Permalink
refactor: use types instead of interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ruicsh committed Dec 11, 2023
1 parent bead3f0 commit a4b52b1
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion sh/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function main() {
await $`esbuild src/cjs/index.cjs --outfile=dist/index.cjs ${flags}`;
await $`esbuild src/index.ts --format=esm --outfile=dist/index.mjs ${flags}`;

await $`rm dist/github.js dist/index.js`;
// await $`rm dist/github.js dist/index.js`;
await $`rm -rf dist/helpers`;
}

Expand Down
1 change: 0 additions & 1 deletion src/github.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { type FetchOptions } from "@tuplo/fetch";
import { vi } from "vitest";

import githubIssuesList from "./__data__/github-list-issues.json";
import { buildUrl, createIssue, findIssue, listIssues } from "./github";
Expand Down
17 changes: 10 additions & 7 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@ import { Agent } from "node:https";

import fetch, { type FetchOptions } from "@tuplo/fetch";

export interface IGithubIssue {
export type IGithubIssue = {
id?: number;
title: string;
labels: string[];
body: string;
}
};

export interface IGitHubOptions {
export type IGitHubOptions = {
user: string;
repo: string;
token: string;
labels?: string[];
}
};

export function buildUrl(template: string, githubOptions: IGitHubOptions) {
const { user, repo: repoName } = githubOptions;
const repo = !/\//.test(repoName) ? `${user}/${repoName}` : repoName;

return ["https://api.github.com", template.replace(/:repo/, repo)].join("");
const uri = new URL("https://api.github.com");
uri.pathname = template.replace(/:repo/, repo);

return uri.href;
}

async function client<T = unknown>(
Expand Down Expand Up @@ -72,9 +75,9 @@ export async function listIssues(githubOptions: IGitHubOptions) {
);
}

interface IFinderFn {
type IFinderFn = {
(issue: IGithubIssue): boolean;
}
};

export async function findIssue(
finder: IFinderFn,
Expand Down
2 changes: 0 additions & 2 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { vi } from "vitest";

import { type IGithubIssue, type IGitHubOptions } from "./github";
import { submitError, uncaughtHandlerFn } from "./index";

Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import * as github from "./github";
import { type IGitHubOptions } from "./github";
import { stringify } from "./helpers/stringify";

export interface IUnhandlerError extends Error {
export type IUnhandlerError = Error & {
body?: unknown;
}
};

interface IProviders {
type IProviders = {
github?: IGitHubOptions;
}
};

export interface IUnhandlerOptions {
export type IUnhandlerOptions = {
appName?: string;
onAfterSubmitError?: (error: Error) => void | Promise<void>;
onBeforeSubmitError?: (error: Error) => void | Promise<void>;
providers: IProviders;
shouldSubmitError?: boolean;
}
};

export async function submitError(
error: IUnhandlerError,
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./dist"
"outDir": "./dist",
"types": ["./node_modules/@types/node"]
},
"exclude": ["node_modules/**/*", "**/*.test.ts", "sh/**/*"]
}
3 changes: 2 additions & 1 deletion vitest.config.ts → vitest.config.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineConfig } from "vitest/config";
import path from "node:path";

import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
globals: true,
Expand Down

0 comments on commit a4b52b1

Please sign in to comment.