@wavemaker/rn-codegen 11.16.0-rc.647821 → 11.16.1-rc.647845

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 (142) hide show
  1. package/command.js +111 -269
  2. package/command.js.map +1 -1
  3. package/index.js +1 -1
  4. package/index.js.map +1 -1
  5. package/npm-shrinkwrap.json +4840 -3624
  6. package/package-lock.json +4840 -3624
  7. package/package.json +62 -42
  8. package/src/app.generator.js +249 -87
  9. package/src/app.generator.js.map +1 -1
  10. package/src/fomatter.js.map +1 -1
  11. package/src/handlebar-helpers.js.map +1 -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 +152 -0
  16. package/src/pipeline/build-pipeline.js.map +1 -0
  17. package/src/pipeline/generation-store.js +288 -0
  18. package/src/pipeline/generation-store.js.map +1 -0
  19. package/src/pipeline/shared-node-modules.js +775 -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 +17 -7
  28. package/src/project.service.js.map +1 -1
  29. package/src/templates/babel.config.js.template +0 -1
  30. package/src/templates/bootstrap.template +3 -1
  31. package/src/templates/device-plugin-service.template +7 -9
  32. package/src/templates/package.web.json +108 -83
  33. package/src/templates/page-stub.template +27 -0
  34. package/src/templates/project/app.json +4 -11
  35. package/src/templates/project/esbuild/esbuild.script.js +129 -89
  36. package/src/templates/project/metro/container-limits.js +195 -0
  37. package/src/templates/project/metro/metro.script.js +833 -0
  38. package/src/templates/project/metro/module-path.js +237 -0
  39. package/src/templates/project/metro/split.serializer.js +184 -0
  40. package/src/templates/project/metro/split.static.js +633 -0
  41. package/src/templates/project/metro/stable-module-ids.js +54 -0
  42. package/src/templates/project/metro/vendor-cache.js +475 -0
  43. package/src/templates/project/metro/wm-boundary.js +138 -0
  44. package/src/templates/project/metro/wm-crawl-override.js +147 -0
  45. package/src/templates/project/metro/wm-fastbuild.js +196 -0
  46. package/src/templates/project/metro/wm-live-reload.js +482 -0
  47. package/src/templates/project/metro/wm-metro-adapter.js +25 -0
  48. package/src/templates/project/metro.config.js +209 -8
  49. package/src/templates/project/package.json +106 -83
  50. package/src/templates/project/patch-utils.js +331 -0
  51. package/src/templates/project/scripts/post-build.js +3 -0
  52. package/src/theme/app-override-css.generator.js +10 -4
  53. package/src/theme/app-override-css.generator.js.map +1 -1
  54. package/src/theme/components/basic/base.styledef.js.map +1 -1
  55. package/src/theme/components/style-definition.provider.js.map +1 -1
  56. package/src/theme/font-stylesheet.transpiler.js +17 -7
  57. package/src/theme/font-stylesheet.transpiler.js.map +1 -1
  58. package/src/theme/rn-stylesheet.transpiler.js +17 -7
  59. package/src/theme/rn-stylesheet.transpiler.js.map +1 -1
  60. package/src/theme/theme.service.js +7 -19
  61. package/src/theme/theme.service.js.map +1 -1
  62. package/src/theme/token.transpiler.js +17 -7
  63. package/src/theme/token.transpiler.js.map +1 -1
  64. package/src/transpile/bind.ex.transformer.js +36 -23
  65. package/src/transpile/bind.ex.transformer.js.map +1 -1
  66. package/src/transpile/components/advanced/carousel.transformer.js.map +1 -1
  67. package/src/transpile/components/advanced/customwidget.transformer.js.map +1 -1
  68. package/src/transpile/components/advanced/login.transformer.js.map +1 -1
  69. package/src/transpile/components/advanced/webview.transformer.js.map +1 -1
  70. package/src/transpile/components/basic/buttongroup.transformer.js.map +1 -1
  71. package/src/transpile/components/basic/custom.transformer.js.map +1 -1
  72. package/src/transpile/components/basic/picture.transformer.js.map +1 -1
  73. package/src/transpile/components/basic/progress-bar.transformer.js.map +1 -1
  74. package/src/transpile/components/basic/search.transformer.js.map +1 -1
  75. package/src/transpile/components/chart/area-chart.transformer.js.map +1 -1
  76. package/src/transpile/components/container/accordion/accordionpane.transformer.js.map +1 -1
  77. package/src/transpile/components/container/accordion.transformer.js.map +1 -1
  78. package/src/transpile/components/container/container.transformer.js.map +1 -1
  79. package/src/transpile/components/container/layoutgrid/gridcolumn.transformer.js.map +1 -1
  80. package/src/transpile/components/container/layoutgrid/gridrow.transformer.js.map +1 -1
  81. package/src/transpile/components/container/layoutgrid.transformer.js.map +1 -1
  82. package/src/transpile/components/container/linearlayout.transformer.js.map +1 -1
  83. package/src/transpile/components/container/panel.transformer.js.map +1 -1
  84. package/src/transpile/components/container/tabs/tabpane.transformer.js.map +1 -1
  85. package/src/transpile/components/container/tabs.transformer.js.map +1 -1
  86. package/src/transpile/components/container/wizard/wizardstep.transformer.js.map +1 -1
  87. package/src/transpile/components/container/wizard.transformer.js.map +1 -1
  88. package/src/transpile/components/data/card/card-content.transformer.js.map +1 -1
  89. package/src/transpile/components/data/form/form-action.transformer.js.map +1 -1
  90. package/src/transpile/components/data/form/form-field.transformer.js.map +1 -1
  91. package/src/transpile/components/data/form.transformer.js.map +1 -1
  92. package/src/transpile/components/data/list.transformer.js +17 -7
  93. package/src/transpile/components/data/list.transformer.js.map +1 -1
  94. package/src/transpile/components/data/liveform.transformer.js.map +1 -1
  95. package/src/transpile/components/dialogs/dialog.transformer.js.map +1 -1
  96. package/src/transpile/components/input/checkboxset.transformer.js.map +1 -1
  97. package/src/transpile/components/input/chips.transformer.js.map +1 -1
  98. package/src/transpile/components/input/epoch/date.transformer.js.map +1 -1
  99. package/src/transpile/components/input/epoch/datetime.transformer.js.map +1 -1
  100. package/src/transpile/components/input/epoch/time.transformer.js.map +1 -1
  101. package/src/transpile/components/input/radioset.transformer.js.map +1 -1
  102. package/src/transpile/components/input/rating.transformer.js.map +1 -1
  103. package/src/transpile/components/input/select.transformer.js.map +1 -1
  104. package/src/transpile/components/input/slider.transformer.js.map +1 -1
  105. package/src/transpile/components/input/switch.transformer.js.map +1 -1
  106. package/src/transpile/components/input/textarea.transformer.js.map +1 -1
  107. package/src/transpile/components/input/toggle.transformer.js.map +1 -1
  108. package/src/transpile/components/navigation/appnavbar.transformer.js.map +1 -1
  109. package/src/transpile/components/navigation/menu.transformer.js.map +1 -1
  110. package/src/transpile/components/navigation/navbar.transformer.js.map +1 -1
  111. package/src/transpile/components/navigation/navitem.transformer.js.map +1 -1
  112. package/src/transpile/components/navigation/popover.transformer.js.map +1 -1
  113. package/src/transpile/components/page/left-panel.transformer.js.map +1 -1
  114. package/src/transpile/components/page/page.transformer.js.map +1 -1
  115. package/src/transpile/components/page/partial-container.transformer.js +17 -7
  116. package/src/transpile/components/page/partial-container.transformer.js.map +1 -1
  117. package/src/transpile/components/prefab/prefab.transformer.js.map +1 -1
  118. package/src/transpile/components/utils.js.map +1 -1
  119. package/src/transpile/property/property-parser.js.map +1 -1
  120. package/src/transpile/property/show-in-device.parser.js.map +1 -1
  121. package/src/transpile/style/background-image.parser.js.map +1 -1
  122. package/src/transpile/style/dimension-style.parser.js.map +1 -1
  123. package/src/transpile/style/multi-dimension-style.parser.js.map +1 -1
  124. package/src/transpile/style/numeric-style.parser.js.map +1 -1
  125. package/src/transpile/style.transformer.js.map +1 -1
  126. package/src/transpile/transpile.js +17 -7
  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/variables/variable.transformer.js.map +1 -1
  131. package/src/wm-namespace.js +14 -0
  132. package/src/wm-namespace.js.map +1 -0
  133. package/test/pipeline/live-reload-pacing.test.js +76 -0
  134. package/test/pipeline/live-reload-pacing.test.js.map +1 -0
  135. package/test/pipeline/npm-install-retry.test.js +57 -0
  136. package/test/pipeline/npm-install-retry.test.js.map +1 -0
  137. package/test/pipeline/repair-vendor-packages.test.js +134 -0
  138. package/test/pipeline/repair-vendor-packages.test.js.map +1 -0
  139. package/test/pipeline/web-preview-files.test.js +48 -0
  140. package/test/pipeline/web-preview-files.test.js.map +1 -0
  141. package/web-preview.js +165 -0
  142. package/web-preview.js.map +1 -0
@@ -0,0 +1,475 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs-extra');
4
+ const path = require('path');
5
+ const crypto = require('crypto');
6
+ const cacache = require('cacache');
7
+ const { topLevelPackageName, normalizeKey, normalizeWmxKey, IS_NODE_MODULE, IS_WMX_MODULE, withLock } = require('./module-path');
8
+
9
+ // Hashes the split-bundle source files so any logic change auto-invalidates stale caches.
10
+ const MODULE_ID_SCHEME_VERSION = (() => {
11
+ try {
12
+ const h = crypto.createHash('md5');
13
+ /* Every file here can change what a chunk CONTAINS, so a change to any of them must invalidate
14
+ cached chunks. wm-boundary.js and wm-crawl-override.js decide which modules reach the graph at
15
+ all, and wm-fastbuild.js emits chunk bytes directly — leaving them out let chunks built under
16
+ different rules share one cache key. wm-live-reload.js is deliberately absent: it is a client
17
+ script injected into index.html and never affects chunk contents, so including it would bust
18
+ every cache for a cosmetic edit. */
19
+ for (const f of ['vendor-cache.js', 'split.serializer.js', 'stable-module-ids.js', 'split.static.js', 'module-path.js', 'wm-metro-adapter.js', 'wm-boundary.js', 'wm-crawl-override.js', 'wm-fastbuild.js']) {
20
+ const p = path.join(__dirname, f);
21
+ if (fs.existsSync(p)) {
22
+ h.update(f);
23
+ h.update(fs.readFileSync(p));
24
+ }
25
+ }
26
+ return h.digest('hex').slice(0, 12);
27
+ } catch {
28
+ return 'scheme-fallback';
29
+ }
30
+ })();
31
+
32
+ const PROJECT_ROOT = path.resolve(__dirname, '..');
33
+
34
+ // command.ts writes <projectRoot>/.wm-vendor-base.json from the rnApp's package-lock.json — the vendor package set + a content hash, shareable across every project on the same rnApp version.
35
+ const BASE_MANIFEST_FILE = '.wm-vendor-base.json';
36
+ let _baseManifest;
37
+
38
+ function loadBaseManifest(projectRoot = PROJECT_ROOT) {
39
+ if (_baseManifest && _baseManifest.projectRoot === projectRoot) {
40
+ return _baseManifest.value;
41
+ }
42
+ let value = null;
43
+ try {
44
+ const p = path.join(projectRoot, BASE_MANIFEST_FILE);
45
+ if (fs.existsSync(p)) {
46
+ const json = fs.readJSONSync(p);
47
+ if (Array.isArray(json.packages) && json.packages.length) {
48
+ value = { packages: new Set(json.packages), hash: json.hash || '' };
49
+ }
50
+ }
51
+ } catch {
52
+ value = null;
53
+ }
54
+ _baseManifest = { projectRoot, value };
55
+ return value;
56
+ }
57
+
58
+ // Without a manifest the build falls back to exact mode (vendor = every node_module).
59
+ function baseModeEnabled(projectRoot = PROJECT_ROOT) {
60
+ return loadBaseManifest(projectRoot) != null;
61
+ }
62
+
63
+ function extrasSplitEnabled() {
64
+ return baseModeEnabled();
65
+ }
66
+
67
+ function isVendorPkgName(name) {
68
+ const base = loadBaseManifest();
69
+ return base != null && base.packages.has(name);
70
+ }
71
+
72
+ function isBaselineModule(filePath) {
73
+ if (isWmxModule(filePath)) return false;
74
+ const name = topLevelPackageName(filePath);
75
+ return name != null && isVendorPkgName(name);
76
+ }
77
+
78
+ function isWmxModule(filePath) {
79
+ return IS_WMX_MODULE.test(filePath);
80
+ }
81
+
82
+ function isExtraModule(filePath) {
83
+ return IS_NODE_MODULE.test(filePath) && baseModeEnabled() && !isBaselineModule(filePath) && !isWmxModule(filePath);
84
+ }
85
+
86
+ function isProjectSourceModule(filePath) {
87
+ return !IS_NODE_MODULE.test(filePath) && !isWmxModule(filePath);
88
+ }
89
+
90
+ // A module Metro synthesises rather than reads from disk (e.g. '\0shim:react-native-web/...').
91
+ function isVirtualModule(filePath) {
92
+ if (filePath.charCodeAt(0) === 0) return true;
93
+ try { return !fs.existsSync(filePath); } catch { return true; }
94
+ }
95
+
96
+ // The packages that SEED the vendor chunk: the rn-app baseline (or every node_module when baseline
97
+ // mode is off).
98
+ function isVendorSeed(filePath) {
99
+ return IS_NODE_MODULE.test(filePath) && !isWmxModule(filePath)
100
+ && (!baseModeEnabled() || isBaselineModule(filePath));
101
+ }
102
+
103
+ // Library code rather than the project's own: node_modules (except wmx components) plus Metro's
104
+ // virtual modules ('\0shim:react-native-web/...'), which are not under node_modules.
105
+ function isLibraryModule(filePath) {
106
+ return IS_NODE_MODULE.test(filePath) ? !isWmxModule(filePath) : isVirtualModule(filePath);
107
+ }
108
+
109
+ // Chunks form strict layers, decided from the dependency graph rather than from package names:
110
+ // vendor -> vendor only (shared across projects, so it may know nothing else)
111
+ // extras -> vendor + extras (this project's extra packages)
112
+ // user -> anything
113
+ // Deciding by package name alone broke both rules — measured on a real preview: vendor had 71 edges
114
+ // into extras (baseline packages importing packages outside the base manifest) and 13 into user (the
115
+ // react-native-web shims). A cached chunk requiring an id that lives in a later layer is how
116
+ // "Requiring unknown module" is thrown.
117
+ // 1. A library module that transitively reaches project code or wmx cannot sit in vendor or extras
118
+ // without breaking the rule, so it (and every library module depending on it) goes to user.
119
+ // 2. vendor = closure of the baseline seed over the remaining library modules. Closed by
120
+ // construction: a dependency of an untainted module is itself untainted library code.
121
+ // 3. extras = every other untainted library module; its dependencies are in vendor or extras.
122
+ // With the extras split off, (3) lands in user, which is still a valid layering.
123
+ function computeChunkLayers(graph) {
124
+ const dependents = new Map();
125
+ const queue = [];
126
+ for (const m of graph.dependencies.values()) {
127
+ for (const d of m.dependencies.values()) {
128
+ const p = d.absolutePath;
129
+ if (!p || !graph.dependencies.has(p)) continue;
130
+ if (!dependents.has(p)) dependents.set(p, []);
131
+ dependents.get(p).push(m.path);
132
+ }
133
+ if (!isLibraryModule(m.path)) queue.push(m.path);
134
+ }
135
+ const tainted = new Set();
136
+ while (queue.length) {
137
+ for (const parent of dependents.get(queue.pop()) || []) {
138
+ if (tainted.has(parent) || !isLibraryModule(parent)) continue;
139
+ tainted.add(parent);
140
+ queue.push(parent);
141
+ }
142
+ }
143
+
144
+ const vendor = new Set();
145
+ for (const m of graph.dependencies.values()) {
146
+ if (isVendorSeed(m.path) && !tainted.has(m.path)) { vendor.add(m.path); queue.push(m); }
147
+ }
148
+ while (queue.length) {
149
+ for (const d of queue.pop().dependencies.values()) {
150
+ const p = d.absolutePath;
151
+ if (!p || vendor.has(p) || tainted.has(p) || !isLibraryModule(p)) continue;
152
+ const target = graph.dependencies.get(p);
153
+ if (!target) continue;
154
+ vendor.add(p);
155
+ queue.push(target);
156
+ }
157
+ }
158
+
159
+ const extras = new Set();
160
+ if (extrasSplitEnabled()) {
161
+ for (const m of graph.dependencies.values()) {
162
+ if (isLibraryModule(m.path) && !vendor.has(m.path) && !tainted.has(m.path)) extras.add(m.path);
163
+ }
164
+ }
165
+ return { vendor, extras, tainted };
166
+ }
167
+
168
+ function computeReachableSetHash(modulePaths, isMember) {
169
+ const keys = [];
170
+ for (const p of modulePaths) {
171
+ if (isMember(p)) keys.push(normalizeKey(p));
172
+ }
173
+ if (!keys.length) return '';
174
+ keys.sort();
175
+ return crypto.createHash('md5').update(keys.join('\n')).digest('hex');
176
+ }
177
+
178
+ function computeVendorSetHash(modulePaths) {
179
+ return computeReachableSetHash(modulePaths, isBaselineModule);
180
+ }
181
+
182
+ function computeExtrasSetHash(modulePaths) {
183
+ return computeReachableSetHash(modulePaths, isExtraModule);
184
+ }
185
+
186
+ function computeWmxContentHash(modulePaths) {
187
+ const keys = [];
188
+ for (const p of modulePaths) {
189
+ if (!isWmxModule(p)) continue;
190
+ let content;
191
+ try {
192
+ content = fs.readFileSync(p);
193
+ } catch {
194
+ continue;
195
+ }
196
+ keys.push(`${normalizeWmxKey(p)}:${crypto.createHash('md5').update(content).digest('hex')}`);
197
+ }
198
+ if (!keys.length) return '';
199
+ keys.sort();
200
+ return crypto.createHash('md5').update(keys.join('\n')).digest('hex');
201
+ }
202
+
203
+ function servedBundleDir() {
204
+ const webappRoot = process.env.WM_PROJECT_SRC
205
+ ? path.resolve(process.env.WM_PROJECT_SRC)
206
+ : path.resolve(PROJECT_ROOT, '..', 'src', 'main', 'webapp');
207
+ return path.join(webappRoot, 'rn-bundle');
208
+ }
209
+
210
+ function sharedVendorGenerationDir() {
211
+ try {
212
+ const p = path.join(PROJECT_ROOT, '.wm-vendor-generation');
213
+ if (fs.existsSync(p)) {
214
+ const dir = fs.readFileSync(p, 'utf8').trim();
215
+ if (dir) return dir;
216
+ }
217
+ } catch {
218
+ // fall through to per-project
219
+ }
220
+ return null;
221
+ }
222
+
223
+ function cacheRoot(kind = 'vendor') {
224
+ if (kind === 'vendor') {
225
+ const sharedDir = sharedVendorGenerationDir();
226
+ if (sharedDir) {
227
+ return path.join(sharedDir, '.vendor-cache');
228
+ }
229
+ }
230
+ return path.join(servedBundleDir(), `.${kind}-cache`);
231
+ }
232
+
233
+ // Hashes lock CONTENTS (not mtimes) so timestamp churn doesn't bust the cache.
234
+ function computeKey(projectRoot, platform, dev, kind = 'vendor', reachableSetHash = '') {
235
+ const h = crypto.createHash('md5');
236
+ h.update(`scheme:${MODULE_ID_SCHEME_VERSION}|platform:${platform}|dev:${dev ? 1 : 0}|kind:${kind}`);
237
+
238
+ if (reachableSetHash) {
239
+ h.update(`${kind}Set:${reachableSetHash}`);
240
+ }
241
+
242
+ const base = loadBaseManifest(projectRoot);
243
+ const files = [];
244
+ if (base) {
245
+ h.update(`baseLock:${base.hash}`);
246
+ files.push('yalc.lock');
247
+ } else {
248
+ files.push('package-lock.json', 'npm-shrinkwrap.json', 'yalc.lock');
249
+ }
250
+
251
+ for (const f of files) {
252
+ const p = path.join(projectRoot, f);
253
+ if (fs.existsSync(p)) {
254
+ h.update(f);
255
+ h.update(fs.readFileSync(p));
256
+ }
257
+ }
258
+ return h.digest('hex');
259
+ }
260
+
261
+ function readMapIfPresent(mapFile) {
262
+ try {
263
+ return fs.existsSync(mapFile) ? fs.readFileSync(mapFile, 'utf8') : null;
264
+ } catch {
265
+ return null;
266
+ }
267
+ }
268
+
269
+ // One entry kept per kind (MAX_ENTRIES was always 1), so eviction is "remove whatever the
270
+ // previous key was", tracked in this sibling marker file next to cacache's own directory.
271
+ function currentKeyFile(kind) {
272
+ return `${cacheRoot(kind)}.current-key`;
273
+ }
274
+
275
+
276
+ async function evictStaleEntry(kind, keptKey) {
277
+ const marker = currentKeyFile(kind);
278
+ let previousKey = '';
279
+ try {
280
+ previousKey = fs.readFileSync(marker, 'utf8').trim();
281
+ } catch {
282
+ // no prior entry
283
+ }
284
+ if (previousKey && previousKey !== keptKey) {
285
+ const cache = cacheRoot(kind);
286
+ try {
287
+ await cacache.rm.entry(cache, previousKey);
288
+ if (kind !== 'extras' && kind !== 'wmx') {
289
+ await cacache.rm.entry(cache, `${previousKey}:map`).catch(() => {});
290
+ }
291
+ // rm.entry only drops the index row; verify() reclaims the now-orphaned content bytes.
292
+ await cacache.verify(cache);
293
+ } catch (err) {
294
+ console.warn(`[vendor-cache] failed to evict stale ${kind} entry:`, err.message);
295
+ }
296
+ }
297
+ fs.mkdirpSync(path.dirname(marker));
298
+ fs.writeFileSync(marker, keptKey);
299
+ }
300
+
301
+ // cacache.get() throws (ENOENT) rather than returning null on a miss.
302
+ async function lookup(projectRoot, platform, dev, kind = 'vendor', vendorSetHash = '') {
303
+ const key = computeKey(projectRoot, platform, dev, kind, vendorSetHash);
304
+ const cache = cacheRoot(kind);
305
+
306
+ let entry;
307
+ try {
308
+ entry = await cacache.get(cache, key);
309
+ } catch {
310
+ return null;
311
+ }
312
+ const meta = entry.metadata || {};
313
+
314
+ if (kind === 'extras' || kind === 'wmx') {
315
+ // Extras/wmx bytes live in rn-bundle, not in the cache — this entry is metadata-only.
316
+ const servedFile = meta.filename
317
+ ? path.join(servedBundleDir(), path.basename(meta.filename))
318
+ : null;
319
+ if (!servedFile || !fs.existsSync(servedFile)) {
320
+ return null;
321
+ }
322
+ return {
323
+ key,
324
+ bundlePath: servedFile,
325
+ mapPath: null,
326
+ source: fs.readFileSync(servedFile, 'utf8'),
327
+ map: readMapIfPresent(`${servedFile}.map`),
328
+ meta,
329
+ };
330
+ }
331
+
332
+ let map = null;
333
+ let mapPath = null;
334
+ try {
335
+ const mapEntry = await cacache.get(cache, `${key}:map`);
336
+ map = mapEntry.data.toString('utf8');
337
+ mapPath = (await cacache.get.info(cache, `${key}:map`)).path;
338
+ } catch {
339
+ // no map cached — the JS is still servable without one
340
+ }
341
+
342
+ const info = await cacache.get.info(cache, key);
343
+ return {
344
+ key,
345
+ bundlePath: info.path,
346
+ mapPath,
347
+ source: entry.data.toString('utf8'),
348
+ map,
349
+ meta,
350
+ };
351
+ }
352
+
353
+ // vendor/extras' actual bytes and integrity are cacache's job now; this only tracks which
354
+ // key is current so the previous generation's entry gets evicted (see evictStaleEntry).
355
+ async function store(key, platform, source, meta, kind = 'vendor', map = null) {
356
+ const cache = cacheRoot(kind);
357
+
358
+ return withLock(cache, async () => {
359
+ if (kind === 'extras' || kind === 'wmx') {
360
+ await cacache.put(cache, key, Buffer.alloc(0), { metadata: meta });
361
+ await evictStaleEntry(kind, key);
362
+ return null;
363
+ }
364
+
365
+ await cacache.put(cache, key, Buffer.from(source, 'utf8'), { metadata: meta });
366
+ let mapPath = null;
367
+ if (map) {
368
+ await cacache.put(cache, `${key}:map`, Buffer.from(map, 'utf8'), { metadata: {} });
369
+ mapPath = (await cacache.get.info(cache, `${key}:map`)).path;
370
+ }
371
+ await evictStaleEntry(kind, key);
372
+ const info = await cacache.get.info(cache, key);
373
+ return { bundlePath: info.path, mapPath };
374
+ });
375
+ }
376
+
377
+ // 'user' is a single evolving baseline per project+platform, forced to fully refresh every WM_USER_CACHE_REFRESH_INTERVAL builds.
378
+ const USER_CACHE_REFRESH_INTERVAL = parseInt(process.env.WM_USER_CACHE_REFRESH_INTERVAL, 10) || 20;
379
+
380
+ function userCacheDir() {
381
+ return path.join(servedBundleDir(), '.user-cache');
382
+ }
383
+
384
+ function userMetaPath(platform) {
385
+ return path.join(userCacheDir(), `meta.${platform}.json`);
386
+ }
387
+
388
+ function loadUserMeta(platform) {
389
+ let meta;
390
+ try {
391
+ meta = fs.readJSONSync(userMetaPath(platform));
392
+ } catch {
393
+ return null;
394
+ }
395
+ if (meta.schemeVersion !== MODULE_ID_SCHEME_VERSION) return null;
396
+ const servedFile = meta.filename ? path.join(servedBundleDir(), path.basename(meta.filename)) : null;
397
+ if (!servedFile || !fs.existsSync(servedFile)) return null;
398
+ return meta;
399
+ }
400
+
401
+ function shouldForceFullUserRefresh(meta) {
402
+ // A baseline from before content hashes were recorded can only be judged by mtime, which a clean
403
+ // preview defeats — recapture it once rather than ship the whole app as `modified` for 20 builds.
404
+ return !meta || !meta.stableHashes || (meta.buildsSinceRefresh ?? 0) >= USER_CACHE_REFRESH_INTERVAL;
405
+ }
406
+
407
+ function readCachedUserSource(meta) {
408
+ return fs.readFileSync(path.join(servedBundleDir(), path.basename(meta.filename)), 'utf8');
409
+ }
410
+
411
+ function readCachedUserMap(meta) {
412
+ return readMapIfPresent(path.join(servedBundleDir(), `${path.basename(meta.filename)}.map`));
413
+ }
414
+
415
+ const md5File = (filePath) => crypto.createHash('md5').update(fs.readFileSync(filePath)).digest('hex');
416
+
417
+ // Stable = in stableKeys and same content as the baseline. Codegen rewrites every file on a clean preview,
418
+ // so mtime alone flagged the whole app as modified; it stays only as the cheap first check.
419
+ function isStableModule(filePath, stableKeySet, builtAt, stableHashes) {
420
+ const key = normalizeKey(filePath);
421
+ if (!stableKeySet.has(key)) return false;
422
+ try {
423
+ if (fs.statSync(filePath).mtimeMs <= builtAt) return true;
424
+ return !!stableHashes && stableHashes[key] === md5File(filePath);
425
+ } catch {
426
+ return false;
427
+ }
428
+ }
429
+
430
+ function storeUserBaseline(platform, filename, stableKeys, builtAt) {
431
+ const stableHashes = {};
432
+ for (const key of stableKeys) {
433
+ try { stableHashes[key] = md5File(key); } catch {}
434
+ }
435
+ fs.ensureDirSync(userCacheDir());
436
+ fs.writeJSONSync(userMetaPath(platform), {
437
+ filename,
438
+ schemeVersion: MODULE_ID_SCHEME_VERSION,
439
+ stableKeys,
440
+ stableHashes,
441
+ builtAt,
442
+ buildsSinceRefresh: 0,
443
+ });
444
+ }
445
+
446
+ function bumpUserBuildCount(platform, meta) {
447
+ fs.writeJSONSync(userMetaPath(platform), { ...meta, buildsSinceRefresh: (meta.buildsSinceRefresh ?? 0) + 1 });
448
+ }
449
+
450
+ module.exports = {
451
+ computeKey,
452
+ lookup,
453
+ store,
454
+ baseModeEnabled,
455
+ extrasSplitEnabled,
456
+ isBaselineModule,
457
+ isExtraModule,
458
+ isWmxModule,
459
+ isProjectSourceModule,
460
+ isVirtualModule,
461
+ isVendorSeed,
462
+ computeChunkLayers,
463
+ isLibraryModule,
464
+ computeVendorSetHash,
465
+ computeExtrasSetHash,
466
+ computeWmxContentHash,
467
+ USER_CACHE_REFRESH_INTERVAL,
468
+ loadUserMeta,
469
+ shouldForceFullUserRefresh,
470
+ readCachedUserSource,
471
+ readCachedUserMap,
472
+ isStableModule,
473
+ storeUserBaseline,
474
+ bumpUserBuildCount,
475
+ };
@@ -0,0 +1,138 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * Stops Metro's graph traversal at the node_modules boundary.
5
+ *
6
+ * User code reaches ~2650 node_modules modules, but only ~85 of them DIRECTLY — the rest are
7
+ * transitive. Those transitive modules are already in the cached vendor/extras chunks, complete with
8
+ * their own `d` arrays baked in when those chunks were built, so re-walking them every build derives
9
+ * nothing new. This preload short-circuits their transform to a stub with no dependencies, which is
10
+ * what makes Metro stop recursing: the graph collapses from 2730 modules to ~159.
11
+ *
12
+ * It ONLY stubs a module whose normalized key is already in the served vendor manifest. Anything not
13
+ * in the manifest is transformed for real and recursed into as usual, so a newly added package is
14
+ * still discovered — and split.static.js then refuses the boundary build and falls back to a full one.
15
+ *
16
+ * Loaded via NODE_OPTIONS=--require from metro.script.js. On by default; disable with WM_BOUNDARY=0.
17
+ */
18
+
19
+ const Module = require('module');
20
+ const fs = require('fs');
21
+ const path = require('path');
22
+
23
+ const STUB_CODE = '__d(function(g,r,i,a,m,e,d){});';
24
+ const EMPTY_SOURCE = Buffer.from('');
25
+
26
+ function servedBundleDir() {
27
+ const webapp = process.env.WM_PROJECT_SRC
28
+ ? path.resolve(process.env.WM_PROJECT_SRC)
29
+ : path.resolve(process.env.WM_BOUNDARY_PROJECT_ROOT || process.cwd(), '..', 'src', 'main', 'webapp');
30
+ return path.join(webapp, 'rn-bundle');
31
+ }
32
+
33
+ // The manifest is the authoritative list of what the cached vendor chunk actually contains.
34
+ function readKeys(file) {
35
+ try {
36
+ const keys = JSON.parse(fs.readFileSync(path.join(servedBundleDir(), file), 'utf8'));
37
+ return Array.isArray(keys) ? keys : [];
38
+ } catch {
39
+ return [];
40
+ }
41
+ }
42
+
43
+ // Extras hang off vendor parents, so stubbing vendor alone would make traversal never reach them and
44
+ // the extras chunk would silently vanish from the bundle. Both lists are cached chunks; treat both
45
+ // as safe to stop at.
46
+ function loadVendorManifestKeys() {
47
+ const keys = [...readKeys('vendor-manifest.json'), ...readKeys('extras-manifest.json')];
48
+ return keys.length ? new Set(keys) : null;
49
+ }
50
+
51
+ // Mirrors the real result shape exactly: dependencies, output, unstable_transformResultKey and
52
+ // getSource. Omitting getSource is what made an earlier probe die on `module.getSource is not a function`.
53
+ function stubResult(filePath) {
54
+ return {
55
+ dependencies: [],
56
+ output: [{
57
+ type: 'js/module',
58
+ data: { code: STUB_CODE, lineCount: 1, map: [], functionMap: null },
59
+ }],
60
+ unstable_transformResultKey: `wm-boundary-stub:${filePath}`,
61
+ getSource: () => EMPTY_SOURCE,
62
+ };
63
+ }
64
+
65
+ const stats = { stubbed: 0, realNodeModules: 0, project: 0 };
66
+
67
+ function install(TransformerClass, manifestKeys, normalizeKey) {
68
+ const proto = TransformerClass && TransformerClass.prototype;
69
+ if (!proto || typeof proto.transformFile !== 'function' || proto.transformFile.__wmBoundary) {
70
+ return false;
71
+ }
72
+ const original = proto.transformFile;
73
+ const patched = async function transformFile(filePath, ...rest) {
74
+ if (typeof filePath === 'string' && filePath.includes('node_modules')) {
75
+ let key = null;
76
+ try { key = normalizeKey(filePath); } catch { key = null; }
77
+ if (key && manifestKeys.has(key)) {
78
+ stats.stubbed++;
79
+ return stubResult(filePath);
80
+ }
81
+ stats.realNodeModules++;
82
+ } else {
83
+ stats.project++;
84
+ }
85
+ return original.apply(this, [filePath, ...rest]);
86
+ };
87
+ patched.__wmBoundary = true;
88
+ Object.defineProperty(proto, 'transformFile', { value: patched, writable: true, configurable: true });
89
+ return true;
90
+ }
91
+
92
+ if (process.env.WM_BOUNDARY !== '0') {
93
+ const manifestKeys = loadVendorManifestKeys();
94
+ if (!manifestKeys) {
95
+ console.log('[boundary] no served vendor manifest — running a normal full traversal');
96
+ } else {
97
+ let normalizeKey;
98
+ try {
99
+ ({ normalizeKey } = require('./module-path'));
100
+ } catch {
101
+ normalizeKey = null;
102
+ }
103
+
104
+ if (!normalizeKey) {
105
+ console.log('[boundary] could not load module-path.js — running a normal full traversal');
106
+ } else {
107
+ const originalLoad = Module._load;
108
+ Module._load = function (request, parent) {
109
+ const exported = originalLoad.apply(this, arguments);
110
+ let filename = '';
111
+ try { filename = Module._resolveFilename(request, parent) || ''; } catch {}
112
+ if (/DeltaBundler[/\\]Transformer\.js$/.test(filename)) {
113
+ try {
114
+ if (install(exported && (exported.Transformer || exported.default || exported), manifestKeys, normalizeKey)) {
115
+ /* The serializer runs in this same process and must gate its safety checks on whether
116
+ the graph is ACTUALLY truncated, not on WM_BOUNDARY. The env var only says the
117
+ optimisation is permitted; every path above this line declines it and still leaves
118
+ a complete graph, and a serializer that assumed otherwise would refuse builds that
119
+ were never truncated (and, worse, trust a full graph to be small). */
120
+ globalThis.__WM_BOUNDARY_ACTIVE__ = true;
121
+ console.log(`[boundary] traversal will stop at node_modules (${manifestKeys.size} vendor keys known)`);
122
+ }
123
+ } catch (err) {
124
+ console.warn('[boundary] could not install:', err.message);
125
+ }
126
+ }
127
+ return exported;
128
+ };
129
+
130
+ process.on('exit', () => {
131
+ console.log(`[boundary] stubbed ${stats.stubbed} vendor module(s), `
132
+ + `transformed ${stats.realNodeModules} unlisted node_modules + ${stats.project} project file(s)`);
133
+ });
134
+ }
135
+ }
136
+ }
137
+
138
+ module.exports = { stubResult, loadVendorManifestKeys };