Skip to content

Commit

Permalink
chore(nestjs) add scripts directory
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Oct 3, 2018
1 parent 1acae78 commit 3a74c79
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 61 deletions.
2 changes: 1 addition & 1 deletion bundle/common/cache/cache.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let CacheModule = CacheModule_1 = class CacheModule {
}
return {
provide: cache_constants_1.CACHE_MODULE_OPTIONS,
useFactory: async (optionsFactory) => await optionsFactory.createCacheOptions(),
useFactory: async (optionsFactory) => optionsFactory.createCacheOptions(),
inject: [options.useExisting || options.useClass],
};
}
Expand Down
2 changes: 1 addition & 1 deletion bundle/common/files/multer.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ let MulterModule = MulterModule_1 = class MulterModule {
}
return {
provide: files_constants_1.MULTER_MODULE_OPTIONS,
useFactory: async (optionsFactory) => await optionsFactory.createMulterOptions(),
useFactory: async (optionsFactory) => optionsFactory.createMulterOptions(),
inject: [options.useExisting || options.useClass],
};
}
Expand Down
53 changes: 25 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
{
"name": "nestjs",
"version": "5.3.8",
"version": "5.3.10",
"description": "Modern, fast, powerful node.js web framework",
"scripts": {
"coverage": "nyc report --reporter=text-lcov | coveralls",
"precommit": "lint-staged",
"test": "nyc --require ts-node/register mocha packages/**/*.spec.ts --reporter spec",
"integration-test": "mocha integration/**/*.spec.ts --reporter spec --require ts-node/register",
"lint": "tslint -p tsconfig.json -c tslint.json \"packages/**/*.ts\" -e \"*.spec.ts\"",
"format": "prettier **/**/*.ts --ignore-path ./.prettierignore --write && git status",
"test":
"nyc --require ts-node/register mocha packages/**/*.spec.ts --reporter spec",
"integration-test":
"mocha integration/**/*.spec.ts --reporter spec --require ts-node/register",
"lint":
"tslint -p tsconfig.json -c tslint.json \"packages/**/*.ts\" -e \"*.spec.ts\"",
"format":
"prettier **/**/*.ts --ignore-path ./.prettierignore --write && git status",
"build": "gulp build && gulp move",
"build:lib": "gulp build --dist bundle",
"postinstall": "opencollective",
"copy-docs": "gulp copy-docs",
"prepare": "npm run build:lib && npm run copy-docs",
"prepare:npm": "npm run build:lib && npm run copy-docs",
"prepare:rc": "npm run build:lib && npm run copy-docs",
"prepare:next": "npm run build:lib && npm run copy-docs",
"prepare:beta": "npm run build:lib && npm run copy-docs",
"publish": "npm run prepare && ./node_modules/.bin/lerna publish --exact -m \"chore(@nestjs) publish %s release\"",
"publish:rc": "npm run prepare && ./node_modules/.bin/lerna publish --npm-tag=rc -m \"chore(@nestjs) publish %s release\"",
"publish:next": "npm run prepare && ./node_modules/.bin/lerna publish --npm-tag=next --skip-git -m \"chore(@nestjs) publish %s release\"",
"publish:beta": "npm run prepare && ./node_modules/.bin/lerna publish --npm-tag=beta -m \"chore(@nestjs) publish %s release\"",
"publish:test": "npm run prepare && ./node_modules/.bin/lerna publish --npm-tag=test --skip-git -m \"chore(@nestjs) publish %s release\""
"publish":
"npm run prepare && ./node_modules/.bin/lerna publish --exact -m \"chore(@nestjs) publish %s release\"",
"publish:rc":
"npm run prepare && ./node_modules/.bin/lerna publish --npm-tag=rc -m \"chore(@nestjs) publish %s release\"",
"publish:next":
"npm run prepare && ./node_modules/.bin/lerna publish --npm-tag=next --skip-git -m \"chore(@nestjs) publish %s release\"",
"publish:beta":
"npm run prepare && ./node_modules/.bin/lerna publish --npm-tag=beta -m \"chore(@nestjs) publish %s release\"",
"publish:test":
"npm run prepare && ./node_modules/.bin/lerna publish --npm-tag=test --skip-git -m \"chore(@nestjs) publish %s release\""
},
"engines": {
"node": ">= 8.9.0"
Expand Down Expand Up @@ -130,9 +139,7 @@
}
},
"nyc": {
"include": [
"packages/**/*.ts"
],
"include": ["packages/**/*.ts"],
"exclude": [
"node_modules/",
"packages/**/*.spec.ts",
Expand All @@ -151,23 +158,13 @@
"packages/common/serializer/**/*",
"packages/common/services/logger.service.ts"
],
"extension": [
".ts"
],
"require": [
"ts-node/register"
],
"reporter": [
"text-summary",
"html"
],
"extension": [".ts"],
"require": ["ts-node/register"],
"reporter": ["text-summary", "html"],
"sourceMap": true,
"instrument": true
},
"lint-staged": {
"packages/**/*.{ts,json}": [
"npm run format",
"git add"
]
"packages/**/*.{ts,json}": ["npm run format", "git add"]
}
}
69 changes: 38 additions & 31 deletions packages/core/injector/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ export class Injector {
) {
const { metatype } = wrapper;
const currentMetatype = collection.get(metatype.name);
if (currentMetatype.instance !== null) return;

if (currentMetatype.instance !== null) {
return;
}
await this.resolveConstructorParams(
wrapper as any,
module,
Expand Down Expand Up @@ -87,12 +88,13 @@ export class Injector {
{ metatype, name }: InstanceWrapper<T>,
collection: Map<string, InstanceWrapper<T>>,
) {
if (!collection) return null;

if (!collection) {
return null;
}
const target = collection.get(name);
if (target.isResolved || !isNil(target.inject) || !metatype.prototype)
if (target.isResolved || !isNil(target.inject) || !metatype.prototype) {
return null;

}
collection.set(name, {
...collection.get(name),
instance: Object.create(metatype.prototype),
Expand Down Expand Up @@ -125,32 +127,21 @@ export class Injector {
return wrapper.done$;
}
const done = this.applyDoneHook(wrapper);
const { metatype, name, inject } = wrapper;
const currentMetatype = collection.get(name);
if (isUndefined(currentMetatype)) {
const { name, inject } = wrapper;

const targetMetatype = collection.get(name);
if (isUndefined(targetMetatype)) {
throw new RuntimeException();
}
if (currentMetatype.isResolved) {
if (targetMetatype.isResolved) {
return void 0;
}

await this.resolveConstructorParams<T>(
wrapper,
module,
inject,
async instances => {
if (isNil(inject)) {
currentMetatype.instance = Object.assign(
currentMetatype.instance,
new metatype(...instances),
);
} else {
const factoryResult = currentMetatype.metatype(...instances);
currentMetatype.instance = await factoryResult;
}
currentMetatype.isResolved = true;
done();
},
async instances =>
this.instantiateClass(instances, wrapper, targetMetatype, done),
);
}

Expand Down Expand Up @@ -269,17 +260,11 @@ export class Injector {
) {
const { name } = dependencyContext;
const scanInExports = () =>
this.lookupComponentInExports(
components,
dependencyContext,
module,
wrapper,
);
this.lookupComponentInExports(dependencyContext, module, wrapper);
return components.has(name) ? components.get(name) : scanInExports();
}

public async lookupComponentInExports<T = any>(
components: Map<string, any>,
dependencyContext: InjectorDependencyContext,
module: Module,
wrapper: InstanceWrapper<T>,
Expand Down Expand Up @@ -328,4 +313,26 @@ export class Injector {
}
return componentRef;
}

public async instantiateClass(
instances: any[],
wrapper: InstanceWrapper<any>,
targetMetatype: InstanceWrapper<any>,
done: Function,
) {
const { metatype, inject } = wrapper;
if (isNil(inject)) {
targetMetatype.instance = Object.assign(
targetMetatype.instance,
new metatype(...instances),
);
} else {
const factoryResult = ((targetMetatype.metatype as any) as Function)(
...instances,
);
targetMetatype.instance = await factoryResult;
}
targetMetatype.isResolved = true;
done();
}
}
8 changes: 8 additions & 0 deletions scripts/prepare_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 1. Install all dependencies
for D in integration/*; do [ -d "${D}" ] && npm i; done

# 2. Build fresh packages and move them to sample and integration directories
npm run build &>/dev/null

# 3. Start docker containers to perform integration tests
cd integration && docker-compose up -d
File renamed without changes.

0 comments on commit 3a74c79

Please sign in to comment.