执行过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
'use strict';
 
var _crypto;
 
function _load_crypto() {
  return (_crypto = _interopRequireDefault(require('crypto')));
}
 
var _fs;
 
function _load_fs() {
  return (_fs = _interopRequireDefault(require('fs')));
}
 
var _path;
 
function _load_path() {
  return (_path = _interopRequireDefault(require('path')));
}
 
var _babelPresetJest;
 
function _load_babelPresetJest() {
  return (_babelPresetJest = _interopRequireDefault(
    require('babel-preset-jest')
  ));
}
 
var _babelCore;
 
function _load_babelCore() {
  return (_babelCore = require('babel-core'));
}
 
var _babelPluginIstanbul;
 
function _load_babelPluginIstanbul() {
  return (_babelPluginIstanbul = _interopRequireDefault(
    require('babel-plugin-istanbul')
  ));
}
 
function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : {default: obj};
}
 
/**
 * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 *
 */
 
const BABELRC_FILENAME = '.babelrc';
const BABELRC_JS_FILENAME = '.babelrc.js';
const BABEL_CONFIG_JS_FILENAME = 'babel.config.js';
const BABEL_CONFIG_KEY = 'babel';
const PACKAGE_JSON = 'package.json';
const THIS_FILE = (_fs || _load_fs()).default.readFileSync(__filename);
 
const createTransformer = options => {
  const cache = Object.create(null);
 
  const getBabelRC = filename => {
    const paths = [];
    let directory = filename;
    while (
      directory !==
      (directory = (_path || _load_path()).default.dirname(directory))
    ) {
      if (cache[directory]) {
        break;
      }
 
      paths.push(directory);
      const configFilePath = (_path || _load_path()).default.join(
        directory,
        BABELRC_FILENAME
      );
      if ((_fs || _load_fs()).default.existsSync(configFilePath)) {
        cache[directory] = (_fs || _load_fs()).default.readFileSync(
          configFilePath,
          'utf8'
        );
        break;
      }
      let configJsFilePath = (_path || _load_path()).default.join(
        directory,
        BABELRC_JS_FILENAME
      );
      if ((_fs || _load_fs()).default.existsSync(configJsFilePath)) {
        // $FlowFixMe
        cache[directory] = JSON.stringify(require(configJsFilePath));
        break;
      }
      configJsFilePath = (_path || _load_path()).default.join(
        directory,
        BABEL_CONFIG_JS_FILENAME
      );
      if ((_fs || _load_fs()).default.existsSync(configJsFilePath)) {
        // $FlowFixMe
        cache[directory] = JSON.stringify(require(configJsFilePath));
        break;
      }
      const resolvedJsonFilePath = (_path || _load_path()).default.join(
        directory,
        PACKAGE_JSON
      );
      const packageJsonFilePath =
        resolvedJsonFilePath === PACKAGE_JSON
          ? (_path || _load_path()).default.resolve(directory, PACKAGE_JSON)
          : resolvedJsonFilePath;
      if ((_fs || _load_fs()).default.existsSync(packageJsonFilePath)) {
        // $FlowFixMe
        const packageJsonFileContents = require(packageJsonFilePath);
        if (packageJsonFileContents[BABEL_CONFIG_KEY]) {
          cache[directory] = JSON.stringify(
            packageJsonFileContents[BABEL_CONFIG_KEY]
          );
          break;
        }
      }
    }
    paths.forEach(directoryPath => (cache[directoryPath] = cache[directory]));
    return cache[directory] || '';
  };
 
  options = Object.assign({}, options, {
    compact: false,
    plugins: (options && options.plugins) || [],
    presets: ((options && options.presets) || []).concat([
      (_babelPresetJest || _load_babelPresetJest()).default
    ]),
    sourceMaps: 'both'
  });
  delete options.cacheDirectory;
  delete options.filename;
 
  return {
    canInstrument: true,
    getCacheKey: function(fileData, filename, configString, _ref) {
      let instrument = _ref.instrument,
        rootDir = _ref.rootDir;
 
      return (_crypto || _load_crypto()).default
        .createHash('md5')
        .update(THIS_FILE)
        .update('\0', 'utf8')
        .update(JSON.stringify(options))
        .update('\0', 'utf8')
        .update(fileData)
        .update('\0', 'utf8')
        .update((_path || _load_path()).default.relative(rootDir, filename))
        .update('\0', 'utf8')
        .update(configString)
        .update('\0', 'utf8')
        .update(getBabelRC(filename))
        .update('\0', 'utf8')
        .update(instrument ? 'instrument' : '')
        .digest('hex');
    },
    process: function(src, filename, config, transformOptions) {
      const altExts = config.moduleFileExtensions.map(
        extension => '.' + extension
      );
      if (
        (_babelCore || _load_babelCore()).util &&
        !(_babelCore || _load_babelCore()).util.canCompile(filename, altExts)
      ) {
        return src;
      }
 
      const theseOptions = Object.assign({filename: filename}, options);
      if (transformOptions && transformOptions.instrument) {
        theseOptions.auxiliaryCommentBefore = ' istanbul ignore next ';
        // Copied from jest-runtime transform.js
        theseOptions.plugins = theseOptions.plugins.concat([
          [
            (_babelPluginIstanbul || _load_babelPluginIstanbul()).default,
            {
              // files outside `cwd` will not be instrumented
              cwd: config.rootDir,
              exclude: []
            }
          ]
        ]);
      }
 
      // babel v7 might return null in the case when the file has been ignored.
      const transformResult = (0, (_babelCore || _load_babelCore()).transform)(
        src,
        theseOptions
      );
 
      return transformResult || src;
    }
  };
};
 
module.exports = createTransformer();
module.exports.createTransformer = createTransformer;