-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
94 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,55 @@ | ||
{ | ||
"name": "awilix-manager", | ||
"description": "Wrapper over awilix to support more complex use-cases, such as async init and eager injection", | ||
"version": "3.3.0", | ||
"dependencies": { | ||
"awilix": "^9.0.0" | ||
}, | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsc", | ||
"build:release": "del-cli dist && del-cli coverage && npm run lint && npm run build", | ||
"test": "vitest", | ||
"test:coverage": "npm test -- --coverage", | ||
"lint": "eslint . --ext .ts", | ||
"lint:fix": "eslint . --ext .ts --fix", | ||
"format": "prettier --write .", | ||
"prepublishOnly": "npm run build:release" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.8.4", | ||
"@typescript-eslint/eslint-plugin": "^6.7.2", | ||
"@typescript-eslint/parser": "^6.7.2", | ||
"@vitest/coverage-v8": "^0.34.6", | ||
"del-cli": "^5.0.0", | ||
"eslint": "^8.51.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-plugin-import": "^2.28.1", | ||
"eslint-plugin-prettier": "^5.0.0", | ||
"eslint-plugin-vitest": "^0.3.2", | ||
"prettier": "^3.0.3", | ||
"typescript": "^5.2.2", | ||
"vitest": "^0.34.6" | ||
}, | ||
"engines": { | ||
"node": ">=16" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/kibertoad/awilix-manager.git" | ||
}, | ||
"keywords": [ | ||
"init", | ||
"async", | ||
"eager", | ||
"awilix", | ||
"di" | ||
], | ||
"homepage": "https://github.com/kibertoad/awilix-manager", | ||
"files": [ | ||
"README.md", | ||
"LICENSE", | ||
"dist/*" | ||
] | ||
} | ||
{ | ||
"name": "awilix-manager", | ||
"description": "Wrapper over awilix to support more complex use-cases, such as async init and eager injection", | ||
"version": "3.3.0", | ||
"dependencies": { | ||
"awilix": "^9.0.0" | ||
}, | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsc", | ||
"build:release": "del-cli dist && del-cli coverage && npm run lint && npm run build", | ||
"test": "vitest", | ||
"test:coverage": "npm test -- --coverage", | ||
"lint": "eslint . --ext .ts && tsc --project tsconfig.lint.json --noEmit", | ||
"lint:fix": "eslint . --ext .ts --fix", | ||
"format": "prettier --write .", | ||
"prepublishOnly": "npm run build:release" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.8.4", | ||
"@typescript-eslint/eslint-plugin": "^6.7.2", | ||
"@typescript-eslint/parser": "^6.7.2", | ||
"@vitest/coverage-v8": "^0.34.6", | ||
"del-cli": "^5.0.0", | ||
"eslint": "^8.51.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-plugin-import": "^2.28.1", | ||
"eslint-plugin-prettier": "^5.0.0", | ||
"eslint-plugin-vitest": "^0.3.2", | ||
"prettier": "^3.0.3", | ||
"typescript": "^5.2.2", | ||
"vitest": "^0.34.6" | ||
}, | ||
"engines": { | ||
"node": ">=16" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/kibertoad/awilix-manager.git" | ||
}, | ||
"keywords": [ | ||
"init", | ||
"async", | ||
"eager", | ||
"awilix", | ||
"di" | ||
], | ||
"homepage": "https://github.com/kibertoad/awilix-manager", | ||
"files": [ | ||
"README.md", | ||
"LICENSE", | ||
"dist/*" | ||
] | ||
} |
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,34 @@ | ||
import type { AwilixContainer } from 'awilix' | ||
import { asClass, Lifetime } from 'awilix' | ||
import type { Resolver } from 'awilix/lib/resolvers' | ||
|
||
export const SINGLETON_CONFIG = { lifetime: Lifetime.SINGLETON } | ||
|
||
export type DependencyOverrides = Partial<DiConfig> | ||
class SomeModule {} | ||
|
||
export function registerDependencies( | ||
diContainer: AwilixContainer, | ||
dependencyOverrides: DependencyOverrides = {}, | ||
): void { | ||
const diConfig: DiConfig = { | ||
module: asClass(SomeModule, { | ||
...SINGLETON_CONFIG, | ||
asyncInit: 'start', | ||
asyncDispose: 'close', | ||
asyncDisposePriority: 10, | ||
enabled: true, | ||
}), | ||
} | ||
diContainer.register(diConfig) | ||
|
||
for (const [dependencyKey, dependencyValue] of Object.entries(dependencyOverrides)) { | ||
diContainer.register(dependencyKey, dependencyValue) | ||
} | ||
} | ||
|
||
type DiConfig = Record<keyof Dependencies, Resolver<any>> | ||
|
||
export interface Dependencies { | ||
module: SomeModule | ||
} |
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,5 @@ | ||
{ | ||
"extends": ["./tsconfig.json"], | ||
"include": ["lib/**/*.ts", "test/**/*.ts", "vitest.config.ts"], | ||
"exclude": [] | ||
} |