diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c96fead6..22b8a100 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -157,7 +157,7 @@ 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 @@ -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: + + Package: runs-on: ubuntu-latest needs: Build steps: @@ -199,3 +200,88 @@ jobs: name: build pattern: build-* delete-merged: true + + - 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 + with: + version: 9 + + - 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: Package + strategy: + fail-fast: false + matrix: + os: + - ubuntu-24.04 + - windows-2022 + - macos-13 + node-version: + - 10 + - 22 + + include: + - os: macos-14 + node-version: 22 + steps: + - name: Install Node + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Install Yarn 1 + if: matrix.node-version == 10 + run: | + npm i -g yarn@^1 + + - 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 9 + if: matrix.node-version == 22 + uses: pnpm/action-setup@v4 + with: + version: 9 + + - 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/.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/.nvmrc b/.nvmrc new file mode 100644 index 00000000..ec7ba0e9 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +22.10.0 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/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,KA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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,CAAC,OAAO,GAAG,SAAS,EAAE,CAAA"} \ No newline at end of file +{"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,SAAS;IAChB,IAAI,KAAK,GAAoB,SAAS,CAAA;IACtC,IAAI;QACF,MAAM,cAAc,GAAG,cAAI,CAAC,OAAO,CACjC,cAAI,CAAC,IAAI,CACP,SAAS,EACT,IAAI,EACJ,OAAO,EACP,OAAO,CAAC,QAAQ,EAChB,OAAO,CAAC,IAAI,EACZ,MAAM,CACP,CACF,CAAA;QACD,MAAM,YAAY,GAAG,YAAE,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YAChE,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;QACxD,CAAC,CAAC,CAAA;QAEF,+BAA+B;QAC/B,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE;YACtC,MAAM,SAAS,GAAG,cAAI,CAAC,IAAI,CAAC,cAAc,EAAE,WAAW,EAAE,YAAY,CAAC,CAAA;YACtE,IAAI;gBACF,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;gBAC1B,MAAK;aACN;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/package.json b/package.json index 1c74d845..f1f2c06f 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,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", @@ -99,19 +98,22 @@ "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", - "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", - "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": { diff --git a/script/smoke-test.bash b/script/smoke-test.bash new file mode 100755 index 00000000..5f791b54 --- /dev/null +++ b/script/smoke-test.bash @@ -0,0 +1,39 @@ +#!/usr/bin/bash +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" +test -f "./${pack_name}" || npm pack + +package_managers=(npm pnpm yarn) + +for pm in "${package_managers[@]}"; do + 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}" + if [[ "${pm}" == "yarn" ]]; then + yarn install --ignore-engines + else + ${pm} install + fi + + echo "Require zeromq" + node -e "console.log(require('zeromq'))" + + cd "${root}" + rm -rf "../zeromq-smoke-test-${pm}" +done + +rm -f "${pack_name}" 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/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/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 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; 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"] } }