react-native-update-cli 2.24.2 → 2.26.0
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/README.md +12 -5
- package/README.zh-CN.md +12 -5
- package/cli.json +7 -1
- package/lib/api.d.ts +2 -0
- package/lib/api.js +63 -18
- package/lib/app.js +25 -3
- package/lib/bin.js +39 -45
- package/lib/bundle-runner.d.ts +45 -1
- package/lib/bundle-runner.js +303 -34
- package/lib/bundle.d.ts +1 -1
- package/lib/bundle.js +23 -7
- package/lib/commands.d.ts +6 -0
- package/lib/commands.js +65 -0
- package/lib/locales/en.d.ts +7 -14
- package/lib/locales/en.js +10 -17
- package/lib/locales/zh.d.ts +7 -13
- package/lib/locales/zh.js +10 -16
- package/lib/package.js +4 -0
- package/lib/provider.d.ts +1 -1
- package/lib/provider.js +3 -1
- package/lib/symbolicate.js +7 -2
- package/lib/types.d.ts +1 -0
- package/lib/user.js +6 -0
- package/lib/utils/add-gitignore.js +7 -1
- package/lib/utils/dep-versions.d.ts +7 -0
- package/lib/utils/dep-versions.js +78 -26
- package/lib/utils/git.js +9 -6
- package/lib/utils/hbcTransform.d.ts +15 -0
- package/lib/utils/hbcTransform.js +22 -0
- package/lib/utils/hermes-base.d.ts +61 -6
- package/lib/utils/hermes-base.js +328 -46
- package/lib/utils/hermes-literals.d.ts +51 -0
- package/lib/utils/hermes-literals.js +210 -0
- package/lib/utils/i18n.d.ts +5 -0
- package/lib/utils/i18n.js +14 -1
- package/lib/utils/index.d.ts +2 -1
- package/lib/utils/index.js +9 -4
- package/lib/utils/latest-version/index.js +8 -0
- package/lib/utils/runtime.d.ts +21 -0
- package/lib/utils/runtime.js +138 -5
- package/lib/utils/zip-range.js +3 -2
- package/lib/versions.js +14 -4
- package/package.json +6 -3
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -17
- package/src/api.ts +0 -470
- package/src/app.ts +0 -241
- package/src/auto-update.ts +0 -647
- package/src/bin-cresc.ts +0 -8
- package/src/bin.ts +0 -115
- package/src/bundle-pack.ts +0 -61
- package/src/bundle-runner.ts +0 -1430
- package/src/bundle.ts +0 -371
- package/src/cache.ts +0 -20
- package/src/diff.ts +0 -1010
- package/src/exports.ts +0 -17
- package/src/index.ts +0 -1
- package/src/install.ts +0 -50
- package/src/locales/en.ts +0 -257
- package/src/locales/zh.ts +0 -234
- package/src/native-package.ts +0 -338
- package/src/package.ts +0 -482
- package/src/provider.ts +0 -294
- package/src/symbolicate.ts +0 -164
- package/src/types.ts +0 -150
- package/src/user.ts +0 -39
- package/src/utils/add-gitignore.ts +0 -35
- package/src/utils/app-info-parser/aab.ts +0 -241
- package/src/utils/app-info-parser/apk.ts +0 -92
- package/src/utils/app-info-parser/app.ts +0 -7
- package/src/utils/app-info-parser/index.ts +0 -54
- package/src/utils/app-info-parser/ipa.ts +0 -109
- package/src/utils/app-info-parser/resource-finder.ts +0 -508
- package/src/utils/app-info-parser/utils.ts +0 -161
- package/src/utils/app-info-parser/xml-parser/binary.ts +0 -693
- package/src/utils/app-info-parser/xml-parser/manifest.ts +0 -228
- package/src/utils/app-info-parser/zip.ts +0 -108
- package/src/utils/check-lockfile.ts +0 -93
- package/src/utils/check-plugin.ts +0 -38
- package/src/utils/command-result.ts +0 -24
- package/src/utils/constants.ts +0 -25
- package/src/utils/dep-versions.ts +0 -83
- package/src/utils/git.ts +0 -71
- package/src/utils/hbcTransform.ts +0 -649
- package/src/utils/hermes-base.ts +0 -1137
- package/src/utils/http-helper.ts +0 -152
- package/src/utils/i18n.ts +0 -39
- package/src/utils/index.ts +0 -698
- package/src/utils/latest-version/index.ts +0 -573
- package/src/utils/options.ts +0 -78
- package/src/utils/plugin-config.ts +0 -32
- package/src/utils/runtime.ts +0 -187
- package/src/utils/slim-sourcemap.ts +0 -105
- package/src/utils/zip-entries.ts +0 -209
- package/src/utils/zip-options.ts +0 -178
- package/src/utils/zip-range.ts +0 -727
- package/src/utils/zip-raw-writer.ts +0 -247
- package/src/versions.ts +0 -892
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LiteralResolver } from './hermes-literals';
|
|
1
2
|
export type HermesBaseOption = 'auto' | 'none' | string;
|
|
2
3
|
/**
|
|
3
4
|
* The base cannot be obtained whatever the transport or how often it is
|
|
@@ -20,11 +21,27 @@ export interface HermesBaseSelection {
|
|
|
20
21
|
hash?: string;
|
|
21
22
|
source: 'cache' | 'download' | 'local' | 'latest-version' | 'native-package';
|
|
22
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* What became of the base for this build, as reported to the server:
|
|
26
|
+
* - `used`: compiled with -base-bytecode (and, when verification was on,
|
|
27
|
+
* the disassembly matched a plain compile)
|
|
28
|
+
* - `rejected`: the disassembly differed from a plain compile; base dropped
|
|
29
|
+
* - `dump-failed`: the check could not run (dump or plain compile failed);
|
|
30
|
+
* base dropped
|
|
31
|
+
* - `none`: no base (none selected, disabled, or the base compile failed)
|
|
32
|
+
*/
|
|
33
|
+
export type HermesBaseOutcome = 'used' | 'rejected' | 'dump-failed' | 'none';
|
|
34
|
+
/** the server column is VARCHAR(500); it truncates too, this just saves bytes */
|
|
35
|
+
export declare const HERMES_BASE_DETAIL_MAX_CHARS = 500;
|
|
23
36
|
/** Metadata attached to version/create so the server can track the chain. */
|
|
24
37
|
export interface HermesBaseMeta {
|
|
25
38
|
bytecodeVersion: number | null;
|
|
26
39
|
baseVersionId: number | null;
|
|
27
40
|
baseHash: string | null;
|
|
41
|
+
/** absent (never null) when the bundle step did not run hermesc */
|
|
42
|
+
hermesBaseOutcome?: HermesBaseOutcome;
|
|
43
|
+
/** first difference / failure reason; absent when there is none */
|
|
44
|
+
hermesBaseDetail?: string;
|
|
28
45
|
}
|
|
29
46
|
/**
|
|
30
47
|
* Hermes V1 (static_h) builds before 2025-07-11 carried a delta-mode bug when a
|
|
@@ -149,19 +166,57 @@ export interface ResolveHermesBaseParams {
|
|
|
149
166
|
*/
|
|
150
167
|
export declare function resolveHermesBase(params: ResolveHermesBaseParams): Promise<HermesBaseSelection | null>;
|
|
151
168
|
export declare function hermescArgsWithBase(baseArgs: string[], basePath: string | null): string[];
|
|
152
|
-
export declare function hermesBaseMeta(selection: HermesBaseSelection | null, bytecodeVersion: number | null
|
|
169
|
+
export declare function hermesBaseMeta(selection: HermesBaseSelection | null, bytecodeVersion: number | null, check?: {
|
|
170
|
+
outcome: HermesBaseOutcome;
|
|
171
|
+
detail?: string;
|
|
172
|
+
}): HermesBaseMeta;
|
|
173
|
+
/** one line, at most HERMES_BASE_DETAIL_MAX_CHARS code points; '' when empty */
|
|
174
|
+
export declare function truncateHermesBaseDetail(detail: string | undefined): string;
|
|
153
175
|
/**
|
|
154
176
|
* Normalize one disassembly line so that a delta-mode compile and a plain
|
|
155
177
|
* compile of the same source compare equal: string IDs are renumbered, literal
|
|
156
178
|
* buffers are laid out differently (offsets, short/long variants), and jump
|
|
157
179
|
* distances follow instruction widths. Everything else must match exactly.
|
|
158
180
|
*/
|
|
159
|
-
|
|
181
|
+
/** separates rendered literal entries inside one normalized line */
|
|
182
|
+
export declare const LITERAL_SEPARATOR = "\u001F";
|
|
183
|
+
export declare function normalizeDisassemblyLine(line: string, strings: Map<number, string>, literals?: LiteralResolver): string | null;
|
|
184
|
+
/** How an equivalence check ended. */
|
|
185
|
+
export type HermesEquivalenceStatus = 'equivalent' | 'different' | 'dump-failed';
|
|
186
|
+
export interface HermesEquivalenceResult {
|
|
187
|
+
status: HermesEquivalenceStatus;
|
|
188
|
+
/**
|
|
189
|
+
* one line for the log: where the first difference is (function, line,
|
|
190
|
+
* both sides) or why a dump could not be read
|
|
191
|
+
*/
|
|
192
|
+
detail?: string;
|
|
193
|
+
/** functions compared on both sides */
|
|
194
|
+
functions: number;
|
|
195
|
+
/**
|
|
196
|
+
* `instruction`: literals decoded from the binary buffers at each
|
|
197
|
+
* New*WithBuffer instruction (HBC v87–96); `buffer`: the dumped buffers
|
|
198
|
+
* compared as a whole (unknown layout, e.g. v98)
|
|
199
|
+
*/
|
|
200
|
+
literals?: 'instruction' | 'buffer';
|
|
201
|
+
}
|
|
202
|
+
export interface HermesEquivalenceOptions {
|
|
203
|
+
/** write each side's raw disassembly here (bug reports) */
|
|
204
|
+
dumpTo?: {
|
|
205
|
+
withBase: string;
|
|
206
|
+
plain: string;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
160
209
|
/**
|
|
161
|
-
* Compare two HBC files by disassembly (see normalizeDisassemblyLine)
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* the
|
|
210
|
+
* Compare two HBC files by disassembly (see normalizeDisassemblyLine): the
|
|
211
|
+
* literal buffers by content, then function by function. `-b` forces hermesc
|
|
212
|
+
* to treat inputs as bytecode whatever their extension. Both dumps are
|
|
213
|
+
* consumed as streams so the ~100 MB of text never touches the disk (unless
|
|
214
|
+
* `dumpTo` asks for it). A dump process that fails or ends early is reported
|
|
215
|
+
* as `dump-failed`, never as a difference: the two cases need different
|
|
216
|
+
* follow-ups. The detail names the first difference so a rejected base can be
|
|
217
|
+
* turned into a normalization rule or a bug report.
|
|
165
218
|
*/
|
|
219
|
+
export declare function compareHermesBytecode(hermesCommand: string, withBase: string, plain: string, options?: HermesEquivalenceOptions): Promise<HermesEquivalenceResult>;
|
|
220
|
+
/** Resolves true when equivalent; see compareHermesBytecode for the details. */
|
|
166
221
|
export declare function verifyHermesBaseEquivalence(hermesCommand: string, withBase: string, plain: string): Promise<boolean>;
|
|
167
222
|
export {};
|
package/lib/utils/hermes-base.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.DEFAULT_CACHE_MAX_FILES = exports.DEFAULT_CACHE_MAX_BYTES = exports.BUNDLE_ENTRY_NAMES = exports.MIN_HERMES_COMPILER_COMMITLY_DATE = exports.MIN_HERMES_COMPILER_BUILD = exports.BundleHashMismatchError = exports.PermanentBaseError = void 0;
|
|
39
|
+
exports.LITERAL_SEPARATOR = exports.DEFAULT_CACHE_MAX_FILES = exports.DEFAULT_CACHE_MAX_BYTES = exports.BUNDLE_ENTRY_NAMES = exports.MIN_HERMES_COMPILER_COMMITLY_DATE = exports.MIN_HERMES_COMPILER_BUILD = exports.HERMES_BASE_DETAIL_MAX_CHARS = exports.BundleHashMismatchError = exports.PermanentBaseError = void 0;
|
|
40
40
|
exports.classifyHermesCommand = classifyHermesCommand;
|
|
41
41
|
exports.sha256Hex = sha256Hex;
|
|
42
42
|
exports.sha256File = sha256File;
|
|
@@ -58,7 +58,9 @@ exports.fetchBaseBundle = fetchBaseBundle;
|
|
|
58
58
|
exports.resolveHermesBase = resolveHermesBase;
|
|
59
59
|
exports.hermescArgsWithBase = hermescArgsWithBase;
|
|
60
60
|
exports.hermesBaseMeta = hermesBaseMeta;
|
|
61
|
+
exports.truncateHermesBaseDetail = truncateHermesBaseDetail;
|
|
61
62
|
exports.normalizeDisassemblyLine = normalizeDisassemblyLine;
|
|
63
|
+
exports.compareHermesBytecode = compareHermesBytecode;
|
|
62
64
|
exports.verifyHermesBaseEquivalence = verifyHermesBaseEquivalence;
|
|
63
65
|
// Hermes `-base-bytecode` (delta optimizing mode) support.
|
|
64
66
|
//
|
|
@@ -79,7 +81,9 @@ const stream_1 = require("stream");
|
|
|
79
81
|
const promises_1 = require("stream/promises");
|
|
80
82
|
const constants_1 = require("./constants");
|
|
81
83
|
const hbcTransform_1 = require("./hbcTransform");
|
|
84
|
+
const hermes_literals_1 = require("./hermes-literals");
|
|
82
85
|
const i18n_1 = require("./i18n");
|
|
86
|
+
const runtime_1 = require("./runtime");
|
|
83
87
|
const zip_entries_1 = require("./zip-entries");
|
|
84
88
|
const zip_range_1 = require("./zip-range");
|
|
85
89
|
/**
|
|
@@ -102,6 +106,8 @@ const FETCH_HEADERS_TIMEOUT_MS = 30_000;
|
|
|
102
106
|
const STREAM_IDLE_TIMEOUT_MS = 60_000;
|
|
103
107
|
/** cachePut leftovers (`<hash>.<pid>.tmp`) older than this are evicted */
|
|
104
108
|
const STALE_CACHE_TMP_MS = 60 * 60 * 1000;
|
|
109
|
+
/** the server column is VARCHAR(500); it truncates too, this just saves bytes */
|
|
110
|
+
exports.HERMES_BASE_DETAIL_MAX_CHARS = 500;
|
|
105
111
|
// ---------------------------------------------------------------------------
|
|
106
112
|
// hermesc gating
|
|
107
113
|
// ---------------------------------------------------------------------------
|
|
@@ -492,7 +498,7 @@ async function downloadToFile(url, destination) {
|
|
|
492
498
|
const headersTimer = setTimeout(() => controller.abort(new Error('timeout waiting for response')), FETCH_HEADERS_TIMEOUT_MS);
|
|
493
499
|
let response;
|
|
494
500
|
try {
|
|
495
|
-
response = await
|
|
501
|
+
response = await (0, runtime_1.webFetch)(url, { signal: controller.signal });
|
|
496
502
|
}
|
|
497
503
|
finally {
|
|
498
504
|
clearTimeout(headersTimer);
|
|
@@ -795,12 +801,27 @@ async function retryOnce(action) {
|
|
|
795
801
|
function hermescArgsWithBase(baseArgs, basePath) {
|
|
796
802
|
return basePath ? [...baseArgs, `-base-bytecode=${basePath}`] : baseArgs;
|
|
797
803
|
}
|
|
798
|
-
function hermesBaseMeta(selection, bytecodeVersion) {
|
|
799
|
-
|
|
804
|
+
function hermesBaseMeta(selection, bytecodeVersion, check) {
|
|
805
|
+
const meta = {
|
|
800
806
|
bytecodeVersion,
|
|
801
807
|
baseVersionId: selection?.versionId ?? null,
|
|
802
808
|
baseHash: selection?.hash ?? null,
|
|
803
809
|
};
|
|
810
|
+
if (check) {
|
|
811
|
+
meta.hermesBaseOutcome = check.outcome;
|
|
812
|
+
const detail = truncateHermesBaseDetail(check.detail);
|
|
813
|
+
if (detail)
|
|
814
|
+
meta.hermesBaseDetail = detail;
|
|
815
|
+
}
|
|
816
|
+
return meta;
|
|
817
|
+
}
|
|
818
|
+
/** one line, at most HERMES_BASE_DETAIL_MAX_CHARS code points; '' when empty */
|
|
819
|
+
function truncateHermesBaseDetail(detail) {
|
|
820
|
+
const compact = (detail ?? '').replace(/\s+/g, ' ').trim();
|
|
821
|
+
const chars = Array.from(compact);
|
|
822
|
+
return chars.length <= exports.HERMES_BASE_DETAIL_MAX_CHARS
|
|
823
|
+
? compact
|
|
824
|
+
: chars.slice(0, exports.HERMES_BASE_DETAIL_MAX_CHARS).join('');
|
|
804
825
|
}
|
|
805
826
|
// ---------------------------------------------------------------------------
|
|
806
827
|
// equivalence check (streams two `-dump-bytecode` outputs, never writes them)
|
|
@@ -812,7 +833,35 @@ const STRING_TABLE_LINE = /^\s*[is](\d+)\[[^\]]*\](?: #[0-9A-F]+)?: (.*)$/;
|
|
|
812
833
|
* buffers are laid out differently (offsets, short/long variants), and jump
|
|
813
834
|
* distances follow instruction widths. Everything else must match exactly.
|
|
814
835
|
*/
|
|
815
|
-
|
|
836
|
+
/** separates rendered literal entries inside one normalized line */
|
|
837
|
+
exports.LITERAL_SEPARATOR = '\u001f';
|
|
838
|
+
/**
|
|
839
|
+
* `NewArrayWithBuffer rX, sizeHint, count, offset` and
|
|
840
|
+
* `NewObjectWithBuffer rX, sizeHint, count, keyOffset, valueOffset` with the
|
|
841
|
+
* literals decoded from the binary buffers at those offsets, so two builds
|
|
842
|
+
* that lay their buffers out differently still compare by what each
|
|
843
|
+
* instruction builds. Null when the operands do not fit the shape; an offset
|
|
844
|
+
* that cannot be decoded is spelled out (and so never equals a decoded one).
|
|
845
|
+
*/
|
|
846
|
+
function renderBufferInstruction(opcode, operands, literals) {
|
|
847
|
+
const [sizeHint, count] = operands;
|
|
848
|
+
if (opcode.startsWith('NewArray')) {
|
|
849
|
+
if (operands.length < 3)
|
|
850
|
+
return null;
|
|
851
|
+
const entries = literals.array(operands[2], count);
|
|
852
|
+
return `size=${sizeHint} n=${count} [${entries ? entries.join(exports.LITERAL_SEPARATOR) : `<undecodable@${operands[2]}>`}]`;
|
|
853
|
+
}
|
|
854
|
+
if (operands.length < 4)
|
|
855
|
+
return null;
|
|
856
|
+
const keys = literals.objectKeys(operands[2], count);
|
|
857
|
+
const values = literals.objectValues(operands[3], count);
|
|
858
|
+
if (!keys || !values) {
|
|
859
|
+
return `size=${sizeHint} n=${count} {<undecodable@${operands[2]}/${operands[3]}>}`;
|
|
860
|
+
}
|
|
861
|
+
const pairs = keys.map((k, i) => `${k}: ${values[i]}`);
|
|
862
|
+
return `size=${sizeHint} n=${count} {${pairs.join(exports.LITERAL_SEPARATOR)}}`;
|
|
863
|
+
}
|
|
864
|
+
function normalizeDisassemblyLine(line, strings, literals) {
|
|
816
865
|
// Cheap dispatch on the opcode before touching any regex: dumps run to
|
|
817
866
|
// millions of lines and only a handful of instructions need rewriting.
|
|
818
867
|
let indent = 0;
|
|
@@ -831,6 +880,13 @@ function normalizeDisassemblyLine(line, strings) {
|
|
|
831
880
|
/^(\s*New(?:Array|Object)WithBuffer)(?:Long)?(?:AndParent)?\s+(r\d+)(.*)$/.exec(line);
|
|
832
881
|
if (m) {
|
|
833
882
|
const nums = m[3].match(/\d+/g) ?? [];
|
|
883
|
+
if (literals) {
|
|
884
|
+
const rendered = renderBufferInstruction(m[1].trim(), nums.map(Number), literals);
|
|
885
|
+
if (rendered)
|
|
886
|
+
return `${m[1]} ${m[2]} ${rendered}`;
|
|
887
|
+
}
|
|
888
|
+
// no binary buffers: only the size hint survives; the buffer content
|
|
889
|
+
// is compared as a whole instead (compareBuffers)
|
|
834
890
|
return `${m[1]} ${m[2]} sizes=${nums.slice(0, 1).join(',')}`;
|
|
835
891
|
}
|
|
836
892
|
}
|
|
@@ -906,75 +962,301 @@ async function* streamLines(stream) {
|
|
|
906
962
|
if (rest)
|
|
907
963
|
yield rest;
|
|
908
964
|
}
|
|
965
|
+
/** `Array Buffer:`, `Object Key Buffer:`, `Debug filename table:`, ... */
|
|
966
|
+
const SECTION_HEADER = /^([A-Z][A-Za-z ]*):$/;
|
|
967
|
+
/** literal buffer entry that refers to the string table by id */
|
|
968
|
+
const BUFFER_STRING_ENTRY = /^\[String (\d+)\]$/;
|
|
969
|
+
/** sections after the functions that only serve debuggers and profilers */
|
|
970
|
+
const TRAILER_SECTION = /^(?:Debug |Textified callees table)/;
|
|
971
|
+
/** stderr kept from a dump process */
|
|
972
|
+
const DUMP_STDERR_KEEP = 4 * 1024;
|
|
973
|
+
/** a diagnostic line is cut to this many characters */
|
|
974
|
+
const DETAIL_LINE_MAX = 120;
|
|
975
|
+
function isFunctionHeader(line) {
|
|
976
|
+
return line.startsWith('Function<') || line.startsWith('NCFunction<');
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* Structured reader over one `hermesc -dump-bytecode -pretty-disassemble`
|
|
980
|
+
* stream. Everything before the functions is either the string table (kept
|
|
981
|
+
* to resolve ids), a literal buffer (kept, with string ids resolved to text,
|
|
982
|
+
* so buffer *content* is compared) or ignored; the functions come out one at
|
|
983
|
+
* a time, normalized; the debug tables after them are drained and ignored.
|
|
984
|
+
*/
|
|
909
985
|
class DumpReader {
|
|
910
986
|
proc;
|
|
911
987
|
iterator;
|
|
912
988
|
strings = new Map();
|
|
989
|
+
/** literal buffers by section name, entries with string ids resolved */
|
|
990
|
+
buffers = new Map();
|
|
991
|
+
exit;
|
|
992
|
+
section = null;
|
|
993
|
+
pending = null;
|
|
913
994
|
inFunctions = false;
|
|
914
995
|
finished = false;
|
|
915
|
-
|
|
996
|
+
/** set when the binary literal buffers of this side could be read */
|
|
997
|
+
literals;
|
|
998
|
+
constructor(proc, dumpTo, buffers) {
|
|
916
999
|
this.proc = proc;
|
|
917
|
-
|
|
1000
|
+
// the string table is filled while the preamble streams by, before the
|
|
1001
|
+
// first instruction needs it
|
|
1002
|
+
if (buffers)
|
|
1003
|
+
this.literals = new hermes_literals_1.LiteralResolver(buffers, this.strings);
|
|
1004
|
+
const pass = new stream_1.PassThrough();
|
|
1005
|
+
proc.stdout.pipe(pass);
|
|
1006
|
+
if (dumpTo)
|
|
1007
|
+
proc.stdout.pipe(fs_extra_1.default.createWriteStream(dumpTo));
|
|
1008
|
+
this.iterator = streamLines(pass);
|
|
1009
|
+
let stderr = '';
|
|
1010
|
+
proc.stderr?.on('data', (chunk) => {
|
|
1011
|
+
stderr = (stderr + chunk.toString()).slice(-DUMP_STDERR_KEEP);
|
|
1012
|
+
});
|
|
1013
|
+
this.exit = new Promise((resolve) => {
|
|
1014
|
+
// a spawn failure (ENOENT) may leave stdout open and never 'close'
|
|
1015
|
+
proc.on('error', (error) => {
|
|
1016
|
+
pass.end();
|
|
1017
|
+
resolve({ code: null, signal: null, error, stderr });
|
|
1018
|
+
});
|
|
1019
|
+
proc.on('close', (code, signal) => resolve({ code, signal, stderr }));
|
|
1020
|
+
});
|
|
918
1021
|
}
|
|
919
|
-
|
|
920
|
-
|
|
1022
|
+
async nextLine() {
|
|
1023
|
+
if (this.pending !== null) {
|
|
1024
|
+
const line = this.pending;
|
|
1025
|
+
this.pending = null;
|
|
1026
|
+
return line;
|
|
1027
|
+
}
|
|
921
1028
|
if (this.finished)
|
|
922
1029
|
return null;
|
|
1030
|
+
const { value, done } = await this.iterator.next();
|
|
1031
|
+
if (done) {
|
|
1032
|
+
this.finished = true;
|
|
1033
|
+
return null;
|
|
1034
|
+
}
|
|
1035
|
+
return value;
|
|
1036
|
+
}
|
|
1037
|
+
/** consume the preamble up to (and returning) the first function header */
|
|
1038
|
+
async skipPreamble() {
|
|
923
1039
|
for (;;) {
|
|
924
|
-
const
|
|
925
|
-
if (
|
|
926
|
-
this.finished = true;
|
|
1040
|
+
const line = await this.nextLine();
|
|
1041
|
+
if (line === null)
|
|
927
1042
|
return null;
|
|
1043
|
+
if (isFunctionHeader(line)) {
|
|
1044
|
+
this.inFunctions = true;
|
|
1045
|
+
return line;
|
|
928
1046
|
}
|
|
929
|
-
const
|
|
930
|
-
if (
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
1047
|
+
const header = SECTION_HEADER.exec(line);
|
|
1048
|
+
if (header) {
|
|
1049
|
+
this.section = header[1];
|
|
1050
|
+
if (this.section.endsWith('Buffer'))
|
|
1051
|
+
this.buffers.set(this.section, []);
|
|
1052
|
+
continue;
|
|
1053
|
+
}
|
|
1054
|
+
if (this.section === 'Global String Table') {
|
|
1055
|
+
const m = STRING_TABLE_LINE.exec(line);
|
|
1056
|
+
if (m)
|
|
1057
|
+
this.strings.set(Number(m[1]), m[2]);
|
|
1058
|
+
}
|
|
1059
|
+
else if (this.section?.endsWith('Buffer') && line.trim() !== '') {
|
|
1060
|
+
const entry = line.trim();
|
|
1061
|
+
const ref = BUFFER_STRING_ENTRY.exec(entry);
|
|
1062
|
+
const text = ref ? this.strings.get(Number(ref[1])) : undefined;
|
|
1063
|
+
this.buffers
|
|
1064
|
+
.get(this.section)
|
|
1065
|
+
.push(ref
|
|
1066
|
+
? `[String ${text === undefined ? `?${ref[1]}` : JSON.stringify(text)}]`
|
|
1067
|
+
: entry);
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
/** next function (header + normalized body), or null after the last one */
|
|
1072
|
+
async nextFunction() {
|
|
1073
|
+
const header = this.inFunctions
|
|
1074
|
+
? await this.nextLine()
|
|
1075
|
+
: await this.skipPreamble();
|
|
1076
|
+
if (header === null)
|
|
1077
|
+
return null;
|
|
1078
|
+
// a non-function header here is a trailer section: no more functions
|
|
1079
|
+
if (!isFunctionHeader(header))
|
|
1080
|
+
return null;
|
|
1081
|
+
const lines = [];
|
|
1082
|
+
for (;;) {
|
|
1083
|
+
const line = await this.nextLine();
|
|
1084
|
+
if (line === null)
|
|
1085
|
+
break;
|
|
1086
|
+
if (isFunctionHeader(line) || TRAILER_SECTION.test(line)) {
|
|
1087
|
+
this.pending = line;
|
|
1088
|
+
break;
|
|
940
1089
|
}
|
|
941
1090
|
if (line.trim() === '')
|
|
942
1091
|
continue;
|
|
943
|
-
const normalized = normalizeDisassemblyLine(line, this.strings);
|
|
1092
|
+
const normalized = normalizeDisassemblyLine(line, this.strings, this.literals);
|
|
944
1093
|
if (normalized !== null)
|
|
945
|
-
|
|
1094
|
+
lines.push(normalized);
|
|
1095
|
+
}
|
|
1096
|
+
return { header, lines };
|
|
1097
|
+
}
|
|
1098
|
+
/** drain whatever is left and report how the process ended */
|
|
1099
|
+
async finish() {
|
|
1100
|
+
while ((await this.nextLine()) !== null) { }
|
|
1101
|
+
return this.exit;
|
|
1102
|
+
}
|
|
1103
|
+
kill() {
|
|
1104
|
+
this.proc.kill();
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
function describeExit(exit) {
|
|
1108
|
+
if (exit.error)
|
|
1109
|
+
return exit.error.message;
|
|
1110
|
+
const how = exit.signal !== null ? `signal ${exit.signal}` : `exit ${exit.code}`;
|
|
1111
|
+
const stderr = exit.stderr.trim().split('\n').pop()?.trim();
|
|
1112
|
+
return stderr ? `${how}: ${stderr}` : how;
|
|
1113
|
+
}
|
|
1114
|
+
function clip(line) {
|
|
1115
|
+
const s = line.trim().split(exports.LITERAL_SEPARATOR).join(', ');
|
|
1116
|
+
return s.length > DETAIL_LINE_MAX ? `${s.slice(0, DETAIL_LINE_MAX - 1)}…` : s;
|
|
1117
|
+
}
|
|
1118
|
+
/**
|
|
1119
|
+
* For two New*WithBuffer lines that differ, the first literal that differs
|
|
1120
|
+
* (the whole line would be clipped before the difference for long literals).
|
|
1121
|
+
*/
|
|
1122
|
+
function literalDifference(a, b) {
|
|
1123
|
+
const open = /^(\s*New\w+WithBuffer r\d+ size=\d+ n=\d+ [[{])/;
|
|
1124
|
+
const ma = open.exec(a);
|
|
1125
|
+
const mb = open.exec(b);
|
|
1126
|
+
if (!ma || !mb)
|
|
1127
|
+
return null;
|
|
1128
|
+
const ea = a.slice(ma[1].length, -1).split(exports.LITERAL_SEPARATOR);
|
|
1129
|
+
const eb = b.slice(mb[1].length, -1).split(exports.LITERAL_SEPARATOR);
|
|
1130
|
+
const n = Math.min(ea.length, eb.length);
|
|
1131
|
+
for (let i = 0; i < n; i++) {
|
|
1132
|
+
if (ea[i] !== eb[i]) {
|
|
1133
|
+
return `${clip(ma[1].slice(0, -1))} entry ${i}: ${clip(ea[i])} vs ${clip(eb[i])}`;
|
|
946
1134
|
}
|
|
947
1135
|
}
|
|
1136
|
+
return null;
|
|
1137
|
+
}
|
|
1138
|
+
function compareBuffers(a, b) {
|
|
1139
|
+
for (const name of new Set([...a.keys(), ...b.keys()])) {
|
|
1140
|
+
const ea = a.get(name) ?? [];
|
|
1141
|
+
const eb = b.get(name) ?? [];
|
|
1142
|
+
const n = Math.min(ea.length, eb.length);
|
|
1143
|
+
for (let i = 0; i < n; i++) {
|
|
1144
|
+
if (ea[i] !== eb[i]) {
|
|
1145
|
+
return `${name} entry ${i}: ${clip(ea[i])} vs ${clip(eb[i])}`;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
if (ea.length !== eb.length) {
|
|
1149
|
+
return `${name}: ${ea.length} vs ${eb.length} entries`;
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
return null;
|
|
1153
|
+
}
|
|
1154
|
+
function compareFunctions(a, b) {
|
|
1155
|
+
if (a.header !== b.header) {
|
|
1156
|
+
return `${clip(a.header)} vs ${clip(b.header)}`;
|
|
1157
|
+
}
|
|
1158
|
+
const n = Math.min(a.lines.length, b.lines.length);
|
|
1159
|
+
for (let i = 0; i < n; i++) {
|
|
1160
|
+
if (a.lines[i] !== b.lines[i]) {
|
|
1161
|
+
const literal = literalDifference(a.lines[i], b.lines[i]);
|
|
1162
|
+
return literal
|
|
1163
|
+
? `${clip(a.header)} +${i + 1}: ${literal}`
|
|
1164
|
+
: `${clip(a.header)} +${i + 1}: ${clip(a.lines[i])} vs ${clip(b.lines[i])}`;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
if (a.lines.length !== b.lines.length) {
|
|
1168
|
+
return `${clip(a.header)}: ${a.lines.length} vs ${b.lines.length} lines`;
|
|
1169
|
+
}
|
|
1170
|
+
return null;
|
|
948
1171
|
}
|
|
949
1172
|
/**
|
|
950
|
-
* Compare two HBC files by disassembly (see normalizeDisassemblyLine)
|
|
951
|
-
*
|
|
952
|
-
*
|
|
953
|
-
* the
|
|
1173
|
+
* Compare two HBC files by disassembly (see normalizeDisassemblyLine): the
|
|
1174
|
+
* literal buffers by content, then function by function. `-b` forces hermesc
|
|
1175
|
+
* to treat inputs as bytecode whatever their extension. Both dumps are
|
|
1176
|
+
* consumed as streams so the ~100 MB of text never touches the disk (unless
|
|
1177
|
+
* `dumpTo` asks for it). A dump process that fails or ends early is reported
|
|
1178
|
+
* as `dump-failed`, never as a difference: the two cases need different
|
|
1179
|
+
* follow-ups. The detail names the first difference so a rejected base can be
|
|
1180
|
+
* turned into a normalization rule or a bug report.
|
|
954
1181
|
*/
|
|
955
|
-
async function
|
|
956
|
-
const spawnDump = (file) => (0, child_process_1.spawn)(hermesCommand, ['-b', '-dump-bytecode', '-pretty-disassemble', file], {
|
|
957
|
-
|
|
1182
|
+
async function compareHermesBytecode(hermesCommand, withBase, plain, options = {}) {
|
|
1183
|
+
const spawnDump = (file) => (0, child_process_1.spawn)(hermesCommand, ['-b', '-dump-bytecode', '-pretty-disassemble', file], { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
1184
|
+
// The literal buffers are read from both files up front (header + three
|
|
1185
|
+
// byte ranges). Only when both sides can be read do the instructions
|
|
1186
|
+
// compare decoded literals; otherwise both fall back to the dumped buffers
|
|
1187
|
+
// as a whole, so the two sides always normalize the same way.
|
|
1188
|
+
const [buffersA, buffersB] = await Promise.all([
|
|
1189
|
+
(0, hermes_literals_1.readLiteralBuffers)(withBase).catch(() => null),
|
|
1190
|
+
(0, hermes_literals_1.readLiteralBuffers)(plain).catch(() => null),
|
|
1191
|
+
]);
|
|
1192
|
+
const binary = buffersA && buffersB && buffersA.version === buffersB.version;
|
|
1193
|
+
const literals = binary ? 'instruction' : 'buffer';
|
|
1194
|
+
const a = new DumpReader(spawnDump(withBase), options.dumpTo?.withBase, binary ? buffersA : null);
|
|
1195
|
+
const b = new DumpReader(spawnDump(plain), options.dumpTo?.plain, binary ? buffersB : null);
|
|
1196
|
+
let functions = 0;
|
|
1197
|
+
const different = (detail) => ({
|
|
1198
|
+
status: 'different',
|
|
1199
|
+
detail,
|
|
1200
|
+
functions,
|
|
1201
|
+
literals,
|
|
1202
|
+
});
|
|
1203
|
+
const dumpFailed = (side, exit) => ({
|
|
1204
|
+
status: 'dump-failed',
|
|
1205
|
+
detail: `${side} dump: ${describeExit(exit)}`,
|
|
1206
|
+
functions,
|
|
1207
|
+
literals,
|
|
958
1208
|
});
|
|
959
|
-
const a = new DumpReader(spawnDump(withBase));
|
|
960
|
-
const b = new DumpReader(spawnDump(plain));
|
|
961
|
-
let equal = true;
|
|
962
|
-
let lines = 0;
|
|
963
1209
|
try {
|
|
964
1210
|
for (;;) {
|
|
965
|
-
const [
|
|
966
|
-
if (
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
1211
|
+
const [fa, fb] = await Promise.all([a.nextFunction(), b.nextFunction()]);
|
|
1212
|
+
if (fa === null || fb === null) {
|
|
1213
|
+
// whoever ended: was that the end of a good dump or a failure?
|
|
1214
|
+
if (fa === null) {
|
|
1215
|
+
const exit = await a.finish();
|
|
1216
|
+
if (exit.error || exit.code !== 0)
|
|
1217
|
+
return dumpFailed('base', exit);
|
|
1218
|
+
}
|
|
1219
|
+
if (fb === null) {
|
|
1220
|
+
const exit = await b.finish();
|
|
1221
|
+
if (exit.error || exit.code !== 0)
|
|
1222
|
+
return dumpFailed('plain', exit);
|
|
1223
|
+
}
|
|
1224
|
+
if (fa !== null || fb !== null) {
|
|
1225
|
+
const extra = fa ?? fb;
|
|
1226
|
+
return different(`function count: ${clip(extra.header)} only in the ${fa ? 'base' : 'plain'} compile`);
|
|
1227
|
+
}
|
|
1228
|
+
if (functions === 0) {
|
|
1229
|
+
return {
|
|
1230
|
+
status: 'dump-failed',
|
|
1231
|
+
detail: 'no functions in the disassembly',
|
|
1232
|
+
functions,
|
|
1233
|
+
literals,
|
|
1234
|
+
};
|
|
1235
|
+
}
|
|
1236
|
+
return { status: 'equivalent', functions, literals };
|
|
1237
|
+
}
|
|
1238
|
+
if (functions === 0 && !binary) {
|
|
1239
|
+
// buffers precede the functions, so both are complete by now. This
|
|
1240
|
+
// whole-buffer comparison is the fallback: the builder overlaps and
|
|
1241
|
+
// deduplicates serialized literals, so a delta build may lay the same
|
|
1242
|
+
// literals out differently and this can reject a good build.
|
|
1243
|
+
const detail = compareBuffers(a.buffers, b.buffers);
|
|
1244
|
+
if (detail)
|
|
1245
|
+
return different(detail);
|
|
971
1246
|
}
|
|
972
|
-
|
|
1247
|
+
const detail = compareFunctions(fa, fb);
|
|
1248
|
+
if (detail)
|
|
1249
|
+
return different(detail);
|
|
1250
|
+
functions++;
|
|
973
1251
|
}
|
|
974
1252
|
}
|
|
975
1253
|
finally {
|
|
976
|
-
a.
|
|
977
|
-
b.
|
|
1254
|
+
a.kill();
|
|
1255
|
+
b.kill();
|
|
978
1256
|
}
|
|
979
|
-
|
|
1257
|
+
}
|
|
1258
|
+
/** Resolves true when equivalent; see compareHermesBytecode for the details. */
|
|
1259
|
+
async function verifyHermesBaseEquivalence(hermesCommand, withBase, plain) {
|
|
1260
|
+
const result = await compareHermesBytecode(hermesCommand, withBase, plain);
|
|
1261
|
+
return result.status === 'equivalent';
|
|
980
1262
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type LiteralValue = {
|
|
2
|
+
kind: 'null' | 'true' | 'false';
|
|
3
|
+
} | {
|
|
4
|
+
kind: 'number';
|
|
5
|
+
value: number;
|
|
6
|
+
} | {
|
|
7
|
+
kind: 'int';
|
|
8
|
+
value: number;
|
|
9
|
+
} | {
|
|
10
|
+
kind: 'string';
|
|
11
|
+
id: number;
|
|
12
|
+
};
|
|
13
|
+
/** The three literal buffers of an HBC v87–96 file. */
|
|
14
|
+
export interface LiteralBuffers {
|
|
15
|
+
version: number;
|
|
16
|
+
array: Buffer;
|
|
17
|
+
objectKeys: Buffer;
|
|
18
|
+
objectValues: Buffer;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Read only the literal buffers of an HBC file (header + three byte ranges,
|
|
22
|
+
* never the whole file). Null for a file whose layout is unknown, including
|
|
23
|
+
* HBC v98 (literalValueBuffer + objShapeTable, not decoded yet): the caller
|
|
24
|
+
* then falls back to comparing the dumped buffers as a whole.
|
|
25
|
+
*/
|
|
26
|
+
export declare function readLiteralBuffers(file: string): Promise<LiteralBuffers | null>;
|
|
27
|
+
/**
|
|
28
|
+
* Decode `count` literal values starting at byte `offset`. Null when the
|
|
29
|
+
* offset or a run reaches outside the buffer or a tag type is unknown; the
|
|
30
|
+
* caller reports that as a difference rather than guessing.
|
|
31
|
+
*/
|
|
32
|
+
export declare function decodeSerializedLiterals(buffer: Buffer, offset: number, count: number): LiteralValue[] | null;
|
|
33
|
+
/**
|
|
34
|
+
* One literal as text, string ids resolved through the dump's string table
|
|
35
|
+
* (an unknown id stays visible as `?id`). Doubles keep their exact bits in
|
|
36
|
+
* the text so -0 and 0, or two NaNs, never collide by accident.
|
|
37
|
+
*/
|
|
38
|
+
export declare function renderLiteral(value: LiteralValue, strings: Map<number, string>): string;
|
|
39
|
+
/**
|
|
40
|
+
* Decodes the literals an instruction refers to, for one side of a compare.
|
|
41
|
+
* Returns rendered entries, or null when the offset cannot be decoded.
|
|
42
|
+
*/
|
|
43
|
+
export declare class LiteralResolver {
|
|
44
|
+
private readonly buffers;
|
|
45
|
+
private readonly strings;
|
|
46
|
+
constructor(buffers: LiteralBuffers, strings: Map<number, string>);
|
|
47
|
+
private decode;
|
|
48
|
+
array(offset: number, count: number): string[] | null;
|
|
49
|
+
objectKeys(offset: number, count: number): string[] | null;
|
|
50
|
+
objectValues(offset: number, count: number): string[] | null;
|
|
51
|
+
}
|