Updating NPM dependencies

This commit is contained in:
Drew Heavner
2020-11-11 13:30:52 +00:00
committed by GitHub
parent 7a6fb66c63
commit bd487ef324
9068 changed files with 1400893 additions and 587661 deletions

View File

@@ -3,52 +3,23 @@
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.createTranspilingRequire = createTranspilingRequire;
exports.default = void 0;
function _crypto() {
const data = _interopRequireDefault(require('crypto'));
const data = require('crypto');
_crypto = function _crypto() {
_crypto = function () {
return data;
};
return data;
}
function _path() {
const data = _interopRequireDefault(require('path'));
function path() {
const data = _interopRequireWildcard(require('path'));
_path = function _path() {
return data;
};
return data;
}
function _vm() {
const data = _interopRequireDefault(require('vm'));
_vm = function _vm() {
return data;
};
return data;
}
function _jestUtil() {
const data = require('jest-util');
_jestUtil = function _jestUtil() {
return data;
};
return data;
}
function _gracefulFs() {
const data = _interopRequireDefault(require('graceful-fs'));
_gracefulFs = function _gracefulFs() {
path = function () {
return data;
};
@@ -58,7 +29,7 @@ function _gracefulFs() {
function _core() {
const data = require('@babel/core');
_core = function _core() {
_core = function () {
return data;
};
@@ -68,7 +39,7 @@ function _core() {
function _babelPluginIstanbul() {
const data = _interopRequireDefault(require('babel-plugin-istanbul'));
_babelPluginIstanbul = function _babelPluginIstanbul() {
_babelPluginIstanbul = function () {
return data;
};
@@ -76,19 +47,9 @@ function _babelPluginIstanbul() {
}
function _convertSourceMap() {
const data = _interopRequireDefault(require('convert-source-map'));
const data = require('convert-source-map');
_convertSourceMap = function _convertSourceMap() {
return data;
};
return data;
}
function _jestHasteMap() {
const data = _interopRequireDefault(require('jest-haste-map'));
_jestHasteMap = function _jestHasteMap() {
_convertSourceMap = function () {
return data;
};
@@ -98,37 +59,17 @@ function _jestHasteMap() {
function _fastJsonStableStringify() {
const data = _interopRequireDefault(require('fast-json-stable-stringify'));
_fastJsonStableStringify = function _fastJsonStableStringify() {
_fastJsonStableStringify = function () {
return data;
};
return data;
}
function _slash() {
const data = _interopRequireDefault(require('slash'));
function fs() {
const data = _interopRequireWildcard(require('graceful-fs'));
_slash = function _slash() {
return data;
};
return data;
}
function _writeFileAtomic() {
const data = _interopRequireDefault(require('write-file-atomic'));
_writeFileAtomic = function _writeFileAtomic() {
return data;
};
return data;
}
function _realpathNative() {
const data = require('realpath-native');
_realpathNative = function _realpathNative() {
fs = function () {
return data;
};
@@ -138,23 +79,105 @@ function _realpathNative() {
function _pirates() {
const data = require('pirates');
_pirates = function _pirates() {
_pirates = function () {
return data;
};
return data;
}
var _shouldInstrument = _interopRequireDefault(require('./shouldInstrument'));
function _slash() {
const data = _interopRequireDefault(require('slash'));
_slash = function () {
return data;
};
return data;
}
function _writeFileAtomic() {
const data = require('write-file-atomic');
_writeFileAtomic = function () {
return data;
};
return data;
}
function _jestHasteMap() {
const data = _interopRequireDefault(require('jest-haste-map'));
_jestHasteMap = function () {
return data;
};
return data;
}
function _jestUtil() {
const data = require('jest-util');
_jestUtil = function () {
return data;
};
return data;
}
var _enhanceUnexpectedTokenMessage = _interopRequireDefault(
require('./enhanceUnexpectedTokenMessage')
);
var _shouldInstrument = _interopRequireDefault(require('./shouldInstrument'));
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {default: obj};
}
function _getRequireWildcardCache() {
if (typeof WeakMap !== 'function') return null;
var cache = new WeakMap();
_getRequireWildcardCache = function () {
return cache;
};
return cache;
}
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
return obj;
}
if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
return {default: obj};
}
var cache = _getRequireWildcardCache();
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor =
Object.defineProperty && Object.getOwnPropertyDescriptor;
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor
? Object.getOwnPropertyDescriptor(obj, key)
: null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
@@ -169,61 +192,22 @@ function _defineProperty(obj, key, value) {
return obj;
}
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);
});
};
}
// Use `require` to avoid TS rootDir
const _require = require('../package.json'),
VERSION = _require.version; // This data structure is used to avoid recalculating some data every time that
const {version: VERSION} = require('../package.json');
// This data structure is used to avoid recalculating some data every time that
// we need to transform a file. Since ScriptTransformer is instantiated for each
// file we need to keep this object in the local scope of this module.
const projectCaches = new WeakMap(); // To reset the cache for specific changesets (rather than package version).
const projectCaches = new Map(); // To reset the cache for specific changesets (rather than package version).
const CACHE_VERSION = '1';
function waitForPromiseWithCleanup(_x, _x2) {
return _waitForPromiseWithCleanup.apply(this, arguments);
}
function _waitForPromiseWithCleanup() {
_waitForPromiseWithCleanup = _asyncToGenerator(function*(promise, cleanup) {
try {
yield promise;
} finally {
cleanup();
}
});
return _waitForPromiseWithCleanup.apply(this, arguments);
async function waitForPromiseWithCleanup(promise, cleanup) {
try {
await promise;
} finally {
cleanup();
}
}
class ScriptTransformer {
@@ -239,41 +223,48 @@ class ScriptTransformer {
this._config = config;
this._transformCache = new Map();
this._transformConfigCache = new Map();
let projectCache = projectCaches.get(config);
const configString = (0, _fastJsonStableStringify().default)(this._config);
let projectCache = projectCaches.get(configString);
if (!projectCache) {
projectCache = {
configString: (0, _fastJsonStableStringify().default)(this._config),
configString,
ignorePatternsRegExp: calcIgnorePatternRegExp(this._config),
transformRegExp: calcTransformRegExp(this._config),
transformedFiles: new Map()
};
projectCaches.set(config, projectCache);
projectCaches.set(configString, projectCache);
}
this._cache = projectCache;
}
_getCacheKey(fileData, filename, instrument) {
_getCacheKey(
fileData,
filename,
instrument,
supportsDynamicImport,
supportsStaticESM
) {
const configString = this._cache.configString;
const transformer = this._getTransformer(filename);
if (transformer && typeof transformer.getCacheKey === 'function') {
return _crypto()
.default.createHash('md5')
return (0, _crypto().createHash)('md5')
.update(
transformer.getCacheKey(fileData, filename, configString, {
config: this._config,
instrument,
rootDir: this._config.rootDir
rootDir: this._config.rootDir,
supportsDynamicImport,
supportsStaticESM
})
)
.update(CACHE_VERSION)
.digest('hex');
} else {
return _crypto()
.default.createHash('md5')
return (0, _crypto().createHash)('md5')
.update(fileData)
.update(configString)
.update(instrument ? 'instrument' : '')
@@ -283,27 +274,34 @@ class ScriptTransformer {
}
}
_getFileCachePath(filename, content, instrument) {
_getFileCachePath(
filename,
content,
instrument,
supportsDynamicImport,
supportsStaticESM
) {
const baseCacheDir = _jestHasteMap().default.getCacheFilePath(
this._config.cacheDirectory,
'jest-transform-cache-' + this._config.name,
VERSION
);
const cacheKey = this._getCacheKey(content, filename, instrument); // Create sub folders based on the cacheKey to avoid creating one
const cacheKey = this._getCacheKey(
content,
filename,
instrument,
supportsDynamicImport,
supportsStaticESM
); // Create sub folders based on the cacheKey to avoid creating one
// directory with many files.
const cacheDir = _path().default.join(
baseCacheDir,
cacheKey[0] + cacheKey[1]
);
const cacheFilenamePrefix = _path()
.default.basename(filename, _path().default.extname(filename))
const cacheDir = path().join(baseCacheDir, cacheKey[0] + cacheKey[1]);
const cacheFilenamePrefix = path()
.basename(filename, path().extname(filename))
.replace(/\W/g, '');
const cachePath = (0, _slash().default)(
_path().default.join(cacheDir, cacheFilenamePrefix + '_' + cacheKey)
path().join(cacheDir, cacheFilenamePrefix + '_' + cacheKey)
);
(0, _jestUtil().createDirectory)(cacheDir);
return cachePath;
@@ -330,48 +328,61 @@ class ScriptTransformer {
}
_getTransformer(filename) {
let transform = null;
if (!this._config.transform || !this._config.transform.length) {
return null;
}
const transformPath = this._getTransformPath(filename);
if (transformPath) {
const transformer = this._transformCache.get(transformPath);
if (transformer != null) {
return transformer;
}
transform = require(transformPath);
const transformerConfig = this._transformConfigCache.get(transformPath);
if (typeof transform.createTransformer === 'function') {
transform = transform.createTransformer(transformerConfig);
}
if (typeof transform.process !== 'function') {
throw new TypeError(
'Jest: a transform must export a `process` function.'
);
}
this._transformCache.set(transformPath, transform);
if (!transformPath) {
return null;
}
const transformer = this._transformCache.get(transformPath);
if (transformer) {
return transformer;
}
let transform = require(transformPath);
if (!transform) {
throw new TypeError('Jest: a transform must export something.');
}
const transformerConfig = this._transformConfigCache.get(transformPath);
if (typeof transform.createTransformer === 'function') {
transform = transform.createTransformer(transformerConfig);
}
if (typeof transform.process !== 'function') {
throw new TypeError(
'Jest: a transform must export a `process` function.'
);
}
this._transformCache.set(transformPath, transform);
return transform;
}
_instrumentFile(filename, content) {
const result = (0, _core().transformSync)(content, {
_instrumentFile(
filename,
input,
supportsDynamicImport,
supportsStaticESM,
canMapToInput
) {
const inputCode = typeof input === 'string' ? input : input.code;
const inputMap = typeof input === 'string' ? null : input.map;
const result = (0, _core().transformSync)(inputCode, {
auxiliaryCommentBefore: ' istanbul ignore next ',
babelrc: false,
caller: {
name: '@jest/transform',
supportsStaticESM: false
supportsDynamicImport,
supportsStaticESM
},
configFile: false,
filename,
@@ -383,42 +394,45 @@ class ScriptTransformer {
// files outside `cwd` will not be instrumented
cwd: this._config.rootDir,
exclude: [],
extension: false,
inputSourceMap: inputMap,
useInlineSourceMaps: false
}
]
]
],
sourceMaps: canMapToInput ? 'both' : false
});
if (result) {
const code = result.code;
if (code) {
return code;
}
if (result && result.code) {
return result;
}
return content;
}
_getRealPath(filepath) {
try {
return (0, _realpathNative().sync)(filepath) || filepath;
} catch (err) {
return filepath;
}
return input;
} // We don't want to expose transformers to the outside - this function is just
// to warm up `this._transformCache`
preloadTransformer(filepath) {
this._getTransformer(filepath);
}
} // TODO: replace third argument with TransformOptions in Jest 26
transformSource(filepath, content, instrument) {
const filename = this._getRealPath(filepath);
transformSource(
filepath,
content,
instrument,
supportsDynamicImport = false,
supportsStaticESM = false
) {
const filename = (0, _jestUtil().tryRealpath)(filepath);
const transform = this._getTransformer(filename);
const cacheFilePath = this._getFileCachePath(filename, content, instrument);
const cacheFilePath = this._getFileCachePath(
filename,
content,
instrument,
supportsDynamicImport,
supportsStaticESM
);
let sourceMapPath = cacheFilePath + '.map'; // Ignore cache if `config.cache` is set (--no-cache)
@@ -427,10 +441,7 @@ class ScriptTransformer {
// logic and will handle it based on `config.collectCoverage` option
const transformWillInstrument =
shouldCallTransform && transform && transform.canInstrument; // If we handle the coverage instrumentation, we should try to map code
// coverage against original source with any provided source map
const mapCoverage = instrument && !transformWillInstrument;
shouldCallTransform && transform && transform.canInstrument;
if (code) {
// This is broken: we return the code, and a path for the source map
@@ -439,7 +450,7 @@ class ScriptTransformer {
// two separate processes write concurrently to the same cache files.
return {
code,
mapCoverage,
originalCode: content,
sourceMapPath
};
}
@@ -451,7 +462,9 @@ class ScriptTransformer {
if (transform && shouldCallTransform) {
const processed = transform.process(content, filename, this._config, {
instrument
instrument,
supportsDynamicImport,
supportsStaticESM
});
if (typeof processed === 'string') {
@@ -467,28 +480,60 @@ class ScriptTransformer {
}
if (!transformed.map) {
//Could be a potential freeze here.
//See: https://github.com/facebook/jest/pull/5177#discussion_r158883570
const inlineSourceMap = _convertSourceMap().default.fromSource(
transformed.code
);
try {
//Could be a potential freeze here.
//See: https://github.com/facebook/jest/pull/5177#discussion_r158883570
const inlineSourceMap = (0, _convertSourceMap().fromSource)(
transformed.code
);
if (inlineSourceMap) {
transformed.map = inlineSourceMap.toJSON();
if (inlineSourceMap) {
transformed.map = inlineSourceMap.toObject();
}
} catch {
const transformPath = this._getTransformPath(filename);
console.warn(
`jest-transform: The source map produced for the file ${filename} ` +
`by ${transformPath} was invalid. Proceeding without source ` +
'mapping for that file.'
);
}
}
} // Apply instrumentation to the code if necessary, keeping the instrumented code and new map
let map = transformed.map;
if (!transformWillInstrument && instrument) {
code = this._instrumentFile(filename, transformed.code);
/**
* We can map the original source code to the instrumented code ONLY if
* - the process of transforming the code produced a source map e.g. ts-jest
* - we did not transform the source code
*
* Otherwise we cannot make any statements about how the instrumented code corresponds to the original code,
* and we should NOT emit any source maps
*
*/
const shouldEmitSourceMaps =
(transform != null && map != null) || transform == null;
const instrumented = this._instrumentFile(
filename,
transformed,
supportsDynamicImport,
supportsStaticESM,
shouldEmitSourceMaps
);
code =
typeof instrumented === 'string' ? instrumented : instrumented.code;
map = typeof instrumented === 'string' ? null : instrumented.map;
} else {
code = transformed.code;
}
if (transformed.map) {
if (map) {
const sourceMapContent =
typeof transformed.map === 'string'
? transformed.map
: JSON.stringify(transformed.map);
typeof map === 'string' ? map : JSON.stringify(map);
writeCacheFile(sourceMapPath, sourceMapContent);
} else {
sourceMapPath = null;
@@ -497,63 +542,48 @@ class ScriptTransformer {
writeCodeCacheFile(cacheFilePath, code);
return {
code,
mapCoverage,
originalCode: content,
sourceMapPath
};
}
_transformAndBuildScript(filename, options, instrument, fileSource) {
const isInternalModule = !!(options && options.isInternalModule);
const isCoreModule = !!(options && options.isCoreModule);
const {
isCoreModule,
isInternalModule,
supportsDynamicImport,
supportsStaticESM
} = options;
const content = stripShebang(
fileSource || _gracefulFs().default.readFileSync(filename, 'utf8')
fileSource || fs().readFileSync(filename, 'utf8')
);
let wrappedCode;
let code = content;
let sourceMapPath = null;
let mapCoverage = false;
const willTransform =
!isInternalModule &&
!isCoreModule &&
(this.shouldTransform(filename) || instrument);
try {
const extraGlobals = (options && options.extraGlobals) || [];
if (willTransform) {
const transformedSource = this.transformSource(
filename,
content,
instrument
instrument,
supportsDynamicImport,
supportsStaticESM
);
wrappedCode = wrap(transformedSource.code, ...extraGlobals);
code = transformedSource.code;
sourceMapPath = transformedSource.sourceMapPath;
mapCoverage = transformedSource.mapCoverage;
} else {
wrappedCode = wrap(content, ...extraGlobals);
}
return {
mapCoverage,
script: new (_vm()).default.Script(wrappedCode, {
displayErrors: true,
filename: isCoreModule ? 'jest-nodejs-core-' + filename : filename
}),
code,
originalCode: content,
sourceMapPath
};
} catch (e) {
if (e.codeFrame) {
e.stack = e.message + '\n' + e.codeFrame;
}
if (
e instanceof SyntaxError &&
e.message.includes('Unexpected token') &&
!e.message.includes(' expected')
) {
throw (0, _enhanceUnexpectedTokenMessage.default)(e);
}
throw e;
throw (0, _enhanceUnexpectedTokenMessage.default)(e);
}
}
@@ -562,11 +592,9 @@ class ScriptTransformer {
let instrument = false;
if (!options.isCoreModule) {
instrument = (0, _shouldInstrument.default)(
filename,
options,
this._config
);
instrument =
options.coverageProvider === 'babel' &&
(0, _shouldInstrument.default)(filename, options, this._config);
scriptCacheKey = getScriptCacheKey(filename, instrument);
const result = this._cache.transformedFiles.get(scriptCacheKey);
@@ -591,19 +619,23 @@ class ScriptTransformer {
}
transformJson(filename, options, fileSource) {
const isInternalModule = options.isInternalModule;
const isCoreModule = options.isCoreModule;
const {
isCoreModule,
isInternalModule,
supportsDynamicImport,
supportsStaticESM
} = options;
const willTransform =
!isInternalModule && !isCoreModule && this.shouldTransform(filename);
if (willTransform) {
const _this$transformSource = this.transformSource(
filename,
fileSource,
false
),
transformedJsonSource = _this$transformSource.code;
const {code: transformedJsonSource} = this.transformSource(
filename,
fileSource,
false,
supportsDynamicImport,
supportsStaticESM
);
return transformedJsonSource;
}
@@ -619,13 +651,17 @@ class ScriptTransformer {
(code, filename) => {
try {
transforming = true;
return this.transformSource(filename, code, false).code || code;
return (
// we might wanna do `supportsDynamicImport` at some point
this.transformSource(filename, code, false, false, false).code ||
code
);
} finally {
transforming = false;
}
},
{
exts: [_path().default.extname(moduleName)],
exts: this._config.moduleFileExtensions.map(ext => `.${ext}`),
ignoreNodeModules: false,
matcher: filename => {
if (transforming) {
@@ -662,7 +698,7 @@ class ScriptTransformer {
/**
* @deprecated use `this.shouldTransform` instead
*/
// @ts-ignore: Unused and private - remove in Jest 25
// @ts-expect-error: Unused and private - remove in Jest 25
_shouldTransform(filename) {
return this.shouldTransform(filename);
@@ -675,16 +711,29 @@ class ScriptTransformer {
!!this._config.transform && !!this._config.transform.length && !isIgnored
);
}
}
} // TODO: do we need to define the generics twice?
exports.default = ScriptTransformer;
_defineProperty(ScriptTransformer, 'EVAL_RESULT_VARIABLE', void 0);
function createTranspilingRequire(config) {
const transformer = new ScriptTransformer(config);
return function requireAndTranspileModule(
resolverPath,
applyInteropRequireDefault = false
) {
const transpiledModule = transformer.requireAndTranspileModule(
resolverPath
);
return applyInteropRequireDefault
? (0, _jestUtil().interopRequireDefault)(transpiledModule).default
: transpiledModule;
};
}
const removeFile = path => {
try {
_gracefulFs().default.unlinkSync(path);
} catch (e) {}
fs().unlinkSync(path);
} catch {}
};
const stripShebang = content => {
@@ -705,11 +754,7 @@ const stripShebang = content => {
*/
function writeCodeCacheFile(cachePath, code) {
const checksum = _crypto()
.default.createHash('md5')
.update(code)
.digest('hex');
const checksum = (0, _crypto().createHash)('md5').update(code).digest('hex');
writeCacheFile(cachePath, checksum + '\n' + code);
}
/**
@@ -727,11 +772,7 @@ function readCodeCacheFile(cachePath) {
}
const code = content.substr(33);
const checksum = _crypto()
.default.createHash('md5')
.update(code)
.digest('hex');
const checksum = (0, _crypto().createHash)('md5').update(code).digest('hex');
if (checksum === content.substr(0, 32)) {
return code;
@@ -748,8 +789,9 @@ function readCodeCacheFile(cachePath) {
const writeCacheFile = (cachePath, fileData) => {
try {
_writeFileAtomic().default.sync(cachePath, fileData, {
encoding: 'utf8'
(0, _writeFileAtomic().sync)(cachePath, fileData, {
encoding: 'utf8',
fsync: false
});
} catch (e) {
if (cacheWriteErrorSafeToIgnore(e, cachePath)) {
@@ -775,17 +817,17 @@ const writeCacheFile = (cachePath, fileData) => {
const cacheWriteErrorSafeToIgnore = (e, cachePath) =>
process.platform === 'win32' &&
e.code === 'EPERM' &&
_gracefulFs().default.existsSync(cachePath);
fs().existsSync(cachePath);
const readCacheFile = cachePath => {
if (!_gracefulFs().default.existsSync(cachePath)) {
if (!fs().existsSync(cachePath)) {
return null;
}
let fileData;
try {
fileData = _gracefulFs().default.readFileSync(cachePath, 'utf8');
fileData = fs().readFileSync(cachePath, 'utf8');
} catch (e) {
e.message =
'jest: failed to read cache file: ' +
@@ -806,8 +848,7 @@ const readCacheFile = cachePath => {
};
const getScriptCacheKey = (filename, instrument) => {
const mtime = _gracefulFs().default.statSync(filename).mtime;
const mtime = fs().statSync(filename).mtime;
return filename + '_' + mtime.getTime() + (instrument ? '_instrumented' : '');
};
@@ -839,25 +880,3 @@ const calcTransformRegExp = config => {
return transformRegexp;
};
const wrap = (content, ...extras) => {
const globals = new Set([
'module',
'exports',
'require',
'__dirname',
'__filename',
'global',
'jest',
...extras
]);
return (
'({"' +
ScriptTransformer.EVAL_RESULT_VARIABLE +
`":function(${Array.from(globals).join(',')}){` +
content +
'\n}});'
);
}; // TODO: Can this be added to the static property?
ScriptTransformer.EVAL_RESULT_VARIABLE = 'Object.<anonymous>';