Socket
Socket
Sign inDemoInstall

metro-file-map

Package Overview
Dependencies
Maintainers
2
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metro-file-map - npm Package Compare versions

Comparing version 0.80.5 to 0.80.6

src/lib/RootPathUtils.js

2

package.json
{
"name": "metro-file-map",
"version": "0.80.5",
"version": "0.80.6",
"description": "[Experimental] - 🚇 File crawling, watching and mapping for Metro",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -17,13 +17,2 @@ "use strict";

}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
const DEFAULT_PREFIX = "metro-file-map";

@@ -59,6 +48,4 @@ const DEFAULT_DIRECTORY = (0, _os.tmpdir)();

if (e?.code === "ENOENT") {
// Cache file not found - not considered an error.
return null;
}
// Rethrow anything else.
throw e;

@@ -65,0 +52,0 @@ }

@@ -1,30 +0,5 @@

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @noformat - Flow comment syntax
*/
/*
* This file exports a set of constants that are used for Jest's haste map
* serialization. On very large repositories, the haste map cache becomes very
* large to the point where it is the largest overhead in starting up Jest.
*
* This constant key map allows to keep the map smaller without having to build
* a custom serialization library.
*/
/*::
import type {HType} from './flow-types';
*/
"use strict";
const constants /*: HType */ = {
/* dependency serialization */
const constants = {
DEPENDENCY_DELIM: "\0",
/* file map attributes */
ID: 0,

@@ -37,9 +12,6 @@ MTIME: 1,

SYMLINK: 6,
/* module map attributes */
PATH: 0,
TYPE: 1,
/* module types */
MODULE: 0,
PACKAGE: 1,
/* platforms */
GENERIC_PLATFORM: "g",

@@ -46,0 +18,0 @@ NATIVE_PLATFORM: "native",

@@ -1,11 +0,1 @@

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
"use strict";

@@ -1,11 +0,1 @@

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
"use strict";

@@ -1,11 +0,1 @@

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
"use strict";

@@ -1,11 +0,1 @@

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
"use strict";

@@ -1,11 +0,1 @@

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
"use strict";

@@ -8,17 +8,5 @@ "use strict";

var _child_process = require("child_process");
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
async function hasNativeFindSupport() {
try {
return await new Promise((resolve) => {
// Check the find binary supports the non-POSIX -iname parameter wrapped in parens.
const args = [

@@ -25,0 +13,0 @@ ".",

"use strict";
var fastPath = _interopRequireWildcard(require("../../lib/fast_path"));
var _RootPathUtils = require("../../lib/RootPathUtils");
var _hasNativeFindSupport = _interopRequireDefault(

@@ -11,5 +11,2 @@ require("./hasNativeFindSupport")

var path = _interopRequireWildcard(require("path"));
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
function _getRequireWildcardCache(nodeInterop) {

@@ -55,13 +52,5 @@ if (typeof WeakMap !== "function") return null;

}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
const debug = require("debug")("Metro:NodeCrawler");

@@ -71,2 +60,3 @@ function find(roots, extensions, ignore, includeSymlinks, rootDir, callback) {

let activeCalls = 0;
const pathUtils = new _RootPathUtils.RootPathUtils(rootDir);
function search(directory) {

@@ -103,3 +93,3 @@ activeCalls++;

if (stat.isSymbolicLink() || extensions.includes(ext)) {
result.set(fastPath.relative(rootDir, file), [
result.set(pathUtils.absoluteToNormal(file), [
"",

@@ -140,13 +130,9 @@ stat.mtime.getTime(),

) {
// Examples:
// ( ( -type f ( -iname *.js ) ) )
// ( ( -type f ( -iname *.js -o -iname *.ts ) ) )
// ( ( -type f ( -iname *.js ) ) -o -type l )
// ( ( -type f ) -o -type l )
const extensionClause = extensions.length
? `( ${extensions.map((ext) => `-iname *.${ext}`).join(" -o ")} )`
: ""; // Empty inner expressions eg "( )" are not allowed
: "";
const expression = `( ( -type f ${extensionClause} ) ${
includeSymlinks ? "-o -type l " : ""
})`;
const pathUtils = new _RootPathUtils.RootPathUtils(rootDir);
const child = (0, _child_process.spawn)(

@@ -177,3 +163,3 @@ "find",

if (!err && stat) {
result.set(fastPath.relative(rootDir, path), [
result.set(pathUtils.absoluteToNormal(path), [
"",

@@ -220,3 +206,2 @@ stat.mtime.getTime(),

try {
// TODO: Use AbortSignal.reason directly when Flow supports it
abortSignal?.throwIfAborted();

@@ -223,0 +208,0 @@ } catch (e) {

"use strict";
var fastPath = _interopRequireWildcard(require("../../lib/fast_path"));
var _normalizePathSeparatorsToPosix = _interopRequireDefault(

@@ -10,2 +9,3 @@ require("../../lib/normalizePathSeparatorsToPosix")

);
var _RootPathUtils = require("../../lib/RootPathUtils");
var _planQuery = require("./planQuery");

@@ -15,5 +15,2 @@ var _invariant = _interopRequireDefault(require("invariant"));

var _perf_hooks = require("perf_hooks");
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
function _getRequireWildcardCache(nodeInterop) {

@@ -59,13 +56,5 @@ if (typeof WeakMap !== "function") return null;

}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
const watchman = require("fb-watchman");

@@ -95,2 +84,3 @@ const WATCHMAN_WARNING_INITIAL_DELAY_MILLISECONDS = 10000;

const client = new watchman.Client();
const pathUtils = new _RootPathUtils.RootPathUtils(rootDir);
abortSignal?.addEventListener("abort", () => client.end());

@@ -103,7 +93,3 @@ perfLogger?.point("watchmanCrawl_start");

});
const cmd = async (
command,
// $FlowFixMe[unclear-type] - Fix to use fb-watchman types
...args
) => {
const cmd = async (command, ...args) => {
let didLogWatchmanWaitMessage = false;

@@ -128,3 +114,2 @@ const startTime = _perf_hooks.performance.now();

const response = await new Promise((resolve, reject) =>
// $FlowFixMe[incompatible-call] - dynamic call of command
client.command([command, ...args], (error, result) =>

@@ -141,6 +126,4 @@ error ? reject(makeWatchmanError(error)) : resolve(result)

}
// $FlowFixMe[incompatible-return]
return response;
} finally {
// $FlowFixMe[incompatible-call] clearInterval / clearTimeout are interchangeable
clearInterval(intervalOrTimeoutId);

@@ -165,4 +148,2 @@ if (didLogWatchmanWaitMessage) {

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.directoryFilters.length > 0;

@@ -178,5 +159,2 @@ if (canBeFiltered) {

} else {
// Make the filter directories an empty array to signal that this
// root was already seen and needs to be watched for all files or
// directories.
watchmanRoots.set(response.watch, {

@@ -200,13 +178,5 @@ watcher: response.watcher,

async ([root, { directoryFilters, watcher }], index) => {
// Jest is only going to store one type of clock; a string that
// represents a local clock. However, the Watchman crawler supports
// a second type of clock that can be written by automation outside of
// Jest, called an "scm query", which fetches changed files based on
// source control mergebases. The reason this is necessary is because
// local clocks are not portable across systems, but scm queries are.
// By using scm queries, we can create the haste map on a different
// system and import it, transforming the clock into a local clock.
const since = previousState.clocks.get(
(0, _normalizePathSeparatorsToPosix.default)(
fastPath.relative(rootDir, root)
pathUtils.absoluteToNormal(root)
)

@@ -235,6 +205,2 @@ );

perfLogger?.point(`watchmanCrawl/query_${index}_end`);
// 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 =

@@ -296,6 +262,5 @@ typeof since !== "string" && since?.scm?.["mergebase-with"] != null;

const fsRoot = (0, _normalizePathSeparatorsToSystem.default)(watchRoot);
const relativeFsRoot = fastPath.relative(rootDir, fsRoot);
const relativeFsRoot = pathUtils.absoluteToNormal(fsRoot);
newClocks.set(
(0, _normalizePathSeparatorsToPosix.default)(relativeFsRoot),
// Ensure we persist only the local clock.
typeof response.clock === "string" ? response.clock : response.clock.clock

@@ -308,3 +273,3 @@ );

(0, _normalizePathSeparatorsToSystem.default)(fileData.name);
const relativeFilePath = fastPath.relative(rootDir, filePath);
const relativeFilePath = pathUtils.absoluteToNormal(filePath);
if (!fileData.exists) {

@@ -314,4 +279,2 @@ if (!isFresh) {

}
// Whether watchman can return exists: false in a fresh instance
// response is unknown, but there's nothing we need to do in that case.
} else if (!ignore(filePath)) {

@@ -334,5 +297,2 @@ const { mtime_ms, size } = fileData;

const nextData = ["", mtime, size, 0, "", sha1hex ?? null, symlinkInfo];
// If watchman is fresh, the removed files map starts with all files
// and we remove them as we verify they still exist.
if (isFresh) {

@@ -339,0 +299,0 @@ freshFileData.set(relativeFilePath, nextData);

@@ -7,12 +7,2 @@ "use strict";

exports.planQuery = planQuery;
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
function planQuery({

@@ -29,16 +19,2 @@ since,

}
/**
* Note on symlink_target:
*
* Watchman supports requesting the symlink_target field, which is
* *potentially* more efficient if targets can be read from metadata without
* reading/materialising files. However, at the time of writing, Watchman has
* issues reporting symlink_target on some backends[1]. Additionally, though
* the Eden watcher is known to work, it reads links serially[2] on demand[3]
* - less efficiently than we can do ourselves.
* [1] https://github.com/facebook/watchman/issues/1084
* [2] https://github.com/facebook/watchman/blob/v2023.01.02.00/watchman/watcher/eden.cpp#L476-L485
* [3] https://github.com/facebook/watchman/blob/v2023.01.02.00/watchman/watcher/eden.cpp#L433-L434
*/
if (includeSymlinks) {

@@ -59,34 +35,6 @@ fields.push("type");

};
/**
* Watchman "query planner".
*
* Watchman file queries consist of 1 or more generators that feed
* files through the expression evaluator.
*
* Strategy:
* 1. Select the narrowest possible generator so that the expression
* evaluator has fewer candidates to process.
* 2. Evaluate expressions from narrowest to broadest.
* 3. Don't use an expression to recheck a condition that the
* generator already guarantees.
* 4. Compose expressions to avoid combinatorial explosions in the
* number of terms.
*
* The ordering of generators/filters, from narrow to broad, is:
* - since = O(changes)
* - glob / dirname = O(files in a subtree of the repo)
* - suffix = O(files in the repo)
*
* We assume that file extensions are ~uniformly distributed in the
* repo but Haste map projects are focused on a handful of
* directories. Therefore `glob` < `suffix`.
*/
let queryGenerator;
if (since != null) {
// Prefer the since generator whenever we have a clock
query.since = since;
queryGenerator = "since";
// Filter on directories using an anyof expression
if (directoryFilters.length > 0) {

@@ -99,3 +47,2 @@ allOfTerms.push([

} else if (directoryFilters.length > 0) {
// Use the `glob` generator and filter only by extension.
query.glob = directoryFilters.map((directory) => `${directory}/**`);

@@ -105,21 +52,10 @@ query.glob_includedotfiles = true;

} else if (!includeSymlinks) {
// Use the `suffix` generator with no path/extension filtering, as long
// as we don't need (suffixless) directory symlinks.
query.suffix = extensions;
queryGenerator = "suffix";
} else {
// Fall back to `all` if we need symlinks and don't have a clock or
// directory filters.
queryGenerator = "all";
}
// `includeSymlinks` implies we need (suffixless) directory links. In the
// case of the `suffix` generator, a suffix expression would be redundant.
if (!includeSymlinks && queryGenerator !== "suffix") {
allOfTerms.push(["suffix", extensions]);
}
// If we only have one "all of" expression we can use it directly, otherwise
// wrap in ['allof', ...expressions]. By construction we should never have
// length 0.
query.expression =

@@ -126,0 +62,0 @@ allOfTerms.length === 1 ? allOfTerms[0] : ["allof", ...allOfTerms];

@@ -1,12 +0,1 @@

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
"use strict";

@@ -48,12 +48,2 @@ "use strict";

}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
const MOCKS_PATTERN = path.sep + "__mocks__" + path.sep;

@@ -60,0 +50,0 @@ const getMockName = (filePath) => {

@@ -32,3 +32,2 @@ "use strict";

var _DuplicateError = require("./lib/DuplicateError");
var fastPath = _interopRequireWildcard(require("./lib/fast_path"));
var _MockMap = _interopRequireDefault(require("./lib/MockMap"));

@@ -39,2 +38,3 @@ var _MutableHasteMap = _interopRequireDefault(require("./lib/MutableHasteMap"));

);
var _RootPathUtils = require("./lib/RootPathUtils");
var _TreeFS = _interopRequireDefault(require("./lib/TreeFS"));

@@ -94,21 +94,5 @@ var _Watcher = require("./Watcher");

}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
const debug = require("debug")("Metro:FileMap");
// This should be bumped whenever a code change to `metro-file-map` itself
// would cause a change to the cache data structure and/or content (for a given
// filesystem state and build parameters).
const CACHE_BREAKER = "7";
const CHANGE_INTERVAL = 30;
// Periodically yield to the event loop to allow parallel I/O, etc.
// Based on 200k files taking up to 800ms => max 40ms between yields.
const YIELD_EVERY_NUM_HASTE_FILES = 10000;

@@ -124,81 +108,2 @@ const NODE_MODULES = path.sep + "node_modules" + path.sep;

];
/**
* FileMap includes a JavaScript implementation of Facebook's haste module system.
*
* This implementation is inspired by https://github.com/facebook/node-haste
* and was built with for high-performance in large code repositories with
* hundreds of thousands of files. This implementation is scalable and provides
* predictable performance.
*
* Because the haste map creation and synchronization is critical to startup
* performance and most tasks are blocked by I/O this class makes heavy use of
* synchronous operations. It uses worker processes for parallelizing file
* access and metadata extraction.
*
* The data structures created by `metro-file-map` can be used directly from the
* cache without further processing. The metadata objects in the `files` and
* `map` objects contain cross-references: a metadata object from one can look
* up the corresponding metadata object in the other map. Note that in most
* projects, the number of files will be greater than the number of haste
* modules one module can refer to many files based on platform extensions.
*
* type CacheData = {
* clocks: WatchmanClocks,
* files: {[filepath: string]: FileMetaData},
* map: {[id: string]: HasteMapItem},
* mocks: {[id: string]: string},
* }
*
* // Watchman clocks are used for query synchronization and file system deltas.
* type WatchmanClocks = {[filepath: string]: string};
*
* type FileMetaData = {
* id: ?string, // used to look up module metadata objects in `map`.
* mtime: number, // check for outdated files.
* size: number, // size of the file in bytes.
* visited: boolean, // whether the file has been parsed or not.
* dependencies: Array<string>, // all relative dependencies of this file.
* sha1: ?string, // SHA-1 of the file, if requested via options.
* symlink: ?(1 | 0 | string), // Truthy if symlink, string is target
* };
*
* // Modules can be targeted to a specific platform based on the file name.
* // Example: platform.ios.js and Platform.android.js will both map to the same
* // `Platform` module. The platform should be specified during resolution.
* type HasteMapItem = {[platform: string]: ModuleMetaData};
*
* //
* type ModuleMetaData = {
* path: string, // the path to look up the file object in `files`.
* type: string, // the module type (either `package` or `module`).
* };
*
* Note that the data structures described above are conceptual only. The actual
* implementation uses arrays and constant keys for metadata storage. Instead of
* `{id: 'flatMap', mtime: 3421, size: 42, visited: true, dependencies: []}` the real
* representation is similar to `['flatMap', 3421, 42, 1, []]` to save storage space
* and reduce parse and write time of a big JSON blob.
*
* The HasteMap is created as follows:
* 1. read data from the cache or create an empty structure.
*
* 2. crawl the file system.
* * empty cache: crawl the entire file system.
* * cache available:
* * if watchman is available: get file system delta changes.
* * if watchman is unavailable: crawl the entire file system.
* * build metadata objects for every file. This builds the `files` part of
* the `HasteMap`.
*
* 3. parse and extract metadata from changed files.
* * this is done in parallel over worker processes to improve performance.
* * the worst case is to parse all files.
* * the best case is no file system access and retrieving all data from
* the cache.
* * the average case is a small number of changed files.
*
* 4. serialize the new `HasteMap` in a cache file.
*
*/
class FileMap extends _events.default {

@@ -215,4 +120,2 @@ static create(options) {

}
// Add VCS_DIRECTORIES to provided ignorePattern
let ignorePattern;

@@ -277,2 +180,3 @@ if (options.ignorePattern) {

this._buildPromise = null;
this._pathUtils = new _RootPathUtils.RootPathUtils(options.rootDir);
this._worker = null;

@@ -302,6 +206,2 @@ this._startupPerfLogger?.point("constructor_end");

rootDir,
// Typed `mixed` because we've read this from an external
// source. It'd be too expensive to validate at runtime, so
// trust our cache manager that this is correct.
// $FlowIgnore
fileSystemData: initialData.fileSystemData,

@@ -314,6 +214,2 @@ })

const mocks = initialData?.mocks ?? new Map();
// Construct the Haste map from the cached file system state while
// crawling to build a diff of current state vs cached. `fileSystem`
// is not mutated during either operation.
const [fileDelta, hasteMap] = await Promise.all([

@@ -326,4 +222,2 @@ this._buildFileDelta({

]);
// Update `fileSystem`, `hasteMap` and `mocks` based on the file delta.
await this._applyFileDelta(fileSystem, hasteMap, mocks, fileDelta);

@@ -373,3 +267,2 @@ await this._takeSnapshotAndPersist(

} of fileSystem.metadataIterator({
// Symlinks and node_modules are never Haste modules or packages.
includeNodeModules: false,

@@ -398,6 +291,2 @@ includeSymlinks: false,

}
/**
* 1. read data from the cache or create an empty structure.
*/
async read() {

@@ -422,6 +311,2 @@ let data;

}
/**
* 2. crawl the file system.
*/
async _buildFileDelta(previousState) {

@@ -465,9 +350,5 @@ this._startupPerfLogger?.point("buildFileDelta_start");

}
/**
* 3. parse and extract metadata from changed files.
*/
_processFile(hasteMap, mockMap, filePath, fileMetadata, workerOptions) {
const rootDir = this._options.rootDir;
const relativeFilePath = fastPath.relative(rootDir, filePath);
const relativeFilePath = this._pathUtils.absoluteToNormal(filePath);
const isSymlink = fileMetadata[_constants.default.SYMLINK] !== 0;

@@ -482,4 +363,2 @@ const computeSha1 =

typeof fileMetadata[_constants.default.SYMLINK] !== "string";
// Callback called when the response from the worker is successful.
const workerReply = (metadata) => {

@@ -503,4 +382,2 @@ fileMetadata[_constants.default.VISITED] = 1;

};
// Callback called when the response from the worker is an error.
const workerError = (error) => {

@@ -513,13 +390,7 @@ if (

) {
// $FlowFixMe[reassign-const] - Refactor this
error = new Error(error);
// $FlowFixMe[incompatible-use] - error is mixed
error.stack = ""; // Remove stack for stack-less errors.
error.stack = "";
}
throw error;
};
// 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)) {

@@ -542,9 +413,4 @@ if (computeSha1 || readLink) {

}
// Symlink Haste modules, Haste packages or mocks are not supported - read
// the target if requested and return early.
if (isSymlink) {
if (readLink) {
// If we only need to read a link, it's more efficient to do it in-band
// (with async file IO) than to have the overhead of worker IO.
return this._getWorker({

@@ -574,3 +440,3 @@ forceInBand: true,

if (existingMockPath != null) {
const secondMockPath = fastPath.relative(rootDir, filePath);
const secondMockPath = this._pathUtils.absoluteToNormal(filePath);
if (existingMockPath !== secondMockPath) {

@@ -618,5 +484,2 @@ const method = this._options.throwOnModuleCollision

const missingFiles = new Set();
// Remove files first so that we don't mistake moved mocks or Haste
// modules as duplicates.
this._startupPerfLogger?.point("applyFileDelta_remove_start");

@@ -628,4 +491,2 @@ for (const relativeFilePath of removedFiles) {

for (const [relativeFilePath, fileData] of changedFiles) {
// A crawler may preserve the H.VISITED flag to indicate that the file
// contents are unchaged and it doesn't need visiting again.
if (fileData[_constants.default.VISITED] === 1) {

@@ -640,8 +501,3 @@ continue;

}
// SHA-1, if requested, should already be present thanks to the crawler.
const filePath = fastPath.resolve(
this._options.rootDir,
relativeFilePath
);
const filePath = this._pathUtils.normalToAbsolute(relativeFilePath);
const maybePromise = this._processFile(

@@ -679,11 +535,2 @@ hasteMap,

for (const relativeFilePath of missingFiles) {
// It's possible that a file could be deleted between being seen by the
// crawler and our attempt to process it. For our purposes, this is
// equivalent to the file being deleted before the crawl, being absent
// from `changedFiles`, and (if we loaded from cache, and the file
// existed previously) possibly being reported in `removedFiles`.
//
// Treat the file accordingly - don't add it to `FileSystem`, and remove
// it if it already exists. We're not emitting events at this point in
// startup, so there's nothing more to do.
changedFiles.delete(relativeFilePath);

@@ -699,3 +546,2 @@ this._removeIfExists(fileSystem, hasteMap, mockMap, relativeFilePath);

if (worker && typeof worker.end === "function") {
// $FlowFixMe[unused-promise]
worker.end();

@@ -705,6 +551,2 @@ }

}
/**
* 4. Serialize a snapshot of our raw data via the configured cache manager
*/
async _takeSnapshotAndPersist(

@@ -732,6 +574,2 @@ fileSystem,

}
/**
* Creates workers or parses files and extracts metadata in-process.
*/
_getWorker(options) {

@@ -753,5 +591,2 @@ if (!this._worker) {

forkOptions: {
// Don't pass Node arguments down to workers. In particular, avoid
// unnecessarily registering Babel when we're running Metro from
// source (our worker is plain CommonJS).
execArgv: [],

@@ -770,3 +605,3 @@ },

}
const moduleName = fileMetadata[_constants.default.ID] || null; // Empty string indicates no module
const moduleName = fileMetadata[_constants.default.ID] || null;
if (moduleName == null) {

@@ -790,6 +625,2 @@ return;

}
/**
* Watch mode
*/
async _watch(fileSystem, hasteMap, mockMap) {

@@ -801,5 +632,2 @@ this._startupPerfLogger?.point("watch_start");

}
// 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;

@@ -809,3 +637,2 @@ this._options.retainAllFiles = true;

this._options.extensions.some((ext) => filePath.endsWith(ext));
const rootDir = this._options.rootDir;
let changeQueue = Promise.resolve();

@@ -815,3 +642,2 @@ let nextEmit = null;

if (nextEmit == null || nextEmit.eventsQueue.length === 0) {
// Nothing to emit
return;

@@ -849,7 +675,4 @@ }

metadata &&
// Ignore all directory events
(metadata.type === "d" ||
// Ignore regular files with unwatched extensions
(metadata.type === "f" && !hasWatchedExtension(filePath)) ||
// Don't emit events relating to symlinks if enableSymlinks: false
(!this._options.enableSymlinks && metadata?.type === "l"))

@@ -863,14 +686,8 @@ ) {

);
// Ignore files (including symlinks) whose path matches ignorePattern
// (we don't ignore node_modules in watch mode)
if (this._options.ignorePattern.test(absoluteFilePath)) {
return;
}
const relativeFilePath = fastPath.relative(rootDir, absoluteFilePath);
const relativeFilePath =
this._pathUtils.absoluteToNormal(absoluteFilePath);
const linkStats = fileSystem.linkStats(relativeFilePath);
// The file has been accessed, not modified. If the modified time is
// null, then it is assumed that the watcher does not have capabilities
// to detect modified time, and change processing proceeds.
if (

@@ -889,3 +706,2 @@ type === "change" &&

.then(async () => {
// If we get duplicate events for the same file, ignore them.
if (

@@ -927,4 +743,2 @@ nextEmit != null &&

};
// If it's not an addition, delete the file and all its metadata
if (linkStats != null) {

@@ -938,5 +752,2 @@ this._removeIfExists(

}
// If the file was added or changed,
// parse it and update the haste map.
if (type === "add" || type === "change") {

@@ -964,5 +775,4 @@ (0, _invariant.default)(

forceInBand: true,
} // No need to clean up workers
}
);
fileSystem.addOrModify(relativeFilePath, fileMetadata);

@@ -974,13 +784,5 @@ enqueueEvent(metadata);

}
// Swallow ENOENT/ACCESS errors silently. Safe because either:
// - We never knew about the file, so neither did any consumers.
// Or,
// - The watcher will soon (or has already) report a "delete"
// event for it, and we'll clean up in the usual way at that
// point.
}
} else if (type === "delete") {
if (linkStats == null) {
// Don't emit deletion events for files we weren't retaining.
// This is expected for deletion of an ignored file.
return null;

@@ -1017,3 +819,2 @@ }

}
// $FlowFixMe[unused-promise]
this._watcher

@@ -1046,6 +847,2 @@ .checkHealth(this._options.healthCheck.timeout)

}
/**
* Helpers
*/
_ignore(filePath) {

@@ -1066,6 +863,11 @@ const ignoreMatched = this._options.ignorePattern.test(filePath);

)
.then(() => true)
.then(({ version }) => {
this._startupPerfLogger?.annotate({
string: {
watchmanVersion: version,
},
});
return true;
})
.catch((e) => {
// TODO: Advise people to either install Watchman or set
// `useWatchman: false` here?
this._startupPerfLogger?.annotate({

@@ -1072,0 +874,0 @@ string: {

@@ -9,12 +9,2 @@ "use strict";

var _util = require("util");
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
async function checkWatchmanCapabilities(requiredCapabilities) {

@@ -28,5 +18,4 @@ const execFilePromise = (0, _util.promisify)(_child_process.execFile);

"--no-pretty",
"--no-spawn", // The client can answer this, so don't spawn a server
"--no-spawn",
]);
rawResponse = result.stdout;

@@ -67,2 +56,5 @@ } catch (e) {

}
return {
version,
};
}

@@ -1,16 +0,5 @@

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
"use strict";
const NOT_A_DOT = "(?<!\\.\\s*)";
const CAPTURE_STRING_LITERAL = (pos /*: number */) =>
`([\`'"])([^'"\`]*?)(?:\\${pos})`;
const CAPTURE_STRING_LITERAL = (pos) => `([\`'"])([^'"\`]*?)(?:\\${pos})`;
const WORD_SEPARATOR = "\\b";

@@ -21,12 +10,9 @@ const LEFT_PARENTHESIS = "\\(";

const OPTIONAL_COMMA = "(:?,\\s*)?";
function createRegExp(
parts /*: $ReadOnlyArray<string> */,
flags /*: string */
) {
function createRegExp(parts, flags) {
return new RegExp(parts.join(""), flags);
}
function alternatives(...parts /*: $ReadOnlyArray<string> */) {
function alternatives(...parts) {
return `(?:${parts.join("|")})`;
}
function functionCallStart(...names /*: $ReadOnlyArray<string> */) {
function functionCallStart(...names) {
return [

@@ -72,9 +58,5 @@ NOT_A_DOT,

);
function extract(code /*: string */) /*: $ReadOnlySet<string> */ {
const dependencies /*: Set<string> */ = new Set();
const addDependency = (
match /*: string */,
_ /*: string */,
dep /*: string */
) => {
function extract(code) {
const dependencies = new Set();
const addDependency = (match, _, dep) => {
dependencies.add(dep);

@@ -81,0 +63,0 @@ return match;

@@ -7,13 +7,2 @@ "use strict";

exports.DuplicateError = void 0;
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
class DuplicateError extends Error {

@@ -20,0 +9,0 @@ constructor(mockPath1, mockPath2) {

@@ -11,13 +11,2 @@ "use strict";

}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
class DuplicateHasteCandidatesError extends Error {

@@ -24,0 +13,0 @@ constructor(name, platform, supportsNativePlatform, duplicatesSet) {

@@ -49,20 +49,5 @@ "use strict";

}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
// rootDir must be normalized and absolute, filename may be any absolute path.
// (but will optimally start with rootDir)
function relative(rootDir, filename) {
if (filename.indexOf(rootDir + path.sep) === 0) {
const relativePath = filename.substr(rootDir.length + 1);
// Allow any sequence of indirection fragments at the start of the path,
// e.g ../../foo, but bail out to Node's path.relative if we find a
// possible indirection after any other segment, or a leading "./".
for (let i = 0; ; i += UP_FRAGMENT_LENGTH) {

@@ -73,7 +58,3 @@ const nextIndirection = relativePath.indexOf(CURRENT_FRAGMENT, i);

}
if (
nextIndirection !== i + 1 ||
// Fallback when ./ later in the path, or leading
relativePath[i] !== "." // and for anything other than a leading ../
) {
if (nextIndirection !== i + 1 || relativePath[i] !== ".") {
return path.relative(rootDir, filename);

@@ -88,18 +69,30 @@ }

const CURRENT_FRAGMENT = "." + path.sep;
// rootDir must be an absolute path and normalPath must be a normal relative
// path (e.g.: foo/bar or ../foo/bar, but never ./foo or foo/../bar)
// As of Node 18 this is several times faster than path.resolve, over
// thousands of real calls with 1-3 levels of indirection.
let cachedDirName = null;
let dirnameCache = [];
function resolve(rootDir, normalPath) {
if (normalPath.startsWith(UP_FRAGMENT)) {
const dirname = rootDir === "" ? "" : path.dirname(rootDir);
return resolve(dirname, normalPath.slice(UP_FRAGMENT_LENGTH));
} else {
return (
rootDir +
// If rootDir is the file system root, it will end in a path separator
(rootDir.endsWith(path.sep) ? normalPath : path.sep + normalPath)
);
let left = rootDir;
let i = 0;
let pos = 0;
while (
normalPath.startsWith(UP_FRAGMENT, pos) ||
(normalPath.endsWith("..") && normalPath.length === 2 + pos)
) {
if (i === 0 && cachedDirName !== rootDir) {
dirnameCache = [];
cachedDirName = rootDir;
}
if (dirnameCache.length === i) {
dirnameCache.push(path.dirname(left));
}
left = dirnameCache[i++];
pos += UP_FRAGMENT_LENGTH;
}
const right = pos === 0 ? normalPath : normalPath.slice(pos);
if (right.length === 0) {
return left;
}
if (left.endsWith(path.sep)) {
return left + right;
}
return left + path.sep + right;
}

@@ -7,13 +7,2 @@ "use strict";

exports.default = getPlatformExtension;
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
// Extract platform extension: index.ios.js -> ios
function getPlatformExtension(file, platforms) {

@@ -20,0 +9,0 @@ const last = file.lastIndexOf(".");

@@ -7,28 +7,17 @@ "use strict";

exports.default = void 0;
var _fast_path = require("./fast_path");
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
var _RootPathUtils = require("./RootPathUtils");
class MockMap {
#raw;
#rootDir;
#pathUtils;
constructor({ rawMockMap, rootDir }) {
this.#raw = rawMockMap;
this.#rootDir = rootDir;
this.#pathUtils = new _RootPathUtils.RootPathUtils(rootDir);
}
getMockModule(name) {
const mockPath = this.#raw.get(name) || this.#raw.get(name + "/index");
return mockPath != null
? (0, _fast_path.resolve)(this.#rootDir, mockPath)
: null;
return mockPath != null ? this.#pathUtils.normalToAbsolute(mockPath) : null;
}
}
exports.default = MockMap;

@@ -10,61 +10,10 @@ "use strict";

var _DuplicateHasteCandidatesError = require("./DuplicateHasteCandidatesError");
var fastPath = _interopRequireWildcard(require("./fast_path"));
var _getPlatformExtension = _interopRequireDefault(
require("./getPlatformExtension")
);
var _RootPathUtils = require("./RootPathUtils");
var _path = _interopRequireDefault(require("path"));
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function (nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interopRequireWildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || (typeof obj !== "object" && typeof obj !== "function")) {
return { default: obj };
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor =
Object.defineProperty && Object.getOwnPropertyDescriptor;
for (var key in obj) {
if (key !== "default" && 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 _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
const EMPTY_OBJ = {};

@@ -77,4 +26,5 @@ const EMPTY_MAP = new Map();

#console;
#pathUtils;
#platforms;
#throwOnModuleCollision;
#platforms;
constructor(options) {

@@ -84,2 +34,3 @@ this.#console = options.console ?? null;

this.#rootDir = options.rootDir;
this.#pathUtils = new _RootPathUtils.RootPathUtils(options.rootDir);
this.#throwOnModuleCollision = options.throwOnModuleCollision;

@@ -124,3 +75,3 @@ }

const modulePath = module[_constants.default.PATH];
return modulePath && fastPath.resolve(this.#rootDir, modulePath);
return modulePath && this.#pathUtils.normalToAbsolute(modulePath);
}

@@ -132,5 +83,2 @@ return null;

}
// FIXME: This is only used by Meta-internal validation and should be
// removed or replaced with a less leaky API.
getRawHasteMap() {

@@ -142,11 +90,2 @@ return {

}
/**
* When looking up a module's data, we walk through each eligible platform for
* the query. For each platform, we want to check if there are known
* duplicates for that name+platform pair. The duplication logic normally
* removes elements from the `map` object, but we want to check upfront to be
* extra sure. If metadata exists both in the `duplicates` object and the
* `map`, this would be a bug.
*/
_getModuleMetadata(name, platform, supportsNativePlatform) {

@@ -194,3 +133,3 @@ const map = this.#map.get(name) || EMPTY_OBJ;

for (const [relativePath, type] of relativePathSet) {
const duplicatePath = fastPath.resolve(this.#rootDir, relativePath);
const duplicatePath = this.#pathUtils.normalToAbsolute(relativePath);
duplicates.set(duplicatePath, type);

@@ -208,3 +147,2 @@ }

if (!hasteMapItem) {
// $FlowFixMe[unclear-type] - Add type coverage
hasteMapItem = Object.create(null);

@@ -246,4 +184,2 @@ this.#map.set(id, hasteMapItem);

}
// We do NOT want consumers to use a module that is ambiguous.
delete hasteMapItem[platform];

@@ -299,11 +235,2 @@ if (Object.keys(hasteMapItem).length === 0) {

}
/**
* This function should be called when the file under `filePath` is removed
* or changed. When that happens, we want to figure out if that file was
* part of a group of files that had the same ID. If it was, we want to
* remove it from the group. Furthermore, if there is only one file
* remaining in the group, then we want to restore that single file as the
* correct resolution for its ID, and cleanup the duplicates index.
*/
_recoverDuplicates(moduleName, relativeFilePath) {

@@ -310,0 +237,0 @@ let dupsByPlatform = this.#duplicates.get(moduleName);

@@ -48,12 +48,2 @@ "use strict";

}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
let normalizePathSeparatorsToPosix;

@@ -60,0 +50,0 @@ if (path.sep === "/") {

@@ -48,12 +48,2 @@ "use strict";

}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
let normalizePathSeparatorsToSystem;

@@ -60,0 +50,0 @@ if (path.sep === "/") {

@@ -7,6 +7,6 @@ "use strict";

exports.default = rootRelativeCacheKeys;
var fastPath = _interopRequireWildcard(require("./fast_path"));
var _normalizePathSeparatorsToPosix = _interopRequireDefault(
require("./normalizePathSeparatorsToPosix")
);
var _RootPathUtils = require("./RootPathUtils");
var _crypto = require("crypto");

@@ -16,53 +16,2 @@ function _interopRequireDefault(obj) {

}
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function (nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interopRequireWildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || (typeof obj !== "object" && typeof obj !== "function")) {
return { default: obj };
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor =
Object.defineProperty && Object.getOwnPropertyDescriptor;
for (var key in obj) {
if (key !== "default" && 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;
}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
function moduleCacheKey(modulePath) {

@@ -72,3 +21,2 @@ if (modulePath == null) {

}
// $FlowFixMe[unsupported-syntax] - Dynamic require
const moduleExports = require(modulePath);

@@ -89,2 +37,3 @@ if (typeof moduleExports?.getCacheKey !== "function") {

.digest("hex");
const pathUtils = new _RootPathUtils.RootPathUtils(rootDir);
const cacheComponents = Object.keys(otherParameters)

@@ -97,3 +46,3 @@ .sort()

(0, _normalizePathSeparatorsToPosix.default)(
fastPath.relative(rootDir, root)
pathUtils.absoluteToNormal(root)
)

@@ -124,6 +73,2 @@ );

});
// JSON.stringify is stable here because we only deal in (nested) arrays of
// primitives. Use a different approach if this is expanded to include
// objects/Sets/Maps, etc.
const relativeConfigHash = (0, _crypto.createHash)("md5")

@@ -130,0 +75,0 @@ .update(JSON.stringify(cacheComponents))

@@ -8,65 +8,8 @@ "use strict";

var _constants = _interopRequireDefault(require("../constants"));
var fastPath = _interopRequireWildcard(require("../lib/fast_path"));
var _RootPathUtils = require("./RootPathUtils");
var _invariant = _interopRequireDefault(require("invariant"));
var _path = _interopRequireDefault(require("path"));
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function (nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interopRequireWildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || (typeof obj !== "object" && typeof obj !== "function")) {
return { default: obj };
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor =
Object.defineProperty && Object.getOwnPropertyDescriptor;
for (var key in obj) {
if (key !== "default" && 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 _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
// Terminology:
//
// mixedPath - a root-relative or absolute path
// relativePath - a root-relative path
// normalPath - a root-relative, normalised path (no extraneous '.' or '..')
// canonicalPath - a root-relative, normalised, real path (no symlinks in dirname)
class TreeFS {

@@ -76,4 +19,6 @@ #cachedNormalSymlinkTargets = new WeakMap();

#rootNode = new Map();
#pathUtils;
constructor({ rootDir, files }) {
this.#rootDir = rootDir;
this.#pathUtils = new _RootPathUtils.RootPathUtils(rootDir);
if (files != null) {

@@ -126,3 +71,2 @@ this.bulkAddOrModify(files);

) {
// Types differ, file has changed
continue;

@@ -132,3 +76,2 @@ }

newMetadata[_constants.default.MTIME] != null &&
// TODO: Remove when mtime is null if not populated
newMetadata[_constants.default.MTIME] != 0 &&

@@ -138,3 +81,2 @@ newMetadata[_constants.default.MTIME] ===

) {
// Types and modified time match - not changed.
changedFiles.delete(canonicalPath);

@@ -147,3 +89,2 @@ } else if (

) {
// Content matches - update modified time but don't revisit
const updatedMetadata = [...metadata];

@@ -171,4 +112,44 @@ updatedMetadata[_constants.default.MTIME] =

}
lookup(mixedPath) {
const normalPath = this._normalizePath(mixedPath);
const result = this._lookupByNormalPath(normalPath, {
followLeaf: true,
});
if (!result.exists) {
const { canonicalMissingPath, canonicalLinkPaths } = result;
return {
exists: false,
links: new Set(
canonicalLinkPaths.map((canonicalPath) =>
this.#pathUtils.normalToAbsolute(canonicalPath)
)
),
missing: this.#pathUtils.normalToAbsolute(canonicalMissingPath),
};
}
const { canonicalPath, canonicalLinkPaths, node } = result;
const type =
node instanceof Map
? "d"
: node[_constants.default.SYMLINK] === 0
? "f"
: "l";
(0, _invariant.default)(
type !== "l",
"lookup follows symlinks, so should never return one (%s -> %s)",
mixedPath,
canonicalPath
);
return {
exists: true,
links: new Set(
canonicalLinkPaths.map((canonicalPath) =>
this.#pathUtils.normalToAbsolute(canonicalPath)
)
),
realPath: this.#pathUtils.normalToAbsolute(canonicalPath),
type,
};
}
getAllFiles() {
const rootDir = this.#rootDir;
return Array.from(

@@ -179,3 +160,3 @@ this.metadataIterator({

}),
({ canonicalPath }) => fastPath.resolve(rootDir, canonicalPath)
({ canonicalPath }) => this.#pathUtils.normalToAbsolute(canonicalPath)
);

@@ -197,8 +178,2 @@ }

}
/**
* Given a search context, return a list of file paths matching the query.
* The query matches against normalized paths which start with `./`,
* for example: `a/b.js` -> `./a/b.js`
*/
*matchFiles({

@@ -214,3 +189,3 @@ filter = null,

const contextRootResult = this._lookupByNormalPath(normalRoot);
if (!contextRootResult) {
if (!contextRootResult.exists) {
return;

@@ -242,5 +217,2 @@ }

filter.test(
// NOTE(EvanBacon): Ensure files start with `./` for matching purposes
// this ensures packages work across Metro and Webpack (ex: Storybook for React DOM / React Native).
// `a/b.js` -> `./a/b.js`
filterCompareAbsolute === true

@@ -262,16 +234,4 @@ ? _path.default.join(

}
getRealPath(mixedPath) {
const normalPath = this._normalizePath(mixedPath);
const result = this._lookupByNormalPath(normalPath, {
followLeaf: true,
});
if (!result || result.node instanceof Map) {
return null;
}
return fastPath.resolve(this.#rootDir, result.canonicalPath);
}
addOrModify(mixedPath, metadata) {
const normalPath = this._normalizePath(mixedPath);
// Walk the tree to find the *real* path of the parent node, creating
// directories as we need.
const parentDirNode = this._lookupByNormalPath(

@@ -283,3 +243,3 @@ _path.default.dirname(normalPath),

);
if (!parentDirNode) {
if (!parentDirNode.exists) {
throw new Error(

@@ -289,3 +249,2 @@ `TreeFS: Failed to make parent directory entry for ${mixedPath}`

}
// Normalize the resulting path to account for the parent node being root.
const canonicalPath = this._normalizePath(

@@ -299,6 +258,2 @@ parentDirNode.canonicalPath +

bulkAddOrModify(addedOrModifiedFiles) {
// Optimisation: Bulk FileData are typically clustered by directory, so we
// optimise for that case by remembering the last directory we looked up.
// Experiments with large result sets show this to be significantly (~30%)
// faster than caching all lookups in a Map, and 70% faster than no cache.
let lastDir;

@@ -318,3 +273,4 @@ let directoryNode;

throw new Error(
`TreeFS: Could not add directory ${dirname} when adding files`
`TreeFS: Could not add directory ${dirname}, adding ${normalPath}. ` +
`${dirname} already exists in the file map as a file.`
);

@@ -333,19 +289,18 @@ }

});
if (!result) {
if (!result.exists) {
return null;
}
const { parentNode, canonicalPath, node } = result;
if (node instanceof Map) {
throw new Error(`TreeFS: remove called on a directory: ${mixedPath}`);
if (node instanceof Map && node.size > 0) {
throw new Error(
`TreeFS: remove called on a non-empty directory: ${mixedPath}`
);
}
// If node is a symlink, get its metadata from the tuple.
const fileMetadata = node;
if (fileMetadata == null) {
throw new Error(`TreeFS: Missing metadata for ${mixedPath}`);
if (parentNode != null) {
parentNode.delete(_path.default.basename(canonicalPath));
if (parentNode.size === 0 && parentNode !== this.#rootNode) {
this.remove(_path.default.dirname(canonicalPath));
}
}
if (parentNode == null) {
throw new Error(`TreeFS: Missing parent node for ${mixedPath}`);
}
parentNode.delete(_path.default.basename(canonicalPath));
return fileMetadata;
return node instanceof Map ? null : node;
}

@@ -359,10 +314,6 @@ _lookupByNormalPath(

) {
// We'll update the target if we hit a symlink.
let targetNormalPath = requestedNormalPath;
// Lazy-initialised set of seen target paths, to detect symlink cycles.
const canonicalLinkPaths = [];
let seen;
// Pointer to the first character of the current path segment in
// targetNormalPath.
let fromIdx = 0;
// The parent of the current segment
let parentNode = this.#rootNode;

@@ -381,11 +332,16 @@ while (targetNormalPath.length > fromIdx) {

if (segmentNode == null) {
if (opts.makeDirectories !== true) {
return null;
if (opts.makeDirectories !== true && segmentName !== "..") {
return {
canonicalLinkPaths,
canonicalMissingPath: isLastSegment
? targetNormalPath
: targetNormalPath.slice(0, fromIdx - 1),
exists: false,
};
}
segmentNode = new Map();
parentNode.set(segmentName, segmentNode);
if (opts.makeDirectories === true) {
parentNode.set(segmentName, segmentNode);
}
}
// If there are no more '/' to come, we're done unless this is a symlink
// we must follow.
if (

@@ -398,3 +354,5 @@ isLastSegment &&

return {
canonicalLinkPaths,
canonicalPath: targetNormalPath,
exists: true,
node: segmentNode,

@@ -404,22 +362,20 @@ parentNode,

}
// If the next node is a directory, go into it
if (segmentNode instanceof Map) {
parentNode = segmentNode;
} else {
const currentPath = isLastSegment
? targetNormalPath
: targetNormalPath.slice(0, fromIdx - 1);
if (segmentNode[_constants.default.SYMLINK] === 0) {
// Regular file in a directory path
return null;
return {
canonicalLinkPaths,
canonicalMissingPath: currentPath,
exists: false,
};
}
// Symlink in a directory path
const normalSymlinkTarget = this._resolveSymlinkTargetToNormalPath(
segmentNode,
isLastSegment
? targetNormalPath
: targetNormalPath.slice(0, fromIdx - 1)
currentPath
);
// Append any subsequent path segments to the symlink target, and reset
// with our new target.
canonicalLinkPaths.push(currentPath);
targetNormalPath = isLastSegment

@@ -431,8 +387,10 @@ ? normalSymlinkTarget

if (seen == null) {
// Optimisation: set this lazily only when we've encountered a symlink
seen = new Set([requestedNormalPath]);
}
if (seen.has(targetNormalPath)) {
// TODO: Warn `Symlink cycle detected: ${[...seen, node].join(' -> ')}`
return null;
return {
canonicalLinkPaths,
canonicalMissingPath: targetNormalPath,
exists: false,
};
}

@@ -449,3 +407,5 @@ seen.add(targetNormalPath);

return {
canonicalLinkPaths,
canonicalPath: targetNormalPath,
exists: true,
node: this.#rootNode,

@@ -485,10 +445,5 @@ parentNode: null,

return _path.default.isAbsolute(relativeOrAbsolutePath)
? fastPath.relative(this.#rootDir, relativeOrAbsolutePath)
: _path.default.normalize(relativeOrAbsolutePath);
? this.#pathUtils.absoluteToNormal(relativeOrAbsolutePath)
: this.#pathUtils.relativeToNormal(relativeOrAbsolutePath);
}
/**
* Enumerate paths under a given node, including symlinks and through
* symlinks (if `follow` is enabled).
*/
*_pathIterator(rootNode, opts, pathPrefix = "", followedLinks = new Set()) {

@@ -504,6 +459,4 @@ const pathSep = opts.alwaysYieldPosix ? "/" : _path.default.sep;

if (node[_constants.default.SYMLINK] === 0) {
// regular file
yield nodePath;
} else {
// symlink
const nodePathWithSystemSeparators =

@@ -513,5 +466,2 @@ pathSep === _path.default.sep

: nodePath.replaceAll(pathSep, _path.default.sep);
// Although both paths are normal, the node path may begin '..' so we
// can't simply concatenate.
const normalPathOfSymlink = _path.default.join(

@@ -521,14 +471,6 @@ opts.canonicalPathOfRoot,

);
// We can't resolve the symlink directly here because we only have
// its normal path, and we need a canonical path for resolution
// (imagine our normal path contains a symlink 'bar' -> '.', and we
// are at /foo/bar/baz where baz -> '..' - that should resolve to
// /foo, not /foo/bar). We *can* use _lookupByNormalPath to walk to
// the canonical symlink, and then to its target.
const resolved = this._lookupByNormalPath(normalPathOfSymlink, {
followLeaf: true,
});
if (resolved == null) {
// Symlink goes nowhere, nothing to report.
if (!resolved.exists) {
continue;

@@ -538,3 +480,2 @@ }

if (!(target instanceof Map)) {
// Symlink points to a file, just yield the path of the symlink.
yield nodePath;

@@ -546,4 +487,2 @@ } else if (

) {
// Symlink points to a directory - iterate over its contents using
// the path where we found the symlink as a prefix.
yield* this._pathIterator(

@@ -576,6 +515,4 @@ target,

"..",
// Symlink target is relative to its containing directory.
literalSymlinkTarget // May be absolute, in which case the above are ignored
literalSymlinkTarget
);
normalSymlinkTarget = _path.default.relative(

@@ -598,3 +535,3 @@ this.#rootDir,

});
if (result == null || result.node instanceof Map) {
if (!result.exists || result.node instanceof Map) {
return null;

@@ -601,0 +538,0 @@ }

@@ -65,12 +65,2 @@ "use strict";

}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
const debug = require("debug")("Metro:Watcher");

@@ -124,3 +114,2 @@ const MAX_WAIT_TIME = 240000;

);
// $FlowFixMe[prop-missing] Found when updating Promise type definition
return (0, _node.default)(crawlerOptions).catch((e) => {

@@ -149,3 +138,2 @@ throw new Error(

try {
// $FlowFixMe[incompatible-call] Found when updating Promise type definition
return crawl(crawlerOptions).catch(retry).then(logEnd);

@@ -158,4 +146,2 @@ } catch (error) {

const { extensions, ignorePattern, useWatchman } = this._options;
// WatchmanWatcher > FSEventsWatcher > sane.NodeWatcher
const WatcherImpl = useWatchman

@@ -183,6 +169,3 @@ ? _WatchmanWatcher.default

glob: [
// Ensure we always include package.json files, which are crucial for
/// module resolution.
"**/package.json",
// Ensure we always watch any health check files
"**/" + this._options.healthCheckFilePrefix + "*",

@@ -295,5 +278,2 @@ ...extensions.map((extension) => "**/*." + extension),

this._pendingHealthChecks.delete(basename);
// Chain a deletion to the creation promise (which may not have even settled yet!),
// don't await it, and swallow errors. This is just best-effort cleanup.
// $FlowFixMe[unused-promise]
creationPromise.then(() =>

@@ -300,0 +280,0 @@ fs.promises.unlink(healthCheckPath).catch(() => {})

@@ -1,17 +0,1 @@

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
/**
* Originally vendored from
* https://github.com/amasad/sane/blob/64ff3a870c42e84f744086884bf55a4f9c22d376/src/common.js
*/
"use strict";

@@ -31,14 +15,7 @@

exports.typeFromStat = typeFromStat;
// $FlowFixMe[untyped-import] - Write libdefs for `anymatch`
const anymatch = require("anymatch");
// $FlowFixMe[untyped-import] - Write libdefs for `micromatch`
const micromatch = require("micromatch");
const platform = require("os").platform();
const path = require("path");
// $FlowFixMe[untyped-import] - Write libdefs for `walker`
const walker = require("walker");
/**
* Constants
*/
const CHANGE_EVENT = "change";

@@ -52,10 +29,2 @@ exports.CHANGE_EVENT = CHANGE_EVENT;

exports.ALL_EVENT = ALL_EVENT;
/**
* Assigns options to the watcher.
*
* @param {NodeWatcher|PollWatcher|WatchmanWatcher} watcher
* @param {?object} opts
* @return {boolean}
* @public
*/
const assignOptions = function (watcher, opts) {

@@ -78,6 +47,2 @@ watcher.globs = opts.glob ?? [];

};
/**
* Checks a file relative path against the globs array.
*/
exports.assignOptions = assignOptions;

@@ -88,4 +53,2 @@ function isIncluded(type, globs, dot, doIgnore, relativePath) {

}
// For non-regular files or if there are no glob matchers, just respect the
// `dot` option to filter dotfiles if dot === false.
if (globs.length === 0 || type !== "f") {

@@ -98,6 +61,2 @@ return dot || micromatch.some(relativePath, "**/*");

}
/**
* Traverse a directory recursively calling `callback` on every directory.
*/
function recReaddir(

@@ -126,7 +85,2 @@ dir,

}
/**
* Returns a callback that when called will normalize a path and call the
* original callback
*/
function normalizeProxy(callback) {

@@ -136,3 +90,2 @@ return (filepath, stats) => callback(path.normalize(filepath), stats);

function typeFromStat(stat) {
// Note: These tests are not mutually exclusive - a symlink passes isFile
if (stat.isSymbolicLink()) {

@@ -145,6 +98,5 @@ return "l";

if (stat.isFile()) {
return "f"; // "Regular" file
return "f";
}
return null;
}

@@ -56,26 +56,7 @@ "use strict";

}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
// $FlowFixMe[cannot-resolve-module] - Optional, Darwin only
// $FlowFixMe[untyped-import] - anymatch
// $FlowFixMe[untyped-import] - walker
const debug = require("debug")("Metro:FSEventsWatcher");
let fsevents = null;
try {
// $FlowFixMe[cannot-resolve-module] - Optional, Darwin only
fsevents = require("fsevents");
} catch {
// Optional dependency, only supported on Darwin.
}
} catch {}
const CHANGE_EVENT = "change";

@@ -85,6 +66,2 @@ const DELETE_EVENT = "delete";

const ALL_EVENT = "all";
/**
* Export `FSEventsWatcher` class.
* Watches `dir`.
*/
class FSEventsWatcher extends _events.default {

@@ -102,5 +79,3 @@ static isSupported() {

symlinkCallback,
// $FlowFixMe[unclear-type] Add types for callback
endCallback,
// $FlowFixMe[unclear-type] Add types for callback
errorCallback,

@@ -150,5 +125,3 @@ ignored

trackPath,
// $FlowFixMe[method-unbinding] - Refactor
this.emit.bind(this, "ready"),
// $FlowFixMe[method-unbinding] - Refactor
this.emit.bind(this, "error"),

@@ -158,6 +131,2 @@ this.ignored

}
/**
* End watching.
*/
async close(callback) {

@@ -167,3 +136,2 @@ await this.fsEventsWatchStopper();

if (typeof callback === "function") {
// $FlowFixMe[extra-arg] - Is this a Node-style callback or as typed?
process.nextTick(callback.bind(null, null, true));

@@ -177,4 +145,2 @@ }

const type = (0, _common.typeFromStat)(stat);
// Ignore files of an unrecognized type
if (!type) {

@@ -210,4 +176,2 @@ return;

}
// Ignore files that aren't tracked and don't exist.
if (!this._tracked.has(filepath)) {

@@ -220,6 +184,2 @@ return;

}
/**
* Emit events.
*/
_emit(type, file, metadata) {

@@ -226,0 +186,0 @@ this.emit(type, file, this.root, metadata);

@@ -1,16 +0,1 @@

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
/**
* Originally vendored from https://github.com/amasad/sane/blob/64ff3a870c42e84f744086884bf55a4f9c22d376/src/node_watcher.js
*/
"use strict";

@@ -28,8 +13,2 @@

const ALL_EVENT = common.ALL_EVENT;
/**
* This setting delays all events. It suppresses 'change' events that
* immediately follow an 'add', and debounces successive 'change' events to
* only emit the latest.
*/
const DEBOUNCE_MS = 100;

@@ -63,17 +42,2 @@ module.exports = class NodeWatcher extends EventEmitter {

}
/**
* Register files that matches our globs to know what to type of event to
* emit in the future.
*
* Registry looks like the following:
*
* dirRegister => Map {
* dirpath => Map {
* filename => true
* }
* }
*
* Return false if ignored or already registered.
*/
_register(filepath, type) {

@@ -98,6 +62,2 @@ const dir = path.dirname(filepath);

}
/**
* Removes a file from the registry.
*/
_unregister(filepath) {

@@ -110,6 +70,2 @@ const dir = path.dirname(filepath);

}
/**
* Removes a dir from the registry.
*/
_unregisterDir(dirpath) {

@@ -120,6 +76,2 @@ if (this._dirRegistry[dirpath]) {

}
/**
* Checks if a file or directory exists in the registry.
*/
_registered(fullpath) {

@@ -133,6 +85,2 @@ const dir = path.dirname(fullpath);

}
/**
* Emit "error" event if it's not an ignorable event
*/
_checkedEmitError = (error) => {

@@ -143,6 +91,2 @@ if (!isIgnorableFileError(error)) {

};
/**
* Watch a directory.
*/
_watchdir = (dir) => {

@@ -166,6 +110,2 @@ if (this.watched[dir]) {

};
/**
* Stop watching a directory.
*/
_stopWatching(dir) {

@@ -177,6 +117,2 @@ if (this.watched[dir]) {

}
/**
* End watching.
*/
async close() {

@@ -186,8 +122,2 @@ Object.keys(this.watched).forEach((dir) => this._stopWatching(dir));

}
/**
* On some platforms, as pointed out on the fs docs (most likely just win32)
* the file argument might be missing from the fs event. Try to detect what
* change by detecting if something was deleted or the most recent file change.
*/
_detectChangedFile(dir, event, callback) {

@@ -226,6 +156,2 @@ if (!this._dirRegistry[dir]) {

}
/**
* Normalize fs events and pass it on to be processed.
*/
_normalizeChange(dir, event, file) {

@@ -246,6 +172,2 @@ if (!file) {

}
/**
* Process changes.
*/
async _processChange(dir, event, file) {

@@ -258,3 +180,2 @@ const fullPath = path.join(dir, file);

if (stat.isDirectory()) {
// win32 emits usless change events on dirs.
if (event === "change") {

@@ -338,10 +259,2 @@ return;

}
/**
* Emits the given event after debouncing, to 1) suppress 'change' events
* immediately following an 'add', and 2) to only emit the latest 'change'
* event when received in quick succession for a given file.
*
* See also note above for DEBOUNCE_MS.
*/
_emitEvent(type, file, metadata) {

@@ -351,4 +264,2 @@ const key = type + "-" + file;

if (type === CHANGE_EVENT && this._changeTimers.has(addKey)) {
// Ignore the change event that is immediately fired after an add event.
// (This happens on Linux).
return;

@@ -368,6 +279,2 @@ }

}
/**
* Actually emit the events
*/
_rawEmitEvent(eventType, file, metadata) {

@@ -381,16 +288,6 @@ this.emit(eventType, file, this.root, metadata);

};
/**
* Determine if a given FS error can be ignored
*/
function isIgnorableFileError(error) {
return (
error.code === "ENOENT" ||
// Workaround Windows EPERM on watched folder deletion, and when
// reading locked files (pending further writes or pending deletion).
// In such cases, we'll receive a subsequent event when the file is
// deleted or ready to read.
// https://github.com/facebook/metro/issues/1001
// https://github.com/nodejs/node-v0.x-archive/issues/4337
(error.code === "EPERM" && platform === "win32")
error.code === "ENOENT" || (error.code === "EPERM" && platform === "win32")
);
}

@@ -1,17 +0,1 @@

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
/**
* Originally vendored from
* https://github.com/amasad/sane/blob/64ff3a870c42e84f744086884bf55a4f9c22d376/src/utils/recrawl-warning-dedupe.js
*/
"use strict";

@@ -52,8 +36,5 @@

if (warning) {
// only keep the highest count, assume count to either stay the same or
// increase.
if (warning.count >= count) {
return true;
} else {
// update the existing warning to the latest (highest) count
warning.count = count;

@@ -60,0 +41,0 @@ return false;

@@ -58,13 +58,2 @@ "use strict";

}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
* @oncall react_native
*/
const debug = require("debug")("Metro:WatchmanWatcher");

@@ -76,6 +65,2 @@ const CHANGE_EVENT = common.CHANGE_EVENT;

const SUB_PREFIX = "metro-file-map";
/**
* Watches `dir`.
*/
class WatchmanWatcher extends _events.default {

@@ -87,4 +72,2 @@ #deferringStates = null;

this.root = _path.default.resolve(dir);
// Use a unique subscription name per process per watched directory
const watchKey = (0, _crypto.createHash)("md5")

@@ -94,11 +77,7 @@ .update(this.root)

const readablePath = this.root
.replace(/[\/\\]/g, "-") // \ and / to -
.replace(/[^\-\w]/g, ""); // Remove non-word/hyphen
.replace(/[\/\\]/g, "-")
.replace(/[^\-\w]/g, "");
this.subscriptionName = `${SUB_PREFIX}-${process.pid}-${readablePath}-${watchKey}`;
this._init();
}
/**
* Run the watchman `watch` command on the root and subscribe to changes.
*/
_init() {

@@ -155,4 +134,2 @@ if (this.client) {

};
// Make sure we honor the dot option if even we're not using globs.
if (self.globs.length === 0 && !self.dot) {

@@ -186,6 +163,2 @@ options.expression = [

}
/**
* Handles a change event coming from the subscription.
*/
_handleChangeEvent(resp) {

@@ -236,6 +209,2 @@ debug(

}
/**
* Handles a single change event record.
*/
_handleFileChange(changeDescriptor) {

@@ -263,4 +232,2 @@ const self = this;

);
// Ignore files of an unrecognized type
if (type != null && !(type === "f" || type === "d" || type === "l")) {

@@ -293,6 +260,3 @@ return;

);
if (
// Change event on dirs are mostly useless.
!(type === "d" && eventType === CHANGE_EVENT)
) {
if (!(type === "d" && eventType === CHANGE_EVENT)) {
const mtime = Number(mtime_ms);

@@ -307,6 +271,2 @@ self._emitEvent(eventType, relativePath, self.root, {

}
/**
* Dispatches the event.
*/
_emitEvent(eventType, filepath, root, changeMetadata) {

@@ -316,6 +276,2 @@ this.emit(eventType, filepath, root, changeMetadata);

}
/**
* Closes the watcher.
*/
async close() {

@@ -340,6 +296,2 @@ this.client.removeAllListeners();

}
/**
* Handles an error and returns true if exists.
*/
exports.default = WatchmanWatcher;

@@ -354,6 +306,2 @@ function handleError(emitter, error) {

}
/**
* Handles a warning in the watchman resp object.
*/
function handleWarning(resp) {

@@ -360,0 +308,0 @@ if ("warning" in resp) {

@@ -1,15 +0,1 @@

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
*/
/*::
import type {WorkerMessage, WorkerMetadata} from './flow-types';
*/
"use strict";

@@ -25,7 +11,5 @@

const PACKAGE_JSON = path.sep + "package.json";
let hasteImpl /*: ?{getHasteName: string => ?string} */ = null;
let hasteImplModulePath /*: ?string */ = null;
function getHasteImpl(
requestedModulePath /*: string */
) /*: {getHasteName: string => ?string} */ {
let hasteImpl = null;
let hasteImplModulePath = null;
function getHasteImpl(requestedModulePath) {
if (hasteImpl) {

@@ -38,19 +22,15 @@ if (requestedModulePath !== hasteImplModulePath) {

hasteImplModulePath = requestedModulePath;
// $FlowFixMe[unsupported-syntax] - dynamic require
hasteImpl = require(hasteImplModulePath);
return hasteImpl;
}
function sha1hex(content /*: string | Buffer */) /*: string */ {
function sha1hex(content) {
return createHash("sha1").update(content).digest("hex");
}
async function worker(
data /*: WorkerMessage */
) /*: Promise<WorkerMetadata> */ {
let content /*: ?Buffer */;
let dependencies /*: WorkerMetadata['dependencies'] */;
let id /*: WorkerMetadata['id'] */;
let module /*: WorkerMetadata['module'] */;
let sha1 /*: WorkerMetadata['sha1'] */;
let symlinkTarget /*: WorkerMetadata['symlinkTarget'] */;
async function worker(data) {
let content;
let dependencies;
let id;
let module;
let sha1;
let symlinkTarget;
const {

@@ -64,12 +44,9 @@ computeDependencies,

} = data;
const getContent = () =>
/*: Buffer */
{
if (content == null) {
content = fs.readFileSync(filePath);
}
return content;
};
const getContent = () => {
if (content == null) {
content = fs.readFileSync(filePath);
}
return content;
};
if (enableHastePackages && filePath.endsWith(PACKAGE_JSON)) {
// Process a package.json that is returned as a PACKAGE type with its name.
try {

@@ -89,3 +66,2 @@ const fileData = JSON.parse(getContent().toString());

) {
// Process a random file that is returned as a MODULE.
if (data.hasteImplModulePath != null) {

@@ -101,4 +77,3 @@ id = getHasteImpl(data.hasteImplModulePath).getHasteName(filePath);

data.dependencyExtractor != null
? // $FlowFixMe[unsupported-syntax] - dynamic require
require(data.dependencyExtractor).extract(
? require(data.dependencyExtractor).extract(
getContent().toString(),

@@ -112,4 +87,2 @@ filePath,

}
// If a SHA-1 is requested on update, compute it.
if (computeSha1) {

@@ -116,0 +89,0 @@ sha1 = sha1hex(getContent());

@@ -1,27 +0,5 @@

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
// This list is compiled after the MDN list of the most common MIME types (see
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/
// Complete_list_of_MIME_types).
//
// Only MIME types starting with "image/", "video/", "audio/" and "font/" are
// reflected in the list. Adding "application/" is too risky since some text
// file formats (like ".js" and ".json") have an "application/" MIME type.
//
// Feel free to add any extensions that cannot be a Haste module.
"use strict";
const extensions /*: $ReadOnlySet<string> */ = new Set([
// JSONs are never haste modules, except for "package.json", which is handled.
const extensions = new Set([
".json",
// Image extensions.
".bmp",

@@ -37,3 +15,2 @@ ".gif",

".webp",
// Video extensions.
".avi",

@@ -47,3 +24,2 @@ ".mp4",

".3g2",
// Audio extensions.
".aac",

@@ -57,3 +33,2 @@ ".midi",

".3g2",
// Font extensions.
".eot",

@@ -60,0 +35,0 @@ ".otf",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc