Skip to content

Commit 1f9f108

Browse files
jamarzkaXapphire13
authored andcommitted
feat: Build ES2015 and ES5 modules (microsoft#17)
* Build ES2015 and ES5 module bundles * Export directly from the modules to improve tree shaking * Add a type declaration build * Rename builds to esm5 and esm2015 * Added tslib * Updated the readme to use the new imports
1 parent 37569d2 commit 1f9f108

9 files changed

+83
-44
lines changed

README.md

+6-12
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ runtime.
5252

5353
#### Usage
5454
```typescript
55-
import {decorators} from "tsyringe";
56-
const {injectable} = decorators;
55+
import {injectable} from "tsyringe";
5756

5857
@injectable()
5958
class Foo {
@@ -74,8 +73,7 @@ global container.
7473

7574
#### Usage
7675
```typescript
77-
import {decorators} from "tsyringe";
78-
const {singleton} = decorators;
76+
import {singleton} from "tsyringe";
7977

8078
@singleton()
8179
class Foo {
@@ -98,8 +96,7 @@ a parameterless constructor that has dependencies auto-resolved.
9896

9997
#### Usage
10098
```typescript
101-
import {decorators} from "tsyringe";
102-
const {autoInjectable} = decorators;
99+
import {autoInjectable} from "tsyringe";
103100

104101
@autoInjectable()
105102
class Foo {
@@ -121,8 +118,7 @@ information to be stored in the constructor's metadata
121118

122119
#### Usage
123120
```typescript
124-
import {decorators} from "tsyringe";
125-
const {injectable, inject} = decorators;
121+
import {injectable, inject} from "tsyringe";
126122

127123
interface Database {
128124
// ...
@@ -146,8 +142,7 @@ export class Foo {}
146142
```typescript
147143
// Bar.ts
148144
import {Foo} from "./Foo";
149-
import {decorators} from "tsyringe";
150-
const {injectable} = decorators;
145+
import {injectable} from "tsyringe";
151146

152147
@injectable()
153148
export class Bar {
@@ -183,8 +178,7 @@ export class TestService implements SuperService {
183178
```
184179
```typescript
185180
// Client.ts
186-
import {decorators} from "tsyringe";
187-
const {injectable, inject} = decorators;
181+
import {injectable, inject} from "tsyringe";
188182

189183
@injectable()
190184
export class Client {

package.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
"name": "tsyringe",
33
"version": "2.2.0",
44
"description": "Lightweight dependency injection container for JavaScript/TypeScript",
5-
"main": "dist/index.js",
5+
"main": "dist/cjs/index.js",
6+
"module": "./dist/esm5/index.js",
7+
"es2015": "./dist/esm2015/index.js",
8+
"typings": "./dist/typings/index.d.ts",
69
"scripts": {
7-
"build": "rimraf ./dist && tsc",
10+
"build": "rimraf ./dist && tsc && tsc -p tsconfig.esm5.json && tsc -p tsconfig.esm2015.json && tsc -p tsconfig.types.json",
811
"test": "npm run lint && jest",
912
"test:coverage": "jest --coverage",
1013
"lint": "tslint -p ."
@@ -30,7 +33,9 @@
3033
"url": "https://github.com/Microsoft/tsyringe/issues"
3134
},
3235
"homepage": "https://github.com/Microsoft/tsyringe#readme",
33-
"dependencies": {},
36+
"dependencies": {
37+
"tslib": "^1.9.3"
38+
},
3439
"devDependencies": {
3540
"@types/jest": "^23.3.9",
3641
"@types/node": "^8.10.16",

src/index.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import * as Types from "./types";
2-
import * as decorators from "./decorators";
3-
import * as factories from "./factories";
4-
import * as providers from "./providers";
1+
import {DependencyContainer} from "./types";
52
import {instance} from "./dependency-container";
63

74
export {DependencyContainer} from "./types";
8-
export {factories};
9-
export {providers};
10-
export {decorators};
11-
export const container: Types.DependencyContainer = instance;
5+
export * from "./decorators";
6+
export * from "./factories";
7+
export * from "./providers";
8+
export const container: DependencyContainer = instance;

tsconfig.base.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"removeComments": true,
4+
"strict": true,
5+
"noImplicitAny": true,
6+
"strictNullChecks": true,
7+
"alwaysStrict": true,
8+
"noImplicitThis": true,
9+
"noUnusedLocals": true,
10+
"noUnusedParameters": true,
11+
"noImplicitReturns": true,
12+
"allowSyntheticDefaultImports": true,
13+
"experimentalDecorators": true,
14+
"emitDecoratorMetadata": true,
15+
"outDir": "dist",
16+
"stripInternal": true,
17+
"moduleResolution": "node",
18+
"importHelpers": true,
19+
},
20+
"include": [
21+
"src/"
22+
]
23+
}

tsconfig.esm2015.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"compilerOptions": {
4+
"target": "es2015",
5+
"module": "es2015",
6+
"outDir": "./dist/esm2015"
7+
}
8+
}

tsconfig.esm5.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"compilerOptions": {
4+
"target": "es5",
5+
"module": "es2015",
6+
"outDir": "./dist/esm5",
7+
"lib": [
8+
"es5",
9+
"es2015.iterable",
10+
"es2015.collection",
11+
"es2015.symbol"
12+
]
13+
}
14+
}

tsconfig.json

+4-20
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
11
{
2+
"extends": "./tsconfig.base.json",
23
"compilerOptions": {
3-
"target": "es6",
4+
"target": "es2015",
45
"module": "commonjs",
5-
"removeComments": true,
6-
"strict": true,
7-
"noImplicitAny": true,
8-
"strictNullChecks": true,
9-
"alwaysStrict": true,
10-
"noImplicitThis": true,
11-
"noUnusedLocals": true,
12-
"noUnusedParameters": true,
13-
"noImplicitReturns": true,
14-
"allowSyntheticDefaultImports": true,
15-
"experimentalDecorators": true,
16-
"emitDecoratorMetadata": true,
17-
"declaration": true,
18-
"outDir": "dist",
19-
"stripInternal": true
20-
},
21-
"include": [
22-
"src/"
23-
]
6+
"outDir": "./dist/cjs"
7+
}
248
}

tsconfig.types.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"compilerOptions": {
4+
"module": "es2015",
5+
"target": "esnext",
6+
"removeComments": false,
7+
"declaration": true,
8+
"declarationDir": "./dist/typings",
9+
"emitDeclarationOnly": true
10+
},
11+
"exclude": [
12+
"src/__tests__"
13+
]
14+
}

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -3644,7 +3644,7 @@ [email protected]:
36443644
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8"
36453645
integrity sha512-f/qGG2tUkrISBlQZEjEqoZ3B2+npJjIf04H1wuAv9iA8i04Icp+61KRXxFdha22670NJopsZCIjhC3SnjPRKrQ==
36463646

3647-
tslib@^1.8.0, tslib@^1.8.1:
3647+
tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.3:
36483648
version "1.9.3"
36493649
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"
36503650
integrity sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==

0 commit comments

Comments
 (0)