@dbx-tools/projen 0.9.5 → 0.9.6

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.
Files changed (47) hide show
  1. package/README.md +64 -16
  2. package/index.ts +7 -5
  3. package/package.json +9 -6
  4. package/src/_rust-project.ts +356 -0
  5. package/src/_rust-release-workflow.ts +901 -0
  6. package/src/_rust-release.ts +605 -0
  7. package/src/_task-command.ts +89 -0
  8. package/src/barrels.ts +9 -7
  9. package/src/engine-root.ts +5 -5
  10. package/src/openapi.ts +1 -1
  11. package/src/packages.ts +9 -9
  12. package/src/pnpm-workspace.ts +1 -1
  13. package/src/project-js.ts +19 -25
  14. package/src/project-py.ts +6 -6
  15. package/src/project-rs.ts +100 -1098
  16. package/src/projen-version.ts +9 -0
  17. package/src/publish.ts +3 -4
  18. package/src/release-catalog.ts +1 -1
  19. package/src/release.ts +11 -12
  20. package/src/scaffold.ts +1 -1
  21. package/src/uniffi.ts +7 -0
  22. package/src/watch.ts +2 -2
  23. package/src/workspace-version.ts +20 -15
  24. package/tasks/barrels.ts +4 -4
  25. package/tasks/build-rust-release.ts +68 -0
  26. package/tasks/bump.ts +3 -2
  27. package/tasks/clean.ts +3 -3
  28. package/tasks/local-publish.ts +21 -3
  29. package/tasks/openapi.ts +2 -2
  30. package/tasks/publish-npm.ts +12 -6
  31. package/tasks/publish-python.ts +2 -2
  32. package/tasks/publish-uniffi-local.ts +11 -15
  33. package/tasks/publish.ts +88 -88
  34. package/tasks/python-registry.ts +1 -1
  35. package/tasks/release-bootstrap.ts +2 -2
  36. package/tasks/release-plan.ts +1 -1
  37. package/tasks/release-please.ts +1 -1
  38. package/tasks/release-pr.ts +60 -115
  39. package/tasks/release-request.ts +8 -29
  40. package/tasks/release-summary-units.ts +2 -9
  41. package/tasks/release-summary.ts +35 -24
  42. package/tasks/release-version.ts +44 -0
  43. package/tasks/rust-release.d.ts +41 -0
  44. package/tasks/rust-release.mjs +1717 -0
  45. package/tasks/uniffi-python.js +1 -1
  46. package/tasks/uniffi.ts +7 -1
  47. package/tasks/version-check.ts +6 -5
@@ -0,0 +1,1717 @@
1
+ #!/usr/bin/env node
2
+ // GENERATED from src/_rust-release.ts by tasks/build-rust-release.ts.
3
+ // src/_rust-release.ts
4
+ import { createHash } from "node:crypto";
5
+ import {
6
+ chmodSync,
7
+ closeSync,
8
+ existsSync,
9
+ lstatSync,
10
+ mkdirSync,
11
+ mkdtempSync,
12
+ openSync,
13
+ readFileSync,
14
+ readSync,
15
+ readlinkSync,
16
+ readdirSync,
17
+ rmSync,
18
+ statSync,
19
+ writeFileSync
20
+ } from "node:fs";
21
+ import { tmpdir } from "node:os";
22
+ import { dirname, join, relative, resolve, sep } from "node:path";
23
+ import { fileURLToPath } from "node:url";
24
+ import { parseArgs } from "node:util";
25
+
26
+ // ../packages/js/node/core/src/exec.ts
27
+ import {
28
+ spawn as nodeSpawn,
29
+ spawnSync as nodeSpawnSync
30
+ } from "node:child_process";
31
+ var COMMAND_NOT_FOUND_EXIT_CODE = 127;
32
+ function parseSpawnArgs(input) {
33
+ let [value, ...values] = input;
34
+ const [command, ...commandArgs] = shlex(value);
35
+ const last = values.at(-1);
36
+ const options = last !== null && typeof last === "object" && !Array.isArray(last) ? last : undefined;
37
+ const argumentValues = options ? values.slice(0, -1) : values;
38
+ const valueArgs = argumentValues.length === 1 && Array.isArray(argumentValues[0]) ? [...argumentValues[0]] : argumentValues;
39
+ return {
40
+ command,
41
+ commandArgs: [...commandArgs, ...valueArgs],
42
+ options
43
+ };
44
+ }
45
+ function withoutSpawnTrailingEmptyLine(lines) {
46
+ if (lines.length > 0 && lines[lines.length - 1] === "") {
47
+ return lines.slice(0, -1);
48
+ }
49
+ return lines;
50
+ }
51
+ function trimSingleTrailingNewline(text) {
52
+ if (text.endsWith(`\r
53
+ `))
54
+ return text.slice(0, -2);
55
+ if (text.endsWith(`
56
+ `))
57
+ return text.slice(0, -1);
58
+ return text;
59
+ }
60
+ function normalizedSyncLines(lines, trim) {
61
+ if (trim === false)
62
+ return lines;
63
+ if (trim === true)
64
+ return linesFromCapturedOutput(lines.join(`
65
+ `).trim());
66
+ return withoutSpawnTrailingEmptyLine(lines);
67
+ }
68
+ function formatSyncCapturedText(text, trim) {
69
+ if (text === undefined)
70
+ return;
71
+ if (trim === false)
72
+ return text;
73
+ if (trim === true)
74
+ return text.trim();
75
+ return trimSingleTrailingNewline(text);
76
+ }
77
+ function commandLabel(command, args) {
78
+ return `\`${command} ${args.join(" ")}\``;
79
+ }
80
+ function isCommandNotFoundError(error) {
81
+ return error instanceof Error && "code" in error && error.code === "ENOENT";
82
+ }
83
+ function createSyncExecResult(exitCode, stdoutText, stderrText, trim) {
84
+ let stdoutLinesCache;
85
+ let stderrLinesCache;
86
+ const syncLines = (text) => {
87
+ if (text === undefined)
88
+ return;
89
+ return normalizedSyncLines(linesFromCapturedOutput(text), trim);
90
+ };
91
+ return {
92
+ exitCode,
93
+ get stdoutLines() {
94
+ if (stdoutText === undefined)
95
+ return [];
96
+ stdoutLinesCache ??= syncLines(stdoutText) ?? [];
97
+ return stdoutLinesCache;
98
+ },
99
+ get stderrLines() {
100
+ if (stderrText === undefined)
101
+ return [];
102
+ stderrLinesCache ??= syncLines(stderrText) ?? [];
103
+ return stderrLinesCache;
104
+ },
105
+ get stdout() {
106
+ return formatSyncCapturedText(stdoutText, trim) ?? "";
107
+ },
108
+ get stderr() {
109
+ return formatSyncCapturedText(stderrText, trim) ?? "";
110
+ }
111
+ };
112
+ }
113
+ function isPassthroughMode(option) {
114
+ return option === "inherit" || option === "pipe" || option === "ignore";
115
+ }
116
+ function isStdinPayload(stdin) {
117
+ return typeof stdin === "string" && !isPassthroughMode(stdin);
118
+ }
119
+ function execError(command, args, result) {
120
+ const detail = result.stderr || result.stdout;
121
+ return new Error(`${commandLabel(command, args)} failed (exit ${result.exitCode})${detail ? `: ${detail}` : ""}`);
122
+ }
123
+ function resolveSyncStdio(option, defaultMode = "inherit") {
124
+ if (option === undefined)
125
+ return defaultMode;
126
+ if (option === "capture")
127
+ return "pipe";
128
+ return option;
129
+ }
130
+ function capturedText(output) {
131
+ if (output === null || output === undefined)
132
+ return;
133
+ return typeof output === "string" ? output : output.toString("utf8");
134
+ }
135
+ function linesFromCapturedOutput(output) {
136
+ return output.replace(/\r\n/g, `
137
+ `).replace(/\r/g, `
138
+ `).split(`
139
+ `);
140
+ }
141
+ function spawnSync(...args) {
142
+ const { command, commandArgs, options = {} } = parseSpawnArgs(args);
143
+ const { stdin, stdout, stderr, check, trim, ...spawnOpts } = options;
144
+ const stdinMode = isStdinPayload(stdin) ? "pipe" : stdin ?? "inherit";
145
+ const captureStdout = stdout === "capture";
146
+ const captureStderr = stderr === "capture";
147
+ const stdoutMode = resolveSyncStdio(stdout);
148
+ const stderrMode = resolveSyncStdio(stderr);
149
+ const result = nodeSpawnSync(command, commandArgs, {
150
+ ...spawnOpts,
151
+ encoding: captureStdout || captureStderr ? "utf8" : undefined,
152
+ stdio: [stdinMode, stdoutMode, stderrMode],
153
+ input: isStdinPayload(stdin) ? stdin : undefined
154
+ });
155
+ const commandNotFound = isCommandNotFoundError(result.error);
156
+ const exitCode = commandNotFound ? COMMAND_NOT_FOUND_EXIT_CODE : result.status ?? 1;
157
+ const stdoutText = captureStdout ? capturedText(result.stdout) : undefined;
158
+ const stderrText = captureStderr ? capturedText(result.stderr) : undefined;
159
+ const execResult = createSyncExecResult(exitCode, stdoutText, stderrText, trim);
160
+ if (result.error && (!commandNotFound || check)) {
161
+ const err = execError(command, commandArgs, execResult);
162
+ err.cause = result.error;
163
+ throw err;
164
+ }
165
+ if (check && execResult.exitCode !== 0)
166
+ throw execError(command, commandArgs, execResult);
167
+ return execResult;
168
+ }
169
+ function shlex(command) {
170
+ const args = [];
171
+ let current = "";
172
+ let quote;
173
+ let escaped = false;
174
+ let quoted = false;
175
+ const push = () => {
176
+ if (quoted || current.length > 0) {
177
+ args.push(current);
178
+ }
179
+ current = "";
180
+ quoted = false;
181
+ };
182
+ for (const ch of command) {
183
+ if (escaped) {
184
+ current += ch;
185
+ escaped = false;
186
+ continue;
187
+ }
188
+ if (ch === "\\") {
189
+ escaped = true;
190
+ continue;
191
+ }
192
+ if (quote) {
193
+ if (ch === quote) {
194
+ quote = undefined;
195
+ quoted = true;
196
+ } else {
197
+ current += ch;
198
+ }
199
+ continue;
200
+ }
201
+ if (ch === "'" || ch === '"') {
202
+ quote = ch;
203
+ quoted = true;
204
+ continue;
205
+ }
206
+ if (/\s/.test(ch)) {
207
+ push();
208
+ continue;
209
+ }
210
+ current += ch;
211
+ }
212
+ if (quote) {
213
+ return [command];
214
+ }
215
+ if (escaped) {
216
+ current += "\\";
217
+ }
218
+ push();
219
+ return args.length ? args : [command];
220
+ }
221
+
222
+ // ../node_modules/smol-toml/dist/date.js
223
+ /*!
224
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
225
+ * SPDX-License-Identifier: BSD-3-Clause
226
+ *
227
+ * Redistribution and use in source and binary forms, with or without
228
+ * modification, are permitted provided that the following conditions are met:
229
+ *
230
+ * 1. Redistributions of source code must retain the above copyright notice, this
231
+ * list of conditions and the following disclaimer.
232
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
233
+ * this list of conditions and the following disclaimer in the
234
+ * documentation and/or other materials provided with the distribution.
235
+ * 3. Neither the name of the copyright holder nor the names of its contributors
236
+ * may be used to endorse or promote products derived from this software without
237
+ * specific prior written permission.
238
+ *
239
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
240
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
241
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
242
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
243
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
244
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
245
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
246
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
247
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
248
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
249
+ */
250
+ var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;
251
+
252
+ class TomlDate extends Date {
253
+ #hasDate = false;
254
+ #hasTime = false;
255
+ #offset = null;
256
+ constructor(date) {
257
+ let hasDate = true;
258
+ let hasTime = true;
259
+ let offset = "Z";
260
+ if (typeof date === "string") {
261
+ let match = date.match(DATE_TIME_RE);
262
+ if (match) {
263
+ if (!match[1]) {
264
+ hasDate = false;
265
+ date = `0000-01-01T${date}`;
266
+ }
267
+ hasTime = !!match[2];
268
+ hasTime && date[10] === " " && (date = date.replace(" ", "T"));
269
+ if (match[2] && +match[2] > 23) {
270
+ date = "";
271
+ } else {
272
+ offset = match[3] || null;
273
+ date = date.toUpperCase();
274
+ if (!offset && hasTime)
275
+ date += "Z";
276
+ }
277
+ } else {
278
+ date = "";
279
+ }
280
+ }
281
+ super(date);
282
+ if (!isNaN(this.getTime())) {
283
+ this.#hasDate = hasDate;
284
+ this.#hasTime = hasTime;
285
+ this.#offset = offset;
286
+ }
287
+ }
288
+ isDateTime() {
289
+ return this.#hasDate && this.#hasTime;
290
+ }
291
+ isLocal() {
292
+ return !this.#hasDate || !this.#hasTime || !this.#offset;
293
+ }
294
+ isDate() {
295
+ return this.#hasDate && !this.#hasTime;
296
+ }
297
+ isTime() {
298
+ return this.#hasTime && !this.#hasDate;
299
+ }
300
+ isValid() {
301
+ return this.#hasDate || this.#hasTime;
302
+ }
303
+ toISOString() {
304
+ let iso = super.toISOString();
305
+ if (this.isDate())
306
+ return iso.slice(0, 10);
307
+ if (this.isTime())
308
+ return iso.slice(11, 23);
309
+ if (this.#offset === null)
310
+ return iso.slice(0, -1);
311
+ if (this.#offset === "Z")
312
+ return iso;
313
+ let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
314
+ offset = this.#offset[0] === "-" ? offset : -offset;
315
+ let offsetDate = new Date(this.getTime() - offset * 60000);
316
+ return offsetDate.toISOString().slice(0, -1) + this.#offset;
317
+ }
318
+ static wrapAsOffsetDateTime(jsDate, offset = "Z") {
319
+ let date = new TomlDate(jsDate);
320
+ date.#offset = offset;
321
+ return date;
322
+ }
323
+ static wrapAsLocalDateTime(jsDate) {
324
+ let date = new TomlDate(jsDate);
325
+ date.#offset = null;
326
+ return date;
327
+ }
328
+ static wrapAsLocalDate(jsDate) {
329
+ let date = new TomlDate(jsDate);
330
+ date.#hasTime = false;
331
+ date.#offset = null;
332
+ return date;
333
+ }
334
+ static wrapAsLocalTime(jsDate) {
335
+ let date = new TomlDate(jsDate);
336
+ date.#hasDate = false;
337
+ date.#offset = null;
338
+ return date;
339
+ }
340
+ }
341
+
342
+ // ../node_modules/smol-toml/dist/error.js
343
+ /*!
344
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
345
+ * SPDX-License-Identifier: BSD-3-Clause
346
+ *
347
+ * Redistribution and use in source and binary forms, with or without
348
+ * modification, are permitted provided that the following conditions are met:
349
+ *
350
+ * 1. Redistributions of source code must retain the above copyright notice, this
351
+ * list of conditions and the following disclaimer.
352
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
353
+ * this list of conditions and the following disclaimer in the
354
+ * documentation and/or other materials provided with the distribution.
355
+ * 3. Neither the name of the copyright holder nor the names of its contributors
356
+ * may be used to endorse or promote products derived from this software without
357
+ * specific prior written permission.
358
+ *
359
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
360
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
361
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
362
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
363
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
364
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
365
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
366
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
367
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
368
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
369
+ */
370
+ function getLineColFromPtr(string, ptr) {
371
+ let lines = string.slice(0, ptr).split(/\r\n|\n|\r/g);
372
+ return [lines.length, lines.pop().length + 1];
373
+ }
374
+ function makeCodeBlock(string, line, column) {
375
+ let lines = string.split(/\r\n|\n|\r/g);
376
+ let codeblock = "";
377
+ let numberLen = (Math.log10(line + 1) | 0) + 1;
378
+ for (let i = line - 1;i <= line + 1; i++) {
379
+ let l = lines[i - 1];
380
+ if (!l)
381
+ continue;
382
+ codeblock += i.toString().padEnd(numberLen, " ");
383
+ codeblock += ": ";
384
+ codeblock += l;
385
+ codeblock += `
386
+ `;
387
+ if (i === line) {
388
+ codeblock += " ".repeat(numberLen + column + 2);
389
+ codeblock += `^
390
+ `;
391
+ }
392
+ }
393
+ return codeblock;
394
+ }
395
+
396
+ class TomlError extends Error {
397
+ line;
398
+ column;
399
+ codeblock;
400
+ constructor(message, options) {
401
+ const [line, column] = getLineColFromPtr(options.toml, options.ptr);
402
+ const codeblock = makeCodeBlock(options.toml, line, column);
403
+ super(`Invalid TOML document: ${message}
404
+
405
+ ${codeblock}`, options);
406
+ this.line = line;
407
+ this.column = column;
408
+ this.codeblock = codeblock;
409
+ }
410
+ }
411
+
412
+ // ../node_modules/smol-toml/dist/util.js
413
+ /*!
414
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
415
+ * SPDX-License-Identifier: BSD-3-Clause
416
+ *
417
+ * Redistribution and use in source and binary forms, with or without
418
+ * modification, are permitted provided that the following conditions are met:
419
+ *
420
+ * 1. Redistributions of source code must retain the above copyright notice, this
421
+ * list of conditions and the following disclaimer.
422
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
423
+ * this list of conditions and the following disclaimer in the
424
+ * documentation and/or other materials provided with the distribution.
425
+ * 3. Neither the name of the copyright holder nor the names of its contributors
426
+ * may be used to endorse or promote products derived from this software without
427
+ * specific prior written permission.
428
+ *
429
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
430
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
431
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
432
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
433
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
434
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
435
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
436
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
437
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
438
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
439
+ */
440
+ function indexOfNewline(str, start = 0) {
441
+ let idx = str.indexOf(`
442
+ `, start);
443
+ if (str.charCodeAt(idx - 1) === 13)
444
+ idx--;
445
+ return idx;
446
+ }
447
+ function skipComment(ctx) {
448
+ for (;ctx.p < ctx.s.length; ctx.p++) {
449
+ let c = ctx.s.charCodeAt(ctx.p);
450
+ if (c === 10)
451
+ break;
452
+ if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) {
453
+ ctx.p++;
454
+ break;
455
+ }
456
+ if (c < 32 && c !== 9 || c === 127) {
457
+ throw new TomlError("control characters are not allowed in comments", {
458
+ toml: ctx.s,
459
+ ptr: ctx.p
460
+ });
461
+ }
462
+ }
463
+ }
464
+ function skipVoid(ctx, banNewLines, banComments) {
465
+ let c;
466
+ while (true) {
467
+ while ((c = ctx.s.charCodeAt(ctx.p)) === 32 || c === 9 || !banNewLines && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10))
468
+ ctx.p++;
469
+ if (banComments || c !== 35)
470
+ break;
471
+ skipComment(ctx);
472
+ }
473
+ }
474
+ function skipUntil(ctx, sep, end) {
475
+ let ptr = ctx.p;
476
+ if (!end) {
477
+ ptr = indexOfNewline(ctx.s, ptr);
478
+ ctx.p = ptr < 0 ? ctx.s.length : ptr;
479
+ return;
480
+ }
481
+ for (;ctx.p < ctx.s.length; ctx.p++) {
482
+ let c = ctx.s.charCodeAt(ctx.p);
483
+ if (c === 35) {
484
+ skipComment(ctx);
485
+ } else if (c === end || c === sep) {
486
+ return;
487
+ }
488
+ }
489
+ throw new TomlError("cannot find end of structure", {
490
+ toml: ctx.s,
491
+ ptr
492
+ });
493
+ }
494
+
495
+ // ../node_modules/smol-toml/dist/primitive.js
496
+ /*!
497
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
498
+ * SPDX-License-Identifier: BSD-3-Clause
499
+ *
500
+ * Redistribution and use in source and binary forms, with or without
501
+ * modification, are permitted provided that the following conditions are met:
502
+ *
503
+ * 1. Redistributions of source code must retain the above copyright notice, this
504
+ * list of conditions and the following disclaimer.
505
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
506
+ * this list of conditions and the following disclaimer in the
507
+ * documentation and/or other materials provided with the distribution.
508
+ * 3. Neither the name of the copyright holder nor the names of its contributors
509
+ * may be used to endorse or promote products derived from this software without
510
+ * specific prior written permission.
511
+ *
512
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
513
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
514
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
515
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
516
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
517
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
518
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
519
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
520
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
521
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
522
+ */
523
+ var INT_REGEX = /^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/;
524
+ var FLOAT_REGEX = /^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/;
525
+ var LEADING_ZERO = /^[+-]?0[0-9_]/;
526
+ function parseString(ctx) {
527
+ let start = ctx.p;
528
+ let c = ctx.s.charCodeAt(ctx.p++);
529
+ let first = c;
530
+ let isLiteral = c === 39;
531
+ let isMultiline = c === ctx.s.charCodeAt(ctx.p) && c === ctx.s.charCodeAt(ctx.p + 1);
532
+ if (isMultiline) {
533
+ if ((c = ctx.s.charCodeAt(ctx.p += 2)) === 10)
534
+ ctx.p++;
535
+ else if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)
536
+ ctx.p += 2;
537
+ }
538
+ let parsed = "";
539
+ let sliceStart = ctx.p;
540
+ let state = 0;
541
+ for (;ctx.p < ctx.s.length; ctx.p++) {
542
+ c = ctx.s.charCodeAt(ctx.p);
543
+ if (isMultiline && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)) {
544
+ state = state && 3;
545
+ } else if (c < 32 && c !== 9 || c === 127) {
546
+ throw new TomlError("control characters are not allowed in strings", {
547
+ toml: ctx.s,
548
+ ptr: ctx.p
549
+ });
550
+ } else if ((!state || state === 3) && c === first && (!isMultiline || ctx.s.charCodeAt(ctx.p + 1) === first && ctx.s.charCodeAt(ctx.p + 2) === first)) {
551
+ if (isMultiline) {
552
+ if (ctx.s.charCodeAt(ctx.p + 3) === first)
553
+ ctx.p++;
554
+ if (ctx.s.charCodeAt(ctx.p + 3) === first)
555
+ ctx.p++;
556
+ }
557
+ if (!state)
558
+ parsed += ctx.s.slice(sliceStart, ctx.p);
559
+ ctx.p += isMultiline ? 3 : 1;
560
+ return parsed;
561
+ } else if (!state) {
562
+ if (!isLiteral && c === 92) {
563
+ parsed += ctx.s.slice(sliceStart, sliceStart = ctx.p);
564
+ state = 1;
565
+ }
566
+ } else if (state === 1) {
567
+ if (c === 120 || c === 117 || c === 85) {
568
+ let value = 0;
569
+ let len = c === 120 ? 2 : c === 117 ? 4 : 8;
570
+ for (let j = 0;j < len; j++, ctx.p++) {
571
+ let hex = ctx.s.charCodeAt(ctx.p + 1);
572
+ let digit = hex >= 48 && hex <= 57 ? hex - 48 : hex >= 65 && hex <= 70 ? hex - 65 + 10 : hex >= 97 && hex <= 102 ? hex - 97 + 10 : -1;
573
+ if (digit < 0)
574
+ throw new TomlError("invalid non-hex character in unicode escape", { toml: ctx.s, ptr: ctx.p + 1 });
575
+ value = value << 4 | digit;
576
+ }
577
+ if (value < 0 || value > 1114111 || value >= 55296 && value <= 57343) {
578
+ throw new TomlError("invalid unicode escape", { toml: ctx.s, ptr: ctx.p });
579
+ }
580
+ parsed += String.fromCodePoint(value);
581
+ sliceStart = ctx.p + 1;
582
+ state = 0;
583
+ } else if (c === 32 || c === 9) {
584
+ state = 2;
585
+ } else {
586
+ if (c === 98)
587
+ parsed += "\b";
588
+ else if (c === 116)
589
+ parsed += "\t";
590
+ else if (c === 110)
591
+ parsed += `
592
+ `;
593
+ else if (c === 102)
594
+ parsed += "\f";
595
+ else if (c === 114)
596
+ parsed += "\r";
597
+ else if (c === 101)
598
+ parsed += "\x1B";
599
+ else if (c === 34)
600
+ parsed += '"';
601
+ else if (c === 92)
602
+ parsed += "\\";
603
+ else
604
+ throw new TomlError("unrecognized escape sequence", { toml: ctx.s, ptr: ctx.p });
605
+ sliceStart = ctx.p + 1;
606
+ state = 0;
607
+ }
608
+ } else if (c !== 32 && c !== 9) {
609
+ if (state === 2) {
610
+ throw new TomlError("invalid escape: only line-ending whitespace may be escaped", {
611
+ toml: ctx.s,
612
+ ptr: sliceStart
613
+ });
614
+ }
615
+ state = !isLiteral && c === 92 ? 1 : 0;
616
+ sliceStart = ctx.p;
617
+ }
618
+ }
619
+ throw new TomlError("unfinished string", { toml: ctx.s, ptr: start });
620
+ }
621
+ function sliceAndTrimEndOf(ctx, start, end) {
622
+ let value = ctx.s.slice(start, end);
623
+ let commentIdx = value.indexOf("#");
624
+ if (commentIdx > 0) {
625
+ skipComment({ s: value, p: commentIdx, d: 0 });
626
+ value = value.slice(0, commentIdx);
627
+ }
628
+ return value.trimEnd();
629
+ }
630
+ function parseValue(ctx, integersAsBigInt, end) {
631
+ let ptr = ctx.p;
632
+ let err = { toml: ctx.s, ptr };
633
+ skipUntil(ctx, 44, end);
634
+ let value = sliceAndTrimEndOf(ctx, ptr, ctx.p);
635
+ if (!value)
636
+ throw new TomlError("incomplete declaration: value expected", err);
637
+ if (value === "-inf")
638
+ return -Infinity;
639
+ if (value === "inf" || value === "+inf")
640
+ return Infinity;
641
+ if (value === "nan" || value === "+nan" || value === "-nan")
642
+ return NaN;
643
+ if (value === "-0")
644
+ return integersAsBigInt ? 0n : 0;
645
+ let isInt = INT_REGEX.test(value);
646
+ if (isInt || FLOAT_REGEX.test(value)) {
647
+ if (LEADING_ZERO.test(value)) {
648
+ throw new TomlError("leading zeroes are not allowed", err);
649
+ }
650
+ value = value.replace(/_/g, "");
651
+ let numeric = +value;
652
+ if (isNaN(numeric)) {
653
+ throw new TomlError("invalid number", err);
654
+ }
655
+ if (isInt) {
656
+ if ((isInt = !Number.isSafeInteger(numeric)) && !integersAsBigInt) {
657
+ throw new TomlError("integer value cannot be represented losslessly", err);
658
+ }
659
+ if (isInt || integersAsBigInt === true)
660
+ numeric = BigInt(value);
661
+ }
662
+ return numeric;
663
+ }
664
+ const date = new TomlDate(value);
665
+ if (!date.isValid())
666
+ throw new TomlError("invalid value", err);
667
+ return date;
668
+ }
669
+
670
+ // ../node_modules/smol-toml/dist/extract.js
671
+ /*!
672
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
673
+ * SPDX-License-Identifier: BSD-3-Clause
674
+ *
675
+ * Redistribution and use in source and binary forms, with or without
676
+ * modification, are permitted provided that the following conditions are met:
677
+ *
678
+ * 1. Redistributions of source code must retain the above copyright notice, this
679
+ * list of conditions and the following disclaimer.
680
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
681
+ * this list of conditions and the following disclaimer in the
682
+ * documentation and/or other materials provided with the distribution.
683
+ * 3. Neither the name of the copyright holder nor the names of its contributors
684
+ * may be used to endorse or promote products derived from this software without
685
+ * specific prior written permission.
686
+ *
687
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
688
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
689
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
690
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
691
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
692
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
693
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
694
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
695
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
696
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
697
+ */
698
+ function extractValue(ctx, end, integersAsBigInt) {
699
+ let ptr = ctx.p;
700
+ let c = ctx.s.charCodeAt(ptr);
701
+ if (c === 91 || c === 123) {
702
+ if (!ctx.d--) {
703
+ throw new TomlError("document contains excessively nested structures. aborting.", {
704
+ toml: ctx.s,
705
+ ptr
706
+ });
707
+ }
708
+ let value = c === 91 ? parseArray(ctx, integersAsBigInt) : parseInlineTable(ctx, integersAsBigInt);
709
+ ctx.d++;
710
+ return value;
711
+ }
712
+ if (c === 34 || c === 39) {
713
+ return parseString(ctx);
714
+ }
715
+ if (c === 116) {
716
+ if (ctx.s.charCodeAt(++ctx.p) !== 114 || ctx.s.charCodeAt(++ctx.p) !== 117 || ctx.s.charCodeAt(++ctx.p) !== 101)
717
+ throw new TomlError("invalid value", { toml: ctx.s, ptr });
718
+ ctx.p++;
719
+ return true;
720
+ }
721
+ if (c === 102) {
722
+ if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 108 || ctx.s.charCodeAt(++ctx.p) !== 115 || ctx.s.charCodeAt(++ctx.p) !== 101)
723
+ throw new TomlError("invalid value", { toml: ctx.s, ptr });
724
+ ctx.p++;
725
+ return false;
726
+ }
727
+ return parseValue(ctx, integersAsBigInt, end);
728
+ }
729
+
730
+ // ../node_modules/smol-toml/dist/struct.js
731
+ /*!
732
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
733
+ * SPDX-License-Identifier: BSD-3-Clause
734
+ *
735
+ * Redistribution and use in source and binary forms, with or without
736
+ * modification, are permitted provided that the following conditions are met:
737
+ *
738
+ * 1. Redistributions of source code must retain the above copyright notice, this
739
+ * list of conditions and the following disclaimer.
740
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
741
+ * this list of conditions and the following disclaimer in the
742
+ * documentation and/or other materials provided with the distribution.
743
+ * 3. Neither the name of the copyright holder nor the names of its contributors
744
+ * may be used to endorse or promote products derived from this software without
745
+ * specific prior written permission.
746
+ *
747
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
748
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
749
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
750
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
751
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
752
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
753
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
754
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
755
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
756
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
757
+ */
758
+ var KEY_PART_RE = /^[a-zA-Z0-9-_]+[ \t]*$/;
759
+ function parseKey(ctx, end = "=") {
760
+ let start = ctx.p;
761
+ let dot = start - 1;
762
+ let parsed = [];
763
+ let endPtr = ctx.s.indexOf(end, start);
764
+ if (endPtr < 0) {
765
+ throw new TomlError("incomplete key-value: cannot find end of key", {
766
+ toml: ctx.s,
767
+ ptr: start
768
+ });
769
+ }
770
+ do {
771
+ let c = ctx.s.charCodeAt(ctx.p = ++dot);
772
+ if (c !== 32 && c !== 9) {
773
+ if (c === 34 || c === 39) {
774
+ if (c === ctx.s.charCodeAt(ctx.p + 1) && c === ctx.s.charCodeAt(ctx.p + 2)) {
775
+ throw new TomlError("multiline strings are not allowed in keys", {
776
+ toml: ctx.s,
777
+ ptr: ctx.p
778
+ });
779
+ }
780
+ let part = parseString(ctx);
781
+ dot = ctx.s.indexOf(".", ctx.p);
782
+ let strEnd = ctx.s.slice(ctx.p, dot < 0 || dot > endPtr ? endPtr : dot);
783
+ let newLine = indexOfNewline(strEnd);
784
+ if (newLine > -1) {
785
+ throw new TomlError("newlines are not allowed in keys", {
786
+ toml: ctx.s,
787
+ ptr: newLine
788
+ });
789
+ }
790
+ if (strEnd.trimStart()) {
791
+ throw new TomlError("found extra tokens after the string part", {
792
+ toml: ctx.s,
793
+ ptr: ctx.p
794
+ });
795
+ }
796
+ if (endPtr < ctx.p) {
797
+ endPtr = ctx.s.indexOf(end, ctx.p);
798
+ if (endPtr < 0) {
799
+ throw new TomlError("incomplete key-value: cannot find end of key", {
800
+ toml: ctx.s,
801
+ ptr: start
802
+ });
803
+ }
804
+ }
805
+ parsed.push(part);
806
+ } else {
807
+ dot = ctx.s.indexOf(".", ctx.p);
808
+ let part = ctx.s.slice(ctx.p, dot < 0 || dot > endPtr ? endPtr : dot);
809
+ if (!KEY_PART_RE.test(part)) {
810
+ throw new TomlError("only letter, numbers, dashes and underscores are allowed in keys", {
811
+ toml: ctx.s,
812
+ ptr: ctx.p
813
+ });
814
+ }
815
+ parsed.push(part.trimEnd());
816
+ }
817
+ }
818
+ } while (dot + 1 && dot < endPtr);
819
+ ctx.p = endPtr + 1;
820
+ skipVoid(ctx, true, true);
821
+ return parsed;
822
+ }
823
+ function parseInlineTable(ctx, integersAsBigInt) {
824
+ let res = {};
825
+ let seen = new Set;
826
+ let c;
827
+ ctx.p++;
828
+ while (ctx.p < ctx.s.length) {
829
+ skipVoid(ctx);
830
+ if ((c = ctx.s.charCodeAt(ctx.p)) === 125) {
831
+ ctx.p++;
832
+ return res;
833
+ }
834
+ let k;
835
+ let t = res;
836
+ let hasOwn = false;
837
+ let p = ctx.p;
838
+ let key = parseKey(ctx);
839
+ for (let i = 0;i < key.length; i++) {
840
+ if (i)
841
+ t = hasOwn ? t[k] : t[k] = {};
842
+ k = key[i];
843
+ if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) {
844
+ throw new TomlError("trying to redefine an already defined value", {
845
+ toml: ctx.s,
846
+ ptr: p
847
+ });
848
+ }
849
+ if (!hasOwn && k === "__proto__") {
850
+ Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
851
+ }
852
+ }
853
+ if (hasOwn) {
854
+ throw new TomlError("trying to redefine an already defined value", {
855
+ toml: ctx.s,
856
+ ptr: ctx.p
857
+ });
858
+ }
859
+ let value = extractValue(ctx, 125, integersAsBigInt);
860
+ seen.add(t[k] = value);
861
+ skipVoid(ctx);
862
+ if ((c = ctx.s.charCodeAt(ctx.p++)) === 125) {
863
+ return res;
864
+ }
865
+ if (c !== 44) {
866
+ throw new TomlError("expected comma or end of structure", { toml: ctx.s, ptr: ctx.p - 1 });
867
+ }
868
+ }
869
+ throw new TomlError("unfinished table encountered", {
870
+ toml: ctx.s,
871
+ ptr: ctx.p
872
+ });
873
+ }
874
+ function parseArray(ctx, integersAsBigInt) {
875
+ let res = [];
876
+ let c;
877
+ ctx.p++;
878
+ while (ctx.p < ctx.s.length) {
879
+ skipVoid(ctx);
880
+ if ((c = ctx.s.charCodeAt(ctx.p)) === 93) {
881
+ ctx.p++;
882
+ return res;
883
+ }
884
+ res.push(extractValue(ctx, 93, integersAsBigInt));
885
+ skipVoid(ctx);
886
+ if ((c = ctx.s.charCodeAt(ctx.p++)) === 93) {
887
+ return res;
888
+ }
889
+ if (c !== 44) {
890
+ throw new TomlError("expected comma or end of structure", { toml: ctx.s, ptr: ctx.p - 1 });
891
+ }
892
+ }
893
+ throw new TomlError("unfinished array encountered", {
894
+ toml: ctx.s,
895
+ ptr: ctx.p
896
+ });
897
+ }
898
+
899
+ // ../node_modules/smol-toml/dist/parse.js
900
+ /*!
901
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
902
+ * SPDX-License-Identifier: BSD-3-Clause
903
+ *
904
+ * Redistribution and use in source and binary forms, with or without
905
+ * modification, are permitted provided that the following conditions are met:
906
+ *
907
+ * 1. Redistributions of source code must retain the above copyright notice, this
908
+ * list of conditions and the following disclaimer.
909
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
910
+ * this list of conditions and the following disclaimer in the
911
+ * documentation and/or other materials provided with the distribution.
912
+ * 3. Neither the name of the copyright holder nor the names of its contributors
913
+ * may be used to endorse or promote products derived from this software without
914
+ * specific prior written permission.
915
+ *
916
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
917
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
918
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
919
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
920
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
921
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
922
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
923
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
924
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
925
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
926
+ */
927
+ function peekTable(key, table, meta, type) {
928
+ let t = table;
929
+ let m = meta;
930
+ let k;
931
+ let hasOwn = false;
932
+ let state;
933
+ for (let i = 0;i < key.length; i++) {
934
+ if (i) {
935
+ t = hasOwn ? t[k] : t[k] = {};
936
+ m = (state = m[k]).c;
937
+ if (type === 0 && (state.t === 1 || state.t === 2)) {
938
+ return null;
939
+ }
940
+ if (state.t === 2) {
941
+ let l = t.length - 1;
942
+ t = t[l];
943
+ m = m[l].c;
944
+ }
945
+ }
946
+ k = key[i];
947
+ if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 && m[k]?.d) {
948
+ return null;
949
+ }
950
+ if (!hasOwn) {
951
+ if (k === "__proto__") {
952
+ Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
953
+ Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
954
+ }
955
+ m[k] = {
956
+ t: i < key.length - 1 && type === 2 ? 3 : type,
957
+ d: false,
958
+ i: 0,
959
+ c: {}
960
+ };
961
+ }
962
+ }
963
+ state = m[k];
964
+ if (state.t !== type && !(type === 1 && state.t === 3)) {
965
+ return null;
966
+ }
967
+ if (type === 2) {
968
+ if (!state.d) {
969
+ state.d = true;
970
+ t[k] = [];
971
+ }
972
+ t[k].push(t = {});
973
+ state.c[state.i++] = state = { t: 1, d: false, i: 0, c: {} };
974
+ }
975
+ if (state.d) {
976
+ return null;
977
+ }
978
+ state.d = true;
979
+ if (type === 1) {
980
+ t = hasOwn ? t[k] : t[k] = {};
981
+ } else if (type === 0 && hasOwn) {
982
+ return null;
983
+ }
984
+ return [k, t, state.c];
985
+ }
986
+ function parse(toml, { maxDepth = 1000, integersAsBigInt } = {}) {
987
+ let ctx = { s: toml, p: 0, d: maxDepth };
988
+ let res = {};
989
+ let meta = {};
990
+ let tmp;
991
+ let tbl = res;
992
+ let m = meta;
993
+ skipVoid(ctx);
994
+ while (ctx.p < toml.length) {
995
+ if (toml.charCodeAt(ctx.p) === 91) {
996
+ let isTableArray = toml.charCodeAt(++ctx.p) === 91;
997
+ tmp = ctx.p += +isTableArray;
998
+ let k = parseKey(ctx, "]");
999
+ if (isTableArray) {
1000
+ if (toml.charCodeAt(ctx.p - 1) !== 93) {
1001
+ throw new TomlError("expected end of table declaration", {
1002
+ toml,
1003
+ ptr: ctx.p - 1
1004
+ });
1005
+ }
1006
+ ctx.p++;
1007
+ }
1008
+ let p = peekTable(k, res, meta, isTableArray ? 2 : 1);
1009
+ if (!p) {
1010
+ throw new TomlError("trying to redefine an already defined table or value", {
1011
+ toml,
1012
+ ptr: tmp
1013
+ });
1014
+ }
1015
+ m = p[2];
1016
+ tbl = p[1];
1017
+ } else {
1018
+ tmp = ctx.p;
1019
+ let k = parseKey(ctx);
1020
+ let p = peekTable(k, tbl, m, 0);
1021
+ if (!p) {
1022
+ throw new TomlError("trying to redefine an already defined table or value", {
1023
+ toml,
1024
+ ptr: tmp
1025
+ });
1026
+ }
1027
+ p[1][p[0]] = extractValue(ctx, undefined, integersAsBigInt);
1028
+ }
1029
+ skipVoid(ctx, true);
1030
+ if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 10 && tmp !== 13) {
1031
+ throw new TomlError("each key-value declaration must be followed by an end-of-line", {
1032
+ toml,
1033
+ ptr: ctx.p
1034
+ });
1035
+ }
1036
+ skipVoid(ctx);
1037
+ }
1038
+ return res;
1039
+ }
1040
+
1041
+ // ../node_modules/smol-toml/dist/stringify.js
1042
+ /*!
1043
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
1044
+ * SPDX-License-Identifier: BSD-3-Clause
1045
+ *
1046
+ * Redistribution and use in source and binary forms, with or without
1047
+ * modification, are permitted provided that the following conditions are met:
1048
+ *
1049
+ * 1. Redistributions of source code must retain the above copyright notice, this
1050
+ * list of conditions and the following disclaimer.
1051
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
1052
+ * this list of conditions and the following disclaimer in the
1053
+ * documentation and/or other materials provided with the distribution.
1054
+ * 3. Neither the name of the copyright holder nor the names of its contributors
1055
+ * may be used to endorse or promote products derived from this software without
1056
+ * specific prior written permission.
1057
+ *
1058
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1059
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1060
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1061
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
1062
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1063
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1064
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1065
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1066
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1067
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1068
+ */
1069
+ var BARE_KEY = /^[a-z0-9-_]+$/i;
1070
+ function extendedTypeOf(obj) {
1071
+ let type = typeof obj;
1072
+ if (type === "object") {
1073
+ if (Array.isArray(obj))
1074
+ return "array";
1075
+ if (typeof obj?.getUTCDate === "function" && obj instanceof Date)
1076
+ return "date";
1077
+ if (globalThis.Temporal && typeof obj?.since === "function" && (obj instanceof Temporal.Instant || obj instanceof Temporal.PlainDate || obj instanceof Temporal.PlainDateTime || obj instanceof Temporal.PlainTime || obj instanceof Temporal.ZonedDateTime)) {
1078
+ return "temporal";
1079
+ }
1080
+ }
1081
+ return type;
1082
+ }
1083
+ function isArrayOfTables(obj) {
1084
+ for (let i = 0;i < obj.length; i++) {
1085
+ if (extendedTypeOf(obj[i]) !== "object")
1086
+ return false;
1087
+ }
1088
+ return obj.length != 0;
1089
+ }
1090
+ function formatString(s) {
1091
+ return JSON.stringify(s).replace(/\x7f/g, "\\u007f");
1092
+ }
1093
+ function stringifyTemporal(temporal) {
1094
+ return temporal.toString({
1095
+ calendarName: "never",
1096
+ timeZoneName: "never"
1097
+ });
1098
+ }
1099
+ function stringifyValue(val, type, depth, numberAsFloat) {
1100
+ if (depth === 0) {
1101
+ throw new Error("Could not stringify the object: maximum object depth exceeded");
1102
+ }
1103
+ switch (type) {
1104
+ case "number":
1105
+ if (isNaN(val))
1106
+ return "nan";
1107
+ if (val === Infinity)
1108
+ return "inf";
1109
+ if (val === -Infinity)
1110
+ return "-inf";
1111
+ if (Number.isInteger(val) && (numberAsFloat || !Number.isSafeInteger(val)))
1112
+ return val.toFixed(1);
1113
+ case "bigint":
1114
+ case "boolean":
1115
+ return val.toString();
1116
+ case "string":
1117
+ return formatString(val);
1118
+ case "date":
1119
+ if (isNaN(val.getTime()))
1120
+ throw new TypeError("cannot serialize invalid date");
1121
+ return val.toISOString();
1122
+ case "object":
1123
+ return stringifyInlineTable(val, depth, numberAsFloat);
1124
+ case "array":
1125
+ return stringifyArray(val, depth, numberAsFloat);
1126
+ case "temporal":
1127
+ return stringifyTemporal(val);
1128
+ }
1129
+ }
1130
+ function stringifyInlineTable(obj, depth, numberAsFloat) {
1131
+ let keys = Object.keys(obj);
1132
+ if (keys.length === 0)
1133
+ return "{}";
1134
+ let res = "{ ";
1135
+ for (let i = 0;i < keys.length; i++) {
1136
+ let k = keys[i];
1137
+ if (i)
1138
+ res += ", ";
1139
+ res += BARE_KEY.test(k) ? k : formatString(k);
1140
+ res += " = ";
1141
+ res += stringifyValue(obj[k], extendedTypeOf(obj[k]), depth - 1, numberAsFloat);
1142
+ }
1143
+ return res + " }";
1144
+ }
1145
+ function stringifyArray(array, depth, numberAsFloat) {
1146
+ if (array.length === 0)
1147
+ return "[]";
1148
+ let res = "[ ";
1149
+ for (let i = 0;i < array.length; i++) {
1150
+ if (i)
1151
+ res += ", ";
1152
+ if (array[i] === null || array[i] === undefined) {
1153
+ throw new TypeError("arrays cannot contain null or undefined values");
1154
+ }
1155
+ res += stringifyValue(array[i], extendedTypeOf(array[i]), depth - 1, numberAsFloat);
1156
+ }
1157
+ return res + " ]";
1158
+ }
1159
+ function stringifyArrayTable(array, key, depth, numberAsFloat) {
1160
+ if (depth === 0) {
1161
+ throw new Error("Could not stringify the object: maximum object depth exceeded");
1162
+ }
1163
+ let res = "";
1164
+ for (let i = 0;i < array.length; i++) {
1165
+ res += `${res && `
1166
+ `}[[${key}]]
1167
+ `;
1168
+ res += stringifyTable(0, array[i], key, depth, numberAsFloat);
1169
+ }
1170
+ return res;
1171
+ }
1172
+ function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat) {
1173
+ if (depth === 0) {
1174
+ throw new Error("Could not stringify the object: maximum object depth exceeded");
1175
+ }
1176
+ let preamble = "";
1177
+ let tables = "";
1178
+ let keys = Object.keys(obj);
1179
+ for (let i = 0;i < keys.length; i++) {
1180
+ let k = keys[i];
1181
+ if (obj[k] !== null && obj[k] !== undefined) {
1182
+ let type = extendedTypeOf(obj[k]);
1183
+ if (type === "symbol" || type === "function") {
1184
+ throw new TypeError(`cannot serialize values of type '${type}'`);
1185
+ }
1186
+ let key = BARE_KEY.test(k) ? k : formatString(k);
1187
+ if (type === "array" && isArrayOfTables(obj[k])) {
1188
+ tables += (tables && `
1189
+ `) + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat);
1190
+ } else if (type === "object") {
1191
+ let tblKey = prefix ? `${prefix}.${key}` : key;
1192
+ tables += (tables && `
1193
+ `) + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat);
1194
+ } else {
1195
+ preamble += key;
1196
+ preamble += " = ";
1197
+ preamble += stringifyValue(obj[k], type, depth, numberAsFloat);
1198
+ preamble += `
1199
+ `;
1200
+ }
1201
+ }
1202
+ }
1203
+ if (tableKey && (preamble || !tables))
1204
+ preamble = preamble ? `[${tableKey}]
1205
+ ${preamble}` : `[${tableKey}]`;
1206
+ return preamble && tables ? `${preamble}
1207
+ ${tables}` : preamble || tables;
1208
+ }
1209
+ function stringify(obj, { maxDepth = 1000, numbersAsFloat = false } = {}) {
1210
+ if (extendedTypeOf(obj) !== "object") {
1211
+ throw new TypeError("stringify can only be called with an object");
1212
+ }
1213
+ let str = stringifyTable(0, obj, "", maxDepth, numbersAsFloat);
1214
+ if (str[str.length - 1] !== `
1215
+ `)
1216
+ return str + `
1217
+ `;
1218
+ return str;
1219
+ }
1220
+
1221
+ // ../node_modules/smol-toml/dist/index.js
1222
+ /*!
1223
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
1224
+ * SPDX-License-Identifier: BSD-3-Clause
1225
+ *
1226
+ * Redistribution and use in source and binary forms, with or without
1227
+ * modification, are permitted provided that the following conditions are met:
1228
+ *
1229
+ * 1. Redistributions of source code must retain the above copyright notice, this
1230
+ * list of conditions and the following disclaimer.
1231
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
1232
+ * this list of conditions and the following disclaimer in the
1233
+ * documentation and/or other materials provided with the distribution.
1234
+ * 3. Neither the name of the copyright holder nor the names of its contributors
1235
+ * may be used to endorse or promote products derived from this software without
1236
+ * specific prior written permission.
1237
+ *
1238
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1239
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1240
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1241
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
1242
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1243
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1244
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1245
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1246
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1247
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1248
+ */
1249
+
1250
+ // src/_rust-release.ts
1251
+ var FINGERPRINT_SCHEMA = 3;
1252
+ var VERSION_SLOT_SCHEMA = 1;
1253
+ var VERSION_CAPACITY = 64;
1254
+ var MAGIC = Buffer.from("DBXVERSION\x00\x00", "binary");
1255
+ var RECORD_SIZE = 128;
1256
+ var VERSION_OFFSET = 16;
1257
+ var EMPTY_RECORD_OFFSET = 80;
1258
+ var MACH_O_MAGICS = new Set([
1259
+ "feedface",
1260
+ "cefaedfe",
1261
+ "feedfacf",
1262
+ "cffaedfe",
1263
+ "cafebabe",
1264
+ "bebafeca",
1265
+ "cafebabf",
1266
+ "bfbafeca"
1267
+ ]);
1268
+ function command(commandName, args, options = {}) {
1269
+ const result = spawnSync(commandName, [...args], {
1270
+ ...options.cwd ? { cwd: options.cwd } : {},
1271
+ stdout: options.inherit ? "inherit" : "capture",
1272
+ stderr: options.inherit ? "inherit" : "capture",
1273
+ stdin: "ignore",
1274
+ check: options.check ?? true
1275
+ });
1276
+ return result.stdout;
1277
+ }
1278
+ function record(value) {
1279
+ return value !== null && typeof value === "object" && !Array.isArray(value);
1280
+ }
1281
+ function removeVersionOnlyFields(value, key) {
1282
+ if (Array.isArray(value)) {
1283
+ for (const item of value)
1284
+ removeVersionOnlyFields(item);
1285
+ return;
1286
+ }
1287
+ if (!record(value))
1288
+ return;
1289
+ if (typeof value.path === "string")
1290
+ delete value.version;
1291
+ if (key === "package")
1292
+ delete value.version;
1293
+ for (const [childKey, child] of Object.entries(value)) {
1294
+ removeVersionOnlyFields(child, childKey);
1295
+ }
1296
+ }
1297
+ function normalizeManifest(text) {
1298
+ const document = parse(text);
1299
+ const packageTable = document.package;
1300
+ if (record(packageTable))
1301
+ delete packageTable.version;
1302
+ const workspace = document.workspace;
1303
+ if (record(workspace) && record(workspace.package))
1304
+ delete workspace.package.version;
1305
+ removeVersionOnlyFields(document);
1306
+ return stringify(document);
1307
+ }
1308
+ function normalizeLockfile(text, workspaceVersion, packageNames = new Set) {
1309
+ const document = parse(text);
1310
+ const packages = document.package;
1311
+ if (Array.isArray(packages)) {
1312
+ for (const candidate of packages) {
1313
+ if (!record(candidate) || candidate.source !== undefined)
1314
+ continue;
1315
+ if (typeof candidate.name === "string" && packageNames.has(candidate.name) || candidate.version === workspaceVersion) {
1316
+ candidate.version = "<workspace>";
1317
+ }
1318
+ }
1319
+ }
1320
+ return stringify(document);
1321
+ }
1322
+ function cargoMetadata(root) {
1323
+ const parsed = JSON.parse(command("cargo", ["metadata", "--format-version", "1", "--no-deps"], { cwd: root }));
1324
+ if (!Array.isArray(parsed.packages) || !Array.isArray(parsed.workspace_members) || typeof parsed.workspace_root !== "string") {
1325
+ throw new Error("cargo metadata returned an incomplete workspace description");
1326
+ }
1327
+ return parsed;
1328
+ }
1329
+ function workspaceVersion(root) {
1330
+ const versionFile = join(root, "VERSION");
1331
+ if (existsSync(versionFile))
1332
+ return readFileSync(versionFile, "utf8").trim();
1333
+ const document = parse(readFileSync(join(root, "Cargo.toml"), "utf8"));
1334
+ const workspace = document.workspace;
1335
+ return record(workspace) && record(workspace.package) && typeof workspace.package.version === "string" ? workspace.package.version : "";
1336
+ }
1337
+ function toPosix(path) {
1338
+ return path.split(sep).join("/");
1339
+ }
1340
+ function sourceRoots(root, metadata, sources) {
1341
+ const members = new Set(metadata.workspace_members);
1342
+ const discovered = metadata.packages.filter((candidate) => members.has(candidate.id)).map((candidate) => dirname(candidate.manifest_path));
1343
+ return [...new Set([...discovered, ...sources.map((source) => resolve(root, source))])].map((path) => toPosix(relative(root, path)) || ".").sort();
1344
+ }
1345
+ function ignoredInput(path) {
1346
+ const segments = path.split("/");
1347
+ return segments.some((segment) => segment === ".git" || segment === "node_modules" || segment === "target");
1348
+ }
1349
+ function walkFiles(root, path, output) {
1350
+ const absolute = resolve(root, path);
1351
+ if (!existsSync(absolute))
1352
+ return;
1353
+ const stat = lstatSync(absolute);
1354
+ if (!stat.isDirectory()) {
1355
+ output.push(toPosix(relative(root, absolute)));
1356
+ return;
1357
+ }
1358
+ for (const entry of readdirSync(absolute, { withFileTypes: true })) {
1359
+ const child = toPosix(relative(root, join(absolute, entry.name)));
1360
+ if (ignoredInput(child))
1361
+ continue;
1362
+ if (entry.isDirectory())
1363
+ walkFiles(root, child, output);
1364
+ else
1365
+ output.push(child);
1366
+ }
1367
+ }
1368
+ function inputFiles(root, roots) {
1369
+ const pathspecs = [
1370
+ "Cargo.toml",
1371
+ "Cargo.lock",
1372
+ ".cargo",
1373
+ "rust-toolchain",
1374
+ "rust-toolchain.toml",
1375
+ ...roots
1376
+ ];
1377
+ const git = spawnSync("git", ["ls-files", "--cached", "--others", "--exclude-standard", "-z", "--", ...pathspecs], {
1378
+ cwd: root,
1379
+ stdout: "capture",
1380
+ stderr: "ignore",
1381
+ stdin: "ignore",
1382
+ check: false,
1383
+ trim: false
1384
+ });
1385
+ const files = git.exitCode === 0 ? git.stdout.split("\x00").filter(Boolean) : pathspecs.flatMap((path) => {
1386
+ const found = [];
1387
+ walkFiles(root, path, found);
1388
+ return found;
1389
+ });
1390
+ return [...new Set(files.map(toPosix))].filter((file) => !ignoredInput(file) && existsSync(join(root, file))).sort();
1391
+ }
1392
+ function normalizedInput(root, file, content, packageNames) {
1393
+ if (file.endsWith("Cargo.toml"))
1394
+ return Buffer.from(normalizeManifest(content.toString("utf8")));
1395
+ if (file === "Cargo.lock") {
1396
+ return Buffer.from(normalizeLockfile(content.toString("utf8"), workspaceVersion(root), packageNames));
1397
+ }
1398
+ return content;
1399
+ }
1400
+ function sourceHash(root, sources = []) {
1401
+ const resolvedRoot = resolve(root);
1402
+ const metadata = cargoMetadata(resolvedRoot);
1403
+ const members = new Set(metadata.workspace_members);
1404
+ const packageNames = new Set(metadata.packages.filter((candidate) => members.has(candidate.id)).map((candidate) => candidate.name));
1405
+ const hash = createHash("sha256");
1406
+ for (const file of inputFiles(resolvedRoot, sourceRoots(resolvedRoot, metadata, sources))) {
1407
+ const absolute = join(resolvedRoot, file);
1408
+ const stat = lstatSync(absolute);
1409
+ hash.update(file);
1410
+ hash.update(Buffer.from([0]));
1411
+ hash.update(String(stat.mode & 73));
1412
+ hash.update(Buffer.from([0]));
1413
+ hash.update(stat.isSymbolicLink() ? Buffer.from(readlinkSync(absolute)) : normalizedInput(resolvedRoot, file, readFileSync(absolute), packageNames));
1414
+ hash.update(Buffer.from([0]));
1415
+ }
1416
+ return hash.digest("hex");
1417
+ }
1418
+ function linkerIdentity(target) {
1419
+ if (target.includes("windows-msvc"))
1420
+ return "rust-lld";
1421
+ if (target.includes("linux"))
1422
+ return "system-linux-linker";
1423
+ if (target.includes("apple-darwin"))
1424
+ return "apple-ld";
1425
+ return "system-linker";
1426
+ }
1427
+ function targetKey({
1428
+ rustSourceHash,
1429
+ target,
1430
+ targetConfig = "",
1431
+ toolchain = "stable",
1432
+ rustc
1433
+ }) {
1434
+ const hash = createHash("sha256");
1435
+ for (const value of [
1436
+ String(FINGERPRINT_SCHEMA),
1437
+ String(VERSION_SLOT_SCHEMA),
1438
+ rustSourceHash,
1439
+ target,
1440
+ targetConfig,
1441
+ toolchain,
1442
+ rustc ?? "<portable>",
1443
+ linkerIdentity(target),
1444
+ "release",
1445
+ "raw-target-release-v2"
1446
+ ]) {
1447
+ hash.update(value);
1448
+ hash.update(Buffer.from([0]));
1449
+ }
1450
+ return hash.digest("hex");
1451
+ }
1452
+ function rustcIdentity() {
1453
+ return command("rustc", ["--version", "--verbose"]).split(/\r?\n/).filter((line) => line && !line.startsWith("host: ")).join(`
1454
+ `);
1455
+ }
1456
+ function fingerprint({
1457
+ root = process.cwd(),
1458
+ output = ".release/rust-build.json",
1459
+ check = false,
1460
+ targets,
1461
+ toolchain = "stable",
1462
+ portable = false,
1463
+ sources = []
1464
+ }) {
1465
+ if (!targets.length)
1466
+ throw new Error("at least one --target is required");
1467
+ const resolvedRoot = resolve(root);
1468
+ const rustSourceHash = sourceHash(resolvedRoot, sources);
1469
+ const rustc = portable ? undefined : rustcIdentity();
1470
+ const targetEntries = targets.map((specification) => {
1471
+ const separator = specification.indexOf("|");
1472
+ const target = separator < 0 ? specification : specification.slice(0, separator);
1473
+ const targetConfig = separator < 0 ? "" : specification.slice(separator + 1);
1474
+ return [
1475
+ target,
1476
+ targetKey({ rustSourceHash, target, targetConfig, toolchain, rustc })
1477
+ ];
1478
+ }).sort(([left], [right]) => left.localeCompare(right));
1479
+ const manifest = {
1480
+ schemaVersion: FINGERPRINT_SCHEMA,
1481
+ versionSlotSchema: VERSION_SLOT_SCHEMA,
1482
+ rustSourceHash,
1483
+ targets: Object.fromEntries(targetEntries)
1484
+ };
1485
+ const outputPath = resolve(resolvedRoot, output);
1486
+ if (check) {
1487
+ const current = JSON.parse(readFileSync(outputPath, "utf8"));
1488
+ const targetsMatch = targetEntries.every(([target, key]) => current.targets?.[target] === key);
1489
+ if (current.schemaVersion !== manifest.schemaVersion || current.versionSlotSchema !== manifest.versionSlotSchema || current.rustSourceHash !== manifest.rustSourceHash || !targetsMatch) {
1490
+ throw new Error(`${outputPath} does not match current Rust inputs`);
1491
+ }
1492
+ } else {
1493
+ mkdirSync(dirname(outputPath), { recursive: true });
1494
+ writeFileSync(outputPath, `${JSON.stringify(manifest, null, 2)}
1495
+ `);
1496
+ }
1497
+ return manifest;
1498
+ }
1499
+ var SECTION_BY_FORMAT = {
1500
+ elf: ".dbxversion",
1501
+ macho: "__DATA,__dbxver",
1502
+ pe: ".dbxver"
1503
+ };
1504
+ function binaryFormat(data) {
1505
+ if (data.length >= 4 && data.subarray(0, 4).equals(Buffer.from([127, 69, 76, 70]))) {
1506
+ return "elf";
1507
+ }
1508
+ if (data.length >= 2 && data.subarray(0, 2).toString("ascii") === "MZ")
1509
+ return "pe";
1510
+ if (data.length >= 4 && MACH_O_MAGICS.has(data.subarray(0, 4).toString("hex")))
1511
+ return "macho";
1512
+ return;
1513
+ }
1514
+ function binaryHeader(path) {
1515
+ const descriptor = openSync(path, "r");
1516
+ try {
1517
+ const header = Buffer.alloc(4);
1518
+ return header.subarray(0, readSync(descriptor, header, 0, header.length, 0));
1519
+ } finally {
1520
+ closeSync(descriptor);
1521
+ }
1522
+ }
1523
+ function executableOnPath(name) {
1524
+ return spawnSync(process.platform === "win32" ? "where" : "which", [name], {
1525
+ stdout: "ignore",
1526
+ stderr: "ignore",
1527
+ stdin: "ignore",
1528
+ check: false
1529
+ }).exitCode === 0;
1530
+ }
1531
+ function llvmObjcopy(explicit) {
1532
+ if (explicit)
1533
+ return explicit;
1534
+ if (process.env.LLVM_OBJCOPY)
1535
+ return process.env.LLVM_OBJCOPY;
1536
+ if (executableOnPath("llvm-objcopy"))
1537
+ return "llvm-objcopy";
1538
+ const verbose = command("rustc", ["--version", "--verbose"]);
1539
+ const host = /^host:\s*(.+)$/m.exec(verbose)?.[1];
1540
+ const sysroot = command("rustc", ["--print", "sysroot"]);
1541
+ if (host) {
1542
+ const candidate = join(sysroot, "lib", "rustlib", host, "bin", process.platform === "win32" ? "llvm-objcopy.exe" : "llvm-objcopy");
1543
+ if (existsSync(candidate))
1544
+ return candidate;
1545
+ }
1546
+ throw new Error("llvm-objcopy is unavailable; install the Rust llvm-tools-preview component");
1547
+ }
1548
+ function validRecord(data, binary, section) {
1549
+ if (data.length !== RECORD_SIZE) {
1550
+ throw new Error(`version section ${section} in ${binary} must be ${RECORD_SIZE} bytes, got ${data.length}`);
1551
+ }
1552
+ if (!data.subarray(0, MAGIC.length).equals(MAGIC)) {
1553
+ throw new Error(`version section ${section} in ${binary} has invalid magic`);
1554
+ }
1555
+ if (data.readUInt16LE(12) !== VERSION_SLOT_SCHEMA || data.readUInt16LE(14) > VERSION_CAPACITY) {
1556
+ throw new Error(`version section ${section} in ${binary} has an unsupported record schema`);
1557
+ }
1558
+ if (!data.subarray(EMPTY_RECORD_OFFSET).every((byte) => byte === 0)) {
1559
+ throw new Error(`version section ${section} in ${binary} has non-zero reserved bytes`);
1560
+ }
1561
+ }
1562
+ function stamp(binary, version, options = {}) {
1563
+ const encoded = Buffer.from(version, "utf8");
1564
+ if (!encoded.length || encoded.length > VERSION_CAPACITY) {
1565
+ throw new Error(`version must contain 1 to ${VERSION_CAPACITY} bytes`);
1566
+ }
1567
+ const format = binaryFormat(binaryHeader(binary));
1568
+ if (!format)
1569
+ return false;
1570
+ const section = SECTION_BY_FORMAT[format];
1571
+ const objcopy = llvmObjcopy(options.objcopy);
1572
+ const temporary = mkdtempSync(join(tmpdir(), "dbx-rust-version-"));
1573
+ const recordPath = join(temporary, "record.bin");
1574
+ const mode = statSync(binary).mode;
1575
+ try {
1576
+ const dumped = spawnSync(objcopy, ["--dump-section", `${section}=${recordPath}`, binary], {
1577
+ stdout: "ignore",
1578
+ stderr: "ignore",
1579
+ stdin: "ignore",
1580
+ check: false
1581
+ });
1582
+ if (dumped.exitCode !== 0 || !existsSync(recordPath))
1583
+ return false;
1584
+ const data = readFileSync(recordPath);
1585
+ validRecord(data, binary, section);
1586
+ data.writeUInt16LE(encoded.length, 14);
1587
+ data.fill(0, VERSION_OFFSET, VERSION_OFFSET + VERSION_CAPACITY);
1588
+ encoded.copy(data, VERSION_OFFSET);
1589
+ writeFileSync(recordPath, data);
1590
+ command(objcopy, ["--update-section", `${section}=${recordPath}`, binary], { inherit: true });
1591
+ chmodSync(binary, mode);
1592
+ if (format === "macho") {
1593
+ command(options.codesign ?? "codesign", ["--force", "--sign", "-", binary], {
1594
+ inherit: true
1595
+ });
1596
+ }
1597
+ return true;
1598
+ } finally {
1599
+ rmSync(temporary, { recursive: true, force: true });
1600
+ }
1601
+ }
1602
+ function files(root) {
1603
+ const found = [];
1604
+ const pending = [root];
1605
+ while (pending.length) {
1606
+ const directory = pending.pop();
1607
+ for (const entry of readdirSync(directory, { withFileTypes: true })) {
1608
+ const path = join(directory, entry.name);
1609
+ if (entry.isDirectory())
1610
+ pending.push(path);
1611
+ else if (entry.isFile())
1612
+ found.push(path);
1613
+ }
1614
+ }
1615
+ return found.sort();
1616
+ }
1617
+ function stampTree(root, version, options = {}) {
1618
+ let stamped = 0;
1619
+ for (const file of files(root))
1620
+ if (stamp(file, version, options))
1621
+ stamped += 1;
1622
+ if (!stamped)
1623
+ throw new Error(`no structured version sections found under ${root}`);
1624
+ process.stdout.write(`stamped ${stamped} native artifact(s)
1625
+ `);
1626
+ return stamped;
1627
+ }
1628
+ function fingerprintCommand(args) {
1629
+ const { values } = parseArgs({
1630
+ args: [...args],
1631
+ options: {
1632
+ root: { type: "string", default: process.cwd() },
1633
+ output: { type: "string", default: ".release/rust-build.json" },
1634
+ check: { type: "boolean", default: false },
1635
+ target: { type: "string", multiple: true },
1636
+ toolchain: { type: "string", default: "stable" },
1637
+ portable: { type: "boolean", default: false },
1638
+ source: { type: "string", multiple: true }
1639
+ },
1640
+ strict: true
1641
+ });
1642
+ fingerprint({
1643
+ root: values.root,
1644
+ output: values.output,
1645
+ check: values.check,
1646
+ targets: values.target ?? [],
1647
+ toolchain: values.toolchain,
1648
+ portable: values.portable,
1649
+ sources: values.source ?? []
1650
+ });
1651
+ }
1652
+ function stampCommand(args) {
1653
+ const { values } = parseArgs({
1654
+ args: [...args],
1655
+ options: {
1656
+ binary: { type: "string" },
1657
+ version: { type: "string" },
1658
+ objcopy: { type: "string" }
1659
+ },
1660
+ strict: true
1661
+ });
1662
+ if (!values.binary || values.version === undefined) {
1663
+ throw new Error("stamp requires --binary and --version");
1664
+ }
1665
+ if (!stamp(values.binary, values.version, { objcopy: values.objcopy })) {
1666
+ throw new Error(`no structured version section found in ${values.binary}`);
1667
+ }
1668
+ }
1669
+ function stampTreeCommand(args) {
1670
+ const { values } = parseArgs({
1671
+ args: [...args],
1672
+ options: {
1673
+ root: { type: "string" },
1674
+ version: { type: "string" },
1675
+ objcopy: { type: "string" }
1676
+ },
1677
+ strict: true
1678
+ });
1679
+ if (!values.root || values.version === undefined) {
1680
+ throw new Error("stamp-tree requires --root and --version");
1681
+ }
1682
+ stampTree(values.root, values.version, { objcopy: values.objcopy });
1683
+ }
1684
+ function main(args = process.argv.slice(2)) {
1685
+ const [subcommand, ...commandArgs] = args;
1686
+ if (subcommand === "fingerprint")
1687
+ return fingerprintCommand(commandArgs);
1688
+ if (subcommand === "stamp")
1689
+ return stampCommand(commandArgs);
1690
+ if (subcommand === "stamp-tree")
1691
+ return stampTreeCommand(commandArgs);
1692
+ throw new Error("expected fingerprint, stamp, or stamp-tree");
1693
+ }
1694
+ var invokedPath = process.argv[1] ? resolve(process.argv[1]) : "";
1695
+ if (invokedPath === fileURLToPath(import.meta.url)) {
1696
+ try {
1697
+ main();
1698
+ } catch (error) {
1699
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}
1700
+ `);
1701
+ process.exitCode = 1;
1702
+ }
1703
+ }
1704
+ export {
1705
+ targetKey,
1706
+ stampTree,
1707
+ stamp,
1708
+ sourceHash,
1709
+ normalizeManifest,
1710
+ normalizeLockfile,
1711
+ main,
1712
+ linkerIdentity,
1713
+ fingerprint,
1714
+ VERSION_SLOT_SCHEMA,
1715
+ VERSION_CAPACITY,
1716
+ FINGERPRINT_SCHEMA
1717
+ };