执行过npm install命令的vue-element-admin源码
康凯
2022-05-20 aa4c235a8ca67ea8b731f90c951a465e92c0a865
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
'use strict';
 
function _path() {
  const data = _interopRequireDefault(require('path'));
 
  _path = function _path() {
    return data;
  };
 
  return data;
}
 
function _fbWatchman() {
  const data = _interopRequireDefault(require('fb-watchman'));
 
  _fbWatchman = function _fbWatchman() {
    return data;
  };
 
  return data;
}
 
var fastPath = _interopRequireWildcard(require('../lib/fast_path'));
 
var _normalizePathSep = _interopRequireDefault(
  require('../lib/normalizePathSep')
);
 
var _constants = _interopRequireDefault(require('../constants'));
 
function _interopRequireWildcard(obj) {
  if (obj && obj.__esModule) {
    return obj;
  } else {
    var newObj = {};
    if (obj != null) {
      for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          var desc =
            Object.defineProperty && Object.getOwnPropertyDescriptor
              ? Object.getOwnPropertyDescriptor(obj, key)
              : {};
          if (desc.get || desc.set) {
            Object.defineProperty(newObj, key, desc);
          } else {
            newObj[key] = obj[key];
          }
        }
      }
    }
    newObj.default = obj;
    return newObj;
  }
}
 
function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : {default: obj};
}
 
function _slicedToArray(arr, i) {
  return (
    _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest()
  );
}
 
function _nonIterableRest() {
  throw new TypeError('Invalid attempt to destructure non-iterable instance');
}
 
function _iterableToArrayLimit(arr, i) {
  var _arr = [];
  var _n = true;
  var _d = false;
  var _e = undefined;
  try {
    for (
      var _i = arr[Symbol.iterator](), _s;
      !(_n = (_s = _i.next()).done);
      _n = true
    ) {
      _arr.push(_s.value);
      if (i && _arr.length === i) break;
    }
  } catch (err) {
    _d = true;
    _e = err;
  } finally {
    try {
      if (!_n && _i['return'] != null) _i['return']();
    } finally {
      if (_d) throw _e;
    }
  }
  return _arr;
}
 
function _arrayWithHoles(arr) {
  if (Array.isArray(arr)) return arr;
}
 
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  try {
    var info = gen[key](arg);
    var value = info.value;
  } catch (error) {
    reject(error);
    return;
  }
  if (info.done) {
    resolve(value);
  } else {
    Promise.resolve(value).then(_next, _throw);
  }
}
 
function _asyncToGenerator(fn) {
  return function() {
    var self = this,
      args = arguments;
    return new Promise(function(resolve, reject) {
      var gen = fn.apply(self, args);
      function _next(value) {
        asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'next', value);
      }
      function _throw(err) {
        asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'throw', err);
      }
      _next(undefined);
    });
  };
}
 
const watchmanURL =
  'https://facebook.github.io/watchman/docs/troubleshooting.html';
 
function WatchmanError(error) {
  error.message =
    `Watchman error: ${error.message.trim()}. Make sure watchman ` +
    `is running for this project. See ${watchmanURL}.`;
  return error;
}
 
module.exports =
  /*#__PURE__*/
  (function() {
    var _watchmanCrawl = _asyncToGenerator(function*(options) {
      const fields = ['name', 'exists', 'mtime_ms', 'size'];
      const data = options.data,
        extensions = options.extensions,
        ignore = options.ignore,
        rootDir = options.rootDir,
        roots = options.roots;
      const defaultWatchExpression = [
        'allof',
        ['type', 'f'],
        ['anyof', ...extensions.map(extension => ['suffix', extension])]
      ];
      const clocks = data.clocks;
      const client = new (_fbWatchman()).default.Client();
      let clientError;
      client.on('error', error => (clientError = WatchmanError(error))); // TODO: type better than `any`
 
      const cmd = (...args) =>
        new Promise((resolve, reject) =>
          client.command(args, (error, result) =>
            error ? reject(WatchmanError(error)) : resolve(result)
          )
        );
 
      if (options.computeSha1) {
        const _ref = yield cmd('list-capabilities'),
          capabilities = _ref.capabilities;
 
        if (capabilities.indexOf('field-content.sha1hex') !== -1) {
          fields.push('content.sha1hex');
        }
      }
 
      function getWatchmanRoots(_x2) {
        return _getWatchmanRoots.apply(this, arguments);
      }
 
      function _getWatchmanRoots() {
        _getWatchmanRoots = _asyncToGenerator(function*(roots) {
          const watchmanRoots = new Map();
          yield Promise.all(
            roots.map(
              /*#__PURE__*/
              (function() {
                var _ref2 = _asyncToGenerator(function*(root) {
                  const response = yield cmd('watch-project', root);
                  const existing = watchmanRoots.get(response.watch); // A root can only be filtered if it was never seen with a
                  // relative_path before.
 
                  const canBeFiltered = !existing || existing.length > 0;
 
                  if (canBeFiltered) {
                    if (response.relative_path) {
                      watchmanRoots.set(
                        response.watch,
                        (existing || []).concat(response.relative_path)
                      );
                    } else {
                      // Make the filter directories an empty array to signal that this
                      // root was already seen and needs to be watched for all files or
                      // directories.
                      watchmanRoots.set(response.watch, []);
                    }
                  }
                });
 
                return function(_x4) {
                  return _ref2.apply(this, arguments);
                };
              })()
            )
          );
          return watchmanRoots;
        });
        return _getWatchmanRoots.apply(this, arguments);
      }
 
      function queryWatchmanForDirs(_x3) {
        return _queryWatchmanForDirs.apply(this, arguments);
      }
 
      function _queryWatchmanForDirs() {
        _queryWatchmanForDirs = _asyncToGenerator(function*(
          rootProjectDirMappings
        ) {
          const files = new Map();
          let isFresh = false;
          yield Promise.all(
            Array.from(rootProjectDirMappings).map(
              /*#__PURE__*/
              (function() {
                var _ref3 = _asyncToGenerator(function*([
                  root,
                  directoryFilters
                ]) {
                  const expression = Array.from(defaultWatchExpression);
                  const glob = [];
 
                  if (directoryFilters.length > 0) {
                    expression.push([
                      'anyof',
                      ...directoryFilters.map(dir => ['dirname', dir])
                    ]);
                    var _iteratorNormalCompletion2 = true;
                    var _didIteratorError2 = false;
                    var _iteratorError2 = undefined;
 
                    try {
                      for (
                        var _iterator2 = directoryFilters[Symbol.iterator](),
                          _step2;
                        !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next())
                          .done);
                        _iteratorNormalCompletion2 = true
                      ) {
                        const directory = _step2.value;
                        var _iteratorNormalCompletion3 = true;
                        var _didIteratorError3 = false;
                        var _iteratorError3 = undefined;
 
                        try {
                          for (
                            var _iterator3 = extensions[Symbol.iterator](),
                              _step3;
                            !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next())
                              .done);
                            _iteratorNormalCompletion3 = true
                          ) {
                            const extension = _step3.value;
                            glob.push(`${directory}/**/*.${extension}`);
                          }
                        } catch (err) {
                          _didIteratorError3 = true;
                          _iteratorError3 = err;
                        } finally {
                          try {
                            if (
                              !_iteratorNormalCompletion3 &&
                              _iterator3.return != null
                            ) {
                              _iterator3.return();
                            }
                          } finally {
                            if (_didIteratorError3) {
                              throw _iteratorError3;
                            }
                          }
                        }
                      }
                    } catch (err) {
                      _didIteratorError2 = true;
                      _iteratorError2 = err;
                    } finally {
                      try {
                        if (
                          !_iteratorNormalCompletion2 &&
                          _iterator2.return != null
                        ) {
                          _iterator2.return();
                        }
                      } finally {
                        if (_didIteratorError2) {
                          throw _iteratorError2;
                        }
                      }
                    }
                  } else {
                    var _iteratorNormalCompletion4 = true;
                    var _didIteratorError4 = false;
                    var _iteratorError4 = undefined;
 
                    try {
                      for (
                        var _iterator4 = extensions[Symbol.iterator](), _step4;
                        !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next())
                          .done);
                        _iteratorNormalCompletion4 = true
                      ) {
                        const extension = _step4.value;
                        glob.push(`**/*.${extension}`);
                      }
                    } catch (err) {
                      _didIteratorError4 = true;
                      _iteratorError4 = err;
                    } finally {
                      try {
                        if (
                          !_iteratorNormalCompletion4 &&
                          _iterator4.return != null
                        ) {
                          _iterator4.return();
                        }
                      } finally {
                        if (_didIteratorError4) {
                          throw _iteratorError4;
                        }
                      }
                    }
                  }
 
                  const relativeRoot = fastPath.relative(rootDir, root);
                  const query = clocks.has(relativeRoot) // Use the `since` generator if we have a clock available
                    ? {
                        expression,
                        fields,
                        since: clocks.get(relativeRoot)
                      } // Otherwise use the `glob` filter
                    : {
                        expression,
                        fields,
                        glob
                      };
                  const response = yield cmd('query', root, query);
 
                  if ('warning' in response) {
                    console.warn('watchman warning: ', response.warning);
                  }
 
                  isFresh = isFresh || response.is_fresh_instance;
                  files.set(root, response);
                });
 
                return function(_x5) {
                  return _ref3.apply(this, arguments);
                };
              })()
            )
          );
          return {
            files,
            isFresh
          };
        });
        return _queryWatchmanForDirs.apply(this, arguments);
      }
 
      let files = data.files;
      let removedFiles = new Map();
      const changedFiles = new Map();
      let watchmanFiles;
      let isFresh = false;
 
      try {
        const watchmanRoots = yield getWatchmanRoots(roots);
        const watchmanFileResults = yield queryWatchmanForDirs(watchmanRoots); // Reset the file map if watchman was restarted and sends us a list of
        // files.
 
        if (watchmanFileResults.isFresh) {
          files = new Map();
          removedFiles = new Map(data.files);
          isFresh = true;
        }
 
        watchmanFiles = watchmanFileResults.files;
      } finally {
        client.end();
      }
 
      if (clientError) {
        throw clientError;
      } // TODO: remove non-null
 
      var _iteratorNormalCompletion = true;
      var _didIteratorError = false;
      var _iteratorError = undefined;
 
      try {
        for (
          var _iterator = watchmanFiles[Symbol.iterator](), _step;
          !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
          _iteratorNormalCompletion = true
        ) {
          const _step$value = _slicedToArray(_step.value, 2),
            watchRoot = _step$value[0],
            response = _step$value[1];
 
          const fsRoot = (0, _normalizePathSep.default)(watchRoot);
          const relativeFsRoot = fastPath.relative(rootDir, fsRoot);
          clocks.set(relativeFsRoot, response.clock);
          var _iteratorNormalCompletion5 = true;
          var _didIteratorError5 = false;
          var _iteratorError5 = undefined;
 
          try {
            for (
              var _iterator5 = response.files[Symbol.iterator](), _step5;
              !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done);
              _iteratorNormalCompletion5 = true
            ) {
              const fileData = _step5.value;
              const filePath =
                fsRoot +
                _path().default.sep +
                (0, _normalizePathSep.default)(fileData.name);
              const relativeFilePath = fastPath.relative(rootDir, filePath);
              const existingFileData = data.files.get(relativeFilePath); // If watchman is fresh, the removed files map starts with all files
              // and we remove them as we verify they still exist.
 
              if (isFresh && existingFileData && fileData.exists) {
                removedFiles.delete(relativeFilePath);
              }
 
              if (!fileData.exists) {
                // No need to act on files that do not exist and were not tracked.
                if (existingFileData) {
                  files.delete(relativeFilePath); // If watchman is not fresh, we will know what specific files were
                  // deleted since we last ran and can track only those files.
 
                  if (!isFresh) {
                    removedFiles.set(relativeFilePath, existingFileData);
                  }
                }
              } else if (!ignore(filePath)) {
                const mtime =
                  typeof fileData.mtime_ms === 'number'
                    ? fileData.mtime_ms
                    : fileData.mtime_ms.toNumber();
                const size = fileData.size;
                let sha1hex = fileData['content.sha1hex'];
 
                if (typeof sha1hex !== 'string' || sha1hex.length !== 40) {
                  sha1hex = null;
                }
 
                let nextData;
 
                if (
                  existingFileData &&
                  existingFileData[_constants.default.MTIME] === mtime
                ) {
                  nextData = existingFileData;
                } else if (
                  existingFileData &&
                  sha1hex &&
                  existingFileData[_constants.default.SHA1] === sha1hex
                ) {
                  nextData = [
                    existingFileData[0],
                    mtime,
                    existingFileData[2],
                    existingFileData[3],
                    existingFileData[4],
                    existingFileData[5]
                  ];
                } else {
                  // See ../constants.ts
                  nextData = ['', mtime, size, 0, '', sha1hex];
                }
 
                const mappings = options.mapper
                  ? options.mapper(filePath)
                  : null;
 
                if (mappings) {
                  var _iteratorNormalCompletion6 = true;
                  var _didIteratorError6 = false;
                  var _iteratorError6 = undefined;
 
                  try {
                    for (
                      var _iterator6 = mappings[Symbol.iterator](), _step6;
                      !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next())
                        .done);
                      _iteratorNormalCompletion6 = true
                    ) {
                      const absoluteVirtualFilePath = _step6.value;
 
                      if (!ignore(absoluteVirtualFilePath)) {
                        const relativeVirtualFilePath = fastPath.relative(
                          rootDir,
                          absoluteVirtualFilePath
                        );
                        files.set(relativeVirtualFilePath, nextData);
                        changedFiles.set(relativeVirtualFilePath, nextData);
                      }
                    }
                  } catch (err) {
                    _didIteratorError6 = true;
                    _iteratorError6 = err;
                  } finally {
                    try {
                      if (
                        !_iteratorNormalCompletion6 &&
                        _iterator6.return != null
                      ) {
                        _iterator6.return();
                      }
                    } finally {
                      if (_didIteratorError6) {
                        throw _iteratorError6;
                      }
                    }
                  }
                } else {
                  files.set(relativeFilePath, nextData);
                  changedFiles.set(relativeFilePath, nextData);
                }
              }
            }
          } catch (err) {
            _didIteratorError5 = true;
            _iteratorError5 = err;
          } finally {
            try {
              if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
                _iterator5.return();
              }
            } finally {
              if (_didIteratorError5) {
                throw _iteratorError5;
              }
            }
          }
        }
      } catch (err) {
        _didIteratorError = true;
        _iteratorError = err;
      } finally {
        try {
          if (!_iteratorNormalCompletion && _iterator.return != null) {
            _iterator.return();
          }
        } finally {
          if (_didIteratorError) {
            throw _iteratorError;
          }
        }
      }
 
      data.files = files;
      return {
        changedFiles: isFresh ? undefined : changedFiles,
        hasteMap: data,
        removedFiles
      };
    });
 
    function watchmanCrawl(_x) {
      return _watchmanCrawl.apply(this, arguments);
    }
 
    return watchmanCrawl;
  })();