minimal-forge-work-pack-sync 0.1.34 → 0.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1388 -333
- package/dist/repair.js +4385 -0
- package/package.json +1 -1
package/dist/repair.js
ADDED
|
@@ -0,0 +1,4385 @@
|
|
|
1
|
+
// packages/cli/src/repair.ts
|
|
2
|
+
import { createInterface } from "node:readline/promises";
|
|
3
|
+
|
|
4
|
+
// packages/cli/src/credentials.ts
|
|
5
|
+
import { chmod, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
6
|
+
function shellCredentialFiles(paths, forgeApiKey) {
|
|
7
|
+
return [
|
|
8
|
+
{ path: paths.envPath, bytes: Buffer.from(`export FORGE_API_KEY=${shellQuote(forgeApiKey)}
|
|
9
|
+
`) },
|
|
10
|
+
{ path: paths.powershellEnvPath, bytes: Buffer.from(renderPowerShellEnv(forgeApiKey)) }
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
async function readCredentials(paths) {
|
|
14
|
+
const raw = await readFile(paths.credentialsPath, "utf8");
|
|
15
|
+
const parsed = JSON.parse(raw);
|
|
16
|
+
if (!parsed.forgeApiKey || !parsed.forgeBaseUrl) {
|
|
17
|
+
throw new Error(`Ficheiro de credenciais inv\xE1lido em ${paths.credentialsPath}`);
|
|
18
|
+
}
|
|
19
|
+
return parsed;
|
|
20
|
+
}
|
|
21
|
+
function shellQuote(value) {
|
|
22
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
23
|
+
}
|
|
24
|
+
function powershellQuote(value) {
|
|
25
|
+
return `'${value.replaceAll("'", "''")}'`;
|
|
26
|
+
}
|
|
27
|
+
function renderPowerShellEnv(forgeApiKey) {
|
|
28
|
+
const quoted = powershellQuote(forgeApiKey);
|
|
29
|
+
return [
|
|
30
|
+
`$env:FORGE_API_KEY = ${quoted}`,
|
|
31
|
+
`[Environment]::SetEnvironmentVariable('FORGE_API_KEY', ${quoted}, 'User')`,
|
|
32
|
+
`Write-Host 'FORGE_API_KEY configurada para esta sess\xE3o PowerShell e sess\xF5es futuras do utilizador.'`,
|
|
33
|
+
""
|
|
34
|
+
].join("\n");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// packages/cli/src/localConfigRecovery.ts
|
|
38
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
39
|
+
import { readFile as readFile4 } from "node:fs/promises";
|
|
40
|
+
import path3 from "node:path";
|
|
41
|
+
|
|
42
|
+
// packages/cli/src/jsonc.ts
|
|
43
|
+
function parseJsonc(input) {
|
|
44
|
+
return JSON.parse(stripTrailingCommas(stripJsonComments(input)));
|
|
45
|
+
}
|
|
46
|
+
function stripJsonComments(input) {
|
|
47
|
+
let output = "";
|
|
48
|
+
let inString = false;
|
|
49
|
+
let escaped = false;
|
|
50
|
+
let inLineComment = false;
|
|
51
|
+
let inBlockComment = false;
|
|
52
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
53
|
+
const char = input[index];
|
|
54
|
+
const next = input[index + 1];
|
|
55
|
+
if (inLineComment) {
|
|
56
|
+
if (char === "\n" || char === "\r") {
|
|
57
|
+
inLineComment = false;
|
|
58
|
+
output += char;
|
|
59
|
+
}
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (inBlockComment) {
|
|
63
|
+
if (char === "*" && next === "/") {
|
|
64
|
+
inBlockComment = false;
|
|
65
|
+
index += 1;
|
|
66
|
+
} else if (char === "\n" || char === "\r") output += char;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (inString) {
|
|
70
|
+
output += char;
|
|
71
|
+
if (escaped) escaped = false;
|
|
72
|
+
else if (char === "\\") escaped = true;
|
|
73
|
+
else if (char === '"') inString = false;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (char === '"') {
|
|
77
|
+
inString = true;
|
|
78
|
+
output += char;
|
|
79
|
+
} else if (char === "/" && next === "/") {
|
|
80
|
+
inLineComment = true;
|
|
81
|
+
index += 1;
|
|
82
|
+
} else if (char === "/" && next === "*") {
|
|
83
|
+
inBlockComment = true;
|
|
84
|
+
index += 1;
|
|
85
|
+
} else output += char;
|
|
86
|
+
}
|
|
87
|
+
return output;
|
|
88
|
+
}
|
|
89
|
+
function stripTrailingCommas(input) {
|
|
90
|
+
let output = "";
|
|
91
|
+
let inString = false;
|
|
92
|
+
let escaped = false;
|
|
93
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
94
|
+
const char = input[index];
|
|
95
|
+
if (inString) {
|
|
96
|
+
output += char;
|
|
97
|
+
if (escaped) escaped = false;
|
|
98
|
+
else if (char === "\\") escaped = true;
|
|
99
|
+
else if (char === '"') inString = false;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (char === '"') {
|
|
103
|
+
inString = true;
|
|
104
|
+
output += char;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (char === ",") {
|
|
108
|
+
let lookahead = index + 1;
|
|
109
|
+
while (/\s/.test(input[lookahead] ?? "")) lookahead += 1;
|
|
110
|
+
if (input[lookahead] === "}" || input[lookahead] === "]") continue;
|
|
111
|
+
}
|
|
112
|
+
output += char;
|
|
113
|
+
}
|
|
114
|
+
return output;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// packages/cli/src/ownerOnlyFile.ts
|
|
118
|
+
import { spawnSync as nodeSpawnSync } from "node:child_process";
|
|
119
|
+
import { randomUUID } from "node:crypto";
|
|
120
|
+
import { chmod as chmod2, mkdir as mkdir2, rename as rename2, rm as rm2, stat, writeFile as writeFile2 } from "node:fs/promises";
|
|
121
|
+
import path from "node:path";
|
|
122
|
+
async function protectOwnerOnlyPath(filePath, kind, options = {}) {
|
|
123
|
+
const platform = options.platform ?? process.platform;
|
|
124
|
+
if (platform !== "win32") {
|
|
125
|
+
await chmod2(filePath, kind === "directory" ? 448 : 384);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const spawn = options.spawnSync ?? nodeSpawnSync;
|
|
129
|
+
const command = kind === "directory" ? "$ErrorActionPreference = 'Stop'; $path = [Console]::In.ReadToEnd(); $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().User; $acl = [System.Security.AccessControl.DirectorySecurity]::new(); $acl.SetAccessRuleProtection($true, $false); $inheritance = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit; $rule = [System.Security.AccessControl.FileSystemAccessRule]::new($identity, [System.Security.AccessControl.FileSystemRights]::FullControl, $inheritance, [System.Security.AccessControl.PropagationFlags]::None, [System.Security.AccessControl.AccessControlType]::Allow); [void]$acl.AddAccessRule($rule); [System.IO.Directory]::SetAccessControl($path, $acl)" : "$ErrorActionPreference = 'Stop'; $path = [Console]::In.ReadToEnd(); $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().User; $acl = [System.Security.AccessControl.FileSecurity]::new(); $acl.SetAccessRuleProtection($true, $false); $rule = [System.Security.AccessControl.FileSystemAccessRule]::new($identity, [System.Security.AccessControl.FileSystemRights]::FullControl, [System.Security.AccessControl.AccessControlType]::Allow); [void]$acl.AddAccessRule($rule); [System.IO.File]::SetAccessControl($path, $acl)";
|
|
130
|
+
const result = spawn("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", command], {
|
|
131
|
+
encoding: "utf8",
|
|
132
|
+
input: filePath
|
|
133
|
+
});
|
|
134
|
+
if (result.status !== 0) {
|
|
135
|
+
const detail = typeof result.stderr === "string" ? result.stderr.trim().replace(/\s+/g, " ").slice(0, 500) : "";
|
|
136
|
+
const context = options.failureContext ?? (kind === "directory" ? "o diret\xF3rio" : "o ficheiro");
|
|
137
|
+
throw new Error(`N\xE3o foi poss\xEDvel proteger ${context} em ${filePath}${detail ? `: ${detail}` : ""}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async function assertExistingDirectoryIsSafe(directory, options) {
|
|
141
|
+
const platform = options.platform ?? process.platform;
|
|
142
|
+
if (platform !== "win32") {
|
|
143
|
+
const info = await stat(directory);
|
|
144
|
+
const currentUid = process.getuid?.();
|
|
145
|
+
if (currentUid !== void 0 && info.uid !== currentUid || (info.mode & 18) !== 0) {
|
|
146
|
+
const mode = (info.mode & 511).toString(8).padStart(3, "0");
|
|
147
|
+
throw new Error(`O diret\xF3rio existente ${directory} n\xE3o \xE9 controlado apenas pelo utilizador atual (modo ${mode})`);
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const spawn = options.spawnSync ?? nodeSpawnSync;
|
|
152
|
+
const command = "$ErrorActionPreference = 'Stop'; $path = [Console]::In.ReadToEnd(); $current = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value; $trusted = @($current, 'S-1-5-18', 'S-1-5-32-544'); $dangerous = [System.Security.AccessControl.FileSystemRights]::Write -bor [System.Security.AccessControl.FileSystemRights]::Delete -bor [System.Security.AccessControl.FileSystemRights]::DeleteSubdirectoriesAndFiles -bor [System.Security.AccessControl.FileSystemRights]::ChangePermissions -bor [System.Security.AccessControl.FileSystemRights]::TakeOwnership; $acl = [System.IO.Directory]::GetAccessControl($path); $rules = $acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier]); foreach ($rule in $rules) { if ($rule.AccessControlType -eq [System.Security.AccessControl.AccessControlType]::Allow -and $rule.PropagationFlags -ne [System.Security.AccessControl.PropagationFlags]::InheritOnly -and ($rule.FileSystemRights -band $dangerous) -ne 0 -and $trusted -notcontains $rule.IdentityReference.Value) { throw ('O diret\xF3rio permite escrita por ' + $rule.IdentityReference.Value) } }";
|
|
153
|
+
const result = spawn("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", command], {
|
|
154
|
+
encoding: "utf8",
|
|
155
|
+
input: directory
|
|
156
|
+
});
|
|
157
|
+
if (result.status !== 0) {
|
|
158
|
+
const detail = typeof result.stderr === "string" ? result.stderr.trim().replace(/\s+/g, " ").slice(0, 500) : "";
|
|
159
|
+
throw new Error(`O diret\xF3rio existente ${directory} n\xE3o \xE9 controlado apenas pelo utilizador atual${detail ? `: ${detail}` : ""}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async function prepareOwnerOnlyFileDestination(filePath, options = {}) {
|
|
163
|
+
const directory = path.dirname(filePath);
|
|
164
|
+
const createdDirectory = await mkdir2(directory, { recursive: true, mode: 448 });
|
|
165
|
+
if (createdDirectory !== void 0) await protectOwnerOnlyPath(directory, "directory", options);
|
|
166
|
+
else await assertExistingDirectoryIsSafe(directory, options);
|
|
167
|
+
}
|
|
168
|
+
async function writeOwnerOnlyTextAtomic(filePath, content, options = {}) {
|
|
169
|
+
const directory = path.dirname(filePath);
|
|
170
|
+
await prepareOwnerOnlyFileDestination(filePath, options);
|
|
171
|
+
const temporary = path.join(directory, `.${path.basename(filePath)}.${randomUUID()}.tmp`);
|
|
172
|
+
try {
|
|
173
|
+
await writeFile2(temporary, content, { flag: "wx", mode: 384 });
|
|
174
|
+
await protectOwnerOnlyPath(temporary, "file", options);
|
|
175
|
+
await rename2(temporary, filePath);
|
|
176
|
+
await protectOwnerOnlyPath(filePath, "file", options);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
await rm2(temporary, { force: true }).catch(() => void 0);
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// packages/cli/src/remoteConfig.ts
|
|
184
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
185
|
+
|
|
186
|
+
// packages/shared/src/contracts/models.ts
|
|
187
|
+
var BUILT_IN_OPENROUTER_MODELS = [
|
|
188
|
+
{
|
|
189
|
+
id: "anthropic/claude-sonnet-4-6",
|
|
190
|
+
name: "Assistente de trabalho profundo",
|
|
191
|
+
approvedByDefault: true,
|
|
192
|
+
requiredInConfig: false,
|
|
193
|
+
upstreamModel: "anthropic/claude-sonnet-4.6",
|
|
194
|
+
metadata: {
|
|
195
|
+
family: "anthropic",
|
|
196
|
+
release_date: "2026-02-17",
|
|
197
|
+
attachment: true,
|
|
198
|
+
reasoning: true,
|
|
199
|
+
temperature: true,
|
|
200
|
+
tool_call: true,
|
|
201
|
+
limit: { context: 1e6, output: 128e3 },
|
|
202
|
+
modalities: { input: ["text", "image", "pdf"], output: ["text"] }
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
id: "anthropic/claude-haiku-4-5",
|
|
207
|
+
name: "Assistente r\xE1pido",
|
|
208
|
+
approvedByDefault: true,
|
|
209
|
+
requiredInConfig: false,
|
|
210
|
+
upstreamModel: "anthropic/claude-haiku-4.5",
|
|
211
|
+
metadata: {
|
|
212
|
+
family: "anthropic",
|
|
213
|
+
release_date: "2025-10-15",
|
|
214
|
+
attachment: true,
|
|
215
|
+
reasoning: true,
|
|
216
|
+
temperature: true,
|
|
217
|
+
tool_call: true,
|
|
218
|
+
limit: { context: 2e5, output: 64e3 },
|
|
219
|
+
modalities: { input: ["text", "image", "pdf"], output: ["text"] }
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
id: "openai/gpt-5.4-mini",
|
|
224
|
+
name: "Assistente de ficheiros e ecr\xE3",
|
|
225
|
+
approvedByDefault: true,
|
|
226
|
+
requiredInConfig: false,
|
|
227
|
+
metadata: {
|
|
228
|
+
family: "gpt-mini",
|
|
229
|
+
release_date: "2026-03-17",
|
|
230
|
+
attachment: true,
|
|
231
|
+
reasoning: true,
|
|
232
|
+
temperature: false,
|
|
233
|
+
tool_call: true,
|
|
234
|
+
limit: { context: 4e5, input: 272e3, output: 128e3 },
|
|
235
|
+
modalities: { input: ["text", "image", "pdf"], output: ["text"] },
|
|
236
|
+
variants: openRouterReasoningVariants(["none", "xhigh"])
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
id: "minimax/minimax-m3",
|
|
241
|
+
name: "Assistente de pesquisa",
|
|
242
|
+
approvedByDefault: true,
|
|
243
|
+
requiredInConfig: false,
|
|
244
|
+
metadata: {
|
|
245
|
+
family: "minimax",
|
|
246
|
+
release_date: "2026-04-07",
|
|
247
|
+
attachment: true,
|
|
248
|
+
reasoning: true,
|
|
249
|
+
temperature: true,
|
|
250
|
+
tool_call: true,
|
|
251
|
+
limit: { context: 524288, output: 512e3 },
|
|
252
|
+
modalities: { input: ["text", "image", "video"], output: ["text"] }
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
id: "minimax/minimax-m2.7",
|
|
257
|
+
name: "Assistente de reda\xE7\xE3o",
|
|
258
|
+
approvedByDefault: true,
|
|
259
|
+
requiredInConfig: false,
|
|
260
|
+
metadata: {
|
|
261
|
+
family: "minimax",
|
|
262
|
+
release_date: "2026-03-18",
|
|
263
|
+
attachment: false,
|
|
264
|
+
reasoning: true,
|
|
265
|
+
temperature: true,
|
|
266
|
+
tool_call: true,
|
|
267
|
+
limit: { context: 196608, output: 196608 },
|
|
268
|
+
modalities: { input: ["text"], output: ["text"] }
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
id: "xiaomi/mimo-v2.5",
|
|
273
|
+
name: "Assistente de revis\xE3o multim\xE9dia",
|
|
274
|
+
approvedByDefault: true,
|
|
275
|
+
requiredInConfig: false,
|
|
276
|
+
metadata: {
|
|
277
|
+
family: "mimo",
|
|
278
|
+
release_date: "2026-04-22",
|
|
279
|
+
attachment: true,
|
|
280
|
+
reasoning: true,
|
|
281
|
+
temperature: true,
|
|
282
|
+
tool_call: true,
|
|
283
|
+
interleaved: { field: "reasoning_details" },
|
|
284
|
+
limit: { context: 32e3, output: 131072 },
|
|
285
|
+
modalities: { input: ["text", "audio", "image", "video"], output: ["text"] }
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
id: "xiaomi/mimo-v2.5-pro",
|
|
290
|
+
name: "Assistente de contexto longo",
|
|
291
|
+
approvedByDefault: true,
|
|
292
|
+
requiredInConfig: false,
|
|
293
|
+
metadata: {
|
|
294
|
+
family: "mimo",
|
|
295
|
+
release_date: "2026-04-22",
|
|
296
|
+
attachment: false,
|
|
297
|
+
reasoning: true,
|
|
298
|
+
temperature: true,
|
|
299
|
+
tool_call: true,
|
|
300
|
+
interleaved: { field: "reasoning_content" },
|
|
301
|
+
limit: { context: 1048576, output: 131072 },
|
|
302
|
+
modalities: { input: ["text"], output: ["text"] }
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
id: "z-ai/glm-5.2",
|
|
307
|
+
name: "Assistente de an\xE1lise",
|
|
308
|
+
approvedByDefault: false,
|
|
309
|
+
requiredInConfig: false,
|
|
310
|
+
metadata: {
|
|
311
|
+
family: "glm",
|
|
312
|
+
release_date: "2026-02-12",
|
|
313
|
+
attachment: false,
|
|
314
|
+
reasoning: true,
|
|
315
|
+
temperature: true,
|
|
316
|
+
tool_call: true,
|
|
317
|
+
interleaved: { field: "reasoning_content" },
|
|
318
|
+
limit: { context: 1048576, output: 32768 },
|
|
319
|
+
modalities: { input: ["text"], output: ["text"] }
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
];
|
|
323
|
+
var APPROVED_MODELS = BUILT_IN_OPENROUTER_MODELS.filter((model) => model.approvedByDefault).map(stripCatalogFlags);
|
|
324
|
+
function knownOpenRouterModelMetadata(model) {
|
|
325
|
+
const normalized = normalizeModelId(model).toLowerCase();
|
|
326
|
+
if (isLegacyDirectZaiModelId(normalized)) return void 0;
|
|
327
|
+
const builtIn = BUILT_IN_OPENROUTER_MODELS.find((candidate) => candidate.id.toLowerCase() === normalized);
|
|
328
|
+
if (builtIn?.metadata) return structuredClone(builtIn.metadata);
|
|
329
|
+
if (isLikelyReasoningModel(normalized)) {
|
|
330
|
+
return {
|
|
331
|
+
family: inferFamily(normalized),
|
|
332
|
+
attachment: false,
|
|
333
|
+
reasoning: true,
|
|
334
|
+
temperature: true,
|
|
335
|
+
tool_call: true,
|
|
336
|
+
modalities: { input: ["text"], output: ["text"] }
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
return void 0;
|
|
340
|
+
}
|
|
341
|
+
function knownModelMetadata(model) {
|
|
342
|
+
return knownOpenRouterModelMetadata(model);
|
|
343
|
+
}
|
|
344
|
+
function normalizeModelId(model) {
|
|
345
|
+
const trimmed = model.trim();
|
|
346
|
+
return trimmed.startsWith("forge/") ? trimmed.slice("forge/".length) : trimmed;
|
|
347
|
+
}
|
|
348
|
+
function isLegacyDirectZaiModelId(model) {
|
|
349
|
+
return /^zai-coding\/glm-[a-z0-9.-]+$/.test(normalizeModelId(model));
|
|
350
|
+
}
|
|
351
|
+
function cloneModel(model) {
|
|
352
|
+
return {
|
|
353
|
+
id: model.id,
|
|
354
|
+
name: model.name,
|
|
355
|
+
...model.provider ? { provider: model.provider } : {},
|
|
356
|
+
...model.upstreamModel ? { upstreamModel: model.upstreamModel } : {},
|
|
357
|
+
...model.billingMode ? { billingMode: model.billingMode } : {},
|
|
358
|
+
...model.metadata ? { metadata: structuredClone(model.metadata) } : {}
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
function stripCatalogFlags(model) {
|
|
362
|
+
const { approvedByDefault: _approvedByDefault, requiredInConfig: _requiredInConfig, ...approved } = model;
|
|
363
|
+
return cloneModel(approved);
|
|
364
|
+
}
|
|
365
|
+
function isLikelyReasoningModel(model) {
|
|
366
|
+
return model.includes("gpt-5") || /(^|\/)o[134](?:-|$)/.test(model) || model.includes("deepseek-r1") || model.includes("deepseek-reasoner") || model.includes("claude-sonnet-4") || model.includes("claude-opus-4") || model.includes("gemini-2.5") || model.includes("gemini-3");
|
|
367
|
+
}
|
|
368
|
+
function inferFamily(model) {
|
|
369
|
+
if (model.includes("openai/") || model.includes("gpt-") || /(^|\/)o[134](?:-|$)/.test(model)) return "openai";
|
|
370
|
+
if (model.includes("anthropic/") || model.includes("claude")) return "anthropic";
|
|
371
|
+
if (model.includes("google/") || model.includes("gemini")) return "google";
|
|
372
|
+
if (model.includes("deepseek")) return "deepseek";
|
|
373
|
+
return void 0;
|
|
374
|
+
}
|
|
375
|
+
function openRouterReasoningVariants(efforts) {
|
|
376
|
+
return Object.fromEntries(efforts.map((effort) => [effort, { reasoning: { effort } }]));
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// packages/shared/src/contracts/debugTrace.ts
|
|
380
|
+
var DEFAULT_DEBUG_TRACE_LIMITS = {
|
|
381
|
+
eventEnvelopeBytes: 256 * 1024,
|
|
382
|
+
artifactChunkBytes: 2 * 1024 * 1024,
|
|
383
|
+
// Serialized request bodies must remain comfortably below Vercel's 4.5 MB
|
|
384
|
+
// function request limit after JSON and base64 overhead.
|
|
385
|
+
uploadBatchBytes: 3 * 1024 * 1024,
|
|
386
|
+
uploadBatchRecords: 100,
|
|
387
|
+
fileSnapshotBytes: 1024 * 1024,
|
|
388
|
+
serverTraceBudgetBytes: 250 * 1024 * 1024,
|
|
389
|
+
workerTraceQuotaPer24h: 100,
|
|
390
|
+
workerBytesQuotaPer24h: 1024 * 1024 * 1024,
|
|
391
|
+
localQueueBytes: 1024 * 1024 * 1024,
|
|
392
|
+
retryBackoffMinMs: 5e3,
|
|
393
|
+
retryBackoffMaxMs: 5 * 60 * 1e3,
|
|
394
|
+
queueMaxAgeDays: 7,
|
|
395
|
+
rawTempExposureSeconds: 15 * 60
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
// packages/shared/src/contracts/deviceEnrollment.ts
|
|
399
|
+
var DEVICE_ENROLLMENT_PROTOCOL_VERSION = 1;
|
|
400
|
+
|
|
401
|
+
// packages/shared/src/contracts/settings.ts
|
|
402
|
+
var DOCUMENT_READER_AGENT = "document-reader";
|
|
403
|
+
var OPENROUTER_ALIAS_PROVIDER_NAME = "OpenRouter (via Forge)";
|
|
404
|
+
var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.35";
|
|
405
|
+
var WORK_PACK_SYNC_PLUGIN_PACKAGE = `minimal-forge-work-pack-sync@${WORK_PACK_SYNC_PLUGIN_VERSION}`;
|
|
406
|
+
var WORK_PACK_SYNC_PLUGIN_FILENAME = `minimal-forge-work-pack-sync-${WORK_PACK_SYNC_PLUGIN_VERSION}.tgz`;
|
|
407
|
+
var FIRECRAWL_KEYLESS_MCP_NAME = "firecrawl";
|
|
408
|
+
var FIRECRAWL_KEYLESS_MCP_URL = "https://mcp.firecrawl.dev/v2/mcp";
|
|
409
|
+
var FIRECRAWL_KEYLESS_PERMISSION = `${FIRECRAWL_KEYLESS_MCP_NAME}_*`;
|
|
410
|
+
function mergeWorkerOpenCodeConfig(existing, manifest, forgeBaseUrl, forgeApiKey = "{env:FORGE_API_KEY}", options = {}) {
|
|
411
|
+
const existingProvider = withoutLegacyForgeProviders(isRecord(existing.provider) ? existing.provider : {});
|
|
412
|
+
const nextConfig = {
|
|
413
|
+
...existing
|
|
414
|
+
};
|
|
415
|
+
const permission = managedPermission(nextConfig.permission);
|
|
416
|
+
delete nextConfig.permission;
|
|
417
|
+
const mcp = isRecord(nextConfig.mcp) ? { ...nextConfig.mcp } : {};
|
|
418
|
+
if (!(FIRECRAWL_KEYLESS_MCP_NAME in mcp)) {
|
|
419
|
+
mcp[FIRECRAWL_KEYLESS_MCP_NAME] = {
|
|
420
|
+
type: "remote",
|
|
421
|
+
url: FIRECRAWL_KEYLESS_MCP_URL,
|
|
422
|
+
enabled: true,
|
|
423
|
+
oauth: false,
|
|
424
|
+
timeout: 3e4
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
delete nextConfig.mcp;
|
|
428
|
+
const experimental = isRecord(nextConfig.experimental) ? { ...nextConfig.experimental } : {};
|
|
429
|
+
delete nextConfig.experimental;
|
|
430
|
+
if (!Array.isArray(nextConfig.instructions)) delete nextConfig.instructions;
|
|
431
|
+
const forgeProvider = {
|
|
432
|
+
npm: "@ai-sdk/openai-compatible",
|
|
433
|
+
name: "Forge",
|
|
434
|
+
options: {
|
|
435
|
+
baseURL: `${manifest.gatewayBaseUrl ? normalizeGatewayBaseUrl(manifest.gatewayBaseUrl) : forgeBaseUrl.replace(/\/$/, "")}/v1`,
|
|
436
|
+
apiKey: forgeApiKey
|
|
437
|
+
},
|
|
438
|
+
models: Object.fromEntries(
|
|
439
|
+
manifest.config.models.map((model) => {
|
|
440
|
+
const entry = normalizeManifestModel(model);
|
|
441
|
+
return [entry.id, modelConfig(entry)];
|
|
442
|
+
})
|
|
443
|
+
)
|
|
444
|
+
};
|
|
445
|
+
const agents = isRecord(nextConfig.agent) ? { ...nextConfig.agent } : {};
|
|
446
|
+
if (manifest.config.documentReaderModel) {
|
|
447
|
+
agents[DOCUMENT_READER_AGENT] = documentReaderAgent(manifest.config.documentReaderModel);
|
|
448
|
+
} else {
|
|
449
|
+
delete agents[DOCUMENT_READER_AGENT];
|
|
450
|
+
}
|
|
451
|
+
delete nextConfig.agent;
|
|
452
|
+
const plugins = (Array.isArray(nextConfig.plugin) ? nextConfig.plugin : []).filter((entry) => {
|
|
453
|
+
if (options.removePluginPath && typeof entry === "string" && entry === options.removePluginPath) return false;
|
|
454
|
+
const name = Array.isArray(entry) ? entry[0] : entry;
|
|
455
|
+
return typeof name !== "string" || !/^minimal-forge-work-pack-sync@/.test(name);
|
|
456
|
+
});
|
|
457
|
+
if (options.automaticWorkPackSync) {
|
|
458
|
+
plugins.push([
|
|
459
|
+
WORK_PACK_SYNC_PLUGIN_PACKAGE,
|
|
460
|
+
{ forgeBaseUrl: forgeBaseUrl.replace(/\/$/, ""), ...options.localConfig ? { localConfig: true } : {} }
|
|
461
|
+
]);
|
|
462
|
+
}
|
|
463
|
+
delete nextConfig.plugin;
|
|
464
|
+
return {
|
|
465
|
+
...nextConfig,
|
|
466
|
+
$schema: "https://opencode.ai/config.json",
|
|
467
|
+
share: "disabled",
|
|
468
|
+
autoupdate: false,
|
|
469
|
+
permission,
|
|
470
|
+
mcp,
|
|
471
|
+
experimental: {
|
|
472
|
+
...experimental,
|
|
473
|
+
clickableFileReferences: true
|
|
474
|
+
},
|
|
475
|
+
model: `forge/${manifest.config.model}`,
|
|
476
|
+
small_model: `forge/${manifest.config.small_model}`,
|
|
477
|
+
provider: options.omitManagedProviders ? { ...existingProvider } : {
|
|
478
|
+
...existingProvider,
|
|
479
|
+
forge: forgeProvider
|
|
480
|
+
},
|
|
481
|
+
...Object.keys(agents).length > 0 ? { agent: agents } : {},
|
|
482
|
+
...plugins.length > 0 ? { plugin: plugins } : {}
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
function managedPermission(value) {
|
|
486
|
+
const existing = typeof value === "string" && ["allow", "ask", "deny"].includes(value) ? { "*": value } : isRecord(value) ? value : {};
|
|
487
|
+
return {
|
|
488
|
+
...existing["*"] === "deny" ? {} : { [FIRECRAWL_KEYLESS_PERMISSION]: "ask" },
|
|
489
|
+
...existing,
|
|
490
|
+
forge_decide: "allow",
|
|
491
|
+
forge_decide_run: "allow",
|
|
492
|
+
forge_generate_codebook: "allow",
|
|
493
|
+
forge_feedback: "deny"
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
function withoutLegacyForgeProviders(provider) {
|
|
497
|
+
const next = { ...provider };
|
|
498
|
+
delete next.forge;
|
|
499
|
+
const openrouter = next.openrouter;
|
|
500
|
+
if (isRecord(openrouter) && openrouter.name === OPENROUTER_ALIAS_PROVIDER_NAME) delete next.openrouter;
|
|
501
|
+
return next;
|
|
502
|
+
}
|
|
503
|
+
function documentReaderAgent(documentReaderModel) {
|
|
504
|
+
return {
|
|
505
|
+
description: "L\xEA ficheiros de imagem (png, jpg, gif, webp) e PDFs, e descreve o que cont\xEAm. Use este agente sempre que for preciso ver uma imagem ou um PDF: d\xEA-lhe o caminho absoluto do ficheiro e pergunte o que precisa de saber.",
|
|
506
|
+
mode: "subagent",
|
|
507
|
+
model: `forge/${documentReaderModel}`,
|
|
508
|
+
tools: { write: false, edit: false, bash: false }
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
function isRecord(value) {
|
|
512
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
513
|
+
}
|
|
514
|
+
function normalizeManifestModel(model) {
|
|
515
|
+
return typeof model === "string" ? { id: model, name: model } : model;
|
|
516
|
+
}
|
|
517
|
+
function modelConfig(model) {
|
|
518
|
+
const metadata = model.metadata ?? knownModelMetadata(model.id) ?? {};
|
|
519
|
+
const { limit, ...compatibleMetadata } = metadata;
|
|
520
|
+
return {
|
|
521
|
+
name: model.name,
|
|
522
|
+
...compatibleMetadata,
|
|
523
|
+
...limit && Number.isFinite(limit.context) && Number.isFinite(limit.output) ? { limit } : {}
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
function normalizeGatewayBaseUrl(value) {
|
|
527
|
+
const url = new URL(value);
|
|
528
|
+
if (url.protocol !== "https:" || url.username || url.password || url.port || url.pathname !== "/" || url.search || url.hash) {
|
|
529
|
+
throw new Error("Gateway URL must be an HTTPS origin without credentials, path, port, query or fragment");
|
|
530
|
+
}
|
|
531
|
+
return url.origin;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// packages/cli/src/remoteConfig.ts
|
|
535
|
+
var WELLKNOWN_ENV_KEY = "FORGE_API_KEY";
|
|
536
|
+
async function removeWellKnownAuth(paths, credentials, previous) {
|
|
537
|
+
const content = await prepareWellKnownAuthRemoval(paths, credentials, previous);
|
|
538
|
+
if (content !== void 0) await writeOwnerOnlyTextAtomic(paths.opencodeAuthPath, content);
|
|
539
|
+
}
|
|
540
|
+
async function prepareWellKnownAuthRemoval(paths, credentials, previous) {
|
|
541
|
+
const auth = await readAuthJson(paths);
|
|
542
|
+
const owned = previous ? [credentials, previous] : [credentials];
|
|
543
|
+
const ownedKeys = new Set(owned.map((entry) => entry.forgeApiKey));
|
|
544
|
+
let changed = false;
|
|
545
|
+
for (const url of owned.flatMap((entry) => [entry.forgeBaseUrl, ...entry.forgeOwnedWellKnownUrls ?? []])) {
|
|
546
|
+
const key = normalizeBaseUrl(url);
|
|
547
|
+
const entry = auth[key];
|
|
548
|
+
if (!isRecord2(entry) || entry.type !== "wellknown" || entry.key !== WELLKNOWN_ENV_KEY || typeof entry.token !== "string" || !entry.token.startsWith("forge_")) continue;
|
|
549
|
+
if (!ownedKeys.has(entry.token)) {
|
|
550
|
+
throw new Error("A autoriza\xE7\xE3o Forge foi alterada; preserve os ficheiros e pe\xE7a uma repara\xE7\xE3o acompanhada.");
|
|
551
|
+
}
|
|
552
|
+
delete auth[key];
|
|
553
|
+
changed = true;
|
|
554
|
+
}
|
|
555
|
+
return changed ? `${JSON.stringify(auth, null, 2)}
|
|
556
|
+
` : void 0;
|
|
557
|
+
}
|
|
558
|
+
function normalizeBaseUrl(value) {
|
|
559
|
+
return value.replace(/\/+$/, "");
|
|
560
|
+
}
|
|
561
|
+
async function readAuthJson(paths) {
|
|
562
|
+
let raw;
|
|
563
|
+
try {
|
|
564
|
+
raw = await readFile2(paths.opencodeAuthPath, "utf8");
|
|
565
|
+
} catch (error) {
|
|
566
|
+
if (error.code === "ENOENT") return {};
|
|
567
|
+
throw error;
|
|
568
|
+
}
|
|
569
|
+
const parsed = JSON.parse(raw.startsWith("\uFEFF") ? raw.slice(1) : raw);
|
|
570
|
+
if (!isRecord2(parsed)) throw new Error("A autentica\xE7\xE3o do OpenCode n\xE3o \xE9 um objeto JSON v\xE1lido");
|
|
571
|
+
return parsed;
|
|
572
|
+
}
|
|
573
|
+
function isRecord2(value) {
|
|
574
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// packages/cli/src/coreSyncTransaction.ts
|
|
578
|
+
import { createHash, randomUUID as randomUUID2 } from "node:crypto";
|
|
579
|
+
import { chmod as chmod3, lstat, mkdir as mkdir3, readFile as readFile3, rename as rename3, rm as rm3, writeFile as writeFile3 } from "node:fs/promises";
|
|
580
|
+
import path2 from "node:path";
|
|
581
|
+
var CORE_RUNTIME_MANIFEST_VERSION = 1;
|
|
582
|
+
var CoreSyncUncertainError = class extends Error {
|
|
583
|
+
constructor(message, paths) {
|
|
584
|
+
super(message);
|
|
585
|
+
this.paths = paths;
|
|
586
|
+
}
|
|
587
|
+
paths;
|
|
588
|
+
};
|
|
589
|
+
var defaultFs = { chmod: chmod3, lstat, mkdir: mkdir3, readFile: readFile3, rename: rename3, rm: rm3, writeFile: writeFile3 };
|
|
590
|
+
function coreRuntimeManifestDigest(files) {
|
|
591
|
+
const canonical = [...files].sort((a, b2) => a.id.localeCompare(b2.id)).map((file) => ({
|
|
592
|
+
id: file.id,
|
|
593
|
+
path: path2.resolve(file.path),
|
|
594
|
+
exists: file.bytes !== null,
|
|
595
|
+
digest: file.bytes === null ? void 0 : sha256(file.bytes),
|
|
596
|
+
mode: file.mode,
|
|
597
|
+
ownerOnly: file.ownerOnly === true
|
|
598
|
+
}));
|
|
599
|
+
return sha256(Buffer.from(JSON.stringify(canonical)));
|
|
600
|
+
}
|
|
601
|
+
function validateCoreRuntimeManifest(manifest) {
|
|
602
|
+
if (manifest.version !== CORE_RUNTIME_MANIFEST_VERSION) throw new Error(`Unsupported core runtime manifest version: ${String(manifest.version)}`);
|
|
603
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/.test(manifest.id)) throw new Error("Invalid core runtime manifest id");
|
|
604
|
+
if (!/^[a-f0-9]{64}$/.test(manifest.digest)) throw new Error("Invalid core runtime manifest digest");
|
|
605
|
+
if (manifest.files.length === 0) throw new Error("Core runtime manifest must contain files");
|
|
606
|
+
const ids = /* @__PURE__ */ new Set();
|
|
607
|
+
const targets = /* @__PURE__ */ new Set();
|
|
608
|
+
for (const file of manifest.files) {
|
|
609
|
+
if (!file.id || ids.has(file.id)) throw new Error(`Duplicate core runtime file id: ${file.id}`);
|
|
610
|
+
const target = path2.resolve(file.path);
|
|
611
|
+
if (!path2.isAbsolute(file.path) || targets.has(target)) throw new Error(`Invalid or duplicate core runtime target: ${file.path}`);
|
|
612
|
+
if (file.mode !== void 0 && (!Number.isInteger(file.mode) || file.mode < 0 || file.mode > 4095)) throw new Error(`Invalid mode for ${file.id}`);
|
|
613
|
+
if (file.ownerOnly !== void 0 && typeof file.ownerOnly !== "boolean") throw new Error(`Invalid owner-only flag for ${file.id}`);
|
|
614
|
+
ids.add(file.id);
|
|
615
|
+
targets.add(target);
|
|
616
|
+
}
|
|
617
|
+
if (coreRuntimeManifestDigest(manifest.files) !== manifest.digest) throw new Error("Core runtime manifest digest mismatch");
|
|
618
|
+
}
|
|
619
|
+
async function applyCoreSyncTransaction(options) {
|
|
620
|
+
validateCoreRuntimeManifest(options.manifest);
|
|
621
|
+
const fs2 = options.fs ?? defaultFs;
|
|
622
|
+
const hooks = options.hooks;
|
|
623
|
+
const existingRecovery = await recoverCoreSyncTransaction({ journalPath: options.journalPath, fs: fs2 });
|
|
624
|
+
if (existingRecovery.status === "uncertain") throw new CoreSyncUncertainError(existingRecovery.message, existingRecovery.uncertainPaths);
|
|
625
|
+
const transactionId = randomUUID2();
|
|
626
|
+
const files = [];
|
|
627
|
+
try {
|
|
628
|
+
for (const desired of options.manifest.files) {
|
|
629
|
+
const target = path2.resolve(desired.path);
|
|
630
|
+
if (desired.ownerOnly && desired.bytes !== null && fs2 === defaultFs) await prepareOwnerOnlyFileDestination(target);
|
|
631
|
+
else await fs2.mkdir(path2.dirname(target), { recursive: true });
|
|
632
|
+
const original = await capture(target, fs2);
|
|
633
|
+
const suffix = `.forge-core-${transactionId}`;
|
|
634
|
+
const backup = original.exists ? `${target}${suffix}.backup` : void 0;
|
|
635
|
+
const stage = desired.bytes === null ? void 0 : `${target}${suffix}.stage`;
|
|
636
|
+
if (backup && original.bytes) await writeExact(backup, original.bytes, original.mode, fs2, desired.ownerOnly === true);
|
|
637
|
+
if (stage && desired.bytes) await writeExact(stage, desired.bytes, desired.mode ?? original.mode ?? 384, fs2, desired.ownerOnly === true);
|
|
638
|
+
files.push({
|
|
639
|
+
id: desired.id,
|
|
640
|
+
target,
|
|
641
|
+
...stage ? { stage } : {},
|
|
642
|
+
...backup ? { backup } : {},
|
|
643
|
+
original: { exists: original.exists, ...original.mode === void 0 ? {} : { mode: original.mode }, ...original.bytes ? { digest: sha256(original.bytes) } : {} },
|
|
644
|
+
desired: { exists: desired.bytes !== null, ...desired.bytes === null ? {} : { digest: sha256(desired.bytes), mode: desired.mode ?? original.mode ?? 384 } },
|
|
645
|
+
...desired.ownerOnly ? { ownerOnly: true } : {}
|
|
646
|
+
});
|
|
647
|
+
await hooks?.boundary?.(`after-prepare:${desired.id}`);
|
|
648
|
+
}
|
|
649
|
+
const journal = {
|
|
650
|
+
schemaVersion: 1,
|
|
651
|
+
transactionId,
|
|
652
|
+
manifest: { version: 1, id: options.manifest.id, digest: options.manifest.digest },
|
|
653
|
+
files
|
|
654
|
+
};
|
|
655
|
+
await hooks?.boundary?.("before-journal");
|
|
656
|
+
await writeJournal(options.journalPath, journal, fs2);
|
|
657
|
+
await hooks?.boundary?.("after-journal");
|
|
658
|
+
for (const file of files) {
|
|
659
|
+
await hooks?.boundary?.(`before-commit:${file.id}`);
|
|
660
|
+
await fs2.rm(file.target, { force: true });
|
|
661
|
+
if (file.stage) await fs2.rename(file.stage, file.target);
|
|
662
|
+
if (file.stage && file.ownerOnly && fs2 === defaultFs) await protectOwnerOnlyPath(file.target, "file");
|
|
663
|
+
await hooks?.boundary?.(`after-commit:${file.id}`);
|
|
664
|
+
}
|
|
665
|
+
await hooks?.boundary?.("before-cleanup");
|
|
666
|
+
await cleanup(journal, options.journalPath, fs2);
|
|
667
|
+
await hooks?.boundary?.("after-cleanup");
|
|
668
|
+
return { status: "committed", manifestId: options.manifest.id, digest: options.manifest.digest };
|
|
669
|
+
} catch (error) {
|
|
670
|
+
if (!await exists(options.journalPath, fs2)) {
|
|
671
|
+
await Promise.all(files.flatMap((file) => [file.stage, file.backup].filter((item) => Boolean(item))).map((item) => fs2.rm(item, { force: true }).catch(() => void 0)));
|
|
672
|
+
throw error;
|
|
673
|
+
}
|
|
674
|
+
const recovery = await recoverCoreSyncTransaction({ journalPath: options.journalPath, fs: fs2 });
|
|
675
|
+
if (recovery.status === "uncertain") throw new CoreSyncUncertainError(recovery.message, recovery.uncertainPaths);
|
|
676
|
+
throw error;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
async function recoverCoreSyncTransaction(options) {
|
|
680
|
+
const fs2 = options.fs ?? defaultFs;
|
|
681
|
+
let journal;
|
|
682
|
+
try {
|
|
683
|
+
journal = JSON.parse(await fs2.readFile(options.journalPath, "utf8"));
|
|
684
|
+
} catch (error) {
|
|
685
|
+
if (isNotFound(error)) return { status: "nothing-to-recover" };
|
|
686
|
+
return { status: "uncertain", uncertainPaths: [options.journalPath], message: "Core sync journal is unreadable; exact recovery is uncertain." };
|
|
687
|
+
}
|
|
688
|
+
if (!validJournal(journal)) return { status: "uncertain", uncertainPaths: [options.journalPath], message: "Core sync journal is invalid; exact recovery is uncertain." };
|
|
689
|
+
const uncertain = [];
|
|
690
|
+
for (const file of journal.files) {
|
|
691
|
+
try {
|
|
692
|
+
if (!file.original.exists) await fs2.rm(file.target, { force: true });
|
|
693
|
+
else {
|
|
694
|
+
if (!file.backup || !await exists(file.backup, fs2)) throw new Error("backup missing");
|
|
695
|
+
const bytes = await fs2.readFile(file.backup);
|
|
696
|
+
if (sha256(bytes) !== file.original.digest) throw new Error("backup digest mismatch");
|
|
697
|
+
await writeExact(`${file.target}.forge-restore-${journal.transactionId}`, bytes, file.original.mode, fs2, file.ownerOnly === true);
|
|
698
|
+
await fs2.rm(file.target, { force: true });
|
|
699
|
+
await fs2.rename(`${file.target}.forge-restore-${journal.transactionId}`, file.target);
|
|
700
|
+
if (file.ownerOnly && fs2 === defaultFs) await protectOwnerOnlyPath(file.target, "file");
|
|
701
|
+
const restored = await capture(file.target, fs2);
|
|
702
|
+
if (!restored.bytes || sha256(restored.bytes) !== file.original.digest || restored.mode !== file.original.mode) throw new Error("restore verification failed");
|
|
703
|
+
}
|
|
704
|
+
} catch {
|
|
705
|
+
uncertain.push(file.target);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
if (uncertain.length > 0) return { status: "uncertain", manifestId: journal.manifest.id, uncertainPaths: uncertain, message: "Core sync could not prove an exact restore for every path." };
|
|
709
|
+
await cleanup(journal, options.journalPath, fs2);
|
|
710
|
+
return { status: "restored", manifestId: journal.manifest.id };
|
|
711
|
+
}
|
|
712
|
+
async function capture(target, fs2) {
|
|
713
|
+
try {
|
|
714
|
+
const info = await fs2.lstat(target);
|
|
715
|
+
if (!info.isFile()) throw new Error(`Core runtime target is not a regular file: ${target}`);
|
|
716
|
+
return { exists: true, bytes: await fs2.readFile(target), mode: info.mode & 4095 };
|
|
717
|
+
} catch (error) {
|
|
718
|
+
if (isNotFound(error)) return { exists: false };
|
|
719
|
+
throw error;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
async function writeExact(target, bytes, mode, fs2, ownerOnly = false) {
|
|
723
|
+
await fs2.writeFile(target, bytes, { flag: "wx", mode });
|
|
724
|
+
await fs2.chmod(target, mode);
|
|
725
|
+
if (ownerOnly && fs2 === defaultFs) await protectOwnerOnlyPath(target, "file");
|
|
726
|
+
}
|
|
727
|
+
async function writeJournal(target, journal, fs2) {
|
|
728
|
+
await fs2.mkdir(path2.dirname(target), { recursive: true });
|
|
729
|
+
const temporary = `${target}.next`;
|
|
730
|
+
await fs2.rm(temporary, { force: true });
|
|
731
|
+
await fs2.writeFile(temporary, `${JSON.stringify(journal, null, 2)}
|
|
732
|
+
`, { flag: "wx", mode: 384 });
|
|
733
|
+
await fs2.chmod(temporary, 384);
|
|
734
|
+
await fs2.rename(temporary, target);
|
|
735
|
+
}
|
|
736
|
+
async function cleanup(journal, journalPath, fs2) {
|
|
737
|
+
await Promise.all(journal.files.flatMap((file) => [file.stage, file.backup].filter((item) => Boolean(item))).map((item) => fs2.rm(item, { force: true })));
|
|
738
|
+
await fs2.rm(journalPath, { force: true });
|
|
739
|
+
}
|
|
740
|
+
async function exists(target, fs2) {
|
|
741
|
+
try {
|
|
742
|
+
await fs2.lstat(target);
|
|
743
|
+
return true;
|
|
744
|
+
} catch (error) {
|
|
745
|
+
if (isNotFound(error)) return false;
|
|
746
|
+
throw error;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
function isNotFound(error) {
|
|
750
|
+
return Boolean(error && typeof error === "object" && "code" in error && error.code === "ENOENT");
|
|
751
|
+
}
|
|
752
|
+
function sha256(value) {
|
|
753
|
+
return createHash("sha256").update(value).digest("hex");
|
|
754
|
+
}
|
|
755
|
+
function validJournal(value) {
|
|
756
|
+
return value?.schemaVersion === 1 && typeof value.transactionId === "string" && value.manifest?.version === 1 && typeof value.manifest.id === "string" && Array.isArray(value.files) && value.files.every((file) => typeof file.id === "string" && path2.isAbsolute(file.target) && typeof file.original?.exists === "boolean" && typeof file.desired?.exists === "boolean" && (file.ownerOnly === void 0 || typeof file.ownerOnly === "boolean"));
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// packages/cli/src/localConfigRecovery.ts
|
|
760
|
+
var LocalConfigRecoveryError = class extends Error {
|
|
761
|
+
};
|
|
762
|
+
var LAST_GOOD_FILENAME = "last-good-opencode.json";
|
|
763
|
+
function lastGoodLocalConfigFile(paths, credentials, content) {
|
|
764
|
+
assertForgeConfig(content, credentials);
|
|
765
|
+
return { id: "last-good-config", path: path3.join(paths.forgeDir, LAST_GOOD_FILENAME), bytes: Buffer.from(content), mode: 384, ownerOnly: true };
|
|
766
|
+
}
|
|
767
|
+
async function inspectLocalConfigRecovery(paths, credentials) {
|
|
768
|
+
const snapshot = await readOptional(path3.join(paths.forgeDir, LAST_GOOD_FILENAME));
|
|
769
|
+
const current = await readOptional(paths.opencodeConfigPath);
|
|
770
|
+
return {
|
|
771
|
+
snapshot: snapshot === void 0 ? "missing" : isForgeConfig(snapshot, credentials) ? "available" : "invalid",
|
|
772
|
+
current: current === void 0 ? "missing" : isForgeConfig(current, credentials) && (snapshot === void 0 || !isForgeConfig(snapshot, credentials) || sameSavedForgeFields(current, snapshot)) ? "valid" : "invalid"
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
async function repairLocalConfig(paths, credentials) {
|
|
776
|
+
const recovery = await recoverCoreSyncTransaction({ journalPath: path3.join(paths.forgeDir, "core-sync-journal.json") });
|
|
777
|
+
if (recovery.status === "uncertain") throw new CoreSyncUncertainError(recovery.message, recovery.uncertainPaths);
|
|
778
|
+
const snapshot = await readOptional(path3.join(paths.forgeDir, LAST_GOOD_FILENAME));
|
|
779
|
+
if (snapshot === void 0) throw new LocalConfigRecoveryError("N\xE3o existe uma configura\xE7\xE3o local v\xE1lida guardada. Execute sync quando o Forge estiver dispon\xEDvel.");
|
|
780
|
+
assertForgeConfig(snapshot, credentials);
|
|
781
|
+
const current = await readOptional(paths.opencodeConfigPath);
|
|
782
|
+
if (current !== void 0) {
|
|
783
|
+
try {
|
|
784
|
+
assertForgeVisible(parseJsonc(current));
|
|
785
|
+
} catch (error) {
|
|
786
|
+
if (error instanceof LocalConfigRecoveryError) throw error;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
if (current !== void 0 && isForgeConfig(current, credentials) && sameSavedForgeFields(current, snapshot)) {
|
|
790
|
+
await removeWellKnownAuth(paths, credentials);
|
|
791
|
+
return { status: "already-valid" };
|
|
792
|
+
}
|
|
793
|
+
const replacement = current === void 0 ? snapshot : repairContent(current, snapshot);
|
|
794
|
+
const previousConfigPath = current === void 0 ? void 0 : path3.join(paths.forgeDir, `opencode-before-repair-${randomUUID3()}.jsonc`);
|
|
795
|
+
if (previousConfigPath && current !== void 0) await writeOwnerOnlyTextAtomic(previousConfigPath, current);
|
|
796
|
+
await writeOwnerOnlyTextAtomic(paths.opencodeConfigPath, replacement);
|
|
797
|
+
try {
|
|
798
|
+
assertForgeConfig(await readFile4(paths.opencodeConfigPath, "utf8"), credentials);
|
|
799
|
+
} catch (error) {
|
|
800
|
+
if (current !== void 0) await writeOwnerOnlyTextAtomic(paths.opencodeConfigPath, current);
|
|
801
|
+
throw error;
|
|
802
|
+
}
|
|
803
|
+
await removeWellKnownAuth(paths, credentials);
|
|
804
|
+
return { status: "restored", ...previousConfigPath ? { previousConfigPath } : {} };
|
|
805
|
+
}
|
|
806
|
+
function assertForgeConfig(content, credentials) {
|
|
807
|
+
if (!isForgeConfig(content, credentials)) {
|
|
808
|
+
throw new LocalConfigRecoveryError("A c\xF3pia local n\xE3o corresponde \xE0s credenciais Forge atuais; a configura\xE7\xE3o n\xE3o foi alterada.");
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
function isForgeConfig(content, credentials) {
|
|
812
|
+
try {
|
|
813
|
+
const config = parseJsonc(content);
|
|
814
|
+
if (!isRecord3(config) || !isRecord3(config.provider) || !isRecord3(config.provider.forge)) return false;
|
|
815
|
+
assertForgeVisible(config);
|
|
816
|
+
const forge = config.provider.forge;
|
|
817
|
+
if (!isRecord3(forge.options) || forge.options.apiKey !== credentials.forgeApiKey || typeof forge.options.baseURL !== "string" || !forge.options.baseURL.endsWith("/v1") || !isRecord3(forge.models) || Object.keys(forge.models).length === 0) return false;
|
|
818
|
+
if (typeof config.model !== "string" || !config.model.startsWith("forge/") || typeof config.small_model !== "string" || !config.small_model.startsWith("forge/")) return false;
|
|
819
|
+
const plugins = forgePluginEntries(config);
|
|
820
|
+
return plugins.length === 1 && plugins.every(
|
|
821
|
+
(entry) => Array.isArray(entry) && typeof entry[0] === "string" && /^minimal-forge-work-pack-sync@/.test(entry[0]) && isRecord3(entry[1]) && entry[1].forgeBaseUrl === credentials.forgeBaseUrl.replace(/\/+$/, "") && entry[1].localConfig === true
|
|
822
|
+
);
|
|
823
|
+
} catch {
|
|
824
|
+
return false;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
function repairContent(current, snapshot) {
|
|
828
|
+
let parsed;
|
|
829
|
+
try {
|
|
830
|
+
parsed = JSON.parse(current);
|
|
831
|
+
} catch {
|
|
832
|
+
try {
|
|
833
|
+
parseJsonc(current);
|
|
834
|
+
throw new LocalConfigRecoveryError("A configura\xE7\xE3o atual cont\xE9m JSONC ou coment\xE1rios; preserve-a e fa\xE7a a repara\xE7\xE3o acompanhada para n\xE3o perder altera\xE7\xF5es externas.");
|
|
835
|
+
} catch (error) {
|
|
836
|
+
if (error instanceof SyntaxError) return snapshot;
|
|
837
|
+
throw error;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
if (!isRecord3(parsed)) throw new LocalConfigRecoveryError("A configura\xE7\xE3o atual n\xE3o \xE9 um objeto; fa\xE7a a repara\xE7\xE3o acompanhada.");
|
|
841
|
+
const saved = JSON.parse(snapshot);
|
|
842
|
+
const currentProvider = isRecord3(parsed.provider) ? parsed.provider : {};
|
|
843
|
+
const savedProvider = saved.provider;
|
|
844
|
+
if (isRecord3(currentProvider.forge) && JSON.stringify(currentProvider.forge) !== JSON.stringify(savedProvider.forge)) {
|
|
845
|
+
throw new LocalConfigRecoveryError("O provider Forge foi alterado fora da sincroniza\xE7\xE3o; fa\xE7a a repara\xE7\xE3o acompanhada.");
|
|
846
|
+
}
|
|
847
|
+
if (typeof parsed.model === "string" && !parsed.model.startsWith("forge/")) {
|
|
848
|
+
throw new LocalConfigRecoveryError("Outro provider est\xE1 selecionado; fa\xE7a a repara\xE7\xE3o acompanhada para preservar essa escolha.");
|
|
849
|
+
}
|
|
850
|
+
const existingPlugins = Array.isArray(parsed.plugin) ? parsed.plugin : [];
|
|
851
|
+
const savedPlugins = Array.isArray(saved.plugin) ? saved.plugin : [];
|
|
852
|
+
const nonForgePlugins = existingPlugins.filter((entry) => {
|
|
853
|
+
const name = Array.isArray(entry) ? entry[0] : entry;
|
|
854
|
+
return typeof name !== "string" || !/^minimal-forge-work-pack-sync@/.test(name);
|
|
855
|
+
});
|
|
856
|
+
const forgePlugins = savedPlugins.filter((entry) => Array.isArray(entry) && typeof entry[0] === "string" && /^minimal-forge-work-pack-sync@/.test(entry[0]));
|
|
857
|
+
return `${JSON.stringify({
|
|
858
|
+
...parsed,
|
|
859
|
+
model: saved.model,
|
|
860
|
+
small_model: saved.small_model,
|
|
861
|
+
provider: { ...currentProvider, forge: savedProvider.forge },
|
|
862
|
+
plugin: [...nonForgePlugins, ...forgePlugins]
|
|
863
|
+
}, null, 2)}
|
|
864
|
+
`;
|
|
865
|
+
}
|
|
866
|
+
function sameSavedForgeFields(current, snapshot) {
|
|
867
|
+
const active = parseJsonc(current);
|
|
868
|
+
const saved = parseJsonc(snapshot);
|
|
869
|
+
const activeProvider = isRecord3(active.provider) ? active.provider.forge : void 0;
|
|
870
|
+
const savedProvider = isRecord3(saved.provider) ? saved.provider.forge : void 0;
|
|
871
|
+
return JSON.stringify(activeProvider) === JSON.stringify(savedProvider) && active.model === saved.model && active.small_model === saved.small_model && JSON.stringify(forgePluginEntries(active)) === JSON.stringify(forgePluginEntries(saved));
|
|
872
|
+
}
|
|
873
|
+
function forgePluginEntries(config) {
|
|
874
|
+
return (Array.isArray(config.plugin) ? config.plugin : []).filter((entry) => {
|
|
875
|
+
const name = Array.isArray(entry) ? entry[0] : entry;
|
|
876
|
+
return typeof name === "string" && /^minimal-forge-work-pack-sync@/.test(name);
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
async function readOptional(filePath) {
|
|
880
|
+
try {
|
|
881
|
+
return await readFile4(filePath, "utf8");
|
|
882
|
+
} catch (error) {
|
|
883
|
+
if (error.code === "ENOENT") return void 0;
|
|
884
|
+
throw error;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
function isRecord3(value) {
|
|
888
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
889
|
+
}
|
|
890
|
+
function assertForgeVisible(config) {
|
|
891
|
+
if (!isRecord3(config)) return;
|
|
892
|
+
if (Array.isArray(config.disabled_providers) && config.disabled_providers.includes("forge") || Array.isArray(config.enabled_providers) && !config.enabled_providers.includes("forge")) {
|
|
893
|
+
throw new LocalConfigRecoveryError("O Forge est\xE1 oculto nas prefer\xEAncias de providers. Pe\xE7a ao respons\xE1vel para rever essa escolha; a configura\xE7\xE3o foi preservada.");
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// packages/cli/src/reconnectWorker.ts
|
|
898
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
899
|
+
import { access, readFile as readFile5 } from "node:fs/promises";
|
|
900
|
+
import path4 from "node:path";
|
|
901
|
+
|
|
902
|
+
// packages/cli/src/deviceEnrollment.ts
|
|
903
|
+
var MAX_RESPONSE_BYTES = 16 * 1024;
|
|
904
|
+
var MAX_INTERVAL_SECONDS = 30;
|
|
905
|
+
var START_REQUEST_TIMEOUT_MS = 3e4;
|
|
906
|
+
var MINIMAL_FORGE_CLI_VERSION = "0.1.0";
|
|
907
|
+
var DeviceEnrollmentError = class extends Error {
|
|
908
|
+
constructor(message, uncertainConsumption = false) {
|
|
909
|
+
super(message);
|
|
910
|
+
this.uncertainConsumption = uncertainConsumption;
|
|
911
|
+
}
|
|
912
|
+
uncertainConsumption;
|
|
913
|
+
};
|
|
914
|
+
async function enrollDevice(options) {
|
|
915
|
+
const baseUrl = normalizeForgeBaseUrl(options.baseUrl);
|
|
916
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
917
|
+
const now = options.now ?? Date.now;
|
|
918
|
+
const sleep = options.sleep ?? sleepWithSignal;
|
|
919
|
+
const output = options.output ?? console.log;
|
|
920
|
+
assertNotCancelled(options.signal);
|
|
921
|
+
const startUrl = new URL("/enroll/device/start", baseUrl);
|
|
922
|
+
const startRequest = requestScope(options.signal, START_REQUEST_TIMEOUT_MS);
|
|
923
|
+
let challenge;
|
|
924
|
+
try {
|
|
925
|
+
const startResponse = await fetchImpl(startUrl, {
|
|
926
|
+
method: "POST",
|
|
927
|
+
headers: { "content-type": "application/json" },
|
|
928
|
+
body: JSON.stringify({
|
|
929
|
+
protocolVersion: DEVICE_ENROLLMENT_PROTOCOL_VERSION,
|
|
930
|
+
cliVersion: options.cliVersion ?? MINIMAL_FORGE_CLI_VERSION,
|
|
931
|
+
installMode: options.installMode,
|
|
932
|
+
...options.deviceLabel ? { deviceLabel: options.deviceLabel } : {},
|
|
933
|
+
...options.hostname ? { hostname: options.hostname } : {}
|
|
934
|
+
}),
|
|
935
|
+
redirect: "manual",
|
|
936
|
+
signal: startRequest.signal
|
|
937
|
+
});
|
|
938
|
+
assertPinnedResponse(startResponse, startUrl.origin, false);
|
|
939
|
+
if (!startResponse.ok) {
|
|
940
|
+
if (startResponse.status === 409) {
|
|
941
|
+
throw new DeviceEnrollmentError("A vers\xE3o da CLI n\xE3o \xE9 compat\xEDvel com este Forge. Use a CLI fixada pelo operador ou --key-stdin.");
|
|
942
|
+
}
|
|
943
|
+
throw new DeviceEnrollmentError("O Forge n\xE3o conseguiu iniciar a autoriza\xE7\xE3o. Tente mais tarde ou use --key-stdin.");
|
|
944
|
+
}
|
|
945
|
+
challenge = assertStartResponse(await readBoundedJson(startResponse, startRequest.signal), startUrl.origin);
|
|
946
|
+
} catch (error) {
|
|
947
|
+
if (options.signal?.aborted) throw cancelledError();
|
|
948
|
+
if (error instanceof DeviceEnrollmentError) throw error;
|
|
949
|
+
throw new DeviceEnrollmentError(
|
|
950
|
+
startRequest.timedOut() ? "O Forge demorou demasiado a iniciar a autoriza\xE7\xE3o. Tente novamente ou use --key-stdin." : "O Forge devolveu um desafio de autoriza\xE7\xE3o inv\xE1lido"
|
|
951
|
+
);
|
|
952
|
+
} finally {
|
|
953
|
+
startRequest.dispose();
|
|
954
|
+
}
|
|
955
|
+
output(`Abra ${challenge.verificationUri}`);
|
|
956
|
+
output(`C\xF3digo de autoriza\xE7\xE3o: ${challenge.userCode}`);
|
|
957
|
+
output(`O c\xF3digo expira em ${challenge.expiresIn} segundos.`);
|
|
958
|
+
const deadline = now() + (challenge.expiresIn + Math.min(challenge.interval, MAX_INTERVAL_SECONDS)) * 1e3;
|
|
959
|
+
let intervalSeconds = challenge.interval;
|
|
960
|
+
const pollUrl = new URL("/enroll/device/poll", baseUrl);
|
|
961
|
+
while (true) {
|
|
962
|
+
assertNotCancelled(options.signal);
|
|
963
|
+
if (now() + intervalSeconds * 1e3 > deadline) throw expiredError();
|
|
964
|
+
try {
|
|
965
|
+
await sleep(intervalSeconds * 1e3, options.signal);
|
|
966
|
+
} catch {
|
|
967
|
+
if (options.signal?.aborted) throw cancelledError();
|
|
968
|
+
continue;
|
|
969
|
+
}
|
|
970
|
+
assertNotCancelled(options.signal);
|
|
971
|
+
const pollRequest = requestScope(options.signal, Math.max(1, deadline - now()));
|
|
972
|
+
try {
|
|
973
|
+
const response = await fetchImpl(pollUrl, {
|
|
974
|
+
method: "POST",
|
|
975
|
+
headers: { "content-type": "application/json" },
|
|
976
|
+
body: JSON.stringify({
|
|
977
|
+
protocolVersion: DEVICE_ENROLLMENT_PROTOCOL_VERSION,
|
|
978
|
+
deviceCode: challenge.deviceCode
|
|
979
|
+
}),
|
|
980
|
+
redirect: "manual",
|
|
981
|
+
signal: pollRequest.signal
|
|
982
|
+
});
|
|
983
|
+
assertPinnedResponse(response, pollUrl.origin, true);
|
|
984
|
+
if (!response.ok) {
|
|
985
|
+
if (response.status === 409) {
|
|
986
|
+
throw new DeviceEnrollmentError(
|
|
987
|
+
"A vers\xE3o da CLI n\xE3o \xE9 compat\xEDvel com este Forge. Use a CLI fixada pelo operador ou --key-stdin."
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
throw uncertainError();
|
|
991
|
+
}
|
|
992
|
+
const result = assertPollResponse(await readBoundedJson(response, pollRequest.signal));
|
|
993
|
+
if (result.status === "authorization_pending") {
|
|
994
|
+
intervalSeconds = boundedInterval(result.interval);
|
|
995
|
+
continue;
|
|
996
|
+
}
|
|
997
|
+
if (result.status === "slow_down") {
|
|
998
|
+
intervalSeconds = boundedInterval(result.interval);
|
|
999
|
+
continue;
|
|
1000
|
+
}
|
|
1001
|
+
if (result.status === "authorized") return result.key;
|
|
1002
|
+
throw terminalError(result);
|
|
1003
|
+
} catch (error) {
|
|
1004
|
+
if (error instanceof DeviceEnrollmentError) throw error;
|
|
1005
|
+
throw uncertainError();
|
|
1006
|
+
} finally {
|
|
1007
|
+
pollRequest.dispose();
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
function normalizeForgeBaseUrl(value) {
|
|
1012
|
+
let url;
|
|
1013
|
+
try {
|
|
1014
|
+
url = new URL(value);
|
|
1015
|
+
} catch {
|
|
1016
|
+
throw new DeviceEnrollmentError("O URL base do Forge \xE9 inv\xE1lido");
|
|
1017
|
+
}
|
|
1018
|
+
const loopback = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]";
|
|
1019
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) {
|
|
1020
|
+
throw new DeviceEnrollmentError("A liga\xE7\xE3o ao Forge exige HTTPS, exceto em loopback local");
|
|
1021
|
+
}
|
|
1022
|
+
if (url.username || url.password || url.search || url.hash || url.pathname !== "/" && url.pathname !== "") {
|
|
1023
|
+
throw new DeviceEnrollmentError("Use apenas a origem base do Forge, sem credenciais, caminho, query ou fragmento");
|
|
1024
|
+
}
|
|
1025
|
+
return url.origin;
|
|
1026
|
+
}
|
|
1027
|
+
function assertStartResponse(value, expectedOrigin) {
|
|
1028
|
+
if (!isRecord4(value) || value.protocolVersion !== DEVICE_ENROLLMENT_PROTOCOL_VERSION) {
|
|
1029
|
+
throw new DeviceEnrollmentError("A resposta de autoriza\xE7\xE3o usa um protocolo incompat\xEDvel. Use a CLI fixada ou --key-stdin.");
|
|
1030
|
+
}
|
|
1031
|
+
if (typeof value.deviceCode !== "string" || !/^[A-Za-z0-9_-]{43}$/.test(value.deviceCode) || typeof value.userCode !== "string" || !/^[A-Z0-9]{4}-[A-Z0-9]{4}$/.test(value.userCode) || typeof value.verificationUri !== "string" || typeof value.expiresIn !== "number" || !Number.isSafeInteger(value.expiresIn) || value.expiresIn < 1 || value.expiresIn > 3600 || !Number.isSafeInteger(value.interval)) {
|
|
1032
|
+
throw new DeviceEnrollmentError("O Forge devolveu um desafio de autoriza\xE7\xE3o inv\xE1lido");
|
|
1033
|
+
}
|
|
1034
|
+
let verificationUrl;
|
|
1035
|
+
try {
|
|
1036
|
+
verificationUrl = new URL(value.verificationUri);
|
|
1037
|
+
} catch {
|
|
1038
|
+
throw new DeviceEnrollmentError("O Forge devolveu um URL de verifica\xE7\xE3o n\xE3o aprovado");
|
|
1039
|
+
}
|
|
1040
|
+
if (verificationUrl.origin !== expectedOrigin || verificationUrl.protocol !== "https:" && !isLoopbackHttp(verificationUrl)) {
|
|
1041
|
+
throw new DeviceEnrollmentError("O Forge devolveu um URL de verifica\xE7\xE3o n\xE3o aprovado");
|
|
1042
|
+
}
|
|
1043
|
+
boundedInterval(value.interval);
|
|
1044
|
+
return value;
|
|
1045
|
+
}
|
|
1046
|
+
function assertPollResponse(value) {
|
|
1047
|
+
if (!isRecord4(value) || value.protocolVersion !== DEVICE_ENROLLMENT_PROTOCOL_VERSION || typeof value.status !== "string") {
|
|
1048
|
+
throw new Error("invalid poll response");
|
|
1049
|
+
}
|
|
1050
|
+
if (value.status === "authorization_pending" || value.status === "slow_down") {
|
|
1051
|
+
boundedInterval(value.interval);
|
|
1052
|
+
return value;
|
|
1053
|
+
}
|
|
1054
|
+
if (value.status === "authorized") {
|
|
1055
|
+
if (typeof value.key !== "string" || !value.key.startsWith("forge_") || Buffer.byteLength(value.key, "utf8") > 4096) {
|
|
1056
|
+
throw new Error("invalid authorized response");
|
|
1057
|
+
}
|
|
1058
|
+
return value;
|
|
1059
|
+
}
|
|
1060
|
+
if (["access_denied", "cancelled", "expired", "person_inactive", "consumed"].includes(value.status)) {
|
|
1061
|
+
return value;
|
|
1062
|
+
}
|
|
1063
|
+
throw new Error("unknown poll status");
|
|
1064
|
+
}
|
|
1065
|
+
function assertPinnedResponse(response, expectedOrigin, polling) {
|
|
1066
|
+
if (response.redirected || response.status >= 300 && response.status < 400) {
|
|
1067
|
+
if (polling) throw uncertainError();
|
|
1068
|
+
throw new DeviceEnrollmentError("O Forge tentou redirecionar a autoriza\xE7\xE3o; o pedido foi interrompido");
|
|
1069
|
+
}
|
|
1070
|
+
if (response.url) {
|
|
1071
|
+
const responseUrl = new URL(response.url);
|
|
1072
|
+
if (responseUrl.origin !== expectedOrigin || responseUrl.protocol !== "https:" && !isLoopbackHttp(responseUrl)) {
|
|
1073
|
+
if (polling) throw uncertainError();
|
|
1074
|
+
throw new DeviceEnrollmentError("A resposta de autoriza\xE7\xE3o veio de uma origem n\xE3o aprovada");
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
async function readBoundedJson(response, signal) {
|
|
1079
|
+
const length = Number.parseInt(response.headers.get("content-length") ?? "0", 10);
|
|
1080
|
+
if (Number.isFinite(length) && length > MAX_RESPONSE_BYTES) throw new Error("response too large");
|
|
1081
|
+
if (!response.body) return JSON.parse("");
|
|
1082
|
+
const reader = response.body.getReader();
|
|
1083
|
+
const chunks = [];
|
|
1084
|
+
let byteLength = 0;
|
|
1085
|
+
try {
|
|
1086
|
+
while (true) {
|
|
1087
|
+
const { done, value } = await readWithSignal(reader, signal);
|
|
1088
|
+
if (done) break;
|
|
1089
|
+
byteLength += value.byteLength;
|
|
1090
|
+
if (byteLength > MAX_RESPONSE_BYTES) {
|
|
1091
|
+
await reader.cancel();
|
|
1092
|
+
throw new Error("response too large");
|
|
1093
|
+
}
|
|
1094
|
+
chunks.push(value);
|
|
1095
|
+
}
|
|
1096
|
+
} finally {
|
|
1097
|
+
reader.releaseLock();
|
|
1098
|
+
}
|
|
1099
|
+
const bytes = new Uint8Array(byteLength);
|
|
1100
|
+
let offset = 0;
|
|
1101
|
+
for (const chunk of chunks) {
|
|
1102
|
+
bytes.set(chunk, offset);
|
|
1103
|
+
offset += chunk.byteLength;
|
|
1104
|
+
}
|
|
1105
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
1106
|
+
}
|
|
1107
|
+
async function readWithSignal(reader, signal) {
|
|
1108
|
+
if (!signal) return reader.read();
|
|
1109
|
+
if (signal.aborted) {
|
|
1110
|
+
await reader.cancel();
|
|
1111
|
+
throw new Error("request aborted");
|
|
1112
|
+
}
|
|
1113
|
+
return new Promise((resolve, reject) => {
|
|
1114
|
+
const abort = () => {
|
|
1115
|
+
void reader.cancel().finally(() => reject(new Error("request aborted")));
|
|
1116
|
+
};
|
|
1117
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
1118
|
+
void reader.read().then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
function requestScope(parent, timeoutMs) {
|
|
1122
|
+
const controller = new AbortController();
|
|
1123
|
+
let didTimeOut = false;
|
|
1124
|
+
const abortFromParent = () => controller.abort();
|
|
1125
|
+
if (parent?.aborted) controller.abort();
|
|
1126
|
+
else parent?.addEventListener("abort", abortFromParent, { once: true });
|
|
1127
|
+
const timer = setTimeout(() => {
|
|
1128
|
+
didTimeOut = true;
|
|
1129
|
+
controller.abort();
|
|
1130
|
+
}, timeoutMs);
|
|
1131
|
+
return {
|
|
1132
|
+
signal: controller.signal,
|
|
1133
|
+
timedOut: () => didTimeOut,
|
|
1134
|
+
dispose: () => {
|
|
1135
|
+
clearTimeout(timer);
|
|
1136
|
+
parent?.removeEventListener("abort", abortFromParent);
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
function boundedInterval(value) {
|
|
1141
|
+
if (!Number.isSafeInteger(value) || Number(value) < 1 || Number(value) > MAX_INTERVAL_SECONDS) {
|
|
1142
|
+
throw new Error("invalid poll interval");
|
|
1143
|
+
}
|
|
1144
|
+
return Number(value);
|
|
1145
|
+
}
|
|
1146
|
+
function terminalError(result) {
|
|
1147
|
+
switch (result.status) {
|
|
1148
|
+
case "access_denied":
|
|
1149
|
+
return new DeviceEnrollmentError("O operador recusou a autoriza\xE7\xE3o. Inicie uma nova inscri\xE7\xE3o ou use --key-stdin.");
|
|
1150
|
+
case "cancelled":
|
|
1151
|
+
return new DeviceEnrollmentError("A aprova\xE7\xE3o foi cancelada. Inicie uma nova inscri\xE7\xE3o ou use --key-stdin.");
|
|
1152
|
+
case "expired":
|
|
1153
|
+
return expiredError();
|
|
1154
|
+
case "person_inactive":
|
|
1155
|
+
return new DeviceEnrollmentError("A pessoa selecionada j\xE1 n\xE3o est\xE1 ativa. Corrija a pessoa e inicie uma nova inscri\xE7\xE3o.");
|
|
1156
|
+
case "consumed":
|
|
1157
|
+
return new DeviceEnrollmentError("Este c\xF3digo j\xE1 foi consumido. Revogue a chave associada e volte a inscrever o dispositivo.");
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
function uncertainError() {
|
|
1161
|
+
return new DeviceEnrollmentError(
|
|
1162
|
+
"O resultado da entrega da chave \xE9 incerto. N\xE3o volte a consultar este c\xF3digo; revogue a chave associada e volte a inscrever o dispositivo.",
|
|
1163
|
+
true
|
|
1164
|
+
);
|
|
1165
|
+
}
|
|
1166
|
+
function expiredError() {
|
|
1167
|
+
return new DeviceEnrollmentError("O c\xF3digo de autoriza\xE7\xE3o expirou. Inicie uma nova inscri\xE7\xE3o ou use --key-stdin.");
|
|
1168
|
+
}
|
|
1169
|
+
function cancelledError() {
|
|
1170
|
+
return new DeviceEnrollmentError("A autoriza\xE7\xE3o foi interrompida. Nenhuma configura\xE7\xE3o local foi alterada.");
|
|
1171
|
+
}
|
|
1172
|
+
function assertNotCancelled(signal) {
|
|
1173
|
+
if (signal?.aborted) throw cancelledError();
|
|
1174
|
+
}
|
|
1175
|
+
function sleepWithSignal(milliseconds, signal) {
|
|
1176
|
+
return new Promise((resolve, reject) => {
|
|
1177
|
+
const timeout = setTimeout(() => {
|
|
1178
|
+
signal?.removeEventListener("abort", abort);
|
|
1179
|
+
resolve();
|
|
1180
|
+
}, milliseconds);
|
|
1181
|
+
const abort = () => {
|
|
1182
|
+
clearTimeout(timeout);
|
|
1183
|
+
signal?.removeEventListener("abort", abort);
|
|
1184
|
+
reject(cancelledError());
|
|
1185
|
+
};
|
|
1186
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
function isLoopbackHttp(url) {
|
|
1190
|
+
return url.protocol === "http:" && (url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]");
|
|
1191
|
+
}
|
|
1192
|
+
function isRecord4(value) {
|
|
1193
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
// packages/cli/src/retireDebugCapture.ts
|
|
1197
|
+
var MANAGED_HEADER = "// Managed by Forge sync. Do not edit.";
|
|
1198
|
+
var RETIRED_DEBUG_PLUGIN = `${MANAGED_HEADER}
|
|
1199
|
+
// Detailed capture retired. Keep this module loadable for old OpenCode configs.
|
|
1200
|
+
export const ForgeDebugTrace = async () => ({})
|
|
1201
|
+
`;
|
|
1202
|
+
|
|
1203
|
+
// packages/cli/src/workPackIntegrity.ts
|
|
1204
|
+
var MAX_FILE_BYTES = 64 * 1024 * 1024;
|
|
1205
|
+
|
|
1206
|
+
// packages/cli/src/sync.ts
|
|
1207
|
+
import os2 from "node:os";
|
|
1208
|
+
|
|
1209
|
+
// node_modules/tar/dist/esm/index.min.js
|
|
1210
|
+
import Qr from "events";
|
|
1211
|
+
import I from "fs";
|
|
1212
|
+
import { EventEmitter as Di } from "node:events";
|
|
1213
|
+
import Cs from "node:stream";
|
|
1214
|
+
import { StringDecoder as Hr } from "node:string_decoder";
|
|
1215
|
+
import cr from "node:path";
|
|
1216
|
+
import Kt from "node:fs";
|
|
1217
|
+
import { dirname as Fn, parse as kn } from "path";
|
|
1218
|
+
import { EventEmitter as Dn } from "events";
|
|
1219
|
+
import zi from "assert";
|
|
1220
|
+
import { Buffer as Ot } from "buffer";
|
|
1221
|
+
import * as Ps from "zlib";
|
|
1222
|
+
import en from "zlib";
|
|
1223
|
+
import { posix as Zt } from "node:path";
|
|
1224
|
+
import { basename as _n } from "node:path";
|
|
1225
|
+
import mi from "fs";
|
|
1226
|
+
import X from "fs";
|
|
1227
|
+
import js from "path";
|
|
1228
|
+
import { win32 as Pn } from "node:path";
|
|
1229
|
+
import ar from "path";
|
|
1230
|
+
import Br from "node:fs";
|
|
1231
|
+
import co from "node:assert";
|
|
1232
|
+
import { randomBytes as Mr } from "node:crypto";
|
|
1233
|
+
import u from "node:fs";
|
|
1234
|
+
import R from "node:path";
|
|
1235
|
+
import pr from "fs";
|
|
1236
|
+
import wi from "node:fs";
|
|
1237
|
+
import we from "node:path";
|
|
1238
|
+
import k from "node:fs";
|
|
1239
|
+
import ro from "node:fs/promises";
|
|
1240
|
+
import Si from "node:path";
|
|
1241
|
+
import { join as xr } from "node:path";
|
|
1242
|
+
import v from "node:fs";
|
|
1243
|
+
import Pr from "node:path";
|
|
1244
|
+
var zr = Object.defineProperty;
|
|
1245
|
+
var Ur = (s3, t) => {
|
|
1246
|
+
for (var e in t) zr(s3, e, { get: t[e], enumerable: true });
|
|
1247
|
+
};
|
|
1248
|
+
var Ds = typeof process == "object" && process ? process : { stdout: null, stderr: null };
|
|
1249
|
+
var Wr = (s3) => !!s3 && typeof s3 == "object" && (s3 instanceof A || s3 instanceof Cs || Gr(s3) || Zr(s3));
|
|
1250
|
+
var Gr = (s3) => !!s3 && typeof s3 == "object" && s3 instanceof Di && typeof s3.pipe == "function" && s3.pipe !== Cs.Writable.prototype.pipe;
|
|
1251
|
+
var Zr = (s3) => !!s3 && typeof s3 == "object" && s3 instanceof Di && typeof s3.write == "function" && typeof s3.end == "function";
|
|
1252
|
+
var Q = /* @__PURE__ */ Symbol("EOF");
|
|
1253
|
+
var J = /* @__PURE__ */ Symbol("maybeEmitEnd");
|
|
1254
|
+
var nt = /* @__PURE__ */ Symbol("emittedEnd");
|
|
1255
|
+
var De = /* @__PURE__ */ Symbol("emittingEnd");
|
|
1256
|
+
var qt = /* @__PURE__ */ Symbol("emittedError");
|
|
1257
|
+
var Ne = /* @__PURE__ */ Symbol("closed");
|
|
1258
|
+
var Ns = /* @__PURE__ */ Symbol("read");
|
|
1259
|
+
var Ae = /* @__PURE__ */ Symbol("flush");
|
|
1260
|
+
var As = /* @__PURE__ */ Symbol("flushChunk");
|
|
1261
|
+
var z = /* @__PURE__ */ Symbol("encoding");
|
|
1262
|
+
var Mt = /* @__PURE__ */ Symbol("decoder");
|
|
1263
|
+
var g = /* @__PURE__ */ Symbol("flowing");
|
|
1264
|
+
var Qt = /* @__PURE__ */ Symbol("paused");
|
|
1265
|
+
var Bt = /* @__PURE__ */ Symbol("resume");
|
|
1266
|
+
var b = /* @__PURE__ */ Symbol("buffer");
|
|
1267
|
+
var N = /* @__PURE__ */ Symbol("pipes");
|
|
1268
|
+
var _ = /* @__PURE__ */ Symbol("bufferLength");
|
|
1269
|
+
var bi = /* @__PURE__ */ Symbol("bufferPush");
|
|
1270
|
+
var Ie = /* @__PURE__ */ Symbol("bufferShift");
|
|
1271
|
+
var L = /* @__PURE__ */ Symbol("objectMode");
|
|
1272
|
+
var S = /* @__PURE__ */ Symbol("destroyed");
|
|
1273
|
+
var _i = /* @__PURE__ */ Symbol("error");
|
|
1274
|
+
var Oi = /* @__PURE__ */ Symbol("emitData");
|
|
1275
|
+
var Is = /* @__PURE__ */ Symbol("emitEnd");
|
|
1276
|
+
var Ti = /* @__PURE__ */ Symbol("emitEnd2");
|
|
1277
|
+
var Z = /* @__PURE__ */ Symbol("async");
|
|
1278
|
+
var xi = /* @__PURE__ */ Symbol("abort");
|
|
1279
|
+
var Ce = /* @__PURE__ */ Symbol("aborted");
|
|
1280
|
+
var Jt = /* @__PURE__ */ Symbol("signal");
|
|
1281
|
+
var Rt = /* @__PURE__ */ Symbol("dataListeners");
|
|
1282
|
+
var C = /* @__PURE__ */ Symbol("discarded");
|
|
1283
|
+
var jt = (s3) => Promise.resolve().then(s3);
|
|
1284
|
+
var Yr = (s3) => s3();
|
|
1285
|
+
var Kr = (s3) => s3 === "end" || s3 === "finish" || s3 === "prefinish";
|
|
1286
|
+
var Vr = (s3) => s3 instanceof ArrayBuffer || !!s3 && typeof s3 == "object" && s3.constructor && s3.constructor.name === "ArrayBuffer" && s3.byteLength >= 0;
|
|
1287
|
+
var $r = (s3) => !Buffer.isBuffer(s3) && ArrayBuffer.isView(s3);
|
|
1288
|
+
var Fe = class {
|
|
1289
|
+
src;
|
|
1290
|
+
dest;
|
|
1291
|
+
opts;
|
|
1292
|
+
ondrain;
|
|
1293
|
+
constructor(t, e, i) {
|
|
1294
|
+
this.src = t, this.dest = e, this.opts = i, this.ondrain = () => t[Bt](), this.dest.on("drain", this.ondrain);
|
|
1295
|
+
}
|
|
1296
|
+
unpipe() {
|
|
1297
|
+
this.dest.removeListener("drain", this.ondrain);
|
|
1298
|
+
}
|
|
1299
|
+
proxyErrors(t) {
|
|
1300
|
+
}
|
|
1301
|
+
end() {
|
|
1302
|
+
this.unpipe(), this.opts.end && this.dest.end();
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
var Li = class extends Fe {
|
|
1306
|
+
unpipe() {
|
|
1307
|
+
this.src.removeListener("error", this.proxyErrors), super.unpipe();
|
|
1308
|
+
}
|
|
1309
|
+
constructor(t, e, i) {
|
|
1310
|
+
super(t, e, i), this.proxyErrors = (r) => this.dest.emit("error", r), t.on("error", this.proxyErrors);
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
var Xr = (s3) => !!s3.objectMode;
|
|
1314
|
+
var qr = (s3) => !s3.objectMode && !!s3.encoding && s3.encoding !== "buffer";
|
|
1315
|
+
var A = class extends Di {
|
|
1316
|
+
[g] = false;
|
|
1317
|
+
[Qt] = false;
|
|
1318
|
+
[N] = [];
|
|
1319
|
+
[b] = [];
|
|
1320
|
+
[L];
|
|
1321
|
+
[z];
|
|
1322
|
+
[Z];
|
|
1323
|
+
[Mt];
|
|
1324
|
+
[Q] = false;
|
|
1325
|
+
[nt] = false;
|
|
1326
|
+
[De] = false;
|
|
1327
|
+
[Ne] = false;
|
|
1328
|
+
[qt] = null;
|
|
1329
|
+
[_] = 0;
|
|
1330
|
+
[S] = false;
|
|
1331
|
+
[Jt];
|
|
1332
|
+
[Ce] = false;
|
|
1333
|
+
[Rt] = 0;
|
|
1334
|
+
[C] = false;
|
|
1335
|
+
writable = true;
|
|
1336
|
+
readable = true;
|
|
1337
|
+
constructor(...t) {
|
|
1338
|
+
let e = t[0] || {};
|
|
1339
|
+
if (super(), e.objectMode && typeof e.encoding == "string") throw new TypeError("Encoding and objectMode may not be used together");
|
|
1340
|
+
Xr(e) ? (this[L] = true, this[z] = null) : qr(e) ? (this[z] = e.encoding, this[L] = false) : (this[L] = false, this[z] = null), this[Z] = !!e.async, this[Mt] = this[z] ? new Hr(this[z]) : null, e && e.debugExposeBuffer === true && Object.defineProperty(this, "buffer", { get: () => this[b] }), e && e.debugExposePipes === true && Object.defineProperty(this, "pipes", { get: () => this[N] });
|
|
1341
|
+
let { signal: i } = e;
|
|
1342
|
+
i && (this[Jt] = i, i.aborted ? this[xi]() : i.addEventListener("abort", () => this[xi]()));
|
|
1343
|
+
}
|
|
1344
|
+
get bufferLength() {
|
|
1345
|
+
return this[_];
|
|
1346
|
+
}
|
|
1347
|
+
get encoding() {
|
|
1348
|
+
return this[z];
|
|
1349
|
+
}
|
|
1350
|
+
set encoding(t) {
|
|
1351
|
+
throw new Error("Encoding must be set at instantiation time");
|
|
1352
|
+
}
|
|
1353
|
+
setEncoding(t) {
|
|
1354
|
+
throw new Error("Encoding must be set at instantiation time");
|
|
1355
|
+
}
|
|
1356
|
+
get objectMode() {
|
|
1357
|
+
return this[L];
|
|
1358
|
+
}
|
|
1359
|
+
set objectMode(t) {
|
|
1360
|
+
throw new Error("objectMode must be set at instantiation time");
|
|
1361
|
+
}
|
|
1362
|
+
get async() {
|
|
1363
|
+
return this[Z];
|
|
1364
|
+
}
|
|
1365
|
+
set async(t) {
|
|
1366
|
+
this[Z] = this[Z] || !!t;
|
|
1367
|
+
}
|
|
1368
|
+
[xi]() {
|
|
1369
|
+
this[Ce] = true, this.emit("abort", this[Jt]?.reason), this.destroy(this[Jt]?.reason);
|
|
1370
|
+
}
|
|
1371
|
+
get aborted() {
|
|
1372
|
+
return this[Ce];
|
|
1373
|
+
}
|
|
1374
|
+
set aborted(t) {
|
|
1375
|
+
}
|
|
1376
|
+
write(t, e, i) {
|
|
1377
|
+
if (this[Ce]) return false;
|
|
1378
|
+
if (this[Q]) throw new Error("write after end");
|
|
1379
|
+
if (this[S]) return this.emit("error", Object.assign(new Error("Cannot call write after a stream was destroyed"), { code: "ERR_STREAM_DESTROYED" })), true;
|
|
1380
|
+
typeof e == "function" && (i = e, e = "utf8"), e || (e = "utf8");
|
|
1381
|
+
let r = this[Z] ? jt : Yr;
|
|
1382
|
+
if (!this[L] && !Buffer.isBuffer(t)) {
|
|
1383
|
+
if ($r(t)) t = Buffer.from(t.buffer, t.byteOffset, t.byteLength);
|
|
1384
|
+
else if (Vr(t)) t = Buffer.from(t);
|
|
1385
|
+
else if (typeof t != "string") throw new Error("Non-contiguous data written to non-objectMode stream");
|
|
1386
|
+
}
|
|
1387
|
+
return this[L] ? (this[g] && this[_] !== 0 && this[Ae](true), this[g] ? this.emit("data", t) : this[bi](t), this[_] !== 0 && this.emit("readable"), i && r(i), this[g]) : t.length ? (typeof t == "string" && !(e === this[z] && !this[Mt]?.lastNeed) && (t = Buffer.from(t, e)), Buffer.isBuffer(t) && this[z] && (t = this[Mt].write(t)), this[g] && this[_] !== 0 && this[Ae](true), this[g] ? this.emit("data", t) : this[bi](t), this[_] !== 0 && this.emit("readable"), i && r(i), this[g]) : (this[_] !== 0 && this.emit("readable"), i && r(i), this[g]);
|
|
1388
|
+
}
|
|
1389
|
+
read(t) {
|
|
1390
|
+
if (this[S]) return null;
|
|
1391
|
+
if (this[C] = false, this[_] === 0 || t === 0 || t && t > this[_]) return this[J](), null;
|
|
1392
|
+
this[L] && (t = null), this[b].length > 1 && !this[L] && (this[b] = [this[z] ? this[b].join("") : Buffer.concat(this[b], this[_])]);
|
|
1393
|
+
let e = this[Ns](t || null, this[b][0]);
|
|
1394
|
+
return this[J](), e;
|
|
1395
|
+
}
|
|
1396
|
+
[Ns](t, e) {
|
|
1397
|
+
if (this[L]) this[Ie]();
|
|
1398
|
+
else {
|
|
1399
|
+
let i = e;
|
|
1400
|
+
t === i.length || t === null ? this[Ie]() : typeof i == "string" ? (this[b][0] = i.slice(t), e = i.slice(0, t), this[_] -= t) : (this[b][0] = i.subarray(t), e = i.subarray(0, t), this[_] -= t);
|
|
1401
|
+
}
|
|
1402
|
+
return this.emit("data", e), !this[b].length && !this[Q] && this.emit("drain"), e;
|
|
1403
|
+
}
|
|
1404
|
+
end(t, e, i) {
|
|
1405
|
+
return typeof t == "function" && (i = t, t = void 0), typeof e == "function" && (i = e, e = "utf8"), t !== void 0 && this.write(t, e), i && this.once("end", i), this[Q] = true, this.writable = false, (this[g] || !this[Qt]) && this[J](), this;
|
|
1406
|
+
}
|
|
1407
|
+
[Bt]() {
|
|
1408
|
+
this[S] || (!this[Rt] && !this[N].length && (this[C] = true), this[Qt] = false, this[g] = true, this.emit("resume"), this[b].length ? this[Ae]() : this[Q] ? this[J]() : this.emit("drain"));
|
|
1409
|
+
}
|
|
1410
|
+
resume() {
|
|
1411
|
+
return this[Bt]();
|
|
1412
|
+
}
|
|
1413
|
+
pause() {
|
|
1414
|
+
this[g] = false, this[Qt] = true, this[C] = false;
|
|
1415
|
+
}
|
|
1416
|
+
get destroyed() {
|
|
1417
|
+
return this[S];
|
|
1418
|
+
}
|
|
1419
|
+
get flowing() {
|
|
1420
|
+
return this[g];
|
|
1421
|
+
}
|
|
1422
|
+
get paused() {
|
|
1423
|
+
return this[Qt];
|
|
1424
|
+
}
|
|
1425
|
+
[bi](t) {
|
|
1426
|
+
this[L] ? this[_] += 1 : this[_] += t.length, this[b].push(t);
|
|
1427
|
+
}
|
|
1428
|
+
[Ie]() {
|
|
1429
|
+
return this[L] ? this[_] -= 1 : this[_] -= this[b][0].length, this[b].shift();
|
|
1430
|
+
}
|
|
1431
|
+
[Ae](t = false) {
|
|
1432
|
+
do
|
|
1433
|
+
;
|
|
1434
|
+
while (this[As](this[Ie]()) && this[b].length);
|
|
1435
|
+
!t && !this[b].length && !this[Q] && this.emit("drain");
|
|
1436
|
+
}
|
|
1437
|
+
[As](t) {
|
|
1438
|
+
return this.emit("data", t), this[g];
|
|
1439
|
+
}
|
|
1440
|
+
pipe(t, e) {
|
|
1441
|
+
if (this[S]) return t;
|
|
1442
|
+
this[C] = false;
|
|
1443
|
+
let i = this[nt];
|
|
1444
|
+
return e = e || {}, t === Ds.stdout || t === Ds.stderr ? e.end = false : e.end = e.end !== false, e.proxyErrors = !!e.proxyErrors, i ? e.end && t.end() : (this[N].push(e.proxyErrors ? new Li(this, t, e) : new Fe(this, t, e)), this[Z] ? jt(() => this[Bt]()) : this[Bt]()), t;
|
|
1445
|
+
}
|
|
1446
|
+
unpipe(t) {
|
|
1447
|
+
let e = this[N].find((i) => i.dest === t);
|
|
1448
|
+
e && (this[N].length === 1 ? (this[g] && this[Rt] === 0 && (this[g] = false), this[N] = []) : this[N].splice(this[N].indexOf(e), 1), e.unpipe());
|
|
1449
|
+
}
|
|
1450
|
+
addListener(t, e) {
|
|
1451
|
+
return this.on(t, e);
|
|
1452
|
+
}
|
|
1453
|
+
on(t, e) {
|
|
1454
|
+
let i = super.on(t, e);
|
|
1455
|
+
if (t === "data") this[C] = false, this[Rt]++, !this[N].length && !this[g] && this[Bt]();
|
|
1456
|
+
else if (t === "readable" && this[_] !== 0) super.emit("readable");
|
|
1457
|
+
else if (Kr(t) && this[nt]) super.emit(t), this.removeAllListeners(t);
|
|
1458
|
+
else if (t === "error" && this[qt]) {
|
|
1459
|
+
let r = e;
|
|
1460
|
+
this[Z] ? jt(() => r.call(this, this[qt])) : r.call(this, this[qt]);
|
|
1461
|
+
}
|
|
1462
|
+
return i;
|
|
1463
|
+
}
|
|
1464
|
+
removeListener(t, e) {
|
|
1465
|
+
return this.off(t, e);
|
|
1466
|
+
}
|
|
1467
|
+
off(t, e) {
|
|
1468
|
+
let i = super.off(t, e);
|
|
1469
|
+
return t === "data" && (this[Rt] = this.listeners("data").length, this[Rt] === 0 && !this[C] && !this[N].length && (this[g] = false)), i;
|
|
1470
|
+
}
|
|
1471
|
+
removeAllListeners(t) {
|
|
1472
|
+
let e = super.removeAllListeners(t);
|
|
1473
|
+
return (t === "data" || t === void 0) && (this[Rt] = 0, !this[C] && !this[N].length && (this[g] = false)), e;
|
|
1474
|
+
}
|
|
1475
|
+
get emittedEnd() {
|
|
1476
|
+
return this[nt];
|
|
1477
|
+
}
|
|
1478
|
+
[J]() {
|
|
1479
|
+
!this[De] && !this[nt] && !this[S] && this[b].length === 0 && this[Q] && (this[De] = true, this.emit("end"), this.emit("prefinish"), this.emit("finish"), this[Ne] && this.emit("close"), this[De] = false);
|
|
1480
|
+
}
|
|
1481
|
+
emit(t, ...e) {
|
|
1482
|
+
let i = e[0];
|
|
1483
|
+
if (t !== "error" && t !== "close" && t !== S && this[S]) return false;
|
|
1484
|
+
if (t === "data") return !this[L] && !i ? false : this[Z] ? (jt(() => this[Oi](i)), true) : this[Oi](i);
|
|
1485
|
+
if (t === "end") return this[Is]();
|
|
1486
|
+
if (t === "close") {
|
|
1487
|
+
if (this[Ne] = true, !this[nt] && !this[S]) return false;
|
|
1488
|
+
let n = super.emit("close");
|
|
1489
|
+
return this.removeAllListeners("close"), n;
|
|
1490
|
+
} else if (t === "error") {
|
|
1491
|
+
this[qt] = i, super.emit(_i, i);
|
|
1492
|
+
let n = !this[Jt] || this.listeners("error").length ? super.emit("error", i) : false;
|
|
1493
|
+
return this[J](), n;
|
|
1494
|
+
} else if (t === "resume") {
|
|
1495
|
+
let n = super.emit("resume");
|
|
1496
|
+
return this[J](), n;
|
|
1497
|
+
} else if (t === "finish" || t === "prefinish") {
|
|
1498
|
+
let n = super.emit(t);
|
|
1499
|
+
return this.removeAllListeners(t), n;
|
|
1500
|
+
}
|
|
1501
|
+
let r = super.emit(t, ...e);
|
|
1502
|
+
return this[J](), r;
|
|
1503
|
+
}
|
|
1504
|
+
[Oi](t) {
|
|
1505
|
+
for (let i of this[N]) i.dest.write(t) === false && this.pause();
|
|
1506
|
+
let e = this[C] ? false : super.emit("data", t);
|
|
1507
|
+
return this[J](), e;
|
|
1508
|
+
}
|
|
1509
|
+
[Is]() {
|
|
1510
|
+
return this[nt] ? false : (this[nt] = true, this.readable = false, this[Z] ? (jt(() => this[Ti]()), true) : this[Ti]());
|
|
1511
|
+
}
|
|
1512
|
+
[Ti]() {
|
|
1513
|
+
if (this[Mt]) {
|
|
1514
|
+
let e = this[Mt].end();
|
|
1515
|
+
if (e) {
|
|
1516
|
+
for (let i of this[N]) i.dest.write(e);
|
|
1517
|
+
this[C] || super.emit("data", e);
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
for (let e of this[N]) e.end();
|
|
1521
|
+
let t = super.emit("end");
|
|
1522
|
+
return this.removeAllListeners("end"), t;
|
|
1523
|
+
}
|
|
1524
|
+
async collect() {
|
|
1525
|
+
let t = Object.assign([], { dataLength: 0 });
|
|
1526
|
+
this[L] || (t.dataLength = 0);
|
|
1527
|
+
let e = this.promise();
|
|
1528
|
+
return this.on("data", (i) => {
|
|
1529
|
+
t.push(i), this[L] || (t.dataLength += i.length);
|
|
1530
|
+
}), await e, t;
|
|
1531
|
+
}
|
|
1532
|
+
async concat() {
|
|
1533
|
+
if (this[L]) throw new Error("cannot concat in objectMode");
|
|
1534
|
+
let t = await this.collect();
|
|
1535
|
+
return this[z] ? t.join("") : Buffer.concat(t, t.dataLength);
|
|
1536
|
+
}
|
|
1537
|
+
async promise() {
|
|
1538
|
+
return new Promise((t, e) => {
|
|
1539
|
+
this.on(S, () => e(new Error("stream destroyed"))), this.on("error", (i) => e(i)), this.on("end", () => t());
|
|
1540
|
+
});
|
|
1541
|
+
}
|
|
1542
|
+
[Symbol.asyncIterator]() {
|
|
1543
|
+
this[C] = false;
|
|
1544
|
+
let t = false, e = async () => (this.pause(), t = true, { value: void 0, done: true });
|
|
1545
|
+
return { next: () => {
|
|
1546
|
+
if (t) return e();
|
|
1547
|
+
let r = this.read();
|
|
1548
|
+
if (r !== null) return Promise.resolve({ done: false, value: r });
|
|
1549
|
+
if (this[Q]) return e();
|
|
1550
|
+
let n, o, h = (d) => {
|
|
1551
|
+
this.off("data", a), this.off("end", l), this.off(S, c), e(), o(d);
|
|
1552
|
+
}, a = (d) => {
|
|
1553
|
+
this.off("error", h), this.off("end", l), this.off(S, c), this.pause(), n({ value: d, done: !!this[Q] });
|
|
1554
|
+
}, l = () => {
|
|
1555
|
+
this.off("error", h), this.off("data", a), this.off(S, c), e(), n({ done: true, value: void 0 });
|
|
1556
|
+
}, c = () => h(new Error("stream destroyed"));
|
|
1557
|
+
return new Promise((d, y) => {
|
|
1558
|
+
o = y, n = d, this.once(S, c), this.once("error", h), this.once("end", l), this.once("data", a);
|
|
1559
|
+
});
|
|
1560
|
+
}, throw: e, return: e, [Symbol.asyncIterator]() {
|
|
1561
|
+
return this;
|
|
1562
|
+
}, [Symbol.asyncDispose]: async () => {
|
|
1563
|
+
} };
|
|
1564
|
+
}
|
|
1565
|
+
[Symbol.iterator]() {
|
|
1566
|
+
this[C] = false;
|
|
1567
|
+
let t = false, e = () => (this.pause(), this.off(_i, e), this.off(S, e), this.off("end", e), t = true, { done: true, value: void 0 }), i = () => {
|
|
1568
|
+
if (t) return e();
|
|
1569
|
+
let r = this.read();
|
|
1570
|
+
return r === null ? e() : { done: false, value: r };
|
|
1571
|
+
};
|
|
1572
|
+
return this.once("end", e), this.once(_i, e), this.once(S, e), { next: i, throw: e, return: e, [Symbol.iterator]() {
|
|
1573
|
+
return this;
|
|
1574
|
+
}, [Symbol.dispose]: () => {
|
|
1575
|
+
} };
|
|
1576
|
+
}
|
|
1577
|
+
destroy(t) {
|
|
1578
|
+
if (this[S]) return t ? this.emit("error", t) : this.emit(S), this;
|
|
1579
|
+
this[S] = true, this[C] = true, this[b].length = 0, this[_] = 0;
|
|
1580
|
+
let e = this;
|
|
1581
|
+
return typeof e.close == "function" && !this[Ne] && e.close(), t ? this.emit("error", t) : this.emit(S), this;
|
|
1582
|
+
}
|
|
1583
|
+
static get isStream() {
|
|
1584
|
+
return Wr;
|
|
1585
|
+
}
|
|
1586
|
+
};
|
|
1587
|
+
var Jr = I.writev;
|
|
1588
|
+
var ht = /* @__PURE__ */ Symbol("_autoClose");
|
|
1589
|
+
var H = /* @__PURE__ */ Symbol("_close");
|
|
1590
|
+
var te = /* @__PURE__ */ Symbol("_ended");
|
|
1591
|
+
var m = /* @__PURE__ */ Symbol("_fd");
|
|
1592
|
+
var Ni = /* @__PURE__ */ Symbol("_finished");
|
|
1593
|
+
var tt = /* @__PURE__ */ Symbol("_flags");
|
|
1594
|
+
var Ai = /* @__PURE__ */ Symbol("_flush");
|
|
1595
|
+
var ki = /* @__PURE__ */ Symbol("_handleChunk");
|
|
1596
|
+
var vi = /* @__PURE__ */ Symbol("_makeBuf");
|
|
1597
|
+
var ie = /* @__PURE__ */ Symbol("_mode");
|
|
1598
|
+
var ke = /* @__PURE__ */ Symbol("_needDrain");
|
|
1599
|
+
var Ut = /* @__PURE__ */ Symbol("_onerror");
|
|
1600
|
+
var Ht = /* @__PURE__ */ Symbol("_onopen");
|
|
1601
|
+
var Ii = /* @__PURE__ */ Symbol("_onread");
|
|
1602
|
+
var Pt = /* @__PURE__ */ Symbol("_onwrite");
|
|
1603
|
+
var at = /* @__PURE__ */ Symbol("_open");
|
|
1604
|
+
var U = /* @__PURE__ */ Symbol("_path");
|
|
1605
|
+
var ot = /* @__PURE__ */ Symbol("_pos");
|
|
1606
|
+
var Y = /* @__PURE__ */ Symbol("_queue");
|
|
1607
|
+
var zt = /* @__PURE__ */ Symbol("_read");
|
|
1608
|
+
var Ci = /* @__PURE__ */ Symbol("_readSize");
|
|
1609
|
+
var j = /* @__PURE__ */ Symbol("_reading");
|
|
1610
|
+
var ee = /* @__PURE__ */ Symbol("_remain");
|
|
1611
|
+
var Fi = /* @__PURE__ */ Symbol("_size");
|
|
1612
|
+
var ve = /* @__PURE__ */ Symbol("_write");
|
|
1613
|
+
var gt = /* @__PURE__ */ Symbol("_writing");
|
|
1614
|
+
var Me = /* @__PURE__ */ Symbol("_defaultFlag");
|
|
1615
|
+
var bt = /* @__PURE__ */ Symbol("_errored");
|
|
1616
|
+
var _t = class extends A {
|
|
1617
|
+
[bt] = false;
|
|
1618
|
+
[m];
|
|
1619
|
+
[U];
|
|
1620
|
+
[Ci];
|
|
1621
|
+
[j] = false;
|
|
1622
|
+
[Fi];
|
|
1623
|
+
[ee];
|
|
1624
|
+
[ht];
|
|
1625
|
+
constructor(t, e) {
|
|
1626
|
+
if (e = e || {}, super(e), this.readable = true, this.writable = false, typeof t != "string") throw new TypeError("path must be a string");
|
|
1627
|
+
this[bt] = false, this[m] = typeof e.fd == "number" ? e.fd : void 0, this[U] = t, this[Ci] = e.readSize || 16 * 1024 * 1024, this[j] = false, this[Fi] = typeof e.size == "number" ? e.size : 1 / 0, this[ee] = this[Fi], this[ht] = typeof e.autoClose == "boolean" ? e.autoClose : true, typeof this[m] == "number" ? this[zt]() : this[at]();
|
|
1628
|
+
}
|
|
1629
|
+
get fd() {
|
|
1630
|
+
return this[m];
|
|
1631
|
+
}
|
|
1632
|
+
get path() {
|
|
1633
|
+
return this[U];
|
|
1634
|
+
}
|
|
1635
|
+
write() {
|
|
1636
|
+
throw new TypeError("this is a readable stream");
|
|
1637
|
+
}
|
|
1638
|
+
end() {
|
|
1639
|
+
throw new TypeError("this is a readable stream");
|
|
1640
|
+
}
|
|
1641
|
+
[at]() {
|
|
1642
|
+
I.open(this[U], "r", (t, e) => this[Ht](t, e));
|
|
1643
|
+
}
|
|
1644
|
+
[Ht](t, e) {
|
|
1645
|
+
t ? this[Ut](t) : (this[m] = e, this.emit("open", e), this[zt]());
|
|
1646
|
+
}
|
|
1647
|
+
[vi]() {
|
|
1648
|
+
return Buffer.allocUnsafe(Math.min(this[Ci], this[ee]));
|
|
1649
|
+
}
|
|
1650
|
+
[zt]() {
|
|
1651
|
+
if (!this[j]) {
|
|
1652
|
+
this[j] = true;
|
|
1653
|
+
let t = this[vi]();
|
|
1654
|
+
if (t.length === 0) return process.nextTick(() => this[Ii](null, 0, t));
|
|
1655
|
+
I.read(this[m], t, 0, t.length, null, (e, i, r) => this[Ii](e, i, r));
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
[Ii](t, e, i) {
|
|
1659
|
+
this[j] = false, t ? this[Ut](t) : this[ki](e, i) && this[zt]();
|
|
1660
|
+
}
|
|
1661
|
+
[H]() {
|
|
1662
|
+
if (this[ht] && typeof this[m] == "number") {
|
|
1663
|
+
let t = this[m];
|
|
1664
|
+
this[m] = void 0, I.close(t, (e) => e ? this.emit("error", e) : this.emit("close"));
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
[Ut](t) {
|
|
1668
|
+
this[j] = true, this[H](), this.emit("error", t);
|
|
1669
|
+
}
|
|
1670
|
+
[ki](t, e) {
|
|
1671
|
+
let i = false;
|
|
1672
|
+
return this[ee] -= t, t > 0 && (i = super.write(t < e.length ? e.subarray(0, t) : e)), (t === 0 || this[ee] <= 0) && (i = false, this[H](), super.end()), i;
|
|
1673
|
+
}
|
|
1674
|
+
emit(t, ...e) {
|
|
1675
|
+
switch (t) {
|
|
1676
|
+
case "prefinish":
|
|
1677
|
+
case "finish":
|
|
1678
|
+
return false;
|
|
1679
|
+
case "drain":
|
|
1680
|
+
return typeof this[m] == "number" && this[zt](), false;
|
|
1681
|
+
case "error":
|
|
1682
|
+
return this[bt] ? false : (this[bt] = true, super.emit(t, ...e));
|
|
1683
|
+
default:
|
|
1684
|
+
return super.emit(t, ...e);
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
};
|
|
1688
|
+
var Be = class extends _t {
|
|
1689
|
+
[at]() {
|
|
1690
|
+
let t = true;
|
|
1691
|
+
try {
|
|
1692
|
+
this[Ht](null, I.openSync(this[U], "r")), t = false;
|
|
1693
|
+
} finally {
|
|
1694
|
+
t && this[H]();
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
[zt]() {
|
|
1698
|
+
let t = true;
|
|
1699
|
+
try {
|
|
1700
|
+
if (!this[j]) {
|
|
1701
|
+
this[j] = true;
|
|
1702
|
+
do {
|
|
1703
|
+
let e = this[vi](), i = e.length === 0 ? 0 : I.readSync(this[m], e, 0, e.length, null);
|
|
1704
|
+
if (!this[ki](i, e)) break;
|
|
1705
|
+
} while (true);
|
|
1706
|
+
this[j] = false;
|
|
1707
|
+
}
|
|
1708
|
+
t = false;
|
|
1709
|
+
} finally {
|
|
1710
|
+
t && this[H]();
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
[H]() {
|
|
1714
|
+
if (this[ht] && typeof this[m] == "number") {
|
|
1715
|
+
let t = this[m];
|
|
1716
|
+
this[m] = void 0, I.closeSync(t), this.emit("close");
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
};
|
|
1720
|
+
var et = class extends Qr {
|
|
1721
|
+
readable = false;
|
|
1722
|
+
writable = true;
|
|
1723
|
+
[bt] = false;
|
|
1724
|
+
[gt] = false;
|
|
1725
|
+
[te] = false;
|
|
1726
|
+
[Y] = [];
|
|
1727
|
+
[ke] = false;
|
|
1728
|
+
[U];
|
|
1729
|
+
[ie];
|
|
1730
|
+
[ht];
|
|
1731
|
+
[m];
|
|
1732
|
+
[Me];
|
|
1733
|
+
[tt];
|
|
1734
|
+
[Ni] = false;
|
|
1735
|
+
[ot];
|
|
1736
|
+
constructor(t, e) {
|
|
1737
|
+
e = e || {}, super(e), this[U] = t, this[m] = typeof e.fd == "number" ? e.fd : void 0, this[ie] = e.mode === void 0 ? 438 : e.mode, this[ot] = typeof e.start == "number" ? e.start : void 0, this[ht] = typeof e.autoClose == "boolean" ? e.autoClose : true;
|
|
1738
|
+
let i = this[ot] !== void 0 ? "r+" : "w";
|
|
1739
|
+
this[Me] = e.flags === void 0, this[tt] = e.flags === void 0 ? i : e.flags, this[m] === void 0 && this[at]();
|
|
1740
|
+
}
|
|
1741
|
+
emit(t, ...e) {
|
|
1742
|
+
if (t === "error") {
|
|
1743
|
+
if (this[bt]) return false;
|
|
1744
|
+
this[bt] = true;
|
|
1745
|
+
}
|
|
1746
|
+
return super.emit(t, ...e);
|
|
1747
|
+
}
|
|
1748
|
+
get fd() {
|
|
1749
|
+
return this[m];
|
|
1750
|
+
}
|
|
1751
|
+
get path() {
|
|
1752
|
+
return this[U];
|
|
1753
|
+
}
|
|
1754
|
+
[Ut](t) {
|
|
1755
|
+
this[H](), this[gt] = true, this.emit("error", t);
|
|
1756
|
+
}
|
|
1757
|
+
[at]() {
|
|
1758
|
+
I.open(this[U], this[tt], this[ie], (t, e) => this[Ht](t, e));
|
|
1759
|
+
}
|
|
1760
|
+
[Ht](t, e) {
|
|
1761
|
+
this[Me] && this[tt] === "r+" && t && t.code === "ENOENT" ? (this[tt] = "w", this[at]()) : t ? this[Ut](t) : (this[m] = e, this.emit("open", e), this[gt] || this[Ai]());
|
|
1762
|
+
}
|
|
1763
|
+
end(t, e) {
|
|
1764
|
+
return t && this.write(t, e), this[te] = true, !this[gt] && !this[Y].length && typeof this[m] == "number" && this[Pt](null, 0), this;
|
|
1765
|
+
}
|
|
1766
|
+
write(t, e) {
|
|
1767
|
+
return typeof t == "string" && (t = Buffer.from(t, e)), this[te] ? (this.emit("error", new Error("write() after end()")), false) : this[m] === void 0 || this[gt] || this[Y].length ? (this[Y].push(t), this[ke] = true, false) : (this[gt] = true, this[ve](t), true);
|
|
1768
|
+
}
|
|
1769
|
+
[ve](t) {
|
|
1770
|
+
I.write(this[m], t, 0, t.length, this[ot], (e, i) => this[Pt](e, i));
|
|
1771
|
+
}
|
|
1772
|
+
[Pt](t, e) {
|
|
1773
|
+
t ? this[Ut](t) : (this[ot] !== void 0 && typeof e == "number" && (this[ot] += e), this[Y].length ? this[Ai]() : (this[gt] = false, this[te] && !this[Ni] ? (this[Ni] = true, this[H](), this.emit("finish")) : this[ke] && (this[ke] = false, this.emit("drain"))));
|
|
1774
|
+
}
|
|
1775
|
+
[Ai]() {
|
|
1776
|
+
if (this[Y].length === 0) this[te] && this[Pt](null, 0);
|
|
1777
|
+
else if (this[Y].length === 1) this[ve](this[Y].pop());
|
|
1778
|
+
else {
|
|
1779
|
+
let t = this[Y];
|
|
1780
|
+
this[Y] = [], Jr(this[m], t, this[ot], (e, i) => this[Pt](e, i));
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
[H]() {
|
|
1784
|
+
if (this[ht] && typeof this[m] == "number") {
|
|
1785
|
+
let t = this[m];
|
|
1786
|
+
this[m] = void 0, I.close(t, (e) => e ? this.emit("error", e) : this.emit("close"));
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
};
|
|
1790
|
+
var Wt = class extends et {
|
|
1791
|
+
[at]() {
|
|
1792
|
+
let t;
|
|
1793
|
+
if (this[Me] && this[tt] === "r+") try {
|
|
1794
|
+
t = I.openSync(this[U], this[tt], this[ie]);
|
|
1795
|
+
} catch (e) {
|
|
1796
|
+
if (e?.code === "ENOENT") return this[tt] = "w", this[at]();
|
|
1797
|
+
throw e;
|
|
1798
|
+
}
|
|
1799
|
+
else t = I.openSync(this[U], this[tt], this[ie]);
|
|
1800
|
+
this[Ht](null, t);
|
|
1801
|
+
}
|
|
1802
|
+
[H]() {
|
|
1803
|
+
if (this[ht] && typeof this[m] == "number") {
|
|
1804
|
+
let t = this[m];
|
|
1805
|
+
this[m] = void 0, I.closeSync(t), this.emit("close");
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
[ve](t) {
|
|
1809
|
+
let e = true;
|
|
1810
|
+
try {
|
|
1811
|
+
this[Pt](null, I.writeSync(this[m], t, 0, t.length, this[ot])), e = false;
|
|
1812
|
+
} finally {
|
|
1813
|
+
if (e) try {
|
|
1814
|
+
this[H]();
|
|
1815
|
+
} catch {
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
};
|
|
1820
|
+
var jr = /* @__PURE__ */ new Map([["C", "cwd"], ["f", "file"], ["z", "gzip"], ["P", "preservePaths"], ["U", "unlink"], ["strip-components", "strip"], ["stripComponents", "strip"], ["keep-newer", "newer"], ["keepNewer", "newer"], ["keep-newer-files", "newer"], ["keepNewerFiles", "newer"], ["k", "keep"], ["keep-existing", "keep"], ["keepExisting", "keep"], ["m", "noMtime"], ["no-mtime", "noMtime"], ["p", "preserveOwner"], ["L", "follow"], ["h", "follow"], ["onentry", "onReadEntry"]]);
|
|
1821
|
+
var Fs = (s3) => !!s3.sync && !!s3.file;
|
|
1822
|
+
var ks = (s3) => !s3.sync && !!s3.file;
|
|
1823
|
+
var vs = (s3) => !!s3.sync && !s3.file;
|
|
1824
|
+
var Ms = (s3) => !s3.sync && !s3.file;
|
|
1825
|
+
var Bs = (s3) => !!s3.file;
|
|
1826
|
+
var tn = (s3) => {
|
|
1827
|
+
let t = jr.get(s3);
|
|
1828
|
+
return t || s3;
|
|
1829
|
+
};
|
|
1830
|
+
var se = (s3 = {}) => {
|
|
1831
|
+
if (!s3) return {};
|
|
1832
|
+
let t = {};
|
|
1833
|
+
for (let [e, i] of Object.entries(s3)) {
|
|
1834
|
+
let r = tn(e);
|
|
1835
|
+
t[r] = i;
|
|
1836
|
+
}
|
|
1837
|
+
return t.chmod === void 0 && t.noChmod === false && (t.chmod = true), delete t.noChmod, t;
|
|
1838
|
+
};
|
|
1839
|
+
var K = (s3, t, e, i, r) => Object.assign((n = [], o, h) => {
|
|
1840
|
+
Array.isArray(n) && (o = n, n = {}), typeof o == "function" && (h = o, o = void 0), o = o ? Array.from(o) : [];
|
|
1841
|
+
let a = se(n);
|
|
1842
|
+
if (r?.(a, o), Fs(a)) {
|
|
1843
|
+
if (typeof h == "function") throw new TypeError("callback not supported for sync tar functions");
|
|
1844
|
+
return s3(a, o);
|
|
1845
|
+
} else if (ks(a)) {
|
|
1846
|
+
let l = t(a, o);
|
|
1847
|
+
return h ? l.then(() => h(), h) : l;
|
|
1848
|
+
} else if (vs(a)) {
|
|
1849
|
+
if (typeof h == "function") throw new TypeError("callback not supported for sync tar functions");
|
|
1850
|
+
return e(a, o);
|
|
1851
|
+
} else if (Ms(a)) {
|
|
1852
|
+
if (typeof h == "function") throw new TypeError("callback only supported with file option");
|
|
1853
|
+
return i(a, o);
|
|
1854
|
+
}
|
|
1855
|
+
throw new Error("impossible options??");
|
|
1856
|
+
}, { syncFile: s3, asyncFile: t, syncNoFile: e, asyncNoFile: i, validate: r });
|
|
1857
|
+
var sn = en.constants || { ZLIB_VERNUM: 4736 };
|
|
1858
|
+
var M = Object.freeze(Object.assign(/* @__PURE__ */ Object.create(null), { Z_NO_FLUSH: 0, Z_PARTIAL_FLUSH: 1, Z_SYNC_FLUSH: 2, Z_FULL_FLUSH: 3, Z_FINISH: 4, Z_BLOCK: 5, Z_OK: 0, Z_STREAM_END: 1, Z_NEED_DICT: 2, Z_ERRNO: -1, Z_STREAM_ERROR: -2, Z_DATA_ERROR: -3, Z_MEM_ERROR: -4, Z_BUF_ERROR: -5, Z_VERSION_ERROR: -6, Z_NO_COMPRESSION: 0, Z_BEST_SPEED: 1, Z_BEST_COMPRESSION: 9, Z_DEFAULT_COMPRESSION: -1, Z_FILTERED: 1, Z_HUFFMAN_ONLY: 2, Z_RLE: 3, Z_FIXED: 4, Z_DEFAULT_STRATEGY: 0, DEFLATE: 1, INFLATE: 2, GZIP: 3, GUNZIP: 4, DEFLATERAW: 5, INFLATERAW: 6, UNZIP: 7, BROTLI_DECODE: 8, BROTLI_ENCODE: 9, Z_MIN_WINDOWBITS: 8, Z_MAX_WINDOWBITS: 15, Z_DEFAULT_WINDOWBITS: 15, Z_MIN_CHUNK: 64, Z_MAX_CHUNK: 1 / 0, Z_DEFAULT_CHUNK: 16384, Z_MIN_MEMLEVEL: 1, Z_MAX_MEMLEVEL: 9, Z_DEFAULT_MEMLEVEL: 8, Z_MIN_LEVEL: -1, Z_MAX_LEVEL: 9, Z_DEFAULT_LEVEL: -1, BROTLI_OPERATION_PROCESS: 0, BROTLI_OPERATION_FLUSH: 1, BROTLI_OPERATION_FINISH: 2, BROTLI_OPERATION_EMIT_METADATA: 3, BROTLI_MODE_GENERIC: 0, BROTLI_MODE_TEXT: 1, BROTLI_MODE_FONT: 2, BROTLI_DEFAULT_MODE: 0, BROTLI_MIN_QUALITY: 0, BROTLI_MAX_QUALITY: 11, BROTLI_DEFAULT_QUALITY: 11, BROTLI_MIN_WINDOW_BITS: 10, BROTLI_MAX_WINDOW_BITS: 24, BROTLI_LARGE_MAX_WINDOW_BITS: 30, BROTLI_DEFAULT_WINDOW: 22, BROTLI_MIN_INPUT_BLOCK_BITS: 16, BROTLI_MAX_INPUT_BLOCK_BITS: 24, BROTLI_PARAM_MODE: 0, BROTLI_PARAM_QUALITY: 1, BROTLI_PARAM_LGWIN: 2, BROTLI_PARAM_LGBLOCK: 3, BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: 4, BROTLI_PARAM_SIZE_HINT: 5, BROTLI_PARAM_LARGE_WINDOW: 6, BROTLI_PARAM_NPOSTFIX: 7, BROTLI_PARAM_NDIRECT: 8, BROTLI_DECODER_RESULT_ERROR: 0, BROTLI_DECODER_RESULT_SUCCESS: 1, BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: 2, BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: 3, BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: 0, BROTLI_DECODER_PARAM_LARGE_WINDOW: 1, BROTLI_DECODER_NO_ERROR: 0, BROTLI_DECODER_SUCCESS: 1, BROTLI_DECODER_NEEDS_MORE_INPUT: 2, BROTLI_DECODER_NEEDS_MORE_OUTPUT: 3, BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: -1, BROTLI_DECODER_ERROR_FORMAT_RESERVED: -2, BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: -3, BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: -4, BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: -5, BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: -6, BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: -7, BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: -8, BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: -9, BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: -10, BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: -11, BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: -12, BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: -13, BROTLI_DECODER_ERROR_FORMAT_PADDING_1: -14, BROTLI_DECODER_ERROR_FORMAT_PADDING_2: -15, BROTLI_DECODER_ERROR_FORMAT_DISTANCE: -16, BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: -19, BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: -20, BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: -21, BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: -22, BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: -25, BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: -26, BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: -27, BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: -30, BROTLI_DECODER_ERROR_UNREACHABLE: -31 }, sn));
|
|
1859
|
+
var rn = Ot.concat;
|
|
1860
|
+
var zs = Object.getOwnPropertyDescriptor(Ot, "concat");
|
|
1861
|
+
var nn = (s3) => s3;
|
|
1862
|
+
var Bi = zs?.writable === true || zs?.set !== void 0 ? (s3) => {
|
|
1863
|
+
Ot.concat = s3 ? nn : rn;
|
|
1864
|
+
} : (s3) => {
|
|
1865
|
+
};
|
|
1866
|
+
var Tt = /* @__PURE__ */ Symbol("_superWrite");
|
|
1867
|
+
var Gt = class extends Error {
|
|
1868
|
+
code;
|
|
1869
|
+
errno;
|
|
1870
|
+
constructor(t, e) {
|
|
1871
|
+
super("zlib: " + t.message, { cause: t }), this.code = t.code, this.errno = t.errno, this.code || (this.code = "ZLIB_ERROR"), this.message = "zlib: " + t.message, Error.captureStackTrace(this, e ?? this.constructor);
|
|
1872
|
+
}
|
|
1873
|
+
get name() {
|
|
1874
|
+
return "ZlibError";
|
|
1875
|
+
}
|
|
1876
|
+
};
|
|
1877
|
+
var Pi = /* @__PURE__ */ Symbol("flushFlag");
|
|
1878
|
+
var re = class extends A {
|
|
1879
|
+
#t = false;
|
|
1880
|
+
#i = false;
|
|
1881
|
+
#s;
|
|
1882
|
+
#n;
|
|
1883
|
+
#r;
|
|
1884
|
+
#e;
|
|
1885
|
+
#o;
|
|
1886
|
+
get sawError() {
|
|
1887
|
+
return this.#t;
|
|
1888
|
+
}
|
|
1889
|
+
get handle() {
|
|
1890
|
+
return this.#e;
|
|
1891
|
+
}
|
|
1892
|
+
get flushFlag() {
|
|
1893
|
+
return this.#s;
|
|
1894
|
+
}
|
|
1895
|
+
constructor(t, e) {
|
|
1896
|
+
if (!t || typeof t != "object") throw new TypeError("invalid options for ZlibBase constructor");
|
|
1897
|
+
if (super(t), this.#s = t.flush ?? 0, this.#n = t.finishFlush ?? 0, this.#r = t.fullFlushFlag ?? 0, typeof Ps[e] != "function") throw new TypeError("Compression method not supported: " + e);
|
|
1898
|
+
try {
|
|
1899
|
+
this.#e = new Ps[e](t);
|
|
1900
|
+
} catch (i) {
|
|
1901
|
+
throw new Gt(i, this.constructor);
|
|
1902
|
+
}
|
|
1903
|
+
this.#o = (i) => {
|
|
1904
|
+
this.#t || (this.#t = true, this.close(), this.emit("error", i));
|
|
1905
|
+
}, this.#e?.on("error", (i) => this.#o(new Gt(i))), this.once("end", () => this.close);
|
|
1906
|
+
}
|
|
1907
|
+
close() {
|
|
1908
|
+
this.#e && (this.#e.close(), this.#e = void 0, this.emit("close"));
|
|
1909
|
+
}
|
|
1910
|
+
reset() {
|
|
1911
|
+
if (!this.#t) return zi(this.#e, "zlib binding closed"), this.#e.reset?.();
|
|
1912
|
+
}
|
|
1913
|
+
flush(t) {
|
|
1914
|
+
this.ended || (typeof t != "number" && (t = this.#r), this.write(Object.assign(Ot.alloc(0), { [Pi]: t })));
|
|
1915
|
+
}
|
|
1916
|
+
end(t, e, i) {
|
|
1917
|
+
return typeof t == "function" && (i = t, e = void 0, t = void 0), typeof e == "function" && (i = e, e = void 0), t && (e ? this.write(t, e) : this.write(t)), this.flush(this.#n), this.#i = true, super.end(i);
|
|
1918
|
+
}
|
|
1919
|
+
get ended() {
|
|
1920
|
+
return this.#i;
|
|
1921
|
+
}
|
|
1922
|
+
[Tt](t) {
|
|
1923
|
+
return super.write(t);
|
|
1924
|
+
}
|
|
1925
|
+
write(t, e, i) {
|
|
1926
|
+
if (typeof e == "function" && (i = e, e = "utf8"), typeof t == "string" && (t = Ot.from(t, e)), this.#t) return;
|
|
1927
|
+
zi(this.#e, "zlib binding closed");
|
|
1928
|
+
let r = this.#e._handle, n = r.close;
|
|
1929
|
+
r.close = () => {
|
|
1930
|
+
};
|
|
1931
|
+
let o = this.#e.close;
|
|
1932
|
+
this.#e.close = () => {
|
|
1933
|
+
}, Bi(true);
|
|
1934
|
+
let h;
|
|
1935
|
+
try {
|
|
1936
|
+
let l = typeof t[Pi] == "number" ? t[Pi] : this.#s;
|
|
1937
|
+
h = this.#e._processChunk(t, l), Bi(false);
|
|
1938
|
+
} catch (l) {
|
|
1939
|
+
Bi(false), this.#o(new Gt(l, this.write));
|
|
1940
|
+
} finally {
|
|
1941
|
+
this.#e && (this.#e._handle = r, r.close = n, this.#e.close = o, this.#e.removeAllListeners("error"));
|
|
1942
|
+
}
|
|
1943
|
+
this.#e && this.#e.on("error", (l) => this.#o(new Gt(l, this.write)));
|
|
1944
|
+
let a;
|
|
1945
|
+
if (h) if (Array.isArray(h) && h.length > 0) {
|
|
1946
|
+
let l = h[0];
|
|
1947
|
+
a = this[Tt](Ot.from(l));
|
|
1948
|
+
for (let c = 1; c < h.length; c++) a = this[Tt](h[c]);
|
|
1949
|
+
} else a = this[Tt](Ot.from(h));
|
|
1950
|
+
return i && i(), a;
|
|
1951
|
+
}
|
|
1952
|
+
};
|
|
1953
|
+
var Pe = class extends re {
|
|
1954
|
+
#t;
|
|
1955
|
+
#i;
|
|
1956
|
+
constructor(t, e) {
|
|
1957
|
+
t = t || {}, t.flush = t.flush || M.Z_NO_FLUSH, t.finishFlush = t.finishFlush || M.Z_FINISH, t.fullFlushFlag = M.Z_FULL_FLUSH, super(t, e), this.#t = t.level, this.#i = t.strategy;
|
|
1958
|
+
}
|
|
1959
|
+
params(t, e) {
|
|
1960
|
+
if (!this.sawError) {
|
|
1961
|
+
if (!this.handle) throw new Error("cannot switch params when binding is closed");
|
|
1962
|
+
if (!this.handle.params) throw new Error("not supported in this implementation");
|
|
1963
|
+
if (this.#t !== t || this.#i !== e) {
|
|
1964
|
+
this.flush(M.Z_SYNC_FLUSH), zi(this.handle, "zlib binding closed");
|
|
1965
|
+
let i = this.handle.flush;
|
|
1966
|
+
this.handle.flush = (r, n) => {
|
|
1967
|
+
typeof r == "function" && (n = r, r = this.flushFlag), this.flush(r), n?.();
|
|
1968
|
+
};
|
|
1969
|
+
try {
|
|
1970
|
+
this.handle.params(t, e);
|
|
1971
|
+
} finally {
|
|
1972
|
+
this.handle.flush = i;
|
|
1973
|
+
}
|
|
1974
|
+
this.handle && (this.#t = t, this.#i = e);
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
};
|
|
1979
|
+
var ze = class extends Pe {
|
|
1980
|
+
#t;
|
|
1981
|
+
constructor(t) {
|
|
1982
|
+
super(t, "Gzip"), this.#t = t && !!t.portable;
|
|
1983
|
+
}
|
|
1984
|
+
[Tt](t) {
|
|
1985
|
+
return this.#t ? (this.#t = false, t[9] = 255, super[Tt](t)) : super[Tt](t);
|
|
1986
|
+
}
|
|
1987
|
+
};
|
|
1988
|
+
var Ue = class extends Pe {
|
|
1989
|
+
constructor(t) {
|
|
1990
|
+
super(t, "Unzip");
|
|
1991
|
+
}
|
|
1992
|
+
};
|
|
1993
|
+
var He = class extends re {
|
|
1994
|
+
constructor(t, e) {
|
|
1995
|
+
t = t || {}, t.flush = t.flush || M.BROTLI_OPERATION_PROCESS, t.finishFlush = t.finishFlush || M.BROTLI_OPERATION_FINISH, t.fullFlushFlag = M.BROTLI_OPERATION_FLUSH, super(t, e);
|
|
1996
|
+
}
|
|
1997
|
+
};
|
|
1998
|
+
var We = class extends He {
|
|
1999
|
+
constructor(t) {
|
|
2000
|
+
super(t, "BrotliCompress");
|
|
2001
|
+
}
|
|
2002
|
+
};
|
|
2003
|
+
var Ge = class extends He {
|
|
2004
|
+
constructor(t) {
|
|
2005
|
+
super(t, "BrotliDecompress");
|
|
2006
|
+
}
|
|
2007
|
+
};
|
|
2008
|
+
var Ze = class extends re {
|
|
2009
|
+
constructor(t, e) {
|
|
2010
|
+
t = t || {}, t.flush = t.flush || M.ZSTD_e_continue, t.finishFlush = t.finishFlush || M.ZSTD_e_end, t.fullFlushFlag = M.ZSTD_e_flush, super(t, e);
|
|
2011
|
+
}
|
|
2012
|
+
};
|
|
2013
|
+
var Ye = class extends Ze {
|
|
2014
|
+
constructor(t) {
|
|
2015
|
+
super(t, "ZstdCompress");
|
|
2016
|
+
}
|
|
2017
|
+
};
|
|
2018
|
+
var Ke = class extends Ze {
|
|
2019
|
+
constructor(t) {
|
|
2020
|
+
super(t, "ZstdDecompress");
|
|
2021
|
+
}
|
|
2022
|
+
};
|
|
2023
|
+
var Us = (s3, t) => {
|
|
2024
|
+
if (Number.isSafeInteger(s3)) s3 < 0 ? an(s3, t) : hn(s3, t);
|
|
2025
|
+
else throw Error("cannot encode number outside of javascript safe integer range");
|
|
2026
|
+
return t;
|
|
2027
|
+
};
|
|
2028
|
+
var hn = (s3, t) => {
|
|
2029
|
+
t[0] = 128;
|
|
2030
|
+
for (var e = t.length; e > 1; e--) t[e - 1] = s3 & 255, s3 = Math.floor(s3 / 256);
|
|
2031
|
+
};
|
|
2032
|
+
var an = (s3, t) => {
|
|
2033
|
+
t[0] = 255;
|
|
2034
|
+
var e = false;
|
|
2035
|
+
s3 = s3 * -1;
|
|
2036
|
+
for (var i = t.length; i > 1; i--) {
|
|
2037
|
+
var r = s3 & 255;
|
|
2038
|
+
s3 = Math.floor(s3 / 256), e ? t[i - 1] = Ws(r) : r === 0 ? t[i - 1] = 0 : (e = true, t[i - 1] = Gs(r));
|
|
2039
|
+
}
|
|
2040
|
+
};
|
|
2041
|
+
var Hs = (s3) => {
|
|
2042
|
+
let t = s3[0], e = t === 128 ? cn(s3.subarray(1, s3.length)) : t === 255 ? ln(s3) : null;
|
|
2043
|
+
if (e === null) throw Error("invalid base256 encoding");
|
|
2044
|
+
if (!Number.isSafeInteger(e)) throw Error("parsed number outside of javascript safe integer range");
|
|
2045
|
+
return e;
|
|
2046
|
+
};
|
|
2047
|
+
var ln = (s3) => {
|
|
2048
|
+
for (var t = s3.length, e = 0, i = false, r = t - 1; r > -1; r--) {
|
|
2049
|
+
var n = Number(s3[r]), o;
|
|
2050
|
+
i ? o = Ws(n) : n === 0 ? o = n : (i = true, o = Gs(n)), o !== 0 && (e -= o * Math.pow(256, t - r - 1));
|
|
2051
|
+
}
|
|
2052
|
+
return e;
|
|
2053
|
+
};
|
|
2054
|
+
var cn = (s3) => {
|
|
2055
|
+
for (var t = s3.length, e = 0, i = t - 1; i > -1; i--) {
|
|
2056
|
+
var r = Number(s3[i]);
|
|
2057
|
+
r !== 0 && (e += r * Math.pow(256, t - i - 1));
|
|
2058
|
+
}
|
|
2059
|
+
return e;
|
|
2060
|
+
};
|
|
2061
|
+
var Ws = (s3) => (255 ^ s3) & 255;
|
|
2062
|
+
var Gs = (s3) => (255 ^ s3) + 1 & 255;
|
|
2063
|
+
var Hi = {};
|
|
2064
|
+
Ur(Hi, { code: () => Ve, isCode: () => ne, isName: () => dn, name: () => oe, normalFsTypes: () => Ui });
|
|
2065
|
+
var ne = (s3) => oe.has(s3);
|
|
2066
|
+
var dn = (s3) => Ve.has(s3);
|
|
2067
|
+
var Ui = /* @__PURE__ */ new Set(["0", "", "1", "2", "3", "4", "5", "6", "7", "D"]);
|
|
2068
|
+
var oe = /* @__PURE__ */ new Map([["0", "File"], ["", "OldFile"], ["1", "Link"], ["2", "SymbolicLink"], ["3", "CharacterDevice"], ["4", "BlockDevice"], ["5", "Directory"], ["6", "FIFO"], ["7", "ContiguousFile"], ["g", "GlobalExtendedHeader"], ["x", "ExtendedHeader"], ["A", "SolarisACL"], ["D", "GNUDumpDir"], ["I", "Inode"], ["K", "NextFileHasLongLinkpath"], ["L", "NextFileHasLongPath"], ["M", "ContinuationFile"], ["N", "OldGnuLongPath"], ["S", "SparseFile"], ["V", "TapeVolumeHeader"], ["X", "OldExtendedHeader"]]);
|
|
2069
|
+
var Ve = new Map(Array.from(oe).map((s3) => [s3[1], s3[0]]));
|
|
2070
|
+
var un = (s3) => s3 === void 0 || s3 < 0 ? void 0 : s3;
|
|
2071
|
+
var F = class {
|
|
2072
|
+
cksumValid = false;
|
|
2073
|
+
needPax = false;
|
|
2074
|
+
nullBlock = false;
|
|
2075
|
+
block;
|
|
2076
|
+
path;
|
|
2077
|
+
mode;
|
|
2078
|
+
uid;
|
|
2079
|
+
gid;
|
|
2080
|
+
size;
|
|
2081
|
+
cksum;
|
|
2082
|
+
#t = "Unsupported";
|
|
2083
|
+
linkpath;
|
|
2084
|
+
uname;
|
|
2085
|
+
gname;
|
|
2086
|
+
devmaj = 0;
|
|
2087
|
+
devmin = 0;
|
|
2088
|
+
atime;
|
|
2089
|
+
ctime;
|
|
2090
|
+
mtime;
|
|
2091
|
+
charset;
|
|
2092
|
+
comment;
|
|
2093
|
+
constructor(t, e = 0, i, r) {
|
|
2094
|
+
Buffer.isBuffer(t) ? this.decode(t, e || 0, i, r) : t && this.#i(t);
|
|
2095
|
+
}
|
|
2096
|
+
decode(t, e, i, r) {
|
|
2097
|
+
if (e || (e = 0), !t || !(t.length >= e + 512)) throw new Error("need 512 bytes for header");
|
|
2098
|
+
let n = xt(t, e + 156, 1), o = Ui.has(n), h = o ? i : void 0, a = o ? r : void 0;
|
|
2099
|
+
if (this.path = h?.path ?? xt(t, e, 100), this.mode = h?.mode ?? a?.mode ?? lt(t, e + 100, 8), this.uid = h?.uid ?? a?.uid ?? lt(t, e + 108, 8), this.gid = h?.gid ?? a?.gid ?? lt(t, e + 116, 8), this.size = un(h?.size ?? a?.size ?? lt(t, e + 124, 12)), this.mtime = h?.mtime ?? a?.mtime ?? Wi(t, e + 136, 12), this.cksum = lt(t, e + 148, 12), a && this.#i(a, true), h && this.#i(h), ne(n) && (this.#t = n || "0"), this.#t === "0" && this.path.slice(-1) === "/" && (this.#t = "5"), this.#t === "5" && (this.size = 0), this.linkpath = xt(t, e + 157, 100), t.subarray(e + 257, e + 265).toString() === "ustar\x0000") if (this.uname = h?.uname ?? a?.uname ?? xt(t, e + 265, 32), this.gname = h?.gname ?? a?.gname ?? xt(t, e + 297, 32), this.devmaj = h?.devmaj ?? a?.devmaj ?? lt(t, e + 329, 8) ?? 0, this.devmin = h?.devmin ?? a?.devmin ?? lt(t, e + 337, 8) ?? 0, t[e + 475] !== 0) {
|
|
2100
|
+
let c = xt(t, e + 345, 155);
|
|
2101
|
+
this.path = c + "/" + this.path;
|
|
2102
|
+
} else {
|
|
2103
|
+
let c = xt(t, e + 345, 130);
|
|
2104
|
+
c && (this.path = c + "/" + this.path), this.atime = i?.atime ?? r?.atime ?? Wi(t, e + 476, 12), this.ctime = i?.ctime ?? r?.ctime ?? Wi(t, e + 488, 12);
|
|
2105
|
+
}
|
|
2106
|
+
let l = 256;
|
|
2107
|
+
for (let c = e; c < e + 148; c++) l += t[c];
|
|
2108
|
+
for (let c = e + 156; c < e + 512; c++) l += t[c];
|
|
2109
|
+
this.cksumValid = l === this.cksum, this.cksum === void 0 && l === 256 && (this.nullBlock = true);
|
|
2110
|
+
}
|
|
2111
|
+
#i(t, e = false) {
|
|
2112
|
+
Object.assign(this, Object.fromEntries(Object.entries(t).filter(([i, r]) => !(r == null || i === "size" && Number(r) < 0 || i === "path" && e || i === "linkpath" && e || i === "global"))));
|
|
2113
|
+
}
|
|
2114
|
+
encode(t, e = 0) {
|
|
2115
|
+
if (t || (t = this.block = Buffer.alloc(512)), this.#t === "Unsupported" && (this.#t = "0"), !(t.length >= e + 512)) throw new Error("need 512 bytes for header");
|
|
2116
|
+
let i = this.ctime || this.atime ? 130 : 155, r = mn(this.path || "", i), n = r[0], o = r[1];
|
|
2117
|
+
this.needPax = !!r[2], this.needPax = Lt(t, e, 100, n) || this.needPax, this.needPax = ct(t, e + 100, 8, this.mode) || this.needPax, this.needPax = ct(t, e + 108, 8, this.uid) || this.needPax, this.needPax = ct(t, e + 116, 8, this.gid) || this.needPax, this.needPax = ct(t, e + 124, 12, this.size) || this.needPax, this.needPax = Gi(t, e + 136, 12, this.mtime) || this.needPax, t[e + 156] = Number(this.#t.codePointAt(0)), this.needPax = Lt(t, e + 157, 100, this.linkpath) || this.needPax, t.write("ustar\x0000", e + 257, 8), this.needPax = Lt(t, e + 265, 32, this.uname) || this.needPax, this.needPax = Lt(t, e + 297, 32, this.gname) || this.needPax, this.needPax = ct(t, e + 329, 8, this.devmaj) || this.needPax, this.needPax = ct(t, e + 337, 8, this.devmin) || this.needPax, this.needPax = Lt(t, e + 345, i, o) || this.needPax, t[e + 475] !== 0 ? this.needPax = Lt(t, e + 345, 155, o) || this.needPax : (this.needPax = Lt(t, e + 345, 130, o) || this.needPax, this.needPax = Gi(t, e + 476, 12, this.atime) || this.needPax, this.needPax = Gi(t, e + 488, 12, this.ctime) || this.needPax);
|
|
2118
|
+
let h = 256;
|
|
2119
|
+
for (let a = e; a < e + 148; a++) h += t[a];
|
|
2120
|
+
for (let a = e + 156; a < e + 512; a++) h += t[a];
|
|
2121
|
+
return this.cksum = h, ct(t, e + 148, 8, this.cksum), this.cksumValid = true, this.needPax;
|
|
2122
|
+
}
|
|
2123
|
+
get type() {
|
|
2124
|
+
return this.#t === "Unsupported" ? this.#t : oe.get(this.#t);
|
|
2125
|
+
}
|
|
2126
|
+
get typeKey() {
|
|
2127
|
+
return this.#t;
|
|
2128
|
+
}
|
|
2129
|
+
set type(t) {
|
|
2130
|
+
let e = String(Ve.get(t));
|
|
2131
|
+
if (ne(e) || e === "Unsupported") this.#t = e;
|
|
2132
|
+
else if (ne(t)) this.#t = t;
|
|
2133
|
+
else throw new TypeError("invalid entry type: " + t);
|
|
2134
|
+
}
|
|
2135
|
+
};
|
|
2136
|
+
var mn = (s3, t) => {
|
|
2137
|
+
let i = s3, r = "", n, o = Zt.parse(s3).root || ".";
|
|
2138
|
+
if (Buffer.byteLength(i) < 100) n = [i, r, false];
|
|
2139
|
+
else {
|
|
2140
|
+
r = Zt.dirname(i), i = Zt.basename(i);
|
|
2141
|
+
do
|
|
2142
|
+
Buffer.byteLength(i) <= 100 && Buffer.byteLength(r) <= t ? n = [i, r, false] : Buffer.byteLength(i) > 100 && Buffer.byteLength(r) <= t ? n = [i.slice(0, 99), r, true] : (i = Zt.join(Zt.basename(r), i), r = Zt.dirname(r));
|
|
2143
|
+
while (r !== o && n === void 0);
|
|
2144
|
+
n || (n = [s3.slice(0, 99), "", true]);
|
|
2145
|
+
}
|
|
2146
|
+
return n;
|
|
2147
|
+
};
|
|
2148
|
+
var xt = (s3, t, e) => s3.subarray(t, t + e).toString("utf8").replace(/\0.*/, "");
|
|
2149
|
+
var Wi = (s3, t, e) => pn(lt(s3, t, e));
|
|
2150
|
+
var pn = (s3) => s3 === void 0 ? void 0 : new Date(s3 * 1e3);
|
|
2151
|
+
var lt = (s3, t, e) => Number(s3[t]) & 128 ? Hs(s3.subarray(t, t + e)) : wn(s3, t, e);
|
|
2152
|
+
var En = (s3) => isNaN(s3) ? void 0 : s3;
|
|
2153
|
+
var wn = (s3, t, e) => En(parseInt(s3.subarray(t, t + e).toString("utf8").replace(/\0.*$/, "").trim(), 8));
|
|
2154
|
+
var Sn = { 12: 8589934591, 8: 2097151 };
|
|
2155
|
+
var ct = (s3, t, e, i) => i === void 0 ? false : i > Sn[e] || i < 0 ? (Us(i, s3.subarray(t, t + e)), true) : (yn(s3, t, e, i), false);
|
|
2156
|
+
var yn = (s3, t, e, i) => s3.write(Rn(i, e), t, e, "ascii");
|
|
2157
|
+
var Rn = (s3, t) => gn(Math.floor(s3).toString(8), t);
|
|
2158
|
+
var gn = (s3, t) => (s3.length === t - 1 ? s3 : new Array(t - s3.length - 1).join("0") + s3 + " ") + "\0";
|
|
2159
|
+
var Gi = (s3, t, e, i) => i === void 0 ? false : ct(s3, t, e, i.getTime() / 1e3);
|
|
2160
|
+
var bn = new Array(156).join("\0");
|
|
2161
|
+
var Lt = (s3, t, e, i) => i === void 0 ? false : (s3.write(i + bn, t, e, "utf8"), i.length !== Buffer.byteLength(i) || i.length > e);
|
|
2162
|
+
var ft = class s {
|
|
2163
|
+
atime;
|
|
2164
|
+
mtime;
|
|
2165
|
+
ctime;
|
|
2166
|
+
charset;
|
|
2167
|
+
comment;
|
|
2168
|
+
gid;
|
|
2169
|
+
uid;
|
|
2170
|
+
gname;
|
|
2171
|
+
uname;
|
|
2172
|
+
linkpath;
|
|
2173
|
+
dev;
|
|
2174
|
+
ino;
|
|
2175
|
+
nlink;
|
|
2176
|
+
path;
|
|
2177
|
+
size;
|
|
2178
|
+
mode;
|
|
2179
|
+
global;
|
|
2180
|
+
constructor(t, e = false) {
|
|
2181
|
+
this.atime = t.atime, this.charset = t.charset, this.comment = t.comment, this.ctime = t.ctime, this.dev = t.dev, this.gid = t.gid, this.global = e, this.gname = t.gname, this.ino = t.ino, this.linkpath = t.linkpath, this.mtime = t.mtime, this.nlink = t.nlink, this.path = t.path, this.size = t.size, this.uid = t.uid, this.uname = t.uname;
|
|
2182
|
+
}
|
|
2183
|
+
encode() {
|
|
2184
|
+
let t = this.encodeBody();
|
|
2185
|
+
if (t === "") return Buffer.allocUnsafe(0);
|
|
2186
|
+
let e = Buffer.byteLength(t), i = 512 * Math.ceil(1 + e / 512), r = Buffer.allocUnsafe(i);
|
|
2187
|
+
for (let n = 0; n < 512; n++) r[n] = 0;
|
|
2188
|
+
new F({ path: ("PaxHeader/" + _n(this.path ?? "")).slice(0, 99), mode: this.mode || 420, uid: this.uid, gid: this.gid, size: e, mtime: this.mtime, type: this.global ? "GlobalExtendedHeader" : "ExtendedHeader", linkpath: "", uname: this.uname || "", gname: this.gname || "", devmaj: 0, devmin: 0, atime: this.atime, ctime: this.ctime }).encode(r), r.write(t, 512, e, "utf8");
|
|
2189
|
+
for (let n = e + 512; n < r.length; n++) r[n] = 0;
|
|
2190
|
+
return r;
|
|
2191
|
+
}
|
|
2192
|
+
encodeBody() {
|
|
2193
|
+
return this.encodeField("path") + this.encodeField("ctime") + this.encodeField("atime") + this.encodeField("dev") + this.encodeField("ino") + this.encodeField("nlink") + this.encodeField("charset") + this.encodeField("comment") + this.encodeField("gid") + this.encodeField("gname") + this.encodeField("linkpath") + this.encodeField("mtime") + this.encodeField("size") + this.encodeField("uid") + this.encodeField("uname");
|
|
2194
|
+
}
|
|
2195
|
+
encodeField(t) {
|
|
2196
|
+
if (this[t] === void 0) return "";
|
|
2197
|
+
let e = this[t], i = e instanceof Date ? e.getTime() / 1e3 : e, r = " " + (t === "dev" || t === "ino" || t === "nlink" ? "SCHILY." : "") + t + "=" + i + `
|
|
2198
|
+
`, n = Buffer.byteLength(r), o = Math.floor(Math.log(n) / Math.log(10)) + 1;
|
|
2199
|
+
return n + o >= Math.pow(10, o) && (o += 1), o + n + r;
|
|
2200
|
+
}
|
|
2201
|
+
static parse(t, e, i = false) {
|
|
2202
|
+
return new s(On(Tn(t), e), i);
|
|
2203
|
+
}
|
|
2204
|
+
};
|
|
2205
|
+
var On = (s3, t) => t ? Object.assign({}, t, s3) : s3;
|
|
2206
|
+
var Tn = (s3) => s3.replace(/\n$/, "").split(`
|
|
2207
|
+
`).reduce(xn, /* @__PURE__ */ Object.create(null));
|
|
2208
|
+
var xn = (s3, t) => {
|
|
2209
|
+
let e = parseInt(t, 10);
|
|
2210
|
+
if (e !== Buffer.byteLength(t) + 1) return s3;
|
|
2211
|
+
t = t.slice((e + " ").length);
|
|
2212
|
+
let i = t.split("="), r = i.shift();
|
|
2213
|
+
if (!r) return s3;
|
|
2214
|
+
let n = r.replace(/^SCHILY\.(dev|ino|nlink)/, "$1"), o = i.join("=").replace(/\0.*/, "");
|
|
2215
|
+
switch (n) {
|
|
2216
|
+
case "path":
|
|
2217
|
+
case "linkpath":
|
|
2218
|
+
case "type":
|
|
2219
|
+
case "charset":
|
|
2220
|
+
case "comment":
|
|
2221
|
+
case "gname":
|
|
2222
|
+
case "uname":
|
|
2223
|
+
s3[n] = o;
|
|
2224
|
+
break;
|
|
2225
|
+
case "ctime":
|
|
2226
|
+
case "atime":
|
|
2227
|
+
case "mtime":
|
|
2228
|
+
s3[n] = new Date(Number(o) * 1e3);
|
|
2229
|
+
break;
|
|
2230
|
+
case "size":
|
|
2231
|
+
let h = +o;
|
|
2232
|
+
h >= 0 && (s3[n] = h);
|
|
2233
|
+
break;
|
|
2234
|
+
case "gid":
|
|
2235
|
+
case "uid":
|
|
2236
|
+
case "dev":
|
|
2237
|
+
case "ino":
|
|
2238
|
+
case "nlink":
|
|
2239
|
+
case "mode":
|
|
2240
|
+
s3[n] = +o;
|
|
2241
|
+
break;
|
|
2242
|
+
}
|
|
2243
|
+
return s3;
|
|
2244
|
+
};
|
|
2245
|
+
var Ln = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform;
|
|
2246
|
+
var f = Ln !== "win32" ? (s3) => String(s3) : (s3) => String(s3).replaceAll(/\\/g, "/");
|
|
2247
|
+
var $e = class extends A {
|
|
2248
|
+
extended;
|
|
2249
|
+
globalExtended;
|
|
2250
|
+
header;
|
|
2251
|
+
startBlockSize;
|
|
2252
|
+
blockRemain;
|
|
2253
|
+
remain;
|
|
2254
|
+
type;
|
|
2255
|
+
meta = false;
|
|
2256
|
+
ignore = false;
|
|
2257
|
+
path;
|
|
2258
|
+
mode;
|
|
2259
|
+
uid;
|
|
2260
|
+
gid;
|
|
2261
|
+
uname;
|
|
2262
|
+
gname;
|
|
2263
|
+
size = 0;
|
|
2264
|
+
mtime;
|
|
2265
|
+
atime;
|
|
2266
|
+
ctime;
|
|
2267
|
+
linkpath;
|
|
2268
|
+
dev;
|
|
2269
|
+
ino;
|
|
2270
|
+
nlink;
|
|
2271
|
+
invalid = false;
|
|
2272
|
+
absolute;
|
|
2273
|
+
unsupported = false;
|
|
2274
|
+
constructor(t, e, i) {
|
|
2275
|
+
switch (super({}), this.pause(), this.extended = e, this.globalExtended = i, this.header = t, this.remain = t.size ?? 0, this.startBlockSize = 512 * Math.ceil(this.remain / 512), this.blockRemain = this.startBlockSize, this.type = t.type, this.type) {
|
|
2276
|
+
case "File":
|
|
2277
|
+
case "OldFile":
|
|
2278
|
+
case "Link":
|
|
2279
|
+
case "SymbolicLink":
|
|
2280
|
+
case "CharacterDevice":
|
|
2281
|
+
case "BlockDevice":
|
|
2282
|
+
case "Directory":
|
|
2283
|
+
case "FIFO":
|
|
2284
|
+
case "ContiguousFile":
|
|
2285
|
+
case "GNUDumpDir":
|
|
2286
|
+
break;
|
|
2287
|
+
case "NextFileHasLongLinkpath":
|
|
2288
|
+
case "NextFileHasLongPath":
|
|
2289
|
+
case "OldGnuLongPath":
|
|
2290
|
+
case "GlobalExtendedHeader":
|
|
2291
|
+
case "ExtendedHeader":
|
|
2292
|
+
case "OldExtendedHeader":
|
|
2293
|
+
this.meta = true;
|
|
2294
|
+
break;
|
|
2295
|
+
default:
|
|
2296
|
+
this.ignore = true;
|
|
2297
|
+
}
|
|
2298
|
+
if (!t.path) throw new Error("no path provided for tar.ReadEntry");
|
|
2299
|
+
this.path = f(t.path), this.mode = t.mode, this.mode && (this.mode = this.mode & 4095), this.uid = t.uid, this.gid = t.gid, this.uname = t.uname, this.gname = t.gname, this.size = this.remain, this.mtime = t.mtime, this.atime = t.atime, this.ctime = t.ctime, this.linkpath = t.linkpath ? f(t.linkpath) : void 0, this.uname = t.uname, this.gname = t.gname, e && this.#t(e), i && this.#t(i, true);
|
|
2300
|
+
}
|
|
2301
|
+
write(t) {
|
|
2302
|
+
let e = t.length;
|
|
2303
|
+
if (e > this.blockRemain) throw new Error("writing more to entry than is appropriate");
|
|
2304
|
+
let i = this.remain, r = this.blockRemain;
|
|
2305
|
+
return this.remain = Math.max(0, i - e), this.blockRemain = Math.max(0, r - e), this.ignore ? true : i >= e ? super.write(t) : super.write(t.subarray(0, i));
|
|
2306
|
+
}
|
|
2307
|
+
#t(t, e = false) {
|
|
2308
|
+
t.path && (t.path = f(t.path)), t.linkpath && (t.linkpath = f(t.linkpath)), Object.assign(this, Object.fromEntries(Object.entries(t).filter(([i, r]) => !(r == null || i === "path" && e))));
|
|
2309
|
+
}
|
|
2310
|
+
};
|
|
2311
|
+
var Dt = (s3, t, e, i = {}) => {
|
|
2312
|
+
s3.file && (i.file = s3.file), s3.cwd && (i.cwd = s3.cwd), i.code = e instanceof Error && e.code || t, i.tarCode = t, !s3.strict && i.recoverable !== false ? (e instanceof Error && (i = Object.assign(e, i), e = e.message), s3.emit("warn", t, e, i)) : e instanceof Error ? s3.emit("error", Object.assign(e, i)) : s3.emit("error", Object.assign(new Error(`${t}: ${e}`), i));
|
|
2313
|
+
};
|
|
2314
|
+
var Nn = 1024 * 1024;
|
|
2315
|
+
var Xi = Buffer.from([31, 139]);
|
|
2316
|
+
var qi = Buffer.from([40, 181, 47, 253]);
|
|
2317
|
+
var An = Math.max(Xi.length, qi.length);
|
|
2318
|
+
var B = /* @__PURE__ */ Symbol("state");
|
|
2319
|
+
var Nt = /* @__PURE__ */ Symbol("writeEntry");
|
|
2320
|
+
var it = /* @__PURE__ */ Symbol("readEntry");
|
|
2321
|
+
var Zi = /* @__PURE__ */ Symbol("nextEntry");
|
|
2322
|
+
var Zs = /* @__PURE__ */ Symbol("processEntry");
|
|
2323
|
+
var V = /* @__PURE__ */ Symbol("extendedHeader");
|
|
2324
|
+
var he = /* @__PURE__ */ Symbol("globalExtendedHeader");
|
|
2325
|
+
var dt = /* @__PURE__ */ Symbol("meta");
|
|
2326
|
+
var Ys = /* @__PURE__ */ Symbol("emitMeta");
|
|
2327
|
+
var p = /* @__PURE__ */ Symbol("buffer");
|
|
2328
|
+
var st = /* @__PURE__ */ Symbol("queue");
|
|
2329
|
+
var ut = /* @__PURE__ */ Symbol("ended");
|
|
2330
|
+
var Yi = /* @__PURE__ */ Symbol("emittedEnd");
|
|
2331
|
+
var At = /* @__PURE__ */ Symbol("emit");
|
|
2332
|
+
var w = /* @__PURE__ */ Symbol("unzip");
|
|
2333
|
+
var Xe = /* @__PURE__ */ Symbol("consumeChunk");
|
|
2334
|
+
var qe = /* @__PURE__ */ Symbol("consumeChunkSub");
|
|
2335
|
+
var Ki = /* @__PURE__ */ Symbol("consumeBody");
|
|
2336
|
+
var Ks = /* @__PURE__ */ Symbol("consumeMeta");
|
|
2337
|
+
var Vs = /* @__PURE__ */ Symbol("consumeHeader");
|
|
2338
|
+
var ae = /* @__PURE__ */ Symbol("consuming");
|
|
2339
|
+
var Vi = /* @__PURE__ */ Symbol("bufferConcat");
|
|
2340
|
+
var Qe = /* @__PURE__ */ Symbol("maybeEnd");
|
|
2341
|
+
var Yt = /* @__PURE__ */ Symbol("writing");
|
|
2342
|
+
var $ = /* @__PURE__ */ Symbol("aborted");
|
|
2343
|
+
var Je = /* @__PURE__ */ Symbol("onDone");
|
|
2344
|
+
var It = /* @__PURE__ */ Symbol("sawValidEntry");
|
|
2345
|
+
var je = /* @__PURE__ */ Symbol("sawNullBlock");
|
|
2346
|
+
var ti = /* @__PURE__ */ Symbol("sawEOF");
|
|
2347
|
+
var $s = /* @__PURE__ */ Symbol("closeStream");
|
|
2348
|
+
var In = 1e3;
|
|
2349
|
+
var le = /* @__PURE__ */ Symbol("compressedBytesRead");
|
|
2350
|
+
var $i = /* @__PURE__ */ Symbol("decompressedBytesRead");
|
|
2351
|
+
var Xs = /* @__PURE__ */ Symbol("checkDecompressionRatio");
|
|
2352
|
+
var Cn = () => true;
|
|
2353
|
+
var rt = class extends Dn {
|
|
2354
|
+
file;
|
|
2355
|
+
strict;
|
|
2356
|
+
maxMetaEntrySize;
|
|
2357
|
+
filter;
|
|
2358
|
+
brotli;
|
|
2359
|
+
zstd;
|
|
2360
|
+
maxDecompressionRatio;
|
|
2361
|
+
writable = true;
|
|
2362
|
+
readable = false;
|
|
2363
|
+
[st] = [];
|
|
2364
|
+
[p];
|
|
2365
|
+
[it];
|
|
2366
|
+
[Nt];
|
|
2367
|
+
[B] = "begin";
|
|
2368
|
+
[dt] = "";
|
|
2369
|
+
[V];
|
|
2370
|
+
[he];
|
|
2371
|
+
[ut] = false;
|
|
2372
|
+
[w];
|
|
2373
|
+
[$] = false;
|
|
2374
|
+
[It];
|
|
2375
|
+
[je] = false;
|
|
2376
|
+
[ti] = false;
|
|
2377
|
+
[Yt] = false;
|
|
2378
|
+
[ae] = false;
|
|
2379
|
+
[Yi] = false;
|
|
2380
|
+
[le] = 0;
|
|
2381
|
+
[$i] = 0;
|
|
2382
|
+
constructor(t = {}) {
|
|
2383
|
+
super(), this.file = t.file || "", this.on(Je, () => {
|
|
2384
|
+
(this[B] === "begin" || this[It] === false) && this.warn("TAR_BAD_ARCHIVE", "Unrecognized archive format");
|
|
2385
|
+
}), t.ondone ? this.on(Je, t.ondone) : this.on(Je, () => {
|
|
2386
|
+
this.emit("prefinish"), this.emit("finish"), this.emit("end");
|
|
2387
|
+
}), this.strict = !!t.strict, this.maxDecompressionRatio = typeof t.maxDecompressionRatio == "number" ? t.maxDecompressionRatio : In, this.maxMetaEntrySize = t.maxMetaEntrySize || Nn, this.filter = typeof t.filter == "function" ? t.filter : Cn;
|
|
2388
|
+
let e = t.file && (t.file.endsWith(".tar.br") || t.file.endsWith(".tbr"));
|
|
2389
|
+
this.brotli = !(t.gzip || t.zstd) && t.brotli !== void 0 ? t.brotli : e ? void 0 : false;
|
|
2390
|
+
let i = t.file && (t.file.endsWith(".tar.zst") || t.file.endsWith(".tzst"));
|
|
2391
|
+
this.zstd = !(t.gzip || t.brotli) && t.zstd !== void 0 ? t.zstd : i ? true : void 0, this.on("end", () => this[$s]()), typeof t.onwarn == "function" && this.on("warn", t.onwarn), typeof t.onReadEntry == "function" && this.on("entry", t.onReadEntry);
|
|
2392
|
+
}
|
|
2393
|
+
warn(t, e, i = {}) {
|
|
2394
|
+
Dt(this, t, e, i);
|
|
2395
|
+
}
|
|
2396
|
+
[Vs](t, e) {
|
|
2397
|
+
this[It] === void 0 && (this[It] = false);
|
|
2398
|
+
let i;
|
|
2399
|
+
try {
|
|
2400
|
+
i = new F(t, e, this[V], this[he]);
|
|
2401
|
+
} catch (r) {
|
|
2402
|
+
return this.warn("TAR_ENTRY_INVALID", r);
|
|
2403
|
+
}
|
|
2404
|
+
if (i.nullBlock) this[je] ? (this[ti] = true, this[B] === "begin" && (this[B] = "header"), this[At]("eof")) : (this[je] = true, this[At]("nullBlock"));
|
|
2405
|
+
else if (this[je] = false, !i.cksumValid) this.warn("TAR_ENTRY_INVALID", "checksum failure", { header: i });
|
|
2406
|
+
else if (!i.path) this.warn("TAR_ENTRY_INVALID", "path is required", { header: i });
|
|
2407
|
+
else {
|
|
2408
|
+
let r = i.type;
|
|
2409
|
+
if (/^(Symbolic)?Link$/.test(r) && !i.linkpath) this.warn("TAR_ENTRY_INVALID", "linkpath required", { header: i });
|
|
2410
|
+
else if (!/^(Symbolic)?Link$/.test(r) && !/^(Global)?ExtendedHeader$/.test(r) && i.linkpath) this.warn("TAR_ENTRY_INVALID", "linkpath forbidden", { header: i });
|
|
2411
|
+
else {
|
|
2412
|
+
let n = this[Nt] = new $e(i, this[V], this[he]);
|
|
2413
|
+
if (!this[It]) if (n.remain) {
|
|
2414
|
+
let o = () => {
|
|
2415
|
+
n.invalid || (this[It] = true);
|
|
2416
|
+
};
|
|
2417
|
+
n.on("end", o);
|
|
2418
|
+
} else this[It] = true;
|
|
2419
|
+
n.meta ? n.size > this.maxMetaEntrySize ? (n.ignore = true, this[At]("ignoredEntry", n), this[B] = "ignore", n.resume()) : n.size > 0 && (this[dt] = "", n.on("data", (o) => this[dt] += o), this[B] = "meta") : (this[V] = void 0, n.ignore = n.ignore || !this.filter(n.path, n), n.ignore ? (this[At]("ignoredEntry", n), this[B] = n.remain ? "ignore" : "header", n.resume()) : (n.remain ? this[B] = "body" : (this[B] = "header", n.end()), this[it] ? this[st].push(n) : (this[st].push(n), this[Zi]())));
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
[$s]() {
|
|
2424
|
+
queueMicrotask(() => this.emit("close"));
|
|
2425
|
+
}
|
|
2426
|
+
[Zs](t) {
|
|
2427
|
+
let e = true;
|
|
2428
|
+
if (!t) this[it] = void 0, e = false;
|
|
2429
|
+
else if (Array.isArray(t)) {
|
|
2430
|
+
let [i, ...r] = t;
|
|
2431
|
+
this.emit(i, ...r);
|
|
2432
|
+
} else this[it] = t, this.emit("entry", t), t.emittedEnd || (t.on("end", () => this[Zi]()), e = false);
|
|
2433
|
+
return e;
|
|
2434
|
+
}
|
|
2435
|
+
[Zi]() {
|
|
2436
|
+
do
|
|
2437
|
+
;
|
|
2438
|
+
while (this[Zs](this[st].shift()));
|
|
2439
|
+
if (this[st].length === 0) {
|
|
2440
|
+
let t = this[it];
|
|
2441
|
+
!t || t.flowing || t.size === t.remain ? this[Yt] || this.emit("drain") : t.once("drain", () => this.emit("drain"));
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
[Ki](t, e) {
|
|
2445
|
+
let i = this[Nt];
|
|
2446
|
+
if (!i) throw new Error("attempt to consume body without entry??");
|
|
2447
|
+
let r = i.blockRemain ?? 0, n = r >= t.length && e === 0 ? t : t.subarray(e, e + r);
|
|
2448
|
+
return i.write(n), i.blockRemain || (this[B] = "header", this[Nt] = void 0, i.end()), n.length;
|
|
2449
|
+
}
|
|
2450
|
+
[Ks](t, e) {
|
|
2451
|
+
let i = this[Nt], r = this[Ki](t, e);
|
|
2452
|
+
return !this[Nt] && i && this[Ys](i), r;
|
|
2453
|
+
}
|
|
2454
|
+
[At](t, e, i) {
|
|
2455
|
+
this[st].length === 0 && !this[it] ? this.emit(t, e, i) : this[st].push([t, e, i]);
|
|
2456
|
+
}
|
|
2457
|
+
[Ys](t) {
|
|
2458
|
+
switch (this[At]("meta", this[dt]), t.type) {
|
|
2459
|
+
case "ExtendedHeader":
|
|
2460
|
+
case "OldExtendedHeader":
|
|
2461
|
+
this[V] = ft.parse(this[dt], this[V], false);
|
|
2462
|
+
break;
|
|
2463
|
+
case "GlobalExtendedHeader":
|
|
2464
|
+
this[he] = ft.parse(this[dt], this[he], true);
|
|
2465
|
+
break;
|
|
2466
|
+
case "NextFileHasLongPath":
|
|
2467
|
+
case "OldGnuLongPath": {
|
|
2468
|
+
let e = this[V] ?? /* @__PURE__ */ Object.create(null);
|
|
2469
|
+
this[V] = e, e.path = this[dt].replace(/\0.*/, "");
|
|
2470
|
+
break;
|
|
2471
|
+
}
|
|
2472
|
+
case "NextFileHasLongLinkpath": {
|
|
2473
|
+
let e = this[V] || /* @__PURE__ */ Object.create(null);
|
|
2474
|
+
this[V] = e, e.linkpath = this[dt].replace(/\0.*/, "");
|
|
2475
|
+
break;
|
|
2476
|
+
}
|
|
2477
|
+
default:
|
|
2478
|
+
throw new Error("unknown meta: " + t.type);
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
abort(t) {
|
|
2482
|
+
if (!this[$]) {
|
|
2483
|
+
if (this[w]) {
|
|
2484
|
+
let e = this[w];
|
|
2485
|
+
e.write = () => true, e.end = () => e, e.emit = () => false, e.destroy?.();
|
|
2486
|
+
}
|
|
2487
|
+
this[$] = true, this.emit("abort", t), this.warn("TAR_ABORT", t, { recoverable: false });
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
[Xs](t) {
|
|
2491
|
+
this[$i] += t.length;
|
|
2492
|
+
let e = this[$i] / this[le];
|
|
2493
|
+
return e > this.maxDecompressionRatio ? (this.abort(new Error(`max decompression ratio exceeded: ${e.toFixed(2)} > ${this.maxDecompressionRatio}`)), false) : true;
|
|
2494
|
+
}
|
|
2495
|
+
write(t, e, i) {
|
|
2496
|
+
if (typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, typeof e == "string" ? e : "utf8")), this[$]) return i?.(), false;
|
|
2497
|
+
if ((this[w] === void 0 || this.brotli === void 0 && this[w] === false) && t) {
|
|
2498
|
+
if (this[p] && (t = Buffer.concat([this[p], t]), this[p] = void 0), t.length < An) return this[p] = t, i?.(), true;
|
|
2499
|
+
for (let a = 0; this[w] === void 0 && a < Xi.length; a++) t[a] !== Xi[a] && (this[w] = false);
|
|
2500
|
+
let o = false;
|
|
2501
|
+
if (this[w] === false && this.zstd !== false) {
|
|
2502
|
+
o = true;
|
|
2503
|
+
for (let a = 0; a < qi.length; a++) if (t[a] !== qi[a]) {
|
|
2504
|
+
o = false;
|
|
2505
|
+
break;
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
let h = this.brotli === void 0 && !o;
|
|
2509
|
+
if (this[w] === false && h) if (t.length < 512) if (this[ut]) this.brotli = true;
|
|
2510
|
+
else return this[p] = t, i?.(), true;
|
|
2511
|
+
else try {
|
|
2512
|
+
new F(t.subarray(0, 512)), this.brotli = false;
|
|
2513
|
+
} catch {
|
|
2514
|
+
this.brotli = true;
|
|
2515
|
+
}
|
|
2516
|
+
if (this[w] === void 0 || this[w] === false && (this.brotli || o)) {
|
|
2517
|
+
let a = this[ut];
|
|
2518
|
+
this[ut] = false, this[w] = this[w] === void 0 ? new Ue({}) : o ? new Ke({}) : new Ge({}), this[w].on("data", (c) => {
|
|
2519
|
+
this[Xs](c) && this[Xe](c);
|
|
2520
|
+
}), this[w].on("error", (c) => {
|
|
2521
|
+
this[$] || this.abort(c);
|
|
2522
|
+
}), this[w].on("end", () => {
|
|
2523
|
+
this[ut] = true, this[Xe]();
|
|
2524
|
+
}), this[Yt] = true, this[le] += t.length;
|
|
2525
|
+
let l = !!this[w][a ? "end" : "write"](t);
|
|
2526
|
+
return this[Yt] = false, i?.(), l;
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
this[Yt] = true, this[w] ? (this[le] += t.length, this[w].write(t)) : this[Xe](t), this[Yt] = false;
|
|
2530
|
+
let n = this[st].length > 0 ? false : this[it] ? this[it].flowing : true;
|
|
2531
|
+
return !n && this[st].length === 0 && this[it]?.once("drain", () => this.emit("drain")), i?.(), n;
|
|
2532
|
+
}
|
|
2533
|
+
[Vi](t) {
|
|
2534
|
+
t && !this[$] && (this[p] = this[p] ? Buffer.concat([this[p], t]) : t);
|
|
2535
|
+
}
|
|
2536
|
+
[Qe]() {
|
|
2537
|
+
if (this[ut] && !this[Yi] && !this[$] && !this[ae]) {
|
|
2538
|
+
this[Yi] = true;
|
|
2539
|
+
let t = this[Nt];
|
|
2540
|
+
if (t?.blockRemain) {
|
|
2541
|
+
let e = this[p] ? this[p].length : 0;
|
|
2542
|
+
this.warn("TAR_BAD_ARCHIVE", `Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`, { entry: t }), this[p] && t.write(this[p]), t.end();
|
|
2543
|
+
}
|
|
2544
|
+
this[At](Je);
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
[Xe](t) {
|
|
2548
|
+
if (this[ae] && t) this[Vi](t);
|
|
2549
|
+
else if (!t && !this[p]) this[Qe]();
|
|
2550
|
+
else if (t) {
|
|
2551
|
+
if (this[ae] = true, this[p]) {
|
|
2552
|
+
this[Vi](t);
|
|
2553
|
+
let e = this[p];
|
|
2554
|
+
this[p] = void 0, this[qe](e);
|
|
2555
|
+
} else this[qe](t);
|
|
2556
|
+
for (; this[p] && this[p]?.length >= 512 && !this[$] && !this[ti]; ) {
|
|
2557
|
+
let e = this[p];
|
|
2558
|
+
this[p] = void 0, this[qe](e);
|
|
2559
|
+
}
|
|
2560
|
+
this[ae] = false;
|
|
2561
|
+
}
|
|
2562
|
+
(!this[p] || this[ut]) && this[Qe]();
|
|
2563
|
+
}
|
|
2564
|
+
[qe](t) {
|
|
2565
|
+
let e = 0, i = t.length;
|
|
2566
|
+
for (; e + 512 <= i && !this[$] && !this[ti]; ) switch (this[B]) {
|
|
2567
|
+
case "begin":
|
|
2568
|
+
case "header":
|
|
2569
|
+
this[Vs](t, e), e += 512;
|
|
2570
|
+
break;
|
|
2571
|
+
case "ignore":
|
|
2572
|
+
case "body":
|
|
2573
|
+
e += this[Ki](t, e);
|
|
2574
|
+
break;
|
|
2575
|
+
case "meta":
|
|
2576
|
+
e += this[Ks](t, e);
|
|
2577
|
+
break;
|
|
2578
|
+
default:
|
|
2579
|
+
throw new Error("invalid state: " + this[B]);
|
|
2580
|
+
}
|
|
2581
|
+
e < i && (this[p] = this[p] ? Buffer.concat([t.subarray(e), this[p]]) : t.subarray(e));
|
|
2582
|
+
}
|
|
2583
|
+
end(t, e, i) {
|
|
2584
|
+
return typeof t == "function" && (i = t, e = void 0, t = void 0), typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, e)), i && this.once("finish", i), this[$] || (this[w] ? (t && (this[le] += t.length, this[w].write(t)), this[w].end()) : (this[ut] = true, (this.brotli === void 0 || this.zstd === void 0) && (t = t || Buffer.alloc(0)), t && this.write(t), this[Qe]())), this;
|
|
2585
|
+
}
|
|
2586
|
+
};
|
|
2587
|
+
var mt = (s3) => {
|
|
2588
|
+
let t = s3.length - 1, e = -1;
|
|
2589
|
+
for (; t > -1 && s3.charAt(t) === "/"; ) e = t, t--;
|
|
2590
|
+
return e === -1 ? s3 : s3.slice(0, e);
|
|
2591
|
+
};
|
|
2592
|
+
var vn = (s3) => {
|
|
2593
|
+
let t = s3.onReadEntry;
|
|
2594
|
+
s3.onReadEntry = t ? (e) => {
|
|
2595
|
+
t(e), e.resume();
|
|
2596
|
+
} : (e) => e.resume();
|
|
2597
|
+
};
|
|
2598
|
+
var Qi = (s3, t) => {
|
|
2599
|
+
let e = new Map(t.map((o) => [mt(o), true])), i = s3.filter, r = 100, n = (o, h = "", a = 0) => {
|
|
2600
|
+
if (a >= r) return e.set(o, false), false;
|
|
2601
|
+
let l = h || kn(o).root || ".", c;
|
|
2602
|
+
if (o === l) c = false;
|
|
2603
|
+
else {
|
|
2604
|
+
let d = e.get(o);
|
|
2605
|
+
c = d !== void 0 ? d : n(Fn(o), l, a + 1);
|
|
2606
|
+
}
|
|
2607
|
+
return e.set(o, c), c;
|
|
2608
|
+
};
|
|
2609
|
+
s3.filter = i ? (o, h) => i(o, h) && n(mt(o)) : (o) => n(mt(o));
|
|
2610
|
+
};
|
|
2611
|
+
var Mn = (s3) => {
|
|
2612
|
+
let t = new rt(s3), e = s3.file, i;
|
|
2613
|
+
try {
|
|
2614
|
+
i = Kt.openSync(e, "r");
|
|
2615
|
+
let r = Kt.fstatSync(i), n = s3.maxReadSize || 16 * 1024 * 1024;
|
|
2616
|
+
if (r.size < n) {
|
|
2617
|
+
let o = Buffer.allocUnsafe(r.size), h = Kt.readSync(i, o, 0, r.size, 0);
|
|
2618
|
+
t.end(h === o.byteLength ? o : o.subarray(0, h));
|
|
2619
|
+
} else {
|
|
2620
|
+
let o = 0, h = Buffer.allocUnsafe(n);
|
|
2621
|
+
for (; o < r.size; ) {
|
|
2622
|
+
let a = Kt.readSync(i, h, 0, n, o);
|
|
2623
|
+
if (a === 0) break;
|
|
2624
|
+
o += a, t.write(h.subarray(0, a));
|
|
2625
|
+
}
|
|
2626
|
+
t.end();
|
|
2627
|
+
}
|
|
2628
|
+
} finally {
|
|
2629
|
+
if (typeof i == "number") try {
|
|
2630
|
+
Kt.closeSync(i);
|
|
2631
|
+
} catch {
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
};
|
|
2635
|
+
var Bn = (s3, t) => {
|
|
2636
|
+
let e = new rt(s3), i = s3.maxReadSize || 16 * 1024 * 1024, r = s3.file;
|
|
2637
|
+
return new Promise((o, h) => {
|
|
2638
|
+
e.on("error", h), e.on("end", o), Kt.stat(r, (a, l) => {
|
|
2639
|
+
if (a) h(a);
|
|
2640
|
+
else {
|
|
2641
|
+
let c = new _t(r, { readSize: i, size: l.size });
|
|
2642
|
+
c.on("error", h), c.pipe(e);
|
|
2643
|
+
}
|
|
2644
|
+
});
|
|
2645
|
+
});
|
|
2646
|
+
};
|
|
2647
|
+
var Ct = K(Mn, Bn, (s3) => new rt(s3), (s3) => new rt(s3), (s3, t) => {
|
|
2648
|
+
t?.length && Qi(s3, t), s3.noResume || vn(s3);
|
|
2649
|
+
});
|
|
2650
|
+
var Ji = (s3, t, e) => (s3 &= 4095, e && (s3 = (s3 | 384) & -19), t && (s3 & 256 && (s3 |= 64), s3 & 32 && (s3 |= 8), s3 & 4 && (s3 |= 1)), s3);
|
|
2651
|
+
var { isAbsolute: zn, parse: qs } = Pn;
|
|
2652
|
+
var ce = (s3) => {
|
|
2653
|
+
let t = "", e = qs(s3);
|
|
2654
|
+
for (; zn(s3) || e.root; ) {
|
|
2655
|
+
let i = s3.charAt(0) === "/" && s3.slice(0, 4) !== "//?/" ? "/" : e.root;
|
|
2656
|
+
s3 = s3.slice(i.length), t += i, e = qs(s3);
|
|
2657
|
+
}
|
|
2658
|
+
return [t, s3];
|
|
2659
|
+
};
|
|
2660
|
+
var ei = ["|", "<", ">", "?", ":"];
|
|
2661
|
+
var ji = ei.map((s3) => String.fromCodePoint(61440 + Number(s3.codePointAt(0))));
|
|
2662
|
+
var Un = new Map(ei.map((s3, t) => [s3, ji[t]]));
|
|
2663
|
+
var Hn = new Map(ji.map((s3, t) => [s3, ei[t]]));
|
|
2664
|
+
var ts = (s3) => ei.reduce((t, e) => t.split(e).join(Un.get(e)), s3);
|
|
2665
|
+
var Qs = (s3) => ji.reduce((t, e) => t.split(e).join(Hn.get(e)), s3);
|
|
2666
|
+
var rr = (s3, t) => t ? (s3 = f(s3).replace(/^\.(\/|$)/, ""), mt(t) + "/" + s3) : f(s3);
|
|
2667
|
+
var Wn = 16 * 1024 * 1024;
|
|
2668
|
+
var tr = /* @__PURE__ */ Symbol("process");
|
|
2669
|
+
var er = /* @__PURE__ */ Symbol("file");
|
|
2670
|
+
var ir = /* @__PURE__ */ Symbol("directory");
|
|
2671
|
+
var is = /* @__PURE__ */ Symbol("symlink");
|
|
2672
|
+
var sr = /* @__PURE__ */ Symbol("hardlink");
|
|
2673
|
+
var fe = /* @__PURE__ */ Symbol("header");
|
|
2674
|
+
var ii = /* @__PURE__ */ Symbol("read");
|
|
2675
|
+
var ss = /* @__PURE__ */ Symbol("lstat");
|
|
2676
|
+
var si = /* @__PURE__ */ Symbol("onlstat");
|
|
2677
|
+
var rs = /* @__PURE__ */ Symbol("onread");
|
|
2678
|
+
var ns = /* @__PURE__ */ Symbol("onreadlink");
|
|
2679
|
+
var os = /* @__PURE__ */ Symbol("openfile");
|
|
2680
|
+
var hs = /* @__PURE__ */ Symbol("onopenfile");
|
|
2681
|
+
var pt = /* @__PURE__ */ Symbol("close");
|
|
2682
|
+
var ri = /* @__PURE__ */ Symbol("mode");
|
|
2683
|
+
var as = /* @__PURE__ */ Symbol("awaitDrain");
|
|
2684
|
+
var es = /* @__PURE__ */ Symbol("ondrain");
|
|
2685
|
+
var q = /* @__PURE__ */ Symbol("prefix");
|
|
2686
|
+
var de = class extends A {
|
|
2687
|
+
path;
|
|
2688
|
+
portable;
|
|
2689
|
+
myuid = process.getuid && process.getuid() || 0;
|
|
2690
|
+
myuser = process.env.USER || "";
|
|
2691
|
+
maxReadSize;
|
|
2692
|
+
linkCache;
|
|
2693
|
+
statCache;
|
|
2694
|
+
preservePaths;
|
|
2695
|
+
cwd;
|
|
2696
|
+
strict;
|
|
2697
|
+
mtime;
|
|
2698
|
+
noPax;
|
|
2699
|
+
noMtime;
|
|
2700
|
+
prefix;
|
|
2701
|
+
fd;
|
|
2702
|
+
blockLen = 0;
|
|
2703
|
+
blockRemain = 0;
|
|
2704
|
+
buf;
|
|
2705
|
+
pos = 0;
|
|
2706
|
+
remain = 0;
|
|
2707
|
+
length = 0;
|
|
2708
|
+
offset = 0;
|
|
2709
|
+
win32;
|
|
2710
|
+
absolute;
|
|
2711
|
+
header;
|
|
2712
|
+
type;
|
|
2713
|
+
linkpath;
|
|
2714
|
+
stat;
|
|
2715
|
+
onWriteEntry;
|
|
2716
|
+
#t = false;
|
|
2717
|
+
constructor(t, e = {}) {
|
|
2718
|
+
let i = se(e);
|
|
2719
|
+
super(), this.path = f(t), this.portable = !!i.portable, this.maxReadSize = i.maxReadSize || Wn, this.linkCache = i.linkCache || /* @__PURE__ */ new Map(), this.statCache = i.statCache || /* @__PURE__ */ new Map(), this.preservePaths = !!i.preservePaths, this.cwd = f(i.cwd || process.cwd()), this.strict = !!i.strict, this.noPax = !!i.noPax, this.noMtime = !!i.noMtime, this.mtime = i.mtime, this.prefix = i.prefix ? f(i.prefix) : void 0, this.onWriteEntry = i.onWriteEntry, typeof i.onwarn == "function" && this.on("warn", i.onwarn);
|
|
2720
|
+
let r = false;
|
|
2721
|
+
if (!this.preservePaths) {
|
|
2722
|
+
let [o, h] = ce(this.path);
|
|
2723
|
+
o && typeof h == "string" && (this.path = h, r = o);
|
|
2724
|
+
}
|
|
2725
|
+
this.win32 = !!i.win32 || process.platform === "win32", this.win32 && (this.path = Qs(this.path.replaceAll(/\\/g, "/")), t = t.replaceAll(/\\/g, "/")), this.absolute = f(i.absolute || js.resolve(this.cwd, t)), this.path === "" && (this.path = "./"), r && this.warn("TAR_ENTRY_INFO", `stripping ${r} from absolute path`, { entry: this, path: r + this.path });
|
|
2726
|
+
let n = this.statCache.get(this.absolute);
|
|
2727
|
+
n ? this[si](n) : this[ss]();
|
|
2728
|
+
}
|
|
2729
|
+
warn(t, e, i = {}) {
|
|
2730
|
+
return Dt(this, t, e, i);
|
|
2731
|
+
}
|
|
2732
|
+
emit(t, ...e) {
|
|
2733
|
+
return t === "error" && (this.#t = true), super.emit(t, ...e);
|
|
2734
|
+
}
|
|
2735
|
+
[ss]() {
|
|
2736
|
+
X.lstat(this.absolute, (t, e) => {
|
|
2737
|
+
if (t) return this.emit("error", t);
|
|
2738
|
+
this[si](e);
|
|
2739
|
+
});
|
|
2740
|
+
}
|
|
2741
|
+
[si](t) {
|
|
2742
|
+
this.statCache.set(this.absolute, t), this.stat = t, t.isFile() || (t.size = 0), this.type = Gn(t), this.emit("stat", t), this[tr]();
|
|
2743
|
+
}
|
|
2744
|
+
[tr]() {
|
|
2745
|
+
switch (this.type) {
|
|
2746
|
+
case "File":
|
|
2747
|
+
return this[er]();
|
|
2748
|
+
case "Directory":
|
|
2749
|
+
return this[ir]();
|
|
2750
|
+
case "SymbolicLink":
|
|
2751
|
+
return this[is]();
|
|
2752
|
+
default:
|
|
2753
|
+
return this.end();
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
[ri](t) {
|
|
2757
|
+
return Ji(t, this.type === "Directory", this.portable);
|
|
2758
|
+
}
|
|
2759
|
+
[q](t) {
|
|
2760
|
+
return rr(t, this.prefix);
|
|
2761
|
+
}
|
|
2762
|
+
[fe]() {
|
|
2763
|
+
if (!this.stat) throw new Error("cannot write header before stat");
|
|
2764
|
+
this.type === "Directory" && this.portable && (this.noMtime = true), this.onWriteEntry?.(this), this.header = new F({ path: this[q](this.path), linkpath: this.type === "Link" && this.linkpath !== void 0 ? this[q](this.linkpath) : this.linkpath, mode: this[ri](this.stat.mode), uid: this.portable ? void 0 : this.stat.uid, gid: this.portable ? void 0 : this.stat.gid, size: this.stat.size, mtime: this.noMtime ? void 0 : this.mtime || this.stat.mtime, type: this.type === "Unsupported" ? void 0 : this.type, uname: this.portable ? void 0 : this.stat.uid === this.myuid ? this.myuser : "", atime: this.portable ? void 0 : this.stat.atime, ctime: this.portable ? void 0 : this.stat.ctime }), this.header.encode() && !this.noPax && super.write(new ft({ atime: this.portable ? void 0 : this.header.atime, ctime: this.portable ? void 0 : this.header.ctime, gid: this.portable ? void 0 : this.header.gid, mtime: this.noMtime ? void 0 : this.mtime || this.header.mtime, path: this[q](this.path), linkpath: this.type === "Link" && this.linkpath !== void 0 ? this[q](this.linkpath) : this.linkpath, size: this.header.size, uid: this.portable ? void 0 : this.header.uid, uname: this.portable ? void 0 : this.header.uname, dev: this.portable ? void 0 : this.stat.dev, ino: this.portable ? void 0 : this.stat.ino, nlink: this.portable ? void 0 : this.stat.nlink }).encode());
|
|
2765
|
+
let t = this.header?.block;
|
|
2766
|
+
if (!t) throw new Error("failed to encode header");
|
|
2767
|
+
super.write(t);
|
|
2768
|
+
}
|
|
2769
|
+
[ir]() {
|
|
2770
|
+
if (!this.stat) throw new Error("cannot create directory entry without stat");
|
|
2771
|
+
this.path.slice(-1) !== "/" && (this.path += "/"), this.stat.size = 0, this[fe](), this.end();
|
|
2772
|
+
}
|
|
2773
|
+
[is]() {
|
|
2774
|
+
X.readlink(this.absolute, (t, e) => {
|
|
2775
|
+
if (t) return this.emit("error", t);
|
|
2776
|
+
this[ns](e);
|
|
2777
|
+
});
|
|
2778
|
+
}
|
|
2779
|
+
[ns](t) {
|
|
2780
|
+
this.linkpath = f(t), this[fe](), this.end();
|
|
2781
|
+
}
|
|
2782
|
+
[sr](t) {
|
|
2783
|
+
if (!this.stat) throw new Error("cannot create link entry without stat");
|
|
2784
|
+
this.type = "Link", this.linkpath = f(js.relative(this.cwd, t)), this.stat.size = 0, this[fe](), this.end();
|
|
2785
|
+
}
|
|
2786
|
+
[er]() {
|
|
2787
|
+
if (!this.stat) throw new Error("cannot create file entry without stat");
|
|
2788
|
+
if (this.stat.nlink > 1) {
|
|
2789
|
+
let t = `${this.stat.dev}:${this.stat.ino}`, e = this.linkCache.get(t);
|
|
2790
|
+
if (e?.indexOf(this.cwd) === 0) return this[sr](e);
|
|
2791
|
+
this.linkCache.set(t, this.absolute);
|
|
2792
|
+
}
|
|
2793
|
+
if (this[fe](), this.stat.size === 0) return this.end();
|
|
2794
|
+
this[os]();
|
|
2795
|
+
}
|
|
2796
|
+
[os]() {
|
|
2797
|
+
X.open(this.absolute, "r", (t, e) => {
|
|
2798
|
+
if (t) return this.emit("error", t);
|
|
2799
|
+
this[hs](e);
|
|
2800
|
+
});
|
|
2801
|
+
}
|
|
2802
|
+
[hs](t) {
|
|
2803
|
+
if (this.fd = t, this.#t) return this[pt]();
|
|
2804
|
+
if (!this.stat) throw new Error("should stat before calling onopenfile");
|
|
2805
|
+
this.blockLen = 512 * Math.ceil(this.stat.size / 512), this.blockRemain = this.blockLen;
|
|
2806
|
+
let e = Math.min(this.blockLen, this.maxReadSize);
|
|
2807
|
+
this.buf = Buffer.allocUnsafe(e), this.offset = 0, this.pos = 0, this.remain = this.stat.size, this.length = this.buf.length, this[ii]();
|
|
2808
|
+
}
|
|
2809
|
+
[ii]() {
|
|
2810
|
+
let { fd: t, buf: e, offset: i, length: r, pos: n } = this;
|
|
2811
|
+
if (t === void 0 || e === void 0) throw new Error("cannot read file without first opening");
|
|
2812
|
+
X.read(t, e, i, r, n, (o, h) => {
|
|
2813
|
+
if (o) return this[pt](() => this.emit("error", o));
|
|
2814
|
+
this[rs](h);
|
|
2815
|
+
});
|
|
2816
|
+
}
|
|
2817
|
+
[pt](t = () => {
|
|
2818
|
+
}) {
|
|
2819
|
+
this.fd !== void 0 && X.close(this.fd, t);
|
|
2820
|
+
}
|
|
2821
|
+
[rs](t) {
|
|
2822
|
+
if (t <= 0 && this.remain > 0) {
|
|
2823
|
+
let r = Object.assign(new Error("encountered unexpected EOF"), { path: this.absolute, syscall: "read", code: "EOF" });
|
|
2824
|
+
return this[pt](() => this.emit("error", r));
|
|
2825
|
+
}
|
|
2826
|
+
if (t > this.remain) {
|
|
2827
|
+
let r = Object.assign(new Error("did not encounter expected EOF"), { path: this.absolute, syscall: "read", code: "EOF" });
|
|
2828
|
+
return this[pt](() => this.emit("error", r));
|
|
2829
|
+
}
|
|
2830
|
+
if (!this.buf) throw new Error("should have created buffer prior to reading");
|
|
2831
|
+
if (t === this.remain) for (let r = t; r < this.length && t < this.blockRemain; r++) this.buf[r + this.offset] = 0, t++, this.remain++;
|
|
2832
|
+
let e = this.offset === 0 && t === this.buf.length ? this.buf : this.buf.subarray(this.offset, this.offset + t);
|
|
2833
|
+
this.write(e) ? this[es]() : this[as](() => this[es]());
|
|
2834
|
+
}
|
|
2835
|
+
[as](t) {
|
|
2836
|
+
this.once("drain", t);
|
|
2837
|
+
}
|
|
2838
|
+
write(t, e, i) {
|
|
2839
|
+
if (typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, typeof e == "string" ? e : "utf8")), this.blockRemain < t.length) {
|
|
2840
|
+
let r = Object.assign(new Error("writing more data than expected"), { path: this.absolute });
|
|
2841
|
+
return this.emit("error", r);
|
|
2842
|
+
}
|
|
2843
|
+
return this.remain -= t.length, this.blockRemain -= t.length, this.pos += t.length, this.offset += t.length, super.write(t, null, i);
|
|
2844
|
+
}
|
|
2845
|
+
[es]() {
|
|
2846
|
+
if (!this.remain) return this.blockRemain && super.write(Buffer.alloc(this.blockRemain)), this[pt]((t) => t ? this.emit("error", t) : this.end());
|
|
2847
|
+
if (!this.buf) throw new Error("buffer lost somehow in ONDRAIN");
|
|
2848
|
+
this.offset >= this.length && (this.buf = Buffer.allocUnsafe(Math.min(this.blockRemain, this.buf.length)), this.offset = 0), this.length = this.buf.length - this.offset, this[ii]();
|
|
2849
|
+
}
|
|
2850
|
+
};
|
|
2851
|
+
var ni = class extends de {
|
|
2852
|
+
sync = true;
|
|
2853
|
+
[ss]() {
|
|
2854
|
+
this[si](X.lstatSync(this.absolute));
|
|
2855
|
+
}
|
|
2856
|
+
[is]() {
|
|
2857
|
+
this[ns](X.readlinkSync(this.absolute));
|
|
2858
|
+
}
|
|
2859
|
+
[os]() {
|
|
2860
|
+
this[hs](X.openSync(this.absolute, "r"));
|
|
2861
|
+
}
|
|
2862
|
+
[ii]() {
|
|
2863
|
+
let t = true;
|
|
2864
|
+
try {
|
|
2865
|
+
let { fd: e, buf: i, offset: r, length: n, pos: o } = this;
|
|
2866
|
+
if (e === void 0 || i === void 0) throw new Error("fd and buf must be set in READ method");
|
|
2867
|
+
let h = X.readSync(e, i, r, n, o);
|
|
2868
|
+
this[rs](h), t = false;
|
|
2869
|
+
} finally {
|
|
2870
|
+
if (t) try {
|
|
2871
|
+
this[pt](() => {
|
|
2872
|
+
});
|
|
2873
|
+
} catch {
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
}
|
|
2877
|
+
[as](t) {
|
|
2878
|
+
t();
|
|
2879
|
+
}
|
|
2880
|
+
[pt](t = () => {
|
|
2881
|
+
}) {
|
|
2882
|
+
this.fd !== void 0 && X.closeSync(this.fd), t();
|
|
2883
|
+
}
|
|
2884
|
+
};
|
|
2885
|
+
var oi = class extends A {
|
|
2886
|
+
blockLen = 0;
|
|
2887
|
+
blockRemain = 0;
|
|
2888
|
+
buf = 0;
|
|
2889
|
+
pos = 0;
|
|
2890
|
+
remain = 0;
|
|
2891
|
+
length = 0;
|
|
2892
|
+
preservePaths;
|
|
2893
|
+
portable;
|
|
2894
|
+
strict;
|
|
2895
|
+
noPax;
|
|
2896
|
+
noMtime;
|
|
2897
|
+
readEntry;
|
|
2898
|
+
type;
|
|
2899
|
+
prefix;
|
|
2900
|
+
path;
|
|
2901
|
+
mode;
|
|
2902
|
+
uid;
|
|
2903
|
+
gid;
|
|
2904
|
+
uname;
|
|
2905
|
+
gname;
|
|
2906
|
+
header;
|
|
2907
|
+
mtime;
|
|
2908
|
+
atime;
|
|
2909
|
+
ctime;
|
|
2910
|
+
linkpath;
|
|
2911
|
+
size;
|
|
2912
|
+
onWriteEntry;
|
|
2913
|
+
warn(t, e, i = {}) {
|
|
2914
|
+
return Dt(this, t, e, i);
|
|
2915
|
+
}
|
|
2916
|
+
constructor(t, e = {}) {
|
|
2917
|
+
let i = se(e);
|
|
2918
|
+
super(), this.preservePaths = !!i.preservePaths, this.portable = !!i.portable, this.strict = !!i.strict, this.noPax = !!i.noPax, this.noMtime = !!i.noMtime, this.onWriteEntry = i.onWriteEntry, this.readEntry = t;
|
|
2919
|
+
let { type: r } = t;
|
|
2920
|
+
if (r === "Unsupported") throw new Error("writing entry that should be ignored");
|
|
2921
|
+
this.type = r, this.type === "Directory" && this.portable && (this.noMtime = true), this.prefix = i.prefix, this.path = f(t.path), this.mode = t.mode !== void 0 ? this[ri](t.mode) : void 0, this.uid = this.portable ? void 0 : t.uid, this.gid = this.portable ? void 0 : t.gid, this.uname = this.portable ? void 0 : t.uname, this.gname = this.portable ? void 0 : t.gname, this.size = t.size, this.mtime = this.noMtime ? void 0 : i.mtime || t.mtime, this.atime = this.portable ? void 0 : t.atime, this.ctime = this.portable ? void 0 : t.ctime, this.linkpath = t.linkpath !== void 0 ? f(t.linkpath) : void 0, typeof i.onwarn == "function" && this.on("warn", i.onwarn);
|
|
2922
|
+
let n = false;
|
|
2923
|
+
if (!this.preservePaths) {
|
|
2924
|
+
let [h, a] = ce(this.path);
|
|
2925
|
+
h && typeof a == "string" && (this.path = a, n = h);
|
|
2926
|
+
}
|
|
2927
|
+
this.remain = t.size, this.blockRemain = t.startBlockSize, this.onWriteEntry?.(this), this.header = new F({ path: this[q](this.path), linkpath: this.type === "Link" && this.linkpath !== void 0 ? this[q](this.linkpath) : this.linkpath, mode: this.mode, uid: this.portable ? void 0 : this.uid, gid: this.portable ? void 0 : this.gid, size: this.size, mtime: this.noMtime ? void 0 : this.mtime, type: this.type, uname: this.portable ? void 0 : this.uname, atime: this.portable ? void 0 : this.atime, ctime: this.portable ? void 0 : this.ctime }), n && this.warn("TAR_ENTRY_INFO", `stripping ${n} from absolute path`, { entry: this, path: n + this.path }), this.header.encode() && !this.noPax && super.write(new ft({ atime: this.portable ? void 0 : this.atime, ctime: this.portable ? void 0 : this.ctime, gid: this.portable ? void 0 : this.gid, mtime: this.noMtime ? void 0 : this.mtime, path: this[q](this.path), linkpath: this.type === "Link" && this.linkpath !== void 0 ? this[q](this.linkpath) : this.linkpath, size: this.size, uid: this.portable ? void 0 : this.uid, uname: this.portable ? void 0 : this.uname, dev: this.portable ? void 0 : this.readEntry.dev, ino: this.portable ? void 0 : this.readEntry.ino, nlink: this.portable ? void 0 : this.readEntry.nlink }).encode());
|
|
2928
|
+
let o = this.header?.block;
|
|
2929
|
+
if (!o) throw new Error("failed to encode header");
|
|
2930
|
+
super.write(o), t.pipe(this);
|
|
2931
|
+
}
|
|
2932
|
+
[q](t) {
|
|
2933
|
+
return rr(t, this.prefix);
|
|
2934
|
+
}
|
|
2935
|
+
[ri](t) {
|
|
2936
|
+
return Ji(t, this.type === "Directory", this.portable);
|
|
2937
|
+
}
|
|
2938
|
+
write(t, e, i) {
|
|
2939
|
+
typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, typeof e == "string" ? e : "utf8"));
|
|
2940
|
+
let r = t.length;
|
|
2941
|
+
if (r > this.blockRemain) throw new Error("writing more to entry than is appropriate");
|
|
2942
|
+
return this.blockRemain -= r, super.write(t, i);
|
|
2943
|
+
}
|
|
2944
|
+
end(t, e, i) {
|
|
2945
|
+
return this.blockRemain && super.write(Buffer.alloc(this.blockRemain)), typeof t == "function" && (i = t, e = void 0, t = void 0), typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, e ?? "utf8")), i && this.once("finish", i), t ? super.end(t, i) : super.end(i), this;
|
|
2946
|
+
}
|
|
2947
|
+
};
|
|
2948
|
+
var Gn = (s3) => s3.isFile() ? "File" : s3.isDirectory() ? "Directory" : s3.isSymbolicLink() ? "SymbolicLink" : "Unsupported";
|
|
2949
|
+
var hi = class s2 {
|
|
2950
|
+
tail;
|
|
2951
|
+
head;
|
|
2952
|
+
length = 0;
|
|
2953
|
+
static create(t = []) {
|
|
2954
|
+
return new s2(t);
|
|
2955
|
+
}
|
|
2956
|
+
constructor(t = []) {
|
|
2957
|
+
for (let e of t) this.push(e);
|
|
2958
|
+
}
|
|
2959
|
+
*[Symbol.iterator]() {
|
|
2960
|
+
for (let t = this.head; t; t = t.next) yield t.value;
|
|
2961
|
+
}
|
|
2962
|
+
removeNode(t) {
|
|
2963
|
+
if (t.list !== this) throw new Error("removing node which does not belong to this list");
|
|
2964
|
+
let e = t.next, i = t.prev;
|
|
2965
|
+
return e && (e.prev = i), i && (i.next = e), t === this.head && (this.head = e), t === this.tail && (this.tail = i), this.length--, t.next = void 0, t.prev = void 0, t.list = void 0, e;
|
|
2966
|
+
}
|
|
2967
|
+
unshiftNode(t) {
|
|
2968
|
+
if (t === this.head) return;
|
|
2969
|
+
t.list && t.list.removeNode(t);
|
|
2970
|
+
let e = this.head;
|
|
2971
|
+
t.list = this, t.next = e, e && (e.prev = t), this.head = t, this.tail || (this.tail = t), this.length++;
|
|
2972
|
+
}
|
|
2973
|
+
pushNode(t) {
|
|
2974
|
+
if (t === this.tail) return;
|
|
2975
|
+
t.list && t.list.removeNode(t);
|
|
2976
|
+
let e = this.tail;
|
|
2977
|
+
t.list = this, t.prev = e, e && (e.next = t), this.tail = t, this.head || (this.head = t), this.length++;
|
|
2978
|
+
}
|
|
2979
|
+
push(...t) {
|
|
2980
|
+
for (let e = 0, i = t.length; e < i; e++) Yn(this, t[e]);
|
|
2981
|
+
return this.length;
|
|
2982
|
+
}
|
|
2983
|
+
unshift(...t) {
|
|
2984
|
+
for (var e = 0, i = t.length; e < i; e++) Kn(this, t[e]);
|
|
2985
|
+
return this.length;
|
|
2986
|
+
}
|
|
2987
|
+
pop() {
|
|
2988
|
+
if (!this.tail) return;
|
|
2989
|
+
let t = this.tail.value, e = this.tail;
|
|
2990
|
+
return this.tail = this.tail.prev, this.tail ? this.tail.next = void 0 : this.head = void 0, e.list = void 0, this.length--, t;
|
|
2991
|
+
}
|
|
2992
|
+
shift() {
|
|
2993
|
+
if (!this.head) return;
|
|
2994
|
+
let t = this.head.value, e = this.head;
|
|
2995
|
+
return this.head = this.head.next, this.head ? this.head.prev = void 0 : this.tail = void 0, e.list = void 0, this.length--, t;
|
|
2996
|
+
}
|
|
2997
|
+
forEach(t, e) {
|
|
2998
|
+
e = e || this;
|
|
2999
|
+
for (let i = this.head, r = 0; i; r++) t.call(e, i.value, r, this), i = i.next;
|
|
3000
|
+
}
|
|
3001
|
+
forEachReverse(t, e) {
|
|
3002
|
+
e = e || this;
|
|
3003
|
+
for (let i = this.tail, r = this.length - 1; i; r--) t.call(e, i.value, r, this), i = i.prev;
|
|
3004
|
+
}
|
|
3005
|
+
get(t) {
|
|
3006
|
+
let e = 0, i = this.head;
|
|
3007
|
+
for (; i && e < t; e++) i = i.next;
|
|
3008
|
+
if (e === t && i) return i.value;
|
|
3009
|
+
}
|
|
3010
|
+
getReverse(t) {
|
|
3011
|
+
let e = 0, i = this.tail;
|
|
3012
|
+
for (; i && e < t; e++) i = i.prev;
|
|
3013
|
+
if (e === t && i) return i.value;
|
|
3014
|
+
}
|
|
3015
|
+
map(t, e) {
|
|
3016
|
+
e = e || this;
|
|
3017
|
+
let i = new s2();
|
|
3018
|
+
for (let r = this.head; r; ) i.push(t.call(e, r.value, this)), r = r.next;
|
|
3019
|
+
return i;
|
|
3020
|
+
}
|
|
3021
|
+
mapReverse(t, e) {
|
|
3022
|
+
e = e || this;
|
|
3023
|
+
var i = new s2();
|
|
3024
|
+
for (let r = this.tail; r; ) i.push(t.call(e, r.value, this)), r = r.prev;
|
|
3025
|
+
return i;
|
|
3026
|
+
}
|
|
3027
|
+
reduce(t, e) {
|
|
3028
|
+
let i, r = this.head;
|
|
3029
|
+
if (arguments.length > 1) i = e;
|
|
3030
|
+
else if (this.head) r = this.head.next, i = this.head.value;
|
|
3031
|
+
else throw new TypeError("Reduce of empty list with no initial value");
|
|
3032
|
+
for (var n = 0; r; n++) i = t(i, r.value, n), r = r.next;
|
|
3033
|
+
return i;
|
|
3034
|
+
}
|
|
3035
|
+
reduceReverse(t, e) {
|
|
3036
|
+
let i, r = this.tail;
|
|
3037
|
+
if (arguments.length > 1) i = e;
|
|
3038
|
+
else if (this.tail) r = this.tail.prev, i = this.tail.value;
|
|
3039
|
+
else throw new TypeError("Reduce of empty list with no initial value");
|
|
3040
|
+
for (let n = this.length - 1; r; n--) i = t(i, r.value, n), r = r.prev;
|
|
3041
|
+
return i;
|
|
3042
|
+
}
|
|
3043
|
+
toArray() {
|
|
3044
|
+
let t = new Array(this.length);
|
|
3045
|
+
for (let e = 0, i = this.head; i; e++) t[e] = i.value, i = i.next;
|
|
3046
|
+
return t;
|
|
3047
|
+
}
|
|
3048
|
+
toArrayReverse() {
|
|
3049
|
+
let t = new Array(this.length);
|
|
3050
|
+
for (let e = 0, i = this.tail; i; e++) t[e] = i.value, i = i.prev;
|
|
3051
|
+
return t;
|
|
3052
|
+
}
|
|
3053
|
+
slice(t = 0, e = this.length) {
|
|
3054
|
+
e < 0 && (e += this.length), t < 0 && (t += this.length);
|
|
3055
|
+
let i = new s2();
|
|
3056
|
+
if (e < t || e < 0) return i;
|
|
3057
|
+
t < 0 && (t = 0), e > this.length && (e = this.length);
|
|
3058
|
+
let r = this.head, n = 0;
|
|
3059
|
+
for (n = 0; r && n < t; n++) r = r.next;
|
|
3060
|
+
for (; r && n < e; n++, r = r.next) i.push(r.value);
|
|
3061
|
+
return i;
|
|
3062
|
+
}
|
|
3063
|
+
sliceReverse(t = 0, e = this.length) {
|
|
3064
|
+
e < 0 && (e += this.length), t < 0 && (t += this.length);
|
|
3065
|
+
let i = new s2();
|
|
3066
|
+
if (e < t || e < 0) return i;
|
|
3067
|
+
t < 0 && (t = 0), e > this.length && (e = this.length);
|
|
3068
|
+
let r = this.length, n = this.tail;
|
|
3069
|
+
for (; n && r > e; r--) n = n.prev;
|
|
3070
|
+
for (; n && r > t; r--, n = n.prev) i.push(n.value);
|
|
3071
|
+
return i;
|
|
3072
|
+
}
|
|
3073
|
+
splice(t, e = 0, ...i) {
|
|
3074
|
+
t > this.length && (t = this.length - 1), t < 0 && (t = this.length + t);
|
|
3075
|
+
let r = this.head;
|
|
3076
|
+
for (let o = 0; r && o < t; o++) r = r.next;
|
|
3077
|
+
let n = [];
|
|
3078
|
+
for (let o = 0; r && o < e; o++) n.push(r.value), r = this.removeNode(r);
|
|
3079
|
+
r ? r !== this.tail && (r = r.prev) : r = this.tail;
|
|
3080
|
+
for (let o of i) r = Zn(this, r, o);
|
|
3081
|
+
return n;
|
|
3082
|
+
}
|
|
3083
|
+
reverse() {
|
|
3084
|
+
let t = this.head, e = this.tail;
|
|
3085
|
+
for (let i = t; i; i = i.prev) {
|
|
3086
|
+
let r = i.prev;
|
|
3087
|
+
i.prev = i.next, i.next = r;
|
|
3088
|
+
}
|
|
3089
|
+
return this.head = e, this.tail = t, this;
|
|
3090
|
+
}
|
|
3091
|
+
};
|
|
3092
|
+
function Zn(s3, t, e) {
|
|
3093
|
+
let i = t, r = t ? t.next : s3.head, n = new ue(e, i, r, s3);
|
|
3094
|
+
return n.next === void 0 && (s3.tail = n), n.prev === void 0 && (s3.head = n), s3.length++, n;
|
|
3095
|
+
}
|
|
3096
|
+
function Yn(s3, t) {
|
|
3097
|
+
s3.tail = new ue(t, s3.tail, void 0, s3), s3.head || (s3.head = s3.tail), s3.length++;
|
|
3098
|
+
}
|
|
3099
|
+
function Kn(s3, t) {
|
|
3100
|
+
s3.head = new ue(t, void 0, s3.head, s3), s3.tail || (s3.tail = s3.head), s3.length++;
|
|
3101
|
+
}
|
|
3102
|
+
var ue = class {
|
|
3103
|
+
list;
|
|
3104
|
+
next;
|
|
3105
|
+
prev;
|
|
3106
|
+
value;
|
|
3107
|
+
constructor(t, e, i, r) {
|
|
3108
|
+
this.list = r, this.value = t, e ? (e.next = this, this.prev = e) : this.prev = void 0, i ? (i.prev = this, this.next = i) : this.next = void 0;
|
|
3109
|
+
}
|
|
3110
|
+
};
|
|
3111
|
+
var pi = class {
|
|
3112
|
+
path;
|
|
3113
|
+
absolute;
|
|
3114
|
+
entry;
|
|
3115
|
+
stat;
|
|
3116
|
+
readdir;
|
|
3117
|
+
pending = false;
|
|
3118
|
+
pendingLink = false;
|
|
3119
|
+
ignore = false;
|
|
3120
|
+
piped = false;
|
|
3121
|
+
constructor(t, e) {
|
|
3122
|
+
this.path = t || "./", this.absolute = e;
|
|
3123
|
+
}
|
|
3124
|
+
};
|
|
3125
|
+
var nr = Buffer.alloc(1024);
|
|
3126
|
+
var li = /* @__PURE__ */ Symbol("onStat");
|
|
3127
|
+
var me = /* @__PURE__ */ Symbol("ended");
|
|
3128
|
+
var W = /* @__PURE__ */ Symbol("queue");
|
|
3129
|
+
var pe = /* @__PURE__ */ Symbol("pendingLinks");
|
|
3130
|
+
var Et = /* @__PURE__ */ Symbol("current");
|
|
3131
|
+
var Ft = /* @__PURE__ */ Symbol("process");
|
|
3132
|
+
var Ee = /* @__PURE__ */ Symbol("processing");
|
|
3133
|
+
var ai = /* @__PURE__ */ Symbol("processJob");
|
|
3134
|
+
var G = /* @__PURE__ */ Symbol("jobs");
|
|
3135
|
+
var ls = /* @__PURE__ */ Symbol("jobDone");
|
|
3136
|
+
var ci = /* @__PURE__ */ Symbol("addFSEntry");
|
|
3137
|
+
var or = /* @__PURE__ */ Symbol("addTarEntry");
|
|
3138
|
+
var ds = /* @__PURE__ */ Symbol("stat");
|
|
3139
|
+
var us = /* @__PURE__ */ Symbol("readdir");
|
|
3140
|
+
var fi = /* @__PURE__ */ Symbol("onreaddir");
|
|
3141
|
+
var di = /* @__PURE__ */ Symbol("pipe");
|
|
3142
|
+
var hr = /* @__PURE__ */ Symbol("entry");
|
|
3143
|
+
var cs = /* @__PURE__ */ Symbol("entryOpt");
|
|
3144
|
+
var ui = /* @__PURE__ */ Symbol("writeEntryClass");
|
|
3145
|
+
var lr = /* @__PURE__ */ Symbol("write");
|
|
3146
|
+
var fs = /* @__PURE__ */ Symbol("ondrain");
|
|
3147
|
+
var wt = class extends A {
|
|
3148
|
+
sync = false;
|
|
3149
|
+
opt;
|
|
3150
|
+
cwd;
|
|
3151
|
+
maxReadSize;
|
|
3152
|
+
preservePaths;
|
|
3153
|
+
strict;
|
|
3154
|
+
noPax;
|
|
3155
|
+
prefix;
|
|
3156
|
+
linkCache;
|
|
3157
|
+
statCache;
|
|
3158
|
+
file;
|
|
3159
|
+
portable;
|
|
3160
|
+
zip;
|
|
3161
|
+
readdirCache;
|
|
3162
|
+
noDirRecurse;
|
|
3163
|
+
follow;
|
|
3164
|
+
noMtime;
|
|
3165
|
+
mtime;
|
|
3166
|
+
filter;
|
|
3167
|
+
jobs;
|
|
3168
|
+
[ui];
|
|
3169
|
+
onWriteEntry;
|
|
3170
|
+
[W];
|
|
3171
|
+
[pe] = /* @__PURE__ */ new Map();
|
|
3172
|
+
[G] = 0;
|
|
3173
|
+
[Ee] = false;
|
|
3174
|
+
[me] = false;
|
|
3175
|
+
constructor(t = {}) {
|
|
3176
|
+
if (super(), this.opt = t, this.file = t.file || "", this.cwd = t.cwd || process.cwd(), this.maxReadSize = t.maxReadSize, this.preservePaths = !!t.preservePaths, this.strict = !!t.strict, this.noPax = !!t.noPax, this.prefix = f(t.prefix || ""), this.linkCache = t.linkCache || /* @__PURE__ */ new Map(), this.statCache = t.statCache || /* @__PURE__ */ new Map(), this.readdirCache = t.readdirCache || /* @__PURE__ */ new Map(), this.onWriteEntry = t.onWriteEntry, this[ui] = de, typeof t.onwarn == "function" && this.on("warn", t.onwarn), this.portable = !!t.portable, t.gzip || t.brotli || t.zstd) {
|
|
3177
|
+
if ((t.gzip ? 1 : 0) + (t.brotli ? 1 : 0) + (t.zstd ? 1 : 0) > 1) throw new TypeError("gzip, brotli, zstd are mutually exclusive");
|
|
3178
|
+
if (t.gzip && (typeof t.gzip != "object" && (t.gzip = {}), this.portable && (t.gzip.portable = true), this.zip = new ze(t.gzip)), t.brotli && (typeof t.brotli != "object" && (t.brotli = {}), this.zip = new We(t.brotli)), t.zstd && (typeof t.zstd != "object" && (t.zstd = {}), this.zip = new Ye(t.zstd)), !this.zip) throw new Error("impossible");
|
|
3179
|
+
let e = this.zip;
|
|
3180
|
+
e.on("data", (i) => super.write(i)), e.on("end", () => super.end()), e.on("drain", () => this[fs]()), this.on("resume", () => e.resume());
|
|
3181
|
+
} else this.on("drain", this[fs]);
|
|
3182
|
+
this.noDirRecurse = !!t.noDirRecurse, this.follow = !!t.follow, this.noMtime = !!t.noMtime, t.mtime && (this.mtime = t.mtime), this.filter = typeof t.filter == "function" ? t.filter : () => true, this[W] = new hi(), this[G] = 0, this.jobs = Number(t.jobs) || 4, this[Ee] = false, this[me] = false;
|
|
3183
|
+
}
|
|
3184
|
+
[lr](t) {
|
|
3185
|
+
return super.write(t);
|
|
3186
|
+
}
|
|
3187
|
+
add(t) {
|
|
3188
|
+
return this.write(t), this;
|
|
3189
|
+
}
|
|
3190
|
+
end(t, e, i) {
|
|
3191
|
+
return typeof t == "function" && (i = t, t = void 0), typeof e == "function" && (i = e, e = void 0), t && this.add(t), this[me] = true, this[Ft](), i && i(), this;
|
|
3192
|
+
}
|
|
3193
|
+
write(t) {
|
|
3194
|
+
if (this[me]) throw new Error("write after end");
|
|
3195
|
+
return typeof t == "string" ? this[ci](t) : this[or](t), this.flowing;
|
|
3196
|
+
}
|
|
3197
|
+
[or](t) {
|
|
3198
|
+
let e = f(ar.resolve(this.cwd, t.path));
|
|
3199
|
+
if (!this.filter(t.path, t)) t.resume();
|
|
3200
|
+
else {
|
|
3201
|
+
let i = new pi(t.path, e);
|
|
3202
|
+
i.entry = new oi(t, this[cs](i)), i.entry.on("end", () => this[ls](i)), this[G] += 1, this[W].push(i);
|
|
3203
|
+
}
|
|
3204
|
+
this[Ft]();
|
|
3205
|
+
}
|
|
3206
|
+
[ci](t) {
|
|
3207
|
+
let e = f(ar.resolve(this.cwd, t));
|
|
3208
|
+
this[W].push(new pi(t, e)), this[Ft]();
|
|
3209
|
+
}
|
|
3210
|
+
[ds](t) {
|
|
3211
|
+
t.pending = true, this[G] += 1;
|
|
3212
|
+
let e = this.follow ? "stat" : "lstat";
|
|
3213
|
+
mi[e](t.absolute, (i, r) => {
|
|
3214
|
+
t.pending = false, this[G] -= 1, i ? this.emit("error", i) : this[li](t, r);
|
|
3215
|
+
});
|
|
3216
|
+
}
|
|
3217
|
+
[li](t, e) {
|
|
3218
|
+
if (this.statCache.set(t.absolute, e), t.stat = e, !this.filter(t.path, e)) t.ignore = true;
|
|
3219
|
+
else if (e.isFile() && e.nlink > 1 && !this.linkCache.get(`${e.dev}:${e.ino}`) && !this.sync) if (t === this[Et]) this[ai](t);
|
|
3220
|
+
else {
|
|
3221
|
+
let i = `${e.dev}:${e.ino}`, r = this[pe].get(i);
|
|
3222
|
+
r ? r.push(t) : this[pe].set(i, [t]), t.pendingLink = true, t.pending = true;
|
|
3223
|
+
}
|
|
3224
|
+
this[Ft]();
|
|
3225
|
+
}
|
|
3226
|
+
[us](t) {
|
|
3227
|
+
t.pending = true, this[G] += 1, mi.readdir(t.absolute, (e, i) => {
|
|
3228
|
+
if (t.pending = false, this[G] -= 1, e) return this.emit("error", e);
|
|
3229
|
+
this[fi](t, i);
|
|
3230
|
+
});
|
|
3231
|
+
}
|
|
3232
|
+
[fi](t, e) {
|
|
3233
|
+
this.readdirCache.set(t.absolute, e), t.readdir = e, this[Ft]();
|
|
3234
|
+
}
|
|
3235
|
+
[Ft]() {
|
|
3236
|
+
if (!this[Ee]) {
|
|
3237
|
+
this[Ee] = true;
|
|
3238
|
+
for (let t = this[W].head; t && this[G] < this.jobs; t = t.next) if (this[ai](t.value), t.value.ignore) {
|
|
3239
|
+
let e = t.next;
|
|
3240
|
+
this[W].removeNode(t), t.next = e;
|
|
3241
|
+
}
|
|
3242
|
+
this[Ee] = false, this[me] && this[W].length === 0 && this[G] === 0 && (this.zip ? this.zip.end(nr) : (super.write(nr), super.end()));
|
|
3243
|
+
}
|
|
3244
|
+
}
|
|
3245
|
+
get [Et]() {
|
|
3246
|
+
return this[W] && this[W].head && this[W].head.value;
|
|
3247
|
+
}
|
|
3248
|
+
[ls](t) {
|
|
3249
|
+
this[W].shift(), this[G] -= 1;
|
|
3250
|
+
let { stat: e } = t;
|
|
3251
|
+
if (e && e.isFile() && e.nlink > 1) {
|
|
3252
|
+
let i = `${e.dev}:${e.ino}`, r = this[pe].get(i);
|
|
3253
|
+
if (r) {
|
|
3254
|
+
this[pe].delete(i);
|
|
3255
|
+
for (let n of r) n.pending = false, this[ai](n);
|
|
3256
|
+
}
|
|
3257
|
+
}
|
|
3258
|
+
this[Ft]();
|
|
3259
|
+
}
|
|
3260
|
+
[ai](t) {
|
|
3261
|
+
if (t.pending && t.pendingLink && t === this[Et] && (t.pending = false, t.pendingLink = false), !t.pending) {
|
|
3262
|
+
if (t.entry) {
|
|
3263
|
+
t === this[Et] && !t.piped && this[di](t);
|
|
3264
|
+
return;
|
|
3265
|
+
}
|
|
3266
|
+
if (!t.stat) {
|
|
3267
|
+
let e = this.statCache.get(t.absolute);
|
|
3268
|
+
e ? this[li](t, e) : this[ds](t);
|
|
3269
|
+
}
|
|
3270
|
+
if (t.stat && !t.ignore) {
|
|
3271
|
+
if (!this.noDirRecurse && t.stat.isDirectory() && !t.readdir) {
|
|
3272
|
+
let e = this.readdirCache.get(t.absolute);
|
|
3273
|
+
if (e ? this[fi](t, e) : this[us](t), !t.readdir) return;
|
|
3274
|
+
}
|
|
3275
|
+
if (t.entry = this[hr](t), !t.entry) {
|
|
3276
|
+
t.ignore = true;
|
|
3277
|
+
return;
|
|
3278
|
+
}
|
|
3279
|
+
t === this[Et] && !t.piped && this[di](t);
|
|
3280
|
+
}
|
|
3281
|
+
}
|
|
3282
|
+
}
|
|
3283
|
+
[cs](t) {
|
|
3284
|
+
return { onwarn: (e, i, r) => this.warn(e, i, r), noPax: this.noPax, cwd: this.cwd, absolute: t.absolute, preservePaths: this.preservePaths, maxReadSize: this.maxReadSize, strict: this.strict, portable: this.portable, linkCache: this.linkCache, statCache: this.statCache, noMtime: this.noMtime, mtime: this.mtime, prefix: this.prefix, onWriteEntry: this.onWriteEntry };
|
|
3285
|
+
}
|
|
3286
|
+
[hr](t) {
|
|
3287
|
+
this[G] += 1;
|
|
3288
|
+
try {
|
|
3289
|
+
return new this[ui](t.path, this[cs](t)).on("end", () => this[ls](t)).on("error", (i) => this.emit("error", i));
|
|
3290
|
+
} catch (e) {
|
|
3291
|
+
this.emit("error", e);
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
3294
|
+
[fs]() {
|
|
3295
|
+
this[Et] && this[Et].entry && this[Et].entry.resume();
|
|
3296
|
+
}
|
|
3297
|
+
[di](t) {
|
|
3298
|
+
t.piped = true, t.readdir && t.readdir.forEach((r) => {
|
|
3299
|
+
let n = t.path, o = n === "./" ? "" : n.replace(/\/*$/, "/");
|
|
3300
|
+
this[ci](o + r);
|
|
3301
|
+
});
|
|
3302
|
+
let e = t.entry, i = this.zip;
|
|
3303
|
+
if (!e) throw new Error("cannot pipe without source");
|
|
3304
|
+
i ? e.on("data", (r) => {
|
|
3305
|
+
i.write(r) || e.pause();
|
|
3306
|
+
}) : e.on("data", (r) => {
|
|
3307
|
+
super.write(r) || e.pause();
|
|
3308
|
+
});
|
|
3309
|
+
}
|
|
3310
|
+
pause() {
|
|
3311
|
+
return this.zip && this.zip.pause(), super.pause();
|
|
3312
|
+
}
|
|
3313
|
+
warn(t, e, i = {}) {
|
|
3314
|
+
Dt(this, t, e, i);
|
|
3315
|
+
}
|
|
3316
|
+
};
|
|
3317
|
+
var kt = class extends wt {
|
|
3318
|
+
sync = true;
|
|
3319
|
+
constructor(t) {
|
|
3320
|
+
super(t), this[ui] = ni;
|
|
3321
|
+
}
|
|
3322
|
+
pause() {
|
|
3323
|
+
}
|
|
3324
|
+
resume() {
|
|
3325
|
+
}
|
|
3326
|
+
[ds](t) {
|
|
3327
|
+
let e = this.follow ? "statSync" : "lstatSync";
|
|
3328
|
+
this[li](t, mi[e](t.absolute));
|
|
3329
|
+
}
|
|
3330
|
+
[us](t) {
|
|
3331
|
+
this[fi](t, mi.readdirSync(t.absolute));
|
|
3332
|
+
}
|
|
3333
|
+
[di](t) {
|
|
3334
|
+
let e = t.entry, i = this.zip;
|
|
3335
|
+
if (t.readdir && t.readdir.forEach((r) => {
|
|
3336
|
+
let n = t.path, o = n === "./" ? "" : n.replace(/\/*$/, "/");
|
|
3337
|
+
this[ci](o + r);
|
|
3338
|
+
}), !e) throw new Error("Cannot pipe without source");
|
|
3339
|
+
i ? e.on("data", (r) => {
|
|
3340
|
+
i.write(r);
|
|
3341
|
+
}) : e.on("data", (r) => {
|
|
3342
|
+
super[lr](r);
|
|
3343
|
+
});
|
|
3344
|
+
}
|
|
3345
|
+
};
|
|
3346
|
+
var Vn = (s3, t) => {
|
|
3347
|
+
let e = new kt(s3), i = new Wt(s3.file, { mode: s3.mode || 438 });
|
|
3348
|
+
e.pipe(i), fr(e, t);
|
|
3349
|
+
};
|
|
3350
|
+
var $n = (s3, t) => {
|
|
3351
|
+
let e = new wt(s3), i = new et(s3.file, { mode: s3.mode || 438 });
|
|
3352
|
+
e.pipe(i);
|
|
3353
|
+
let r = new Promise((n, o) => {
|
|
3354
|
+
i.on("error", o), i.on("close", n), e.on("error", o);
|
|
3355
|
+
});
|
|
3356
|
+
return dr(e, t).catch((n) => e.emit("error", n)), r;
|
|
3357
|
+
};
|
|
3358
|
+
var fr = (s3, t) => {
|
|
3359
|
+
t.forEach((e) => {
|
|
3360
|
+
e.charAt(0) === "@" ? Ct({ file: cr.resolve(s3.cwd, e.slice(1)), sync: true, noResume: true, onReadEntry: (i) => s3.add(i) }) : s3.add(e);
|
|
3361
|
+
}), s3.end();
|
|
3362
|
+
};
|
|
3363
|
+
var dr = async (s3, t) => {
|
|
3364
|
+
for (let e of t) e.charAt(0) === "@" ? await Ct({ file: cr.resolve(String(s3.cwd), e.slice(1)), noResume: true, onReadEntry: (i) => {
|
|
3365
|
+
s3.add(i);
|
|
3366
|
+
} }) : s3.add(e);
|
|
3367
|
+
s3.end();
|
|
3368
|
+
};
|
|
3369
|
+
var Xn = (s3, t) => {
|
|
3370
|
+
let e = new kt(s3);
|
|
3371
|
+
return fr(e, t), e;
|
|
3372
|
+
};
|
|
3373
|
+
var qn = (s3, t) => {
|
|
3374
|
+
let e = new wt(s3);
|
|
3375
|
+
return dr(e, t).catch((i) => e.emit("error", i)), e;
|
|
3376
|
+
};
|
|
3377
|
+
var Qn = K(Vn, $n, Xn, qn, (s3, t) => {
|
|
3378
|
+
if (!t?.length) throw new TypeError("no paths specified to add to archive");
|
|
3379
|
+
});
|
|
3380
|
+
var Jn = process.env.__FAKE_PLATFORM__ || process.platform;
|
|
3381
|
+
var Er = Jn === "win32";
|
|
3382
|
+
var { O_CREAT: wr, O_NOFOLLOW: ur, O_TRUNC: Sr, O_WRONLY: yr } = pr.constants;
|
|
3383
|
+
var Rr = Number(process.env.__FAKE_FS_O_FILENAME__) || pr.constants.UV_FS_O_FILEMAP || 0;
|
|
3384
|
+
var jn = Er && !!Rr;
|
|
3385
|
+
var to = 512 * 1024;
|
|
3386
|
+
var eo = Rr | Sr | wr | yr;
|
|
3387
|
+
var mr = !Er && typeof ur == "number" ? ur | Sr | wr | yr : null;
|
|
3388
|
+
var ms = mr !== null ? () => mr : jn ? (s3) => s3 < to ? eo : "w" : () => "w";
|
|
3389
|
+
var ps = (s3, t, e) => {
|
|
3390
|
+
try {
|
|
3391
|
+
return wi.lchownSync(s3, t, e);
|
|
3392
|
+
} catch (i) {
|
|
3393
|
+
if (i?.code !== "ENOENT") throw i;
|
|
3394
|
+
}
|
|
3395
|
+
};
|
|
3396
|
+
var Ei = (s3, t, e, i) => {
|
|
3397
|
+
wi.lchown(s3, t, e, (r) => {
|
|
3398
|
+
i(r && r?.code !== "ENOENT" ? r : null);
|
|
3399
|
+
});
|
|
3400
|
+
};
|
|
3401
|
+
var io = (s3, t, e, i, r) => {
|
|
3402
|
+
if (t.isDirectory()) Es(we.resolve(s3, t.name), e, i, (n) => {
|
|
3403
|
+
if (n) return r(n);
|
|
3404
|
+
let o = we.resolve(s3, t.name);
|
|
3405
|
+
Ei(o, e, i, r);
|
|
3406
|
+
});
|
|
3407
|
+
else {
|
|
3408
|
+
let n = we.resolve(s3, t.name);
|
|
3409
|
+
Ei(n, e, i, r);
|
|
3410
|
+
}
|
|
3411
|
+
};
|
|
3412
|
+
var Es = (s3, t, e, i) => {
|
|
3413
|
+
wi.readdir(s3, { withFileTypes: true }, (r, n) => {
|
|
3414
|
+
if (r) {
|
|
3415
|
+
if (r.code === "ENOENT") return i();
|
|
3416
|
+
if (r.code !== "ENOTDIR" && r.code !== "ENOTSUP") return i(r);
|
|
3417
|
+
}
|
|
3418
|
+
if (r || !n.length) return Ei(s3, t, e, i);
|
|
3419
|
+
let o = n.length, h = null, a = (l) => {
|
|
3420
|
+
if (!h) {
|
|
3421
|
+
if (l) return i(h = l);
|
|
3422
|
+
if (--o === 0) return Ei(s3, t, e, i);
|
|
3423
|
+
}
|
|
3424
|
+
};
|
|
3425
|
+
for (let l of n) io(s3, l, t, e, a);
|
|
3426
|
+
});
|
|
3427
|
+
};
|
|
3428
|
+
var so = (s3, t, e, i) => {
|
|
3429
|
+
t.isDirectory() && ws(we.resolve(s3, t.name), e, i), ps(we.resolve(s3, t.name), e, i);
|
|
3430
|
+
};
|
|
3431
|
+
var ws = (s3, t, e) => {
|
|
3432
|
+
let i;
|
|
3433
|
+
try {
|
|
3434
|
+
i = wi.readdirSync(s3, { withFileTypes: true });
|
|
3435
|
+
} catch (r) {
|
|
3436
|
+
let n = r;
|
|
3437
|
+
if (n?.code === "ENOENT") return;
|
|
3438
|
+
if (n?.code === "ENOTDIR" || n?.code === "ENOTSUP") return ps(s3, t, e);
|
|
3439
|
+
throw n;
|
|
3440
|
+
}
|
|
3441
|
+
for (let r of i) so(s3, r, t, e);
|
|
3442
|
+
return ps(s3, t, e);
|
|
3443
|
+
};
|
|
3444
|
+
var Se = class extends Error {
|
|
3445
|
+
path;
|
|
3446
|
+
code;
|
|
3447
|
+
syscall = "chdir";
|
|
3448
|
+
constructor(t, e) {
|
|
3449
|
+
super(`${e}: Cannot cd into '${t}'`), this.path = t, this.code = e;
|
|
3450
|
+
}
|
|
3451
|
+
get name() {
|
|
3452
|
+
return "CwdError";
|
|
3453
|
+
}
|
|
3454
|
+
};
|
|
3455
|
+
var St = class extends Error {
|
|
3456
|
+
path;
|
|
3457
|
+
symlink;
|
|
3458
|
+
syscall = "symlink";
|
|
3459
|
+
code = "TAR_SYMLINK_ERROR";
|
|
3460
|
+
constructor(t, e) {
|
|
3461
|
+
super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"), this.symlink = t, this.path = e;
|
|
3462
|
+
}
|
|
3463
|
+
get name() {
|
|
3464
|
+
return "SymlinkError";
|
|
3465
|
+
}
|
|
3466
|
+
};
|
|
3467
|
+
var no = (s3, t) => {
|
|
3468
|
+
k.stat(s3, (e, i) => {
|
|
3469
|
+
(e || !i.isDirectory()) && (e = new Se(s3, e?.code || "ENOTDIR")), t(e);
|
|
3470
|
+
});
|
|
3471
|
+
};
|
|
3472
|
+
var gr = (s3, t, e) => {
|
|
3473
|
+
s3 = f(s3);
|
|
3474
|
+
let i = t.umask ?? 18, r = t.mode | 448, n = (r & i) !== 0, o = t.uid, h = t.gid, a = typeof o == "number" && typeof h == "number" && (o !== t.processUid || h !== t.processGid), l = t.preserve, c = t.unlink, d = f(t.cwd), y = (E, x) => {
|
|
3475
|
+
E ? e(E) : x && a ? Es(x, o, h, (Le) => y(Le)) : n ? k.chmod(s3, r, e) : e();
|
|
3476
|
+
};
|
|
3477
|
+
if (s3 === d) return no(s3, y);
|
|
3478
|
+
if (l) return ro.mkdir(s3, { mode: r, recursive: true }).then((E) => y(null, E ?? void 0), y);
|
|
3479
|
+
let D = f(Si.relative(d, s3)).split("/");
|
|
3480
|
+
Ss(d, D, r, c, d, void 0, y);
|
|
3481
|
+
};
|
|
3482
|
+
var Ss = (s3, t, e, i, r, n, o) => {
|
|
3483
|
+
if (t.length === 0) return o(null, n);
|
|
3484
|
+
let h = t.shift(), a = f(Si.resolve(s3 + "/" + h));
|
|
3485
|
+
k.mkdir(a, e, br(a, t, e, i, r, n, o));
|
|
3486
|
+
};
|
|
3487
|
+
var br = (s3, t, e, i, r, n, o) => (h) => {
|
|
3488
|
+
h ? k.lstat(s3, (a, l) => {
|
|
3489
|
+
if (a) a.path = a.path && f(a.path), o(a);
|
|
3490
|
+
else if (l.isDirectory()) Ss(s3, t, e, i, r, n, o);
|
|
3491
|
+
else if (i) k.unlink(s3, (c) => {
|
|
3492
|
+
if (c) return o(c);
|
|
3493
|
+
k.mkdir(s3, e, br(s3, t, e, i, r, n, o));
|
|
3494
|
+
});
|
|
3495
|
+
else {
|
|
3496
|
+
if (l.isSymbolicLink()) return o(new St(s3, s3 + "/" + t.join("/")));
|
|
3497
|
+
o(h);
|
|
3498
|
+
}
|
|
3499
|
+
}) : (n = n || s3, Ss(s3, t, e, i, r, n, o));
|
|
3500
|
+
};
|
|
3501
|
+
var oo = (s3) => {
|
|
3502
|
+
let t = false, e;
|
|
3503
|
+
try {
|
|
3504
|
+
t = k.statSync(s3).isDirectory();
|
|
3505
|
+
} catch (i) {
|
|
3506
|
+
e = i?.code;
|
|
3507
|
+
} finally {
|
|
3508
|
+
if (!t) throw new Se(s3, e ?? "ENOTDIR");
|
|
3509
|
+
}
|
|
3510
|
+
};
|
|
3511
|
+
var _r = (s3, t) => {
|
|
3512
|
+
s3 = f(s3);
|
|
3513
|
+
let e = t.umask ?? 18, i = t.mode | 448, r = (i & e) !== 0, n = t.uid, o = t.gid, h = typeof n == "number" && typeof o == "number" && (n !== t.processUid || o !== t.processGid), a = t.preserve, l = t.unlink, c = f(t.cwd), d = (E) => {
|
|
3514
|
+
E && h && ws(E, n, o), r && k.chmodSync(s3, i);
|
|
3515
|
+
};
|
|
3516
|
+
if (s3 === c) return oo(c), d();
|
|
3517
|
+
if (a) return d(k.mkdirSync(s3, { mode: i, recursive: true }) ?? void 0);
|
|
3518
|
+
let T = f(Si.relative(c, s3)).split("/"), D;
|
|
3519
|
+
for (let E = T.shift(), x = c; E && (x += "/" + E); E = T.shift()) {
|
|
3520
|
+
x = f(Si.resolve(x));
|
|
3521
|
+
try {
|
|
3522
|
+
k.mkdirSync(x, i), D = D || x;
|
|
3523
|
+
} catch {
|
|
3524
|
+
let Le = k.lstatSync(x);
|
|
3525
|
+
if (Le.isDirectory()) continue;
|
|
3526
|
+
if (l) {
|
|
3527
|
+
k.unlinkSync(x), k.mkdirSync(x, i), D = D || x;
|
|
3528
|
+
continue;
|
|
3529
|
+
} else if (Le.isSymbolicLink()) return new St(x, x + "/" + T.join("/"));
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3532
|
+
return d(D);
|
|
3533
|
+
};
|
|
3534
|
+
var ys = /* @__PURE__ */ Object.create(null);
|
|
3535
|
+
var Or = 1e4;
|
|
3536
|
+
var Vt = /* @__PURE__ */ new Set();
|
|
3537
|
+
var Tr = (s3) => {
|
|
3538
|
+
Vt.has(s3) ? Vt.delete(s3) : ys[s3] = s3.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"), Vt.add(s3);
|
|
3539
|
+
let t = ys[s3], e = Vt.size - Or;
|
|
3540
|
+
if (e > Or / 10) {
|
|
3541
|
+
for (let i of Vt) if (Vt.delete(i), delete ys[i], --e <= 0) break;
|
|
3542
|
+
}
|
|
3543
|
+
return t;
|
|
3544
|
+
};
|
|
3545
|
+
var ho = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform;
|
|
3546
|
+
var ao = ho === "win32";
|
|
3547
|
+
var lo = (s3) => s3.split("/").slice(0, -1).reduce((e, i) => {
|
|
3548
|
+
let r = e.at(-1);
|
|
3549
|
+
return r !== void 0 && (i = xr(r, i)), e.push(i || "/"), e;
|
|
3550
|
+
}, []);
|
|
3551
|
+
var yi = class {
|
|
3552
|
+
#t = /* @__PURE__ */ new Map();
|
|
3553
|
+
#i = /* @__PURE__ */ new Map();
|
|
3554
|
+
#s = /* @__PURE__ */ new Set();
|
|
3555
|
+
reserve(t, e) {
|
|
3556
|
+
t = ao ? ["win32 parallelization disabled"] : t.map((r) => mt(xr(Tr(r))));
|
|
3557
|
+
let i = new Set(t.map((r) => lo(r)).reduce((r, n) => r.concat(n)));
|
|
3558
|
+
this.#i.set(e, { dirs: i, paths: t });
|
|
3559
|
+
for (let r of t) {
|
|
3560
|
+
let n = this.#t.get(r);
|
|
3561
|
+
n ? n.push(e) : this.#t.set(r, [e]);
|
|
3562
|
+
}
|
|
3563
|
+
for (let r of i) {
|
|
3564
|
+
let n = this.#t.get(r);
|
|
3565
|
+
if (!n) this.#t.set(r, [/* @__PURE__ */ new Set([e])]);
|
|
3566
|
+
else {
|
|
3567
|
+
let o = n.at(-1);
|
|
3568
|
+
o instanceof Set ? o.add(e) : n.push(/* @__PURE__ */ new Set([e]));
|
|
3569
|
+
}
|
|
3570
|
+
}
|
|
3571
|
+
return this.#r(e);
|
|
3572
|
+
}
|
|
3573
|
+
#n(t) {
|
|
3574
|
+
let e = this.#i.get(t);
|
|
3575
|
+
if (!e) throw new Error("function does not have any path reservations");
|
|
3576
|
+
return { paths: e.paths.map((i) => this.#t.get(i)), dirs: [...e.dirs].map((i) => this.#t.get(i)) };
|
|
3577
|
+
}
|
|
3578
|
+
check(t) {
|
|
3579
|
+
let { paths: e, dirs: i } = this.#n(t);
|
|
3580
|
+
return e.every((r) => r && r[0] === t) && i.every((r) => r && r[0] instanceof Set && r[0].has(t));
|
|
3581
|
+
}
|
|
3582
|
+
#r(t) {
|
|
3583
|
+
return this.#s.has(t) || !this.check(t) ? false : (this.#s.add(t), t(() => this.#e(t)), true);
|
|
3584
|
+
}
|
|
3585
|
+
#e(t) {
|
|
3586
|
+
if (!this.#s.has(t)) return false;
|
|
3587
|
+
let e = this.#i.get(t);
|
|
3588
|
+
if (!e) throw new Error("invalid reservation");
|
|
3589
|
+
let { paths: i, dirs: r } = e, n = /* @__PURE__ */ new Set();
|
|
3590
|
+
for (let o of i) {
|
|
3591
|
+
let h = this.#t.get(o);
|
|
3592
|
+
if (!h || h?.[0] !== t) continue;
|
|
3593
|
+
let a = h[1];
|
|
3594
|
+
if (!a) {
|
|
3595
|
+
this.#t.delete(o);
|
|
3596
|
+
continue;
|
|
3597
|
+
}
|
|
3598
|
+
if (h.shift(), typeof a == "function") n.add(a);
|
|
3599
|
+
else for (let l of a) n.add(l);
|
|
3600
|
+
}
|
|
3601
|
+
for (let o of r) {
|
|
3602
|
+
let h = this.#t.get(o), a = h?.[0];
|
|
3603
|
+
if (!(!h || !(a instanceof Set))) if (a.size === 1 && h.length === 1) {
|
|
3604
|
+
this.#t.delete(o);
|
|
3605
|
+
continue;
|
|
3606
|
+
} else if (a.size === 1) {
|
|
3607
|
+
h.shift();
|
|
3608
|
+
let l = h[0];
|
|
3609
|
+
typeof l == "function" && n.add(l);
|
|
3610
|
+
} else a.delete(t);
|
|
3611
|
+
}
|
|
3612
|
+
return this.#s.delete(t), n.forEach((o) => this.#r(o)), true;
|
|
3613
|
+
}
|
|
3614
|
+
};
|
|
3615
|
+
var Lr = () => process.umask();
|
|
3616
|
+
var Dr = /* @__PURE__ */ Symbol("onEntry");
|
|
3617
|
+
var _s = /* @__PURE__ */ Symbol("checkFs");
|
|
3618
|
+
var Nr = /* @__PURE__ */ Symbol("checkFs2");
|
|
3619
|
+
var Os = /* @__PURE__ */ Symbol("isReusable");
|
|
3620
|
+
var P = /* @__PURE__ */ Symbol("makeFs");
|
|
3621
|
+
var Ts = /* @__PURE__ */ Symbol("file");
|
|
3622
|
+
var xs = /* @__PURE__ */ Symbol("directory");
|
|
3623
|
+
var gi = /* @__PURE__ */ Symbol("link");
|
|
3624
|
+
var Ar = /* @__PURE__ */ Symbol("symlink");
|
|
3625
|
+
var Ir = /* @__PURE__ */ Symbol("hardlink");
|
|
3626
|
+
var Re = /* @__PURE__ */ Symbol("ensureNoSymlink");
|
|
3627
|
+
var Cr = /* @__PURE__ */ Symbol("unsupported");
|
|
3628
|
+
var Fr = /* @__PURE__ */ Symbol("checkPath");
|
|
3629
|
+
var Rs = /* @__PURE__ */ Symbol("stripAbsolutePath");
|
|
3630
|
+
var yt = /* @__PURE__ */ Symbol("mkdir");
|
|
3631
|
+
var O = /* @__PURE__ */ Symbol("onError");
|
|
3632
|
+
var Ri = /* @__PURE__ */ Symbol("pending");
|
|
3633
|
+
var kr = /* @__PURE__ */ Symbol("pend");
|
|
3634
|
+
var $t = /* @__PURE__ */ Symbol("unpend");
|
|
3635
|
+
var gs = /* @__PURE__ */ Symbol("ended");
|
|
3636
|
+
var bs = /* @__PURE__ */ Symbol("maybeClose");
|
|
3637
|
+
var Ls = /* @__PURE__ */ Symbol("skip");
|
|
3638
|
+
var ge = /* @__PURE__ */ Symbol("doChown");
|
|
3639
|
+
var be = /* @__PURE__ */ Symbol("uid");
|
|
3640
|
+
var _e = /* @__PURE__ */ Symbol("gid");
|
|
3641
|
+
var Oe = /* @__PURE__ */ Symbol("checkedCwd");
|
|
3642
|
+
var fo = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform;
|
|
3643
|
+
var Te = fo === "win32";
|
|
3644
|
+
var uo = 1024;
|
|
3645
|
+
var mo = (s3, t) => {
|
|
3646
|
+
if (!Te) return u.unlink(s3, t);
|
|
3647
|
+
let e = s3 + ".DELETE." + Mr(16).toString("hex");
|
|
3648
|
+
u.rename(s3, e, (i) => {
|
|
3649
|
+
if (i) return t(i);
|
|
3650
|
+
u.unlink(e, t);
|
|
3651
|
+
});
|
|
3652
|
+
};
|
|
3653
|
+
var po = (s3) => {
|
|
3654
|
+
if (!Te) return u.unlinkSync(s3);
|
|
3655
|
+
let t = s3 + ".DELETE." + Mr(16).toString("hex");
|
|
3656
|
+
u.renameSync(s3, t), u.unlinkSync(t);
|
|
3657
|
+
};
|
|
3658
|
+
var vr = (s3, t, e) => s3 !== void 0 && s3 === s3 >>> 0 ? s3 : t !== void 0 && t === t >>> 0 ? t : e;
|
|
3659
|
+
var Xt = class extends rt {
|
|
3660
|
+
[gs] = false;
|
|
3661
|
+
[Oe] = false;
|
|
3662
|
+
[Ri] = 0;
|
|
3663
|
+
reservations = new yi();
|
|
3664
|
+
transform;
|
|
3665
|
+
writable = true;
|
|
3666
|
+
readable = false;
|
|
3667
|
+
uid;
|
|
3668
|
+
gid;
|
|
3669
|
+
setOwner;
|
|
3670
|
+
preserveOwner;
|
|
3671
|
+
processGid;
|
|
3672
|
+
processUid;
|
|
3673
|
+
maxDepth;
|
|
3674
|
+
forceChown;
|
|
3675
|
+
win32;
|
|
3676
|
+
newer;
|
|
3677
|
+
keep;
|
|
3678
|
+
noMtime;
|
|
3679
|
+
preservePaths;
|
|
3680
|
+
unlink;
|
|
3681
|
+
cwd;
|
|
3682
|
+
strip;
|
|
3683
|
+
processUmask;
|
|
3684
|
+
umask;
|
|
3685
|
+
dmode;
|
|
3686
|
+
fmode;
|
|
3687
|
+
chmod;
|
|
3688
|
+
constructor(t = {}) {
|
|
3689
|
+
if (t.ondone = () => {
|
|
3690
|
+
this[gs] = true, this[bs]();
|
|
3691
|
+
}, super(t), this.transform = t.transform, this.chmod = !!t.chmod, typeof t.uid == "number" || typeof t.gid == "number") {
|
|
3692
|
+
if (typeof t.uid != "number" || typeof t.gid != "number") throw new TypeError("cannot set owner without number uid and gid");
|
|
3693
|
+
if (t.preserveOwner) throw new TypeError("cannot preserve owner in archive and also set owner explicitly");
|
|
3694
|
+
this.uid = t.uid, this.gid = t.gid, this.setOwner = true;
|
|
3695
|
+
} else this.uid = void 0, this.gid = void 0, this.setOwner = false;
|
|
3696
|
+
this.preserveOwner = t.preserveOwner === void 0 && typeof t.uid != "number" ? process.getuid?.() === 0 : !!t.preserveOwner, this.processUid = (this.preserveOwner || this.setOwner) && process.getuid ? process.getuid() : void 0, this.processGid = (this.preserveOwner || this.setOwner) && process.getgid ? process.getgid() : void 0, this.maxDepth = typeof t.maxDepth == "number" ? t.maxDepth : uo, this.forceChown = t.forceChown === true, this.win32 = !!t.win32 || Te, this.newer = !!t.newer, this.keep = !!t.keep, this.noMtime = !!t.noMtime, this.preservePaths = !!t.preservePaths, this.unlink = !!t.unlink, this.cwd = f(R.resolve(t.cwd || process.cwd())), this.strip = Number(t.strip) || 0, this.processUmask = this.chmod ? typeof t.processUmask == "number" ? t.processUmask : Lr() : 0, this.umask = typeof t.umask == "number" ? t.umask : this.processUmask, this.dmode = t.dmode || 511 & ~this.umask, this.fmode = t.fmode || 438 & ~this.umask, this.on("entry", (e) => this[Dr](e));
|
|
3697
|
+
}
|
|
3698
|
+
warn(t, e, i = {}) {
|
|
3699
|
+
return (t === "TAR_BAD_ARCHIVE" || t === "TAR_ABORT") && (i.recoverable = false), super.warn(t, e, i);
|
|
3700
|
+
}
|
|
3701
|
+
[bs]() {
|
|
3702
|
+
this[gs] && this[Ri] === 0 && (this.emit("prefinish"), this.emit("finish"), this.emit("end"));
|
|
3703
|
+
}
|
|
3704
|
+
[Rs](t, e) {
|
|
3705
|
+
let i = t[e], { type: r } = t;
|
|
3706
|
+
if (!i || this.preservePaths) return true;
|
|
3707
|
+
let [n, o] = ce(i), h = o.replaceAll(/\\/g, "/").split("/");
|
|
3708
|
+
if (h.includes("..") || Te && /^[a-z]:\.\.$/i.test(h[0] ?? "")) {
|
|
3709
|
+
if (e === "path" || r === "Link") return this.warn("TAR_ENTRY_ERROR", `${e} contains '..'`, { entry: t, [e]: i }), false;
|
|
3710
|
+
let a = R.posix.dirname(t.path), l = R.posix.normalize(R.posix.join(a, h.join("/")));
|
|
3711
|
+
if (l.startsWith("../") || l === "..") return this.warn("TAR_ENTRY_ERROR", `${e} escapes extraction directory`, { entry: t, [e]: i }), false;
|
|
3712
|
+
}
|
|
3713
|
+
return n && (t[e] = String(o), this.warn("TAR_ENTRY_INFO", `stripping ${n} from absolute ${e}`, { entry: t, [e]: i })), true;
|
|
3714
|
+
}
|
|
3715
|
+
[Fr](t) {
|
|
3716
|
+
let e = f(t.path), i = e.split("/");
|
|
3717
|
+
if (this.strip) {
|
|
3718
|
+
if (i.length < this.strip) return false;
|
|
3719
|
+
if (t.type === "Link") {
|
|
3720
|
+
let r = f(String(t.linkpath)).split("/");
|
|
3721
|
+
if (r.length >= this.strip) t.linkpath = r.slice(this.strip).join("/");
|
|
3722
|
+
else return false;
|
|
3723
|
+
}
|
|
3724
|
+
i.splice(0, this.strip), t.path = i.join("/");
|
|
3725
|
+
}
|
|
3726
|
+
if (isFinite(this.maxDepth) && i.length > this.maxDepth) return this.warn("TAR_ENTRY_ERROR", "path excessively deep", { entry: t, path: e, depth: i.length, maxDepth: this.maxDepth }), false;
|
|
3727
|
+
if (!this[Rs](t, "path") || !this[Rs](t, "linkpath")) return false;
|
|
3728
|
+
if (t.absolute = R.isAbsolute(t.path) ? f(R.resolve(t.path)) : f(R.resolve(this.cwd, t.path)), !this.preservePaths && typeof t.absolute == "string" && t.absolute.indexOf(this.cwd + "/") !== 0 && t.absolute !== this.cwd) return this.warn("TAR_ENTRY_ERROR", "path escaped extraction target", { entry: t, path: f(t.path), resolvedPath: t.absolute, cwd: this.cwd }), false;
|
|
3729
|
+
if (t.absolute === this.cwd && t.type !== "Directory" && t.type !== "GNUDumpDir") return false;
|
|
3730
|
+
if (this.win32) {
|
|
3731
|
+
let { root: r } = R.win32.parse(String(t.absolute));
|
|
3732
|
+
t.absolute = r + ts(String(t.absolute).slice(r.length));
|
|
3733
|
+
let { root: n } = R.win32.parse(t.path);
|
|
3734
|
+
t.path = n + ts(t.path.slice(n.length));
|
|
3735
|
+
}
|
|
3736
|
+
return true;
|
|
3737
|
+
}
|
|
3738
|
+
[Dr](t) {
|
|
3739
|
+
if (!this[Fr](t)) return t.resume();
|
|
3740
|
+
switch (co.equal(typeof t.absolute, "string"), t.type) {
|
|
3741
|
+
case "Directory":
|
|
3742
|
+
case "GNUDumpDir":
|
|
3743
|
+
t.mode && (t.mode = t.mode | 448);
|
|
3744
|
+
case "File":
|
|
3745
|
+
case "OldFile":
|
|
3746
|
+
case "ContiguousFile":
|
|
3747
|
+
case "Link":
|
|
3748
|
+
case "SymbolicLink":
|
|
3749
|
+
return this[_s](t);
|
|
3750
|
+
default:
|
|
3751
|
+
return this[Cr](t);
|
|
3752
|
+
}
|
|
3753
|
+
}
|
|
3754
|
+
[O](t, e) {
|
|
3755
|
+
t.name === "CwdError" ? this.emit("error", t) : (this.warn("TAR_ENTRY_ERROR", t, { entry: e }), this[$t](), e.resume());
|
|
3756
|
+
}
|
|
3757
|
+
[yt](t, e, i) {
|
|
3758
|
+
gr(f(t), { uid: this.uid, gid: this.gid, processUid: this.processUid, processGid: this.processGid, umask: this.processUmask, preserve: this.preservePaths, unlink: this.unlink, cwd: this.cwd, mode: e }, i);
|
|
3759
|
+
}
|
|
3760
|
+
[ge](t) {
|
|
3761
|
+
return this.forceChown || this.preserveOwner && (typeof t.uid == "number" && t.uid !== this.processUid || typeof t.gid == "number" && t.gid !== this.processGid) || typeof this.uid == "number" && this.uid !== this.processUid || typeof this.gid == "number" && this.gid !== this.processGid;
|
|
3762
|
+
}
|
|
3763
|
+
[be](t) {
|
|
3764
|
+
return vr(this.uid, t.uid, this.processUid);
|
|
3765
|
+
}
|
|
3766
|
+
[_e](t) {
|
|
3767
|
+
return vr(this.gid, t.gid, this.processGid);
|
|
3768
|
+
}
|
|
3769
|
+
[Ts](t, e) {
|
|
3770
|
+
let i = typeof t.mode == "number" ? t.mode & 4095 : this.fmode, r = new et(String(t.absolute), { flags: ms(t.size), mode: i, autoClose: false });
|
|
3771
|
+
r.on("error", (a) => {
|
|
3772
|
+
r.fd && u.close(r.fd, () => {
|
|
3773
|
+
}), r.write = () => true, this[O](a, t), e();
|
|
3774
|
+
});
|
|
3775
|
+
let n = 1, o = (a) => {
|
|
3776
|
+
if (a) {
|
|
3777
|
+
r.fd && u.close(r.fd, () => {
|
|
3778
|
+
}), this[O](a, t), e();
|
|
3779
|
+
return;
|
|
3780
|
+
}
|
|
3781
|
+
--n === 0 && r.fd !== void 0 && u.close(r.fd, (l) => {
|
|
3782
|
+
l ? this[O](l, t) : this[$t](), e();
|
|
3783
|
+
});
|
|
3784
|
+
};
|
|
3785
|
+
r.on("finish", () => {
|
|
3786
|
+
let a = String(t.absolute), l = r.fd;
|
|
3787
|
+
if (typeof l == "number" && t.mtime && !this.noMtime) {
|
|
3788
|
+
n++;
|
|
3789
|
+
let c = t.atime || /* @__PURE__ */ new Date(), d = t.mtime;
|
|
3790
|
+
u.futimes(l, c, d, (y) => y ? u.utimes(a, c, d, (T) => o(T && y)) : o());
|
|
3791
|
+
}
|
|
3792
|
+
if (typeof l == "number" && this[ge](t)) {
|
|
3793
|
+
n++;
|
|
3794
|
+
let c = this[be](t), d = this[_e](t);
|
|
3795
|
+
typeof c == "number" && typeof d == "number" && u.fchown(l, c, d, (y) => y ? u.chown(a, c, d, (T) => o(T && y)) : o());
|
|
3796
|
+
}
|
|
3797
|
+
o();
|
|
3798
|
+
});
|
|
3799
|
+
let h = this.transform && this.transform(t) || t;
|
|
3800
|
+
h !== t && (h.on("error", (a) => {
|
|
3801
|
+
this[O](a, t), e();
|
|
3802
|
+
}), t.pipe(h)), h.pipe(r);
|
|
3803
|
+
}
|
|
3804
|
+
[xs](t, e) {
|
|
3805
|
+
let i = typeof t.mode == "number" ? t.mode & 4095 : this.dmode;
|
|
3806
|
+
this[yt](String(t.absolute), i, (r) => {
|
|
3807
|
+
if (r) {
|
|
3808
|
+
this[O](r, t), e();
|
|
3809
|
+
return;
|
|
3810
|
+
}
|
|
3811
|
+
let n = 1, o = () => {
|
|
3812
|
+
--n === 0 && (e(), this[$t](), t.resume());
|
|
3813
|
+
};
|
|
3814
|
+
t.mtime && !this.noMtime && (n++, u.utimes(String(t.absolute), t.atime || /* @__PURE__ */ new Date(), t.mtime, o)), this[ge](t) && (n++, u.chown(String(t.absolute), Number(this[be](t)), Number(this[_e](t)), o)), o();
|
|
3815
|
+
});
|
|
3816
|
+
}
|
|
3817
|
+
[Cr](t) {
|
|
3818
|
+
t.unsupported = true, this.warn("TAR_ENTRY_UNSUPPORTED", `unsupported entry type: ${t.type}`, { entry: t }), t.resume();
|
|
3819
|
+
}
|
|
3820
|
+
[Ar](t, e) {
|
|
3821
|
+
let i = f(R.relative(this.cwd, R.resolve(R.dirname(String(t.absolute)), String(t.linkpath)))).split("/");
|
|
3822
|
+
this[Re](t, this.cwd, i, () => this[gi](t, String(t.linkpath), "symlink", e), (r) => {
|
|
3823
|
+
this[O](r, t), e();
|
|
3824
|
+
});
|
|
3825
|
+
}
|
|
3826
|
+
[Ir](t, e) {
|
|
3827
|
+
let i = f(R.resolve(this.cwd, String(t.linkpath))), r = f(String(t.linkpath)).split("/");
|
|
3828
|
+
this[Re](t, this.cwd, r, () => this[gi](t, i, "link", e), (n) => {
|
|
3829
|
+
this[O](n, t), e();
|
|
3830
|
+
});
|
|
3831
|
+
}
|
|
3832
|
+
[Re](t, e, i, r, n) {
|
|
3833
|
+
let o = i.shift();
|
|
3834
|
+
if (this.preservePaths || o === void 0) return r();
|
|
3835
|
+
let h = R.resolve(e, o);
|
|
3836
|
+
u.lstat(h, (a, l) => {
|
|
3837
|
+
if (a) return r();
|
|
3838
|
+
if (l?.isSymbolicLink()) return n(new St(h, R.resolve(h, i.join("/"))));
|
|
3839
|
+
this[Re](t, h, i, r, n);
|
|
3840
|
+
});
|
|
3841
|
+
}
|
|
3842
|
+
[kr]() {
|
|
3843
|
+
this[Ri]++;
|
|
3844
|
+
}
|
|
3845
|
+
[$t]() {
|
|
3846
|
+
this[Ri]--, this[bs]();
|
|
3847
|
+
}
|
|
3848
|
+
[Ls](t) {
|
|
3849
|
+
this[$t](), t.resume();
|
|
3850
|
+
}
|
|
3851
|
+
[Os](t, e) {
|
|
3852
|
+
return t.type === "File" && !this.unlink && e.isFile() && e.nlink <= 1 && !Te;
|
|
3853
|
+
}
|
|
3854
|
+
[_s](t) {
|
|
3855
|
+
this[kr]();
|
|
3856
|
+
let e = [t.path];
|
|
3857
|
+
t.linkpath && e.push(t.linkpath), this.reservations.reserve(e, (i) => this[Nr](t, i));
|
|
3858
|
+
}
|
|
3859
|
+
[Nr](t, e) {
|
|
3860
|
+
let i = (h) => {
|
|
3861
|
+
e(h);
|
|
3862
|
+
}, r = () => {
|
|
3863
|
+
this[yt](this.cwd, this.dmode, (h) => {
|
|
3864
|
+
if (h) {
|
|
3865
|
+
this[O](h, t), i();
|
|
3866
|
+
return;
|
|
3867
|
+
}
|
|
3868
|
+
this[Oe] = true, n();
|
|
3869
|
+
});
|
|
3870
|
+
}, n = () => {
|
|
3871
|
+
if (t.absolute !== this.cwd) {
|
|
3872
|
+
let h = f(R.dirname(String(t.absolute)));
|
|
3873
|
+
if (h !== this.cwd) return this[yt](h, this.dmode, (a) => {
|
|
3874
|
+
if (a) {
|
|
3875
|
+
this[O](a, t), i();
|
|
3876
|
+
return;
|
|
3877
|
+
}
|
|
3878
|
+
o();
|
|
3879
|
+
});
|
|
3880
|
+
}
|
|
3881
|
+
o();
|
|
3882
|
+
}, o = () => {
|
|
3883
|
+
u.lstat(String(t.absolute), (h, a) => {
|
|
3884
|
+
if (a && (this.keep || this.newer && a.mtime > (t.mtime ?? a.mtime))) {
|
|
3885
|
+
this[Ls](t), i();
|
|
3886
|
+
return;
|
|
3887
|
+
}
|
|
3888
|
+
if (h || this[Os](t, a)) return this[P](null, t, i);
|
|
3889
|
+
if (a.isDirectory()) {
|
|
3890
|
+
if (t.type === "Directory") {
|
|
3891
|
+
let l = this.chmod && t.mode && (a.mode & 4095) !== t.mode, c = (d) => this[P](d ?? null, t, i);
|
|
3892
|
+
return l ? u.chmod(String(t.absolute), Number(t.mode), c) : c();
|
|
3893
|
+
}
|
|
3894
|
+
if (t.absolute !== this.cwd) return u.rmdir(String(t.absolute), (l) => this[P](l ?? null, t, i));
|
|
3895
|
+
}
|
|
3896
|
+
if (t.absolute === this.cwd) return this[P](null, t, i);
|
|
3897
|
+
mo(String(t.absolute), (l) => this[P](l ?? null, t, i));
|
|
3898
|
+
});
|
|
3899
|
+
};
|
|
3900
|
+
this[Oe] ? n() : r();
|
|
3901
|
+
}
|
|
3902
|
+
[P](t, e, i) {
|
|
3903
|
+
if (t) {
|
|
3904
|
+
this[O](t, e), i();
|
|
3905
|
+
return;
|
|
3906
|
+
}
|
|
3907
|
+
switch (e.type) {
|
|
3908
|
+
case "File":
|
|
3909
|
+
case "OldFile":
|
|
3910
|
+
case "ContiguousFile":
|
|
3911
|
+
return this[Ts](e, i);
|
|
3912
|
+
case "Link":
|
|
3913
|
+
return this[Ir](e, i);
|
|
3914
|
+
case "SymbolicLink":
|
|
3915
|
+
return this[Ar](e, i);
|
|
3916
|
+
case "Directory":
|
|
3917
|
+
case "GNUDumpDir":
|
|
3918
|
+
return this[xs](e, i);
|
|
3919
|
+
}
|
|
3920
|
+
}
|
|
3921
|
+
[gi](t, e, i, r) {
|
|
3922
|
+
u[i](e, String(t.absolute), (n) => {
|
|
3923
|
+
n ? this[O](n, t) : (this[$t](), t.resume()), r();
|
|
3924
|
+
});
|
|
3925
|
+
}
|
|
3926
|
+
};
|
|
3927
|
+
var ye = (s3) => {
|
|
3928
|
+
try {
|
|
3929
|
+
return [null, s3()];
|
|
3930
|
+
} catch (t) {
|
|
3931
|
+
return [t, null];
|
|
3932
|
+
}
|
|
3933
|
+
};
|
|
3934
|
+
var xe = class extends Xt {
|
|
3935
|
+
sync = true;
|
|
3936
|
+
[P](t, e) {
|
|
3937
|
+
return super[P](t, e, () => {
|
|
3938
|
+
});
|
|
3939
|
+
}
|
|
3940
|
+
[_s](t) {
|
|
3941
|
+
if (!this[Oe]) {
|
|
3942
|
+
let n = this[yt](this.cwd, this.dmode);
|
|
3943
|
+
if (n) return this[O](n, t);
|
|
3944
|
+
this[Oe] = true;
|
|
3945
|
+
}
|
|
3946
|
+
if (t.absolute !== this.cwd) {
|
|
3947
|
+
let n = f(R.dirname(String(t.absolute)));
|
|
3948
|
+
if (n !== this.cwd) {
|
|
3949
|
+
let o = this[yt](n, this.dmode);
|
|
3950
|
+
if (o) return this[O](o, t);
|
|
3951
|
+
}
|
|
3952
|
+
}
|
|
3953
|
+
let [e, i] = ye(() => u.lstatSync(String(t.absolute)));
|
|
3954
|
+
if (i && (this.keep || this.newer && i.mtime > (t.mtime ?? i.mtime))) return this[Ls](t);
|
|
3955
|
+
if (e || this[Os](t, i)) return this[P](null, t);
|
|
3956
|
+
if (i.isDirectory()) {
|
|
3957
|
+
if (t.type === "Directory") {
|
|
3958
|
+
let o = this.chmod && t.mode && (i.mode & 4095) !== t.mode, [h] = o ? ye(() => {
|
|
3959
|
+
u.chmodSync(String(t.absolute), Number(t.mode));
|
|
3960
|
+
}) : [];
|
|
3961
|
+
return this[P](h, t);
|
|
3962
|
+
}
|
|
3963
|
+
let [n] = ye(() => u.rmdirSync(String(t.absolute)));
|
|
3964
|
+
this[P](n, t);
|
|
3965
|
+
}
|
|
3966
|
+
let [r] = t.absolute === this.cwd ? [] : ye(() => po(String(t.absolute)));
|
|
3967
|
+
this[P](r, t);
|
|
3968
|
+
}
|
|
3969
|
+
[Ts](t, e) {
|
|
3970
|
+
let i = typeof t.mode == "number" ? t.mode & 4095 : this.fmode, r = (h) => {
|
|
3971
|
+
let a;
|
|
3972
|
+
try {
|
|
3973
|
+
u.closeSync(n);
|
|
3974
|
+
} catch (l) {
|
|
3975
|
+
a = l;
|
|
3976
|
+
}
|
|
3977
|
+
(h || a) && this[O](h || a, t), e();
|
|
3978
|
+
}, n;
|
|
3979
|
+
try {
|
|
3980
|
+
n = u.openSync(String(t.absolute), ms(t.size), i);
|
|
3981
|
+
} catch (h) {
|
|
3982
|
+
return r(h);
|
|
3983
|
+
}
|
|
3984
|
+
let o = this.transform && this.transform(t) || t;
|
|
3985
|
+
o !== t && (o.on("error", (h) => this[O](h, t)), t.pipe(o)), o.on("data", (h) => {
|
|
3986
|
+
try {
|
|
3987
|
+
u.writeSync(n, h, 0, h.length);
|
|
3988
|
+
} catch (a) {
|
|
3989
|
+
r(a);
|
|
3990
|
+
}
|
|
3991
|
+
}), o.on("end", () => {
|
|
3992
|
+
let h = null;
|
|
3993
|
+
if (t.mtime && !this.noMtime) {
|
|
3994
|
+
let a = t.atime || /* @__PURE__ */ new Date(), l = t.mtime;
|
|
3995
|
+
try {
|
|
3996
|
+
u.futimesSync(n, a, l);
|
|
3997
|
+
} catch (c) {
|
|
3998
|
+
try {
|
|
3999
|
+
u.utimesSync(String(t.absolute), a, l);
|
|
4000
|
+
} catch {
|
|
4001
|
+
h = c;
|
|
4002
|
+
}
|
|
4003
|
+
}
|
|
4004
|
+
}
|
|
4005
|
+
if (this[ge](t)) {
|
|
4006
|
+
let a = this[be](t), l = this[_e](t);
|
|
4007
|
+
try {
|
|
4008
|
+
u.fchownSync(n, Number(a), Number(l));
|
|
4009
|
+
} catch (c) {
|
|
4010
|
+
try {
|
|
4011
|
+
u.chownSync(String(t.absolute), Number(a), Number(l));
|
|
4012
|
+
} catch {
|
|
4013
|
+
h = h || c;
|
|
4014
|
+
}
|
|
4015
|
+
}
|
|
4016
|
+
}
|
|
4017
|
+
r(h);
|
|
4018
|
+
});
|
|
4019
|
+
}
|
|
4020
|
+
[xs](t, e) {
|
|
4021
|
+
let i = typeof t.mode == "number" ? t.mode & 4095 : this.dmode, r = this[yt](String(t.absolute), i);
|
|
4022
|
+
if (r) {
|
|
4023
|
+
this[O](r, t), e();
|
|
4024
|
+
return;
|
|
4025
|
+
}
|
|
4026
|
+
if (t.mtime && !this.noMtime) try {
|
|
4027
|
+
u.utimesSync(String(t.absolute), t.atime || /* @__PURE__ */ new Date(), t.mtime);
|
|
4028
|
+
} catch {
|
|
4029
|
+
}
|
|
4030
|
+
if (this[ge](t)) try {
|
|
4031
|
+
u.chownSync(String(t.absolute), Number(this[be](t)), Number(this[_e](t)));
|
|
4032
|
+
} catch {
|
|
4033
|
+
}
|
|
4034
|
+
e(), t.resume();
|
|
4035
|
+
}
|
|
4036
|
+
[yt](t, e) {
|
|
4037
|
+
try {
|
|
4038
|
+
return _r(f(t), { uid: this.uid, gid: this.gid, processUid: this.processUid, processGid: this.processGid, umask: this.processUmask, preserve: this.preservePaths, unlink: this.unlink, cwd: this.cwd, mode: e });
|
|
4039
|
+
} catch (i) {
|
|
4040
|
+
return i;
|
|
4041
|
+
}
|
|
4042
|
+
}
|
|
4043
|
+
[Re](t, e, i, r, n) {
|
|
4044
|
+
if (this.preservePaths || i.length === 0) return r();
|
|
4045
|
+
let o = e;
|
|
4046
|
+
for (let h of i) {
|
|
4047
|
+
o = R.resolve(o, h);
|
|
4048
|
+
let [a, l] = ye(() => u.lstatSync(o));
|
|
4049
|
+
if (a) return r();
|
|
4050
|
+
if (l.isSymbolicLink()) return n(new St(o, R.resolve(e, i.join("/"))));
|
|
4051
|
+
}
|
|
4052
|
+
r();
|
|
4053
|
+
}
|
|
4054
|
+
[gi](t, e, i, r) {
|
|
4055
|
+
let n = `${i}Sync`;
|
|
4056
|
+
try {
|
|
4057
|
+
u[n](e, String(t.absolute)), r(), t.resume();
|
|
4058
|
+
} catch (o) {
|
|
4059
|
+
return this[O](o, t);
|
|
4060
|
+
}
|
|
4061
|
+
}
|
|
4062
|
+
};
|
|
4063
|
+
var Eo = (s3) => {
|
|
4064
|
+
let t = new xe(s3), e = s3.file, i = Br.statSync(e), r = s3.maxReadSize || 16 * 1024 * 1024;
|
|
4065
|
+
new Be(e, { readSize: r, size: i.size }).pipe(t);
|
|
4066
|
+
};
|
|
4067
|
+
var wo = (s3, t) => {
|
|
4068
|
+
let e = new Xt(s3), i = s3.maxReadSize || 16 * 1024 * 1024, r = s3.file;
|
|
4069
|
+
return new Promise((o, h) => {
|
|
4070
|
+
e.on("error", h), e.on("close", o), Br.stat(r, (a, l) => {
|
|
4071
|
+
if (a) h(a);
|
|
4072
|
+
else {
|
|
4073
|
+
let c = new _t(r, { readSize: i, size: l.size });
|
|
4074
|
+
c.on("error", h), c.pipe(e);
|
|
4075
|
+
}
|
|
4076
|
+
});
|
|
4077
|
+
});
|
|
4078
|
+
};
|
|
4079
|
+
var So = K(Eo, wo, (s3) => new xe(s3), (s3) => new Xt(s3), (s3, t) => {
|
|
4080
|
+
t?.length && Qi(s3, t);
|
|
4081
|
+
});
|
|
4082
|
+
var yo = (s3, t) => {
|
|
4083
|
+
let e = new kt(s3), i = true, r, n;
|
|
4084
|
+
try {
|
|
4085
|
+
try {
|
|
4086
|
+
r = v.openSync(s3.file, "r+");
|
|
4087
|
+
} catch (a) {
|
|
4088
|
+
if (a?.code === "ENOENT") r = v.openSync(s3.file, "w+");
|
|
4089
|
+
else throw a;
|
|
4090
|
+
}
|
|
4091
|
+
let o = v.fstatSync(r), h = Buffer.alloc(512);
|
|
4092
|
+
t: for (n = 0; n < o.size; n += 512) {
|
|
4093
|
+
for (let c = 0, d = 0; c < 512; c += d) {
|
|
4094
|
+
if (d = v.readSync(r, h, c, h.length - c, n + c), n === 0 && h[0] === 31 && h[1] === 139) throw new Error("cannot append to compressed archives");
|
|
4095
|
+
if (!d) break t;
|
|
4096
|
+
}
|
|
4097
|
+
let a = new F(h);
|
|
4098
|
+
if (!a.cksumValid) break;
|
|
4099
|
+
let l = 512 * Math.ceil((a.size || 0) / 512);
|
|
4100
|
+
if (n + l + 512 > o.size) break;
|
|
4101
|
+
n += l, s3.mtimeCache && a.mtime && s3.mtimeCache.set(String(a.path), a.mtime);
|
|
4102
|
+
}
|
|
4103
|
+
i = false, Ro(s3, e, n, r, t);
|
|
4104
|
+
} finally {
|
|
4105
|
+
if (i) try {
|
|
4106
|
+
v.closeSync(r);
|
|
4107
|
+
} catch {
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
};
|
|
4111
|
+
var Ro = (s3, t, e, i, r) => {
|
|
4112
|
+
let n = new Wt(s3.file, { fd: i, start: e });
|
|
4113
|
+
t.pipe(n), bo(t, r);
|
|
4114
|
+
};
|
|
4115
|
+
var go = (s3, t) => {
|
|
4116
|
+
t = Array.from(t);
|
|
4117
|
+
let e = new wt(s3), i = (n, o, h) => {
|
|
4118
|
+
let a = (T, D) => {
|
|
4119
|
+
T ? v.close(n, (E) => h(T)) : h(null, D);
|
|
4120
|
+
}, l = 0;
|
|
4121
|
+
if (o === 0) return a(null, 0);
|
|
4122
|
+
let c = 0, d = Buffer.alloc(512), y = (T, D) => {
|
|
4123
|
+
if (T || D === void 0) return a(T);
|
|
4124
|
+
if (c += D, c < 512 && D) return v.read(n, d, c, d.length - c, l + c, y);
|
|
4125
|
+
if (l === 0 && d[0] === 31 && d[1] === 139) return a(new Error("cannot append to compressed archives"));
|
|
4126
|
+
if (c < 512) return a(null, l);
|
|
4127
|
+
let E = new F(d);
|
|
4128
|
+
if (!E.cksumValid) return a(null, l);
|
|
4129
|
+
let x = 512 * Math.ceil((E.size ?? 0) / 512);
|
|
4130
|
+
if (l + x + 512 > o || (l += x + 512, l >= o)) return a(null, l);
|
|
4131
|
+
s3.mtimeCache && E.mtime && s3.mtimeCache.set(String(E.path), E.mtime), c = 0, v.read(n, d, 0, 512, l, y);
|
|
4132
|
+
};
|
|
4133
|
+
v.read(n, d, 0, 512, l, y);
|
|
4134
|
+
};
|
|
4135
|
+
return new Promise((n, o) => {
|
|
4136
|
+
e.on("error", o);
|
|
4137
|
+
let h = "r+", a = (l, c) => {
|
|
4138
|
+
if (l && l.code === "ENOENT" && h === "r+") return h = "w+", v.open(s3.file, h, a);
|
|
4139
|
+
if (l || !c) return o(l);
|
|
4140
|
+
v.fstat(c, (d, y) => {
|
|
4141
|
+
if (d) return v.close(c, () => o(d));
|
|
4142
|
+
i(c, y.size, (T, D) => {
|
|
4143
|
+
if (T) return o(T);
|
|
4144
|
+
let E = new et(s3.file, { fd: c, start: D });
|
|
4145
|
+
e.pipe(E), E.on("error", o), E.on("close", n), _o(e, t);
|
|
4146
|
+
});
|
|
4147
|
+
});
|
|
4148
|
+
};
|
|
4149
|
+
v.open(s3.file, h, a);
|
|
4150
|
+
});
|
|
4151
|
+
};
|
|
4152
|
+
var bo = (s3, t) => {
|
|
4153
|
+
t.forEach((e) => {
|
|
4154
|
+
e.charAt(0) === "@" ? Ct({ file: Pr.resolve(s3.cwd, e.slice(1)), sync: true, noResume: true, onReadEntry: (i) => s3.add(i) }) : s3.add(e);
|
|
4155
|
+
}), s3.end();
|
|
4156
|
+
};
|
|
4157
|
+
var _o = async (s3, t) => {
|
|
4158
|
+
for (let e of t) e.charAt(0) === "@" ? await Ct({ file: Pr.resolve(String(s3.cwd), e.slice(1)), noResume: true, onReadEntry: (i) => s3.add(i) }) : s3.add(e);
|
|
4159
|
+
s3.end();
|
|
4160
|
+
};
|
|
4161
|
+
var vt = K(yo, go, () => {
|
|
4162
|
+
throw new TypeError("file is required");
|
|
4163
|
+
}, () => {
|
|
4164
|
+
throw new TypeError("file is required");
|
|
4165
|
+
}, (s3, t) => {
|
|
4166
|
+
if (!Bs(s3)) throw new TypeError("file is required");
|
|
4167
|
+
if (s3.gzip || s3.brotli || s3.zstd || s3.file.endsWith(".br") || s3.file.endsWith(".tbr")) throw new TypeError("cannot append to compressed archives");
|
|
4168
|
+
if (!t?.length) throw new TypeError("no paths specified to add/replace");
|
|
4169
|
+
});
|
|
4170
|
+
var Oo = K(vt.syncFile, vt.asyncFile, vt.syncNoFile, vt.asyncNoFile, (s3, t = []) => {
|
|
4171
|
+
vt.validate?.(s3, t), To(s3);
|
|
4172
|
+
});
|
|
4173
|
+
var To = (s3) => {
|
|
4174
|
+
let t = s3.filter;
|
|
4175
|
+
s3.mtimeCache || (s3.mtimeCache = /* @__PURE__ */ new Map()), s3.filter = t ? (e, i) => t(e, i) && !((s3.mtimeCache?.get(e) ?? i.mtime ?? 0) > (i.mtime ?? 0)) : (e, i) => !((s3.mtimeCache?.get(e) ?? i.mtime ?? 0) > (i.mtime ?? 0));
|
|
4176
|
+
};
|
|
4177
|
+
|
|
4178
|
+
// packages/cli/src/sync.ts
|
|
4179
|
+
var MAX_SYNC_ERROR_BODY_BYTES = 1536;
|
|
4180
|
+
function extractErrorBody(response) {
|
|
4181
|
+
return response.text().then((text) => text.slice(0, MAX_SYNC_ERROR_BODY_BYTES)).catch(() => "");
|
|
4182
|
+
}
|
|
4183
|
+
function buildSyncFailureMessage(operation, details) {
|
|
4184
|
+
const parts = [`${operation} falhou: ${details.status} ${details.statusText || "sem status"}`];
|
|
4185
|
+
if (details.requestId) parts.push(`x-forge-request-id=${details.requestId}`);
|
|
4186
|
+
if (details.body) parts.push(`resposta=${JSON.stringify(details.body)}`);
|
|
4187
|
+
return parts.join(" | ");
|
|
4188
|
+
}
|
|
4189
|
+
async function fetchManifest(credentials) {
|
|
4190
|
+
let response;
|
|
4191
|
+
try {
|
|
4192
|
+
response = await fetch(`${credentials.forgeBaseUrl.replace(/\/$/, "")}/sync/manifest`, {
|
|
4193
|
+
headers: {
|
|
4194
|
+
authorization: `Bearer ${credentials.forgeApiKey}`,
|
|
4195
|
+
"x-forge-hostname": os2.hostname(),
|
|
4196
|
+
"x-forge-agent-version": "0.1.0"
|
|
4197
|
+
},
|
|
4198
|
+
signal: AbortSignal.timeout(15e3)
|
|
4199
|
+
});
|
|
4200
|
+
} catch (error) {
|
|
4201
|
+
throw new Error(
|
|
4202
|
+
`Falha de rede a obter o manifesto. Verifique o endere\xE7o do Forge, autoriza\xE7\xE3o e conectividade: ${error instanceof Error ? error.message : "erro desconhecido"}`
|
|
4203
|
+
);
|
|
4204
|
+
}
|
|
4205
|
+
if (!response.ok) {
|
|
4206
|
+
const requestId = response.headers.get("x-forge-request-id");
|
|
4207
|
+
const responseText = await extractErrorBody(response);
|
|
4208
|
+
throw new Error(
|
|
4209
|
+
buildSyncFailureMessage("Pedido de manifesto", {
|
|
4210
|
+
status: response.status,
|
|
4211
|
+
statusText: response.statusText,
|
|
4212
|
+
requestId,
|
|
4213
|
+
body: responseText
|
|
4214
|
+
})
|
|
4215
|
+
);
|
|
4216
|
+
}
|
|
4217
|
+
let parsed;
|
|
4218
|
+
try {
|
|
4219
|
+
parsed = await response.json();
|
|
4220
|
+
} catch {
|
|
4221
|
+
throw new Error("O manifesto Forge n\xE3o cont\xE9m JSON v\xE1lido; a configura\xE7\xE3o local foi preservada.");
|
|
4222
|
+
}
|
|
4223
|
+
if (!validCoreManifest(parsed)) {
|
|
4224
|
+
throw new Error("O manifesto Forge n\xE3o cont\xE9m um provider e modelos aprovados v\xE1lidos; a configura\xE7\xE3o local foi preservada.");
|
|
4225
|
+
}
|
|
4226
|
+
return parsed;
|
|
4227
|
+
}
|
|
4228
|
+
function validCoreManifest(value) {
|
|
4229
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
4230
|
+
const manifest = value;
|
|
4231
|
+
if (!manifest.config || typeof manifest.config !== "object" || Array.isArray(manifest.config) || !Array.isArray(manifest.skills)) return false;
|
|
4232
|
+
const config = manifest.config;
|
|
4233
|
+
if (typeof config.model !== "string" || !config.model || typeof config.small_model !== "string" || !config.small_model || typeof config.theme !== "string" || typeof config.instructionsUrl !== "string" || !Array.isArray(config.models) || config.models.length === 0) return false;
|
|
4234
|
+
const modelIds = config.models.map((model) => model && typeof model === "object" && !Array.isArray(model) ? model.id : void 0);
|
|
4235
|
+
return modelIds.every((id) => typeof id === "string" && id.length > 0) && modelIds.includes(config.model) && modelIds.includes(config.small_model);
|
|
4236
|
+
}
|
|
4237
|
+
|
|
4238
|
+
// packages/cli/src/reconnectWorker.ts
|
|
4239
|
+
async function reconnectWorker(paths) {
|
|
4240
|
+
const origin = JSON.parse(await readFile5(path4.join(paths.forgeDir, "recovery-origin.json"), "utf8"));
|
|
4241
|
+
const forgeBaseUrl = normalizeForgeBaseUrl(origin.forgeBaseUrl);
|
|
4242
|
+
let current;
|
|
4243
|
+
try {
|
|
4244
|
+
current = await readFile5(paths.opencodeConfigPath, "utf8");
|
|
4245
|
+
} catch (error) {
|
|
4246
|
+
if (error.code !== "ENOENT") throw error;
|
|
4247
|
+
}
|
|
4248
|
+
let existing = {};
|
|
4249
|
+
if (current !== void 0) {
|
|
4250
|
+
try {
|
|
4251
|
+
existing = JSON.parse(current);
|
|
4252
|
+
} catch {
|
|
4253
|
+
throw new LocalConfigRecoveryError("A configura\xE7\xE3o cont\xE9m coment\xE1rios ou est\xE1 danificada. Pe\xE7a ao operador para preservar e resolver esse conflito antes de criar outra chave.");
|
|
4254
|
+
}
|
|
4255
|
+
if (!existing || typeof existing !== "object" || Array.isArray(existing) || typeof existing.model === "string" && !existing.model.startsWith("forge/")) {
|
|
4256
|
+
throw new LocalConfigRecoveryError("A configura\xE7\xE3o pertence a outro provider ou tem um conflito; a nova inscri\xE7\xE3o n\xE3o foi iniciada.");
|
|
4257
|
+
}
|
|
4258
|
+
}
|
|
4259
|
+
assertForgeVisible(existing);
|
|
4260
|
+
const previous = await readCredentials(paths).catch(() => void 0);
|
|
4261
|
+
if (previous && previous.forgeBaseUrl.replace(/\/+$/, "") !== forgeBaseUrl) {
|
|
4262
|
+
throw new LocalConfigRecoveryError("A credencial pertence a outra organiza\xE7\xE3o; pe\xE7a uma repara\xE7\xE3o acompanhada antes de criar outra chave.");
|
|
4263
|
+
}
|
|
4264
|
+
const authContent = await prepareWellKnownAuthRemoval(paths, previous ?? {
|
|
4265
|
+
forgeBaseUrl,
|
|
4266
|
+
forgeApiKey: "",
|
|
4267
|
+
installedAt: ""
|
|
4268
|
+
});
|
|
4269
|
+
const forgeApiKey = await enrollDevice({ baseUrl: forgeBaseUrl, installMode: "local", deviceLabel: "Recupera\xE7\xE3o Forge", cliVersion: "forge-plugin-recovery-1" });
|
|
4270
|
+
const credentials = { forgeBaseUrl, forgeApiKey, installedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
4271
|
+
try {
|
|
4272
|
+
const manifest = await fetchManifest(credentials);
|
|
4273
|
+
const config = mergeWorkerOpenCodeConfig(existing, manifest, forgeBaseUrl, forgeApiKey, { automaticWorkPackSync: true, localConfig: true });
|
|
4274
|
+
const content = JSON.stringify(config, null, 2) + "\n";
|
|
4275
|
+
if (current !== void 0) await writeOwnerOnlyTextAtomic(path4.join(paths.forgeDir, `opencode-before-reconnect-${randomUUID4()}.jsonc`), current);
|
|
4276
|
+
const files = [
|
|
4277
|
+
{ id: "opencode-config", path: paths.opencodeConfigPath, bytes: Buffer.from(content), mode: 384, ownerOnly: true },
|
|
4278
|
+
{ id: "credentials", path: paths.credentialsPath, bytes: Buffer.from(JSON.stringify(credentials) + "\n"), mode: 384, ownerOnly: true },
|
|
4279
|
+
lastGoodLocalConfigFile(paths, credentials, content)
|
|
4280
|
+
];
|
|
4281
|
+
if (authContent !== void 0) files.push({
|
|
4282
|
+
id: "opencode-auth",
|
|
4283
|
+
path: paths.opencodeAuthPath,
|
|
4284
|
+
bytes: Buffer.from(authContent),
|
|
4285
|
+
mode: 384,
|
|
4286
|
+
ownerOnly: true
|
|
4287
|
+
});
|
|
4288
|
+
for (const file of shellCredentialFiles(paths, forgeApiKey)) {
|
|
4289
|
+
if (await fileExists(file.path)) files.push({ id: path4.basename(file.path), ...file, mode: 384, ownerOnly: true });
|
|
4290
|
+
}
|
|
4291
|
+
const digest = coreRuntimeManifestDigest(files);
|
|
4292
|
+
await applyCoreSyncTransaction({ journalPath: path4.join(paths.forgeDir, "core-sync-journal.json"), manifest: { version: 1, id: `reconnect:${digest.slice(0, 32)}`, digest, files } });
|
|
4293
|
+
} catch {
|
|
4294
|
+
throw new LocalConfigRecoveryError("A nova chave foi emitida, mas a configura\xE7\xE3o n\xE3o ficou verificada. Pe\xE7a ao operador para revogar essa chave correlacionada antes de tentar outra inscri\xE7\xE3o.");
|
|
4295
|
+
}
|
|
4296
|
+
}
|
|
4297
|
+
async function fileExists(filePath) {
|
|
4298
|
+
return access(filePath).then(() => true, () => false);
|
|
4299
|
+
}
|
|
4300
|
+
|
|
4301
|
+
// packages/cli/src/paths.ts
|
|
4302
|
+
import os3 from "node:os";
|
|
4303
|
+
import path5 from "node:path";
|
|
4304
|
+
import { existsSync } from "node:fs";
|
|
4305
|
+
function resolvePaths(home = os3.homedir(), platform = process.platform, env = process.env, exists2 = existsSync) {
|
|
4306
|
+
const pathApi = platform === "win32" ? path5.win32 : path5.posix;
|
|
4307
|
+
const userHome = platform === "win32" ? env.USERPROFILE ?? home : home;
|
|
4308
|
+
const forgeConfigRoot = env.XDG_CONFIG_HOME ?? pathApi.join(userHome, ".config");
|
|
4309
|
+
const forgeDir = pathApi.join(forgeConfigRoot, "forge");
|
|
4310
|
+
const rollbackDir = pathApi.join(forgeDir, "rollback");
|
|
4311
|
+
const explicitOpenCodeConfig = env.OPENCODE_CONFIG;
|
|
4312
|
+
const opencodeDir = explicitOpenCodeConfig ? pathApi.dirname(explicitOpenCodeConfig) : resolveOpenCodeDir(userHome, platform, env, exists2, pathApi);
|
|
4313
|
+
const opencodeDataDir = resolveOpenCodeDataDir(userHome, platform, env, pathApi);
|
|
4314
|
+
const opencodeJsonc = pathApi.join(opencodeDir, "opencode.jsonc");
|
|
4315
|
+
const opencodeJson = pathApi.join(opencodeDir, "opencode.json");
|
|
4316
|
+
return {
|
|
4317
|
+
forgeDir,
|
|
4318
|
+
credentialsPath: pathApi.join(forgeDir, "credentials.json"),
|
|
4319
|
+
envPath: pathApi.join(forgeDir, "forge.env"),
|
|
4320
|
+
powershellEnvPath: pathApi.join(forgeDir, "forge.ps1"),
|
|
4321
|
+
rollbackDir,
|
|
4322
|
+
rollbackCapsulePath: pathApi.join(rollbackDir, "capsule.json"),
|
|
4323
|
+
rollbackLifecyclePath: pathApi.join(rollbackDir, "lifecycle.json"),
|
|
4324
|
+
rollbackRescuesDir: pathApi.join(rollbackDir, "rescues"),
|
|
4325
|
+
opencodeDir,
|
|
4326
|
+
opencodeDataDir,
|
|
4327
|
+
opencodeAuthPath: pathApi.join(opencodeDataDir, "auth.json"),
|
|
4328
|
+
opencodeConfigPath: explicitOpenCodeConfig ?? (exists2(opencodeJsonc) ? opencodeJsonc : exists2(opencodeJson) ? opencodeJson : opencodeJsonc),
|
|
4329
|
+
tuiConfigPath: pathApi.join(opencodeDir, "tui.json"),
|
|
4330
|
+
skillsDir: pathApi.join(opencodeDir, "skills"),
|
|
4331
|
+
agentsDir: pathApi.join(opencodeDir, "agents"),
|
|
4332
|
+
commandsDir: pathApi.join(opencodeDir, "commands"),
|
|
4333
|
+
pluginDir: pathApi.join(opencodeDir, "plugins")
|
|
4334
|
+
};
|
|
4335
|
+
}
|
|
4336
|
+
function resolveOpenCodeDataDir(userHome, platform, env, pathApi) {
|
|
4337
|
+
if (platform === "win32") return pathApi.join(userHome, ".local", "share", "opencode");
|
|
4338
|
+
return pathApi.join(env.XDG_DATA_HOME ?? pathApi.join(userHome, ".local", "share"), "opencode");
|
|
4339
|
+
}
|
|
4340
|
+
function resolveOpenCodeDir(home, platform, env, exists2, pathApi) {
|
|
4341
|
+
if (env.OPENCODE_CONFIG_DIR) return env.OPENCODE_CONFIG_DIR;
|
|
4342
|
+
if (platform !== "win32") return pathApi.join(env.XDG_CONFIG_HOME ?? pathApi.join(home, ".config"), "opencode");
|
|
4343
|
+
return pathApi.join(home, ".config", "opencode");
|
|
4344
|
+
}
|
|
4345
|
+
|
|
4346
|
+
// packages/cli/src/repair.ts
|
|
4347
|
+
async function main() {
|
|
4348
|
+
const env = { ...process.env };
|
|
4349
|
+
delete env.OPENCODE_CONFIG;
|
|
4350
|
+
delete env.OPENCODE_CONFIG_DIR;
|
|
4351
|
+
const paths = resolvePaths(void 0, void 0, env);
|
|
4352
|
+
const credentials = await readCredentials(paths).catch(() => void 0);
|
|
4353
|
+
const state = credentials ? await inspectLocalConfigRecovery(paths, credentials) : { snapshot: "not-checked", current: "not-checked", credential: "missing-or-invalid" };
|
|
4354
|
+
if (process.argv.includes("--check")) {
|
|
4355
|
+
console.log(JSON.stringify(state));
|
|
4356
|
+
return;
|
|
4357
|
+
}
|
|
4358
|
+
console.log("Verificar e reparar a liga\xE7\xE3o ao Forge");
|
|
4359
|
+
console.log(`Configura\xE7\xE3o atual: ${state.current}. C\xF3pia de recupera\xE7\xE3o: ${state.snapshot}.`);
|
|
4360
|
+
console.log("Feche o OpenWork antes de continuar. A recupera\xE7\xE3o local n\xE3o precisa de rede; uma nova inscri\xE7\xE3o precisa da aprova\xE7\xE3o do operador e n\xE3o reutiliza chaves antigas.");
|
|
4361
|
+
let action = process.argv.includes("--reenrol") ? "2" : process.argv.includes("--apply") ? "1" : "";
|
|
4362
|
+
if (!action && process.stdin.isTTY) {
|
|
4363
|
+
const prompt = createInterface({ input: process.stdin, output: process.stdout });
|
|
4364
|
+
try {
|
|
4365
|
+
action = (await prompt.question("1 \u2014 Recuperar configura\xE7\xE3o local; 2 \u2014 Nova inscri\xE7\xE3o com aprova\xE7\xE3o do operador; Enter \u2014 Sair: ")).trim();
|
|
4366
|
+
} finally {
|
|
4367
|
+
prompt.close();
|
|
4368
|
+
}
|
|
4369
|
+
}
|
|
4370
|
+
if (action === "2") {
|
|
4371
|
+
await reconnectWorker(paths);
|
|
4372
|
+
console.log("Nova inscri\xE7\xE3o guardada. Reabra o OpenWork e confirme o grupo Forge e uma resposta antes de dar a liga\xE7\xE3o como verificada.");
|
|
4373
|
+
return;
|
|
4374
|
+
}
|
|
4375
|
+
if (action !== "1") return;
|
|
4376
|
+
if (!credentials) throw new LocalConfigRecoveryError("A credencial atual est\xE1 ausente ou inv\xE1lida. Escolha uma nova inscri\xE7\xE3o com aprova\xE7\xE3o do operador; a c\xF3pia de configura\xE7\xE3o n\xE3o ser\xE1 usada para recuperar uma chave antiga.");
|
|
4377
|
+
const result = await repairLocalConfig(paths, credentials);
|
|
4378
|
+
console.log(result.status === "restored" ? "Configura\xE7\xE3o local recuperada. Reabra o OpenWork e confirme o grupo Forge." : "A configura\xE7\xE3o local est\xE1 v\xE1lida. Reabra o OpenWork e confirme o grupo Forge.");
|
|
4379
|
+
if (result.previousConfigPath) console.log(`A c\xF3pia anterior foi preservada em ${result.previousConfigPath}`);
|
|
4380
|
+
}
|
|
4381
|
+
main().catch((error) => {
|
|
4382
|
+
if (error instanceof LocalConfigRecoveryError) console.error(error.message);
|
|
4383
|
+
console.error("N\xE3o foi poss\xEDvel concluir a recupera\xE7\xE3o. Preserve os ficheiros e pe\xE7a apoio ao operador. Se um c\xF3digo de inscri\xE7\xE3o j\xE1 foi aprovado, confirme o estado e revogue a chave correlacionada antes de repetir.");
|
|
4384
|
+
process.exitCode = 1;
|
|
4385
|
+
});
|