@alchemy.run/node-utils 0.0.5 → 2.0.0-beta.72
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/LICENSE +201 -0
- package/NOTICE +5 -0
- package/THIRD_PARTY_LICENSES.md +138 -0
- package/lib/ignore.d.ts +49 -16
- package/lib/ignore.d.ts.map +1 -1
- package/lib/ignore.js +50 -61
- package/lib/ignore.js.map +1 -1
- package/package.json +33 -31
- package/src/ignore.ts +157 -105
- package/lib/adapter.d.ts +0 -14
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -65
- package/lib/adapter.js.map +0 -1
- package/lib/exit-hook.d.ts +0 -22
- package/lib/exit-hook.d.ts.map +0 -1
- package/lib/exit-hook.js +0 -86
- package/lib/exit-hook.js.map +0 -1
- package/lib/foreground-child.d.ts +0 -57
- package/lib/foreground-child.d.ts.map +0 -1
- package/lib/foreground-child.js +0 -201
- package/lib/foreground-child.js.map +0 -1
- package/lib/index.d.ts +0 -6
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -6
- package/lib/index.js.map +0 -1
- package/lib/lockfile-async.d.ts +0 -9
- package/lib/lockfile-async.d.ts.map +0 -1
- package/lib/lockfile-async.js +0 -23
- package/lib/lockfile-async.js.map +0 -1
- package/lib/lockfile.d.ts +0 -53
- package/lib/lockfile.d.ts.map +0 -1
- package/lib/lockfile.js +0 -287
- package/lib/lockfile.js.map +0 -1
- package/lib/mtime-precision.d.ts +0 -11
- package/lib/mtime-precision.d.ts.map +0 -1
- package/lib/mtime-precision.js +0 -40
- package/lib/mtime-precision.js.map +0 -1
- package/lib/retry.d.ts +0 -56
- package/lib/retry.d.ts.map +0 -1
- package/lib/retry.js +0 -203
- package/lib/retry.js.map +0 -1
- package/src/adapter.ts +0 -94
- package/src/exit-hook.ts +0 -96
- package/src/foreground-child.ts +0 -243
- package/src/index.ts +0 -5
- package/src/lockfile-async.ts +0 -44
- package/src/lockfile.ts +0 -502
- package/src/mtime-precision.ts +0 -83
- package/src/retry.ts +0 -309
package/src/ignore.ts
CHANGED
|
@@ -1,40 +1,11 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
* ---------------------------------------------------------------------------
|
|
11
|
-
* Copyright (c) 2013 Kael Zhang <i@kael.me>, contributors
|
|
12
|
-
* http://kael.me/
|
|
13
|
-
*
|
|
14
|
-
* Permission is hereby granted, free of charge, to any person obtaining
|
|
15
|
-
* a copy of this software and associated documentation files (the
|
|
16
|
-
* "Software"), to deal in the Software without restriction, including
|
|
17
|
-
* without limitation the rights to use, copy, modify, merge, publish,
|
|
18
|
-
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
19
|
-
* permit persons to whom the Software is furnished to do so, subject to
|
|
20
|
-
* the following conditions:
|
|
21
|
-
*
|
|
22
|
-
* The above copyright notice and this permission notice shall be
|
|
23
|
-
* included in all copies or substantial portions of the Software.
|
|
24
|
-
*
|
|
25
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
26
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
27
|
-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
28
|
-
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
29
|
-
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
30
|
-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
31
|
-
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
32
|
-
* ---------------------------------------------------------------------------
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
// A simple implementation of make-array
|
|
36
|
-
function makeArray(subject) {
|
|
37
|
-
return Array.isArray(subject) ? subject : [subject];
|
|
1
|
+
// Alchemy modifications are licensed under Apache-2.0.
|
|
2
|
+
// This file includes third-party code; see /THIRD_PARTY_LICENSES.md.
|
|
3
|
+
//
|
|
4
|
+
// TypeScript port of `ignore` (https://github.com/kaelzhang/node-ignore) v7.0.5.
|
|
5
|
+
// Copyright (c) 2013 Kael Zhang <i@kael.me>, contributors. MIT License.
|
|
6
|
+
|
|
7
|
+
function makeArray<T>(subject: T | readonly T[]): T[] {
|
|
8
|
+
return Array.isArray(subject) ? [...subject] : [subject as T];
|
|
38
9
|
}
|
|
39
10
|
|
|
40
11
|
const UNDEFINED = undefined;
|
|
@@ -62,14 +33,14 @@ const REGEX_TEST_TRAILING_SLASH = /\/$/;
|
|
|
62
33
|
const SLASH = "/";
|
|
63
34
|
|
|
64
35
|
// Do not use ternary expression here, since "istanbul ignore next" is buggy
|
|
65
|
-
let TMP_KEY_IGNORE = "node-ignore";
|
|
36
|
+
let TMP_KEY_IGNORE: string | symbol = "node-ignore";
|
|
66
37
|
/* istanbul ignore else */
|
|
67
38
|
if (typeof Symbol !== "undefined") {
|
|
68
39
|
TMP_KEY_IGNORE = Symbol.for("node-ignore");
|
|
69
40
|
}
|
|
70
41
|
const KEY_IGNORE = TMP_KEY_IGNORE;
|
|
71
42
|
|
|
72
|
-
const define = (object, key, value) => {
|
|
43
|
+
const define = <T>(object: object, key: PropertyKey, value: T): T => {
|
|
73
44
|
Object.defineProperty(object, key, { value });
|
|
74
45
|
return value;
|
|
75
46
|
};
|
|
@@ -80,7 +51,7 @@ const RETURN_FALSE = () => false;
|
|
|
80
51
|
|
|
81
52
|
// Sanitize the range of a regular expression
|
|
82
53
|
// The cases are complicated, see test cases for details
|
|
83
|
-
const sanitizeRange = (range) =>
|
|
54
|
+
const sanitizeRange = (range: string): string =>
|
|
84
55
|
range.replace(REGEX_REGEXP_RANGE, (match, from, to) =>
|
|
85
56
|
from.charCodeAt(0) <= to.charCodeAt(0)
|
|
86
57
|
? match
|
|
@@ -89,8 +60,18 @@ const sanitizeRange = (range) =>
|
|
|
89
60
|
EMPTY,
|
|
90
61
|
);
|
|
91
62
|
|
|
63
|
+
// > An optional `!` or `^` at the start of a class negates it, so that it
|
|
64
|
+
// > matches any character not in the set. (gitignore(5), fnmatch(3))
|
|
65
|
+
// The leading `^` has already been escaped to `\^` by the metacharacter
|
|
66
|
+
// escaper, so we strip the literal `!` or escaped `^` and emit a single
|
|
67
|
+
// regex `^` which is the JavaScript negation token.
|
|
68
|
+
const negateRange = (range: string): string =>
|
|
69
|
+
range.startsWith("!") || range.startsWith("\\^")
|
|
70
|
+
? `^${range.slice(range[0] === "!" ? 1 : 2)}`
|
|
71
|
+
: range;
|
|
72
|
+
|
|
92
73
|
// See fixtures #59
|
|
93
|
-
const cleanRangeBackSlash = (slashes) => {
|
|
74
|
+
const cleanRangeBackSlash = (slashes: string): string => {
|
|
94
75
|
const { length } = slashes;
|
|
95
76
|
return slashes.slice(0, length - (length % 2));
|
|
96
77
|
};
|
|
@@ -106,7 +87,9 @@ const cleanRangeBackSlash = (slashes) => {
|
|
|
106
87
|
// you could use option `mark: true` with `glob`
|
|
107
88
|
|
|
108
89
|
// '`foo/`' should not continue with the '`..`'
|
|
109
|
-
|
|
90
|
+
type Replacer = (this: string, ...args: any[]) => string;
|
|
91
|
+
|
|
92
|
+
const REPLACERS: Array<readonly [RegExp, Replacer]> = [
|
|
110
93
|
[
|
|
111
94
|
// Remove BOM
|
|
112
95
|
// TODO:
|
|
@@ -181,7 +164,7 @@ const REPLACERS = [
|
|
|
181
164
|
// > "**/foo/bar" matches file or directory "bar" anywhere that is directly
|
|
182
165
|
// > under directory "foo".
|
|
183
166
|
// Notice that the '*'s have been replaced as '\\*'
|
|
184
|
-
|
|
167
|
+
/^\^*(?:\\\*\\\*\\\/)+/,
|
|
185
168
|
|
|
186
169
|
// '**/foo' <-> 'foo'
|
|
187
170
|
() => "^(?:.*\\/)?",
|
|
@@ -193,7 +176,7 @@ const REPLACERS = [
|
|
|
193
176
|
// (which has been replaced by section "leading slash")
|
|
194
177
|
// If starts with '**', adding a '^' to the regular expression also works
|
|
195
178
|
/^(?=[^^])/,
|
|
196
|
-
function startingReplacer() {
|
|
179
|
+
function startingReplacer(this: string) {
|
|
197
180
|
// If has a slash `/` at the beginning or middle
|
|
198
181
|
return !/\/(?!$)/.test(this)
|
|
199
182
|
? // > Prior to 2.22.1
|
|
@@ -291,7 +274,7 @@ const REPLACERS = [
|
|
|
291
274
|
? // A normal case, and it is a range notation
|
|
292
275
|
// '[bar]'
|
|
293
276
|
// '[bar\\\\]'
|
|
294
|
-
`[${sanitizeRange(range)}${endEscape}]`
|
|
277
|
+
`[${negateRange(sanitizeRange(range))}${endEscape}]`
|
|
295
278
|
: // Invalid range notaton
|
|
296
279
|
// '[bar\\]' -> '[bar\\\\]'
|
|
297
280
|
"[]"
|
|
@@ -328,10 +311,11 @@ const REPLACERS = [
|
|
|
328
311
|
const REGEX_REPLACE_TRAILING_WILDCARD = /(^|\\\/)?\\\*$/;
|
|
329
312
|
const MODE_IGNORE = "regex";
|
|
330
313
|
const MODE_CHECK_IGNORE = "checkRegex";
|
|
331
|
-
const UNDERSCORE = "_";
|
|
332
314
|
|
|
333
|
-
|
|
334
|
-
|
|
315
|
+
type MatcherMode = typeof MODE_IGNORE | typeof MODE_CHECK_IGNORE;
|
|
316
|
+
|
|
317
|
+
const TRAILING_WILD_CARD_REPLACERS: Record<MatcherMode, Replacer> = {
|
|
318
|
+
[MODE_IGNORE](_, p1: string | undefined) {
|
|
335
319
|
const prefix = p1
|
|
336
320
|
? // '\^':
|
|
337
321
|
// '/*' does not match EMPTY
|
|
@@ -347,7 +331,7 @@ const TRAILING_WILD_CARD_REPLACERS = {
|
|
|
347
331
|
return `${prefix}(?=$|\\/$)`;
|
|
348
332
|
},
|
|
349
333
|
|
|
350
|
-
[MODE_CHECK_IGNORE](_, p1) {
|
|
334
|
+
[MODE_CHECK_IGNORE](_, p1: string | undefined) {
|
|
351
335
|
// When doing `git check-ignore`
|
|
352
336
|
const prefix = p1
|
|
353
337
|
? // '\\\/':
|
|
@@ -362,29 +346,47 @@ const TRAILING_WILD_CARD_REPLACERS = {
|
|
|
362
346
|
};
|
|
363
347
|
|
|
364
348
|
// @param {pattern}
|
|
365
|
-
const makeRegexPrefix = (pattern) =>
|
|
349
|
+
const makeRegexPrefix = (pattern: string): string =>
|
|
366
350
|
REPLACERS.reduce(
|
|
367
351
|
(prev, [matcher, replacer]) =>
|
|
368
352
|
prev.replace(matcher, replacer.bind(pattern)),
|
|
369
353
|
pattern,
|
|
370
354
|
);
|
|
371
355
|
|
|
372
|
-
const isString = (subject)
|
|
356
|
+
const isString = (subject: unknown): subject is string =>
|
|
357
|
+
typeof subject === "string";
|
|
373
358
|
|
|
374
359
|
// > A blank line matches no files, so it can serve as a separator for readability.
|
|
375
|
-
const checkPattern = (pattern) =>
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
360
|
+
const checkPattern = (pattern: string): boolean =>
|
|
361
|
+
Boolean(
|
|
362
|
+
pattern &&
|
|
363
|
+
!REGEX_TEST_BLANK_LINE.test(pattern) &&
|
|
364
|
+
!REGEX_INVALID_TRAILING_BACKSLASH.test(pattern) &&
|
|
365
|
+
// > A line starting with # serves as a comment.
|
|
366
|
+
pattern.indexOf("#") !== 0,
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
const splitPattern = (pattern: string): string[] =>
|
|
384
370
|
pattern.split(REGEX_SPLITALL_CRLF).filter(Boolean);
|
|
385
371
|
|
|
386
372
|
class IgnoreRule {
|
|
387
|
-
|
|
373
|
+
readonly pattern: string;
|
|
374
|
+
readonly mark: string | undefined;
|
|
375
|
+
readonly negative: boolean;
|
|
376
|
+
readonly body!: string;
|
|
377
|
+
readonly ignoreCase!: boolean;
|
|
378
|
+
readonly regexPrefix!: string;
|
|
379
|
+
private _regex?: RegExp;
|
|
380
|
+
private _checkRegex?: RegExp;
|
|
381
|
+
|
|
382
|
+
constructor(
|
|
383
|
+
pattern: string,
|
|
384
|
+
mark: string | undefined,
|
|
385
|
+
body: string,
|
|
386
|
+
ignoreCase: boolean,
|
|
387
|
+
negative: boolean,
|
|
388
|
+
prefix: string,
|
|
389
|
+
) {
|
|
388
390
|
this.pattern = pattern;
|
|
389
391
|
this.mark = mark;
|
|
390
392
|
this.negative = negative;
|
|
@@ -395,7 +397,7 @@ class IgnoreRule {
|
|
|
395
397
|
}
|
|
396
398
|
|
|
397
399
|
get regex() {
|
|
398
|
-
const key =
|
|
400
|
+
const key = `_${MODE_IGNORE}` as const;
|
|
399
401
|
|
|
400
402
|
if (this[key]) {
|
|
401
403
|
return this[key];
|
|
@@ -405,7 +407,7 @@ class IgnoreRule {
|
|
|
405
407
|
}
|
|
406
408
|
|
|
407
409
|
get checkRegex() {
|
|
408
|
-
const key =
|
|
410
|
+
const key = `_${MODE_CHECK_IGNORE}` as const;
|
|
409
411
|
|
|
410
412
|
if (this[key]) {
|
|
411
413
|
return this[key];
|
|
@@ -414,7 +416,7 @@ class IgnoreRule {
|
|
|
414
416
|
return this._make(MODE_CHECK_IGNORE, key);
|
|
415
417
|
}
|
|
416
418
|
|
|
417
|
-
_make(mode, key) {
|
|
419
|
+
_make(mode: MatcherMode, key: "_regex" | "_checkRegex"): RegExp {
|
|
418
420
|
const str = this.regexPrefix.replace(
|
|
419
421
|
REGEX_REPLACE_TRAILING_WILDCARD,
|
|
420
422
|
|
|
@@ -428,7 +430,10 @@ class IgnoreRule {
|
|
|
428
430
|
}
|
|
429
431
|
}
|
|
430
432
|
|
|
431
|
-
const createRule = (
|
|
433
|
+
const createRule = (
|
|
434
|
+
{ pattern, mark }: PatternParams,
|
|
435
|
+
ignoreCase: boolean,
|
|
436
|
+
): IgnoreRule => {
|
|
432
437
|
let negative = false;
|
|
433
438
|
let body = pattern;
|
|
434
439
|
|
|
@@ -452,15 +457,19 @@ const createRule = ({ pattern, mark }, ignoreCase) => {
|
|
|
452
457
|
};
|
|
453
458
|
|
|
454
459
|
class RuleManager {
|
|
455
|
-
|
|
460
|
+
private readonly _ignoreCase: boolean;
|
|
461
|
+
_rules: IgnoreRule[] = [];
|
|
462
|
+
private _added = false;
|
|
463
|
+
|
|
464
|
+
constructor(ignoreCase: boolean) {
|
|
456
465
|
this._ignoreCase = ignoreCase;
|
|
457
|
-
this._rules = [];
|
|
458
466
|
}
|
|
459
467
|
|
|
460
|
-
_add(pattern) {
|
|
468
|
+
_add(pattern: string | Ignore | PatternParams): void {
|
|
461
469
|
// #32
|
|
462
|
-
|
|
463
|
-
|
|
470
|
+
const ignorePattern = pattern as Ignore & Record<PropertyKey, unknown>;
|
|
471
|
+
if (pattern && ignorePattern[KEY_IGNORE]) {
|
|
472
|
+
this._rules = this._rules.concat(ignorePattern._rules._rules);
|
|
464
473
|
this._added = true;
|
|
465
474
|
return;
|
|
466
475
|
}
|
|
@@ -471,21 +480,28 @@ class RuleManager {
|
|
|
471
480
|
};
|
|
472
481
|
}
|
|
473
482
|
|
|
474
|
-
|
|
475
|
-
|
|
483
|
+
const patternParams = pattern as PatternParams;
|
|
484
|
+
if (checkPattern(patternParams.pattern)) {
|
|
485
|
+
const rule = createRule(patternParams, this._ignoreCase);
|
|
476
486
|
this._added = true;
|
|
477
487
|
this._rules.push(rule);
|
|
478
488
|
}
|
|
479
489
|
}
|
|
480
490
|
|
|
481
491
|
// @param {Array<string> | string | Ignore} pattern
|
|
482
|
-
add(
|
|
492
|
+
add(
|
|
493
|
+
pattern: string | Ignore | PatternParams | readonly (string | Ignore)[],
|
|
494
|
+
): boolean {
|
|
483
495
|
this._added = false;
|
|
484
496
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
497
|
+
const patterns: readonly (string | Ignore | PatternParams)[] = isString(
|
|
498
|
+
pattern,
|
|
499
|
+
)
|
|
500
|
+
? splitPattern(pattern)
|
|
501
|
+
: Array.isArray(pattern)
|
|
502
|
+
? pattern
|
|
503
|
+
: [pattern as Ignore | PatternParams];
|
|
504
|
+
patterns.forEach(this._add, this);
|
|
489
505
|
|
|
490
506
|
return this._added;
|
|
491
507
|
}
|
|
@@ -498,10 +514,14 @@ class RuleManager {
|
|
|
498
514
|
// - check `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
|
|
499
515
|
|
|
500
516
|
// @returns {TestResult} true if a file is ignored
|
|
501
|
-
test(
|
|
517
|
+
test(
|
|
518
|
+
path: string,
|
|
519
|
+
checkUnignored: boolean,
|
|
520
|
+
mode: MatcherMode,
|
|
521
|
+
): IgnoreTestResult {
|
|
502
522
|
let ignored = false;
|
|
503
523
|
let unignored = false;
|
|
504
|
-
let matchedRule;
|
|
524
|
+
let matchedRule: IgnoreRule | undefined;
|
|
505
525
|
|
|
506
526
|
this._rules.forEach((rule) => {
|
|
507
527
|
const { negative } = rule;
|
|
@@ -536,7 +556,7 @@ class RuleManager {
|
|
|
536
556
|
matchedRule = negative ? UNDEFINED : rule;
|
|
537
557
|
});
|
|
538
558
|
|
|
539
|
-
const ret = {
|
|
559
|
+
const ret: IgnoreTestResult = {
|
|
540
560
|
ignored,
|
|
541
561
|
unignored,
|
|
542
562
|
};
|
|
@@ -549,11 +569,23 @@ class RuleManager {
|
|
|
549
569
|
}
|
|
550
570
|
}
|
|
551
571
|
|
|
552
|
-
|
|
572
|
+
type ErrorConstructor = new (message: string) => Error;
|
|
573
|
+
type InvalidPathHandler = (
|
|
574
|
+
message: string,
|
|
575
|
+
constructor: ErrorConstructor,
|
|
576
|
+
) => boolean;
|
|
577
|
+
|
|
578
|
+
const throwError: InvalidPathHandler = (message, Ctor) => {
|
|
553
579
|
throw new Ctor(message);
|
|
554
580
|
};
|
|
555
581
|
|
|
556
|
-
|
|
582
|
+
interface CheckPath {
|
|
583
|
+
(path: unknown, originalPath: unknown, doThrow: InvalidPathHandler): boolean;
|
|
584
|
+
isNotRelative: (path: string) => boolean;
|
|
585
|
+
convert: (path: string) => string;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
const checkPath: CheckPath = (path, originalPath, doThrow) => {
|
|
557
589
|
if (!isString(path)) {
|
|
558
590
|
return doThrow(
|
|
559
591
|
`path must be a string, but got \`${originalPath}\``,
|
|
@@ -578,20 +610,27 @@ const checkPath = (path, originalPath, doThrow) => {
|
|
|
578
610
|
return true;
|
|
579
611
|
};
|
|
580
612
|
|
|
581
|
-
const isNotRelative = (path) =>
|
|
613
|
+
const isNotRelative = (path: string): boolean =>
|
|
614
|
+
REGEX_TEST_INVALID_PATH.test(path);
|
|
582
615
|
|
|
583
616
|
checkPath.isNotRelative = isNotRelative;
|
|
584
617
|
|
|
585
618
|
// On windows, the following function will be replaced
|
|
586
619
|
/* istanbul ignore next */
|
|
587
|
-
checkPath.convert = (
|
|
620
|
+
checkPath.convert = (path) => path;
|
|
588
621
|
|
|
589
622
|
class Ignore {
|
|
623
|
+
readonly [KEY_IGNORE]?: true;
|
|
624
|
+
readonly _rules: RuleManager;
|
|
625
|
+
private readonly _strictPathCheck: boolean;
|
|
626
|
+
private _ignoreCache!: Record<string, IgnoreTestResult>;
|
|
627
|
+
private _testCache!: Record<string, IgnoreTestResult>;
|
|
628
|
+
|
|
590
629
|
constructor({
|
|
591
630
|
ignorecase = true,
|
|
592
631
|
ignoreCase = ignorecase,
|
|
593
632
|
allowRelativePaths = false,
|
|
594
|
-
} = {}) {
|
|
633
|
+
}: IgnoreOptions = {}) {
|
|
595
634
|
define(this, KEY_IGNORE, true);
|
|
596
635
|
|
|
597
636
|
this._rules = new RuleManager(ignoreCase);
|
|
@@ -599,7 +638,7 @@ class Ignore {
|
|
|
599
638
|
this._initCache();
|
|
600
639
|
}
|
|
601
640
|
|
|
602
|
-
_initCache() {
|
|
641
|
+
_initCache(): void {
|
|
603
642
|
// A cache for the result of `.ignores()`
|
|
604
643
|
this._ignoreCache = Object.create(null);
|
|
605
644
|
|
|
@@ -607,7 +646,9 @@ class Ignore {
|
|
|
607
646
|
this._testCache = Object.create(null);
|
|
608
647
|
}
|
|
609
648
|
|
|
610
|
-
add(
|
|
649
|
+
add(
|
|
650
|
+
pattern: string | Ignore | readonly (string | Ignore)[] | PatternParams,
|
|
651
|
+
): this {
|
|
611
652
|
if (this._rules.add(pattern)) {
|
|
612
653
|
// Some rules have just added to the ignore,
|
|
613
654
|
// making the behavior changed,
|
|
@@ -619,12 +660,17 @@ class Ignore {
|
|
|
619
660
|
}
|
|
620
661
|
|
|
621
662
|
// legacy
|
|
622
|
-
addPattern(pattern) {
|
|
663
|
+
addPattern(pattern: string | readonly string[]): this {
|
|
623
664
|
return this.add(pattern);
|
|
624
665
|
}
|
|
625
666
|
|
|
626
667
|
// @returns {TestResult}
|
|
627
|
-
_test(
|
|
668
|
+
_test(
|
|
669
|
+
originalPath: string,
|
|
670
|
+
cache: Record<string, IgnoreTestResult>,
|
|
671
|
+
checkUnignored: boolean,
|
|
672
|
+
slices?: string[],
|
|
673
|
+
): IgnoreTestResult {
|
|
628
674
|
const path =
|
|
629
675
|
originalPath &&
|
|
630
676
|
// Supports nullable path
|
|
@@ -639,7 +685,7 @@ class Ignore {
|
|
|
639
685
|
return this._t(path, cache, checkUnignored, slices);
|
|
640
686
|
}
|
|
641
687
|
|
|
642
|
-
checkIgnore(path) {
|
|
688
|
+
checkIgnore(path: string): IgnoreTestResult {
|
|
643
689
|
// If the path doest not end with a slash, `.ignores()` is much equivalent
|
|
644
690
|
// to `git check-ignore`
|
|
645
691
|
if (!REGEX_TEST_TRAILING_SLASH.test(path)) {
|
|
@@ -667,17 +713,17 @@ class Ignore {
|
|
|
667
713
|
|
|
668
714
|
_t(
|
|
669
715
|
// The path to be tested
|
|
670
|
-
path,
|
|
716
|
+
path: string,
|
|
671
717
|
|
|
672
718
|
// The cache for the result of a certain checking
|
|
673
|
-
cache,
|
|
719
|
+
cache: Record<string, IgnoreTestResult>,
|
|
674
720
|
|
|
675
721
|
// Whether should check if the path is unignored
|
|
676
|
-
checkUnignored,
|
|
722
|
+
checkUnignored: boolean,
|
|
677
723
|
|
|
678
724
|
// The path slices
|
|
679
|
-
slices,
|
|
680
|
-
) {
|
|
725
|
+
slices?: string[],
|
|
726
|
+
): IgnoreTestResult {
|
|
681
727
|
if (path in cache) {
|
|
682
728
|
return cache[path];
|
|
683
729
|
}
|
|
@@ -714,33 +760,33 @@ class Ignore {
|
|
|
714
760
|
: this._rules.test(path, checkUnignored, MODE_IGNORE));
|
|
715
761
|
}
|
|
716
762
|
|
|
717
|
-
ignores(path) {
|
|
763
|
+
ignores(path: string): boolean {
|
|
718
764
|
return this._test(path, this._ignoreCache, false).ignored;
|
|
719
765
|
}
|
|
720
766
|
|
|
721
|
-
createFilter() {
|
|
722
|
-
return (path) => !this.ignores(path);
|
|
767
|
+
createFilter(): (path: string) => boolean {
|
|
768
|
+
return (path: string) => !this.ignores(path);
|
|
723
769
|
}
|
|
724
770
|
|
|
725
|
-
filter(paths) {
|
|
771
|
+
filter(paths: readonly string[]): string[] {
|
|
726
772
|
return makeArray(paths).filter(this.createFilter());
|
|
727
773
|
}
|
|
728
774
|
|
|
729
775
|
// @returns {TestResult}
|
|
730
|
-
test(path) {
|
|
776
|
+
test(path: string): IgnoreTestResult {
|
|
731
777
|
return this._test(path, this._testCache, true);
|
|
732
778
|
}
|
|
733
779
|
}
|
|
734
780
|
|
|
735
|
-
const factory = (options) => new Ignore(options);
|
|
781
|
+
const factory = (options?: IgnoreOptions): Ignore => new Ignore(options);
|
|
736
782
|
|
|
737
|
-
const isPathValid = (path) =>
|
|
783
|
+
const isPathValid = (path: string): boolean =>
|
|
738
784
|
checkPath(path && checkPath.convert(path), path, RETURN_FALSE);
|
|
739
785
|
|
|
740
786
|
/* istanbul ignore next */
|
|
741
787
|
const setupWindows = () => {
|
|
742
788
|
/* eslint no-control-regex: "off" */
|
|
743
|
-
const makePosix = (str) =>
|
|
789
|
+
const makePosix = (str: string): string =>
|
|
744
790
|
/^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str)
|
|
745
791
|
? str
|
|
746
792
|
: str.replace(/\\/g, "/");
|
|
@@ -750,7 +796,7 @@ const setupWindows = () => {
|
|
|
750
796
|
// 'C:\\foo' <- 'C:\\foo' has been converted to 'C:/'
|
|
751
797
|
// 'd:\\foo'
|
|
752
798
|
const REGEX_TEST_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
|
|
753
|
-
checkPath.isNotRelative = (path) =>
|
|
799
|
+
checkPath.isNotRelative = (path: string) =>
|
|
754
800
|
REGEX_TEST_WINDOWS_PATH_ABSOLUTE.test(path) || isNotRelative(path);
|
|
755
801
|
};
|
|
756
802
|
|
|
@@ -772,7 +818,7 @@ if (
|
|
|
772
818
|
export default factory as unknown as (
|
|
773
819
|
options?: IgnoreOptions,
|
|
774
820
|
) => IgnoreInstance;
|
|
775
|
-
export {
|
|
821
|
+
export { Ignore, isPathValid };
|
|
776
822
|
|
|
777
823
|
// --- Type declarations -----------------------------------------------------
|
|
778
824
|
// (not part of the verbatim upstream source; mirrors upstream `index.d.ts`)
|
|
@@ -784,6 +830,12 @@ interface PatternParams {
|
|
|
784
830
|
mark?: string;
|
|
785
831
|
}
|
|
786
832
|
|
|
833
|
+
interface IgnoreTestResult {
|
|
834
|
+
ignored: boolean;
|
|
835
|
+
unignored: boolean;
|
|
836
|
+
rule?: IgnoreRule;
|
|
837
|
+
}
|
|
838
|
+
|
|
787
839
|
export interface IgnoreOptions {
|
|
788
840
|
ignorecase?: boolean;
|
|
789
841
|
/** For compatibility. */
|
package/lib/adapter.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
type AnyFs = Record<string, any>;
|
|
2
|
-
type AsyncMethod = (...args: any[]) => void;
|
|
3
|
-
export declare function toPromise<T = any>(method: AsyncMethod): (...args: any[]) => Promise<T>;
|
|
4
|
-
export declare function toSync<T = any>(method: AsyncMethod): (...args: any[]) => T;
|
|
5
|
-
export interface SyncOptions {
|
|
6
|
-
fs?: AnyFs;
|
|
7
|
-
retries?: number | {
|
|
8
|
-
retries?: number;
|
|
9
|
-
};
|
|
10
|
-
[key: string]: any;
|
|
11
|
-
}
|
|
12
|
-
export declare function toSyncOptions(options?: SyncOptions): SyncOptions;
|
|
13
|
-
export {};
|
|
14
|
-
//# sourceMappingURL=adapter.d.ts.map
|
package/lib/adapter.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAEA,KAAK,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEjC,KAAK,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AA0B5C,wBAAgB,SAAS,CAAC,CAAC,GAAG,GAAG,EAC/B,MAAM,EAAE,WAAW,GAClB,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,CAahC;AAED,wBAAgB,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,MAAM,EAAE,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAkB1E;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,CAAC,EAAE,KAAK,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,GAAG;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACxC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,WAAW,CAoBhE"}
|
package/lib/adapter.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
function createSyncFs(fs) {
|
|
3
|
-
const methods = ["mkdir", "realpath", "stat", "rmdir", "utimes"];
|
|
4
|
-
const newFs = { ...fs };
|
|
5
|
-
methods.forEach((method) => {
|
|
6
|
-
newFs[method] = (...args) => {
|
|
7
|
-
const callback = args.pop();
|
|
8
|
-
let ret;
|
|
9
|
-
try {
|
|
10
|
-
ret = fs[`${method}Sync`](...args);
|
|
11
|
-
}
|
|
12
|
-
catch (err) {
|
|
13
|
-
return callback(err);
|
|
14
|
-
}
|
|
15
|
-
callback(null, ret);
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
return newFs;
|
|
19
|
-
}
|
|
20
|
-
// ----------------------------------------------------------
|
|
21
|
-
export function toPromise(method) {
|
|
22
|
-
return (...args) => new Promise((resolve, reject) => {
|
|
23
|
-
args.push((err, result) => {
|
|
24
|
-
if (err) {
|
|
25
|
-
reject(err);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
resolve(result);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
method(...args);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
export function toSync(method) {
|
|
35
|
-
return (...args) => {
|
|
36
|
-
let err;
|
|
37
|
-
let result;
|
|
38
|
-
args.push((_err, _result) => {
|
|
39
|
-
err = _err;
|
|
40
|
-
result = _result;
|
|
41
|
-
});
|
|
42
|
-
method(...args);
|
|
43
|
-
if (err) {
|
|
44
|
-
throw err;
|
|
45
|
-
}
|
|
46
|
-
return result;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
export function toSyncOptions(options) {
|
|
50
|
-
// Shallow clone options because we are going to mutate them
|
|
51
|
-
const next = { ...options };
|
|
52
|
-
// Transform fs to use the sync methods instead
|
|
53
|
-
next.fs = createSyncFs(next.fs || fs);
|
|
54
|
-
// Retries are not allowed because it requires the flow to be sync
|
|
55
|
-
if ((typeof next.retries === "number" && next.retries > 0) ||
|
|
56
|
-
(next.retries &&
|
|
57
|
-
typeof next.retries.retries === "number" &&
|
|
58
|
-
next.retries.retries > 0)) {
|
|
59
|
-
throw Object.assign(new Error("Cannot use retries with the sync api"), {
|
|
60
|
-
code: "ESYNC",
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
return next;
|
|
64
|
-
}
|
|
65
|
-
//# sourceMappingURL=adapter.js.map
|
package/lib/adapter.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAMzB,SAAS,YAAY,CAAC,EAAS;IAC7B,MAAM,OAAO,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAU,CAAC;IAC1E,MAAM,KAAK,GAAU,EAAE,GAAG,EAAE,EAAE,CAAC;IAE/B,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QACzB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE;YACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAiB,CAAC;YAC3C,IAAI,GAAG,CAAC;YAER,IAAI,CAAC;gBACH,GAAG,GAAG,EAAE,CAAC,GAAG,MAAM,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;YACrC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,QAAQ,CAAC,GAA4B,CAAC,CAAC;YAChD,CAAC;YAED,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC;AAED,6DAA6D;AAE7D,MAAM,UAAU,SAAS,CACvB,MAAmB;IAEnB,OAAO,CAAC,GAAG,IAAW,EAAE,EAAE,CACxB,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACjC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAiC,EAAE,MAAS,EAAE,EAAE;YACzD,IAAI,GAAG,EAAE,CAAC;gBACR,MAAM,CAAC,GAAG,CAAC,CAAC;YACd,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACP,CAAC;AAED,MAAM,UAAU,MAAM,CAAU,MAAmB;IACjD,OAAO,CAAC,GAAG,IAAW,EAAE,EAAE;QACxB,IAAI,GAA6C,CAAC;QAClD,IAAI,MAAqB,CAAC;QAE1B,IAAI,CAAC,IAAI,CAAC,CAAC,IAAkC,EAAE,OAAU,EAAE,EAAE;YAC3D,GAAG,GAAG,IAAI,CAAC;YACX,MAAM,GAAG,OAAO,CAAC;QACnB,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;QAEhB,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,GAAG,CAAC;QACZ,CAAC;QAED,OAAO,MAAW,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC;AAQD,MAAM,UAAU,aAAa,CAAC,OAAqB;IACjD,4DAA4D;IAC5D,MAAM,IAAI,GAAgB,EAAE,GAAG,OAAO,EAAE,CAAC;IAEzC,+CAA+C;IAC/C,IAAI,CAAC,EAAE,GAAG,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IAEtC,kEAAkE;IAClE,IACE,CAAC,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;QACtD,CAAC,IAAI,CAAC,OAAO;YACX,OAAQ,IAAI,CAAC,OAAgC,CAAC,OAAO,KAAK,QAAQ;YAChE,IAAI,CAAC,OAAgC,CAAC,OAAkB,GAAG,CAAC,CAAC,EACjE,CAAC;QACD,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,sCAAsC,CAAC,EAAE;YACrE,IAAI,EAAE,OAAO;SACd,CAAC,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/lib/exit-hook.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lightweight replacement for the `exit-hook` npm package.
|
|
3
|
-
*
|
|
4
|
-
* The third-party `exit-hook` registers process listeners (`exit`, `SIGINT`,
|
|
5
|
-
* `SIGTERM`, and `message`) that are never removed — even after every
|
|
6
|
-
* callback has been unregistered. Those dangling listeners are harmless in
|
|
7
|
-
* long-running processes, but in short-lived child processes (e.g. those
|
|
8
|
-
* spawned by `node --test`) they can prevent clean exit by holding refs on
|
|
9
|
-
* handles such as the IPC channel.
|
|
10
|
-
*
|
|
11
|
-
* This module tracks the number of active registrations and removes **all**
|
|
12
|
-
* process listeners once the last registration is unregistered, so they
|
|
13
|
-
* cannot keep the event loop alive after dispose.
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* Register a callback to run when the process exits. Returns a function
|
|
17
|
-
* that unregisters the callback. When the last callback is unregistered,
|
|
18
|
-
* all underlying process listeners are removed so they cannot keep the
|
|
19
|
-
* event loop alive.
|
|
20
|
-
*/
|
|
21
|
-
export declare function exitHook(callback: () => void): () => void;
|
|
22
|
-
//# sourceMappingURL=exit-hook.d.ts.map
|
package/lib/exit-hook.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exit-hook.d.ts","sourceRoot":"","sources":["../src/exit-hook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AA+DH;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAazD"}
|