From 3158103dc7f599a3af35bf52bf043c1631192188 Mon Sep 17 00:00:00 2001 From: Avi Fenesh <55848801+avifenesh@users.noreply.github.com> Date: Tue, 2 Apr 2024 14:40:24 +0300 Subject: [PATCH] Align main with changes needed for hybrid publish (#1199) * Align main with changes needed for hybrid publish * remove unnecessary info * add relevant changes to the change log --- CHANGELOG.md | 9 ++++----- node/DEVELOPER.md | 14 -------------- node/fixup_pj_files_for_build_type | 13 ------------- node/npm/glide/index.ts | 27 ++++++++------------------- node/npm/glide/package.json | 18 ++++++------------ node/npm/glide/tsconfig-cjs.json | 9 --------- node/npm/glide/tsconfig-mjs.json | 9 --------- node/npm/glide/tsconfig.json | 7 +++---- node/package.json | 18 ++++++------------ node/tsconfig-cjs.json | 9 --------- node/tsconfig-mjs.json | 9 --------- node/tsconfig.json | 3 ++- 12 files changed, 29 insertions(+), 116 deletions(-) delete mode 100755 node/fixup_pj_files_for_build_type delete mode 100644 node/npm/glide/tsconfig-cjs.json delete mode 100644 node/npm/glide/tsconfig-mjs.json delete mode 100644 node/tsconfig-cjs.json delete mode 100644 node/tsconfig-mjs.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 306fc0a371..e7e7b936a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,14 @@ #### Changes * Python: Added JSON.DEL JSON.FORGET commands ([#1146](https://github.com/aws/glide-for-redis/pull/1146)) - +* #### Fixes * Python: Fix typing error "‘type’ object is not subscriptable" ([#1203](https://github.com/aws/glide-for-redis/pull/1203)) -## 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) @@ -83,4 +82,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. \ No newline at end of file diff --git a/node/DEVELOPER.md b/node/DEVELOPER.md index ae9d137023..a6d019eea3 100644 --- a/node/DEVELOPER.md +++ b/node/DEVELOPER.md @@ -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. diff --git a/node/fixup_pj_files_for_build_type b/node/fixup_pj_files_for_build_type deleted file mode 100755 index 46f8d9cadc..0000000000 --- a/node/fixup_pj_files_for_build_type +++ /dev/null @@ -1,13 +0,0 @@ -#!/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 <build-ts/mjs/package.json < { - console.error("Failed to initialize:", error); - process.exit(1); -}); +initialize(); export default globalObject; diff --git a/node/npm/glide/package.json b/node/npm/glide/package.json index a391abbae6..b6ded308e1 100644 --- a/node/npm/glide/package.json +++ b/node/npm/glide/package.json @@ -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" diff --git a/node/npm/glide/tsconfig-cjs.json b/node/npm/glide/tsconfig-cjs.json deleted file mode 100644 index 8a792008fc..0000000000 --- a/node/npm/glide/tsconfig-cjs.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "./tsconfig.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. */ - } -} diff --git a/node/npm/glide/tsconfig-mjs.json b/node/npm/glide/tsconfig-mjs.json deleted file mode 100644 index ffe56714fb..0000000000 --- a/node/npm/glide/tsconfig-mjs.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - /* Visit https://aka.ms/tsconfig to read more about this file */ - "module": "esnext" /* Specify what module code is generated. */, - /* Emit */ - "outDir": "./build-ts/mjs" /* Specify an output folder for all emitted files. */ - } -} diff --git a/node/npm/glide/tsconfig.json b/node/npm/glide/tsconfig.json index 5cad794a11..14c61aaf26 100644 --- a/node/npm/glide/tsconfig.json +++ b/node/npm/glide/tsconfig.json @@ -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": "./", @@ -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": [ diff --git a/node/package.json b/node/package.json index b1316b0b46..817e6e138f 100644 --- a/node/package.json +++ b/node/package.json @@ -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" @@ -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", diff --git a/node/tsconfig-cjs.json b/node/tsconfig-cjs.json deleted file mode 100644 index 62a16e2af3..0000000000 --- a/node/tsconfig-cjs.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "./tsconfig.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. */ - } -} diff --git a/node/tsconfig-mjs.json b/node/tsconfig-mjs.json deleted file mode 100644 index d7ed360fb9..0000000000 --- a/node/tsconfig-mjs.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "./tsconfig.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. */ - } -} diff --git a/node/tsconfig.json b/node/tsconfig.json index 4ae08b5bc3..4cd744701c 100644 --- a/node/tsconfig.json +++ b/node/tsconfig.json @@ -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. */, @@ -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"],