@wavemaker/rn-codegen 11.15.5-rc.647813 → 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 (182) hide show
  1. package/command.js +94 -232
  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 +567 -548
  6. package/package-lock.json +567 -548
  7. package/package.json +14 -10
  8. package/scripts/check-deps-compat.js +579 -0
  9. package/src/app.generator.js +457 -137
  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 +12 -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/basic/icon.less +6 -4
  39. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/basic/label.less +46 -4
  40. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/container/tabs/tab-header.less +15 -3
  41. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/data/form.less +14 -0
  42. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/input/checkboxset.less +1 -0
  43. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/input/chips.less +49 -0
  44. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/input/radioset.less +1 -1
  45. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/input/select.less +29 -1
  46. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/input/switch.less +4 -4
  47. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/navigation/menu.less +1 -0
  48. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/studio/basic/icon.less +0 -3
  49. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/studio/container/tabs.less +5 -1
  50. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/studio/input/currency.less +6 -2
  51. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/studio/input/form.less +20 -5
  52. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/tokens.light.css +21 -3
  53. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/variables/button.variant.less +2 -2
  54. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/variables/chips.variant.less +5 -1
  55. package/src/templates/foundation-theme/build/ios/wavemaker/components/input/epoch/date.less +8 -1
  56. package/src/templates/foundation-theme/build/ios/wavemaker/components/input/epoch/datetime.less +8 -1
  57. package/src/templates/foundation-theme/build/ios/wavemaker/components/input/epoch/time.less +8 -1
  58. package/src/templates/foundation-theme/build/ios/wavemaker/components/input/number.less +14 -0
  59. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/basic/button.less +2 -2
  60. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/basic/icon.less +6 -4
  61. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/basic/label.less +46 -4
  62. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/container/tabs/tab-header.less +15 -3
  63. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/data/form.less +14 -0
  64. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/input/checkboxset.less +1 -0
  65. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/input/chips.less +49 -0
  66. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/input/radioset.less +1 -1
  67. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/input/select.less +29 -1
  68. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/input/switch.less +4 -4
  69. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/navigation/menu.less +1 -0
  70. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/studio/basic/icon.less +0 -3
  71. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/studio/container/tabs.less +5 -1
  72. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/studio/input/currency.less +6 -2
  73. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/studio/input/form.less +20 -5
  74. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/tokens.light.css +21 -3
  75. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/variables/button.variant.less +2 -2
  76. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/variables/chips.variant.less +5 -1
  77. package/src/templates/foundation-theme/dist/android/style.css +23 -5
  78. package/src/templates/foundation-theme/dist/android/style.js +200 -59
  79. package/src/templates/foundation-theme/dist/android/tokens.js +21 -3
  80. package/src/templates/foundation-theme/dist/ios/style.css +23 -5
  81. package/src/templates/foundation-theme/dist/ios/style.js +200 -59
  82. package/src/templates/foundation-theme/dist/ios/tokens.js +21 -3
  83. package/src/templates/foundation-theme/wavemaker/components/input/epoch/date.less +8 -1
  84. package/src/templates/foundation-theme/wavemaker/components/input/epoch/datetime.less +8 -1
  85. package/src/templates/foundation-theme/wavemaker/components/input/epoch/time.less +8 -1
  86. package/src/templates/foundation-theme/wavemaker/components/input/number.less +14 -0
  87. package/src/templates/foundation-theme/wavemaker/design-tokens/basic/button.less +2 -2
  88. package/src/templates/foundation-theme/wavemaker/design-tokens/basic/icon.less +6 -4
  89. package/src/templates/foundation-theme/wavemaker/design-tokens/basic/label.less +46 -4
  90. package/src/templates/foundation-theme/wavemaker/design-tokens/container/tabs/tab-header.less +15 -3
  91. package/src/templates/foundation-theme/wavemaker/design-tokens/data/form.less +14 -0
  92. package/src/templates/foundation-theme/wavemaker/design-tokens/input/checkboxset.less +1 -0
  93. package/src/templates/foundation-theme/wavemaker/design-tokens/input/chips.less +49 -0
  94. package/src/templates/foundation-theme/wavemaker/design-tokens/input/radioset.less +1 -1
  95. package/src/templates/foundation-theme/wavemaker/design-tokens/input/select.less +29 -1
  96. package/src/templates/foundation-theme/wavemaker/design-tokens/input/switch.less +4 -4
  97. package/src/templates/foundation-theme/wavemaker/design-tokens/navigation/menu.less +1 -0
  98. package/src/templates/foundation-theme/wavemaker/design-tokens/studio/basic/icon.less +0 -3
  99. package/src/templates/foundation-theme/wavemaker/design-tokens/studio/container/tabs.less +5 -1
  100. package/src/templates/foundation-theme/wavemaker/design-tokens/studio/input/currency.less +6 -2
  101. package/src/templates/foundation-theme/wavemaker/design-tokens/studio/input/form.less +20 -5
  102. package/src/templates/foundation-theme/wavemaker/design-tokens/tokens.light.css +21 -3
  103. package/src/templates/foundation-theme/wavemaker/design-tokens/variables/button.variant.less +2 -2
  104. package/src/templates/foundation-theme/wavemaker/design-tokens/variables/chips.variant.less +5 -1
  105. package/src/templates/package.web.json +17 -7
  106. package/src/templates/page-stub.template +27 -0
  107. package/src/templates/project/.npmrc +1 -0
  108. package/src/templates/project/app.json +2 -1
  109. package/src/templates/project/esbuild/esbuild.script.js +57 -8
  110. package/src/templates/project/metro/container-limits.js +195 -0
  111. package/src/templates/project/metro/metro.script.js +850 -0
  112. package/src/templates/project/metro/module-path.js +237 -0
  113. package/src/templates/project/metro/split.serializer.js +184 -0
  114. package/src/templates/project/metro/split.static.js +633 -0
  115. package/src/templates/project/metro/stable-module-ids.js +54 -0
  116. package/src/templates/project/metro/vendor-cache.js +475 -0
  117. package/src/templates/project/metro/wm-boundary.js +150 -0
  118. package/src/templates/project/metro/wm-crawl-override.js +161 -0
  119. package/src/templates/project/metro/wm-fastbuild.js +196 -0
  120. package/src/templates/project/metro/wm-live-reload.js +482 -0
  121. package/src/templates/project/metro/wm-metro-adapter.js +25 -0
  122. package/src/templates/project/metro/wm-prebuilt.js +31 -0
  123. package/src/templates/project/metro.config.js +13 -2
  124. package/src/templates/project/package-lock.json +15308 -0
  125. package/src/templates/project/package.json +14 -6
  126. package/src/templates/project/patch-utils.js +331 -0
  127. package/src/templates/project/plugins/expo-pull-to-refresh/android/build.gradle +15 -0
  128. package/src/templates/project/plugins/expo-pull-to-refresh/android/src/main/java/expo/modules/pulltorefresh/ExpoPullToRefreshModule.kt +21 -0
  129. package/src/templates/project/plugins/expo-pull-to-refresh/android/src/main/java/expo/modules/pulltorefresh/ExpoPullToRefreshView.kt +221 -0
  130. package/src/templates/project/plugins/expo-pull-to-refresh/expo-module.config.json +16 -0
  131. package/src/templates/project/plugins/expo-pull-to-refresh/ios/ExpoPullToRefresh.podspec +24 -0
  132. package/src/templates/project/plugins/expo-pull-to-refresh/ios/ExpoPullToRefreshControlModule.swift +17 -0
  133. package/src/templates/project/plugins/expo-pull-to-refresh/ios/ExpoPullToRefreshControlView.swift +92 -0
  134. package/src/templates/project/plugins/expo-pull-to-refresh/package.json +15 -0
  135. package/src/templates/project/scripts/wm-babel.transform.plugin.js +11 -1
  136. package/src/templates/project/wavepulse/rn2css.json +5 -0
  137. package/src/theme/app-override-css.generator.js +10 -4
  138. package/src/theme/app-override-css.generator.js.map +1 -1
  139. package/src/theme/components/input/epoch/datetime.styledef.js +5 -0
  140. package/src/theme/components/input/epoch/datetime.styledef.js.map +1 -1
  141. package/src/theme/components/input/number.styledef.js +10 -0
  142. package/src/theme/components/input/number.styledef.js.map +1 -1
  143. package/src/theme/rn-stylesheet.transpiler.js +30 -6
  144. package/src/theme/rn-stylesheet.transpiler.js.map +1 -1
  145. package/src/theme/theme.service.js +3 -2
  146. package/src/theme/theme.service.js.map +1 -1
  147. package/src/transpile/bind.ex.transformer.js +55 -37
  148. package/src/transpile/bind.ex.transformer.js.map +1 -1
  149. package/src/transpile/components/container/wizard/wizardstep.transformer.js +10 -2
  150. package/src/transpile/components/container/wizard/wizardstep.transformer.js.map +1 -1
  151. package/src/transpile/components/data/form/form-field.transformer.js +36 -1
  152. package/src/transpile/components/data/form/form-field.transformer.js.map +1 -1
  153. package/src/transpile/components/page/page.transformer.js +11 -1
  154. package/src/transpile/components/page/page.transformer.js.map +1 -1
  155. package/src/transpile/property/property-parser.js +7 -1
  156. package/src/transpile/property/property-parser.js.map +1 -1
  157. package/src/transpile/style.transformer.js +1 -0
  158. package/src/transpile/style.transformer.js.map +1 -1
  159. package/src/transpile/transpile.js +10 -1
  160. package/src/transpile/transpile.js.map +1 -1
  161. package/src/utils.js +8 -1
  162. package/src/utils.js.map +1 -1
  163. package/src/variables/variable.transformer.js +7 -7
  164. package/src/variables/variable.transformer.js.map +1 -1
  165. package/src/wm-namespace.js +14 -0
  166. package/src/wm-namespace.js.map +1 -0
  167. package/test/pipeline/build-leftovers.test.js +172 -0
  168. package/test/pipeline/build-leftovers.test.js.map +1 -0
  169. package/test/pipeline/chmod-tree.test.js +54 -0
  170. package/test/pipeline/chmod-tree.test.js.map +1 -0
  171. package/test/pipeline/crawl-override.test.js +53 -0
  172. package/test/pipeline/crawl-override.test.js.map +1 -0
  173. package/test/pipeline/live-reload-pacing.test.js +76 -0
  174. package/test/pipeline/live-reload-pacing.test.js.map +1 -0
  175. package/test/pipeline/npm-install-retry.test.js +57 -0
  176. package/test/pipeline/npm-install-retry.test.js.map +1 -0
  177. package/test/pipeline/repair-vendor-packages.test.js +134 -0
  178. package/test/pipeline/repair-vendor-packages.test.js.map +1 -0
  179. package/test/pipeline/web-preview-files.test.js +48 -0
  180. package/test/pipeline/web-preview-files.test.js.map +1 -0
  181. package/web-preview.js +155 -0
  182. package/web-preview.js.map +1 -0
@@ -0,0 +1,161 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * Skips Metro's file-map verification crawl when nothing was added or removed.
5
+ *
6
+ * The crawl walks ~11.9k directories / 79k files (measured ~700-790ms) purely to diff the
7
+ * filesystem against a snapshot it has already loaded. Metro reads file CONTENT at transform time
8
+ * through TreeFS, not from the crawl delta, so an edit to an existing file still lands without it.
9
+ * What the crawl is genuinely needed for is files appearing or disappearing, so we do that check
10
+ * ourselves over the project source tree only — node_modules is vendored and locked.
11
+ *
12
+ * Loaded via NODE_OPTIONS=--require from metro.script.js. Disable with WM_CRAWL_OVERRIDE=0.
13
+ */
14
+
15
+ const Module = require('module');
16
+ const fs = require('fs');
17
+ const path = require('path');
18
+
19
+ const MANIFEST = '.wm-crawl-manifest.json';
20
+ const TRANSFORM_OPTS = '.wm-transform-options.json';
21
+ const SKIP_DIRS = new Set(['node_modules', '.git', '.expo', 'dist', 'build', 'ios', 'android']);
22
+
23
+ /*
24
+ * Second hook, same preload: record the exact options Metro hands the transform worker for one
25
+ * project-source file. wm-fastbuild.js replays them verbatim, so the fast path never has to guess
26
+ * how Metro composed them — a guess would silently produce differently-transformed output.
27
+ */
28
+ function installTransformCapture(workerExports, projectRoot) {
29
+ if (!workerExports || typeof workerExports.transform !== 'function' || workerExports.__wmCapture) {
30
+ return false;
31
+ }
32
+ const original = workerExports.transform;
33
+ const target = path.join(projectRoot, 'src') + path.sep;
34
+ let captured = false;
35
+ try {
36
+ Object.defineProperty(workerExports, 'transform', {
37
+ configurable: true,
38
+ writable: true,
39
+ value: async function transform(config, root, filename, data, options) {
40
+ const result = await original.apply(this, arguments);
41
+ if (!captured && filename && path.resolve(root, filename).startsWith(target)) {
42
+ captured = true;
43
+ try {
44
+ fs.writeFileSync(
45
+ path.join(projectRoot, TRANSFORM_OPTS),
46
+ JSON.stringify({ capturedFrom: filename, options }, null, 1),
47
+ );
48
+ } catch {}
49
+ }
50
+ return result;
51
+ },
52
+ });
53
+ workerExports.__wmCapture = true;
54
+ return true;
55
+ } catch {
56
+ return false;
57
+ }
58
+ }
59
+
60
+ function projectRootOf() {
61
+ return process.env.WM_CRAWL_PROJECT_ROOT || process.cwd();
62
+ }
63
+
64
+ // Paths only — content changes are Metro's job, we just detect structural drift.
65
+ function listSourceFiles(root) {
66
+ const out = [];
67
+ const walk = (dir) => {
68
+ let entries;
69
+ try { entries = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; }
70
+ for (const e of entries) {
71
+ if (e.name.startsWith('.wm-')) continue;
72
+ const full = path.join(dir, e.name);
73
+ if (e.isDirectory()) {
74
+ if (SKIP_DIRS.has(e.name) || e.name.startsWith('.')) continue;
75
+ walk(full);
76
+ } else if (e.isFile()) {
77
+ out.push(full);
78
+ }
79
+ }
80
+ };
81
+ walk(root);
82
+ out.sort();
83
+ return out;
84
+ }
85
+
86
+ function readManifest(root) {
87
+ try { return JSON.parse(fs.readFileSync(path.join(root, MANIFEST), 'utf8')); } catch { return null; }
88
+ }
89
+
90
+ function writeManifest(root, files) {
91
+ try {
92
+ fs.writeFileSync(path.join(root, MANIFEST), JSON.stringify({ count: files.length, files }));
93
+ } catch {}
94
+ }
95
+
96
+ // Metro's file-map cache (os.tmpdir) can be empty while the manifest matches; skipping then breaks resolution.
97
+ function previousMapHasFiles(watcher, files) {
98
+ const fileSystem = watcher && watcher._options && watcher._options.previousState
99
+ && watcher._options.previousState.fileSystem;
100
+ if (!fileSystem || typeof fileSystem.exists !== 'function') return false;
101
+ try {
102
+ return files.every(f => fileSystem.exists(f));
103
+ } catch {
104
+ return false;
105
+ }
106
+ }
107
+
108
+ function install(WatcherClass) {
109
+ const proto = WatcherClass && WatcherClass.prototype;
110
+ if (!proto || typeof proto.crawl !== 'function' || proto.crawl.__wmOverride) return false;
111
+
112
+ const originalCrawl = proto.crawl;
113
+ const patched = async function crawl(...args) {
114
+ const root = projectRootOf();
115
+ let current;
116
+ try { current = listSourceFiles(root); } catch { current = null; }
117
+
118
+ if (current) {
119
+ const prev = readManifest(root);
120
+ const unchanged = prev
121
+ && prev.count === current.length
122
+ && Array.isArray(prev.files)
123
+ && prev.files.length === current.length
124
+ && prev.files.every((f, i) => f === current[i]);
125
+
126
+ if (unchanged && previousMapHasFiles(this, current)) {
127
+ console.log(`[crawl] skipped full crawl — ${current.length} project source files unchanged`);
128
+ return { changedFiles: new Map(), removedFiles: new Set() };
129
+ }
130
+ console.log(unchanged
131
+ ? '[crawl] running full crawl — Metro\'s cached file map is missing project files'
132
+ : `[crawl] running full crawl — project source file set changed (${prev ? prev.count : 'no'} -> ${current.length})`);
133
+ }
134
+
135
+ const result = await originalCrawl.apply(this, args);
136
+ if (current) writeManifest(root, current);
137
+ return result;
138
+ };
139
+ patched.__wmOverride = true;
140
+ Object.defineProperty(proto, 'crawl', { value: patched, writable: true, configurable: true });
141
+ return true;
142
+ }
143
+
144
+ if (process.env.WM_CRAWL_OVERRIDE !== '0') {
145
+ const originalLoad = Module._load;
146
+ Module._load = function (request, parent) {
147
+ const exported = originalLoad.apply(this, arguments);
148
+ let filename = '';
149
+ try { filename = Module._resolveFilename(request, parent) || ''; } catch {}
150
+ if (/metro-file-map[/\\]build[/\\]Watcher\.js$/.test(filename)) {
151
+ try { install(exported && (exported.Watcher || exported.default || exported)); } catch {}
152
+ }
153
+ // Expo's worker, not metro-transform-worker — config.transformerPath points here.
154
+ if (/transform-worker[/\\]transform-worker\.js$/.test(filename)) {
155
+ try { installTransformCapture(exported, projectRootOf()); } catch {}
156
+ }
157
+ return exported;
158
+ };
159
+ }
160
+
161
+ module.exports = { listSourceFiles, install };
@@ -0,0 +1,196 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * Re-emits only the project modules that actually changed, without building the dependency graph.
5
+ *
6
+ * A caption edit changes 5 of ~2730 modules (0.18%), yet a full export walks all of them — about
7
+ * 2.8s of the ~6s build. This path reads the manifest the split serializer wrote on the last full
8
+ * build (module id, dependency ids in Metro's `d`-array order, source hash), re-transforms just the
9
+ * changed files with Metro's OWN worker, re-wraps them with Metro's OWN addParamsToDefineCall, and
10
+ * writes a new `modified` chunk. wm-live-reload.js picks it up from index.html with no refresh.
11
+ *
12
+ * It is deliberately conservative: anything it cannot prove safe returns {ok:false, reason} and the
13
+ * caller runs a normal full export. Dependency *names* are re-checked after transforming, because a
14
+ * changed import means resolution moved and the cached dependency ids no longer apply.
15
+ */
16
+
17
+ const path = require('path');
18
+ const fs = require('fs-extra');
19
+ const crypto = require('crypto');
20
+
21
+ const MANIFEST_FILE = '.wm-fastpath.json';
22
+ const TRANSFORM_OPTS_FILE = '.wm-transform-options.json';
23
+ const INDEX_TEMPLATE_FILE = '.wm-index-template.html';
24
+
25
+ const md5 = (buf) => crypto.createHash('md5').update(buf).digest('hex');
26
+
27
+ function readJson(file) {
28
+ try { return fs.readJSONSync(file); } catch { return null; }
29
+ }
30
+
31
+ // Resolved from the project so we always use the same copies Metro itself loaded.
32
+ function loadProjectModule(projectRoot, relPath) {
33
+ return require(path.join(projectRoot, relPath));
34
+ }
35
+
36
+ function collectChanged(projectRoot, manifest) {
37
+ const changed = [];
38
+ for (const [rel, info] of Object.entries(manifest.modules)) {
39
+ const abs = path.join(projectRoot, rel);
40
+ let buf;
41
+ try { buf = fs.readFileSync(abs); } catch { return { bail: `source missing: ${rel}` }; }
42
+ if (md5(buf) !== info.srcHash) { changed.push({ rel, abs, info, buf }); }
43
+ }
44
+ return { changed };
45
+ }
46
+
47
+ async function emitChangedModules({ projectRoot, manifest, transformOptions, changed }) {
48
+ const worker = loadProjectModule(projectRoot,
49
+ 'node_modules/@expo/metro-config/build/transform-worker/transform-worker.js');
50
+ const { addParamsToDefineCall } = loadProjectModule(projectRoot, 'node_modules/metro-transform-plugins');
51
+ const { loadConfig } = loadProjectModule(projectRoot, 'node_modules/metro-config');
52
+ const config = await loadConfig({ cwd: projectRoot, projectRoot });
53
+
54
+ const pieces = [];
55
+ for (const item of changed) {
56
+ const result = await worker.transform(
57
+ config.transformer, projectRoot, item.rel, item.buf, transformOptions,
58
+ );
59
+ // Exact match, not startsWith: 'js/module/asset' also starts with 'js/module', so a font or
60
+ // image reaching this far would be wrapped as if it were code. The manifest already excludes
61
+ // them, but this is the layer that would actually emit the corrupt module, so it re-checks.
62
+ const output = (result.output || []).find(o => o.type === 'js/module');
63
+ if (!output) { return { ok: false, reason: `no plain js output for ${item.rel}` }; }
64
+
65
+ const names = (result.dependencies || []).map(d => d.name);
66
+ const expected = item.info.depNames || [];
67
+ const firstDiff = names.findIndex((n, i) => n !== expected[i]);
68
+ if (names.length !== expected.length || firstDiff !== -1) {
69
+ const detail = firstDiff === -1
70
+ ? `${expected.length} -> ${names.length}`
71
+ : `#${firstDiff} ${JSON.stringify(expected[firstDiff])} -> ${JSON.stringify(names[firstDiff])}`;
72
+ return { ok: false, reason: `dependencies changed in ${item.rel} (${detail})` };
73
+ }
74
+ pieces.push(addParamsToDefineCall(output.data.code, item.info.id, item.info.depIds));
75
+ }
76
+ return { ok: true, code: pieces.join('\n') + '\n' };
77
+ }
78
+
79
+ // Chunk order is load-bearing: __d is first-registration-wins, so `modified` must precede `user`.
80
+ function rewriteIndexHtml(bundleDir, newFilename, projectRoot) {
81
+ const indexFile = path.join(bundleDir, 'index.html');
82
+ let html;
83
+ try { html = fs.readFileSync(indexFile, 'utf8'); } catch { return { ok: false, reason: 'index.html unreadable' }; }
84
+
85
+ // The pipeline replaces the served index.html with a placeholder before every build, so on a
86
+ // Studio-triggered build this file has no chunk tags at all. Fall back to the snapshot the last
87
+ // full build took — that is the page we actually want to re-publish with a new modified chunk.
88
+ if (!/-user\.js"/.test(html)) {
89
+ try {
90
+ html = fs.readFileSync(path.join(projectRoot, INDEX_TEMPLATE_FILE), 'utf8');
91
+ } catch {
92
+ return { ok: false, reason: 'served index.html is a placeholder and no snapshot exists yet' };
93
+ }
94
+ }
95
+
96
+ // Expo emits src="/./<chunk>.js"; metro.script.js later rewrites those to "./<chunk>.js" for the
97
+ // served bundle. Match either, and reuse whichever prefix this page already uses.
98
+ const userTag = /<script src="((?:\/)?\.\/)[0-9a-f]{8}-user\.js"[^>]*><\/script>/;
99
+ const found = html.match(userTag);
100
+ if (!found) { return { ok: false, reason: 'no user chunk tag in index.html' }; }
101
+ const prefix = found[1];
102
+ const tag = `<script src="${prefix}${newFilename}" defer></script>`;
103
+
104
+ const existing = /<script src="(?:\/)?\.\/[0-9a-f]{8}-modified\.js"[^>]*><\/script>\s*/;
105
+ const next = existing.test(html)
106
+ ? html.replace(existing, `${tag}\n`)
107
+ : html.replace(userTag, `${tag}\n${found[0]}`);
108
+
109
+ fs.writeFileSync(indexFile, next);
110
+ return { ok: true };
111
+ }
112
+
113
+ async function fastBuild({ projectRoot, bundleDir }) {
114
+ if (process.env.WM_FASTPATH === '0') { return { ok: false, reason: 'disabled by WM_FASTPATH=0' }; }
115
+
116
+ const manifest = readJson(path.join(projectRoot, MANIFEST_FILE));
117
+ if (!manifest || !manifest.modules) { return { ok: false, reason: 'no fast-path manifest' }; }
118
+
119
+ const captured = readJson(path.join(projectRoot, TRANSFORM_OPTS_FILE));
120
+ if (!captured || !captured.options) { return { ok: false, reason: 'no captured transform options' }; }
121
+
122
+ const { changed, bail } = collectChanged(projectRoot, manifest);
123
+ if (bail) { return { ok: false, reason: bail }; }
124
+ if (!changed.length) { return { ok: false, reason: 'no source changes' }; }
125
+
126
+ // Re-emit the previous override set too. The user chunk holds every project module, and `modified`
127
+ // only wins by loading first — so anything we drop here silently reverts to its baseline version.
128
+ const changedRel = new Set(changed.map(c => c.rel));
129
+ const toEmit = [...changed];
130
+ for (const rel of manifest.overrideRel || []) {
131
+ if (changedRel.has(rel) || !manifest.modules[rel]) { continue; }
132
+ const abs = path.join(projectRoot, rel);
133
+ let buf;
134
+ try { buf = fs.readFileSync(abs); } catch { return { ok: false, reason: `override source missing: ${rel}` }; }
135
+ toEmit.push({ rel, abs, info: manifest.modules[rel], buf });
136
+ }
137
+
138
+ // Each module goes through the transform worker serially and uncached (~0.3s apiece on a big
139
+ // app), so a large set costs far more here than a full export with the warm transform cache.
140
+ const maxEmit = parseInt(process.env.WM_FASTPATH_MAX_EMIT, 10) || 150;
141
+ if (toEmit.length > maxEmit) {
142
+ return { ok: false, reason: `${toEmit.length} modules to emit exceeds fast-path limit ${maxEmit}` };
143
+ }
144
+
145
+ const emitted = await emitChangedModules({
146
+ projectRoot, manifest, transformOptions: captured.options, changed: toEmit,
147
+ });
148
+ if (!emitted.ok) { return emitted; }
149
+
150
+ const filename = `${md5(emitted.code).slice(0, 8)}-modified.js`;
151
+ fs.writeFileSync(path.join(bundleDir, filename), emitted.code);
152
+
153
+ const rewritten = rewriteIndexHtml(bundleDir, filename, projectRoot);
154
+ if (!rewritten.ok) { return rewritten; }
155
+
156
+ // Each run emits a new content-hashed chunk, so without this the bundle dir grows by one dead
157
+ // chunk per edit — and a stale one could still be picked up if index.html were ever rebuilt.
158
+ let pruned = 0;
159
+ for (const name of fs.readdirSync(bundleDir)) {
160
+ if (name !== filename && /^[0-9a-f]{8}-modified\.js(\.map)?$/.test(name)) {
161
+ try { fs.removeSync(path.join(bundleDir, name)); pruned++; } catch {}
162
+ }
163
+ }
164
+
165
+ // Only now, once the chunk is actually on disk, does the manifest describe what was shipped —
166
+ // including the override set, which is now exactly what this chunk contains.
167
+ for (const item of changed) { manifest.modules[item.rel].srcHash = md5(item.buf); }
168
+ manifest.overrideRel = toEmit.map(item => item.rel);
169
+ fs.writeJSONSync(path.join(projectRoot, MANIFEST_FILE), manifest);
170
+
171
+ return {
172
+ ok: true,
173
+ filename,
174
+ changedCount: changed.length,
175
+ emittedCount: toEmit.length,
176
+ pruned,
177
+ files: changed.map(c => c.rel),
178
+ };
179
+ }
180
+
181
+ module.exports = { fastBuild };
182
+
183
+ if (require.main === module) {
184
+ const [, , projectRoot, bundleDir] = process.argv;
185
+ if (!projectRoot || !bundleDir) {
186
+ console.error('usage: node wm-fastbuild.js <projectRoot> <bundleDir>');
187
+ process.exit(2);
188
+ }
189
+ const started = Date.now();
190
+ fastBuild({ projectRoot: path.resolve(projectRoot), bundleDir: path.resolve(bundleDir) })
191
+ .then((r) => {
192
+ console.log(JSON.stringify({ ...r, ms: Date.now() - started }));
193
+ process.exit(r.ok ? 0 : 1);
194
+ })
195
+ .catch((e) => { console.error('[fastbuild] ' + e.stack); process.exit(3); });
196
+ }