@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.
- package/command.js +111 -269
- package/command.js.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/npm-shrinkwrap.json +4840 -3624
- package/package-lock.json +4840 -3624
- package/package.json +62 -42
- package/src/app.generator.js +249 -87
- package/src/app.generator.js.map +1 -1
- package/src/fomatter.js.map +1 -1
- package/src/handlebar-helpers.js.map +1 -1
- package/src/increment-builder.js.map +1 -1
- package/src/pipeline/build-common.js +63 -0
- package/src/pipeline/build-common.js.map +1 -0
- package/src/pipeline/build-pipeline.js +152 -0
- package/src/pipeline/build-pipeline.js.map +1 -0
- package/src/pipeline/generation-store.js +288 -0
- package/src/pipeline/generation-store.js.map +1 -0
- package/src/pipeline/shared-node-modules.js +775 -0
- package/src/pipeline/shared-node-modules.js.map +1 -0
- package/src/pipeline/web-preview-templates.js +80 -0
- package/src/pipeline/web-preview-templates.js.map +1 -0
- package/src/pipeline/working-set.js +103 -0
- package/src/pipeline/working-set.js.map +1 -0
- package/src/profiles/legacy-web-preview.profile.js +15 -0
- package/src/profiles/legacy-web-preview.profile.js.map +1 -0
- package/src/project.service.js +17 -7
- package/src/project.service.js.map +1 -1
- package/src/templates/babel.config.js.template +0 -1
- package/src/templates/bootstrap.template +3 -1
- package/src/templates/device-plugin-service.template +7 -9
- package/src/templates/package.web.json +108 -83
- package/src/templates/page-stub.template +27 -0
- package/src/templates/project/app.json +4 -11
- package/src/templates/project/esbuild/esbuild.script.js +129 -89
- package/src/templates/project/metro/container-limits.js +195 -0
- package/src/templates/project/metro/metro.script.js +833 -0
- package/src/templates/project/metro/module-path.js +237 -0
- package/src/templates/project/metro/split.serializer.js +184 -0
- package/src/templates/project/metro/split.static.js +633 -0
- package/src/templates/project/metro/stable-module-ids.js +54 -0
- package/src/templates/project/metro/vendor-cache.js +475 -0
- package/src/templates/project/metro/wm-boundary.js +138 -0
- package/src/templates/project/metro/wm-crawl-override.js +147 -0
- package/src/templates/project/metro/wm-fastbuild.js +196 -0
- package/src/templates/project/metro/wm-live-reload.js +482 -0
- package/src/templates/project/metro/wm-metro-adapter.js +25 -0
- package/src/templates/project/metro.config.js +209 -8
- package/src/templates/project/package.json +106 -83
- package/src/templates/project/patch-utils.js +331 -0
- package/src/templates/project/scripts/post-build.js +3 -0
- package/src/theme/app-override-css.generator.js +10 -4
- package/src/theme/app-override-css.generator.js.map +1 -1
- package/src/theme/components/basic/base.styledef.js.map +1 -1
- package/src/theme/components/style-definition.provider.js.map +1 -1
- package/src/theme/font-stylesheet.transpiler.js +17 -7
- package/src/theme/font-stylesheet.transpiler.js.map +1 -1
- package/src/theme/rn-stylesheet.transpiler.js +17 -7
- package/src/theme/rn-stylesheet.transpiler.js.map +1 -1
- package/src/theme/theme.service.js +7 -19
- package/src/theme/theme.service.js.map +1 -1
- package/src/theme/token.transpiler.js +17 -7
- package/src/theme/token.transpiler.js.map +1 -1
- package/src/transpile/bind.ex.transformer.js +36 -23
- package/src/transpile/bind.ex.transformer.js.map +1 -1
- package/src/transpile/components/advanced/carousel.transformer.js.map +1 -1
- package/src/transpile/components/advanced/customwidget.transformer.js.map +1 -1
- package/src/transpile/components/advanced/login.transformer.js.map +1 -1
- package/src/transpile/components/advanced/webview.transformer.js.map +1 -1
- package/src/transpile/components/basic/buttongroup.transformer.js.map +1 -1
- package/src/transpile/components/basic/custom.transformer.js.map +1 -1
- package/src/transpile/components/basic/picture.transformer.js.map +1 -1
- package/src/transpile/components/basic/progress-bar.transformer.js.map +1 -1
- package/src/transpile/components/basic/search.transformer.js.map +1 -1
- package/src/transpile/components/chart/area-chart.transformer.js.map +1 -1
- package/src/transpile/components/container/accordion/accordionpane.transformer.js.map +1 -1
- package/src/transpile/components/container/accordion.transformer.js.map +1 -1
- package/src/transpile/components/container/container.transformer.js.map +1 -1
- package/src/transpile/components/container/layoutgrid/gridcolumn.transformer.js.map +1 -1
- package/src/transpile/components/container/layoutgrid/gridrow.transformer.js.map +1 -1
- package/src/transpile/components/container/layoutgrid.transformer.js.map +1 -1
- package/src/transpile/components/container/linearlayout.transformer.js.map +1 -1
- package/src/transpile/components/container/panel.transformer.js.map +1 -1
- package/src/transpile/components/container/tabs/tabpane.transformer.js.map +1 -1
- package/src/transpile/components/container/tabs.transformer.js.map +1 -1
- package/src/transpile/components/container/wizard/wizardstep.transformer.js.map +1 -1
- package/src/transpile/components/container/wizard.transformer.js.map +1 -1
- package/src/transpile/components/data/card/card-content.transformer.js.map +1 -1
- package/src/transpile/components/data/form/form-action.transformer.js.map +1 -1
- package/src/transpile/components/data/form/form-field.transformer.js.map +1 -1
- package/src/transpile/components/data/form.transformer.js.map +1 -1
- package/src/transpile/components/data/list.transformer.js +17 -7
- package/src/transpile/components/data/list.transformer.js.map +1 -1
- package/src/transpile/components/data/liveform.transformer.js.map +1 -1
- package/src/transpile/components/dialogs/dialog.transformer.js.map +1 -1
- package/src/transpile/components/input/checkboxset.transformer.js.map +1 -1
- package/src/transpile/components/input/chips.transformer.js.map +1 -1
- package/src/transpile/components/input/epoch/date.transformer.js.map +1 -1
- package/src/transpile/components/input/epoch/datetime.transformer.js.map +1 -1
- package/src/transpile/components/input/epoch/time.transformer.js.map +1 -1
- package/src/transpile/components/input/radioset.transformer.js.map +1 -1
- package/src/transpile/components/input/rating.transformer.js.map +1 -1
- package/src/transpile/components/input/select.transformer.js.map +1 -1
- package/src/transpile/components/input/slider.transformer.js.map +1 -1
- package/src/transpile/components/input/switch.transformer.js.map +1 -1
- package/src/transpile/components/input/textarea.transformer.js.map +1 -1
- package/src/transpile/components/input/toggle.transformer.js.map +1 -1
- package/src/transpile/components/navigation/appnavbar.transformer.js.map +1 -1
- package/src/transpile/components/navigation/menu.transformer.js.map +1 -1
- package/src/transpile/components/navigation/navbar.transformer.js.map +1 -1
- package/src/transpile/components/navigation/navitem.transformer.js.map +1 -1
- package/src/transpile/components/navigation/popover.transformer.js.map +1 -1
- package/src/transpile/components/page/left-panel.transformer.js.map +1 -1
- package/src/transpile/components/page/page.transformer.js.map +1 -1
- package/src/transpile/components/page/partial-container.transformer.js +17 -7
- package/src/transpile/components/page/partial-container.transformer.js.map +1 -1
- package/src/transpile/components/prefab/prefab.transformer.js.map +1 -1
- package/src/transpile/components/utils.js.map +1 -1
- package/src/transpile/property/property-parser.js.map +1 -1
- package/src/transpile/property/show-in-device.parser.js.map +1 -1
- package/src/transpile/style/background-image.parser.js.map +1 -1
- package/src/transpile/style/dimension-style.parser.js.map +1 -1
- package/src/transpile/style/multi-dimension-style.parser.js.map +1 -1
- package/src/transpile/style/numeric-style.parser.js.map +1 -1
- package/src/transpile/style.transformer.js.map +1 -1
- package/src/transpile/transpile.js +17 -7
- package/src/transpile/transpile.js.map +1 -1
- package/src/utils.js +8 -1
- package/src/utils.js.map +1 -1
- package/src/variables/variable.transformer.js.map +1 -1
- package/src/wm-namespace.js +14 -0
- package/src/wm-namespace.js.map +1 -0
- package/test/pipeline/live-reload-pacing.test.js +76 -0
- package/test/pipeline/live-reload-pacing.test.js.map +1 -0
- package/test/pipeline/npm-install-retry.test.js +57 -0
- package/test/pipeline/npm-install-retry.test.js.map +1 -0
- package/test/pipeline/repair-vendor-packages.test.js +134 -0
- package/test/pipeline/repair-vendor-packages.test.js.map +1 -0
- package/test/pipeline/web-preview-files.test.js +48 -0
- package/test/pipeline/web-preview-files.test.js.map +1 -0
- package/web-preview.js +165 -0
- package/web-preview.js.map +1 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const crypto = require('crypto');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const { isJscSafeUrl, toNormalUrl } = require('jsc-safe-url');
|
|
8
|
+
const lockfile = require('proper-lockfile');
|
|
9
|
+
// Container/cgroup helpers live in a dependency-free module so the codegen pipeline
|
|
10
|
+
// can require them WITHOUT pulling in this file's jsc-safe-url / proper-lockfile deps.
|
|
11
|
+
const { containerMemoryLimitMB, containerMemoryUsedMB, findDeviceRoot, oomKillCount, waitForHeadroom }
|
|
12
|
+
= require('./container-limits');
|
|
13
|
+
|
|
14
|
+
const NM_MARKER = `${path.sep}node_modules${path.sep}`;
|
|
15
|
+
const IS_NODE_MODULE = /[/\\]node_modules[/\\]/;
|
|
16
|
+
|
|
17
|
+
const WMX_MARKER = `${path.sep}wmx-components${path.sep}`;
|
|
18
|
+
const IS_WMX_MODULE = /[/\\]wmx-components[/\\]/;
|
|
19
|
+
|
|
20
|
+
// Decodes Expo's jsc-safe-url encoding and parses as a URL, or null on failure. Shared by split.serializer.js and split.static.js.
|
|
21
|
+
function parseSourceUrl(raw) {
|
|
22
|
+
if (!raw) return null;
|
|
23
|
+
try {
|
|
24
|
+
const decoded = isJscSafeUrl(raw) ? toNormalUrl(raw) : raw;
|
|
25
|
+
return new URL(decoded, 'http://localhost');
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function nodeModulesSegmentCount(filePath) {
|
|
32
|
+
let count = 0;
|
|
33
|
+
let from = 0;
|
|
34
|
+
for (;;) {
|
|
35
|
+
const idx = filePath.indexOf(NM_MARKER, from);
|
|
36
|
+
if (idx === -1) break;
|
|
37
|
+
count++;
|
|
38
|
+
from = idx + NM_MARKER.length;
|
|
39
|
+
}
|
|
40
|
+
return count;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function topLevelPackageName(filePath) {
|
|
44
|
+
const parts = filePath.split(NM_MARKER);
|
|
45
|
+
if (parts.length !== 2) return null;
|
|
46
|
+
const segs = parts[1].split(path.sep).filter(Boolean);
|
|
47
|
+
if (segs.length === 0) return null;
|
|
48
|
+
return segs[0][0] === '@' && segs.length > 1 ? `${segs[0]}/${segs[1]}` : segs[0];
|
|
49
|
+
}
|
|
50
|
+
function normalizeKey(filePath) {
|
|
51
|
+
const idx = filePath.lastIndexOf(NM_MARKER);
|
|
52
|
+
return idx !== -1 ? filePath.slice(idx) : filePath;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function normalizeWmxKey(filePath) {
|
|
56
|
+
const idx = filePath.lastIndexOf(WMX_MARKER);
|
|
57
|
+
return idx !== -1 ? filePath.slice(idx) : filePath;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function nestedPackageParts(filePath) {
|
|
61
|
+
const idx = filePath.lastIndexOf(NM_MARKER);
|
|
62
|
+
const rest = filePath.slice(idx + NM_MARKER.length);
|
|
63
|
+
const segs = rest.split(path.sep);
|
|
64
|
+
const pkgDirLen = segs[0][0] === '@' ? 2 : 1;
|
|
65
|
+
const pkgRoot = path.join(filePath.slice(0, idx + NM_MARKER.length), ...segs.slice(0, pkgDirLen));
|
|
66
|
+
return { pkgRoot, relPath: path.relative(pkgRoot, filePath) };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Nested/pinned copies are keyed by package name+version instead of path, so a cached cross-project vendor bundle's IDs stay valid.
|
|
70
|
+
function stableIdKey(filePath) {
|
|
71
|
+
const count = nodeModulesSegmentCount(filePath);
|
|
72
|
+
if (count === 0) return filePath;
|
|
73
|
+
if (count === 1) return normalizeKey(filePath);
|
|
74
|
+
try {
|
|
75
|
+
const { pkgRoot, relPath } = nestedPackageParts(filePath);
|
|
76
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(pkgRoot, 'package.json'), 'utf8'));
|
|
77
|
+
return `${NM_MARKER}${pkg.name}@${pkg.version}${path.sep}${relPath}`;
|
|
78
|
+
} catch {
|
|
79
|
+
return filePath;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Highest ancestor of 'start' still on the same mounted filesystem — fallback for findVolumeRoot when there's no 'vol-<id>' segment.
|
|
84
|
+
// Real memory ceiling for THIS container (cgroup v2, then v1, then the host). A
|
|
85
|
+
// --max-old-space-size larger than the cgroup limit is actively harmful: V8 sees no
|
|
86
|
+
// reason to GC aggressively and grows until the KERNEL SIGKILLs the process, which is
|
|
87
|
+
// opaque and leaves the parent hanging; sized below the limit, V8 fails cleanly inside
|
|
88
|
+
// its own heap instead. Shared by shared-node-modules.ts's npm install cap and this
|
|
89
|
+
// file's own callers (metro.script.js's expo export cap) so both stay in sync.
|
|
90
|
+
function findVolumeRoot(start) {
|
|
91
|
+
const resolved = path.resolve(start);
|
|
92
|
+
const parts = resolved.split(path.sep);
|
|
93
|
+
const idx = parts.findIndex((p) => /^vol-/.test(p));
|
|
94
|
+
if (idx === -1) {
|
|
95
|
+
return findDeviceRoot(start);
|
|
96
|
+
}
|
|
97
|
+
return parts.slice(0, idx + 1).join(path.sep);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Device-wide Metro transform cache, SHARED across every project on this volume.
|
|
101
|
+
//
|
|
102
|
+
// Why: transform output for a node_modules module is byte-identical for every
|
|
103
|
+
// project on the same rn-app version (same file content, same transform options),
|
|
104
|
+
// and node_modules dwarfs project source — measured 2723 graph modules vs 26
|
|
105
|
+
// project files. With a per-project cache dir every project re-transformed ~99%
|
|
106
|
+
// of the graph from scratch on its first build. This is the transform-level
|
|
107
|
+
// analogue of the vendor BUNDLE sharing that already exists.
|
|
108
|
+
//
|
|
109
|
+
// Correctness: Metro keys each cache entry by file content + transform options +
|
|
110
|
+
// cacheVersion, so two projects can only collide when the inputs are genuinely
|
|
111
|
+
// identical — in which case sharing the result is correct by definition.
|
|
112
|
+
//
|
|
113
|
+
// Invalidation: the rn-app/runtime generation is part of the PATH rather than
|
|
114
|
+
// something we wipe, so a runtime bump lands in a fresh directory instead of
|
|
115
|
+
// forcing a wipe that would penalise every other project sharing the cache.
|
|
116
|
+
function sharedMetroCacheRoot(projectRoot) {
|
|
117
|
+
const resolvedRoot = path.resolve(projectRoot);
|
|
118
|
+
const volumeRoot = findVolumeRoot(resolvedRoot);
|
|
119
|
+
let generation = 'default';
|
|
120
|
+
try {
|
|
121
|
+
const marker = fs.readFileSync(path.join(resolvedRoot, '.wm-vendor-generation'), 'utf8').trim();
|
|
122
|
+
if (marker) {
|
|
123
|
+
generation = require('crypto').createHash('md5').update(marker).digest('hex').slice(0, 12);
|
|
124
|
+
}
|
|
125
|
+
} catch {
|
|
126
|
+
// No marker yet (e.g. exact/local mode) — fall back to a shared 'default' bucket.
|
|
127
|
+
}
|
|
128
|
+
return path.join(volumeRoot, '.wm-rn-cache', '_shared', 'metro', generation);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Transforms of the project's own files never leave the project; only node_modules transforms are shared.
|
|
132
|
+
function projectMetroCacheRoot(projectRoot) {
|
|
133
|
+
return path.join(path.resolve(projectRoot), '.wm-cache', 'metro', path.basename(sharedMetroCacheRoot(projectRoot)));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Per platform: the Expo Go android export must not overwrite the web build's list.
|
|
137
|
+
const expoAssetCacheFile = (platform) => `.wm-expo-assets.${platform}.json`;
|
|
138
|
+
const PROJECT_SOURCE_EXT =/\.(js|jsx|ts|tsx|mjs|cjs|json)$/;
|
|
139
|
+
// The project cache lives inside the project; Metro's file map must not crawl it.
|
|
140
|
+
const PROJECT_CACHE_DIR = /[\\/]\.wm-cache[\\/]/;
|
|
141
|
+
|
|
142
|
+
function projectSourceSha1s(dir, out = new Set()) {
|
|
143
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
144
|
+
if (entry.name === 'node_modules' || entry.name.startsWith('.')) continue;
|
|
145
|
+
const full = path.join(dir, entry.name);
|
|
146
|
+
if (entry.isDirectory()) {
|
|
147
|
+
projectSourceSha1s(full, out);
|
|
148
|
+
} else if (entry.isFile() && PROJECT_SOURCE_EXT.test(entry.name)) {
|
|
149
|
+
out.add(crypto.createHash('sha1').update(fs.readFileSync(full)).digest('hex'));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Metro keys a transform as <hash of path + options><sha1 of the file content> and hands the store only that
|
|
156
|
+
// key, so route on its last 20 bytes: a project file's content goes to the project store, the rest is shared.
|
|
157
|
+
function createMetroCacheStores(projectRoot) {
|
|
158
|
+
const { FileStore } = require('metro-cache');
|
|
159
|
+
const sharedRoot = sharedMetroCacheRoot(projectRoot);
|
|
160
|
+
const ownRoot = projectMetroCacheRoot(projectRoot);
|
|
161
|
+
console.log('[metro-cache] SHARED transform cache root:', sharedRoot, '| PROJECT transform cache root:', ownRoot);
|
|
162
|
+
const shared = new FileStore({ root: sharedRoot });
|
|
163
|
+
const own = new FileStore({ root: ownRoot });
|
|
164
|
+
let projectSha1s;
|
|
165
|
+
try {
|
|
166
|
+
projectSha1s = projectSourceSha1s(path.resolve(projectRoot));
|
|
167
|
+
} catch (err) {
|
|
168
|
+
// Can't tell project files apart: keep every transform in the project store rather than risk sharing one.
|
|
169
|
+
console.warn('[metro-cache] project file scan failed, not sharing transforms this build:', err.message);
|
|
170
|
+
return [own];
|
|
171
|
+
}
|
|
172
|
+
const storeFor = (key) => (projectSha1s.has(key.subarray(key.length - 20).toString('hex')) ? own : shared);
|
|
173
|
+
return [{
|
|
174
|
+
get: (key) => storeFor(key).get(key),
|
|
175
|
+
set: (key, value) => storeFor(key).set(key, value),
|
|
176
|
+
clear: () => Promise.all([shared.clear(), own.clear()]),
|
|
177
|
+
}];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Container-wide build admission gate. withLock(webapp) below only serialises
|
|
181
|
+
// builds of the SAME project; two DIFFERENT projects hold different paths and so
|
|
182
|
+
// run concurrently. Each build peaks at ~1.1-2.2GB against a 2536MB cgroup cap,
|
|
183
|
+
// so two overlapping builds exhaust the container and the kernel OOM-kills one.
|
|
184
|
+
// This path is deliberately volume-global so every project contends on it.
|
|
185
|
+
function buildAdmissionPath(projectRoot) {
|
|
186
|
+
return path.join(findVolumeRoot(path.resolve(projectRoot)), '.wm-rn-cache', '.build-admission');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Shared inter-process lock (mkdirSync ensures `target` exists first, since proper-lockfile needs
|
|
190
|
+
// a real path). Used by vendor-cache.js (per cache-kind writes) and metro.script.js (per-project
|
|
191
|
+
// served-directory writes) so both don't each carry their own copy of the same retry tuning.
|
|
192
|
+
async function withLock(target, fn, opts = {}) {
|
|
193
|
+
fs.mkdirSync(target, { recursive: true });
|
|
194
|
+
const release = await lockfile.lock(target, {
|
|
195
|
+
realpath: false,
|
|
196
|
+
// proper-lockfile refreshes the lock's mtime while held and treats it as stale
|
|
197
|
+
// after `stale` ms, so a build that dies holding the lock frees it rather than
|
|
198
|
+
// blocking the container forever. Callers can widen `retries` when they may
|
|
199
|
+
// have to wait out a full cold build (PNB-scale can run tens of minutes).
|
|
200
|
+
retries: opts.retries
|
|
201
|
+
|| { retries: 30, factor: 1.2, minTimeout: 1000, maxTimeout: 10000 },
|
|
202
|
+
});
|
|
203
|
+
try {
|
|
204
|
+
return await fn();
|
|
205
|
+
} finally {
|
|
206
|
+
await release();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Kept as a named wrapper: metro.script.js imports waitForBuildHeadroom by this name.
|
|
211
|
+
const waitForBuildHeadroom = (waitMs, pollMs = 5000) =>
|
|
212
|
+
waitForHeadroom({ waitMs, pollMs, label: 'build' });
|
|
213
|
+
|
|
214
|
+
module.exports = {
|
|
215
|
+
NM_MARKER,
|
|
216
|
+
IS_NODE_MODULE,
|
|
217
|
+
WMX_MARKER,
|
|
218
|
+
IS_WMX_MODULE,
|
|
219
|
+
topLevelPackageName,
|
|
220
|
+
normalizeKey,
|
|
221
|
+
normalizeWmxKey,
|
|
222
|
+
stableIdKey,
|
|
223
|
+
findDeviceRoot,
|
|
224
|
+
findVolumeRoot,
|
|
225
|
+
containerMemoryLimitMB,
|
|
226
|
+
sharedMetroCacheRoot,
|
|
227
|
+
projectMetroCacheRoot,
|
|
228
|
+
createMetroCacheStores,
|
|
229
|
+
PROJECT_CACHE_DIR,
|
|
230
|
+
expoAssetCacheFile,
|
|
231
|
+
buildAdmissionPath,
|
|
232
|
+
containerMemoryUsedMB,
|
|
233
|
+
oomKillCount,
|
|
234
|
+
waitForBuildHeadroom,
|
|
235
|
+
parseSourceUrl,
|
|
236
|
+
withLock,
|
|
237
|
+
};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const http = require('http');
|
|
4
|
+
const https = require('https');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
const { baseJSBundle, bundleToString, sourceMapString } = require('./wm-metro-adapter');
|
|
8
|
+
|
|
9
|
+
const { NM_MARKER, IS_NODE_MODULE, normalizeKey, parseSourceUrl } = require('./module-path');
|
|
10
|
+
const { baseModeEnabled, extrasSplitEnabled, isWmxModule, computeChunkLayers } = require('./vendor-cache');
|
|
11
|
+
const BASELINE = baseModeEnabled();
|
|
12
|
+
const EXTRAS_SPLIT = extrasSplitEnabled();
|
|
13
|
+
|
|
14
|
+
const localVendorKeys = new Set();
|
|
15
|
+
const remoteManifestCache = new Map();
|
|
16
|
+
|
|
17
|
+
function fetchRemoteManifest(vendorUrl) {
|
|
18
|
+
if (remoteManifestCache.has(vendorUrl)) return remoteManifestCache.get(vendorUrl);
|
|
19
|
+
|
|
20
|
+
const promise = new Promise((resolve) => {
|
|
21
|
+
const url = `${vendorUrl}/vendor-manifest.json`;
|
|
22
|
+
const get = url.startsWith('https') ? https.get : http.get;
|
|
23
|
+
get(url, (res) => {
|
|
24
|
+
let data = '';
|
|
25
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
26
|
+
res.on('end', () => {
|
|
27
|
+
try {
|
|
28
|
+
resolve(new Set(JSON.parse(data)));
|
|
29
|
+
console.log(`[split] fetched vendor manifest from ${url} (${JSON.parse(data).length} keys)`);
|
|
30
|
+
} catch {
|
|
31
|
+
console.warn(`[split] failed to parse vendor manifest from ${url}`);
|
|
32
|
+
resolve(null);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}).on('error', (err) => {
|
|
36
|
+
console.warn(`[split] could not reach vendor server at ${url}: ${err.message}`);
|
|
37
|
+
resolve(null);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
remoteManifestCache.set(vendorUrl, promise);
|
|
42
|
+
return promise;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Metro ignore-lists every node_modules module (x_google_ignoreList), so Chrome hides the WaveMaker
|
|
46
|
+
// runtime from Sources and steps over it. Our own packages must stay debuggable.
|
|
47
|
+
const isWmRuntimeModule = (module) => /[\\/]node_modules[\\/]@wavemaker[\\/]/.test(module.path);
|
|
48
|
+
|
|
49
|
+
function buildSourceMap(preModulesForBundle, graph, options, processModuleFilter) {
|
|
50
|
+
const sortedGraphModules = [...graph.dependencies.values()].sort(
|
|
51
|
+
(a, b) => options.createModuleId(a.path) - options.createModuleId(b.path),
|
|
52
|
+
);
|
|
53
|
+
return sourceMapString([...preModulesForBundle, ...sortedGraphModules], {
|
|
54
|
+
...options,
|
|
55
|
+
excludeSource: false,
|
|
56
|
+
processModuleFilter,
|
|
57
|
+
shouldAddToIgnoreList: (module) => !isWmRuntimeModule(module)
|
|
58
|
+
&& (options.shouldAddToIgnoreList ? options.shouldAddToIgnoreList(module) : false),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Shared tail for every split kind: build the bundle with the given filter, stringify it, build its source map.
|
|
63
|
+
function emitChunk(entryPoint, preModulesForBundle, graph, options, filter, runModule) {
|
|
64
|
+
const bundle = baseJSBundle(entryPoint, preModulesForBundle, graph, {
|
|
65
|
+
...options,
|
|
66
|
+
processModuleFilter: filter,
|
|
67
|
+
...(runModule !== undefined ? { runModule } : {}),
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
code: bundleToString(bundle).code,
|
|
71
|
+
map: buildSourceMap(preModulesForBundle, graph, options, filter),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = function createSplitSerializer(opts = {}) {
|
|
76
|
+
const vendorUrl = opts.vendorUrl ?? null;
|
|
77
|
+
|
|
78
|
+
return async function splitSerializer(entryPoint, preModules, graph, options) {
|
|
79
|
+
const parsedUrl = parseSourceUrl(options.sourceUrl);
|
|
80
|
+
const split = parsedUrl?.searchParams.get('__split') ?? null;
|
|
81
|
+
|
|
82
|
+
options = { ...options, sourceUrl: undefined };
|
|
83
|
+
|
|
84
|
+
const allModules = [...graph.dependencies.values()];
|
|
85
|
+
// Chunk membership comes from the dependency graph (see computeChunkLayers): vendor requires only
|
|
86
|
+
// vendor, extras only vendor + extras. split.static.js computes it once per graph and passes it in.
|
|
87
|
+
const layers = options.wmChunkLayers ?? computeChunkLayers(graph);
|
|
88
|
+
const inVendorChunk = (m) => layers.vendor.has(m.path);
|
|
89
|
+
const inExtrasChunk = (m) => layers.extras.has(m.path);
|
|
90
|
+
const nmModules = allModules.filter(m => IS_NODE_MODULE.test(m.path));
|
|
91
|
+
const srcModules = allModules.filter(m => !IS_NODE_MODULE.test(m.path) && !isWmxModule(m.path));
|
|
92
|
+
|
|
93
|
+
if (split === 'vendor') {
|
|
94
|
+
const preModulePaths = new Set(preModules.map(m => m.path));
|
|
95
|
+
const vendorModules = allModules.filter(inVendorChunk);
|
|
96
|
+
|
|
97
|
+
localVendorKeys.clear();
|
|
98
|
+
for (const m of vendorModules) localVendorKeys.add(normalizeKey(m.path));
|
|
99
|
+
remoteManifestCache.clear();
|
|
100
|
+
|
|
101
|
+
console.log(`[split] vendor: emitting ${vendorModules.length} library modules`
|
|
102
|
+
+ (BASELINE ? ` (baseline + dependency closure; ${layers.extras.size} left for extras, `
|
|
103
|
+
+ `${layers.tainted.size} reaching project code left for user)` : '')
|
|
104
|
+
+ ` (skipping ${srcModules.length} project files)`
|
|
105
|
+
+ ` | preModules: ${preModules.length}`
|
|
106
|
+
+ ` | manifest: ${localVendorKeys.size} keys`);
|
|
107
|
+
|
|
108
|
+
const vendorFilter = (m) => preModulePaths.has(m.path) || inVendorChunk(m);
|
|
109
|
+
return emitChunk(entryPoint, preModules, graph, options, vendorFilter, false);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (split === 'extras') {
|
|
113
|
+
const preModulePaths = new Set(preModules.map(m => m.path));
|
|
114
|
+
const extrasModules = allModules.filter(inExtrasChunk);
|
|
115
|
+
|
|
116
|
+
console.log(`[split] extras: emitting ${extrasModules.length} app-specific node_modules`);
|
|
117
|
+
|
|
118
|
+
const extrasFilter = (m) => !preModulePaths.has(m.path) && inExtrasChunk(m);
|
|
119
|
+
return emitChunk(entryPoint, preModules, graph, options, extrasFilter, false);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (split === 'wmx') {
|
|
123
|
+
const preModulePaths = new Set(preModules.map(m => m.path));
|
|
124
|
+
const wmxModules = allModules.filter(m => isWmxModule(m.path));
|
|
125
|
+
|
|
126
|
+
console.log(`[split] wmx: emitting ${wmxModules.length} wmx-component module(s)`);
|
|
127
|
+
|
|
128
|
+
const wmxFilter = (m) => !preModulePaths.has(m.path) && isWmxModule(m.path);
|
|
129
|
+
return emitChunk(entryPoint, preModules, graph, options, wmxFilter, false);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (split === 'user') {
|
|
133
|
+
let vendorKeys = null;
|
|
134
|
+
if (vendorUrl) {
|
|
135
|
+
vendorKeys = await fetchRemoteManifest(vendorUrl) ?? new Set();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const extraNmModules = vendorKeys ? nmModules.filter(m => !vendorKeys.has(normalizeKey(m.path))) : [];
|
|
139
|
+
|
|
140
|
+
console.log(`[split] user: emitting ${srcModules.length} project-file modules`
|
|
141
|
+
+ (extraNmModules.length ? ` + ${extraNmModules.length} extra node_modules not in vendor` : '')
|
|
142
|
+
+ ` | skipping ${nmModules.length - extraNmModules.length} vendor node_modules`);
|
|
143
|
+
|
|
144
|
+
const modifiedKeys = options.wmModifiedKeys ?? new Set();
|
|
145
|
+
|
|
146
|
+
const userFilter = (m) => {
|
|
147
|
+
if (isWmxModule(m.path)) return false;
|
|
148
|
+
if (inVendorChunk(m) || inExtrasChunk(m)) return false;
|
|
149
|
+
if (!IS_NODE_MODULE.test(m.path)) return !modifiedKeys.has(normalizeKey(m.path));
|
|
150
|
+
// Library code that reaches project code: it cannot live in a lower layer, so it is user's.
|
|
151
|
+
if (layers.tainted.has(m.path)) return true;
|
|
152
|
+
if (!vendorKeys) return false;
|
|
153
|
+
if (vendorKeys.size === 0) return false;
|
|
154
|
+
return !vendorKeys.has(normalizeKey(m.path));
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// 'user' is reused byte-for-byte across builds, so it must never embed the __r(entry) bootstrap call.
|
|
158
|
+
return emitChunk(entryPoint, [], graph, options, userFilter, true);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (split === 'modified') {
|
|
162
|
+
const modifiedKeys = options.wmModifiedKeys ?? new Set();
|
|
163
|
+
const modifiedModules = srcModules.filter(m => modifiedKeys.has(normalizeKey(m.path)));
|
|
164
|
+
|
|
165
|
+
console.log(`[split] modified: emitting ${modifiedModules.length} changed project file(s)`);
|
|
166
|
+
|
|
167
|
+
const modifiedFilter = (m) => !IS_NODE_MODULE.test(m.path) && !isWmxModule(m.path) && modifiedKeys.has(normalizeKey(m.path));
|
|
168
|
+
return emitChunk(entryPoint, [], graph, options, modifiedFilter, false);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
console.log(`[split] full bundle: ${allModules.length} modules`
|
|
172
|
+
+ (split ? ` (unknown split="${split}", falling back to full)` : ''));
|
|
173
|
+
|
|
174
|
+
const fullFilter = options.processModuleFilter ?? (() => true);
|
|
175
|
+
return emitChunk(entryPoint, preModules, graph, options, fullFilter, undefined);
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
module.exports.getVendorManifest = () => [...localVendorKeys];
|
|
180
|
+
|
|
181
|
+
module.exports.setVendorManifest = (keys) => {
|
|
182
|
+
localVendorKeys.clear();
|
|
183
|
+
for (const k of keys) localVendorKeys.add(k);
|
|
184
|
+
};
|