forked from svrjs/svrjs
feat: add support for Deno 2
This commit is contained in:
parent
2f475b4066
commit
9abb89d560
4 changed files with 45 additions and 11 deletions
31
src/index.js
31
src/index.js
|
@ -138,7 +138,9 @@ let disableMods = false;
|
|||
const args = process.argv;
|
||||
for (
|
||||
let i =
|
||||
process.argv[0].indexOf("node") > -1 || process.argv[0].indexOf("bun") > -1
|
||||
process.argv[0].indexOf("node") > -1 ||
|
||||
process.argv[0].indexOf("bun") > -1 ||
|
||||
process.argv[0].indexOf("deno") > -1
|
||||
? 2
|
||||
: 1;
|
||||
i < args.length;
|
||||
|
@ -631,6 +633,7 @@ try {
|
|||
}
|
||||
|
||||
if (vnum === undefined) vnum = 0;
|
||||
if (process.versions && process.versions.deno) vnum = 64;
|
||||
if (process.isBun) vnum = 64;
|
||||
|
||||
let mods = [];
|
||||
|
@ -1416,13 +1419,24 @@ function SVRJSFork() {
|
|||
serverconsole.locwarnmessage(
|
||||
`${name} limited the number of workers to one, because of startup problems in Bun 1.0 and newer with shimmed (not native) clustering module. Reliability may suffer.`
|
||||
);
|
||||
} else if (
|
||||
!threadLimitWarned &&
|
||||
cluster.__shimmed__ &&
|
||||
process.versions &&
|
||||
process.versions.deno
|
||||
) {
|
||||
threadLimitWarned = true;
|
||||
serverconsole.locwarnmessage(
|
||||
`${name} limited the number of workers to one, because of startup problems in Deno with shimmed (not native) clustering module. Reliability may suffer.`
|
||||
);
|
||||
}
|
||||
if (
|
||||
!(
|
||||
cluster.__shimmed__ &&
|
||||
process.isBun &&
|
||||
process.versions.bun &&
|
||||
process.versions.bun[0] != "0" &&
|
||||
((process.isBun &&
|
||||
process.versions.bun &&
|
||||
process.versions.bun[0] != "0") ||
|
||||
(process.versions && process.versions.deno_)) &&
|
||||
Object.keys(cluster.workers) > 0
|
||||
)
|
||||
) {
|
||||
|
@ -1434,7 +1448,10 @@ function SVRJSFork() {
|
|||
);
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.name == "NotImplementedError") {
|
||||
if (
|
||||
err.name == "NotImplementedError" ||
|
||||
err.message == "Not implemented: cluster.fork"
|
||||
) {
|
||||
// If cluster.fork throws a NotImplementedError, shim cluster module
|
||||
cluster.bunShim();
|
||||
if (
|
||||
|
@ -1725,6 +1742,7 @@ function start(init) {
|
|||
);
|
||||
if (
|
||||
!process.isBun &&
|
||||
!(process.versions && process.versions.deno) &&
|
||||
/^v(?:[0-9]\.|1[0-7]\.|18\.(?:[0-9]|1[0-8])\.|18\.19\.0|20\.(?:[0-9]|10)\.|20\.11\.0|21\.[0-5]\.|21\.6\.0|21\.6\.1(?![0-9]))/.test(
|
||||
process.version
|
||||
)
|
||||
|
@ -1734,6 +1752,7 @@ function start(init) {
|
|||
);
|
||||
if (
|
||||
!process.isBun &&
|
||||
!(process.versions && process.versions.deno) &&
|
||||
/^v(?:[0-9]\.|1[0-7]\.|18\.(?:1?[0-9])\.|18\.20\.0|20\.(?:[0-9]|1[01])\.|20\.12\.0|21\.[0-6]\.|21\.7\.0|21\.7\.1(?![0-9]))/.test(
|
||||
process.version
|
||||
)
|
||||
|
@ -1805,6 +1824,8 @@ function start(init) {
|
|||
serverconsole.locmessage("Server version: " + version);
|
||||
if (process.isBun)
|
||||
serverconsole.locmessage("Bun version: v" + process.versions.bun);
|
||||
else if (process.versions && process.versions.deno)
|
||||
serverconsole.locmessage("Deno version: " + process.versions.deno);
|
||||
else serverconsole.locmessage("Node.JS version: " + process.version);
|
||||
const CPUs = os.cpus();
|
||||
if (CPUs.length > 0)
|
||||
|
|
|
@ -13,7 +13,7 @@ if (!process.singleThreaded) {
|
|||
// Clustering is not supported!
|
||||
}
|
||||
|
||||
// Cluster & IPC shim for Bun
|
||||
// Cluster & IPC shim for Bun and Deno
|
||||
|
||||
cluster.bunShim = () => {
|
||||
cluster.isMaster = !process.env.NODE_UNIQUE_ID;
|
||||
|
@ -126,7 +126,7 @@ if (!process.singleThreaded) {
|
|||
};
|
||||
|
||||
try {
|
||||
worker.send(undefined);
|
||||
if (process.isBun) worker.send(undefined);
|
||||
} catch (err) {
|
||||
if (err.message === "NOT IMPLEMENTED") {
|
||||
sendImplemented = false;
|
||||
|
@ -216,7 +216,7 @@ if (!process.singleThreaded) {
|
|||
};
|
||||
|
||||
if (
|
||||
process.isBun &&
|
||||
(process.isBun || (process.versions && process.versions.deno)) &&
|
||||
(cluster.isMaster === undefined ||
|
||||
(cluster.isMaster && process.env.NODE_UNIQUE_ID))
|
||||
) {
|
||||
|
|
|
@ -7,7 +7,12 @@ function generateServerString(exposeServerVersion) {
|
|||
? `${name.replace(/ /g, "-")}/${version} (${getOS()}; ${
|
||||
process.isBun
|
||||
? "Bun/v" + process.versions.bun + "; like Node.JS/" + process.version
|
||||
: "Node.JS/" + process.version
|
||||
: process.versions && process.versions.deno
|
||||
? "Deno/v" +
|
||||
process.versions.deno +
|
||||
"; like Node.JS/" +
|
||||
process.version
|
||||
: "Node.JS/" + process.version
|
||||
})`
|
||||
: name.replace(/ /g, "-");
|
||||
}
|
||||
|
|
|
@ -28,8 +28,16 @@ try {
|
|||
function sendStatistics(modInfos, callback) {
|
||||
const statisticsToSend = JSON.stringify({
|
||||
version: version,
|
||||
runtime: process.isBun ? "Bun" : "Node.js",
|
||||
runtimeVersion: process.isBun ? process.versions.bun : process.version,
|
||||
runtime: process.isBun
|
||||
? "Bun"
|
||||
: process.versions && process.versions.deno
|
||||
? "Deno"
|
||||
: "Node.js",
|
||||
runtimeVersion: process.isBun
|
||||
? process.versions.bun
|
||||
: process.versions && process.versions.deno
|
||||
? process.versions.deno
|
||||
: process.version,
|
||||
mods: modInfos
|
||||
});
|
||||
const statisticsRequest = https.request(
|
||||
|
|
Reference in a new issue