plain-ioc 0.1.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019 Sality
3
+ Copyright (c) 2025 mvcbox
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,2 +1,270 @@
1
+ [![npm version](https://badge.fury.io/js/plain-ioc.svg)](https://badge.fury.io/js/plain-ioc)
2
+
1
3
  # plain-ioc
2
- Plain inversion of control container
4
+
5
+ A small, dependency-free **Inversion of Control (IoC) / Dependency Injection** container for Node.js and TypeScript.
6
+
7
+ **Highlights**
8
+
9
+ - **Synchronous factories only** (factories cannot return a `Promise`)
10
+ - **Transient** and **singleton** bindings
11
+ - Optional **circular dependency detection** (useful in development)
12
+ - Tiny API surface
13
+
14
+ ---
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install plain-ioc
20
+ ```
21
+
22
+ ---
23
+
24
+ ## Core concepts
25
+
26
+ ### Dependency keys
27
+
28
+ A *dependency key* is used to register and later resolve a dependency.
29
+
30
+ In TypeScript, the key type is:
31
+
32
+ ```ts
33
+ type DependencyKey = string | symbol | object;
34
+ ```
35
+
36
+ Recommended key styles:
37
+
38
+ - **`symbol`** keys for interfaces or abstract concepts (prevents accidental collisions)
39
+ - **class constructors** as keys for concrete classes
40
+ - **`string`** keys for quick scripts or small apps
41
+
42
+ > Tip: Using `Symbol('Name')` makes debugging easier.
43
+
44
+ ### Factories
45
+
46
+ A *factory* creates the dependency instance.
47
+
48
+ ```ts
49
+ interface DependencyFactory<T> {
50
+ (container: Container): T; // must not return a Promise
51
+ }
52
+ ```
53
+
54
+ Factories receive the `Container`, so they can resolve other dependencies.
55
+
56
+ ---
57
+
58
+ ## Usage
59
+
60
+ ### Create a container
61
+
62
+ ```ts
63
+ import { Container } from "plain-ioc";
64
+
65
+ const container = new Container();
66
+ ```
67
+
68
+ ### Bind and resolve (transient)
69
+
70
+ `bind()` registers a factory that runs **every time** you resolve the key.
71
+
72
+ ```ts
73
+ import { Container } from "plain-ioc";
74
+
75
+ const c = new Container();
76
+
77
+ c.bind("now", () => Date.now());
78
+
79
+ const a = c.resolve<number>("now");
80
+ const b = c.resolve<number>("now");
81
+ // a !== b (very likely)
82
+ ```
83
+
84
+ ### Bind and resolve (singleton)
85
+
86
+ `bindSingleton()` registers a factory that runs **once**. The created instance is cached and returned for subsequent resolves.
87
+
88
+ ```ts
89
+ import { Container } from "plain-ioc";
90
+
91
+ class Logger {
92
+ log(message: string) {
93
+ console.log(message);
94
+ }
95
+ }
96
+
97
+ const c = new Container();
98
+
99
+ c.bindSingleton(Logger, () => new Logger());
100
+
101
+ const l1 = c.resolve<Logger>(Logger);
102
+ const l2 = c.resolve<Logger>(Logger);
103
+ // l1 === l2
104
+ ```
105
+
106
+ ### Using symbols (recommended for interfaces)
107
+
108
+ ```ts
109
+ import { Container } from "plain-ioc";
110
+
111
+ interface Config {
112
+ baseUrl: string;
113
+ }
114
+
115
+ const TOKENS = {
116
+ Config: Symbol("Config"),
117
+ } as const;
118
+
119
+ const c = new Container();
120
+
121
+ c.bindSingleton<Config>(TOKENS.Config, () => ({ baseUrl: "https://api.example.com" }));
122
+
123
+ const cfg = c.resolve<Config>(TOKENS.Config);
124
+ ```
125
+
126
+ ### Wiring dependencies together
127
+
128
+ ```ts
129
+ import { Container } from "plain-ioc";
130
+
131
+ const TOKENS = {
132
+ BaseUrl: Symbol("BaseUrl"),
133
+ } as const;
134
+
135
+ class ApiClient {
136
+ constructor(public readonly baseUrl: string) {}
137
+ }
138
+
139
+ const c = new Container();
140
+
141
+ c.bindSingleton<string>(TOKENS.BaseUrl, () => "https://api.example.com");
142
+ c.bindSingleton(ApiClient, (c) => new ApiClient(c.resolve(TOKENS.BaseUrl)));
143
+
144
+ const api = c.resolve<ApiClient>(ApiClient);
145
+ console.log(api.baseUrl);
146
+ ```
147
+
148
+ ### Check if a key is bound
149
+
150
+ ```ts
151
+ import { Container } from "plain-ioc";
152
+
153
+ const c = new Container();
154
+
155
+ c.isBound("service"); // false
156
+ c.bind("service", () => ({ ok: true }));
157
+ c.isBound("service"); // true
158
+ ```
159
+
160
+ ### Unbind
161
+
162
+ `unbind()` removes the factory. If the binding was a singleton, its cached instance is removed as well.
163
+
164
+ ```ts
165
+ import { Container } from "plain-ioc";
166
+
167
+ const c = new Container();
168
+
169
+ c.bindSingleton("app", () => ({ name: "demo" }));
170
+
171
+ c.unbind("app");
172
+ // c.resolve("app") will now throw
173
+ ```
174
+
175
+ ---
176
+
177
+ ## Circular dependency detection
178
+
179
+ By default, circular dependency detection is **off**.
180
+
181
+ Enable it when creating the container:
182
+
183
+ ```ts
184
+ import { Container } from "plain-ioc";
185
+
186
+ const c = new Container({ circularDependencyDetect: true });
187
+ ```
188
+
189
+ When enabled, `resolve()` tracks a stack of keys being resolved. If the same key appears twice in the stack, a `PlainIocCircularDependencyError` is thrown with a message that includes the dependency stack.
190
+
191
+ > Recommendation: Keep this enabled in development/test, and turn it off in production for minimal overhead.
192
+
193
+ ---
194
+
195
+ ## API reference
196
+
197
+ ### `new Container(options?)`
198
+
199
+ Creates a container.
200
+
201
+ - `options.circularDependencyDetect?: boolean` — default `false`
202
+
203
+ ### `container.bind<T>(key, factory)`
204
+
205
+ Registers a **transient** factory.
206
+
207
+ - Throws `PlainIocFactoryAlreadyBoundError` if the key is already registered.
208
+
209
+ ### `container.bindSingleton<T>(key, factory)`
210
+
211
+ Registers a **singleton** factory.
212
+
213
+ - Throws `PlainIocFactoryAlreadyBoundError` if the key is already registered.
214
+
215
+ ### `container.resolve<T>(key): T`
216
+
217
+ Resolves an instance.
218
+
219
+ - Throws `PlainIocFactoryNotBoundError` if the key is not registered.
220
+ - Throws `PlainIocCircularDependencyError` when circular dependency detection is enabled and a cycle is detected.
221
+
222
+ ### `container.unbind(key)`
223
+
224
+ Removes a registered factory and clears any cached singleton instance.
225
+
226
+ - Throws `PlainIocFactoryNotBoundError` if the key is not registered.
227
+
228
+ ### `container.isBound(key): boolean`
229
+
230
+ Returns `true` if a factory is registered for `key`.
231
+
232
+ ---
233
+
234
+ ## Errors
235
+
236
+ All library errors extend the base class `PlainIocError`:
237
+
238
+ - `PlainIocError`
239
+ - `PlainIocFactoryNotBoundError`
240
+ - `PlainIocFactoryAlreadyBoundError`
241
+ - `PlainIocCircularDependencyError`
242
+
243
+ You can catch these specifically:
244
+
245
+ ```ts
246
+ import { Container, PlainIocFactoryNotBoundError } from "plain-ioc";
247
+
248
+ const c = new Container();
249
+
250
+ try {
251
+ c.resolve("missing");
252
+ } catch (e) {
253
+ if (e instanceof PlainIocFactoryNotBoundError) {
254
+ console.error("Not registered");
255
+ }
256
+ }
257
+ ```
258
+
259
+ ---
260
+
261
+ ## Notes & limitations
262
+
263
+ - Factories are **synchronous** (the type system rejects `Promise`-returning factories). If you need async initialization, create the instance elsewhere and bind it as a singleton value via a factory like `() => alreadyInitialized`.
264
+ - There is a single container scope (no built-in child containers / scopes).
265
+
266
+ ---
267
+
268
+ ## License
269
+
270
+ MIT
@@ -1,13 +1,19 @@
1
- import { Dependency } from './Dependency';
2
- import { DependencyKey } from './DependencyKey';
3
- import { DependencyFacroty } from './DependencyFacroty';
1
+ import type { Dependency } from './Dependency';
2
+ import type { DependencyKey } from './DependencyKey';
3
+ import type { ContainerOptions } from './ContainerOptions';
4
+ import type { DependencyFactory } from './DependencyFactory';
4
5
  export declare class Container {
5
- dependencies: Map<DependencyKey, Dependency<any>>;
6
- initInstances: Map<DependencyKey, any>;
7
- bind<T>(key: DependencyKey, factory: DependencyFacroty<T>): void;
8
- unbind(key: DependencyKey): void;
9
- bindSingleton<T>(key: DependencyKey, factory: DependencyFacroty<T>): void;
6
+ protected readonly circularDependencyDetect: boolean;
7
+ protected readonly circularDependencyStack: DependencyKey[];
8
+ protected readonly initializedInstances: Map<DependencyKey, unknown>;
9
+ protected readonly dependencies: Map<DependencyKey, Dependency<unknown>>;
10
+ constructor(options?: ContainerOptions);
11
+ protected circularDependencyStackPush(key: DependencyKey): void;
12
+ protected circularDependencyStackPop(): void;
13
+ protected keyToString(key: DependencyKey): string;
14
+ bind<T>(key: DependencyKey, factory: DependencyFactory<T>): this;
15
+ bindSingleton<T>(key: DependencyKey, factory: DependencyFactory<T>): this;
16
+ unbind(key: DependencyKey): this;
10
17
  isBound(key: DependencyKey): boolean;
11
18
  resolve<T>(key: DependencyKey): T;
12
- keyToString(key: DependencyKey): string;
13
19
  }
package/dist/Container.js CHANGED
@@ -1,59 +1,103 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Container = void 0;
3
4
  const errors_1 = require("./errors");
4
5
  class Container {
5
- constructor() {
6
+ constructor(options) {
7
+ var _a;
8
+ this.circularDependencyStack = [];
9
+ this.initializedInstances = new Map();
6
10
  this.dependencies = new Map();
7
- this.initInstances = new Map();
11
+ this.circularDependencyDetect = (_a = options === null || options === void 0 ? void 0 : options.circularDependencyDetect) !== null && _a !== void 0 ? _a : false;
12
+ }
13
+ circularDependencyStackPush(key) {
14
+ if (!this.circularDependencyDetect) {
15
+ return;
16
+ }
17
+ const detected = this.circularDependencyStack.findIndex(item => item === key) !== -1;
18
+ this.circularDependencyStack.push(key);
19
+ if (detected) {
20
+ let errorMessage = 'Circular dependency detected\n\n';
21
+ errorMessage += '>>>>>>> Circular Dependency Stack <<<<<<<\n';
22
+ errorMessage += this.circularDependencyStack.map((item, index) => {
23
+ return `>>> [${index}]: ${this.keyToString(item)}\n`;
24
+ }).join('');
25
+ throw new errors_1.PlainIocCircularDependencyError(errorMessage);
26
+ }
27
+ }
28
+ circularDependencyStackPop() {
29
+ if (this.circularDependencyDetect) {
30
+ this.circularDependencyStack.pop();
31
+ }
32
+ }
33
+ keyToString(key) {
34
+ const keyType = typeof key;
35
+ try {
36
+ if (typeof key === 'function') {
37
+ return `[${keyType}] "${key.name || '<anonymous>'}"`;
38
+ }
39
+ else if (typeof key === 'symbol') {
40
+ return `[${keyType}] "${Symbol.prototype.toString.call(key)}"`;
41
+ }
42
+ else if (typeof key === 'object') {
43
+ return `[${keyType}] "${Object.prototype.toString.call(key)}"`;
44
+ }
45
+ return `[${keyType}] "${String(key)}"`;
46
+ }
47
+ catch (_a) {
48
+ return `[${keyType}] "<unprintable>"`;
49
+ }
8
50
  }
9
51
  bind(key, factory) {
10
52
  if (this.dependencies.has(key)) {
11
- throw new errors_1.FactoryAlreadyBoundError(`Factory for ${this.keyToString(key)} already bound`);
53
+ throw new errors_1.PlainIocFactoryAlreadyBoundError(`Factory for ${this.keyToString(key)} already bound`);
12
54
  }
13
55
  this.dependencies.set(key, {
14
56
  factory
15
57
  });
16
- }
17
- unbind(key) {
18
- if (!this.dependencies.has(key)) {
19
- throw new errors_1.FactoryNotBoundError(`Factory not bound with ${this.keyToString(key)}`);
20
- }
21
- this.dependencies.delete(key);
22
- this.initInstances.delete(key);
58
+ return this;
23
59
  }
24
60
  bindSingleton(key, factory) {
25
61
  if (this.dependencies.has(key)) {
26
- throw new errors_1.FactoryAlreadyBoundError(`Factory for ${this.keyToString(key)} already bound`);
62
+ throw new errors_1.PlainIocFactoryAlreadyBoundError(`Factory for ${this.keyToString(key)} already bound`);
27
63
  }
28
64
  this.dependencies.set(key, {
29
65
  factory,
30
66
  singleton: true
31
67
  });
68
+ return this;
69
+ }
70
+ unbind(key) {
71
+ if (!this.dependencies.has(key)) {
72
+ throw new errors_1.PlainIocFactoryNotBoundError(`Factory not bound with ${this.keyToString(key)}`);
73
+ }
74
+ this.dependencies.delete(key);
75
+ this.initializedInstances.delete(key);
76
+ return this;
32
77
  }
33
78
  isBound(key) {
34
79
  return this.dependencies.has(key);
35
80
  }
36
81
  resolve(key) {
37
- if (!this.dependencies.has(key)) {
38
- throw new errors_1.FactoryNotBoundError(`Factory not bound with ${this.keyToString(key)}`);
39
- }
40
82
  const dependency = this.dependencies.get(key);
41
- if (dependency.singleton && this.initInstances.has(key)) {
42
- return this.initInstances.get(key);
83
+ if (!dependency) {
84
+ throw new errors_1.PlainIocFactoryNotBoundError(`Factory not bound with ${this.keyToString(key)}`);
43
85
  }
44
- else if (dependency.singleton) {
45
- const instance = dependency.factory(this);
46
- this.initInstances.set(key, instance);
86
+ if (dependency.singleton && this.initializedInstances.has(key)) {
87
+ return this.initializedInstances.get(key);
88
+ }
89
+ try {
90
+ this.circularDependencyStackPush(key);
91
+ const { factory } = dependency;
92
+ const instance = factory(this);
93
+ if (dependency.singleton) {
94
+ this.initializedInstances.set(key, instance);
95
+ }
47
96
  return instance;
48
97
  }
49
- return dependency.factory(this);
50
- }
51
- keyToString(key) {
52
- const type = typeof key;
53
- if (typeof key === 'function') {
54
- key = key.name || '';
98
+ finally {
99
+ this.circularDependencyStackPop();
55
100
  }
56
- return String(`'${String(key)}' (${type})`);
57
101
  }
58
102
  }
59
103
  exports.Container = Container;
@@ -0,0 +1,3 @@
1
+ export type ContainerOptions = {
2
+ circularDependencyDetect?: boolean;
3
+ };
@@ -1,5 +1,5 @@
1
- import { DependencyFacroty } from './DependencyFacroty';
1
+ import type { DependencyFactory } from './DependencyFactory';
2
2
  export interface Dependency<T> {
3
- factory: DependencyFacroty<T>;
3
+ factory: DependencyFactory<T>;
4
4
  singleton?: boolean;
5
5
  }
@@ -0,0 +1,6 @@
1
+ import type { Container } from './Container';
2
+ type NotPromise<T> = T extends PromiseLike<any> ? never : T;
3
+ export interface DependencyFactory<T> {
4
+ (container: Container): NotPromise<T>;
5
+ }
6
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1 @@
1
- export declare type DependencyKey = string | symbol | object;
1
+ export type DependencyKey = string | symbol | object;
@@ -0,0 +1,3 @@
1
+ import { PlainIocError } from './PlainIocError';
2
+ export declare class PlainIocCircularDependencyError extends PlainIocError {
3
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlainIocCircularDependencyError = void 0;
4
+ const PlainIocError_1 = require("./PlainIocError");
5
+ class PlainIocCircularDependencyError extends PlainIocError_1.PlainIocError {
6
+ }
7
+ exports.PlainIocCircularDependencyError = PlainIocCircularDependencyError;
@@ -0,0 +1,3 @@
1
+ export declare class PlainIocError extends Error {
2
+ constructor(message?: string);
3
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlainIocError = void 0;
4
+ class PlainIocError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = new.target.name;
8
+ if (Error.captureStackTrace) {
9
+ Error.captureStackTrace(this, new.target);
10
+ }
11
+ }
12
+ }
13
+ exports.PlainIocError = PlainIocError;
@@ -0,0 +1,3 @@
1
+ import { PlainIocError } from './PlainIocError';
2
+ export declare class PlainIocFactoryAlreadyBoundError extends PlainIocError {
3
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlainIocFactoryAlreadyBoundError = void 0;
4
+ const PlainIocError_1 = require("./PlainIocError");
5
+ class PlainIocFactoryAlreadyBoundError extends PlainIocError_1.PlainIocError {
6
+ }
7
+ exports.PlainIocFactoryAlreadyBoundError = PlainIocFactoryAlreadyBoundError;
@@ -0,0 +1,3 @@
1
+ import { PlainIocError } from './PlainIocError';
2
+ export declare class PlainIocFactoryNotBoundError extends PlainIocError {
3
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlainIocFactoryNotBoundError = void 0;
4
+ const PlainIocError_1 = require("./PlainIocError");
5
+ class PlainIocFactoryNotBoundError extends PlainIocError_1.PlainIocError {
6
+ }
7
+ exports.PlainIocFactoryNotBoundError = PlainIocFactoryNotBoundError;
@@ -1,2 +1,4 @@
1
- export { FactoryNotBoundError } from './FactoryNotBoundError';
2
- export { FactoryAlreadyBoundError } from './FactoryAlreadyBoundError';
1
+ export { PlainIocError } from './PlainIocError';
2
+ export { PlainIocFactoryNotBoundError } from './PlainIocFactoryNotBoundError';
3
+ export { PlainIocCircularDependencyError } from './PlainIocCircularDependencyError';
4
+ export { PlainIocFactoryAlreadyBoundError } from './PlainIocFactoryAlreadyBoundError';
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var FactoryNotBoundError_1 = require("./FactoryNotBoundError");
4
- exports.FactoryNotBoundError = FactoryNotBoundError_1.FactoryNotBoundError;
5
- var FactoryAlreadyBoundError_1 = require("./FactoryAlreadyBoundError");
6
- exports.FactoryAlreadyBoundError = FactoryAlreadyBoundError_1.FactoryAlreadyBoundError;
3
+ exports.PlainIocFactoryAlreadyBoundError = exports.PlainIocCircularDependencyError = exports.PlainIocFactoryNotBoundError = exports.PlainIocError = void 0;
4
+ var PlainIocError_1 = require("./PlainIocError");
5
+ Object.defineProperty(exports, "PlainIocError", { enumerable: true, get: function () { return PlainIocError_1.PlainIocError; } });
6
+ var PlainIocFactoryNotBoundError_1 = require("./PlainIocFactoryNotBoundError");
7
+ Object.defineProperty(exports, "PlainIocFactoryNotBoundError", { enumerable: true, get: function () { return PlainIocFactoryNotBoundError_1.PlainIocFactoryNotBoundError; } });
8
+ var PlainIocCircularDependencyError_1 = require("./PlainIocCircularDependencyError");
9
+ Object.defineProperty(exports, "PlainIocCircularDependencyError", { enumerable: true, get: function () { return PlainIocCircularDependencyError_1.PlainIocCircularDependencyError; } });
10
+ var PlainIocFactoryAlreadyBoundError_1 = require("./PlainIocFactoryAlreadyBoundError");
11
+ Object.defineProperty(exports, "PlainIocFactoryAlreadyBoundError", { enumerable: true, get: function () { return PlainIocFactoryAlreadyBoundError_1.PlainIocFactoryAlreadyBoundError; } });
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './errors';
2
2
  export { Container } from './Container';
3
- export { Dependency } from './Dependency';
4
- export { DependencyKey } from './DependencyKey';
5
- export { DependencyFacroty } from './DependencyFacroty';
3
+ export type { Dependency } from './Dependency';
4
+ export type { DependencyKey } from './DependencyKey';
5
+ export type { DependencyFactory } from './DependencyFactory';
6
+ export type { ContainerOptions } from './ContainerOptions';
package/dist/index.js CHANGED
@@ -1,8 +1,20 @@
1
1
  "use strict";
2
- function __export(m) {
3
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
- }
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
6
- __export(require("./errors"));
17
+ exports.Container = void 0;
18
+ __exportStar(require("./errors"), exports);
7
19
  var Container_1 = require("./Container");
8
- exports.Container = Container_1.Container;
20
+ Object.defineProperty(exports, "Container", { enumerable: true, get: function () { return Container_1.Container; } });
package/package.json CHANGED
@@ -1,12 +1,37 @@
1
1
  {
2
2
  "name": "plain-ioc",
3
- "version": "0.1.4",
3
+ "version": "1.1.0",
4
4
  "description": "Plain inversion of control container",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "type": "commonjs",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "require": "./dist/index.js",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
7
16
  "scripts": {
8
- "build": "node ./node_modules/typescript/bin/tsc",
9
- "test": "echo \"Error: no test specified\" && exit 1"
17
+ "build": "npm run clean && node ./node_modules/.bin/tsc",
18
+ "clean": "node -e \"['./dist'].forEach(item => require('fs').rmSync(item, {recursive:true,force:true}));\"",
19
+ "prepack": "npm run build"
20
+ },
21
+ "engines": {
22
+ "node": ">=6.0.0"
23
+ },
24
+ "devEngines": {
25
+ "runtime": {
26
+ "name": "node",
27
+ "version": ">=18.0.0",
28
+ "onFail": "error"
29
+ },
30
+ "packageManager": {
31
+ "name": "npm",
32
+ "version": ">=8.6.0",
33
+ "onFail": "error"
34
+ }
10
35
  },
11
36
  "repository": {
12
37
  "type": "git",
@@ -24,8 +49,13 @@
24
49
  "url": "https://github.com/mvcbox/node-plain-ioc/issues"
25
50
  },
26
51
  "homepage": "https://github.com/mvcbox/node-plain-ioc#readme",
52
+ "files": [
53
+ "dist",
54
+ "LICENSE",
55
+ "README.md"
56
+ ],
27
57
  "devDependencies": {
28
- "@types/node": "^12.7.2",
29
- "typescript": "^3.5.3"
58
+ "@types/node": "^6.14.13",
59
+ "typescript": "^4.7.2"
30
60
  }
31
61
  }
@@ -1,4 +0,0 @@
1
- import { Container } from './Container';
2
- export interface DependencyFacroty<T> {
3
- (container: Container): T;
4
- }
@@ -1,2 +0,0 @@
1
- export declare class FactoryAlreadyBoundError extends Error {
2
- }
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class FactoryAlreadyBoundError extends Error {
4
- }
5
- exports.FactoryAlreadyBoundError = FactoryAlreadyBoundError;
@@ -1,2 +0,0 @@
1
- export declare class FactoryNotBound extends Error {
2
- }
@@ -1,23 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- exports.__esModule = true;
16
- var FactoryNotBound = (function (_super) {
17
- __extends(FactoryNotBound, _super);
18
- function FactoryNotBound() {
19
- return _super !== null && _super.apply(this, arguments) || this;
20
- }
21
- return FactoryNotBound;
22
- }(Error));
23
- exports.FactoryNotBound = FactoryNotBound;
@@ -1,2 +0,0 @@
1
- export declare class FactoryNotBoundError extends Error {
2
- }
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class FactoryNotBoundError extends Error {
4
- }
5
- exports.FactoryNotBoundError = FactoryNotBoundError;