Skip to content

Commit

Permalink
Tsconfig checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
WonderPanda committed Feb 8, 2019
1 parent b817f52 commit 2f8e195
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 9 deletions.
3 changes: 2 additions & 1 deletion examples/discovery/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { AppController } from './app.controller';
import { AppService } from './app.service';
import { DiscoveryModule } from './discovery/discovery.module';
import { ExampleService } from './example/example.service';
import { AnotherService } from './example/another/another.service';

@Module({
imports: [DiscoveryModule],
controllers: [AppController],
providers: [AppService, ExampleService],
providers: [AppService, ExampleService, AnotherService],
})
export class AppModule {}
18 changes: 18 additions & 0 deletions examples/discovery/src/example/another/another.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AnotherService } from './another.service';

describe('AnotherService', () => {
let service: AnotherService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AnotherService],
}).compile();

service = module.get<AnotherService>(AnotherService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
4 changes: 4 additions & 0 deletions examples/discovery/src/example/another/another.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class AnotherService {}
2 changes: 1 addition & 1 deletion packages/caching/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"lib"
],
"scripts": {
"tsc": "tsc",
"build": "tsc --build tsconfig.build.json",
"test": "echo \"Error: run tests from root\" && exit 1"
},
"dependencies": {
Expand Down
10 changes: 10 additions & 0 deletions packages/caching/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib",
"composite": true
},
"include": ["./src"],
"exclude": ["./src/**/*.spec.ts"],
"references": [{ "path": "../common" }]
}
2 changes: 1 addition & 1 deletion packages/caching/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib"
"composite": true
},
"include": ["./src"],
"references": [{ "path": "../common" }]
Expand Down
47 changes: 47 additions & 0 deletions packages/common/__tests__/discovery/discovery.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Injectable, Module, ReflectMetadata } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import {
DiscoveryModule,
DiscoveryService,
withMetaKey
} from '../../src/discovery';

const TestConfigSymbol = Symbol('TestConfigSymbol');

const TestDecorator = (config: any) =>
ReflectMetadata(TestConfigSymbol, config);

@Injectable()
@TestDecorator('42')
class ExampleService {
doSomething() {
console.log('doing something');
}
}

@Module({
providers: [ExampleService]
})
class ExampleModule {}

describe('Discovery', () => {
let app: TestingModule;

beforeEach(async () => {
app = await Test.createTestingModule({
imports: [DiscoveryModule, ExampleModule]
}).compile();

await app.init();
});

it('should discover providers based on metadata', () => {
const discoveryService = app.get<DiscoveryService>(DiscoveryService);
const testProviders = discoveryService.discoverClasses(x =>
withMetaKey(TestConfigSymbol, x)
);

expect(testProviders).toHaveLength(1);
console.log(testProviders[0].instance);
});
});
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"url": "git+https://github.com/WonderPanda/nestjs-plus.git"
},
"scripts": {
"tsc": "tsc",
"build": "tsc --build tsconfig.build.json",
"test": "jest"
},
"bugs": {
Expand Down
6 changes: 4 additions & 2 deletions packages/common/src/discovery/discovery.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { ModulesContainer } from '@nestjs/core/injector/modules-container';
import { MetadataScanner } from '@nestjs/core/metadata-scanner';
import { flatMap } from 'lodash';

export const withMetaKey = (
export function withMetaKey(
metaKey: string | number | Symbol,
injectableWrapper: InstanceWrapper<NestInjectable>
) => Reflect.getMetadata(metaKey, injectableWrapper.instance.constructor);
): boolean {
return Reflect.getMetadata(metaKey, injectableWrapper.instance.constructor);
}

@Injectable()
export class DiscoveryService {
Expand Down
8 changes: 8 additions & 0 deletions packages/common/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./lib",
"composite": true
},
"exclude": ["./src/**/*.spec.ts"]
}
1 change: 0 additions & 1 deletion packages/common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib",
"composite": true
},
"include": ["./src"]
Expand Down
3 changes: 2 additions & 1 deletion packages/rabbitmq/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"outDir": "./lib",
"composite": true
},
"include": ["./src"]
"include": ["./src"],
"exclude": ["./src/**/*.spec.ts"]
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"@nestjs-plus/*": ["./*/src"]
}
},
"exclude": ["node_modules", "**/*.spec.ts"]
"exclude": ["node_modules"]
}

0 comments on commit 2f8e195

Please sign in to comment.