From c518b027965a0c8ecbb3fdd23b8be202c36e4f87 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 24 Oct 2024 18:39:07 -0700 Subject: [PATCH 01/21] ci: add smoke-test for various node version and package managers --- .github/workflows/CI.yml | 42 +++++++++++++++++++++++++++++++++++++++- .gitignore | 5 ++++- package.json | 1 + script/smoke-test.bash | 37 +++++++++++++++++++++++++++++++++++ src/module.cc | 4 ++-- src/outgoing_msg.cc | 1 + src/poller.h | 4 ++-- 7 files changed, 88 insertions(+), 6 deletions(-) create mode 100755 script/smoke-test.bash diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c96fead6..b0415d56 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -189,7 +189,8 @@ jobs: pnpm install -g electron@latest xvfb-run --auto-servernum pnpm run test.electron.main continue-on-error: true - merge-build: + + MergeBuild: runs-on: ubuntu-latest needs: Build steps: @@ -199,3 +200,42 @@ jobs: name: build pattern: build-* delete-merged: true + + SmokeTest: + runs-on: ${{ matrix.os }} + needs: MergeBuild + strategy: + fail-fast: false + matrix: + os: + - ubuntu-24.04 + - windows-2022 + - macos-14 + - macos-13 + node-version: + - 10 + - 22 + steps: + - uses: actions/setup-node@v4 + + - name: Place Builds + uses: actions/download-artifact@v4 + with: + name: build + path: ./build + + - name: Install Node + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Install pnpm + uses: pnpm/action-setup@v4 + + - name: Install Yarn + run: | + npm i -g yarn + yarn set version stable + + - name: Smoke Test + run: npm run test.smoke diff --git a/.gitignore b/.gitignore index be2af693..7b3bcd27 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,7 @@ tsconfig.*.tsbuildinfo !/lib/load-addon.js !/lib/load-addon.js.map -compile_commands.json \ No newline at end of file +compile_commands.json + +/smoke-test-* +/*.tgz diff --git a/package.json b/package.json index 1c74d845..0f7c85fc 100644 --- a/package.json +++ b/package.json @@ -99,6 +99,7 @@ "build": "run-p build.js build.native", "build.debug": "run-s build.js build.native.debug", "test": "run-s clean.temp build && mocha", + "test.smoke": "bash ./script/smoke-test.bash", "test.skip_gc_tests": "run-s clean.temp build.debug && cross-env SKIP_GC_TESTS=true mocha", "test.electron.main": "run-s clean.temp build && electron-mocha", "format": "run-s format.prettier format.clang-format", diff --git a/script/smoke-test.bash b/script/smoke-test.bash new file mode 100755 index 00000000..ee293390 --- /dev/null +++ b/script/smoke-test.bash @@ -0,0 +1,37 @@ +#!/usr/bin/bash +set -ev +set -o pipefail + +echo "Pack zeromq.js" +version=$(npm pkg get version | tr -d '"') +pack_name="zeromq-${version}.tgz" +rm -f "${pack_name}" +npm pack + +init_smoke_test() { + local pm=$1 + echo "Init Smoke Test Project ${pm}" + + rm -rf "./smoke-test-${pm}" + mkdir "./smoke-test-${pm}" + cd "./smoke-test-${pm}" + npm init -q --init-module "smoke-test-${pm}" -y + npm pkg set dependencies.zeromq="file:../${pack_name}" +} + +package_managers=(npm pnpm yarn) + +for pm in "${package_managers[@]}"; do + init_smoke_test "${pm}" + + echo "Install with ${pm}" + ${pm} install + + echo "Require zeromq" + node -e "console.log(require('zeromq'))" + + cd ../ + rm -rf "./smoke-test-${pm}" +done + +rm -f "${pack_name}" diff --git a/src/module.cc b/src/module.cc index 1c854f53..554d7225 100644 --- a/src/module.cc +++ b/src/module.cc @@ -1,8 +1,8 @@ -#include - #include "./module.h" +#include + #include "./context.h" #include "./observer.h" #include "./outgoing_msg.h" diff --git a/src/outgoing_msg.cc b/src/outgoing_msg.cc index 75bf7355..64c80fc5 100644 --- a/src/outgoing_msg.cc +++ b/src/outgoing_msg.cc @@ -2,6 +2,7 @@ #include "./outgoing_msg.h" #include + #include "./module.h" #include "util/error.h" diff --git a/src/poller.h b/src/poller.h index cbeb8088..132f83a9 100644 --- a/src/poller.h +++ b/src/poller.h @@ -23,8 +23,8 @@ class Poller { /* Initialize the poller with the given file descriptor. FD should be ZMQ style edge-triggered, with READABLE state indicating that ANY event may be present on the corresponding ZMQ socket. */ - int32_t Initialize( - Napi::Env env, uv_os_sock_t& file_descriptor, std::function finalizer = nullptr) { + int32_t Initialize(Napi::Env env, uv_os_sock_t& file_descriptor, + std::function finalizer = nullptr) { auto* loop = UvLoop(env); poll->data = this; From 1df5e05aeacd3c1661e6d4dd8c15effcd10c8a9c Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 24 Oct 2024 19:05:21 -0700 Subject: [PATCH 02/21] ci: specify pnpm version as the package manager --- .github/workflows/CI.yml | 2 -- package.json | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index b0415d56..7c09ddc0 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -107,8 +107,6 @@ jobs: - uses: pnpm/action-setup@v4 if: ${{ !matrix.docker }} - with: - version: 9 - name: Install Node 20 if: ${{ !matrix.docker }} diff --git a/package.json b/package.json index 0f7c85fc..06c110d9 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "node-gyp": "10.0.1" } }, + "packageManager": "pnpm@9.12.1", "engines": { "node": ">= 10", "pnpm": ">= 9" From 2dd7663ce11aab979cec00f1c3c5072fe775c818 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 25 Oct 2024 18:31:27 -0700 Subject: [PATCH 03/21] ci: checkout the repo for smoke test --- .github/workflows/CI.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7c09ddc0..ed86a680 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -214,6 +214,8 @@ jobs: - 10 - 22 steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 - name: Place Builds From 86f11f954b9a0659be07ca8c18daabd480d778d8 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 25 Oct 2024 19:25:14 -0700 Subject: [PATCH 04/21] ci: avoid yarn install failures --- .github/workflows/CI.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ed86a680..d29f8d93 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -214,10 +214,6 @@ jobs: - 10 - 22 steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4 - - name: Place Builds uses: actions/download-artifact@v4 with: @@ -229,13 +225,15 @@ jobs: with: node-version: ${{ matrix.node-version }} - - name: Install pnpm - uses: pnpm/action-setup@v4 - - name: Install Yarn run: | npm i -g yarn yarn set version stable + - uses: actions/checkout@v4 + + - name: Install pnpm + uses: pnpm/action-setup@v4 + - name: Smoke Test run: npm run test.smoke From de453d8b187c0abe7c90671083d8282cafc0214b Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 25 Oct 2024 19:46:28 -0700 Subject: [PATCH 05/21] ci: install yarn@2, pnpm@5 for testing Node 10 --- .github/workflows/CI.yml | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d29f8d93..5187829e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -225,15 +225,29 @@ jobs: with: node-version: ${{ matrix.node-version }} - - name: Install Yarn + - name: Install Yarn 2 + if: matrix.node-version == 10 run: | - npm i -g yarn - yarn set version stable + npm i -g yarn@^2 - - uses: actions/checkout@v4 + - name: Install Yarn Latest + if: matrix.node-version == 22 + run: | + npm i -g yarn@latest + + - name: Install Pnpm 5 + if: matrix.node-version == 10 + uses: pnpm/action-setup@v4 + with: + version: 5 - - name: Install pnpm + - name: Install Pnpm 9 + if: matrix.node-version == 22 uses: pnpm/action-setup@v4 + with: + version: 9 + + - uses: actions/checkout@v4 - name: Smoke Test run: npm run test.smoke From 730496901fd0dd7fad2fc1c8aed1c1788912fedc Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 25 Oct 2024 20:09:51 -0700 Subject: [PATCH 06/21] ci: download the lib from artifacts --- .github/workflows/CI.yml | 18 ++++++++++++++++-- package.json | 2 -- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 5187829e..035e0dd1 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -155,13 +155,21 @@ jobs: docker tag ${{ matrix.docker }} builder docker run --volume ${{ github.workspace }}:/app --workdir /app --privileged builder sh -c "${{ matrix.docker_cmd }}" - - name: Upload artifacts + - name: Upload build uses: actions/upload-artifact@v4 with: path: ./build name: build-${{ strategy.job-index }} overwrite: true + - name: Upload lib + if: matrix.os == 'ubuntu-20.04' + uses: actions/upload-artifact@v4 + with: + path: ./lib + name: lib + overwrite: true + - name: Lint if: "${{ contains(matrix.os, 'ubuntu') && !matrix.docker }}" run: pnpm run lint-test @@ -214,12 +222,18 @@ jobs: - 10 - 22 steps: - - name: Place Builds + - name: Place build uses: actions/download-artifact@v4 with: name: build path: ./build + - name: Place lib + uses: actions/download-artifact@v4 + with: + name: lib + path: ./lib + - name: Install Node uses: actions/setup-node@v4 with: diff --git a/package.json b/package.json index 06c110d9..8ffba347 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,6 @@ ], "scripts": { "install": "node ./script/install.js", - "prepare": "pnpm run build.js", "clean": "shx rm -rf ./build ./prebuilds && run-p clean.lib clean.temp", "clean.lib": "shx rm -rf ./lib/", "clean.release": "shx rm -rf ./build/Release", @@ -113,7 +112,6 @@ "lint": "run-p format lint.eslint format", "lint-test": "run-s lint-test.eslint", "bench": "node --expose-gc test/bench", - "prepublishOnly": "pnpm run build.js", "bump": "pnpx npm-check-updates -u -x typescript,eslint,chai && pnpx typesync && pnpm update" }, "cmake-ts": { From 69139376655ed0c6d8fcd6a4129074d3b0e04a8b Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 25 Oct 2024 20:49:42 -0700 Subject: [PATCH 07/21] fix: pack zeromq on the main CI --- .github/workflows/CI.yml | 17 +++++++++++------ package.json | 1 + script/smoke-test.bash | 5 ++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 035e0dd1..19c32d4e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -162,12 +162,17 @@ jobs: name: build-${{ strategy.job-index }} overwrite: true - - name: Upload lib + - name: Pack Zeromq + if: matrix.os == 'ubuntu-20.04' + run: | + pnpm pack + + - name: Upload Pack if: matrix.os == 'ubuntu-20.04' uses: actions/upload-artifact@v4 with: - path: ./lib - name: lib + path: ./*.tgz + name: pack overwrite: true - name: Lint @@ -228,11 +233,11 @@ jobs: name: build path: ./build - - name: Place lib + - name: Place Pack uses: actions/download-artifact@v4 with: - name: lib - path: ./lib + name: pack + path: ./ - name: Install Node uses: actions/setup-node@v4 diff --git a/package.json b/package.json index 8ffba347..cd350a9a 100644 --- a/package.json +++ b/package.json @@ -112,6 +112,7 @@ "lint": "run-p format lint.eslint format", "lint-test": "run-s lint-test.eslint", "bench": "node --expose-gc test/bench", + "prepublishOnly": "pnpm run build.js", "bump": "pnpx npm-check-updates -u -x typescript,eslint,chai && pnpx typesync && pnpm update" }, "cmake-ts": { diff --git a/script/smoke-test.bash b/script/smoke-test.bash index ee293390..25f6894a 100755 --- a/script/smoke-test.bash +++ b/script/smoke-test.bash @@ -2,11 +2,10 @@ set -ev set -o pipefail -echo "Pack zeromq.js" +echo "Pack zeromq.js if needed" version=$(npm pkg get version | tr -d '"') pack_name="zeromq-${version}.tgz" -rm -f "${pack_name}" -npm pack +test -f "${pack_name}" || npm pack init_smoke_test() { local pm=$1 From 00fcbb7cc8e2471f5eb771b144ae3895dbeec6cb Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 25 Oct 2024 22:01:02 -0700 Subject: [PATCH 08/21] ci: run smoke test script directly --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 19c32d4e..ef795b85 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -269,4 +269,4 @@ jobs: - uses: actions/checkout@v4 - name: Smoke Test - run: npm run test.smoke + run: bash ./script/smoke-test.bash From 1af6c6fcbbe9c9f3adf7777a587b9e110138088b Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 25 Oct 2024 23:00:44 -0700 Subject: [PATCH 09/21] ci: ensure lib files are in the zeromq pack --- .github/workflows/CI.yml | 1 + package.json | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ef795b85..1d9456a8 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -165,6 +165,7 @@ jobs: - name: Pack Zeromq if: matrix.os == 'ubuntu-20.04' run: | + pnpm run build.js pnpm pack - name: Upload Pack diff --git a/package.json b/package.json index cd350a9a..8ffba347 100644 --- a/package.json +++ b/package.json @@ -112,7 +112,6 @@ "lint": "run-p format lint.eslint format", "lint-test": "run-s lint-test.eslint", "bench": "node --expose-gc test/bench", - "prepublishOnly": "pnpm run build.js", "bump": "pnpx npm-check-updates -u -x typescript,eslint,chai && pnpx typesync && pnpm update" }, "cmake-ts": { From f1bbbb560aab5d5b237760a91436e31bcf786f32 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 26 Oct 2024 00:29:37 -0700 Subject: [PATCH 10/21] ci: pack zeromq in the package stage --- .github/workflows/CI.yml | 57 ++++++++++++++++++++++++---------------- .nvmrc | 1 + package.json | 1 + script/smoke-test.bash | 4 ++- 4 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 .nvmrc diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 1d9456a8..93430d1e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -162,20 +162,6 @@ jobs: name: build-${{ strategy.job-index }} overwrite: true - - name: Pack Zeromq - if: matrix.os == 'ubuntu-20.04' - run: | - pnpm run build.js - pnpm pack - - - name: Upload Pack - if: matrix.os == 'ubuntu-20.04' - uses: actions/upload-artifact@v4 - with: - path: ./*.tgz - name: pack - overwrite: true - - name: Lint if: "${{ contains(matrix.os, 'ubuntu') && !matrix.docker }}" run: pnpm run lint-test @@ -202,7 +188,7 @@ jobs: xvfb-run --auto-servernum pnpm run test.electron.main continue-on-error: true - MergeBuild: + Package: runs-on: ubuntu-latest needs: Build steps: @@ -213,9 +199,40 @@ jobs: pattern: build-* delete-merged: true + - run: | + ls -R + + - uses: actions/checkout@v4 + + - name: Place build + uses: actions/download-artifact@v4 + with: + name: build + path: ./build + + - name: Install Node + uses: actions/setup-node@v4 + with: + node-version-file: "./.nvmrc" + + - name: Install Pnpm + uses: pnpm/action-setup@v4 + + - name: Pack Zeromq + run: | + pnpm install + pnpm pack + + - name: Upload Pack + uses: actions/upload-artifact@v4 + with: + path: ./*.tgz + name: pack + overwrite: true + SmokeTest: runs-on: ${{ matrix.os }} - needs: MergeBuild + needs: Package strategy: fail-fast: false matrix: @@ -228,13 +245,7 @@ jobs: - 10 - 22 steps: - - name: Place build - uses: actions/download-artifact@v4 - with: - name: build - path: ./build - - - name: Place Pack + - name: Download Pack uses: actions/download-artifact@v4 with: name: pack diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000..ec7ba0e9 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +22.10.0 diff --git a/package.json b/package.json index 8ffba347..cd350a9a 100644 --- a/package.json +++ b/package.json @@ -112,6 +112,7 @@ "lint": "run-p format lint.eslint format", "lint-test": "run-s lint-test.eslint", "bench": "node --expose-gc test/bench", + "prepublishOnly": "pnpm run build.js", "bump": "pnpx npm-check-updates -u -x typescript,eslint,chai && pnpx typesync && pnpm update" }, "cmake-ts": { diff --git a/script/smoke-test.bash b/script/smoke-test.bash index 25f6894a..d656466f 100755 --- a/script/smoke-test.bash +++ b/script/smoke-test.bash @@ -3,7 +3,7 @@ set -ev set -o pipefail echo "Pack zeromq.js if needed" -version=$(npm pkg get version | tr -d '"') +version=$(node -e 'console.log(require("./package.json").version)') pack_name="zeromq-${version}.tgz" test -f "${pack_name}" || npm pack @@ -26,6 +26,8 @@ for pm in "${package_managers[@]}"; do echo "Install with ${pm}" ${pm} install + ls -R ./node_modules/zeromq + echo "Require zeromq" node -e "console.log(require('zeromq'))" From bb0d9fba4e03843789084dbbec98900aa5d6023e Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 26 Oct 2024 01:16:52 -0700 Subject: [PATCH 11/21] ci: place the pack in the smoke test --- .github/workflows/CI.yml | 4 ---- script/smoke-test.bash | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 93430d1e..8888ccd0 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -199,9 +199,6 @@ jobs: pattern: build-* delete-merged: true - - run: | - ls -R - - uses: actions/checkout@v4 - name: Place build @@ -249,7 +246,6 @@ jobs: uses: actions/download-artifact@v4 with: name: pack - path: ./ - name: Install Node uses: actions/setup-node@v4 diff --git a/script/smoke-test.bash b/script/smoke-test.bash index d656466f..26a209cc 100755 --- a/script/smoke-test.bash +++ b/script/smoke-test.bash @@ -15,7 +15,7 @@ init_smoke_test() { mkdir "./smoke-test-${pm}" cd "./smoke-test-${pm}" npm init -q --init-module "smoke-test-${pm}" -y - npm pkg set dependencies.zeromq="file:../${pack_name}" + npm pkg set dependencies.zeromq="file:../${pack_name}" || (jq '.dependencies.zeromq = "file:../${pack_name}"' package.json >temp.json && mv temp.json package.json) } package_managers=(npm pnpm yarn) From 1257c49b7037727fb186177dde42c47a2070f562 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 26 Oct 2024 02:11:57 -0700 Subject: [PATCH 12/21] ci: smoke test only on node 22 --- .github/workflows/CI.yml | 2 +- script/smoke-test.bash | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 8888ccd0..9a164506 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -239,7 +239,7 @@ jobs: - macos-14 - macos-13 node-version: - - 10 + # - 10 - 22 steps: - name: Download Pack diff --git a/script/smoke-test.bash b/script/smoke-test.bash index 26a209cc..9610ea37 100755 --- a/script/smoke-test.bash +++ b/script/smoke-test.bash @@ -5,7 +5,8 @@ set -o pipefail echo "Pack zeromq.js if needed" version=$(node -e 'console.log(require("./package.json").version)') pack_name="zeromq-${version}.tgz" -test -f "${pack_name}" || npm pack +echo "${pack_name}" +test -f "${pack_name}" || ls -R init_smoke_test() { local pm=$1 @@ -26,8 +27,6 @@ for pm in "${package_managers[@]}"; do echo "Install with ${pm}" ${pm} install - ls -R ./node_modules/zeromq - echo "Require zeromq" node -e "console.log(require('zeromq'))" From 9b8f85fe813a853aea2d8bb7eb590d79239c4827 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 26 Oct 2024 02:57:23 -0700 Subject: [PATCH 13/21] ci: download pack after checkout + enable node 10 --- .github/workflows/CI.yml | 17 ++++++++++------- script/smoke-test.bash | 6 +++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 9a164506..f68b73f5 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -236,17 +236,15 @@ jobs: os: - ubuntu-24.04 - windows-2022 - - macos-14 - macos-13 node-version: - # - 10 + - 10 - 22 - steps: - - name: Download Pack - uses: actions/download-artifact@v4 - with: - name: pack + include: + - os: macos-14 + node-version: 22 + steps: - name: Install Node uses: actions/setup-node@v4 with: @@ -276,5 +274,10 @@ jobs: - uses: actions/checkout@v4 + - name: Download Pack + uses: actions/download-artifact@v4 + with: + name: pack + - name: Smoke Test run: bash ./script/smoke-test.bash diff --git a/script/smoke-test.bash b/script/smoke-test.bash index 9610ea37..36a791aa 100755 --- a/script/smoke-test.bash +++ b/script/smoke-test.bash @@ -6,7 +6,7 @@ echo "Pack zeromq.js if needed" version=$(node -e 'console.log(require("./package.json").version)') pack_name="zeromq-${version}.tgz" echo "${pack_name}" -test -f "${pack_name}" || ls -R +test -f "${pack_name}" || npm pack init_smoke_test() { local pm=$1 @@ -15,8 +15,8 @@ init_smoke_test() { rm -rf "./smoke-test-${pm}" mkdir "./smoke-test-${pm}" cd "./smoke-test-${pm}" - npm init -q --init-module "smoke-test-${pm}" -y - npm pkg set dependencies.zeromq="file:../${pack_name}" || (jq '.dependencies.zeromq = "file:../${pack_name}"' package.json >temp.json && mv temp.json package.json) + npm init -y + npm pkg set dependencies.zeromq="file:../${pack_name}" || (jq ".dependencies.zeromq = \"file:../${pack_name}\"" package.json >temp.json && mv temp.json package.json) } package_managers=(npm pnpm yarn) From 5ab0a3804df26435b42cca3965299cd80aee7c1a Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 26 Oct 2024 20:33:44 -0700 Subject: [PATCH 14/21] chore: run prepare before packing --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cd350a9a..4268488b 100644 --- a/package.json +++ b/package.json @@ -112,7 +112,7 @@ "lint": "run-p format lint.eslint format", "lint-test": "run-s lint-test.eslint", "bench": "node --expose-gc test/bench", - "prepublishOnly": "pnpm run build.js", + "prepare": "pnpm run build.js", "bump": "pnpx npm-check-updates -u -x typescript,eslint,chai && pnpx typesync && pnpm update" }, "cmake-ts": { From eef0e50bb802f0be6f97c1eff74528fae360169a Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 26 Oct 2024 20:34:11 -0700 Subject: [PATCH 15/21] fix: allow installation with yarn --- .github/workflows/CI.yml | 4 ++++ package.json | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index f68b73f5..a1502f4c 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -107,6 +107,8 @@ jobs: - uses: pnpm/action-setup@v4 if: ${{ !matrix.docker }} + with: + version: 9 - name: Install Node 20 if: ${{ !matrix.docker }} @@ -214,6 +216,8 @@ jobs: - name: Install Pnpm uses: pnpm/action-setup@v4 + with: + version: 9 - name: Pack Zeromq run: | diff --git a/package.json b/package.json index 4268488b..09ed1f99 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,6 @@ "node-gyp": "10.0.1" } }, - "packageManager": "pnpm@9.12.1", "engines": { "node": ">= 10", "pnpm": ">= 9" From faded66191b26b87178bd3ce482c6bbde113c262 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 26 Oct 2024 20:45:25 -0700 Subject: [PATCH 16/21] test: create the smoke test dirs outside the repo --- script/smoke-test.bash | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/script/smoke-test.bash b/script/smoke-test.bash index 36a791aa..49086243 100755 --- a/script/smoke-test.bash +++ b/script/smoke-test.bash @@ -2,21 +2,23 @@ set -ev set -o pipefail +root="${PWD}" + echo "Pack zeromq.js if needed" version=$(node -e 'console.log(require("./package.json").version)') -pack_name="zeromq-${version}.tgz" -echo "${pack_name}" -test -f "${pack_name}" || npm pack +pack_path="${root}/zeromq-${version}.tgz" +test -f "${pack_path}" || npm pack + init_smoke_test() { local pm=$1 echo "Init Smoke Test Project ${pm}" - rm -rf "./smoke-test-${pm}" - mkdir "./smoke-test-${pm}" - cd "./smoke-test-${pm}" + rm -rf "../zeromq-smoke-test-${pm}" + mkdir "../zeromq-smoke-test-${pm}" + cd "../zeromq-smoke-test-${pm}" npm init -y - npm pkg set dependencies.zeromq="file:../${pack_name}" || (jq ".dependencies.zeromq = \"file:../${pack_name}\"" package.json >temp.json && mv temp.json package.json) + npm pkg set dependencies.zeromq="file:${pack_path}" || (jq ".dependencies.zeromq = \"file:${pack_path}\"" package.json >temp.json && mv temp.json package.json) } package_managers=(npm pnpm yarn) @@ -30,8 +32,8 @@ for pm in "${package_managers[@]}"; do echo "Require zeromq" node -e "console.log(require('zeromq'))" - cd ../ - rm -rf "./smoke-test-${pm}" + cd "${root}" + rm -rf "../zeromq-smoke-test-${pm}" done -rm -f "${pack_name}" +rm -f "${pack_path}" From 14e9c5e7593fd79e01960c277b0a5599982f78c2 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 26 Oct 2024 02:18:17 -0700 Subject: [PATCH 17/21] fix: use import for loading the addon --- lib/load-addon.js | 3 ++- lib/load-addon.js.map | 2 +- src/load-addon.ts | 3 ++- src/native.ts | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/load-addon.js b/lib/load-addon.js index afc1bd24..d620a3fa 100644 --- a/lib/load-addon.js +++ b/lib/load-addon.js @@ -47,5 +47,6 @@ function findAddon() { } return addon; } -module.exports = findAddon(); +const addon = findAddon(); +exports.default = addon; //# sourceMappingURL=load-addon.js.map \ No newline at end of file diff --git a/lib/load-addon.js.map b/lib/load-addon.js.map index 9a4154ad..69adb3ae 100644 --- a/lib/load-addon.js.map +++ b/lib/load-addon.js.map @@ -1 +1 @@ -{"version":3,"file":"load-addon.js","sourceRoot":"","sources":["../src/load-addon.ts"],"names":[],"mappings":";;;;;AAAA,gDAAuB;AACvB,4CAAmB;AAEnB,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,KAAK,YAAY,KAAK;QAC3B,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,KAAK,EAAE;QACnD,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACnB,CAAC;AAED,SAAS,OAAO,CAAC,OAAe;IAC9B,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;KACtB;AACH,CAAC;AAED,SAAS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ACN;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAI,YAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;oBAC5B,OAAO,CACL,2BAA2B,SAAS,KAAK,MAAM,CAAC,GAAG,CAAC,oBAAoB,CACzE,CAAA;iBACF;qBAAM;oBACL,OAAO,CAAC,0BAA0B,SAAS,oBAAoB,CAAC,CAAA;iBACjE;aACF;SACF;KACF;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,wCAAwC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;KACvE;IAED,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;KACvD;IAED,OAAO,KAAK,CAAA;AACd,CAAC;AAED,MAAM,KAAK,GAAG,SAAS,EAAE,CAAA;AACzB,kBAAe,KAAK,CAAA"} \ No newline at end of file diff --git a/src/load-addon.ts b/src/load-addon.ts index 3cd5a9c0..1a882c63 100644 --- a/src/load-addon.ts +++ b/src/load-addon.ts @@ -57,4 +57,5 @@ function findAddon(): any | undefined { return addon } -module.exports = findAddon() +const addon = findAddon() +export default addon diff --git a/src/native.ts b/src/native.ts index 4dbc3aae..8f9c1f0b 100644 --- a/src/native.ts +++ b/src/native.ts @@ -1,7 +1,8 @@ /* eslint-disable @typescript-eslint/no-var-requires */ /* Declare all native C++ classes and methods in this file. */ -module.exports = require("./load-addon") +import addon from "./load-addon" +module.exports = addon /** * The version of the ØMQ library the bindings were built with. Formatted as From 9516f77d2c35650a6f1f2d925715068e45cea6b1 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 26 Oct 2024 02:19:26 -0700 Subject: [PATCH 18/21] test: run type-checking in the lint --- .vscode/settings.json | 16 +++++++++++++++- package.json | 6 ++++-- test/tsconfig.json | 10 +++++++++- tsconfig.json | 6 +----- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4746bdc2..350f941b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,21 @@ { + "[typescript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[javascript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[json]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[jsonc]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, "mochaExplorer.parallel": true, "mochaExplorer.globImplementation": "vscode", - "mochaExplorer.nodeArgv": ["--expose-gc"], + "mochaExplorer.nodeArgv": [ + "--expose-gc" + ], "mochaExplorer.debuggerConfig": "JS-Attach", "files.exclude": { "**/.DS_Store": true, diff --git a/package.json b/package.json index 09ed1f99..f1f2c06f 100644 --- a/package.json +++ b/package.json @@ -102,13 +102,15 @@ "test.skip_gc_tests": "run-s clean.temp build.debug && cross-env SKIP_GC_TESTS=true mocha", "test.electron.main": "run-s clean.temp build && electron-mocha", "format": "run-s format.prettier format.clang-format", - "format.prettier": "prettier --write .", + "format.prettier": "prettier -l --cache --cache-location ./.cache/prettier --write .", "format.clang-format": "clang-format -i -style=file ./src/*.cc ./src/*.h ./src/util/*.h", "test.electron.renderer": "run-s build && electron-mocha --renderer", "lint-test.eslint": "eslint ./**/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/", "lint.eslint": "pnpm run lint-test.eslint --fix", + "lint.tsc": "tsc --noEmit -p ./src/tsconfig.json", + "lint.tsc-test": "tsc --noEmit -p ./test/tsconfig.json", "lint.clang-tidy": "git ls-files --exclude-standard | grep -E '\\.(cpp|hpp|c|cc|cxx|hxx|h|ixx)$' | xargs -n 1 -P $(nproc) clang-tidy", - "lint": "run-p format lint.eslint format", + "lint": "run-p lint.tsc-test lint.tsc lint.eslint format", "lint-test": "run-s lint-test.eslint", "bench": "node --expose-gc test/bench", "prepare": "pnpm run build.js", diff --git a/test/tsconfig.json b/test/tsconfig.json index e516b7fa..b5bce5fa 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -1,4 +1,12 @@ { "extends": "../tsconfig.json", - "include": ["**/*.ts"] + "include": ["**/*.ts"], + "compilerOptions": { + "skipLibCheck": true, + "lib": [ + "ES2020", + // only used in tests + "ES2021.WeakRef" + ] + } } diff --git a/tsconfig.json b/tsconfig.json index 86dcaddd..5f6b4dde 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,10 +19,6 @@ "incremental": true, "sourceMap": true, "esModuleInterop": true, - "lib": [ - "ES2020", - // only used in tests - "ES2021.WeakRef" - ] + "lib": ["ES2020"] } } From bbe216b48b374b7bfac13466fe43ff883eeaab3b Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 26 Oct 2024 21:19:27 -0700 Subject: [PATCH 19/21] test: fix the smoke test on Windows --- script/smoke-test.bash | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/script/smoke-test.bash b/script/smoke-test.bash index 49086243..0019cc90 100755 --- a/script/smoke-test.bash +++ b/script/smoke-test.bash @@ -6,25 +6,21 @@ root="${PWD}" echo "Pack zeromq.js if needed" version=$(node -e 'console.log(require("./package.json").version)') -pack_path="${root}/zeromq-${version}.tgz" -test -f "${pack_path}" || npm pack - - -init_smoke_test() { - local pm=$1 - echo "Init Smoke Test Project ${pm}" - - rm -rf "../zeromq-smoke-test-${pm}" - mkdir "../zeromq-smoke-test-${pm}" - cd "../zeromq-smoke-test-${pm}" - npm init -y - npm pkg set dependencies.zeromq="file:${pack_path}" || (jq ".dependencies.zeromq = \"file:${pack_path}\"" package.json >temp.json && mv temp.json package.json) -} +pack_name="zeromq-${version}.tgz" +test -f "./${pack_name}" || npm pack package_managers=(npm pnpm yarn) for pm in "${package_managers[@]}"; do - init_smoke_test "${pm}" + dir="../zeromq-smoke-test-${pm}" + + echo "Init Smoke Test Project ${pm}" + rm -rf "${dir}" + mkdir "${dir}" + cp "./${pack_name}" "${dir}" + cd "${dir}" + npm init -y + npm pkg set dependencies.zeromq="file:./${pack_name}" || (jq ".dependencies.zeromq = \"file:./${pack_name}\"" package.json >temp.json && mv temp.json package.json) echo "Install with ${pm}" ${pm} install @@ -36,4 +32,4 @@ for pm in "${package_managers[@]}"; do rm -rf "../zeromq-smoke-test-${pm}" done -rm -f "${pack_path}" +rm -f "${pack_name}" From 1a9e232eeb8f550b8e51f67206f3027edd50de9e Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 26 Oct 2024 21:20:11 -0700 Subject: [PATCH 20/21] test: use yarn 1 for the old smoke test --- .github/workflows/CI.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a1502f4c..22b8a100 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -254,10 +254,10 @@ jobs: with: node-version: ${{ matrix.node-version }} - - name: Install Yarn 2 + - name: Install Yarn 1 if: matrix.node-version == 10 run: | - npm i -g yarn@^2 + npm i -g yarn@^1 - name: Install Yarn Latest if: matrix.node-version == 22 From d448f41b6de68c81a791ce2e42c8114b6749191c Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 26 Oct 2024 21:43:31 -0700 Subject: [PATCH 21/21] test: ignore engines when testing yarn --- script/smoke-test.bash | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/script/smoke-test.bash b/script/smoke-test.bash index 0019cc90..5f791b54 100755 --- a/script/smoke-test.bash +++ b/script/smoke-test.bash @@ -23,7 +23,11 @@ for pm in "${package_managers[@]}"; do npm pkg set dependencies.zeromq="file:./${pack_name}" || (jq ".dependencies.zeromq = \"file:./${pack_name}\"" package.json >temp.json && mv temp.json package.json) echo "Install with ${pm}" - ${pm} install + if [[ "${pm}" == "yarn" ]]; then + yarn install --ignore-engines + else + ${pm} install + fi echo "Require zeromq" node -e "console.log(require('zeromq'))"