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