pythonlib 1.0.2 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/README.md +123 -49
  2. package/dist/base64-C_am75Sv.d.ts +165 -0
  3. package/dist/base64.d.ts +1 -0
  4. package/dist/base64.js +37 -0
  5. package/dist/chunk-2QEMKE7U.js +252 -0
  6. package/dist/chunk-2YTO24B5.js +78 -0
  7. package/dist/chunk-3HQSBCEC.js +348 -0
  8. package/dist/{chunk-7BZB2TQF.js → chunk-3M3PB4RO.js} +4 -6
  9. package/dist/chunk-5OKGPZBQ.js +1106 -0
  10. package/dist/chunk-B5LQJODJ.js +37 -0
  11. package/dist/{chunk-CUP6EPDB.js → chunk-BCMGGBWG.js} +2 -5
  12. package/dist/chunk-BCVIH2BN.js +175 -0
  13. package/dist/chunk-CANUXHVB.js +349 -0
  14. package/dist/{chunk-QURVRHY2.js → chunk-D35YI363.js} +15 -12
  15. package/dist/{chunk-RSBRI27Z.js → chunk-ETBW6XNR.js} +3 -4
  16. package/dist/chunk-HSTC277I.js +255 -0
  17. package/dist/chunk-HTCQ4OO5.js +238 -0
  18. package/dist/chunk-IANXD4D4.js +250 -0
  19. package/dist/{chunk-G6PUQTVZ.js → chunk-JAUU3HMH.js} +1 -2
  20. package/dist/chunk-JVTQM7CI.js +195 -0
  21. package/dist/chunk-KKJHGY4C.js +551 -0
  22. package/dist/chunk-LHPQS75Z.js +192 -0
  23. package/dist/{chunk-OSX7QZAW.js → chunk-LK2L2TFG.js} +5 -6
  24. package/dist/{chunk-CEZSBJJV.js → chunk-LWYBTWBZ.js} +2 -3
  25. package/dist/chunk-MEEU4SH5.js +362 -0
  26. package/dist/{chunk-TAYRRHJ3.js → chunk-MFKIEN7N.js} +1 -2
  27. package/dist/{chunk-PZ5AY32C.js → chunk-MLKGABMK.js} +0 -1
  28. package/dist/chunk-OZRS5PC4.js +312 -0
  29. package/dist/chunk-PVK4F3ME.js +194 -0
  30. package/dist/{chunk-56DGFWIJ.js → chunk-QKJBQKPY.js} +1 -2
  31. package/dist/chunk-RB6BYCIQ.js +141 -0
  32. package/dist/chunk-RRSOZXZE.js +155 -0
  33. package/dist/chunk-THMJVAK6.js +282 -0
  34. package/dist/chunk-UGZ5OY5Z.js +165 -0
  35. package/dist/chunk-WTZSAITC.js +82 -0
  36. package/dist/chunk-YONWJHJU.js +265 -0
  37. package/dist/collections.js +2 -3
  38. package/dist/copy-6ZaZ__ge.d.ts +59 -0
  39. package/dist/copy.d.ts +1 -0
  40. package/dist/copy.js +9 -0
  41. package/dist/datetime.js +2 -3
  42. package/dist/functools.js +2 -3
  43. package/dist/glob.browser-B6d_YdV5.d.ts +50 -0
  44. package/dist/glob.browser.d.ts +1 -0
  45. package/dist/glob.browser.js +15 -0
  46. package/dist/glob.node-wn5ehtyM.d.ts +80 -0
  47. package/dist/glob.node.d.ts +1 -0
  48. package/dist/glob.node.js +15 -0
  49. package/dist/hashlib-vKP511NY.d.ts +205 -0
  50. package/dist/hashlib.d.ts +1 -0
  51. package/dist/hashlib.js +39 -0
  52. package/dist/index.browser.d.ts +172 -0
  53. package/dist/index.browser.js +305 -0
  54. package/dist/index.d.ts +36 -602
  55. package/dist/index.js +138 -1073
  56. package/dist/itertools.js +2 -3
  57. package/dist/json.js +2 -3
  58. package/dist/logging.browser-Dux4L5kz.d.ts +185 -0
  59. package/dist/logging.browser.d.ts +1 -0
  60. package/dist/logging.browser.js +63 -0
  61. package/dist/logging.node-CH75bVdE.d.ts +185 -0
  62. package/dist/logging.node.d.ts +1 -0
  63. package/dist/logging.node.js +61 -0
  64. package/dist/math.js +2 -3
  65. package/dist/{os-CqGKe872.d.ts → os.browser-krjSx5kF.d.ts} +32 -55
  66. package/dist/os.browser.d.ts +2 -0
  67. package/dist/{os.js → os.browser.js} +41 -16
  68. package/dist/os.node-CQjch8Ht.d.ts +124 -0
  69. package/dist/os.node.d.ts +2 -0
  70. package/dist/os.node.js +83 -0
  71. package/dist/os.shared-C3x70nhO.d.ts +59 -0
  72. package/dist/pathlib.browser-NC7kKQYe.d.ts +91 -0
  73. package/dist/pathlib.browser.d.ts +1 -0
  74. package/dist/pathlib.browser.js +17 -0
  75. package/dist/pathlib.node-CY3yUFdT.d.ts +331 -0
  76. package/dist/pathlib.node.d.ts +2 -0
  77. package/dist/pathlib.node.js +17 -0
  78. package/dist/random.js +2 -3
  79. package/dist/re.js +2 -3
  80. package/dist/set-JQbLAq8B.d.ts +592 -0
  81. package/dist/shutil.browser-Ck5oWhnP.d.ts +113 -0
  82. package/dist/shutil.browser.d.ts +1 -0
  83. package/dist/shutil.browser.js +33 -0
  84. package/dist/shutil.node-C9kwvhAf.d.ts +160 -0
  85. package/dist/shutil.node.d.ts +2 -0
  86. package/dist/shutil.node.js +33 -0
  87. package/dist/string.js +2 -3
  88. package/dist/subprocess-CZVYzQ3V.d.ts +214 -0
  89. package/dist/subprocess.d.ts +1 -0
  90. package/dist/subprocess.js +29 -0
  91. package/dist/sys-IL8LgI_W.d.ts +212 -0
  92. package/dist/sys.d.ts +1 -0
  93. package/dist/sys.js +51 -0
  94. package/dist/tempfile.browser-DciOKfNm.d.ts +78 -0
  95. package/dist/tempfile.browser.d.ts +1 -0
  96. package/dist/tempfile.browser.js +19 -0
  97. package/dist/tempfile.node-bVMY60Cu.d.ts +195 -0
  98. package/dist/tempfile.node.d.ts +2 -0
  99. package/dist/tempfile.node.js +23 -0
  100. package/dist/time-CcYhdiSu.d.ts +245 -0
  101. package/dist/time.d.ts +1 -0
  102. package/dist/time.js +49 -0
  103. package/dist/urllib-DJtkj-0f.d.ts +198 -0
  104. package/dist/urllib.d.ts +1 -0
  105. package/dist/urllib.js +37 -0
  106. package/dist/uuid-C0ypmn56.d.ts +160 -0
  107. package/dist/uuid.d.ts +1 -0
  108. package/dist/uuid.js +23 -0
  109. package/package.json +128 -5
  110. package/dist/chunk-56DGFWIJ.js.map +0 -1
  111. package/dist/chunk-5AOJFFYN.js +0 -313
  112. package/dist/chunk-5AOJFFYN.js.map +0 -1
  113. package/dist/chunk-7BZB2TQF.js.map +0 -1
  114. package/dist/chunk-CEZSBJJV.js.map +0 -1
  115. package/dist/chunk-CUP6EPDB.js.map +0 -1
  116. package/dist/chunk-G6PUQTVZ.js.map +0 -1
  117. package/dist/chunk-OSX7QZAW.js.map +0 -1
  118. package/dist/chunk-PZ5AY32C.js.map +0 -1
  119. package/dist/chunk-QURVRHY2.js.map +0 -1
  120. package/dist/chunk-RSBRI27Z.js.map +0 -1
  121. package/dist/chunk-TAYRRHJ3.js.map +0 -1
  122. package/dist/collections.js.map +0 -1
  123. package/dist/datetime.js.map +0 -1
  124. package/dist/functools.js.map +0 -1
  125. package/dist/index.js.map +0 -1
  126. package/dist/itertools.js.map +0 -1
  127. package/dist/json.js.map +0 -1
  128. package/dist/math.js.map +0 -1
  129. package/dist/os.d.ts +0 -1
  130. package/dist/os.js.map +0 -1
  131. package/dist/random.js.map +0 -1
  132. package/dist/re.js.map +0 -1
  133. package/dist/string.js.map +0 -1
@@ -0,0 +1,155 @@
1
+ import {
2
+ __export
3
+ } from "./chunk-MLKGABMK.js";
4
+
5
+ // src/copy.ts
6
+ var copy_exports = {};
7
+ __export(copy_exports, {
8
+ copy: () => copy,
9
+ deepcopy: () => deepcopy
10
+ });
11
+ function copy(x) {
12
+ if (x === null || x === void 0) {
13
+ return x;
14
+ }
15
+ const type = typeof x;
16
+ if (type === "number" || type === "string" || type === "boolean" || type === "bigint" || type === "symbol") {
17
+ return x;
18
+ }
19
+ if (x instanceof Date) {
20
+ return new Date(x.getTime());
21
+ }
22
+ if (x instanceof RegExp) {
23
+ return new RegExp(x.source, x.flags);
24
+ }
25
+ if (Array.isArray(x)) {
26
+ return [...x];
27
+ }
28
+ if (x instanceof Map) {
29
+ return new Map(x);
30
+ }
31
+ if (x instanceof Set) {
32
+ return new Set(x);
33
+ }
34
+ if (ArrayBuffer.isView(x) && !(x instanceof DataView)) {
35
+ const TypedArrayConstructor = x.constructor;
36
+ const typedArray = x;
37
+ return new TypedArrayConstructor(typedArray.buffer.slice(0));
38
+ }
39
+ if (x instanceof DataView) {
40
+ return new DataView(x.buffer.slice(0), x.byteOffset, x.byteLength);
41
+ }
42
+ if (x instanceof ArrayBuffer) {
43
+ return x.slice(0);
44
+ }
45
+ if (type === "object") {
46
+ const proto = Object.getPrototypeOf(x);
47
+ if (proto === Object.prototype || proto === null) {
48
+ return { ...x };
49
+ }
50
+ const result = Object.create(proto);
51
+ Object.assign(result, x);
52
+ return result;
53
+ }
54
+ return x;
55
+ }
56
+ function deepcopy(x, memo) {
57
+ if (typeof structuredClone === "function") {
58
+ try {
59
+ return structuredClone(x);
60
+ } catch {
61
+ }
62
+ }
63
+ if (x === null || x === void 0) {
64
+ return x;
65
+ }
66
+ const type = typeof x;
67
+ if (type === "number" || type === "string" || type === "boolean" || type === "bigint" || type === "symbol") {
68
+ return x;
69
+ }
70
+ memo ??= /* @__PURE__ */ new Map();
71
+ if (memo.has(x)) {
72
+ return memo.get(x);
73
+ }
74
+ if (x instanceof Date) {
75
+ const result = new Date(x.getTime());
76
+ memo.set(x, result);
77
+ return result;
78
+ }
79
+ if (x instanceof RegExp) {
80
+ const result = new RegExp(x.source, x.flags);
81
+ memo.set(x, result);
82
+ return result;
83
+ }
84
+ if (Array.isArray(x)) {
85
+ const result = [];
86
+ memo.set(x, result);
87
+ for (const item of x) {
88
+ result.push(deepcopy(item, memo));
89
+ }
90
+ return result;
91
+ }
92
+ if (x instanceof Map) {
93
+ const result = /* @__PURE__ */ new Map();
94
+ memo.set(x, result);
95
+ for (const [key, value] of x) {
96
+ result.set(deepcopy(key, memo), deepcopy(value, memo));
97
+ }
98
+ return result;
99
+ }
100
+ if (x instanceof Set) {
101
+ const result = /* @__PURE__ */ new Set();
102
+ memo.set(x, result);
103
+ for (const item of x) {
104
+ result.add(deepcopy(item, memo));
105
+ }
106
+ return result;
107
+ }
108
+ if (ArrayBuffer.isView(x) && !(x instanceof DataView)) {
109
+ const TypedArrayConstructor = x.constructor;
110
+ const typedArray = x;
111
+ const result = new TypedArrayConstructor(typedArray.buffer.slice(0));
112
+ memo.set(x, result);
113
+ return result;
114
+ }
115
+ if (x instanceof DataView) {
116
+ const result = new DataView(x.buffer.slice(0), x.byteOffset, x.byteLength);
117
+ memo.set(x, result);
118
+ return result;
119
+ }
120
+ if (x instanceof ArrayBuffer) {
121
+ const result = x.slice(0);
122
+ memo.set(x, result);
123
+ return result;
124
+ }
125
+ if (type === "function") {
126
+ return x;
127
+ }
128
+ if (type === "object") {
129
+ const proto = Object.getPrototypeOf(x);
130
+ const result = Object.create(proto);
131
+ memo.set(x, result);
132
+ for (const key of Object.keys(x)) {
133
+ result[key] = deepcopy(x[key], memo);
134
+ }
135
+ for (const sym of Object.getOwnPropertySymbols(x)) {
136
+ const descriptor = Object.getOwnPropertyDescriptor(x, sym);
137
+ if (descriptor?.enumerable) {
138
+ ;
139
+ result[sym] = deepcopy(
140
+ x[sym],
141
+ memo
142
+ );
143
+ }
144
+ }
145
+ return result;
146
+ }
147
+ return x;
148
+ }
149
+
150
+ export {
151
+ copy,
152
+ deepcopy,
153
+ copy_exports
154
+ };
155
+ /* v8 ignore start -- fallback for environments without structuredClone @preserve */
@@ -0,0 +1,282 @@
1
+ import {
2
+ __export
3
+ } from "./chunk-MLKGABMK.js";
4
+
5
+ // src/subprocess.ts
6
+ var subprocess_exports = {};
7
+ __export(subprocess_exports, {
8
+ CalledProcessError: () => CalledProcessError,
9
+ DEVNULL: () => DEVNULL,
10
+ PIPE: () => PIPE,
11
+ Popen: () => Popen,
12
+ STDOUT: () => STDOUT,
13
+ TimeoutExpired: () => TimeoutExpired,
14
+ call: () => call,
15
+ checkCall: () => checkCall,
16
+ checkOutput: () => checkOutput,
17
+ getoutput: () => getoutput,
18
+ getstatusoutput: () => getstatusoutput,
19
+ run: () => run
20
+ });
21
+ import * as childProcess from "child_process";
22
+ var PIPE = "pipe";
23
+ var STDOUT = "stdout";
24
+ var DEVNULL = "devnull";
25
+ var CalledProcessError = class extends Error {
26
+ returncode;
27
+ cmd;
28
+ stdout;
29
+ stderr;
30
+ constructor(returncode, cmd, stdout = null, stderr = null) {
31
+ super(`Command '${cmd.join(" ")}' returned non-zero exit status ${String(returncode)}`);
32
+ this.name = "CalledProcessError";
33
+ this.returncode = returncode;
34
+ this.cmd = cmd;
35
+ this.stdout = stdout;
36
+ this.stderr = stderr;
37
+ }
38
+ };
39
+ var TimeoutExpired = class extends Error {
40
+ cmd;
41
+ timeout;
42
+ stdout;
43
+ stderr;
44
+ constructor(cmd, timeout, stdout = null, stderr = null) {
45
+ super(`Command '${cmd.join(" ")}' timed out after ${String(timeout)} milliseconds`);
46
+ this.name = "TimeoutExpired";
47
+ this.cmd = cmd;
48
+ this.timeout = timeout;
49
+ this.stdout = stdout;
50
+ this.stderr = stderr;
51
+ }
52
+ };
53
+ function run(args, options) {
54
+ const encoding = options?.encoding ?? "utf-8";
55
+ const text = options?.text ?? true;
56
+ let command;
57
+ let cmdArgs;
58
+ if (typeof args === "string") {
59
+ command = args;
60
+ cmdArgs = [args];
61
+ } else {
62
+ command = args[0] ?? "";
63
+ cmdArgs = args.slice(1);
64
+ }
65
+ const spawnOptions = {
66
+ cwd: options?.cwd,
67
+ env: options?.env ? { ...process.env, ...options.env } : void 0,
68
+ input: options?.input,
69
+ timeout: options?.timeout,
70
+ shell: options?.shell,
71
+ encoding: text ? encoding : "buffer",
72
+ stdio: [
73
+ options?.input !== void 0 ? "pipe" : "inherit",
74
+ options?.stdout === PIPE ? "pipe" : options?.stdout === DEVNULL ? "ignore" : "inherit",
75
+ options?.stderr === PIPE ? "pipe" : options?.stderr === STDOUT ? "pipe" : options?.stderr === DEVNULL ? "ignore" : "inherit"
76
+ ]
77
+ };
78
+ let result;
79
+ if (typeof args === "string" || options?.shell) {
80
+ result = childProcess.spawnSync(typeof args === "string" ? args : args.join(" "), [], {
81
+ ...spawnOptions,
82
+ shell: true
83
+ });
84
+ } else {
85
+ result = childProcess.spawnSync(command, cmdArgs, spawnOptions);
86
+ }
87
+ if (result.error && result.error.code === "ETIMEDOUT") {
88
+ throw new TimeoutExpired(
89
+ typeof args === "string" ? [args] : args,
90
+ options?.timeout ?? 0,
91
+ result.stdout ? result.stdout.toString() : null,
92
+ result.stderr ? result.stderr.toString() : null
93
+ );
94
+ }
95
+ const stdout = result.stdout ? text ? result.stdout.toString() : result.stdout.toString() : null;
96
+ const stderr = result.stderr ? text ? result.stderr.toString() : result.stderr.toString() : null;
97
+ const returncode = result.status ?? -1;
98
+ if (options?.check && returncode !== 0) {
99
+ throw new CalledProcessError(
100
+ returncode,
101
+ typeof args === "string" ? [args] : args,
102
+ stdout,
103
+ stderr
104
+ );
105
+ }
106
+ return {
107
+ args: typeof args === "string" ? [args] : args,
108
+ returncode,
109
+ stdout,
110
+ stderr
111
+ };
112
+ }
113
+ function call(args, options) {
114
+ const result = run(args, options);
115
+ return result.returncode;
116
+ }
117
+ function checkCall(args, options) {
118
+ const result = run(args, { ...options, check: true });
119
+ return result.returncode;
120
+ }
121
+ function checkOutput(args, options) {
122
+ const result = run(args, { ...options, stdout: PIPE, check: true });
123
+ return result.stdout ?? "";
124
+ }
125
+ function getoutput(cmd) {
126
+ try {
127
+ const result = run(cmd, { shell: true, stdout: PIPE, stderr: DEVNULL });
128
+ return result.stdout?.trim() ?? "";
129
+ } catch {
130
+ return "";
131
+ }
132
+ }
133
+ function getstatusoutput(cmd) {
134
+ const result = run(cmd, { shell: true, stdout: PIPE, stderr: STDOUT });
135
+ return [result.returncode, result.stdout?.trim() ?? ""];
136
+ }
137
+ var Popen = class {
138
+ args;
139
+ process;
140
+ _returncode = null;
141
+ _stdout = null;
142
+ _stderr = null;
143
+ constructor(args, options) {
144
+ this.args = typeof args === "string" ? [args] : args;
145
+ const command = typeof args === "string" ? args : args[0] ?? "";
146
+ const cmdArgs = typeof args === "string" ? [] : args.slice(1);
147
+ const spawnOptions = {
148
+ cwd: options?.cwd,
149
+ env: options?.env ? { ...process.env, ...options.env } : void 0,
150
+ shell: options?.shell,
151
+ stdio: [
152
+ options?.input !== void 0 ? "pipe" : "inherit",
153
+ options?.stdout === PIPE ? "pipe" : options?.stdout === DEVNULL ? "ignore" : "inherit",
154
+ options?.stderr === PIPE ? "pipe" : options?.stderr === STDOUT ? "pipe" : options?.stderr === DEVNULL ? "ignore" : "inherit"
155
+ ]
156
+ };
157
+ if (typeof args === "string" || options?.shell) {
158
+ this.process = childProcess.spawn(typeof args === "string" ? args : args.join(" "), [], {
159
+ ...spawnOptions,
160
+ shell: true
161
+ });
162
+ } else {
163
+ this.process = childProcess.spawn(command, cmdArgs, spawnOptions);
164
+ }
165
+ if (options?.input !== void 0 && this.process.stdin) {
166
+ this.process.stdin.write(options.input);
167
+ this.process.stdin.end();
168
+ }
169
+ if (this.process.stdout) {
170
+ let data = "";
171
+ this.process.stdout.on("data", (chunk) => {
172
+ data += chunk.toString();
173
+ });
174
+ this.process.stdout.on("end", () => {
175
+ this._stdout = data;
176
+ });
177
+ }
178
+ if (this.process.stderr) {
179
+ let data = "";
180
+ this.process.stderr.on("data", (chunk) => {
181
+ data += chunk.toString();
182
+ });
183
+ this.process.stderr.on("end", () => {
184
+ this._stderr = data;
185
+ });
186
+ }
187
+ this.process.on("exit", (code) => {
188
+ this._returncode = code ?? -1;
189
+ });
190
+ }
191
+ /**
192
+ * Wait for the process to complete.
193
+ */
194
+ wait() {
195
+ return new Promise((resolve) => {
196
+ if (this._returncode !== null) {
197
+ resolve(this._returncode);
198
+ } else {
199
+ this.process.on("exit", (code) => {
200
+ resolve(code ?? -1);
201
+ });
202
+ }
203
+ });
204
+ }
205
+ /**
206
+ * Get the exit code (or null if still running).
207
+ */
208
+ poll() {
209
+ return this._returncode;
210
+ }
211
+ /**
212
+ * Communicate with the process and return stdout/stderr.
213
+ */
214
+ async communicate(input) {
215
+ if (input !== void 0 && this.process.stdin) {
216
+ this.process.stdin.write(input);
217
+ this.process.stdin.end();
218
+ }
219
+ await this.wait();
220
+ return [this._stdout, this._stderr];
221
+ }
222
+ /* v8 ignore start -- process control methods are hard to test reliably @preserve */
223
+ /**
224
+ * Send a signal to the process.
225
+ */
226
+ send_signal(signal) {
227
+ return this.process.kill(signal);
228
+ }
229
+ /**
230
+ * Terminate the process.
231
+ */
232
+ terminate() {
233
+ return this.process.kill("SIGTERM");
234
+ }
235
+ /**
236
+ * Kill the process.
237
+ */
238
+ kill() {
239
+ return this.process.kill("SIGKILL");
240
+ }
241
+ /* v8 ignore stop */
242
+ /**
243
+ * The process ID.
244
+ */
245
+ get pid() {
246
+ return this.process.pid;
247
+ }
248
+ /**
249
+ * The exit code (or null if still running).
250
+ */
251
+ get returncode() {
252
+ return this._returncode;
253
+ }
254
+ /**
255
+ * The captured stdout.
256
+ */
257
+ get stdout() {
258
+ return this._stdout;
259
+ }
260
+ /**
261
+ * The captured stderr.
262
+ */
263
+ get stderr() {
264
+ return this._stderr;
265
+ }
266
+ };
267
+
268
+ export {
269
+ PIPE,
270
+ STDOUT,
271
+ DEVNULL,
272
+ CalledProcessError,
273
+ TimeoutExpired,
274
+ run,
275
+ call,
276
+ checkCall,
277
+ checkOutput,
278
+ getoutput,
279
+ getstatusoutput,
280
+ Popen,
281
+ subprocess_exports
282
+ };
@@ -0,0 +1,165 @@
1
+ import {
2
+ __export
3
+ } from "./chunk-MLKGABMK.js";
4
+
5
+ // src/tempfile.node.ts
6
+ var tempfile_node_exports = {};
7
+ __export(tempfile_node_exports, {
8
+ NamedTemporaryFile: () => NamedTemporaryFile,
9
+ TemporaryDirectory: () => TemporaryDirectory,
10
+ gettempdir: () => gettempdir,
11
+ gettempprefix: () => gettempprefix,
12
+ mkdtemp: () => mkdtemp,
13
+ mkstemp: () => mkstemp,
14
+ mktemp: () => mktemp,
15
+ namedTemporaryFile: () => namedTemporaryFile,
16
+ temporaryDirectory: () => temporaryDirectory
17
+ });
18
+ import { mkdir, open, rm, unlink } from "fs/promises";
19
+ import { join } from "path";
20
+ import { tmpdir } from "os";
21
+ import { randomBytes } from "crypto";
22
+ function gettempdir() {
23
+ return tmpdir();
24
+ }
25
+ function mktemp(suffix = "", prefix = "tmp", dir) {
26
+ const tempDir = dir ?? gettempdir();
27
+ const randomPart = randomBytes(8).toString("hex");
28
+ return join(tempDir, `${prefix}${randomPart}${suffix}`);
29
+ }
30
+ async function mkstemp(suffix = "", prefix = "tmp", dir, _text = false) {
31
+ const tempDir = dir ?? gettempdir();
32
+ const randomPart = randomBytes(8).toString("hex");
33
+ const path = join(tempDir, `${prefix}${randomPart}${suffix}`);
34
+ const handle = await open(path, "w+", 384);
35
+ return [handle, path];
36
+ }
37
+ async function mkdtemp(suffix = "", prefix = "tmp", dir) {
38
+ const tempDir = dir ?? gettempdir();
39
+ const randomPart = randomBytes(8).toString("hex");
40
+ const path = join(tempDir, `${prefix}${randomPart}${suffix}`);
41
+ await mkdir(path, { mode: 448 });
42
+ return path;
43
+ }
44
+ var NamedTemporaryFile = class _NamedTemporaryFile {
45
+ /** The file handle */
46
+ handle;
47
+ /** The file path */
48
+ name;
49
+ /** Whether to delete the file on close */
50
+ deleteOnClose;
51
+ _closed = false;
52
+ constructor(handle, name, deleteOnClose) {
53
+ this.handle = handle;
54
+ this.name = name;
55
+ this.deleteOnClose = deleteOnClose;
56
+ }
57
+ /**
58
+ * Create a new NamedTemporaryFile.
59
+ */
60
+ static async create(options) {
61
+ const suffix = options?.suffix ?? "";
62
+ const prefix = options?.prefix ?? "tmp";
63
+ const dir = options?.dir;
64
+ const deleteOnClose = options?.delete ?? true;
65
+ const [handle, path] = await mkstemp(suffix, prefix, dir);
66
+ return new _NamedTemporaryFile(handle, path, deleteOnClose);
67
+ }
68
+ /**
69
+ * Write data to the file.
70
+ */
71
+ async write(data) {
72
+ const result = await this.handle.write(typeof data === "string" ? Buffer.from(data) : data);
73
+ return result.bytesWritten;
74
+ }
75
+ /**
76
+ * Read data from the file.
77
+ */
78
+ async read(size) {
79
+ const fileSize = size ?? (await this.handle.stat()).size;
80
+ const buffer = Buffer.alloc(fileSize);
81
+ await this.handle.read(buffer, 0, buffer.length, 0);
82
+ return buffer;
83
+ }
84
+ /**
85
+ * Seek to a position in the file.
86
+ */
87
+ seek(_offset, _whence = 0) {
88
+ }
89
+ /**
90
+ * Flush the file buffer.
91
+ */
92
+ async flush() {
93
+ await this.handle.sync();
94
+ }
95
+ /**
96
+ * Close the file.
97
+ */
98
+ async close() {
99
+ if (!this._closed) {
100
+ await this.handle.close();
101
+ if (this.deleteOnClose) {
102
+ try {
103
+ await unlink(this.name);
104
+ } catch {
105
+ }
106
+ }
107
+ this._closed = true;
108
+ }
109
+ }
110
+ /**
111
+ * Check if the file is closed.
112
+ */
113
+ get closed() {
114
+ return this._closed;
115
+ }
116
+ };
117
+ var TemporaryDirectory = class _TemporaryDirectory {
118
+ /** The directory path */
119
+ name;
120
+ _cleaned = false;
121
+ constructor(name) {
122
+ this.name = name;
123
+ }
124
+ /**
125
+ * Create a new TemporaryDirectory.
126
+ */
127
+ static async create(options) {
128
+ const name = await mkdtemp(options?.suffix, options?.prefix, options?.dir);
129
+ return new _TemporaryDirectory(name);
130
+ }
131
+ /**
132
+ * Remove the temporary directory and its contents.
133
+ */
134
+ async cleanup() {
135
+ if (!this._cleaned) {
136
+ try {
137
+ await rm(this.name, { recursive: true, force: true });
138
+ } catch {
139
+ }
140
+ this._cleaned = true;
141
+ }
142
+ }
143
+ };
144
+ async function namedTemporaryFile(options) {
145
+ return NamedTemporaryFile.create(options);
146
+ }
147
+ async function temporaryDirectory(options) {
148
+ return TemporaryDirectory.create(options);
149
+ }
150
+ function gettempprefix() {
151
+ return "tmp";
152
+ }
153
+
154
+ export {
155
+ gettempdir,
156
+ mktemp,
157
+ mkstemp,
158
+ mkdtemp,
159
+ NamedTemporaryFile,
160
+ TemporaryDirectory,
161
+ namedTemporaryFile,
162
+ temporaryDirectory,
163
+ gettempprefix,
164
+ tempfile_node_exports
165
+ };
@@ -0,0 +1,82 @@
1
+ import {
2
+ __export
3
+ } from "./chunk-MLKGABMK.js";
4
+
5
+ // src/shutil.browser.ts
6
+ var shutil_browser_exports = {};
7
+ __export(shutil_browser_exports, {
8
+ copy: () => copy,
9
+ copy2: () => copy2,
10
+ copyFile: () => copyFile,
11
+ copyFileObj: () => copyFileObj,
12
+ copyMode: () => copyMode,
13
+ copyStat: () => copyStat,
14
+ copytree: () => copytree,
15
+ diskUsage: () => diskUsage,
16
+ getTerminalSize: () => getTerminalSize,
17
+ makeArchive: () => makeArchive,
18
+ move: () => move,
19
+ rmtree: () => rmtree,
20
+ unpackArchive: () => unpackArchive,
21
+ which: () => which
22
+ });
23
+ async function copy(_src, _dst) {
24
+ throw new Error("shutil.copy is not supported in browser environment");
25
+ }
26
+ async function copy2(_src, _dst) {
27
+ throw new Error("shutil.copy2 is not supported in browser environment");
28
+ }
29
+ async function copytree(_src, _dst, _options) {
30
+ throw new Error("shutil.copytree is not supported in browser environment");
31
+ }
32
+ async function move(_src, _dst) {
33
+ throw new Error("shutil.move is not supported in browser environment");
34
+ }
35
+ async function rmtree(_path, _ignoreErrors = false) {
36
+ throw new Error("shutil.rmtree is not supported in browser environment");
37
+ }
38
+ async function which(_cmd, _mode, _path) {
39
+ return null;
40
+ }
41
+ async function diskUsage(_path) {
42
+ throw new Error("shutil.diskUsage is not supported in browser environment");
43
+ }
44
+ async function copyMode(_src, _dst) {
45
+ }
46
+ async function copyStat(_src, _dst) {
47
+ }
48
+ async function copyFile(_src, _dst) {
49
+ throw new Error("shutil.copyFile is not supported in browser environment");
50
+ }
51
+ async function copyFileObj(_fsrc, _fdst, _length) {
52
+ throw new Error("shutil.copyFileObj is not supported in browser environment");
53
+ }
54
+ function getTerminalSize(fallback) {
55
+ const [columns, lines] = fallback ?? [80, 24];
56
+ return { columns, lines };
57
+ }
58
+ function makeArchive(_baseName, _format, _rootDir) {
59
+ throw new Error("makeArchive is not supported in browser environment");
60
+ }
61
+ function unpackArchive(_filename, _extractDir) {
62
+ throw new Error("unpackArchive is not supported in browser environment");
63
+ }
64
+
65
+ export {
66
+ copy,
67
+ copy2,
68
+ copytree,
69
+ move,
70
+ rmtree,
71
+ which,
72
+ diskUsage,
73
+ copyMode,
74
+ copyStat,
75
+ copyFile,
76
+ copyFileObj,
77
+ getTerminalSize,
78
+ makeArchive,
79
+ unpackArchive,
80
+ shutil_browser_exports
81
+ };
82
+ /* v8 ignore start -- browser stubs @preserve */