| @@ -1,28 +1,33 | |||||
| 1 | HISTORY |
|
1 | HISTORY | |
| 2 | ======= |
|
2 | ======= | |
| 3 |
|
3 | |||
|
|
4 | 1.2.17 | |||
|
|
5 | ------ | |||
|
|
6 | ||||
|
|
7 | Bug fixes | |||
|
|
8 | ||||
| 4 | 1.2.16 |
|
9 | 1.2.16 | |
| 5 | ------ |
|
10 | ------ | |
| 6 |
|
11 | |||
| 7 | Minor fixes and improvements |
|
12 | Minor fixes and improvements | |
| 8 |
|
13 | |||
| 9 | - added `isCancellable` type predicate function to `safe` module |
|
14 | - added `isCancellable` type predicate function to `safe` module | |
| 10 | - `isString, isNumber, isInteger, isPrimitive` are now type predicates |
|
15 | - `isString, isNumber, isInteger, isPrimitive` are now type predicates | |
| 11 |
|
16 | |||
| 12 | 1.2.0 |
|
17 | 1.2.0 | |
| 13 | ----- |
|
18 | ----- | |
| 14 |
|
19 | |||
| 15 | Major rafactoring, moving to support both browser (rjs) and server (cjs) environments. |
|
20 | Major rafactoring, moving to support both browser (rjs) and server (cjs) environments. | |
| 16 |
|
21 | |||
| 17 | - dependency injection container ported to typescript |
|
22 | - dependency injection container ported to typescript | |
| 18 | - sources are split to several sets to provide the ability for the conditional build of the project. |
|
23 | - sources are split to several sets to provide the ability for the conditional build of the project. | |
| 19 |
|
24 | |||
| 20 | 1.0.1 |
|
25 | 1.0.1 | |
| 21 | ----- |
|
26 | ----- | |
| 22 |
|
27 | |||
| 23 | First release, intorduces the following features |
|
28 | First release, intorduces the following features | |
| 24 |
|
29 | |||
| 25 | - `di` - dependency injection container |
|
30 | - `di` - dependency injection container | |
| 26 | - `log` - log4 style logging system |
|
31 | - `log` - log4 style logging system | |
| 27 | - `text` - simple and fast text templating and formatting |
|
32 | - `text` - simple and fast text templating and formatting | |
| 28 | - `Uuid` - uuid generation traits No newline at end of file |
|
33 | - `Uuid` - uuid generation traits | |
| @@ -1,41 +1,45 | |||||
| 1 | import { Uuid } from "../Uuid"; |
|
1 | import { Uuid } from "../Uuid"; | |
| 2 |
import { argumentNotEmptyString, getGlobal |
|
2 | import { argumentNotEmptyString, getGlobal } from "../safe"; | |
| 3 | import { TraceSource } from "../log/TraceSource"; |
|
3 | import { TraceSource } from "../log/TraceSource"; | |
| 4 | import m = require("module"); |
|
4 | import m = require("module"); | |
| 5 |
|
5 | |||
| 6 | const sandboxId = Uuid(); |
|
6 | const sandboxId = Uuid(); | |
| 7 | define(sandboxId, ["require"], r => r); |
|
7 | define(sandboxId, ["require"], r => r); | |
| 8 |
|
8 | |||
| 9 | // tslint:disable-next-line:no-var-requires |
|
9 | const globalRequire = getGlobal().require as Require || requirejs; | |
| 10 | const globalRequire = getGlobal().require as Require; |
|
|||
| 11 |
|
10 | |||
| 12 | const trace = TraceSource.get(m.id); |
|
11 | const trace = TraceSource.get(m.id); | |
|
|
12 | trace.debug("globalRequire = {0}", globalRequire); | |||
| 13 |
|
13 | |||
| 14 | class ModuleResolver { |
|
14 | class ModuleResolver { | |
| 15 | _base: string; |
|
15 | _base: string; | |
| 16 | _require: Require; |
|
16 | _require: Require; | |
| 17 |
|
17 | |||
| 18 | constructor(req: Require, base?: string) { |
|
18 | constructor(req: Require, base?: string) { | |
| 19 | this._base = base; |
|
19 | this._base = base; | |
| 20 | this._require = req; |
|
20 | this._require = req; | |
| 21 | } |
|
21 | } | |
| 22 |
|
22 | |||
| 23 | resolve(moduleName: string) { |
|
23 | resolve(moduleName: string) { | |
| 24 | argumentNotEmptyString(moduleName, "moduleName"); |
|
24 | argumentNotEmptyString(moduleName, "moduleName"); | |
| 25 | const resolvedName = moduleName[0] === "." && this._base ? [this._base, moduleName].join("/") : moduleName; |
|
25 | const resolvedName = moduleName[0] === "." && this._base ? [this._base, moduleName].join("/") : moduleName; | |
| 26 | trace.debug(`${moduleName} -> ${resolvedName}`); |
|
26 | trace.debug(`${moduleName} -> ${resolvedName}`); | |
| 27 |
|
27 | |||
| 28 | const req = this._require; |
|
28 | const req = this._require; | |
| 29 |
|
29 | |||
| 30 | return new Promise<any>((cb, eb) => { |
|
30 | return new Promise<any>((cb, eb) => { | |
| 31 | req([resolvedName], cb, eb); |
|
31 | req([resolvedName], cb, eb); | |
| 32 | }); |
|
32 | }); | |
| 33 | } |
|
33 | } | |
| 34 | } |
|
34 | } | |
| 35 |
|
35 | |||
| 36 | export function makeResolver(moduleName: string, contextRequire: Require) { |
|
36 | export function makeResolver(moduleName: string, contextRequire: Require) { | |
| 37 | const base = moduleName && moduleName.split("/").slice(0, -1).join("/"); |
|
37 | const base = moduleName && moduleName.split("/").slice(0, -1).join("/"); | |
| 38 |
|
38 | |||
| 39 |
const re |
|
39 | const req = contextRequire || globalRequire; | |
|
|
40 | if (!req) | |||
|
|
41 | throw new Error("A global require isn't defined, the contextRequire parameter is mandatory"); | |||
|
|
42 | ||||
|
|
43 | const resolver = new ModuleResolver(req, base); | |||
| 40 | return (id: string) => resolver.resolve(id); |
|
44 | return (id: string) => resolver.resolve(id); | |
| 41 | } |
|
45 | } | |
General Comments 0
You need to be logged in to leave comments.
Login now
