Skip to content

Commit 8a827ff

Browse files
committed
Merge branch 'master' of github.com:nestjs/nest into refactor_clean_as_any
2 parents 66ee3eb + 89d84d2 commit 8a827ff

File tree

10 files changed

+98
-42
lines changed

10 files changed

+98
-42
lines changed

CONTRIBUTING.md

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ today! As a contributor, here are the guidelines we would like you to follow:
88
- [Issues and Bugs](#issue)
99
- [Feature Requests](#feature)
1010
- [Submission Guidelines](#submit)
11+
- [Development Setup](#development)
1112
- [Coding Rules](#rules)
1213
- [Commit Message Guidelines](#commit)
1314
<!-- - [Signing the CLA](#cla) -->
@@ -143,6 +144,41 @@ from the main (upstream) repository:
143144
```shell
144145
git pull --ff upstream master
145146
```
147+
148+
## <a name="development"></a> Development Setup
149+
150+
You will need Node.js version 8.9.0+.
151+
152+
1. After cloning the repo, run:
153+
```bash
154+
$ npm i # (or yarn install)
155+
```
156+
157+
2. In order to prepare your environment run `prepare.sh` shell script:
158+
```bash
159+
$ sh scripts/prepare.sh
160+
```
161+
162+
That will compile fresh packages and afterward, move them to all `sample` directories as well as integration tests.
163+
164+
### Commonly used NPM scripts
165+
166+
```bash
167+
# build all packages and move to "sample" and "integration" directories
168+
# if cross-packages breaking changes were performed you may face irrelevant errors
169+
# in order to verify the build, you can run this command again then
170+
$ npm run build
171+
172+
# run the full unit tests suite
173+
$ npm run test
174+
175+
# run integration tests
176+
# docker is required(!)
177+
$ sh scripts/run-integration.sh
178+
179+
# run linter
180+
$ npm run lint
181+
```
146182
147183
## <a name="rules"></a> Coding Rules
148184
To ensure consistency throughout the source code, keep these rules in mind as you are working:
@@ -184,11 +220,7 @@ Samples: (even more [samples](https://github.com/nestjs/nest/commits/master))
184220
185221
```
186222
docs(changelog) update change log to beta.5
187-
```
188-
```
189223
bugfix(core) need to depend on latest rxjs and zone.js
190-
191-
The version in our package.json gets copied to the one we publish, and users need the latest of these.
192224
```
193225
194226
### Revert

bundle/common/cache/cache.module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let CacheModule = CacheModule_1 = class CacheModule {
4545
}
4646
return {
4747
provide: cache_constants_1.CACHE_MODULE_OPTIONS,
48-
useFactory: async (optionsFactory) => await optionsFactory.createCacheOptions(),
48+
useFactory: async (optionsFactory) => optionsFactory.createCacheOptions(),
4949
inject: [options.useExisting || options.useClass],
5050
};
5151
}

bundle/common/files/multer.module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let MulterModule = MulterModule_1 = class MulterModule {
4646
}
4747
return {
4848
provide: files_constants_1.MULTER_MODULE_OPTIONS,
49-
useFactory: async (optionsFactory) => await optionsFactory.createMulterOptions(),
49+
useFactory: async (optionsFactory) => optionsFactory.createMulterOptions(),
5050
inject: [options.useExisting || options.useClass],
5151
};
5252
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nestjs",
3-
"version": "5.3.8",
3+
"version": "5.3.10",
44
"description": "Modern, fast, powerful node.js web framework",
55
"scripts": {
66
"coverage": "nyc report --reporter=text-lcov | coveralls",
@@ -13,7 +13,7 @@
1313
"build:lib": "gulp build --dist bundle",
1414
"postinstall": "opencollective",
1515
"copy-docs": "gulp copy-docs",
16-
"prepare": "npm run build:lib && npm run copy-docs",
16+
"prepare:npm": "npm run build:lib && npm run copy-docs",
1717
"prepare:rc": "npm run build:lib && npm run copy-docs",
1818
"prepare:next": "npm run build:lib && npm run copy-docs",
1919
"prepare:beta": "npm run build:lib && npm run copy-docs",

packages/core/injector/injector.ts

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ export class Injector {
5252
) {
5353
const { metatype } = wrapper;
5454
const currentMetatype = collection.get(metatype.name);
55-
if (currentMetatype.instance !== null) return;
56-
55+
if (currentMetatype.instance !== null) {
56+
return;
57+
}
5758
await this.resolveConstructorParams(
5859
wrapper as any,
5960
module,
@@ -87,12 +88,13 @@ export class Injector {
8788
{ metatype, name }: InstanceWrapper<T>,
8889
collection: Map<string, InstanceWrapper<T>>,
8990
) {
90-
if (!collection) return null;
91-
91+
if (!collection) {
92+
return null;
93+
}
9294
const target = collection.get(name);
93-
if (target.isResolved || !isNil(target.inject) || !metatype.prototype)
95+
if (target.isResolved || !isNil(target.inject) || !metatype.prototype) {
9496
return null;
95-
97+
}
9698
collection.set(name, {
9799
...collection.get(name),
98100
instance: Object.create(metatype.prototype),
@@ -125,32 +127,21 @@ export class Injector {
125127
return wrapper.done$;
126128
}
127129
const done = this.applyDoneHook(wrapper);
128-
const { metatype, name, inject } = wrapper;
129-
const currentMetatype = collection.get(name);
130-
if (isUndefined(currentMetatype)) {
130+
const { name, inject } = wrapper;
131+
132+
const targetMetatype = collection.get(name);
133+
if (isUndefined(targetMetatype)) {
131134
throw new RuntimeException();
132135
}
133-
if (currentMetatype.isResolved) {
136+
if (targetMetatype.isResolved) {
134137
return void 0;
135138
}
136-
137139
await this.resolveConstructorParams<T>(
138140
wrapper,
139141
module,
140142
inject,
141-
async instances => {
142-
if (isNil(inject)) {
143-
currentMetatype.instance = Object.assign(
144-
currentMetatype.instance,
145-
new metatype(...instances),
146-
);
147-
} else {
148-
const factoryResult = currentMetatype.metatype(...instances);
149-
currentMetatype.instance = await factoryResult;
150-
}
151-
currentMetatype.isResolved = true;
152-
done();
153-
},
143+
async instances =>
144+
this.instantiateClass(instances, wrapper, targetMetatype, done),
154145
);
155146
}
156147

@@ -269,17 +260,11 @@ export class Injector {
269260
) {
270261
const { name } = dependencyContext;
271262
const scanInExports = () =>
272-
this.lookupComponentInExports(
273-
components,
274-
dependencyContext,
275-
module,
276-
wrapper,
277-
);
263+
this.lookupComponentInExports(dependencyContext, module, wrapper);
278264
return components.has(name) ? components.get(name) : scanInExports();
279265
}
280266

281267
public async lookupComponentInExports<T = any>(
282-
components: Map<string, any>,
283268
dependencyContext: InjectorDependencyContext,
284269
module: Module,
285270
wrapper: InstanceWrapper<T>,
@@ -328,4 +313,26 @@ export class Injector {
328313
}
329314
return componentRef;
330315
}
316+
317+
public async instantiateClass(
318+
instances: any[],
319+
wrapper: InstanceWrapper<any>,
320+
targetMetatype: InstanceWrapper<any>,
321+
done: Function,
322+
) {
323+
const { metatype, inject } = wrapper;
324+
if (isNil(inject)) {
325+
targetMetatype.instance = Object.assign(
326+
targetMetatype.instance,
327+
new metatype(...instances),
328+
);
329+
} else {
330+
const factoryResult = ((targetMetatype.metatype as any) as Function)(
331+
...instances,
332+
);
333+
targetMetatype.instance = await factoryResult;
334+
}
335+
targetMetatype.isResolved = true;
336+
done();
337+
}
331338
}

scripts/prepare.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# 1. Install all dependencies
2+
for D in integration/*; do [ -d "${D}" ] && npm i; done
3+
4+
# 2. Build fresh packages and move them to sample and integration directories
5+
npm run build &>/dev/null
6+
7+
# 3. Start docker containers to perform integration tests
8+
cd integration && docker-compose up -d

scripts/run-integration.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# 1. Build fresh packages and move them integration dit
2+
npm run build &>/dev/null
3+
4+
# 2. Start docker containers to perform integration tests
5+
cd integration && docker-compose up -d
6+
7+
# 3. Run integration tests
8+
npm run integration-test

scripts/test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Run both unit and integration tests
2+
npm run test
3+
npm run integration-test

test.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)