Skip to content

Commit

Permalink
fix(sirv): separate ESM vs CJS type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Oct 11, 2024
1 parent 912af6f commit 982fcc8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
29 changes: 29 additions & 0 deletions packages/sirv/index.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { Stats } from "node:fs";
import type { IncomingMessage, ServerResponse } from "node:http";

type Arrayable<T> = T | T[];

export type NextHandler = () => void | Promise<void>;

export type RequestHandler = (
req: IncomingMessage,
res: ServerResponse,
next?: NextHandler,
) => void;

export interface Options {
dev?: boolean;
etag?: boolean;
maxAge?: number;
immutable?: boolean;
single?: string | boolean;
ignores?: false | Arrayable<string | RegExp>;
extensions?: string[];
dotfiles?: boolean;
brotli?: boolean;
gzip?: boolean;
onNoMatch?: (req: IncomingMessage, res: ServerResponse) => void;
setHeaders?: (res: ServerResponse, pathname: string, stats: Stats) => void;
}

export default function (dir?: string, opts?: Options): RequestHandler;
20 changes: 14 additions & 6 deletions packages/sirv/sirv.d.ts → packages/sirv/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
declare module 'sirv' {
import type { Stats } from 'fs';
import type { IncomingMessage, ServerResponse } from 'http';
import type { Stats } from "node:fs";
import type { IncomingMessage, ServerResponse } from "node:http";

declare namespace sirv {
type Arrayable<T> = T | T[];

export type NextHandler = () => void | Promise<void>;
export type RequestHandler = (req: IncomingMessage, res: ServerResponse, next?: NextHandler) => void;

export type RequestHandler = (
req: IncomingMessage,
res: ServerResponse,
next?: NextHandler,
) => void;

export interface Options {
dev?: boolean;
Expand All @@ -20,6 +26,8 @@ declare module 'sirv' {
onNoMatch?: (req: IncomingMessage, res: ServerResponse) => void;
setHeaders?: (res: ServerResponse, pathname: string, stats: Stats) => void;
}

export default function(dir?: string, opts?: Options): RequestHandler;
}

declare function sirv(dir?: string, opts?: sirv.Options): sirv.RequestHandler;

export = sirv;
6 changes: 3 additions & 3 deletions packages/sirv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
"license": "MIT",
"files": [
"build.*",
"sirv.d.ts"
"index.d.*"
],
"exports": {
".": {
"import": {
"types": "./sirv.d.ts",
"types": "./index.d.mts",
"default": "./build.mjs"
},
"require": {
"types": "./sirv.d.ts",
"types": "./index.d.ts",
"default": "./build.js"
}
},
Expand Down

0 comments on commit 982fcc8

Please sign in to comment.