rsbuild-plugin-arethetypeswrong 0.1.1 → 0.3.0

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.
@@ -0,0 +1,856 @@
1
+ import promises from "node:fs/promises";
2
+ import node_path, { delimiter, dirname, normalize, resolve } from "node:path";
3
+ import node_process, { cwd as external_node_process_cwd } from "node:process";
4
+ import { createRequire } from "node:module";
5
+ import { spawn } from "node:child_process";
6
+ import { PassThrough } from "node:stream";
7
+ import node_readline from "node:readline";
8
+ const constants_AGENTS = [
9
+ "npm",
10
+ "yarn",
11
+ "yarn@berry",
12
+ "pnpm",
13
+ "pnpm@6",
14
+ "bun",
15
+ "deno"
16
+ ];
17
+ const LOCKS = {
18
+ "bun.lock": "bun",
19
+ "bun.lockb": "bun",
20
+ "deno.lock": "deno",
21
+ "pnpm-lock.yaml": "pnpm",
22
+ "pnpm-workspace.yaml": "pnpm",
23
+ "yarn.lock": "yarn",
24
+ "package-lock.json": "npm",
25
+ "npm-shrinkwrap.json": "npm"
26
+ };
27
+ const INSTALL_METADATA = {
28
+ "node_modules/.deno/": "deno",
29
+ "node_modules/.pnpm/": "pnpm",
30
+ "node_modules/.yarn-state.yml": "yarn",
31
+ "node_modules/.yarn_integrity": "yarn",
32
+ "node_modules/.package-lock.json": "npm",
33
+ ".pnp.cjs": "yarn",
34
+ ".pnp.js": "yarn",
35
+ "bun.lock": "bun",
36
+ "bun.lockb": "bun"
37
+ };
38
+ async function pathExists(path2, type) {
39
+ try {
40
+ const stat = await promises.stat(path2);
41
+ return "file" === type ? stat.isFile() : stat.isDirectory();
42
+ } catch {
43
+ return false;
44
+ }
45
+ }
46
+ function* lookup(cwd = node_process.cwd()) {
47
+ let directory = node_path.resolve(cwd);
48
+ const { root } = node_path.parse(directory);
49
+ while(directory && directory !== root){
50
+ yield directory;
51
+ directory = node_path.dirname(directory);
52
+ }
53
+ }
54
+ async function parsePackageJson(filepath, options) {
55
+ if (!filepath || !await pathExists(filepath, "file")) return null;
56
+ return await handlePackageManager(filepath, options);
57
+ }
58
+ async function detect(options = {}) {
59
+ const { cwd, strategies = [
60
+ "lockfile",
61
+ "packageManager-field",
62
+ "devEngines-field"
63
+ ] } = options;
64
+ let stopDir;
65
+ if ("string" == typeof options.stopDir) {
66
+ const resolved = node_path.resolve(options.stopDir);
67
+ stopDir = (dir)=>dir === resolved;
68
+ } else stopDir = options.stopDir;
69
+ for (const directory of lookup(cwd)){
70
+ for (const strategy of strategies)switch(strategy){
71
+ case "lockfile":
72
+ for (const lock of Object.keys(LOCKS))if (await pathExists(node_path.join(directory, lock), "file")) {
73
+ const name = LOCKS[lock];
74
+ const result = await parsePackageJson(node_path.join(directory, "package.json"), options);
75
+ if (result) return result;
76
+ return {
77
+ name,
78
+ agent: name
79
+ };
80
+ }
81
+ break;
82
+ case "packageManager-field":
83
+ case "devEngines-field":
84
+ {
85
+ const result = await parsePackageJson(node_path.join(directory, "package.json"), options);
86
+ if (result) return result;
87
+ break;
88
+ }
89
+ case "install-metadata":
90
+ for (const metadata of Object.keys(INSTALL_METADATA)){
91
+ const fileOrDir = metadata.endsWith("/") ? "dir" : "file";
92
+ if (await pathExists(node_path.join(directory, metadata), fileOrDir)) {
93
+ const name = INSTALL_METADATA[metadata];
94
+ const agent = "yarn" === name ? isMetadataYarnClassic(metadata) ? "yarn" : "yarn@berry" : name;
95
+ return {
96
+ name,
97
+ agent
98
+ };
99
+ }
100
+ }
101
+ break;
102
+ }
103
+ if (stopDir?.(directory)) break;
104
+ }
105
+ return null;
106
+ }
107
+ function getNameAndVer(pkg) {
108
+ const handelVer = (version)=>version?.match(/\d+(\.\d+){0,2}/)?.[0] ?? version;
109
+ if ("string" == typeof pkg.packageManager) {
110
+ const [name, ver] = pkg.packageManager.replace(/^\^/, "").split("@");
111
+ return {
112
+ name,
113
+ ver: handelVer(ver)
114
+ };
115
+ }
116
+ if ("string" == typeof pkg.devEngines?.packageManager?.name) return {
117
+ name: pkg.devEngines.packageManager.name,
118
+ ver: handelVer(pkg.devEngines.packageManager.version)
119
+ };
120
+ }
121
+ async function handlePackageManager(filepath, options) {
122
+ try {
123
+ const content = await promises.readFile(filepath, "utf8");
124
+ const pkg = options.packageJsonParser ? await options.packageJsonParser(content, filepath) : JSON.parse(content);
125
+ let agent;
126
+ const nameAndVer = getNameAndVer(pkg);
127
+ if (nameAndVer) {
128
+ const name = nameAndVer.name;
129
+ const ver = nameAndVer.ver;
130
+ let version = ver;
131
+ if ("yarn" === name && ver && Number.parseInt(ver) > 1) {
132
+ agent = "yarn@berry";
133
+ version = "berry";
134
+ return {
135
+ name,
136
+ agent,
137
+ version
138
+ };
139
+ }
140
+ if ("pnpm" === name && ver && Number.parseInt(ver) < 7) {
141
+ agent = "pnpm@6";
142
+ return {
143
+ name,
144
+ agent,
145
+ version
146
+ };
147
+ }
148
+ if (!constants_AGENTS.includes(name)) return options.onUnknown?.(pkg.packageManager) ?? null;
149
+ agent = name;
150
+ return {
151
+ name,
152
+ agent,
153
+ version
154
+ };
155
+ }
156
+ } catch {}
157
+ return null;
158
+ }
159
+ function isMetadataYarnClassic(metadataPath) {
160
+ return metadataPath.endsWith(".yarn_integrity");
161
+ }
162
+ var main_l = (e, t)=>()=>(t || e((t = {
163
+ exports: {}
164
+ }).exports, t), t.exports);
165
+ var main_u = /* @__PURE__ */ createRequire(import.meta.url);
166
+ const main_d = /^path$/i;
167
+ const main_f = {
168
+ key: "PATH",
169
+ value: ""
170
+ };
171
+ function p(e) {
172
+ for(const t in e){
173
+ if (!Object.prototype.hasOwnProperty.call(e, t) || !main_d.test(t)) continue;
174
+ const n = e[t];
175
+ if (!n) break;
176
+ return {
177
+ key: t,
178
+ value: n
179
+ };
180
+ }
181
+ return main_f;
182
+ }
183
+ function m(e, t) {
184
+ const i = t.value.split(delimiter);
185
+ const o = [];
186
+ let s = e;
187
+ let c;
188
+ do {
189
+ o.push(resolve(s, "node_modules", ".bin"));
190
+ c = s;
191
+ s = dirname(s);
192
+ }while (s !== c);
193
+ const l = o.concat(i).join(delimiter);
194
+ return {
195
+ key: t.key,
196
+ value: l
197
+ };
198
+ }
199
+ function h(e, t) {
200
+ const n = {
201
+ ...process.env,
202
+ ...t
203
+ };
204
+ const r = m(e, p(n));
205
+ n[r.key] = r.value;
206
+ return n;
207
+ }
208
+ const g = (e)=>{
209
+ let t = e.length;
210
+ const n = new PassThrough();
211
+ const r = ()=>{
212
+ if (0 === --t) n.emit("end");
213
+ };
214
+ for (const t of e){
215
+ t.pipe(n, {
216
+ end: false
217
+ });
218
+ t.on("end", r);
219
+ }
220
+ return n;
221
+ };
222
+ var _ = /* @__PURE__ */ main_l((e, t)=>{
223
+ t.exports = a;
224
+ a.sync = o;
225
+ var n = main_u("fs");
226
+ function r(e, t) {
227
+ var n = void 0 !== t.pathExt ? t.pathExt : process.env.PATHEXT;
228
+ if (!n) return true;
229
+ n = n.split(";");
230
+ if (-1 !== n.indexOf("")) return true;
231
+ for(var r = 0; r < n.length; r++){
232
+ var i = n[r].toLowerCase();
233
+ if (i && e.substr(-i.length).toLowerCase() === i) return true;
234
+ }
235
+ return false;
236
+ }
237
+ function i(e, t, n) {
238
+ if (!e.isSymbolicLink() && !e.isFile()) return false;
239
+ return r(t, n);
240
+ }
241
+ function a(e, t, r) {
242
+ n.stat(e, function(n, a) {
243
+ r(n, n ? false : i(a, e, t));
244
+ });
245
+ }
246
+ function o(e, t) {
247
+ return i(n.statSync(e), e, t);
248
+ }
249
+ });
250
+ var v = /* @__PURE__ */ main_l((e, t)=>{
251
+ t.exports = r;
252
+ r.sync = i;
253
+ var n = main_u("fs");
254
+ function r(e, t, r) {
255
+ n.stat(e, function(e, n) {
256
+ r(e, e ? false : a(n, t));
257
+ });
258
+ }
259
+ function i(e, t) {
260
+ return a(n.statSync(e), t);
261
+ }
262
+ function a(e, t) {
263
+ return e.isFile() && o(e, t);
264
+ }
265
+ function o(e, t) {
266
+ var n = e.mode;
267
+ var r = e.uid;
268
+ var i = e.gid;
269
+ var a = void 0 !== t.uid ? t.uid : process.getuid && process.getuid();
270
+ var o = void 0 !== t.gid ? t.gid : process.getgid && process.getgid();
271
+ var s = parseInt("100", 8);
272
+ var c = parseInt("010", 8);
273
+ var l = parseInt("001", 8);
274
+ var u = s | c;
275
+ return n & l || n & c && i === o || n & s && r === a || n & u && 0 === a;
276
+ }
277
+ });
278
+ var y = /* @__PURE__ */ main_l((e, t)=>{
279
+ main_u("fs");
280
+ var n;
281
+ n = "win32" === process.platform || global.TESTING_WINDOWS ? _() : v();
282
+ t.exports = r;
283
+ r.sync = i;
284
+ function r(e, t, i) {
285
+ if ("function" == typeof t) {
286
+ i = t;
287
+ t = {};
288
+ }
289
+ if (!i) {
290
+ if ("function" != typeof Promise) throw new TypeError("callback not provided");
291
+ return new Promise(function(n, i) {
292
+ r(e, t || {}, function(e, t) {
293
+ if (e) i(e);
294
+ else n(t);
295
+ });
296
+ });
297
+ }
298
+ n(e, t || {}, function(e, n) {
299
+ if (e) {
300
+ if ("EACCES" === e.code || t && t.ignoreErrors) {
301
+ e = null;
302
+ n = false;
303
+ }
304
+ }
305
+ i(e, n);
306
+ });
307
+ }
308
+ function i(e, t) {
309
+ try {
310
+ return n.sync(e, t || {});
311
+ } catch (e) {
312
+ if (t && t.ignoreErrors || "EACCES" === e.code) return false;
313
+ throw e;
314
+ }
315
+ }
316
+ });
317
+ var b = /* @__PURE__ */ main_l((e, t)=>{
318
+ const n = "win32" === process.platform || "cygwin" === process.env.OSTYPE || "msys" === process.env.OSTYPE;
319
+ const r = main_u("path");
320
+ const i = n ? ";" : ":";
321
+ const a = y();
322
+ const o = (e)=>Object.assign(/* @__PURE__ */ new Error(`not found: ${e}`), {
323
+ code: "ENOENT"
324
+ });
325
+ const s = (e, t)=>{
326
+ const r = t.colon || i;
327
+ const a = e.match(/\//) || n && e.match(/\\/) ? [
328
+ ""
329
+ ] : [
330
+ ...n ? [
331
+ process.cwd()
332
+ ] : [],
333
+ ...(t.path || process.env.PATH || "").split(r)
334
+ ];
335
+ const o = n ? t.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "";
336
+ const s = n ? o.split(r) : [
337
+ ""
338
+ ];
339
+ if (n) {
340
+ if (-1 !== e.indexOf(".") && "" !== s[0]) s.unshift("");
341
+ }
342
+ return {
343
+ pathEnv: a,
344
+ pathExt: s,
345
+ pathExtExe: o
346
+ };
347
+ };
348
+ const c = (e, t, n)=>{
349
+ if ("function" == typeof t) {
350
+ n = t;
351
+ t = {};
352
+ }
353
+ if (!t) t = {};
354
+ const { pathEnv: i, pathExt: c, pathExtExe: l } = s(e, t);
355
+ const u = [];
356
+ const d = (n)=>new Promise((a, s)=>{
357
+ if (n === i.length) return t.all && u.length ? a(u) : s(o(e));
358
+ const c = i[n];
359
+ const l = /^".*"$/.test(c) ? c.slice(1, -1) : c;
360
+ const d = r.join(l, e);
361
+ a(f(!l && /^\.[\\\/]/.test(e) ? e.slice(0, 2) + d : d, n, 0));
362
+ });
363
+ const f = (e, n, r)=>new Promise((i, o)=>{
364
+ if (r === c.length) return i(d(n + 1));
365
+ const s = c[r];
366
+ a(e + s, {
367
+ pathExt: l
368
+ }, (a, o)=>{
369
+ if (!a && o) if (!t.all) return i(e + s);
370
+ else u.push(e + s);
371
+ return i(f(e, n, r + 1));
372
+ });
373
+ });
374
+ return n ? d(0).then((e)=>n(null, e), n) : d(0);
375
+ };
376
+ const l = (e, t)=>{
377
+ t = t || {};
378
+ const { pathEnv: n, pathExt: i, pathExtExe: c } = s(e, t);
379
+ const l = [];
380
+ for(let o = 0; o < n.length; o++){
381
+ const s = n[o];
382
+ const u = /^".*"$/.test(s) ? s.slice(1, -1) : s;
383
+ const d = r.join(u, e);
384
+ const f = !u && /^\.[\\\/]/.test(e) ? e.slice(0, 2) + d : d;
385
+ for(let e = 0; e < i.length; e++){
386
+ const n = f + i[e];
387
+ try {
388
+ if (a.sync(n, {
389
+ pathExt: c
390
+ })) if (!t.all) return n;
391
+ else l.push(n);
392
+ } catch (e) {}
393
+ }
394
+ }
395
+ if (t.all && l.length) return l;
396
+ if (t.nothrow) return null;
397
+ throw o(e);
398
+ };
399
+ t.exports = c;
400
+ c.sync = l;
401
+ });
402
+ var x = /* @__PURE__ */ main_l((e, t)=>{
403
+ const n = (e = {})=>{
404
+ const t = e.env || process.env;
405
+ if ("win32" !== (e.platform || process.platform)) return "PATH";
406
+ return Object.keys(t).reverse().find((e)=>"PATH" === e.toUpperCase()) || "Path";
407
+ };
408
+ t.exports = n;
409
+ t.exports.default = n;
410
+ });
411
+ var S = /* @__PURE__ */ main_l((e, t)=>{
412
+ const n = main_u("path");
413
+ const r = b();
414
+ const i = x();
415
+ function a(e, t) {
416
+ const a = e.options.env || process.env;
417
+ const o = process.cwd();
418
+ const s = null != e.options.cwd;
419
+ const c = s && void 0 !== process.chdir && !process.chdir.disabled;
420
+ if (c) try {
421
+ process.chdir(e.options.cwd);
422
+ } catch (e) {}
423
+ let l;
424
+ try {
425
+ l = r.sync(e.command, {
426
+ path: a[i({
427
+ env: a
428
+ })],
429
+ pathExt: t ? n.delimiter : void 0
430
+ });
431
+ } catch (e) {} finally{
432
+ if (c) process.chdir(o);
433
+ }
434
+ if (l) l = n.resolve(s ? e.options.cwd : "", l);
435
+ return l;
436
+ }
437
+ function o(e) {
438
+ return a(e) || a(e, true);
439
+ }
440
+ t.exports = o;
441
+ });
442
+ var C = /* @__PURE__ */ main_l((e, t)=>{
443
+ const n = /([()\][%!^"`<>&|;, *?])/g;
444
+ function r(e) {
445
+ e = e.replace(n, "^$1");
446
+ return e;
447
+ }
448
+ function i(e, t) {
449
+ e = `${e}`;
450
+ e = e.replace(/(?=(\\+?)?)\1"/g, "$1$1\\\"");
451
+ e = e.replace(/(?=(\\+?)?)\1$/, "$1$1");
452
+ e = `"${e}"`;
453
+ e = e.replace(n, "^$1");
454
+ if (t) e = e.replace(n, "^$1");
455
+ return e;
456
+ }
457
+ t.exports.command = r;
458
+ t.exports.argument = i;
459
+ });
460
+ var w = /* @__PURE__ */ main_l((e, t)=>{
461
+ t.exports = /^#!(.*)/;
462
+ });
463
+ var T = /* @__PURE__ */ main_l((e, t)=>{
464
+ const n = w();
465
+ t.exports = (e = "")=>{
466
+ const t = e.match(n);
467
+ if (!t) return null;
468
+ const [r, i] = t[0].replace(/#! ?/, "").split(" ");
469
+ const a = r.split("/").pop();
470
+ if ("env" === a) return i;
471
+ return i ? `${a} ${i}` : a;
472
+ };
473
+ });
474
+ var E = /* @__PURE__ */ main_l((e, t)=>{
475
+ const n = main_u("fs");
476
+ const r = T();
477
+ function i(e) {
478
+ const t = 150;
479
+ const i = Buffer.alloc(t);
480
+ let a;
481
+ try {
482
+ a = n.openSync(e, "r");
483
+ n.readSync(a, i, 0, t, 0);
484
+ n.closeSync(a);
485
+ } catch (e) {}
486
+ return r(i.toString());
487
+ }
488
+ t.exports = i;
489
+ });
490
+ var D = /* @__PURE__ */ main_l((e, t)=>{
491
+ const n = main_u("path");
492
+ const r = S();
493
+ const i = C();
494
+ const a = E();
495
+ const o = "win32" === process.platform;
496
+ const s = /\.(?:com|exe)$/i;
497
+ const c = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
498
+ function l(e) {
499
+ e.file = r(e);
500
+ const t = e.file && a(e.file);
501
+ if (t) {
502
+ e.args.unshift(e.file);
503
+ e.command = t;
504
+ return r(e);
505
+ }
506
+ return e.file;
507
+ }
508
+ function d(e) {
509
+ if (!o) return e;
510
+ const t = l(e);
511
+ const r = !s.test(t);
512
+ if (e.options.forceShell || r) {
513
+ const r = c.test(t);
514
+ e.command = n.normalize(e.command);
515
+ e.command = i.command(e.command);
516
+ e.args = e.args.map((e)=>i.argument(e, r));
517
+ e.args = [
518
+ "/d",
519
+ "/s",
520
+ "/c",
521
+ `"${[
522
+ e.command
523
+ ].concat(e.args).join(" ")}"`
524
+ ];
525
+ e.command = process.env.comspec || "cmd.exe";
526
+ e.options.windowsVerbatimArguments = true;
527
+ }
528
+ return e;
529
+ }
530
+ function f(e, t, n) {
531
+ if (t && !Array.isArray(t)) {
532
+ n = t;
533
+ t = null;
534
+ }
535
+ t = t ? t.slice(0) : [];
536
+ n = Object.assign({}, n);
537
+ const r = {
538
+ command: e,
539
+ args: t,
540
+ options: n,
541
+ file: void 0,
542
+ original: {
543
+ command: e,
544
+ args: t
545
+ }
546
+ };
547
+ return n.shell ? r : d(r);
548
+ }
549
+ t.exports = f;
550
+ });
551
+ var O = /* @__PURE__ */ main_l((e, t)=>{
552
+ const n = "win32" === process.platform;
553
+ function r(e, t) {
554
+ return Object.assign(/* @__PURE__ */ new Error(`${t} ${e.command} ENOENT`), {
555
+ code: "ENOENT",
556
+ errno: "ENOENT",
557
+ syscall: `${t} ${e.command}`,
558
+ path: e.command,
559
+ spawnargs: e.args
560
+ });
561
+ }
562
+ function i(e, t) {
563
+ if (!n) return;
564
+ const r = e.emit;
565
+ e.emit = function(n, i) {
566
+ if ("exit" === n) {
567
+ const n = a(i, t);
568
+ if (n) return r.call(e, "error", n);
569
+ }
570
+ return r.apply(e, arguments);
571
+ };
572
+ }
573
+ function a(e, t) {
574
+ if (n && 1 === e && !t.file) return r(t.original, "spawn");
575
+ return null;
576
+ }
577
+ function o(e, t) {
578
+ if (n && 1 === e && !t.file) return r(t.original, "spawnSync");
579
+ return null;
580
+ }
581
+ t.exports = {
582
+ hookChildProcess: i,
583
+ verifyENOENT: a,
584
+ verifyENOENTSync: o,
585
+ notFoundError: r
586
+ };
587
+ });
588
+ var k = /* @__PURE__ */ main_l((e, t)=>{
589
+ const n = main_u("child_process");
590
+ const r = D();
591
+ const i = O();
592
+ function a(e, t, a) {
593
+ const o = r(e, t, a);
594
+ const s = n.spawn(o.command, o.args, o.options);
595
+ i.hookChildProcess(s, o);
596
+ return s;
597
+ }
598
+ function o(e, t, a) {
599
+ const o = r(e, t, a);
600
+ const s = n.spawnSync(o.command, o.args, o.options);
601
+ s.error = s.error || i.verifyENOENTSync(s.status, o);
602
+ return s;
603
+ }
604
+ t.exports = a;
605
+ t.exports.spawn = a;
606
+ t.exports.sync = o;
607
+ t.exports._parse = r;
608
+ t.exports._enoent = i;
609
+ });
610
+ var A = k();
611
+ var j = class extends Error {
612
+ result;
613
+ output;
614
+ get exitCode() {
615
+ if (null !== this.result.exitCode) return this.result.exitCode;
616
+ }
617
+ constructor(e, t){
618
+ super(`Process exited with non-zero status (${e.exitCode})`);
619
+ this.result = e;
620
+ this.output = t;
621
+ }
622
+ };
623
+ const M = {
624
+ timeout: void 0,
625
+ persist: false
626
+ };
627
+ const N = {
628
+ windowsHide: true
629
+ };
630
+ function P(e, t) {
631
+ return {
632
+ command: normalize(e),
633
+ args: t ?? []
634
+ };
635
+ }
636
+ function F(e) {
637
+ const t = new AbortController();
638
+ for (const n of e){
639
+ if (n.aborted) {
640
+ t.abort();
641
+ return n;
642
+ }
643
+ const e = ()=>{
644
+ t.abort(n.reason);
645
+ };
646
+ n.addEventListener("abort", e, {
647
+ signal: t.signal
648
+ });
649
+ }
650
+ return t.signal;
651
+ }
652
+ async function I(e) {
653
+ let t = "";
654
+ for await (const n of e)t += n.toString();
655
+ return t;
656
+ }
657
+ var L = class {
658
+ _process;
659
+ _aborted = false;
660
+ _options;
661
+ _command;
662
+ _args;
663
+ _resolveClose;
664
+ _processClosed;
665
+ _thrownError;
666
+ get process() {
667
+ return this._process;
668
+ }
669
+ get pid() {
670
+ return this._process?.pid;
671
+ }
672
+ get exitCode() {
673
+ if (this._process && null !== this._process.exitCode) return this._process.exitCode;
674
+ }
675
+ constructor(e, t, n){
676
+ this._options = {
677
+ ...M,
678
+ ...n
679
+ };
680
+ this._command = e;
681
+ this._args = t ?? [];
682
+ this._processClosed = new Promise((e)=>{
683
+ this._resolveClose = e;
684
+ });
685
+ }
686
+ kill(e) {
687
+ return this._process?.kill(e) === true;
688
+ }
689
+ get aborted() {
690
+ return this._aborted;
691
+ }
692
+ get killed() {
693
+ return this._process?.killed === true;
694
+ }
695
+ pipe(e, t, n) {
696
+ return z(e, t, {
697
+ ...n,
698
+ stdin: this
699
+ });
700
+ }
701
+ async *[Symbol.asyncIterator]() {
702
+ const e = this._process;
703
+ if (!e) return;
704
+ const t = [];
705
+ if (this._streamErr) t.push(this._streamErr);
706
+ if (this._streamOut) t.push(this._streamOut);
707
+ const n = g(t);
708
+ const r = node_readline.createInterface({
709
+ input: n
710
+ });
711
+ for await (const e of r)yield e.toString();
712
+ await this._processClosed;
713
+ e.removeAllListeners();
714
+ if (this._thrownError) throw this._thrownError;
715
+ if (this._options?.throwOnError && 0 !== this.exitCode && void 0 !== this.exitCode) throw new j(this);
716
+ }
717
+ async _waitForOutput() {
718
+ const e = this._process;
719
+ if (!e) throw new Error("No process was started");
720
+ const [t, n] = await Promise.all([
721
+ this._streamOut ? I(this._streamOut) : "",
722
+ this._streamErr ? I(this._streamErr) : ""
723
+ ]);
724
+ await this._processClosed;
725
+ if (this._options?.stdin) await this._options.stdin;
726
+ e.removeAllListeners();
727
+ if (this._thrownError) throw this._thrownError;
728
+ const r = {
729
+ stderr: n,
730
+ stdout: t,
731
+ exitCode: this.exitCode
732
+ };
733
+ if (this._options.throwOnError && 0 !== this.exitCode && void 0 !== this.exitCode) throw new j(this, r);
734
+ return r;
735
+ }
736
+ then(e, t) {
737
+ return this._waitForOutput().then(e, t);
738
+ }
739
+ _streamOut;
740
+ _streamErr;
741
+ spawn() {
742
+ const e = external_node_process_cwd();
743
+ const n = this._options;
744
+ const r = {
745
+ ...N,
746
+ ...n.nodeOptions
747
+ };
748
+ const i = [];
749
+ this._resetState();
750
+ if (void 0 !== n.timeout) i.push(AbortSignal.timeout(n.timeout));
751
+ if (void 0 !== n.signal) i.push(n.signal);
752
+ if (true === n.persist) r.detached = true;
753
+ if (i.length > 0) r.signal = F(i);
754
+ r.env = h(e, r.env);
755
+ const { command: a, args: s } = P(this._command, this._args);
756
+ const c = (0, A._parse)(a, s, r);
757
+ const l = spawn(c.command, c.args, c.options);
758
+ if (l.stderr) this._streamErr = l.stderr;
759
+ if (l.stdout) this._streamOut = l.stdout;
760
+ this._process = l;
761
+ l.once("error", this._onError);
762
+ l.once("close", this._onClose);
763
+ if (void 0 !== n.stdin && l.stdin && n.stdin.process) {
764
+ const { stdout: e } = n.stdin.process;
765
+ if (e) e.pipe(l.stdin);
766
+ }
767
+ }
768
+ _resetState() {
769
+ this._aborted = false;
770
+ this._processClosed = new Promise((e)=>{
771
+ this._resolveClose = e;
772
+ });
773
+ this._thrownError = void 0;
774
+ }
775
+ _onError = (e)=>{
776
+ if ("AbortError" === e.name && (!(e.cause instanceof Error) || "TimeoutError" !== e.cause.name)) {
777
+ this._aborted = true;
778
+ return;
779
+ }
780
+ this._thrownError = e;
781
+ };
782
+ _onClose = ()=>{
783
+ if (this._resolveClose) this._resolveClose();
784
+ };
785
+ };
786
+ const R = (e, t, n)=>{
787
+ const r = new L(e, t, n);
788
+ r.spawn();
789
+ return r;
790
+ };
791
+ const z = R;
792
+ async function createTarball(root, pkg) {
793
+ const tarballPath = node_path.join(root, `${normalizeNpmPackageName(pkg.name)}-${pkg.version}.tgz`);
794
+ const detectResult = await detect({
795
+ cwd: root
796
+ });
797
+ const [command, args] = function() {
798
+ switch(detectResult?.agent){
799
+ case "yarn":
800
+ return [
801
+ "yarn",
802
+ [
803
+ "pack",
804
+ "--filename",
805
+ tarballPath
806
+ ]
807
+ ];
808
+ case "yarn@berry":
809
+ return [
810
+ "yarn",
811
+ [
812
+ "pack",
813
+ "--out",
814
+ tarballPath
815
+ ]
816
+ ];
817
+ case "pnpm":
818
+ case "pnpm@6":
819
+ return [
820
+ "pnpm",
821
+ [
822
+ "pack"
823
+ ]
824
+ ];
825
+ case "npm":
826
+ case "bun":
827
+ case "deno":
828
+ case void 0:
829
+ default:
830
+ return [
831
+ "npm",
832
+ [
833
+ "pack"
834
+ ]
835
+ ];
836
+ }
837
+ }();
838
+ await R(command, args, {
839
+ nodeOptions: {
840
+ cwd: root
841
+ },
842
+ throwOnError: true
843
+ });
844
+ return {
845
+ path: tarballPath,
846
+ async [Symbol.asyncDispose] () {
847
+ try {
848
+ await promises.unlink(tarballPath);
849
+ } catch {}
850
+ }
851
+ };
852
+ }
853
+ function normalizeNpmPackageName(name) {
854
+ return name.replaceAll("@", "").replaceAll("/", "-");
855
+ }
856
+ export { createTarball };