Skip to content

Commit

Permalink
chore: remove esm package
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Sep 3, 2024
1 parent 9656b12 commit 2456f60
Show file tree
Hide file tree
Showing 29 changed files with 358 additions and 286 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
15 changes: 15 additions & 0 deletions packages/cluster/index.d.cts
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 0 additions & 7 deletions packages/cluster/index.d.mts

This file was deleted.

14 changes: 3 additions & 11 deletions packages/cluster/index.d.ts
Original file line number Diff line number Diff line change
@@ -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;
15 changes: 8 additions & 7 deletions packages/cluster/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
41 changes: 41 additions & 0 deletions packages/compression/index.d.cts
Original file line number Diff line number Diff line change
@@ -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<IncomingMessage, 'method' | 'headers'>,
response: ServerResponse,
next?: (error?: Error | string) => any,
) => void;
}

declare function compression(options?: compression.Options): compression.Middleware;

export = compression;
37 changes: 0 additions & 37 deletions packages/compression/index.d.mts

This file was deleted.

70 changes: 33 additions & 37 deletions packages/compression/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<IncomingMessage, 'method' | 'headers'>,
response: ServerResponse,
next?: (error?: Error | string) => any,
) => void;
}
export type Middleware = (
request: Pick<IncomingMessage, 'method' | 'headers'>,
response: ServerResponse,
next?: (error?: Error | string) => any,
) => void;

declare function compression(options?: compression.Options): compression.Middleware;

export = compression;
export default function (options?: Options): Middleware;
15 changes: 8 additions & 7 deletions packages/compression/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 6 additions & 3 deletions packages/compression/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
58 changes: 58 additions & 0 deletions packages/compression/test/util/index.mjs
Original file line number Diff line number Diff line change
@@ -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,'');
}
9 changes: 5 additions & 4 deletions packages/parse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading

0 comments on commit 2456f60

Please sign in to comment.