sv 0.17.0 → 0.17.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,6 +1,8 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { AGENTS, COMMANDS, KIT3_TSCONFIG, KIT3_TSCONFIG_DEFAULT, Walker, coerceVersion, color, constructCommand, createPrinter, dedent, defineEnv, detect, downloadJson, fileExists, isKit3, isVersionUnsupportedBelow, js, libSubpathImports, loadFile, loadPackageJson, minVersion, parse, pnpm, resolveCommand, resolveCommandArray, resolveLibPrefix, sanitizeName, saveFile, svelte, svelteConfig, transforms } from "@sveltejs/sv-utils";
3
+ import * as fs$1 from "node:fs";
3
4
  import fs, { closeSync, existsSync, openSync, readSync, statSync } from "node:fs";
5
+ import * as path$1 from "node:path";
4
6
  import path, { basename, delimiter, dirname, isAbsolute, join, normalize, resolve } from "node:path";
5
7
  import { promisify, stripVTControlCharacters, styleText } from "node:util";
6
8
  import V, { cwd, stdin, stdout } from "node:process";
@@ -10,10 +12,11 @@ import { ReadStream } from "node:tty";
10
12
  import { fileURLToPath } from "node:url";
11
13
  import childProcess, { exec, spawn, spawnSync } from "node:child_process";
12
14
  import { pipeline } from "node:stream/promises";
13
- import { PassThrough } from "node:stream";
15
+ import { PassThrough, Writable } from "node:stream";
14
16
  import { EventEmitter } from "node:events";
15
17
  import crypto from "node:crypto";
16
- import { platform } from "node:os";
18
+ import * as fsp from "node:fs/promises";
19
+ import { cpus, platform } from "node:os";
17
20
  import { createGunzip } from "node:zlib";
18
21
  //#region \0rolldown/runtime.js
19
22
  var __create = Object.create;
@@ -1348,7 +1351,7 @@ ${i ? styleText("cyan", x$1) : ""}
1348
1351
  //#endregion
1349
1352
  //#region package.json
1350
1353
  var name = "sv";
1351
- var version = "0.17.0";
1354
+ var version = "0.17.1";
1352
1355
  //#endregion
1353
1356
  //#region src/core/errors.ts
1354
1357
  var UnsupportedError = class extends Error {
@@ -6628,9 +6631,14 @@ var drizzle_default = defineAddon({
6628
6631
  group: "client",
6629
6632
  default: "libsql",
6630
6633
  options: [
6634
+ {
6635
+ value: "node-sqlite",
6636
+ label: "node:sqlite",
6637
+ hint: "built-in to Node.js and Deno"
6638
+ },
6631
6639
  {
6632
6640
  value: "better-sqlite3",
6633
- hint: "for traditional Node environments"
6641
+ hint: "for server environments"
6634
6642
  },
6635
6643
  {
6636
6644
  value: "libsql",
@@ -6906,6 +6914,17 @@ var drizzle_default = defineAddon({
6906
6914
  clientExpression = js.common.parseExpression(`createClient({ url: ${dbUrl}, authToken: ${dbToken} })`);
6907
6915
  } else clientExpression = js.common.parseExpression(`createClient({ url: ${dbUrl} })`);
6908
6916
  }
6917
+ if (options.sqlite === "node-sqlite") {
6918
+ js.imports.addNamed(ast, {
6919
+ from: "node:sqlite",
6920
+ imports: ["DatabaseSync"]
6921
+ });
6922
+ js.imports.addNamed(ast, {
6923
+ from: "drizzle-orm/node-sqlite",
6924
+ imports: ["drizzle"]
6925
+ });
6926
+ clientExpression = js.common.parseExpression(`new DatabaseSync(${dbUrl})`);
6927
+ }
6909
6928
  if (options.mysql === "mysql2" || options.mysql === "planetscale") {
6910
6929
  js.imports.addDefault(ast, {
6911
6930
  from: "mysql2/promise",
@@ -7008,7 +7027,11 @@ const generateEnv = (opts, isExample) => transforms.text(({ content, text }) =>
7008
7027
  let value;
7009
7028
  const comment = ["Drizzle"];
7010
7029
  if (opts.docker) value = `"${opts.database === "mysql" ? "mysql" : "postgres"}://root:mysecretpassword@localhost:${PORTS[opts.database]}/local"`;
7011
- else if (opts.sqlite === "better-sqlite3" || opts.sqlite === "libsql") value = opts.sqlite === "libsql" ? "file:local.db" : "local.db";
7030
+ else if ([
7031
+ "better-sqlite3",
7032
+ "libsql",
7033
+ "node-sqlite"
7034
+ ].includes(opts.sqlite)) value = opts.sqlite === "libsql" ? "file:local.db" : "local.db";
7012
7035
  else if (opts.sqlite === "turso") if (isExample) {
7013
7036
  value = "\"libsql://db-name-user.turso.io\"";
7014
7037
  comment.push("Replace with your DB credentials!", {
@@ -8093,2711 +8116,1048 @@ function getAddonDetails(id) {
8093
8116
  return details;
8094
8117
  }
8095
8118
  //#endregion
8096
- //#region ../../node_modules/.pnpm/events-universal@1.0.1/node_modules/events-universal/default.js
8097
- var require_default = /* @__PURE__ */ __commonJSMin(((exports, module) => {
8098
- module.exports = __require("events");
8099
- }));
8100
- //#endregion
8101
- //#region ../../node_modules/.pnpm/fast-fifo@1.3.2/node_modules/fast-fifo/fixed-size.js
8102
- var require_fixed_size = /* @__PURE__ */ __commonJSMin(((exports, module) => {
8103
- module.exports = class FixedFIFO {
8104
- constructor(hwm) {
8105
- if (!(hwm > 0) || (hwm - 1 & hwm) !== 0) throw new Error("Max size for a FixedFIFO should be a power of two");
8106
- this.buffer = new Array(hwm);
8107
- this.mask = hwm - 1;
8108
- this.top = 0;
8109
- this.btm = 0;
8110
- this.next = null;
8111
- }
8112
- clear() {
8113
- this.top = this.btm = 0;
8114
- this.next = null;
8115
- this.buffer.fill(void 0);
8116
- }
8117
- push(data) {
8118
- if (this.buffer[this.top] !== void 0) return false;
8119
- this.buffer[this.top] = data;
8120
- this.top = this.top + 1 & this.mask;
8121
- return true;
8122
- }
8123
- shift() {
8124
- const last = this.buffer[this.btm];
8125
- if (last === void 0) return void 0;
8126
- this.buffer[this.btm] = void 0;
8127
- this.btm = this.btm + 1 & this.mask;
8128
- return last;
8129
- }
8130
- peek() {
8131
- return this.buffer[this.btm];
8132
- }
8133
- isEmpty() {
8134
- return this.buffer[this.btm] === void 0;
8119
+ //#region ../../node_modules/.pnpm/modern-tar@0.7.7/node_modules/modern-tar/dist/packer-BtsuoKCV.js
8120
+ const FILE = "file";
8121
+ const LINK = "link";
8122
+ const SYMLINK = "symlink";
8123
+ const DIRECTORY = "directory";
8124
+ const FLAGTYPE = {
8125
+ "0": FILE,
8126
+ "1": LINK,
8127
+ "2": SYMLINK,
8128
+ "3": "character-device",
8129
+ "4": "block-device",
8130
+ "5": DIRECTORY,
8131
+ "6": "fifo",
8132
+ x: "pax-header",
8133
+ g: "pax-global-header",
8134
+ L: "gnu-long-name",
8135
+ K: "gnu-long-link-name"
8136
+ };
8137
+ const EMPTY = /* @__PURE__ */ new Uint8Array(0);
8138
+ new TextEncoder();
8139
+ const decoder = new TextDecoder();
8140
+ function readString(view, offset, size) {
8141
+ const end = view.indexOf(0, offset);
8142
+ const sliceEnd = end === -1 || end > offset + size ? offset + size : end;
8143
+ return decoder.decode(view.subarray(offset, sliceEnd));
8144
+ }
8145
+ function readOctal(view, offset, size) {
8146
+ let value = 0;
8147
+ const end = offset + size;
8148
+ for (let i = offset; i < end; i++) {
8149
+ const charCode = view[i];
8150
+ if (charCode === 0) break;
8151
+ if (charCode === 32) continue;
8152
+ value = value * 8 + (charCode - 48);
8153
+ }
8154
+ return value;
8155
+ }
8156
+ function readNumeric(view, offset, size) {
8157
+ if (view[offset] & 128) {
8158
+ let result = 0;
8159
+ result = view[offset] & 127;
8160
+ for (let i = 1; i < size; i++) result = result * 256 + view[offset + i];
8161
+ if (!Number.isSafeInteger(result)) throw new Error("TAR number too large");
8162
+ return result;
8163
+ }
8164
+ return readOctal(view, offset, size);
8165
+ }
8166
+ const isBodyless = (header) => header.type === "directory" || header.type === "symlink" || header.type === "link" || header.type === "character-device" || header.type === "block-device" || header.type === "fifo";
8167
+ const stripPath = (p, n) => {
8168
+ const parts = p.split("/").filter(Boolean);
8169
+ return n >= parts.length ? "" : parts.slice(n).join("/");
8170
+ };
8171
+ function transformHeader(header, options) {
8172
+ const { strip, filter, map } = options;
8173
+ if (!strip && !filter && !map) return header;
8174
+ const h = { ...header };
8175
+ if (strip && strip > 0) {
8176
+ const newName = stripPath(h.name, strip);
8177
+ if (!newName) return null;
8178
+ h.name = h.type === "directory" && !newName.endsWith("/") ? `${newName}/` : newName;
8179
+ if (h.linkname) {
8180
+ const isAbsolute = h.linkname.startsWith("/");
8181
+ if (isAbsolute || h.type === "link") {
8182
+ const stripped = stripPath(h.linkname, strip);
8183
+ h.linkname = isAbsolute ? `/${stripped}` || "/" : stripped;
8184
+ }
8185
+ }
8186
+ }
8187
+ if (filter?.(h) === false) return null;
8188
+ const result = map ? map(h) : h;
8189
+ if (result && (!result.name || !result.name.trim() || result.name === "." || result.name === "/")) return null;
8190
+ return result;
8191
+ }
8192
+ const INITIAL_CAPACITY = 256;
8193
+ function createChunkQueue() {
8194
+ let chunks = new Array(INITIAL_CAPACITY);
8195
+ let capacityMask = chunks.length - 1;
8196
+ let head = 0;
8197
+ let tail = 0;
8198
+ let totalAvailable = 0;
8199
+ const consumeFromHead = (count) => {
8200
+ const chunk = chunks[head];
8201
+ if (count === chunk.length) {
8202
+ chunks[head] = EMPTY;
8203
+ head = head + 1 & capacityMask;
8204
+ } else chunks[head] = chunk.subarray(count);
8205
+ totalAvailable -= count;
8206
+ if (totalAvailable === 0 && chunks.length > INITIAL_CAPACITY) {
8207
+ chunks = new Array(INITIAL_CAPACITY);
8208
+ capacityMask = INITIAL_CAPACITY - 1;
8209
+ head = 0;
8210
+ tail = 0;
8135
8211
  }
8136
8212
  };
8137
- }));
8138
- //#endregion
8139
- //#region ../../node_modules/.pnpm/fast-fifo@1.3.2/node_modules/fast-fifo/index.js
8140
- var require_fast_fifo = /* @__PURE__ */ __commonJSMin(((exports, module) => {
8141
- const FixedFIFO = require_fixed_size();
8142
- module.exports = class FastFIFO {
8143
- constructor(hwm) {
8144
- this.hwm = hwm || 16;
8145
- this.head = new FixedFIFO(this.hwm);
8146
- this.tail = this.head;
8147
- this.length = 0;
8213
+ function pull(bytes, callback) {
8214
+ if (callback) {
8215
+ let fed = 0;
8216
+ let remaining = Math.min(bytes, totalAvailable);
8217
+ while (remaining > 0) {
8218
+ const chunk = chunks[head];
8219
+ const toFeed = Math.min(remaining, chunk.length);
8220
+ const segment = toFeed === chunk.length ? chunk : chunk.subarray(0, toFeed);
8221
+ consumeFromHead(toFeed);
8222
+ remaining -= toFeed;
8223
+ fed += toFeed;
8224
+ if (!callback(segment)) break;
8225
+ }
8226
+ return fed;
8227
+ }
8228
+ if (totalAvailable < bytes) return null;
8229
+ if (bytes === 0) return EMPTY;
8230
+ const firstChunk = chunks[head];
8231
+ if (firstChunk.length >= bytes) {
8232
+ const view = firstChunk.length === bytes ? firstChunk : firstChunk.subarray(0, bytes);
8233
+ consumeFromHead(bytes);
8234
+ return view;
8235
+ }
8236
+ const result = new Uint8Array(bytes);
8237
+ let copied = 0;
8238
+ let remaining = bytes;
8239
+ while (remaining > 0) {
8240
+ const chunk = chunks[head];
8241
+ const toCopy = Math.min(remaining, chunk.length);
8242
+ result.set(toCopy === chunk.length ? chunk : chunk.subarray(0, toCopy), copied);
8243
+ copied += toCopy;
8244
+ remaining -= toCopy;
8245
+ consumeFromHead(toCopy);
8148
8246
  }
8149
- clear() {
8150
- this.head = this.tail;
8151
- this.head.clear();
8152
- this.length = 0;
8153
- }
8154
- push(val) {
8155
- this.length++;
8156
- if (!this.head.push(val)) {
8157
- const prev = this.head;
8158
- this.head = prev.next = new FixedFIFO(2 * this.head.buffer.length);
8159
- this.head.push(val);
8247
+ return result;
8248
+ }
8249
+ return {
8250
+ push: (chunk) => {
8251
+ if (chunk.length === 0) return;
8252
+ let nextTail = tail + 1 & capacityMask;
8253
+ if (nextTail === head) {
8254
+ const oldLen = chunks.length;
8255
+ const newLen = oldLen * 2;
8256
+ const newChunks = new Array(newLen);
8257
+ const count = tail - head + oldLen & oldLen - 1;
8258
+ if (head < tail) for (let i = 0; i < count; i++) newChunks[i] = chunks[head + i];
8259
+ else if (count > 0) {
8260
+ const firstPart = oldLen - head;
8261
+ for (let i = 0; i < firstPart; i++) newChunks[i] = chunks[head + i];
8262
+ for (let i = 0; i < tail; i++) newChunks[firstPart + i] = chunks[i];
8263
+ }
8264
+ chunks = newChunks;
8265
+ capacityMask = newLen - 1;
8266
+ head = 0;
8267
+ tail = count;
8268
+ nextTail = tail + 1 & capacityMask;
8269
+ }
8270
+ chunks[tail] = chunk;
8271
+ tail = nextTail;
8272
+ totalAvailable += chunk.length;
8273
+ },
8274
+ available: () => totalAvailable,
8275
+ peek: (bytes) => {
8276
+ if (totalAvailable < bytes) return null;
8277
+ if (bytes === 0) return EMPTY;
8278
+ const firstChunk = chunks[head];
8279
+ if (firstChunk.length >= bytes) return firstChunk.length === bytes ? firstChunk : firstChunk.subarray(0, bytes);
8280
+ const result = new Uint8Array(bytes);
8281
+ let copied = 0;
8282
+ let index = head;
8283
+ while (copied < bytes) {
8284
+ const chunk = chunks[index];
8285
+ const toCopy = Math.min(bytes - copied, chunk.length);
8286
+ if (toCopy === chunk.length) result.set(chunk, copied);
8287
+ else result.set(chunk.subarray(0, toCopy), copied);
8288
+ copied += toCopy;
8289
+ index = index + 1 & capacityMask;
8160
8290
  }
8161
- }
8162
- shift() {
8163
- if (this.length !== 0) this.length--;
8164
- const val = this.tail.shift();
8165
- if (val === void 0 && this.tail.next) {
8166
- const next = this.tail.next;
8167
- this.tail.next = null;
8168
- this.tail = next;
8169
- return this.tail.shift();
8291
+ return result;
8292
+ },
8293
+ discard: (bytes) => {
8294
+ if (bytes > totalAvailable) throw new Error("Too many bytes consumed");
8295
+ if (bytes === 0) return;
8296
+ let remaining = bytes;
8297
+ while (remaining > 0) {
8298
+ const chunk = chunks[head];
8299
+ const toConsume = Math.min(remaining, chunk.length);
8300
+ consumeFromHead(toConsume);
8301
+ remaining -= toConsume;
8170
8302
  }
8171
- return val;
8172
- }
8173
- peek() {
8174
- const val = this.tail.peek();
8175
- if (val === void 0 && this.tail.next) return this.tail.next.peek();
8176
- return val;
8177
- }
8178
- isEmpty() {
8179
- return this.length === 0;
8180
- }
8181
- };
8182
- }));
8183
- //#endregion
8184
- //#region ../../node_modules/.pnpm/b4a@1.8.1/node_modules/b4a/index.js
8185
- var require_b4a = /* @__PURE__ */ __commonJSMin(((exports, module) => {
8186
- function isBuffer(value) {
8187
- return Buffer.isBuffer(value) || value instanceof Uint8Array;
8188
- }
8189
- function isEncoding(encoding) {
8190
- return Buffer.isEncoding(encoding);
8191
- }
8192
- function alloc(size, fill, encoding) {
8193
- return Buffer.alloc(size, fill, encoding);
8194
- }
8195
- function allocUnsafe(size) {
8196
- return Buffer.allocUnsafe(size);
8197
- }
8198
- function allocUnsafeSlow(size) {
8199
- return Buffer.allocUnsafeSlow(size);
8200
- }
8201
- function byteLength(string, encoding) {
8202
- return Buffer.byteLength(string, encoding);
8203
- }
8204
- function compare(a, b) {
8205
- return Buffer.compare(a, b);
8206
- }
8207
- function concat(buffers, totalLength) {
8208
- return Buffer.concat(buffers, totalLength);
8209
- }
8210
- function copy(source, target, targetStart, start, end) {
8211
- return toBuffer(source).copy(target, targetStart, start, end);
8212
- }
8213
- function equals(a, b) {
8214
- return toBuffer(a).equals(b);
8215
- }
8216
- function fill(buffer, value, offset, end, encoding) {
8217
- return toBuffer(buffer).fill(value, offset, end, encoding);
8218
- }
8219
- function from(value, encodingOrOffset, length) {
8220
- return Buffer.from(value, encodingOrOffset, length);
8221
- }
8222
- function includes(buffer, value, byteOffset, encoding) {
8223
- return toBuffer(buffer).includes(value, byteOffset, encoding);
8224
- }
8225
- function indexOf(buffer, value, byfeOffset, encoding) {
8226
- return toBuffer(buffer).indexOf(value, byfeOffset, encoding);
8227
- }
8228
- function lastIndexOf(buffer, value, byteOffset, encoding) {
8229
- return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding);
8230
- }
8231
- function swap16(buffer) {
8232
- return toBuffer(buffer).swap16();
8233
- }
8234
- function swap32(buffer) {
8235
- return toBuffer(buffer).swap32();
8236
- }
8237
- function swap64(buffer) {
8238
- return toBuffer(buffer).swap64();
8239
- }
8240
- function toBuffer(buffer) {
8241
- if (Buffer.isBuffer(buffer)) return buffer;
8242
- return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
8243
- }
8244
- function toString(buffer, encoding, start, end) {
8245
- return toBuffer(buffer).toString(encoding, start, end);
8246
- }
8247
- function write(buffer, string, offset, length, encoding) {
8248
- return toBuffer(buffer).write(string, offset, length, encoding);
8249
- }
8250
- function readDoubleBE(buffer, offset) {
8251
- return toBuffer(buffer).readDoubleBE(offset);
8252
- }
8253
- function readDoubleLE(buffer, offset) {
8254
- return toBuffer(buffer).readDoubleLE(offset);
8255
- }
8256
- function readFloatBE(buffer, offset) {
8257
- return toBuffer(buffer).readFloatBE(offset);
8258
- }
8259
- function readFloatLE(buffer, offset) {
8260
- return toBuffer(buffer).readFloatLE(offset);
8261
- }
8262
- function readInt32BE(buffer, offset) {
8263
- return toBuffer(buffer).readInt32BE(offset);
8264
- }
8265
- function readInt32LE(buffer, offset) {
8266
- return toBuffer(buffer).readInt32LE(offset);
8267
- }
8268
- function readUInt32BE(buffer, offset) {
8269
- return toBuffer(buffer).readUInt32BE(offset);
8270
- }
8271
- function readUInt32LE(buffer, offset) {
8272
- return toBuffer(buffer).readUInt32LE(offset);
8273
- }
8274
- function writeDoubleBE(buffer, value, offset) {
8275
- return toBuffer(buffer).writeDoubleBE(value, offset);
8276
- }
8277
- function writeDoubleLE(buffer, value, offset) {
8278
- return toBuffer(buffer).writeDoubleLE(value, offset);
8279
- }
8280
- function writeFloatBE(buffer, value, offset) {
8281
- return toBuffer(buffer).writeFloatBE(value, offset);
8282
- }
8283
- function writeFloatLE(buffer, value, offset) {
8284
- return toBuffer(buffer).writeFloatLE(value, offset);
8285
- }
8286
- function writeInt32BE(buffer, value, offset) {
8287
- return toBuffer(buffer).writeInt32BE(value, offset);
8288
- }
8289
- function writeInt32LE(buffer, value, offset) {
8290
- return toBuffer(buffer).writeInt32LE(value, offset);
8291
- }
8292
- function writeUInt32BE(buffer, value, offset) {
8293
- return toBuffer(buffer).writeUInt32BE(value, offset);
8294
- }
8295
- function writeUInt32LE(buffer, value, offset) {
8296
- return toBuffer(buffer).writeUInt32LE(value, offset);
8297
- }
8298
- module.exports = {
8299
- isBuffer,
8300
- isEncoding,
8301
- alloc,
8302
- allocUnsafe,
8303
- allocUnsafeSlow,
8304
- byteLength,
8305
- compare,
8306
- concat,
8307
- copy,
8308
- equals,
8309
- fill,
8310
- from,
8311
- includes,
8312
- indexOf,
8313
- lastIndexOf,
8314
- swap16,
8315
- swap32,
8316
- swap64,
8317
- toBuffer,
8318
- toString,
8319
- write,
8320
- readDoubleBE,
8321
- readDoubleLE,
8322
- readFloatBE,
8323
- readFloatLE,
8324
- readInt32BE,
8325
- readInt32LE,
8326
- readUInt32BE,
8327
- readUInt32LE,
8328
- writeDoubleBE,
8329
- writeDoubleLE,
8330
- writeFloatBE,
8331
- writeFloatLE,
8332
- writeInt32BE,
8333
- writeInt32LE,
8334
- writeUInt32BE,
8335
- writeUInt32LE
8303
+ },
8304
+ pull
8336
8305
  };
8337
- }));
8338
- //#endregion
8339
- //#region ../../node_modules/.pnpm/text-decoder@1.2.7/node_modules/text-decoder/lib/pass-through-decoder.js
8340
- var require_pass_through_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
8341
- const b4a = require_b4a();
8342
- module.exports = class PassThroughDecoder {
8343
- constructor(encoding) {
8344
- this.encoding = encoding;
8345
- }
8346
- get remaining() {
8347
- return 0;
8348
- }
8349
- decode(data) {
8350
- return b4a.toString(data, this.encoding);
8351
- }
8352
- flush() {
8353
- return "";
8354
- }
8306
+ }
8307
+ const CHECKSUM_SPACE = 32;
8308
+ function validateChecksum(block) {
8309
+ const stored = readOctal(block, 148, 8);
8310
+ let sum = 0;
8311
+ for (let i = 0; i < block.length; i++) if (i >= 148 && i < 156) sum += CHECKSUM_SPACE;
8312
+ else sum += block[i];
8313
+ return stored === sum;
8314
+ }
8315
+ function parseUstarHeader(block, strict) {
8316
+ if (strict && !validateChecksum(block)) throw new Error("Invalid tar header checksum.");
8317
+ const typeflag = readString(block, 156, 1);
8318
+ const header = {
8319
+ name: readString(block, 0, 100),
8320
+ mode: readOctal(block, 100, 8),
8321
+ uid: readNumeric(block, 108, 8),
8322
+ gid: readNumeric(block, 116, 8),
8323
+ size: readNumeric(block, 124, 12),
8324
+ mtime: /* @__PURE__ */ new Date(readNumeric(block, 136, 12) * 1e3),
8325
+ type: FLAGTYPE[typeflag] || "file",
8326
+ linkname: readString(block, 157, 100)
8355
8327
  };
8356
- }));
8357
- //#endregion
8358
- //#region ../../node_modules/.pnpm/text-decoder@1.2.7/node_modules/text-decoder/lib/utf8-decoder.js
8359
- var require_utf8_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
8360
- const b4a = require_b4a();
8361
- /**
8362
- * https://encoding.spec.whatwg.org/#utf-8-decoder
8363
- */
8364
- module.exports = class UTF8Decoder {
8365
- constructor() {
8366
- this._reset();
8367
- }
8368
- get remaining() {
8369
- return this.bytesSeen;
8370
- }
8371
- decode(data) {
8372
- if (data.byteLength === 0) return "";
8373
- if (this.bytesNeeded === 0 && trailingIncomplete(data, 0) === 0) {
8374
- this.bytesSeen = trailingBytesSeen(data);
8375
- return b4a.toString(data, "utf8");
8376
- }
8377
- let result = "";
8378
- let start = 0;
8379
- if (this.bytesNeeded > 0) {
8380
- while (start < data.byteLength) {
8381
- const byte = data[start];
8382
- if (byte < this.lowerBoundary || byte > this.upperBoundary) {
8383
- result += "�";
8384
- this._reset();
8385
- break;
8386
- }
8387
- this.lowerBoundary = 128;
8388
- this.upperBoundary = 191;
8389
- this.codePoint = this.codePoint << 6 | byte & 63;
8390
- this.bytesSeen++;
8391
- start++;
8392
- if (this.bytesSeen === this.bytesNeeded) {
8393
- result += String.fromCodePoint(this.codePoint);
8394
- this._reset();
8395
- break;
8328
+ const magic = readString(block, 257, 6);
8329
+ if (magic.trim() === "ustar") {
8330
+ header.uname = readString(block, 265, 32);
8331
+ header.gname = readString(block, 297, 32);
8332
+ }
8333
+ if (magic === "ustar") header.prefix = readString(block, 345, 155);
8334
+ return header;
8335
+ }
8336
+ const PAX_MAPPING = {
8337
+ path: ["name", (v) => v],
8338
+ linkpath: ["linkname", (v) => v],
8339
+ size: ["size", (v) => /^\d+$/.test(v) && Number.isSafeInteger(+v) ? +v : NaN],
8340
+ mtime: ["mtime", parseFloat],
8341
+ uid: ["uid", (v) => parseInt(v, 10)],
8342
+ gid: ["gid", (v) => parseInt(v, 10)],
8343
+ uname: ["uname", (v) => v],
8344
+ gname: ["gname", (v) => v]
8345
+ };
8346
+ function parsePax(buffer) {
8347
+ const overrides = Object.create(null);
8348
+ const pax = Object.create(null);
8349
+ let isPax = false;
8350
+ let offset = 0;
8351
+ while (offset < buffer.length) {
8352
+ const spaceIndex = buffer.indexOf(32, offset);
8353
+ if (spaceIndex === -1) break;
8354
+ const length = parseInt(decoder.decode(buffer.subarray(offset, spaceIndex)), 10);
8355
+ if (!(length > 0)) break;
8356
+ const recordEnd = offset + length;
8357
+ const recordStr = decoder.decode(buffer.subarray(spaceIndex + 1, recordEnd - 1));
8358
+ const equalsIndex = recordStr.indexOf("=");
8359
+ if (equalsIndex > 0) {
8360
+ const key = recordStr.slice(0, equalsIndex);
8361
+ const value = recordStr.slice(equalsIndex + 1);
8362
+ pax[key] = value;
8363
+ isPax = true;
8364
+ if (Object.hasOwn(PAX_MAPPING, key)) {
8365
+ const [targetKey, parser] = PAX_MAPPING[key];
8366
+ const parsedValue = parser(value);
8367
+ if (typeof parsedValue === "string" || !Number.isNaN(parsedValue)) overrides[targetKey] = parsedValue;
8368
+ }
8369
+ }
8370
+ offset = recordEnd;
8371
+ }
8372
+ if (isPax) overrides.pax = pax;
8373
+ return overrides;
8374
+ }
8375
+ function applyOverrides(header, overrides) {
8376
+ if (overrides.name !== void 0) header.name = overrides.name;
8377
+ if (overrides.linkname !== void 0) header.linkname = overrides.linkname;
8378
+ if (overrides.size !== void 0) header.size = overrides.size;
8379
+ if (overrides.mtime !== void 0) header.mtime = /* @__PURE__ */ new Date(overrides.mtime * 1e3);
8380
+ if (overrides.uid !== void 0) header.uid = overrides.uid;
8381
+ if (overrides.gid !== void 0) header.gid = overrides.gid;
8382
+ if (overrides.uname !== void 0) header.uname = overrides.uname;
8383
+ if (overrides.gname !== void 0) header.gname = overrides.gname;
8384
+ if (overrides.pax) header.pax = Object.assign({}, header.pax ?? {}, overrides.pax);
8385
+ }
8386
+ function getMetaParser(type) {
8387
+ switch (type) {
8388
+ case "pax-global-header":
8389
+ case "pax-header": return parsePax;
8390
+ case "gnu-long-name": return (data) => ({ name: readString(data, 0, data.length) });
8391
+ case "gnu-long-link-name": return (data) => ({ linkname: readString(data, 0, data.length) });
8392
+ default: return;
8393
+ }
8394
+ }
8395
+ const STATE_HEADER = 0;
8396
+ const STATE_BODY = 1;
8397
+ const MAX_META_SIZE = 8 * 1024 * 1024;
8398
+ const truncateErr = /* @__PURE__ */ new Error("Tar archive is truncated.");
8399
+ function createUnpacker(options = {}) {
8400
+ const strict = options.strict ?? false;
8401
+ const { available, peek, push, discard, pull } = createChunkQueue();
8402
+ let state = STATE_HEADER;
8403
+ let ended = false;
8404
+ let done = false;
8405
+ let eof = false;
8406
+ let currentEntry = null;
8407
+ const paxGlobals = {};
8408
+ let nextEntryOverrides = {};
8409
+ const unpacker = {
8410
+ isEntryActive: () => state === STATE_BODY,
8411
+ isBodyComplete: () => !currentEntry || currentEntry.remaining === 0,
8412
+ canFinish: () => !currentEntry || available() >= currentEntry.remaining + currentEntry.padding,
8413
+ bodyBytes: () => currentEntry && currentEntry.remaining > 0 ? Math.min(currentEntry.remaining, available()) : 0,
8414
+ write(chunk) {
8415
+ if (ended) throw new Error("Archive already ended.");
8416
+ push(chunk);
8417
+ },
8418
+ end() {
8419
+ ended = true;
8420
+ },
8421
+ readHeader() {
8422
+ if (state !== STATE_HEADER) throw new Error("Cannot read header while an entry is active");
8423
+ if (done) return void 0;
8424
+ while (!done) {
8425
+ if (available() < 512) {
8426
+ if (ended) {
8427
+ if (available() > 0 && strict) throw truncateErr;
8428
+ done = true;
8429
+ return;
8396
8430
  }
8431
+ return null;
8397
8432
  }
8398
- if (this.bytesNeeded > 0) return result;
8399
- }
8400
- const trailing = trailingIncomplete(data, start);
8401
- const end = data.byteLength - trailing;
8402
- if (end > start) result += b4a.toString(data, "utf8", start, end);
8403
- for (let i = end; i < data.byteLength; i++) {
8404
- const byte = data[i];
8405
- if (this.bytesNeeded === 0) {
8406
- if (byte <= 127) {
8407
- this.bytesSeen = 0;
8408
- result += String.fromCharCode(byte);
8409
- } else if (byte >= 194 && byte <= 223) {
8410
- this.bytesNeeded = 2;
8411
- this.bytesSeen = 1;
8412
- this.codePoint = byte & 31;
8413
- } else if (byte >= 224 && byte <= 239) {
8414
- if (byte === 224) this.lowerBoundary = 160;
8415
- else if (byte === 237) this.upperBoundary = 159;
8416
- this.bytesNeeded = 3;
8417
- this.bytesSeen = 1;
8418
- this.codePoint = byte & 15;
8419
- } else if (byte >= 240 && byte <= 244) {
8420
- if (byte === 240) this.lowerBoundary = 144;
8421
- else if (byte === 244) this.upperBoundary = 143;
8422
- this.bytesNeeded = 4;
8423
- this.bytesSeen = 1;
8424
- this.codePoint = byte & 7;
8425
- } else {
8426
- this.bytesSeen = 1;
8427
- result += "�";
8433
+ const headerBlock = peek(512);
8434
+ if (isZeroBlock(headerBlock)) {
8435
+ if (available() < 512 * 2) {
8436
+ if (ended) {
8437
+ if (strict) throw truncateErr;
8438
+ done = true;
8439
+ return;
8440
+ }
8441
+ return null;
8428
8442
  }
8443
+ if (isZeroBlock(peek(512 * 2).subarray(512))) {
8444
+ discard(512 * 2);
8445
+ done = true;
8446
+ eof = true;
8447
+ return;
8448
+ }
8449
+ if (strict) throw new Error("Invalid tar header.");
8450
+ discard(512);
8451
+ continue;
8452
+ }
8453
+ let internalHeader;
8454
+ try {
8455
+ internalHeader = parseUstarHeader(headerBlock, strict);
8456
+ } catch (err) {
8457
+ if (strict) throw err;
8458
+ discard(512);
8429
8459
  continue;
8430
8460
  }
8431
- if (byte < this.lowerBoundary || byte > this.upperBoundary) {
8432
- result += "�";
8433
- i--;
8434
- this._reset();
8461
+ const metaParser = getMetaParser(internalHeader.type);
8462
+ if (metaParser) {
8463
+ if (internalHeader.size > MAX_META_SIZE) throw new Error("Tar metadata entry exceeds maximum size.");
8464
+ const paddedSize = internalHeader.size + (-internalHeader.size & 511);
8465
+ if (available() < 512 + paddedSize) {
8466
+ if (ended && strict) throw truncateErr;
8467
+ return null;
8468
+ }
8469
+ discard(512);
8470
+ const overrides = metaParser(pull(paddedSize).subarray(0, internalHeader.size));
8471
+ if (nextEntryOverrides.pax) nextEntryOverrides = {};
8472
+ const target = internalHeader.type === "pax-global-header" ? paxGlobals : nextEntryOverrides;
8473
+ for (const key in overrides) target[key] = overrides[key];
8435
8474
  continue;
8436
8475
  }
8437
- this.lowerBoundary = 128;
8438
- this.upperBoundary = 191;
8439
- this.codePoint = this.codePoint << 6 | byte & 63;
8440
- this.bytesSeen++;
8441
- if (this.bytesSeen === this.bytesNeeded) {
8442
- result += String.fromCodePoint(this.codePoint);
8443
- this._reset();
8476
+ discard(512);
8477
+ const header = internalHeader;
8478
+ if (internalHeader.prefix) header.name = `${internalHeader.prefix}/${header.name}`;
8479
+ applyOverrides(header, paxGlobals);
8480
+ applyOverrides(header, nextEntryOverrides);
8481
+ let archiveSize = header.size;
8482
+ if (isBodyless(header)) {
8483
+ archiveSize = 0;
8484
+ header.size = 0;
8485
+ } else if (header.name.endsWith("/") && header.type === "file") {
8486
+ header.type = DIRECTORY;
8487
+ header.size = 0;
8488
+ }
8489
+ nextEntryOverrides = {};
8490
+ currentEntry = {
8491
+ header,
8492
+ remaining: archiveSize,
8493
+ padding: -archiveSize & 511
8494
+ };
8495
+ state = STATE_BODY;
8496
+ return header;
8497
+ }
8498
+ },
8499
+ streamBody(callback) {
8500
+ if (state !== STATE_BODY || !currentEntry || currentEntry.remaining === 0) return 0;
8501
+ const bytesToFeed = Math.min(currentEntry.remaining, available());
8502
+ if (bytesToFeed === 0) return 0;
8503
+ const fed = pull(bytesToFeed, callback);
8504
+ currentEntry.remaining -= fed;
8505
+ return fed;
8506
+ },
8507
+ skipPadding() {
8508
+ if (state !== STATE_BODY || !currentEntry) return true;
8509
+ if (currentEntry.remaining > 0) throw new Error("Body not fully consumed");
8510
+ if (available() < currentEntry.padding) return false;
8511
+ discard(currentEntry.padding);
8512
+ currentEntry = null;
8513
+ state = STATE_HEADER;
8514
+ return true;
8515
+ },
8516
+ skipEntry() {
8517
+ if (state !== STATE_BODY || !currentEntry) return true;
8518
+ const toDiscard = Math.min(currentEntry.remaining, available());
8519
+ if (toDiscard > 0) {
8520
+ discard(toDiscard);
8521
+ currentEntry.remaining -= toDiscard;
8522
+ }
8523
+ if (currentEntry.remaining > 0) return false;
8524
+ return unpacker.skipPadding();
8525
+ },
8526
+ validateEOF() {
8527
+ if (strict) {
8528
+ if (!eof) throw truncateErr;
8529
+ if (available() > 0) {
8530
+ if (pull(available()).some((byte) => byte !== 0)) throw new Error("Invalid EOF.");
8444
8531
  }
8445
8532
  }
8446
- return result;
8447
- }
8448
- flush() {
8449
- const result = this.bytesNeeded > 0 ? "�" : "";
8450
- this._reset();
8451
- return result;
8452
- }
8453
- _reset() {
8454
- this.codePoint = 0;
8455
- this.bytesNeeded = 0;
8456
- this.bytesSeen = 0;
8457
- this.lowerBoundary = 128;
8458
- this.upperBoundary = 191;
8459
8533
  }
8460
8534
  };
8461
- function trailingIncomplete(data, start) {
8462
- const len = data.byteLength;
8463
- if (len <= start) return 0;
8464
- const limit = Math.max(start, len - 4);
8465
- let i = len - 1;
8466
- while (i > limit && (data[i] & 192) === 128) i--;
8467
- if (i < start) return 0;
8468
- const byte = data[i];
8469
- let needed;
8470
- if (byte <= 127) return 0;
8471
- if (byte >= 194 && byte <= 223) needed = 2;
8472
- else if (byte >= 224 && byte <= 239) needed = 3;
8473
- else if (byte >= 240 && byte <= 244) needed = 4;
8474
- else return 0;
8475
- const available = len - i;
8476
- return available < needed ? available : 0;
8477
- }
8478
- function trailingBytesSeen(data) {
8479
- const len = data.byteLength;
8480
- if (len === 0) return 0;
8481
- const last = data[len - 1];
8482
- if (last <= 127) return 0;
8483
- if ((last & 192) !== 128) return 1;
8484
- const limit = Math.max(0, len - 4);
8485
- let i = len - 2;
8486
- while (i >= limit && (data[i] & 192) === 128) i--;
8487
- if (i < 0) return 1;
8488
- const first = data[i];
8489
- let needed;
8490
- if (first >= 194 && first <= 223) needed = 2;
8491
- else if (first >= 224 && first <= 239) needed = 3;
8492
- else if (first >= 240 && first <= 244) needed = 4;
8493
- else return 1;
8494
- if (len - i !== needed) return 1;
8495
- if (needed >= 3) {
8496
- const second = data[i + 1];
8497
- if (first === 224 && second < 160) return 1;
8498
- if (first === 237 && second > 159) return 1;
8499
- if (first === 240 && second < 144) return 1;
8500
- if (first === 244 && second > 143) return 1;
8501
- }
8502
- return 0;
8503
- }
8504
- }));
8535
+ return unpacker;
8536
+ }
8537
+ function isZeroBlock(block) {
8538
+ if (block.byteOffset % 8 === 0) {
8539
+ const view = new BigUint64Array(block.buffer, block.byteOffset, block.length / 8);
8540
+ for (let i = 0; i < view.length; i++) if (view[i] !== 0n) return false;
8541
+ return true;
8542
+ }
8543
+ for (let i = 0; i < block.length; i++) if (block[i] !== 0) return false;
8544
+ return true;
8545
+ }
8505
8546
  //#endregion
8506
- //#region ../../node_modules/.pnpm/text-decoder@1.2.7/node_modules/text-decoder/index.js
8507
- var require_text_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
8508
- const PassThroughDecoder = require_pass_through_decoder();
8509
- const UTF8Decoder = require_utf8_decoder();
8510
- module.exports = class TextDecoder {
8511
- constructor(encoding = "utf8") {
8512
- this.encoding = normalizeEncoding(encoding);
8513
- switch (this.encoding) {
8514
- case "utf8":
8515
- this.decoder = new UTF8Decoder();
8516
- break;
8517
- case "utf16le":
8518
- case "base64": throw new Error("Unsupported encoding: " + this.encoding);
8519
- default: this.decoder = new PassThroughDecoder(this.encoding);
8520
- }
8521
- }
8522
- get remaining() {
8523
- return this.decoder.remaining;
8524
- }
8525
- push(data) {
8526
- if (typeof data === "string") return data;
8527
- return this.decoder.decode(data);
8528
- }
8529
- write(data) {
8530
- return this.push(data);
8547
+ //#region ../../node_modules/.pnpm/modern-tar@0.7.7/node_modules/modern-tar/dist/fs/index.js
8548
+ function validateBounds(targetPath, destDir, errorMessage) {
8549
+ const target = path$1.resolve(targetPath);
8550
+ const dest = path$1.resolve(destDir);
8551
+ if (target !== dest && !target.startsWith(dest + path$1.sep)) throw new Error(errorMessage);
8552
+ }
8553
+ const win32Reserved = {
8554
+ ":": "",
8555
+ "<": "",
8556
+ ">": "",
8557
+ "|": "",
8558
+ "?": "",
8559
+ "*": "",
8560
+ "\"": ""
8561
+ };
8562
+ function normalizeName(name) {
8563
+ const path = name.replace(/\\/g, "/");
8564
+ if (path.split("/").includes("..") || /^[a-zA-Z]:\.\./.test(path)) throw new Error(`${name} points outside extraction directory`);
8565
+ let relative = path;
8566
+ if (/^[a-zA-Z]:/.test(relative)) relative = relative.replace(/^[a-zA-Z]:[/\\]?/, "");
8567
+ else if (relative.startsWith("/")) relative = relative.replace(/^\/+/, "");
8568
+ if (process.platform === "win32") return relative.replace(/[<>:"|?*]/g, (char) => win32Reserved[char]);
8569
+ return relative;
8570
+ }
8571
+ const normalizeHeaderName = (s) => normalizeName(s.replace(/\/+$/, ""));
8572
+ const createOperationQueue = (concurrency) => {
8573
+ let active = 0;
8574
+ const tasks = [];
8575
+ let head = 0;
8576
+ let idle = null;
8577
+ let resolveIdle = null;
8578
+ const ensureIdle = () => idle ??= new Promise((resolve) => resolveIdle = resolve);
8579
+ const flush = () => {
8580
+ while (active < concurrency && head < tasks.length) {
8581
+ const task = tasks[head++];
8582
+ active++;
8583
+ task().finally(() => {
8584
+ active--;
8585
+ flush();
8586
+ });
8531
8587
  }
8532
- end(data) {
8533
- let result = "";
8534
- if (data) result = this.push(data);
8535
- result += this.decoder.flush();
8536
- return result;
8588
+ if (head === tasks.length) {
8589
+ tasks.length = 0;
8590
+ head = 0;
8591
+ if (active === 0 && resolveIdle) {
8592
+ resolveIdle();
8593
+ idle = null;
8594
+ resolveIdle = null;
8595
+ }
8537
8596
  }
8538
8597
  };
8539
- function normalizeEncoding(encoding) {
8540
- encoding = encoding.toLowerCase();
8541
- switch (encoding) {
8542
- case "utf8":
8543
- case "utf-8": return "utf8";
8544
- case "ucs2":
8545
- case "ucs-2":
8546
- case "utf16le":
8547
- case "utf-16le": return "utf16le";
8548
- case "latin1":
8549
- case "binary": return "latin1";
8550
- case "base64":
8551
- case "ascii":
8552
- case "hex": return encoding;
8553
- default: throw new Error("Unknown encoding: " + encoding);
8554
- }
8555
- }
8556
- }));
8557
- //#endregion
8558
- //#region ../../node_modules/.pnpm/streamx@2.26.0/node_modules/streamx/lib/errors.js
8559
- var require_errors = /* @__PURE__ */ __commonJSMin(((exports, module) => {
8560
- module.exports = class StreamError extends Error {
8561
- constructor(msg, code, fn = StreamError) {
8562
- super(msg);
8563
- this.code = code;
8564
- if (Error.captureStackTrace) Error.captureStackTrace(this, fn);
8598
+ return {
8599
+ add(op) {
8600
+ const wasIdle = active === 0 && head === tasks.length;
8601
+ return new Promise((resolve, reject) => {
8602
+ tasks.push(() => Promise.resolve().then(op).then(resolve, reject));
8603
+ if (wasIdle) ensureIdle();
8604
+ flush();
8605
+ });
8606
+ },
8607
+ onIdle() {
8608
+ return active === 0 && head === tasks.length ? Promise.resolve() : ensureIdle();
8565
8609
  }
8566
- static isStreamDestroyed(err) {
8567
- return err && err.code === "STREAM_DESTROYED";
8610
+ };
8611
+ };
8612
+ const BATCH_BYTES = 256 * 1024;
8613
+ const CREATE_FLAGS = fs$1.constants.O_WRONLY | fs$1.constants.O_CREAT | fs$1.constants.O_TRUNC | (fs$1.constants.O_NOFOLLOW ?? 0) | fs$1.constants.O_EXCL;
8614
+ const STATE_OPENING = 1;
8615
+ const STATE_OPEN = 2;
8616
+ const STATE_CLOSED = 3;
8617
+ const STATE_FAILED = 4;
8618
+ const DRAINED_PROMISE = Promise.resolve();
8619
+ function createFileSink(path, { mode = 438, mtime } = {}) {
8620
+ let state = STATE_OPENING;
8621
+ let flushing = false;
8622
+ let fd = null;
8623
+ let queue = [];
8624
+ let spare = [];
8625
+ let bytes = 0;
8626
+ let storedError = null;
8627
+ let endPromise = null;
8628
+ let endResolve = null;
8629
+ let endReject = null;
8630
+ const waitResolves = [];
8631
+ const waitRejects = [];
8632
+ const settleWaiters = () => {
8633
+ if (waitResolves.length === 0) return;
8634
+ for (let i = 0; i < waitResolves.length; i++) waitResolves[i]();
8635
+ waitResolves.length = 0;
8636
+ waitRejects.length = 0;
8637
+ };
8638
+ const failWaiters = (error) => {
8639
+ if (waitRejects.length === 0) return;
8640
+ for (let i = 0; i < waitRejects.length; i++) waitRejects[i](error);
8641
+ waitRejects.length = 0;
8642
+ waitResolves.length = 0;
8643
+ };
8644
+ const resetBuffers = () => {
8645
+ bytes = 0;
8646
+ queue.length = 0;
8647
+ spare.length = 0;
8648
+ };
8649
+ const finish = () => {
8650
+ state = STATE_CLOSED;
8651
+ endResolve?.();
8652
+ settleWaiters();
8653
+ };
8654
+ const swapQueues = () => {
8655
+ const current = queue;
8656
+ queue = spare;
8657
+ spare = current;
8658
+ queue.length = 0;
8659
+ return current;
8660
+ };
8661
+ const fail = (error) => {
8662
+ if (storedError) return;
8663
+ storedError = error;
8664
+ state = STATE_FAILED;
8665
+ resetBuffers();
8666
+ flushing = false;
8667
+ const fdToClose = fd;
8668
+ fd = null;
8669
+ if (fdToClose !== null) fs$1.ftruncate(fdToClose, 0, () => fs$1.close(fdToClose));
8670
+ endReject?.(error);
8671
+ failWaiters(error);
8672
+ };
8673
+ const close = () => {
8674
+ if (fd === null) {
8675
+ finish();
8676
+ return;
8568
8677
  }
8569
- static isPrematureClose(err) {
8570
- return err && err.code === "PREMATURE_CLOSE";
8678
+ const fdToClose = fd;
8679
+ fd = null;
8680
+ if (mtime) fs$1.futimes(fdToClose, mtime, mtime, (err) => {
8681
+ if (err) return fail(err);
8682
+ fs$1.close(fdToClose, (closeErr) => {
8683
+ if (closeErr) fail(closeErr);
8684
+ else finish();
8685
+ });
8686
+ });
8687
+ else fs$1.close(fdToClose, (err) => {
8688
+ if (err) fail(err);
8689
+ else finish();
8690
+ });
8691
+ };
8692
+ const flush = () => {
8693
+ if (flushing || queue.length === 0 || state !== STATE_OPEN) return;
8694
+ flushing = true;
8695
+ const bufs = swapQueues();
8696
+ const onDone = (err, written = 0) => {
8697
+ if (err) return fail(err);
8698
+ flushing = false;
8699
+ bytes -= written;
8700
+ spare.length = 0;
8701
+ if (bytes < BATCH_BYTES) settleWaiters();
8702
+ if (queue.length > 0) flush();
8703
+ else if (endResolve) close();
8704
+ };
8705
+ if (bufs.length === 1) {
8706
+ const buf = bufs[0];
8707
+ fs$1.write(fd, buf, 0, buf.length, null, onDone);
8708
+ } else fs$1.writev(fd, bufs, onDone);
8709
+ };
8710
+ const onOpen = (err, openFd) => {
8711
+ if (err) return fail(err);
8712
+ if (state === STATE_CLOSED || state === STATE_FAILED) {
8713
+ fs$1.close(openFd);
8714
+ return;
8571
8715
  }
8572
- static isAborted(err) {
8573
- return err && err.code === "ABORTED";
8716
+ fd = openFd;
8717
+ state = STATE_OPEN;
8718
+ if (endResolve) if (queue.length > 0) flush();
8719
+ else close();
8720
+ else if (bytes >= BATCH_BYTES && !flushing) flush();
8721
+ else settleWaiters();
8722
+ };
8723
+ const write = (chunk) => {
8724
+ if (storedError || state >= STATE_CLOSED || endResolve) return false;
8725
+ const buf = Buffer.isBuffer(chunk) ? chunk : chunk instanceof Uint8Array ? Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength) : Buffer.from(chunk);
8726
+ if (buf.length === 0) return bytes < BATCH_BYTES;
8727
+ queue.push(buf);
8728
+ bytes += buf.length;
8729
+ if (state === STATE_OPEN && !flushing && bytes >= BATCH_BYTES) flush();
8730
+ return bytes < BATCH_BYTES;
8731
+ };
8732
+ const waitDrain = () => {
8733
+ if (state === STATE_OPENING || state === STATE_OPEN && bytes >= BATCH_BYTES) return new Promise((resolve, reject) => {
8734
+ waitResolves.push(resolve);
8735
+ waitRejects.push(reject);
8736
+ });
8737
+ return DRAINED_PROMISE;
8738
+ };
8739
+ const end = () => {
8740
+ if (state >= STATE_CLOSED) return DRAINED_PROMISE;
8741
+ if (storedError) return Promise.reject(storedError);
8742
+ if (endPromise) return endPromise;
8743
+ endPromise = new Promise((resolve, reject) => {
8744
+ endResolve = resolve;
8745
+ endReject = reject;
8746
+ if (state === STATE_OPEN && !flushing) if (queue.length > 0) flush();
8747
+ else close();
8748
+ });
8749
+ return endPromise;
8750
+ };
8751
+ const destroy = (error) => {
8752
+ if (error) {
8753
+ fail(error);
8754
+ return;
8574
8755
  }
8575
- get name() {
8576
- return "StreamError";
8756
+ if (state >= STATE_CLOSED || storedError) return;
8757
+ resetBuffers();
8758
+ flushing = false;
8759
+ if (fd !== null) {
8760
+ const fdToClose = fd;
8761
+ fd = null;
8762
+ fs$1.close(fdToClose);
8577
8763
  }
8578
- static STREAM_DESTROYED() {
8579
- return new StreamError("Stream was destroyed", "STREAM_DESTROYED", StreamError.STREAM_DESTROYED);
8764
+ finish();
8765
+ };
8766
+ fs$1.open(path, CREATE_FLAGS, mode, (err, openFd) => {
8767
+ if (!err || err.code !== "EEXIST") return onOpen(err, openFd);
8768
+ fs$1.rm(path, { force: true }, (rmErr) => {
8769
+ if (rmErr) return fail(rmErr);
8770
+ fs$1.open(path, CREATE_FLAGS, mode, onOpen);
8771
+ });
8772
+ });
8773
+ return {
8774
+ write,
8775
+ end,
8776
+ destroy,
8777
+ waitDrain
8778
+ };
8779
+ }
8780
+ const createCache = () => {
8781
+ const m = /* @__PURE__ */ new Map();
8782
+ return {
8783
+ get(k) {
8784
+ const v = m.get(k);
8785
+ if (m.delete(k)) m.set(k, v);
8786
+ return v;
8787
+ },
8788
+ set(k, v) {
8789
+ if (m.set(k, v).size > 1e4) m.delete(m.keys().next().value);
8790
+ },
8791
+ clear() {
8792
+ m.clear();
8580
8793
  }
8581
- static PREMATURE_CLOSE() {
8582
- return new StreamError("Premature close", "PREMATURE_CLOSE", StreamError.PREMATURE_CLOSE);
8794
+ };
8795
+ };
8796
+ const ENOENT = "ENOENT";
8797
+ const MAX_SYMLINKS = 64;
8798
+ const linkSep = process.platform === "win32" ? /[/\\]/ : "/";
8799
+ const linkParts = (linkname) => linkname.split(linkSep).filter((part) => part && part !== ".");
8800
+ const createPathCache = (destDirPath, options, opQueue, concurrency) => {
8801
+ const { maxDepth = 1024, dmode } = options;
8802
+ const dirPromises = createCache();
8803
+ const pathConflicts = /* @__PURE__ */ new Map();
8804
+ const deferredLinks = [];
8805
+ let symlinks;
8806
+ const realDirCache = createCache();
8807
+ const initializeDestDir = async (destDirPath) => {
8808
+ const symbolic = path$1.resolve(destDirPath);
8809
+ try {
8810
+ await fsp.mkdir(symbolic, { recursive: true });
8811
+ } catch (err) {
8812
+ if (err.code === ENOENT) {
8813
+ const parentDir = path$1.dirname(symbolic);
8814
+ if (parentDir === symbolic) throw err;
8815
+ await fsp.mkdir(parentDir, { recursive: true });
8816
+ await fsp.mkdir(symbolic, { recursive: true });
8817
+ } else throw err;
8583
8818
  }
8584
- static ABORTED() {
8585
- return new StreamError("Stream aborted", "ABORTED", StreamError.ABORTED);
8819
+ try {
8820
+ return {
8821
+ symbolic,
8822
+ real: await fsp.realpath(symbolic)
8823
+ };
8824
+ } catch (err) {
8825
+ if (err.code === ENOENT) return {
8826
+ symbolic,
8827
+ real: symbolic
8828
+ };
8829
+ throw err;
8586
8830
  }
8587
8831
  };
8588
- }));
8589
- //#endregion
8590
- //#region ../../node_modules/.pnpm/streamx@2.26.0/node_modules/streamx/index.js
8591
- var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
8592
- const { EventEmitter } = require_default();
8593
- const FIFO = require_fast_fifo();
8594
- const TextDecoder = require_text_decoder();
8595
- const StreamError = require_errors();
8596
- const qmt = typeof queueMicrotask === "undefined" ? (fn) => global.process.nextTick(fn) : queueMicrotask;
8597
- const OPENING = 1;
8598
- const PREDESTROYING = 2;
8599
- const DESTROYING = 4;
8600
- const DESTROYED = 8;
8601
- const NOT_OPENING = 536870910;
8602
- const NOT_PREDESTROYING = 536870909;
8603
- const READ_UPDATING = 32;
8604
- const READ_PRIMARY = 64;
8605
- const READ_QUEUED = 128;
8606
- const READ_RESUMED = 256;
8607
- const READ_PIPE_DRAINED = 512;
8608
- const READ_ENDING = 1024;
8609
- const READ_EMIT_DATA = 2048;
8610
- const READ_EMIT_READABLE = 4096;
8611
- const READ_EMITTED_READABLE = 8192;
8612
- const READ_DONE = 16384;
8613
- const READ_NEXT_TICK = 32768;
8614
- const READ_READ_AHEAD = 131072;
8615
- const READ_FLOWING = 768;
8616
- const READ_ACTIVE_AND_NEEDS_PUSH = 65552;
8617
- const READ_PRIMARY_AND_ACTIVE = 80;
8618
- const READ_EMIT_READABLE_AND_QUEUED = 4224;
8619
- const READ_RESUMED_READ_AHEAD = 131328;
8620
- const READ_NOT_ACTIVE = 536870895;
8621
- const READ_NON_PRIMARY_AND_PUSHED = 536805311;
8622
- const READ_PUSHED = 536805375;
8623
- const READ_PAUSED = 536870655;
8624
- const READ_NOT_QUEUED = 536862591;
8625
- const READ_NOT_ENDING = 536869887;
8626
- const READ_PIPE_NOT_DRAINED = 536870143;
8627
- const READ_NOT_NEXT_TICK = 536838143;
8628
- const READ_NOT_UPDATING = 536870879;
8629
- const READ_NO_READ_AHEAD = 536739839;
8630
- const READ_PAUSED_NO_READ_AHEAD = 536739583;
8631
- const WRITE_ACTIVE = 1 << 18;
8632
- const WRITE_UPDATING = 2 << 18;
8633
- const WRITE_PRIMARY = 4 << 18;
8634
- const WRITE_QUEUED = 8 << 18;
8635
- const WRITE_UNDRAINED = 16 << 18;
8636
- const WRITE_DONE = 32 << 18;
8637
- const WRITE_EMIT_DRAIN = 64 << 18;
8638
- const WRITE_NEXT_TICK = 128 << 18;
8639
- const WRITE_WRITING = 256 << 18;
8640
- const WRITE_FINISHING = 512 << 18;
8641
- const WRITE_CORKED = 1024 << 18;
8642
- const WRITE_NOT_ACTIVE = 469499903;
8643
- const WRITE_NON_PRIMARY = 535822335;
8644
- const WRITE_NOT_FINISHING = 402391039;
8645
- const WRITE_DRAINED = 532676607;
8646
- const WRITE_NOT_QUEUED = 534773759;
8647
- const WRITE_NOT_NEXT_TICK = 503316479;
8648
- const WRITE_NOT_UPDATING = 536346623;
8649
- const WRITE_NOT_CORKED = 268435455;
8650
- const ACTIVE = 262160;
8651
- const NOT_ACTIVE = 536608751;
8652
- const DONE = 8404992;
8653
- const DESTROY_STATUS = 14;
8654
- const OPEN_STATUS = 15;
8655
- const AUTO_DESTROY = 8405006;
8656
- const NON_PRIMARY = 535822271;
8657
- const ACTIVE_OR_TICKING = 33587200;
8658
- const IS_OPENING = 33587215;
8659
- const READ_PRIMARY_STATUS = 17423;
8660
- const READ_STATUS = 16527;
8661
- const READ_ENDING_STATUS = 1167;
8662
- const READ_READABLE_STATUS = 12431;
8663
- const SHOULD_NOT_READ = 214047;
8664
- const READ_BACKPRESSURE_STATUS = 17422;
8665
- const READ_UPDATE_SYNC_STATUS = 32879;
8666
- const READ_NEXT_TICK_OR_OPENING = 32769;
8667
- const WRITE_PRIMARY_STATUS = 142606351;
8668
- const WRITE_QUEUED_AND_UNDRAINED = 6291456;
8669
- const WRITE_QUEUED_AND_ACTIVE = 2359296;
8670
- const WRITE_DRAIN_STATUS = 6553615;
8671
- const WRITE_STATUS = 270794767;
8672
- const WRITE_PRIMARY_AND_ACTIVE = 1310720;
8673
- const WRITE_ACTIVE_AND_WRITING = 67371008;
8674
- const WRITE_FINISHING_STATUS = 144965647;
8675
- const WRITE_BACKPRESSURE_STATUS = 146800654;
8676
- const WRITE_UPDATE_SYNC_STATUS = 35127311;
8677
- const WRITE_DROP_DATA = 142606350;
8678
- const asyncIterator = Symbol.asyncIterator || Symbol("asyncIterator");
8679
- var WritableState = class {
8680
- constructor(stream, { highWaterMark = 16384, map = null, mapWritable, byteLength, byteLengthWritable } = {}) {
8681
- this.stream = stream;
8682
- this.queue = new FIFO();
8683
- this.highWaterMark = highWaterMark;
8684
- this.buffered = 0;
8685
- this.error = null;
8686
- this.pipeline = null;
8687
- this.drains = null;
8688
- this.byteLength = byteLengthWritable || byteLength || defaultByteLength;
8689
- this.map = mapWritable || map;
8690
- this.afterWrite = afterWrite.bind(this);
8691
- this.afterUpdateNextTick = updateWriteNT.bind(this);
8692
- }
8693
- get ending() {
8694
- return (this.stream._duplexState & WRITE_FINISHING) !== 0;
8695
- }
8696
- get ended() {
8697
- return (this.stream._duplexState & WRITE_DONE) !== 0;
8698
- }
8699
- push(data) {
8700
- if ((this.stream._duplexState & WRITE_DROP_DATA) !== 0) return false;
8701
- if (this.map !== null) data = this.map(data);
8702
- this.buffered += this.byteLength(data);
8703
- this.queue.push(data);
8704
- if (this.buffered < this.highWaterMark) {
8705
- this.stream._duplexState |= WRITE_QUEUED;
8706
- return true;
8707
- }
8708
- this.stream._duplexState |= WRITE_QUEUED_AND_UNDRAINED;
8709
- return false;
8832
+ const destDirPromise = initializeDestDir(destDirPath);
8833
+ destDirPromise.catch(() => {});
8834
+ const getRealDir = async (dirPath, errorMessage) => {
8835
+ const destDir = await destDirPromise;
8836
+ if (dirPath === destDir.symbolic) return destDir.real;
8837
+ let promise = realDirCache.get(dirPath);
8838
+ if (!promise) {
8839
+ promise = fsp.realpath(dirPath).then((realPath) => {
8840
+ validateBounds(realPath, destDir.real, errorMessage);
8841
+ return realPath;
8842
+ });
8843
+ realDirCache.set(dirPath, promise);
8710
8844
  }
8711
- shift() {
8712
- const data = this.queue.shift();
8713
- this.buffered -= this.byteLength(data);
8714
- if (this.buffered === 0) this.stream._duplexState &= WRITE_NOT_QUEUED;
8715
- return data;
8716
- }
8717
- end(data) {
8718
- if (typeof data === "function") this.stream.once("finish", data);
8719
- else if (data !== void 0 && data !== null) this.push(data);
8720
- this.stream._duplexState = (this.stream._duplexState | WRITE_FINISHING) & WRITE_NON_PRIMARY;
8721
- }
8722
- autoBatch(data, cb) {
8723
- const buffer = [];
8724
- const stream = this.stream;
8725
- buffer.push(data);
8726
- while ((stream._duplexState & WRITE_STATUS) === WRITE_QUEUED_AND_ACTIVE) buffer.push(stream._writableState.shift());
8727
- if ((stream._duplexState & OPEN_STATUS) !== 0) return cb(null);
8728
- stream._writev(buffer, cb);
8729
- }
8730
- update() {
8731
- const stream = this.stream;
8732
- stream._duplexState |= WRITE_UPDATING;
8733
- do {
8734
- while ((stream._duplexState & WRITE_STATUS) === WRITE_QUEUED) {
8735
- const data = this.shift();
8736
- stream._duplexState |= WRITE_ACTIVE_AND_WRITING;
8737
- stream._write(data, this.afterWrite);
8845
+ return promise;
8846
+ };
8847
+ const prepareDirectory = async (dirPath, mode) => {
8848
+ let promise = dirPromises.get(dirPath);
8849
+ if (promise) return promise;
8850
+ promise = (async () => {
8851
+ if (dirPath === (await destDirPromise).symbolic) return;
8852
+ await prepareDirectory(path$1.dirname(dirPath));
8853
+ try {
8854
+ const stat = await fsp.lstat(dirPath);
8855
+ if (stat.isDirectory()) return;
8856
+ if (stat.isSymbolicLink()) try {
8857
+ const realPath = await getRealDir(dirPath, `Symlink "${dirPath}" points outside the extraction directory.`);
8858
+ if ((await fsp.stat(realPath)).isDirectory()) return;
8859
+ } catch (err) {
8860
+ if (err.code === ENOENT) throw new Error(`Symlink "${dirPath}" points outside the extraction directory.`);
8861
+ throw err;
8738
8862
  }
8739
- if ((stream._duplexState & WRITE_PRIMARY_AND_ACTIVE) === 0) this.updateNonPrimary();
8740
- } while (this.continueUpdate() === true);
8741
- stream._duplexState &= WRITE_NOT_UPDATING;
8742
- }
8743
- updateNonPrimary() {
8744
- const stream = this.stream;
8745
- if ((stream._duplexState & WRITE_FINISHING_STATUS) === WRITE_FINISHING) {
8746
- stream._duplexState = stream._duplexState | WRITE_ACTIVE;
8747
- stream._final(afterFinal.bind(this));
8748
- return;
8749
- }
8750
- if ((stream._duplexState & DESTROY_STATUS) === DESTROYING) {
8751
- if ((stream._duplexState & ACTIVE_OR_TICKING) === 0) {
8752
- stream._duplexState |= ACTIVE;
8753
- stream._destroy(afterDestroy.bind(this));
8863
+ throw new Error(`"${dirPath}" is not a valid directory component.`);
8864
+ } catch (err) {
8865
+ if (err.code === ENOENT) {
8866
+ await fsp.mkdir(dirPath, { mode: mode ?? options.dmode });
8867
+ return;
8754
8868
  }
8755
- return;
8756
- }
8757
- if ((stream._duplexState & IS_OPENING) === OPENING) {
8758
- stream._duplexState = (stream._duplexState | ACTIVE) & NOT_OPENING;
8759
- stream._open(afterOpen.bind(this));
8869
+ throw err;
8760
8870
  }
8761
- }
8762
- continueUpdate() {
8763
- if ((this.stream._duplexState & WRITE_NEXT_TICK) === 0) return false;
8764
- this.stream._duplexState &= WRITE_NOT_NEXT_TICK;
8765
- return true;
8766
- }
8767
- updateCallback() {
8768
- if ((this.stream._duplexState & WRITE_UPDATE_SYNC_STATUS) === WRITE_PRIMARY) this.update();
8769
- else this.updateNextTick();
8770
- }
8771
- updateNextTick() {
8772
- if ((this.stream._duplexState & WRITE_NEXT_TICK) !== 0) return;
8773
- this.stream._duplexState |= WRITE_NEXT_TICK;
8774
- if ((this.stream._duplexState & WRITE_UPDATING) === 0) qmt(this.afterUpdateNextTick);
8775
- }
8871
+ })();
8872
+ dirPromises.set(dirPath, promise);
8873
+ return promise;
8776
8874
  };
8777
- var ReadableState = class {
8778
- constructor(stream, { highWaterMark = 16384, map = null, mapReadable, byteLength, byteLengthReadable } = {}) {
8779
- this.stream = stream;
8780
- this.queue = new FIFO();
8781
- this.highWaterMark = highWaterMark === 0 ? 1 : highWaterMark;
8782
- this.buffered = 0;
8783
- this.readAhead = highWaterMark > 0;
8784
- this.error = null;
8785
- this.pipeline = null;
8786
- this.byteLength = byteLengthReadable || byteLength || defaultByteLength;
8787
- this.map = mapReadable || map;
8788
- this.pipeTo = null;
8789
- this.afterRead = afterRead.bind(this);
8790
- this.afterUpdateNextTick = updateReadNT.bind(this);
8791
- }
8792
- get ending() {
8793
- return (this.stream._duplexState & READ_ENDING) !== 0;
8794
- }
8795
- get ended() {
8796
- return (this.stream._duplexState & READ_DONE) !== 0;
8797
- }
8798
- pipe(pipeTo, cb) {
8799
- if (this.pipeTo !== null) throw new Error("Can only pipe to one destination");
8800
- if (typeof cb !== "function") cb = null;
8801
- this.stream._duplexState |= READ_PIPE_DRAINED;
8802
- this.pipeTo = pipeTo;
8803
- this.pipeline = new Pipeline(this.stream, pipeTo, cb);
8804
- if (cb) this.stream.on("error", noop);
8805
- if (isStreamx(pipeTo)) {
8806
- pipeTo._writableState.pipeline = this.pipeline;
8807
- if (cb) pipeTo.on("error", noop);
8808
- pipeTo.on("finish", this.pipeline.finished.bind(this.pipeline));
8809
- } else {
8810
- const onerror = this.pipeline.done.bind(this.pipeline, pipeTo);
8811
- const onclose = this.pipeline.done.bind(this.pipeline, pipeTo, null);
8812
- pipeTo.on("error", onerror);
8813
- pipeTo.on("close", onclose);
8814
- pipeTo.on("finish", this.pipeline.finished.bind(this.pipeline));
8815
- }
8816
- pipeTo.on("drain", afterDrain.bind(this));
8817
- this.stream.emit("piping", pipeTo);
8818
- pipeTo.emit("pipe", this.stream);
8819
- }
8820
- push(data) {
8821
- const stream = this.stream;
8822
- if (data === null) {
8823
- this.highWaterMark = 0;
8824
- stream._duplexState = (stream._duplexState | READ_ENDING) & READ_NON_PRIMARY_AND_PUSHED;
8825
- return false;
8875
+ return {
8876
+ async ready() {
8877
+ await destDirPromise;
8878
+ },
8879
+ async preparePath(header) {
8880
+ const { name, linkname, type, mode, mtime } = header;
8881
+ const normalizedName = normalizeHeaderName(name);
8882
+ const destDir = await destDirPromise;
8883
+ const outPath = path$1.join(destDir.symbolic, normalizedName);
8884
+ if (maxDepth !== Infinity) {
8885
+ let depth = 1;
8886
+ for (const char of normalizedName) if (char === "/" && ++depth > maxDepth) throw new Error("Tar exceeds max specified depth.");
8887
+ }
8888
+ const prevOp = pathConflicts.get(normalizedName);
8889
+ if (prevOp) {
8890
+ if (prevOp === "directory" && type !== "directory" || prevOp !== "directory" && type === "directory") throw new Error(`Path conflict ${type} over existing ${prevOp} at "${name}"`);
8891
+ return;
8826
8892
  }
8827
- if (this.map !== null) {
8828
- data = this.map(data);
8829
- if (data === null) {
8830
- stream._duplexState &= READ_PUSHED;
8831
- return this.buffered < this.highWaterMark;
8893
+ const parentDir = path$1.dirname(outPath);
8894
+ switch (type) {
8895
+ case DIRECTORY: {
8896
+ pathConflicts.set(normalizedName, DIRECTORY);
8897
+ const safeMode = mode ? mode & 511 : void 0;
8898
+ await prepareDirectory(outPath, dmode ?? safeMode);
8899
+ if (mtime) await fsp.lutimes(outPath, mtime, mtime).catch(() => {});
8900
+ return;
8832
8901
  }
8833
- }
8834
- this.buffered += this.byteLength(data);
8835
- this.queue.push(data);
8836
- stream._duplexState = (stream._duplexState | READ_QUEUED) & READ_PUSHED;
8837
- return this.buffered < this.highWaterMark;
8838
- }
8839
- shift() {
8840
- const data = this.queue.shift();
8841
- this.buffered -= this.byteLength(data);
8842
- if (this.buffered === 0) this.stream._duplexState &= READ_NOT_QUEUED;
8843
- return data;
8844
- }
8845
- unshift(data) {
8846
- const pending = [this.map !== null ? this.map(data) : data];
8847
- while (this.buffered > 0) pending.push(this.shift());
8848
- for (let i = 0; i < pending.length - 1; i++) {
8849
- const data = pending[i];
8850
- this.buffered += this.byteLength(data);
8851
- this.queue.push(data);
8852
- }
8853
- this.push(pending[pending.length - 1]);
8854
- }
8855
- read() {
8856
- const stream = this.stream;
8857
- if ((stream._duplexState & READ_STATUS) === READ_QUEUED) {
8858
- const data = this.shift();
8859
- if (this.pipeTo !== null && this.pipeTo.write(data) === false) stream._duplexState &= READ_PIPE_NOT_DRAINED;
8860
- if ((stream._duplexState & READ_EMIT_DATA) !== 0) stream.emit("data", data);
8861
- return data;
8862
- }
8863
- if (this.readAhead === false) {
8864
- stream._duplexState |= READ_READ_AHEAD;
8865
- this.updateNextTick();
8866
- }
8867
- return null;
8868
- }
8869
- drain() {
8870
- const stream = this.stream;
8871
- while ((stream._duplexState & READ_STATUS) === READ_QUEUED && (stream._duplexState & READ_FLOWING) !== 0) {
8872
- const data = this.shift();
8873
- if (this.pipeTo !== null && this.pipeTo.write(data) === false) stream._duplexState &= READ_PIPE_NOT_DRAINED;
8874
- if ((stream._duplexState & READ_EMIT_DATA) !== 0) stream.emit("data", data);
8875
- }
8876
- }
8877
- update() {
8878
- const stream = this.stream;
8879
- stream._duplexState |= READ_UPDATING;
8880
- do {
8881
- this.drain();
8882
- while (this.buffered < this.highWaterMark && (stream._duplexState & SHOULD_NOT_READ) === READ_READ_AHEAD) {
8883
- stream._duplexState |= READ_ACTIVE_AND_NEEDS_PUSH;
8884
- stream._read(this.afterRead);
8885
- this.drain();
8902
+ case FILE:
8903
+ pathConflicts.set(normalizedName, FILE);
8904
+ await prepareDirectory(parentDir);
8905
+ return path$1.join(await getRealDir(parentDir, `File "${name}" points outside the extraction directory.`), path$1.basename(outPath));
8906
+ case SYMLINK: {
8907
+ pathConflicts.set(normalizedName, SYMLINK);
8908
+ if (!linkname) return;
8909
+ validateBounds(path$1.resolve(parentDir, linkname), destDir.symbolic, `Symlink "${linkname}" points outside the extraction directory.`);
8910
+ await prepareDirectory(parentDir);
8911
+ const realParentDir = await fsp.realpath(parentDir);
8912
+ validateBounds(realParentDir, destDir.real, "Symlink parent changed.");
8913
+ validateBounds(path$1.resolve(realParentDir, linkname), destDir.real, `Symlink "${linkname}" points outside the extraction directory.`);
8914
+ const realOutPath = path$1.join(realParentDir, path$1.basename(outPath));
8915
+ try {
8916
+ await fsp.symlink(linkname, realOutPath);
8917
+ } catch (err) {
8918
+ if (err.code !== "EEXIST") throw err;
8919
+ await fsp.rm(realOutPath, { force: true });
8920
+ if (await fsp.realpath(parentDir) !== realParentDir) throw new Error("Symlink parent changed.");
8921
+ await fsp.symlink(linkname, realOutPath);
8922
+ }
8923
+ (symlinks ??= []).push([normalizedName, linkname]);
8924
+ dirPromises.clear();
8925
+ realDirCache.clear();
8926
+ if (mtime) await fsp.lutimes(outPath, mtime, mtime).catch(() => {});
8927
+ return;
8886
8928
  }
8887
- if ((stream._duplexState & READ_READABLE_STATUS) === READ_EMIT_READABLE_AND_QUEUED) {
8888
- stream._duplexState |= READ_EMITTED_READABLE;
8889
- stream.emit("readable");
8929
+ case LINK: {
8930
+ pathConflicts.set(normalizedName, LINK);
8931
+ if (!linkname) return;
8932
+ if (path$1.isAbsolute(linkname)) throw new Error(`Hardlink "${linkname}" points outside the extraction directory.`);
8933
+ const linkTarget = path$1.join(destDir.symbolic, linkname);
8934
+ validateBounds(linkTarget, destDir.symbolic, `Hardlink "${linkname}" points outside the extraction directory.`);
8935
+ await prepareDirectory(parentDir);
8936
+ if (linkTarget !== outPath) deferredLinks.push({
8937
+ linkTarget,
8938
+ outPath
8939
+ });
8940
+ return;
8890
8941
  }
8891
- if ((stream._duplexState & READ_PRIMARY_AND_ACTIVE) === 0) this.updateNonPrimary();
8892
- } while (this.continueUpdate() === true);
8893
- stream._duplexState &= READ_NOT_UPDATING;
8894
- }
8895
- updateNonPrimary() {
8896
- const stream = this.stream;
8897
- if ((stream._duplexState & READ_ENDING_STATUS) === READ_ENDING) {
8898
- stream._duplexState = (stream._duplexState | READ_DONE) & READ_NOT_ENDING;
8899
- stream.emit("end");
8900
- if ((stream._duplexState & AUTO_DESTROY) === DONE) stream._duplexState |= DESTROYING;
8901
- if (this.pipeTo !== null) this.pipeTo.end();
8942
+ default: return;
8902
8943
  }
8903
- if ((stream._duplexState & DESTROY_STATUS) === DESTROYING) {
8904
- if ((stream._duplexState & ACTIVE_OR_TICKING) === 0) {
8905
- stream._duplexState |= ACTIVE;
8906
- stream._destroy(afterDestroy.bind(this));
8944
+ },
8945
+ async checkSymlinks() {
8946
+ if (!symlinks) return;
8947
+ const { symbolic: dest, real } = await destDirPromise;
8948
+ const realPrefix = real + path$1.sep;
8949
+ const root = path$1.parse(real).root;
8950
+ const depth = linkParts(real.slice(root.length)).length;
8951
+ const targetParts = (linkname, resolvedParts, message) => {
8952
+ if (!path$1.isAbsolute(linkname)) return linkParts(linkname);
8953
+ validateBounds(linkname, real, message);
8954
+ resolvedParts.length = 0;
8955
+ const parts = linkParts(linkname.slice(root.length));
8956
+ parts.splice(0, depth);
8957
+ return parts;
8958
+ };
8959
+ const getSymlinkError = async ([name, storedLinkname]) => {
8960
+ const outPath = path$1.join(dest, name);
8961
+ try {
8962
+ try {
8963
+ const resolved = await fsp.realpath(outPath);
8964
+ if (resolved !== real && !resolved.startsWith(realPrefix)) throw new Error(`Symlink "${storedLinkname}" points outside the extraction directory.`);
8965
+ return;
8966
+ } catch (err) {
8967
+ if (err.code !== ENOENT) throw err;
8968
+ }
8969
+ if (!(await fsp.lstat(outPath)).isSymbolicLink()) return;
8970
+ const linkname = await fsp.readlink(outPath);
8971
+ const message = `Symlink "${linkname}" points outside the extraction directory.`;
8972
+ const realParent = await fsp.realpath(path$1.dirname(outPath));
8973
+ validateBounds(realParent, real, message);
8974
+ const resolvedParts = linkParts(path$1.relative(real, realParent));
8975
+ const pendingParts = targetParts(linkname, resolvedParts, message);
8976
+ let followedSymlinks = 0;
8977
+ for (let i = 0; i < pendingParts.length; i++) {
8978
+ const part = pendingParts[i];
8979
+ if (part === "..") {
8980
+ if (!resolvedParts.length) throw new Error(message);
8981
+ resolvedParts.pop();
8982
+ continue;
8983
+ }
8984
+ resolvedParts.push(part);
8985
+ const nextPath = path$1.join(real, ...resolvedParts);
8986
+ let nextStat;
8987
+ try {
8988
+ nextStat = await fsp.lstat(nextPath);
8989
+ } catch (err) {
8990
+ if (err.code === ENOENT) continue;
8991
+ throw err;
8992
+ }
8993
+ if (!nextStat.isSymbolicLink()) continue;
8994
+ if (++followedSymlinks > MAX_SYMLINKS) throw new Error(message);
8995
+ const nextLink = await fsp.readlink(nextPath);
8996
+ resolvedParts.pop();
8997
+ pendingParts.splice(i + 1, 0, ...targetParts(nextLink, resolvedParts, message));
8998
+ }
8999
+ } catch (err) {
9000
+ if (err.code !== ENOENT) return err;
9001
+ }
9002
+ };
9003
+ for (let start = 0; start < symlinks.length; start += concurrency) {
9004
+ const batch = symlinks.slice(start, start + concurrency);
9005
+ const errors = await Promise.all(batch.map((symlink) => opQueue.add(() => getSymlinkError(symlink))));
9006
+ for (const [i, error] of errors.entries()) {
9007
+ if (error === void 0) continue;
9008
+ await fsp.rm(path$1.join(dest, batch[i][0]), { force: true });
9009
+ throw error;
8907
9010
  }
8908
- return;
8909
9011
  }
8910
- if ((stream._duplexState & IS_OPENING) === OPENING) {
8911
- stream._duplexState = (stream._duplexState | ACTIVE) & NOT_OPENING;
8912
- stream._open(afterOpen.bind(this));
9012
+ },
9013
+ async applyLinks() {
9014
+ const destRoot = (await destDirPromise).real;
9015
+ for (const { linkTarget, outPath } of deferredLinks) try {
9016
+ const realTargetDir = await fsp.realpath(path$1.dirname(linkTarget));
9017
+ validateBounds(realTargetDir, destRoot, `Hardlink "${linkTarget}" points outside the extraction directory.`);
9018
+ const realTarget = path$1.join(realTargetDir, path$1.basename(linkTarget));
9019
+ const [targetResult, outDirResult] = await Promise.allSettled([opQueue.add(() => fsp.lstat(realTarget)), opQueue.add(() => fsp.realpath(path$1.dirname(outPath)))]);
9020
+ if (targetResult.status === "rejected") throw targetResult.reason;
9021
+ const targetStat = targetResult.value;
9022
+ if (targetStat.isSymbolicLink()) throw new Error(`Hardlink "${linkTarget}" is a symlink.`);
9023
+ if (outDirResult.status === "rejected") throw outDirResult.reason;
9024
+ const realOutDir = outDirResult.value;
9025
+ validateBounds(realOutDir, destRoot, `Hardlink "${outPath}" points outside the extraction directory.`);
9026
+ const realOutPath = path$1.join(realOutDir, path$1.basename(outPath));
9027
+ try {
9028
+ await fsp.link(realTarget, realOutPath);
9029
+ } catch (err) {
9030
+ const code = err.code;
9031
+ if (code !== "EEXIST" && code !== ENOENT) throw err;
9032
+ try {
9033
+ const outStat = await fsp.lstat(realOutPath);
9034
+ if (outStat.dev === targetStat.dev && outStat.ino === targetStat.ino) continue;
9035
+ await fsp.rm(realOutPath, { force: true });
9036
+ } catch (err) {
9037
+ if (err.code !== ENOENT) throw err;
9038
+ }
9039
+ await fsp.link(realTarget, realOutPath);
9040
+ }
9041
+ const linkStat = await fsp.lstat(realOutPath);
9042
+ if (linkStat.dev !== targetStat.dev || linkStat.ino !== targetStat.ino) {
9043
+ await fsp.rm(realOutPath, { force: true });
9044
+ throw new Error(`Hardlink target "${linkTarget}" changed during creation for link at "${outPath}".`);
9045
+ }
9046
+ } catch (err) {
9047
+ if (err.code === ENOENT) throw new Error(`Hardlink target "${linkTarget}" does not exist for link at "${outPath}".`);
9048
+ throw err;
8913
9049
  }
8914
9050
  }
8915
- continueUpdate() {
8916
- if ((this.stream._duplexState & READ_NEXT_TICK) === 0) return false;
8917
- this.stream._duplexState &= READ_NOT_NEXT_TICK;
8918
- return true;
8919
- }
8920
- updateCallback() {
8921
- if ((this.stream._duplexState & READ_UPDATE_SYNC_STATUS) === READ_PRIMARY) this.update();
8922
- else this.updateNextTick();
8923
- }
8924
- updateNextTickIfOpen() {
8925
- if ((this.stream._duplexState & READ_NEXT_TICK_OR_OPENING) !== 0) return;
8926
- this.stream._duplexState |= READ_NEXT_TICK;
8927
- if ((this.stream._duplexState & READ_UPDATING) === 0) qmt(this.afterUpdateNextTick);
8928
- }
8929
- updateNextTick() {
8930
- if ((this.stream._duplexState & READ_NEXT_TICK) !== 0) return;
8931
- this.stream._duplexState |= READ_NEXT_TICK;
8932
- if ((this.stream._duplexState & READ_UPDATING) === 0) qmt(this.afterUpdateNextTick);
8933
- }
8934
9051
  };
8935
- var TransformState = class {
8936
- constructor(stream) {
8937
- this.data = null;
8938
- this.afterTransform = afterTransform.bind(stream);
8939
- this.afterFinal = null;
8940
- }
9052
+ };
9053
+ function unpackTar(directoryPath, options = {}) {
9054
+ const unpacker = createUnpacker(options);
9055
+ const concurrency = options.concurrency || cpus().length || 8;
9056
+ const opQueue = createOperationQueue(concurrency);
9057
+ const pathCache = createPathCache(directoryPath, options, opQueue, concurrency);
9058
+ let currentFileStream = null;
9059
+ let currentWriteCallback = null;
9060
+ let queuedError = null;
9061
+ const onQueuedError = (err) => {
9062
+ queuedError ??= err;
9063
+ if (!writable.destroyed) writable.destroy(err);
8941
9064
  };
8942
- var Pipeline = class {
8943
- constructor(src, dst, cb) {
8944
- this.from = src;
8945
- this.to = dst;
8946
- this.afterPipe = cb;
8947
- this.error = null;
8948
- this.pipeToFinished = false;
8949
- }
8950
- finished() {
8951
- this.pipeToFinished = true;
8952
- }
8953
- done(stream, err) {
8954
- if (err) this.error = err;
8955
- if (stream === this.to) {
8956
- this.to = null;
8957
- if (this.from !== null) {
8958
- if ((this.from._duplexState & READ_DONE) === 0 || !this.pipeToFinished) this.from.destroy(this.error || /* @__PURE__ */ new Error("Writable stream closed prematurely"));
8959
- return;
9065
+ const writable = new Writable({
9066
+ async write(chunk, _, cb) {
9067
+ const pendingFileOpens = [];
9068
+ let writeError;
9069
+ try {
9070
+ unpacker.write(chunk);
9071
+ if (unpacker.isEntryActive()) {
9072
+ if (currentFileStream && currentWriteCallback) {
9073
+ let needsDrain = false;
9074
+ const writeCallback = currentWriteCallback;
9075
+ while (!unpacker.isBodyComplete()) {
9076
+ needsDrain = false;
9077
+ if (unpacker.streamBody(writeCallback) === 0) if (needsDrain) await currentFileStream.waitDrain();
9078
+ else return;
9079
+ }
9080
+ while (!unpacker.skipPadding()) return;
9081
+ const streamToClose = currentFileStream;
9082
+ if (streamToClose) opQueue.add(() => streamToClose.end()).catch(onQueuedError);
9083
+ currentFileStream = null;
9084
+ currentWriteCallback = null;
9085
+ } else if (!unpacker.skipEntry()) return;
8960
9086
  }
8961
- }
8962
- if (stream === this.from) {
8963
- this.from = null;
8964
- if (this.to !== null) {
8965
- if ((stream._duplexState & READ_DONE) === 0) this.to.destroy(this.error || /* @__PURE__ */ new Error("Readable stream closed before ending"));
8966
- return;
9087
+ while (true) {
9088
+ const header = unpacker.readHeader();
9089
+ if (header === void 0 || header === null) return;
9090
+ const transformedHeader = transformHeader(header, options);
9091
+ if (!transformedHeader) {
9092
+ if (!unpacker.skipEntry()) return;
9093
+ continue;
9094
+ }
9095
+ const outPath = await opQueue.add(() => pathCache.preparePath(transformedHeader));
9096
+ if (outPath) {
9097
+ const safeMode = transformedHeader.mode ? transformedHeader.mode & 511 : void 0;
9098
+ const fileStream = createFileSink(outPath, {
9099
+ mode: options.fmode ?? safeMode,
9100
+ mtime: transformedHeader.mtime ?? void 0
9101
+ });
9102
+ pendingFileOpens.push(fileStream.waitDrain().catch((error) => error));
9103
+ let needsDrain = false;
9104
+ const writeCallback = (chunk) => {
9105
+ const writeOk = fileStream.write(chunk);
9106
+ if (!writeOk) needsDrain = true;
9107
+ return writeOk;
9108
+ };
9109
+ while (!unpacker.isBodyComplete()) {
9110
+ needsDrain = false;
9111
+ if (unpacker.streamBody(writeCallback) === 0) if (needsDrain) await fileStream.waitDrain();
9112
+ else {
9113
+ currentFileStream = fileStream;
9114
+ currentWriteCallback = writeCallback;
9115
+ return;
9116
+ }
9117
+ }
9118
+ while (!unpacker.skipPadding()) {
9119
+ currentFileStream = fileStream;
9120
+ currentWriteCallback = writeCallback;
9121
+ return;
9122
+ }
9123
+ opQueue.add(() => fileStream.end()).catch(onQueuedError);
9124
+ } else if (!unpacker.skipEntry()) return;
8967
9125
  }
9126
+ } catch (err) {
9127
+ writeError = err;
9128
+ } finally {
9129
+ cb((pendingFileOpens.length ? (await Promise.all(pendingFileOpens)).find((error) => error) : void 0) ?? writeError);
8968
9130
  }
8969
- if (this.afterPipe !== null) this.afterPipe(this.error);
8970
- this.to = this.from = this.afterPipe = null;
8971
- }
8972
- };
8973
- function afterDrain() {
8974
- this.stream._duplexState |= READ_PIPE_DRAINED;
8975
- this.updateCallback();
8976
- }
8977
- function afterFinal(err) {
8978
- const stream = this.stream;
8979
- if (err) stream.destroy(err);
8980
- if ((stream._duplexState & DESTROY_STATUS) === 0) {
8981
- stream._duplexState |= WRITE_DONE;
8982
- stream.emit("finish");
8983
- }
8984
- if ((stream._duplexState & AUTO_DESTROY) === DONE) stream._duplexState |= DESTROYING;
8985
- stream._duplexState &= WRITE_NOT_FINISHING;
8986
- if ((stream._duplexState & WRITE_UPDATING) === 0) this.update();
8987
- else this.updateNextTick();
8988
- }
8989
- function afterDestroy(err) {
8990
- const stream = this.stream;
8991
- if (!err && !StreamError.isStreamDestroyed(this.error)) err = this.error;
8992
- if (err) stream.emit("error", err);
8993
- stream._duplexState |= DESTROYED;
8994
- stream.emit("close");
8995
- const rs = stream._readableState;
8996
- const ws = stream._writableState;
8997
- if (rs !== null && rs.pipeline !== null) rs.pipeline.done(stream, err);
8998
- if (ws !== null) {
8999
- while (ws.drains !== null && ws.drains.length > 0) ws.drains.shift().resolve(false);
9000
- if (ws.pipeline !== null) ws.pipeline.done(stream, err);
9001
- }
9002
- }
9003
- function afterWrite(err) {
9004
- const stream = this.stream;
9005
- if (err) stream.destroy(err);
9006
- stream._duplexState &= WRITE_NOT_ACTIVE;
9007
- if (this.drains !== null) tickDrains(this.drains);
9008
- if ((stream._duplexState & WRITE_DRAIN_STATUS) === WRITE_UNDRAINED) {
9009
- stream._duplexState &= WRITE_DRAINED;
9010
- if ((stream._duplexState & WRITE_EMIT_DRAIN) === WRITE_EMIT_DRAIN) stream.emit("drain");
9011
- }
9012
- this.updateCallback();
9013
- }
9014
- function afterRead(err) {
9015
- if (err) this.stream.destroy(err);
9016
- this.stream._duplexState &= READ_NOT_ACTIVE;
9017
- if (this.readAhead === false && (this.stream._duplexState & READ_RESUMED) === 0) this.stream._duplexState &= READ_NO_READ_AHEAD;
9018
- this.updateCallback();
9019
- }
9020
- function updateReadNT() {
9021
- if ((this.stream._duplexState & READ_UPDATING) === 0) {
9022
- this.stream._duplexState &= READ_NOT_NEXT_TICK;
9023
- this.update();
9024
- }
9025
- }
9026
- function updateWriteNT() {
9027
- if ((this.stream._duplexState & WRITE_UPDATING) === 0) {
9028
- this.stream._duplexState &= WRITE_NOT_NEXT_TICK;
9029
- this.update();
9030
- }
9031
- }
9032
- function tickDrains(drains) {
9033
- for (let i = 0; i < drains.length; i++) if (--drains[i].writes === 0) {
9034
- drains.shift().resolve(true);
9035
- i--;
9036
- }
9037
- }
9038
- function afterOpen(err) {
9039
- const stream = this.stream;
9040
- if (err) stream.destroy(err);
9041
- if ((stream._duplexState & DESTROYING) === 0) {
9042
- if ((stream._duplexState & READ_PRIMARY_STATUS) === 0) stream._duplexState |= READ_PRIMARY;
9043
- if ((stream._duplexState & WRITE_PRIMARY_STATUS) === 0) stream._duplexState |= WRITE_PRIMARY;
9044
- stream.emit("open");
9045
- }
9046
- stream._duplexState &= NOT_ACTIVE;
9047
- if (stream._writableState !== null) stream._writableState.updateCallback();
9048
- if (stream._readableState !== null) stream._readableState.updateCallback();
9049
- }
9050
- function afterTransform(err, data) {
9051
- if (data !== void 0 && data !== null) this.push(data);
9052
- this._writableState.afterWrite(err);
9053
- }
9054
- function newListener(name) {
9055
- if (this._readableState !== null) {
9056
- if (name === "data") {
9057
- this._duplexState |= 133376;
9058
- this._readableState.updateNextTick();
9059
- }
9060
- if (name === "readable") {
9061
- this._duplexState |= READ_EMIT_READABLE;
9062
- this._readableState.updateNextTick();
9131
+ },
9132
+ async final(cb) {
9133
+ try {
9134
+ unpacker.end();
9135
+ unpacker.validateEOF();
9136
+ await pathCache.ready();
9137
+ await opQueue.onIdle();
9138
+ if (queuedError) throw queuedError;
9139
+ await pathCache.checkSymlinks();
9140
+ await pathCache.applyLinks();
9141
+ cb();
9142
+ } catch (err) {
9143
+ cb(err);
9063
9144
  }
9145
+ },
9146
+ destroy(error, callback) {
9147
+ (async () => {
9148
+ if (currentFileStream) {
9149
+ currentFileStream.destroy(error ?? void 0);
9150
+ currentFileStream = null;
9151
+ currentWriteCallback = null;
9152
+ }
9153
+ await opQueue.onIdle();
9154
+ })().then(() => callback(error ?? null), (e) => callback(error ?? (e instanceof Error ? e : /* @__PURE__ */ new Error("Stream destroyed"))));
9064
9155
  }
9065
- if (this._writableState !== null) {
9066
- if (name === "drain") {
9067
- this._duplexState |= WRITE_EMIT_DRAIN;
9068
- this._writableState.updateNextTick();
9069
- }
9070
- }
9071
- }
9072
- var Stream = class extends EventEmitter {
9073
- constructor(opts) {
9074
- super();
9075
- this._duplexState = 0;
9076
- this._readableState = null;
9077
- this._writableState = null;
9078
- if (opts) {
9079
- if (opts.open) this._open = opts.open;
9080
- if (opts.destroy) this._destroy = opts.destroy;
9081
- if (opts.predestroy) this._predestroy = opts.predestroy;
9082
- if (opts.signal) opts.signal.addEventListener("abort", abort.bind(this));
9083
- }
9084
- this.on("newListener", newListener);
9085
- }
9086
- _open(cb) {
9087
- cb(null);
9088
- }
9089
- _destroy(cb) {
9090
- cb(null);
9091
- }
9092
- _predestroy() {}
9093
- get readable() {
9094
- return this._readableState !== null ? true : void 0;
9095
- }
9096
- get writable() {
9097
- return this._writableState !== null ? true : void 0;
9098
- }
9099
- get destroyed() {
9100
- return (this._duplexState & DESTROYED) !== 0;
9101
- }
9102
- get destroying() {
9103
- return (this._duplexState & DESTROY_STATUS) !== 0;
9104
- }
9105
- destroy(err) {
9106
- if ((this._duplexState & DESTROY_STATUS) === 0) {
9107
- if (!err) err = StreamError.STREAM_DESTROYED();
9108
- this._duplexState = (this._duplexState | DESTROYING) & NON_PRIMARY;
9109
- if (this._readableState !== null) {
9110
- this._readableState.highWaterMark = 0;
9111
- this._readableState.error = err;
9112
- }
9113
- if (this._writableState !== null) {
9114
- this._writableState.highWaterMark = 0;
9115
- this._writableState.error = err;
9116
- }
9117
- this._duplexState |= PREDESTROYING;
9118
- this._predestroy();
9119
- this._duplexState &= NOT_PREDESTROYING;
9120
- if (this._readableState !== null) this._readableState.updateNextTick();
9121
- if (this._writableState !== null) this._writableState.updateNextTick();
9122
- }
9123
- }
9124
- };
9125
- var Readable = class Readable extends Stream {
9126
- constructor(opts) {
9127
- super(opts);
9128
- this._duplexState |= 8519681;
9129
- this._readableState = new ReadableState(this, opts);
9130
- if (opts) {
9131
- if (this._readableState.readAhead === false) this._duplexState &= READ_NO_READ_AHEAD;
9132
- if (opts.read) this._read = opts.read;
9133
- if (opts.eagerOpen) this._readableState.updateNextTick();
9134
- if (opts.encoding) this.setEncoding(opts.encoding);
9135
- }
9136
- }
9137
- static deferred(fn, opts) {
9138
- const out = new PassThrough(opts);
9139
- fn().then((src) => {
9140
- if (src === null) return out.end();
9141
- if (out.destroying) return;
9142
- pipeline(src, out, noop);
9143
- }).catch((err) => out.destroy(err));
9144
- return out;
9145
- }
9146
- setEncoding(encoding) {
9147
- const dec = new TextDecoder(encoding);
9148
- const map = this._readableState.map || echo;
9149
- this._readableState.map = mapOrSkip;
9150
- return this;
9151
- function mapOrSkip(data) {
9152
- const next = dec.push(data);
9153
- return next === "" && (data.byteLength !== 0 || dec.remaining > 0) ? null : map(next);
9154
- }
9155
- }
9156
- _read(cb) {
9157
- cb(null);
9158
- }
9159
- pipe(dest, cb) {
9160
- this._readableState.updateNextTick();
9161
- this._readableState.pipe(dest, cb);
9162
- return dest;
9163
- }
9164
- read() {
9165
- this._readableState.updateNextTick();
9166
- return this._readableState.read();
9167
- }
9168
- push(data) {
9169
- this._readableState.updateNextTickIfOpen();
9170
- return this._readableState.push(data);
9171
- }
9172
- unshift(data) {
9173
- this._readableState.updateNextTickIfOpen();
9174
- return this._readableState.unshift(data);
9175
- }
9176
- resume() {
9177
- this._duplexState |= READ_RESUMED_READ_AHEAD;
9178
- this._readableState.updateNextTick();
9179
- return this;
9180
- }
9181
- pause() {
9182
- this._duplexState &= this._readableState.readAhead === false ? READ_PAUSED_NO_READ_AHEAD : READ_PAUSED;
9183
- return this;
9184
- }
9185
- static _fromAsyncIterator(ite, opts) {
9186
- let destroy;
9187
- const rs = new Readable({
9188
- ...opts,
9189
- read(cb) {
9190
- ite.next().then(push).then(cb.bind(null, null)).catch(cb);
9191
- },
9192
- predestroy() {
9193
- destroy = ite.return();
9194
- },
9195
- destroy(cb) {
9196
- if (!destroy) return cb(null);
9197
- destroy.then(cb.bind(null, null)).catch(cb);
9198
- }
9199
- });
9200
- return rs;
9201
- function push(data) {
9202
- if (data.done) rs.push(null);
9203
- else rs.push(data.value);
9204
- }
9205
- }
9206
- static from(data, opts) {
9207
- if (isReadStreamx(data)) return data;
9208
- if (data[asyncIterator]) return this._fromAsyncIterator(data[asyncIterator](), opts);
9209
- if (!Array.isArray(data)) data = data === void 0 ? [] : [data];
9210
- let i = 0;
9211
- return new Readable({
9212
- ...opts,
9213
- read(cb) {
9214
- this.push(i === data.length ? null : data[i++]);
9215
- cb(null);
9216
- }
9217
- });
9218
- }
9219
- static isBackpressured(rs) {
9220
- return (rs._duplexState & READ_BACKPRESSURE_STATUS) !== 0 || rs._readableState.buffered >= rs._readableState.highWaterMark;
9221
- }
9222
- static isPaused(rs) {
9223
- return (rs._duplexState & READ_RESUMED) === 0;
9224
- }
9225
- [asyncIterator]() {
9226
- const stream = this;
9227
- let error = null;
9228
- let promiseResolve = null;
9229
- let promiseReject = null;
9230
- this.on("error", (err) => {
9231
- error = err;
9232
- });
9233
- this.on("readable", onreadable);
9234
- this.on("close", onclose);
9235
- return {
9236
- [asyncIterator]() {
9237
- return this;
9238
- },
9239
- next() {
9240
- return new Promise(function(resolve, reject) {
9241
- promiseResolve = resolve;
9242
- promiseReject = reject;
9243
- const data = stream.read();
9244
- if (data !== null) ondata(data);
9245
- else if ((stream._duplexState & DESTROYED) !== 0) ondata(null);
9246
- });
9247
- },
9248
- return() {
9249
- return destroy(null);
9250
- },
9251
- throw(err) {
9252
- return destroy(err);
9253
- }
9254
- };
9255
- function onreadable() {
9256
- if (promiseResolve !== null) ondata(stream.read());
9257
- }
9258
- function onclose() {
9259
- if (promiseResolve !== null) ondata(null);
9260
- }
9261
- function ondata(data) {
9262
- if (promiseReject === null) return;
9263
- if (error) promiseReject(error);
9264
- else if (data === null && (stream._duplexState & READ_DONE) === 0) promiseReject(StreamError.STREAM_DESTROYED());
9265
- else promiseResolve({
9266
- value: data,
9267
- done: data === null
9268
- });
9269
- promiseReject = promiseResolve = null;
9270
- }
9271
- function destroy(err) {
9272
- stream.destroy(err);
9273
- return new Promise((resolve, reject) => {
9274
- if (stream._duplexState & DESTROYED) return resolve({
9275
- value: void 0,
9276
- done: true
9277
- });
9278
- stream.once("close", function() {
9279
- if (err) reject(err);
9280
- else resolve({
9281
- value: void 0,
9282
- done: true
9283
- });
9284
- });
9285
- });
9286
- }
9287
- }
9288
- };
9289
- var Writable = class extends Stream {
9290
- constructor(opts) {
9291
- super(opts);
9292
- this._duplexState |= 16385;
9293
- this._writableState = new WritableState(this, opts);
9294
- if (opts) {
9295
- if (opts.writev) this._writev = opts.writev;
9296
- if (opts.write) this._write = opts.write;
9297
- if (opts.final) this._final = opts.final;
9298
- if (opts.eagerOpen) this._writableState.updateNextTick();
9299
- }
9300
- }
9301
- cork() {
9302
- this._duplexState |= WRITE_CORKED;
9303
- }
9304
- uncork() {
9305
- this._duplexState &= WRITE_NOT_CORKED;
9306
- this._writableState.updateNextTick();
9307
- }
9308
- _writev(batch, cb) {
9309
- cb(null);
9310
- }
9311
- _write(data, cb) {
9312
- this._writableState.autoBatch(data, cb);
9313
- }
9314
- _final(cb) {
9315
- cb(null);
9316
- }
9317
- static isBackpressured(ws) {
9318
- return (ws._duplexState & WRITE_BACKPRESSURE_STATUS) !== 0;
9319
- }
9320
- static drained(ws) {
9321
- if (ws.destroyed) return Promise.resolve(false);
9322
- const state = ws._writableState;
9323
- const writes = (isWritev(ws) ? Math.min(1, state.queue.length) : state.queue.length) + (ws._duplexState & WRITE_WRITING ? 1 : 0);
9324
- if (writes === 0) return Promise.resolve(true);
9325
- if (state.drains === null) state.drains = [];
9326
- return new Promise((resolve) => {
9327
- state.drains.push({
9328
- writes,
9329
- resolve
9330
- });
9331
- });
9332
- }
9333
- write(data) {
9334
- this._writableState.updateNextTick();
9335
- return this._writableState.push(data);
9336
- }
9337
- end(data) {
9338
- this._writableState.updateNextTick();
9339
- this._writableState.end(data);
9340
- return this;
9341
- }
9342
- };
9343
- var Duplex = class extends Readable {
9344
- constructor(opts) {
9345
- super(opts);
9346
- this._duplexState = OPENING | this._duplexState & READ_READ_AHEAD;
9347
- this._writableState = new WritableState(this, opts);
9348
- if (opts) {
9349
- if (opts.writev) this._writev = opts.writev;
9350
- if (opts.write) this._write = opts.write;
9351
- if (opts.final) this._final = opts.final;
9352
- }
9353
- }
9354
- cork() {
9355
- this._duplexState |= WRITE_CORKED;
9356
- }
9357
- uncork() {
9358
- this._duplexState &= WRITE_NOT_CORKED;
9359
- this._writableState.updateNextTick();
9360
- }
9361
- _writev(batch, cb) {
9362
- cb(null);
9363
- }
9364
- _write(data, cb) {
9365
- this._writableState.autoBatch(data, cb);
9366
- }
9367
- _final(cb) {
9368
- cb(null);
9369
- }
9370
- write(data) {
9371
- this._writableState.updateNextTick();
9372
- return this._writableState.push(data);
9373
- }
9374
- end(data) {
9375
- this._writableState.updateNextTick();
9376
- this._writableState.end(data);
9377
- return this;
9378
- }
9379
- };
9380
- var Transform = class extends Duplex {
9381
- constructor(opts) {
9382
- super(opts);
9383
- this._transformState = new TransformState(this);
9384
- if (opts) {
9385
- if (opts.transform) this._transform = opts.transform;
9386
- if (opts.flush) this._flush = opts.flush;
9387
- }
9388
- }
9389
- _write(data, cb) {
9390
- if (this._readableState.buffered >= this._readableState.highWaterMark) this._transformState.data = data;
9391
- else this._transform(data, this._transformState.afterTransform);
9392
- }
9393
- _read(cb) {
9394
- if (this._transformState.data !== null) {
9395
- const data = this._transformState.data;
9396
- this._transformState.data = null;
9397
- cb(null);
9398
- this._transform(data, this._transformState.afterTransform);
9399
- } else cb(null);
9400
- }
9401
- destroy(err) {
9402
- super.destroy(err);
9403
- if (this._transformState.data !== null) {
9404
- this._transformState.data = null;
9405
- this._transformState.afterTransform();
9406
- }
9407
- }
9408
- _transform(data, cb) {
9409
- cb(null, data);
9410
- }
9411
- _flush(cb) {
9412
- cb(null);
9413
- }
9414
- _final(cb) {
9415
- this._transformState.afterFinal = cb;
9416
- this._flush(transformAfterFlush.bind(this));
9417
- }
9418
- };
9419
- var PassThrough = class extends Transform {};
9420
- function transformAfterFlush(err, data) {
9421
- const cb = this._transformState.afterFinal;
9422
- if (err) return cb(err);
9423
- if (data !== null && data !== void 0) this.push(data);
9424
- this.push(null);
9425
- cb(null);
9426
- }
9427
- function pipelinePromise(...streams) {
9428
- return new Promise((resolve, reject) => {
9429
- return pipeline(...streams, (err) => {
9430
- if (err) return reject(err);
9431
- resolve();
9432
- });
9433
- });
9434
- }
9435
- function pipeline(stream, ...streams) {
9436
- const all = Array.isArray(stream) ? [...stream, ...streams] : [stream, ...streams];
9437
- const done = all.length && typeof all[all.length - 1] === "function" ? all.pop() : null;
9438
- if (all.length < 2) throw new Error("Pipeline requires at least 2 streams");
9439
- let src = all[0];
9440
- let dest = null;
9441
- let error = null;
9442
- for (let i = 1; i < all.length; i++) {
9443
- dest = all[i];
9444
- if (isStreamx(src)) src.pipe(dest, onerror);
9445
- else {
9446
- errorHandle(src, true, i > 1, onerror);
9447
- src.pipe(dest);
9448
- }
9449
- src = dest;
9450
- }
9451
- if (done) {
9452
- let fin = false;
9453
- const autoDestroy = isStreamx(dest) || !!(dest._writableState && dest._writableState.autoDestroy);
9454
- dest.on("error", (err) => {
9455
- if (error === null) error = err;
9456
- });
9457
- dest.on("finish", () => {
9458
- fin = true;
9459
- if (!autoDestroy) done(error);
9460
- });
9461
- if (autoDestroy) dest.on("close", () => done(error || (fin ? null : StreamError.PREMATURE_CLOSE())));
9462
- }
9463
- return dest;
9464
- function errorHandle(s, rd, wr, onerror) {
9465
- s.on("error", onerror);
9466
- s.on("close", onclose);
9467
- function onclose() {
9468
- if (rd && s._readableState && !s._readableState.ended) return onerror(StreamError.PREMATURE_CLOSE());
9469
- if (wr && s._writableState && !s._writableState.ended) return onerror(StreamError.PREMATURE_CLOSE());
9470
- }
9471
- }
9472
- function onerror(err) {
9473
- if (!err || error) return;
9474
- error = err;
9475
- for (const s of all) s.destroy(err);
9476
- }
9477
- }
9478
- function echo(s) {
9479
- return s;
9480
- }
9481
- function isStream(stream) {
9482
- return !!stream._readableState || !!stream._writableState;
9483
- }
9484
- function isStreamx(stream) {
9485
- return typeof stream._duplexState === "number" && isStream(stream);
9486
- }
9487
- function isEnding(stream) {
9488
- return !!stream._readableState && stream._readableState.ending;
9489
- }
9490
- function isEnded(stream) {
9491
- return !!stream._readableState && stream._readableState.ended;
9492
- }
9493
- function isFinishing(stream) {
9494
- return !!stream._writableState && stream._writableState.ending;
9495
- }
9496
- function isFinished(stream) {
9497
- return !!stream._writableState && stream._writableState.ended;
9498
- }
9499
- function getStreamError(stream, opts = {}) {
9500
- const err = stream._readableState && stream._readableState.error || stream._writableState && stream._writableState.error;
9501
- return !opts.all && StreamError.isStreamDestroyed(err) ? null : err;
9502
- }
9503
- function isReadStreamx(stream) {
9504
- return isStreamx(stream) && stream.readable;
9505
- }
9506
- function isDisturbed(stream) {
9507
- return (stream._duplexState & OPENING) !== OPENING || (stream._duplexState & DESTROYING) === DESTROYING || (stream._duplexState & ACTIVE_OR_TICKING) !== 0;
9508
- }
9509
- function isTypedArray(data) {
9510
- return typeof data === "object" && data !== null && typeof data.byteLength === "number";
9511
- }
9512
- function defaultByteLength(data) {
9513
- return isTypedArray(data) ? data.byteLength : 1024;
9514
- }
9515
- function noop() {}
9516
- function abort() {
9517
- this.destroy(StreamError.ABORTED());
9518
- }
9519
- function isWritev(s) {
9520
- return s._writev !== Writable.prototype._writev && s._writev !== Duplex.prototype._writev;
9521
- }
9522
- module.exports = {
9523
- pipeline,
9524
- pipelinePromise,
9525
- isStream,
9526
- isStreamx,
9527
- isEnding,
9528
- isEnded,
9529
- isFinishing,
9530
- isFinished,
9531
- isDisturbed,
9532
- getStreamError,
9533
- Stream,
9534
- Writable,
9535
- Readable,
9536
- Duplex,
9537
- Transform,
9538
- PassThrough
9539
- };
9540
- }));
9541
- //#endregion
9542
- //#region ../../node_modules/.pnpm/tar-stream@3.2.0/node_modules/tar-stream/headers.js
9543
- var require_headers = /* @__PURE__ */ __commonJSMin(((exports) => {
9544
- const b4a = require_b4a();
9545
- const ZEROS = "0000000000000000000";
9546
- const SEVENS = "7777777777777777777";
9547
- const ZERO_OFFSET = "0".charCodeAt(0);
9548
- const USTAR_MAGIC = b4a.from([
9549
- 117,
9550
- 115,
9551
- 116,
9552
- 97,
9553
- 114,
9554
- 0
9555
- ]);
9556
- const USTAR_VER = b4a.from([ZERO_OFFSET, ZERO_OFFSET]);
9557
- const GNU_MAGIC = b4a.from([
9558
- 117,
9559
- 115,
9560
- 116,
9561
- 97,
9562
- 114,
9563
- 32
9564
- ]);
9565
- const GNU_VER = b4a.from([32, 0]);
9566
- const MASK = 4095;
9567
- const MAGIC_OFFSET = 257;
9568
- const VERSION_OFFSET = 263;
9569
- exports.decodeLongPath = function decodeLongPath(buf, encoding) {
9570
- return decodeStr(buf, 0, buf.length, encoding);
9571
- };
9572
- exports.encodePax = function encodePax(opts) {
9573
- let result = "";
9574
- if (opts.name) result += addLength(" path=" + opts.name + "\n");
9575
- if (opts.linkname) result += addLength(" linkpath=" + opts.linkname + "\n");
9576
- const pax = opts.pax;
9577
- if (pax) for (const key in pax) result += addLength(" " + key + "=" + pax[key] + "\n");
9578
- return b4a.from(result);
9579
- };
9580
- exports.decodePax = function decodePax(buf) {
9581
- const result = {};
9582
- while (buf.length) {
9583
- let i = 0;
9584
- while (i < buf.length && buf[i] !== 32) i++;
9585
- const len = parseInt(b4a.toString(buf.subarray(0, i)), 10);
9586
- if (!len) return result;
9587
- const b = b4a.toString(buf.subarray(i + 1, len - 1));
9588
- const keyIndex = b.indexOf("=");
9589
- if (keyIndex === -1) return result;
9590
- result[b.slice(0, keyIndex)] = b.slice(keyIndex + 1);
9591
- buf = buf.subarray(len);
9592
- }
9593
- return result;
9594
- };
9595
- exports.encode = function encode(opts) {
9596
- const buf = b4a.alloc(512);
9597
- let name = opts.name;
9598
- let prefix = "";
9599
- if (opts.typeflag === 5 && name[name.length - 1] !== "/") name += "/";
9600
- if (b4a.byteLength(name) !== name.length) return null;
9601
- while (b4a.byteLength(name) > 100) {
9602
- const i = name.indexOf("/");
9603
- if (i === -1) return null;
9604
- prefix += prefix ? "/" + name.slice(0, i) : name.slice(0, i);
9605
- name = name.slice(i + 1);
9606
- }
9607
- if (b4a.byteLength(name) > 100 || b4a.byteLength(prefix) > 155) return null;
9608
- if (opts.linkname && b4a.byteLength(opts.linkname) > 100) return null;
9609
- b4a.write(buf, name);
9610
- b4a.write(buf, encodeOct(opts.mode & MASK, 6), 100);
9611
- b4a.write(buf, encodeOct(opts.uid, 6), 108);
9612
- b4a.write(buf, encodeOct(opts.gid, 6), 116);
9613
- encodeSize(opts.size, buf, 124);
9614
- b4a.write(buf, encodeOct(opts.mtime.getTime() / 1e3 | 0, 11), 136);
9615
- buf[156] = ZERO_OFFSET + toTypeflag(opts.type);
9616
- if (opts.linkname) b4a.write(buf, opts.linkname, 157);
9617
- b4a.copy(USTAR_MAGIC, buf, MAGIC_OFFSET);
9618
- b4a.copy(USTAR_VER, buf, VERSION_OFFSET);
9619
- if (opts.uname) b4a.write(buf, opts.uname, 265);
9620
- if (opts.gname) b4a.write(buf, opts.gname, 297);
9621
- b4a.write(buf, encodeOct(opts.devmajor || 0, 6), 329);
9622
- b4a.write(buf, encodeOct(opts.devminor || 0, 6), 337);
9623
- if (prefix) b4a.write(buf, prefix, 345);
9624
- b4a.write(buf, encodeOct(cksum(buf), 6), 148);
9625
- return buf;
9626
- };
9627
- exports.decode = function decode(buf, filenameEncoding, allowUnknownFormat) {
9628
- let typeflag = buf[156] === 0 ? 0 : buf[156] - ZERO_OFFSET;
9629
- let name = decodeStr(buf, 0, 100, filenameEncoding);
9630
- const mode = decodeOct(buf, 100, 8);
9631
- const uid = decodeOct(buf, 108, 8);
9632
- const gid = decodeOct(buf, 116, 8);
9633
- const size = decodeOct(buf, 124, 12);
9634
- const mtime = decodeOct(buf, 136, 12);
9635
- const type = toType(typeflag);
9636
- const linkname = buf[157] === 0 ? null : decodeStr(buf, 157, 100, filenameEncoding);
9637
- const uname = decodeStr(buf, 265, 32);
9638
- const gname = decodeStr(buf, 297, 32);
9639
- const devmajor = decodeOct(buf, 329, 8);
9640
- const devminor = decodeOct(buf, 337, 8);
9641
- const c = cksum(buf);
9642
- if (c === 256) return null;
9643
- if (c !== decodeOct(buf, 148, 8)) throw new Error("Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped?");
9644
- if (isUSTAR(buf)) {
9645
- if (buf[345]) name = decodeStr(buf, 345, 155, filenameEncoding) + "/" + name;
9646
- } else if (isGNU(buf)) {} else if (!allowUnknownFormat) throw new Error("Invalid tar header: unknown format.");
9647
- if (typeflag === 0 && name && name[name.length - 1] === "/") typeflag = 5;
9648
- return {
9649
- name,
9650
- mode,
9651
- uid,
9652
- gid,
9653
- size,
9654
- byteOffset: 0,
9655
- mtime: /* @__PURE__ */ new Date(1e3 * mtime),
9656
- type,
9657
- linkname,
9658
- uname,
9659
- gname,
9660
- devmajor,
9661
- devminor,
9662
- pax: null
9663
- };
9664
- };
9665
- function isUSTAR(buf) {
9666
- return b4a.equals(USTAR_MAGIC, buf.subarray(MAGIC_OFFSET, 263));
9667
- }
9668
- function isGNU(buf) {
9669
- return b4a.equals(GNU_MAGIC, buf.subarray(MAGIC_OFFSET, 263)) && b4a.equals(GNU_VER, buf.subarray(VERSION_OFFSET, 265));
9670
- }
9671
- function clamp(index, len, defaultValue) {
9672
- if (typeof index !== "number") return defaultValue;
9673
- index = ~~index;
9674
- if (index >= len) return len;
9675
- if (index >= 0) return index;
9676
- index += len;
9677
- if (index >= 0) return index;
9678
- return 0;
9679
- }
9680
- function toType(flag) {
9681
- switch (flag) {
9682
- case 0: return "file";
9683
- case 1: return "link";
9684
- case 2: return "symlink";
9685
- case 3: return "character-device";
9686
- case 4: return "block-device";
9687
- case 5: return "directory";
9688
- case 6: return "fifo";
9689
- case 7: return "contiguous-file";
9690
- case 72: return "pax-header";
9691
- case 55: return "pax-global-header";
9692
- case 27: return "gnu-long-link-path";
9693
- case 28:
9694
- case 30: return "gnu-long-path";
9695
- }
9696
- return null;
9697
- }
9698
- function toTypeflag(flag) {
9699
- switch (flag) {
9700
- case "file": return 0;
9701
- case "link": return 1;
9702
- case "symlink": return 2;
9703
- case "character-device": return 3;
9704
- case "block-device": return 4;
9705
- case "directory": return 5;
9706
- case "fifo": return 6;
9707
- case "contiguous-file": return 7;
9708
- case "pax-header": return 72;
9709
- }
9710
- return 0;
9711
- }
9712
- function indexOf(block, num, offset, end) {
9713
- for (; offset < end; offset++) if (block[offset] === num) return offset;
9714
- return end;
9715
- }
9716
- function cksum(block) {
9717
- let sum = 256;
9718
- for (let i = 0; i < 148; i++) sum += block[i];
9719
- for (let j = 156; j < 512; j++) sum += block[j];
9720
- return sum;
9721
- }
9722
- function encodeOct(val, n) {
9723
- val = val.toString(8);
9724
- if (val.length > n) return SEVENS.slice(0, n) + " ";
9725
- return ZEROS.slice(0, n - val.length) + val + " ";
9726
- }
9727
- function encodeSizeBin(num, buf, off) {
9728
- buf[off] = 128;
9729
- for (let i = 11; i > 0; i--) {
9730
- buf[off + i] = num & 255;
9731
- num = Math.floor(num / 256);
9732
- }
9733
- }
9734
- function encodeSize(num, buf, off) {
9735
- if (num.toString(8).length > 11) encodeSizeBin(num, buf, off);
9736
- else b4a.write(buf, encodeOct(num, 11), off);
9737
- }
9738
- function parse256(buf) {
9739
- let positive;
9740
- if (buf[0] === 128) positive = true;
9741
- else if (buf[0] === 255) positive = false;
9742
- else return null;
9743
- const tuple = [];
9744
- let i;
9745
- for (i = buf.length - 1; i > 0; i--) {
9746
- const byte = buf[i];
9747
- if (positive) tuple.push(byte);
9748
- else tuple.push(255 - byte);
9749
- }
9750
- let sum = 0;
9751
- const l = tuple.length;
9752
- for (i = 0; i < l; i++) sum += tuple[i] * Math.pow(256, i);
9753
- return positive ? sum : -1 * sum;
9754
- }
9755
- function decodeOct(val, offset, length) {
9756
- val = val.subarray(offset, offset + length);
9757
- offset = 0;
9758
- if (val[offset] & 128) return parse256(val);
9759
- else {
9760
- while (offset < val.length && val[offset] === 32) offset++;
9761
- const end = clamp(indexOf(val, 32, offset, val.length), val.length, val.length);
9762
- while (offset < end && val[offset] === 0) offset++;
9763
- if (end === offset) return 0;
9764
- return parseInt(b4a.toString(val.subarray(offset, end)), 8);
9765
- }
9766
- }
9767
- function decodeStr(val, offset, length, encoding) {
9768
- return b4a.toString(val.subarray(offset, indexOf(val, 0, offset, offset + length)), encoding);
9769
- }
9770
- function addLength(str) {
9771
- const len = b4a.byteLength(str);
9772
- let digits = Math.floor(Math.log(len) / Math.log(10)) + 1;
9773
- if (len + digits >= Math.pow(10, digits)) digits++;
9774
- return len + digits + str;
9775
- }
9776
- }));
9777
- //#endregion
9778
- //#region ../../node_modules/.pnpm/tar-stream@3.2.0/node_modules/tar-stream/extract.js
9779
- var require_extract = /* @__PURE__ */ __commonJSMin(((exports, module) => {
9780
- const { Writable, Readable, getStreamError } = require_streamx();
9781
- const FIFO = require_fast_fifo();
9782
- const b4a = require_b4a();
9783
- const headers = require_headers();
9784
- const EMPTY = b4a.alloc(0);
9785
- const MAX_HEADER_SIZE = 4 * 1024 * 1024;
9786
- var BufferList = class {
9787
- constructor() {
9788
- this.buffered = 0;
9789
- this.shifted = 0;
9790
- this.queue = new FIFO();
9791
- this._offset = 0;
9792
- }
9793
- push(buffer) {
9794
- this.buffered += buffer.byteLength;
9795
- this.queue.push(buffer);
9796
- }
9797
- shiftFirst(size) {
9798
- return this.buffered === 0 ? null : this._next(size);
9799
- }
9800
- shift(size) {
9801
- if (size > this.buffered) return null;
9802
- if (size === 0) return EMPTY;
9803
- let chunk = this._next(size);
9804
- if (size === chunk.byteLength) return chunk;
9805
- const chunks = [chunk];
9806
- while ((size -= chunk.byteLength) > 0) {
9807
- chunk = this._next(size);
9808
- chunks.push(chunk);
9809
- }
9810
- return b4a.concat(chunks);
9811
- }
9812
- _next(size) {
9813
- const buf = this.queue.peek();
9814
- const rem = buf.byteLength - this._offset;
9815
- if (size >= rem) {
9816
- const sub = this._offset ? buf.subarray(this._offset, buf.byteLength) : buf;
9817
- this.queue.shift();
9818
- this._offset = 0;
9819
- this.buffered -= rem;
9820
- this.shifted += rem;
9821
- return sub;
9822
- }
9823
- this.buffered -= size;
9824
- this.shifted += size;
9825
- return buf.subarray(this._offset, this._offset += size);
9826
- }
9827
- };
9828
- var Source = class extends Readable {
9829
- constructor(self, header, offset) {
9830
- super();
9831
- this.header = header;
9832
- this.offset = offset;
9833
- this._parent = self;
9834
- }
9835
- _read(cb) {
9836
- if (this.header.size === 0) this.push(null);
9837
- if (this._parent._stream === this) this._parent._update();
9838
- cb(null);
9839
- }
9840
- _predestroy() {
9841
- this._parent.destroy(getStreamError(this));
9842
- }
9843
- _detach() {
9844
- if (this._parent._stream === this) {
9845
- this._parent._stream = null;
9846
- this._parent._missing = overflow(this.header.size);
9847
- this._parent._update();
9848
- }
9849
- }
9850
- _destroy(cb) {
9851
- this._detach();
9852
- cb(null);
9853
- }
9854
- };
9855
- var Extract = class extends Writable {
9856
- constructor(opts) {
9857
- super(opts);
9858
- if (!opts) opts = {};
9859
- this._buffer = new BufferList();
9860
- this._offset = 0;
9861
- this._header = null;
9862
- this._stream = null;
9863
- this._missing = 0;
9864
- this._longHeader = false;
9865
- this._callback = noop;
9866
- this._locked = false;
9867
- this._finished = false;
9868
- this._pax = null;
9869
- this._paxGlobal = null;
9870
- this._gnuLongPath = null;
9871
- this._gnuLongLinkPath = null;
9872
- this._filenameEncoding = opts.filenameEncoding || "utf-8";
9873
- this._allowUnknownFormat = !!opts.allowUnknownFormat;
9874
- this._unlockBound = this._unlock.bind(this);
9875
- }
9876
- _unlock(err) {
9877
- this._locked = false;
9878
- if (err) {
9879
- this.destroy(err);
9880
- this._continueWrite(err);
9881
- return;
9882
- }
9883
- this._update();
9884
- }
9885
- _consumeHeader() {
9886
- if (this._locked) return false;
9887
- this._offset = this._buffer.shifted;
9888
- try {
9889
- this._header = headers.decode(this._buffer.shift(512), this._filenameEncoding, this._allowUnknownFormat);
9890
- } catch (err) {
9891
- this._continueWrite(err);
9892
- return false;
9893
- }
9894
- if (!this._header) return true;
9895
- this._header.byteOffset = this._buffer.shifted;
9896
- switch (this._header.type) {
9897
- case "gnu-long-path":
9898
- case "gnu-long-link-path":
9899
- case "pax-global-header":
9900
- case "pax-header":
9901
- this._longHeader = true;
9902
- this._missing = this._header.size;
9903
- if (this._missing > MAX_HEADER_SIZE) {
9904
- this._continueWrite(/* @__PURE__ */ new Error("Header exceeds max size"));
9905
- return false;
9906
- }
9907
- return true;
9908
- }
9909
- this._locked = true;
9910
- this._applyLongHeaders();
9911
- if (!(this._header.size >= 0)) {
9912
- this._continueWrite(/* @__PURE__ */ new Error("Invalid header"));
9913
- return false;
9914
- }
9915
- if (this._header.size === 0 || this._header.type === "directory") {
9916
- this.emit("entry", this._header, this._createStream(), this._unlockBound);
9917
- return true;
9918
- }
9919
- this._stream = this._createStream();
9920
- this._missing = this._header.size;
9921
- this.emit("entry", this._header, this._stream, this._unlockBound);
9922
- return true;
9923
- }
9924
- _applyLongHeaders() {
9925
- if (this._gnuLongPath) {
9926
- this._header.name = this._gnuLongPath;
9927
- this._gnuLongPath = null;
9928
- }
9929
- if (this._gnuLongLinkPath) {
9930
- this._header.linkname = this._gnuLongLinkPath;
9931
- this._gnuLongLinkPath = null;
9932
- }
9933
- if (this._pax) {
9934
- if (this._pax.path) this._header.name = this._pax.path;
9935
- if (this._pax.linkpath) this._header.linkname = this._pax.linkpath;
9936
- if (this._pax.size) this._header.size = parseInt(this._pax.size, 10);
9937
- this._header.pax = this._pax;
9938
- this._pax = null;
9939
- }
9940
- }
9941
- _decodeLongHeader(buf) {
9942
- switch (this._header.type) {
9943
- case "gnu-long-path":
9944
- this._gnuLongPath = headers.decodeLongPath(buf, this._filenameEncoding);
9945
- break;
9946
- case "gnu-long-link-path":
9947
- this._gnuLongLinkPath = headers.decodeLongPath(buf, this._filenameEncoding);
9948
- break;
9949
- case "pax-global-header":
9950
- this._paxGlobal = headers.decodePax(buf);
9951
- break;
9952
- case "pax-header":
9953
- this._pax = this._paxGlobal === null ? headers.decodePax(buf) : Object.assign({}, this._paxGlobal, headers.decodePax(buf));
9954
- break;
9955
- }
9956
- }
9957
- _consumeLongHeader() {
9958
- this._longHeader = false;
9959
- this._missing = overflow(this._header.size);
9960
- const buf = this._buffer.shift(this._header.size);
9961
- try {
9962
- this._decodeLongHeader(buf);
9963
- } catch (err) {
9964
- this._continueWrite(err);
9965
- return false;
9966
- }
9967
- return true;
9968
- }
9969
- _consumeStream() {
9970
- const buf = this._buffer.shiftFirst(this._missing);
9971
- if (buf === null) return false;
9972
- this._missing -= buf.byteLength;
9973
- const drained = this._stream.push(buf);
9974
- if (this._missing === 0) {
9975
- this._stream.push(null);
9976
- if (drained) this._stream._detach();
9977
- return drained && this._locked === false;
9978
- }
9979
- return drained;
9980
- }
9981
- _createStream() {
9982
- return new Source(this, this._header, this._offset);
9983
- }
9984
- _update() {
9985
- while (this._buffer.buffered > 0 && !this.destroying) {
9986
- if (this._missing > 0) {
9987
- if (this._stream !== null) {
9988
- if (this._consumeStream() === false) return;
9989
- continue;
9990
- }
9991
- if (this._longHeader === true) {
9992
- if (this._missing > this._buffer.buffered) break;
9993
- if (this._consumeLongHeader() === false) return false;
9994
- continue;
9995
- }
9996
- const ignore = this._buffer.shiftFirst(this._missing);
9997
- if (ignore !== null) this._missing -= ignore.byteLength;
9998
- continue;
9999
- }
10000
- if (this._buffer.buffered < 512) break;
10001
- if (this._stream !== null || this._consumeHeader() === false) return;
10002
- }
10003
- this._continueWrite(null);
10004
- }
10005
- _continueWrite(err) {
10006
- const cb = this._callback;
10007
- this._callback = noop;
10008
- cb(err);
10009
- }
10010
- _write(data, cb) {
10011
- this._callback = cb;
10012
- this._buffer.push(data);
10013
- this._update();
10014
- }
10015
- _final(cb) {
10016
- this._finished = this._missing === 0 && this._buffer.buffered === 0;
10017
- cb(this._finished ? null : /* @__PURE__ */ new Error("Unexpected end of data"));
10018
- }
10019
- _predestroy() {
10020
- this._continueWrite(null);
10021
- }
10022
- _destroy(cb) {
10023
- if (this._stream) this._stream.destroy(getStreamError(this));
10024
- cb(null);
10025
- }
10026
- [Symbol.asyncIterator]() {
10027
- let error = null;
10028
- let promiseResolve = null;
10029
- let promiseReject = null;
10030
- let entryStream = null;
10031
- let entryCallback = null;
10032
- const extract = this;
10033
- this.on("entry", onentry);
10034
- this.on("error", (err) => {
10035
- error = err;
10036
- });
10037
- this.on("close", onclose);
10038
- return {
10039
- [Symbol.asyncIterator]() {
10040
- return this;
10041
- },
10042
- next() {
10043
- return new Promise(onnext);
10044
- },
10045
- return() {
10046
- return destroy(null);
10047
- },
10048
- throw(err) {
10049
- return destroy(err);
10050
- }
10051
- };
10052
- function consumeCallback(err) {
10053
- if (!entryCallback) return;
10054
- const cb = entryCallback;
10055
- entryCallback = null;
10056
- cb(err);
10057
- }
10058
- function onnext(resolve, reject) {
10059
- if (error) return reject(error);
10060
- if (entryStream) {
10061
- resolve({
10062
- value: entryStream,
10063
- done: false
10064
- });
10065
- entryStream = null;
10066
- return;
10067
- }
10068
- promiseResolve = resolve;
10069
- promiseReject = reject;
10070
- consumeCallback(null);
10071
- if (extract._finished && promiseResolve) {
10072
- promiseResolve({
10073
- value: void 0,
10074
- done: true
10075
- });
10076
- promiseResolve = promiseReject = null;
10077
- }
10078
- }
10079
- function onentry(header, stream, callback) {
10080
- entryCallback = callback;
10081
- stream.on("error", noop);
10082
- if (promiseResolve) {
10083
- promiseResolve({
10084
- value: stream,
10085
- done: false
10086
- });
10087
- promiseResolve = promiseReject = null;
10088
- } else entryStream = stream;
10089
- }
10090
- function onclose() {
10091
- consumeCallback(error);
10092
- if (!promiseResolve) return;
10093
- if (error) promiseReject(error);
10094
- else promiseResolve({
10095
- value: void 0,
10096
- done: true
10097
- });
10098
- promiseResolve = promiseReject = null;
10099
- }
10100
- function destroy(err) {
10101
- extract.destroy(err);
10102
- consumeCallback(err);
10103
- return new Promise((resolve, reject) => {
10104
- if (extract.destroyed) return resolve({
10105
- value: void 0,
10106
- done: true
10107
- });
10108
- extract.once("close", function() {
10109
- if (err) reject(err);
10110
- else resolve({
10111
- value: void 0,
10112
- done: true
10113
- });
10114
- });
10115
- });
10116
- }
10117
- }
10118
- };
10119
- module.exports = function extract(opts) {
10120
- return new Extract(opts);
10121
- };
10122
- function noop() {}
10123
- function overflow(size) {
10124
- size &= 511;
10125
- return size && 512 - size;
10126
- }
10127
- }));
10128
- //#endregion
10129
- //#region ../../node_modules/.pnpm/tar-stream@3.2.0/node_modules/tar-stream/constants.js
10130
- var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
10131
- const constants = {
10132
- S_IFMT: 61440,
10133
- S_IFDIR: 16384,
10134
- S_IFCHR: 8192,
10135
- S_IFBLK: 24576,
10136
- S_IFIFO: 4096,
10137
- S_IFLNK: 40960
10138
- };
10139
- try {
10140
- module.exports = __require("fs").constants || constants;
10141
- } catch {
10142
- module.exports = constants;
10143
- }
10144
- }));
10145
- //#endregion
10146
- //#region ../../node_modules/.pnpm/tar-stream@3.2.0/node_modules/tar-stream/pack.js
10147
- var require_pack = /* @__PURE__ */ __commonJSMin(((exports, module) => {
10148
- const { Readable, Writable, getStreamError } = require_streamx();
10149
- const b4a = require_b4a();
10150
- const constants = require_constants();
10151
- const headers = require_headers();
10152
- const DMODE = 493;
10153
- const FMODE = 420;
10154
- const END_OF_TAR = b4a.alloc(1024);
10155
- var Sink = class extends Writable {
10156
- constructor(pack, header, callback) {
10157
- super({
10158
- mapWritable,
10159
- eagerOpen: true
10160
- });
10161
- this.written = 0;
10162
- this.header = header;
10163
- this._callback = callback;
10164
- this._linkname = null;
10165
- this._isLinkname = header.type === "symlink" && !header.linkname;
10166
- this._isVoid = header.type !== "file" && header.type !== "contiguous-file";
10167
- this._finished = false;
10168
- this._pack = pack;
10169
- this._openCallback = null;
10170
- if (this._pack._stream === null) this._pack._stream = this;
10171
- else this._pack._pending.push(this);
10172
- }
10173
- _open(cb) {
10174
- this._openCallback = cb;
10175
- if (this._pack._stream === this) this._continueOpen();
10176
- }
10177
- _continuePack(err) {
10178
- if (this._callback === null) return;
10179
- const callback = this._callback;
10180
- this._callback = null;
10181
- callback(err);
10182
- }
10183
- _continueOpen() {
10184
- if (this._pack._stream === null) this._pack._stream = this;
10185
- const cb = this._openCallback;
10186
- this._openCallback = null;
10187
- if (cb === null) return;
10188
- if (this._pack.destroying) return cb(/* @__PURE__ */ new Error("pack stream destroyed"));
10189
- if (this._pack._finalized) return cb(/* @__PURE__ */ new Error("pack stream is already finalized"));
10190
- this._pack._stream = this;
10191
- if (!this._isLinkname) this._pack._encode(this.header);
10192
- if (this._isVoid) {
10193
- this._finish();
10194
- this._continuePack(null);
10195
- }
10196
- cb(null);
10197
- }
10198
- _write(data, cb) {
10199
- if (this._isLinkname) {
10200
- this._linkname = this._linkname ? b4a.concat([this._linkname, data]) : data;
10201
- return cb(null);
10202
- }
10203
- if (this._isVoid) {
10204
- if (data.byteLength > 0) return cb(/* @__PURE__ */ new Error("No body allowed for this entry"));
10205
- return cb();
10206
- }
10207
- this.written += data.byteLength;
10208
- if (this._pack.push(data)) return cb();
10209
- this._pack._drain = cb;
10210
- }
10211
- _finish() {
10212
- if (this._finished) return;
10213
- this._finished = true;
10214
- if (this._isLinkname) {
10215
- this.header.linkname = this._linkname ? b4a.toString(this._linkname, "utf-8") : "";
10216
- this._pack._encode(this.header);
10217
- }
10218
- overflow(this._pack, this.header.size);
10219
- this._pack._done(this);
10220
- }
10221
- _final(cb) {
10222
- if (this.written !== this.header.size) return cb(/* @__PURE__ */ new Error("Size mismatch"));
10223
- this._finish();
10224
- cb(null);
10225
- }
10226
- _getError() {
10227
- return getStreamError(this) || /* @__PURE__ */ new Error("tar entry destroyed");
10228
- }
10229
- _predestroy() {
10230
- this._pack.destroy(this._getError());
10231
- }
10232
- _destroy(cb) {
10233
- this._pack._done(this);
10234
- this._continuePack(this._finished ? null : this._getError());
10235
- cb();
10236
- }
10237
- };
10238
- var Pack = class extends Readable {
10239
- constructor(opts) {
10240
- super(opts);
10241
- this._drain = noop;
10242
- this._finalized = false;
10243
- this._finalizing = false;
10244
- this._pending = [];
10245
- this._stream = null;
10246
- }
10247
- entry(header, buffer, callback) {
10248
- if (this._finalized || this.destroying) throw new Error("already finalized or destroyed");
10249
- if (typeof buffer === "function") {
10250
- callback = buffer;
10251
- buffer = null;
10252
- }
10253
- if (!callback) callback = noop;
10254
- if (!header.size || header.type === "symlink") header.size = 0;
10255
- if (!header.type) header.type = modeToType(header.mode);
10256
- if (!header.mode) header.mode = header.type === "directory" ? DMODE : FMODE;
10257
- if (!header.uid) header.uid = 0;
10258
- if (!header.gid) header.gid = 0;
10259
- if (!header.mtime) header.mtime = /* @__PURE__ */ new Date();
10260
- if (typeof buffer === "string") buffer = b4a.from(buffer);
10261
- const sink = new Sink(this, header, callback);
10262
- if (b4a.isBuffer(buffer)) {
10263
- header.size = buffer.byteLength;
10264
- sink.write(buffer);
10265
- sink.end();
10266
- return sink;
10267
- }
10268
- if (sink._isVoid) return sink;
10269
- return sink;
10270
- }
10271
- finalize() {
10272
- if (this._stream || this._pending.length > 0) {
10273
- this._finalizing = true;
10274
- return;
10275
- }
10276
- if (this._finalized) return;
10277
- this._finalized = true;
10278
- this.push(END_OF_TAR);
10279
- this.push(null);
10280
- }
10281
- _done(stream) {
10282
- if (stream !== this._stream) return;
10283
- this._stream = null;
10284
- if (this._finalizing) this.finalize();
10285
- if (this._pending.length) this._pending.shift()._continueOpen();
10286
- }
10287
- _encode(header) {
10288
- if (!header.pax) {
10289
- const buf = headers.encode(header);
10290
- if (buf) {
10291
- this.push(buf);
10292
- return;
10293
- }
10294
- }
10295
- this._encodePax(header);
10296
- }
10297
- _encodePax(header) {
10298
- const paxHeader = headers.encodePax({
10299
- name: header.name,
10300
- linkname: header.linkname,
10301
- pax: header.pax
10302
- });
10303
- const newHeader = {
10304
- name: "PaxHeader",
10305
- mode: header.mode,
10306
- uid: header.uid,
10307
- gid: header.gid,
10308
- size: paxHeader.byteLength,
10309
- mtime: header.mtime,
10310
- type: "pax-header",
10311
- linkname: header.linkname && "PaxHeader",
10312
- uname: header.uname,
10313
- gname: header.gname,
10314
- devmajor: header.devmajor,
10315
- devminor: header.devminor
10316
- };
10317
- this.push(headers.encode(newHeader));
10318
- this.push(paxHeader);
10319
- overflow(this, paxHeader.byteLength);
10320
- newHeader.size = header.size;
10321
- newHeader.type = header.type;
10322
- this.push(headers.encode(newHeader));
10323
- }
10324
- _doDrain() {
10325
- const drain = this._drain;
10326
- this._drain = noop;
10327
- drain();
10328
- }
10329
- _predestroy() {
10330
- const err = getStreamError(this);
10331
- if (this._stream) this._stream.destroy(err);
10332
- while (this._pending.length) {
10333
- const stream = this._pending.shift();
10334
- stream.destroy(err);
10335
- stream._continueOpen();
10336
- }
10337
- this._doDrain();
10338
- }
10339
- _read(cb) {
10340
- this._doDrain();
10341
- cb();
10342
- }
10343
- };
10344
- module.exports = function pack(opts) {
10345
- return new Pack(opts);
10346
- };
10347
- function modeToType(mode) {
10348
- switch (mode & constants.S_IFMT) {
10349
- case constants.S_IFBLK: return "block-device";
10350
- case constants.S_IFCHR: return "character-device";
10351
- case constants.S_IFDIR: return "directory";
10352
- case constants.S_IFIFO: return "fifo";
10353
- case constants.S_IFLNK: return "symlink";
10354
- }
10355
- return "file";
10356
- }
10357
- function noop() {}
10358
- function overflow(self, size) {
10359
- size &= 511;
10360
- if (size) self.push(END_OF_TAR.subarray(0, 512 - size));
10361
- }
10362
- function mapWritable(buf) {
10363
- return b4a.isBuffer(buf) ? buf : b4a.from(buf);
10364
- }
10365
- }));
10366
- //#endregion
10367
- //#region ../../node_modules/.pnpm/tar-stream@3.2.0/node_modules/tar-stream/index.js
10368
- var require_tar_stream = /* @__PURE__ */ __commonJSMin(((exports) => {
10369
- exports.extract = require_extract();
10370
- exports.pack = require_pack();
10371
- }));
10372
- //#endregion
10373
- //#region ../../node_modules/.pnpm/wrappy@1.0.2/node_modules/wrappy/wrappy.js
10374
- var require_wrappy = /* @__PURE__ */ __commonJSMin(((exports, module) => {
10375
- module.exports = wrappy;
10376
- function wrappy(fn, cb) {
10377
- if (fn && cb) return wrappy(fn)(cb);
10378
- if (typeof fn !== "function") throw new TypeError("need wrapper function");
10379
- Object.keys(fn).forEach(function(k) {
10380
- wrapper[k] = fn[k];
10381
- });
10382
- return wrapper;
10383
- function wrapper() {
10384
- var args = new Array(arguments.length);
10385
- for (var i = 0; i < args.length; i++) args[i] = arguments[i];
10386
- var ret = fn.apply(this, args);
10387
- var cb = args[args.length - 1];
10388
- if (typeof ret === "function" && ret !== cb) Object.keys(cb).forEach(function(k) {
10389
- ret[k] = cb[k];
10390
- });
10391
- return ret;
10392
- }
10393
- }
10394
- }));
10395
- //#endregion
10396
- //#region ../../node_modules/.pnpm/once@1.4.0/node_modules/once/once.js
10397
- var require_once = /* @__PURE__ */ __commonJSMin(((exports, module) => {
10398
- var wrappy = require_wrappy();
10399
- module.exports = wrappy(once);
10400
- module.exports.strict = wrappy(onceStrict);
10401
- once.proto = once(function() {
10402
- Object.defineProperty(Function.prototype, "once", {
10403
- value: function() {
10404
- return once(this);
10405
- },
10406
- configurable: true
10407
- });
10408
- Object.defineProperty(Function.prototype, "onceStrict", {
10409
- value: function() {
10410
- return onceStrict(this);
10411
- },
10412
- configurable: true
10413
- });
10414
9156
  });
10415
- function once(fn) {
10416
- var f = function() {
10417
- if (f.called) return f.value;
10418
- f.called = true;
10419
- return f.value = fn.apply(this, arguments);
10420
- };
10421
- f.called = false;
10422
- return f;
10423
- }
10424
- function onceStrict(fn) {
10425
- var f = function() {
10426
- if (f.called) throw new Error(f.onceError);
10427
- f.called = true;
10428
- return f.value = fn.apply(this, arguments);
10429
- };
10430
- f.onceError = (fn.name || "Function wrapped with `once`") + " shouldn't be called more than once";
10431
- f.called = false;
10432
- return f;
10433
- }
10434
- }));
10435
- //#endregion
10436
- //#region ../../node_modules/.pnpm/end-of-stream@1.4.5/node_modules/end-of-stream/index.js
10437
- var require_end_of_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
10438
- var once = require_once();
10439
- var noop = function() {};
10440
- var qnt = global.Bare ? queueMicrotask : process.nextTick.bind(process);
10441
- var isRequest = function(stream) {
10442
- return stream.setHeader && typeof stream.abort === "function";
10443
- };
10444
- var isChildProcess = function(stream) {
10445
- return stream.stdio && Array.isArray(stream.stdio) && stream.stdio.length === 3;
10446
- };
10447
- var eos = function(stream, opts, callback) {
10448
- if (typeof opts === "function") return eos(stream, null, opts);
10449
- if (!opts) opts = {};
10450
- callback = once(callback || noop);
10451
- var ws = stream._writableState;
10452
- var rs = stream._readableState;
10453
- var readable = opts.readable || opts.readable !== false && stream.readable;
10454
- var writable = opts.writable || opts.writable !== false && stream.writable;
10455
- var cancelled = false;
10456
- var onlegacyfinish = function() {
10457
- if (!stream.writable) onfinish();
10458
- };
10459
- var onfinish = function() {
10460
- writable = false;
10461
- if (!readable) callback.call(stream);
10462
- };
10463
- var onend = function() {
10464
- readable = false;
10465
- if (!writable) callback.call(stream);
10466
- };
10467
- var onexit = function(exitCode) {
10468
- callback.call(stream, exitCode ? /* @__PURE__ */ new Error("exited with error code: " + exitCode) : null);
10469
- };
10470
- var onerror = function(err) {
10471
- callback.call(stream, err);
10472
- };
10473
- var onclose = function() {
10474
- qnt(onclosenexttick);
10475
- };
10476
- var onclosenexttick = function() {
10477
- if (cancelled) return;
10478
- if (readable && !(rs && rs.ended && !rs.destroyed)) return callback.call(stream, /* @__PURE__ */ new Error("premature close"));
10479
- if (writable && !(ws && ws.ended && !ws.destroyed)) return callback.call(stream, /* @__PURE__ */ new Error("premature close"));
10480
- };
10481
- var onrequest = function() {
10482
- stream.req.on("finish", onfinish);
10483
- };
10484
- if (isRequest(stream)) {
10485
- stream.on("complete", onfinish);
10486
- stream.on("abort", onclose);
10487
- if (stream.req) onrequest();
10488
- else stream.on("request", onrequest);
10489
- } else if (writable && !ws) {
10490
- stream.on("end", onlegacyfinish);
10491
- stream.on("close", onlegacyfinish);
10492
- }
10493
- if (isChildProcess(stream)) stream.on("exit", onexit);
10494
- stream.on("end", onend);
10495
- stream.on("finish", onfinish);
10496
- if (opts.error !== false) stream.on("error", onerror);
10497
- stream.on("close", onclose);
10498
- return function() {
10499
- cancelled = true;
10500
- stream.removeListener("complete", onfinish);
10501
- stream.removeListener("abort", onclose);
10502
- stream.removeListener("request", onrequest);
10503
- if (stream.req) stream.req.removeListener("finish", onfinish);
10504
- stream.removeListener("end", onlegacyfinish);
10505
- stream.removeListener("close", onlegacyfinish);
10506
- stream.removeListener("finish", onfinish);
10507
- stream.removeListener("exit", onexit);
10508
- stream.removeListener("end", onend);
10509
- stream.removeListener("error", onerror);
10510
- stream.removeListener("close", onclose);
10511
- };
10512
- };
10513
- module.exports = eos;
10514
- }));
10515
- //#endregion
10516
- //#region ../../node_modules/.pnpm/pump@3.0.4/node_modules/pump/index.js
10517
- var require_pump = /* @__PURE__ */ __commonJSMin(((exports, module) => {
10518
- var once = require_once();
10519
- var eos = require_end_of_stream();
10520
- var fs;
10521
- try {
10522
- fs = __require("fs");
10523
- } catch (e) {}
10524
- var noop = function() {};
10525
- var ancient = typeof process === "undefined" ? false : /^v?\.0/.test(process.version);
10526
- var isFn = function(fn) {
10527
- return typeof fn === "function";
10528
- };
10529
- var isFS = function(stream) {
10530
- if (!ancient) return false;
10531
- if (!fs) return false;
10532
- return (stream instanceof (fs.ReadStream || noop) || stream instanceof (fs.WriteStream || noop)) && isFn(stream.close);
10533
- };
10534
- var isRequest = function(stream) {
10535
- return stream.setHeader && isFn(stream.abort);
10536
- };
10537
- var destroyer = function(stream, reading, writing, callback) {
10538
- callback = once(callback);
10539
- var closed = false;
10540
- stream.on("close", function() {
10541
- closed = true;
10542
- });
10543
- eos(stream, {
10544
- readable: reading,
10545
- writable: writing
10546
- }, function(err) {
10547
- if (err) return callback(err);
10548
- closed = true;
10549
- callback();
10550
- });
10551
- var destroyed = false;
10552
- return function(err) {
10553
- if (closed) return;
10554
- if (destroyed) return;
10555
- destroyed = true;
10556
- if (isFS(stream)) return stream.close(noop);
10557
- if (isRequest(stream)) return stream.abort();
10558
- if (isFn(stream.destroy)) return stream.destroy();
10559
- callback(err || /* @__PURE__ */ new Error("stream was destroyed"));
10560
- };
10561
- };
10562
- var call = function(fn) {
10563
- fn();
10564
- };
10565
- var pipe = function(from, to) {
10566
- return from.pipe(to);
10567
- };
10568
- var pump = function() {
10569
- var streams = Array.prototype.slice.call(arguments);
10570
- var callback = isFn(streams[streams.length - 1] || noop) && streams.pop() || noop;
10571
- if (Array.isArray(streams[0])) streams = streams[0];
10572
- if (streams.length < 2) throw new Error("pump requires two streams per minimum");
10573
- var error;
10574
- var destroys = streams.map(function(stream, i) {
10575
- var reading = i < streams.length - 1;
10576
- return destroyer(stream, reading, i > 0, function(err) {
10577
- if (!error) error = err;
10578
- if (err) destroys.forEach(call);
10579
- if (reading) return;
10580
- destroys.forEach(call);
10581
- callback(error);
10582
- });
10583
- });
10584
- return streams.reduce(pipe);
10585
- };
10586
- module.exports = pump;
10587
- }));
9157
+ return writable;
9158
+ }
10588
9159
  //#endregion
10589
9160
  //#region src/core/fetch-packages.ts
10590
- var import_tar_fs = (/* @__PURE__ */ __commonJSMin(((exports) => {
10591
- const tar = require_tar_stream();
10592
- const pump = require_pump();
10593
- const fs$1 = __require("fs");
10594
- const path$1 = __require("path");
10595
- const win32 = (global.Bare ? global.Bare.platform : process.platform) === "win32";
10596
- function head(list) {
10597
- return list.length ? list[list.length - 1] : null;
10598
- }
10599
- function processGetuid() {
10600
- return !global.Bare && process.getuid ? process.getuid() : -1;
10601
- }
10602
- function processUmask() {
10603
- return !global.Bare && process.umask ? process.umask() : 0;
10604
- }
10605
- exports.extract = function extract(cwd, opts) {
10606
- if (!cwd) cwd = ".";
10607
- if (!opts) opts = {};
10608
- cwd = path$1.resolve(cwd);
10609
- const xfs = opts.fs || fs$1;
10610
- const ignore = opts.ignore || opts.filter || noop;
10611
- const mapStream = opts.mapStream || echo;
10612
- const own = opts.chown !== false && !win32 && processGetuid() === 0;
10613
- const extract = opts.extract || tar.extract();
10614
- const stack = [];
10615
- const now = /* @__PURE__ */ new Date();
10616
- const umask = typeof opts.umask === "number" ? ~opts.umask : ~processUmask();
10617
- const strict = opts.strict !== false;
10618
- const validateSymLinks = opts.validateSymlinks !== false;
10619
- let map = opts.map || noop;
10620
- let dmode = typeof opts.dmode === "number" ? opts.dmode : 0;
10621
- let fmode = typeof opts.fmode === "number" ? opts.fmode : 0;
10622
- if (opts.strip) map = strip(map, opts.strip);
10623
- if (opts.readable) {
10624
- dmode |= parseInt(555, 8);
10625
- fmode |= parseInt(444, 8);
10626
- }
10627
- if (opts.writable) {
10628
- dmode |= parseInt(333, 8);
10629
- fmode |= parseInt(222, 8);
10630
- }
10631
- extract.on("entry", onentry);
10632
- if (opts.finish) extract.on("finish", opts.finish);
10633
- return extract;
10634
- function onentry(header, stream, next) {
10635
- header = map(header) || header;
10636
- header.name = normalize(header.name);
10637
- const name = path$1.join(cwd, path$1.join("/", header.name));
10638
- if (ignore(name, header)) {
10639
- stream.resume();
10640
- return next();
10641
- }
10642
- const dir = path$1.join(name, ".") === path$1.join(cwd, ".") ? cwd : path$1.dirname(name);
10643
- validate(xfs, dir, path$1.join(cwd, "."), function(err, valid) {
10644
- if (err) return next(err);
10645
- if (!valid) return next(/* @__PURE__ */ new Error(dir + " is not a valid path"));
10646
- if (header.type === "directory") {
10647
- stack.push([name, header.mtime]);
10648
- return mkdirfix(name, {
10649
- fs: xfs,
10650
- own,
10651
- uid: header.uid,
10652
- gid: header.gid,
10653
- mode: header.mode
10654
- }, stat);
10655
- }
10656
- mkdirfix(dir, {
10657
- fs: xfs,
10658
- own,
10659
- uid: header.uid,
10660
- gid: header.gid,
10661
- mode: 493
10662
- }, function(err) {
10663
- if (err) return next(err);
10664
- switch (header.type) {
10665
- case "file": return onfile();
10666
- case "link": return onlink();
10667
- case "symlink": return onsymlink();
10668
- }
10669
- if (strict) return next(/* @__PURE__ */ new Error("unsupported type for " + name + " (" + header.type + ")"));
10670
- stream.resume();
10671
- next();
10672
- });
10673
- });
10674
- function stat(err) {
10675
- if (err) return next(err);
10676
- utimes(name, header, function(err) {
10677
- if (err) return next(err);
10678
- if (win32) return next();
10679
- chperm(name, header, next);
10680
- });
10681
- }
10682
- function onsymlink() {
10683
- if (win32) return next();
10684
- xfs.unlink(name, function() {
10685
- const dst = path$1.resolve(path$1.dirname(name), header.linkname);
10686
- if (!inCwd(dst) && validateSymLinks) return next(/* @__PURE__ */ new Error(name + " is not a valid symlink"));
10687
- validateNotSymlink(xfs, dst, path$1.join(cwd, "."), function(err, valid) {
10688
- if (err) return next(err);
10689
- if (!valid && validateSymLinks) return next(/* @__PURE__ */ new Error(name + " is not a valid symlink"));
10690
- xfs.symlink(header.linkname, name, stat);
10691
- });
10692
- });
10693
- }
10694
- function onlink() {
10695
- if (win32) return next();
10696
- xfs.unlink(name, function() {
10697
- const link = path$1.join(cwd, path$1.join("/", header.linkname));
10698
- xfs.realpath(link, function(err, dst) {
10699
- if (err || !inCwd(dst)) return next(/* @__PURE__ */ new Error(name + " is not a valid hardlink"));
10700
- xfs.link(dst, name, function(err) {
10701
- if (err && err.code === "EPERM" && opts.hardlinkAsFilesFallback) {
10702
- stream = xfs.createReadStream(dst);
10703
- return onfile();
10704
- }
10705
- stat(err);
10706
- });
10707
- });
10708
- });
10709
- }
10710
- function inCwd(dst) {
10711
- return dst === cwd || dst.startsWith(cwd + path$1.sep);
10712
- }
10713
- function onfile() {
10714
- const ws = xfs.createWriteStream(name);
10715
- const rs = mapStream(stream, header);
10716
- ws.on("error", function(err) {
10717
- rs.destroy(err);
10718
- });
10719
- pump(rs, ws, function(err) {
10720
- if (err) return next(err);
10721
- ws.on("close", stat);
10722
- });
10723
- }
10724
- }
10725
- function utimesParent(name, cb) {
10726
- let top;
10727
- while ((top = head(stack)) && name.slice(0, top[0].length) !== top[0]) stack.pop();
10728
- if (!top) return cb();
10729
- xfs.utimes(top[0], now, top[1], cb);
10730
- }
10731
- function utimes(name, header, cb) {
10732
- if (opts.utimes === false) return cb();
10733
- if (header.type === "directory") return xfs.utimes(name, now, header.mtime, cb);
10734
- if (header.type === "symlink") return utimesParent(name, cb);
10735
- xfs.utimes(name, now, header.mtime, function(err) {
10736
- if (err) return cb(err);
10737
- utimesParent(name, cb);
10738
- });
10739
- }
10740
- function chperm(name, header, cb) {
10741
- const link = header.type === "symlink";
10742
- const chmod = link ? xfs.lchmod : xfs.chmod;
10743
- const chown = link ? xfs.lchown : xfs.chown;
10744
- if (!chmod) return cb();
10745
- const mode = (header.mode | (header.type === "directory" ? dmode : fmode)) & umask;
10746
- if (chown && own) chown.call(xfs, name, header.uid, header.gid, onchown);
10747
- else onchown(null);
10748
- function onchown(err) {
10749
- if (err) return cb(err);
10750
- if (!chmod) return cb();
10751
- chmod.call(xfs, name, mode, cb);
10752
- }
10753
- }
10754
- function mkdirfix(name, opts, cb) {
10755
- xfs.stat(name, function(err) {
10756
- if (!err) return cb(null);
10757
- if (err.code !== "ENOENT") return cb(err);
10758
- xfs.mkdir(name, {
10759
- mode: opts.mode,
10760
- recursive: true
10761
- }, function(err, made) {
10762
- if (err) return cb(err);
10763
- chperm(name, opts, cb);
10764
- });
10765
- });
10766
- }
10767
- };
10768
- function validateNotSymlink(fs, name, root, cb) {
10769
- if (name === root) return cb(null, true);
10770
- if (!name.startsWith(root + path$1.sep)) return cb(null, false);
10771
- fs.lstat(name, function(err, st) {
10772
- if (err && err.code !== "ENOENT" && err.code !== "EPERM") return cb(err);
10773
- if (err || !st.isSymbolicLink()) return validateNotSymlink(fs, path$1.join(name, ".."), root, cb);
10774
- cb(null, false);
10775
- });
10776
- }
10777
- function validate(fs, name, root, cb) {
10778
- if (name === root) return cb(null, true);
10779
- fs.lstat(name, function(err, st) {
10780
- if (err && err.code !== "ENOENT" && err.code !== "EPERM") return cb(err);
10781
- if (err || st.isDirectory()) return validate(fs, path$1.join(name, ".."), root, cb);
10782
- cb(null, false);
10783
- });
10784
- }
10785
- function noop() {}
10786
- function echo(name) {
10787
- return name;
10788
- }
10789
- function normalize(name) {
10790
- return win32 ? name.replace(/\\/g, "/").replace(/[:?<>|]/g, "_") : name;
10791
- }
10792
- function strip(map, level) {
10793
- return function(header) {
10794
- header.name = header.name.split("/").slice(level).join("/");
10795
- const linkname = header.linkname;
10796
- if (linkname && (header.type === "link" || path$1.isAbsolute(linkname))) header.linkname = linkname.split("/").slice(level).join("/");
10797
- return map(header);
10798
- };
10799
- }
10800
- })))();
10801
9161
  const NODE_MODULES = fileURLToPath(new URL("../../node_modules", import.meta.url));
10802
9162
  function verifyPackage(addonPkg, specifier) {
10803
9163
  const peerDeps = { ...addonPkg.peerDependencies };
@@ -10847,10 +9207,7 @@ async function downloadPackage(options) {
10847
9207
  const tarballUrl = pkg.dist.tarball;
10848
9208
  const data = await fetch(tarballUrl);
10849
9209
  if (!data.body) throw new Error(`Unexpected response: '${tarballUrl}' responded with no body`);
10850
- await pipeline(data.body, createGunzip(), (0, import_tar_fs.extract)(NODE_MODULES, { map: (header) => {
10851
- header.name = header.name.replace("package", pkg.name);
10852
- return header;
10853
- } }));
9210
+ await pipeline(data.body, createGunzip(), unpackTar(path.join(NODE_MODULES, pkg.name), { strip: 1 }));
10854
9211
  return await importAddonCode(pkg.name, pkg.version);
10855
9212
  }
10856
9213
  async function importAddonCode(pkgName, pkgVersion) {
@@ -10943,18 +9300,11 @@ async function packageManagerPrompt(cwd) {
10943
9300
  const agent = (await detect({ cwd }))?.name ?? getUserAgent();
10944
9301
  if (!V.stdout.isTTY) return agent;
10945
9302
  const pm = await Ee({
10946
- message: "Which package manager do you want to install dependencies with?",
9303
+ message: "Detected package managers. Which one should we use to install dependencies?",
10947
9304
  options: [{
10948
9305
  label: "None",
10949
9306
  value: void 0
10950
- }, ...AGENT_NAMES.map((agent) => {
10951
- const installed = isInstalled(agent);
10952
- return {
10953
- value: agent,
10954
- label: installed ? agent : color.dim(`${agent} (not installed)`),
10955
- installed
10956
- };
10957
- }).sort((a, b) => Number(b.installed) - Number(a.installed))],
9307
+ }, ...AGENT_NAMES.filter(isInstalled).map((agent) => ({ value: agent }))],
10958
9308
  initialValue: agent
10959
9309
  });
10960
9310
  if (R$2(pm)) {