Skip to content

Commit

Permalink
fix: make Log4brains run on Node 18 and 20
Browse files Browse the repository at this point in the history
  • Loading branch information
thomvaill authored Oct 29, 2024
1 parent 8e93409 commit 58dcfff
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 59 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
# We use a matrix even if it's not needed here to be able to re-use the same Yarn setup snippet everywhere
matrix:
os: [ubuntu-latest]
node-version: [16.x] # Active LTS (https://github.com/nodejs/release)
node-version: [20.x] # Active LTS (https://github.com/nodejs/release)
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -70,18 +70,17 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version:
# - 18.x # Current version # TODO: @log4brains/web does not build anymore on v18.x
- 16.x # Active LTS (https://github.com/nodejs/release)
- 14.x # Maintenance LTS
- 20.x # Active LTS (https://github.com/nodejs/release)
- 18.x # Maintenance LTS
exclude: # these cases are tested after the release with E2E tests
- os: windows-latest
node-version: 18.x
- os: windows-latest
node-version: 14.x
node-version: 18.x
- os: macos-latest
node-version: 18.x
- os: macos-latest
node-version: 14.x
node-version: 18.x
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -142,7 +141,7 @@ jobs:
# We use a matrix even if it's not needed here to be able to re-use the same Yarn setup snippet everywhere
matrix:
os: [ubuntu-latest]
node-version: [16.x] # Active LTS (https://github.com/nodejs/release)
node-version: [20.x] # Active LTS (https://github.com/nodejs/release)
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -204,7 +203,7 @@ jobs:
# We use a matrix even if it's not needed here to be able to re-use the same Yarn setup snippet everywhere
matrix:
os: [ubuntu-latest]
node-version: [16.x] # Active LTS (https://github.com/nodejs/release)
node-version: [20.x] # Active LTS (https://github.com/nodejs/release)
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
# We use a matrix even if it's not needed here to be able to re-use the same Yarn setup snippet everywhere
matrix:
os: [ubuntu-latest]
node-version: [16.x] # Active LTS (https://github.com/nodejs/release)
node-version: [20.x] # Active LTS (https://github.com/nodejs/release)
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [16.x] # Active LTS (https://github.com/nodejs/release); we test other versions in the main Build workflow because it's too slow
node-version: [20.x] # Active LTS (https://github.com/nodejs/release); we test other versions in the main Build workflow because it's too slow
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/post-release-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version:
# - 18.x # Current version # TODO: broken https://github.com/thomvaill/log4brains/issues/85
- 16.x # Active LTS (https://github.com/nodejs/release)
- 14.x # Maintenance LTS
- 20.x # Active LTS (https://github.com/nodejs/release)
- 18.x # Maintenance LTS
runs-on: ${{ matrix.os }}
steps:
- name: use node.js ${{ matrix.node-version }}
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
20
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@
"typedoc",
"unversioned",
"workdir"
]
],
"typescript.tsdk": "node_modules/typescript/lib"
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"name": "root",
"private": true,
"engines": {
"node": ">=12"
"node": ">=18"
},
"workspaces": [
"packages/**"
],
"scripts": {
"dev": "export NODE_OPTIONS=--openssl-legacy-provider && lerna run --parallel dev",
"build": "export NODE_OPTIONS=--openssl-legacy-provider && lerna run --stream build",
"dev": "cross-env NODE_OPTIONS=--openssl-legacy-provider lerna run --parallel dev",
"build": "cross-env NODE_OPTIONS=--openssl-legacy-provider lerna run --stream build",
"clean": "lerna run clean",
"typescript": "lerna run --stream typescript",
"test": "lerna run --stream test",
Expand All @@ -35,7 +35,7 @@
"@typescript-eslint/parser": "^4.2.0",
"chai": "^4.2.0",
"chalk": "^4.1.0",
"cross-env": "^7.0.2",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.9.0",
"eslint-config-airbnb-typescript": "^10.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"directory": "packages/cli-common"
},
"engines": {
"node": ">=10.23.0"
"node": ">=18"
},
"files": [
"dist"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"directory": "packages/cli"
},
"engines": {
"node": ">=10.23.0"
"node": ">=18"
},
"files": [
"dist"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"directory": "packages/core"
},
"engines": {
"node": ">=10.23.0"
"node": ">=18"
},
"files": [
"dist"
Expand Down
4 changes: 2 additions & 2 deletions packages/global-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"directory": "packages/global-cli"
},
"engines": {
"node": ">=10.23.0"
"node": ">=18"
},
"files": [
"dist"
Expand All @@ -38,7 +38,7 @@
},
"scripts": {
"dev": "nodemon",
"build": "tsc --build tsconfig.build.json && copyfiles -u 1 src/log4brains dist",
"build": "tsc --build tsconfig.build.json && copyfiles -u 1 src/log4brains src/index.js dist",
"clean": "rimraf ./dist",
"typescript": "tsc --noEmit",
"lint": "eslint . --max-warnings=0",
Expand Down
5 changes: 5 additions & 0 deletions packages/global-cli/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node
require = require("esm")(module, {
mainFields: ["module", "main"]
});
module.exports = require("./main");
19 changes: 15 additions & 4 deletions packages/global-cli/src/log4brains
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#!/usr/bin/env node
require = require("esm")(module, {
mainFields: ["module", "main"]
});
module.exports = require("./main");
const path = require("path");
const { spawn } = require("child_process");

// Temporary fix of https://github.com/thomvaill/log4brains/issues/85 (legacy md4 hash used by webpack4)
// that enables us to force the --openssl-legacy-provider NODE_OPTIONS flag without asking the user to do it himself.
// This is really hacky but will be removed as soon as we manage to upgrade our dependencies.
const child = spawn(
"node",
[path.join(__dirname, "index.js"), ...process.argv.slice(2)],
{
env: { ...process.env, NODE_OPTIONS: "--openssl-legacy-provider" },
cwd: process.cwd(),
stdio: "inherit"
}
);
2 changes: 1 addition & 1 deletion packages/init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"directory": "packages/init"
},
"engines": {
"node": ">=10.23.0"
"node": ">=18"
},
"files": [
"assets",
Expand Down
6 changes: 2 additions & 4 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"directory": "packages/web"
},
"engines": {
"node": ">=10.23.0"
"node": ">=18"
},
"files": [
"dist"
Expand Down Expand Up @@ -49,7 +49,6 @@
"@next/bundle-analyzer": "^10.0.1",
"babel-plugin-import": "^1.13.1",
"badge-maker": "^3.3.0",
"bufferutil": "^4.0.2",
"chalk": "^4.1.0",
"clsx": "^1.1.1",
"commander": "^6.1.0",
Expand All @@ -66,8 +65,7 @@
"react-icons": "^3.11.0",
"slugify": "^1.4.5",
"socket.io": "^2.3.0",
"socket.io-client": "^2.3.1",
"utf-8-validate": "^5.0.3"
"socket.io-client": "^2.3.1"
},
"devDependencies": {
"@babel/core": "^7.11.6",
Expand Down
16 changes: 10 additions & 6 deletions packages/web/src/cli/commands/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ type Deps = {
appConsole: AppConsole;
};

type SystemError = Error & { code?: string };
function isSystemError(obj: unknown): obj is SystemError {
return obj instanceof Error && "code" in obj;
}

export async function previewCommand(
{ appConsole }: Deps,
port: number,
Expand Down Expand Up @@ -69,8 +74,8 @@ export async function previewCommand(
);
} catch (err) {
appConsole.stopSpinner();
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (err.code === "EADDRINUSE") {

if (isSystemError(err) && err.code === "EADDRINUSE") {
if (openBrowser && adrSlug) {
appConsole.println(
chalk.dim(
Expand All @@ -85,15 +90,14 @@ export async function previewCommand(
`Port ${port} is already in use. Use the -p <PORT> option to select another one.`
);
process.exit(1);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
} else if (err.code === "EACCES") {
} else if (isSystemError(err) && err.code === "EACCES") {
appConsole.fatal(
`Impossible to use port ${port} (permission denied). Use the -p <PORT> option to select another one.`
);
process.exit(1);
} else {
throw err;
}

throw err;
}

appConsole.stopSpinner();
Expand Down
21 changes: 1 addition & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5640,13 +5640,6 @@ buffer@^5.5.0:
base64-js "^1.3.1"
ieee754 "^1.1.13"

bufferutil@^4.0.2:
version "4.0.3"
resolved "https://registry.yarnpkg.com/bufferutil/-/bufferutil-4.0.3.tgz#66724b756bed23cd7c28c4d306d7994f9943cc6b"
integrity sha512-yEYTwGndELGvfXsImMBLop58eaGW+YdONi1fNjTINSY98tmMmFijBG6WXgdkfuLNt4imzQNtIE+eBp1PVpMCSw==
dependencies:
node-gyp-build "^4.2.0"

builtin-modules@^3.1.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.2.0.tgz#45d5db99e7ee5e6bc4f362e008bf917ab5049887"
Expand Down Expand Up @@ -6900,7 +6893,7 @@ create-require@^1.1.0:
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==

cross-env@^7.0.2:
cross-env@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf"
integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==
Expand Down Expand Up @@ -13316,11 +13309,6 @@ node-fetch@^2.6.7:
dependencies:
whatwg-url "^5.0.0"

node-gyp-build@^4.2.0:
version "4.2.3"
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.2.3.tgz#ce6277f853835f718829efb47db20f3e4d9c4739"
integrity sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==

node-gyp-build@^4.3.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.5.0.tgz#7a64eefa0b21112f89f58379da128ac177f20e40"
Expand Down Expand Up @@ -18453,13 +18441,6 @@ use@^3.1.0:
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==

utf-8-validate@^5.0.3:
version "5.0.4"
resolved "https://registry.yarnpkg.com/utf-8-validate/-/utf-8-validate-5.0.4.tgz#72a1735983ddf7a05a43a9c6b67c5ce1c910f9b8"
integrity sha512-MEF05cPSq3AwJ2C7B7sHAA6i53vONoZbMGX8My5auEVm6W+dJ2Jd/TZPyGJ5CH42V2XtbI5FD28HeHeqlPzZ3Q==
dependencies:
node-gyp-build "^4.2.0"

util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
Expand Down

0 comments on commit 58dcfff

Please sign in to comment.