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