执行过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
'use strict';
 
function _crypto() {
  const data = _interopRequireDefault(require('crypto'));
 
  _crypto = function _crypto() {
    return data;
  };
 
  return data;
}
 
function _fs() {
  const data = _interopRequireDefault(require('fs'));
 
  _fs = function _fs() {
    return data;
  };
 
  return data;
}
 
function _path() {
  const data = _interopRequireDefault(require('path'));
 
  _path = function _path() {
    return data;
  };
 
  return data;
}
 
function _core() {
  const data = require('@babel/core');
 
  _core = function _core() {
    return data;
  };
 
  return data;
}
 
function _chalk() {
  const data = _interopRequireDefault(require('chalk'));
 
  _chalk = function _chalk() {
    return data;
  };
 
  return data;
}
 
function _slash() {
  const data = _interopRequireDefault(require('slash'));
 
  _slash = function _slash() {
    return data;
  };
 
  return data;
}
 
function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : {default: obj};
}
 
function _objectSpread(target) {
  for (var i = 1; i < arguments.length; i++) {
    var source = arguments[i] != null ? arguments[i] : {};
    var ownKeys = Object.keys(source);
    if (typeof Object.getOwnPropertySymbols === 'function') {
      ownKeys = ownKeys.concat(
        Object.getOwnPropertySymbols(source).filter(function(sym) {
          return Object.getOwnPropertyDescriptor(source, sym).enumerable;
        })
      );
    }
    ownKeys.forEach(function(key) {
      _defineProperty(target, key, source[key]);
    });
  }
  return target;
}
 
function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }
  return obj;
}
 
const THIS_FILE = _fs().default.readFileSync(__filename);
 
const jestPresetPath = require.resolve('babel-preset-jest');
 
const babelIstanbulPlugin = require.resolve('babel-plugin-istanbul'); // Narrow down the types
 
const createTransformer = (options = {}) => {
  options = _objectSpread({}, options, {
    caller: {
      name: 'babel-jest',
      supportsStaticESM: false
    },
    compact: false,
    plugins: (options && options.plugins) || [],
    presets: ((options && options.presets) || []).concat(jestPresetPath),
    sourceMaps: 'both'
  });
 
  function loadBabelConfig(cwd, filename) {
    // `cwd` first to allow incoming options to override it
    const babelConfig = (0, _core().loadPartialConfig)(
      _objectSpread(
        {
          cwd
        },
        options,
        {
          filename
        }
      )
    );
 
    if (!babelConfig) {
      throw new Error(
        `babel-jest: Babel ignores ${_chalk().default.bold(
          (0, _slash().default)(_path().default.relative(cwd, filename))
        )} - make sure to include the file in Jest's ${_chalk().default.bold(
          'transformIgnorePatterns'
        )} as well.`
      );
    }
 
    return babelConfig;
  }
 
  return {
    canInstrument: true,
 
    getCacheKey(
      fileData,
      filename,
      configString,
      {config, instrument, rootDir}
    ) {
      const babelOptions = loadBabelConfig(config.cwd, filename);
      const configPath = [
        babelOptions.config || '',
        babelOptions.babelrc || ''
      ];
      return _crypto()
        .default.createHash('md5')
        .update(THIS_FILE)
        .update('\0', 'utf8')
        .update(JSON.stringify(babelOptions.options))
        .update('\0', 'utf8')
        .update(fileData)
        .update('\0', 'utf8')
        .update(_path().default.relative(rootDir, filename))
        .update('\0', 'utf8')
        .update(configString)
        .update('\0', 'utf8')
        .update(configPath.join(''))
        .update('\0', 'utf8')
        .update(instrument ? 'instrument' : '')
        .update('\0', 'utf8')
        .update(process.env.NODE_ENV || '')
        .update('\0', 'utf8')
        .update(process.env.BABEL_ENV || '')
        .digest('hex');
    },
 
    process(src, filename, config, transformOptions) {
      const babelOptions = _objectSpread(
        {},
        loadBabelConfig(config.cwd, filename).options
      );
 
      if (transformOptions && transformOptions.instrument) {
        babelOptions.auxiliaryCommentBefore = ' istanbul ignore next '; // Copied from jest-runtime transform.js
 
        babelOptions.plugins = (babelOptions.plugins || []).concat([
          [
            babelIstanbulPlugin,
            {
              // files outside `cwd` will not be instrumented
              cwd: config.rootDir,
              exclude: []
            }
          ]
        ]);
      }
 
      const transformResult = (0, _core().transformSync)(src, babelOptions);
 
      if (transformResult) {
        const code = transformResult.code,
          map = transformResult.map;
 
        if (typeof code === 'string') {
          return {
            code,
            map
          };
        }
      }
 
      return src;
    }
  };
};
 
const transformer = _objectSpread({}, createTransformer(), {
  // Assigned here so only the exported transformer has `createTransformer`,
  // instead of all created transformers by the function
  createTransformer
});
 
module.exports = transformer;