-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
10485 lines (9777 loc) · 346 KB
/
Copy pathindex.js
File metadata and controls
10485 lines (9777 loc) · 346 KB
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
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ 9081:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.parseCredential = parseCredential;
exports.isServiceAccountKey = isServiceAccountKey;
exports.isExternalAccount = isExternalAccount;
const errors_1 = __nccwpck_require__(3916);
const encoding_1 = __nccwpck_require__(6266);
/**
* parseCredential attempts to parse the given string as a service account key
* JSON or external account credentials. It handles if the input is
* base64-encoded.
*
* @param input String that is an exported JSON service account key or external
* account credentials file (or base64-encoded).
*
* @return The parsed credential. It could be a service account key or an
* external credentials file.
*/
function parseCredential(input) {
input = (input || '').trim();
if (!input) {
throw new Error(`Missing service account key JSON (got empty value)`);
}
// If the string doesn't start with a JSON object character, it is probably
// base64-encoded.
if (!input.startsWith('{')) {
input = (0, encoding_1.fromBase64)(input);
}
try {
const creds = JSON.parse(input);
return creds;
}
catch (err) {
const msg = (0, errors_1.errorMessage)(err);
throw new SyntaxError(`Failed to parse service account key JSON credentials: ${msg}`);
}
}
/**
* isServiceAccountKey returns true if the given interface is a
* ServiceAccountKey, false otherwise.
*
* @param credential Credential to check if is a service account key.
*/
function isServiceAccountKey(credential) {
return credential.type === 'service_account';
}
/**
* isExternalAccount returns true if the given interface is a ExternalAccount,
* false otherwise.
*
* @param credential Credential to check if is an external account
*/
function isExternalAccount(credential) {
return credential.type !== 'external_account';
}
exports["default"] = { parseCredential, isServiceAccountKey, isExternalAccount };
/***/ }),
/***/ 3214:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.deepClone = deepClone;
const v8 = __importStar(__nccwpck_require__(1493));
/**
* deepClone builds a deep copy (clone) of the given input. By default, it uses
* structuredClone if defined. Otherwise, it uses v8 to serialize and
* deserialize the input.
*
* @param input Object to deep clone.
* @param useStructuredClone Use structuredClone method (defaults to true).
* @return Deep copy of input.
*/
function deepClone(input, useStructuredClone = true) {
if (useStructuredClone && typeof structuredClone === 'function') {
return structuredClone(input);
}
return v8.deserialize(v8.serialize(input));
}
/***/ }),
/***/ 731:
/***/ ((__unused_webpack_module, exports) => {
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.parseCSV = parseCSV;
exports.parseMultilineCSV = parseMultilineCSV;
/**
* parseCSV accepts a comma-separated list of items. Whitespace around entries
* is removed.
*
* @param input String representing a list.
*
* @returns Array of strings, in the same order they were supplied.
*/
function parseCSV(input) {
input = (input || '').trim();
if (!input) {
return [];
}
const list = input.split(/(?<!\\),/gi);
for (let i = 0; i < list.length; i++) {
list[i] = list[i].trim().replace(/\\,/gi, ',');
}
return list;
}
/**
* parseMultilineCSV parses a CSV input where entries can be separated by
* newlines. This is specific for GitHub Actions, since the YAML syntax does not
* allow complex types, and sometimes splitting long entries over multiple lines
* assists with readability.
*
* @param input String representing a comma-separated list
*
* @returns Array of strings, in the same order they were supplied.
*/
function parseMultilineCSV(input) {
const result = [];
for (const line of (input || '').split(/\r|\n/)) {
const pieces = parseCSV(line);
for (const piece of pieces) {
const trimmed = (piece || '').trim();
if (trimmed) {
result.push(trimmed);
}
}
}
return result;
}
/***/ }),
/***/ 6266:
/***/ ((__unused_webpack_module, exports) => {
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.toBase64 = toBase64;
exports.fromBase64 = fromBase64;
/**
* toBase64 base64 encodes the input as URL-encoded, unpadded.
*
* @param input String or Buffer to encode as base64.
*
* @return URL-encoded, unpadded base64 string.
*/
function toBase64(input) {
return Buffer.from(input)
.toString('base64')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=+$/, '');
}
/**
* fromBase64 base64 decodes the input, handling URL vs standard encoding and
* padded vs unpadded. This should only be used to decode string values - the
* return result is a string and therefore this will not work with binary data.
*
* @param input Base64-encoded string.
*
* @return Decoded string.
*/
function fromBase64(input, outEncoding) {
if (!outEncoding) {
outEncoding = 'utf8';
}
let str = input.replace(/-/g, '+').replace(/_/g, '/');
while (str.length % 4)
str += '=';
return Buffer.from(str, 'base64').toString(outEncoding);
}
/***/ }),
/***/ 3466:
/***/ ((__unused_webpack_module, exports) => {
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.toEnum = toEnum;
/**
* toEnum converts the input value to the best enum value. If no enum value
* exists, it throws an error.
*
* @param e Enum to check against.
* @param s String to enumerize.
* @returns string
*/
function toEnum(e, s) {
const originalValue = (s || '').toUpperCase();
const mutatedValue = originalValue.replace(/[\s-]+/g, '_');
if (originalValue in e) {
return e[originalValue];
}
else if (mutatedValue in e) {
return e[mutatedValue];
}
else {
const keys = Object.keys(e);
throw new Error(`Invalid value ${s}, valid values are ${JSON.stringify(keys)}`);
}
}
/***/ }),
/***/ 8204:
/***/ ((__unused_webpack_module, exports) => {
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.stubEnv = stubEnv;
/**
* stubEnv accepts an input dictionary and sets the provided environment
* variables in the current process environment. Values set to "undefined" are
* deleted from the environment.
*
* The function is only safe for concurrent use if the target is safe for
* concurrent use. The function itself provides no locking.
*
* @param input Map of string value pairs to set in the new environment.
* @param target Target map to set and restore (defaults to `process.env`).
*
* @return Function that restores the environment.
*/
function stubEnv(input, target = process.env) {
const restore = {};
for (const name in input) {
restore[name] = target[name];
if (input[name] !== undefined) {
target[name] = input[name];
}
else {
delete target[name];
}
}
return () => {
for (const name in restore) {
if (restore[name] !== undefined) {
target[name] = restore[name];
}
else {
delete target[name];
}
}
};
}
/***/ }),
/***/ 3916:
/***/ ((__unused_webpack_module, exports) => {
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.errorMessage = errorMessage;
exports.isNotFoundError = isNotFoundError;
/**
* errorMessage extracts the error message from the given error. It does this
* via best effort and makes the error embeddable in other errors. It discards
* any error details including stacktraces.
*
* @param err Error input.
*
* @return Error information as a string.
*/
function errorMessage(err) {
let msgText;
if (err === null) {
msgText = 'null';
}
else if (err === undefined || typeof err === 'undefined') {
msgText = 'undefined';
}
else if (typeof err === 'bigint' || err instanceof BigInt) {
msgText = err.toString();
}
else if (typeof err === 'boolean' || err instanceof Boolean) {
msgText = err.toString();
}
else if (err instanceof Error) {
msgText = err.message;
}
else if (typeof err === 'function' || err instanceof Function) {
msgText = errorMessage(err());
}
else if (typeof err === 'number' || err instanceof Number) {
msgText = err.toString();
}
else if (typeof err === 'string' || err instanceof String) {
msgText = err.toString();
}
else if (typeof err === 'symbol' || err instanceof Symbol) {
msgText = err.toString();
}
else if (typeof err === 'object' || err instanceof Object) {
msgText = JSON.stringify(err);
}
else {
msgText = String(`[${typeof err}] ${err}`);
}
const msg = msgText.trim().replace('Error: ', '').trim();
if (!msg)
return '';
// If the first letter is a capital letter and the second letter is not a
// capital letter, downcase the first letter.
if (msg.length > 1 && isUpper(msg[0]) && !isUpper(msg[1])) {
return msg[0].toLowerCase() + msg.slice(1);
}
// If we got this far, it means the message has less than two characters or
// there are multiple capital letters (e.g. ERRNOFILE).
return msg;
}
/**
* isNotFoundError determines if the given error is "not found". Since there's
* literally no way to actually do this in Node, it inspects the string output
* for "ENOENT".
*
* @param err The error result to check.
*
* @return Boolean, true if the error represents NotFound, false otherwise.
*/
function isNotFoundError(err) {
const msg = errorMessage(err);
return msg.toUpperCase().includes('ENOENT');
}
/**
* isUpper returns true if the given string is uppercase.
*
* @param str String or character to check.
*
* @return True if the input is uppercase, false otherwise.
*/
function isUpper(str) {
return str === str.toUpperCase();
}
/***/ }),
/***/ 6148:
/***/ ((__unused_webpack_module, exports) => {
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.parseFlags = parseFlags;
exports.readUntil = readUntil;
/**
* parseFlags takes an input string and parses it as posix-compliant flags.
*
* @param input Flag string input.
* @return Array of strings in the order in which they were defined as flags.
*/
function parseFlags(input) {
const result = [];
let current = '';
let expectingArg = false;
for (let i = 0; i < input.length; i++) {
const ch = input[i];
// If we encounter a single quote, read until we encounter another single
// quote.
if (ch === `'`) {
const next = readUntil(input.slice(i + 1), `'`);
if (next === null) {
throw new Error(`Unterminated single quote in ${input} at position ${i}`);
}
current += ch + next;
i += next.length;
continue;
}
// If we encounter a double quote, read until we encounter another double
// quote.
if (ch === `"`) {
const next = readUntil(input.slice(i + 1), `"`);
if (next === null) {
throw new Error(`Unterminated double quote in ${input} at position ${i}`);
}
current += ch + next;
i += next.length;
continue;
}
// Whitespace characters trigger argument termination.
if (ch === '\r' || ch === `\n` || ch === ` `) {
// We are no longer expecting an argument.
expectingArg = false;
// If there's anything in the buffer, append now.
if (current !== ``) {
result.push(current);
current = ``;
}
// Regardless, do not append these strings to the result.
continue;
}
// If we've encountered an equal sign, we need to check whether we're
// expecting an argument. If we're not expecting an argument and the current
// entry looks like a flag, terminate. Otherwise, continue normal appending
// below.
if (ch === `=`) {
if (!expectingArg && current[0] === `-`) {
result.push(current);
current = ``;
expectingArg = true;
continue;
}
}
// Otherwise, append.
current += ch;
}
if (current !== '') {
result.push(current);
}
// Post-process and remove any super-quoted strings.
for (let i = 0; i < result.length; i++) {
for (;;) {
const v = result[i];
if (v.length < 2) {
break;
}
const first = v.at(0);
const last = v.at(-1);
if ((first === `'` || first === `"`) && first === last) {
result[i] = v.slice(1, -1);
continue;
}
break;
}
}
return result;
}
/**
* readUntil reads up to and including the given character and returns the
* result. It ignores escaped versions of the character if they are preceeded by
* with "\". If ch is not found, it returns null.
*
* This is a utility function, but it is exported for testing.
*
* @param input The input string.
* @param ch The character to search.
*
* @return the string up to and including the search character, or null if no
* match is found.
*/
function readUntil(input, ch) {
let escaped = false;
let result = '';
for (let i = 0; i < input.length; i++) {
const next = input[i];
result += next;
if (next === `\\`) {
escaped = true;
continue;
}
if (next === ch && !escaped) {
return result;
}
escaped = false;
}
return null;
}
/***/ }),
/***/ 4772:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.forceRemove = forceRemove;
exports.isEmptyDir = isEmptyDir;
exports.writeSecureFile = writeSecureFile;
exports.removeFile = removeFile;
const fs_1 = __nccwpck_require__(9896);
const errors_1 = __nccwpck_require__(3916);
/**
* forceRemove forcibly removes a file or directory (recursively). If the file
* or directory does not exist, it does nothing. This is functionally equivalent
* to fs.rm, but avoids the need to handle errors for when the target file or
* directory does not exist.
*
* @param pth Path to the file or directory to remove.
*/
async function forceRemove(pth) {
try {
await fs_1.promises.rm(pth, { force: true, recursive: true });
}
catch (err) {
if (!(0, errors_1.isNotFoundError)(err)) {
const msg = (0, errors_1.errorMessage)(err);
throw new Error(`Failed to remove "${pth}": ${msg}`);
}
}
}
/**
* isEmptyDir returns true if the given directory does not exist, or exists but
* contains no files. It also returns true if the current user does not have
* permission to read the directory, since it is effectively empty from the
* viewpoint of the caller.
*
* @param dir Path to a directory.
*/
async function isEmptyDir(dir) {
try {
const files = await fs_1.promises.readdir(dir);
return files.length <= 0;
}
catch {
return true;
}
}
/**
* writeSecureFile writes a file to disk with 0640 permissions and locks the
* file during writing.
*
* @param outputPath Path in which to create the secure file.
* @param data Data to write to file.
* @param options additional options to pass to writeFile. The default options
* are permissions of 0640, write-exclusive, and flush-on-success.
*
* @returns Path to written file.
*/
async function writeSecureFile(outputPath, data, options) {
const opts = Object.assign({}, { mode: 0o640, flag: 'wx', flush: true }, options);
await fs_1.promises.writeFile(outputPath, data, opts);
return outputPath;
}
/**
* removeFile removes the file at the given path. If the file does not exist, it
* does nothing.
*
* @param filePath Path of the file on disk to delete.
*
* @returns A boolean, true if the file was deleted, false otherwise.
*
* @deprecated Use #forceRemove instead.
*/
async function removeFile(filePath) {
try {
await fs_1.promises.unlink(filePath);
return true;
}
catch (err) {
if ((0, errors_1.isNotFoundError)(err)) {
return false;
}
const msg = (0, errors_1.errorMessage)(err);
throw new Error(`Failed to remove "${filePath}": ${msg}`);
}
}
/***/ }),
/***/ 7237:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.parseGcloudIgnore = parseGcloudIgnore;
const fs_1 = __nccwpck_require__(9896);
const path_1 = __nccwpck_require__(6928);
const errors_1 = __nccwpck_require__(3916);
/**
* parseGcloudIgnore parses a gcloud ignore at the given filepath. It follows
* the parsing rules defined at
* https://cloud.google.com/sdk/gcloud/reference/topic/gcloudignore, including
* parsing any included files.
*
* @param pth Path to the gcloudignore file.
* @return Ordered list of strings from the various ignore files.
*/
async function parseGcloudIgnore(pth) {
const parentDir = (0, path_1.dirname)(pth);
let ignoreContents = [];
try {
ignoreContents = (await fs_1.promises.readFile(pth, { encoding: 'utf8' }))
.toString()
.split(/\r?\n/)
.filter(shouldKeepIgnoreLine)
.map((line) => line.trim());
}
catch (err) {
if (!(0, errors_1.isNotFoundError)(err)) {
throw err;
}
}
// Iterate through each line and parse any includes.
for (let i = 0; i < ignoreContents.length; i++) {
const line = ignoreContents[i];
if (line.startsWith('#!include:')) {
const includeName = line.substring(10).trim();
const includePth = (0, path_1.join)(parentDir, includeName);
const subIgnoreContents = (await fs_1.promises.readFile(includePth, { encoding: 'utf8' }))
.toString()
.split(/\r?\n/)
.filter(shouldKeepIgnoreLine)
.map((line) => line.trim());
ignoreContents.splice(i, 1, ...subIgnoreContents);
i += subIgnoreContents.length;
}
}
return ignoreContents;
}
/**
* shouldKeepIgnoreLine is a helper that returns true if the given line is not
* blank or a comment.
*
* @param line The line to check.
* @return boolean
*/
function shouldKeepIgnoreLine(line) {
const trimmed = (line || '').trim();
if (trimmed === '') {
return false;
}
if (trimmed.startsWith('#') && !trimmed.startsWith('#!')) {
return false;
}
return true;
}
/***/ }),
/***/ 9407:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
__exportStar(__nccwpck_require__(9081), exports);
__exportStar(__nccwpck_require__(3214), exports);
__exportStar(__nccwpck_require__(731), exports);
__exportStar(__nccwpck_require__(6266), exports);
__exportStar(__nccwpck_require__(3466), exports);
__exportStar(__nccwpck_require__(8204), exports);
__exportStar(__nccwpck_require__(3916), exports);
__exportStar(__nccwpck_require__(6148), exports);
__exportStar(__nccwpck_require__(4772), exports);
__exportStar(__nccwpck_require__(7237), exports);
__exportStar(__nccwpck_require__(3599), exports);
__exportStar(__nccwpck_require__(4958), exports);
__exportStar(__nccwpck_require__(3716), exports);
__exportStar(__nccwpck_require__(7384), exports);
__exportStar(__nccwpck_require__(436), exports);
__exportStar(__nccwpck_require__(9809), exports);
__exportStar(__nccwpck_require__(8935), exports);
__exportStar(__nccwpck_require__(9834), exports);
__exportStar(__nccwpck_require__(6244), exports);
__exportStar(__nccwpck_require__(5215), exports);
__exportStar(__nccwpck_require__(286), exports);
/***/ }),
/***/ 3599:
/***/ ((__unused_webpack_module, exports) => {
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.parseBoolean = parseBoolean;
const booleanTable = {
'1': true,
't': true,
'T': true,
'true': true,
'True': true,
'TRUE': true,
'0': false,
'f': false,
'F': false,
'false': false,
'False': false,
'FALSE': false,
};
/**
* parseBoolean converts a string into a boolean. Unparseable or invalid values
* return false.
*
* @param input The value to check
* @return boolean
*/
function parseBoolean(input, defaultValue = false) {
const key = (input || '').trim();
if (key === '') {
return defaultValue;
}
if (!(key in booleanTable)) {
throw new Error(`invalid boolean value "${key}"`);
}
return booleanTable[key];
}
/***/ }),
/***/ 4958:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.joinKVString = joinKVString;
exports.joinKVStringForGCloud = joinKVStringForGCloud;
exports.parseKVString = parseKVString;
exports.parseKVFile = parseKVFile;
exports.parseKVJSON = parseKVJSON;
exports.parseKVYAML = parseKVYAML;
exports.parseKVStringAndFile = parseKVStringAndFile;
const yaml_1 = __importDefault(__nccwpck_require__(8815));
const fs_1 = __nccwpck_require__(9896);
const errors_1 = __nccwpck_require__(3916);
const validations_1 = __nccwpck_require__(5215);
/**
* joinKVString joins the given KVPair using the provided separator.
*
* @param input KVPair to serialize.
* @param separator Join separator.
*/
function joinKVString(input, separator = ',') {
return Object.entries(input)
.map(([k, v]) => {
return `${k}=${v}`;
})
.join(separator);
}
/**
* joinKVStringForGCloud creates a string suitable for using with gcloud by
* choosing a custom escape delimiter sequence that does not exist in the input
* string.
*
* @param input KVPair to serialize.
* @param chars String of characters to use.
*/
function joinKVStringForGCloud(input, chars = ',.!@#$%&*()_=+~`[]{}|:;<>?🚀🍪🐼\u200B') {
const initial = joinKVString(input, '');
if (initial === '') {
return '';
}
const initialMap = {};
for (let i = 0; i < initial.length; i++) {