chore: update min supported node version to >=18 (#19)
Update required minimum node version to >=18 in preparation for updating other dependencies that require newer node versions.
This commit is contained in:
parent
a13295b223
commit
999b9b54a2
9 changed files with 2712 additions and 1745 deletions
2
.nvmrc
2
.nvmrc
|
|
@ -1 +1 @@
|
|||
lts/erbium
|
||||
18
|
||||
|
|
|
|||
|
|
@ -8,5 +8,4 @@ os:
|
|||
node_js:
|
||||
- node
|
||||
- lts/*
|
||||
- 12
|
||||
- 10
|
||||
- 18
|
||||
|
|
|
|||
1093
examples/personal-site/package-lock.json
generated
1093
examples/personal-site/package-lock.json
generated
File diff suppressed because it is too large
Load diff
1646
package-lock.json
generated
1646
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -9,7 +9,7 @@
|
|||
"license": "MPL-2.0",
|
||||
"repository": "github:websnacksjs/websnacks",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
"node": ">=18"
|
||||
},
|
||||
"main": "dist/index.js",
|
||||
"types": "types.d.ts",
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
"test:e2e": "cd test && ts-node --script-mode ./run-e2e.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "~10",
|
||||
"@types/node": "~18",
|
||||
"@types/ws": "^7.4.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.15.2",
|
||||
"@typescript-eslint/parser": "^4.15.2",
|
||||
|
|
@ -44,8 +44,8 @@
|
|||
"eslint-plugin-prettier": "^3.3.1",
|
||||
"eslint-plugin-react": "^7.22.0",
|
||||
"prettier": "=2.2.1",
|
||||
"ts-node": "^9.1.1",
|
||||
"typescript": "~4.2.2"
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "~4.9.5"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"node-watch": "^0.7.1",
|
||||
|
|
|
|||
|
|
@ -34,9 +34,7 @@ const renderPagesToHtml = async ({
|
|||
try {
|
||||
compiledHtml = renderPage(pageSrc.page());
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
`failed to compile ${srcPath}: ${error.stack ?? error}`,
|
||||
);
|
||||
throw new Error(`failed to compile ${srcPath}: ${error}`);
|
||||
}
|
||||
const relPath = path.relative(pagesDir, path.dirname(srcPath));
|
||||
let baseName = path.basename(srcPath, ".tsx");
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@
|
|||
|
||||
import { existsSync, promises as fs, watch } from "fs";
|
||||
import * as http from "http";
|
||||
import * as net from "net";
|
||||
import * as path from "path";
|
||||
|
||||
import { renderSite } from "../../build";
|
||||
import { Config, loadConfig } from "../../config";
|
||||
import { isErrnoException } from "../../utils/error";
|
||||
import { Command, UsageError } from "../types";
|
||||
|
||||
const DEFAULT_SERVER_PORT = 8080;
|
||||
|
|
@ -119,14 +119,16 @@ const guessMimeType = (ext: string): string => {
|
|||
return mimeType;
|
||||
};
|
||||
|
||||
const portFromServer = (server: Pick<net.Server, "address">): number => {
|
||||
const addrInfo = server.address();
|
||||
if (addrInfo == null) {
|
||||
throw new Error(`server address is null (this should never happen!)`);
|
||||
}
|
||||
if (typeof addrInfo === "string") {
|
||||
const portFromServer = (
|
||||
addrInfo: { port: number } | object | string | undefined | null,
|
||||
): number => {
|
||||
if (
|
||||
typeof addrInfo !== "object" ||
|
||||
addrInfo == null ||
|
||||
!("port" in addrInfo)
|
||||
) {
|
||||
throw new Error(
|
||||
`server address is a string (this should never happen!)`,
|
||||
"server address does not have a valid port (this should never happen!)",
|
||||
);
|
||||
}
|
||||
return addrInfo.port;
|
||||
|
|
@ -158,7 +160,7 @@ const startHttpServer = async (publicDir: string): Promise<http.Server> => {
|
|||
}
|
||||
const mimeType = guessMimeType(reqExt);
|
||||
if (mimeType === "text/html") {
|
||||
const port = portFromServer(req.socket);
|
||||
const port = portFromServer(req.socket.address());
|
||||
contents = injectLiveReloadScript(contents.toString("utf8"), port);
|
||||
}
|
||||
res.writeHead(200, {
|
||||
|
|
@ -176,12 +178,16 @@ const startHttpServer = async (publicDir: string): Promise<http.Server> => {
|
|||
try {
|
||||
await listen(DEFAULT_SERVER_PORT);
|
||||
} catch (error) {
|
||||
if (error.code !== "EADDRINUSE") {
|
||||
if (
|
||||
error instanceof Error &&
|
||||
isErrnoException(error) &&
|
||||
error.code !== "EADDRINUSE"
|
||||
) {
|
||||
throw error;
|
||||
}
|
||||
await listen();
|
||||
}
|
||||
const port = portFromServer(httpServer);
|
||||
const port = portFromServer(httpServer.address());
|
||||
console.log(`Listening at http://127.0.0.1:${port}`);
|
||||
return httpServer;
|
||||
};
|
||||
|
|
@ -194,7 +200,11 @@ const startWebSocketServer = async (
|
|||
try {
|
||||
ws = await import("ws");
|
||||
} catch (error) {
|
||||
if (error.code !== "MODULE_NOT_FOUND") {
|
||||
if (
|
||||
error instanceof Error &&
|
||||
isErrnoException(error) &&
|
||||
error.code !== "MODULE_NOT_FOUND"
|
||||
) {
|
||||
throw error;
|
||||
}
|
||||
console.warn(`'ws' module not found, live-reloading will be disabled`);
|
||||
|
|
@ -218,7 +228,11 @@ const watchFolders = async (
|
|||
nodeWatch.default(folders, { recursive: true }, listener);
|
||||
return;
|
||||
} catch (error) {
|
||||
if (error.code !== "MODULE_NOT_FOUND") {
|
||||
if (
|
||||
error instanceof Error &&
|
||||
isErrnoException(error) &&
|
||||
error.code !== "MODULE_NOT_FOUND"
|
||||
) {
|
||||
throw error;
|
||||
}
|
||||
console.warn(
|
||||
|
|
@ -230,7 +244,7 @@ const watchFolders = async (
|
|||
// triggering duplicate file events on some systems.
|
||||
for (const folder of folders) {
|
||||
watch(folder, { recursive: true }, (_, fileName) => {
|
||||
listener("update", fileName);
|
||||
listener("update", fileName || undefined);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,11 +3,17 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { isErrnoException } from "./error";
|
||||
|
||||
const resolveModulePath = (importPath: string): string | undefined => {
|
||||
try {
|
||||
return require.resolve(importPath);
|
||||
} catch (error) {
|
||||
if (error.code === "MODULE_NOT_FOUND") {
|
||||
if (
|
||||
error instanceof Error &&
|
||||
isErrnoException(error) &&
|
||||
error.code === "MODULE_NOT_FOUND"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
throw error;
|
||||
|
|
|
|||
3
src/utils/error.ts
Normal file
3
src/utils/error.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export const isErrnoException = (
|
||||
error: Error,
|
||||
): error is NodeJS.ErrnoException => "code" in error;
|
||||
Loading…
Add table
Add a link
Reference in a new issue