Skip to content

Switch to awilix 13#424

Open
kibertoad wants to merge 7 commits intomainfrom
feat/awilix-13
Open

Switch to awilix 13#424
kibertoad wants to merge 7 commits intomainfrom
feat/awilix-13

Conversation

@kibertoad
Copy link
Copy Markdown
Owner

@kibertoad kibertoad commented Apr 2, 2026

Summary by CodeRabbit

  • Refactor

    • Updated optional chaining syntax for improved code clarity and maintainability.
    • Enhanced TypeScript type inference in test utilities for stronger compile-time type safety.
  • Chores

    • Upgraded awilix dependency to version 13.0.3 across all packages.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

📝 Walkthrough

Walkthrough

This pull request upgrades the Awilix dependency version across multiple packages from v12 to v13, adds explicit generic type parameters to Awilix container initialization in test utilities, and refactors two conditional checks in AbstractAmqpConsumer to use optional chaining syntax.

Changes

Cohort / File(s) Summary
Optional Chaining Refactor
packages/amqp/lib/AbstractAmqpConsumer.ts
Updated two early-abort checks to use optional chaining (?.) instead of sequential null/undefined checks, preserving identical behavior with cleaner syntax.
Awilix Dependency Upgrade
packages/amqp/package.json, packages/core/package.json, packages/gcp-pubsub/package.json, packages/kafka/package.json, packages/sns/package.json, packages/sqs/package.json
Updated awilix dev dependency from v12.0.1–12.1.1 to v13.0.3 across all packages.
Container Generic Type Annotations
packages/amqp/test/utils/testContext.ts, packages/core/test/testContext.ts, packages/gcp-pubsub/test/utils/testContext.ts, packages/kafka/test/utils/testContext.ts, packages/sns/test/utils/testContext.ts, packages/sqs/test/utils/testContext.ts
Added explicit generic type parameter <Dependencies> to createContainer() calls, strengthening compile-time type inference without runtime changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • kjamrog
  • CarlosGamero

Poem

🐰 With optional chains we skip and bound,
Type parameters make containers sound,
Awilix climbs to thirteen's call,
Cleaner code for one and all!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Switch to awilix 13' directly and accurately describes the main change in the pull request, which is updating the awilix dependency from version 12 to version 13 across multiple packages.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/awilix-13

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/amqp/test/utils/testContext.ts (1)

114-123: ⚠️ Potential issue | 🟠 Major

Restore lifetime: Lifetime.SINGLETON to amqpConnectionManager.

The amqpConnectionManager registration is missing an explicit lifetime specification. In Awilix, the default is TRANSIENT, meaning a new instance is created per resolution. This is problematic for a connection manager with asyncInit/asyncDispose lifecycle hooks:

  • Multiple AMQP connections will be created if the dependency is resolved more than once
  • Resource cleanup will be incomplete since only one instance's asyncDispose will be properly tracked

All other similar registrations in this file (permissionConsumer, permissionPublisher, queuePublisherManager, topicPublisherManager) explicitly specify lifetime: Lifetime.SINGLETON. This registration should too.

Fix
     amqpConnectionManager: asFunction(
       ({ logger }: Dependencies) => {
         return new AmqpConnectionManager(config, logger)
       },
       {
+        lifetime: Lifetime.SINGLETON,
         asyncInit: 'init',
         asyncDispose: 'close',
         asyncDisposePriority: 1,
       },
     ),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/amqp/test/utils/testContext.ts` around lines 114 - 123, The
amqpConnectionManager registration is missing an explicit Lifetime.SINGLETON,
causing Awilix to treat it as TRANSIENT and create multiple
AmqpConnectionManager instances (breaking asyncInit/asyncDispose lifecycle
tracking); update the asFunction registration for amqpConnectionManager to
include lifetime: Lifetime.SINGLETON (matching other registrations like
permissionConsumer/permissionPublisher/queuePublisherManager/topicPublisherManager)
so a single AmqpConnectionManager instance is created and its
asyncInit/asyncDispose hooks are managed correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/amqp/package.json`:
- Around line 40-53: Update the package TypeScript configuration to pin
TS6-breaking defaults so builds don’t change: add or update tsconfig.json's
"compilerOptions" to explicitly set "strict" (false or your intended value),
"target" (e.g., "es2022" or your prior target), "module" (e.g., "commonjs" or
"esnext" to match runtime), "types" (include needed libs instead of empty), and
"noUncheckedSideEffectImports" (set to false if you relied on previous
behavior), and include "ignoreDeprecations": "6.0" to silence TS6 deprecation
errors; ensure the package.json's "typescript" devDependency remains as intended
and run CI/tests to verify everything passes.

---

Outside diff comments:
In `@packages/amqp/test/utils/testContext.ts`:
- Around line 114-123: The amqpConnectionManager registration is missing an
explicit Lifetime.SINGLETON, causing Awilix to treat it as TRANSIENT and create
multiple AmqpConnectionManager instances (breaking asyncInit/asyncDispose
lifecycle tracking); update the asFunction registration for
amqpConnectionManager to include lifetime: Lifetime.SINGLETON (matching other
registrations like
permissionConsumer/permissionPublisher/queuePublisherManager/topicPublisherManager)
so a single AmqpConnectionManager instance is created and its
asyncInit/asyncDispose hooks are managed correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 06ffdfa1-24b5-4577-bf63-7b6a55229e3d

📥 Commits

Reviewing files that changed from the base of the PR and between c98a004 and d40d66b.

📒 Files selected for processing (9)
  • packages/amqp/lib/AbstractAmqpConsumer.ts
  • packages/amqp/package.json
  • packages/amqp/test/utils/testContext.ts
  • packages/core/package.json
  • packages/gcp-pubsub/package.json
  • packages/kafka/lib/utils/KafkaMessageBatchStream.ts
  • packages/kafka/package.json
  • packages/sns/package.json
  • packages/sqs/package.json

Comment on lines +40 to +53
"@biomejs/biome": "^2.3.15",
"@lokalise/biome-config": "^3.1.0",
"@lokalise/tsconfig": "^3.0.0",
"@message-queue-toolkit/core": "*",
"@types/amqplib": "0.10.8",
"@types/node": "^25.0.2",
"@vitest/coverage-v8": "^4.0.15",
"amqplib": "^0.10.8",
"awilix": "^12.0.5",
"awilix-manager": "^6.1.0",
"rimraf": "^6.0.1",
"typescript": "^5.9.3",
"vitest": "^4.0.15",
"zod": "^4.1.13"
"@types/node": "^25.5.0",
"@types/amqplib": "^0.10.8",
"@vitest/coverage-v8": "^4.0.18",
"amqplib": "^1.0.3",
"awilix": "^13.0.3",
"awilix-manager": "^6.4.0",
"rimraf": "^6.1.3",
"typescript": "^6.0.2",
"vitest": "^4.0.18",
"zod": "^4.3.6"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check for any amqplib-specific type imports or usages that might be affected
rg -n --type ts "from ['\"]amqplib['\"]"

Repository: kibertoad/message-queue-toolkit

Length of output: 1826


🌐 Web query:

amqplib 1.0 breaking changes from 0.10

💡 Result:

The breaking changes in amqplib 1.0.0 from 0.10.x are primarily: - Minimum Node.js requirement raised to v18 (previously supported down to v10 in 0.10.x). Other changes include: - Introduction of Biome formatter for code formatting. - Automated formatting via pre-commit hooks using Lefthook. - Formatted entire codebase with standardised rules. - Added npm format script. - Enabled and fixed lint rules: noUnusedFunctionParameters and noUnusedVariables. No API or behavioral changes to the AMQP client functionality are mentioned; the update appears to be a maintenance release focused on tooling, linting, and Node.js version support. The library remains an AMQP 0-9-1 client compatible with RabbitMQ.

Citations:


🌐 Web query:

awilix 13.0 breaking changes from 12.x

💡 Result:

The breaking changes in Awilix 13.0.0 from 12.x are all TypeScript-only and do not affect runtime behavior. They are: - Default cradle type changed from any to {}: createContainer without an explicit generic now returns AwilixContainer<{}> instead of AwilixContainer. This enables better type accumulation via register chaining. - register returns a new container type that includes the registered resolvers. - asValue now preserves literal types and deep readonly for objects. No migration is required for JavaScript users or runtime code. Subsequent patch releases (13.0.1-13.0.3) fixed ESM/CJS interop issues but introduced no additional breaking changes.

Citations:


🌐 Web query:

typescript 6.0 breaking changes

💡 Result:

TypeScript 6.0, released in March 2026, is a bridge release preparing for the native Go-based TypeScript 7.0. It introduces several breaking changes, deprecations, and default shifts. Deprecations can be temporarily ignored with "ignoreDeprecations": "6.0" in tsconfig.json, but will be removed in 7.0. Key breaking changes and deprecations: New Defaults (potentially breaking if relying on old defaults): - strict: true (was false) - target: es2025 (was ES3/ES5) - module: esnext - types: [] (was ["*"], now explicitly set e.g. ["node"]) - rootDir: config directory (was inferred) - noUncheckedSideEffectImports: true - alwaysStrict assumed everywhere (alwaysStrict: false deprecated) Deprecated/Removed Options: - target: es5 (minimum now es2015) - --outFile (removed; use bundlers) - baseUrl (deprecated; migrate paths) - moduleResolution: node10/node/classic (use nodenext/bundler) - module: amd/umd/system (removed) - downlevelIteration (deprecated) - esModuleInterop/allowSyntheticDefaultImports: false (now always true) - Legacy module Foo {} syntax (use namespace) - Import assertions: assert {} (use with {}; deprecated in static/dynamic imports) - Triple-slash references /// <reference ... /> - --stableTypeOrdering flag for diagnosing 7.0 differences Behavioral Changes: - Less context-sensitivity for this-less functions (tighter inference) - Type ordering in .d.ts may differ (use --stableTypeOrdering to preview) - dom lib now includes dom.iterable/asynciterable Migration Tips: - Use experimental ts5to6 codemod for baseUrl/rootDir. - Explicitly set types array. - Set rootDir if sources are in subdir. - Update imports for new interop. - See https://aka.ms/ts6 for official migration info. These align TypeScript with modern JS ecosystem (ESM, bundlers, evergreen browsers).

Citations:


Prioritize testing TypeScript 6.0 compatibility and configuration adjustments.

While amqplib 1.0.x has no API breaking changes (only Node.js v18+ requirement), TypeScript 6.0 introduces significant breaking changes including new compiler defaults: strict: true, target: es2025, module: esnext, types: [], and noUncheckedSideEffectImports: true. These defaults could affect the build and type checking without an explicit ignoreDeprecations: "6.0" configuration.

The awilix 13.x changes are TypeScript-only (type inference changes to cradle) and don't affect runtime behavior.

Verify that the tsconfig.json explicitly sets required configuration options and that CI passes with these new compiler defaults.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/amqp/package.json` around lines 40 - 53, Update the package
TypeScript configuration to pin TS6-breaking defaults so builds don’t change:
add or update tsconfig.json's "compilerOptions" to explicitly set "strict"
(false or your intended value), "target" (e.g., "es2022" or your prior target),
"module" (e.g., "commonjs" or "esnext" to match runtime), "types" (include
needed libs instead of empty), and "noUncheckedSideEffectImports" (set to false
if you relied on previous behavior), and include "ignoreDeprecations": "6.0" to
silence TS6 deprecation errors; ensure the package.json's "typescript"
devDependency remains as intended and run CI/tests to verify everything passes.

@kibertoad kibertoad changed the title Switch to awilix 13 and amqp 1.x Switch to awilix 13 Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant