##// END OF EJS Templates
Minor fixes and improvements...
cin -
r71:600f0201c4ba v1.2.16 default
parent child
Show More
@@ -1,6 +1,14
1 HISTORY
1 HISTORY
2 =======
2 =======
3
3
4 1.2.16
5 ------
6
7 Minor fixes and improvements
8
9 - added `isCancellable` type predicate function to `safe` module
10 - `isString, isNumber, isInteger, isPrimitive` are now type predicates
11
4 1.2.0
12 1.2.0
5 -----
13 -----
6
14
@@ -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 },
@@ -144,7 +144,7
144 "dependencies": {
144 "dependencies": {
145 "tape": {
145 "tape": {
146 "version": "2.3.3",
146 "version": "2.3.3",
147 "resolved": "http://registry.npmjs.org/tape/-/tape-2.3.3.tgz",
147 "resolved": "https://registry.npmjs.org/tape/-/tape-2.3.3.tgz",
148 "integrity": "sha1-Lnzgox3wn41oUWZKcYQuDKUFevc=",
148 "integrity": "sha1-Lnzgox3wn41oUWZKcYQuDKUFevc=",
149 "dev": true,
149 "dev": true,
150 "requires": {
150 "requires": {
@@ -277,7 +277,7
277 },
277 },
278 "minimist": {
278 "minimist": {
279 "version": "0.0.5",
279 "version": "0.0.5",
280 "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.5.tgz",
280 "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.5.tgz",
281 "integrity": "sha1-16oye87PUY+RBqxrjwA/o7zqhWY=",
281 "integrity": "sha1-16oye87PUY+RBqxrjwA/o7zqhWY=",
282 "dev": true
282 "dev": true
283 },
283 },
@@ -316,7 +316,7
316 },
316 },
317 "readable-stream": {
317 "readable-stream": {
318 "version": "1.1.14",
318 "version": "1.1.14",
319 "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
319 "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
320 "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
320 "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
321 "dev": true,
321 "dev": true,
322 "requires": {
322 "requires": {
@@ -369,7 +369,7
369 },
369 },
370 "string_decoder": {
370 "string_decoder": {
371 "version": "0.10.31",
371 "version": "0.10.31",
372 "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
372 "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
373 "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
373 "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
374 "dev": true
374 "dev": true
375 },
375 },
@@ -432,7 +432,7
432 },
432 },
433 "through2": {
433 "through2": {
434 "version": "0.2.3",
434 "version": "0.2.3",
435 "resolved": "http://registry.npmjs.org/through2/-/through2-0.2.3.tgz",
435 "resolved": "https://registry.npmjs.org/through2/-/through2-0.2.3.tgz",
436 "integrity": "sha1-6zKE2k6jEbbMis42U3SKUqvyWj8=",
436 "integrity": "sha1-6zKE2k6jEbbMis42U3SKUqvyWj8=",
437 "dev": true,
437 "dev": true,
438 "requires": {
438 "requires": {
@@ -1,6 +1,6
1 import { Uuid } from "../Uuid";
1 import { Uuid } from "../Uuid";
2 import { argumentNotEmptyString, getGlobal, isNullOrEmptyString } from "../safe";
2 import { argumentNotEmptyString, getGlobal, isNullOrEmptyString } from "../safe";
3 import { TraceSource, DebugLevel } 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();
@@ -11,38 +11,13 const globalRequire = getGlobal().requir
11
11
12 const trace = TraceSource.get(m.id);
12 const trace = TraceSource.get(m.id);
13
13
14 export async function createContextRequire(moduleName: string): Promise<Require> {
15 argumentNotEmptyString(moduleName, "moduleName");
16
17 const parts = moduleName.split("/");
18 if (parts[0] === ".")
19 throw new Error("An absolute module path is required");
20
21 if (parts.length > 1)
22 parts.splice(-1, 1, Uuid());
23 else
24 parts.push(Uuid());
25
26 const shim = parts.join("/");
27
28 trace.debug(`define shim ${shim}`);
29
30 return new Promise<Require>(cb => {
31 define(shim, ["require"], r => {
32 trace.debug("shim resolved");
33 return r;
34 });
35 require([shim], cb);
36 });
37 }
38
39 class ModuleResolver {
14 class ModuleResolver {
40 _base: string;
15 _base: string;
41 _require: Require;
16 _require: Require;
42
17
43 constructor(req: Require, base?: string) {
18 constructor(req: Require, base?: string) {
44 this._base = base;
19 this._base = base;
45 this._require = req || globalRequire;
20 this._require = req;
46 }
21 }
47
22
48 resolve(moduleName: string) {
23 resolve(moduleName: string) {
@@ -58,17 +33,9 class ModuleResolver {
58 }
33 }
59 }
34 }
60
35
61 export async function makeResolver(moduleName: string, contextRequire: Require) {
36 export function makeResolver(moduleName: string, contextRequire: Require) {
62 trace.debug(
37 const base = moduleName && moduleName.split("/").slice(0, -1).join("/");
63 "makeResolver moduleName={0}, contextRequire={1}",
64 moduleName || "<nil>",
65 contextRequire ? typeof (contextRequire) : "<nil>"
66 );
67
38
68 const nestedRequire = isNullOrEmptyString(moduleName) ? null : await createContextRequire(moduleName);
39 const resolver = new ModuleResolver(contextRequire, base);
69
70 // const base = moduleName && moduleName.split("/").slice(0, -1).join("/");
71
72 const resolver = new ModuleResolver(nestedRequire, null);
73 return (id: string) => resolver.resolve(id);
40 return (id: string) => resolver.resolve(id);
74 }
41 }
@@ -178,7 +178,7 export class Configuration {
178 trace.debug("<{0}", name);
178 trace.debug("<{0}", name);
179 }
179 }
180
180
181 _visit(data, name: string): Promise<any> {
181 async _visit(data, name: string) {
182 if (isPrimitive(data) || isDescriptor(data))
182 if (isPrimitive(data) || isDescriptor(data))
183 return data;
183 return data;
184
184
@@ -1,3 +1,5
1 import { ICancellable } from "./interfaces";
2
1 let _nextOid = 0;
3 let _nextOid = 0;
2 const _oid = typeof Symbol === "function" ?
4 const _oid = typeof Symbol === "function" ?
3 Symbol("__implab__oid__") :
5 Symbol("__implab__oid__") :
@@ -40,20 +42,20 export function isNull(arg) {
40 return (arg === null || arg === undefined);
42 return (arg === null || arg === undefined);
41 }
43 }
42
44
43 export function isPrimitive(arg) {
45 export function isPrimitive(arg): arg is string | number | boolean | undefined | null {
44 return (arg === null || arg === undefined || typeof (arg) === "string" ||
46 return (arg === null || arg === undefined || typeof (arg) === "string" ||
45 typeof (arg) === "number" || typeof (arg) === "boolean");
47 typeof (arg) === "number" || typeof (arg) === "boolean");
46 }
48 }
47
49
48 export function isInteger(arg) {
50 export function isInteger(arg): arg is number {
49 return parseInt(arg, 10) === arg;
51 return parseInt(arg, 10) === arg;
50 }
52 }
51
53
52 export function isNumber(arg) {
54 export function isNumber(arg): arg is number {
53 return parseFloat(arg) === arg;
55 return parseFloat(arg) === arg;
54 }
56 }
55
57
56 export function isString(val) {
58 export function isString(val): val is string {
57 return typeof (val) === "string" || val instanceof String;
59 return typeof (val) === "string" || val instanceof String;
58 }
60 }
59
61
@@ -61,6 +63,10 export function isPromise(val): val is P
61 return val && typeof val.then === "function";
63 return val && typeof val.then === "function";
62 }
64 }
63
65
66 export function isCancellable(val): val is ICancellable {
67 return val && typeof val.cancel === "function";
68 }
69
64 export function isNullOrEmptyString(str) {
70 export function isNullOrEmptyString(str) {
65 if (str === null || str === undefined ||
71 if (str === null || str === undefined ||
66 ((typeof (str) === "string" || str instanceof String) && str.length === 0))
72 ((typeof (str) === "string" || str instanceof String) && str.length === 0))
General Comments 0
You need to be logged in to leave comments. Login now