js-build-tools 3.0.0 → 3.0.1

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.
Files changed (63) hide show
  1. package/dist/build.js +59 -59
  2. package/dist/bundle.js +12 -12
  3. package/dist/bundleLint.js +17 -17
  4. package/dist/bundleMinify.js +8 -8
  5. package/dist/copyFonts.js +8 -8
  6. package/dist/default.js +15 -15
  7. package/dist/distLint.js +17 -17
  8. package/dist/distMinify.js +8 -8
  9. package/dist/partials/addToReadme.js +13 -13
  10. package/dist/partials/beginWatcher.js +9 -9
  11. package/dist/partials/distFor.js +16 -16
  12. package/dist/partials/distForSrc.js +9 -9
  13. package/dist/partials/distSeries.js +19 -19
  14. package/dist/partials/imagesFor.js +27 -27
  15. package/dist/partials/readmeTemplate.js +11 -11
  16. package/dist/partials/runOnChange.js +27 -27
  17. package/dist/partials/sassFor.js +20 -20
  18. package/dist/partials/tsFor.js +20 -20
  19. package/dist/partials.js +34 -34
  20. package/dist/test-helpers/setUp.js +51 -51
  21. package/dist/testFull.js +17 -17
  22. package/dist/testHelpers.js +8 -8
  23. package/dist/testQuick.js +19 -19
  24. package/dist/utilities/dotGet.js +42 -42
  25. package/dist/utilities/dotNotate.js +50 -50
  26. package/dist/utilities/dotSet.js +36 -36
  27. package/dist/utilities/isObject.js +4 -4
  28. package/dist/utilities/strAfter.js +14 -0
  29. package/dist/utilities/strBefore.js +14 -0
  30. package/dist/watchTest.js +13 -13
  31. package/functions/utilities/dotGet.js +2 -2
  32. package/functions/utilities/dotSet.js +2 -2
  33. package/functions/utilities/strAfter.js +13 -0
  34. package/functions/utilities/strBefore.js +13 -0
  35. package/package.json +3 -3
  36. package/vendor/array-union/index.js +30 -30
  37. package/vendor/easy-transform-stream/index.js +54 -58
  38. package/vendor/globby/gitignore.js +96 -100
  39. package/vendor/globby/index.js +191 -195
  40. package/vendor/globby/stream-utils.js +57 -57
  41. package/vendor/globby/to-path.js +19 -19
  42. package/vendor/gulp-plugin-extras/index.js +42 -46
  43. package/vendor/gulp-plugin-extras/plugin-error.js +144 -144
  44. package/vendor/ignore/index.js +467 -467
  45. package/vendor/imagemin/index.js +90 -94
  46. package/vendor/imagemin-gifsicle/index.js +33 -37
  47. package/vendor/imagemin-mozjpeg/index.js +100 -104
  48. package/vendor/imagemin-mozjpeg/node_modules/execa/index.js +2 -6
  49. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/kill.js +2 -2
  50. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/stream.js +2 -6
  51. package/vendor/imagemin-optipng/index.js +43 -43
  52. package/vendor/imagemin-svgo/index.js +26 -26
  53. package/vendor/is-jpg/index.js +11 -11
  54. package/vendor/junk/index.js +48 -48
  55. package/vendor/mozjpeg/index.js +8 -8
  56. package/vendor/mozjpeg/lib/index.js +17 -17
  57. package/vendor/mozjpeg/package.json +49 -50
  58. package/vendor/mozjpeg/vendor/cjpeg +0 -0
  59. package/vendor/mozjpeg/vendor/source/mozjpeg.tar.gz +0 -0
  60. package/vendor/p-pipe/index.js +22 -26
  61. package/vendor/plur/index.js +31 -31
  62. package/vendor/pretty-bytes/index.js +70 -70
  63. package/vendor/slash/index.js +11 -11
@@ -1,468 +1,468 @@
1
- "use strict";
2
-
3
- require("core-js/modules/es.string.replace.js");
4
- require("core-js/modules/esnext.async-iterator.filter.js");
5
- require("core-js/modules/esnext.async-iterator.for-each.js");
6
- require("core-js/modules/esnext.async-iterator.reduce.js");
7
- require("core-js/modules/esnext.iterator.constructor.js");
8
- require("core-js/modules/esnext.iterator.filter.js");
9
- require("core-js/modules/esnext.iterator.for-each.js");
10
- require("core-js/modules/esnext.iterator.reduce.js");
11
- // A simple implementation of make-array
12
- function makeArray(subject) {
13
- return Array.isArray(subject) ? subject : [subject];
14
- }
15
- const EMPTY = '';
16
- const SPACE = ' ';
17
- const ESCAPE = '\\';
18
- const REGEX_TEST_BLANK_LINE = /^\s+$/;
19
- const REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
20
- const REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
21
- const REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
22
- const REGEX_SPLITALL_CRLF = /\r?\n/g;
23
- // /foo,
24
- // ./foo,
25
- // ../foo,
26
- // .
27
- // ..
28
- const REGEX_TEST_INVALID_PATH = /^\.*\/|^\.+$/;
29
- const SLASH = '/';
30
-
31
- // Do not use ternary expression here, since "istanbul ignore next" is buggy
32
- let TMP_KEY_IGNORE = 'node-ignore';
33
- /* istanbul ignore else */
34
- if (typeof Symbol !== 'undefined') {
35
- TMP_KEY_IGNORE = Symbol.for('node-ignore');
36
- }
37
- const KEY_IGNORE = TMP_KEY_IGNORE;
38
- const define = (object, key, value) => Object.defineProperty(object, key, {
39
- value
40
- });
41
- const REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g;
42
- const RETURN_FALSE = () => false;
43
-
44
- // Sanitize the range of a regular expression
45
- // The cases are complicated, see test cases for details
46
- const sanitizeRange = range => range.replace(REGEX_REGEXP_RANGE, (match, from, to) => from.charCodeAt(0) <= to.charCodeAt(0) ? match
47
- // Invalid range (out of order) which is ok for gitignore rules but
48
- // fatal for JavaScript regular expression, so eliminate it.
49
- : EMPTY);
50
-
51
- // See fixtures #59
52
- const cleanRangeBackSlash = slashes => {
53
- const {
54
- length
55
- } = slashes;
56
- return slashes.slice(0, length - length % 2);
57
- };
58
-
59
- // > If the pattern ends with a slash,
60
- // > it is removed for the purpose of the following description,
61
- // > but it would only find a match with a directory.
62
- // > In other words, foo/ will match a directory foo and paths underneath it,
63
- // > but will not match a regular file or a symbolic link foo
64
- // > (this is consistent with the way how pathspec works in general in Git).
65
- // '`foo/`' will not match regular file '`foo`' or symbolic link '`foo`'
66
- // -> ignore-rules will not deal with it, because it costs extra `fs.stat` call
67
- // you could use option `mark: true` with `glob`
68
-
69
- // '`foo/`' should not continue with the '`..`'
70
- const REPLACERS = [[
71
- // remove BOM
72
- // TODO:
73
- // Other similar zero-width characters?
74
- /^\uFEFF/, () => EMPTY],
75
- // > Trailing spaces are ignored unless they are quoted with backslash ("\")
76
- [
77
- // (a\ ) -> (a )
78
- // (a ) -> (a)
79
- // (a \ ) -> (a )
80
- /\\?\s+$/, match => match.indexOf('\\') === 0 ? SPACE : EMPTY],
81
- // replace (\ ) with ' '
82
- [/\\\s/g, () => SPACE],
83
- // Escape metacharacters
84
- // which is written down by users but means special for regular expressions.
85
-
86
- // > There are 12 characters with special meanings:
87
- // > - the backslash \,
88
- // > - the caret ^,
89
- // > - the dollar sign $,
90
- // > - the period or dot .,
91
- // > - the vertical bar or pipe symbol |,
92
- // > - the question mark ?,
93
- // > - the asterisk or star *,
94
- // > - the plus sign +,
95
- // > - the opening parenthesis (,
96
- // > - the closing parenthesis ),
97
- // > - and the opening square bracket [,
98
- // > - the opening curly brace {,
99
- // > These special characters are often called "metacharacters".
100
- [/[\\$.|*+(){^]/g, match => "\\".concat(match)], [
101
- // > a question mark (?) matches a single character
102
- /(?!\\)\?/g, () => '[^/]'],
103
- // leading slash
104
- [
105
- // > A leading slash matches the beginning of the pathname.
106
- // > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
107
- // A leading slash matches the beginning of the pathname
108
- /^\//, () => '^'],
109
- // replace special metacharacter slash after the leading slash
110
- [/\//g, () => '\\/'], [
111
- // > A leading "**" followed by a slash means match in all directories.
112
- // > For example, "**/foo" matches file or directory "foo" anywhere,
113
- // > the same as pattern "foo".
114
- // > "**/foo/bar" matches file or directory "bar" anywhere that is directly
115
- // > under directory "foo".
116
- // Notice that the '*'s have been replaced as '\\*'
117
- /^\^*\\\*\\\*\\\//,
118
- // '**/foo' <-> 'foo'
119
- () => '^(?:.*\\/)?'],
120
- // starting
121
- [
122
- // there will be no leading '/'
123
- // (which has been replaced by section "leading slash")
124
- // If starts with '**', adding a '^' to the regular expression also works
125
- /^(?=[^^])/, function startingReplacer() {
126
- // If has a slash `/` at the beginning or middle
127
- return !/\/(?!$)/.test(this)
128
- // > Prior to 2.22.1
129
- // > If the pattern does not contain a slash /,
130
- // > Git treats it as a shell glob pattern
131
- // Actually, if there is only a trailing slash,
132
- // git also treats it as a shell glob pattern
133
-
134
- // After 2.22.1 (compatible but clearer)
135
- // > If there is a separator at the beginning or middle (or both)
136
- // > of the pattern, then the pattern is relative to the directory
137
- // > level of the particular .gitignore file itself.
138
- // > Otherwise the pattern may also match at any level below
139
- // > the .gitignore level.
140
- ? '(?:^|\\/)'
141
-
142
- // > Otherwise, Git treats the pattern as a shell glob suitable for
143
- // > consumption by fnmatch(3)
144
- : '^';
145
- }],
146
- // two globstars
147
- [
148
- // Use lookahead assertions so that we could match more than one `'/**'`
149
- /\\\/\\\*\\\*(?=\\\/|$)/g,
150
- // Zero, one or several directories
151
- // should not use '*', or it will be replaced by the next replacer
152
-
153
- // Check if it is not the last `'/**'`
154
- (_, index, str) => index + 6 < str.length
155
-
156
- // case: /**/
157
- // > A slash followed by two consecutive asterisks then a slash matches
158
- // > zero or more directories.
159
- // > For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
160
- // '/**/'
161
- ? '(?:\\/[^\\/]+)*'
162
-
163
- // case: /**
164
- // > A trailing `"/**"` matches everything inside.
165
-
166
- // #21: everything inside but it should not include the current folder
167
- : '\\/.+'],
168
- // normal intermediate wildcards
169
- [
170
- // Never replace escaped '*'
171
- // ignore rule '\*' will match the path '*'
172
-
173
- // 'abc.*/' -> go
174
- // 'abc.*' -> skip this rule,
175
- // coz trailing single wildcard will be handed by [trailing wildcard]
176
- /(^|[^\\]+)(\\\*)+(?=.+)/g,
177
- // '*.js' matches '.js'
178
- // '*.js' doesn't match 'abc'
179
- (_, p1, p2) => {
180
- // 1.
181
- // > An asterisk "*" matches anything except a slash.
182
- // 2.
183
- // > Other consecutive asterisks are considered regular asterisks
184
- // > and will match according to the previous rules.
185
- const unescaped = p2.replace(/\\\*/g, '[^\\/]*');
186
- return p1 + unescaped;
187
- }], [
188
- // unescape, revert step 3 except for back slash
189
- // For example, if a user escape a '\\*',
190
- // after step 3, the result will be '\\\\\\*'
191
- /\\\\\\(?=[$.|*+(){^])/g, () => ESCAPE], [
192
- // '\\\\' -> '\\'
193
- /\\\\/g, () => ESCAPE], [
194
- // > The range notation, e.g. [a-zA-Z],
195
- // > can be used to match one of the characters in a range.
196
-
197
- // `\` is escaped by step 3
198
- /(\\)?\[([^\]/]*?)(\\*)($|\])/g, (match, leadEscape, range, endEscape, close) => leadEscape === ESCAPE
199
- // '\\[bar]' -> '\\\\[bar\\]'
200
- ? "\\[".concat(range).concat(cleanRangeBackSlash(endEscape)).concat(close) : close === ']' ? endEscape.length % 2 === 0
201
- // A normal case, and it is a range notation
202
- // '[bar]'
203
- // '[bar\\\\]'
204
- ? "[".concat(sanitizeRange(range)).concat(endEscape, "]") // Invalid range notaton
205
- // '[bar\\]' -> '[bar\\\\]'
206
- : '[]' : '[]'],
207
- // ending
208
- [
209
- // 'js' will not match 'js.'
210
- // 'ab' will not match 'abc'
211
- /(?:[^*])$/,
212
- // WTF!
213
- // https://git-scm.com/docs/gitignore
214
- // changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
215
- // which re-fixes #24, #38
216
-
217
- // > If there is a separator at the end of the pattern then the pattern
218
- // > will only match directories, otherwise the pattern can match both
219
- // > files and directories.
220
-
221
- // 'js*' will not match 'a.js'
222
- // 'js/' will not match 'a.js'
223
- // 'js' will match 'a.js' and 'a.js/'
224
- match => /\/$/.test(match)
225
- // foo/ will not match 'foo'
226
- ? "".concat(match, "$") // foo matches 'foo' and 'foo/'
227
- : "".concat(match, "(?=$|\\/$)")],
228
- // trailing wildcard
229
- [/(\^|\\\/)?\\\*$/, (_, p1) => {
230
- const prefix = p1
231
- // '\^':
232
- // '/*' does not match EMPTY
233
- // '/*' does not match everything
234
-
235
- // '\\\/':
236
- // 'abc/*' does not match 'abc/'
237
- ? "".concat(p1, "[^/]+") // 'a*' matches 'a'
238
- // 'a*' matches 'aa'
239
- : '[^/]*';
240
- return "".concat(prefix, "(?=$|\\/$)");
241
- }]];
242
-
243
- // A simple cache, because an ignore rule only has only one certain meaning
244
- const regexCache = Object.create(null);
245
-
246
- // @param {pattern}
247
- const makeRegex = (pattern, ignoreCase) => {
248
- let source = regexCache[pattern];
249
- if (!source) {
250
- source = REPLACERS.reduce((prev, current) => prev.replace(current[0], current[1].bind(pattern)), pattern);
251
- regexCache[pattern] = source;
252
- }
253
- return ignoreCase ? new RegExp(source, 'i') : new RegExp(source);
254
- };
255
- const isString = subject => typeof subject === 'string';
256
-
257
- // > A blank line matches no files, so it can serve as a separator for readability.
258
- const checkPattern = pattern => pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern)
259
-
260
- // > A line starting with # serves as a comment.
261
- && pattern.indexOf('#') !== 0;
262
- const splitPattern = pattern => pattern.split(REGEX_SPLITALL_CRLF);
263
- class IgnoreRule {
264
- constructor(origin, pattern, negative, regex) {
265
- this.origin = origin;
266
- this.pattern = pattern;
267
- this.negative = negative;
268
- this.regex = regex;
269
- }
270
- }
271
- const createRule = (pattern, ignoreCase) => {
272
- const origin = pattern;
273
- let negative = false;
274
-
275
- // > An optional prefix "!" which negates the pattern;
276
- if (pattern.indexOf('!') === 0) {
277
- negative = true;
278
- pattern = pattern.substr(1);
279
- }
280
- pattern = pattern
281
- // > Put a backslash ("\") in front of the first "!" for patterns that
282
- // > begin with a literal "!", for example, `"\!important!.txt"`.
283
- .replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, '!')
284
- // > Put a backslash ("\") in front of the first hash for patterns that
285
- // > begin with a hash.
286
- .replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#');
287
- const regex = makeRegex(pattern, ignoreCase);
288
- return new IgnoreRule(origin, pattern, negative, regex);
289
- };
290
- const throwError = (message, Ctor) => {
291
- throw new Ctor(message);
292
- };
293
- const checkPath = (path, originalPath, doThrow) => {
294
- if (!isString(path)) {
295
- return doThrow("path must be a string, but got `".concat(originalPath, "`"), TypeError);
296
- }
297
-
298
- // We don't know if we should ignore EMPTY, so throw
299
- if (!path) {
300
- return doThrow("path must not be empty", TypeError);
301
- }
302
-
303
- // Check if it is a relative path
304
- if (checkPath.isNotRelative(path)) {
305
- const r = '`path.relative()`d';
306
- return doThrow("path should be a ".concat(r, " string, but got \"").concat(originalPath, "\""), RangeError);
307
- }
308
- return true;
309
- };
310
- const isNotRelative = path => REGEX_TEST_INVALID_PATH.test(path);
311
- checkPath.isNotRelative = isNotRelative;
312
- checkPath.convert = p => p;
313
- class Ignore {
314
- constructor() {
315
- let {
316
- ignorecase = true,
317
- ignoreCase = ignorecase,
318
- allowRelativePaths = false
319
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
320
- define(this, KEY_IGNORE, true);
321
- this._rules = [];
322
- this._ignoreCase = ignoreCase;
323
- this._allowRelativePaths = allowRelativePaths;
324
- this._initCache();
325
- }
326
- _initCache() {
327
- this._ignoreCache = Object.create(null);
328
- this._testCache = Object.create(null);
329
- }
330
- _addPattern(pattern) {
331
- // #32
332
- if (pattern && pattern[KEY_IGNORE]) {
333
- this._rules = this._rules.concat(pattern._rules);
334
- this._added = true;
335
- return;
336
- }
337
- if (checkPattern(pattern)) {
338
- const rule = createRule(pattern, this._ignoreCase);
339
- this._added = true;
340
- this._rules.push(rule);
341
- }
342
- }
343
-
344
- // @param {Array<string> | string | Ignore} pattern
345
- add(pattern) {
346
- this._added = false;
347
- makeArray(isString(pattern) ? splitPattern(pattern) : pattern).forEach(this._addPattern, this);
348
-
349
- // Some rules have just added to the ignore,
350
- // making the behavior changed.
351
- if (this._added) {
352
- this._initCache();
353
- }
354
- return this;
355
- }
356
-
357
- // legacy
358
- addPattern(pattern) {
359
- return this.add(pattern);
360
- }
361
-
362
- // | ignored : unignored
363
- // negative | 0:0 | 0:1 | 1:0 | 1:1
364
- // -------- | ------- | ------- | ------- | --------
365
- // 0 | TEST | TEST | SKIP | X
366
- // 1 | TESTIF | SKIP | TEST | X
367
-
368
- // - SKIP: always skip
369
- // - TEST: always test
370
- // - TESTIF: only test if checkUnignored
371
- // - X: that never happen
372
-
373
- // @param {boolean} whether should check if the path is unignored,
374
- // setting `checkUnignored` to `false` could reduce additional
375
- // path matching.
376
-
377
- // @returns {TestResult} true if a file is ignored
378
- _testOne(path, checkUnignored) {
379
- let ignored = false;
380
- let unignored = false;
381
- this._rules.forEach(rule => {
382
- const {
383
- negative
384
- } = rule;
385
- if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) {
386
- return;
387
- }
388
- const matched = rule.regex.test(path);
389
- if (matched) {
390
- ignored = !negative;
391
- unignored = negative;
392
- }
393
- });
394
- return {
395
- ignored,
396
- unignored
397
- };
398
- }
399
-
400
- // @returns {TestResult}
401
- _test(originalPath, cache, checkUnignored, slices) {
402
- const path = originalPath
403
- // Supports nullable path
404
- && checkPath.convert(originalPath);
405
- checkPath(path, originalPath, this._allowRelativePaths ? RETURN_FALSE : throwError);
406
- return this._t(path, cache, checkUnignored, slices);
407
- }
408
- _t(path, cache, checkUnignored, slices) {
409
- if (path in cache) {
410
- return cache[path];
411
- }
412
- if (!slices) {
413
- // path/to/a.js
414
- // ['path', 'to', 'a.js']
415
- slices = path.split(SLASH);
416
- }
417
- slices.pop();
418
-
419
- // If the path has no parent directory, just test it
420
- if (!slices.length) {
421
- return cache[path] = this._testOne(path, checkUnignored);
422
- }
423
- const parent = this._t(slices.join(SLASH) + SLASH, cache, checkUnignored, slices);
424
-
425
- // If the path contains a parent directory, check the parent first
426
- return cache[path] = parent.ignored
427
- // > It is not possible to re-include a file if a parent directory of
428
- // > that file is excluded.
429
- ? parent : this._testOne(path, checkUnignored);
430
- }
431
- ignores(path) {
432
- return this._test(path, this._ignoreCache, false).ignored;
433
- }
434
- createFilter() {
435
- return path => !this.ignores(path);
436
- }
437
- filter(paths) {
438
- return makeArray(paths).filter(this.createFilter());
439
- }
440
-
441
- // @returns {TestResult}
442
- test(path) {
443
- return this._test(path, this._testCache, true);
444
- }
445
- }
446
- const factory = options => new Ignore(options);
447
- const isPathValid = path => checkPath(path && checkPath.convert(path), path, RETURN_FALSE);
448
- factory.isPathValid = isPathValid;
449
-
450
- // Fixes typescript
451
- factory.default = factory;
452
- module.exports = factory;
453
-
454
- // Windows
455
- // --------------------------------------------------------------
456
- /* istanbul ignore if */
457
- if (
458
- // Detect `process` so that it can run in browsers.
459
- typeof process !== 'undefined' && (process.env && process.env.IGNORE_TEST_WIN32 || process.platform === 'win32')) {
460
- /* eslint no-control-regex: "off" */
461
- const makePosix = str => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, '/');
462
- checkPath.convert = makePosix;
463
-
464
- // 'C:\\foo' <- 'C:\\foo' has been converted to 'C:/'
465
- // 'd:\\foo'
466
- const REGIX_IS_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
467
- checkPath.isNotRelative = path => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path) || isNotRelative(path);
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.string.replace.js");
4
+ require("core-js/modules/esnext.async-iterator.filter.js");
5
+ require("core-js/modules/esnext.async-iterator.for-each.js");
6
+ require("core-js/modules/esnext.async-iterator.reduce.js");
7
+ require("core-js/modules/esnext.iterator.constructor.js");
8
+ require("core-js/modules/esnext.iterator.filter.js");
9
+ require("core-js/modules/esnext.iterator.for-each.js");
10
+ require("core-js/modules/esnext.iterator.reduce.js");
11
+ // A simple implementation of make-array
12
+ function makeArray(subject) {
13
+ return Array.isArray(subject) ? subject : [subject];
14
+ }
15
+ const EMPTY = '';
16
+ const SPACE = ' ';
17
+ const ESCAPE = '\\';
18
+ const REGEX_TEST_BLANK_LINE = /^\s+$/;
19
+ const REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
20
+ const REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
21
+ const REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
22
+ const REGEX_SPLITALL_CRLF = /\r?\n/g;
23
+ // /foo,
24
+ // ./foo,
25
+ // ../foo,
26
+ // .
27
+ // ..
28
+ const REGEX_TEST_INVALID_PATH = /^\.*\/|^\.+$/;
29
+ const SLASH = '/';
30
+
31
+ // Do not use ternary expression here, since "istanbul ignore next" is buggy
32
+ let TMP_KEY_IGNORE = 'node-ignore';
33
+ /* istanbul ignore else */
34
+ if (typeof Symbol !== 'undefined') {
35
+ TMP_KEY_IGNORE = Symbol.for('node-ignore');
36
+ }
37
+ const KEY_IGNORE = TMP_KEY_IGNORE;
38
+ const define = (object, key, value) => Object.defineProperty(object, key, {
39
+ value
40
+ });
41
+ const REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g;
42
+ const RETURN_FALSE = () => false;
43
+
44
+ // Sanitize the range of a regular expression
45
+ // The cases are complicated, see test cases for details
46
+ const sanitizeRange = range => range.replace(REGEX_REGEXP_RANGE, (match, from, to) => from.charCodeAt(0) <= to.charCodeAt(0) ? match
47
+ // Invalid range (out of order) which is ok for gitignore rules but
48
+ // fatal for JavaScript regular expression, so eliminate it.
49
+ : EMPTY);
50
+
51
+ // See fixtures #59
52
+ const cleanRangeBackSlash = slashes => {
53
+ const {
54
+ length
55
+ } = slashes;
56
+ return slashes.slice(0, length - length % 2);
57
+ };
58
+
59
+ // > If the pattern ends with a slash,
60
+ // > it is removed for the purpose of the following description,
61
+ // > but it would only find a match with a directory.
62
+ // > In other words, foo/ will match a directory foo and paths underneath it,
63
+ // > but will not match a regular file or a symbolic link foo
64
+ // > (this is consistent with the way how pathspec works in general in Git).
65
+ // '`foo/`' will not match regular file '`foo`' or symbolic link '`foo`'
66
+ // -> ignore-rules will not deal with it, because it costs extra `fs.stat` call
67
+ // you could use option `mark: true` with `glob`
68
+
69
+ // '`foo/`' should not continue with the '`..`'
70
+ const REPLACERS = [[
71
+ // remove BOM
72
+ // TODO:
73
+ // Other similar zero-width characters?
74
+ /^\uFEFF/, () => EMPTY],
75
+ // > Trailing spaces are ignored unless they are quoted with backslash ("\")
76
+ [
77
+ // (a\ ) -> (a )
78
+ // (a ) -> (a)
79
+ // (a \ ) -> (a )
80
+ /\\?\s+$/, match => match.indexOf('\\') === 0 ? SPACE : EMPTY],
81
+ // replace (\ ) with ' '
82
+ [/\\\s/g, () => SPACE],
83
+ // Escape metacharacters
84
+ // which is written down by users but means special for regular expressions.
85
+
86
+ // > There are 12 characters with special meanings:
87
+ // > - the backslash \,
88
+ // > - the caret ^,
89
+ // > - the dollar sign $,
90
+ // > - the period or dot .,
91
+ // > - the vertical bar or pipe symbol |,
92
+ // > - the question mark ?,
93
+ // > - the asterisk or star *,
94
+ // > - the plus sign +,
95
+ // > - the opening parenthesis (,
96
+ // > - the closing parenthesis ),
97
+ // > - and the opening square bracket [,
98
+ // > - the opening curly brace {,
99
+ // > These special characters are often called "metacharacters".
100
+ [/[\\$.|*+(){^]/g, match => "\\".concat(match)], [
101
+ // > a question mark (?) matches a single character
102
+ /(?!\\)\?/g, () => '[^/]'],
103
+ // leading slash
104
+ [
105
+ // > A leading slash matches the beginning of the pathname.
106
+ // > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
107
+ // A leading slash matches the beginning of the pathname
108
+ /^\//, () => '^'],
109
+ // replace special metacharacter slash after the leading slash
110
+ [/\//g, () => '\\/'], [
111
+ // > A leading "**" followed by a slash means match in all directories.
112
+ // > For example, "**/foo" matches file or directory "foo" anywhere,
113
+ // > the same as pattern "foo".
114
+ // > "**/foo/bar" matches file or directory "bar" anywhere that is directly
115
+ // > under directory "foo".
116
+ // Notice that the '*'s have been replaced as '\\*'
117
+ /^\^*\\\*\\\*\\\//,
118
+ // '**/foo' <-> 'foo'
119
+ () => '^(?:.*\\/)?'],
120
+ // starting
121
+ [
122
+ // there will be no leading '/'
123
+ // (which has been replaced by section "leading slash")
124
+ // If starts with '**', adding a '^' to the regular expression also works
125
+ /^(?=[^^])/, function startingReplacer() {
126
+ // If has a slash `/` at the beginning or middle
127
+ return !/\/(?!$)/.test(this)
128
+ // > Prior to 2.22.1
129
+ // > If the pattern does not contain a slash /,
130
+ // > Git treats it as a shell glob pattern
131
+ // Actually, if there is only a trailing slash,
132
+ // git also treats it as a shell glob pattern
133
+
134
+ // After 2.22.1 (compatible but clearer)
135
+ // > If there is a separator at the beginning or middle (or both)
136
+ // > of the pattern, then the pattern is relative to the directory
137
+ // > level of the particular .gitignore file itself.
138
+ // > Otherwise the pattern may also match at any level below
139
+ // > the .gitignore level.
140
+ ? '(?:^|\\/)'
141
+
142
+ // > Otherwise, Git treats the pattern as a shell glob suitable for
143
+ // > consumption by fnmatch(3)
144
+ : '^';
145
+ }],
146
+ // two globstars
147
+ [
148
+ // Use lookahead assertions so that we could match more than one `'/**'`
149
+ /\\\/\\\*\\\*(?=\\\/|$)/g,
150
+ // Zero, one or several directories
151
+ // should not use '*', or it will be replaced by the next replacer
152
+
153
+ // Check if it is not the last `'/**'`
154
+ (_, index, str) => index + 6 < str.length
155
+
156
+ // case: /**/
157
+ // > A slash followed by two consecutive asterisks then a slash matches
158
+ // > zero or more directories.
159
+ // > For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
160
+ // '/**/'
161
+ ? '(?:\\/[^\\/]+)*'
162
+
163
+ // case: /**
164
+ // > A trailing `"/**"` matches everything inside.
165
+
166
+ // #21: everything inside but it should not include the current folder
167
+ : '\\/.+'],
168
+ // normal intermediate wildcards
169
+ [
170
+ // Never replace escaped '*'
171
+ // ignore rule '\*' will match the path '*'
172
+
173
+ // 'abc.*/' -> go
174
+ // 'abc.*' -> skip this rule,
175
+ // coz trailing single wildcard will be handed by [trailing wildcard]
176
+ /(^|[^\\]+)(\\\*)+(?=.+)/g,
177
+ // '*.js' matches '.js'
178
+ // '*.js' doesn't match 'abc'
179
+ (_, p1, p2) => {
180
+ // 1.
181
+ // > An asterisk "*" matches anything except a slash.
182
+ // 2.
183
+ // > Other consecutive asterisks are considered regular asterisks
184
+ // > and will match according to the previous rules.
185
+ const unescaped = p2.replace(/\\\*/g, '[^\\/]*');
186
+ return p1 + unescaped;
187
+ }], [
188
+ // unescape, revert step 3 except for back slash
189
+ // For example, if a user escape a '\\*',
190
+ // after step 3, the result will be '\\\\\\*'
191
+ /\\\\\\(?=[$.|*+(){^])/g, () => ESCAPE], [
192
+ // '\\\\' -> '\\'
193
+ /\\\\/g, () => ESCAPE], [
194
+ // > The range notation, e.g. [a-zA-Z],
195
+ // > can be used to match one of the characters in a range.
196
+
197
+ // `\` is escaped by step 3
198
+ /(\\)?\[([^\]/]*?)(\\*)($|\])/g, (match, leadEscape, range, endEscape, close) => leadEscape === ESCAPE
199
+ // '\\[bar]' -> '\\\\[bar\\]'
200
+ ? "\\[".concat(range).concat(cleanRangeBackSlash(endEscape)).concat(close) : close === ']' ? endEscape.length % 2 === 0
201
+ // A normal case, and it is a range notation
202
+ // '[bar]'
203
+ // '[bar\\\\]'
204
+ ? "[".concat(sanitizeRange(range)).concat(endEscape, "]") // Invalid range notaton
205
+ // '[bar\\]' -> '[bar\\\\]'
206
+ : '[]' : '[]'],
207
+ // ending
208
+ [
209
+ // 'js' will not match 'js.'
210
+ // 'ab' will not match 'abc'
211
+ /(?:[^*])$/,
212
+ // WTF!
213
+ // https://git-scm.com/docs/gitignore
214
+ // changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
215
+ // which re-fixes #24, #38
216
+
217
+ // > If there is a separator at the end of the pattern then the pattern
218
+ // > will only match directories, otherwise the pattern can match both
219
+ // > files and directories.
220
+
221
+ // 'js*' will not match 'a.js'
222
+ // 'js/' will not match 'a.js'
223
+ // 'js' will match 'a.js' and 'a.js/'
224
+ match => /\/$/.test(match)
225
+ // foo/ will not match 'foo'
226
+ ? "".concat(match, "$") // foo matches 'foo' and 'foo/'
227
+ : "".concat(match, "(?=$|\\/$)")],
228
+ // trailing wildcard
229
+ [/(\^|\\\/)?\\\*$/, (_, p1) => {
230
+ const prefix = p1
231
+ // '\^':
232
+ // '/*' does not match EMPTY
233
+ // '/*' does not match everything
234
+
235
+ // '\\\/':
236
+ // 'abc/*' does not match 'abc/'
237
+ ? "".concat(p1, "[^/]+") // 'a*' matches 'a'
238
+ // 'a*' matches 'aa'
239
+ : '[^/]*';
240
+ return "".concat(prefix, "(?=$|\\/$)");
241
+ }]];
242
+
243
+ // A simple cache, because an ignore rule only has only one certain meaning
244
+ const regexCache = Object.create(null);
245
+
246
+ // @param {pattern}
247
+ const makeRegex = (pattern, ignoreCase) => {
248
+ let source = regexCache[pattern];
249
+ if (!source) {
250
+ source = REPLACERS.reduce((prev, current) => prev.replace(current[0], current[1].bind(pattern)), pattern);
251
+ regexCache[pattern] = source;
252
+ }
253
+ return ignoreCase ? new RegExp(source, 'i') : new RegExp(source);
254
+ };
255
+ const isString = subject => typeof subject === 'string';
256
+
257
+ // > A blank line matches no files, so it can serve as a separator for readability.
258
+ const checkPattern = pattern => pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern)
259
+
260
+ // > A line starting with # serves as a comment.
261
+ && pattern.indexOf('#') !== 0;
262
+ const splitPattern = pattern => pattern.split(REGEX_SPLITALL_CRLF);
263
+ class IgnoreRule {
264
+ constructor(origin, pattern, negative, regex) {
265
+ this.origin = origin;
266
+ this.pattern = pattern;
267
+ this.negative = negative;
268
+ this.regex = regex;
269
+ }
270
+ }
271
+ const createRule = (pattern, ignoreCase) => {
272
+ const origin = pattern;
273
+ let negative = false;
274
+
275
+ // > An optional prefix "!" which negates the pattern;
276
+ if (pattern.indexOf('!') === 0) {
277
+ negative = true;
278
+ pattern = pattern.substr(1);
279
+ }
280
+ pattern = pattern
281
+ // > Put a backslash ("\") in front of the first "!" for patterns that
282
+ // > begin with a literal "!", for example, `"\!important!.txt"`.
283
+ .replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, '!')
284
+ // > Put a backslash ("\") in front of the first hash for patterns that
285
+ // > begin with a hash.
286
+ .replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#');
287
+ const regex = makeRegex(pattern, ignoreCase);
288
+ return new IgnoreRule(origin, pattern, negative, regex);
289
+ };
290
+ const throwError = (message, Ctor) => {
291
+ throw new Ctor(message);
292
+ };
293
+ const checkPath = (path, originalPath, doThrow) => {
294
+ if (!isString(path)) {
295
+ return doThrow("path must be a string, but got `".concat(originalPath, "`"), TypeError);
296
+ }
297
+
298
+ // We don't know if we should ignore EMPTY, so throw
299
+ if (!path) {
300
+ return doThrow("path must not be empty", TypeError);
301
+ }
302
+
303
+ // Check if it is a relative path
304
+ if (checkPath.isNotRelative(path)) {
305
+ const r = '`path.relative()`d';
306
+ return doThrow("path should be a ".concat(r, " string, but got \"").concat(originalPath, "\""), RangeError);
307
+ }
308
+ return true;
309
+ };
310
+ const isNotRelative = path => REGEX_TEST_INVALID_PATH.test(path);
311
+ checkPath.isNotRelative = isNotRelative;
312
+ checkPath.convert = p => p;
313
+ class Ignore {
314
+ constructor() {
315
+ let {
316
+ ignorecase = true,
317
+ ignoreCase = ignorecase,
318
+ allowRelativePaths = false
319
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
320
+ define(this, KEY_IGNORE, true);
321
+ this._rules = [];
322
+ this._ignoreCase = ignoreCase;
323
+ this._allowRelativePaths = allowRelativePaths;
324
+ this._initCache();
325
+ }
326
+ _initCache() {
327
+ this._ignoreCache = Object.create(null);
328
+ this._testCache = Object.create(null);
329
+ }
330
+ _addPattern(pattern) {
331
+ // #32
332
+ if (pattern && pattern[KEY_IGNORE]) {
333
+ this._rules = this._rules.concat(pattern._rules);
334
+ this._added = true;
335
+ return;
336
+ }
337
+ if (checkPattern(pattern)) {
338
+ const rule = createRule(pattern, this._ignoreCase);
339
+ this._added = true;
340
+ this._rules.push(rule);
341
+ }
342
+ }
343
+
344
+ // @param {Array<string> | string | Ignore} pattern
345
+ add(pattern) {
346
+ this._added = false;
347
+ makeArray(isString(pattern) ? splitPattern(pattern) : pattern).forEach(this._addPattern, this);
348
+
349
+ // Some rules have just added to the ignore,
350
+ // making the behavior changed.
351
+ if (this._added) {
352
+ this._initCache();
353
+ }
354
+ return this;
355
+ }
356
+
357
+ // legacy
358
+ addPattern(pattern) {
359
+ return this.add(pattern);
360
+ }
361
+
362
+ // | ignored : unignored
363
+ // negative | 0:0 | 0:1 | 1:0 | 1:1
364
+ // -------- | ------- | ------- | ------- | --------
365
+ // 0 | TEST | TEST | SKIP | X
366
+ // 1 | TESTIF | SKIP | TEST | X
367
+
368
+ // - SKIP: always skip
369
+ // - TEST: always test
370
+ // - TESTIF: only test if checkUnignored
371
+ // - X: that never happen
372
+
373
+ // @param {boolean} whether should check if the path is unignored,
374
+ // setting `checkUnignored` to `false` could reduce additional
375
+ // path matching.
376
+
377
+ // @returns {TestResult} true if a file is ignored
378
+ _testOne(path, checkUnignored) {
379
+ let ignored = false;
380
+ let unignored = false;
381
+ this._rules.forEach(rule => {
382
+ const {
383
+ negative
384
+ } = rule;
385
+ if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) {
386
+ return;
387
+ }
388
+ const matched = rule.regex.test(path);
389
+ if (matched) {
390
+ ignored = !negative;
391
+ unignored = negative;
392
+ }
393
+ });
394
+ return {
395
+ ignored,
396
+ unignored
397
+ };
398
+ }
399
+
400
+ // @returns {TestResult}
401
+ _test(originalPath, cache, checkUnignored, slices) {
402
+ const path = originalPath
403
+ // Supports nullable path
404
+ && checkPath.convert(originalPath);
405
+ checkPath(path, originalPath, this._allowRelativePaths ? RETURN_FALSE : throwError);
406
+ return this._t(path, cache, checkUnignored, slices);
407
+ }
408
+ _t(path, cache, checkUnignored, slices) {
409
+ if (path in cache) {
410
+ return cache[path];
411
+ }
412
+ if (!slices) {
413
+ // path/to/a.js
414
+ // ['path', 'to', 'a.js']
415
+ slices = path.split(SLASH);
416
+ }
417
+ slices.pop();
418
+
419
+ // If the path has no parent directory, just test it
420
+ if (!slices.length) {
421
+ return cache[path] = this._testOne(path, checkUnignored);
422
+ }
423
+ const parent = this._t(slices.join(SLASH) + SLASH, cache, checkUnignored, slices);
424
+
425
+ // If the path contains a parent directory, check the parent first
426
+ return cache[path] = parent.ignored
427
+ // > It is not possible to re-include a file if a parent directory of
428
+ // > that file is excluded.
429
+ ? parent : this._testOne(path, checkUnignored);
430
+ }
431
+ ignores(path) {
432
+ return this._test(path, this._ignoreCache, false).ignored;
433
+ }
434
+ createFilter() {
435
+ return path => !this.ignores(path);
436
+ }
437
+ filter(paths) {
438
+ return makeArray(paths).filter(this.createFilter());
439
+ }
440
+
441
+ // @returns {TestResult}
442
+ test(path) {
443
+ return this._test(path, this._testCache, true);
444
+ }
445
+ }
446
+ const factory = options => new Ignore(options);
447
+ const isPathValid = path => checkPath(path && checkPath.convert(path), path, RETURN_FALSE);
448
+ factory.isPathValid = isPathValid;
449
+
450
+ // Fixes typescript
451
+ factory.default = factory;
452
+ module.exports = factory;
453
+
454
+ // Windows
455
+ // --------------------------------------------------------------
456
+ /* istanbul ignore if */
457
+ if (
458
+ // Detect `process` so that it can run in browsers.
459
+ typeof process !== 'undefined' && (process.env && process.env.IGNORE_TEST_WIN32 || process.platform === 'win32')) {
460
+ /* eslint no-control-regex: "off" */
461
+ const makePosix = str => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, '/');
462
+ checkPath.convert = makePosix;
463
+
464
+ // 'C:\\foo' <- 'C:\\foo' has been converted to 'C:/'
465
+ // 'd:\\foo'
466
+ const REGIX_IS_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
467
+ checkPath.isNotRelative = path => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path) || isNotRelative(path);
468
468
  }