jimexist opened a new pull request, #3528: URL: https://github.com/apache/thrift/pull/3528
## Summary Removes the runtime dependency on the [`q`](https://github.com/kriskowal/q) Promise library and switches the JS/TS code generator to emit native `Promise` by default. Adds a `js:native_promise=[true|false]` compiler flag (default `true`) so users who still need the old output can opt back in. ## What changed **Compiler** ([`compiler/cpp/src/thrift/generate/t_js_generator.cc`](compiler/cpp/src/thrift/generate/t_js_generator.cc)) - In non-ES6 mode the generated processor now emits `new Promise((resolve) => resolve(handler.fn(args)))` instead of `Q.fcall(...)`. - The non-ES6 Node client now emits `new Promise((resolve, reject) => { ... })` instead of `Q.defer()` / `_defer.promise`. - The non-ES6 JS/TS `_includes` no longer pull in `Q` by default. - New flag `js:native_promise=[true|false]` (default `true`). When `false`, the legacy `Q.fcall` / `Q.defer` output is restored and `Q` is imported directly via `require('q')` (no longer routed through `thrift.Q`), so legacy users only need `q` in their own `node_modules`. **Runtime** ([`lib/nodejs/lib/thrift/index.js`](lib/nodejs/lib/thrift/index.js), [`lib/nodejs/lib/thrift/browser.js`](lib/nodejs/lib/thrift/browser.js)) - Removed `exports.Q = require("q")`. **Dependencies** ([`package.json`](package.json), [`package-lock.json`](package-lock.json), [`lib/nodejs/test/package-lock.json`](lib/nodejs/test/package-lock.json)) - Dropped `q` from `dependencies` and `@types/q` from `devDependencies`; pruned the matching lockfile entries. **Tests** ([`lib/nodets/test/test_driver.ts`](lib/nodets/test/test_driver.ts), [`lib/nodets/test/test_handler.ts`](lib/nodets/test/test_handler.ts)) - `Q.IPromise<T>` → `Promise<T>`; `Q.resolve(x)` → `Promise.resolve(x)`; `.fail(...)` → `.catch(...)`. - Removed `import Q = require("q")` / `import Q = thrift.Q`. - `AsyncThriftTestHandler` method return types changed to `Promise<void>` since the callback delivers the value and the body returns `Promise.resolve()` (native `Promise<void>` is not assignable to `Promise<string>` etc. under TS strict mode, unlike Q's loose typings). - Renamed `"Q Promise Client Tests"` → `"Promise Client Tests"`. ## Why `q` has been in maintenance mode for years; native `Promise` is available in every supported runtime (`node >= 10.18.0` per [`package.json`](package.json)). Removing it shrinks the dependency footprint and brings the non-ES6 / Node output in line with what the ES6 generator already emitted. The `native_promise` flag is an escape hatch for downstream code that still depends on the Q-shaped output. ## Heads-up for reviewers - A JIRA ticket should be filed under [THRIFT](https://issues.apache.org/jira/browse/THRIFT) — this is non-trivial and the PR title / commit should be prefixed with the ticket ID before merge. - I was unable to run the JS/TS toolchain or build the C++ compiler in my environment. Please verify locally: `npm run lint`, `npm run test-ts`, and a thrift compiler build that regenerates an example service in both default and `native_promise=false` modes. - The runtime export `thrift.Q` is gone; downstream code that imported it will break. Users who need to keep it can use the new `native_promise=false` generator flag and install `q` themselves. ## Test plan - [ ] `make style` passes - [ ] `npm run lint` and `npm run test-ts` pass - [ ] Thrift compiler builds; generated code for a sample `.thrift` service is valid JS/TS under both `native_promise` defaults - [ ] `native_promise=false` output still works against a project that has `q` installed - [ ] CI green 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
