Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add node test for checking exported symbols #2835

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
62abaea
Add node test for checking exported symbols
prateek-kumar-improving Dec 18, 2024
9bfb65d
Add package.json.tmpl file
prateek-kumar-improving Dec 18, 2024
be79255
Fix formatting
prateek-kumar-improving Dec 18, 2024
1df6ec1
formatting fixed
prateek-kumar-improving Dec 18, 2024
cb320e2
Formatting fixed
prateek-kumar-improving Dec 18, 2024
540180f
Fix formatting
prateek-kumar-improving Dec 18, 2024
c2cbf13
Formatting fixed
prateek-kumar-improving Dec 18, 2024
77c6c1c
Node: Change log updated
prateek-kumar-improving Dec 18, 2024
2d100ee
Node: Add npm install
prateek-kumar-improving Jan 14, 2025
7d9ae5a
Node: update changelog.md
prateek-kumar-improving Jan 14, 2025
d7c4254
Node: Add changelog.md
prateek-kumar-improving Jan 14, 2025
cd67e1c
Node: update workflow
prateek-kumar-improving Jan 14, 2025
def5619
Node: Update workflow
prateek-kumar-improving Jan 14, 2025
522fed8
Node: Update workflow
prateek-kumar-improving Jan 14, 2025
479f6a9
Merge branch 'main' into node-exports-check-new
prateek-kumar-improving Jan 14, 2025
59524ee
Merge branch 'main' into node-exports-check-new
prateek-kumar-improving Jan 22, 2025
5e04970
Node: npm/glide package json created
prateek-kumar-improving Jan 22, 2025
8c43948
Node: npm/glide package json created
prateek-kumar-improving Jan 22, 2025
5013e66
Node: npm/glide package json created
prateek-kumar-improving Jan 22, 2025
f35176c
Node: npm/glide package json created
prateek-kumar-improving Jan 22, 2025
ef4ca6e
Node: npm/glide package json created
prateek-kumar-improving Jan 22, 2025
6cdcddf
Node: npm/glide package json created
prateek-kumar-improving Jan 22, 2025
212e367
Node: npm/glide package json created
prateek-kumar-improving Jan 22, 2025
03f2023
Node: npm/glide package json created
prateek-kumar-improving Jan 22, 2025
35602e0
Node: npm/glide package json created
prateek-kumar-improving Jan 22, 2025
ebd30f4
Node: npm/glide package json created
prateek-kumar-improving Jan 22, 2025
a8f4a12
Node: npm/glide package json created
prateek-kumar-improving Jan 22, 2025
d8fc4b9
Node: npm/glide package json created
prateek-kumar-improving Jan 22, 2025
4d92a5d
Node: update workflow
prateek-kumar-improving Jan 24, 2025
a2bf0f1
Node: update workflow
prateek-kumar-improving Jan 24, 2025
8cbfbe9
Node: update workflow
prateek-kumar-improving Jan 24, 2025
23d4df3
Update DEVELOPER.md and README.md files
prateek-kumar-improving Jan 27, 2025
71a3939
Fix formatting
prateek-kumar-improving Jan 27, 2025
4c8ca4b
Fix formatting
prateek-kumar-improving Jan 27, 2025
ffb231e
package.json.tmpl file removed
prateek-kumar-improving Jan 27, 2025
42fa269
Updated env variables
prateek-kumar-improving Jan 27, 2025
481ec1d
Node update formatting
prateek-kumar-improving Jan 27, 2025
1365fb6
Node update formatting
prateek-kumar-improving Jan 27, 2025
242103e
Node update formatting
prateek-kumar-improving Jan 27, 2025
5828ee9
Node update formatting
prateek-kumar-improving Jan 27, 2025
297db5b
Node: index.ts updated
prateek-kumar-improving Jan 29, 2025
390e9ad
Node: index.ts updated
prateek-kumar-improving Jan 29, 2025
caca266
Node: Review comments updated
prateek-kumar-improving Jan 29, 2025
1242f69
Node: fix test case
prateek-kumar-improving Jan 29, 2025
8fe390e
Node: fix formatting
prateek-kumar-improving Jan 29, 2025
0f07070
Node: Fix formatting
prateek-kumar-improving Jan 29, 2025
f5545d2
Merge branch 'main' into node-exports-check-new
prateek-kumar-improving Jan 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,32 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
engine-version: ${{ matrix.engine.version }}

- name: Run npm install in ./npm/glide package
run: |
export pkg_name=valkey-glide
echo "The workflow is: ${{env.EVENT_NAME}}"
if ${{ env.EVENT_NAME == 'workflow_dispatch' }}; then
R_VERSION="${{ env.INPUT_VERSION }}"
else
R_VERSION=${GITHUB_REF:11}
fi
echo "RELEASE_VERSION=${R_VERSION}" >> $GITHUB_ENV
export arch="${{ matrix.host.ARCH }}"
export named_os="${{ matrix.host.NAMED_OS }}"
export package_version=${R_VERSION}
export scope=`if [ "$NPM_SCOPE" != '' ]; then echo "$NPM_SCOPE/"; fi`
envsubst < package.json.temp > "package.json"
cat package.json
# Fix index.ts based on the scope variable
# sed -i "s/\@scope/${scope}/g" index.ts
sed -i "s|@scope/|${scope}|g" index.ts
npm install
env:
NPM_SCOPE: ${{ vars.NPM_SCOPE }}
EVENT_NAME: ${{ github.event_name }}
INPUT_VERSION: ${{ github.event.inputs.version }}
working-directory: ./node/npm/glide

- name: test
run: npm test
working-directory: ./node
Expand Down
44 changes: 22 additions & 22 deletions node/DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Software Dependencies

If your Nodejs version is below the supported version specified in the client's [documentation](https://github.com/valkey-io/valkey-glide/blob/main/node/README.md#nodejs-supported-version), you can upgrade it using [NVM](https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script).

- npm
- git
- GCC
- pkg-config
- protoc (protobuf compiler)
- openssl
- openssl-dev
- rustup
- npm
prateek-kumar-improving marked this conversation as resolved.
Show resolved Hide resolved
- git
- GCC
- pkg-config
- protoc (protobuf compiler)
- openssl
- openssl-dev
- rustup

**Dependencies installation for Ubuntu**

Expand Down Expand Up @@ -107,16 +107,16 @@ Before starting this step, make sure you've installed all software requirments.
5. Integrating the built GLIDE package into your project:
Add the package to your project using the folder path with the command `npm install <path to GLIDE>/node`.

- For a fast build, execute `npm run build`. This will perform a full, unoptimized build, which is suitable for developing tests. Keep in mind that performance is significantly affected in an unoptimized build, so it's required to build with the `build:release` or `build:benchmark` option when measuring performance.
- If your modifications are limited to the TypeScript code, run `npm run build-external` to build the external package without rebuilding the internal package.
- If your modifications are limited to the Rust code, execute `npm run build-internal` to build the internal package and generate TypeScript code.
- To generate Node's protobuf files, execute `npm run build-protobuf`. Keep in mind that protobuf files are generated as part of full builds (e.g., `build`, `build:release`, etc.).
- For a fast build, execute `npm run build`. This will perform a full, unoptimized build, which is suitable for developing tests. Keep in mind that performance is significantly affected in an unoptimized build, so it's required to build with the `build:release` or `build:benchmark` option when measuring performance.
- If your modifications are limited to the TypeScript code, run `npm run build-external` to build the external package without rebuilding the internal package.
- If your modifications are limited to the Rust code, execute `npm run build-internal` to build the internal package and generate TypeScript code.
- To generate Node's protobuf files, execute `npm run build-protobuf`. Keep in mind that protobuf files are generated as part of full builds (e.g., `build`, `build:release`, etc.).

> Note: Once building completed, you'll find the compiled JavaScript code in the `node/build-ts` folder.

### Troubleshooting

- If the build fails after running `npx tsc` because `glide-rs` isn't found, check if your npm version is in the range 9.0.0-9.4.1, and if so, upgrade it. 9.4.2 contains a fix to a change introduced in 9.0.0 that is required in order to build the library.
- If the build fails after running `npx tsc` because `glide-rs` isn't found, check if your npm version is in the range 9.0.0-9.4.1, and if so, upgrade it. 9.4.2 contains a fix to a change introduced in 9.0.0 that is required in order to build the library.

### Test

Expand Down Expand Up @@ -202,13 +202,13 @@ Development on the Node wrapper may involve changes in either the TypeScript or

**TypeScript:**

- ESLint
- Prettier
- ESLint
- Prettier

**Rust:**

- clippy
- fmt
- clippy
- fmt

#### Running the linters

Expand All @@ -231,8 +231,8 @@ Development on the Node wrapper may involve changes in either the TypeScript or

### Recommended extensions for VS Code

- [Prettier - Code formatter](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) - JavaScript / TypeScript formatter.
- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) - linter.
- [Jest Runner](https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner) - in-editor test runner.
- [Jest Test Explorer](https://marketplace.visualstudio.com/items?itemName=kavod-io.vscode-jest-test-adapter) - adapter to the VSCode testing UI.
- [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) - Rust language support for VSCode.
- [Prettier - Code formatter](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) - JavaScript / TypeScript formatter.
- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) - linter.
- [Jest Runner](https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner) - in-editor test runner.
- [Jest Test Explorer](https://marketplace.visualstudio.com/items?itemName=kavod-io.vscode-jest-test-adapter) - adapter to the VSCode testing UI.
- [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) - Rust language support for VSCode.
8 changes: 4 additions & 4 deletions node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ The release of Valkey GLIDE was tested on the following platforms:

Linux:

- Ubuntu 22.04.1 (x86_64 and aarch64)
- Amazon Linux 2023 (AL2023) (x86_64)
- Ubuntu 22.04.1 (x86_64 and aarch64)
- Amazon Linux 2023 (AL2023) (x86_64)

macOS:

- macOS 14.7 (Apple silicon/aarch_64)
- macOS 14.7 (Apple silicon/aarch_64)

Alpine:

- node:alpine (default on aarch64 and x86_64)
- node:alpine (default on aarch64 and x86_64)

## NodeJS supported version

Expand Down
111 changes: 60 additions & 51 deletions node/npm/glide/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,73 @@ let globalObject = global as unknown;

/* eslint-disable @typescript-eslint/no-require-imports */
function loadNativeBinding() {
let nativeBinding = null;
let nativeStr = process.env.native_binding;

switch (platform) {
case "linux":
switch (arch) {
case "x64":
switch (familySync()) {
case GLIBC:
nativeBinding = require("@scope/valkey-glide-linux-x64");
break;
case MUSL:
nativeBinding = require("@scope/valkey-glide-linux-musl-x64");
break;
default:
nativeBinding = require("@scope/valkey-glide-linux-x64");
break;
}
if (nativeStr == undefined) {
switch (platform) {
case "linux":
switch (arch) {
case "x64":
switch (familySync()) {
case MUSL:
nativeStr = "linux-musl-x64";
break;
case GLIBC:
default:
nativeStr = "linux-x64";
break;
}

break;
case "arm64":
switch (familySync()) {
case GLIBC:
nativeBinding = require("@scope/valkey-glide-linux-arm64");
break;
case MUSL:
nativeBinding = require("@scope/valkey-glide-linux-musl-arm64");
break;
default:
nativeBinding = require("@scope/valkey-glide-linux-arm64");
break;
}
break;
case "arm64":
switch (familySync()) {
case MUSL:
nativeStr = "linux-musl-arm64";
break;
case GLIBC:
default:
nativeStr = "linux-arm64";
break;
}

break;
default:
throw new Error(
`Unsupported OS: ${platform}, architecture: ${arch}`,
);
}
break;
default:
throw new Error(
`Unsupported OS: ${platform}, architecture: ${arch}`,
);
}

break;
case "darwin":
switch (arch) {
case "arm64":
nativeBinding = require("@scope/valkey-glide-darwin-arm64");
break;
default:
throw new Error(
`Unsupported OS: ${platform}, architecture: ${arch}`,
);
}
break;
case "darwin":
switch (arch) {
case "x64":
nativeStr = "darwin-x64";
break;
case "arm64":
nativeStr = "darwin-arm64";
break;
default:
throw new Error(
`Unsupported OS: ${platform}, architecture: ${arch}`,
);
}

break;
default:
throw new Error(
`Unsupported OS: ${platform}, architecture: ${arch}`,
);
break;
default:
throw new Error(
`Unsupported OS: ${platform}, architecture: ${arch}`,
);
}
}

let scope = process.env.scope || "@scope";

if (scope == "@scope") {
scope = "@valkey/";
}

const nativeBinding = require(`${scope}valkey-glide-${nativeStr}`);

if (!nativeBinding) {
throw new Error(`Failed to load native binding`);
}
Expand Down
32 changes: 32 additions & 0 deletions node/npm/glide/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint no-undef: off */
module.exports = {
preset: "ts-jest",
transform: {
"^.+\\.(t|j)s$": ["ts-jest", { isolatedModules: true }],
},
testEnvironment: "node",
testRegex: "/tests/.*\\.(test|spec)?\\.(ts|tsx)$",
moduleFileExtensions: [
"ts",
"tsx",
"js",
"jsx",
"json",
"node",
"cjs",
"mjs",
],
testTimeout: 600000,
reporters: [
"default",
[
"./node_modules/jest-html-reporter",
{
includeFailureMsg: true,
includeSuiteFailure: true,
executionTimeWarningThreshold: 60,
sort: "status",
},
],
],
};
74 changes: 74 additions & 0 deletions node/npm/glide/package.json.temp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"name": "${scope}${pkg_name}",
"types": "build-ts/index.d.ts",
"version": "${package_version}",
"description": "General Language Independent Driver for the Enterprise (GLIDE) for Valkey",
"main": "build-ts/index.js",
"module": "build-ts/index.js",
"type": "commonjs",
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"clean": "rm -rf build-ts/",
"copy-declaration-files": "cp ../../build-ts/*.d.ts build-ts/ && cp ../../build-ts/src/*.d.ts build-ts/src/ && cp ../../build-ts/src/server-modules/*.d.ts build-ts/src/server-modules/",
"build": "tsc && mkdir -p build-ts/src && mkdir -p build-ts/src/server-modules && npm run copy-declaration-files",
"build:test": "npm i && npm run build",
"test": "jest --verbose"
},
"files": [
"/build-ts"
],
"repository": {
"type": "git",
"url": "git+https://github.com/valkey-io/valkey-glide.git"
},
"keywords": [
"valkey",
"valkeyClient",
"client",
"valkey-glide"
],
"author": "Valkey GLIDE Maintainers",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/valkey-io/valkey-glide/issues"
},
"homepage": "https://github.com/valkey-io/valkey-glide#readme",
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/jest": "^29.5.14",
"ts-jest": "^29.2.5",
"jest": "^29.7.0",
"jest-html-reporter": "^3.10.2",
"@types/node": "^18.11.18",
"@typescript-eslint/eslint-plugin": "^5.48.0",
"@typescript-eslint/parser": "^5.48.0",
"eslint": "^8.31.0",
"typescript": "^4.9.4",
"${scope}valkey-glide-${named_os}-${arch}": "../.."
},
"optionalDependencies": {
"${scope}valkey-glide-darwin-arm64": "${package_version}",
"${scope}valkey-glide-linux-arm64": "${package_version}",
"${scope}valkey-glide-linux-x64": "${package_version}",
"${scope}valkey-glide-linux-musl-arm64": "${package_version}",
"${scope}valkey-glide-linux-musl-x64": "${package_version}"
},
"eslintConfig": {
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"ignorePatterns": [
"build-ts/*"
],
"root": true
},
"dependencies": {
"detect-libc": "^2.0.3"
}
}
Loading
Loading