##// END OF EJS Templates
tests moved under src/ folder...
cin -
r50:7a4fac383b10 di-typescript
parent child
Show More
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
@@ -0,0 +1,11
1 {
2 "extends": "../tsconfig.json",
3 "compilerOptions": {
4 "types": [
5 "@types/node"
6 ]
7 },
8 "include": [
9 "ts/**/*.ts"
10 ]
11 } No newline at end of file
@@ -90,7 +90,7
90 },
90 },
91 "duplexer": {
91 "duplexer": {
92 "version": "0.1.1",
92 "version": "0.1.1",
93 "resolved": "http://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz",
93 "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz",
94 "integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=",
94 "integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=",
95 "dev": true
95 "dev": true
96 },
96 },
@@ -135,7 +135,7
135 "dependencies": {
135 "dependencies": {
136 "tape": {
136 "tape": {
137 "version": "2.3.3",
137 "version": "2.3.3",
138 "resolved": "http://registry.npmjs.org/tape/-/tape-2.3.3.tgz",
138 "resolved": "https://registry.npmjs.org/tape/-/tape-2.3.3.tgz",
139 "integrity": "sha1-Lnzgox3wn41oUWZKcYQuDKUFevc=",
139 "integrity": "sha1-Lnzgox3wn41oUWZKcYQuDKUFevc=",
140 "dev": true,
140 "dev": true,
141 "requires": {
141 "requires": {
@@ -295,7 +295,7
295 },
295 },
296 "path-is-absolute": {
296 "path-is-absolute": {
297 "version": "1.0.1",
297 "version": "1.0.1",
298 "resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
298 "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
299 "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
299 "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
300 "dev": true
300 "dev": true
301 },
301 },
@@ -307,7 +307,7
307 },
307 },
308 "readable-stream": {
308 "readable-stream": {
309 "version": "1.1.14",
309 "version": "1.1.14",
310 "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
310 "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
311 "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
311 "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
312 "dev": true,
312 "dev": true,
313 "requires": {
313 "requires": {
@@ -360,7 +360,7
360 },
360 },
361 "string_decoder": {
361 "string_decoder": {
362 "version": "0.10.31",
362 "version": "0.10.31",
363 "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
363 "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
364 "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
364 "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
365 "dev": true
365 "dev": true
366 },
366 },
@@ -417,13 +417,13
417 },
417 },
418 "through": {
418 "through": {
419 "version": "2.3.8",
419 "version": "2.3.8",
420 "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz",
420 "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
421 "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=",
421 "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=",
422 "dev": true
422 "dev": true
423 },
423 },
424 "through2": {
424 "through2": {
425 "version": "0.2.3",
425 "version": "0.2.3",
426 "resolved": "http://registry.npmjs.org/through2/-/through2-0.2.3.tgz",
426 "resolved": "https://registry.npmjs.org/through2/-/through2-0.2.3.tgz",
427 "integrity": "sha1-6zKE2k6jEbbMis42U3SKUqvyWj8=",
427 "integrity": "sha1-6zKE2k6jEbbMis42U3SKUqvyWj8=",
428 "dev": true,
428 "dev": true,
429 "requires": {
429 "requires": {
@@ -1,12 +1,7
1 import { Uuid } from "../Uuid";
1 import { Uuid } from "../Uuid";
2 import { argumentNotEmptyString } from "../safe";
2 import { argumentNotEmptyString, argumentNotNull } from "../safe";
3 import { TraceSource } from "../log/TraceSource";
3 import { TraceSource } from "../log/TraceSource";
4
4
5 export const rjs = require;
6
7 declare function define(name: string, modules: string[], cb?: (...args: any[]) => any, eb?: (e) => any): void;
8 declare function define(modules: string[], cb?: (...args: any[]) => any, eb?: (e) => any): void;
9
10 const trace = TraceSource.get("@implab/core/di/RequireJsHelper");
5 const trace = TraceSource.get("@implab/core/di/RequireJsHelper");
11
6
12 export async function createContextRequire(moduleName: string): Promise<Require> {
7 export async function createContextRequire(moduleName: string): Promise<Require> {
@@ -25,11 +20,21 export async function createContextRequi
25
20
26 trace.debug(`define shim ${shim}`);
21 trace.debug(`define shim ${shim}`);
27
22
28 return new Promise<Require>(fulfill => {
23 return new Promise<Require>(cb => {
29 define(shim, ["require"], r => {
24 define(shim, ["require"], r => {
30 trace.debug("shim resolved");
25 trace.debug("shim resolved");
31 return r;
26 return r;
32 });
27 });
33 require([shim], fulfill);
28 require([shim], cb);
34 });
29 });
35 }
30 }
31
32 export function makeResolver(req: Require) {
33 argumentNotNull(req, "req");
34
35 return (name: string) => {
36 return new Promise<any>((cb, eb) => {
37 req([name], cb, eb);
38 });
39 };
40 }
@@ -20,7 +20,6 import { Container } from "./Container";
20 import { ReferenceDescriptor } from "./ReferenceDescriptor";
20 import { ReferenceDescriptor } from "./ReferenceDescriptor";
21 import { TypeServiceDescriptor } from "./TypeServiceDescriptor";
21 import { TypeServiceDescriptor } from "./TypeServiceDescriptor";
22 import { FactoryServiceDescriptor } from "./FactoryServiceDescriptor";
22 import { FactoryServiceDescriptor } from "./FactoryServiceDescriptor";
23 import { rjs, createContextRequire } from "./RequireJsHelper";
24 import { TraceSource } from "../log/TraceSource";
23 import { TraceSource } from "../log/TraceSource";
25 import { ConfigError } from "./ConfigError";
24 import { ConfigError } from "./ConfigError";
26 import { Cancellation } from "../Cancellation";
25 import { Cancellation } from "../Cancellation";
@@ -44,9 +43,7 async function mapAll(data: object | any
44 }
43 }
45 }
44 }
46
45
47 interface MapOf<T> {
46 type Resolver = (qname: string) => any;
48 [key: string]: T;
49 }
50
47
51 type _key = string | number;
48 type _key = string | number;
52
49
@@ -60,7 +57,7 export class Configuration {
60
57
61 _configName: string;
58 _configName: string;
62
59
63 _require = rjs;
60 _require: Resolver;
64
61
65 constructor(container: Container) {
62 constructor(container: Container) {
66 argumentNotNull(container, container);
63 argumentNotNull(container, container);
@@ -68,37 +65,15 export class Configuration {
68 this._path = [];
65 this._path = [];
69 }
66 }
70
67
71 async loadConfiguration(moduleName: string, ct = Cancellation.none) {
68 async applyConfiguration(data: object, resolver?: Resolver, ct = Cancellation.none) {
72 argumentNotEmptyString(moduleName, "moduleName");
73
74 trace.log("loadConfiguration {0}", moduleName);
75
76 this._configName = moduleName;
77
78 const config = await this._loadModule(moduleName);
79
80 this._require = await this._createContextRequire(moduleName);
81
82 let services: ServiceMap;
83
84 try {
85 services = await this._visitRegistrations(config, moduleName);
86 } catch (e) {
87 throw this._makeError(e);
88 }
89
90 this._container.register(services);
91 }
92
93 async applyConfiguration(data: object, contextRequire?: Require, ct = Cancellation.none) {
94 argumentNotNull(data, "data");
69 argumentNotNull(data, "data");
95
70
96 trace.log("applyConfiguration");
71 trace.log("applyConfiguration");
97
72
98 this._configName = "$";
73 this._configName = "$";
99
74
100 if (contextRequire)
75 if (resolver)
101 this._require = contextRequire;
76 this._require = resolver;
102
77
103 let services: ServiceMap;
78 let services: ServiceMap;
104
79
@@ -142,17 +117,11 export class Configuration {
142 async _loadModule(moduleName: string) {
117 async _loadModule(moduleName: string) {
143 trace.debug("loadModule {0}", moduleName);
118 trace.debug("loadModule {0}", moduleName);
144
119
145 const m = await new Promise(fulfill => {
120 const m = await this._require(moduleName);
146 this._require([moduleName], fulfill);
147 });
148
121
149 return m;
122 return m;
150 }
123 }
151
124
152 _createContextRequire(moduleName: string) {
153 return createContextRequire(moduleName);
154 }
155
156 async _visitRegistrations(data, name: _key) {
125 async _visitRegistrations(data, name: _key) {
157 this._enter(name);
126 this._enter(name);
158
127
@@ -99,7 +99,7 export class Container {
99 * The function which will be used to load a configuration or types for services.
99 * The function which will be used to load a configuration or types for services.
100 *
100 *
101 */
101 */
102 async configure(config: string | object, opts?: any, ct = Cancellation.none) {
102 async configure(config: string | object, opts?, ct = Cancellation.none) {
103 const c = new Configuration(this);
103 const c = new Configuration(this);
104
104
105 if (typeof (config) === "string") {
105 if (typeof (config) === "string") {
1 NO CONTENT: file renamed from test/js/example.js to src/test/js/example.js
NO CONTENT: file renamed from test/js/example.js to src/test/js/example.js
1 NO CONTENT: file renamed from test/js/mock/config1.js to src/test/js/mock/config1.js
NO CONTENT: file renamed from test/js/mock/config1.js to src/test/js/mock/config1.js
1 NO CONTENT: file renamed from test/js/plan.js to src/test/js/plan.js
NO CONTENT: file renamed from test/js/plan.js to src/test/js/plan.js
1 NO CONTENT: file renamed from test/js/trace-test.js to src/test/js/trace-test.js
NO CONTENT: file renamed from test/js/trace-test.js to src/test/js/trace-test.js
1 NO CONTENT: file renamed from test/ts/ActivatableTests.ts to src/test/ts/ActivatableTests.ts
NO CONTENT: file renamed from test/ts/ActivatableTests.ts to src/test/ts/ActivatableTests.ts
1 NO CONTENT: file renamed from test/ts/CancellationTests.ts to src/test/ts/CancellationTests.ts
NO CONTENT: file renamed from test/ts/CancellationTests.ts to src/test/ts/CancellationTests.ts
1 NO CONTENT: file renamed from test/ts/ContainerTests.ts to src/test/ts/ContainerTests.ts
NO CONTENT: file renamed from test/ts/ContainerTests.ts to src/test/ts/ContainerTests.ts
1 NO CONTENT: file renamed from test/ts/ObservableTests.ts to src/test/ts/ObservableTests.ts
NO CONTENT: file renamed from test/ts/ObservableTests.ts to src/test/ts/ObservableTests.ts
1 NO CONTENT: file renamed from test/ts/TestTraits.ts to src/test/ts/TestTraits.ts
NO CONTENT: file renamed from test/ts/TestTraits.ts to src/test/ts/TestTraits.ts
1 NO CONTENT: file renamed from test/ts/TraceSourceTests.ts to src/test/ts/TraceSourceTests.ts
NO CONTENT: file renamed from test/ts/TraceSourceTests.ts to src/test/ts/TraceSourceTests.ts
1 NO CONTENT: file renamed from test/ts/dummy.ts to src/test/ts/dummy.ts
NO CONTENT: file renamed from test/ts/dummy.ts to src/test/ts/dummy.ts
1 NO CONTENT: file renamed from test/ts/mock/Bar.ts to src/test/ts/mock/Bar.ts
NO CONTENT: file renamed from test/ts/mock/Bar.ts to src/test/ts/mock/Bar.ts
1 NO CONTENT: file renamed from test/ts/mock/Foo.ts to src/test/ts/mock/Foo.ts
NO CONTENT: file renamed from test/ts/mock/Foo.ts to src/test/ts/mock/Foo.ts
1 NO CONTENT: file renamed from test/ts/mock/MockActivationController.ts to src/test/ts/mock/MockActivationController.ts
NO CONTENT: file renamed from test/ts/mock/MockActivationController.ts to src/test/ts/mock/MockActivationController.ts
1 NO CONTENT: file renamed from test/ts/mock/SimpleActivatable.ts to src/test/ts/mock/SimpleActivatable.ts
NO CONTENT: file renamed from test/ts/mock/SimpleActivatable.ts to src/test/ts/mock/SimpleActivatable.ts
1 NO CONTENT: file renamed from test/tsconfig.json to src/test/tsconfig.json
NO CONTENT: file renamed from test/tsconfig.json to src/test/tsconfig.json
@@ -14,7 +14,8
14 ],
14 ],
15 "rootDirs": [
15 "rootDirs": [
16 "main/ts",
16 "main/ts",
17 "amd/ts"
17 "amd/ts",
18 "cjs/ts"
18 ],
19 ],
19 "types": []
20 "types": []
20 }
21 }
General Comments 0
You need to be logged in to leave comments. Login now