forked from valkey-io/valkey-glide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a hybrid module for node (valkey-io#1132)
* Added a hybrid module for node * Added explanation to DEVELOPER.md about the hybrid build process * PR fixes - DEVELOPER.md wordings, Script naming, CI structure, tsconfig usage in npm folder, enter to change log * added tsconfig property to jest * Added comment to fixup script file
- Loading branch information
Showing
18 changed files
with
300 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
# This script add "type" and "types" entries to the different `package.json` that been created for `ECMAScript` and `CommonJS` with the fitting values. | ||
cat >build-ts/cjs/package.json <<!EOF | ||
{ | ||
"type": "commonjs", | ||
"types": "build-ts/cjs/index.d.ts" | ||
} | ||
!EOF | ||
|
||
cat >build-ts/mjs/package.json <<!EOF | ||
{ | ||
"type": "module", | ||
"types": "build-ts/mjs/index.d.ts" | ||
} | ||
!EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const { AsyncClient } = require("glide-rs"); | ||
const RedisServer = require("redis-server"); | ||
const FreePort = require("find-free-port"); | ||
const PORT_NUMBER = 4001; | ||
|
||
let server; | ||
let port; | ||
|
||
const { exec } = require("child_process"); | ||
|
||
function flushallOnPort(port) { | ||
return new Promise((resolve, reject) => { | ||
exec(`redis-cli -p ${port} FLUSHALL`, (error, _, stderr) => { | ||
if (error) { | ||
console.error(stderr); | ||
reject(error); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
FreePort(PORT_NUMBER) | ||
.then(([free_port]) => { | ||
port = free_port; | ||
server = new RedisServer(port); | ||
server.open(async (err) => { | ||
if (err) { | ||
console.error("Error opening server:", err); | ||
throw err; | ||
} | ||
|
||
const client = AsyncClient.CreateConnection( | ||
`redis://localhost:${port}`, | ||
); | ||
await client.set("test", "test"); | ||
let result = await client.get("test"); | ||
|
||
if (result !== "test") { | ||
throw new Error("Common Test failed"); | ||
} else { | ||
console.log("Common Test passed"); | ||
} | ||
|
||
await flushallOnPort(port).then(() => { | ||
console.log("db flushed"); | ||
}); | ||
await server.close().then(() => { | ||
console.log("server closed"); | ||
}); | ||
}); | ||
}) | ||
.catch((error) => { | ||
console.error("Error occurred while finding a free port:", error); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "common-test", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "Common-test.cjs", | ||
"type": "commonjs", | ||
"scripts": { | ||
"build": "cd ../../../node && npm run build", | ||
"test": "node commonjs-test.cjs", | ||
"build-and-test": "npm run build && npm run test", | ||
"prettier:check:ci": "./node_modules/.bin/prettier --check .", | ||
"prettier:format": "./node_modules/.bin/prettier --write . " | ||
}, | ||
"author": "Amazon Web Services", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"child_process": "^1.0.2", | ||
"find-free-port": "^2.0.0", | ||
"glide-for-redis": "file:../../../node/build-ts/cjs" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.7.9", | ||
"prettier": "^2.8.8", | ||
"typescript": "^4.8.4" | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
node/hybrid-node-tests/ecmascript-test/ecmascript-test.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { exec } from "child_process"; | ||
import findFreePorts from "find-free-ports"; | ||
import { AsyncClient } from "glide-rs"; | ||
import RedisServer from "redis-server"; | ||
|
||
const PORT_NUMBER = 4001; | ||
let server; | ||
let port; | ||
|
||
export function flushallOnPort(port) { | ||
return new Promise((resolve, reject) => { | ||
exec(`redis-cli -p ${port} FLUSHALL`, (error, _, stderr) => { | ||
if (error) { | ||
console.error(stderr); | ||
reject(error); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
port = await findFreePorts(PORT_NUMBER).then(([free_port]) => free_port); | ||
server = await new Promise((resolve, reject) => { | ||
const server = new RedisServer(port); | ||
server.open(async (err) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
|
||
resolve(server); | ||
}); | ||
}); | ||
const client = AsyncClient.CreateConnection("redis://localhost:" + port); | ||
await client.set("test", "test"); | ||
let result = await client.get("test"); | ||
|
||
if (result !== "test") { | ||
throw new Error("Ecma Test failed"); | ||
} else { | ||
console.log("Ecma Test passed"); | ||
} | ||
|
||
await flushallOnPort(port).then(() => { | ||
console.log("db flushed"); | ||
}); | ||
await server.close().then(() => { | ||
console.log("server closed"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"author": "Amazon Web Services", | ||
"license": "Apache-2.0", | ||
"name": "ecma-test", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "Ecma-test.mjs", | ||
"type": "module", | ||
"scripts": { | ||
"build": "cd ../../../node && npm run build", | ||
"test": "node ecmascript-test.mjs", | ||
"build-and-test": "npm run build && npm run test", | ||
"prettier:check:ci": "./node_modules/.bin/prettier --check .", | ||
"prettier:format": "./node_modules/.bin/prettier --write . " | ||
}, | ||
"dependencies": { | ||
"child_process": "^1.0.2", | ||
"find-free-ports": "^3.1.1", | ||
"glide-for-redis": "file:../../../node/build-ts/mjs" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.7.9", | ||
"prettier": "^2.8.8", | ||
"typescript": "^4.8.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../tsconfig-cjs.json", | ||
"compilerOptions": { | ||
"outDir": "./build-ts/cjs" /* Specify an output folder for all emitted files. */ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../tsconfig-mjs.json", | ||
"compilerOptions": { | ||
"outDir": "./build-ts/mjs" /* Specify an output folder for all emitted files. */ | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, | ||
"sourceMap": true /* Create source map files for emitted JavaScript files. */, | ||
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */, | ||
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, | ||
"strict": true /* Enable all strict type-checking options. */, | ||
"skipLibCheck": true /* Skip type checking all .d.ts files. */, | ||
"allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */, | ||
"allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */, | ||
"baseUrl": "./" /* Specify the base directory to resolve non-relative module names. */, | ||
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, | ||
"inlineSourceMap": false /* Include sourcemap files inside the emitted JavaScript. */, | ||
"listEmittedFiles": false /* List emitted files. */, | ||
"listFiles": false /* Print names of files part of the compilation */, | ||
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */, | ||
"noFallthroughCasesInSwitch": true /* Enable error reporting for fallthrough cases in switch statements. */, | ||
"pretty": true, | ||
"resolveJsonModule": true /* Enable importing .json files. */, | ||
"rootDir": "./" /* Specify the root folder within your source files. */, | ||
"traceResolution": false /* true to have TypeScript print information about its resolution process for each processed file */, | ||
"lib": [ | ||
"esnext" | ||
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */ | ||
}, | ||
"compileOnSave": false, | ||
"include": ["./*.ts", "src/*.ts", "src/*.js"], | ||
"exclude": ["node_modules", "build-ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "./tsconfig-base.json", | ||
"compilerOptions": { | ||
/* Visit https://aka.ms/tsconfig to read more about this file */ | ||
"module": "commonjs" /* Specify what module code is generated. */, | ||
/* Emit */ | ||
"outDir": "./build-ts/cjs" /* Specify an output folder for all emitted files. */ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "./tsconfig-base.json", | ||
"compilerOptions": { | ||
/* Visit https://aka.ms/tsconfig to read more about this file */ | ||
"module": "ES2022" /* Specify what module code is generated. */, | ||
/* Emit */ | ||
"outDir": "./build-ts/mjs" /* Specify an output folder for all emitted files. */ | ||
} | ||
} |
Oops, something went wrong.