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

Refactor to reference glide-rs as a separate external package - Yarn fix #2943

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/install-shared-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ inputs:
description: "Specified target for rust toolchain, ex. x86_64-apple-darwin"
type: string
required: false
defalt: "x86_64-unknown-linux-gnu"
default: "x86_64-unknown-linux-gnu"
options:
- x86_64-unknown-linux-gnu
- aarch64-unknown-linux-gnu
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/node-create-package-file/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ runs:
steps:
- name: Create package.json file
shell: bash
working-directory: ./node
working-directory: ./node/rust-client
run: |
# echo -musl if inputs.target is musl
export MUSL_FLAG=`if [[ "${{ inputs.target }}" =~ .*"musl".* ]]; then echo "-musl"; fi`
# set the package name
name="valkey-glide"
name="glide-rs"
# derive the OS and architecture from the inputs
export node_os="${{ inputs.named_os }}"
export node_arch="${{ inputs.arch }}"
Expand Down
36 changes: 30 additions & 6 deletions .github/workflows/npm-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,31 @@ jobs:
EVENT_NAME: ${{ github.event_name }}
INPUT_VERSION: ${{ github.event.inputs.version }}

- name: Set platform-specific package name
shell: bash
run: |
PLATFORM_NAME="${{ matrix.build.NAMED_OS }}${{ contains(matrix.build.TARGET, 'musl') && '-musl' || '' }}-${{ matrix.build.ARCH }}"
echo "PLATFORM_NAME=${PLATFORM_NAME}" >> $GITHUB_ENV
echo "NODE_OS=${{ matrix.build.NAMED_OS }}" >> $GITHUB_ENV
echo "NODE_ARCH=${{ matrix.build.ARCH }}" >> $GITHUB_ENV
echo "PACKAGE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV

- name: Update Rust client package.json
working-directory: ./node/rust-client
run: |
sed -i 's|\${PLATFORM_NAME}|'"${PLATFORM_NAME}"'|g' package.json
sed -i 's|\${PACKAGE_VERSION}|'"${PACKAGE_VERSION}"'|g' package.json
sed -i 's|\${NODE_OS}|'"${NODE_OS}"'|g' package.json
sed -i 's|\${NODE_ARCH}|'"${NODE_ARCH}"'|g' package.json

- name: Validate Rust client package.json
working-directory: ./node/rust-client
run: |
if ! grep -q "@valkey/glide-rs-${PLATFORM_NAME}" package.json; then
echo "Error: package.json does not contain the correct package name"
exit 1
fi

- name: Setup node
if: ${{ !contains(matrix.build.TARGET, 'musl') }}
uses: actions/setup-node@v4
Expand Down Expand Up @@ -178,7 +203,7 @@ jobs:
- name: Publish to NPM
if: github.event_name != 'pull_request'
shell: bash
working-directory: ./node
working-directory: ./node/rust-client
run: |
npm pkg fix
set +e # Disable immediate exit on non-zero exit codes
Expand All @@ -196,7 +221,7 @@ jobs:
echo "Skipping publishing, package already published."
elif [[ ! -z "$npm_publish_err" ]]; then
echo "Failed to publish with error: $npm_publish_err"
exit 1
exit 1
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
Expand All @@ -216,7 +241,7 @@ jobs:
publish-base-to-npm:
if: github.event_name != 'pull_request'
name: Publish the base NPM package
needs: publish-binaries
needs: [publish-binaries]
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -252,7 +277,7 @@ jobs:
envsubst < package.json.tmpl > "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" glide-rs.ts
env:
NPM_SCOPE: ${{ vars.NPM_SCOPE }}
EVENT_NAME: ${{ github.event_name }}
Expand All @@ -276,7 +301,6 @@ jobs:
echo "This is a stable release"
export npm_tag="latest"
fi
echo "NPM_TAG=${npm_tag}" >> $GITHUB_ENV

- name: Publish the base package
if: github.event_name != 'pull_request'
Expand Down Expand Up @@ -422,7 +446,7 @@ jobs:
echo "${PLATFORM_MATRIX}" > platform_matrix.json

while read -r pkg; do
package_name="@valkey/valkey-glide-${pkg}"
package_name="@valkey/glide-rs-${pkg}"
echo "Deprecating ${package_name}@${RELEASE_VERSION}"
npm deprecate "${package_name}@${RELEASE_VERSION}" "This version has been deprecated" --force || true
done < <(jq -r '.[] | "\(.NAMED_OS)\(.TARGET | test("musl") | if . then "-musl" else "" end)-\(.ARCH)"' platform_matrix.json)
Expand Down
4 changes: 2 additions & 2 deletions node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
*/

export { ClusterScanCursor, Script } from "glide-rs";
export { ClusterScanCursor, Script } from "../npm/glide/glide-rs";
export * from "./src/BaseClient";
export * from "./src/Commands";
export * from "./src/Errors";
export * from "./src/GlideClient";
export * from "./src/GlideClusterClient";
export * from "./src/Logger";
export * from "./src/server-modules/GlideJson";
export * from "./src/server-modules/GlideFt";
export * from "./src/server-modules/GlideFtOptions";
export * from "./src/server-modules/GlideJson";
export * from "./src/Transaction";
79 changes: 79 additions & 0 deletions node/npm/glide/glide-rs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env node

/**
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
*/

import { GLIBC, MUSL, familySync } from "detect-libc";
import { arch, platform } from "process";

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

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

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

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

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

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

if (!nativeBinding) {
throw new Error(`Failed to load native binding`);
}

return nativeBinding;
}

const nativeBinding = loadNativeBinding();

export = nativeBinding;
77 changes: 3 additions & 74 deletions node/npm/glide/index.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,12 @@
#!/usr/bin/env node

/**
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
*/

import { GLIBC, MUSL, familySync } from "detect-libc";
import { arch, platform } from "process";
import glideRs from "./glide-rs";

let globalObject = global as unknown;

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

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;
}

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;
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;
default:
throw new Error(
`Unsupported OS: ${platform}, architecture: ${arch}`,
);
}

if (!nativeBinding) {
throw new Error(`Failed to load native binding`);
}

return nativeBinding;
}

function initialize() {
const nativeBinding = loadNativeBinding();
const {
AggregationType,
BaseScanOptions,
Expand Down Expand Up @@ -224,7 +153,7 @@ function initialize() {
ReturnTypeAttribute,
ReturnTypeJson,
UniversalReturnTypeJson,
} = nativeBinding;
} = glideRs;

module.exports = {
AggregationType,
Expand Down Expand Up @@ -374,7 +303,7 @@ function initialize() {
UniversalReturnTypeJson,
};

globalObject = Object.assign(global, nativeBinding);
globalObject = Object.assign(global, glideRs);
}

initialize();
Expand Down
10 changes: 5 additions & 5 deletions node/npm/glide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
"typescript": "^4.9.4"
},
"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}"
"${scope}glide-rs-darwin-arm64": "${package_version}",
"${scope}glide-rs-linux-arm64": "${package_version}",
"${scope}glide-rs-linux-x64": "${package_version}",
"${scope}glide-rs-linux-musl-arm64": "${package_version}",
"${scope}glide-rs-linux-musl-x64": "${package_version}"
},
"eslintConfig": {
"extends": [
Expand Down
12 changes: 8 additions & 4 deletions node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@
},
"homepage": "https://github.com/valkey-io/valkey-glide#readme",
"dependencies": {
"glide-rs": "file:rust-client",
"long": "^5.2.3",
"npmignore": "^0.3.1",
"protobufjs": "^7.4.0"
},
"bundleDependencies": [
"glide-rs"
],
"optionalDependencies": {
"@valkey/glide-rs-linux-x64": "${package_version}",
"@valkey/glide-rs-linux-arm64": "${package_version}",
"@valkey/glide-rs-darwin-x64": "${package_version}",
"@valkey/glide-rs-darwin-arm64": "${package_version}",
"@valkey/glide-rs-linux-musl-x64": "${package_version}",
"@valkey/glide-rs-linux-musl-arm64": "${package_version}"
},
"scripts": {
"build": "npm run prereq && npm run build-internal && npm run build-protobuf && npm run build-external",
"build:release": "npm run build-internal:release && npm run build-protobuf && npm run build-external:release",
Expand Down
12 changes: 9 additions & 3 deletions node/rust-client/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"name": "glide-rs",
"version": "0.1.0",
"description": "Valkey client",
"name": "@valkey/glide-rs-${PLATFORM_NAME}",
"version": "${PACKAGE_VERSION}",
"description": "Valkey client for ${PLATFORM_NAME}",
"main": "index.js",
"os": [
"${NODE_OS}"
],
"cpu": [
"${NODE_ARCH}"
],
"license": "Apache-2.0",
"files": [
"index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions node/src/BaseClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
*/
import * as net from "net";
import { Buffer, BufferWriter, Long, Reader, Writer } from "protobufjs";
import {
DEFAULT_CONNECTION_TIMEOUT_IN_MILLISECONDS,
DEFAULT_INFLIGHT_REQUESTS_LIMIT,
Expand All @@ -9,9 +11,7 @@ import {
StartSocketConnection,
getStatistics,
valueFromSplitPointer,
} from "glide-rs";
import * as net from "net";
import { Buffer, BufferWriter, Long, Reader, Writer } from "protobufjs";
} from "../npm/glide/glide-rs";
import {
AggregationType,
BaseScanOptions,
Expand Down
5 changes: 4 additions & 1 deletion node/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
*/

import { createLeakedStringVec, MAX_REQUEST_ARGS_LEN } from "glide-rs";
import Long from "long";
import {
createLeakedStringVec,
MAX_REQUEST_ARGS_LEN,
} from "../npm/glide/glide-rs";

import {
BaseClient, // eslint-disable-line @typescript-eslint/no-unused-vars
Expand Down
Loading
Loading