@naanlang/naan 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +46 -0
  3. package/dist/env_web.js +431 -0
  4. package/dist/naan.min.js +73 -0
  5. package/frameworks/browser/browser.nlg +30 -0
  6. package/frameworks/browser/pouchdb/pouchdb.min.js +7 -0
  7. package/frameworks/browser/spark-md5/spark-md5.min.js +1 -0
  8. package/frameworks/browser/sworker.js +192 -0
  9. package/frameworks/browser/terminals.nlg +787 -0
  10. package/frameworks/browser/workers.nlg +386 -0
  11. package/frameworks/client/apiclient.nlg +183 -0
  12. package/frameworks/client/client.nlg +29 -0
  13. package/frameworks/client/psm_client.nlg +572 -0
  14. package/frameworks/common/common.nlg +464 -0
  15. package/frameworks/common/preferences.nlg +131 -0
  16. package/frameworks/common/repltools.nlg +100 -0
  17. package/frameworks/common/watching.nlg +97 -0
  18. package/frameworks/node/apiserver.nlg +399 -0
  19. package/frameworks/node/filesystem.nlg +1012 -0
  20. package/frameworks/node/gitter.nlg +234 -0
  21. package/frameworks/node/node.nlg +81 -0
  22. package/frameworks/node/psm_server.nlg +465 -0
  23. package/frameworks/node/worker.nlg +560 -0
  24. package/frameworks/project/build.nlg +1229 -0
  25. package/frameworks/project/jszip.js +30 -0
  26. package/frameworks/project/jszip.nlg +87 -0
  27. package/frameworks/project/proj_cliser.nlg +139 -0
  28. package/frameworks/project/proj_console.nlg +137 -0
  29. package/frameworks/project/proj_folder.nlg +143 -0
  30. package/frameworks/project/proj_lambda.nlg +137 -0
  31. package/frameworks/project/proj_static.nlg +138 -0
  32. package/frameworks/project/project.nlg +29 -0
  33. package/frameworks/project/projects.nlg +587 -0
  34. package/frameworks/project/uglifyjs.js +1 -0
  35. package/frameworks/project/uglifyjs.nlg +79 -0
  36. package/frameworks/running/debugcom.nlg +163 -0
  37. package/frameworks/running/debugnub.nlg +565 -0
  38. package/frameworks/running/debugutil.nlg +510 -0
  39. package/frameworks/running/executors.nlg +767 -0
  40. package/frameworks/running/running.nlg +151 -0
  41. package/frameworks/running/sourcecode.nlg +346 -0
  42. package/frameworks/running/taskexec.nlg +196 -0
  43. package/frameworks/storage/dbt_pouch.nlg +773 -0
  44. package/frameworks/storage/file_manager.nlg +772 -0
  45. package/frameworks/storage/psm.nlg +326 -0
  46. package/frameworks/storage/psm_dbtables.nlg +814 -0
  47. package/frameworks/storage/resources.nlg +445 -0
  48. package/frameworks/storage/storage.nlg +52 -0
  49. package/lib/browser/env_web.js +431 -0
  50. package/lib/browser/env_webworker.js +146 -0
  51. package/lib/browser/require.js +1653 -0
  52. package/lib/core/naanlib.js +73 -0
  53. package/lib/env_node.js +282 -0
  54. package/lib/env_nodeworker.js +165 -0
  55. package/lib/node_repl.js +25 -0
  56. package/lib/node_repl_init.nlg +52 -0
  57. package/package.json +13 -0
  58. package/plugins/gitClient/clientops.nlg +317 -0
  59. package/plugins/gitClient/gitClient.nlg +63 -0
  60. package/plugins/gitClient/gitutils.nlg +1331 -0
  61. package/plugins/gitClient/minimatch.js +945 -0
  62. package/plugins/gitClient/minimatch_license.txt +15 -0
  63. package/plugins/gitClient/minimatch_readme.md +208 -0
  64. package/plugins/nodeLib/nodeLib.nlg +26 -0
  65. package/plugins/nodeLib/node_cp.nlg +65 -0
  66. package/plugins/nodeLib/node_fs.nlg +137 -0
  67. package/plugins/nodeLib/node_https.nlg +172 -0
  68. package/plugins/nodeLib/node_util.nlg +180 -0
  69. package/plugins/serviceAws/aws/aws-sdk.min.js +88 -0
  70. package/plugins/serviceAws/aws/lambda_rest_index.js +122 -0
  71. package/plugins/serviceAws/aws/lambda_rest_init.nlg +58 -0
  72. package/plugins/serviceAws/aws/lambda_ws_index.js +498 -0
  73. package/plugins/serviceAws/aws/lambda_ws_init.nlg +49 -0
  74. package/plugins/serviceAws/aws_cloudwatchlogs.nlg +122 -0
  75. package/plugins/serviceAws/aws_cognito.nlg +76 -0
  76. package/plugins/serviceAws/aws_dynamo.nlg +509 -0
  77. package/plugins/serviceAws/aws_lambda.nlg +95 -0
  78. package/plugins/serviceAws/aws_s3.nlg +134 -0
  79. package/plugins/serviceAws/aws_utils.nlg +86 -0
  80. package/plugins/serviceAws/dbt_aws.nlg +769 -0
  81. package/plugins/serviceAws/lambda_naan_control.nlg +175 -0
  82. package/plugins/serviceAws/psm_aws.nlg +258 -0
  83. package/plugins/serviceAws/serviceAws.nlg +38 -0
  84. package/plugins/serviceGitHub/gitops.nlg +522 -0
  85. package/plugins/serviceGitHub/psm_github.nlg +205 -0
  86. package/plugins/serviceGitHub/serviceGitHub.nlg +65 -0
  87. package/plugins/serviceGitLab/gitops.nlg +528 -0
  88. package/plugins/serviceGitLab/psm_gitlab.nlg +205 -0
  89. package/plugins/serviceGitLab/serviceGitLab.nlg +65 -0
  90. package/test/harness.nlg +312 -0
  91. package/test/node_test.js +33 -0
  92. package/test/test_01_core.nlg +768 -0
  93. package/test/test_02_context.nlg +269 -0
  94. package/test/test_03_jsinterop.nlg +137 -0
  95. package/test/test_04_numerics.nlg +450 -0
  96. package/test/test_05_strings.nlg +63 -0
  97. package/test/test_06_lingoparse.nlg +500 -0
  98. package/test/test_07_lingo.nlg +623 -0
@@ -0,0 +1,945 @@
1
+ /*
2
+ * minimatch.js
3
+ *
4
+ * This is an implementation of fnmatch (3), adapted from the open source minimatch library.
5
+ * Copied from https://github.com/isaacs/minimatch on 20210126 by Rcz. Modifications to the original
6
+ * include:
7
+ * 1. Adapted to be usable in either browser or NodeJS environments.
8
+ * 2.
9
+ *
10
+ * column positioning: // // !
11
+ *
12
+ */
13
+
14
+ (function(exports){
15
+
16
+ var path = { sep: '/' }
17
+ try {
18
+ path = require('path')
19
+ } catch (er) {}
20
+
21
+ var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
22
+ var expand = require('brace-expansion')
23
+
24
+ var plTypes = {
25
+ '!': { open: '(?:(?!(?:', close: '))[^/]*?)'},
26
+ '?': { open: '(?:', close: ')?' },
27
+ '+': { open: '(?:', close: ')+' },
28
+ '*': { open: '(?:', close: ')*' },
29
+ '@': { open: '(?:', close: ')' }
30
+ }
31
+
32
+ // any single thing other than /
33
+ // don't need to escape / when using new RegExp()
34
+ var qmark = '[^/]'
35
+
36
+ // * => any number of characters
37
+ var star = qmark + '*?'
38
+
39
+ // ** when dots are allowed. Anything goes, except .. and .
40
+ // not (^ or / followed by one or two dots followed by $ or /),
41
+ // followed by anything, any number of times.
42
+ var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'
43
+
44
+ // not a ^ or / followed by a dot,
45
+ // followed by anything, any number of times.
46
+ var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'
47
+
48
+ // characters that need to be escaped in RegExp.
49
+ var reSpecials = charSet('().*{}+?[]^$\\!')
50
+
51
+ // "abc" -> { a:true, b:true, c:true }
52
+ function charSet (s) {
53
+ return s.split('').reduce(function (set, c) {
54
+ set[c] = true
55
+ return set
56
+ }, {})
57
+ }
58
+
59
+ // normalizes slashes.
60
+ var slashSplit = /\/+/
61
+
62
+ minimatch.filter = filter
63
+ function filter (pattern, options) {
64
+ options = options || {}
65
+ return function (p, i, list) {
66
+ return minimatch(p, pattern, options)
67
+ }
68
+ }
69
+
70
+ function ext (a, b) {
71
+ a = a || {}
72
+ b = b || {}
73
+ var t = {}
74
+ Object.keys(b).forEach(function (k) {
75
+ t[k] = b[k]
76
+ })
77
+ Object.keys(a).forEach(function (k) {
78
+ t[k] = a[k]
79
+ })
80
+ return t
81
+ }
82
+
83
+ minimatch.defaults = function (def) {
84
+ if (!def || !Object.keys(def).length) return minimatch
85
+
86
+ var orig = minimatch
87
+
88
+ var m = function minimatch (p, pattern, options) {
89
+ return orig.minimatch(p, pattern, ext(def, options))
90
+ }
91
+
92
+ m.Minimatch = function Minimatch (pattern, options) {
93
+ return new orig.Minimatch(pattern, ext(def, options))
94
+ }
95
+
96
+ return m
97
+ }
98
+
99
+ Minimatch.defaults = function (def) {
100
+ if (!def || !Object.keys(def).length) return Minimatch
101
+ return minimatch.defaults(def).Minimatch
102
+ }
103
+
104
+ function minimatch (p, pattern, options) {
105
+ if (typeof pattern !== 'string') {
106
+ throw new TypeError('glob pattern string required')
107
+ }
108
+
109
+ if (!options) options = {}
110
+
111
+ // shortcut: comments match nothing.
112
+ if (!options.nocomment && pattern.charAt(0) === '#') {
113
+ return false
114
+ }
115
+
116
+ // "" only matches ""
117
+ if (pattern.trim() === '') return p === ''
118
+
119
+ return new Minimatch(pattern, options).match(p)
120
+ }
121
+
122
+ function Minimatch (pattern, options) {
123
+ if (!(this instanceof Minimatch)) {
124
+ return new Minimatch(pattern, options)
125
+ }
126
+
127
+ if (typeof pattern !== 'string') {
128
+ throw new TypeError('glob pattern string required')
129
+ }
130
+
131
+ if (!options) options = {}
132
+ pattern = pattern.trim()
133
+
134
+ // windows support: need to use /, not \
135
+ if (path.sep !== '/') {
136
+ pattern = pattern.split(path.sep).join('/')
137
+ }
138
+
139
+ this.options = options
140
+ this.set = []
141
+ this.pattern = pattern
142
+ this.regexp = null
143
+ this.negate = false
144
+ this.comment = false
145
+ this.empty = false
146
+
147
+ // make the set of regexps etc.
148
+ this.make()
149
+ }
150
+
151
+ Minimatch.prototype.debug = function () {}
152
+
153
+ Minimatch.prototype.make = make
154
+ function make () {
155
+ // don't do it more than once.
156
+ if (this._made) return
157
+
158
+ var pattern = this.pattern
159
+ var options = this.options
160
+
161
+ // empty patterns and comments match nothing.
162
+ if (!options.nocomment && pattern.charAt(0) === '#') {
163
+ this.comment = true
164
+ return
165
+ }
166
+ if (!pattern) {
167
+ this.empty = true
168
+ return
169
+ }
170
+
171
+ // step 1: figure out negation, etc.
172
+ this.parseNegate()
173
+
174
+ // step 2: expand braces
175
+ var set = this.globSet = this.braceExpand()
176
+
177
+ if (options.debug) this.debug = console.error
178
+
179
+ this.debug(this.pattern, set)
180
+
181
+ // step 3: now we have a set, so turn each one into a series of path-portion
182
+ // matching patterns.
183
+ // These will be regexps, except in the case of "**", which is
184
+ // set to the GLOBSTAR object for globstar behavior,
185
+ // and will not contain any / characters
186
+ set = this.globParts = set.map(function (s) {
187
+ return s.split(slashSplit)
188
+ })
189
+
190
+ this.debug(this.pattern, set)
191
+
192
+ // glob --> regexps
193
+ set = set.map(function (s, si, set) {
194
+ return s.map(this.parse, this)
195
+ }, this)
196
+
197
+ this.debug(this.pattern, set)
198
+
199
+ // filter out everything that didn't compile properly.
200
+ set = set.filter(function (s) {
201
+ return s.indexOf(false) === -1
202
+ })
203
+
204
+ this.debug(this.pattern, set)
205
+
206
+ this.set = set
207
+ }
208
+
209
+ Minimatch.prototype.parseNegate = parseNegate
210
+ function parseNegate () {
211
+ var pattern = this.pattern
212
+ var negate = false
213
+ var options = this.options
214
+ var negateOffset = 0
215
+
216
+ if (options.nonegate) return
217
+
218
+ for (var i = 0, l = pattern.length
219
+ ; i < l && pattern.charAt(i) === '!'
220
+ ; i++) {
221
+ negate = !negate
222
+ negateOffset++
223
+ }
224
+
225
+ if (negateOffset) this.pattern = pattern.substr(negateOffset)
226
+ this.negate = negate
227
+ }
228
+
229
+ // Brace expansion:
230
+ // a{b,c}d -> abd acd
231
+ // a{b,}c -> abc ac
232
+ // a{0..3}d -> a0d a1d a2d a3d
233
+ // a{b,c{d,e}f}g -> abg acdfg acefg
234
+ // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
235
+ //
236
+ // Invalid sets are not expanded.
237
+ // a{2..}b -> a{2..}b
238
+ // a{b}c -> a{b}c
239
+ minimatch.braceExpand = function (pattern, options) {
240
+ return braceExpand(pattern, options)
241
+ }
242
+
243
+ Minimatch.prototype.braceExpand = braceExpand
244
+
245
+ function braceExpand (pattern, options) {
246
+ if (!options) {
247
+ if (this instanceof Minimatch) {
248
+ options = this.options
249
+ } else {
250
+ options = {}
251
+ }
252
+ }
253
+
254
+ pattern = typeof pattern === 'undefined'
255
+ ? this.pattern : pattern
256
+
257
+ if (typeof pattern === 'undefined') {
258
+ throw new TypeError('undefined pattern')
259
+ }
260
+
261
+ if (options.nobrace ||
262
+ !pattern.match(/\{.*\}/)) {
263
+ // shortcut. no need to expand.
264
+ return [pattern]
265
+ }
266
+
267
+ return expand(pattern)
268
+ }
269
+
270
+ // parse a component of the expanded set.
271
+ // At this point, no pattern may contain "/" in it
272
+ // so we're going to return a 2d array, where each entry is the full
273
+ // pattern, split on '/', and then turned into a regular expression.
274
+ // A regexp is made at the end which joins each array with an
275
+ // escaped /, and another full one which joins each regexp with |.
276
+ //
277
+ // Following the lead of Bash 4.1, note that "**" only has special meaning
278
+ // when it is the *only* thing in a path portion. Otherwise, any series
279
+ // of * is equivalent to a single *. Globstar behavior is enabled by
280
+ // default, and can be disabled by setting options.noglobstar.
281
+ Minimatch.prototype.parse = parse
282
+ var SUBPARSE = {}
283
+ function parse (pattern, isSub) {
284
+ if (pattern.length > 1024 * 64) {
285
+ throw new TypeError('pattern is too long')
286
+ }
287
+
288
+ var options = this.options
289
+
290
+ // shortcuts
291
+ if (!options.noglobstar && pattern === '**') return GLOBSTAR
292
+ if (pattern === '') return ''
293
+
294
+ var re = ''
295
+ var hasMagic = !!options.nocase
296
+ var escaping = false
297
+ // ? => one single character
298
+ var patternListStack = []
299
+ var negativeLists = []
300
+ var stateChar
301
+ var inClass = false
302
+ var reClassStart = -1
303
+ var classStart = -1
304
+ // . and .. never match anything that doesn't start with .,
305
+ // even when options.dot is set.
306
+ var patternStart = pattern.charAt(0) === '.' ? '' // anything
307
+ // not (start or / followed by . or .. followed by / or end)
308
+ : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))'
309
+ : '(?!\\.)'
310
+ var self = this
311
+
312
+ function clearStateChar () {
313
+ if (stateChar) {
314
+ // we had some state-tracking character
315
+ // that wasn't consumed by this pass.
316
+ switch (stateChar) {
317
+ case '*':
318
+ re += star
319
+ hasMagic = true
320
+ break
321
+ case '?':
322
+ re += qmark
323
+ hasMagic = true
324
+ break
325
+ default:
326
+ re += '\\' + stateChar
327
+ break
328
+ }
329
+ self.debug('clearStateChar %j %j', stateChar, re)
330
+ stateChar = false
331
+ }
332
+ }
333
+
334
+ for (var i = 0, len = pattern.length, c
335
+ ; (i < len) && (c = pattern.charAt(i))
336
+ ; i++) {
337
+ this.debug('%s\t%s %s %j', pattern, i, re, c)
338
+
339
+ // skip over any that are escaped.
340
+ if (escaping && reSpecials[c]) {
341
+ re += '\\' + c
342
+ escaping = false
343
+ continue
344
+ }
345
+
346
+ switch (c) {
347
+ case '/':
348
+ // completely not allowed, even escaped.
349
+ // Should already be path-split by now.
350
+ return false
351
+
352
+ case '\\':
353
+ clearStateChar()
354
+ escaping = true
355
+ continue
356
+
357
+ // the various stateChar values
358
+ // for the "extglob" stuff.
359
+ case '?':
360
+ case '*':
361
+ case '+':
362
+ case '@':
363
+ case '!':
364
+ this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c)
365
+
366
+ // all of those are literals inside a class, except that
367
+ // the glob [!a] means [^a] in regexp
368
+ if (inClass) {
369
+ this.debug(' in class')
370
+ if (c === '!' && i === classStart + 1) c = '^'
371
+ re += c
372
+ continue
373
+ }
374
+
375
+ // if we already have a stateChar, then it means
376
+ // that there was something like ** or +? in there.
377
+ // Handle the stateChar, then proceed with this one.
378
+ self.debug('call clearStateChar %j', stateChar)
379
+ clearStateChar()
380
+ stateChar = c
381
+ // if extglob is disabled, then +(asdf|foo) isn't a thing.
382
+ // just clear the statechar *now*, rather than even diving into
383
+ // the patternList stuff.
384
+ if (options.noext) clearStateChar()
385
+ continue
386
+
387
+ case '(':
388
+ if (inClass) {
389
+ re += '('
390
+ continue
391
+ }
392
+
393
+ if (!stateChar) {
394
+ re += '\\('
395
+ continue
396
+ }
397
+
398
+ patternListStack.push({
399
+ type: stateChar,
400
+ start: i - 1,
401
+ reStart: re.length,
402
+ open: plTypes[stateChar].open,
403
+ close: plTypes[stateChar].close
404
+ })
405
+ // negation is (?:(?!js)[^/]*)
406
+ re += stateChar === '!' ? '(?:(?!(?:' : '(?:'
407
+ this.debug('plType %j %j', stateChar, re)
408
+ stateChar = false
409
+ continue
410
+
411
+ case ')':
412
+ if (inClass || !patternListStack.length) {
413
+ re += '\\)'
414
+ continue
415
+ }
416
+
417
+ clearStateChar()
418
+ hasMagic = true
419
+ var pl = patternListStack.pop()
420
+ // negation is (?:(?!js)[^/]*)
421
+ // The others are (?:<pattern>)<type>
422
+ re += pl.close
423
+ if (pl.type === '!') {
424
+ negativeLists.push(pl)
425
+ }
426
+ pl.reEnd = re.length
427
+ continue
428
+
429
+ case '|':
430
+ if (inClass || !patternListStack.length || escaping) {
431
+ re += '\\|'
432
+ escaping = false
433
+ continue
434
+ }
435
+
436
+ clearStateChar()
437
+ re += '|'
438
+ continue
439
+
440
+ // these are mostly the same in regexp and glob
441
+ case '[':
442
+ // swallow any state-tracking char before the [
443
+ clearStateChar()
444
+
445
+ if (inClass) {
446
+ re += '\\' + c
447
+ continue
448
+ }
449
+
450
+ inClass = true
451
+ classStart = i
452
+ reClassStart = re.length
453
+ re += c
454
+ continue
455
+
456
+ case ']':
457
+ // a right bracket shall lose its special
458
+ // meaning and represent itself in
459
+ // a bracket expression if it occurs
460
+ // first in the list. -- POSIX.2 2.8.3.2
461
+ if (i === classStart + 1 || !inClass) {
462
+ re += '\\' + c
463
+ escaping = false
464
+ continue
465
+ }
466
+
467
+ // handle the case where we left a class open.
468
+ // "[z-a]" is valid, equivalent to "\[z-a\]"
469
+ if (inClass) {
470
+ // split where the last [ was, make sure we don't have
471
+ // an invalid re. if so, re-walk the contents of the
472
+ // would-be class to re-translate any characters that
473
+ // were passed through as-is
474
+ // TODO: It would probably be faster to determine this
475
+ // without a try/catch and a new RegExp, but it's tricky
476
+ // to do safely. For now, this is safe and works.
477
+ var cs = pattern.substring(classStart + 1, i)
478
+ try {
479
+ RegExp('[' + cs + ']')
480
+ } catch (er) {
481
+ // not a valid class!
482
+ var sp = this.parse(cs, SUBPARSE)
483
+ re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]'
484
+ hasMagic = hasMagic || sp[1]
485
+ inClass = false
486
+ continue
487
+ }
488
+ }
489
+
490
+ // finish up the class.
491
+ hasMagic = true
492
+ inClass = false
493
+ re += c
494
+ continue
495
+
496
+ default:
497
+ // swallow any state char that wasn't consumed
498
+ clearStateChar()
499
+
500
+ if (escaping) {
501
+ // no need
502
+ escaping = false
503
+ } else if (reSpecials[c]
504
+ && !(c === '^' && inClass)) {
505
+ re += '\\'
506
+ }
507
+
508
+ re += c
509
+
510
+ } // switch
511
+ } // for
512
+
513
+ // handle the case where we left a class open.
514
+ // "[abc" is valid, equivalent to "\[abc"
515
+ if (inClass) {
516
+ // split where the last [ was, and escape it
517
+ // this is a huge pita. We now have to re-walk
518
+ // the contents of the would-be class to re-translate
519
+ // any characters that were passed through as-is
520
+ cs = pattern.substr(classStart + 1)
521
+ sp = this.parse(cs, SUBPARSE)
522
+ re = re.substr(0, reClassStart) + '\\[' + sp[0]
523
+ hasMagic = hasMagic || sp[1]
524
+ }
525
+
526
+ // handle the case where we had a +( thing at the *end*
527
+ // of the pattern.
528
+ // each pattern list stack adds 3 chars, and we need to go through
529
+ // and escape any | chars that were passed through as-is for the regexp.
530
+ // Go through and escape them, taking care not to double-escape any
531
+ // | chars that were already escaped.
532
+ for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
533
+ var tail = re.slice(pl.reStart + pl.open.length)
534
+ this.debug('setting tail', re, pl)
535
+ // maybe some even number of \, then maybe 1 \, followed by a |
536
+ tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function (_, $1, $2) {
537
+ if (!$2) {
538
+ // the | isn't already escaped, so escape it.
539
+ $2 = '\\'
540
+ }
541
+
542
+ // need to escape all those slashes *again*, without escaping the
543
+ // one that we need for escaping the | character. As it works out,
544
+ // escaping an even number of slashes can be done by simply repeating
545
+ // it exactly after itself. That's why this trick works.
546
+ //
547
+ // I am sorry that you have to see this.
548
+ return $1 + $1 + $2 + '|'
549
+ })
550
+
551
+ this.debug('tail=%j\n %s', tail, tail, pl, re)
552
+ var t = pl.type === '*' ? star
553
+ : pl.type === '?' ? qmark
554
+ : '\\' + pl.type
555
+
556
+ hasMagic = true
557
+ re = re.slice(0, pl.reStart) + t + '\\(' + tail
558
+ }
559
+
560
+ // handle trailing things that only matter at the very end.
561
+ clearStateChar()
562
+ if (escaping) {
563
+ // trailing \\
564
+ re += '\\\\'
565
+ }
566
+
567
+ // only need to apply the nodot start if the re starts with
568
+ // something that could conceivably capture a dot
569
+ var addPatternStart = false
570
+ switch (re.charAt(0)) {
571
+ case '.':
572
+ case '[':
573
+ case '(': addPatternStart = true
574
+ }
575
+
576
+ // Hack to work around lack of negative lookbehind in JS
577
+ // A pattern like: *.!(x).!(y|z) needs to ensure that a name
578
+ // like 'a.xyz.yz' doesn't match. So, the first negative
579
+ // lookahead, has to look ALL the way ahead, to the end of
580
+ // the pattern.
581
+ for (var n = negativeLists.length - 1; n > -1; n--) {
582
+ var nl = negativeLists[n]
583
+
584
+ var nlBefore = re.slice(0, nl.reStart)
585
+ var nlFirst = re.slice(nl.reStart, nl.reEnd - 8)
586
+ var nlLast = re.slice(nl.reEnd - 8, nl.reEnd)
587
+ var nlAfter = re.slice(nl.reEnd)
588
+
589
+ nlLast += nlAfter
590
+
591
+ // Handle nested stuff like *(*.js|!(*.json)), where open parens
592
+ // mean that we should *not* include the ) in the bit that is considered
593
+ // "after" the negated section.
594
+ var openParensBefore = nlBefore.split('(').length - 1
595
+ var cleanAfter = nlAfter
596
+ for (i = 0; i < openParensBefore; i++) {
597
+ cleanAfter = cleanAfter.replace(/\)[+*?]?/, '')
598
+ }
599
+ nlAfter = cleanAfter
600
+
601
+ var dollar = ''
602
+ if (nlAfter === '' && isSub !== SUBPARSE) {
603
+ dollar = '$'
604
+ }
605
+ var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast
606
+ re = newRe
607
+ }
608
+
609
+ // if the re is not "" at this point, then we need to make sure
610
+ // it doesn't match against an empty path part.
611
+ // Otherwise a/* will match a/, which it should not.
612
+ if (re !== '' && hasMagic) {
613
+ re = '(?=.)' + re
614
+ }
615
+
616
+ if (addPatternStart) {
617
+ re = patternStart + re
618
+ }
619
+
620
+ // parsing just a piece of a larger pattern.
621
+ if (isSub === SUBPARSE) {
622
+ return [re, hasMagic]
623
+ }
624
+
625
+ // skip the regexp for non-magical patterns
626
+ // unescape anything in it, though, so that it'll be
627
+ // an exact match against a file etc.
628
+ if (!hasMagic) {
629
+ return globUnescape(pattern)
630
+ }
631
+
632
+ var flags = options.nocase ? 'i' : ''
633
+ try {
634
+ var regExp = new RegExp('^' + re + '$', flags)
635
+ } catch (er) {
636
+ // If it was an invalid regular expression, then it can't match
637
+ // anything. This trick looks for a character after the end of
638
+ // the string, which is of course impossible, except in multi-line
639
+ // mode, but it's not a /m regex.
640
+ return new RegExp('$.')
641
+ }
642
+
643
+ regExp._glob = pattern
644
+ regExp._src = re
645
+
646
+ return regExp
647
+ }
648
+
649
+ minimatch.makeRe = function (pattern, options) {
650
+ return new Minimatch(pattern, options || {}).makeRe()
651
+ }
652
+
653
+ Minimatch.prototype.makeRe = makeRe
654
+ function makeRe () {
655
+ if (this.regexp || this.regexp === false) return this.regexp
656
+
657
+ // at this point, this.set is a 2d array of partial
658
+ // pattern strings, or "**".
659
+ //
660
+ // It's better to use .match(). This function shouldn't
661
+ // be used, really, but it's pretty convenient sometimes,
662
+ // when you just want to work with a regex.
663
+ var set = this.set
664
+
665
+ if (!set.length) {
666
+ this.regexp = false
667
+ return this.regexp
668
+ }
669
+ var options = this.options
670
+
671
+ var twoStar = options.noglobstar ? star
672
+ : options.dot ? twoStarDot
673
+ : twoStarNoDot
674
+ var flags = options.nocase ? 'i' : ''
675
+
676
+ var re = set.map(function (pattern) {
677
+ return pattern.map(function (p) {
678
+ return (p === GLOBSTAR) ? twoStar
679
+ : (typeof p === 'string') ? regExpEscape(p)
680
+ : p._src
681
+ }).join('\\\/')
682
+ }).join('|')
683
+
684
+ // must match entire pattern
685
+ // ending in a * or ** will make it less strict.
686
+ re = '^(?:' + re + ')$'
687
+
688
+ // can match anything, as long as it's not this.
689
+ if (this.negate) re = '^(?!' + re + ').*$'
690
+
691
+ try {
692
+ this.regexp = new RegExp(re, flags)
693
+ } catch (ex) {
694
+ this.regexp = false
695
+ }
696
+ return this.regexp
697
+ }
698
+
699
+ minimatch.match = function (list, pattern, options) {
700
+ options = options || {}
701
+ var mm = new Minimatch(pattern, options)
702
+ list = list.filter(function (f) {
703
+ return mm.match(f)
704
+ })
705
+ if (mm.options.nonull && !list.length) {
706
+ list.push(pattern)
707
+ }
708
+ return list
709
+ }
710
+
711
+ Minimatch.prototype.match = match
712
+ function match (f, partial) {
713
+ this.debug('match', f, this.pattern)
714
+ // short-circuit in the case of busted things.
715
+ // comments, etc.
716
+ if (this.comment) return false
717
+ if (this.empty) return f === ''
718
+
719
+ if (f === '/' && partial) return true
720
+
721
+ var options = this.options
722
+
723
+ // windows: need to use /, not \
724
+ if (path.sep !== '/') {
725
+ f = f.split(path.sep).join('/')
726
+ }
727
+
728
+ // treat the test path as a set of pathparts.
729
+ f = f.split(slashSplit)
730
+ this.debug(this.pattern, 'split', f)
731
+
732
+ // just ONE of the pattern sets in this.set needs to match
733
+ // in order for it to be valid. If negating, then just one
734
+ // match means that we have failed.
735
+ // Either way, return on the first hit.
736
+
737
+ var set = this.set
738
+ this.debug(this.pattern, 'set', set)
739
+
740
+ // Find the basename of the path by looking for the last non-empty segment
741
+ var filename
742
+ var i
743
+ for (i = f.length - 1; i >= 0; i--) {
744
+ filename = f[i]
745
+ if (filename) break
746
+ }
747
+
748
+ for (i = 0; i < set.length; i++) {
749
+ var pattern = set[i]
750
+ var file = f
751
+ if (options.matchBase && pattern.length === 1) {
752
+ file = [filename]
753
+ }
754
+ var hit = this.matchOne(file, pattern, partial)
755
+ if (hit) {
756
+ if (options.flipNegate) return true
757
+ return !this.negate
758
+ }
759
+ }
760
+
761
+ // didn't get any hits. this is success if it's a negative
762
+ // pattern, failure otherwise.
763
+ if (options.flipNegate) return false
764
+ return this.negate
765
+ }
766
+
767
+ // set partial to true to test if, for example,
768
+ // "/a/b" matches the start of "/*/b/*/d"
769
+ // Partial means, if you run out of file before you run
770
+ // out of pattern, then that's fine, as long as all
771
+ // the parts match.
772
+ Minimatch.prototype.matchOne = function (file, pattern, partial) {
773
+ var options = this.options
774
+
775
+ this.debug('matchOne',
776
+ { 'this': this, file: file, pattern: pattern })
777
+
778
+ this.debug('matchOne', file.length, pattern.length)
779
+
780
+ for (var fi = 0,
781
+ pi = 0,
782
+ fl = file.length,
783
+ pl = pattern.length
784
+ ; (fi < fl) && (pi < pl)
785
+ ; fi++, pi++) {
786
+ this.debug('matchOne loop')
787
+ var p = pattern[pi]
788
+ var f = file[fi]
789
+
790
+ this.debug(pattern, p, f)
791
+
792
+ // should be impossible.
793
+ // some invalid regexp stuff in the set.
794
+ if (p === false) return false
795
+
796
+ if (p === GLOBSTAR) {
797
+ this.debug('GLOBSTAR', [pattern, p, f])
798
+
799
+ // "**"
800
+ // a/**/b/**/c would match the following:
801
+ // a/b/x/y/z/c
802
+ // a/x/y/z/b/c
803
+ // a/b/x/b/x/c
804
+ // a/b/c
805
+ // To do this, take the rest of the pattern after
806
+ // the **, and see if it would match the file remainder.
807
+ // If so, return success.
808
+ // If not, the ** "swallows" a segment, and try again.
809
+ // This is recursively awful.
810
+ //
811
+ // a/**/b/**/c matching a/b/x/y/z/c
812
+ // - a matches a
813
+ // - doublestar
814
+ // - matchOne(b/x/y/z/c, b/**/c)
815
+ // - b matches b
816
+ // - doublestar
817
+ // - matchOne(x/y/z/c, c) -> no
818
+ // - matchOne(y/z/c, c) -> no
819
+ // - matchOne(z/c, c) -> no
820
+ // - matchOne(c, c) yes, hit
821
+ var fr = fi
822
+ var pr = pi + 1
823
+ if (pr === pl) {
824
+ this.debug('** at the end')
825
+ // a ** at the end will just swallow the rest.
826
+ // We have found a match.
827
+ // however, it will not swallow /.x, unless
828
+ // options.dot is set.
829
+ // . and .. are *never* matched by **, for explosively
830
+ // exponential reasons.
831
+ for (; fi < fl; fi++) {
832
+ if (file[fi] === '.' || file[fi] === '..' ||
833
+ (!options.dot && file[fi].charAt(0) === '.')) return false
834
+ }
835
+ return true
836
+ }
837
+
838
+ // ok, let's see if we can swallow whatever we can.
839
+ while (fr < fl) {
840
+ var swallowee = file[fr]
841
+
842
+ this.debug('\nglobstar while', file, fr, pattern, pr, swallowee)
843
+
844
+ // XXX remove this slice. Just pass the start index.
845
+ if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
846
+ this.debug('globstar found match!', fr, fl, swallowee)
847
+ // found a match.
848
+ return true
849
+ } else {
850
+ // can't swallow "." or ".." ever.
851
+ // can only swallow ".foo" when explicitly asked.
852
+ if (swallowee === '.' || swallowee === '..' ||
853
+ (!options.dot && swallowee.charAt(0) === '.')) {
854
+ this.debug('dot detected!', file, fr, pattern, pr)
855
+ break
856
+ }
857
+
858
+ // ** swallows a segment, and continue.
859
+ this.debug('globstar swallow a segment, and continue')
860
+ fr++
861
+ }
862
+ }
863
+
864
+ // no match was found.
865
+ // However, in partial mode, we can't say this is necessarily over.
866
+ // If there's more *pattern* left, then
867
+ if (partial) {
868
+ // ran out of file
869
+ this.debug('\n>>> no match, partial?', file, fr, pattern, pr)
870
+ if (fr === fl) return true
871
+ }
872
+ return false
873
+ }
874
+
875
+ // something other than **
876
+ // non-magic patterns just have to match exactly
877
+ // patterns with magic have been turned into regexps.
878
+ var hit
879
+ if (typeof p === 'string') {
880
+ if (options.nocase) {
881
+ hit = f.toLowerCase() === p.toLowerCase()
882
+ } else {
883
+ hit = f === p
884
+ }
885
+ this.debug('string match', p, f, hit)
886
+ } else {
887
+ hit = f.match(p)
888
+ this.debug('pattern match', p, f, hit)
889
+ }
890
+
891
+ if (!hit) return false
892
+ }
893
+
894
+ // Note: ending in / means that we'll get a final ""
895
+ // at the end of the pattern. This can only match a
896
+ // corresponding "" at the end of the file.
897
+ // If the file ends in /, then it can only match a
898
+ // a pattern that ends in /, unless the pattern just
899
+ // doesn't have any more for it. But, a/b/ should *not*
900
+ // match "a/b/*", even though "" matches against the
901
+ // [^/]*? pattern, except in partial mode, where it might
902
+ // simply not be reached yet.
903
+ // However, a/b/ should still satisfy a/*
904
+
905
+ // now either we fell off the end of the pattern, or we're done.
906
+ if (fi === fl && pi === pl) {
907
+ // ran out of pattern and filename at the same time.
908
+ // an exact hit!
909
+ return true
910
+ } else if (fi === fl) {
911
+ // ran out of file, but still had pattern left.
912
+ // this is ok if we're doing the match as part of
913
+ // a glob fs traversal.
914
+ return partial
915
+ } else if (pi === pl) {
916
+ // ran out of pattern, still have file left.
917
+ // this is only acceptable if we're on the very last
918
+ // empty segment of a file with a trailing slash.
919
+ // a/* should match a/b/
920
+ var emptyFileEnd = (fi === fl - 1) && (file[fi] === '')
921
+ return emptyFileEnd
922
+ }
923
+
924
+ // should be unreachable.
925
+ throw new Error('wtf?')
926
+ }
927
+
928
+ // replace stuff like \* with *
929
+ function globUnescape (s) {
930
+ return s.replace(/\\(.)/g, '$1')
931
+ }
932
+
933
+ function regExpEscape (s) {
934
+ return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
935
+ }
936
+
937
+ /*
938
+ * Public exports
939
+ *
940
+ */
941
+
942
+ exports.Minimatch = Minimatch;
943
+
944
+ })(typeof exports === 'undefined'? this['MinimatchLib']={}: exports);
945
+