whet 0.0.8 → 0.0.11

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.
@@ -1,6 +1,5 @@
1
1
  import {CacheManager} from "./cache/CacheManager.js"
2
2
  import {Whet_Fields_} from "./Whet.js"
3
- import {SourceId_Fields_} from "./SourceId.js"
4
3
  import {Log} from "./Log.js"
5
4
  import * as Path from "path"
6
5
  import {Register} from "../genes/Register.js"
@@ -39,18 +38,30 @@ class Project extends Register.inherits() {
39
38
  file = decodeURI(file);
40
39
  file = StringTools.replace(file, "file:///", "");
41
40
  var s = Path.relative(process.cwd(), file);
42
- s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
43
- s = StringTools.replace(s, "\\", "/");
44
- var this1 = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
41
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
42
+ if (str.length > 0) {
43
+ str = Path.posix.normalize(str);
44
+ str = StringTools.replace(str, "\\", "/");
45
+ };
46
+ s = str;
47
+ var this1 = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
45
48
  var s = this1.substring(0, this1.lastIndexOf("/") + 1);
46
- s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
47
- s = StringTools.replace(s, "\\", "/");
48
- this.rootDir = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
49
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
50
+ if (str.length > 0) {
51
+ str = Path.posix.normalize(str);
52
+ str = StringTools.replace(str, "\\", "/");
53
+ };
54
+ s = str;
55
+ this.rootDir = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
49
56
  } else {
50
57
  var s = config.rootDir;
51
- s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
52
- s = StringTools.replace(s, "\\", "/");
53
- this.rootDir = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
58
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
59
+ if (str.length > 0) {
60
+ str = Path.posix.normalize(str);
61
+ str = StringTools.replace(str, "\\", "/");
62
+ };
63
+ s = str;
64
+ this.rootDir = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
54
65
  };
55
66
  this.cache = (config.cache == null) ? new CacheManager(this) : config.cache;
56
67
  Project.projects.push(this);
@@ -26,6 +26,10 @@ export declare class Source {
26
26
  export declare class SourceData {
27
27
  protected constructor(id: string, data: Buffer)
28
28
  data: Buffer
29
+
30
+ /**
31
+ Name relative to the stone that generated it.
32
+ */
29
33
  id: string
30
34
  hash: SourceHash
31
35
  source: Source
@@ -43,7 +47,10 @@ export declare class SourceData {
43
47
  protected getFilePath(idOverride?: null | string): Promise<string>
44
48
 
45
49
  /**
46
- * `path` is the actual cwd-relative path. `pathId` is the project-relative source Id.
50
+ * @param id Path id relative to stone that generates it.
51
+ * @param path Actual path relative to CWD.
52
+ * @param pathId Path Id relative to project.
53
+ * @return Promise<SourceData>
47
54
  */
48
55
  static fromFile(id: string, path: string, pathId: string): Promise<SourceData>
49
56
  static fromString(id: string, s: string): SourceData
@@ -1,5 +1,5 @@
1
1
  import {Utils} from "./Utils.js"
2
- import {SourceId_Fields_, SourceId, RootDir} from "./SourceId.js"
2
+ import {SourceId, RootDir} from "./SourceId.js"
3
3
  import {SourceHash} from "./SourceHash.js"
4
4
  import {Log} from "./Log.js"
5
5
  import * as Path from "path"
@@ -46,9 +46,13 @@ class Source extends Register.inherits() {
46
46
  return this.data[0];
47
47
  } else {
48
48
  var s = id;
49
- s = Path.posix.normalize((id.length > 1 && SourceId_Fields_.startsWithSlash(id)) ? HxOverrides.substr(id, 1, null) : id);
50
- s = StringTools.replace(s, "\\", "/");
51
- var sid = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
49
+ var str = (id.length > 1 && HxOverrides.cca(id, 0) == 47) ? id.substring(1) : id;
50
+ if (str.length > 0) {
51
+ str = Path.posix.normalize(str);
52
+ str = StringTools.replace(str, "\\", "/");
53
+ };
54
+ s = str;
55
+ var sid = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
52
56
  return Lambda.find(this.data, function (entry) {
53
57
  return entry.id == sid;
54
58
  });
@@ -113,7 +117,10 @@ class SourceData extends Register.inherits() {
113
117
  }
114
118
 
115
119
  /**
116
- * `path` is the actual cwd-relative path. `pathId` is the project-relative source Id.
120
+ * @param id Path id relative to stone that generates it.
121
+ * @param path Actual path relative to CWD.
122
+ * @param pathId Path Id relative to project.
123
+ * @return Promise<SourceData>
117
124
  */
118
125
  static fromFile(id, path, pathId) {
119
126
  return new Promise(function (res, rej) {
@@ -125,9 +132,13 @@ class SourceData extends Register.inherits() {
125
132
  var source = SourceData.fromBytes(id, buffer);
126
133
  source.filePath = path;
127
134
  var s = pathId;
128
- s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
129
- s = StringTools.replace(s, "\\", "/");
130
- source.filePathId = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
135
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
136
+ if (str.length > 0) {
137
+ str = Path.posix.normalize(str);
138
+ str = StringTools.replace(str, "\\", "/");
139
+ };
140
+ s = str;
141
+ source.filePathId = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
131
142
  res(source);
132
143
  };
133
144
  });
@@ -138,9 +149,13 @@ class SourceData extends Register.inherits() {
138
149
  }
139
150
  static fromBytes(id, data) {
140
151
  var s = id;
141
- s = Path.posix.normalize((id.length > 1 && SourceId_Fields_.startsWithSlash(id)) ? HxOverrides.substr(id, 1, null) : id);
142
- s = StringTools.replace(s, "\\", "/");
143
- return new SourceData((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s, data);
152
+ var str = (id.length > 1 && HxOverrides.cca(id, 0) == 47) ? id.substring(1) : id;
153
+ if (str.length > 0) {
154
+ str = Path.posix.normalize(str);
155
+ str = StringTools.replace(str, "\\", "/");
156
+ };
157
+ s = str;
158
+ return new SourceData((HxOverrides.cca(s, 0) == 47) ? s : "/" + s, data);
144
159
  }
145
160
  static get __name__() {
146
161
  return "whet.SourceData"
@@ -9,3 +9,4 @@ export declare class RootDir {
9
9
  static fromProject(p: Project): string
10
10
  }
11
11
 
12
+ export const fromCwdPath: (s: string, root: string) => string
@@ -8,37 +8,53 @@ const $global = Register.$global
8
8
  export const SourceId = Register.global("$hxClasses")["whet._SourceId.SourceId"] =
9
9
  class SourceId {
10
10
  static relativeTo(this1, directory) {
11
- if (!SourceId_Fields_.endsWithSlash(directory)) {
11
+ if (HxOverrides.cca(directory, directory.length - 1) != 47) {
12
12
  throw new Error("\"" + directory + "\" is not a directory.");
13
13
  };
14
14
  var tmp;
15
15
  var s = this1.substring(0, this1.lastIndexOf("/") + 1);
16
- s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
17
- s = StringTools.replace(s, "\\", "/");
18
- tmp = ((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s).indexOf(directory) == 0;
16
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
17
+ if (str.length > 0) {
18
+ str = Path.posix.normalize(str);
19
+ str = StringTools.replace(str, "\\", "/");
20
+ };
21
+ s = str;
22
+ tmp = ((HxOverrides.cca(s, 0) == 47) ? s : "/" + s).indexOf(directory) == 0;
19
23
  if (tmp) {
20
- return HxOverrides.substr(this1, directory.length - 1, null);
24
+ return this1.substring(directory.length - 1);
21
25
  } else {
22
26
  return null;
23
27
  };
24
28
  }
25
29
  static getPutInDir(this1, dir) {
26
- if (!SourceId_Fields_.endsWithSlash(dir)) {
30
+ if (HxOverrides.cca(dir, dir.length - 1) != 47) {
27
31
  throw new Error("\"" + dir + "\" is not a directory.");
28
32
  };
29
33
  var s = "/";
30
- s = Path.posix.normalize(("/".length > 1 && SourceId_Fields_.startsWithSlash("/")) ? HxOverrides.substr("/", 1, null) : "/");
31
- s = StringTools.replace(s, "\\", "/");
32
- if (dir == ((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s)) {
34
+ var str = ("/".length > 1 && HxOverrides.cca("/", 0) == 47) ? "/".substring(1) : "/";
35
+ if (str.length > 0) {
36
+ str = Path.posix.normalize(str);
37
+ str = StringTools.replace(str, "\\", "/");
38
+ };
39
+ s = str;
40
+ if (dir == ((HxOverrides.cca(s, 0) == 47) ? s : "/" + s)) {
33
41
  var s = this1;
34
- s = Path.posix.normalize((this1.length > 1 && SourceId_Fields_.startsWithSlash(this1)) ? HxOverrides.substr(this1, 1, null) : this1);
35
- s = StringTools.replace(s, "\\", "/");
36
- return (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
42
+ var str = (this1.length > 1 && HxOverrides.cca(this1, 0) == 47) ? this1.substring(1) : this1;
43
+ if (str.length > 0) {
44
+ str = Path.posix.normalize(str);
45
+ str = StringTools.replace(str, "\\", "/");
46
+ };
47
+ s = str;
48
+ return (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
37
49
  } else {
38
50
  var s = dir + this1;
39
- s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
40
- s = StringTools.replace(s, "\\", "/");
41
- return (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
51
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
52
+ if (str.length > 0) {
53
+ str = Path.posix.normalize(str);
54
+ str = StringTools.replace(str, "\\", "/");
55
+ };
56
+ s = str;
57
+ return (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
42
58
  };
43
59
  }
44
60
  static get __name__() {
@@ -66,11 +82,20 @@ class RootDir {
66
82
 
67
83
  export const SourceId_Fields_ = Register.global("$hxClasses")["whet._SourceId.SourceId_Fields_"] =
68
84
  class SourceId_Fields_ {
69
- static startsWithSlash(str) {
70
- return HxOverrides.cca(str, 0) == 47;
71
- }
72
- static endsWithSlash(str) {
73
- return HxOverrides.cca(str, str.length - 1) == 47;
85
+ static fromCwdPath(s, root) {
86
+ var s1 = Path.posix;
87
+ var str = s;
88
+ if (str.length > 0) {
89
+ str = Path.posix.normalize(str);
90
+ str = StringTools.replace(str, "\\", "/");
91
+ };
92
+ s = s1.resolve(str);
93
+ var rootStr = root;
94
+ if (HxOverrides.cca(rootStr, 0) == 47) {
95
+ rootStr = rootStr.substring(1);
96
+ };
97
+ rootStr = Path.posix.resolve(rootStr);
98
+ return Path.posix.relative(rootStr, s);
74
99
  }
75
100
  static get __name__() {
76
101
  return "whet._SourceId.SourceId_Fields_"
@@ -81,3 +106,4 @@ class SourceId_Fields_ {
81
106
  }
82
107
 
83
108
 
109
+ export const fromCwdPath = SourceId_Fields_.fromCwdPath
@@ -1,4 +1,5 @@
1
1
  import {StoneIdType} from "./magic/StoneId"
2
+ import {MaybeArray} from "./magic/MaybeArray"
2
3
  import {CacheManager} from "./cache/CacheManager"
3
4
  import {CacheStrategy} from "./cache/Cache"
4
5
  import {SourceHash} from "./SourceHash"
@@ -35,7 +36,9 @@ export declare class Stone<T extends StoneConfig> {
35
36
  getSource(): Promise<Source>
36
37
 
37
38
  /**
38
- Hash of this stone with its current config. Defaults to hash of generated source.
39
+ * **Do not override.**
40
+ * Hash of this stone with its current config. Defaults to hash of generated source.
41
+ * Hashes of dependency stones (see `config.dependencies`) will be added to the hash.
39
42
  */
40
43
  getHash(): Promise<SourceHash>
41
44
 
@@ -72,7 +75,8 @@ export declare class Stone<T extends StoneConfig> {
72
75
  * @param path
73
76
  * If `path` is a directory, stores the file(s) under that path, using their standard names.
74
77
  * If `path` is a file and this stone generates only single data source, stores it under the supplied path.
75
- * @param generate If true (default), the source is exported right away.
78
+ * @param generate If true (default), the source is exported right away. Will not re-save the file, if it already
79
+ * exists under the same path and hash.
76
80
  */
77
81
  setAbsolutePath(path: string, generate?: boolean): Promise<Source>
78
82
 
@@ -95,6 +99,17 @@ export declare class Stone<T extends StoneConfig> {
95
99
  export type StoneConfig = {
96
100
  cacheStrategy?: null | CacheStrategy,
97
101
  /**
102
+ * Registers another stone as dependency of this one. Useful for external processes
103
+ * that use a source of some stone, but don't go via Whet to get it.
104
+ * Use with combination of `setAbsolutePath` on the dependency, so that the external process
105
+ * can rely on fixed path.
106
+ * Will make sure the cached file is up to date when generating this stone.
107
+ * Hash of the dependency is automatically combined with hash generated by this stone. There's no
108
+ * need to add it manually.
109
+ * Do not create cyclic dependencies!
110
+ */
111
+ dependencies?: null | MaybeArray<AnyStone>,
112
+ /**
98
113
  Defaults to the Stone's class name.
99
114
  */
100
115
  id?: null | StoneIdType,
package/bin/whet/Stone.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import {StoneId_Fields_} from "./magic/StoneId.js"
2
+ import {MaybeArray_Fields_} from "./magic/MaybeArray.js"
2
3
  import {CacheStrategy, CacheDurability} from "./cache/Cache.js"
3
4
  import {Utils} from "./Utils.js"
4
- import {SourceId_Fields_, SourceId, RootDir} from "./SourceId.js"
5
+ import {SourceId, RootDir} from "./SourceId.js"
5
6
  import {SourceHash} from "./SourceHash.js"
6
7
  import {Source} from "./Source.js"
7
8
  import {Project} from "./Project.js"
@@ -58,7 +59,9 @@ class Stone extends Register.inherits() {
58
59
  }
59
60
 
60
61
  /**
61
- Hash of this stone with its current config. Defaults to hash of generated source.
62
+ * **Do not override.**
63
+ * Hash of this stone with its current config. Defaults to hash of generated source.
64
+ * Hashes of dependency stones (see `config.dependencies`) will be added to the hash.
62
65
  */
63
66
  getHash() {
64
67
  var _gthis = this;
@@ -68,7 +71,17 @@ class Stone extends Register.inherits() {
68
71
  return hash;
69
72
  } else {
70
73
  return _gthis.getSource().then(function (s) {
71
- return s.hash;
74
+ if (_gthis.config.dependencies != null) {
75
+ var _g = [];
76
+ var _g1 = 0;
77
+ var _g2 = MaybeArray_Fields_.makeArray(_gthis.config.dependencies);
78
+ while (_g1 < _g2.length) _g.push(_g2[_g1++].getHash());
79
+ return Promise.all(_g).then(function (hashes) {
80
+ return s.hash.add(SourceHash.merge(...hashes));
81
+ });
82
+ } else {
83
+ return Promise.resolve(s.hash);
84
+ };
72
85
  });
73
86
  };
74
87
  });
@@ -82,24 +95,37 @@ class Stone extends Register.inherits() {
82
95
  generateSource(hash) {
83
96
  var _gthis = this;
84
97
  Log.log(20, ...["Generating source.", {"stone": this, "hash": hash}]);
85
- var dataPromise = this.generate(hash);
86
- if (dataPromise != null) {
87
- return dataPromise.then(function (data) {
88
- if (hash == null) {
89
- var result = new Array(data.length);
90
- var _g = 0;
91
- var _g1 = data.length;
92
- while (_g < _g1) {
93
- var i = _g++;
94
- result[i] = SourceHash.fromBytes(data[i].data);
95
- };
96
- hash = SourceHash.merge(...result);
97
- };
98
- return new Source(data, hash, _gthis, Date.now() / 1000);
99
- });
98
+ console.log("src/whet/Stone.hx:74:",this.config.dependencies);
99
+ var init;
100
+ if (this.config.dependencies != null) {
101
+ var _g = [];
102
+ var _g1 = 0;
103
+ var _g2 = MaybeArray_Fields_.makeArray(this.config.dependencies);
104
+ while (_g1 < _g2.length) _g.push(_g2[_g1++].getSource());
105
+ init = Promise.all(_g);
100
106
  } else {
101
- return null;
107
+ init = Promise.resolve(null);
102
108
  };
109
+ return init.then(function (_) {
110
+ var dataPromise = _gthis.generate(hash);
111
+ if (dataPromise != null) {
112
+ return dataPromise.then(function (data) {
113
+ if (hash == null) {
114
+ var result = new Array(data.length);
115
+ var _g = 0;
116
+ var _g1 = data.length;
117
+ while (_g < _g1) {
118
+ var i = _g++;
119
+ result[i] = SourceHash.fromBytes(data[i].data);
120
+ };
121
+ hash = SourceHash.merge(...result);
122
+ };
123
+ return new Source(data, hash, _gthis, Date.now() / 1000);
124
+ });
125
+ } else {
126
+ return null;
127
+ };
128
+ });
103
129
  }
104
130
 
105
131
  /**
@@ -134,16 +160,21 @@ class Stone extends Register.inherits() {
134
160
  * @param path
135
161
  * If `path` is a directory, stores the file(s) under that path, using their standard names.
136
162
  * If `path` is a file and this stone generates only single data source, stores it under the supplied path.
137
- * @param generate If true (default), the source is exported right away.
163
+ * @param generate If true (default), the source is exported right away. Will not re-save the file, if it already
164
+ * exists under the same path and hash.
138
165
  */
139
166
  setAbsolutePath(path, generate) {
140
167
  if (generate == null) {
141
168
  generate = true;
142
169
  };
143
170
  var s = path;
144
- s = Path.posix.normalize((path.length > 1 && SourceId_Fields_.startsWithSlash(path)) ? HxOverrides.substr(path, 1, null) : path);
145
- s = StringTools.replace(s, "\\", "/");
146
- this.cacheStrategy = CacheStrategy.AbsolutePath((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s, CacheDurability.LimitCountByAge(1));
171
+ var str = (path.length > 1 && HxOverrides.cca(path, 0) == 47) ? path.substring(1) : path;
172
+ if (str.length > 0) {
173
+ str = Path.posix.normalize(str);
174
+ str = StringTools.replace(str, "\\", "/");
175
+ };
176
+ s = str;
177
+ this.cacheStrategy = CacheStrategy.AbsolutePath((HxOverrides.cca(s, 0) == 47) ? s : "/" + s, CacheDurability.LimitCountByAge(1));
147
178
  if (generate) {
148
179
  return this.getSource();
149
180
  } else {
@@ -160,10 +191,14 @@ class Stone extends Register.inherits() {
160
191
  var _gthis = this;
161
192
  Log.log(30, ...["Exporting file(s).", {"path": path, "stone": this}]);
162
193
  var s = path;
163
- s = Path.posix.normalize((path.length > 1 && SourceId_Fields_.startsWithSlash(path)) ? HxOverrides.substr(path, 1, null) : path);
164
- s = StringTools.replace(s, "\\", "/");
165
- var pathId = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
166
- var isDir = SourceId_Fields_.endsWithSlash(pathId);
194
+ var str = (path.length > 1 && HxOverrides.cca(path, 0) == 47) ? path.substring(1) : path;
195
+ if (str.length > 0) {
196
+ str = Path.posix.normalize(str);
197
+ str = StringTools.replace(str, "\\", "/");
198
+ };
199
+ s = str;
200
+ var pathId = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
201
+ var isDir = HxOverrides.cca(pathId, pathId.length - 1) == 47;
167
202
  return this.getSource().then(function (src) {
168
203
  if (src.data.length > 1 && !isDir) {
169
204
  throw new Error("Path is not a directory for multiple source export.");
package/bin/whet/Whet.js CHANGED
@@ -10,7 +10,7 @@ const $global = Register.$global
10
10
  export const Whet_Fields_ = Register.global("$hxClasses")["whet._Whet.Whet_Fields_"] =
11
11
  class Whet_Fields_ {
12
12
  static main() {
13
- Whet_Fields_.program.enablePositionalOptions().passThroughOptions().description("Project tooling.").usage("[options] [command] [+ [command]...]").version("0.0.8", "-v, --version").allowUnknownOption(true).showSuggestionAfterError(true).option("-p, --project <file>", "project to run", "Project.mjs").option("-l, --log-level <level>", "log level, a string/number", "info");
13
+ Whet_Fields_.program.enablePositionalOptions().passThroughOptions().description("Project tooling.").usage("[options] [command] [+ [command]...]").version("0.0.11", "-v, --version").allowUnknownOption(true).showSuggestionAfterError(true).option("-p, --project <file>", "project to run", "Project.mjs").option("-l, --log-level <level>", "log level, a string/number", "info");
14
14
  Whet_Fields_.program.parse();
15
15
  var options = Whet_Fields_.program.opts();
16
16
  if (options.logLevel != null) {
@@ -1,5 +1,5 @@
1
1
  import {Cache} from "./Cache.js"
2
- import {SourceId_Fields_, SourceId} from "../SourceId.js"
2
+ import {SourceId} from "../SourceId.js"
3
3
  import {SourceHash} from "../SourceHash.js"
4
4
  import {Log} from "../Log.js"
5
5
  import * as Path from "path"
@@ -15,7 +15,7 @@ const $global = Register.$global
15
15
  export const BaseCache = Register.global("$hxClasses")["whet.cache.BaseCache"] =
16
16
  class BaseCache extends Register.inherits() {
17
17
  new(rootDir, cache) {
18
- if (!SourceId_Fields_.endsWithSlash(rootDir)) {
18
+ if (HxOverrides.cca(rootDir, rootDir.length - 1) != 47) {
19
19
  throw new Error("Root dir is a not a dir.");
20
20
  };
21
21
  this.rootDir = rootDir;
@@ -125,9 +125,13 @@ class BaseCache extends Register.inherits() {
125
125
  var filenames = this.getExistingDirs(stone);
126
126
  var maxNum = (filenames != null) ? Lambda.fold(filenames, function (fn, num) {
127
127
  var s = fn.substring(0, fn.lastIndexOf("/") + 1);
128
- s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
129
- s = StringTools.replace(s, "\\", "/");
130
- var this1 = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
128
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
129
+ if (str.length > 0) {
130
+ str = Path.posix.normalize(str);
131
+ str = StringTools.replace(str, "\\", "/");
132
+ };
133
+ s = str;
134
+ var this1 = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
131
135
  var root = _gthis.rootDir;
132
136
  if (this1.charAt(0) != "/") {
133
137
  throw new Error("Badly formed SourceId.");
@@ -138,9 +142,13 @@ class BaseCache extends Register.inherits() {
138
142
  }, 0) : 0;
139
143
  ++maxNum;
140
144
  var s = "v" + maxNum + "/";
141
- s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
142
- s = StringTools.replace(s, "\\", "/");
143
- return SourceId.getPutInDir((SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s, baseDir);
145
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
146
+ if (str.length > 0) {
147
+ str = Path.posix.normalize(str);
148
+ str = StringTools.replace(str, "\\", "/");
149
+ };
150
+ s = str;
151
+ return SourceId.getPutInDir((HxOverrides.cca(s, 0) == 47) ? s : "/" + s, baseDir);
144
152
  }
145
153
  checkDurability(stone, values, durability, useIndex, ageIndex) {
146
154
  Log.log(20, ...["Checking durability.", {"stone": stone, "durability": Std.string(durability)}]);
@@ -19,6 +19,11 @@ export declare class CacheManager {
19
19
  defaultFileStrategy: CacheStrategy
20
20
  getSource(stone: AnyStone): Promise<Source>
21
21
 
22
+ /**
23
+ * Re-generates source even if the currently cached value is valid.
24
+ */
25
+ refreshSource(stone: AnyStone): Promise<Source>
26
+
22
27
  /**
23
28
  * Get valid directory to generate files in. The path is unique per stone based on caching rules.
24
29
  * If hash is supplied, and a path was already assigned, the same path is returned, assuring consistency.
@@ -1,7 +1,7 @@
1
1
  import {MemoryCache} from "./MemoryCache.js"
2
2
  import {FileCache} from "./FileCache.js"
3
3
  import {CacheStrategy, CacheDurability, DurabilityCheck} from "./Cache.js"
4
- import {RootDir, SourceId_Fields_, SourceId} from "../SourceId.js"
4
+ import {RootDir, SourceId} from "../SourceId.js"
5
5
  import {Log} from "../Log.js"
6
6
  import * as Path from "path"
7
7
  import {Register} from "../../genes/Register.js"
@@ -47,6 +47,30 @@ class CacheManager extends Register.inherits() {
47
47
  };
48
48
  }
49
49
 
50
+ /**
51
+ * Re-generates source even if the currently cached value is valid.
52
+ */
53
+ refreshSource(stone) {
54
+ Log.log(10, ...["Re-generating cached stone.", {"stone": stone}]);
55
+ switch (stone.cacheStrategy._hx_index) {
56
+ case 0:
57
+ return stone.generateHash().then(function (hash) {
58
+ return stone.generateSource(hash);
59
+ });
60
+ break
61
+ case 1:
62
+ return this.memCache.get(stone, CacheDurability.MaxAge(-1), DurabilityCheck.SingleOnGet);
63
+ break
64
+ case 2:
65
+ return this.fileCache.get(stone, CacheDurability.MaxAge(-1), DurabilityCheck.SingleOnGet);
66
+ break
67
+ case 3:
68
+ return this.fileCache.get(stone, CacheDurability.MaxAge(-1), DurabilityCheck.SingleOnGet);
69
+ break
70
+
71
+ };
72
+ }
73
+
50
74
  /**
51
75
  * Get valid directory to generate files in. The path is unique per stone based on caching rules.
52
76
  * If hash is supplied, and a path was already assigned, the same path is returned, assuring consistency.
@@ -54,9 +78,13 @@ class CacheManager extends Register.inherits() {
54
78
  */
55
79
  getDir(stone, hash) {
56
80
  var s = stone.id + "/";
57
- s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
58
- s = StringTools.replace(s, "\\", "/");
59
- var baseDir = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
81
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
82
+ if (str.length > 0) {
83
+ str = Path.posix.normalize(str);
84
+ str = StringTools.replace(str, "\\", "/");
85
+ };
86
+ s = str;
87
+ var baseDir = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
60
88
  var tmp;
61
89
  switch (stone.cacheStrategy._hx_index) {
62
90
  case 0:
@@ -71,14 +99,22 @@ class CacheManager extends Register.inherits() {
71
99
  };
72
100
  if (tmp) {
73
101
  var s = ".temp/";
74
- s = Path.posix.normalize((".temp/".length > 1 && SourceId_Fields_.startsWithSlash(".temp/")) ? HxOverrides.substr(".temp/", 1, null) : ".temp/");
75
- s = StringTools.replace(s, "\\", "/");
76
- baseDir = SourceId.getPutInDir(baseDir, (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s);
102
+ var str = (".temp/".length > 1 && HxOverrides.cca(".temp/", 0) == 47) ? ".temp/".substring(1) : ".temp/";
103
+ if (str.length > 0) {
104
+ str = Path.posix.normalize(str);
105
+ str = StringTools.replace(str, "\\", "/");
106
+ };
107
+ s = str;
108
+ baseDir = SourceId.getPutInDir(baseDir, (HxOverrides.cca(s, 0) == 47) ? s : "/" + s);
77
109
  };
78
110
  var s = ".whet/";
79
- s = Path.posix.normalize((".whet/".length > 1 && SourceId_Fields_.startsWithSlash(".whet/")) ? HxOverrides.substr(".whet/", 1, null) : ".whet/");
80
- s = StringTools.replace(s, "\\", "/");
81
- baseDir = SourceId.getPutInDir(baseDir, (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s);
111
+ var str = (".whet/".length > 1 && HxOverrides.cca(".whet/", 0) == 47) ? ".whet/".substring(1) : ".whet/";
112
+ if (str.length > 0) {
113
+ str = Path.posix.normalize(str);
114
+ str = StringTools.replace(str, "\\", "/");
115
+ };
116
+ s = str;
117
+ baseDir = SourceId.getPutInDir(baseDir, (HxOverrides.cca(s, 0) == 47) ? s : "/" + s);
82
118
  var id;
83
119
  var _g = stone.cacheStrategy;
84
120
  switch (_g._hx_index) {
@@ -94,9 +130,13 @@ class CacheManager extends Register.inherits() {
94
130
  case 3:
95
131
  var _g1 = _g.path;
96
132
  var s = _g1.substring(0, _g1.lastIndexOf("/") + 1);
97
- s = Path.posix.normalize((s.length > 1 && SourceId_Fields_.startsWithSlash(s)) ? HxOverrides.substr(s, 1, null) : s);
98
- s = StringTools.replace(s, "\\", "/");
99
- id = (SourceId_Fields_.startsWithSlash(s)) ? s : "/" + s;
133
+ var str = (s.length > 1 && HxOverrides.cca(s, 0) == 47) ? s.substring(1) : s;
134
+ if (str.length > 0) {
135
+ str = Path.posix.normalize(str);
136
+ str = StringTools.replace(str, "\\", "/");
137
+ };
138
+ s = str;
139
+ id = (HxOverrides.cca(s, 0) == 47) ? s : "/" + s;
100
140
  break
101
141
 
102
142
  };