Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove esm package #214

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
nodejs: [10, 12, 14, 16, 18]
nodejs: [12, 14, 16, 18]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also drop 12,14,16 as they reached eof for while https://endoflife.date/nodejs and add new version like 19, 20, 21?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

19 and 21 are EOL too. Adding 20 and 22 would be interesting.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd versions are experimental and should never be used.


steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -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
Expand Down
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