react-native-update-cli 2.28.3 → 2.29.1

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.
@@ -1,48 +1,16 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
38
5
  Object.defineProperty(exports, "__esModule", { value: true });
39
6
  exports.resolveNativePackageEntry = resolveNativePackageEntry;
40
7
  exports.createSlimNativePackage = createSlimNativePackage;
41
- const fs = __importStar(require("fs-extra"));
8
+ const fs_1 = __importDefault(require("fs"));
42
9
  const os_1 = __importDefault(require("os"));
43
10
  const path_1 = __importDefault(require("path"));
44
11
  const yauzl_1 = require("yauzl");
45
12
  const yazl_1 = require("yazl");
13
+ const fs_helpers_1 = require("./utils/fs-helpers");
46
14
  const zip_raw_writer_1 = require("./utils/zip-raw-writer");
47
15
  const nativePackageRules = {
48
16
  android: {
@@ -130,7 +98,7 @@ class RepackSink {
130
98
  this.writePromise = new Promise((resolve, reject) => {
131
99
  this.outputZip.outputStream.once('error', reject);
132
100
  this.outputZip.outputStream
133
- .pipe(fs.createWriteStream(output))
101
+ .pipe(fs_1.default.createWriteStream(output))
134
102
  .once('error', reject)
135
103
  .once('close', () => resolve());
136
104
  });
@@ -164,7 +132,7 @@ class RepackSink {
164
132
  async abort() {
165
133
  this.outputZip.end();
166
134
  await this.writePromise.catch(() => { });
167
- await fs.remove(this.output).catch(() => { });
135
+ await (0, fs_helpers_1.remove)(this.output).catch(() => { });
168
136
  }
169
137
  }
170
138
  function openZip(source) {
@@ -189,7 +157,7 @@ function extractEntryToFile(sourceZip, entry, outputPath) {
189
157
  reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
190
158
  return;
191
159
  }
192
- const writeStream = fs.createWriteStream(outputPath);
160
+ const writeStream = fs_1.default.createWriteStream(outputPath);
193
161
  readStream.once('error', reject);
194
162
  writeStream.once('error', reject);
195
163
  writeStream.once('close', () => resolve());
@@ -198,13 +166,13 @@ function extractEntryToFile(sourceZip, entry, outputPath) {
198
166
  });
199
167
  }
200
168
  async function filterNativePackageArchive(source, output, platform, options) {
201
- await fs.ensureDir(path_1.default.dirname(output));
202
- const scratchDir = await fs.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'rnu-native-package-entry-'));
169
+ await (0, fs_helpers_1.ensureDir)(path_1.default.dirname(output));
170
+ const scratchDir = await fs_1.default.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'rnu-native-package-entry-'));
203
171
  const sourceZip = await openZip(source);
204
172
  // a subset of the source never outgrows it, so the source's own size and
205
173
  // entry count decide whether plain (non-zip64) headers are enough
206
174
  const rawCopy = !options.repack &&
207
- (0, zip_raw_writer_1.fitsRawZip)((await fs.stat(source)).size, sourceZip.entryCount);
175
+ (0, zip_raw_writer_1.fitsRawZip)((await fs_1.default.promises.stat(source)).size, sourceZip.entryCount);
208
176
  const sink = rawCopy
209
177
  ? new RawCopySink(output)
210
178
  : new RepackSink(output);
@@ -277,7 +245,7 @@ async function filterNativePackageArchive(source, output, platform, options) {
277
245
  throw error;
278
246
  }
279
247
  finally {
280
- await fs.remove(scratchDir);
248
+ await (0, fs_helpers_1.remove)(scratchDir);
281
249
  }
282
250
  }
283
251
  /**
@@ -287,7 +255,7 @@ async function filterNativePackageArchive(source, output, platform, options) {
287
255
  async function createSlimNativePackage(source, output, platform, options = {}) {
288
256
  const result = await filterNativePackageArchive(source, output, platform, options);
289
257
  if (result.bundles === 0) {
290
- await fs.remove(output);
258
+ await (0, fs_helpers_1.remove)(output);
291
259
  throw new Error(`Bundle entry not found in native package: ${source}`);
292
260
  }
293
261
  }
package/lib/package.js CHANGED
@@ -1,37 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
@@ -40,7 +7,7 @@ exports.packageCommands = void 0;
40
7
  exports.normalizeUploadBuildTime = normalizeUploadBuildTime;
41
8
  exports.listPackage = listPackage;
42
9
  exports.choosePackage = choosePackage;
43
- const fs = __importStar(require("fs-extra"));
10
+ const fs_1 = __importDefault(require("fs"));
44
11
  const os_1 = __importDefault(require("os"));
45
12
  const path_1 = __importDefault(require("path"));
46
13
  const api_1 = require("./api");
@@ -49,6 +16,7 @@ const native_package_1 = require("./native-package");
49
16
  const utils_1 = require("./utils");
50
17
  const constants_1 = require("./utils/constants");
51
18
  const dep_versions_1 = require("./utils/dep-versions");
19
+ const fs_helpers_1 = require("./utils/fs-helpers");
52
20
  const git_1 = require("./utils/git");
53
21
  const hermes_base_1 = require("./utils/hermes-base");
54
22
  const i18n_1 = require("./utils/i18n");
@@ -124,7 +92,7 @@ async function uploadNativePackage(filePath, options, config) {
124
92
  if (customVersion !== undefined) {
125
93
  console.log((0, i18n_1.t)('usingCustomVersion', { version: versionName }));
126
94
  }
127
- const tempRoot = await fs.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'rnu-native-package-upload-'));
95
+ const tempRoot = await fs_1.default.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'rnu-native-package-upload-'));
128
96
  const slimPackagePath = path_1.default.join(tempRoot, `package${config.extension}`);
129
97
  try {
130
98
  await (0, native_package_1.createSlimNativePackage)(filePath, slimPackagePath, config.platform);
@@ -170,7 +138,7 @@ async function uploadNativePackage(filePath, options, config) {
170
138
  }));
171
139
  }
172
140
  finally {
173
- await fs.remove(tempRoot);
141
+ await (0, fs_helpers_1.remove)(tempRoot);
174
142
  }
175
143
  }
176
144
  /**
@@ -252,7 +220,7 @@ exports.packageCommands = {
252
220
  const source = ensureFileByExt(args[0], '.aab', 'usageUploadAab');
253
221
  // private temp dir: unpredictable path, safe against symlink squatting in
254
222
  // the shared tmpdir and against concurrent uploads of same-named AABs
255
- const tempRoot = await fs.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'rnu-aab-upload-'));
223
+ const tempRoot = await fs_1.default.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'rnu-aab-upload-'));
256
224
  const output = path_1.default.join(tempRoot, 'universal.apk');
257
225
  const includeAllSplits = parseBooleanOption(options.includeAllSplits);
258
226
  const splits = parseCsvOption(options.splits);
@@ -268,7 +236,7 @@ exports.packageCommands = {
268
236
  });
269
237
  }
270
238
  finally {
271
- await fs.remove(tempRoot);
239
+ await (0, fs_helpers_1.remove)(tempRoot);
272
240
  }
273
241
  },
274
242
  uploadApp: async ({ args, options, }) => {
@@ -1,47 +1,15 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
38
5
  Object.defineProperty(exports, "__esModule", { value: true });
39
6
  exports.AabParser = void 0;
40
7
  const child_process_1 = require("child_process");
41
- const fs = __importStar(require("fs-extra"));
8
+ const fs_1 = __importDefault(require("fs"));
42
9
  const os_1 = __importDefault(require("os"));
43
10
  const path_1 = __importDefault(require("path"));
44
11
  const yauzl_1 = require("yauzl");
12
+ const fs_helpers_1 = require("../fs-helpers");
45
13
  const i18n_1 = require("../i18n");
46
14
  const resource_finder_1 = require("./resource-finder");
47
15
  const utils_1 = require("./utils");
@@ -78,7 +46,7 @@ class AabParser extends zip_1.Zip {
78
46
  });
79
47
  });
80
48
  // Create a temp file for the .apks output
81
- const tempDir = await fs.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'bundletool-'));
49
+ const tempDir = await fs_1.default.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'bundletool-'));
82
50
  const tempApksPath = path_1.default.join(tempDir, 'output.apks');
83
51
  const needsNpxDownload = async () => {
84
52
  try {
@@ -155,7 +123,7 @@ class AabParser extends zip_1.Zip {
155
123
  reject(err || new Error((0, i18n_1.t)('aabReadUniversalApkFailed')));
156
124
  return;
157
125
  }
158
- const writeStream = fs.createWriteStream(outputPath);
126
+ const writeStream = fs_1.default.createWriteStream(outputPath);
159
127
  readStream.pipe(writeStream);
160
128
  writeStream.on('close', () => {
161
129
  zipfile.close();
@@ -179,8 +147,8 @@ class AabParser extends zip_1.Zip {
179
147
  }
180
148
  finally {
181
149
  // Cleanup
182
- if (await fs.pathExists(tempDir)) {
183
- await fs.remove(tempDir);
150
+ if (await (0, fs_helpers_1.pathExists)(tempDir)) {
151
+ await (0, fs_helpers_1.remove)(tempDir);
184
152
  }
185
153
  }
186
154
  }
@@ -11,38 +11,30 @@ export declare class ResourceFinder {
11
11
  private responseMap;
12
12
  private entryMap;
13
13
  /**
14
- * Same to C# BinaryReader.readBytes
15
14
  *
16
- * @param bb ByteBuffer
17
- * @param len length
18
- * @returns {Buffer}
19
- */
20
- static readBytes(bb: any, len: number): any;
21
- /**
22
- *
23
- * @param {ByteBuffer} bb
15
+ * @param {Reader} bb
24
16
  * @return {Map<String, Set<String>>}
25
17
  */
26
18
  processResourceTable(resourceBuffer: Buffer): Record<string, any[]>;
27
19
  /**
28
20
  *
29
- * @param {ByteBuffer} bb
21
+ * @param {Reader} bb
30
22
  */
31
23
  private processPackage;
32
24
  /**
33
25
  *
34
- * @param {ByteBuffer} bb
26
+ * @param {Reader} bb
35
27
  */
36
28
  private processType;
37
29
  /**
38
30
  *
39
- * @param {ByteBuffer} bb
31
+ * @param {Reader} bb
40
32
  * @return {Array}
41
33
  */
42
34
  private processStringPool;
43
35
  /**
44
36
  *
45
- * @param {ByteBuffer} bb
37
+ * @param {Reader} bb
46
38
  */
47
39
  private processTypeSpec;
48
40
  private putIntoMap;
@@ -6,7 +6,55 @@
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.ResourceFinder = void 0;
9
- const ByteBuffer = require('bytebuffer');
9
+ /**
10
+ * Little-endian cursor over a Buffer: the subset of the `bytebuffer` API this
11
+ * decoder used. Reads past `limit` throw a RangeError, which the chunk loops
12
+ * below rely on to stop at the end of the data.
13
+ */
14
+ class Reader {
15
+ buffer;
16
+ offset = 0;
17
+ limit;
18
+ constructor(buffer) {
19
+ this.buffer = buffer;
20
+ this.limit = buffer.length;
21
+ }
22
+ advance(size) {
23
+ const at = this.offset;
24
+ if (at < 0 || at + size > this.limit) {
25
+ throw new RangeError(`Illegal offset: 0 <= ${at} (+${size}) <= ${this.limit}`);
26
+ }
27
+ this.offset = at + size;
28
+ return at;
29
+ }
30
+ remaining() {
31
+ return this.limit - this.offset;
32
+ }
33
+ readByte() {
34
+ return this.buffer.readInt8(this.advance(1));
35
+ }
36
+ readUint8() {
37
+ return this.buffer.readUInt8(this.advance(1));
38
+ }
39
+ readShort() {
40
+ return this.buffer.readInt16LE(this.advance(2));
41
+ }
42
+ readUint16() {
43
+ return this.buffer.readUInt16LE(this.advance(2));
44
+ }
45
+ readInt() {
46
+ return this.buffer.readInt32LE(this.advance(4));
47
+ }
48
+ /** The next `len` bytes as a new reader (a view, not a copy). */
49
+ readBytes(len) {
50
+ const at = this.advance(len);
51
+ return new Reader(this.buffer.subarray(at, at + len));
52
+ }
53
+ }
54
+ /** The `size`-byte chunk starting at `pos`, cut short at the end of the data. */
55
+ function chunkAt(bb, pos, size) {
56
+ return new Reader(bb.buffer.subarray(pos, pos + size));
57
+ }
10
58
  const DEBUG = false;
11
59
  const RES_STRING_POOL_TYPE = 0x0001;
12
60
  const RES_TABLE_TYPE = 0x0002;
@@ -22,33 +70,17 @@ class ResourceFinder {
22
70
  packageId = 0;
23
71
  responseMap = {};
24
72
  entryMap = {};
25
- /**
26
- * Same to C# BinaryReader.readBytes
27
- *
28
- * @param bb ByteBuffer
29
- * @param len length
30
- * @returns {Buffer}
31
- */
32
- static readBytes(bb, len) {
33
- const uint8Array = new Uint8Array(len);
34
- for (let i = 0; i < len; i++) {
35
- uint8Array[i] = bb.readUint8();
36
- }
37
- return ByteBuffer.wrap(uint8Array, 'binary', true);
38
- }
39
73
  /**
40
74
  *
41
- * @param {ByteBuffer} bb
75
+ * @param {Reader} bb
42
76
  * @return {Map<String, Set<String>>}
43
77
  */
44
78
  processResourceTable(resourceBuffer) {
45
- const bb = ByteBuffer.wrap(resourceBuffer, 'binary', true);
79
+ const bb = new Reader(resourceBuffer);
46
80
  const type = bb.readShort();
47
81
  const headerSize = bb.readShort();
48
82
  const size = bb.readInt();
49
83
  const packageCount = bb.readInt();
50
- let buffer;
51
- let bb2;
52
84
  if (type !== RES_TABLE_TYPE) {
53
85
  throw new Error('No RES_TABLE_TYPE found!');
54
86
  }
@@ -77,12 +109,7 @@ class ResourceFinder {
77
109
  if (DEBUG) {
78
110
  console.log('Processing the string pool ...');
79
111
  }
80
- buffer = new ByteBuffer(s);
81
- bb.offset = pos;
82
- bb.prependTo(buffer);
83
- bb2 = ByteBuffer.wrap(buffer, 'binary', true);
84
- bb2.LE();
85
- this.valueStringPool = this.processStringPool(bb2);
112
+ this.valueStringPool = this.processStringPool(chunkAt(bb, pos, s));
86
113
  }
87
114
  realStringPoolCount++;
88
115
  }
@@ -90,12 +117,7 @@ class ResourceFinder {
90
117
  if (DEBUG) {
91
118
  console.log(`Processing the package ${realPackageCount} ...`);
92
119
  }
93
- buffer = new ByteBuffer(s);
94
- bb.offset = pos;
95
- bb.prependTo(buffer);
96
- bb2 = ByteBuffer.wrap(buffer, 'binary', true);
97
- bb2.LE();
98
- this.processPackage(bb2);
120
+ this.processPackage(chunkAt(bb, pos, s));
99
121
  realPackageCount++;
100
122
  }
101
123
  else {
@@ -115,7 +137,7 @@ class ResourceFinder {
115
137
  }
116
138
  /**
117
139
  *
118
- * @param {ByteBuffer} bb
140
+ * @param {Reader} bb
119
141
  */
120
142
  processPackage(bb) {
121
143
  const type = bb.readShort();
@@ -142,7 +164,7 @@ class ResourceFinder {
142
164
  }
143
165
  let lastPosition = bb.offset;
144
166
  bb.offset = typeStrings;
145
- const bbTypeStrings = ResourceFinder.readBytes(bb, bb.limit - bb.offset);
167
+ const bbTypeStrings = bb.readBytes(bb.limit - bb.offset);
146
168
  bb.offset = lastPosition;
147
169
  this.typeStringPool = this.processStringPool(bbTypeStrings);
148
170
  if (DEBUG) {
@@ -156,7 +178,7 @@ class ResourceFinder {
156
178
  void keyHeaderSize;
157
179
  lastPosition = bb.offset;
158
180
  bb.offset = keyStrings;
159
- const bbKeyStrings = ResourceFinder.readBytes(bb, bb.limit - bb.offset);
181
+ const bbKeyStrings = bb.readBytes(bb.limit - bb.offset);
160
182
  bb.offset = lastPosition;
161
183
  this.keyStringPool = this.processStringPool(bbKeyStrings);
162
184
  let typeSpecCount = 0;
@@ -172,13 +194,13 @@ class ResourceFinder {
172
194
  void hs;
173
195
  if (t === RES_TABLE_TYPE_SPEC_TYPE) {
174
196
  bb.offset = pos;
175
- bb2 = ResourceFinder.readBytes(bb, s);
197
+ bb2 = bb.readBytes(s);
176
198
  this.processTypeSpec(bb2);
177
199
  typeSpecCount++;
178
200
  }
179
201
  else if (t === RES_TABLE_TYPE_TYPE) {
180
202
  bb.offset = pos;
181
- bb2 = ResourceFinder.readBytes(bb, s);
203
+ bb2 = bb.readBytes(s);
182
204
  this.processType(bb2);
183
205
  typeCount++;
184
206
  }
@@ -199,7 +221,7 @@ class ResourceFinder {
199
221
  }
200
222
  /**
201
223
  *
202
- * @param {ByteBuffer} bb
224
+ * @param {Reader} bb
203
225
  */
204
226
  processType(bb) {
205
227
  const type = bb.readShort();
@@ -309,7 +331,7 @@ class ResourceFinder {
309
331
  }
310
332
  /**
311
333
  *
312
- * @param {ByteBuffer} bb
334
+ * @param {Reader} bb
313
335
  * @return {Array}
314
336
  */
315
337
  processStringPool(bb) {
@@ -346,16 +368,7 @@ class ResourceFinder {
346
368
  u8len = ((u8len & 0x7f) << 8) + bb.readUint8();
347
369
  }
348
370
  if (u8len > 0) {
349
- const buffer = ResourceFinder.readBytes(bb, u8len);
350
- try {
351
- strings[i] = ByteBuffer.wrap(buffer, 'utf8', true).toString('utf8');
352
- }
353
- catch (e) {
354
- if (DEBUG) {
355
- console.error(e);
356
- console.log('Error when turning buffer to utf-8 string.');
357
- }
358
- }
371
+ strings[i] = bb.readBytes(u8len).buffer.toString('utf8');
359
372
  }
360
373
  else {
361
374
  strings[i] = '';
@@ -367,17 +380,7 @@ class ResourceFinder {
367
380
  u16len = ((u16len & 0x7fff) << 16) + bb.readUint16();
368
381
  }
369
382
  if (u16len > 0) {
370
- const len = u16len * 2;
371
- const buffer = ResourceFinder.readBytes(bb, len);
372
- try {
373
- strings[i] = ByteBuffer.wrap(buffer, 'utf8', true).toString('utf8');
374
- }
375
- catch (e) {
376
- if (DEBUG) {
377
- console.error(e);
378
- console.log('Error when turning buffer to utf-8 string.');
379
- }
380
- }
383
+ strings[i] = bb.readBytes(u16len * 2).buffer.toString('utf16le');
381
384
  }
382
385
  }
383
386
  if (DEBUG) {
@@ -388,7 +391,7 @@ class ResourceFinder {
388
391
  }
389
392
  /**
390
393
  *
391
- * @param {ByteBuffer} bb
394
+ * @param {Reader} bb
392
395
  */
393
396
  processTypeSpec(bb) {
394
397
  const type = bb.readShort();
@@ -0,0 +1,13 @@
1
+ /** `rm -rf`: no error when the path is already gone. */
2
+ export declare function remove(target: string): Promise<void>;
3
+ export declare function removeSync(target: string): void;
4
+ export declare function ensureDir(dir: string): Promise<void>;
5
+ export declare function ensureDirSync(dir: string): void;
6
+ export declare function pathExists(target: string): Promise<boolean>;
7
+ /** Deletes everything inside `dir`, creating it when missing. */
8
+ export declare function emptyDirSync(dir: string): void;
9
+ /**
10
+ * Moves `src` to `dest`, replacing it. Creates the parent of `dest`, and
11
+ * falls back to copy + delete when the two are on different devices.
12
+ */
13
+ export declare function moveSync(src: string, dest: string): void;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ // The handful of fs-extra conveniences the CLI used, on plain node:fs.
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.remove = remove;
8
+ exports.removeSync = removeSync;
9
+ exports.ensureDir = ensureDir;
10
+ exports.ensureDirSync = ensureDirSync;
11
+ exports.pathExists = pathExists;
12
+ exports.emptyDirSync = emptyDirSync;
13
+ exports.moveSync = moveSync;
14
+ const fs_1 = __importDefault(require("fs"));
15
+ const path_1 = __importDefault(require("path"));
16
+ /** `rm -rf`: no error when the path is already gone. */
17
+ function remove(target) {
18
+ return fs_1.default.promises.rm(target, { recursive: true, force: true });
19
+ }
20
+ function removeSync(target) {
21
+ fs_1.default.rmSync(target, { recursive: true, force: true });
22
+ }
23
+ async function ensureDir(dir) {
24
+ await fs_1.default.promises.mkdir(dir, { recursive: true });
25
+ }
26
+ function ensureDirSync(dir) {
27
+ fs_1.default.mkdirSync(dir, { recursive: true });
28
+ }
29
+ function pathExists(target) {
30
+ return fs_1.default.promises.access(target).then(() => true, () => false);
31
+ }
32
+ /** Deletes everything inside `dir`, creating it when missing. */
33
+ function emptyDirSync(dir) {
34
+ let names;
35
+ try {
36
+ names = fs_1.default.readdirSync(dir);
37
+ }
38
+ catch (err) {
39
+ // only a missing directory is created; an unreadable one must not pass
40
+ // for emptied
41
+ if (err.code !== 'ENOENT')
42
+ throw err;
43
+ ensureDirSync(dir);
44
+ return;
45
+ }
46
+ for (const name of names)
47
+ removeSync(path_1.default.join(dir, name));
48
+ }
49
+ /**
50
+ * Moves `src` to `dest`, replacing it. Creates the parent of `dest`, and
51
+ * falls back to copy + delete when the two are on different devices.
52
+ */
53
+ function moveSync(src, dest) {
54
+ ensureDirSync(path_1.default.dirname(dest));
55
+ try {
56
+ fs_1.default.renameSync(src, dest);
57
+ }
58
+ catch (err) {
59
+ if (err.code !== 'EXDEV')
60
+ throw err;
61
+ removeSync(dest);
62
+ fs_1.default.cpSync(src, dest, { recursive: true });
63
+ removeSync(src);
64
+ }
65
+ }