@wavemaker/rn-codegen 11.16.1-rc.647845 → 11.16.2-rc.647883
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/npm-shrinkwrap.json +289 -273
- package/package-lock.json +289 -273
- package/package.json +3 -3
- package/scripts/check-deps-compat.js +554 -0
- package/src/app.generator.js +109 -70
- package/src/app.generator.js.map +1 -1
- package/src/pipeline/build-pipeline.js +19 -2
- package/src/pipeline/build-pipeline.js.map +1 -1
- package/src/pipeline/generation-store.js +43 -22
- package/src/pipeline/generation-store.js.map +1 -1
- package/src/pipeline/shared-node-modules.js +172 -13
- package/src/pipeline/shared-node-modules.js.map +1 -1
- package/src/templates/app.template +20 -0
- package/src/templates/bootstrap.template +2 -1
- package/src/templates/foundation-theme/build/android/wavemaker/components/input/epoch/date.less +8 -1
- package/src/templates/foundation-theme/build/android/wavemaker/components/input/epoch/datetime.less +8 -1
- package/src/templates/foundation-theme/build/android/wavemaker/components/input/epoch/time.less +8 -1
- package/src/templates/foundation-theme/build/android/wavemaker/components/input/number.less +14 -0
- package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/basic/button.less +2 -2
- package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/input/checkboxset.less +1 -0
- package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/input/chips.less +12 -0
- package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/input/radioset.less +1 -1
- package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/studio/input/currency.less +6 -2
- package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/tokens.light.css +3 -2
- package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/variables/button.variant.less +2 -2
- package/src/templates/foundation-theme/build/ios/wavemaker/components/input/epoch/date.less +8 -1
- package/src/templates/foundation-theme/build/ios/wavemaker/components/input/epoch/datetime.less +8 -1
- package/src/templates/foundation-theme/build/ios/wavemaker/components/input/epoch/time.less +8 -1
- package/src/templates/foundation-theme/build/ios/wavemaker/components/input/number.less +14 -0
- package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/basic/button.less +2 -2
- package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/input/checkboxset.less +1 -0
- package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/input/chips.less +12 -0
- package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/input/radioset.less +1 -1
- package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/studio/input/currency.less +6 -2
- package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/tokens.light.css +3 -2
- package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/variables/button.variant.less +2 -2
- package/src/templates/foundation-theme/dist/android/style.css +5 -4
- package/src/templates/foundation-theme/dist/android/style.js +22 -9
- package/src/templates/foundation-theme/dist/android/tokens.js +3 -2
- package/src/templates/foundation-theme/dist/ios/style.css +5 -4
- package/src/templates/foundation-theme/dist/ios/style.js +22 -9
- package/src/templates/foundation-theme/dist/ios/tokens.js +3 -2
- package/src/templates/foundation-theme/wavemaker/components/input/epoch/date.less +8 -1
- package/src/templates/foundation-theme/wavemaker/components/input/epoch/datetime.less +8 -1
- package/src/templates/foundation-theme/wavemaker/components/input/epoch/time.less +8 -1
- package/src/templates/foundation-theme/wavemaker/components/input/number.less +14 -0
- package/src/templates/foundation-theme/wavemaker/design-tokens/basic/button.less +2 -2
- package/src/templates/foundation-theme/wavemaker/design-tokens/input/checkboxset.less +1 -0
- package/src/templates/foundation-theme/wavemaker/design-tokens/input/chips.less +12 -0
- package/src/templates/foundation-theme/wavemaker/design-tokens/input/radioset.less +1 -1
- package/src/templates/foundation-theme/wavemaker/design-tokens/studio/input/currency.less +6 -2
- package/src/templates/foundation-theme/wavemaker/design-tokens/tokens.light.css +3 -2
- package/src/templates/foundation-theme/wavemaker/design-tokens/variables/button.variant.less +2 -2
- package/src/templates/package.web.json +10 -5
- package/src/templates/project/metro/metro.script.js +19 -2
- package/src/templates/project/metro/vendor-cache.js +1 -1
- package/src/templates/project/metro/wm-boundary.js +40 -28
- package/src/templates/project/metro/wm-crawl-override.js +16 -2
- package/src/templates/project/metro/wm-prebuilt.js +31 -0
- package/src/templates/project/package-lock.json +13214 -0
- package/src/templates/project/package.json +10 -5
- package/src/templates/project/wavepulse/rn2css.json +5 -0
- package/src/theme/components/input/epoch/datetime.styledef.js +5 -0
- package/src/theme/components/input/epoch/datetime.styledef.js.map +1 -1
- package/src/theme/components/input/number.styledef.js +10 -0
- package/src/theme/components/input/number.styledef.js.map +1 -1
- package/src/transpile/bind.ex.transformer.js +109 -5
- package/src/transpile/bind.ex.transformer.js.map +1 -1
- package/src/transpile/components/data/form/form-field.transformer.js +25 -1
- package/src/transpile/components/data/form/form-field.transformer.js.map +1 -1
- package/test/pipeline/build-leftovers.test.js +172 -0
- package/test/pipeline/build-leftovers.test.js.map +1 -0
- package/test/pipeline/chmod-tree.test.js +54 -0
- package/test/pipeline/chmod-tree.test.js.map +1 -0
- package/test/pipeline/crawl-override.test.js +53 -0
- package/test/pipeline/crawl-override.test.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wavemaker/rn-codegen",
|
|
3
|
-
"version": "11.16.
|
|
3
|
+
"version": "11.16.2-rc.647883",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"@types/prettier": "3.0.0",
|
|
30
30
|
"@types/proper-lockfile": "4.1.4",
|
|
31
31
|
"@types/yargs": "17.0.35",
|
|
32
|
-
"@wavemaker/custom-widgets-m3": "11.16.
|
|
33
|
-
"@wavemaker/foundation-css": "11.16.
|
|
32
|
+
"@wavemaker/custom-widgets-m3": "11.16.2-rc.647883",
|
|
33
|
+
"@wavemaker/foundation-css": "11.16.2-rc.647883",
|
|
34
34
|
"adm-zip": "0.6.1",
|
|
35
35
|
"axios": "1.20.0",
|
|
36
36
|
"clean-css": "5.3.3",
|
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*
|
|
3
|
+
* Reports (never changes) whether plugin, prefab and wmx packages fit WaveMaker's locked base; verifies rn-app locks at release.
|
|
4
|
+
*
|
|
5
|
+
* node scripts/check-deps-compat.js --base <dir> --add <name@spec> [--add ...] [--npmrc <file>]
|
|
6
|
+
*
|
|
7
|
+
* <dir> holds the base package.json and package-lock.json. Exit code 0 = all fit, 1 = some don't, 2 = usage error.
|
|
8
|
+
*/
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const os = require('os');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const crypto = require('crypto');
|
|
13
|
+
const { execFile } = require('child_process');
|
|
14
|
+
const semver = require('semver');
|
|
15
|
+
|
|
16
|
+
const NPMJS = 'https://registry.npmjs.org/';
|
|
17
|
+
// Used when the configured registry is Nexus or has no advisory API (WaveMaker's npm proxy answers 400).
|
|
18
|
+
const AUDIT_FALLBACK = process.env.WM_AUDIT_REGISTRY || NPMJS;
|
|
19
|
+
const BLOCKING_SEVERITIES = ['high', 'critical'];
|
|
20
|
+
const MAX_CANDIDATES = 40;
|
|
21
|
+
const MAX_SUGGESTION_SIMULATIONS = 5;
|
|
22
|
+
const CONCURRENCY = 3;
|
|
23
|
+
|
|
24
|
+
const hash = (...parts) => crypto.createHash('sha1').update(parts.join('\n')).digest('hex').slice(0, 16);
|
|
25
|
+
const readJson = (file) => JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
26
|
+
const pkgName = (lockKey) => lockKey.slice(lockKey.lastIndexOf('node_modules/') + 'node_modules/'.length);
|
|
27
|
+
const sameRegistry = (a, b) => a.replace(/\/+$/, '') === b.replace(/\/+$/, '');
|
|
28
|
+
// Nexus proxies npm but answers an audit with an empty report, so a Nexus project is audited on AUDIT_FALLBACK.
|
|
29
|
+
const isNexus = (registry) => /\/repository\//.test(registry);
|
|
30
|
+
|
|
31
|
+
function run(cmd, cmdArgs, cwd) {
|
|
32
|
+
return new Promise((resolve) => {
|
|
33
|
+
execFile(cmd, cmdArgs, { cwd, maxBuffer: 64 * 1024 * 1024 }, (err, stdout, stderr) => {
|
|
34
|
+
resolve({ code: err ? (err.code || 1) : 0, stdout, stderr });
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function firstErrorLines(stderr) {
|
|
40
|
+
return stderr.split('\n').filter((l) => /npm (error|ERR!)/.test(l)).slice(0, 12)
|
|
41
|
+
.map((l) => l.replace(/^npm (error|ERR!)\s?/, '')).join('\n');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function pool(items, size, fn) {
|
|
45
|
+
const results = new Array(items.length);
|
|
46
|
+
let next = 0;
|
|
47
|
+
await Promise.all(Array.from({ length: Math.min(size, items.length) }, async () => {
|
|
48
|
+
while (next < items.length) {
|
|
49
|
+
const i = next++;
|
|
50
|
+
results[i] = await fn(items[i]);
|
|
51
|
+
}
|
|
52
|
+
}));
|
|
53
|
+
return results;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// A scratch folder that sees the same registries and tokens as the project.
|
|
57
|
+
function scratchDir(prefix, npmrc) {
|
|
58
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
59
|
+
if (npmrc && fs.existsSync(npmrc)) fs.copyFileSync(npmrc, path.join(dir, '.npmrc'));
|
|
60
|
+
return dir;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// The default registry and every scope mapped to its own registry (e.g. @by on a customer's JFrog), as seen from
|
|
64
|
+
// a folder holding a copy of `npmrc`. Read once per npmrc.
|
|
65
|
+
const registriesByNpmrc = new Map();
|
|
66
|
+
async function npmRegistries(dir, npmrc) {
|
|
67
|
+
if (!registriesByNpmrc.has(npmrc)) {
|
|
68
|
+
const res = await run('npm', ['config', 'list', '--json'], dir);
|
|
69
|
+
const config = res.code === 0 ? JSON.parse(res.stdout) : {};
|
|
70
|
+
const scopes = {};
|
|
71
|
+
Object.keys(config).filter((k) => /^@[^:]+:registry$/.test(k)).forEach((k) => { scopes[k.split(':')[0]] = config[k]; });
|
|
72
|
+
registriesByNpmrc.set(npmrc, { registry: config.registry || NPMJS, scopes });
|
|
73
|
+
}
|
|
74
|
+
return registriesByNpmrc.get(npmrc);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// name -> Set of versions, for every package in a lock.
|
|
78
|
+
function lockVersions(lock) {
|
|
79
|
+
const out = new Map();
|
|
80
|
+
Object.entries(lock.packages || {}).forEach(([key, meta]) => {
|
|
81
|
+
if (!key || meta.link) return;
|
|
82
|
+
const name = meta.name || pkgName(key);
|
|
83
|
+
if (!out.has(name)) out.set(name, new Set());
|
|
84
|
+
out.get(name).add(meta.version);
|
|
85
|
+
});
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Base versions that are gone after resolving.
|
|
90
|
+
function displacedBaseVersions(baseVersions, after) {
|
|
91
|
+
const displaced = [];
|
|
92
|
+
baseVersions.forEach((versions, name) => versions.forEach((v) => {
|
|
93
|
+
if (!after.has(name) || !after.get(name).has(v)) {
|
|
94
|
+
displaced.push({ name, from: v, to: after.has(name) ? [...after.get(name)].join(', ') : 'removed' });
|
|
95
|
+
}
|
|
96
|
+
}));
|
|
97
|
+
return displaced;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Base packages that gained a copy at a version we don't ship (a custom package bringing its own react, ...).
|
|
101
|
+
function introducedBaseVersions(baseVersions, after, lock) {
|
|
102
|
+
const introduced = [];
|
|
103
|
+
baseVersions.forEach((versions, name) => (after.get(name) || new Set()).forEach((v) => {
|
|
104
|
+
if (!versions.has(v)) {
|
|
105
|
+
const paths = Object.keys(lock.packages).filter((k) => pkgName(k) === name && lock.packages[k].version === v);
|
|
106
|
+
introduced.push({ name, version: v, shipped: [...versions].join(', '), paths });
|
|
107
|
+
}
|
|
108
|
+
}));
|
|
109
|
+
return introduced;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/*
|
|
113
|
+
* High and critical advisories in `lock`. With baseLock, only packages the base doesn't ship at that version count.
|
|
114
|
+
* The configured registry is asked first, unless it is Nexus. Packages of privately hosted scopes are never sent to
|
|
115
|
+
* the public fallback, and come back as `unaudited` instead. Returns { vulns, unaudited } or { error }.
|
|
116
|
+
*/
|
|
117
|
+
async function auditLock(dir, lock, { baseLock, npmrc } = {}) {
|
|
118
|
+
const tmp = scratchDir('wm-audit-', npmrc);
|
|
119
|
+
try {
|
|
120
|
+
const { registry, scopes } = await npmRegistries(tmp, npmrc);
|
|
121
|
+
const privateScopes = Object.keys(scopes).filter((s) => !sameRegistry(scopes[s], NPMJS));
|
|
122
|
+
const isPrivate = (key) => privateScopes.some((s) => pkgName(key).startsWith(`${s}/`));
|
|
123
|
+
fs.copyFileSync(path.join(dir, 'package.json'), path.join(tmp, 'package.json'));
|
|
124
|
+
// Only entries that differ from the base are reported, so only those are sent (a few, not ~1000).
|
|
125
|
+
const changed = !baseLock ? lock : { ...lock, packages: Object.fromEntries(Object.entries(lock.packages)
|
|
126
|
+
.filter(([k, meta]) => !k || (baseLock.packages[k] || {}).version !== meta.version)) };
|
|
127
|
+
const attempt = async (target, auditedLock) => {
|
|
128
|
+
fs.writeFileSync(path.join(tmp, 'package-lock.json'), JSON.stringify(auditedLock));
|
|
129
|
+
const res = await run('npm', ['audit', '--package-lock-only', '--json', `--registry=${target}`], tmp);
|
|
130
|
+
try {
|
|
131
|
+
const report = JSON.parse(res.stdout);
|
|
132
|
+
return report.error ? null : report;
|
|
133
|
+
} catch (e) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
let unaudited = [];
|
|
138
|
+
let report = sameRegistry(registry, NPMJS) || isNexus(registry) ? null : await attempt(registry, changed);
|
|
139
|
+
if (!report) {
|
|
140
|
+
const publicLock = { ...changed, packages: {} };
|
|
141
|
+
Object.entries(changed.packages).forEach(([k, meta]) => {
|
|
142
|
+
if (k && isPrivate(k)) unaudited.push(pkgName(k));
|
|
143
|
+
else publicLock.packages[k] = meta;
|
|
144
|
+
});
|
|
145
|
+
unaudited = [...new Set(unaudited)];
|
|
146
|
+
report = await attempt(AUDIT_FALLBACK, publicLock);
|
|
147
|
+
}
|
|
148
|
+
if (!report) return { error: `no advisory service answered (${registry}, ${AUDIT_FALLBACK})` };
|
|
149
|
+
const vulns = [];
|
|
150
|
+
Object.entries(report.vulnerabilities || {}).forEach(([name, v]) => {
|
|
151
|
+
// Only direct advisories describe this package; the rest just depend on a vulnerable one.
|
|
152
|
+
const advisories = (v.via || []).filter((x) => typeof x !== 'string');
|
|
153
|
+
const paths = (v.nodes || []).filter((k) => !baseLock || (baseLock.packages[k] || {}).version !== (lock.packages[k] || {}).version);
|
|
154
|
+
if (!BLOCKING_SEVERITIES.includes(v.severity) || !advisories.length || !paths.length) return;
|
|
155
|
+
vulns.push({
|
|
156
|
+
name, version: lock.packages[paths[0]].version, range: v.range, severity: v.severity, paths,
|
|
157
|
+
// The packages that pull it in, so a nested advisory points back at the custom package.
|
|
158
|
+
requiredBy: [...new Set(Object.entries(lock.packages)
|
|
159
|
+
.filter(([k, meta]) => k && (meta.dependencies || {})[name] && paths.includes(resolveIn(lock, k, name)))
|
|
160
|
+
.map(([k]) => pkgName(k)))],
|
|
161
|
+
titles: advisories.map((x) => `${x.title} (${x.url})`)
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
return { vulns, unaudited };
|
|
165
|
+
} finally {
|
|
166
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// The top-level package a lock key sits under: node_modules/@a/b/node_modules/c -> @a/b.
|
|
171
|
+
const topPackage = (key) => (key.match(/^node_modules\/((?:@[^/]+\/)?[^/]+)/) || [])[1];
|
|
172
|
+
|
|
173
|
+
// Lock key of the copy of `name` that the package at lock key `from` loads (nearest node_modules upwards).
|
|
174
|
+
function resolveIn(lock, from, name) {
|
|
175
|
+
for (let dir = from; ; dir = dir.slice(0, Math.max(dir.lastIndexOf('/node_modules/'), 0))) {
|
|
176
|
+
const key = `${dir ? `${dir}/` : ''}node_modules/${name}`;
|
|
177
|
+
if (lock.packages[key]) return key;
|
|
178
|
+
if (!dir) return null;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Every non-prerelease version of `name` with the given fields, from whichever registry serves its scope
|
|
183
|
+
// (`name@*` would return only the latest).
|
|
184
|
+
async function npmVersions(name, fields, cwd) {
|
|
185
|
+
const res = await run('npm', ['view', `${name}@>=0.0.0`, 'version', ...fields, '--json'], cwd);
|
|
186
|
+
if (res.code !== 0) throw new Error(firstErrorLines(res.stderr) || `npm view ${name} failed`);
|
|
187
|
+
return [].concat(JSON.parse(res.stdout));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
class Checker {
|
|
191
|
+
constructor(baseDir, { npmrc } = {}) {
|
|
192
|
+
this.baseDir = path.resolve(baseDir);
|
|
193
|
+
this.npmrc = npmrc;
|
|
194
|
+
this.memo = new Map();
|
|
195
|
+
this.basePkg = readJson(path.join(this.baseDir, 'package.json'));
|
|
196
|
+
this.baseLockRaw = fs.readFileSync(path.join(this.baseDir, 'package-lock.json'), 'utf8');
|
|
197
|
+
this.baseLock = JSON.parse(this.baseLockRaw);
|
|
198
|
+
// Base deps the lock doesn't cover (file:.yalc links) are not part of the locked tree.
|
|
199
|
+
['dependencies', 'devDependencies'].forEach((s) => Object.keys(this.basePkg[s] || {}).forEach((n) => {
|
|
200
|
+
if (!this.baseLock.packages[`node_modules/${n}`]) delete this.basePkg[s][n];
|
|
201
|
+
}));
|
|
202
|
+
this.baseVersions = lockVersions(this.baseLock);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
baseTopLevelVersion(name) {
|
|
206
|
+
return (this.baseLock.packages[`node_modules/${name}`] || {}).version;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// A package WaveMaker already ships (locked top-level, or pinned in overrides).
|
|
210
|
+
providedVersion(name) {
|
|
211
|
+
const override = (this.basePkg.overrides || {})[name];
|
|
212
|
+
return this.baseTopLevelVersion(name) || (typeof override === 'string' ? override : undefined);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
once(key, compute) {
|
|
216
|
+
if (!this.memo.has(key)) this.memo.set(key, compute());
|
|
217
|
+
return this.memo.get(key);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Expo's native module versions for the locked SDK (bundledNativeModules.json).
|
|
221
|
+
async expoBundledModules() {
|
|
222
|
+
const expo = this.baseTopLevelVersion('expo');
|
|
223
|
+
if (!expo) return null;
|
|
224
|
+
return this.once(`expo-bundled-${expo}`, async () => {
|
|
225
|
+
const dir = scratchDir('wm-expo-pack-', this.npmrc);
|
|
226
|
+
try {
|
|
227
|
+
const pack = await run('npm', ['pack', `expo@${expo}`, '--silent'], dir);
|
|
228
|
+
await run('tar', ['xzf', pack.stdout.trim().split('\n').pop(), 'package/bundledNativeModules.json'], dir);
|
|
229
|
+
return readJson(path.join(dir, 'package', 'bundledNativeModules.json'));
|
|
230
|
+
} catch (e) {
|
|
231
|
+
console.warn(`Could not read Expo ${expo} bundledNativeModules.json: ${e.message}`);
|
|
232
|
+
return null;
|
|
233
|
+
} finally {
|
|
234
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async sdkMismatch(name, resolvedVersion) {
|
|
240
|
+
const range = ((await this.expoBundledModules()) || {})[name];
|
|
241
|
+
if (!range || !resolvedVersion || !semver.validRange(range)) return null;
|
|
242
|
+
return semver.satisfies(resolvedVersion, range, { includePrerelease: true }) ? null : range;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Resolve base + additions with npm (nothing is installed), then audit what was added.
|
|
246
|
+
simulate(additions) {
|
|
247
|
+
return this.once(JSON.stringify(Object.entries(additions).sort()), async () => {
|
|
248
|
+
const dir = scratchDir('wm-dep-compat-', this.npmrc);
|
|
249
|
+
try {
|
|
250
|
+
const pkg = { ...this.basePkg, dependencies: { ...this.basePkg.dependencies, ...additions } };
|
|
251
|
+
fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify(pkg, null, 2));
|
|
252
|
+
fs.writeFileSync(path.join(dir, 'package-lock.json'), this.baseLockRaw);
|
|
253
|
+
const res = await run('npm', ['install', '--package-lock-only', '--ignore-scripts', '--no-audit', '--no-fund', '--prefer-offline'], dir);
|
|
254
|
+
if (res.code !== 0) {
|
|
255
|
+
const error = firstErrorLines(res.stderr) || res.stderr.slice(0, 2000);
|
|
256
|
+
return { ok: false, error, displaced: [], introduced: [], vulns: [], resolved: {} };
|
|
257
|
+
}
|
|
258
|
+
const lock = readJson(path.join(dir, 'package-lock.json'));
|
|
259
|
+
const after = lockVersions(lock);
|
|
260
|
+
const displaced = displacedBaseVersions(this.baseVersions, after);
|
|
261
|
+
const introduced = introducedBaseVersions(this.baseVersions, after, lock);
|
|
262
|
+
const resolved = {};
|
|
263
|
+
Object.keys(additions).forEach((n) => { resolved[n] = (lock.packages[`node_modules/${n}`] || {}).version; });
|
|
264
|
+
const audit = await auditLock(dir, lock, { baseLock: this.baseLock, npmrc: this.npmrc });
|
|
265
|
+
const vulns = audit.vulns || [];
|
|
266
|
+
return {
|
|
267
|
+
ok: !displaced.length && !introduced.length && !vulns.length, error: null,
|
|
268
|
+
displaced, introduced, resolved, vulns, unaudited: audit.unaudited || [], auditError: audit.error || null
|
|
269
|
+
};
|
|
270
|
+
} finally {
|
|
271
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Requested major from the requested version up (newest first: the smallest API change), then nearer newer
|
|
277
|
+
// majors, then older releases, which rarely carry a fix.
|
|
278
|
+
closestFirst(requested) {
|
|
279
|
+
const want = semver.minVersion(semver.validRange(requested) || '*');
|
|
280
|
+
const major = semver.major(want);
|
|
281
|
+
const rank = (v) => {
|
|
282
|
+
const m = semver.major(v);
|
|
283
|
+
if (m === major) return semver.gte(v, want) ? 0 : 500;
|
|
284
|
+
return m > major ? m - major : 1000 + (major - m);
|
|
285
|
+
};
|
|
286
|
+
return (a, b) => rank(a.version) - rank(b.version) || semver.rcompare(a.version, b.version);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// A peer must accept the top-level copy we ship; a dependency can use any copy we ship (npm nests it).
|
|
290
|
+
staticallyCompatible(manifest) {
|
|
291
|
+
const accepts = (range, versions) => !semver.validRange(range)
|
|
292
|
+
|| versions.some((v) => semver.satisfies(v, range, { includePrerelease: true }));
|
|
293
|
+
return Object.entries(manifest.peerDependencies || {}).every(([dep, range]) => {
|
|
294
|
+
const shipped = this.baseTopLevelVersion(dep);
|
|
295
|
+
return !shipped || accepts(range, [shipped]);
|
|
296
|
+
}) && Object.entries(manifest.dependencies || {}).every(([dep, range]) => {
|
|
297
|
+
const shipped = this.baseVersions.get(dep);
|
|
298
|
+
return !shipped || accepts(range, [...shipped]);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
async suggest(name, requested) {
|
|
303
|
+
const sdkRange = ((await this.expoBundledModules()) || {})[name];
|
|
304
|
+
let manifests;
|
|
305
|
+
try {
|
|
306
|
+
manifests = await npmVersions(name, ['deprecated', 'dependencies', 'peerDependencies', 'dist-tags'], this.baseDir);
|
|
307
|
+
} catch (e) {
|
|
308
|
+
return { error: e.message };
|
|
309
|
+
}
|
|
310
|
+
const latest = (manifests[0] || {})['dist-tags']?.latest;
|
|
311
|
+
const candidates = manifests
|
|
312
|
+
.filter((m) => semver.valid(m.version) && !m.deprecated)
|
|
313
|
+
.filter((m) => !sdkRange || !semver.validRange(sdkRange) || semver.satisfies(m.version, sdkRange))
|
|
314
|
+
.sort(this.closestFirst(requested))
|
|
315
|
+
.slice(0, MAX_CANDIDATES)
|
|
316
|
+
.filter((m) => this.staticallyCompatible(m))
|
|
317
|
+
.slice(0, MAX_SUGGESTION_SIMULATIONS);
|
|
318
|
+
// Closest first, a few at a time in parallel.
|
|
319
|
+
for (let i = 0; i < candidates.length; i += CONCURRENCY) {
|
|
320
|
+
const batch = candidates.slice(i, i + CONCURRENCY);
|
|
321
|
+
const sims = await pool(batch, CONCURRENCY, (m) => this.simulate({ [name]: m.version }));
|
|
322
|
+
const fit = batch.find((m, j) => sims[j].ok);
|
|
323
|
+
if (fit) return { version: fit.version, latest };
|
|
324
|
+
}
|
|
325
|
+
return { version: null, latest };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
async check(custom) {
|
|
329
|
+
// A package WaveMaker already ships keeps WaveMaker's version only if the requested spec accepts it.
|
|
330
|
+
const provided = Object.keys(custom).filter((n) => this.providedVersion(n));
|
|
331
|
+
const report = await this.checkNew(Object.fromEntries(Object.entries(custom).filter(([n]) => !provided.includes(n))));
|
|
332
|
+
const shipped = provided.map((n) => {
|
|
333
|
+
const version = this.providedVersion(n);
|
|
334
|
+
const spec = custom[n].version;
|
|
335
|
+
const keeps = !semver.validRange(spec) || semver.satisfies(version, spec, { includePrerelease: true });
|
|
336
|
+
return { name: n, ...custom[n], ok: keeps, provided: version };
|
|
337
|
+
});
|
|
338
|
+
report.packages = shipped.concat(report.packages);
|
|
339
|
+
report.ok = report.ok && shipped.every((p) => p.ok);
|
|
340
|
+
return report;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
async checkNew(custom) {
|
|
344
|
+
const names = Object.keys(custom);
|
|
345
|
+
if (!names.length) return { ok: true, packages: [] };
|
|
346
|
+
const combined = await this.simulate(Object.fromEntries(names.map((n) => [n, custom[n].version])));
|
|
347
|
+
if (combined.ok && (await Promise.all(names.map((n) => this.sdkMismatch(n, combined.resolved[n])))).every((r) => !r)) {
|
|
348
|
+
return { ok: true, combined, packages: names.map((n) => ({ name: n, ...custom[n], resolved: combined.resolved[n], ok: true })) };
|
|
349
|
+
}
|
|
350
|
+
// Advisories and extra copies name their package; anything else is simulated per package.
|
|
351
|
+
const owns = (n) => (p) => topPackage(p) === n;
|
|
352
|
+
const ownProblems = (n) => ({
|
|
353
|
+
vulns: (combined.vulns || []).filter((v) => v.paths.some(owns(n)) || (v.requiredBy || []).includes(n)),
|
|
354
|
+
introduced: (combined.introduced || []).filter((d) => d.paths.some(owns(n)))
|
|
355
|
+
});
|
|
356
|
+
const items = [...(combined.vulns || []), ...(combined.introduced || [])];
|
|
357
|
+
const attributable = !combined.error && !(combined.displaced || []).length
|
|
358
|
+
&& items.every((i) => names.some((n) => i.paths.some(owns(n)) || (i.requiredBy || []).includes(n)));
|
|
359
|
+
const packages = await pool(names, CONCURRENCY, async (n) => {
|
|
360
|
+
const sim = attributable
|
|
361
|
+
? { ...combined, ...ownProblems(n), displaced: [], resolved: combined.resolved }
|
|
362
|
+
: await this.simulate({ [n]: custom[n].version });
|
|
363
|
+
if (attributable) sim.ok = !sim.vulns.length && !sim.introduced.length;
|
|
364
|
+
const sdkRange = await this.sdkMismatch(n, sim.resolved[n]);
|
|
365
|
+
const entry = { name: n, ...custom[n], ...sim, resolved: sim.resolved[n], sdkRange, ok: sim.ok && !sdkRange };
|
|
366
|
+
// A tarball has no other versions to suggest.
|
|
367
|
+
if (!entry.ok && !custom[n].version.startsWith('file:')) entry.suggestion = await this.suggest(n, custom[n].version);
|
|
368
|
+
return entry;
|
|
369
|
+
});
|
|
370
|
+
return { ok: false, combinedOnly: packages.every((p) => p.ok), combined, packages };
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const printProblems = (r, indent) => {
|
|
375
|
+
if (r.error) console.log(r.error.split('\n').map((l) => indent + l).join('\n'));
|
|
376
|
+
if (r.sdkRange) console.log(`${indent}not built for this Expo SDK: it needs ${r.sdkRange}`);
|
|
377
|
+
(r.vulns || []).slice(0, 10).forEach((v) => console.log(`${indent}${v.severity} advisory in ${v.name}@${v.version}`
|
|
378
|
+
+ `${(v.requiredBy || []).length ? ` (required by ${v.requiredBy.join(', ')})` : ''}: ${v.titles[0]}`));
|
|
379
|
+
(r.displaced || []).slice(0, 10).forEach((d) => console.log(`${indent}would change locked ${d.name} ${d.from} -> ${d.to}`));
|
|
380
|
+
(r.introduced || []).slice(0, 10).forEach((d) => console.log(`${indent}brings its own ${d.name}@${d.version} (we ship ${d.shipped}) at ${d.paths.join(', ')}`));
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
function printReport(report) {
|
|
384
|
+
const line = '-'.repeat(72);
|
|
385
|
+
console.log(`${line}\nCustom package report (nothing is changed or installed)\n${line}`);
|
|
386
|
+
report.packages.forEach((p) => {
|
|
387
|
+
const label = `${p.name}@${p.version}`.padEnd(44);
|
|
388
|
+
if (p.provided) {
|
|
389
|
+
console.log(`${p.ok ? 'OK ' : 'WARN'} ${label} [${p.source}] WaveMaker ships ${p.provided}`
|
|
390
|
+
+ (p.ok ? '' : `; this spec replaces it, use ${p.provided} to keep the tested version`));
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
console.log(`${p.ok ? 'OK ' : 'WARN'} ${label} [${p.source}]${p.resolved ? ` -> ${p.resolved}` : ''}`);
|
|
394
|
+
if (p.ok) return;
|
|
395
|
+
printProblems(p, ' ');
|
|
396
|
+
const s = p.suggestion;
|
|
397
|
+
if (!s) return;
|
|
398
|
+
if (s.error) console.log(` could not look up versions: ${s.error}`);
|
|
399
|
+
else if (s.version) console.log(` suggested: ${p.name}@${s.version} keeps the locked versions and has no high/critical advisory`);
|
|
400
|
+
else console.log(` no compatible, advisory-free version among the closest releases (latest is ${s.latest})`);
|
|
401
|
+
});
|
|
402
|
+
if (!report.ok && report.packages.every((p) => p.ok)) {
|
|
403
|
+
console.log('\nEach package fits on its own, but together they do not:');
|
|
404
|
+
printProblems(report.combined, ' ');
|
|
405
|
+
}
|
|
406
|
+
const audited = [report.combined || {}, ...report.packages];
|
|
407
|
+
const unaudited = [...new Set(audited.flatMap((r) => r.unaudited || []))];
|
|
408
|
+
const auditError = audited.map((r) => r.auditError).find(Boolean);
|
|
409
|
+
if (unaudited.length) console.log(`Not audited (private registry without an advisory service): ${unaudited.join(', ')}`);
|
|
410
|
+
if (auditError) console.log(`Security advisories could not be checked: ${auditError}`);
|
|
411
|
+
console.log(line);
|
|
412
|
+
console.log(report.ok ? 'All custom packages fit the locked base.'
|
|
413
|
+
: 'Packages marked WARN are installed as requested and may not work with the locked base, or carry advisories.');
|
|
414
|
+
console.log('To hide this report, set "dependencyCheck": false in wm_rn_config.json.');
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// --- Generated app integration (app.generator.ts) ---
|
|
418
|
+
|
|
419
|
+
// Lives in the generated folder, so it goes away with it.
|
|
420
|
+
const BASE_LOCK_MARKER = '.wm-base-lock.json';
|
|
421
|
+
const LEGACY_CACHE_DIR = path.join(os.homedir(), '.wm', 'dep-compat-cache');
|
|
422
|
+
|
|
423
|
+
/*
|
|
424
|
+
* Copies the base (rn-app) lock into the project when it has none, or when the base changed since it was copied
|
|
425
|
+
* (a codegen upgrade); otherwise an existing app would keep its old lock. Returns true when it was (re)copied.
|
|
426
|
+
*/
|
|
427
|
+
function syncBaseLock(projectPath, baseLockPath) {
|
|
428
|
+
// Earlier codegen versions kept check results here; nothing reads them any more.
|
|
429
|
+
try {
|
|
430
|
+
fs.rmSync(LEGACY_CACHE_DIR, { recursive: true, force: true });
|
|
431
|
+
} catch (e) {
|
|
432
|
+
console.warn(`[deps] could not remove ${LEGACY_CACHE_DIR}: ${e.message}`);
|
|
433
|
+
}
|
|
434
|
+
if (!baseLockPath || !fs.existsSync(baseLockPath)) return false;
|
|
435
|
+
const projectLock = path.join(projectPath, 'package-lock.json');
|
|
436
|
+
const marker = path.join(projectPath, BASE_LOCK_MARKER);
|
|
437
|
+
const baseHash = hash(fs.readFileSync(baseLockPath, 'utf8'));
|
|
438
|
+
if (fs.existsSync(projectLock) && fs.existsSync(marker) && readJson(marker).baseHash === baseHash) return false;
|
|
439
|
+
if (fs.existsSync(projectLock)) console.log(`[deps] base lock changed (${baseLockPath}), replacing the project's package-lock.json`);
|
|
440
|
+
fs.copyFileSync(baseLockPath, projectLock);
|
|
441
|
+
fs.writeFileSync(marker, JSON.stringify({ baseLockPath, baseHash }));
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// Logs the report for every project dependency the base doesn't pin; never changes package.json or stops the build.
|
|
446
|
+
async function reportCustomDependencies(projectPath, { baseDir, ownScope }) {
|
|
447
|
+
try {
|
|
448
|
+
const pkg = readJson(path.join(projectPath, 'package.json'));
|
|
449
|
+
const checker = new Checker(baseDir, { npmrc: path.join(projectPath, '.npmrc') });
|
|
450
|
+
const custom = {};
|
|
451
|
+
const skipped = [];
|
|
452
|
+
Object.entries(pkg.dependencies || {}).forEach(([name, spec]) => {
|
|
453
|
+
if (checker.baseTopLevelVersion(name) === spec || (ownScope && name.startsWith(`${ownScope}/`))) return;
|
|
454
|
+
const tarball = spec.startsWith('file:') && path.resolve(projectPath, spec.slice(5));
|
|
455
|
+
if (tarball && fs.existsSync(tarball)) custom[name] = { version: `file:${tarball}`, source: 'project' };
|
|
456
|
+
else if (!tarball && (semver.validRange(spec) || /^[a-z][\w.-]*$/i.test(spec))) custom[name] = { version: spec, source: 'project' };
|
|
457
|
+
else skipped.push(`${name}@${spec}`);
|
|
458
|
+
});
|
|
459
|
+
if (skipped.length) console.log(`[deps] not checked (not a registry version or a missing file): ${skipped.join(', ')}`);
|
|
460
|
+
if (!Object.keys(custom).length) return;
|
|
461
|
+
console.log(`[deps] checking ${Object.keys(custom).length} custom package(s) against ${baseDir}/package-lock.json`);
|
|
462
|
+
printReport(await checker.check(custom));
|
|
463
|
+
} catch (e) {
|
|
464
|
+
console.warn(`[deps] custom package report skipped: ${e.message}`);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// --- Release build (scripts/build.js generateRnApp) ---
|
|
469
|
+
|
|
470
|
+
// The smallest release after `current` in its major that is outside the vulnerable range, or null.
|
|
471
|
+
async function safeVersionInMajor(name, current, vulnerableRange, cwd) {
|
|
472
|
+
try {
|
|
473
|
+
return (await npmVersions(name, [], cwd)).map((m) => m.version || m)
|
|
474
|
+
.filter((v) => semver.valid(v) && semver.gt(v, current) && semver.major(v) === semver.major(current) && !semver.satisfies(v, vulnerableRange))
|
|
475
|
+
.sort(semver.compare)[0] || null;
|
|
476
|
+
} catch (e) {
|
|
477
|
+
return null;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/*
|
|
482
|
+
* An rn-app lock resolved on top of the template lock must keep every pinned version and bring no high/critical
|
|
483
|
+
* advisory. Fails with the version to pin; WM_ALLOW_AUDIT_HIGH=1 turns remaining advisories into a warning.
|
|
484
|
+
*/
|
|
485
|
+
async function verifyRnAppLock(dir, baseLockPath) {
|
|
486
|
+
const baseLock = readJson(baseLockPath);
|
|
487
|
+
const lock = readJson(path.join(dir, 'package-lock.json'));
|
|
488
|
+
// A package that is gone entirely was removed on purpose (generateRnApp drops a few devDependencies).
|
|
489
|
+
const displaced = displacedBaseVersions(lockVersions(baseLock), lockVersions(lock)).filter((d) => d.to !== 'removed');
|
|
490
|
+
if (displaced.length) {
|
|
491
|
+
throw new Error(`Resolving ${dir}/package.json changed versions pinned in ${baseLockPath}:\n`
|
|
492
|
+
+ displaced.map((d) => ` ${d.name} ${d.from} -> ${d.to}`).join('\n')
|
|
493
|
+
+ '\nRegenerate the template package-lock.json or pin the package that pulled them in.');
|
|
494
|
+
}
|
|
495
|
+
const audit = await auditLock(dir, lock, { baseLock, npmrc: path.join(dir, '.npmrc') });
|
|
496
|
+
if (audit.error) {
|
|
497
|
+
console.warn(`Could not check ${dir}/package-lock.json for advisories: ${audit.error}`);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
if (audit.unaudited.length) console.warn(`Not audited (private registry): ${audit.unaudited.join(', ')}`);
|
|
501
|
+
if (!audit.vulns.length) return;
|
|
502
|
+
const lines = await Promise.all(audit.vulns.map(async (v) => {
|
|
503
|
+
const safe = await safeVersionInMajor(v.name, v.version, v.range, dir);
|
|
504
|
+
return ` ${v.severity} ${v.name}@${v.version} (${v.paths[0]}): ${v.titles[0]}\n `
|
|
505
|
+
+ (safe ? `fix: add "${v.name}": "${safe}" to overrides in src/templates/project/package.json`
|
|
506
|
+
: `no fixed release in ${semver.major(v.version)}.x: the package that depends on it must be upgraded`);
|
|
507
|
+
}));
|
|
508
|
+
const message = `${dir}/package-lock.json has high/critical advisories:\n${lines.join('\n')}`;
|
|
509
|
+
if (process.env.WM_ALLOW_AUDIT_HIGH !== '1') throw new Error(`${message}\nPin a fixed version, or set WM_ALLOW_AUDIT_HIGH=1.`);
|
|
510
|
+
console.warn(`WARNING (WM_ALLOW_AUDIT_HIGH=1) ${message}`);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function parseArgs(argv) {
|
|
514
|
+
const args = { add: [] };
|
|
515
|
+
for (let i = 0; i < argv.length; i++) {
|
|
516
|
+
const a = argv[i];
|
|
517
|
+
if (a === '--base') args.base = argv[++i];
|
|
518
|
+
else if (a === '--add') args.add.push(argv[++i]);
|
|
519
|
+
else if (a === '--npmrc') args.npmrc = argv[++i];
|
|
520
|
+
else if (a === '--json') args.json = argv[++i];
|
|
521
|
+
}
|
|
522
|
+
return args;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
async function main() {
|
|
526
|
+
const args = parseArgs(process.argv.slice(2));
|
|
527
|
+
if (!args.base) {
|
|
528
|
+
console.error('Missing --base <dir containing package.json and package-lock.json>');
|
|
529
|
+
process.exit(2);
|
|
530
|
+
}
|
|
531
|
+
const custom = {};
|
|
532
|
+
args.add.forEach((spec) => {
|
|
533
|
+
const at = spec.lastIndexOf('@');
|
|
534
|
+
const [name, version] = at > 0 ? [spec.slice(0, at), spec.slice(at + 1)] : [spec, 'latest'];
|
|
535
|
+
custom[name] = { version, source: 'custom' };
|
|
536
|
+
});
|
|
537
|
+
if (!Object.keys(custom).length) {
|
|
538
|
+
console.log('No custom packages to check.');
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
const report = await new Checker(args.base, { npmrc: args.npmrc }).check(custom);
|
|
542
|
+
printReport(report);
|
|
543
|
+
if (args.json) fs.writeFileSync(args.json, JSON.stringify(report, null, 2));
|
|
544
|
+
process.exit(report.ok ? 0 : 1);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (require.main === module) {
|
|
548
|
+
main().catch((e) => {
|
|
549
|
+
console.error(e.stack || e.message);
|
|
550
|
+
process.exit(2);
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
module.exports = { Checker, printReport, reportCustomDependencies, syncBaseLock, verifyRnAppLock };
|