|
|
1 | 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 | 91 | "duplexer": { |
|
|
92 | 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 | 94 | "integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=", |
|
|
95 | 95 | "dev": true |
|
|
96 | 96 | }, |
| @@ -135,7 +135,7 | |||
|
|
135 | 135 | "dependencies": { |
|
|
136 | 136 | "tape": { |
|
|
137 | 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 | 139 | "integrity": "sha1-Lnzgox3wn41oUWZKcYQuDKUFevc=", |
|
|
140 | 140 | "dev": true, |
|
|
141 | 141 | "requires": { |
| @@ -295,7 +295,7 | |||
|
|
295 | 295 | }, |
|
|
296 | 296 | "path-is-absolute": { |
|
|
297 | 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 | 299 | "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", |
|
|
300 | 300 | "dev": true |
|
|
301 | 301 | }, |
| @@ -307,7 +307,7 | |||
|
|
307 | 307 | }, |
|
|
308 | 308 | "readable-stream": { |
|
|
309 | 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 | 311 | "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", |
|
|
312 | 312 | "dev": true, |
|
|
313 | 313 | "requires": { |
| @@ -360,7 +360,7 | |||
|
|
360 | 360 | }, |
|
|
361 | 361 | "string_decoder": { |
|
|
362 | 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 | 364 | "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", |
|
|
365 | 365 | "dev": true |
|
|
366 | 366 | }, |
| @@ -417,13 +417,13 | |||
|
|
417 | 417 | }, |
|
|
418 | 418 | "through": { |
|
|
419 | 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 | 421 | "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", |
|
|
422 | 422 | "dev": true |
|
|
423 | 423 | }, |
|
|
424 | 424 | "through2": { |
|
|
425 | 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 | 427 | "integrity": "sha1-6zKE2k6jEbbMis42U3SKUqvyWj8=", |
|
|
428 | 428 | "dev": true, |
|
|
429 | 429 | "requires": { |
| @@ -1,12 +1,7 | |||
|
|
1 | 1 | import { Uuid } from "../Uuid"; |
|
|
2 | import { argumentNotEmptyString } from "../safe"; | |
|
|
2 | import { argumentNotEmptyString, argumentNotNull } from "../safe"; | |
|
|
3 | 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 | 5 | const trace = TraceSource.get("@implab/core/di/RequireJsHelper"); |
|
|
11 | 6 | |
|
|
12 | 7 | export async function createContextRequire(moduleName: string): Promise<Require> { |
| @@ -25,11 +20,21 export async function createContextRequi | |||
|
|
25 | 20 | |
|
|
26 | 21 | trace.debug(`define shim ${shim}`); |
|
|
27 | 22 | |
|
|
28 |
return new Promise<Require>( |
|
|
|
23 | return new Promise<Require>(cb => { | |
|
|
29 | 24 | define(shim, ["require"], r => { |
|
|
30 | 25 | trace.debug("shim resolved"); |
|
|
31 | 26 | return r; |
|
|
32 | 27 | }); |
|
|
33 |
require([shim], |
|
|
|
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 | 20 | import { ReferenceDescriptor } from "./ReferenceDescriptor"; |
|
|
21 | 21 | import { TypeServiceDescriptor } from "./TypeServiceDescriptor"; |
|
|
22 | 22 | import { FactoryServiceDescriptor } from "./FactoryServiceDescriptor"; |
|
|
23 | import { rjs, createContextRequire } from "./RequireJsHelper"; | |
|
|
24 | 23 | import { TraceSource } from "../log/TraceSource"; |
|
|
25 | 24 | import { ConfigError } from "./ConfigError"; |
|
|
26 | 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> { | |
|
|
48 | [key: string]: T; | |
|
|
49 | } | |
|
|
46 | type Resolver = (qname: string) => any; | |
|
|
50 | 47 | |
|
|
51 | 48 | type _key = string | number; |
|
|
52 | 49 | |
| @@ -60,7 +57,7 export class Configuration { | |||
|
|
60 | 57 | |
|
|
61 | 58 | _configName: string; |
|
|
62 | 59 | |
|
|
63 |
_require |
|
|
|
60 | _require: Resolver; | |
|
|
64 | 61 | |
|
|
65 | 62 | constructor(container: Container) { |
|
|
66 | 63 | argumentNotNull(container, container); |
| @@ -68,37 +65,15 export class Configuration { | |||
|
|
68 | 65 | this._path = []; |
|
|
69 | 66 | } |
|
|
70 | 67 | |
|
|
71 |
async |
|
|
|
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) { | |
|
|
68 | async applyConfiguration(data: object, resolver?: Resolver, ct = Cancellation.none) { | |
|
|
94 | 69 | argumentNotNull(data, "data"); |
|
|
95 | 70 | |
|
|
96 | 71 | trace.log("applyConfiguration"); |
|
|
97 | 72 | |
|
|
98 | 73 | this._configName = "$"; |
|
|
99 | 74 | |
|
|
100 |
if ( |
|
|
|
101 |
this._require = |
|
|
|
75 | if (resolver) | |
|
|
76 | this._require = resolver; | |
|
|
102 | 77 | |
|
|
103 | 78 | let services: ServiceMap; |
|
|
104 | 79 | |
| @@ -142,17 +117,11 export class Configuration { | |||
|
|
142 | 117 | async _loadModule(moduleName: string) { |
|
|
143 | 118 | trace.debug("loadModule {0}", moduleName); |
|
|
144 | 119 | |
|
|
145 |
const m = await |
|
|
|
146 | this._require([moduleName], fulfill); | |
|
|
147 | }); | |
|
|
120 | const m = await this._require(moduleName); | |
|
|
148 | 121 | |
|
|
149 | 122 | return m; |
|
|
150 | 123 | } |
|
|
151 | 124 | |
|
|
152 | _createContextRequire(moduleName: string) { | |
|
|
153 | return createContextRequire(moduleName); | |
|
|
154 | } | |
|
|
155 | ||
|
|
156 | 125 | async _visitRegistrations(data, name: _key) { |
|
|
157 | 126 | this._enter(name); |
|
|
158 | 127 | |
| @@ -99,7 +99,7 export class Container { | |||
|
|
99 | 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? |
|
|
|
102 | async configure(config: string | object, opts?, ct = Cancellation.none) { | |
|
|
103 | 103 | const c = new Configuration(this); |
|
|
104 | 104 | |
|
|
105 | 105 | if (typeof (config) === "string") { |
|
|
1 | 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 |
|
|
1 | 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 |
|
|
1 | 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 |
|
|
1 | 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 |
|
|
1 | 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 |
|
|
1 | 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 |
|
|
1 | 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 |
|
|
1 | 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 |
General Comments 0
You need to be logged in to leave comments.
Login now
