Skip to content

Commit 20fb006

Browse files
committed
chore: move to tiny-di package
1 parent 80c3be8 commit 20fb006

File tree

8 files changed

+76
-14
lines changed

8 files changed

+76
-14
lines changed

packages/tiny-di/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# tiny-di
2+
3+
Extremely simple dependency injection library.
4+
See `./src/index.test.ts` for the basic usage.
5+
6+
The idea is similar to [tsyringe](https://github.com/microsoft/tsyringe)'s constructor injection
7+
but this library has following benefits:
8+
9+
- extreme simplicity (~ 100 LOC)
10+
- it doesn't rely on typescript decorator metadata and thus doesn't require special setup for vite/esbuild based proejcts.
11+
- it provides a dependency graph to implement, for example, own per-module setup/teardown hooks very easily.
12+
13+
# ideas
14+
15+
- https://github.com/microsoft/tsyringe
16+
- https://docs.nestjs.com/fundamentals/lifecycle-events

packages/tiny-di/package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "@hiogawa/tiny-di",
3+
"version": "0.0.0",
4+
"type": "module",
5+
"main": "./dist/index.js",
6+
"module": "./dist/index.js",
7+
"types": "./dist/index.d.ts",
8+
"exports": {
9+
".": {
10+
"import": "./dist/index.js",
11+
"require": "./dist/index.cjs",
12+
"types": "./dist/index.d.ts"
13+
}
14+
},
15+
"files": [
16+
"dist"
17+
],
18+
"license": "MIT",
19+
"repository": {
20+
"type": "git",
21+
"url": "https://github.com/hi-ogawa/js-utils",
22+
"directory": "packages/tiny-di"
23+
},
24+
"typedoc": {
25+
"displayName": "@hiogawa/tiny-di",
26+
"readmeFile": "./README.md",
27+
"entryPoint": "./src/index.ts"
28+
},
29+
"scripts": {
30+
"build": "tsup",
31+
"test": "vitest",
32+
"release": "pnpm publish --no-git-checks --access public"
33+
},
34+
"devDependencies": {
35+
"@hiogawa/utils": "workspace:*"
36+
}
37+
}

packages/utils/src/singleton.test.ts renamed to packages/tiny-di/src/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { wrapError } from "@hiogawa/utils";
12
import { beforeAll, describe, expect, it } from "vitest";
2-
import { wrapError } from "./result";
3-
import { Singleton } from "./singleton";
3+
import { Singleton } from ".";
44

55
beforeAll(() => {
66
// pretty print class

packages/utils/src/singleton.ts renamed to packages/tiny-di/src/index.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
import { range } from "./lodash";
2-
import { tinyassert } from "./tinyassert";
3-
4-
// tsyringe-like idea https://github.com/microsoft/tsyringe
5-
// but with following benefits
6-
// - extreme simplicity
7-
// - it doesn't rely on typescript decorator metadata
8-
// - it provides dependency graph (e.g. to implement per-module async init/deinit hooks)
9-
10-
// references
11-
// - https://github.com/microsoft/tsyringe
12-
// - https://docs.nestjs.com/fundamentals/lifecycle-events
1+
import { range, tinyassert } from "@hiogawa/utils";
132

143
type InstanceKey = new () => unknown;
154
type Instance = unknown;

packages/tiny-di/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"include": ["src"]
4+
}

packages/tiny-di/tsup.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from "tsup";
2+
3+
export default defineConfig({
4+
entry: ["src/index.ts"],
5+
format: ["esm", "cjs"],
6+
dts: true,
7+
});

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
{
1414
"path": "packages/tiny-sql/examples/sqlite"
1515
},
16+
{
17+
"path": "packages/tiny-di"
18+
},
1619
{
1720
"path": "packages/theme-script"
1821
},

0 commit comments

Comments
 (0)