jest-haste-map
Advanced tools
Comparing version 29.1.2 to 29.2.0
@@ -7,3 +7,2 @@ 'use strict'; | ||
exports.default = void 0; | ||
/** | ||
@@ -15,2 +14,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
// This list is compiled after the MDN list of the most common MIME types (see | ||
@@ -25,5 +25,7 @@ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/ | ||
// Feel free to add any extensions that cannot be a Haste module. | ||
const extensions = new Set([ | ||
// JSONs are never haste modules, except for "package.json", which is handled. | ||
'.json', // Image extensions. | ||
'.json', | ||
// Image extensions. | ||
'.bmp', | ||
@@ -38,3 +40,4 @@ '.gif', | ||
'.tif', | ||
'.webp', // Video extensions. | ||
'.webp', | ||
// Video extensions. | ||
'.avi', | ||
@@ -47,3 +50,4 @@ '.mp4', | ||
'.3gp', | ||
'.3g2', // Audio extensions. | ||
'.3g2', | ||
// Audio extensions. | ||
'.aac', | ||
@@ -56,3 +60,4 @@ '.midi', | ||
'.3gp', | ||
'.3g2', // Font extensions. | ||
'.3g2', | ||
// Font extensions. | ||
'.eot', | ||
@@ -59,0 +64,0 @@ '.otf', |
@@ -7,3 +7,2 @@ 'use strict'; | ||
exports.default = void 0; | ||
/** | ||
@@ -29,3 +28,2 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
DEPENDENCY_DELIM: '\0', | ||
/* file map attributes */ | ||
@@ -38,11 +36,8 @@ ID: 0, | ||
SHA1: 5, | ||
/* module map attributes */ | ||
PATH: 0, | ||
TYPE: 1, | ||
/* module types */ | ||
MODULE: 0, | ||
PACKAGE: 1, | ||
/* platforms */ | ||
@@ -53,4 +48,3 @@ GENERIC_PLATFORM: 'g', | ||
/* eslint-enable */ | ||
var _default = constants; | ||
exports.default = _default; |
@@ -7,41 +7,28 @@ 'use strict'; | ||
exports.nodeCrawl = nodeCrawl; | ||
function _child_process() { | ||
const data = require('child_process'); | ||
_child_process = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function path() { | ||
const data = _interopRequireWildcard(require('path')); | ||
path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function fs() { | ||
const data = _interopRequireWildcard(require('graceful-fs')); | ||
fs = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _constants = _interopRequireDefault(require('../constants')); | ||
var fastPath = _interopRequireWildcard(require('../lib/fast_path')); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -55,3 +42,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -89,3 +75,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
/** | ||
@@ -97,2 +82,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
async function hasNativeFindSupport(forceNodeFilesystemAPI) { | ||
@@ -102,3 +88,2 @@ if (forceNodeFilesystemAPI) { | ||
} | ||
try { | ||
@@ -133,7 +118,5 @@ return await new Promise(resolve => { | ||
} | ||
function find(roots, extensions, ignore, enableSymlinks, callback) { | ||
const result = []; | ||
let activeCalls = 0; | ||
function search(directory) { | ||
@@ -148,3 +131,2 @@ activeCalls++; | ||
activeCalls--; | ||
if (err) { | ||
@@ -154,17 +136,12 @@ if (activeCalls === 0) { | ||
} | ||
return; | ||
} | ||
entries.forEach(entry => { | ||
const file = path().join(directory, entry.name); | ||
if (ignore(file)) { | ||
return; | ||
} | ||
if (entry.isSymbolicLink()) { | ||
return; | ||
} | ||
if (entry.isDirectory()) { | ||
@@ -174,9 +151,9 @@ search(file); | ||
} | ||
activeCalls++; | ||
const stat = enableSymlinks ? fs().stat : fs().lstat; | ||
stat(file, (err, stat) => { | ||
activeCalls--; // This logic is unnecessary for node > v10.10, but leaving it in | ||
activeCalls--; | ||
// This logic is unnecessary for node > v10.10, but leaving it in | ||
// since we need it for backwards-compatibility still. | ||
if (!err && stat && !stat.isSymbolicLink()) { | ||
@@ -187,3 +164,2 @@ if (stat.isDirectory()) { | ||
const ext = path().extname(file).substr(1); | ||
if (extensions.indexOf(ext) !== -1) { | ||
@@ -194,3 +170,2 @@ result.push([file, stat.mtime.getTime(), stat.size]); | ||
} | ||
if (activeCalls === 0) { | ||
@@ -201,3 +176,2 @@ callback(result); | ||
}); | ||
if (activeCalls === 0) { | ||
@@ -209,3 +183,2 @@ callback(result); | ||
} | ||
if (roots.length > 0) { | ||
@@ -217,6 +190,4 @@ roots.forEach(search); | ||
} | ||
function findNative(roots, extensions, ignore, enableSymlinks, callback) { | ||
const args = Array.from(roots); | ||
if (enableSymlinks) { | ||
@@ -227,7 +198,5 @@ args.push('(', '-type', 'f', '-o', '-type', 'l', ')'); | ||
} | ||
if (extensions.length) { | ||
args.push('('); | ||
} | ||
extensions.forEach((ext, index) => { | ||
@@ -237,14 +206,10 @@ if (index) { | ||
} | ||
args.push('-iname'); | ||
args.push(`*.${ext}`); | ||
}); | ||
if (extensions.length) { | ||
args.push(')'); | ||
} | ||
const child = (0, _child_process().spawn)('find', args); | ||
let stdout = ''; | ||
if (child.stdout === null) { | ||
@@ -255,3 +220,2 @@ throw new Error( | ||
} | ||
child.stdout.setEncoding('utf-8'); | ||
@@ -266,3 +230,2 @@ child.stdout.on('data', data => (stdout += data)); | ||
let count = lines.length; | ||
if (!count) { | ||
@@ -277,3 +240,2 @@ callback([]); | ||
} | ||
if (--count === 0) { | ||
@@ -287,3 +249,2 @@ callback(result); | ||
} | ||
async function nodeCrawl(options) { | ||
@@ -308,3 +269,2 @@ const { | ||
const existingFile = data.files.get(relativeFilePath); | ||
if (existingFile && existingFile[_constants.default.MTIME] === mtime) { | ||
@@ -316,3 +276,2 @@ files.set(relativeFilePath, existingFile); | ||
} | ||
removedFiles.delete(relativeFilePath); | ||
@@ -326,3 +285,2 @@ }); | ||
}; | ||
if (useNativeFind) { | ||
@@ -329,0 +287,0 @@ findNative(roots, extensions, ignore, enableSymlinks, callback); |
@@ -7,35 +7,24 @@ 'use strict'; | ||
exports.watchmanCrawl = watchmanCrawl; | ||
function path() { | ||
const data = _interopRequireWildcard(require('path')); | ||
path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _fbWatchman() { | ||
const data = _interopRequireDefault(require('fb-watchman')); | ||
_fbWatchman = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _constants = _interopRequireDefault(require('../constants')); | ||
var fastPath = _interopRequireWildcard(require('../lib/fast_path')); | ||
var _normalizePathSep = _interopRequireDefault( | ||
require('../lib/normalizePathSep') | ||
); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -49,3 +38,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -83,3 +71,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
/** | ||
@@ -91,4 +78,4 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const watchmanURL = 'https://facebook.github.io/watchman/docs/troubleshooting'; | ||
function WatchmanError(error) { | ||
@@ -100,2 +87,3 @@ error.message = | ||
} | ||
/** | ||
@@ -108,3 +96,2 @@ * Wrap watchman capabilityCheck method as a promise. | ||
*/ | ||
async function capabilityCheck(client, caps) { | ||
@@ -125,3 +112,2 @@ return new Promise((resolve, reject) => { | ||
} | ||
async function watchmanCrawl(options) { | ||
@@ -132,5 +118,6 @@ const fields = ['name', 'exists', 'mtime_ms', 'size']; | ||
const clocks = data.clocks; | ||
const client = new (_fbWatchman().default.Client)(); // https://facebook.github.io/watchman/docs/capabilities.html | ||
const client = new (_fbWatchman().default.Client)(); | ||
// https://facebook.github.io/watchman/docs/capabilities.html | ||
// Check adds about ~28ms | ||
const capabilities = await capabilityCheck(client, { | ||
@@ -141,3 +128,2 @@ // If a required capability is missing then an error will be thrown, | ||
}); | ||
if (capabilities?.capabilities['suffix-set']) { | ||
@@ -154,6 +140,4 @@ // If available, use the optimized `suffix-set` operation: | ||
} | ||
let clientError; | ||
client.on('error', error => (clientError = WatchmanError(error))); | ||
const cmd = (...args) => | ||
@@ -165,6 +149,4 @@ new Promise((resolve, reject) => | ||
); | ||
if (options.computeSha1) { | ||
const {capabilities} = await cmd('list-capabilities'); | ||
if (capabilities.indexOf('field-content.sha1hex') !== -1) { | ||
@@ -174,3 +156,2 @@ fields.push('content.sha1hex'); | ||
} | ||
async function getWatchmanRoots(roots) { | ||
@@ -181,7 +162,6 @@ const watchmanRoots = new Map(); | ||
const response = await cmd('watch-project', root); | ||
const existing = watchmanRoots.get(response.watch); // A root can only be filtered if it was never seen with a | ||
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) { | ||
@@ -204,3 +184,2 @@ if (response.relative_path) { | ||
} | ||
async function queryWatchmanForDirs(rootProjectDirMappings) { | ||
@@ -214,3 +193,2 @@ const results = new Map(); | ||
const glob = []; | ||
if (directoryFilters.length > 0) { | ||
@@ -221,3 +199,2 @@ expression.push([ | ||
]); | ||
for (const directory of directoryFilters) { | ||
@@ -232,3 +209,5 @@ for (const extension of extensions) { | ||
} | ||
} // Jest is only going to store one type of clock; a string that | ||
} | ||
// Jest is only going to store one type of clock; a string that | ||
// represents a local clock. However, the Watchman crawler supports | ||
@@ -241,12 +220,13 @@ // a second type of clock that can be written by automation outside of | ||
// system and import it, transforming the clock into a local clock. | ||
const since = clocks.get(fastPath.relative(rootDir, root)); | ||
const query = | ||
since !== undefined // Use the `since` generator if we have a clock available | ||
? { | ||
since !== undefined | ||
? // Use the `since` generator if we have a clock available | ||
{ | ||
expression, | ||
fields, | ||
since | ||
} // Otherwise use the `glob` filter | ||
: { | ||
} | ||
: // Otherwise use the `glob` filter | ||
{ | ||
expression, | ||
@@ -258,17 +238,15 @@ fields, | ||
const response = await cmd('query', root, query); | ||
if ('warning' in response) { | ||
console.warn('watchman warning: ', response.warning); | ||
} // When a source-control query is used, we ignore the "is fresh" | ||
} | ||
// When a source-control query is used, we ignore the "is fresh" | ||
// response from Watchman because it will be true despite the query | ||
// being incremental. | ||
const isSourceControlQuery = | ||
typeof since !== 'string' && | ||
since?.scm?.['mergebase-with'] !== undefined; | ||
if (!isSourceControlQuery) { | ||
isFresh = isFresh || response.is_fresh_instance; | ||
} | ||
results.set(root, response); | ||
@@ -283,3 +261,2 @@ } | ||
} | ||
let files = data.files; | ||
@@ -290,8 +267,8 @@ let removedFiles = new Map(); | ||
let isFresh = false; | ||
try { | ||
const watchmanRoots = await getWatchmanRoots(roots); | ||
const watchmanFileResults = await queryWatchmanForDirs(watchmanRoots); // Reset the file map if watchman was restarted and sends us a list of | ||
const watchmanFileResults = await queryWatchmanForDirs(watchmanRoots); | ||
// Reset the file map if watchman was restarted and sends us a list of | ||
// files. | ||
if (watchmanFileResults.isFresh) { | ||
@@ -302,3 +279,2 @@ files = new Map(); | ||
} | ||
results = watchmanFileResults.results; | ||
@@ -308,7 +284,5 @@ } finally { | ||
} | ||
if (clientError) { | ||
throw clientError; | ||
} | ||
for (const [watchRoot, response] of results) { | ||
@@ -318,6 +292,6 @@ const fsRoot = (0, _normalizePathSep.default)(watchRoot); | ||
clocks.set( | ||
relativeFsRoot, // Ensure we persist only the local clock. | ||
relativeFsRoot, | ||
// Ensure we persist only the local clock. | ||
typeof response.clock === 'string' ? response.clock : response.clock.clock | ||
); | ||
for (const fileData of response.files) { | ||
@@ -327,15 +301,16 @@ const filePath = | ||
const relativeFilePath = fastPath.relative(rootDir, filePath); | ||
const existingFileData = data.files.get(relativeFilePath); // If watchman is fresh, the removed files map starts with all files | ||
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 | ||
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) { | ||
@@ -352,9 +327,6 @@ removedFiles.set(relativeFilePath, existingFileData); | ||
let sha1hex = fileData['content.sha1hex']; | ||
if (typeof sha1hex !== 'string' || sha1hex.length !== 40) { | ||
sha1hex = undefined; | ||
} | ||
let nextData; | ||
if ( | ||
@@ -382,3 +354,2 @@ existingFileData && | ||
} | ||
files.set(relativeFilePath, nextData); | ||
@@ -389,3 +360,2 @@ changedFiles.set(relativeFilePath, nextData); | ||
} | ||
data.files = files; | ||
@@ -392,0 +362,0 @@ return { |
@@ -7,13 +7,9 @@ 'use strict'; | ||
exports.default = void 0; | ||
function path() { | ||
const data = _interopRequireWildcard(require('path')); | ||
path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -27,3 +23,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -61,3 +56,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
/** | ||
@@ -69,4 +63,4 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const MOCKS_PATTERN = `${path().sep}__mocks__${path().sep}`; | ||
const getMockName = filePath => { | ||
@@ -78,4 +72,3 @@ const mockPath = filePath.split(MOCKS_PATTERN)[1]; | ||
}; | ||
var _default = getMockName; | ||
exports.default = _default; |
@@ -7,17 +7,11 @@ 'use strict'; | ||
exports.default = void 0; | ||
function _jestUtil() { | ||
const data = require('jest-util'); | ||
_jestUtil = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _constants = _interopRequireDefault(require('./constants')); | ||
var fastPath = _interopRequireWildcard(require('./lib/fast_path')); | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -31,3 +25,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -65,7 +58,5 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
/** | ||
@@ -77,6 +68,6 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
class HasteFS { | ||
_rootDir; | ||
_files; | ||
constructor({rootDir, files}) { | ||
@@ -86,18 +77,12 @@ this._rootDir = rootDir; | ||
} | ||
getModuleName(file) { | ||
const fileMetadata = this._getFileData(file); | ||
return (fileMetadata && fileMetadata[_constants.default.ID]) || null; | ||
} | ||
getSize(file) { | ||
const fileMetadata = this._getFileData(file); | ||
return (fileMetadata && fileMetadata[_constants.default.SIZE]) || null; | ||
} | ||
getDependencies(file) { | ||
const fileMetadata = this._getFileData(file); | ||
if (fileMetadata) { | ||
@@ -113,21 +98,15 @@ return fileMetadata[_constants.default.DEPENDENCIES] | ||
} | ||
getSha1(file) { | ||
const fileMetadata = this._getFileData(file); | ||
return (fileMetadata && fileMetadata[_constants.default.SHA1]) || null; | ||
} | ||
exists(file) { | ||
return this._getFileData(file) != null; | ||
} | ||
getAllFiles() { | ||
return Array.from(this.getAbsoluteFileIterator()); | ||
} | ||
getFileIterator() { | ||
return this._files.keys(); | ||
} | ||
*getAbsoluteFileIterator() { | ||
@@ -138,3 +117,2 @@ for (const file of this.getFileIterator()) { | ||
} | ||
matchFiles(pattern) { | ||
@@ -144,5 +122,3 @@ if (!(pattern instanceof RegExp)) { | ||
} | ||
const files = []; | ||
for (const file of this.getAbsoluteFileIterator()) { | ||
@@ -153,13 +129,9 @@ if (pattern.test(file)) { | ||
} | ||
return files; | ||
} | ||
matchFilesWithGlob(globs, root) { | ||
const files = new Set(); | ||
const matcher = (0, _jestUtil().globsToMatcher)(globs); | ||
for (const file of this.getAbsoluteFileIterator()) { | ||
const filePath = root ? fastPath.relative(root, file) : file; | ||
if (matcher((0, _jestUtil().replacePathSepForGlob)(filePath))) { | ||
@@ -169,6 +141,4 @@ files.add(file); | ||
} | ||
return files; | ||
} | ||
_getFileData(file) { | ||
@@ -179,3 +149,2 @@ const relativePath = fastPath.relative(this._rootDir, file); | ||
} | ||
exports.default = HasteFS; |
@@ -7,133 +7,90 @@ 'use strict'; | ||
exports.default = exports.ModuleMap = exports.DuplicateError = void 0; | ||
function _crypto() { | ||
const data = require('crypto'); | ||
_crypto = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _events() { | ||
const data = require('events'); | ||
_events = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _os() { | ||
const data = require('os'); | ||
_os = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function path() { | ||
const data = _interopRequireWildcard(require('path')); | ||
path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _v() { | ||
const data = require('v8'); | ||
_v = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _gracefulFs() { | ||
const data = require('graceful-fs'); | ||
_gracefulFs = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestRegexUtil() { | ||
const data = require('jest-regex-util'); | ||
_jestRegexUtil = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestUtil() { | ||
const data = require('jest-util'); | ||
_jestUtil = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestWorker() { | ||
const data = require('jest-worker'); | ||
_jestWorker = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _HasteFS = _interopRequireDefault(require('./HasteFS')); | ||
var _ModuleMap = _interopRequireDefault(require('./ModuleMap')); | ||
var _constants = _interopRequireDefault(require('./constants')); | ||
var _node = require('./crawlers/node'); | ||
var _watchman = require('./crawlers/watchman'); | ||
var _getMockName = _interopRequireDefault(require('./getMockName')); | ||
var fastPath = _interopRequireWildcard(require('./lib/fast_path')); | ||
var _getPlatformExtension = _interopRequireDefault( | ||
require('./lib/getPlatformExtension') | ||
); | ||
var _isWatchmanInstalled = _interopRequireDefault( | ||
require('./lib/isWatchmanInstalled') | ||
); | ||
var _normalizePathSep = _interopRequireDefault( | ||
require('./lib/normalizePathSep') | ||
); | ||
var _FSEventsWatcher = require('./watchers/FSEventsWatcher'); | ||
var _NodeWatcher = _interopRequireDefault(require('./watchers/NodeWatcher')); | ||
var _WatchmanWatcher = _interopRequireDefault( | ||
require('./watchers/WatchmanWatcher') | ||
); | ||
var _worker = require('./worker'); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -147,3 +104,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -181,3 +137,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
/** | ||
@@ -189,8 +144,10 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
// @ts-expect-error: not converted to TypeScript - it's a fork: https://github.com/facebook/jest/pull/10919 | ||
// @ts-expect-error: not converted to TypeScript - it's a fork: https://github.com/facebook/jest/pull/5387 | ||
// TypeScript doesn't like us importing from outside `rootDir`, but it doesn't | ||
// understand `require`. | ||
const {version: VERSION} = require('../package.json'); | ||
const ModuleMap = _ModuleMap.default; | ||
@@ -207,3 +164,2 @@ exports.ModuleMap = ModuleMap; | ||
.join('|'); | ||
function invariant(condition, message) { | ||
@@ -214,2 +170,3 @@ if (!condition) { | ||
} | ||
/** | ||
@@ -293,3 +250,2 @@ * HasteMap is a JavaScript implementation of Facebook's haste module system. | ||
*/ | ||
class HasteMap extends _events().EventEmitter { | ||
@@ -304,3 +260,2 @@ _buildPromise = null; | ||
_worker = null; | ||
static getStatic(config) { | ||
@@ -310,13 +265,9 @@ if (config.haste.hasteMapModulePath) { | ||
} | ||
return HasteMap; | ||
} | ||
static async create(options) { | ||
if (options.hasteMapModulePath) { | ||
const CustomHasteMap = require(options.hasteMapModulePath); | ||
return new CustomHasteMap(options); | ||
} | ||
const hasteMap = new HasteMap(options); | ||
@@ -326,3 +277,2 @@ await hasteMap.setupCachePath(options); | ||
} | ||
constructor(options) { | ||
@@ -355,3 +305,2 @@ super(); | ||
this._console = options.console || globalThis.console; | ||
if (options.ignorePattern) { | ||
@@ -371,3 +320,2 @@ if (options.ignorePattern instanceof RegExp) { | ||
} | ||
if (this._options.enableSymlinks && this._options.useWatchman) { | ||
@@ -381,3 +329,2 @@ throw new Error( | ||
} | ||
async setupCachePath(options) { | ||
@@ -390,6 +337,4 @@ const rootDirHash = (0, _crypto().createHash)('sha256') | ||
let dependencyExtractorHash = ''; | ||
if (options.hasteImplModulePath) { | ||
const hasteImpl = require(options.hasteImplModulePath); | ||
if (hasteImpl.getCacheKey) { | ||
@@ -399,3 +344,2 @@ hasteImplHash = String(hasteImpl.getCacheKey()); | ||
} | ||
if (options.dependencyExtractor) { | ||
@@ -406,3 +350,2 @@ const dependencyExtractor = await (0, _jestUtil().requireOrImportModule)( | ||
); | ||
if (dependencyExtractor.getCacheKey) { | ||
@@ -412,3 +355,2 @@ dependencyExtractorHash = String(dependencyExtractor.getCacheKey()); | ||
} | ||
this._cachePath = HasteMap.getCacheFilePath( | ||
@@ -432,3 +374,2 @@ this._options.cacheDirectory, | ||
} | ||
static getCacheFilePath(tmpdir, id, ...extra) { | ||
@@ -441,19 +382,16 @@ const hash = (0, _crypto().createHash)('sha256').update(extra.join('')); | ||
} | ||
static getModuleMapFromJSON(json) { | ||
return _ModuleMap.default.fromJSON(json); | ||
} | ||
getCacheFilePath() { | ||
return this._cachePath; | ||
} | ||
build() { | ||
if (!this._buildPromise) { | ||
this._buildPromise = (async () => { | ||
const data = await this._buildFileMap(); // Persist when we don't know if files changed (changedFiles undefined) | ||
const data = await this._buildFileMap(); | ||
// Persist when we don't know if files changed (changedFiles undefined) | ||
// or when we know a file was changed or deleted. | ||
let hasteMap; | ||
if ( | ||
@@ -465,3 +403,2 @@ data.changedFiles === undefined || | ||
hasteMap = await this._buildHasteMap(data); | ||
this._persist(hasteMap); | ||
@@ -471,3 +408,2 @@ } else { | ||
} | ||
const rootDir = this._options.rootDir; | ||
@@ -484,6 +420,4 @@ const hasteFS = new _HasteFS.default({ | ||
}); | ||
const __hasteMapForTest = | ||
(process.env.NODE_ENV === 'test' && hasteMap) || null; | ||
await this._watch(hasteMap); | ||
@@ -497,12 +431,10 @@ return { | ||
} | ||
return this._buildPromise; | ||
} | ||
/** | ||
* 1. read data from the cache or create an empty structure. | ||
*/ | ||
read() { | ||
let hasteMap; | ||
try { | ||
@@ -515,6 +447,4 @@ hasteMap = (0, _v().deserialize)( | ||
} | ||
return hasteMap; | ||
} | ||
readModuleMap() { | ||
@@ -529,9 +459,8 @@ const data = this.read(); | ||
} | ||
/** | ||
* 2. crawl the file system. | ||
*/ | ||
async _buildFileMap() { | ||
let hasteMap; | ||
try { | ||
@@ -543,15 +472,12 @@ const read = this._options.resetCache ? this._createEmptyMap : this.read; | ||
} | ||
return this._crawl(hasteMap); | ||
} | ||
/** | ||
* 3. parse and extract metadata from changed files. | ||
*/ | ||
_processFile(hasteMap, map, mocks, filePath, workerOptions) { | ||
const rootDir = this._options.rootDir; | ||
const setModule = (id, module) => { | ||
let moduleMap = map.get(id); | ||
if (!moduleMap) { | ||
@@ -561,3 +487,2 @@ moduleMap = Object.create(null); | ||
} | ||
const platform = | ||
@@ -568,5 +493,3 @@ (0, _getPlatformExtension.default)( | ||
) || _constants.default.GENERIC_PLATFORM; | ||
const existingModule = moduleMap[platform]; | ||
if ( | ||
@@ -578,3 +501,2 @@ existingModule && | ||
const method = this._options.throwOnModuleCollision ? 'error' : 'warn'; | ||
this._console[method]( | ||
@@ -591,3 +513,2 @@ [ | ||
); | ||
if (this._options.throwOnModuleCollision) { | ||
@@ -598,12 +519,10 @@ throw new DuplicateError( | ||
); | ||
} // We do NOT want consumers to use a module that is ambiguous. | ||
} | ||
// We do NOT want consumers to use a module that is ambiguous. | ||
delete moduleMap[platform]; | ||
if (Object.keys(moduleMap).length === 1) { | ||
map.delete(id); | ||
} | ||
let dupsByPlatform = hasteMap.duplicates.get(id); | ||
if (dupsByPlatform == null) { | ||
@@ -613,3 +532,2 @@ dupsByPlatform = new Map(); | ||
} | ||
const dups = new Map([ | ||
@@ -625,8 +543,5 @@ [module[_constants.default.PATH], module[_constants.default.TYPE]], | ||
} | ||
const dupsByPlatform = hasteMap.duplicates.get(id); | ||
if (dupsByPlatform != null) { | ||
const dups = dupsByPlatform.get(platform); | ||
if (dups != null) { | ||
@@ -638,12 +553,8 @@ dups.set( | ||
} | ||
return; | ||
} | ||
moduleMap[platform] = module; | ||
}; | ||
const relativeFilePath = fastPath.relative(rootDir, filePath); | ||
const fileMetadata = hasteMap.files.get(relativeFilePath); | ||
if (!fileMetadata) { | ||
@@ -654,3 +565,2 @@ throw new Error( | ||
} | ||
const moduleMetadata = hasteMap.map.get( | ||
@@ -660,4 +570,5 @@ fileMetadata[_constants.default.ID] | ||
const computeSha1 = | ||
this._options.computeSha1 && !fileMetadata[_constants.default.SHA1]; // Callback called when the response from the worker is successful. | ||
this._options.computeSha1 && !fileMetadata[_constants.default.SHA1]; | ||
// Callback called when the response from the worker is successful. | ||
const workerReply = metadata => { | ||
@@ -668,3 +579,2 @@ // `1` for truthy values instead of `true` to save cache space. | ||
const metadataModule = metadata.module; | ||
if (metadataId && metadataModule) { | ||
@@ -674,12 +584,11 @@ fileMetadata[_constants.default.ID] = metadataId; | ||
} | ||
fileMetadata[_constants.default.DEPENDENCIES] = metadata.dependencies | ||
? metadata.dependencies.join(_constants.default.DEPENDENCY_DELIM) | ||
: ''; | ||
if (computeSha1) { | ||
fileMetadata[_constants.default.SHA1] = metadata.sha1; | ||
} | ||
}; // Callback called when the response from the worker is an error. | ||
}; | ||
// Callback called when the response from the worker is an error. | ||
const workerError = error => { | ||
@@ -693,9 +602,11 @@ if (typeof error !== 'object' || !error.message || !error.stack) { | ||
throw error; | ||
} // If a file cannot be read we remove it from the file list and | ||
} | ||
// If a file cannot be read we remove it from the file list and | ||
// ignore the failure silently. | ||
hasteMap.files.delete(relativeFilePath); | ||
}; | ||
hasteMap.files.delete(relativeFilePath); | ||
}; // If we retain all files in the virtual HasteFS representation, we avoid | ||
// If we retain all files in the virtual HasteFS representation, we avoid | ||
// reading them if they aren't important (node_modules). | ||
if (this._options.retainAllFiles && filePath.includes(NODE_MODULES)) { | ||
@@ -714,6 +625,4 @@ if (computeSha1) { | ||
} | ||
return null; | ||
} | ||
if ( | ||
@@ -725,6 +634,4 @@ this._options.mocksPattern && | ||
const existingMockPath = mocks.get(mockPath); | ||
if (existingMockPath) { | ||
const secondMockPath = fastPath.relative(rootDir, filePath); | ||
if (existingMockPath !== secondMockPath) { | ||
@@ -734,3 +641,2 @@ const method = this._options.throwOnModuleCollision | ||
: 'warn'; | ||
this._console[method]( | ||
@@ -745,3 +651,2 @@ [ | ||
); | ||
if (this._options.throwOnModuleCollision) { | ||
@@ -752,6 +657,4 @@ throw new DuplicateError(existingMockPath, secondMockPath); | ||
} | ||
mocks.set(mockPath, relativeFilePath); | ||
} | ||
if (fileMetadata[_constants.default.VISITED]) { | ||
@@ -761,3 +664,2 @@ if (!fileMetadata[_constants.default.ID]) { | ||
} | ||
if (moduleMetadata != null) { | ||
@@ -769,12 +671,8 @@ const platform = | ||
) || _constants.default.GENERIC_PLATFORM; | ||
const module = moduleMetadata[platform]; | ||
if (module == null) { | ||
return null; | ||
} | ||
const moduleId = fileMetadata[_constants.default.ID]; | ||
let modulesByPlatform = map.get(moduleId); | ||
if (!modulesByPlatform) { | ||
@@ -784,3 +682,2 @@ modulesByPlatform = Object.create(null); | ||
} | ||
modulesByPlatform[platform] = module; | ||
@@ -790,3 +687,2 @@ return null; | ||
} | ||
return this._getWorker(workerOptions) | ||
@@ -803,11 +699,10 @@ .worker({ | ||
} | ||
_buildHasteMap(data) { | ||
const {removedFiles, changedFiles, hasteMap} = data; | ||
_buildHasteMap(data) { | ||
const {removedFiles, changedFiles, hasteMap} = data; // If any files were removed or we did not track what files changed, process | ||
// If any files were removed or we did not track what files changed, process | ||
// every file looking for changes. Otherwise, process only changed files. | ||
let map; | ||
let mocks; | ||
let filesToProcess; | ||
if (changedFiles === undefined || removedFiles.size) { | ||
@@ -822,3 +717,2 @@ map = new Map(); | ||
} | ||
for (const [relativeFilePath, fileMetadata] of removedFiles) { | ||
@@ -831,5 +725,3 @@ this._recoverDuplicates( | ||
} | ||
const promises = []; | ||
for (const relativeFilePath of filesToProcess.keys()) { | ||
@@ -841,4 +733,4 @@ if ( | ||
continue; | ||
} // SHA-1, if requested, should already be present thanks to the crawler. | ||
} | ||
// SHA-1, if requested, should already be present thanks to the crawler. | ||
const filePath = fastPath.resolve( | ||
@@ -848,5 +740,3 @@ this._options.rootDir, | ||
); | ||
const promise = this._processFile(hasteMap, map, mocks, filePath); | ||
if (promise) { | ||
@@ -856,7 +746,5 @@ promises.push(promise); | ||
} | ||
return Promise.all(promises).then( | ||
() => { | ||
this._cleanup(); | ||
hasteMap.map = map; | ||
@@ -868,3 +756,2 @@ hasteMap.mocks = mocks; | ||
this._cleanup(); | ||
throw error; | ||
@@ -874,16 +761,13 @@ } | ||
} | ||
_cleanup() { | ||
const worker = this._worker; | ||
if (worker && 'end' in worker) { | ||
worker.end(); | ||
} | ||
this._worker = null; | ||
} | ||
/** | ||
* 4. serialize the new `HasteMap` in a cache file. | ||
*/ | ||
_persist(hasteMap) { | ||
@@ -895,6 +779,6 @@ (0, _gracefulFs().writeFileSync)( | ||
} | ||
/** | ||
* Creates workers or parses files and extracts metadata in-process. | ||
*/ | ||
_getWorker( | ||
@@ -922,11 +806,7 @@ options = { | ||
} | ||
return this._worker; | ||
} | ||
async _crawl(hasteMap) { | ||
const options = this._options; | ||
const ignore = this._ignore.bind(this); | ||
const crawl = (await this._shouldUseWatchman()) | ||
@@ -945,3 +825,2 @@ ? _watchman.watchmanCrawl | ||
}; | ||
const retry = error => { | ||
@@ -957,3 +836,2 @@ if (crawl === _watchman.watchmanCrawl) { | ||
); | ||
return (0, _node.nodeCrawl)(crawlerOptions).catch(e => { | ||
@@ -967,8 +845,6 @@ throw new Error( | ||
} | ||
throw error; | ||
}; | ||
try { | ||
return crawl(crawlerOptions).catch(retry); | ||
return await crawl(crawlerOptions); | ||
} catch (error) { | ||
@@ -978,15 +854,17 @@ return retry(error); | ||
} | ||
/** | ||
* Watch mode | ||
*/ | ||
async _watch(hasteMap) { | ||
if (!this._options.watch) { | ||
return Promise.resolve(); | ||
} // In watch mode, we'll only warn about module collisions and we'll retain | ||
} | ||
// In watch mode, we'll only warn about module collisions and we'll retain | ||
// all files, even changes to node_modules. | ||
this._options.throwOnModuleCollision = false; | ||
this._options.retainAllFiles = true; // WatchmanWatcher > FSEventsWatcher > sane.NodeWatcher | ||
this._options.retainAllFiles = true; | ||
// WatchmanWatcher > FSEventsWatcher > sane.NodeWatcher | ||
const Watcher = (await this._shouldUseWatchman()) | ||
@@ -1001,6 +879,5 @@ ? _WatchmanWatcher.default | ||
let changeQueue = Promise.resolve(); | ||
let eventsQueue = []; // We only need to copy the entire haste map once on every "frame". | ||
let eventsQueue = []; | ||
// We only need to copy the entire haste map once on every "frame". | ||
let mustCopy = true; | ||
const createWatcher = root => { | ||
@@ -1024,3 +901,2 @@ const watcher = new Watcher(root, { | ||
}; | ||
const emitChange = () => { | ||
@@ -1046,6 +922,4 @@ if (eventsQueue.length) { | ||
}; | ||
const onChange = (type, filePath, root, stat) => { | ||
filePath = path().join(root, (0, _normalizePathSep.default)(filePath)); | ||
if ( | ||
@@ -1058,6 +932,6 @@ (stat && stat.isDirectory()) || | ||
} | ||
const relativeFilePath = fastPath.relative(rootDir, filePath); | ||
const fileMetadata = hasteMap.files.get(relativeFilePath); // The file has been accessed, not modified | ||
const fileMetadata = hasteMap.files.get(relativeFilePath); | ||
// The file has been accessed, not modified | ||
if ( | ||
@@ -1071,3 +945,2 @@ type === 'change' && | ||
} | ||
changeQueue = changeQueue | ||
@@ -1089,3 +962,2 @@ .then(() => { | ||
} | ||
if (mustCopy) { | ||
@@ -1101,3 +973,2 @@ mustCopy = false; | ||
} | ||
const add = () => { | ||
@@ -1111,8 +982,7 @@ eventsQueue.push({ | ||
}; | ||
const fileMetadata = hasteMap.files.get(relativeFilePath); | ||
const fileMetadata = hasteMap.files.get(relativeFilePath); // If it's not an addition, delete the file and all its metadata | ||
// If it's not an addition, delete the file and all its metadata | ||
if (fileMetadata != null) { | ||
const moduleName = fileMetadata[_constants.default.ID]; | ||
const platform = | ||
@@ -1123,6 +993,4 @@ (0, _getPlatformExtension.default)( | ||
) || _constants.default.GENERIC_PLATFORM; | ||
hasteMap.files.delete(relativeFilePath); | ||
let moduleMap = hasteMap.map.get(moduleName); | ||
if (moduleMap != null) { | ||
@@ -1133,3 +1001,2 @@ // We are forced to copy the object because jest-haste-map exposes | ||
delete moduleMap[platform]; | ||
if (Object.keys(moduleMap).length === 0) { | ||
@@ -1141,3 +1008,2 @@ hasteMap.map.delete(moduleName); | ||
} | ||
if ( | ||
@@ -1150,7 +1016,7 @@ this._options.mocksPattern && | ||
} | ||
this._recoverDuplicates(hasteMap, relativeFilePath, moduleName); | ||
} | ||
this._recoverDuplicates(hasteMap, relativeFilePath, moduleName); | ||
} // If the file was added or changed, | ||
// If the file was added or changed, | ||
// parse it and update the haste map. | ||
if (type === 'add' || type === 'change') { | ||
@@ -1170,3 +1036,2 @@ invariant( | ||
hasteMap.files.set(relativeFilePath, fileMetadata); | ||
const promise = this._processFile( | ||
@@ -1180,6 +1045,5 @@ hasteMap, | ||
} | ||
); // Cleanup | ||
); | ||
// Cleanup | ||
this._cleanup(); | ||
if (promise) { | ||
@@ -1195,3 +1059,2 @@ return promise.then(add); | ||
} | ||
return null; | ||
@@ -1205,3 +1068,2 @@ }) | ||
}; | ||
this._changeInterval = setInterval(emitChange, CHANGE_INTERVAL); | ||
@@ -1214,2 +1076,3 @@ return Promise.all(this._options.roots.map(createWatcher)).then( | ||
} | ||
/** | ||
@@ -1223,10 +1086,7 @@ * This function should be called when the file under `filePath` is removed | ||
*/ | ||
_recoverDuplicates(hasteMap, relativeFilePath, moduleName) { | ||
let dupsByPlatform = hasteMap.duplicates.get(moduleName); | ||
if (dupsByPlatform == null) { | ||
return; | ||
} | ||
const platform = | ||
@@ -1237,9 +1097,6 @@ (0, _getPlatformExtension.default)( | ||
) || _constants.default.GENERIC_PLATFORM; | ||
let dups = dupsByPlatform.get(platform); | ||
if (dups == null) { | ||
return; | ||
} | ||
dupsByPlatform = copyMap(dupsByPlatform); | ||
@@ -1250,15 +1107,10 @@ hasteMap.duplicates.set(moduleName, dupsByPlatform); | ||
dups.delete(relativeFilePath); | ||
if (dups.size !== 1) { | ||
return; | ||
} | ||
const uniqueModule = dups.entries().next().value; | ||
if (!uniqueModule) { | ||
return; | ||
} | ||
let dedupMap = hasteMap.map.get(moduleName); | ||
if (!dedupMap) { | ||
@@ -1268,6 +1120,4 @@ dedupMap = Object.create(null); | ||
} | ||
dedupMap[platform] = uniqueModule; | ||
dupsByPlatform.delete(platform); | ||
if (dupsByPlatform.size === 0) { | ||
@@ -1277,3 +1127,2 @@ hasteMap.duplicates.delete(moduleName); | ||
} | ||
async end() { | ||
@@ -1283,14 +1132,12 @@ if (this._changeInterval) { | ||
} | ||
if (!this._watchers.length) { | ||
return; | ||
} | ||
await Promise.all(this._watchers.map(watcher => watcher.close())); | ||
this._watchers = []; | ||
} | ||
/** | ||
* Helpers | ||
*/ | ||
_ignore(filePath) { | ||
@@ -1307,3 +1154,2 @@ const ignorePattern = this._options.ignorePattern; | ||
} | ||
async _shouldUseWatchman() { | ||
@@ -1313,10 +1159,7 @@ if (!this._options.useWatchman) { | ||
} | ||
if (!this._isWatchmanInstalledPromise) { | ||
this._isWatchmanInstalledPromise = (0, _isWatchmanInstalled.default)(); | ||
} | ||
return this._isWatchmanInstalledPromise; | ||
} | ||
_createEmptyMap() { | ||
@@ -1331,10 +1174,7 @@ return { | ||
} | ||
static H = _constants.default; | ||
} | ||
class DuplicateError extends Error { | ||
mockPath1; | ||
mockPath2; | ||
constructor(mockPath1, mockPath2) { | ||
@@ -1346,15 +1186,14 @@ super('Duplicated files or mocks. Please check the console for more info'); | ||
} | ||
exports.DuplicateError = DuplicateError; | ||
function copy(object) { | ||
return Object.assign(Object.create(null), object); | ||
} | ||
function copyMap(input) { | ||
return new Map(input); | ||
} // Export the smallest API surface required by Jest | ||
} | ||
// Export the smallest API surface required by Jest | ||
const JestHasteMap = HasteMap; | ||
var _default = JestHasteMap; | ||
exports.default = _default; |
@@ -7,3 +7,2 @@ 'use strict'; | ||
exports.extractor = void 0; | ||
/** | ||
@@ -15,6 +14,5 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const NOT_A_DOT = '(?<!\\.\\s*)'; | ||
const CAPTURE_STRING_LITERAL = pos => `([\`'"])([^'"\`]*?)(?:\\${pos})`; | ||
const WORD_SEPARATOR = '\\b'; | ||
@@ -25,11 +23,8 @@ const LEFT_PARENTHESIS = '\\('; | ||
const OPTIONAL_COMMA = '(:?,\\s*)?'; | ||
function createRegExp(parts, flags) { | ||
return new RegExp(parts.join(''), flags); | ||
} | ||
function alternatives(...parts) { | ||
return `(?:${parts.join('|')})`; | ||
} | ||
function functionCallStart(...names) { | ||
@@ -45,3 +40,2 @@ return [ | ||
} | ||
const BLOCK_COMMENT_RE = /\/\*[^]*?\*\//g; | ||
@@ -81,3 +75,2 @@ const LINE_COMMENT_RE = /\/\/.*/g; | ||
const dependencies = new Set(); | ||
const addDependency = (match, _, dep) => { | ||
@@ -87,3 +80,2 @@ dependencies.add(dep); | ||
}; | ||
code | ||
@@ -90,0 +82,0 @@ .replace(BLOCK_COMMENT_RE, '') |
@@ -8,13 +8,9 @@ 'use strict'; | ||
exports.resolve = resolve; | ||
function path() { | ||
const data = _interopRequireWildcard(require('path')); | ||
path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -28,3 +24,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -62,3 +57,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
/** | ||
@@ -70,2 +64,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
// rootDir and filename must be absolute paths (resolved) | ||
@@ -77,6 +72,6 @@ function relative(rootDir, filename) { | ||
} | ||
const INDIRECTION_FRAGMENT = `..${path().sep}`; | ||
const INDIRECTION_FRAGMENT = `..${path().sep}`; // rootDir must be an absolute path and relativeFilename must be simple | ||
// rootDir must be an absolute path and relativeFilename must be simple | ||
// (e.g.: foo/bar or ../foo/bar, but never ./foo or foo/../bar) | ||
function resolve(rootDir, relativeFilename) { | ||
@@ -83,0 +78,0 @@ return relativeFilename.indexOf(INDIRECTION_FRAGMENT) === 0 |
@@ -7,3 +7,2 @@ 'use strict'; | ||
exports.default = getPlatformExtension; | ||
/** | ||
@@ -15,19 +14,19 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const SUPPORTED_PLATFORM_EXTS = new Set(['android', 'ios', 'native', 'web']); // Extract platform extension: index.ios.js -> ios | ||
const SUPPORTED_PLATFORM_EXTS = new Set(['android', 'ios', 'native', 'web']); | ||
// Extract platform extension: index.ios.js -> ios | ||
function getPlatformExtension(file, platforms) { | ||
const last = file.lastIndexOf('.'); | ||
const secondToLast = file.lastIndexOf('.', last - 1); | ||
if (secondToLast === -1) { | ||
return null; | ||
} | ||
const platform = file.substring(secondToLast + 1, last); | ||
// If an overriding platform array is passed, check that first | ||
const platform = file.substring(secondToLast + 1, last); // If an overriding platform array is passed, check that first | ||
if (platforms && platforms.indexOf(platform) !== -1) { | ||
return platform; | ||
} | ||
return SUPPORTED_PLATFORM_EXTS.has(platform) ? platform : null; | ||
} |
@@ -7,23 +7,16 @@ 'use strict'; | ||
exports.default = isWatchmanInstalled; | ||
function _child_process() { | ||
const data = require('child_process'); | ||
_child_process = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _util() { | ||
const data = require('util'); | ||
_util = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
/** | ||
@@ -35,2 +28,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
async function isWatchmanInstalled() { | ||
@@ -37,0 +31,0 @@ try { |
@@ -7,13 +7,9 @@ 'use strict'; | ||
exports.default = void 0; | ||
function path() { | ||
const data = _interopRequireWildcard(require('path')); | ||
path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -27,3 +23,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -61,3 +56,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
/** | ||
@@ -69,4 +63,4 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
let normalizePathSep; | ||
if (path().sep === '/') { | ||
@@ -77,4 +71,3 @@ normalizePathSep = filePath => filePath; | ||
} | ||
var _default = normalizePathSep; | ||
exports.default = _default; |
@@ -7,7 +7,4 @@ 'use strict'; | ||
exports.default = void 0; | ||
var _constants = _interopRequireDefault(require('./constants')); | ||
var fastPath = _interopRequireWildcard(require('./lib/fast_path')); | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -21,3 +18,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -55,7 +51,5 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
/** | ||
@@ -67,5 +61,5 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const EMPTY_OBJ = {}; | ||
const EMPTY_MAP = new Map(); | ||
class ModuleMap { | ||
@@ -75,13 +69,9 @@ static DuplicateHasteCandidatesError; | ||
json; | ||
static mapToArrayRecursive(map) { | ||
let arr = Array.from(map); | ||
if (arr[0] && arr[0][1] instanceof Map) { | ||
arr = arr.map(el => [el[0], this.mapToArrayRecursive(el[1])]); | ||
} | ||
return arr; | ||
} | ||
static mapFromArrayRecursive(arr) { | ||
@@ -91,10 +81,7 @@ if (arr[0] && Array.isArray(arr[1])) { | ||
} | ||
return new Map(arr); | ||
} | ||
constructor(raw) { | ||
this._raw = raw; | ||
} | ||
getModule(name, platform, supportsNativePlatform, type) { | ||
@@ -104,3 +91,2 @@ if (type == null) { | ||
} | ||
const module = this._getModuleMetadata( | ||
@@ -111,3 +97,2 @@ name, | ||
); | ||
if (module && module[_constants.default.TYPE] === type) { | ||
@@ -117,17 +102,12 @@ const modulePath = module[_constants.default.PATH]; | ||
} | ||
return null; | ||
} | ||
getPackage(name, platform, _supportsNativePlatform) { | ||
return this.getModule(name, platform, null, _constants.default.PACKAGE); | ||
} | ||
getMockModule(name) { | ||
const mockPath = | ||
this._raw.mocks.get(name) || this._raw.mocks.get(`${name}/index`); | ||
return mockPath && fastPath.resolve(this._raw.rootDir, mockPath); | ||
} | ||
getRawModuleMap() { | ||
@@ -141,3 +121,2 @@ return { | ||
} | ||
toJSON() { | ||
@@ -152,6 +131,4 @@ if (!this.json) { | ||
} | ||
return this.json; | ||
} | ||
static fromJSON(serializableModuleMap) { | ||
@@ -167,2 +144,3 @@ return new ModuleMap({ | ||
} | ||
/** | ||
@@ -176,7 +154,5 @@ * When looking up a module's data, we walk through each eligible platform for | ||
*/ | ||
_getModuleMetadata(name, platform, supportsNativePlatform) { | ||
const map = this._raw.map.get(name) || EMPTY_OBJ; | ||
const dupMap = this._raw.duplicates.get(name) || EMPTY_MAP; | ||
if (platform != null) { | ||
@@ -189,3 +165,2 @@ this._assertNoDuplicates( | ||
); | ||
if (map[platform] != null) { | ||
@@ -195,3 +170,2 @@ return map[platform]; | ||
} | ||
if (supportsNativePlatform) { | ||
@@ -204,3 +178,2 @@ this._assertNoDuplicates( | ||
); | ||
if (map[_constants.default.NATIVE_PLATFORM]) { | ||
@@ -210,3 +183,2 @@ return map[_constants.default.NATIVE_PLATFORM]; | ||
} | ||
this._assertNoDuplicates( | ||
@@ -218,18 +190,14 @@ name, | ||
); | ||
if (map[_constants.default.GENERIC_PLATFORM]) { | ||
return map[_constants.default.GENERIC_PLATFORM]; | ||
} | ||
return null; | ||
} | ||
_assertNoDuplicates(name, platform, supportsNativePlatform, relativePathSet) { | ||
if (relativePathSet == null) { | ||
return; | ||
} // Force flow refinement | ||
} | ||
// Force flow refinement | ||
const previousSet = relativePathSet; | ||
const duplicates = new Map(); | ||
for (const [relativePath, type] of previousSet) { | ||
@@ -239,3 +207,2 @@ const duplicatePath = fastPath.resolve(this._raw.rootDir, relativePath); | ||
} | ||
throw new DuplicateHasteCandidatesError( | ||
@@ -248,3 +215,2 @@ name, | ||
} | ||
static create(rootDir) { | ||
@@ -259,5 +225,3 @@ return new ModuleMap({ | ||
} | ||
exports.default = ModuleMap; | ||
class DuplicateHasteCandidatesError extends Error { | ||
@@ -268,3 +232,2 @@ hasteName; | ||
duplicatesSet; | ||
constructor(name, platform, supportsNativePlatform, duplicatesSet) { | ||
@@ -293,3 +256,2 @@ const platformMessage = getPlatformMessage(platform); | ||
} | ||
function getPlatformMessage(platform) { | ||
@@ -299,6 +261,4 @@ if (platform === _constants.default.GENERIC_PLATFORM) { | ||
} | ||
return `The platform extension is \`${platform}\`.`; | ||
} | ||
function getTypeMessage(type) { | ||
@@ -308,10 +268,7 @@ switch (type) { | ||
return 'module'; | ||
case _constants.default.PACKAGE: | ||
return 'package'; | ||
} | ||
return 'unknown'; | ||
} | ||
ModuleMap.DuplicateHasteCandidatesError = DuplicateHasteCandidatesError; |
// vendored from https://github.com/amasad/sane/blob/64ff3a870c42e84f744086884bf55a4f9c22d376/src/common.js | ||
'use strict'; | ||
const platform = require('os').platform(); | ||
const path = require('path'); | ||
const anymatch = require('anymatch'); | ||
const micromatch = require('micromatch'); | ||
const walker = require('walker'); | ||
const walker = require('walker'); | ||
/** | ||
@@ -22,2 +20,3 @@ * Constants | ||
exports.ALL_EVENT = 'all'; | ||
/** | ||
@@ -37,17 +36,14 @@ * Assigns options to the watcher. | ||
watcher.ignored = opts.ignored || false; | ||
if (!Array.isArray(watcher.globs)) { | ||
watcher.globs = [watcher.globs]; | ||
} | ||
watcher.hasIgnore = | ||
Boolean(opts.ignored) && !(Array.isArray(opts) && opts.length > 0); | ||
watcher.doIgnore = opts.ignored ? anymatch(opts.ignored) : () => false; | ||
if (opts.watchman && opts.watchmanPath) { | ||
watcher.watchmanPath = opts.watchmanPath; | ||
} | ||
return opts; | ||
}; | ||
/** | ||
@@ -66,3 +62,2 @@ * Checks a file relative path against the globs array. | ||
} | ||
return globs.length | ||
@@ -74,2 +69,3 @@ ? micromatch.some(relativePath, globs, { | ||
}; | ||
/** | ||
@@ -107,2 +103,3 @@ * Traverse a directory recursively calling `callback` on every directory. | ||
}; | ||
/** | ||
@@ -109,0 +106,0 @@ * Returns a callback that when called will normalize a path and call the |
@@ -7,67 +7,47 @@ 'use strict'; | ||
exports.FSEventsWatcher = void 0; | ||
function _events() { | ||
const data = require('events'); | ||
_events = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function path() { | ||
const data = _interopRequireWildcard(require('path')); | ||
path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _anymatch() { | ||
const data = _interopRequireDefault(require('anymatch')); | ||
_anymatch = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function fs() { | ||
const data = _interopRequireWildcard(require('graceful-fs')); | ||
fs = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _micromatch() { | ||
const data = _interopRequireDefault(require('micromatch')); | ||
_micromatch = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _walker() { | ||
const data = _interopRequireDefault(require('walker')); | ||
_walker = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -81,3 +61,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -115,3 +94,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
/** | ||
@@ -124,7 +102,8 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
// @ts-expect-error no types | ||
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error, @typescript-eslint/ban-ts-comment | ||
// @ts-ignore: this is for CI which runs linux and might not have this | ||
let fsevents = null; | ||
try { | ||
@@ -135,3 +114,2 @@ fsevents = require('fsevents'); | ||
} | ||
const CHANGE_EVENT = 'change'; | ||
@@ -141,3 +119,2 @@ const DELETE_EVENT = 'delete'; | ||
const ALL_EVENT = 'all'; | ||
/** | ||
@@ -156,11 +133,8 @@ * Export `FSEventsWatcher` class. | ||
_tracked; | ||
static isSupported() { | ||
return fsevents !== null; | ||
} | ||
static normalizeProxy(callback) { | ||
return (filepath, stats) => callback(path().normalize(filepath), stats); | ||
} | ||
static recReaddir( | ||
@@ -185,3 +159,2 @@ dir, | ||
} | ||
constructor(dir, opts) { | ||
@@ -193,3 +166,2 @@ if (!fsevents) { | ||
} | ||
super(); | ||
@@ -223,10 +195,9 @@ this.dot = opts.dot || false; | ||
} | ||
/** | ||
* End watching. | ||
*/ | ||
async close(callback) { | ||
await this.fsEventsWatchStopper(); | ||
this.removeAllListeners(); | ||
if (typeof callback === 'function') { | ||
@@ -236,3 +207,2 @@ process.nextTick(callback.bind(null, null, true)); | ||
} | ||
isFileIncluded(relativePath) { | ||
@@ -242,3 +212,2 @@ if (this.doIgnore(relativePath)) { | ||
} | ||
return this.glob.length | ||
@@ -251,10 +220,7 @@ ? (0, _micromatch().default)([relativePath], this.glob, { | ||
} | ||
handleEvent(filepath) { | ||
const relativePath = path().relative(this.root, filepath); | ||
if (!this.isFileIncluded(relativePath)) { | ||
return; | ||
} | ||
fs().lstat(filepath, (error, stat) => { | ||
@@ -265,3 +231,2 @@ if (error && error.code !== 'ENOENT') { | ||
} | ||
if (error) { | ||
@@ -272,10 +237,6 @@ // Ignore files that aren't tracked and don't exist. | ||
} | ||
this._emit(DELETE_EVENT, relativePath); | ||
this._tracked.delete(filepath); | ||
return; | ||
} | ||
if (this._tracked.has(filepath)) { | ||
@@ -285,3 +246,2 @@ this._emit(CHANGE_EVENT, relativePath, stat); | ||
this._tracked.add(filepath); | ||
this._emit(ADD_EVENT, relativePath, stat); | ||
@@ -291,6 +251,6 @@ } | ||
} | ||
/** | ||
* Emit events. | ||
*/ | ||
_emit(type, file, stat) { | ||
@@ -301,3 +261,2 @@ this.emit(type, file, this.root, stat); | ||
} | ||
exports.FSEventsWatcher = FSEventsWatcher; |
// vendored from https://github.com/amasad/sane/blob/64ff3a870c42e84f744086884bf55a4f9c22d376/src/node_watcher.js | ||
'use strict'; | ||
const EventEmitter = require('events').EventEmitter; | ||
const fs = require('fs'); | ||
const platform = require('os').platform(); | ||
const path = require('path'); | ||
const common = require('./common'); | ||
const common = require('./common'); | ||
/** | ||
@@ -22,2 +20,3 @@ * Constants | ||
const ALL_EVENT = common.ALL_EVENT; | ||
/** | ||
@@ -54,2 +53,3 @@ * Export `NodeWatcher` class. | ||
} | ||
/** | ||
@@ -74,3 +74,2 @@ * Register files that matches our globs to know what to type of event to | ||
const relativePath = path.relative(this.root, filepath); | ||
if ( | ||
@@ -81,9 +80,6 @@ !common.isFileIncluded(this.globs, this.dot, this.doIgnore, relativePath) | ||
} | ||
const dir = path.dirname(filepath); | ||
if (!this.dirRegistery[dir]) { | ||
this.dirRegistery[dir] = Object.create(null); | ||
} | ||
const filename = path.basename(filepath); | ||
@@ -93,2 +89,3 @@ this.dirRegistery[dir][filename] = true; | ||
} | ||
/** | ||
@@ -103,3 +100,2 @@ * Removes a file from the registery. | ||
const dir = path.dirname(filepath); | ||
if (this.dirRegistery[dir]) { | ||
@@ -110,2 +106,3 @@ const filename = path.basename(filepath); | ||
} | ||
/** | ||
@@ -123,2 +120,3 @@ * Removes a dir from the registery. | ||
} | ||
/** | ||
@@ -140,2 +138,3 @@ * Checks if a file or directory exists in the registery. | ||
} | ||
/** | ||
@@ -147,3 +146,2 @@ * Emit "error" event if it's not an ignorable event | ||
*/ | ||
checkedEmitError(error) { | ||
@@ -154,2 +152,3 @@ if (!isIgnorableFileError(error)) { | ||
} | ||
/** | ||
@@ -166,3 +165,2 @@ * Watch a directory. | ||
} | ||
const watcher = fs.watch( | ||
@@ -177,3 +175,2 @@ dir, | ||
watcher.on('error', this.checkedEmitError); | ||
if (this.root !== dir) { | ||
@@ -183,2 +180,3 @@ this.register(dir); | ||
} | ||
/** | ||
@@ -197,2 +195,3 @@ * Stop watching a directory. | ||
} | ||
/** | ||
@@ -209,2 +208,3 @@ * End watching. | ||
} | ||
/** | ||
@@ -225,3 +225,2 @@ * On some platforms, as pointed out on the fs docs (most likely just win32) | ||
} | ||
let found = false; | ||
@@ -237,3 +236,2 @@ let closest = { | ||
} | ||
if (error) { | ||
@@ -251,3 +249,2 @@ if (isIgnorableFileError(error)) { | ||
} | ||
if (arr.length === ++c) { | ||
@@ -260,2 +257,3 @@ callback(closest.file); | ||
} | ||
/** | ||
@@ -281,2 +279,3 @@ * Normalize fs events and pass it on to be processed. | ||
} | ||
/** | ||
@@ -301,3 +300,2 @@ * Process changes. | ||
this.watchdir(fullPath); | ||
if ( | ||
@@ -316,3 +314,2 @@ common.isFileIncluded( | ||
const registered = this.registered(fullPath); | ||
if (error && error.code === 'ENOENT') { | ||
@@ -322,3 +319,2 @@ this.unregister(fullPath); | ||
this.unregisterDir(fullPath); | ||
if (registered) { | ||
@@ -337,2 +333,3 @@ this.emitEvent(DELETE_EVENT, relativePath); | ||
} | ||
/** | ||
@@ -348,3 +345,2 @@ * Triggers a 'change' event after debounding it to take care of duplicate | ||
const addKey = `${ADD_EVENT}-${file}`; | ||
if (type === CHANGE_EVENT && this.changeTimers[addKey]) { | ||
@@ -355,7 +351,5 @@ // Ignore the change event that is immediately fired after an add event. | ||
} | ||
clearTimeout(this.changeTimers[key]); | ||
this.changeTimers[key] = setTimeout(() => { | ||
delete this.changeTimers[key]; | ||
if (type === ADD_EVENT && stat.isDirectory()) { | ||
@@ -382,6 +376,6 @@ // Recursively emit add events and watch for sub-files/folders | ||
} | ||
/** | ||
* Actually emit the events | ||
*/ | ||
rawEmitEvent(type, file, stat) { | ||
@@ -397,8 +391,8 @@ this.emit(type, file, this.root, stat); | ||
*/ | ||
function isIgnorableFileError(error) { | ||
return ( | ||
error.code === 'ENOENT' || // Workaround Windows node issue #4337. | ||
error.code === 'ENOENT' || | ||
// Workaround Windows node issue #4337. | ||
(error.code === 'EPERM' && platform === 'win32') | ||
); | ||
} |
// vendored from https://github.com/amasad/sane/blob/64ff3a870c42e84f744086884bf55a4f9c22d376/src/utils/recrawl-warning-dedupe.js | ||
'use strict'; | ||
@@ -9,7 +10,5 @@ | ||
} | ||
static findByRoot(root) { | ||
for (let i = 0; i < this.RECRAWL_WARNINGS.length; i++) { | ||
const warning = this.RECRAWL_WARNINGS[i]; | ||
if (warning.root === root) { | ||
@@ -19,6 +18,4 @@ return warning; | ||
} | ||
return undefined; | ||
} | ||
static isRecrawlWarningDupe(warningMessage) { | ||
@@ -28,13 +25,9 @@ if (typeof warningMessage !== 'string') { | ||
} | ||
const match = warningMessage.match(this.REGEXP); | ||
if (!match) { | ||
return false; | ||
} | ||
const count = Number(match[1]); | ||
const root = match[2]; | ||
const warning = this.findByRoot(root); | ||
if (warning) { | ||
@@ -56,3 +49,2 @@ // only keep the highest count, assume count to either stay the same or | ||
} | ||
RecrawlWarning.RECRAWL_WARNINGS = []; | ||
@@ -59,0 +51,0 @@ RecrawlWarning.REGEXP = |
@@ -7,57 +7,42 @@ 'use strict'; | ||
exports.default = WatchmanWatcher; | ||
function _assert() { | ||
const data = _interopRequireDefault(require('assert')); | ||
const data = require('assert'); | ||
_assert = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _events() { | ||
const data = require('events'); | ||
_events = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _path() { | ||
const data = _interopRequireDefault(require('path')); | ||
_path = function () { | ||
function path() { | ||
const data = _interopRequireWildcard(require('path')); | ||
path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _fbWatchman() { | ||
const data = _interopRequireDefault(require('fb-watchman')); | ||
_fbWatchman = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function fs() { | ||
const data = _interopRequireWildcard(require('graceful-fs')); | ||
fs = function () { | ||
function _gracefulFs() { | ||
const data = _interopRequireDefault(require('graceful-fs')); | ||
_gracefulFs = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _RecrawlWarning = _interopRequireDefault(require('./RecrawlWarning')); | ||
var _common = _interopRequireDefault(require('./common')); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -71,3 +56,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -105,7 +89,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
/** | ||
@@ -117,2 +96,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const CHANGE_EVENT = _common.default.CHANGE_EVENT; | ||
@@ -123,2 +103,3 @@ const DELETE_EVENT = _common.default.DELETE_EVENT; | ||
const SUB_NAME = 'sane-sub'; | ||
/** | ||
@@ -135,7 +116,5 @@ * Watches `dir`. | ||
_common.default.assignOptions(this, opts); | ||
this.root = _path().default.resolve(dir); | ||
this.root = path().resolve(dir); | ||
this.init(); | ||
} | ||
Object.setPrototypeOf( | ||
@@ -145,2 +124,3 @@ WatchmanWatcher.prototype, | ||
); | ||
/** | ||
@@ -156,3 +136,2 @@ * Run the watchman `watch` command on the root and subscribe to changes. | ||
} | ||
const self = this; | ||
@@ -169,7 +148,5 @@ this.client = new (_fbWatchman().default.Client)(); | ||
this.watchProjectInfo = null; | ||
function getWatchRoot() { | ||
return self.watchProjectInfo ? self.watchProjectInfo.root : self.root; | ||
} | ||
function onCapability(error, resp) { | ||
@@ -180,6 +157,4 @@ if (handleError(self, error)) { | ||
} | ||
handleWarning(resp); | ||
self.capabilities = resp.capabilities; | ||
if (self.capabilities.relative_root) { | ||
@@ -191,3 +166,2 @@ self.client.command(['watch-project', getWatchRoot()], onWatchProject); | ||
} | ||
function onWatchProject(error, resp) { | ||
@@ -197,3 +171,2 @@ if (handleError(self, error)) { | ||
} | ||
handleWarning(resp); | ||
@@ -206,3 +179,2 @@ self.watchProjectInfo = { | ||
} | ||
function onWatch(error, resp) { | ||
@@ -212,7 +184,5 @@ if (handleError(self, error)) { | ||
} | ||
handleWarning(resp); | ||
self.client.command(['clock', getWatchRoot()], onClock); | ||
} | ||
function onClock(error, resp) { | ||
@@ -222,3 +192,2 @@ if (handleError(self, error)) { | ||
} | ||
handleWarning(resp); | ||
@@ -228,3 +197,5 @@ const options = { | ||
since: resp.clock | ||
}; // If the server has the wildmatch capability available it supports | ||
}; | ||
// If the server has the wildmatch capability available it supports | ||
// the recursive **/*.foo style match and we can offload our globs | ||
@@ -234,3 +205,2 @@ // to the watchman server. This saves both on data size to be | ||
// in our node process. | ||
if (self.capabilities.wildmatch) { | ||
@@ -251,3 +221,2 @@ if (self.globs.length === 0) { | ||
options.expression = ['anyof']; | ||
for (const i in self.globs) { | ||
@@ -265,7 +234,5 @@ options.expression.push([ | ||
} | ||
if (self.capabilities.relative_root) { | ||
options.relative_root = self.watchProjectInfo.relativePath; | ||
} | ||
self.client.command( | ||
@@ -276,3 +243,2 @@ ['subscribe', getWatchRoot(), SUB_NAME, options], | ||
} | ||
function onSubscribe(error, resp) { | ||
@@ -282,7 +248,5 @@ if (handleError(self, error)) { | ||
} | ||
handleWarning(resp); | ||
self.emit('ready'); | ||
} | ||
self.client.capabilityCheck( | ||
@@ -295,2 +259,3 @@ { | ||
}; | ||
/** | ||
@@ -304,3 +269,3 @@ * Handles a change event coming from the subscription. | ||
WatchmanWatcher.prototype.handleChangeEvent = function (resp) { | ||
_assert().default.equal( | ||
_assert().strict.equal( | ||
resp.subscription, | ||
@@ -310,11 +275,8 @@ SUB_NAME, | ||
); | ||
if (resp.is_fresh_instance) { | ||
this.emit('fresh_instance'); | ||
} | ||
if (resp.is_fresh_instance) { | ||
this.emit('fresh_instance'); | ||
} | ||
if (Array.isArray(resp.files)) { | ||
@@ -324,2 +286,3 @@ resp.files.forEach(this.handleFileChange, this); | ||
}; | ||
/** | ||
@@ -336,6 +299,5 @@ * Handles a single change event record. | ||
let relativePath; | ||
if (this.capabilities.relative_root) { | ||
relativePath = changeDescriptor.name; | ||
absPath = _path().default.join( | ||
absPath = path().join( | ||
this.watchProjectInfo.root, | ||
@@ -346,6 +308,5 @@ this.watchProjectInfo.relativePath, | ||
} else { | ||
absPath = _path().default.join(this.root, changeDescriptor.name); | ||
absPath = path().join(this.root, changeDescriptor.name); | ||
relativePath = changeDescriptor.name; | ||
} | ||
if ( | ||
@@ -362,7 +323,6 @@ !(self.capabilities.wildmatch && !this.hasIgnore) && | ||
} | ||
if (!changeDescriptor.exists) { | ||
self.emitEvent(DELETE_EVENT, relativePath, self.root); | ||
} else { | ||
fs().lstat(absPath, (error, stat) => { | ||
_gracefulFs().default.lstat(absPath, (error, stat) => { | ||
// Files can be deleted between the event and the lstat call | ||
@@ -373,9 +333,8 @@ // the most reliable thing to do here is to ignore the event. | ||
} | ||
if (handleError(self, error)) { | ||
return; | ||
} | ||
const eventType = changeDescriptor.new ? ADD_EVENT : CHANGE_EVENT; | ||
const eventType = changeDescriptor.new ? ADD_EVENT : CHANGE_EVENT; // Change event on dirs are mostly useless. | ||
// Change event on dirs are mostly useless. | ||
if (!(eventType === CHANGE_EVENT && stat.isDirectory())) { | ||
@@ -387,2 +346,3 @@ self.emitEvent(eventType, relativePath, self.root, stat); | ||
}; | ||
/** | ||
@@ -407,2 +367,3 @@ * Dispatches the event. | ||
}; | ||
/** | ||
@@ -418,2 +379,3 @@ * Closes the watcher. | ||
}; | ||
/** | ||
@@ -435,2 +397,3 @@ * Handles an error and returns true if exists. | ||
} | ||
/** | ||
@@ -448,3 +411,2 @@ * Handles a warning in the watchman resp object. | ||
} | ||
console.warn(resp.warning); | ||
@@ -451,0 +413,0 @@ return true; |
@@ -8,53 +8,36 @@ 'use strict'; | ||
exports.worker = worker; | ||
function _crypto() { | ||
const data = require('crypto'); | ||
_crypto = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function path() { | ||
const data = _interopRequireWildcard(require('path')); | ||
path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function fs() { | ||
const data = _interopRequireWildcard(require('graceful-fs')); | ||
fs = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestUtil() { | ||
const data = require('jest-util'); | ||
_jestUtil = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _blacklist = _interopRequireDefault(require('./blacklist')); | ||
var _constants = _interopRequireDefault(require('./constants')); | ||
var _dependencyExtractor = require('./lib/dependencyExtractor'); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -68,3 +51,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -102,3 +84,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
/** | ||
@@ -110,10 +91,9 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const PACKAGE_JSON = `${path().sep}package.json`; | ||
let hasteImpl = null; | ||
let hasteImplModulePath = null; | ||
function sha1hex(content) { | ||
return (0, _crypto().createHash)('sha1').update(content).digest('hex'); | ||
} | ||
async function worker(data) { | ||
@@ -127,7 +107,5 @@ if ( | ||
} | ||
hasteImplModulePath = data.hasteImplModulePath; | ||
hasteImpl = require(hasteImplModulePath); | ||
} | ||
let content; | ||
@@ -139,3 +117,2 @@ let dependencies; | ||
const {computeDependencies, computeSha1, rootDir, filePath} = data; | ||
const getContent = () => { | ||
@@ -145,6 +122,4 @@ if (content === undefined) { | ||
} | ||
return content; | ||
}; | ||
if (filePath.endsWith(PACKAGE_JSON)) { | ||
@@ -154,3 +129,2 @@ // Process a package.json that is returned as a PACKAGE type with its name. | ||
const fileData = JSON.parse(getContent()); | ||
if (fileData.name) { | ||
@@ -171,3 +145,2 @@ const relativeFilePath = path().relative(rootDir, filePath); | ||
} | ||
if (computeDependencies) { | ||
@@ -189,3 +162,2 @@ const content = getContent(); | ||
} | ||
if (id) { | ||
@@ -195,8 +167,8 @@ const relativeFilePath = path().relative(rootDir, filePath); | ||
} | ||
} // If a SHA-1 is requested on update, compute it. | ||
} | ||
// If a SHA-1 is requested on update, compute it. | ||
if (computeSha1) { | ||
sha1 = sha1hex(content || fs().readFileSync(filePath)); | ||
} | ||
return { | ||
@@ -209,3 +181,2 @@ dependencies, | ||
} | ||
async function getSha1(data) { | ||
@@ -212,0 +183,0 @@ const sha1 = data.computeSha1 |
{ | ||
"name": "jest-haste-map", | ||
"version": "29.1.2", | ||
"version": "29.2.0", | ||
"repository": { | ||
@@ -20,3 +20,3 @@ "type": "git", | ||
"dependencies": { | ||
"@jest/types": "^29.1.2", | ||
"@jest/types": "^29.2.0", | ||
"@types/graceful-fs": "^4.1.3", | ||
@@ -27,5 +27,5 @@ "@types/node": "*", | ||
"graceful-fs": "^4.2.9", | ||
"jest-regex-util": "^29.0.0", | ||
"jest-util": "^29.1.2", | ||
"jest-worker": "^29.1.2", | ||
"jest-regex-util": "^29.2.0", | ||
"jest-util": "^29.2.0", | ||
"jest-worker": "^29.2.0", | ||
"micromatch": "^4.0.4", | ||
@@ -35,3 +35,3 @@ "walker": "^1.0.8" | ||
"devDependencies": { | ||
"@jest/test-utils": "^29.1.2", | ||
"@jest/test-utils": "^29.2.0", | ||
"@types/fb-watchman": "^2.0.0", | ||
@@ -50,3 +50,3 @@ "@types/micromatch": "^4.0.1", | ||
}, | ||
"gitHead": "3c31dd619e8c022cde53f40fa12ea2a67f4752ce" | ||
"gitHead": "ee5b37a4f4433afcfffb0356cea47739d8092287" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3990
121427
Updated@jest/types@^29.2.0
Updatedjest-regex-util@^29.2.0
Updatedjest-util@^29.2.0
Updatedjest-worker@^29.2.0