-
Notifications
You must be signed in to change notification settings - Fork 28.3k
/
corepack.js
executable file
Β·17161 lines (14985 loc) Β· 591 KB
/
corepack.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env node
/* eslint-disable */
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ "../../../.yarn/berry/cache/@zkochan-cmd-shim-npm-5.3.0-8f73631a81-9.zip/node_modules/@zkochan/cmd-shim/index.js":
/*!***********************************************************************************************************************!*\
!*** ../../../.yarn/berry/cache/@zkochan-cmd-shim-npm-5.3.0-8f73631a81-9.zip/node_modules/@zkochan/cmd-shim/index.js ***!
\***********************************************************************************************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
"use strict";
cmdShim.ifExists = cmdShimIfExists;
const util_1 = __webpack_require__(/*! util */ "util");
const path = __webpack_require__(/*! path */ "path");
const isWindows = __webpack_require__(/*! is-windows */ "../../../.yarn/berry/cache/is-windows-npm-1.0.2-898cd6f3d7-9.zip/node_modules/is-windows/index.js");
const CMD_EXTENSION = __webpack_require__(/*! cmd-extension */ "../../../.yarn/berry/cache/cmd-extension-npm-1.0.2-11aa204c4b-9.zip/node_modules/cmd-extension/index.js");
const shebangExpr = /^#!\s*(?:\/usr\/bin\/env)?\s*([^ \t]+)(.*)$/;
const DEFAULT_OPTIONS = {
// Create PowerShell file by default if the option hasn't been specified
createPwshFile: true,
createCmdFile: isWindows(),
fs: __webpack_require__(/*! fs */ "fs")
};
/**
* Map from extensions of files that this module is frequently used for to their runtime.
* @type {Map<string, string>}
*/
const extensionToProgramMap = new Map([
['.js', 'node'],
['.cjs', 'node'],
['.mjs', 'node'],
['.cmd', 'cmd'],
['.bat', 'cmd'],
['.ps1', 'pwsh'],
['.sh', 'sh']
]);
function ingestOptions(opts) {
const opts_ = { ...DEFAULT_OPTIONS, ...opts };
const fs = opts_.fs;
opts_.fs_ = {
chmod: fs.chmod ? util_1.promisify(fs.chmod) : (async () => { }),
mkdir: util_1.promisify(fs.mkdir),
readFile: util_1.promisify(fs.readFile),
stat: util_1.promisify(fs.stat),
unlink: util_1.promisify(fs.unlink),
writeFile: util_1.promisify(fs.writeFile)
};
return opts_;
}
/**
* Try to create shims.
*
* @param src Path to program (executable or script).
* @param to Path to shims.
* Don't add an extension if you will create multiple types of shims.
* @param opts Options.
* @throws If `src` is missing.
*/
async function cmdShim(src, to, opts) {
const opts_ = ingestOptions(opts);
await opts_.fs_.stat(src);
await cmdShim_(src, to, opts_);
}
/**
* Try to create shims.
*
* Does nothing if `src` doesn't exist.
*
* @param src Path to program (executable or script).
* @param to Path to shims.
* Don't add an extension if you will create multiple types of shims.
* @param opts Options.
*/
function cmdShimIfExists(src, to, opts) {
return cmdShim(src, to, opts).catch(() => { });
}
/**
* Try to unlink, but ignore errors.
* Any problems will surface later.
*
* @param path File to be removed.
*/
function rm(path, opts) {
return opts.fs_.unlink(path).catch(() => { });
}
/**
* Try to create shims **even if `src` is missing**.
*
* @param src Path to program (executable or script).
* @param to Path to shims.
* Don't add an extension if you will create multiple types of shims.
* @param opts Options.
*/
async function cmdShim_(src, to, opts) {
const srcRuntimeInfo = await searchScriptRuntime(src, opts);
// Always tries to create all types of shims by calling `writeAllShims` as of now.
// Append your code here to change the behavior in response to `srcRuntimeInfo`.
// Create 3 shims for (Ba)sh in Cygwin / MSYS, no extension) & CMD (.cmd) & PowerShell (.ps1)
await writeShimsPreCommon(to, opts);
return writeAllShims(src, to, srcRuntimeInfo, opts);
}
/**
* Do processes before **all** shims are created.
* This must be called **only once** for one call of `cmdShim(IfExists)`.
*
* @param target Path of shims that are going to be created.
*/
function writeShimsPreCommon(target, opts) {
return opts.fs_.mkdir(path.dirname(target), { recursive: true });
}
/**
* Write all types (sh & cmd & pwsh) of shims to files.
* Extensions (`.cmd` and `.ps1`) are appended to cmd and pwsh shims.
*
*
* @param src Path to program (executable or script).
* @param to Path to shims **without extensions**.
* Extensions are added for CMD and PowerShell shims.
* @param srcRuntimeInfo Return value of `await searchScriptRuntime(src)`.
* @param opts Options.
*/
function writeAllShims(src, to, srcRuntimeInfo, opts) {
const opts_ = ingestOptions(opts);
const generatorAndExts = [{ generator: generateShShim, extension: '' }];
if (opts_.createCmdFile) {
generatorAndExts.push({ generator: generateCmdShim, extension: CMD_EXTENSION });
}
if (opts_.createPwshFile) {
generatorAndExts.push({ generator: generatePwshShim, extension: '.ps1' });
}
return Promise.all(generatorAndExts.map((generatorAndExt) => writeShim(src, to + generatorAndExt.extension, srcRuntimeInfo, generatorAndExt.generator, opts_)));
}
/**
* Do processes before writing shim.
*
* @param target Path to shim that is going to be created.
*/
function writeShimPre(target, opts) {
return rm(target, opts);
}
/**
* Do processes after writing the shim.
*
* @param target Path to just created shim.
*/
function writeShimPost(target, opts) {
// Only chmoding shims as of now.
// Some other processes may be appended.
return chmodShim(target, opts);
}
/**
* Look into runtime (e.g. `node` & `sh` & `pwsh`) and its arguments
* of the target program (script or executable).
*
* @param target Path to the executable or script.
* @return Promise of infomation of runtime of `target`.
*/
async function searchScriptRuntime(target, opts) {
const data = await opts.fs_.readFile(target, 'utf8');
// First, check if the bin is a #! of some sort.
const firstLine = data.trim().split(/\r*\n/)[0];
const shebang = firstLine.match(shebangExpr);
if (!shebang) {
// If not, infer script type from its extension.
// If the inference fails, it's something that'll be compiled, or some other
// sort of script, and just call it directly.
const targetExtension = path.extname(target).toLowerCase();
return {
// undefined if extension is unknown but it's converted to null.
program: extensionToProgramMap.get(targetExtension) || null,
additionalArgs: ''
};
}
return {
program: shebang[1],
additionalArgs: shebang[2]
};
}
/**
* Write shim to the file system while executing the pre- and post-processes
* defined in `WriteShimPre` and `WriteShimPost`.
*
* @param src Path to the executable or script.
* @param to Path to the (sh) shim(s) that is going to be created.
* @param srcRuntimeInfo Result of `await searchScriptRuntime(src)`.
* @param generateShimScript Generator of shim script.
* @param opts Other options.
*/
async function writeShim(src, to, srcRuntimeInfo, generateShimScript, opts) {
const defaultArgs = opts.preserveSymlinks ? '--preserve-symlinks' : '';
// `Array.prototype.filter` removes ''.
// ['--foo', '--bar'].join(' ') and [].join(' ') returns '--foo --bar' and '' respectively.
const args = [srcRuntimeInfo.additionalArgs, defaultArgs].filter(arg => arg).join(' ');
opts = Object.assign({}, opts, {
prog: srcRuntimeInfo.program,
args: args
});
await writeShimPre(to, opts);
await opts.fs_.writeFile(to, generateShimScript(src, to, opts), 'utf8');
return writeShimPost(to, opts);
}
/**
* Generate the content of a shim for CMD.
*
* @param src Path to the executable or script.
* @param to Path to the shim to be created.
* It is highly recommended to end with `.cmd` (or `.bat`).
* @param opts Options.
* @return The content of shim.
*/
function generateCmdShim(src, to, opts) {
// `shTarget` is not used to generate the content.
const shTarget = path.relative(path.dirname(to), src);
let target = shTarget.split('/').join('\\');
const quotedPathToTarget = path.isAbsolute(target) ? `"${target}"` : `"%~dp0\\${target}"`;
let longProg;
let prog = opts.prog;
let args = opts.args || '';
const nodePath = normalizePathEnvVar(opts.nodePath).win32;
const prependToPath = normalizePathEnvVar(opts.prependToPath).win32;
if (!prog) {
prog = quotedPathToTarget;
args = '';
target = '';
}
else if (prog === 'node' && opts.nodeExecPath) {
prog = `"${opts.nodeExecPath}"`;
target = quotedPathToTarget;
}
else {
longProg = `"%~dp0\\${prog}.exe"`;
target = quotedPathToTarget;
}
let progArgs = opts.progArgs ? `${opts.progArgs.join(` `)} ` : '';
// @IF EXIST "%~dp0\node.exe" (
// "%~dp0\node.exe" "%~dp0\.\node_modules\npm\bin\npm-cli.js" %*
// ) ELSE (
// SETLOCAL
// SET PATHEXT=%PATHEXT:;.JS;=;%
// node "%~dp0\.\node_modules\npm\bin\npm-cli.js" %*
// )
let cmd = '@SETLOCAL\r\n';
if (prependToPath) {
cmd += `@SET "PATH=${prependToPath}:%PATH%"\r\n`;
}
if (nodePath) {
cmd += `\
@IF NOT DEFINED NODE_PATH (\r
@SET "NODE_PATH=${nodePath}"\r
) ELSE (\r
@SET "NODE_PATH=%NODE_PATH%;${nodePath}"\r
)\r
`;
}
if (longProg) {
cmd += `\
@IF EXIST ${longProg} (\r
${longProg} ${args} ${target} ${progArgs}%*\r
) ELSE (\r
@SET PATHEXT=%PATHEXT:;.JS;=;%\r
${prog} ${args} ${target} ${progArgs}%*\r
)\r
`;
}
else {
cmd += `@${prog} ${args} ${target} ${progArgs}%*\r\n`;
}
return cmd;
}
/**
* Generate the content of a shim for (Ba)sh in, for example, Cygwin and MSYS(2).
*
* @param src Path to the executable or script.
* @param to Path to the shim to be created.
* It is highly recommended to end with `.sh` or to contain no extension.
* @param opts Options.
* @return The content of shim.
*/
function generateShShim(src, to, opts) {
let shTarget = path.relative(path.dirname(to), src);
let shProg = opts.prog && opts.prog.split('\\').join('/');
let shLongProg;
shTarget = shTarget.split('\\').join('/');
const quotedPathToTarget = path.isAbsolute(shTarget) ? `"${shTarget}"` : `"$basedir/${shTarget}"`;
let args = opts.args || '';
const shNodePath = normalizePathEnvVar(opts.nodePath).posix;
if (!shProg) {
shProg = quotedPathToTarget;
args = '';
shTarget = '';
}
else if (opts.prog === 'node' && opts.nodeExecPath) {
shProg = `"${opts.nodeExecPath}"`;
shTarget = quotedPathToTarget;
}
else {
shLongProg = `"$basedir/${opts.prog}"`;
shTarget = quotedPathToTarget;
}
let progArgs = opts.progArgs ? `${opts.progArgs.join(` `)} ` : '';
// #!/bin/sh
// basedir=`dirname "$0"`
//
// case `uname` in
// *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
// esac
//
// export NODE_PATH="<nodepath>"
//
// if [ -x "$basedir/node.exe" ]; then
// exec "$basedir/node.exe" "$basedir/node_modules/npm/bin/npm-cli.js" "$@"
// else
// exec node "$basedir/node_modules/npm/bin/npm-cli.js" "$@"
// fi
let sh = `\
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")
case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;;
esac
`;
if (opts.prependToPath) {
sh += `\
export PATH="${opts.prependToPath}:$PATH"
`;
}
if (shNodePath) {
sh += `\
if [ -z "$NODE_PATH" ]; then
export NODE_PATH="${shNodePath}"
else
export NODE_PATH="$NODE_PATH:${shNodePath}"
fi
`;
}
if (shLongProg) {
sh += `\
if [ -x ${shLongProg} ]; then
exec ${shLongProg} ${args} ${shTarget} ${progArgs}"$@"
else
exec ${shProg} ${args} ${shTarget} ${progArgs}"$@"
fi
`;
}
else {
sh += `\
${shProg} ${args} ${shTarget} ${progArgs}"$@"
exit $?
`;
}
return sh;
}
/**
* Generate the content of a shim for PowerShell.
*
* @param src Path to the executable or script.
* @param to Path to the shim to be created.
* It is highly recommended to end with `.ps1`.
* @param opts Options.
* @return The content of shim.
*/
function generatePwshShim(src, to, opts) {
let shTarget = path.relative(path.dirname(to), src);
const shProg = opts.prog && opts.prog.split('\\').join('/');
let pwshProg = shProg && `"${shProg}$exe"`;
let pwshLongProg;
shTarget = shTarget.split('\\').join('/');
const quotedPathToTarget = path.isAbsolute(shTarget) ? `"${shTarget}"` : `"$basedir/${shTarget}"`;
let args = opts.args || '';
let normalizedNodePathEnvVar = normalizePathEnvVar(opts.nodePath);
const nodePath = normalizedNodePathEnvVar.win32;
const shNodePath = normalizedNodePathEnvVar.posix;
let normalizedPrependPathEnvVar = normalizePathEnvVar(opts.prependToPath);
const prependPath = normalizedPrependPathEnvVar.win32;
const shPrependPath = normalizedPrependPathEnvVar.posix;
if (!pwshProg) {
pwshProg = quotedPathToTarget;
args = '';
shTarget = '';
}
else if (opts.prog === 'node' && opts.nodeExecPath) {
pwshProg = `"${opts.nodeExecPath}"`;
shTarget = quotedPathToTarget;
}
else {
pwshLongProg = `"$basedir/${opts.prog}$exe"`;
shTarget = quotedPathToTarget;
}
let progArgs = opts.progArgs ? `${opts.progArgs.join(` `)} ` : '';
// #!/usr/bin/env pwsh
// $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
//
// $ret=0
// $exe = ""
// if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
// # Fix case when both the Windows and Linux builds of Node
// # are installed in the same directory
// $exe = ".exe"
// }
// if (Test-Path "$basedir/node") {
// # Support pipeline input
// if ($MyInvocation.ExpectingInput) {
// $input | & "$basedir/node$exe" "$basedir/node_modules/npm/bin/npm-cli.js" $args
// } else {
// & "$basedir/node$exe" "$basedir/node_modules/npm/bin/npm-cli.js" $args
// }
// $ret=$LASTEXITCODE
// } else {
// # Support pipeline input
// if ($MyInvocation.ExpectingInput) {
// $input | & "node$exe" "$basedir/node_modules/npm/bin/npm-cli.js" $args
// } else {
// & "node$exe" "$basedir/node_modules/npm/bin/npm-cli.js" $args
// }
// $ret=$LASTEXITCODE
// }
// exit $ret
let pwsh = `\
#!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
$exe=""
${(nodePath || prependPath) ? '$pathsep=":"\n' : ''}\
${nodePath ? `\
$env_node_path=$env:NODE_PATH
$new_node_path="${nodePath}"
` : ''}\
${prependPath ? `\
$env_path=$env:PATH
$prepend_path="${prependPath}"
` : ''}\
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
# Fix case when both the Windows and Linux builds of Node
# are installed in the same directory
$exe=".exe"
${(nodePath || prependPath) ? ' $pathsep=";"\n' : ''}\
}`;
if (shNodePath || shPrependPath) {
pwsh += `\
else {
${shNodePath ? ` $new_node_path="${shNodePath}"\n` : ''}\
${shPrependPath ? ` $prepend_path="${shPrependPath}"\n` : ''}\
}
`;
}
if (shNodePath) {
pwsh += `\
if ([string]::IsNullOrEmpty($env_node_path)) {
$env:NODE_PATH=$new_node_path
} else {
$env:NODE_PATH="$env_node_path$pathsep$new_node_path"
}
`;
}
if (opts.prependToPath) {
pwsh += `
$env:PATH="$prepend_path$pathsep$env:PATH"
`;
}
if (pwshLongProg) {
pwsh += `
$ret=0
if (Test-Path ${pwshLongProg}) {
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & ${pwshLongProg} ${args} ${shTarget} ${progArgs}$args
} else {
& ${pwshLongProg} ${args} ${shTarget} ${progArgs}$args
}
$ret=$LASTEXITCODE
} else {
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & ${pwshProg} ${args} ${shTarget} ${progArgs}$args
} else {
& ${pwshProg} ${args} ${shTarget} ${progArgs}$args
}
$ret=$LASTEXITCODE
}
${nodePath ? '$env:NODE_PATH=$env_node_path\n' : ''}\
${prependPath ? '$env:PATH=$env_path\n' : ''}\
exit $ret
`;
}
else {
pwsh += `
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & ${pwshProg} ${args} ${shTarget} ${progArgs}$args
} else {
& ${pwshProg} ${args} ${shTarget} ${progArgs}$args
}
${nodePath ? '$env:NODE_PATH=$env_node_path\n' : ''}\
${prependPath ? '$env:PATH=$env_path\n' : ''}\
exit $LASTEXITCODE
`;
}
return pwsh;
}
/**
* Chmod just created shim and make it executable
*
* @param to Path to shim.
*/
function chmodShim(to, opts) {
return opts.fs_.chmod(to, 0o755);
}
function normalizePathEnvVar(nodePath) {
if (!nodePath || !nodePath.length) {
return {
win32: '',
posix: ''
};
}
let split = (typeof nodePath === 'string' ? nodePath.split(path.delimiter) : Array.from(nodePath));
let result = {};
for (let i = 0; i < split.length; i++) {
const win32 = split[i].split('/').join('\\');
const posix = isWindows() ? split[i].split('\\').join('/').replace(/^([^:\\/]*):/, (_, $1) => `/mnt/${$1.toLowerCase()}`) : split[i];
result.win32 = result.win32 ? `${result.win32};${win32}` : win32;
result.posix = result.posix ? `${result.posix}:${posix}` : posix;
result[i] = { win32, posix };
}
return result;
}
module.exports = cmdShim;
//# sourceMappingURL=index.js.map
/***/ }),
/***/ "../../../.yarn/berry/cache/chownr-npm-2.0.0-638f1c9c61-9.zip/node_modules/chownr/chownr.js":
/*!**************************************************************************************************!*\
!*** ../../../.yarn/berry/cache/chownr-npm-2.0.0-638f1c9c61-9.zip/node_modules/chownr/chownr.js ***!
\**************************************************************************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
"use strict";
const fs = __webpack_require__(/*! fs */ "fs")
const path = __webpack_require__(/*! path */ "path")
/* istanbul ignore next */
const LCHOWN = fs.lchown ? 'lchown' : 'chown'
/* istanbul ignore next */
const LCHOWNSYNC = fs.lchownSync ? 'lchownSync' : 'chownSync'
/* istanbul ignore next */
const needEISDIRHandled = fs.lchown &&
!process.version.match(/v1[1-9]+\./) &&
!process.version.match(/v10\.[6-9]/)
const lchownSync = (path, uid, gid) => {
try {
return fs[LCHOWNSYNC](path, uid, gid)
} catch (er) {
if (er.code !== 'ENOENT')
throw er
}
}
/* istanbul ignore next */
const chownSync = (path, uid, gid) => {
try {
return fs.chownSync(path, uid, gid)
} catch (er) {
if (er.code !== 'ENOENT')
throw er
}
}
/* istanbul ignore next */
const handleEISDIR =
needEISDIRHandled ? (path, uid, gid, cb) => er => {
// Node prior to v10 had a very questionable implementation of
// fs.lchown, which would always try to call fs.open on a directory
// Fall back to fs.chown in those cases.
if (!er || er.code !== 'EISDIR')
cb(er)
else
fs.chown(path, uid, gid, cb)
}
: (_, __, ___, cb) => cb
/* istanbul ignore next */
const handleEISDirSync =
needEISDIRHandled ? (path, uid, gid) => {
try {
return lchownSync(path, uid, gid)
} catch (er) {
if (er.code !== 'EISDIR')
throw er
chownSync(path, uid, gid)
}
}
: (path, uid, gid) => lchownSync(path, uid, gid)
// fs.readdir could only accept an options object as of node v6
const nodeVersion = process.version
let readdir = (path, options, cb) => fs.readdir(path, options, cb)
let readdirSync = (path, options) => fs.readdirSync(path, options)
/* istanbul ignore next */
if (/^v4\./.test(nodeVersion))
readdir = (path, options, cb) => fs.readdir(path, cb)
const chown = (cpath, uid, gid, cb) => {
fs[LCHOWN](cpath, uid, gid, handleEISDIR(cpath, uid, gid, er => {
// Skip ENOENT error
cb(er && er.code !== 'ENOENT' ? er : null)
}))
}
const chownrKid = (p, child, uid, gid, cb) => {
if (typeof child === 'string')
return fs.lstat(path.resolve(p, child), (er, stats) => {
// Skip ENOENT error
if (er)
return cb(er.code !== 'ENOENT' ? er : null)
stats.name = child
chownrKid(p, stats, uid, gid, cb)
})
if (child.isDirectory()) {
chownr(path.resolve(p, child.name), uid, gid, er => {
if (er)
return cb(er)
const cpath = path.resolve(p, child.name)
chown(cpath, uid, gid, cb)
})
} else {
const cpath = path.resolve(p, child.name)
chown(cpath, uid, gid, cb)
}
}
const chownr = (p, uid, gid, cb) => {
readdir(p, { withFileTypes: true }, (er, children) => {
// any error other than ENOTDIR or ENOTSUP means it's not readable,
// or doesn't exist. give up.
if (er) {
if (er.code === 'ENOENT')
return cb()
else if (er.code !== 'ENOTDIR' && er.code !== 'ENOTSUP')
return cb(er)
}
if (er || !children.length)
return chown(p, uid, gid, cb)
let len = children.length
let errState = null
const then = er => {
if (errState)
return
if (er)
return cb(errState = er)
if (-- len === 0)
return chown(p, uid, gid, cb)
}
children.forEach(child => chownrKid(p, child, uid, gid, then))
})
}
const chownrKidSync = (p, child, uid, gid) => {
if (typeof child === 'string') {
try {
const stats = fs.lstatSync(path.resolve(p, child))
stats.name = child
child = stats
} catch (er) {
if (er.code === 'ENOENT')
return
else
throw er
}
}
if (child.isDirectory())
chownrSync(path.resolve(p, child.name), uid, gid)
handleEISDirSync(path.resolve(p, child.name), uid, gid)
}
const chownrSync = (p, uid, gid) => {
let children
try {
children = readdirSync(p, { withFileTypes: true })
} catch (er) {
if (er.code === 'ENOENT')
return
else if (er.code === 'ENOTDIR' || er.code === 'ENOTSUP')
return handleEISDirSync(p, uid, gid)
else
throw er
}
if (children && children.length)
children.forEach(child => chownrKidSync(p, child, uid, gid))
return handleEISDirSync(p, uid, gid)
}
module.exports = chownr
chownr.sync = chownrSync
/***/ }),
/***/ "../../../.yarn/berry/cache/cmd-extension-npm-1.0.2-11aa204c4b-9.zip/node_modules/cmd-extension/index.js":
/*!***************************************************************************************************************!*\
!*** ../../../.yarn/berry/cache/cmd-extension-npm-1.0.2-11aa204c4b-9.zip/node_modules/cmd-extension/index.js ***!
\***************************************************************************************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
"use strict";
const path = __webpack_require__(/*! path */ "path")
let cmdExtension
if (process.env.PATHEXT) {
cmdExtension = process.env.PATHEXT
.split(path.delimiter)
.find(ext => ext.toUpperCase() === '.CMD')
}
module.exports = cmdExtension || '.cmd'
/***/ }),
/***/ "../../../.yarn/berry/cache/fs-minipass-npm-2.1.0-501ef87306-9.zip/node_modules/fs-minipass/index.js":
/*!***********************************************************************************************************!*\
!*** ../../../.yarn/berry/cache/fs-minipass-npm-2.1.0-501ef87306-9.zip/node_modules/fs-minipass/index.js ***!
\***********************************************************************************************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
"use strict";
const MiniPass = __webpack_require__(/*! minipass */ "../../../.yarn/berry/cache/minipass-npm-3.3.4-6cf48a6c5e-9.zip/node_modules/minipass/index.js")
const EE = (__webpack_require__(/*! events */ "events").EventEmitter)
const fs = __webpack_require__(/*! fs */ "fs")
let writev = fs.writev
/* istanbul ignore next */
if (!writev) {
// This entire block can be removed if support for earlier than Node.js
// 12.9.0 is not needed.
const binding = process.binding('fs')
const FSReqWrap = binding.FSReqWrap || binding.FSReqCallback
writev = (fd, iovec, pos, cb) => {
const done = (er, bw) => cb(er, bw, iovec)
const req = new FSReqWrap()
req.oncomplete = done
binding.writeBuffers(fd, iovec, pos, req)
}
}
const _autoClose = Symbol('_autoClose')
const _close = Symbol('_close')
const _ended = Symbol('_ended')
const _fd = Symbol('_fd')
const _finished = Symbol('_finished')
const _flags = Symbol('_flags')
const _flush = Symbol('_flush')
const _handleChunk = Symbol('_handleChunk')
const _makeBuf = Symbol('_makeBuf')
const _mode = Symbol('_mode')
const _needDrain = Symbol('_needDrain')
const _onerror = Symbol('_onerror')
const _onopen = Symbol('_onopen')
const _onread = Symbol('_onread')
const _onwrite = Symbol('_onwrite')
const _open = Symbol('_open')
const _path = Symbol('_path')
const _pos = Symbol('_pos')
const _queue = Symbol('_queue')
const _read = Symbol('_read')
const _readSize = Symbol('_readSize')
const _reading = Symbol('_reading')
const _remain = Symbol('_remain')
const _size = Symbol('_size')
const _write = Symbol('_write')
const _writing = Symbol('_writing')
const _defaultFlag = Symbol('_defaultFlag')
const _errored = Symbol('_errored')
class ReadStream extends MiniPass {
constructor (path, opt) {
opt = opt || {}
super(opt)
this.readable = true
this.writable = false
if (typeof path !== 'string')
throw new TypeError('path must be a string')
this[_errored] = false
this[_fd] = typeof opt.fd === 'number' ? opt.fd : null
this[_path] = path
this[_readSize] = opt.readSize || 16*1024*1024
this[_reading] = false
this[_size] = typeof opt.size === 'number' ? opt.size : Infinity
this[_remain] = this[_size]
this[_autoClose] = typeof opt.autoClose === 'boolean' ?
opt.autoClose : true
if (typeof this[_fd] === 'number')
this[_read]()
else
this[_open]()
}
get fd () { return this[_fd] }
get path () { return this[_path] }
write () {
throw new TypeError('this is a readable stream')
}
end () {
throw new TypeError('this is a readable stream')
}
[_open] () {
fs.open(this[_path], 'r', (er, fd) => this[_onopen](er, fd))
}
[_onopen] (er, fd) {
if (er)
this[_onerror](er)
else {
this[_fd] = fd
this.emit('open', fd)
this[_read]()
}
}
[_makeBuf] () {
return Buffer.allocUnsafe(Math.min(this[_readSize], this[_remain]))
}
[_read] () {
if (!this[_reading]) {
this[_reading] = true
const buf = this[_makeBuf]()
/* istanbul ignore if */
if (buf.length === 0)
return process.nextTick(() => this[_onread](null, 0, buf))
fs.read(this[_fd], buf, 0, buf.length, null, (er, br, buf) =>
this[_onread](er, br, buf))
}
}
[_onread] (er, br, buf) {
this[_reading] = false
if (er)
this[_onerror](er)
else if (this[_handleChunk](br, buf))
this[_read]()
}
[_close] () {
if (this[_autoClose] && typeof this[_fd] === 'number') {
const fd = this[_fd]
this[_fd] = null
fs.close(fd, er => er ? this.emit('error', er) : this.emit('close'))
}
}
[_onerror] (er) {
this[_reading] = true
this[_close]()
this.emit('error', er)
}
[_handleChunk] (br, buf) {
let ret = false
// no effect if infinite
this[_remain] -= br
if (br > 0)
ret = super.write(br < buf.length ? buf.slice(0, br) : buf)
if (br === 0 || this[_remain] <= 0) {
ret = false
this[_close]()
super.end()
}
return ret
}
emit (ev, data) {
switch (ev) {
case 'prefinish':
case 'finish':
break
case 'drain':
if (typeof this[_fd] === 'number')
this[_read]()
break
case 'error':
if (this[_errored])
return
this[_errored] = true
return super.emit(ev, data)
default:
return super.emit(ev, data)
}
}
}
class ReadStreamSync extends ReadStream {
[_open] () {
let threw = true
try {
this[_onopen](null, fs.openSync(this[_path], 'r'))
threw = false
} finally {
if (threw)
this[_close]()
}
}
[_read] () {
let threw = true
try {
if (!this[_reading]) {
this[_reading] = true
do {
const buf = this[_makeBuf]()
/* istanbul ignore next */
const br = buf.length === 0 ? 0
: fs.readSync(this[_fd], buf, 0, buf.length, null)
if (!this[_handleChunk](br, buf))
break
} while (true)
this[_reading] = false
}
threw = false
} finally {
if (threw)
this[_close]()
}
}
[_close] () {
if (this[_autoClose] && typeof this[_fd] === 'number') {
const fd = this[_fd]
this[_fd] = null
fs.closeSync(fd)
this.emit('close')
}
}
}
class WriteStream extends EE {
constructor (path, opt) {
opt = opt || {}
super(opt)
this.readable = false
this.writable = true
this[_errored] = false
this[_writing] = false
this[_ended] = false
this[_needDrain] = false
this[_queue] = []
this[_path] = path
this[_fd] = typeof opt.fd === 'number' ? opt.fd : null
this[_mode] = opt.mode === undefined ? 0o666 : opt.mode
this[_pos] = typeof opt.start === 'number' ? opt.start : null
this[_autoClose] = typeof opt.autoClose === 'boolean' ?
opt.autoClose : true
// truncating makes no sense when writing into the middle
const defaultFlag = this[_pos] !== null ? 'r+' : 'w'
this[_defaultFlag] = opt.flags === undefined
this[_flags] = this[_defaultFlag] ? defaultFlag : opt.flags
if (this[_fd] === null)
this[_open]()
}
emit (ev, data) {
if (ev === 'error') {
if (this[_errored])
return
this[_errored] = true
}
return super.emit(ev, data)
}