fix: import from ESM only environments
refactor: strictest typescript preset
This commit is contained in:
parent
669b200fb7
commit
476299ed08
@ -5,11 +5,15 @@ import {version} from "../package.json";
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
const optimistUsageLength = 98;
|
const optimistUsageLength = 98;
|
||||||
import yargs from "yargs";
|
import yargs from "yargs";
|
||||||
import { PeerServer } from "../src";
|
import { hideBin } from 'yargs/helpers'
|
||||||
import { AddressInfo } from "node:net";
|
import { PeerServer} from "../src";
|
||||||
const opts = yargs
|
import type { AddressInfo } from "node:net";
|
||||||
|
|
||||||
|
const y = yargs(hideBin(process.argv));
|
||||||
|
|
||||||
|
const opts = y
|
||||||
.usage("Usage: $0")
|
.usage("Usage: $0")
|
||||||
.wrap(Math.min(optimistUsageLength, yargs.terminalWidth()))
|
.wrap(Math.min(optimistUsageLength, y.terminalWidth()))
|
||||||
.options({
|
.options({
|
||||||
expire_timeout: {
|
expire_timeout: {
|
||||||
demandOption: false,
|
demandOption: false,
|
||||||
@ -82,13 +86,10 @@ process.on("uncaughtException", function (e) {
|
|||||||
|
|
||||||
if (opts.sslkey || opts.sslcert) {
|
if (opts.sslkey || opts.sslcert) {
|
||||||
if (opts.sslkey && opts.sslcert) {
|
if (opts.sslkey && opts.sslcert) {
|
||||||
opts.ssl = {
|
opts["ssl"] = {
|
||||||
key: fs.readFileSync(path.resolve(opts.sslkey)),
|
key: fs.readFileSync(path.resolve(opts.sslkey)),
|
||||||
cert: fs.readFileSync(path.resolve(opts.sslcert)),
|
cert: fs.readFileSync(path.resolve(opts.sslcert)),
|
||||||
};
|
};
|
||||||
|
|
||||||
delete opts.sslkey;
|
|
||||||
delete opts.sslcert;
|
|
||||||
} else {
|
} else {
|
||||||
console.error(
|
console.error(
|
||||||
"Warning: PeerServer will not run because either " +
|
"Warning: PeerServer will not run because either " +
|
||||||
|
9358
package-lock.json
generated
9358
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
18
package.json
18
package.json
@ -18,8 +18,21 @@
|
|||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"contributors": [],
|
"contributors": [],
|
||||||
"main": "dist/index.js",
|
"type": "module",
|
||||||
"module": "dist/module.js",
|
"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",
|
"source": "src/index.ts",
|
||||||
"binary": "dist/bin/peerjs.js",
|
"binary": "dist/bin/peerjs.js",
|
||||||
"types": "dist/peer.d.ts",
|
"types": "dist/peer.d.ts",
|
||||||
@ -73,6 +86,7 @@
|
|||||||
"@parcel/transformer-typescript-types": "^2.8.2",
|
"@parcel/transformer-typescript-types": "^2.8.2",
|
||||||
"@semantic-release/changelog": "^6.0.1",
|
"@semantic-release/changelog": "^6.0.1",
|
||||||
"@semantic-release/git": "^10.0.1",
|
"@semantic-release/git": "^10.0.1",
|
||||||
|
"@tsconfig/node16-strictest-esm": "^1.0.3",
|
||||||
"@types/chai": "^4.2.11",
|
"@types/chai": "^4.2.11",
|
||||||
"@types/cors": "^2.8.6",
|
"@types/cors": "^2.8.6",
|
||||||
"@types/mocha": "^10.0.0",
|
"@types/mocha": "^10.0.0",
|
||||||
|
@ -21,7 +21,7 @@ export default ({ config, realm }: {
|
|||||||
return res.send(clientsIds);
|
return res.send(clientsIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.sendStatus(401);
|
return res.sendStatus(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import type {Server, ServerOptions} from 'ws';
|
import type {WebSocketServer, ServerOptions} from 'ws';
|
||||||
|
|
||||||
export interface IConfig {
|
export interface IConfig {
|
||||||
readonly host: string;
|
readonly host: string;
|
||||||
@ -16,7 +16,7 @@ export interface IConfig {
|
|||||||
cert: string;
|
cert: string;
|
||||||
};
|
};
|
||||||
readonly generateClientId?: () => string;
|
readonly generateClientId?: () => string;
|
||||||
readonly createWebSocketServer?: (options: ServerOptions) => Server;
|
readonly createWebSocketServer?: (options: ServerOptions) => WebSocketServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultConfig: IConfig = {
|
const defaultConfig: IConfig = {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import express from "express";
|
import type express from "express";
|
||||||
import {Server as HttpServer} from "node:http";
|
import type {Server as HttpServer} from "node:http";
|
||||||
import {Server as HttpsServer} from "node:https";
|
import type {Server as HttpsServer} from "node:https";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import type {IRealm} from "./models/realm";
|
import type {IRealm} from "./models/realm";
|
||||||
import {Realm} from "./models/realm";
|
import {Realm} from "./models/realm";
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {MessageType} from "../enums";
|
import type {MessageType} from "../enums";
|
||||||
import type {IClient} from "../models/client";
|
import type {IClient} from "../models/client";
|
||||||
import type {IMessage} from "../models/message";
|
import type {IMessage} from "../models/message";
|
||||||
import type {Handler} from "./handler";
|
import type {Handler} from "./handler";
|
||||||
|
@ -4,5 +4,5 @@ export interface IMessage {
|
|||||||
readonly type: MessageType;
|
readonly type: MessageType;
|
||||||
readonly src: string;
|
readonly src: string;
|
||||||
readonly dst: string;
|
readonly dst: string;
|
||||||
readonly payload?: string;
|
readonly payload?: string |undefined;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ export class MessagesExpire implements IMessagesExpire {
|
|||||||
this.messageHandler.handle(undefined, {
|
this.messageHandler.handle(undefined, {
|
||||||
type: MessageType.EXPIRE,
|
type: MessageType.EXPIRE,
|
||||||
src: message.dst,
|
src: message.dst,
|
||||||
dst: message.src
|
dst: message.src,
|
||||||
});
|
});
|
||||||
|
|
||||||
seen[seenKey] = true;
|
seen[seenKey] = true;
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import {EventEmitter} from "node:events";
|
import {EventEmitter} from "node:events";
|
||||||
import {IncomingMessage} from "node:http";
|
import type {IncomingMessage} from "node:http";
|
||||||
import url from "node:url";
|
import url from "node:url";
|
||||||
import type WebSocket from "ws";
|
import type WebSocket from "ws";
|
||||||
import * as WebSocketLib from "ws";
|
|
||||||
import {Errors, MessageType} from "../../enums";
|
import {Errors, MessageType} from "../../enums";
|
||||||
import type {IClient} from "../../models/client";
|
import type {IClient} from "../../models/client";
|
||||||
import {Client} from "../../models/client";
|
import {Client} from "../../models/client";
|
||||||
import type {IConfig} from "../../config";
|
import type {IConfig} from "../../config";
|
||||||
import type {IRealm} from "../../models/realm";
|
import type {IRealm} from "../../models/realm";
|
||||||
import {Server as HttpServer} from "node:http";
|
import {WebSocketServer as Server} from "ws";
|
||||||
import {Server as HttpsServer} from "node:https";
|
import type {Server as HttpServer} from "node:http";
|
||||||
|
import type {Server as HttpsServer} from "node:https";
|
||||||
|
|
||||||
export interface IWebSocketServer extends EventEmitter {
|
export interface IWebSocketServer extends EventEmitter {
|
||||||
readonly path: string;
|
readonly path: string;
|
||||||
@ -30,7 +30,7 @@ export class WebSocketServer extends EventEmitter implements IWebSocketServer {
|
|||||||
public readonly path: string;
|
public readonly path: string;
|
||||||
private readonly realm: IRealm;
|
private readonly realm: IRealm;
|
||||||
private readonly config: CustomConfig;
|
private readonly config: CustomConfig;
|
||||||
public readonly socketServer: WebSocketLib.Server;
|
public readonly socketServer: Server;
|
||||||
|
|
||||||
constructor({ server, realm, config }: { server: HttpServer | HttpsServer; realm: IRealm; config: CustomConfig; }) {
|
constructor({ server, realm, config }: { server: HttpServer | HttpsServer; realm: IRealm; config: CustomConfig; }) {
|
||||||
super();
|
super();
|
||||||
@ -43,7 +43,7 @@ export class WebSocketServer extends EventEmitter implements IWebSocketServer {
|
|||||||
const path = this.config.path;
|
const path = this.config.path;
|
||||||
this.path = `${path}${path.endsWith('/') ? "" : "/"}${WS_PATH}`;
|
this.path = `${path}${path.endsWith('/') ? "" : "/"}${WS_PATH}`;
|
||||||
|
|
||||||
const options: WebSocketLib.ServerOptions = {
|
const options: WebSocket.ServerOptions = {
|
||||||
path: this.path,
|
path: this.path,
|
||||||
server,
|
server,
|
||||||
};
|
};
|
||||||
@ -51,7 +51,7 @@ export class WebSocketServer extends EventEmitter implements IWebSocketServer {
|
|||||||
this.socketServer = (
|
this.socketServer = (
|
||||||
config.createWebSocketServer ?
|
config.createWebSocketServer ?
|
||||||
config.createWebSocketServer(options) :
|
config.createWebSocketServer(options) :
|
||||||
new WebSocketLib.Server(options)
|
new Server(options)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.socketServer.on("connection", (socket, req) => this._onSocketConnection(socket, req));
|
this.socketServer.on("connection", (socket, req) => this._onSocketConnection(socket, req));
|
||||||
|
@ -1,28 +1,18 @@
|
|||||||
{
|
{
|
||||||
|
"extends": "@tsconfig/node16-strictest-esm/tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"lib": [
|
"lib": [
|
||||||
"esnext"
|
"esnext"
|
||||||
],
|
],
|
||||||
"noEmit": true,
|
"noEmit": true,
|
||||||
"target": "es2016",
|
|
||||||
"module": "commonjs",
|
|
||||||
"strict": true,
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"downlevelIteration": true,
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"noImplicitAny": true,
|
|
||||||
"noUnusedLocals": true,
|
|
||||||
"noUnusedParameters": true,
|
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"skipLibCheck": false,
|
"exactOptionalPropertyTypes": false
|
||||||
"sourceMap": true,
|
|
||||||
"outDir": "dist"
|
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"./src/**/*",
|
"./src/**/*"
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"test",
|
"test",
|
||||||
"bin",
|
"bin"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user