@wavemaker/rn-codegen 11.15.5-rc.647771 → 11.15.5-rc.647878

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.
Files changed (147) hide show
  1. package/command.js +94 -262
  2. package/command.js.map +1 -1
  3. package/index.js +131 -125
  4. package/index.js.map +1 -1
  5. package/npm-shrinkwrap.json +575 -556
  6. package/package-lock.json +575 -556
  7. package/package.json +14 -10
  8. package/scripts/check-deps-compat.js +579 -0
  9. package/src/app.generator.js +438 -159
  10. package/src/app.generator.js.map +1 -1
  11. package/src/increment-builder.js +2 -1
  12. package/src/increment-builder.js.map +1 -1
  13. package/src/pipeline/build-common.js +63 -0
  14. package/src/pipeline/build-common.js.map +1 -0
  15. package/src/pipeline/build-pipeline.js +169 -0
  16. package/src/pipeline/build-pipeline.js.map +1 -0
  17. package/src/pipeline/generation-store.js +309 -0
  18. package/src/pipeline/generation-store.js.map +1 -0
  19. package/src/pipeline/shared-node-modules.js +934 -0
  20. package/src/pipeline/shared-node-modules.js.map +1 -0
  21. package/src/pipeline/web-preview-templates.js +80 -0
  22. package/src/pipeline/web-preview-templates.js.map +1 -0
  23. package/src/pipeline/working-set.js +103 -0
  24. package/src/pipeline/working-set.js.map +1 -0
  25. package/src/profiles/legacy-web-preview.profile.js +15 -0
  26. package/src/profiles/legacy-web-preview.profile.js.map +1 -0
  27. package/src/project.service.js +14 -0
  28. package/src/project.service.js.map +1 -1
  29. package/src/templates/app.template +74 -2
  30. package/src/templates/babel.config.js.template +3 -6
  31. package/src/templates/bootstrap.template +10 -1
  32. package/src/templates/component/component.template +1 -0
  33. package/src/templates/foundation-theme/build/android/wavemaker/components/input/epoch/date.less +8 -1
  34. package/src/templates/foundation-theme/build/android/wavemaker/components/input/epoch/datetime.less +8 -1
  35. package/src/templates/foundation-theme/build/android/wavemaker/components/input/epoch/time.less +8 -1
  36. package/src/templates/foundation-theme/build/android/wavemaker/components/input/number.less +14 -0
  37. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/basic/button.less +2 -2
  38. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/input/checkboxset.less +1 -0
  39. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/input/chips.less +12 -0
  40. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/input/radioset.less +1 -1
  41. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/studio/input/currency.less +6 -2
  42. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/tokens.light.css +3 -2
  43. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/variables/button.variant.less +2 -2
  44. package/src/templates/foundation-theme/build/ios/wavemaker/components/input/epoch/date.less +8 -1
  45. package/src/templates/foundation-theme/build/ios/wavemaker/components/input/epoch/datetime.less +8 -1
  46. package/src/templates/foundation-theme/build/ios/wavemaker/components/input/epoch/time.less +8 -1
  47. package/src/templates/foundation-theme/build/ios/wavemaker/components/input/number.less +14 -0
  48. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/basic/button.less +2 -2
  49. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/input/checkboxset.less +1 -0
  50. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/input/chips.less +12 -0
  51. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/input/radioset.less +1 -1
  52. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/studio/input/currency.less +6 -2
  53. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/tokens.light.css +3 -2
  54. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/variables/button.variant.less +2 -2
  55. package/src/templates/foundation-theme/dist/android/style.css +5 -4
  56. package/src/templates/foundation-theme/dist/android/style.js +22 -9
  57. package/src/templates/foundation-theme/dist/android/tokens.js +3 -2
  58. package/src/templates/foundation-theme/dist/ios/style.css +5 -4
  59. package/src/templates/foundation-theme/dist/ios/style.js +22 -9
  60. package/src/templates/foundation-theme/dist/ios/tokens.js +3 -2
  61. package/src/templates/foundation-theme/wavemaker/components/input/epoch/date.less +8 -1
  62. package/src/templates/foundation-theme/wavemaker/components/input/epoch/datetime.less +8 -1
  63. package/src/templates/foundation-theme/wavemaker/components/input/epoch/time.less +8 -1
  64. package/src/templates/foundation-theme/wavemaker/components/input/number.less +14 -0
  65. package/src/templates/foundation-theme/wavemaker/design-tokens/basic/button.less +2 -2
  66. package/src/templates/foundation-theme/wavemaker/design-tokens/input/checkboxset.less +1 -0
  67. package/src/templates/foundation-theme/wavemaker/design-tokens/input/chips.less +12 -0
  68. package/src/templates/foundation-theme/wavemaker/design-tokens/input/radioset.less +1 -1
  69. package/src/templates/foundation-theme/wavemaker/design-tokens/studio/input/currency.less +6 -2
  70. package/src/templates/foundation-theme/wavemaker/design-tokens/tokens.light.css +3 -2
  71. package/src/templates/foundation-theme/wavemaker/design-tokens/variables/button.variant.less +2 -2
  72. package/src/templates/package.web.json +17 -7
  73. package/src/templates/page-stub.template +27 -0
  74. package/src/templates/project/.npmrc +1 -0
  75. package/src/templates/project/app.json +2 -1
  76. package/src/templates/project/esbuild/esbuild.script.js +56 -16
  77. package/src/templates/project/metro/container-limits.js +195 -0
  78. package/src/templates/project/metro/metro.script.js +850 -0
  79. package/src/templates/project/metro/module-path.js +237 -0
  80. package/src/templates/project/metro/split.serializer.js +184 -0
  81. package/src/templates/project/metro/split.static.js +633 -0
  82. package/src/templates/project/metro/stable-module-ids.js +54 -0
  83. package/src/templates/project/metro/vendor-cache.js +475 -0
  84. package/src/templates/project/metro/wm-boundary.js +150 -0
  85. package/src/templates/project/metro/wm-crawl-override.js +161 -0
  86. package/src/templates/project/metro/wm-fastbuild.js +196 -0
  87. package/src/templates/project/metro/wm-live-reload.js +482 -0
  88. package/src/templates/project/metro/wm-metro-adapter.js +25 -0
  89. package/src/templates/project/metro/wm-prebuilt.js +31 -0
  90. package/src/templates/project/metro.config.js +13 -2
  91. package/src/templates/project/package-lock.json +15308 -0
  92. package/src/templates/project/package.json +14 -6
  93. package/src/templates/project/patch-utils.js +331 -0
  94. package/src/templates/project/plugins/expo-pull-to-refresh/android/build.gradle +15 -0
  95. package/src/templates/project/plugins/expo-pull-to-refresh/android/src/main/java/expo/modules/pulltorefresh/ExpoPullToRefreshModule.kt +21 -0
  96. package/src/templates/project/plugins/expo-pull-to-refresh/android/src/main/java/expo/modules/pulltorefresh/ExpoPullToRefreshView.kt +221 -0
  97. package/src/templates/project/plugins/expo-pull-to-refresh/expo-module.config.json +16 -0
  98. package/src/templates/project/plugins/expo-pull-to-refresh/ios/ExpoPullToRefresh.podspec +24 -0
  99. package/src/templates/project/plugins/expo-pull-to-refresh/ios/ExpoPullToRefreshControlModule.swift +17 -0
  100. package/src/templates/project/plugins/expo-pull-to-refresh/ios/ExpoPullToRefreshControlView.swift +92 -0
  101. package/src/templates/project/plugins/expo-pull-to-refresh/package.json +15 -0
  102. package/src/templates/project/scripts/wm-babel.transform.plugin.js +11 -1
  103. package/src/templates/project/wavepulse/rn2css.json +5 -0
  104. package/src/theme/app-override-css.generator.js +10 -4
  105. package/src/theme/app-override-css.generator.js.map +1 -1
  106. package/src/theme/components/input/epoch/datetime.styledef.js +5 -0
  107. package/src/theme/components/input/epoch/datetime.styledef.js.map +1 -1
  108. package/src/theme/components/input/number.styledef.js +10 -0
  109. package/src/theme/components/input/number.styledef.js.map +1 -1
  110. package/src/theme/rn-stylesheet.transpiler.js +30 -6
  111. package/src/theme/rn-stylesheet.transpiler.js.map +1 -1
  112. package/src/theme/theme.service.js +3 -2
  113. package/src/theme/theme.service.js.map +1 -1
  114. package/src/transpile/bind.ex.transformer.js +55 -37
  115. package/src/transpile/bind.ex.transformer.js.map +1 -1
  116. package/src/transpile/components/container/wizard/wizardstep.transformer.js +10 -2
  117. package/src/transpile/components/container/wizard/wizardstep.transformer.js.map +1 -1
  118. package/src/transpile/components/data/form/form-field.transformer.js +36 -1
  119. package/src/transpile/components/data/form/form-field.transformer.js.map +1 -1
  120. package/src/transpile/components/page/page.transformer.js +11 -1
  121. package/src/transpile/components/page/page.transformer.js.map +1 -1
  122. package/src/transpile/property/property-parser.js +4 -1
  123. package/src/transpile/property/property-parser.js.map +1 -1
  124. package/src/transpile/style.transformer.js +1 -0
  125. package/src/transpile/style.transformer.js.map +1 -1
  126. package/src/transpile/transpile.js +10 -1
  127. package/src/transpile/transpile.js.map +1 -1
  128. package/src/utils.js +8 -1
  129. package/src/utils.js.map +1 -1
  130. package/src/wm-namespace.js +14 -0
  131. package/src/wm-namespace.js.map +1 -0
  132. package/test/pipeline/build-leftovers.test.js +172 -0
  133. package/test/pipeline/build-leftovers.test.js.map +1 -0
  134. package/test/pipeline/chmod-tree.test.js +54 -0
  135. package/test/pipeline/chmod-tree.test.js.map +1 -0
  136. package/test/pipeline/crawl-override.test.js +53 -0
  137. package/test/pipeline/crawl-override.test.js.map +1 -0
  138. package/test/pipeline/live-reload-pacing.test.js +76 -0
  139. package/test/pipeline/live-reload-pacing.test.js.map +1 -0
  140. package/test/pipeline/npm-install-retry.test.js +57 -0
  141. package/test/pipeline/npm-install-retry.test.js.map +1 -0
  142. package/test/pipeline/repair-vendor-packages.test.js +134 -0
  143. package/test/pipeline/repair-vendor-packages.test.js.map +1 -0
  144. package/test/pipeline/web-preview-files.test.js +48 -0
  145. package/test/pipeline/web-preview-files.test.js.map +1 -0
  146. package/web-preview.js +155 -0
  147. package/web-preview.js.map +1 -0
@@ -0,0 +1,482 @@
1
+ /*
2
+ * Web-preview live reload: applies a rebuild to the running page without a refresh.
3
+ * Polls index.html (304 until it changes). A fast-path build that only re-emits the modified
4
+ * overlay is hot-patched in place; anything else falls back to clearing Metro's registry and
5
+ * re-running the chunks. A project turns it off with "preview": { "liveReload": false } and sets the
6
+ * interval with "preview": { "pollIntervalMs": N } in wm_rn_config.json. Also disabled by WM_LIVE_RELOAD=0 or
7
+ * window.__WM_LIVE_RELOAD__ =
8
+ * {enabled:false}; disable just the hot patch with {hotPatch:false}.
9
+ */
10
+ (function () {
11
+ 'use strict';
12
+
13
+ var g = typeof globalThis !== 'undefined' ? globalThis : window;
14
+ var cfg = g.__WM_LIVE_RELOAD__ || {};
15
+ if (cfg.enabled === false) { return; }
16
+
17
+ /* A restart re-injects every script tag in index.html, this one included, and __c() does not
18
+ touch plain-script closures -- so without this guard each restart left another poller running
19
+ and the next edit was applied N times concurrently. */
20
+ if (g.__WM_LIVE_RELOAD_ACTIVE__) { return; }
21
+ g.__WM_LIVE_RELOAD_ACTIVE__ = true;
22
+
23
+ var INTERVAL = cfg.intervalMs || 2000;
24
+ var CHUNK_RE = /<script src="\.\/([^"]+\.js)"/g;
25
+ var MODIFIED_RE = /-modified\.js$/;
26
+ var SELF_RE = /wm-live-reload\.js$/;
27
+
28
+ function log() {
29
+ if (cfg.quiet) { return; }
30
+ try { console.log.apply(console, ['[wm-live]'].concat([].slice.call(arguments))); } catch (e) {}
31
+ }
32
+
33
+ var base = (function () {
34
+ try {
35
+ if (document.currentScript && document.currentScript.src) {
36
+ return String(document.currentScript.src).replace(/\/[^/]*$/, '');
37
+ }
38
+ return location.pathname.replace(/\/[^/]*$/, '');
39
+ } catch (e) { return ''; }
40
+ })();
41
+
42
+ /* This client is a script tag in index.html too, but it is not a bundle chunk: it never changes
43
+ name and must never be re-executed, so it is filtered out of every list built from the page. */
44
+ function chunksOf(html) {
45
+ var out = [], m;
46
+ CHUNK_RE.lastIndex = 0;
47
+ while ((m = CHUNK_RE.exec(html)) !== null) {
48
+ if (!SELF_RE.test(m[1])) { out.push(m[1]); }
49
+ }
50
+ return out;
51
+ }
52
+
53
+ /* The chunks this page was loaded with are the baseline. Taking it from the first index.html fetch was
54
+ wrong when that fetch hit a build's placeholder (no chunks), so the finished build was never applied. */
55
+ var current = chunksOf(document.documentElement.innerHTML);
56
+ if (!current.length) { current = null; }
57
+ var etag = null;
58
+ var applying = false;
59
+
60
+ /* Chunk filenames are content-hashed, so a cached source can never be stale: a changed chunk
61
+ always arrives under a new name and misses. Only the modified chunk changes between builds, so
62
+ this turns a ~900ms re-fetch (vendor alone is ~4.9MB) into one small request. */
63
+ var sourceCache = Object.create(null);
64
+
65
+ function fetchChunk(file) {
66
+ if (sourceCache[file] !== undefined) { return Promise.resolve(sourceCache[file]); }
67
+ return fetch(base + '/' + file, { credentials: 'same-origin' }).then(function (res) {
68
+ if (!res.ok) { throw new Error('failed to load ' + file); }
69
+ return res.text();
70
+ }).then(function (src) {
71
+ sourceCache[file] = src;
72
+ return src;
73
+ });
74
+ }
75
+
76
+ /* Every build mints a new modified-chunk name, so without this the cache grows by one entry per edit. */
77
+ function pruneCache(list) {
78
+ Object.keys(sourceCache).forEach(function (f) {
79
+ if (list.indexOf(f) === -1) { delete sourceCache[f]; }
80
+ });
81
+ }
82
+
83
+ /* Fetch every chunk at once, then execute in order. Appending <script src> one at a time cost a
84
+ full round trip per chunk (measured ~260ms x 5) even though only the modified chunk changed;
85
+ inline execution still runs synchronously on append, so __d registration order is preserved. */
86
+ function loadInOrder(list) {
87
+ pruneCache(list);
88
+ return Promise.all(list.map(fetchChunk)).then(function (sources) {
89
+ sources.forEach(function (src, i) {
90
+ var el = document.createElement('script');
91
+ el.textContent = src + '\n//# sourceURL=' + base + '/' + list[i];
92
+ document.body.appendChild(el);
93
+ });
94
+ });
95
+ }
96
+
97
+ /* ---------------------------------------------------------------------------
98
+ Hot patch: update the running app without dropping the module registry.
99
+
100
+ Metro's __d is first-registration-wins and __r.getModules is undefined in this bundle, so a
101
+ module cannot be replaced once registered -- which is why the restart path below exists. But
102
+ __r(id) still hands back the LIVE exports object, and a class's identity for React lives in the
103
+ class object, not in its methods. So: execute the new chunk in a sandbox whose __d only records
104
+ factories, run the factory ourselves against the real __r (it resolves live dependencies), then
105
+ copy the new prototype onto the live class. React keeps reconciling by the same type and
106
+ updates in place instead of remounting, and the 4.9MB vendor chunk is never re-executed.
107
+
108
+ It is deliberately conservative. Every module and every export must be provably patchable
109
+ BEFORE anything is mutated; otherwise it returns false and the caller does a normal restart.
110
+ --------------------------------------------------------------------------- */
111
+
112
+ var FN_RESERVED = ['length', 'name', 'prototype', 'arguments', 'caller'];
113
+
114
+ /* The modified chunk carries every module edited since the last full build, not just the ones
115
+ this build touched, so the factory source of each is kept to tell them apart. Warmed at startup
116
+ from the chunk already on the page, which is by definition the version currently running. */
117
+ var factorySrc = Object.create(null);
118
+ var haveBaseline = false;
119
+
120
+ function sandboxExecute(src) {
121
+ var captured = Object.create(null);
122
+ var define = function (factory, id, deps) { captured[id] = { factory: factory, deps: deps }; };
123
+ /* The real __r is passed through so the factory resolves live dependencies, but __d and __c are
124
+ stubbed -- the running registry must not be touched while we are only inspecting. */
125
+ new Function('__d', '__r', '__c', src)(define, g.__r, function () {});
126
+ return captured;
127
+ }
128
+
129
+ /* Only a React class needs its prototype patched -- React reconciles by the class object, so the
130
+ object must survive and only its methods may change. Everything else is better replaced
131
+ outright: Babel compiles `import x from m` to a live `_m.default` read against this same
132
+ exports object (verified in the running app), so assigning over it takes effect at the next
133
+ call. Prototype-patching a non-class would copy an empty prototype and silently leave the old
134
+ body running -- which is exactly what a page script export looks like. */
135
+ function isReactClass(v) {
136
+ return typeof v === 'function' && !!v.prototype && !!v.prototype.isReactComponent;
137
+ }
138
+
139
+ function classify(liveVal, newVal) {
140
+ if (isReactClass(newVal)) { return isReactClass(liveVal) ? 'class' : null; }
141
+ if (isReactClass(liveVal)) { return null; }
142
+ if (newVal && liveVal && typeof newVal === 'object' && typeof liveVal === 'object'
143
+ && Array.isArray(newVal) === Array.isArray(liveVal)) {
144
+ return 'obj';
145
+ }
146
+ if (typeof newVal === typeof liveVal || liveVal === undefined) { return 'ref'; }
147
+ return null;
148
+ }
149
+
150
+ function patchFunction(liveFn, newFn) {
151
+ var fresh = Object.getOwnPropertyNames(newFn.prototype);
152
+ fresh.forEach(function (k) {
153
+ if (k === 'constructor') { return; }
154
+ Object.defineProperty(liveFn.prototype, k, Object.getOwnPropertyDescriptor(newFn.prototype, k));
155
+ });
156
+ /* A method the edit deleted must go, or the old implementation keeps running. */
157
+ Object.getOwnPropertyNames(liveFn.prototype).forEach(function (k) {
158
+ if (k !== 'constructor' && fresh.indexOf(k) === -1) {
159
+ try { delete liveFn.prototype[k]; } catch (e) {}
160
+ }
161
+ });
162
+ /* Statics carry defaultProps / propTypes / contextType, which affect rendering. */
163
+ Object.getOwnPropertyNames(newFn).forEach(function (k) {
164
+ if (FN_RESERVED.indexOf(k) !== -1) { return; }
165
+ var d = Object.getOwnPropertyDescriptor(newFn, k);
166
+ try { Object.defineProperty(liveFn, k, d); } catch (e) {}
167
+ });
168
+ }
169
+
170
+ /* Styles and config objects are captured by reference at module scope, so they have to be updated
171
+ in place -- replacing the binding would leave every existing consumer on the old object. */
172
+ function patchObject(liveObj, newObj) {
173
+ Object.getOwnPropertyNames(liveObj).forEach(function (k) {
174
+ if (!Object.prototype.hasOwnProperty.call(newObj, k)) {
175
+ try { delete liveObj[k]; } catch (e) {}
176
+ }
177
+ });
178
+ Object.getOwnPropertyNames(newObj).forEach(function (k) {
179
+ try { Object.defineProperty(liveObj, k, Object.getOwnPropertyDescriptor(newObj, k)); } catch (e) {}
180
+ });
181
+ }
182
+
183
+ function decline(reason) {
184
+ log('hot patch declined:', reason);
185
+ return false;
186
+ }
187
+
188
+ function hotPatch(file) {
189
+ if (cfg.hotPatch === false) { return Promise.resolve(false); }
190
+ if (typeof g.__r !== 'function') { return Promise.resolve(decline('no __r')); }
191
+
192
+ var appConfig = g.wm && g.wm.App && g.wm.App.appConfig;
193
+ if (!appConfig || typeof appConfig.refresh !== 'function') {
194
+ return Promise.resolve(decline('no appConfig.refresh'));
195
+ }
196
+
197
+ return fetchChunk(file).then(function (src) {
198
+ var captured;
199
+ try { captured = sandboxExecute(src); }
200
+ catch (e) { return decline('sandbox threw: ' + (e && e.message)); }
201
+
202
+ var allIds = Object.keys(captured);
203
+ if (!allIds.length) { return decline('chunk registered no modules'); }
204
+
205
+ /* Without a baseline every module looks new, and re-running factories we have no evidence
206
+ changed is exactly how a stale body slips through. Restart instead. */
207
+ if (!haveBaseline) { return decline('no baseline to diff against yet'); }
208
+
209
+ var ids = allIds.filter(function (id) { return String(captured[id].factory) !== factorySrc[id]; });
210
+ if (!ids.length) { return decline('chunk is new but no module body changed'); }
211
+
212
+ /* Plan first, mutate second: a module we cannot patch must leave the app untouched so the
213
+ restart fallback starts from a clean state. */
214
+ var plan = [];
215
+ for (var i = 0; i < ids.length; i++) {
216
+ var id = ids[i];
217
+ var live;
218
+ /* __r executes the module if it has not run yet. That is wanted -- an unexecuted module
219
+ would otherwise come up stale later -- but it can throw, which means bail. */
220
+ try { live = g.__r(Number(id)); }
221
+ catch (e) { return decline('module ' + id + ' would not load: ' + (e && e.message)); }
222
+ if (!live || typeof live !== 'object') { return decline('module ' + id + ' has no object exports'); }
223
+
224
+ var mod = { exports: {} };
225
+ try {
226
+ captured[id].factory(g, g.__r, g.__r.importDefault, g.__r.importAll,
227
+ mod, mod.exports, captured[id].deps);
228
+ } catch (e) { return decline('new factory threw for module ' + id + ': ' + (e && e.message)); }
229
+
230
+ var keys = Object.keys(mod.exports);
231
+ for (var j = 0; j < keys.length; j++) {
232
+ var k = keys[j];
233
+ var kind = classify(live[k], mod.exports[k]);
234
+ if (!kind) { return decline('export "' + k + '" of module ' + id + ' is not patchable'); }
235
+ /* A class is re-read on every render and an object is read through the same live
236
+ reference, so both take effect immediately. A bare function is different: the page
237
+ script and variables factories are invoked once during page init, and the page instance
238
+ survives a hot patch, so swapping the reference would never re-run them and the edit
239
+ would silently not apply. That has to restart. */
240
+ if (kind === 'ref') {
241
+ return decline('module ' + id + ' exports a factory that only runs at page init');
242
+ }
243
+ plan.push({ kind: kind, exports: live, key: k, live: live[k], fresh: mod.exports[k] });
244
+ }
245
+ for (var n = 0, lk = Object.keys(live); n < lk.length; n++) {
246
+ if (keys.indexOf(lk[n]) === -1) {
247
+ return decline('export "' + lk[n] + '" of module ' + id + ' was removed');
248
+ }
249
+ }
250
+ }
251
+
252
+ var counts = { class: 0, obj: 0 };
253
+ plan.forEach(function (p) {
254
+ if (p.kind === 'class') { patchFunction(p.live, p.fresh); } else { patchObject(p.live, p.fresh); }
255
+ counts[p.kind]++;
256
+ });
257
+
258
+ /* Record what is now running, including the modules this build left alone, so the next diff
259
+ is against the truth rather than against the last thing we happened to patch. */
260
+ allIds.forEach(function (id) { factorySrc[id] = String(captured[id].factory); });
261
+
262
+ /* refresh() is forceUpdate on the app + common partial + current page, then watcher.check().
263
+ Passing true would call reload(), which is the remount we are trying to avoid. */
264
+ appConfig.refresh();
265
+ log('hot patched ' + ids.length + ' changed module(s) of ' + allIds.length + ': '
266
+ + counts.class + ' class, ' + counts.obj + ' object');
267
+ return true;
268
+ }).catch(function (e) {
269
+ return decline('unexpected: ' + (e && e.message));
270
+ });
271
+ }
272
+
273
+ /* A preview stub that asked Studio to build its page stored the name; the restart that delivers the
274
+ page boots at the home page, so go back to it once the app has a current page. */
275
+ function reopenRequestedPage() {
276
+ var page;
277
+ try {
278
+ page = sessionStorage.getItem('wm-preview-open-page');
279
+ sessionStorage.removeItem('wm-preview-open-page');
280
+ } catch (e) { return; }
281
+ if (!page) { return; }
282
+ var tries = 0;
283
+ var timer = setInterval(function () {
284
+ var current = g.wm && g.wm.App && g.wm.App.appConfig && g.wm.App.appConfig.currentPage;
285
+ if (current || ++tries > 50) {
286
+ clearInterval(timer);
287
+ if (current && current.pageName !== page) { current.goToPage(page); }
288
+ }
289
+ }, 200);
290
+ }
291
+
292
+ /* __c() drops every module, including the page classes cached behind bundle-splitter. */
293
+ function restart(list) {
294
+ var root = document.getElementById('root');
295
+ if (!root || typeof g.__c !== 'function') {
296
+ log('cannot restart in place, reloading');
297
+ location.reload();
298
+ return Promise.resolve();
299
+ }
300
+
301
+ root.innerHTML = '';
302
+ Object.keys(root).forEach(function (k) {
303
+ if (k.indexOf('__react') === 0) { try { delete root[k]; } catch (e) {} }
304
+ });
305
+
306
+ g.__c();
307
+
308
+ [].slice.call(document.querySelectorAll('script[src]')).forEach(function (s) {
309
+ s.parentNode && s.parentNode.removeChild(s);
310
+ });
311
+
312
+ return loadInOrder(list).then(function () {
313
+ reopenRequestedPage();
314
+ /* The restart booted a different modified chunk, so the old baseline now describes code that
315
+ is no longer running -- re-take it or the next edit diffs against the wrong version. */
316
+ var mod = list.filter(function (c) { return MODIFIED_RE.test(c); })[0];
317
+ if (!mod || sourceCache[mod] === undefined) { return; }
318
+ try {
319
+ var captured = sandboxExecute(sourceCache[mod]);
320
+ factorySrc = Object.create(null);
321
+ Object.keys(captured).forEach(function (id) { factorySrc[id] = String(captured[id].factory); });
322
+ haveBaseline = true;
323
+ } catch (e) { haveBaseline = false; }
324
+ });
325
+ }
326
+
327
+ /* Checks index.html once. Runs only when asked: the build watch below calls kick() while a build is
328
+ running, and once more when it ends. A kick during a check runs one more check after it. */
329
+ var polling = false;
330
+ var kickQueued = false;
331
+ function kick() {
332
+ if (polling) { kickQueued = true; return; }
333
+ poll();
334
+ }
335
+
336
+ function poll() {
337
+ polling = true;
338
+ var headers = etag ? { 'If-None-Match': etag } : {};
339
+ fetch(base + '/index.html', { credentials: 'same-origin', headers: headers })
340
+ .then(function (res) {
341
+ if (res.status === 304) { return null; }
342
+ /* Not consumed while a change is being applied: taking its ETag here would make every later
343
+ poll a 304, so a build that lands mid-apply would never reach the page. */
344
+ if (applying) { return null; }
345
+ var tag = res.headers.get('ETag');
346
+ if (tag) { etag = tag; }
347
+ return res.ok ? res.text() : null;
348
+ })
349
+ .then(function (html) {
350
+ if (!html || applying) { return; }
351
+ var list = chunksOf(html);
352
+ if (!list.length) { return; }
353
+ if (!current) { current = list; return; }
354
+
355
+ var changed = list.filter(function (c) { return current.indexOf(c) === -1; });
356
+ if (!changed.length) { current = list; return; }
357
+
358
+ /* A fast-path build changes exactly one chunk -- the modified overlay -- and leaves the rest
359
+ byte-identical. Any other shape (full rebuild, new vendor set) can move module ids, so
360
+ patching against the running registry would be unsound. */
361
+ var stable = function (l) { return l.filter(function (c) { return !MODIFIED_RE.test(c); }).join(); };
362
+ var patchable = changed.length === 1 && MODIFIED_RE.test(changed[0])
363
+ && stable(current) === stable(list);
364
+
365
+ applying = true;
366
+ log('changed:', changed.join(', '));
367
+ current = list;
368
+
369
+ var apply = patchable
370
+ ? hotPatch(changed[0]).then(function (ok) {
371
+ pruneCache(list);
372
+ if (ok) { return; }
373
+ log('falling back to restart');
374
+ return restart(list);
375
+ })
376
+ : restart(list);
377
+
378
+ return apply
379
+ .then(function () { log('applied without refresh'); })
380
+ .catch(function (e) { log('apply failed, reloading:', e && e.message); location.reload(); })
381
+ .then(function () { applying = false; });
382
+ })
383
+ .catch(function (e) { log('poll error', e && e.message); })
384
+ .then(function () {
385
+ polling = false;
386
+ if (kickQueued) { kickQueued = false; kick(); }
387
+ });
388
+ }
389
+
390
+ // One-line build result from build-status.json. A failed build leaves this page running, so this is
391
+ // the only place the failure shows. Durations use the server's clock only.
392
+ var lastStatus = null;
393
+ var hideTimer = null;
394
+ function toast(text, ok) {
395
+ try {
396
+ var el = document.getElementById('wm-build-toast');
397
+ if (!el) {
398
+ el = document.createElement('div');
399
+ el.id = 'wm-build-toast';
400
+ el.style.cssText = 'position:fixed;left:50%;bottom:16px;transform:translateX(-50%);z-index:2147483647;'
401
+ + 'display:flex;align-items:center;gap:8px;padding:8px 14px;border-radius:4px;background:#323232;'
402
+ + 'color:#fff;font:13px/1.4 Roboto,"Helvetica Neue",Arial,sans-serif;max-width:90%;'
403
+ + 'box-shadow:0 3px 10px rgba(0,0,0,.25);pointer-events:none';
404
+ el.innerHTML = '<span style="font-family:FontAwesome;font-size:15px"></span><span></span>';
405
+ document.body.appendChild(el);
406
+ }
407
+ // FontAwesome check-circle / times-circle, the icon font the runtime already loads.
408
+ el.firstChild.textContent = ok ? '\uf058' : '\uf057';
409
+ el.firstChild.style.color = ok ? '#4caf50' : '#f44336';
410
+ el.lastChild.textContent = text;
411
+ el.style.display = 'flex';
412
+ clearTimeout(hideTimer);
413
+ if (ok) { hideTimer = setTimeout(function () { el.style.display = 'none'; }, 6000); }
414
+ } catch (e) {}
415
+ }
416
+ /* While the tab is open (visible, including a Studio iframe or a split view), build-status.json is read every
417
+ INTERVAL. A finished build (new endedAt) is shown once and triggers one index check, which applies it.
418
+ A hidden tab stops reading, and returning to it reads right away. */
419
+ function showStatus(s) {
420
+ var secs = ((s.endedAt - s.startedAt) / 1000).toFixed(1);
421
+ var msg = s.ok ? 'Build finished · took ' + secs + 's' : 'Preview build failed after ' + secs + 's' + (s.error ? ': ' + s.error : '');
422
+ log(msg);
423
+ toast(msg, s.ok);
424
+ }
425
+ function readStatus(cb) {
426
+ fetch(base + '/build-status.json?ts=' + Date.now(), { credentials: 'same-origin' })
427
+ .then(function (res) { return res.ok ? res.json() : null; })
428
+ .catch(function () { return null; })
429
+ .then(cb);
430
+ }
431
+ /* After IDLE_AFTER ms with no build running or finishing, status reads slow to IDLE_INTERVAL until a
432
+ build shows up or the tab is shown again. */
433
+ var IDLE_AFTER = cfg.idleAfterMs || 120000;
434
+ var IDLE_INTERVAL = Math.max(INTERVAL, cfg.idleIntervalMs || 5000);
435
+ var lastActivityAt = Date.now();
436
+ function active() { lastActivityAt = Date.now(); }
437
+ function pace(ms) { return Date.now() - lastActivityAt > IDLE_AFTER ? Math.max(ms, IDLE_INTERVAL) : ms; }
438
+ var statusTimer = null;
439
+ function scheduleStatus(ms) {
440
+ clearTimeout(statusTimer);
441
+ statusTimer = setTimeout(pollStatus, pace(ms));
442
+ }
443
+ function pollStatus() {
444
+ if (document.hidden) { return; }
445
+ readStatus(function (s) {
446
+ if (s && s.state === 'building') { active(); }
447
+ if (s && s.state === 'done' && s.endedAt) {
448
+ var key = s.startedAt + ':' + s.endedAt;
449
+ if (key !== lastStatus) {
450
+ active();
451
+ if (lastStatus !== null) { showStatus(s); }
452
+ lastStatus = key;
453
+ kick();
454
+ }
455
+ }
456
+ if (!document.hidden) { scheduleStatus(INTERVAL); }
457
+ });
458
+ }
459
+ document.addEventListener('visibilitychange', function () {
460
+ if (!document.hidden) { active(); scheduleStatus(0); }
461
+ });
462
+ scheduleStatus(0);
463
+
464
+ /* Warm the cache for the chunks already on the page, so even the first edit skips the big fetch,
465
+ and take the hot-patch baseline off the modified chunk this page actually booted with --
466
+ without it the first edit after every reload would fall back to a restart. */
467
+ setTimeout(function () {
468
+ chunksOf(document.documentElement.innerHTML).forEach(function (f) {
469
+ fetchChunk(f).then(function (src) {
470
+ if (!MODIFIED_RE.test(f) || haveBaseline) { return; }
471
+ try {
472
+ var captured = sandboxExecute(src);
473
+ Object.keys(captured).forEach(function (id) { factorySrc[id] = String(captured[id].factory); });
474
+ haveBaseline = true;
475
+ log('hot-patch baseline: ' + Object.keys(captured).length + ' module(s) from ' + f);
476
+ } catch (e) { log('hot-patch baseline unavailable:', e && e.message); }
477
+ }).catch(function () {});
478
+ });
479
+ }, 1000);
480
+
481
+ log('watching index.html every ' + INTERVAL + 'ms');
482
+ })();
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ // Single choke-point for Metro's undocumented /private/* serializer APIs — update this file first if Metro reorganises these paths.
4
+ const path = require('path');
5
+
6
+ const resolveOpts = { paths: [path.dirname(require.resolve('expo/package.json'))] };
7
+
8
+ // Handles both CJS default-export shapes; throws loudly with an actionable message if Metro moved the path.
9
+ function requireMetroPrivate(modulePath, exportName) {
10
+ const raw = require(require.resolve(modulePath, resolveOpts));
11
+ const fn = typeof raw === 'function' ? raw : raw[exportName ?? 'default'];
12
+ if (typeof fn !== 'function') {
13
+ throw new Error(
14
+ `[wm] ${modulePath} is not a function — Metro reorganised its private/ paths on this Expo stack version. ` +
15
+ 'Update the path in src/templates/project/metro/wm-metro-adapter.js.',
16
+ );
17
+ }
18
+ return fn;
19
+ }
20
+
21
+ const baseJSBundle = requireMetroPrivate('metro/private/DeltaBundler/Serializers/baseJSBundle');
22
+ const bundleToString = requireMetroPrivate('metro/private/lib/bundleToString');
23
+ const sourceMapString = requireMetroPrivate('metro/private/DeltaBundler/Serializers/sourceMapString', 'sourceMapString');
24
+
25
+ module.exports = { baseJSBundle, bundleToString, sourceMapString };
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * Passes dependency-free prebuilt files through Metro untransformed. @babel/standalone (pulled in by a
5
+ * metadata wm-form) is a 5MB single-file UMD whose Babel transform exhausts the 1GB heap on cold builds,
6
+ * before a vendor manifest exists for wm-boundary.js to stub against.
7
+ */
8
+
9
+ const fs = require('fs');
10
+ const { stubResult, wrapTransformFile, whenTransformerLoads } = require('./wm-boundary');
11
+
12
+ const PREBUILT = [/[/\\]node_modules[/\\]@babel[/\\]standalone[/\\]babel(\.min)?\.js$/];
13
+
14
+ function prebuiltResult(filePath) {
15
+ const source = fs.readFileSync(filePath);
16
+ const code = `__d(function(global,require,_$$_IMPORT_DEFAULT,_$$_IMPORT_ALL,module,exports,_dependencyMap){${source}\n});`;
17
+ const result = stubResult(filePath);
18
+ Object.assign(result.output[0].data, { code, lineCount: code.split('\n').length });
19
+ result.unstable_transformResultKey = `wm-prebuilt:${filePath}`;
20
+ result.getSource = () => source;
21
+ return result;
22
+ }
23
+
24
+ whenTransformerLoads((TransformerClass) => {
25
+ try {
26
+ wrapTransformFile(TransformerClass, '__wmPrebuilt', (filePath) =>
27
+ (typeof filePath === 'string' && PREBUILT.some((re) => re.test(filePath)) ? prebuiltResult(filePath) : undefined));
28
+ } catch (err) {
29
+ console.warn('[prebuilt] could not install:', err.message);
30
+ }
31
+ });
@@ -1,13 +1,15 @@
1
1
  const { getDefaultConfig } = require('expo/metro-config');
2
2
  const path = require('path');
3
+ const fs = require('fs');
3
4
 
4
5
  module.exports = (async () => {
5
6
  try {
6
7
  const projectRoot = __dirname;
7
- const config = getDefaultConfig(projectRoot);
8
+ let config = getDefaultConfig(projectRoot);
8
9
  config.watchFolders = [projectRoot];
9
10
  config.resolver.nodeModulesPaths = [
10
- path.resolve(projectRoot, 'node_modules')
11
+ path.resolve(projectRoot, 'node_modules'),
12
+ path.resolve(projectRoot, 'node_modules/expo/node_modules')
11
13
  ];
12
14
  config.resolver.extraNodeModules = {
13
15
  '@wavemaker/wmx-component': path.join(projectRoot, 'wmx-components', 'src')
@@ -15,6 +17,10 @@ module.exports = (async () => {
15
17
  config.resolver.watchFolders = [
16
18
  path.join(projectRoot, 'wmx-components')
17
19
  ];
20
+ // wmx-components' own devDependencies would otherwise cause a duplicate instance via hierarchical lookup.
21
+ const wmxComponentsDir = path.join(projectRoot, 'wmx-components');
22
+ config.resolver.blockList = [].concat(config.resolver.blockList || [], new RegExp(
23
+ `^${wmxComponentsDir.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[/\\\\]node_modules[/\\\\].*`));
18
24
  config.transformer = {
19
25
  ...config.transformer,
20
26
  minifierPath: 'metro-minify-terser',
@@ -31,6 +37,11 @@ module.exports = (async () => {
31
37
  }
32
38
  })
33
39
  }
40
+ const customMetroConfigPath = path.join(projectRoot, 'custommetro.config.js');
41
+ if (fs.existsSync(customMetroConfigPath)) {
42
+ const customizeMetroConfig = require(customMetroConfigPath);
43
+ config = (await customizeMetroConfig(config)) || config;
44
+ }
34
45
  return config;
35
46
  }
36
47
  catch (e) {