whet 0.0.12 → 0.0.13

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.
@@ -42,18 +42,34 @@ export declare class Stone<T extends StoneConfig> {
42
42
  */
43
43
  getHash(): Promise<SourceHash>
44
44
 
45
+ /**
46
+ * **Do not override.**
47
+ * Should only be used internally.
48
+ * Used to finalize a hash in `getHash` or in `generateSource` if `getHash` isn't implemented.
49
+ * Also used by the cache for the same purpose.
50
+ */
51
+ protected finalizeHash(hash: SourceHash): Promise<null | SourceHash>
52
+
45
53
  /**
46
54
  * **Do not override.**
47
55
  * Generates new Source. Used by the cache when needed.
48
56
  * Hash passed should be the same as is this stone's current one. Passed in as optimization.
49
57
  */
50
- protected generateSource(hash: SourceHash): Promise<Source>
58
+ protected generateSource(hash: null | SourceHash): Promise<Source>
51
59
 
52
60
  /**
53
61
  * Optionally overridable hash generation as optimization.
62
+ * Do not use directly. Use `getHash` instead.
54
63
  */
55
64
  protected generateHash(): Promise<SourceHash>
56
65
 
66
+ /**
67
+ * **Do not override.**
68
+ * Used by cache. Returns either null, or result of `generateHash` finalized by adding
69
+ * dependencies.
70
+ */
71
+ protected finalMaybeHash(): Promise<null | SourceHash>
72
+
57
73
  /**
58
74
  * Abstract method.
59
75
  * Function that actually generates the source. Passed hash is only non-null
package/bin/whet/Stone.js CHANGED
@@ -66,27 +66,37 @@ class Stone extends Register.inherits() {
66
66
  getHash() {
67
67
  var _gthis = this;
68
68
  Log.log(20, ...["Generating hash.", {"stone": this}]);
69
- return this.generateHash().then(function (hash) {
69
+ return this.finalMaybeHash().then(function (hash) {
70
70
  if (hash != null) {
71
71
  return hash;
72
72
  } else {
73
73
  return _gthis.getSource().then(function (s) {
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
- };
74
+ return s.hash;
85
75
  });
86
76
  };
87
77
  });
88
78
  }
89
79
 
80
+ /**
81
+ * **Do not override.**
82
+ * Should only be used internally.
83
+ * Used to finalize a hash in `getHash` or in `generateSource` if `getHash` isn't implemented.
84
+ * Also used by the cache for the same purpose.
85
+ */
86
+ finalizeHash(hash) {
87
+ if (hash == null || this.config.dependencies == null) {
88
+ return Promise.resolve(hash);
89
+ } else {
90
+ var _g = [];
91
+ var _g1 = 0;
92
+ var _g2 = MaybeArray_Fields_.makeArray(this.config.dependencies);
93
+ while (_g1 < _g2.length) _g.push(_g2[_g1++].getHash());
94
+ return Promise.all(_g).then(function (hashes) {
95
+ return hash.add(SourceHash.merge(...hashes));
96
+ });
97
+ };
98
+ }
99
+
90
100
  /**
91
101
  * **Do not override.**
92
102
  * Generates new Source. Used by the cache when needed.
@@ -109,7 +119,11 @@ class Stone extends Register.inherits() {
109
119
  var dataPromise = _gthis.generate(hash);
110
120
  if (dataPromise != null) {
111
121
  return dataPromise.then(function (data) {
112
- if (hash == null) {
122
+ var finalHash;
123
+ if (hash != null) {
124
+ finalHash = Promise.resolve(hash);
125
+ } else {
126
+ var _gthis1 = _gthis;
113
127
  var result = new Array(data.length);
114
128
  var _g = 0;
115
129
  var _g1 = data.length;
@@ -117,9 +131,11 @@ class Stone extends Register.inherits() {
117
131
  var i = _g++;
118
132
  result[i] = SourceHash.fromBytes(data[i].data);
119
133
  };
120
- hash = SourceHash.merge(...result);
134
+ finalHash = _gthis1.finalizeHash(SourceHash.merge(...result));
121
135
  };
122
- return new Source(data, hash, _gthis, Date.now() / 1000);
136
+ return finalHash.then(function (hash) {
137
+ return new Source(data, hash, _gthis, Date.now() / 1000);
138
+ });
123
139
  });
124
140
  } else {
125
141
  return null;
@@ -129,11 +145,24 @@ class Stone extends Register.inherits() {
129
145
 
130
146
  /**
131
147
  * Optionally overridable hash generation as optimization.
148
+ * Do not use directly. Use `getHash` instead.
132
149
  */
133
150
  generateHash() {
134
151
  return Promise.resolve(null);
135
152
  }
136
153
 
154
+ /**
155
+ * **Do not override.**
156
+ * Used by cache. Returns either null, or result of `generateHash` finalized by adding
157
+ * dependencies.
158
+ */
159
+ finalMaybeHash() {
160
+ var _gthis = this;
161
+ return this.generateHash().then(function (hash) {
162
+ return _gthis.finalizeHash(hash);
163
+ });
164
+ }
165
+
137
166
  /**
138
167
  * Returns a list of sources that this stone generates.
139
168
  * Used by Router for finding the correct asset.
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.12", "-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.13", "-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) {
@@ -23,7 +23,7 @@ class BaseCache extends Register.inherits() {
23
23
  }
24
24
  get(stone, durability, check) {
25
25
  var _gthis = this;
26
- return stone.generateHash().then(function (hash) {
26
+ return stone.finalMaybeHash().then(function (hash) {
27
27
  if (hash == null) {
28
28
  Log.log(20, ...["Generating source, because it does not supply a hash.", {"stone": stone, "cache": _gthis}]);
29
29
  };
@@ -27,7 +27,7 @@ class CacheManager extends Register.inherits() {
27
27
  var _g = stone.cacheStrategy;
28
28
  switch (_g._hx_index) {
29
29
  case 0:
30
- return stone.generateHash().then(function (hash) {
30
+ return stone.finalMaybeHash().then(function (hash) {
31
31
  return stone.generateSource(hash);
32
32
  });
33
33
  break
@@ -54,7 +54,7 @@ class CacheManager extends Register.inherits() {
54
54
  Log.log(10, ...["Re-generating cached stone.", {"stone": stone}]);
55
55
  switch (stone.cacheStrategy._hx_index) {
56
56
  case 0:
57
- return stone.generateHash().then(function (hash) {
57
+ return stone.finalMaybeHash().then(function (hash) {
58
58
  return stone.generateSource(hash);
59
59
  });
60
60
  break
@@ -124,7 +124,7 @@ class HaxeBuild extends Register.inherits(Stone) {
124
124
  };
125
125
  result[i] = Path.posix.join(".", root, ".", this1);
126
126
  };
127
- return Promise.all([this.config.hxml.generateHash(), SourceHash.fromFiles(result)]).then(function (r) {
127
+ return Promise.all([this.config.hxml.getHash(), SourceHash.fromFiles(result)]).then(function (r) {
128
128
  return SourceHash.merge(...r);
129
129
  });
130
130
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whet",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "NodeJS based assets management and project tooling library.",
5
5
  "scripts": {
6
6
  "devinit": "npx dts2hx commander --modular --noLibWrap",