From 2456f60aeb6d766795208281a0cde2ada414d214 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:28:37 -0700 Subject: [PATCH 1/3] chore: remove esm package --- package.json | 3 +- packages/cluster/index.d.cts | 15 ++++ packages/cluster/index.d.mts | 7 -- packages/cluster/index.d.ts | 14 +--- packages/cluster/package.json | 15 ++-- packages/compression/index.d.cts | 41 ++++++++++ packages/compression/index.d.mts | 37 --------- packages/compression/index.d.ts | 70 ++++++++--------- packages/compression/package.json | 15 ++-- packages/compression/test/index.js | 9 ++- packages/compression/test/util/index.mjs | 58 ++++++++++++++ packages/parse/package.json | 9 ++- packages/polka/index.d.cts | 70 +++++++++++++++++ packages/polka/index.d.mts | 66 ---------------- packages/polka/index.d.ts | 98 ++++++++++++------------ packages/polka/package.json | 15 ++-- packages/polka/test/index.js | 4 +- packages/redirect/index.d.cts | 5 ++ packages/redirect/index.d.mts | 2 - packages/redirect/index.d.ts | 5 +- packages/redirect/package.json | 15 ++-- packages/redirect/test/index.js | 2 +- packages/send/index.d.cts | 14 ++++ packages/send/index.d.mts | 3 - packages/send/index.d.ts | 15 +--- packages/send/package.json | 15 ++-- packages/send/test/index.js | 11 ++- packages/url/package.json | 9 ++- packages/url/test/index.js | 2 +- 29 files changed, 358 insertions(+), 286 deletions(-) create mode 100644 packages/cluster/index.d.cts delete mode 100644 packages/cluster/index.d.mts create mode 100644 packages/compression/index.d.cts delete mode 100644 packages/compression/index.d.mts create mode 100644 packages/compression/test/util/index.mjs create mode 100644 packages/polka/index.d.cts delete mode 100644 packages/polka/index.d.mts create mode 100644 packages/redirect/index.d.cts delete mode 100644 packages/redirect/index.d.mts create mode 100644 packages/send/index.d.cts delete mode 100644 packages/send/index.d.mts diff --git a/package.json b/package.json index cd75a5e..e6f8b2b 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,11 @@ }, "scripts": { "build": "bun run scripts/build.ts", - "test": "uvu -r esm -i util -i bench packages test" + "test": "uvu -i util -i bench packages test" }, "devDependencies": { "bump": "1.0.0-next.1", "bundt": "1.1.2", - "esm": "3.2.25", "httpie": "1.1.2", "uvu": "0.5.1" }, diff --git a/packages/cluster/index.d.cts b/packages/cluster/index.d.cts new file mode 100644 index 0000000..2ed1290 --- /dev/null +++ b/packages/cluster/index.d.cts @@ -0,0 +1,15 @@ +import type { RequestListener } from 'http'; + +declare namespace cluster { + export interface ClusterController { + listen(port: number): void; + } +} + +declare function cluster( + app: RequestListener | { + listen: Function + } +): cluster.ClusterController; + +export = cluster; diff --git a/packages/cluster/index.d.mts b/packages/cluster/index.d.mts deleted file mode 100644 index 520a15e..0000000 --- a/packages/cluster/index.d.mts +++ /dev/null @@ -1,7 +0,0 @@ -import type { RequestListener } from 'http'; - -export interface ClusterController { - listen(port: number): void; -} - -export default function (app: RequestListener | { listen: Function }): ClusterController; diff --git a/packages/cluster/index.d.ts b/packages/cluster/index.d.ts index 2ed1290..520a15e 100644 --- a/packages/cluster/index.d.ts +++ b/packages/cluster/index.d.ts @@ -1,15 +1,7 @@ import type { RequestListener } from 'http'; -declare namespace cluster { - export interface ClusterController { - listen(port: number): void; - } +export interface ClusterController { + listen(port: number): void; } -declare function cluster( - app: RequestListener | { - listen: Function - } -): cluster.ClusterController; - -export = cluster; +export default function (app: RequestListener | { listen: Function }): ClusterController; diff --git a/packages/cluster/package.json b/packages/cluster/package.json index a4cd9ba..0ac6330 100644 --- a/packages/cluster/package.json +++ b/packages/cluster/package.json @@ -3,19 +3,20 @@ "name": "@polka/cluster", "repository": "lukeed/polka", "description": "Intialize and run a HTTP cluster", - "module": "build.mjs", - "types": "index.d.ts", - "main": "build.js", + "type": "module", + "module": "build.js", + "types": "index.d.cts", + "main": "build.cjs", "license": "MIT", "exports": { ".": { "import": { - "types": "./index.d.mts", - "default": "./build.mjs" - }, - "require": { "types": "./index.d.ts", "default": "./build.js" + }, + "require": { + "types": "./index.d.cts", + "default": "./build.cjs" } }, "./package.json": "./package.json" diff --git a/packages/compression/index.d.cts b/packages/compression/index.d.cts new file mode 100644 index 0000000..a48a4f7 --- /dev/null +++ b/packages/compression/index.d.cts @@ -0,0 +1,41 @@ +import type { IncomingMessage, ServerResponse } from 'node:http'; + +declare namespace compression { + export type Options = { + /** + * Don't compress responses below this size (in bytes). + * @default 1024 + */ + threshold?: number; + /** + * Gzip/Brotli compression effort (1-11, or -1 for default) + * @default -1 + */ + level?: number; + /** + * Generate and serve Brotli-compressed responses. + * @default false + */ + brotli?: boolean; + /** + * Generate and serve Gzip-compressed responses. + * @default true + */ + gzip?: boolean; + /** + * Regular expression of response MIME types to compress. + * @default /text|javascript|\/json|xml/i + */ + mimes?: RegExp; + }; + + export type Middleware = ( + request: Pick, + response: ServerResponse, + next?: (error?: Error | string) => any, + ) => void; +} + +declare function compression(options?: compression.Options): compression.Middleware; + +export = compression; diff --git a/packages/compression/index.d.mts b/packages/compression/index.d.mts deleted file mode 100644 index c69edcb..0000000 --- a/packages/compression/index.d.mts +++ /dev/null @@ -1,37 +0,0 @@ -import type { IncomingMessage, ServerResponse } from 'node:http'; - -export type Options = { - /** - * Don't compress responses below this size (in bytes). - * @default 1024 - */ - threshold?: number; - /** - * Gzip/Brotli compression effort (1-11, or -1 for default) - * @default -1 - */ - level?: number; - /** - * Generate and serve Brotli-compressed responses. - * @default false - */ - brotli?: boolean; - /** - * Generate and serve Gzip-compressed responses. - * @default true - */ - gzip?: boolean; - /** - * Regular expression of response MIME types to compress. - * @default /text|javascript|\/json|xml/i - */ - mimes?: RegExp; -}; - -export type Middleware = ( - request: Pick, - response: ServerResponse, - next?: (error?: Error | string) => any, -) => void; - -export default function (options?: Options): Middleware; diff --git a/packages/compression/index.d.ts b/packages/compression/index.d.ts index a48a4f7..c69edcb 100644 --- a/packages/compression/index.d.ts +++ b/packages/compression/index.d.ts @@ -1,41 +1,37 @@ import type { IncomingMessage, ServerResponse } from 'node:http'; -declare namespace compression { - export type Options = { - /** - * Don't compress responses below this size (in bytes). - * @default 1024 - */ - threshold?: number; - /** - * Gzip/Brotli compression effort (1-11, or -1 for default) - * @default -1 - */ - level?: number; - /** - * Generate and serve Brotli-compressed responses. - * @default false - */ - brotli?: boolean; - /** - * Generate and serve Gzip-compressed responses. - * @default true - */ - gzip?: boolean; - /** - * Regular expression of response MIME types to compress. - * @default /text|javascript|\/json|xml/i - */ - mimes?: RegExp; - }; +export type Options = { + /** + * Don't compress responses below this size (in bytes). + * @default 1024 + */ + threshold?: number; + /** + * Gzip/Brotli compression effort (1-11, or -1 for default) + * @default -1 + */ + level?: number; + /** + * Generate and serve Brotli-compressed responses. + * @default false + */ + brotli?: boolean; + /** + * Generate and serve Gzip-compressed responses. + * @default true + */ + gzip?: boolean; + /** + * Regular expression of response MIME types to compress. + * @default /text|javascript|\/json|xml/i + */ + mimes?: RegExp; +}; - export type Middleware = ( - request: Pick, - response: ServerResponse, - next?: (error?: Error | string) => any, - ) => void; -} +export type Middleware = ( + request: Pick, + response: ServerResponse, + next?: (error?: Error | string) => any, +) => void; -declare function compression(options?: compression.Options): compression.Middleware; - -export = compression; +export default function (options?: Options): Middleware; diff --git a/packages/compression/package.json b/packages/compression/package.json index 9e342e2..e34b01c 100644 --- a/packages/compression/package.json +++ b/packages/compression/package.json @@ -4,19 +4,20 @@ "repository": "lukeed/polka", "description": "Fast gzip+brotli compression middleware for polka & express with zero dependencies.", "homepage": "https://github.com/lukeed/polka/tree/next/packages/compression", - "module": "build.mjs", - "types": "index.d.ts", - "main": "build.js", + "type": "module", + "module": "build.js", + "types": "index.d.cts", + "main": "build.cjs", "license": "MIT", "exports": { ".": { "import": { - "types": "./index.d.mts", - "default": "./build.mjs" - }, - "require": { "types": "./index.d.ts", "default": "./build.js" + }, + "require": { + "types": "./index.d.cts", + "default": "./build.cjs" } }, "./package.json": "./package.json" diff --git a/packages/compression/test/index.js b/packages/compression/test/index.js index e430605..932f797 100644 --- a/packages/compression/test/index.js +++ b/packages/compression/test/index.js @@ -2,11 +2,14 @@ import { suite } from 'uvu'; import * as assert from 'uvu/assert'; import fs from 'fs'; +import { dirname, join } from 'path'; +import { fileURLToPath } from 'url'; import * as zlib from 'zlib'; -import { join } from 'path'; -import { prepare, toAscii } from './util/index'; -import compression from '../index'; +import { prepare, toAscii } from './util/index.js'; +import compression from '../index.js'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); const GZIP = 'gzip, deflate'; const BR = 'br, gzip, deflate'; diff --git a/packages/compression/test/util/index.mjs b/packages/compression/test/util/index.mjs new file mode 100644 index 0000000..32e7d66 --- /dev/null +++ b/packages/compression/test/util/index.mjs @@ -0,0 +1,58 @@ +import { IncomingMessage, ServerResponse } from 'http'; + +// IncomingMessage +class Request { + constructor(method = 'GET', headers = {}) { + this.method = method.toUpperCase(); + this.headers = {}; + for (let i in headers) { + this.headers[i.toLowerCase()] = headers[i]; + } + } +} + +class Response extends ServerResponse { + constructor(req) { + super(req); + this._chunks = []; + this.done = new Promise(r => this._done = r); + } + write(chunk, enc, cb) { + if (!Buffer.isBuffer(chunk)) chunk = Buffer.from(chunk, enc); + this._chunks.push(chunk); + if (cb) cb(null); + return true; + } + end(chunk, enc, cb) { + if (chunk) this.write(chunk, enc); + if (cb) cb(); + this._done(Buffer.concat(this._chunks)); + return this; + } + getResponseData() { + return this.done; + } + async getResponseText() { + return (await this.done).toString(); + } +} + +/** + * @param {string} method + * @param {string} encoding + * @returns {{ req: IncomingMessage, res: Response }} + */ +export function prepare(method, encoding) { + let req = new Request(method, { + 'Accept-Encoding': encoding, + }); + let res = new Response(req); + // @ts-expect-error + return { req, res }; +} + +export function toAscii(thing) { + return JSON.stringify( + Buffer.from(thing).toString('ascii') + ).replace(/(^"|"$)/g,''); +} diff --git a/packages/parse/package.json b/packages/parse/package.json index bee9eb0..3b3757a 100644 --- a/packages/parse/package.json +++ b/packages/parse/package.json @@ -3,19 +3,20 @@ "name": "@polka/parse", "repository": "lukeed/polka", "description": "WIP", - "module": "build.mjs", + "type": "module", + "module": "build.js", "types": "index.d.ts", - "main": "build.js", + "main": "build.cjs", "license": "MIT", "exports": { ".": { "import": { "types": "./index.d.ts", - "default": "./build.mjs" + "default": "./build.js" }, "require": { "types": "./index.d.ts", - "default": "./build.js" + "default": "./build.cjs" } }, "./package.json": "./package.json" diff --git a/packages/polka/index.d.cts b/packages/polka/index.d.cts new file mode 100644 index 0000000..d945760 --- /dev/null +++ b/packages/polka/index.d.cts @@ -0,0 +1,70 @@ +import type { IncomingMessage, ServerResponse } from 'http'; +import type { ListenOptions, Server } from 'net'; +import type { ParsedURL } from '@polka/url'; +import type { Trouter } from 'trouter'; + +type Promisable = Promise | T; +type ListenCallback = () => Promisable; + +declare namespace polka { + export interface IError extends Error { + code?: number; + status?: number; + details?: any; + } + + export type NextHandler = (err?: string | IError) => Promisable; + export type ErrorHandler = (err: string | IError, req: T, res: Response, next: NextHandler) => Promisable; + export type Middleware = (req: T & Request, res: Response, next: NextHandler) => Promisable; + + export interface IOptions { + server?: Server; + onNoMatch?: Middleware; + onError?: ErrorHandler; + } + + export type Response = ServerResponse; + + export interface Request extends IncomingMessage { + url: string; + method: string; + originalUrl: string; + params: Record; + path: string; + search: string; + query: Record; + body?: any; + _decoded?: true; + _parsedUrl: ParsedURL; + } + + export interface Polka extends Trouter> { + readonly server: Server; + readonly wares: Middleware[]; + + readonly onError: ErrorHandler; + readonly onNoMatch: Middleware; + + readonly handler: Middleware; + parse: (req: IncomingMessage) => ParsedURL; + + use(pattern: RegExp|string, ...handlers: (Polka | Middleware)[]): this; + use(...handlers: (Polka | Middleware)[]): this; + + listen(port?: number, hostname?: string, backlog?: number, callback?: ListenCallback): this; + listen(port?: number, hostname?: string, callback?: ListenCallback): this; + listen(port?: number, backlog?: number, callback?: ListenCallback): this; + listen(port?: number, callback?: ListenCallback): this; + listen(path: string, backlog?: number, callback?: ListenCallback): this; + listen(path: string, callback?: ListenCallback): this; + listen(options: ListenOptions, callback?: ListenCallback): this; + listen(handle: any, backlog?: number, callback?: ListenCallback): this; + listen(handle: any, callback?: ListenCallback): this; + } +} + +declare function polka( + options?: polka.IOptions +): polka.Polka; + +export = polka; diff --git a/packages/polka/index.d.mts b/packages/polka/index.d.mts deleted file mode 100644 index 7375e44..0000000 --- a/packages/polka/index.d.mts +++ /dev/null @@ -1,66 +0,0 @@ -import type { IncomingMessage, ServerResponse } from 'http'; -import type { ListenOptions, Server } from 'net'; -import type { ParsedURL } from '@polka/url'; -import type { Trouter } from 'trouter'; - -type Promisable = Promise | T; -type ListenCallback = () => Promisable; - -export interface IError extends Error { - code?: number; - status?: number; - details?: any; -} - -export type NextHandler = (err?: string | IError) => Promisable; -export type ErrorHandler = (err: string | IError, req: T, res: Response, next: NextHandler) => Promisable; -export type Middleware = (req: T & Request, res: Response, next: NextHandler) => Promisable; - -export interface IOptions { - server?: Server; - onNoMatch?: Middleware; - onError?: ErrorHandler; -} - -export type Response = ServerResponse; - -export interface Request extends IncomingMessage { - url: string; - method: string; - originalUrl: string; - params: Record; - path: string; - search: string; - query: Record; - body?: any; - _decoded?: true; - _parsedUrl: ParsedURL; -} - -export interface Polka extends Trouter> { - readonly server: Server; - readonly wares: Middleware[]; - - readonly onError: ErrorHandler; - readonly onNoMatch: Middleware; - - readonly handler: Middleware; - parse: (req: IncomingMessage) => ParsedURL; - - use(pattern: RegExp|string, ...handlers: (Polka | Middleware)[]): this; - use(...handlers: (Polka | Middleware)[]): this; - - listen(port?: number, hostname?: string, backlog?: number, callback?: ListenCallback): this; - listen(port?: number, hostname?: string, callback?: ListenCallback): this; - listen(port?: number, backlog?: number, callback?: ListenCallback): this; - listen(port?: number, callback?: ListenCallback): this; - listen(path: string, backlog?: number, callback?: ListenCallback): this; - listen(path: string, callback?: ListenCallback): this; - listen(options: ListenOptions, callback?: ListenCallback): this; - listen(handle: any, backlog?: number, callback?: ListenCallback): this; - listen(handle: any, callback?: ListenCallback): this; -} - -export default function( - options?: IOptions -): Polka; diff --git a/packages/polka/index.d.ts b/packages/polka/index.d.ts index d945760..7375e44 100644 --- a/packages/polka/index.d.ts +++ b/packages/polka/index.d.ts @@ -6,65 +6,61 @@ import type { Trouter } from 'trouter'; type Promisable = Promise | T; type ListenCallback = () => Promisable; -declare namespace polka { - export interface IError extends Error { - code?: number; - status?: number; - details?: any; - } +export interface IError extends Error { + code?: number; + status?: number; + details?: any; +} - export type NextHandler = (err?: string | IError) => Promisable; - export type ErrorHandler = (err: string | IError, req: T, res: Response, next: NextHandler) => Promisable; - export type Middleware = (req: T & Request, res: Response, next: NextHandler) => Promisable; +export type NextHandler = (err?: string | IError) => Promisable; +export type ErrorHandler = (err: string | IError, req: T, res: Response, next: NextHandler) => Promisable; +export type Middleware = (req: T & Request, res: Response, next: NextHandler) => Promisable; - export interface IOptions { - server?: Server; - onNoMatch?: Middleware; - onError?: ErrorHandler; - } +export interface IOptions { + server?: Server; + onNoMatch?: Middleware; + onError?: ErrorHandler; +} - export type Response = ServerResponse; +export type Response = ServerResponse; - export interface Request extends IncomingMessage { - url: string; - method: string; - originalUrl: string; - params: Record; - path: string; - search: string; - query: Record; - body?: any; - _decoded?: true; - _parsedUrl: ParsedURL; - } +export interface Request extends IncomingMessage { + url: string; + method: string; + originalUrl: string; + params: Record; + path: string; + search: string; + query: Record; + body?: any; + _decoded?: true; + _parsedUrl: ParsedURL; +} - export interface Polka extends Trouter> { - readonly server: Server; - readonly wares: Middleware[]; +export interface Polka extends Trouter> { + readonly server: Server; + readonly wares: Middleware[]; - readonly onError: ErrorHandler; - readonly onNoMatch: Middleware; + readonly onError: ErrorHandler; + readonly onNoMatch: Middleware; - readonly handler: Middleware; - parse: (req: IncomingMessage) => ParsedURL; + readonly handler: Middleware; + parse: (req: IncomingMessage) => ParsedURL; - use(pattern: RegExp|string, ...handlers: (Polka | Middleware)[]): this; - use(...handlers: (Polka | Middleware)[]): this; + use(pattern: RegExp|string, ...handlers: (Polka | Middleware)[]): this; + use(...handlers: (Polka | Middleware)[]): this; - listen(port?: number, hostname?: string, backlog?: number, callback?: ListenCallback): this; - listen(port?: number, hostname?: string, callback?: ListenCallback): this; - listen(port?: number, backlog?: number, callback?: ListenCallback): this; - listen(port?: number, callback?: ListenCallback): this; - listen(path: string, backlog?: number, callback?: ListenCallback): this; - listen(path: string, callback?: ListenCallback): this; - listen(options: ListenOptions, callback?: ListenCallback): this; - listen(handle: any, backlog?: number, callback?: ListenCallback): this; - listen(handle: any, callback?: ListenCallback): this; - } + listen(port?: number, hostname?: string, backlog?: number, callback?: ListenCallback): this; + listen(port?: number, hostname?: string, callback?: ListenCallback): this; + listen(port?: number, backlog?: number, callback?: ListenCallback): this; + listen(port?: number, callback?: ListenCallback): this; + listen(path: string, backlog?: number, callback?: ListenCallback): this; + listen(path: string, callback?: ListenCallback): this; + listen(options: ListenOptions, callback?: ListenCallback): this; + listen(handle: any, backlog?: number, callback?: ListenCallback): this; + listen(handle: any, callback?: ListenCallback): this; } -declare function polka( - options?: polka.IOptions -): polka.Polka; - -export = polka; +export default function( + options?: IOptions +): Polka; diff --git a/packages/polka/package.json b/packages/polka/package.json index 51ef678..8e02f7a 100644 --- a/packages/polka/package.json +++ b/packages/polka/package.json @@ -3,19 +3,20 @@ "version": "1.0.0-next.25", "repository": "lukeed/polka", "description": "A micro web server so fast, it'll make you dance! :dancers:", - "module": "build.mjs", - "types": "index.d.ts", - "main": "build.js", + "type": "module", + "module": "build.js", + "types": "index.d.cts", + "main": "build.cjs", "license": "MIT", "exports": { ".": { "import": { - "types": "./index.d.mts", - "default": "./build.mjs" - }, - "require": { "types": "./index.d.ts", "default": "./build.js" + }, + "require": { + "types": "./index.d.cts", + "default": "./build.cjs" } }, "./package.json": "./package.json" diff --git a/packages/polka/test/index.js b/packages/polka/test/index.js index db890ec..d0f15ab 100644 --- a/packages/polka/test/index.js +++ b/packages/polka/test/index.js @@ -3,8 +3,8 @@ import http from 'http'; import { test } from 'uvu'; import * as assert from 'uvu/assert'; import { get, send, post } from 'httpie'; -import polka from '../index'; -import * as $ from './util'; +import polka from '../index.js'; +import * as $ from './util/index.js'; const hasNamedGroups = 'groups' in /x/.exec('x'); const sleep = ms => new Promise(r => setTimeout(r, ms)); diff --git a/packages/redirect/index.d.cts b/packages/redirect/index.d.cts new file mode 100644 index 0000000..81ad8a1 --- /dev/null +++ b/packages/redirect/index.d.cts @@ -0,0 +1,5 @@ +import type { ServerResponse } from 'http'; + +declare function redirect(res: ServerResponse, code?: number, location?: string): void; + +export = redirect; diff --git a/packages/redirect/index.d.mts b/packages/redirect/index.d.mts deleted file mode 100644 index a044616..0000000 --- a/packages/redirect/index.d.mts +++ /dev/null @@ -1,2 +0,0 @@ -import type { ServerResponse } from 'http'; -export default function (res: ServerResponse, code?: number, location?: string): void; diff --git a/packages/redirect/index.d.ts b/packages/redirect/index.d.ts index 81ad8a1..a044616 100644 --- a/packages/redirect/index.d.ts +++ b/packages/redirect/index.d.ts @@ -1,5 +1,2 @@ import type { ServerResponse } from 'http'; - -declare function redirect(res: ServerResponse, code?: number, location?: string): void; - -export = redirect; +export default function (res: ServerResponse, code?: number, location?: string): void; diff --git a/packages/redirect/package.json b/packages/redirect/package.json index f745666..1ee015b 100644 --- a/packages/redirect/package.json +++ b/packages/redirect/package.json @@ -3,19 +3,20 @@ "name": "@polka/redirect", "repository": "lukeed/polka", "description": "A response helper for URL redirects", - "module": "build.mjs", - "types": "index.d.ts", - "main": "build.js", + "type": "module", + "module": "build.js", + "types": "index.d.cts", + "main": "build.cjs", "license": "MIT", "exports": { ".": { "import": { - "types": "./index.d.mts", - "default": "./build.mjs" - }, - "require": { "types": "./index.d.ts", "default": "./build.js" + }, + "require": { + "types": "./index.d.cts", + "default": "./build.cjs" } }, "./package.json": "./package.json" diff --git a/packages/redirect/test/index.js b/packages/redirect/test/index.js index 9328207..811d294 100644 --- a/packages/redirect/test/index.js +++ b/packages/redirect/test/index.js @@ -1,6 +1,6 @@ import { test } from 'uvu'; import * as assert from 'uvu/assert'; -import fn from '../index'; +import fn from '../index.js'; function isRedirect(arr, code=302) { let [starting, next, result] = arr; diff --git a/packages/send/index.d.cts b/packages/send/index.d.cts new file mode 100644 index 0000000..20dde6d --- /dev/null +++ b/packages/send/index.d.cts @@ -0,0 +1,14 @@ +import type { ServerResponse } from 'http'; + +declare namespace send { + export type OutgoingHeaders = Record; +} + +declare function send( + res: ServerResponse, + status?: number, + data?: any, + headers?: send.OutgoingHeaders +): void; + +export = send; diff --git a/packages/send/index.d.mts b/packages/send/index.d.mts deleted file mode 100644 index 6d73313..0000000 --- a/packages/send/index.d.mts +++ /dev/null @@ -1,3 +0,0 @@ -import type { ServerResponse } from 'http'; -export type OutgoingHeaders = Record; -export default function (res: ServerResponse, status?: number, data?: any, headers?: OutgoingHeaders): void; diff --git a/packages/send/index.d.ts b/packages/send/index.d.ts index 20dde6d..6d73313 100644 --- a/packages/send/index.d.ts +++ b/packages/send/index.d.ts @@ -1,14 +1,3 @@ import type { ServerResponse } from 'http'; - -declare namespace send { - export type OutgoingHeaders = Record; -} - -declare function send( - res: ServerResponse, - status?: number, - data?: any, - headers?: send.OutgoingHeaders -): void; - -export = send; +export type OutgoingHeaders = Record; +export default function (res: ServerResponse, status?: number, data?: any, headers?: OutgoingHeaders): void; diff --git a/packages/send/package.json b/packages/send/package.json index 4ccb15c..acaad0a 100644 --- a/packages/send/package.json +++ b/packages/send/package.json @@ -3,19 +3,20 @@ "name": "@polka/send", "repository": "lukeed/polka", "description": "A response helper that detects & handles Content-Types", - "module": "build.mjs", - "types": "index.d.ts", - "main": "build.js", + "type": "module", + "module": "build.js", + "types": "index.d.cts", + "main": "build.cjs", "license": "MIT", "exports": { ".": { "import": { - "types": "./index.d.mts", - "default": "./build.mjs" - }, - "require": { "types": "./index.d.ts", "default": "./build.js" + }, + "require": { + "types": "./index.d.cts", + "default": "./build.cjs" } }, "./package.json": "./package.json" diff --git a/packages/send/test/index.js b/packages/send/test/index.js index c16ed79..5d4b4e2 100644 --- a/packages/send/test/index.js +++ b/packages/send/test/index.js @@ -1,12 +1,17 @@ import fs from 'fs'; +import { createRequire } from 'module'; +import { dirname, join } from 'path'; +import { fileURLToPath } from 'url'; import { suite } from 'uvu'; -import { join } from 'path'; import * as assert from 'uvu/assert'; -import { Response, toStatusText } from './util'; -import send from '../index'; +import { Response, toStatusText } from './util/index.js'; +import send from '../index.js'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); const TYPE = 'Content-Type'; const LENGTH = 'Content-Length'; +const require = createRequire(import.meta.url); const INPUT = require.resolve('../'); const basics = suite('basics'); diff --git a/packages/url/package.json b/packages/url/package.json index bd673c1..14070f0 100644 --- a/packages/url/package.json +++ b/packages/url/package.json @@ -3,15 +3,16 @@ "name": "@polka/url", "repository": "lukeed/polka", "description": "Super fast, memoized `req.url` parser", - "module": "build.mjs", + "type": "module", + "module": "build.js", "types": "index.d.ts", - "main": "build.js", + "main": "build.cjs", "license": "MIT", "exports": { ".": { "types": "./index.d.ts", - "import": "./build.mjs", - "require": "./build.js" + "import": "./build.js", + "require": "./build.cjs" }, "./package.json": "./package.json" }, diff --git a/packages/url/test/index.js b/packages/url/test/index.js index 81eebde..ff23877 100644 --- a/packages/url/test/index.js +++ b/packages/url/test/index.js @@ -1,6 +1,6 @@ import { test } from 'uvu'; import * as assert from 'uvu/assert'; -import { parse } from '../index'; +import { parse } from '../index.js'; /** * @param {string} url From 1015453230e84ad949c71380bc9939512cdfa0c1 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:37:48 -0700 Subject: [PATCH 2/3] build --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d21ae68..49f2003 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,6 +47,9 @@ jobs: if: matrix.nodejs >= 18 run: oxlint . + - name: Build + run: npm run build + - name: Test if: matrix.nodejs < 18 run: npm test From c2ea20e20d10338d84c09915ac47a37c84597169 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:40:18 -0700 Subject: [PATCH 3/3] drop node 10 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 49f2003..c881939 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - nodejs: [10, 12, 14, 16, 18] + nodejs: [12, 14, 16, 18] steps: - uses: actions/checkout@v4