fix: import from ESM only environments

refactor: strictest typescript preset
This commit is contained in:
Jonas Gloning 2023-02-14 12:01:10 +01:00
parent 669b200fb7
commit 476299ed08
No known key found for this signature in database
GPG Key ID: 684639B5E59E7614
11 changed files with 147 additions and 9298 deletions

View File

@ -5,11 +5,15 @@ import {version} from "../package.json";
import fs from "node:fs";
const optimistUsageLength = 98;
import yargs from "yargs";
import { hideBin } from 'yargs/helpers'
import { PeerServer} from "../src";
import { AddressInfo } from "node:net";
const opts = yargs
import type { AddressInfo } from "node:net";
const y = yargs(hideBin(process.argv));
const opts = y
.usage("Usage: $0")
.wrap(Math.min(optimistUsageLength, yargs.terminalWidth()))
.wrap(Math.min(optimistUsageLength, y.terminalWidth()))
.options({
expire_timeout: {
demandOption: false,
@ -82,13 +86,10 @@ process.on("uncaughtException", function (e) {
if (opts.sslkey || opts.sslcert) {
if (opts.sslkey && opts.sslcert) {
opts.ssl = {
opts["ssl"] = {
key: fs.readFileSync(path.resolve(opts.sslkey)),
cert: fs.readFileSync(path.resolve(opts.sslcert)),
};
delete opts.sslkey;
delete opts.sslcert;
} else {
console.error(
"Warning: PeerServer will not run because either " +

9358
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -18,8 +18,21 @@
},
"license": "MIT",
"contributors": [],
"main": "dist/index.js",
"module": "dist/module.js",
"type": "module",
"exports": {
".": {
"import": {
"types": "./dist/peer.d.ts",
"default": "./dist/module.mjs"
},
"require":{
"types": "./dist/peer.d.ts",
"default": "./dist/index.cjs"
}
}
},
"main": "dist/index.cjs",
"module": "dist/module.mjs",
"source": "src/index.ts",
"binary": "dist/bin/peerjs.js",
"types": "dist/peer.d.ts",
@ -73,6 +86,7 @@
"@parcel/transformer-typescript-types": "^2.8.2",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@tsconfig/node16-strictest-esm": "^1.0.3",
"@types/chai": "^4.2.11",
"@types/cors": "^2.8.6",
"@types/mocha": "^10.0.0",

View File

@ -21,7 +21,7 @@ export default ({ config, realm }: {
return res.send(clientsIds);
}
res.sendStatus(401);
return res.sendStatus(401);
});
return app;

View File

@ -1,4 +1,4 @@
import type {Server, ServerOptions} from 'ws';
import type {WebSocketServer, ServerOptions} from 'ws';
export interface IConfig {
readonly host: string;
@ -16,7 +16,7 @@ export interface IConfig {
cert: string;
};
readonly generateClientId?: () => string;
readonly createWebSocketServer?: (options: ServerOptions) => Server;
readonly createWebSocketServer?: (options: ServerOptions) => WebSocketServer;
}
const defaultConfig: IConfig = {

View File

@ -1,6 +1,6 @@
import express from "express";
import {Server as HttpServer} from "node:http";
import {Server as HttpsServer} from "node:https";
import type express from "express";
import type {Server as HttpServer} from "node:http";
import type {Server as HttpsServer} from "node:https";
import path from "node:path";
import type {IRealm} from "./models/realm";
import {Realm} from "./models/realm";

View File

@ -1,4 +1,4 @@
import {MessageType} from "../enums";
import type {MessageType} from "../enums";
import type {IClient} from "../models/client";
import type {IMessage} from "../models/message";
import type {Handler} from "./handler";

View File

@ -4,5 +4,5 @@ export interface IMessage {
readonly type: MessageType;
readonly src: string;
readonly dst: string;
readonly payload?: string;
readonly payload?: string |undefined;
}

View File

@ -75,7 +75,7 @@ export class MessagesExpire implements IMessagesExpire {
this.messageHandler.handle(undefined, {
type: MessageType.EXPIRE,
src: message.dst,
dst: message.src
dst: message.src,
});
seen[seenKey] = true;

View File

@ -1,15 +1,15 @@
import {EventEmitter} from "node:events";
import {IncomingMessage} from "node:http";
import type {IncomingMessage} from "node:http";
import url from "node:url";
import type WebSocket from "ws";
import * as WebSocketLib from "ws";
import {Errors, MessageType} from "../../enums";
import type {IClient} from "../../models/client";
import {Client} from "../../models/client";
import type {IConfig} from "../../config";
import type {IRealm} from "../../models/realm";
import {Server as HttpServer} from "node:http";
import {Server as HttpsServer} from "node:https";
import {WebSocketServer as Server} from "ws";
import type {Server as HttpServer} from "node:http";
import type {Server as HttpsServer} from "node:https";
export interface IWebSocketServer extends EventEmitter {
readonly path: string;
@ -30,7 +30,7 @@ export class WebSocketServer extends EventEmitter implements IWebSocketServer {
public readonly path: string;
private readonly realm: IRealm;
private readonly config: CustomConfig;
public readonly socketServer: WebSocketLib.Server;
public readonly socketServer: Server;
constructor({ server, realm, config }: { server: HttpServer | HttpsServer; realm: IRealm; config: CustomConfig; }) {
super();
@ -43,7 +43,7 @@ export class WebSocketServer extends EventEmitter implements IWebSocketServer {
const path = this.config.path;
this.path = `${path}${path.endsWith('/') ? "" : "/"}${WS_PATH}`;
const options: WebSocketLib.ServerOptions = {
const options: WebSocket.ServerOptions = {
path: this.path,
server,
};
@ -51,7 +51,7 @@ export class WebSocketServer extends EventEmitter implements IWebSocketServer {
this.socketServer = (
config.createWebSocketServer ?
config.createWebSocketServer(options) :
new WebSocketLib.Server(options)
new Server(options)
);
this.socketServer.on("connection", (socket, req) => this._onSocketConnection(socket, req));

View File

@ -1,28 +1,18 @@
{
"extends": "@tsconfig/node16-strictest-esm/tsconfig.json",
"compilerOptions": {
"lib": [
"esnext"
],
"noEmit": true,
"target": "es2016",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"downlevelIteration": true,
"moduleResolution": "node",
"noImplicitAny": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"skipLibCheck": false,
"sourceMap": true,
"outDir": "dist"
"exactOptionalPropertyTypes": false
},
"include": [
"./src/**/*",
"./src/**/*"
],
"exclude": [
"test",
"bin",
"bin"
]
}