react-native-update-cli 2.22.8 → 2.23.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 +3 -2
- package/README.zh-CN.md +3 -2
- package/cli.json +21 -1
- package/lib/bin.js +2 -0
- package/lib/bundle.js +9 -1
- package/lib/locales/en.d.ts +8 -0
- package/lib/locales/en.js +8 -0
- package/lib/locales/zh.d.ts +8 -0
- package/lib/locales/zh.js +8 -0
- package/lib/native-package.d.ts +5 -1
- package/lib/native-package.js +145 -84
- package/lib/provider.d.ts +2 -1
- package/lib/provider.js +15 -0
- package/lib/symbolicate.d.ts +30 -0
- package/lib/symbolicate.js +117 -0
- package/lib/types.d.ts +17 -0
- package/lib/utils/latest-version/index.js +28 -7
- package/lib/utils/zip-raw-writer.d.ts +47 -0
- package/lib/utils/zip-raw-writer.js +204 -0
- package/lib/versions.js +38 -1
- package/package.json +2 -3
- package/src/bin.ts +2 -0
- package/src/bundle.ts +13 -1
- package/src/locales/en.ts +14 -0
- package/src/locales/zh.ts +11 -0
- package/src/native-package.ts +186 -96
- package/src/provider.ts +24 -0
- package/src/symbolicate.ts +159 -0
- package/src/types.ts +18 -0
- package/src/utils/latest-version/index.ts +27 -4
- package/src/utils/zip-raw-writer.ts +247 -0
- package/src/versions.ts +47 -1
package/src/native-package.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from 'yauzl';
|
|
9
9
|
import { ZipFile as YazlZipFile } from 'yazl';
|
|
10
10
|
import type { Platform } from './types';
|
|
11
|
+
import { fitsRawZip, RawZipWriter } from './utils/zip-raw-writer';
|
|
11
12
|
|
|
12
13
|
export type NativePackageEntry = {
|
|
13
14
|
diffPath: string;
|
|
@@ -66,28 +67,115 @@ export function resolveNativePackageEntry(
|
|
|
66
67
|
return nativePackageRules[platform].resolveEntry(entryName);
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
entry: Entry
|
|
72
|
-
|
|
73
|
-
): Promise<void
|
|
70
|
+
/** Where the kept entries go: a raw copy (default) or a yazl repack. */
|
|
71
|
+
interface SlimSink {
|
|
72
|
+
copyEntry(sourceZip: YauzlZipFile, entry: Entry): Promise<void>;
|
|
73
|
+
/** add a local file under `fileName`, dated like `like` */
|
|
74
|
+
addFile(filePath: string, fileName: string, like: Entry): Promise<void>;
|
|
75
|
+
end(): Promise<void>;
|
|
76
|
+
abort(): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Copies each entry's stored bytes, CRC and sizes verbatim (yauzl hands out
|
|
81
|
+
* the raw file data with `decodeFileData: false`), so slimming a package is
|
|
82
|
+
* bound by disk I/O rather than by deflating every asset again.
|
|
83
|
+
*/
|
|
84
|
+
class RawCopySink implements SlimSink {
|
|
85
|
+
private readonly writer: RawZipWriter;
|
|
86
|
+
constructor(output: string) {
|
|
87
|
+
this.writer = new RawZipWriter(output);
|
|
88
|
+
}
|
|
89
|
+
copyEntry(sourceZip: YauzlZipFile, entry: Entry): Promise<void> {
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
sourceZip.openReadStream(
|
|
92
|
+
entry,
|
|
93
|
+
{ decodeFileData: false },
|
|
94
|
+
(error, readStream) => {
|
|
95
|
+
if (error || !readStream) {
|
|
96
|
+
reject(
|
|
97
|
+
error ?? new Error(`Unable to read zip entry: ${entry.fileName}`),
|
|
98
|
+
);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.writer.addRawEntry(entry, readStream).then(resolve, reject);
|
|
102
|
+
},
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
addFile(filePath: string, fileName: string, like: Entry): Promise<void> {
|
|
107
|
+
// a nested slim archive is a zip of deflated entries: storing it as-is
|
|
108
|
+
// loses nothing and skips another pass over its bytes
|
|
109
|
+
return this.writer.addStoredFile(filePath, fileName, like);
|
|
110
|
+
}
|
|
111
|
+
end(): Promise<void> {
|
|
112
|
+
return this.writer.end();
|
|
113
|
+
}
|
|
114
|
+
abort(): Promise<void> {
|
|
115
|
+
return this.writer.abort();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Re-deflates every kept entry through yazl; only for sources that need zip64. */
|
|
120
|
+
class RepackSink implements SlimSink {
|
|
121
|
+
private readonly outputZip = new YazlZipFile();
|
|
122
|
+
private readonly writePromise: Promise<void>;
|
|
123
|
+
constructor(readonly output: string) {
|
|
124
|
+
this.writePromise = new Promise<void>((resolve, reject) => {
|
|
125
|
+
this.outputZip.outputStream.once('error', reject);
|
|
126
|
+
this.outputZip.outputStream
|
|
127
|
+
.pipe(fs.createWriteStream(output))
|
|
128
|
+
.once('error', reject)
|
|
129
|
+
.once('close', () => resolve());
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
copyEntry(sourceZip: YauzlZipFile, entry: Entry): Promise<void> {
|
|
133
|
+
return new Promise((resolve, reject) => {
|
|
134
|
+
sourceZip.openReadStream(entry, (error, readStream) => {
|
|
135
|
+
if (error || !readStream) {
|
|
136
|
+
reject(
|
|
137
|
+
error ?? new Error(`Unable to read zip entry: ${entry.fileName}`),
|
|
138
|
+
);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
readStream.once('error', reject);
|
|
142
|
+
readStream.once('end', () => resolve());
|
|
143
|
+
this.outputZip.addReadStream(readStream, entry.fileName, {
|
|
144
|
+
compress: entry.compressionMethod !== 0,
|
|
145
|
+
mtime: entry.getLastModDate(),
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
async addFile(
|
|
151
|
+
filePath: string,
|
|
152
|
+
fileName: string,
|
|
153
|
+
like: Entry,
|
|
154
|
+
): Promise<void> {
|
|
155
|
+
this.outputZip.addFile(filePath, fileName, {
|
|
156
|
+
compress: like.compressionMethod !== 0,
|
|
157
|
+
mtime: like.getLastModDate(),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
async end(): Promise<void> {
|
|
161
|
+
this.outputZip.end();
|
|
162
|
+
await this.writePromise;
|
|
163
|
+
}
|
|
164
|
+
async abort(): Promise<void> {
|
|
165
|
+
this.outputZip.end();
|
|
166
|
+
await this.writePromise.catch(() => {});
|
|
167
|
+
await fs.remove(this.output).catch(() => {});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function openZip(source: string): Promise<YauzlZipFile> {
|
|
74
172
|
return new Promise((resolve, reject) => {
|
|
75
|
-
|
|
76
|
-
if (error) {
|
|
77
|
-
reject(error);
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (!readStream) {
|
|
81
|
-
reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
|
|
173
|
+
openZipFile(source, { lazyEntries: true }, (error, zipFile) => {
|
|
174
|
+
if (error || !zipFile) {
|
|
175
|
+
reject(error ?? new Error(`Unable to open zip file: ${source}`));
|
|
82
176
|
return;
|
|
83
177
|
}
|
|
84
|
-
|
|
85
|
-
readStream.once('error', reject);
|
|
86
|
-
readStream.once('end', () => resolve());
|
|
87
|
-
outputZip.addReadStream(readStream, entry.fileName, {
|
|
88
|
-
compress: entry.compressionMethod !== 0,
|
|
89
|
-
mtime: entry.getLastModDate(),
|
|
90
|
-
});
|
|
178
|
+
resolve(zipFile);
|
|
91
179
|
});
|
|
92
180
|
});
|
|
93
181
|
}
|
|
@@ -117,114 +205,110 @@ function extractEntryToFile(
|
|
|
117
205
|
});
|
|
118
206
|
}
|
|
119
207
|
|
|
208
|
+
export interface SlimPackageOptions {
|
|
209
|
+
/** re-deflate through yazl even when a raw copy would do (tests) */
|
|
210
|
+
repack?: boolean;
|
|
211
|
+
}
|
|
212
|
+
|
|
120
213
|
async function filterNativePackageArchive(
|
|
121
214
|
source: string,
|
|
122
215
|
output: string,
|
|
123
216
|
platform: Platform,
|
|
217
|
+
options: SlimPackageOptions,
|
|
124
218
|
): Promise<{ bundles: number; entries: number }> {
|
|
125
219
|
await fs.ensureDir(path.dirname(output));
|
|
126
220
|
const scratchDir = await fs.mkdtemp(
|
|
127
221
|
path.join(os.tmpdir(), 'rnu-native-package-entry-'),
|
|
128
222
|
);
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
223
|
+
const sourceZip = await openZip(source);
|
|
224
|
+
// a subset of the source never outgrows it, so the source's own size and
|
|
225
|
+
// entry count decide whether plain (non-zip64) headers are enough
|
|
226
|
+
const rawCopy =
|
|
227
|
+
!options.repack &&
|
|
228
|
+
fitsRawZip((await fs.stat(source)).size, sourceZip.entryCount);
|
|
229
|
+
const sink: SlimSink = rawCopy
|
|
230
|
+
? new RawCopySink(output)
|
|
231
|
+
: new RepackSink(output);
|
|
137
232
|
let includedEntries = 0;
|
|
138
233
|
let includedBundles = 0;
|
|
139
234
|
let nestedArchiveIndex = 0;
|
|
140
235
|
|
|
141
236
|
try {
|
|
142
237
|
await new Promise<void>((resolve, reject) => {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
238
|
+
let settled = false;
|
|
239
|
+
const fail = (error: unknown) => {
|
|
240
|
+
if (settled) {
|
|
146
241
|
return;
|
|
147
242
|
}
|
|
243
|
+
settled = true;
|
|
244
|
+
sourceZip.close();
|
|
245
|
+
reject(error);
|
|
246
|
+
};
|
|
148
247
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
248
|
+
sourceZip.once('error', fail);
|
|
249
|
+
sourceZip.once('end', () => {
|
|
250
|
+
if (!settled) {
|
|
154
251
|
settled = true;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
resolve();
|
|
252
|
+
resolve();
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
sourceZip.on('entry', async (entry) => {
|
|
256
|
+
try {
|
|
257
|
+
if (entry.fileName.endsWith('/')) {
|
|
258
|
+
sourceZip.readEntry();
|
|
259
|
+
return;
|
|
164
260
|
}
|
|
165
|
-
});
|
|
166
|
-
sourceZip.on('entry', async (entry) => {
|
|
167
|
-
try {
|
|
168
|
-
if (entry.fileName.endsWith('/')) {
|
|
169
|
-
sourceZip.readEntry();
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// Harmony .app packages contain one or more nested .hap archives.
|
|
174
|
-
// Rebuild those archives recursively and keep their outer path so
|
|
175
|
-
// the slim package has the same nesting as the original package.
|
|
176
|
-
if (
|
|
177
|
-
platform === 'harmony' &&
|
|
178
|
-
entry.fileName.toLowerCase().endsWith('.hap')
|
|
179
|
-
) {
|
|
180
|
-
const index = nestedArchiveIndex++;
|
|
181
|
-
const nestedSource = path.join(scratchDir, `${index}.source.hap`);
|
|
182
|
-
const nestedOutput = path.join(scratchDir, `${index}.slim.hap`);
|
|
183
|
-
await extractEntryToFile(sourceZip, entry, nestedSource);
|
|
184
|
-
const nestedResult = await filterNativePackageArchive(
|
|
185
|
-
nestedSource,
|
|
186
|
-
nestedOutput,
|
|
187
|
-
platform,
|
|
188
|
-
);
|
|
189
|
-
if (nestedResult.entries > 0) {
|
|
190
|
-
outputZip.addFile(nestedOutput, entry.fileName, {
|
|
191
|
-
compress: entry.compressionMethod !== 0,
|
|
192
|
-
mtime: entry.getLastModDate(),
|
|
193
|
-
});
|
|
194
|
-
includedEntries += nestedResult.entries;
|
|
195
|
-
includedBundles += nestedResult.bundles;
|
|
196
|
-
}
|
|
197
|
-
sourceZip.readEntry();
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
261
|
|
|
201
|
-
|
|
262
|
+
// Harmony .app packages contain one or more nested .hap archives.
|
|
263
|
+
// Rebuild those archives recursively and keep their outer path so
|
|
264
|
+
// the slim package has the same nesting as the original package.
|
|
265
|
+
if (
|
|
266
|
+
platform === 'harmony' &&
|
|
267
|
+
entry.fileName.toLowerCase().endsWith('.hap')
|
|
268
|
+
) {
|
|
269
|
+
const index = nestedArchiveIndex++;
|
|
270
|
+
const nestedSource = path.join(scratchDir, `${index}.source.hap`);
|
|
271
|
+
const nestedOutput = path.join(scratchDir, `${index}.slim.hap`);
|
|
272
|
+
await extractEntryToFile(sourceZip, entry, nestedSource);
|
|
273
|
+
const nestedResult = await filterNativePackageArchive(
|
|
274
|
+
nestedSource,
|
|
275
|
+
nestedOutput,
|
|
202
276
|
platform,
|
|
203
|
-
|
|
277
|
+
options,
|
|
204
278
|
);
|
|
205
|
-
if (
|
|
206
|
-
await
|
|
207
|
-
includedEntries +=
|
|
208
|
-
|
|
209
|
-
includedBundles += 1;
|
|
210
|
-
}
|
|
279
|
+
if (nestedResult.entries > 0) {
|
|
280
|
+
await sink.addFile(nestedOutput, entry.fileName, entry);
|
|
281
|
+
includedEntries += nestedResult.entries;
|
|
282
|
+
includedBundles += nestedResult.bundles;
|
|
211
283
|
}
|
|
212
284
|
sourceZip.readEntry();
|
|
213
|
-
|
|
214
|
-
fail(error);
|
|
285
|
+
return;
|
|
215
286
|
}
|
|
216
|
-
});
|
|
217
287
|
|
|
218
|
-
|
|
288
|
+
const resolvedEntry = resolveNativePackageEntry(
|
|
289
|
+
platform,
|
|
290
|
+
entry.fileName,
|
|
291
|
+
);
|
|
292
|
+
if (resolvedEntry) {
|
|
293
|
+
await sink.copyEntry(sourceZip, entry);
|
|
294
|
+
includedEntries += 1;
|
|
295
|
+
if (resolvedEntry.kind === 'bundle') {
|
|
296
|
+
includedBundles += 1;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
sourceZip.readEntry();
|
|
300
|
+
} catch (error) {
|
|
301
|
+
fail(error);
|
|
302
|
+
}
|
|
219
303
|
});
|
|
304
|
+
|
|
305
|
+
sourceZip.readEntry();
|
|
220
306
|
});
|
|
221
307
|
|
|
222
|
-
|
|
223
|
-
await writePromise;
|
|
308
|
+
await sink.end();
|
|
224
309
|
return { bundles: includedBundles, entries: includedEntries };
|
|
225
310
|
} catch (error) {
|
|
226
|
-
|
|
227
|
-
await writePromise.catch(() => {});
|
|
311
|
+
await sink.abort();
|
|
228
312
|
throw error;
|
|
229
313
|
} finally {
|
|
230
314
|
await fs.remove(scratchDir);
|
|
@@ -239,8 +323,14 @@ export async function createSlimNativePackage(
|
|
|
239
323
|
source: string,
|
|
240
324
|
output: string,
|
|
241
325
|
platform: Platform,
|
|
326
|
+
options: SlimPackageOptions = {},
|
|
242
327
|
): Promise<void> {
|
|
243
|
-
const result = await filterNativePackageArchive(
|
|
328
|
+
const result = await filterNativePackageArchive(
|
|
329
|
+
source,
|
|
330
|
+
output,
|
|
331
|
+
platform,
|
|
332
|
+
options,
|
|
333
|
+
);
|
|
244
334
|
if (result.bundles === 0) {
|
|
245
335
|
await fs.remove(output);
|
|
246
336
|
throw new Error(`Bundle entry not found in native package: ${source}`);
|
package/src/provider.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
Platform,
|
|
9
9
|
PublishOptions,
|
|
10
10
|
Session,
|
|
11
|
+
SymbolicateOptions,
|
|
11
12
|
UpdateVersionOptions,
|
|
12
13
|
UploadOptions,
|
|
13
14
|
} from './types';
|
|
@@ -128,6 +129,7 @@ export class CLIProviderImpl implements CLIProvider {
|
|
|
128
129
|
? undefined
|
|
129
130
|
: String(options.rollout),
|
|
130
131
|
dryRun: options.dryRun || false,
|
|
132
|
+
sourcemap: options.sourcemap,
|
|
131
133
|
},
|
|
132
134
|
options.filePath ? [options.filePath] : [],
|
|
133
135
|
);
|
|
@@ -140,6 +142,28 @@ export class CLIProviderImpl implements CLIProvider {
|
|
|
140
142
|
);
|
|
141
143
|
}
|
|
142
144
|
|
|
145
|
+
async symbolicate(options: SymbolicateOptions): Promise<CommandResult> {
|
|
146
|
+
return this.runMessageCommand(
|
|
147
|
+
async () => {
|
|
148
|
+
const context = this.createContext(
|
|
149
|
+
{
|
|
150
|
+
hash: options.hash,
|
|
151
|
+
versionId: options.versionId,
|
|
152
|
+
platform: options.platform,
|
|
153
|
+
appId: options.appId,
|
|
154
|
+
config: options.config,
|
|
155
|
+
output: options.output,
|
|
156
|
+
},
|
|
157
|
+
options.stackFile ? [options.stackFile] : [],
|
|
158
|
+
);
|
|
159
|
+
const { symbolicateCommands } = await import('./symbolicate');
|
|
160
|
+
await symbolicateCommands.symbolicate(context);
|
|
161
|
+
},
|
|
162
|
+
'Unknown error during symbolication',
|
|
163
|
+
'Stack symbolicated',
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
143
167
|
async upload(options: UploadOptions): Promise<CommandResult> {
|
|
144
168
|
return this.runMessageCommand(
|
|
145
169
|
async () => {
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import fetch from 'node-fetch';
|
|
3
|
+
import { SourceMapConsumer } from 'source-map';
|
|
4
|
+
import { get } from './api';
|
|
5
|
+
import { getPlatform, getSelectedApp } from './app';
|
|
6
|
+
import type { Platform, Version } from './types';
|
|
7
|
+
import { t } from './utils/i18n';
|
|
8
|
+
import { fetchVersions } from './versions';
|
|
9
|
+
|
|
10
|
+
// A frame location inside a shipped bundle: `<bundle>:<line>:<column>`. Covers
|
|
11
|
+
// `index.bundlejs`, `index.android.bundle`, `main.jsbundle`, `bundle.harmony.js`
|
|
12
|
+
// and plain `.js`/`.hbc` names; an optional `address at ` prefix marks a
|
|
13
|
+
// Hermes bytecode frame (column = bytecode offset, already 0-based).
|
|
14
|
+
const FRAME_PATTERN =
|
|
15
|
+
/(address at )?((?:[\w.-]+\/)*[\w.-]+\.(?:bundlejs|jsbundle|bundle|hbc|js))(?:\?[^\s:)]*)?:(\d+):(\d+)/g;
|
|
16
|
+
|
|
17
|
+
export interface FrameConsumer {
|
|
18
|
+
originalPositionFor(position: { line: number; column: number }): {
|
|
19
|
+
source?: string | null;
|
|
20
|
+
line?: number | null;
|
|
21
|
+
column?: number | null;
|
|
22
|
+
name?: string | null;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Rewrites every bundle frame of `stack` to its original source position.
|
|
28
|
+
* JS engines report 1-based columns, so they are shifted to the 0-based
|
|
29
|
+
* columns source maps use; Hermes bytecode frames (`address at`) carry the
|
|
30
|
+
* bytecode offset, which the composed hermes map keys directly.
|
|
31
|
+
*/
|
|
32
|
+
export function symbolicateStack(
|
|
33
|
+
stack: string,
|
|
34
|
+
consumer: FrameConsumer,
|
|
35
|
+
): { text: string; mapped: number } {
|
|
36
|
+
let mapped = 0;
|
|
37
|
+
const text = stack.replace(
|
|
38
|
+
FRAME_PATTERN,
|
|
39
|
+
(
|
|
40
|
+
frame,
|
|
41
|
+
hermes: string | undefined,
|
|
42
|
+
_bundle,
|
|
43
|
+
line: string,
|
|
44
|
+
column: string,
|
|
45
|
+
) => {
|
|
46
|
+
const position = consumer.originalPositionFor({
|
|
47
|
+
line: Number(line),
|
|
48
|
+
column: hermes ? Number(column) : Math.max(0, Number(column) - 1),
|
|
49
|
+
});
|
|
50
|
+
if (
|
|
51
|
+
!position.source ||
|
|
52
|
+
position.line === null ||
|
|
53
|
+
position.line === undefined
|
|
54
|
+
) {
|
|
55
|
+
return frame;
|
|
56
|
+
}
|
|
57
|
+
mapped++;
|
|
58
|
+
const original = `${position.source}:${position.line}:${(position.column ?? 0) + 1}`;
|
|
59
|
+
return position.name ? `${original} (${position.name})` : original;
|
|
60
|
+
},
|
|
61
|
+
);
|
|
62
|
+
return { text, mapped };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function findVersionByHash(
|
|
66
|
+
appId: string,
|
|
67
|
+
hash: string,
|
|
68
|
+
): Promise<Version | undefined> {
|
|
69
|
+
const limit = 100;
|
|
70
|
+
// The list is newest-first; crashes are usually about recent versions.
|
|
71
|
+
for (let offset = 0; offset < 100 * limit; offset += limit) {
|
|
72
|
+
const page = await fetchVersions(appId, offset, limit);
|
|
73
|
+
const found = page.find((version) => version.hash === hash);
|
|
74
|
+
if (found) {
|
|
75
|
+
return found;
|
|
76
|
+
}
|
|
77
|
+
if (page.length < limit) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function readStack(source: string | undefined): Promise<string> {
|
|
85
|
+
if (!source || source === '-') {
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
const chunks: Buffer[] = [];
|
|
88
|
+
process.stdin.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
|
|
89
|
+
process.stdin.on('end', () =>
|
|
90
|
+
resolve(Buffer.concat(chunks).toString('utf8')),
|
|
91
|
+
);
|
|
92
|
+
process.stdin.on('error', reject);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return fs.readFileSync(source, 'utf8');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const symbolicateCommands = {
|
|
99
|
+
symbolicate: async ({
|
|
100
|
+
args,
|
|
101
|
+
options,
|
|
102
|
+
}: {
|
|
103
|
+
args: string[];
|
|
104
|
+
options: Record<string, unknown>;
|
|
105
|
+
}) => {
|
|
106
|
+
const hash = typeof options.hash === 'string' ? options.hash : '';
|
|
107
|
+
const versionIdOption =
|
|
108
|
+
typeof options.versionId === 'string' ? options.versionId : '';
|
|
109
|
+
if (!hash && !versionIdOption) {
|
|
110
|
+
throw new Error(t('symbolicateUsage'));
|
|
111
|
+
}
|
|
112
|
+
const platform = await getPlatform(
|
|
113
|
+
typeof options.platform === 'string'
|
|
114
|
+
? (options.platform as Platform)
|
|
115
|
+
: undefined,
|
|
116
|
+
);
|
|
117
|
+
const appId =
|
|
118
|
+
typeof options.appId === 'string' && options.appId
|
|
119
|
+
? options.appId
|
|
120
|
+
: (await getSelectedApp(platform, options.config as string | undefined))
|
|
121
|
+
.appId;
|
|
122
|
+
|
|
123
|
+
let versionId = versionIdOption;
|
|
124
|
+
if (!versionId) {
|
|
125
|
+
const version = await findVersionByHash(appId, hash);
|
|
126
|
+
if (!version) {
|
|
127
|
+
throw new Error(t('symbolicateVersionNotFound', { hash }));
|
|
128
|
+
}
|
|
129
|
+
versionId = String(version.id);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const located = await get(`/app/${appId}/version/${versionId}/sourceMap`);
|
|
133
|
+
if (!located?.url) {
|
|
134
|
+
throw new Error(t('symbolicateNoSourceMap', { id: versionId }));
|
|
135
|
+
}
|
|
136
|
+
const response = await fetch(located.url);
|
|
137
|
+
if (!response.ok) {
|
|
138
|
+
throw new Error(`Failed to download source map: HTTP ${response.status}`);
|
|
139
|
+
}
|
|
140
|
+
const rawMap = JSON.parse(await response.text());
|
|
141
|
+
const consumer = new SourceMapConsumer(rawMap);
|
|
142
|
+
|
|
143
|
+
const stack = await readStack(args[0]);
|
|
144
|
+
const { text, mapped } = symbolicateStack(stack, consumer);
|
|
145
|
+
if (typeof options.output === 'string' && options.output) {
|
|
146
|
+
fs.writeFileSync(options.output, text);
|
|
147
|
+
} else {
|
|
148
|
+
process.stdout.write(text.endsWith('\n') ? text : `${text}\n`);
|
|
149
|
+
}
|
|
150
|
+
console.error(
|
|
151
|
+
t('symbolicateDone', {
|
|
152
|
+
count: mapped,
|
|
153
|
+
id: versionId,
|
|
154
|
+
hash: located.hash ?? hash,
|
|
155
|
+
}),
|
|
156
|
+
);
|
|
157
|
+
return { versionId, mapped };
|
|
158
|
+
},
|
|
159
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -28,6 +28,8 @@ export interface Version {
|
|
|
28
28
|
name: string;
|
|
29
29
|
packages?: Package[];
|
|
30
30
|
deps?: Record<string, string> | string | null;
|
|
31
|
+
/** storage key of the archived source map (absent when published without one) */
|
|
32
|
+
sourceMapKey?: string;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
export interface CommandContext<
|
|
@@ -69,6 +71,8 @@ export interface BundleOptions {
|
|
|
69
71
|
|
|
70
72
|
export interface PublishOptions {
|
|
71
73
|
filePath?: string;
|
|
74
|
+
/** path of the final source map to archive with the version */
|
|
75
|
+
sourcemap?: string;
|
|
72
76
|
platform?: Platform;
|
|
73
77
|
name?: string;
|
|
74
78
|
description?: string;
|
|
@@ -104,9 +108,23 @@ export interface UpdateVersionOptions {
|
|
|
104
108
|
dryRun?: boolean;
|
|
105
109
|
}
|
|
106
110
|
|
|
111
|
+
export interface SymbolicateOptions {
|
|
112
|
+
/** stack trace file ('-' for stdin) */
|
|
113
|
+
stackFile?: string;
|
|
114
|
+
/** update hash of the running version (from getUpdateMetadata().currentVersion) */
|
|
115
|
+
hash?: string;
|
|
116
|
+
versionId?: string;
|
|
117
|
+
platform?: Platform;
|
|
118
|
+
appId?: string;
|
|
119
|
+
config?: string;
|
|
120
|
+
/** write the symbolicated stack here instead of stdout */
|
|
121
|
+
output?: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
107
124
|
export interface CLIProvider {
|
|
108
125
|
bundle: (options: BundleOptions) => Promise<CommandResult>;
|
|
109
126
|
publish: (options: PublishOptions) => Promise<CommandResult>;
|
|
127
|
+
symbolicate: (options: SymbolicateOptions) => Promise<CommandResult>;
|
|
110
128
|
upload: (options: UploadOptions) => Promise<CommandResult>;
|
|
111
129
|
|
|
112
130
|
createApp: (name: string, platform: Platform) => Promise<CommandResult>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { compare, compareVersions, satisfies } from 'compare-versions';
|
|
1
2
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
2
3
|
import { npm, yarn } from 'global-dirs';
|
|
3
4
|
import type {
|
|
@@ -10,8 +11,6 @@ import { homedir } from 'os';
|
|
|
10
11
|
import { dirname, join, parse, resolve as pathResolve } from 'path';
|
|
11
12
|
import registryAuthToken from 'registry-auth-token';
|
|
12
13
|
import getRegistryUrl from 'registry-auth-token/registry-url';
|
|
13
|
-
import gt from 'semver/functions/gt';
|
|
14
|
-
import maxSatisfying from 'semver/ranges/max-satisfying';
|
|
15
14
|
import { URL } from 'url';
|
|
16
15
|
|
|
17
16
|
interface RegistryVersions {
|
|
@@ -401,12 +400,36 @@ const getRegistryVersions = async (
|
|
|
401
400
|
if (tagOrRange && pkgMetadata?.distTags[tagOrRange]) {
|
|
402
401
|
versions.wanted = pkgMetadata.distTags[tagOrRange];
|
|
403
402
|
} else if (tagOrRange && pkgMetadata?.versions.length) {
|
|
404
|
-
versions.wanted =
|
|
405
|
-
maxSatisfying(pkgMetadata.versions, tagOrRange) ?? undefined;
|
|
403
|
+
versions.wanted = maxSatisfying(pkgMetadata.versions, tagOrRange);
|
|
406
404
|
}
|
|
407
405
|
return versions;
|
|
408
406
|
};
|
|
409
407
|
|
|
408
|
+
/** the highest of `versions` within `range` (npm range syntax), if any */
|
|
409
|
+
const maxSatisfying = (
|
|
410
|
+
versions: string[],
|
|
411
|
+
range: string,
|
|
412
|
+
): string | undefined => {
|
|
413
|
+
const matching = versions.filter((version) => {
|
|
414
|
+
try {
|
|
415
|
+
return satisfies(version, range);
|
|
416
|
+
} catch {
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
if (!matching.length) return undefined;
|
|
421
|
+
return matching.sort(compareVersions)[matching.length - 1];
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
/** `a > b` for two versions; invalid input counts as "not newer" */
|
|
425
|
+
const gt = (a: string, b: string): boolean => {
|
|
426
|
+
try {
|
|
427
|
+
return compare(a, b, '>');
|
|
428
|
+
} catch {
|
|
429
|
+
return false;
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
|
|
410
433
|
const getInstalledVersion = (
|
|
411
434
|
pkgName: string,
|
|
412
435
|
location: keyof InstalledVersions = 'local',
|