whet 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/StringBuf.d.ts +13 -0
- package/bin/StringBuf.js +25 -0
- package/bin/haxe/CallStack.d.ts +41 -0
- package/bin/haxe/CallStack.js +96 -0
- package/bin/haxe/NativeStackTrace.js +147 -0
- package/bin/whet/Log.js +3 -0
- package/bin/whet/Project.d.ts +1 -0
- package/bin/whet/Project.js +12 -8
- package/bin/whet/Source.d.ts +2 -2
- package/bin/whet/Source.js +20 -5
- package/bin/whet/SourceHash.d.ts +7 -1
- package/bin/whet/SourceHash.js +93 -7
- package/bin/whet/SourceId.d.ts +1 -0
- package/bin/whet/SourceId.js +37 -28
- package/bin/whet/Stone.d.ts +12 -2
- package/bin/whet/Stone.js +25 -13
- package/bin/whet/Utils.d.ts +8 -2
- package/bin/whet/Utils.js +25 -5
- package/bin/whet/Whet.js +4 -1
- package/bin/whet/cache/BaseCache.js +18 -17
- package/bin/whet/cache/CacheManager.d.ts +5 -0
- package/bin/whet/cache/CacheManager.js +21 -13
- package/bin/whet/cache/FileCache.js +83 -43
- package/bin/whet/magic/RoutePathType.js +10 -5
- package/bin/whet/magic/RouteType.d.ts +2 -2
- package/bin/whet/magic/RouteType.js +28 -14
- package/bin/whet/magic/StoneId.d.ts +1 -0
- package/bin/whet/magic/StoneId.js +11 -1
- package/bin/whet/route/Route.d.ts +5 -1
- package/bin/whet/route/Route.js +33 -14
- package/bin/whet/route/Router.js +27 -37
- package/bin/whet/stones/Files.js +25 -17
- package/bin/whet/stones/JsonStone.js +7 -7
- package/bin/whet/stones/RemoteFile.js +5 -8
- package/bin/whet/stones/Server.js +26 -19
- package/bin/whet/stones/Zip.js +17 -12
- package/bin/whet/stones/haxe/HaxeBuild.d.ts +1 -0
- package/bin/whet/stones/haxe/HaxeBuild.js +37 -66
- package/bin/whet/stones/haxe/Hxml.js +39 -24
- package/bin/whet.d.ts +2 -0
- package/bin/whet.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
A String buffer is an efficient way to build a big string by appending small
|
|
4
|
+
elements together.
|
|
5
|
+
|
|
6
|
+
Unlike String, an instance of StringBuf is not immutable in the sense that
|
|
7
|
+
it can be passed as argument to functions which modify it by appending more
|
|
8
|
+
values.
|
|
9
|
+
*/
|
|
10
|
+
export declare class StringBuf {
|
|
11
|
+
constructor()
|
|
12
|
+
protected b: string
|
|
13
|
+
}
|
package/bin/StringBuf.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {Register} from "./genes/Register.js"
|
|
2
|
+
|
|
3
|
+
const $global = Register.$global
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
A String buffer is an efficient way to build a big string by appending small
|
|
7
|
+
elements together.
|
|
8
|
+
|
|
9
|
+
Unlike String, an instance of StringBuf is not immutable in the sense that
|
|
10
|
+
it can be passed as argument to functions which modify it by appending more
|
|
11
|
+
values.
|
|
12
|
+
*/
|
|
13
|
+
export const StringBuf = Register.global("$hxClasses")["StringBuf"] =
|
|
14
|
+
class StringBuf extends Register.inherits() {
|
|
15
|
+
new() {
|
|
16
|
+
this.b = "";
|
|
17
|
+
}
|
|
18
|
+
static get __name__() {
|
|
19
|
+
return "StringBuf"
|
|
20
|
+
}
|
|
21
|
+
get __class__() {
|
|
22
|
+
return StringBuf
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {StringBuf} from "../StringBuf"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Elements return by `CallStack` methods.
|
|
5
|
+
*/
|
|
6
|
+
export declare namespace StackItem {
|
|
7
|
+
export type Module = {_hx_index: 1, m: string, __enum__: "haxe.StackItem"}
|
|
8
|
+
export const Module: (m: string) => StackItem
|
|
9
|
+
export type Method = {_hx_index: 3, classname: null | string, method: string, __enum__: "haxe.StackItem"}
|
|
10
|
+
export const Method: (classname: null | string, method: string) => StackItem
|
|
11
|
+
export type LocalFunction = {_hx_index: 4, v: null | number, __enum__: "haxe.StackItem"}
|
|
12
|
+
export const LocalFunction: (v: null | number) => StackItem
|
|
13
|
+
export type FilePos = {_hx_index: 2, s: null | StackItem, file: string, line: number, column: null | number, __enum__: "haxe.StackItem"}
|
|
14
|
+
export const FilePos: (s: null | StackItem, file: string, line: number, column: null | number) => StackItem
|
|
15
|
+
export type CFunction = {_hx_index: 0, __enum__: "haxe.StackItem"}
|
|
16
|
+
export const CFunction: CFunction
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
Elements return by `CallStack` methods.
|
|
21
|
+
*/
|
|
22
|
+
export declare type StackItem =
|
|
23
|
+
| StackItem.Module
|
|
24
|
+
| StackItem.Method
|
|
25
|
+
| StackItem.LocalFunction
|
|
26
|
+
| StackItem.FilePos
|
|
27
|
+
| StackItem.CFunction
|
|
28
|
+
|
|
29
|
+
export declare class CallStack {
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
Return the call stack elements, or an empty array if not available.
|
|
33
|
+
*/
|
|
34
|
+
static callStack(): StackItem[]
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
Returns a representation of the stack as a printable string.
|
|
38
|
+
*/
|
|
39
|
+
static toString(stack: StackItem[]): string
|
|
40
|
+
protected static itemToString(b: StringBuf, s: StackItem): void
|
|
41
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {NativeStackTrace} from "./NativeStackTrace.js"
|
|
2
|
+
import {Register} from "../genes/Register.js"
|
|
3
|
+
import {StringBuf} from "../StringBuf.js"
|
|
4
|
+
import {Std} from "../Std.js"
|
|
5
|
+
|
|
6
|
+
const $global = Register.$global
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
Elements return by `CallStack` methods.
|
|
10
|
+
*/
|
|
11
|
+
export const StackItem =
|
|
12
|
+
Register.global("$hxEnums")["haxe.StackItem"] =
|
|
13
|
+
{
|
|
14
|
+
__ename__: "haxe.StackItem",
|
|
15
|
+
|
|
16
|
+
CFunction: {_hx_name: "CFunction", _hx_index: 0, __enum__: "haxe.StackItem"},
|
|
17
|
+
Module: Object.assign((m) => ({_hx_index: 1, __enum__: "haxe.StackItem", "m": m}), {_hx_name: "Module", __params__: ["m"]}),
|
|
18
|
+
FilePos: Object.assign((s, file, line, column) => ({_hx_index: 2, __enum__: "haxe.StackItem", "s": s, "file": file, "line": line, "column": column}), {_hx_name: "FilePos", __params__: ["s", "file", "line", "column"]}),
|
|
19
|
+
Method: Object.assign((classname, method) => ({_hx_index: 3, __enum__: "haxe.StackItem", "classname": classname, "method": method}), {_hx_name: "Method", __params__: ["classname", "method"]}),
|
|
20
|
+
LocalFunction: Object.assign((v) => ({_hx_index: 4, __enum__: "haxe.StackItem", "v": v}), {_hx_name: "LocalFunction", __params__: ["v"]})
|
|
21
|
+
}
|
|
22
|
+
StackItem.__constructs__ = [StackItem.CFunction, StackItem.Module, StackItem.FilePos, StackItem.Method, StackItem.LocalFunction]
|
|
23
|
+
StackItem.__empty_constructs__ = [StackItem.CFunction]
|
|
24
|
+
|
|
25
|
+
export const CallStack = Register.global("$hxClasses")["haxe._CallStack.CallStack"] =
|
|
26
|
+
class CallStack {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
Return the call stack elements, or an empty array if not available.
|
|
30
|
+
*/
|
|
31
|
+
static callStack() {
|
|
32
|
+
return NativeStackTrace.toHaxe(NativeStackTrace.callStack());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
Returns a representation of the stack as a printable string.
|
|
37
|
+
*/
|
|
38
|
+
static toString(stack) {
|
|
39
|
+
var b = new StringBuf();
|
|
40
|
+
var _g = 0;
|
|
41
|
+
var _g1 = stack;
|
|
42
|
+
while (_g < _g1.length) {
|
|
43
|
+
var s = _g1[_g++];
|
|
44
|
+
b.b += "\nCalled from ";
|
|
45
|
+
CallStack.itemToString(b, s);
|
|
46
|
+
};
|
|
47
|
+
return b.b;
|
|
48
|
+
}
|
|
49
|
+
static itemToString(b, s) {
|
|
50
|
+
switch (s._hx_index) {
|
|
51
|
+
case 0:
|
|
52
|
+
b.b += "a C function";
|
|
53
|
+
break
|
|
54
|
+
case 1:
|
|
55
|
+
var _g = s.m;
|
|
56
|
+
b.b = (b.b += "module ") + ((_g == null) ? "null" : "" + _g);
|
|
57
|
+
break
|
|
58
|
+
case 2:
|
|
59
|
+
var _g = s.s;
|
|
60
|
+
var _g1 = s.file;
|
|
61
|
+
var _g2 = s.line;
|
|
62
|
+
var _g3 = s.column;
|
|
63
|
+
if (_g != null) {
|
|
64
|
+
CallStack.itemToString(b, _g);
|
|
65
|
+
b.b += " (";
|
|
66
|
+
};
|
|
67
|
+
b.b = (b.b += (_g1 == null) ? "null" : "" + _g1) + " line ";
|
|
68
|
+
b.b += (_g2 == null) ? "null" : "" + _g2;
|
|
69
|
+
if (_g3 != null) {
|
|
70
|
+
b.b = (b.b += " column ") + ((_g3 == null) ? "null" : "" + _g3);
|
|
71
|
+
};
|
|
72
|
+
if (_g != null) {
|
|
73
|
+
b.b += ")";
|
|
74
|
+
};
|
|
75
|
+
break
|
|
76
|
+
case 3:
|
|
77
|
+
var _g = s.classname;
|
|
78
|
+
var _g1 = s.method;
|
|
79
|
+
b.b = (b.b += Std.string((_g == null) ? "<unknown>" : _g)) + ".";
|
|
80
|
+
b.b += (_g1 == null) ? "null" : "" + _g1;
|
|
81
|
+
break
|
|
82
|
+
case 4:
|
|
83
|
+
var _g = s.v;
|
|
84
|
+
b.b = (b.b += "local function #") + ((_g == null) ? "null" : "" + _g);
|
|
85
|
+
break
|
|
86
|
+
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
static get __name__() {
|
|
90
|
+
return "haxe._CallStack.CallStack_Impl_"
|
|
91
|
+
}
|
|
92
|
+
get __class__() {
|
|
93
|
+
return CallStack
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import {StackItem} from "./CallStack.js"
|
|
2
|
+
import {Register} from "../genes/Register.js"
|
|
3
|
+
import {StringTools} from "../StringTools.js"
|
|
4
|
+
import {Std} from "../Std.js"
|
|
5
|
+
|
|
6
|
+
const $global = Register.$global
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
Do not use manually.
|
|
10
|
+
*/
|
|
11
|
+
export const NativeStackTrace = Register.global("$hxClasses")["haxe.NativeStackTrace"] =
|
|
12
|
+
class NativeStackTrace {
|
|
13
|
+
static callStack() {
|
|
14
|
+
var e = new Error("");
|
|
15
|
+
var stack = NativeStackTrace.tryHaxeStack(e);
|
|
16
|
+
if (typeof(stack) == "undefined") {
|
|
17
|
+
try {
|
|
18
|
+
throw e;
|
|
19
|
+
}catch (_g) {
|
|
20
|
+
};
|
|
21
|
+
stack = e.stack;
|
|
22
|
+
};
|
|
23
|
+
return NativeStackTrace.normalize(stack, 2);
|
|
24
|
+
}
|
|
25
|
+
static toHaxe(s, skip) {
|
|
26
|
+
if (skip == null) {
|
|
27
|
+
skip = 0;
|
|
28
|
+
};
|
|
29
|
+
if (s == null) {
|
|
30
|
+
return [];
|
|
31
|
+
} else if (typeof(s) == "string") {
|
|
32
|
+
var stack = s.split("\n");
|
|
33
|
+
if (stack[0] == "Error") {
|
|
34
|
+
stack.shift();
|
|
35
|
+
};
|
|
36
|
+
var m = [];
|
|
37
|
+
var _g = 0;
|
|
38
|
+
var _g1 = stack.length;
|
|
39
|
+
while (_g < _g1) {
|
|
40
|
+
var i = _g++;
|
|
41
|
+
if (skip > i) {
|
|
42
|
+
continue;
|
|
43
|
+
};
|
|
44
|
+
var line = stack[i];
|
|
45
|
+
var matched = line.match(/^ at ([A-Za-z0-9_. ]+) \(([^)]+):([0-9]+):([0-9]+)\)$/);
|
|
46
|
+
if (matched != null) {
|
|
47
|
+
var path = matched[1].split(".");
|
|
48
|
+
if (path[0] == "$hxClasses") {
|
|
49
|
+
path.shift();
|
|
50
|
+
};
|
|
51
|
+
var meth = path.pop();
|
|
52
|
+
var file = matched[2];
|
|
53
|
+
var line1 = Std.parseInt(matched[3]);
|
|
54
|
+
var column = Std.parseInt(matched[4]);
|
|
55
|
+
m.push(StackItem.FilePos((meth == "Anonymous function") ? StackItem.LocalFunction() : (meth == "Global code") ? null : StackItem.Method(path.join("."), meth), file, line1, column));
|
|
56
|
+
} else {
|
|
57
|
+
m.push(StackItem.Module(StringTools.trim(line)));
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
return m;
|
|
61
|
+
} else if (skip > 0 && Array.isArray(s)) {
|
|
62
|
+
return s.slice(skip);
|
|
63
|
+
} else {
|
|
64
|
+
return s;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
static tryHaxeStack(e) {
|
|
68
|
+
if (e == null) {
|
|
69
|
+
return [];
|
|
70
|
+
};
|
|
71
|
+
var oldValue = Error.prepareStackTrace;
|
|
72
|
+
Error.prepareStackTrace = NativeStackTrace.prepareHxStackTrace;
|
|
73
|
+
Error.prepareStackTrace = oldValue;
|
|
74
|
+
return e.stack;
|
|
75
|
+
}
|
|
76
|
+
static prepareHxStackTrace(e, callsites) {
|
|
77
|
+
var stack = [];
|
|
78
|
+
var _g = 0;
|
|
79
|
+
while (_g < callsites.length) {
|
|
80
|
+
var site = callsites[_g];
|
|
81
|
+
++_g;
|
|
82
|
+
if (NativeStackTrace.wrapCallSite != null) {
|
|
83
|
+
site = NativeStackTrace.wrapCallSite(site);
|
|
84
|
+
};
|
|
85
|
+
var method = null;
|
|
86
|
+
var fullName = site.getFunctionName();
|
|
87
|
+
if (fullName != null) {
|
|
88
|
+
var idx = fullName.lastIndexOf(".");
|
|
89
|
+
if (idx >= 0) {
|
|
90
|
+
method = StackItem.Method(fullName.substring(0, idx), fullName.substring(idx + 1));
|
|
91
|
+
} else {
|
|
92
|
+
method = StackItem.Method(null, fullName);
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
var fileName = site.getFileName();
|
|
96
|
+
var fileAddr = (fileName == null) ? -1 : fileName.indexOf("file:");
|
|
97
|
+
if (NativeStackTrace.wrapCallSite != null && fileAddr > 0) {
|
|
98
|
+
fileName = fileName.substring(fileAddr + 6);
|
|
99
|
+
};
|
|
100
|
+
stack.push(StackItem.FilePos(method, fileName, site.getLineNumber(), site.getColumnNumber()));
|
|
101
|
+
};
|
|
102
|
+
return stack;
|
|
103
|
+
}
|
|
104
|
+
static normalize(stack, skipItems) {
|
|
105
|
+
if (skipItems == null) {
|
|
106
|
+
skipItems = 0;
|
|
107
|
+
};
|
|
108
|
+
if (Array.isArray(stack) && skipItems > 0) {
|
|
109
|
+
return stack.slice(skipItems);
|
|
110
|
+
} else if (typeof(stack) == "string") {
|
|
111
|
+
switch (stack.substring(0, 6)) {
|
|
112
|
+
case "Error\n":case "Error:":
|
|
113
|
+
++skipItems;
|
|
114
|
+
break
|
|
115
|
+
default:
|
|
116
|
+
|
|
117
|
+
};
|
|
118
|
+
return NativeStackTrace.skipLines(stack, skipItems);
|
|
119
|
+
} else {
|
|
120
|
+
return stack;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
static skipLines(stack, skip, pos) {
|
|
124
|
+
if (pos == null) {
|
|
125
|
+
pos = 0;
|
|
126
|
+
};
|
|
127
|
+
while (true) if (skip > 0) {
|
|
128
|
+
pos = stack.indexOf("\n", pos);
|
|
129
|
+
if (pos < 0) {
|
|
130
|
+
return "";
|
|
131
|
+
} else {
|
|
132
|
+
skip = --skip;
|
|
133
|
+
pos += 1;
|
|
134
|
+
continue;
|
|
135
|
+
};
|
|
136
|
+
} else {
|
|
137
|
+
return stack.substring(pos);
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
static get __name__() {
|
|
141
|
+
return "haxe.NativeStackTrace"
|
|
142
|
+
}
|
|
143
|
+
get __class__() {
|
|
144
|
+
return NativeStackTrace
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
package/bin/whet/Log.js
CHANGED
package/bin/whet/Project.d.ts
CHANGED
package/bin/whet/Project.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {CacheManager} from "./cache/CacheManager.js"
|
|
2
2
|
import {Whet_Fields_} from "./Whet.js"
|
|
3
|
+
import {SourceId_Fields_} from "./SourceId.js"
|
|
3
4
|
import {Log} from "./Log.js"
|
|
4
5
|
import * as Path from "path"
|
|
5
|
-
import {Path as Path__1} from "../haxe/io/Path.js"
|
|
6
6
|
import {Register} from "../genes/Register.js"
|
|
7
7
|
import {StringTools} from "../StringTools.js"
|
|
8
|
-
import {HxOverrides} from "../HxOverrides.js"
|
|
9
8
|
|
|
10
9
|
const $global = Register.$global
|
|
11
10
|
|
|
12
11
|
export const Project = Register.global("$hxClasses")["whet.Project"] =
|
|
13
12
|
class Project extends Register.inherits() {
|
|
14
13
|
new(config) {
|
|
14
|
+
this.stones = [];
|
|
15
15
|
this.cache = null;
|
|
16
16
|
var this1 = ["Instantiating new Project."];
|
|
17
17
|
Log.log(20, ...this1);
|
|
@@ -37,14 +37,18 @@ class Project extends Register.inherits() {
|
|
|
37
37
|
file = decodeURI(file);
|
|
38
38
|
file = StringTools.replace(file, "file:///", "");
|
|
39
39
|
var s = Path.relative(process.cwd(), file);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var
|
|
43
|
-
|
|
40
|
+
s = Path.posix.normalize(s);
|
|
41
|
+
s = StringTools.replace(s, "\\", "/");
|
|
42
|
+
var this1 = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
43
|
+
var s = this1.substring(0, this1.lastIndexOf("/") + 1);
|
|
44
|
+
s = Path.posix.normalize(s);
|
|
45
|
+
s = StringTools.replace(s, "\\", "/");
|
|
46
|
+
this.rootDir = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
44
47
|
} else {
|
|
45
48
|
var s = config.rootDir;
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
s = Path.posix.normalize(s);
|
|
50
|
+
s = StringTools.replace(s, "\\", "/");
|
|
51
|
+
this.rootDir = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
48
52
|
};
|
|
49
53
|
this.cache = (config.cache == null) ? new CacheManager(this) : config.cache;
|
|
50
54
|
Project.projects.push(this);
|
package/bin/whet/Source.d.ts
CHANGED
|
@@ -35,12 +35,12 @@ export declare class SourceData {
|
|
|
35
35
|
/**
|
|
36
36
|
Same as `getFilePath` but relative to project, not CWD.
|
|
37
37
|
*/
|
|
38
|
-
getFilePathId(idOverride?: null | string): Promise<string>
|
|
38
|
+
protected getFilePathId(idOverride?: null | string): Promise<string>
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
Path to a file for this source, relative to CWD.
|
|
42
42
|
*/
|
|
43
|
-
getFilePath(idOverride?: null | string): Promise<string>
|
|
43
|
+
protected getFilePath(idOverride?: null | string): Promise<string>
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* `path` is the actual cwd-relative path. `pathId` is the project-relative source Id.
|
package/bin/whet/Source.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {Utils} from "./Utils.js"
|
|
2
|
-
import {SourceId, RootDir} from "./SourceId.js"
|
|
2
|
+
import {SourceId_Fields_, SourceId, RootDir} from "./SourceId.js"
|
|
3
3
|
import {SourceHash} from "./SourceHash.js"
|
|
4
4
|
import {Log} from "./Log.js"
|
|
5
|
+
import * as Path from "path"
|
|
5
6
|
import {Register} from "../genes/Register.js"
|
|
6
7
|
import * as Fs from "fs"
|
|
7
8
|
import {Buffer} from "buffer"
|
|
9
|
+
import {StringTools} from "../StringTools.js"
|
|
8
10
|
import {Lambda} from "../Lambda.js"
|
|
9
11
|
|
|
10
12
|
const $global = Register.$global
|
|
@@ -42,8 +44,12 @@ class Source extends Register.inherits() {
|
|
|
42
44
|
if (id == null) {
|
|
43
45
|
return this.data[0];
|
|
44
46
|
} else {
|
|
47
|
+
var s = id;
|
|
48
|
+
s = Path.posix.normalize(id);
|
|
49
|
+
s = StringTools.replace(s, "\\", "/");
|
|
50
|
+
var sid = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
45
51
|
return Lambda.find(this.data, function (entry) {
|
|
46
|
-
return entry.id ==
|
|
52
|
+
return entry.id == sid;
|
|
47
53
|
});
|
|
48
54
|
};
|
|
49
55
|
}
|
|
@@ -93,7 +99,10 @@ class SourceData extends Register.inherits() {
|
|
|
93
99
|
this.filePathId = SourceId.getPutInDir((idOverride != null) ? idOverride : this.id, dir);
|
|
94
100
|
var this1 = this.filePathId;
|
|
95
101
|
var root = RootDir.fromProject(this.source.origin.project);
|
|
96
|
-
|
|
102
|
+
if (this1.charAt(0) != "/") {
|
|
103
|
+
throw new Error("Badly formed SourceId.");
|
|
104
|
+
};
|
|
105
|
+
this.filePath = Path.posix.join(".", root, ".", this1);
|
|
97
106
|
return Utils.saveBytes(this.filePath, this.data).then(function (_) {
|
|
98
107
|
return _gthis.filePath;
|
|
99
108
|
});
|
|
@@ -114,7 +123,10 @@ class SourceData extends Register.inherits() {
|
|
|
114
123
|
} else {
|
|
115
124
|
var source = SourceData.fromBytes(id, buffer);
|
|
116
125
|
source.filePath = path;
|
|
117
|
-
|
|
126
|
+
var s = pathId;
|
|
127
|
+
s = Path.posix.normalize(s);
|
|
128
|
+
s = StringTools.replace(s, "\\", "/");
|
|
129
|
+
source.filePathId = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
|
|
118
130
|
res(source);
|
|
119
131
|
};
|
|
120
132
|
});
|
|
@@ -124,7 +136,10 @@ class SourceData extends Register.inherits() {
|
|
|
124
136
|
return SourceData.fromBytes(id, Buffer.from(s, "utf-8"));
|
|
125
137
|
}
|
|
126
138
|
static fromBytes(id, data) {
|
|
127
|
-
|
|
139
|
+
var s = id;
|
|
140
|
+
s = Path.posix.normalize(id);
|
|
141
|
+
s = StringTools.replace(s, "\\", "/");
|
|
142
|
+
return new SourceData((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s, data);
|
|
128
143
|
}
|
|
129
144
|
static get __name__() {
|
|
130
145
|
return "whet.SourceData"
|
package/bin/whet/SourceHash.d.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
+
import {MaybeArray} from "./magic/MaybeArray"
|
|
1
2
|
import {Buffer} from "buffer"
|
|
2
3
|
|
|
3
4
|
export declare class SourceHash {
|
|
4
5
|
protected constructor(bytes: Buffer)
|
|
5
6
|
protected bytes: Buffer
|
|
7
|
+
add(hash: SourceHash): SourceHash
|
|
6
8
|
toString(): string
|
|
7
9
|
static EMPTY: SourceHash
|
|
8
10
|
static fromFile(path: string): Promise<SourceHash>
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Creates hashes of all files and or content of directories, optionally recursive.
|
|
14
|
+
*/
|
|
15
|
+
static fromFiles(paths: MaybeArray<string>, filter?: null | ((arg0: string) => boolean), recursive?: boolean): Promise<SourceHash>
|
|
9
16
|
static fromBytes(data: Buffer): SourceHash
|
|
10
17
|
static fromString(data: string): SourceHash
|
|
11
|
-
static add(a: SourceHash, b: SourceHash): SourceHash
|
|
12
18
|
static equals(a: SourceHash, b: SourceHash): boolean
|
|
13
19
|
static toHex(hash: SourceHash): string
|
|
14
20
|
static fromHex(hex: string): SourceHash
|
package/bin/whet/SourceHash.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {MaybeArray_Fields_} from "./magic/MaybeArray.js"
|
|
2
|
+
import {Utils} from "./Utils.js"
|
|
1
3
|
import {Register} from "../genes/Register.js"
|
|
2
4
|
import * as Fs from "fs"
|
|
3
5
|
import * as Crypto from "crypto"
|
|
@@ -10,6 +12,12 @@ class SourceHash extends Register.inherits() {
|
|
|
10
12
|
new(bytes) {
|
|
11
13
|
this.bytes = bytes;
|
|
12
14
|
}
|
|
15
|
+
add(hash) {
|
|
16
|
+
var data = Buffer.alloc(64);
|
|
17
|
+
this.bytes.copy(data, 0, 0, 32);
|
|
18
|
+
hash.bytes.copy(data, 32, 0, 32);
|
|
19
|
+
return SourceHash.fromBytes(data);
|
|
20
|
+
}
|
|
13
21
|
toString() {
|
|
14
22
|
return this.bytes.toString("hex");
|
|
15
23
|
}
|
|
@@ -24,18 +32,96 @@ class SourceHash extends Register.inherits() {
|
|
|
24
32
|
});
|
|
25
33
|
});
|
|
26
34
|
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creates hashes of all files and or content of directories, optionally recursive.
|
|
38
|
+
*/
|
|
39
|
+
static fromFiles(paths, filter, recursive) {
|
|
40
|
+
if (recursive == null) {
|
|
41
|
+
recursive = true;
|
|
42
|
+
};
|
|
43
|
+
var _g = [];
|
|
44
|
+
var _g1 = 0;
|
|
45
|
+
var _g2 = MaybeArray_Fields_.makeArray(paths);
|
|
46
|
+
while (_g1 < _g2.length) {
|
|
47
|
+
var src = [_g2[_g1]];
|
|
48
|
+
++_g1;
|
|
49
|
+
_g.push(new Promise((function (src) {
|
|
50
|
+
return function (res, rej) {
|
|
51
|
+
Fs.stat(src[0], (function (src) {
|
|
52
|
+
return function (err, stats) {
|
|
53
|
+
if (err != null) {
|
|
54
|
+
rej(err);
|
|
55
|
+
} else if (stats.isDirectory()) {
|
|
56
|
+
Utils.listDirectoryFiles(src[0], recursive).then((function () {
|
|
57
|
+
return function (files) {
|
|
58
|
+
res(files);
|
|
59
|
+
};
|
|
60
|
+
})());
|
|
61
|
+
} else {
|
|
62
|
+
res([src[0]]);
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
})(src));
|
|
66
|
+
};
|
|
67
|
+
})(src)));
|
|
68
|
+
};
|
|
69
|
+
var allFilesProm = _g;
|
|
70
|
+
return Promise.all(allFilesProm).then(function (arrFiles) {
|
|
71
|
+
var result = new Array(arrFiles.length);
|
|
72
|
+
var _g = 0;
|
|
73
|
+
var _g1 = arrFiles.length;
|
|
74
|
+
while (_g < _g1) {
|
|
75
|
+
var i = _g++;
|
|
76
|
+
var files = arrFiles[i];
|
|
77
|
+
if (filter != null) {
|
|
78
|
+
var _g2 = [];
|
|
79
|
+
var _g3 = 0;
|
|
80
|
+
var _g4 = files;
|
|
81
|
+
while (_g3 < _g4.length) {
|
|
82
|
+
var v = _g4[_g3];
|
|
83
|
+
++_g3;
|
|
84
|
+
if (filter(v)) {
|
|
85
|
+
_g2.push(v);
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
files = _g2;
|
|
89
|
+
};
|
|
90
|
+
files.sort();
|
|
91
|
+
var result1 = new Array(files.length);
|
|
92
|
+
var _g5 = 0;
|
|
93
|
+
var _g6 = files.length;
|
|
94
|
+
while (_g5 < _g6) {
|
|
95
|
+
var i1 = _g5++;
|
|
96
|
+
result1[i1] = SourceHash.fromFile(files[i1]);
|
|
97
|
+
};
|
|
98
|
+
result[i] = Promise.all(result1);
|
|
99
|
+
};
|
|
100
|
+
return result;
|
|
101
|
+
}).then(function (proms) {
|
|
102
|
+
return Promise.all(proms);
|
|
103
|
+
}).then(function (allHashes) {
|
|
104
|
+
var _g = [];
|
|
105
|
+
var _g_current = 0;
|
|
106
|
+
var _g_array = allHashes;
|
|
107
|
+
while (_g_current < _g_array.length) {
|
|
108
|
+
var e = _g_array[_g_current++];
|
|
109
|
+
var x = Register.iter(e);
|
|
110
|
+
while (x.hasNext()) {
|
|
111
|
+
var x1 = x.next();
|
|
112
|
+
_g.push(x1);
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
var this1 = _g;
|
|
116
|
+
return SourceHash.merge(...this1);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
27
119
|
static fromBytes(data) {
|
|
28
120
|
return new SourceHash(Crypto.createHash("sha256").update(data).digest());
|
|
29
121
|
}
|
|
30
122
|
static fromString(data) {
|
|
31
123
|
return SourceHash.fromBytes(Buffer.from(data));
|
|
32
124
|
}
|
|
33
|
-
static add(a, b) {
|
|
34
|
-
var data = Buffer.alloc(64);
|
|
35
|
-
a.bytes.copy(data, 0, 0, 32);
|
|
36
|
-
b.bytes.copy(data, 32, 0, 32);
|
|
37
|
-
return SourceHash.fromBytes(data);
|
|
38
|
-
}
|
|
39
125
|
static equals(a, b) {
|
|
40
126
|
if (a != null && b != null) {
|
|
41
127
|
return a.bytes.compare(b.bytes) == 0;
|
|
@@ -65,7 +151,7 @@ class SourceHash extends Register.inherits() {
|
|
|
65
151
|
var h = hash[0];
|
|
66
152
|
var _g = 1;
|
|
67
153
|
var _g1 = hash.length;
|
|
68
|
-
while (_g < _g1) h =
|
|
154
|
+
while (_g < _g1) h = h.add(hash[_g++]);
|
|
69
155
|
return h;
|
|
70
156
|
}
|
|
71
157
|
static get __name__() {
|
package/bin/whet/SourceId.d.ts
CHANGED