feat: ESM support
feat: automatic .d.ts generation chore(deps): yargs@17
This commit is contained in:
parent
59d4f6671b
commit
2b73b5c97d
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,6 +8,7 @@ coverage
|
||||
*.pid
|
||||
*.gz
|
||||
|
||||
.parcel-cache
|
||||
dist
|
||||
pids
|
||||
logs
|
||||
|
75
bin/peerjs → bin/peerjs.ts
Executable file → Normal file
75
bin/peerjs → bin/peerjs.ts
Executable file → Normal file
@ -1,13 +1,12 @@
|
||||
#!/usr/bin/env node
|
||||
// tslint:disable
|
||||
|
||||
const path = require("path");
|
||||
const pkg = require("../package.json");
|
||||
const fs = require("fs");
|
||||
import path from "path";
|
||||
import {version} from "../package.json";
|
||||
import fs from "fs";
|
||||
const optimistUsageLength = 98;
|
||||
const yargs = require("yargs");
|
||||
const version = pkg.version;
|
||||
const { PeerServer } = require("../dist/src");
|
||||
import yargs from "yargs";
|
||||
import { PeerServer } from "../src";
|
||||
import { AddressInfo } from "net";
|
||||
const opts = yargs
|
||||
.usage("Usage: $0")
|
||||
.wrap(Math.min(optimistUsageLength, yargs.terminalWidth()))
|
||||
@ -16,60 +15,66 @@ const opts = yargs
|
||||
demandOption: false,
|
||||
alias: "t",
|
||||
describe: "timeout (milliseconds)",
|
||||
default: 5000
|
||||
default: 5000,
|
||||
},
|
||||
concurrent_limit: {
|
||||
demandOption: false,
|
||||
alias: "c",
|
||||
describe: "concurrent limit",
|
||||
default: 5000
|
||||
default: 5000,
|
||||
},
|
||||
alive_timeout: {
|
||||
demandOption: false,
|
||||
describe: "broken connection check timeout (milliseconds)",
|
||||
default: 60000
|
||||
default: 60000,
|
||||
},
|
||||
key: {
|
||||
demandOption: false,
|
||||
alias: "k",
|
||||
describe: "connection key",
|
||||
default: "peerjs"
|
||||
default: "peerjs",
|
||||
},
|
||||
sslkey: {
|
||||
type: "string",
|
||||
demandOption: false,
|
||||
describe: "path to SSL key"
|
||||
describe: "path to SSL key",
|
||||
},
|
||||
sslcert: {
|
||||
type: "string",
|
||||
demandOption: false,
|
||||
describe: "path to SSL certificate"
|
||||
describe: "path to SSL certificate",
|
||||
},
|
||||
host: {
|
||||
type: "string",
|
||||
demandOption: false,
|
||||
alias: "H",
|
||||
describe: "host"
|
||||
describe: "host",
|
||||
},
|
||||
port: {
|
||||
type: "number",
|
||||
demandOption: true,
|
||||
alias: "p",
|
||||
describe: "port"
|
||||
describe: "port",
|
||||
},
|
||||
path: {
|
||||
type: "string",
|
||||
demandOption: false,
|
||||
describe: "custom path",
|
||||
default: "/"
|
||||
default: "/",
|
||||
},
|
||||
allow_discovery: {
|
||||
type: "boolean",
|
||||
demandOption: false,
|
||||
describe: "allow discovery of peers"
|
||||
describe: "allow discovery of peers",
|
||||
},
|
||||
proxied: {
|
||||
type: "boolean",
|
||||
demandOption: false,
|
||||
describe: "Set true if PeerServer stays behind a reverse proxy",
|
||||
default: false
|
||||
}
|
||||
default: false,
|
||||
},
|
||||
})
|
||||
.boolean("allow_discovery")
|
||||
.argv;
|
||||
.boolean("allow_discovery").argv;
|
||||
|
||||
process.on("uncaughtException", function (e) {
|
||||
console.error("Error: " + e);
|
||||
@ -79,44 +84,48 @@ if (opts.sslkey || opts.sslcert) {
|
||||
if (opts.sslkey && opts.sslcert) {
|
||||
opts.ssl = {
|
||||
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 {
|
||||
console.error("Warning: PeerServer will not run because either " +
|
||||
"the key or the certificate has not been provided.");
|
||||
console.error(
|
||||
"Warning: PeerServer will not run because either " +
|
||||
"the key or the certificate has not been provided."
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
const userPath = opts.path;
|
||||
const server = PeerServer(opts, server => {
|
||||
const host = server.address().address;
|
||||
const port = server.address().port;
|
||||
const server = PeerServer(opts, (server) => {
|
||||
const { address: host, port } = server.address() as AddressInfo;
|
||||
|
||||
console.log(
|
||||
"Started PeerServer on %s, port: %s, path: %s (v. %s)",
|
||||
host, port, userPath || "/", version
|
||||
host,
|
||||
port,
|
||||
userPath || "/",
|
||||
version
|
||||
);
|
||||
|
||||
const shutdownApp = () => {
|
||||
server.close(() => {
|
||||
console.log('Http server closed.');
|
||||
console.log("Http server closed.");
|
||||
|
||||
process.exit(0);
|
||||
});
|
||||
};
|
||||
|
||||
process.on('SIGINT', shutdownApp);
|
||||
process.on('SIGTERM', shutdownApp);
|
||||
process.on("SIGINT", shutdownApp);
|
||||
process.on("SIGTERM", shutdownApp);
|
||||
});
|
||||
|
||||
server.on("connection", client => {
|
||||
server.on("connection", (client) => {
|
||||
console.log(`Client connected: ${client.getId()}`);
|
||||
});
|
||||
|
||||
server.on("disconnect", client => {
|
||||
server.on("disconnect", (client) => {
|
||||
console.log(`Client disconnected: ${client.getId()}`);
|
||||
});
|
5021
package-lock.json
generated
5021
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
39
package.json
39
package.json
@ -18,9 +18,13 @@
|
||||
},
|
||||
"license": "MIT",
|
||||
"contributors": [],
|
||||
"main": "dist/src/index.js",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/module.js",
|
||||
"source": "src/index.ts",
|
||||
"binary": "dist/bin/peerjs.js",
|
||||
"types": "dist/peer.d.ts",
|
||||
"bin": {
|
||||
"peerjs": "./bin/peerjs"
|
||||
"peerjs": "dist/bin/peerjs.js"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
@ -31,36 +35,39 @@
|
||||
"url": "https://opencollective.com/peer"
|
||||
},
|
||||
"files": [
|
||||
"bin/",
|
||||
"dist/",
|
||||
"index.d.ts"
|
||||
"dist/"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"targets": {
|
||||
"binary": {
|
||||
"source": "bin/peerjs.ts"
|
||||
},
|
||||
"main": {},
|
||||
"module": {}
|
||||
},
|
||||
"scripts": {
|
||||
"preversion": "npm run clean && npm run build",
|
||||
"build": "tsc",
|
||||
"clean": "rimraf ./dist",
|
||||
"lint": "eslint --ext .js,.ts .",
|
||||
"tsc": "tsc",
|
||||
"prebuild": "npm run lint",
|
||||
"build": "parcel build",
|
||||
"lint": "eslint --ext .js,.ts . && npm run check",
|
||||
"check": "tsc --noEmit",
|
||||
"test": "npm run lint && mocha \"test/**/*\"",
|
||||
"coverage": "nyc mocha \"test/**/*\"",
|
||||
"coverage:lcov": "nyc --reporter=lcov mocha \"test/**/*\"",
|
||||
"start": "bin/peerjs --port ${PORT:=9000}",
|
||||
"dev:start": "npm-run-all build start",
|
||||
"dev": "nodemon --watch src -e ts --exec npm run dev:start",
|
||||
"start": "dist/bin/peerjs.js --port ${PORT:=9000}",
|
||||
"dev": "nodemon --watch src -e ts --exec npm run start",
|
||||
"semantic-release": "semantic-release"
|
||||
},
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"ws": "^7.2.3",
|
||||
"yargs": "^15.3.1"
|
||||
"yargs": "^17.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
||||
"@parcel/packager-ts": "^2.8.2",
|
||||
"@parcel/transformer-typescript-types": "^2.8.2",
|
||||
"@semantic-release/changelog": "^6.0.1",
|
||||
"@semantic-release/git": "^10.0.1",
|
||||
"@types/chai": "^4.2.11",
|
||||
@ -69,6 +76,7 @@
|
||||
"@types/mocha": "^7.0.2",
|
||||
"@types/node": "^14.18.33",
|
||||
"@types/ws": "^7.2.3",
|
||||
"@types/yargs": "^17.0.19",
|
||||
"@typescript-eslint/eslint-plugin": "^2.24.0",
|
||||
"@typescript-eslint/parser": "^2.24.0",
|
||||
"chai": "^4.2.0",
|
||||
@ -78,6 +86,7 @@
|
||||
"nodemon": "^2.0.20",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"nyc": "^15.1.0",
|
||||
"parcel": "^2.8.2",
|
||||
"rimraf": "^3.0.2",
|
||||
"semantic-release": "^19.0.5",
|
||||
"sinon": "^7.5.0",
|
||||
|
@ -35,7 +35,7 @@ describe('Check bin/peerjs', () => {
|
||||
rejecter = reject;
|
||||
});
|
||||
|
||||
const ls = spawn('node', [path.join(__dirname, '../', 'bin/peerjs'), '--port', PORT]);
|
||||
const ls = spawn('node', [path.join(__dirname, '../', 'dist/bin/peerjs.js'), '--port', PORT]);
|
||||
|
||||
ls.stdout.on('data', async (data: string) => {
|
||||
if (!data.includes('Started')) return;
|
||||
|
@ -3,6 +3,7 @@
|
||||
"lib": [
|
||||
"esnext"
|
||||
],
|
||||
"noEmit": true,
|
||||
"target": "es2016",
|
||||
"module": "commonjs",
|
||||
"strict": true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user