Skip to content

Commit

Permalink
Merge a1b1069 into 6be9213
Browse files Browse the repository at this point in the history
  • Loading branch information
AVykhrystyuk committed Sep 15, 2021
2 parents 6be9213 + a1b1069 commit 3d1d450
Show file tree
Hide file tree
Showing 12 changed files with 5,901 additions and 11,967 deletions.
1 change: 0 additions & 1 deletion .husky/.gitignore

This file was deleted.

5 changes: 5 additions & 0 deletions .husky/commit-msg
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

echo "git-hook: commit-msg"
npx --no-install commitlint --edit $1
1 change: 1 addition & 0 deletions .husky/pre-commit
@@ -1,4 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

echo "git-hook: pre-commit"
npx lint-staged
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -13,6 +13,7 @@ install:
script:
- npm run build:prod
- npm run test
- npm run size

after_success:
- npm run test:send-coverage-to-coveralls
28 changes: 28 additions & 0 deletions README.md
Expand Up @@ -2,3 +2,31 @@

[![Build Status](https://travis-ci.com/AVykhrystyuk/try-di.svg?branch=master)](https://travis-ci.com/AVykhrystyuk/try-di)
[![Coverage Status](https://coveralls.io/repos/github/AVykhrystyuk/try-di/badge.svg)](https://coveralls.io/github/AVykhrystyuk/try-di)

Try DI is a simple, typesafe and lightweight dependency injection container for TypeScript. Designed with the idea to avoid having runtime errors due to missing, incorrect or outdated mapping configuration.

- **Safe.** It type-checks every mapping. Allows to verify all the mappings on CI.
- **Fast.** `TODO: need to measure a sample`
- **Simple.** It supports the minimum required and sufficient functionality for most apps.
- **Small.** 828 bytes (minified and gzipped). No dependencies.
[Size Limit] controls the size.

```js
import { createContainer } from 'try-di';

const container = createContainer();

container
.useValue({ for: Water, use: new Water() })
.useValue({ for: Fish, use: new Fish() })
.useFactory({ for: Milk, use: (r) => new Milk(r.resolve(Water)) })
.useClass({ for: Animal, use: Cat, inject: [Fish, Milk] });

assert.ok(container.resolve(Cat).isCat, "Cat wasn't resolved");
```

Supports modern browsers, IE and Node.js. Provides modern ES2019 and CommonJS bundles, as well as legacy ones (ES5).

[size limit]: https://github.com/ai/size-limit

`TODO: more samples - how to verifyAll() and all possible ways to register deps`
6 changes: 4 additions & 2 deletions babel.config.js
Expand Up @@ -27,13 +27,15 @@ function buildConfig(options) {
}

function buildPresetEnv({ buildType, isProduction, isTest }) {
const preserveESmodules = false; /* 'false' to preserve ES modules */

switch (buildType) {
/* lts nodejs */
case 'cjs':
return ['@babel/preset-env', {
debug: !isProduction,
loose: true,
modules: isTest ? 'commonjs' : false,
modules: isTest ? 'commonjs' : preserveESmodules,
targets: {
node: 'current', // the same as process.versions.node
},
Expand All @@ -44,7 +46,7 @@ function buildPresetEnv({ buildType, isProduction, isTest }) {
return ['@babel/preset-env', {
debug: !isProduction,
loose: true,
modules: false,
modules: preserveESmodules,
}];

default:
Expand Down
3 changes: 3 additions & 0 deletions commitlint.config.js
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional']
}

0 comments on commit 3d1d450

Please sign in to comment.