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

Align main with changes needed for hybrid publish #1199

Merged
merged 4 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#### Changes
* Python: Added JSON.DEL JSON.FORGET commands ([#1146](https://github.com/aws/glide-for-redis/pull/1146))

## 0.3.1 (2024-03-28)
## 0.3.3 (2024-03-28)

#### Fixes

* Node: Ignore hybrid-tests folder for npm publish. ([#1178](https://github.com/aws/glide-for-redis/pull/1178))
* Node: Fixed broken path of tsconfig translation. ([#1183](https://github.com/aws/glide-for-redis/pull/1183))
* Node: Fix issue with dual usage, `CommonJS` and `ECMAScript` modules. ([#1199](https://github.com/aws/glide-for-redis/pull/1199))

## 0.3.0 (2024-03-25)

Expand Down Expand Up @@ -80,4 +79,4 @@

Preview release of **GLIDE for Redis** a Polyglot Redis client.

See the [README](README.md) for additional information.
See the [README](README.md) for additional information.
14 changes: 0 additions & 14 deletions node/DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,3 @@ Development on the Node wrapper may involve changes in either the TypeScript or
- [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.

### Hybrid package publishing method

In this project we are using hybrid method for building the package for NodeJS, in order to support GLIDE's usage in projects based on either `CommonJS` or `ECMAScript` modules.
Hybrid method -
In order to build the package for usage in either module system, we use three different tsconfig files:

- `tsconfig` is the general tsconfig file, which the others will extend.
- `tsconfig-cjs` for `commonJS` build with `CommonJS` as the target of translation.
- `tsconfig` for `ECMA` build with `ECMA` as the target of translation.

The build is composed of 2 build steps, one will use `tsconfig` and write the results of the package's translation into the `build-ts/mjs` folder, and the other will use `tsconfig-cjs` and will write into the `build-ts/cjs` folder.
Additionaly, we add to `package.json` the following export rule, which presents to the user the correct index file, based on the import statement used - `import` for `ECMA`, and `require` for `CommonJS`.
As part of the build we run the `fixup_pj_files_for_build_type` script, which adds the `type` and `types` entries to the different `package.json` that been created for `ECMAScript` and `CommonJS` with the fitting values.
13 changes: 0 additions & 13 deletions node/fixup_pj_files_for_build_type

This file was deleted.

27 changes: 8 additions & 19 deletions node/npm/glide/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,16 @@ import { arch, platform } from "process";

let globalObject = global as unknown;

async function loadNativeBinding() {
function loadNativeBinding() {
let nativeBinding = null;
switch (platform) {
case "linux":
switch (arch) {
case "x64":
nativeBinding = await import(
"@scope/glide-for-redis-linux-x64"
);
nativeBinding = require("@scope/glide-for-redis-linux-x64");
break;
case "arm64":
nativeBinding = await import(
"@scope/glide-for-redis-linux-arm64"
);
nativeBinding = require("@scope/glide-for-redis-linux-arm64");
break;
default:
throw new Error(
Expand All @@ -32,14 +28,10 @@ async function loadNativeBinding() {
case "darwin":
switch (arch) {
case "x64":
nativeBinding = await import(
"@scope/glide-for-redis-darwin-x64"
);
nativeBinding = require("@scope/glide-for-redis-darwin-x64");
break;
case "arm64":
nativeBinding = await import(
"@scope/glide-for-redis-darwin-arm64"
);
nativeBinding = require("@scope/glide-for-redis-darwin-arm64");
break;
default:
throw new Error(
Expand All @@ -58,8 +50,8 @@ async function loadNativeBinding() {
return nativeBinding;
}

async function initialize() {
const nativeBinding = await loadNativeBinding();
function initialize() {
const nativeBinding = loadNativeBinding();
const {
RedisClient,
RedisClusterClient,
Expand Down Expand Up @@ -93,9 +85,6 @@ async function initialize() {
globalObject = Object.assign(global, nativeBinding);
}

initialize().catch((error) => {
console.error("Failed to initialize:", error);
process.exit(1);
});
initialize();

export default globalObject;
18 changes: 6 additions & 12 deletions node/npm/glide/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
{
"name": "${scope}${pkg_name}",
"types": "build-ts/mjs/index.d.ts",
"types": "build-ts/index.d.ts",
"version": "${package_version}",
"description": "An AWS-sponsored, open-source Redis client.",
"main": "build-ts/cjs/index.js",
"module": "build-ts/mjs/index.js",
"exports": {
".": {
"import": "./build-ts/mjs/index.js",
"require": "./build-ts/cjs/index.js",
"types": "./build-ts/mjs/index.d.ts"
}
},
"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/mjs/*.d.ts build-ts/mjs/ && cp ../../build-ts/cjs/*.d.ts build-ts/cjs/ && cp ../../build-ts/cjs/src/*.d.ts build-ts/cjs/src/ && cp ../../build-ts/mjs/src/*.d.ts build-ts/mjs/src/",
"build": "tsc -p tsconfig-mjs.json && tsc -p tsconfig-cjs.json && ./../../fixup_pj_files_for_build_type && mkdir -p build-ts/mjs/src && mkdir -p build-ts/cjs/src && npm run copy-declaration-files"
"copy-declaration-files": "cp ../../build-ts/*.d.ts build-ts/ && cp ../../build-ts/src/*.d.ts build-ts/src/",
"build": "tsc && mkdir -p build-ts/src && npm run copy-declaration-files"
},
"files": [
"/build-ts"
Expand Down
9 changes: 0 additions & 9 deletions node/npm/glide/tsconfig-cjs.json

This file was deleted.

9 changes: 0 additions & 9 deletions node/npm/glide/tsconfig-mjs.json

This file was deleted.

7 changes: 3 additions & 4 deletions node/npm/glide/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"target": "esnext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"target": "ESNext",
"module": "commonjs",
"allowJs": true,
"esModuleInterop": true,
"baseUrl": "./",
Expand All @@ -19,9 +20,7 @@
"resolveJsonModule": true,
"traceResolution": false,
"types": ["node", "jest"],
/* The bellow parts are for developer extention usage and should be overriden in cjs and mjs tscofig's files */
"module": "ESNext" /* Specify what module code is generated. Ovrride in tsconfig-cjs/mjs */,
"outDir": "./build-ts/mjs" /* Specify an output folder for all emitted files. Ovrride in tsconfig-cjs */
"outDir": "./build-ts" /* Specify an output folder for all emitted files */
},
"include": ["./*.ts", "src/*.ts", "src/*.js"],
"exclude": [
Expand Down
18 changes: 6 additions & 12 deletions node/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
{
"name": "@aws/glide-for-redis",
"description": "An AWS-sponsored, open-source Redis client.",
"main": "build-ts/cjs/index.js",
"module": "build-ts/mjs/index.js",
"types": "./build-ts/mjs/index.d.ts",
"exports": {
".": {
"import": "./build-ts/mjs/index.js",
"require": "./build-ts/cjs/index.js",
"types": "./build-ts/mjs/index.d.ts"
}
},
"main": "build-ts/index.js",
"module": "build-ts/index.js",
"types": "./build-ts/index.d.ts",
"type": "commonjs",
"repository": {
"type": "git",
"url": "git+https://github.com/aws/glide-for-redis.git"
Expand All @@ -33,8 +27,8 @@
"build-internal": "cd rust-client && npm run build",
"build-internal:release": "cd rust-client && npm run build:release",
"build-internal:benchmark": "cd rust-client && npm run build:benchmark",
"build-external": "rm -rf build-ts && tsc -p tsconfig-mjs.json && tsc -p tsconfig-cjs.json && ./fixup_pj_files_for_build_type",
"build-external:release": "rm -rf build-ts && tsc -p tsconfig-mjs.json && tsc -p tsconfig-cjs.json && ./fixup_pj_files_for_build_type --stripInternal",
"build-external": "rm -rf build-ts && tsc",
"build-external:release": "rm -rf build-ts && tsc --stripInternal",
"build-protobuf": "npm run compile-protobuf-files && npm run fix-protobuf-file",
"compile-protobuf-files": "cd src && pbjs -t static-module -o ProtobufMessage.js ../../glide-core/src/protobuf/*.proto && pbts -o ProtobufMessage.d.ts ProtobufMessage.js",
"fix-protobuf-file": "replace 'this\\.encode\\(message, writer\\)\\.ldelim' 'this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim' src/ProtobufMessage.js",
Expand Down
9 changes: 0 additions & 9 deletions node/tsconfig-cjs.json

This file was deleted.

9 changes: 0 additions & 9 deletions node/tsconfig-mjs.json

This file was deleted.

3 changes: 2 additions & 1 deletion node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"target": "ES6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"module": "CommonJS" /* Specify what module code is generated. */,
"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. */,
Expand All @@ -22,7 +23,7 @@
"lib": [
"esnext"
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
"outDir": "./build-ts/mjs" /* Specify an output folder for all emitted files. Ovrride in tsconfig-cjs */
"outDir": "./build-ts" /* Specify an output folder for all emitted files.*/
},
"compileOnSave": false,
"include": ["./*.ts", "src/*.ts", "src/*.js"],
Expand Down
Loading