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.73.3 to 0.73.4

src/lib/DuplicateHasteCandidatesError.js

2

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

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

@@ -249,3 +249,3 @@ "use strict";

const {
data,
previousState,
extensions,

@@ -265,19 +265,20 @@ forceNodeFilesystemAPI,

const callback = (list) => {
const files = new Map();
const removedFiles = new Map(data.files);
list.forEach((fileData) => {
const changedFiles = new Map();
const removedFiles = new Map(previousState.files);
for (const fileData of list) {
const [filePath, mtime, size] = fileData;
const relativeFilePath = fastPath.relative(rootDir, filePath);
const existingFile = data.files.get(relativeFilePath);
const existingFile = previousState.files.get(relativeFilePath);
removedFiles.delete(relativeFilePath);
if (existingFile && existingFile[_constants.default.MTIME] === mtime) {
files.set(relativeFilePath, existingFile);
} else {
if (
existingFile == null ||
existingFile[_constants.default.MTIME] !== mtime
) {
// See ../constants.js; SHA-1 will always be null and fulfilled later.
files.set(relativeFilePath, ["", mtime, size, 0, "", null]);
changedFiles.set(relativeFilePath, ["", mtime, size, 0, "", null]);
}
}
removedFiles.delete(relativeFilePath);
});
data.files = files;
perfLogger === null || perfLogger === void 0

@@ -287,3 +288,3 @@ ? void 0

resolve({
hasteMap: data,
changedFiles,
removedFiles,

@@ -290,0 +291,0 @@ });

"use strict";
var _planQuery = require("./planQuery");
var _constants = _interopRequireDefault(require("../../constants"));

@@ -13,2 +11,4 @@

var _planQuery = require("./planQuery");
var _invariant = _interopRequireDefault(require("invariant"));

@@ -18,2 +18,4 @@

var _perf_hooks = require("perf_hooks");
function _getRequireWildcardCache(nodeInterop) {

@@ -91,9 +93,10 @@ if (typeof WeakMap !== "function") return null;

computeSha1,
data,
enableSymlinks,
extensions,
ignore,
onStatus,
perfLogger,
previousState,
rootDir,
roots,
perfLogger,
}) {

@@ -103,3 +106,3 @@ perfLogger === null || perfLogger === void 0

: perfLogger.point("watchmanCrawl_start");
const clocks = data.clocks;
const newClocks = new Map();
const client = new watchman.Client();

@@ -113,8 +116,18 @@ abortSignal === null || abortSignal === void 0

});
let didLogWatchmanWaitMessage = false; // $FlowFixMe[unclear-type] - Fix to use fb-watchman types
const cmd = async (command, ...args) => {
const cmd = async (
command, // $FlowFixMe[unclear-type] - Fix to use fb-watchman types
...args
) => {
let didLogWatchmanWaitMessage = false;
const startTime = _perf_hooks.performance.now();
const logWatchmanWaitMessage = () => {
didLogWatchmanWaitMessage = true;
console.warn(`Waiting for Watchman (${command})...`);
onStatus({
type: "watchman_slow_command",
timeElapsed: _perf_hooks.performance.now() - startTime,
command,
});
};

@@ -131,3 +144,3 @@

try {
return await new Promise(
const response = await new Promise(
(

@@ -141,5 +154,23 @@ resolve,

);
if ("warning" in response) {
onStatus({
type: "watchman_warning",
warning: response.warning,
command,
});
}
return response;
} finally {
// $FlowFixMe[incompatible-call] clearInterval / clearTimeout are interchangeable
clearInterval(intervalOrTimeoutId);
if (didLogWatchmanWaitMessage) {
onStatus({
type: "watchman_slow_command_complete",
timeElapsed: _perf_hooks.performance.now() - startTime,
command,
});
}
}

@@ -207,3 +238,5 @@ };

// system and import it, transforming the clock into a local clock.
const since = clocks.get(fastPath.relative(rootDir, root));
const since = previousState.clocks.get(
fastPath.relative(rootDir, root)
);
perfLogger === null || perfLogger === void 0

@@ -236,7 +269,3 @@ ? void 0

? void 0
: perfLogger.point(`watchmanCrawl/query_${index}_end`);
if ("warning" in response) {
console.warn("watchman warning: ", response.warning);
} // When a source-control query is used, we ignore the "is fresh"
: 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

@@ -270,3 +299,2 @@ // being incremental.

let files = data.files;
let removedFiles = new Map();

@@ -284,4 +312,3 @@ const changedFiles = new Map();

if (watchmanFileResults.isFresh) {
files = new Map();
removedFiles = new Map(data.files);
removedFiles = new Map(previousState.files);
isFresh = true;

@@ -350,3 +377,3 @@ }

const relativeFsRoot = fastPath.relative(rootDir, fsRoot);
clocks.set(
newClocks.set(
relativeFsRoot, // Ensure we persist only the local clock.

@@ -365,3 +392,3 @@ typeof response.clock === "string" ? response.clock : response.clock.clock

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 = previousState.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.

@@ -376,5 +403,4 @@

if (existingFileData) {
files.delete(relativeFilePath); // If watchman is not fresh, we will know what specific files were
// 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) {

@@ -385,2 +411,4 @@ removedFiles.set(relativeFilePath, existingFileData);

} else if (!ignore(filePath)) {
var _sha1hex;
const { mtime_ms, size } = fileData;

@@ -393,2 +421,10 @@ (0, _invariant.default)(

typeof mtime_ms === "number" ? mtime_ms : mtime_ms.toNumber();
if (
existingFileData &&
existingFileData[_constants.default.MTIME] === mtime
) {
continue;
}
let sha1hex = fileData["content.sha1hex"];

@@ -400,14 +436,20 @@

let nextData;
let nextData = [
"",
mtime,
size,
0,
"",
(_sha1hex = sha1hex) !== null && _sha1hex !== void 0
? _sha1hex
: null,
];
if (
existingFileData &&
existingFileData[_constants.default.MTIME] === mtime
) {
nextData = existingFileData;
} else if (
existingFileData &&
sha1hex != null &&
existingFileData[_constants.default.SHA1] === sha1hex
) {
// Special case - file touched but not modified, so we can reuse the
// metadata and just update mtime.
nextData = [

@@ -421,19 +463,4 @@ existingFileData[0],

];
} else {
var _sha1hex;
// See ../constants.ts
nextData = [
"",
mtime,
size,
0,
"",
(_sha1hex = sha1hex) !== null && _sha1hex !== void 0
? _sha1hex
: null,
];
}
files.set(relativeFilePath, nextData);
changedFiles.set(relativeFilePath, nextData);

@@ -444,3 +471,2 @@ }

data.files = files;
perfLogger === null || perfLogger === void 0

@@ -452,12 +478,7 @@ ? void 0

: perfLogger.point("watchmanCrawl_end");
if (didLogWatchmanWaitMessage) {
console.warn("Watchman query finished.");
}
return {
changedFiles: isFresh ? undefined : changedFiles,
hasteMap: data,
changedFiles,
removedFiles,
clocks: newClocks,
};
};

@@ -18,6 +18,9 @@ "use strict";

});
exports.DuplicateError =
exports.default =
exports.DuplicateHasteCandidatesError =
void 0;
Object.defineProperty(exports, "DuplicateHasteCandidatesError", {
enumerable: true,
get: function () {
return _DuplicateHasteCandidatesError.DuplicateHasteCandidatesError;
},
});
exports.DuplicateError = exports.default = void 0;

@@ -50,6 +53,2 @@ var _DiskCacheManager = require("./cache/DiskCacheManager");

var _rootRelativeCacheKeys = _interopRequireDefault(
require("./lib/rootRelativeCacheKeys")
);
var _ModuleMap = _interopRequireDefault(require("./ModuleMap"));

@@ -73,2 +72,8 @@

var _perf_hooks = require("perf_hooks");
var _nullthrows = _interopRequireDefault(require("nullthrows"));
var _DuplicateHasteCandidatesError = require("./lib/DuplicateHasteCandidatesError");
function _getRequireWildcardCache(nodeInterop) {

@@ -133,5 +138,2 @@ if (typeof WeakMap !== "function") return null;

// $FlowFixMe[untyped-import] - this is a polyfill
const DuplicateHasteCandidatesError =
_ModuleMap.default.DuplicateHasteCandidatesError;
exports.DuplicateHasteCandidatesError = DuplicateHasteCandidatesError;
// This should be bumped whenever a code change to `metro-file-map` itself

@@ -239,15 +241,24 @@ // would cause a change to the cache data structure and/or content (for a given

constructor(options) {
var _options$dependencyEx, _options$watchmanDefe, _this$_options$perfLo;
var _options$dependencyEx, _options$watchmanDefe, _this$_startupPerfLog2;
if (options.perfLogger) {
var _options$perfLogger;
super();
(_options$perfLogger = options.perfLogger) === null ||
_options$perfLogger === void 0
if (options.perfLoggerFactory) {
var _options$perfLoggerFa, _options$perfLoggerFa2, _this$_startupPerfLog;
this._startupPerfLogger =
(_options$perfLoggerFa =
(_options$perfLoggerFa2 = options.perfLoggerFactory) === null ||
_options$perfLoggerFa2 === void 0
? void 0
: _options$perfLoggerFa2.call(options).subSpan("hasteMap")) !==
null && _options$perfLoggerFa !== void 0
? _options$perfLoggerFa
: null;
(_this$_startupPerfLog = this._startupPerfLogger) === null ||
_this$_startupPerfLog === void 0
? void 0
: _options$perfLogger.point("constructor_start");
}
: _this$_startupPerfLog.point("constructor_start");
} // Add VCS_DIRECTORIES to provided ignorePattern
super(); // Add VCS_DIRECTORIES to provided ignorePattern
let ignorePattern;

@@ -303,3 +314,3 @@

maxWorkers: options.maxWorkers,
perfLogger: options.perfLogger,
perfLoggerFactory: options.perfLoggerFactory,
resetCache: options.resetCache,

@@ -332,84 +343,68 @@ throwOnModuleCollision: !!options.throwOnModuleCollision,

this._worker = null;
(_this$_options$perfLo = this._options.perfLogger) === null ||
_this$_options$perfLo === void 0
(_this$_startupPerfLog2 = this._startupPerfLogger) === null ||
_this$_startupPerfLog2 === void 0
? void 0
: _this$_options$perfLo.point("constructor_end");
: _this$_startupPerfLog2.point("constructor_end");
this._crawlerAbortController = new _abortController.default();
this._changeID = 0;
}
static getCacheFilePath(cacheDirectory, cacheFilePrefix, buildParameters) {
const { rootDirHash, relativeConfigHash } = (0,
_rootRelativeCacheKeys.default)(buildParameters);
return path.join(
cacheDirectory,
`${cacheFilePrefix}-${rootDirHash}-${relativeConfigHash}`
);
}
static getModuleMapFromJSON(json) {
return _ModuleMap.default.fromJSON(json);
}
getCacheFilePath() {
if (!(this._cacheManager instanceof _DiskCacheManager.DiskCacheManager)) {
throw new Error(
"metro-file-map: getCacheFilePath is only supported when using DiskCacheManager"
);
}
return this._cacheManager.getCacheFilePath();
}
build() {
var _this$_options$perfLo2;
var _this$_startupPerfLog3;
(_this$_options$perfLo2 = this._options.perfLogger) === null ||
_this$_options$perfLo2 === void 0
(_this$_startupPerfLog3 = this._startupPerfLogger) === null ||
_this$_startupPerfLog3 === void 0
? void 0
: _this$_options$perfLo2.point("build_start");
: _this$_startupPerfLog3.point("build_start");
if (!this._buildPromise) {
this._buildPromise = (async () => {
var _data$changedFiles, _data$removedFiles;
let initialData;
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.
try {
initialData =
this._options.resetCache === true
? this._createEmptyMap()
: await this.read();
} catch {
initialData = this._createEmptyMap();
}
let hasteMap;
const fileDelta = await this._buildFileDelta({
files: initialData.files,
clocks: initialData.clocks,
});
let data;
if (
data.changedFiles == null ||
data.changedFiles.size > 0 ||
data.removedFiles.size > 0
fileDelta.changedFiles.size > 0 ||
fileDelta.removedFiles.size > 0
) {
hasteMap = await this._buildHasteMap(data);
data = await this._applyFileDelta(initialData, fileDelta);
} else if (fileDelta.clocks) {
data = { ...initialData, clocks: fileDelta.clocks };
} else {
hasteMap = data.hasteMap;
data = initialData;
}
const snapshot = (0, _deepCloneInternalData.default)(data);
await this._persist(
hasteMap,
(_data$changedFiles = data.changedFiles) !== null &&
_data$changedFiles !== void 0
? _data$changedFiles
: new Map(),
(_data$removedFiles = data.removedFiles) !== null &&
_data$removedFiles !== void 0
? _data$removedFiles
: new Map()
snapshot,
fileDelta.changedFiles,
fileDelta.removedFiles
);
const rootDir = this._options.rootDir;
const hasteFS = new _HasteFS.default({
files: hasteMap.files,
const snapshotFS = new _HasteFS.default({
files: snapshot.files,
rootDir,
});
const moduleMap = new _ModuleMap.default({
duplicates: hasteMap.duplicates,
map: hasteMap.map,
mocks: hasteMap.mocks,
duplicates: snapshot.duplicates,
map: snapshot.map,
mocks: snapshot.mocks,
rootDir,
});
await this._watch(hasteMap);
await this._watch(data);
return {
hasteFS,
snapshotFS,
moduleMap,

@@ -421,8 +416,8 @@ };

return this._buildPromise.then((result) => {
var _this$_options$perfLo3;
var _this$_startupPerfLog4;
(_this$_options$perfLo3 = this._options.perfLogger) === null ||
_this$_options$perfLo3 === void 0
(_this$_startupPerfLog4 = this._startupPerfLogger) === null ||
_this$_startupPerfLog4 === void 0
? void 0
: _this$_options$perfLo3.point("build_end");
: _this$_startupPerfLog4.point("build_end");
return result;

@@ -436,9 +431,9 @@ });

async read() {
var _this$_options$perfLo4, _data, _this$_options$perfLo6;
var _this$_startupPerfLog5, _data, _this$_startupPerfLog7;
let data;
(_this$_options$perfLo4 = this._options.perfLogger) === null ||
_this$_options$perfLo4 === void 0
(_this$_startupPerfLog5 = this._startupPerfLogger) === null ||
_this$_startupPerfLog5 === void 0
? void 0
: _this$_options$perfLo4.point("read_start");
: _this$_startupPerfLog5.point("read_start");

@@ -448,3 +443,3 @@ try {

} catch (e) {
var _this$_options$perfLo5;
var _this$_startupPerfLog6;

@@ -456,6 +451,6 @@ this._console.warn(

(_this$_options$perfLo5 = this._options.perfLogger) === null ||
_this$_options$perfLo5 === void 0
(_this$_startupPerfLog6 = this._startupPerfLogger) === null ||
_this$_startupPerfLog6 === void 0
? void 0
: _this$_options$perfLo5.annotate({
: _this$_startupPerfLog6.annotate({
string: {

@@ -471,18 +466,8 @@ cacheReadError: e.toString(),

: this._createEmptyMap();
(_this$_options$perfLo6 = this._options.perfLogger) === null ||
_this$_options$perfLo6 === void 0
(_this$_startupPerfLog7 = this._startupPerfLogger) === null ||
_this$_startupPerfLog7 === void 0
? void 0
: _this$_options$perfLo6.point("read_end");
: _this$_startupPerfLog7.point("read_end");
return data;
}
async readModuleMap() {
const data = await this.read();
return new _ModuleMap.default({
duplicates: data.duplicates,
map: data.map,
mocks: data.mocks,
rootDir: this._options.rootDir,
});
}
/**

@@ -492,20 +477,9 @@ * 2. crawl the file system.

async _buildFileMap() {
var _this$_options$perfLo7;
async _buildFileDelta(previousState) {
var _this$_startupPerfLog8;
let hasteMap;
(_this$_options$perfLo7 = this._options.perfLogger) === null ||
_this$_options$perfLo7 === void 0
(_this$_startupPerfLog8 = this._startupPerfLogger) === null ||
_this$_startupPerfLog8 === void 0
? void 0
: _this$_options$perfLo7.point("buildFileMap_start");
try {
hasteMap =
this._options.resetCache === true
? this._createEmptyMap()
: await this.read();
} catch {
hasteMap = this._createEmptyMap();
}
: _this$_startupPerfLog8.point("buildFileDelta_start");
const {

@@ -517,3 +491,2 @@ computeSha1,

ignorePattern,
perfLogger,
roots,

@@ -534,4 +507,4 @@ rootDir,

ignorePattern,
initialData: hasteMap,
perfLogger,
perfLogger: this._startupPerfLogger,
previousState,
roots,

@@ -543,9 +516,11 @@ rootDir,

});
return this._watcher.crawl().then((result) => {
var _this$_options$perfLo8;
const watcher = this._watcher;
watcher.on("status", (status) => this.emit("status", status));
return watcher.crawl().then((result) => {
var _this$_startupPerfLog9;
(_this$_options$perfLo8 = this._options.perfLogger) === null ||
_this$_options$perfLo8 === void 0
(_this$_startupPerfLog9 = this._startupPerfLogger) === null ||
_this$_startupPerfLog9 === void 0
? void 0
: _this$_options$perfLo8.point("buildFileMap_end");
: _this$_startupPerfLog9.point("buildFileDelta_end");
return result;

@@ -798,32 +773,18 @@ });

_buildHasteMap(data) {
var _this$_options$perfLo9;
_applyFileDelta(data, delta) {
var _this$_startupPerfLog10;
(_this$_options$perfLo9 = this._options.perfLogger) === null ||
_this$_options$perfLo9 === void 0
(_this$_startupPerfLog10 = this._startupPerfLogger) === null ||
_this$_startupPerfLog10 === void 0
? void 0
: _this$_options$perfLo9.point("buildHasteMap_start");
const { removedFiles, changedFiles, hasteMap } = data; // If any files were removed or we did not track what files changed, process
// every file looking for changes. Otherwise, process only changed files.
: _this$_startupPerfLog10.point("applyFileDelta_start");
const { changedFiles, removedFiles, clocks } = delta;
data.clocks = clocks !== null && clocks !== void 0 ? clocks : new Map();
let map;
let mocks;
let filesToProcess;
if (changedFiles == null || removedFiles.size) {
map = new Map();
mocks = new Map();
filesToProcess = hasteMap.files;
} else {
map = hasteMap.map;
mocks = hasteMap.mocks;
filesToProcess = changedFiles;
for (const [relativeFilePath] of removedFiles) {
this._removeIfExists(data, relativeFilePath);
}
for (const [relativeFilePath, fileMetadata] of removedFiles) {
this._recoverDuplicates(
hasteMap,
relativeFilePath,
fileMetadata[_constants.default.ID]
);
for (const [relativeFilePath, fileMetadata] of changedFiles) {
data.files.set(relativeFilePath, fileMetadata);
}

@@ -833,3 +794,3 @@

for (const relativeFilePath of filesToProcess.keys()) {
for (const relativeFilePath of changedFiles.keys()) {
if (

@@ -847,3 +808,3 @@ this._options.skipPackageJson &&

const promise = this._processFile(hasteMap, map, mocks, filePath);
const promise = this._processFile(data, data.map, data.mocks, filePath);

@@ -857,13 +818,11 @@ if (promise) {

() => {
var _this$_options$perfLo10;
var _this$_startupPerfLog11;
this._cleanup();
hasteMap.map = map;
hasteMap.mocks = mocks;
(_this$_options$perfLo10 = this._options.perfLogger) === null ||
_this$_options$perfLo10 === void 0
(_this$_startupPerfLog11 = this._startupPerfLogger) === null ||
_this$_startupPerfLog11 === void 0
? void 0
: _this$_options$perfLo10.point("buildHasteMap_end");
return hasteMap;
: _this$_startupPerfLog11.point("applyFileDelta_end");
return data;
},

@@ -891,10 +850,9 @@ (error) => {

async _persist(hasteMap, changed, removed) {
var _this$_options$perfLo11, _this$_options$perfLo12;
async _persist(snapshot, changed, removed) {
var _this$_startupPerfLog12, _this$_startupPerfLog13;
(_this$_options$perfLo11 = this._options.perfLogger) === null ||
_this$_options$perfLo11 === void 0
(_this$_startupPerfLog12 = this._startupPerfLogger) === null ||
_this$_startupPerfLog12 === void 0
? void 0
: _this$_options$perfLo11.point("persist_start");
const snapshot = (0, _deepCloneInternalData.default)(hasteMap);
: _this$_startupPerfLog12.point("persist_start");
await this._cacheManager.write(snapshot, {

@@ -904,6 +862,6 @@ changed,

});
(_this$_options$perfLo12 = this._options.perfLogger) === null ||
_this$_options$perfLo12 === void 0
(_this$_startupPerfLog13 = this._startupPerfLogger) === null ||
_this$_startupPerfLog13 === void 0
? void 0
: _this$_options$perfLo12.point("persist_end");
: _this$_startupPerfLog13.point("persist_end");
}

@@ -932,2 +890,67 @@ /**

}
_getSnapshot(data) {
const rootDir = this._options.rootDir;
return {
snapshotFS: new _HasteFS.default({
files: new Map(data.files),
rootDir,
}),
moduleMap: new _ModuleMap.default({
duplicates: new Map(data.duplicates),
map: new Map(data.map),
mocks: new Map(data.mocks),
rootDir,
}),
};
}
_removeIfExists(data, relativeFilePath) {
const fileMetadata = data.files.get(relativeFilePath);
if (!fileMetadata) {
return;
}
const moduleName = fileMetadata[_constants.default.ID];
const platform =
(0, _getPlatformExtension.default)(
relativeFilePath,
this._options.platforms
) || _constants.default.GENERIC_PLATFORM;
data.files.delete(relativeFilePath);
let moduleMap = data.map.get(moduleName);
if (moduleMap != null) {
// We are forced to copy the object because metro-file-map exposes
// the map as an immutable entity.
moduleMap = Object.assign(Object.create(null), moduleMap);
delete moduleMap[platform];
if (Object.keys(moduleMap).length === 0) {
data.map.delete(moduleName);
} else {
data.map.set(moduleName, moduleMap);
}
}
if (this._options.mocksPattern) {
const absoluteFilePath = path.join(
this._options.rootDir,
(0, _normalizePathSep.default)(relativeFilePath)
);
if (
this._options.mocksPattern &&
this._options.mocksPattern.test(absoluteFilePath)
) {
const mockName = (0, _getMockName.default)(absoluteFilePath);
data.mocks.delete(mockName);
}
}
this._recoverDuplicates(data, relativeFilePath, moduleName);
}
/**

@@ -937,17 +960,17 @@ * Watch mode

async _watch(hasteMap) {
var _this$_options$perfLo13, _this$_options$perfLo15;
async _watch(data) {
var _this$_startupPerfLog14, _this$_startupPerfLog16;
(_this$_options$perfLo13 = this._options.perfLogger) === null ||
_this$_options$perfLo13 === void 0
(_this$_startupPerfLog14 = this._startupPerfLogger) === null ||
_this$_startupPerfLog14 === void 0
? void 0
: _this$_options$perfLo13.point("watch_start");
: _this$_startupPerfLog14.point("watch_start");
if (!this._options.watch) {
var _this$_options$perfLo14;
var _this$_startupPerfLog15;
(_this$_options$perfLo14 = this._options.perfLogger) === null ||
_this$_options$perfLo14 === void 0
(_this$_startupPerfLog15 = this._startupPerfLogger) === null ||
_this$_startupPerfLog15 === void 0
? void 0
: _this$_options$perfLo14.point("watch_end");
: _this$_startupPerfLog15.point("watch_end");
return;

@@ -962,24 +985,41 @@ } // In watch mode, we'll only warn about module collisions and we'll retain

let changeQueue = Promise.resolve();
let eventsQueue = []; // We only need to copy the entire haste map once on every "frame".
let eventsQueue = [];
let eventStartTimestamp = null;
let mustCopy = true;
const emitChange = () => {
if (eventsQueue.length) {
mustCopy = true;
var _this$_options$perfLo, _this$_options;
const hmrPerfLogger =
(_this$_options$perfLo = (_this$_options = this._options)
.perfLoggerFactory) === null || _this$_options$perfLo === void 0
? void 0
: _this$_options$perfLo.call(_this$_options, "HMR", {
key: this._getNextChangeID(),
});
if (hmrPerfLogger != null) {
hmrPerfLogger.start({
timestamp: (0, _nullthrows.default)(eventStartTimestamp),
});
hmrPerfLogger.point("waitingForChangeInterval_start", {
timestamp: (0, _nullthrows.default)(eventStartTimestamp),
});
hmrPerfLogger.point("waitingForChangeInterval_end");
hmrPerfLogger.annotate({
int: {
eventsQueueLength: eventsQueue.length,
},
});
hmrPerfLogger.point("fileChange_start");
}
const changeEvent = {
logger: hmrPerfLogger,
eventsQueue,
hasteFS: new _HasteFS.default({
files: hasteMap.files,
rootDir,
}),
moduleMap: new _ModuleMap.default({
duplicates: hasteMap.duplicates,
map: hasteMap.map,
mocks: hasteMap.mocks,
rootDir,
}),
...this._getSnapshot(data),
};
this.emit("change", changeEvent);
eventsQueue = [];
eventStartTimestamp = null;
}

@@ -1003,3 +1043,3 @@ };

const relativeFilePath = fastPath.relative(rootDir, absoluteFilePath);
const fileMetadata = hasteMap.files.get(relativeFilePath); // The file has been accessed, not modified
const fileMetadata = data.files.get(relativeFilePath); // The file has been accessed, not modified

@@ -1015,2 +1055,7 @@ if (

if (eventStartTimestamp == null) {
eventStartTimestamp =
_perf_hooks.performance.timeOrigin + _perf_hooks.performance.now();
}
changeQueue = changeQueue

@@ -1033,14 +1078,2 @@ .then(() => {

if (mustCopy) {
mustCopy = false; // $FlowFixMe[reassign-const] - Refactor this
hasteMap = {
clocks: new Map(hasteMap.clocks),
duplicates: new Map(hasteMap.duplicates),
files: new Map(hasteMap.files),
map: new Map(hasteMap.map),
mocks: new Map(hasteMap.mocks),
};
}
const add = () => {

@@ -1055,38 +1088,6 @@ eventsQueue.push({

const fileMetadata = hasteMap.files.get(relativeFilePath); // If it's not an addition, delete the file and all its metadata
const fileMetadata = data.files.get(relativeFilePath); // If it's not an addition, delete the file and all its metadata
if (fileMetadata != null) {
const moduleName = fileMetadata[_constants.default.ID];
const platform =
(0, _getPlatformExtension.default)(
absoluteFilePath,
this._options.platforms
) || _constants.default.GENERIC_PLATFORM;
hasteMap.files.delete(relativeFilePath);
let moduleMap = hasteMap.map.get(moduleName);
if (moduleMap != null) {
// We are forced to copy the object because metro-file-map exposes
// the map as an immutable entity.
moduleMap = Object.assign(Object.create(null), moduleMap);
delete moduleMap[platform];
if (Object.keys(moduleMap).length === 0) {
hasteMap.map.delete(moduleName);
} else {
hasteMap.map.set(moduleName, moduleMap);
}
}
if (
this._options.mocksPattern &&
this._options.mocksPattern.test(absoluteFilePath)
) {
const mockName = (0, _getMockName.default)(absoluteFilePath);
hasteMap.mocks.delete(mockName);
}
this._recoverDuplicates(hasteMap, relativeFilePath, moduleName);
this._removeIfExists(data, relativeFilePath);
} // If the file was added or changed,

@@ -1108,8 +1109,8 @@ // parse it and update the haste map.

];
hasteMap.files.set(relativeFilePath, fileMetadata);
data.files.set(relativeFilePath, fileMetadata);
const promise = this._processFile(
hasteMap,
hasteMap.map,
hasteMap.mocks,
data,
data.map,
data.mocks,
absoluteFilePath,

@@ -1146,3 +1147,3 @@ {

this._watcher != null,
"Expected _watcher to have been initialised by _buildFileMap"
"Expected _watcher to have been initialised by build()"
);

@@ -1171,6 +1172,6 @@ await this._watcher.watch(onChange);

(_this$_options$perfLo15 = this._options.perfLogger) === null ||
_this$_options$perfLo15 === void 0
(_this$_startupPerfLog16 = this._startupPerfLogger) === null ||
_this$_startupPerfLog16 === void 0
? void 0
: _this$_options$perfLo15.point("watch_end");
: _this$_startupPerfLog16.point("watch_end");
}

@@ -1281,10 +1282,10 @@ /**

.catch((e) => {
var _this$_options$perfLo16, _e$message;
var _this$_startupPerfLog17, _e$message;
// TODO: Advise people to either install Watchman or set
// `useWatchman: false` here?
(_this$_options$perfLo16 = this._options.perfLogger) === null ||
_this$_options$perfLo16 === void 0
(_this$_startupPerfLog17 = this._startupPerfLogger) === null ||
_this$_startupPerfLog17 === void 0
? void 0
: _this$_options$perfLo16.annotate({
: _this$_startupPerfLog17.annotate({
string: {

@@ -1316,2 +1317,10 @@ watchmanFailedCapabilityCheck:

_getNextChangeID() {
if (this._changeID >= Number.MAX_SAFE_INTEGER) {
this._changeID = 0;
}
return ++this._changeID;
}
static H = _constants.default;

@@ -1318,0 +1327,0 @@ }

@@ -10,2 +10,4 @@ "use strict";

var _DuplicateHasteCandidatesError = require("./lib/DuplicateHasteCandidatesError");
var fastPath = _interopRequireWildcard(require("./lib/fast_path"));

@@ -73,28 +75,2 @@

class ModuleMap {
// $FlowFixMe[unclear-type] - Refactor away this function
static _mapToArrayRecursive(map) {
let arr = Array.from(map);
if (arr[0] && arr[0][1] instanceof Map) {
arr = arr.map(
// $FlowFixMe[unclear-type] - Refactor away this function
(el) => [el[0], this._mapToArrayRecursive(el[1])]
);
}
return arr;
}
static _mapFromArrayRecursive(arr) { // $FlowFixMe[unclear-type] - Refactor away this function
if (arr[0] && Array.isArray(arr[1])) {
// $FlowFixMe[reassign-const] - Refactor away this function
arr = arr.map((el) => [
el[0], // $FlowFixMe[unclear-type] - Refactor away this function
this._mapFromArrayRecursive(el[1]), // $FlowFixMe[unclear-type] - Refactor away this function
]);
}
return new Map(arr);
}
constructor(raw) {

@@ -134,3 +110,4 @@ this._raw = raw;

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

@@ -145,26 +122,2 @@ getRawModuleMap() {

}
toJSON() {
if (!this._json) {
this._json = {
duplicates: ModuleMap._mapToArrayRecursive(this._raw.duplicates),
map: Array.from(this._raw.map),
mocks: Array.from(this._raw.mocks),
rootDir: this._raw.rootDir,
};
}
return this._json;
}
static fromJSON(serializableModuleMap) {
return new ModuleMap({
duplicates: ModuleMap._mapFromArrayRecursive(
serializableModuleMap.duplicates
),
map: new Map(serializableModuleMap.map),
mocks: new Map(serializableModuleMap.mocks),
rootDir: serializableModuleMap.rootDir,
});
}
/**

@@ -236,3 +189,3 @@ * When looking up a module's data, we walk through each eligible platform for

throw new DuplicateHasteCandidatesError(
throw new _DuplicateHasteCandidatesError.DuplicateHasteCandidatesError(
name,

@@ -256,47 +209,1 @@ platform,

exports.default = ModuleMap;
class DuplicateHasteCandidatesError extends Error {
constructor(name, platform, supportsNativePlatform, duplicatesSet) {
const platformMessage = getPlatformMessage(platform);
super(
`The name \`${name}\` was looked up in the Haste module map. It ` +
"cannot be resolved, because there exists several different " +
"files, or packages, that provide a module for " +
`that particular name and platform. ${platformMessage} You must ` +
"delete or exclude files until there remains only one of these:\n\n" +
Array.from(duplicatesSet)
.map(
([dupFilePath, dupFileType]) =>
` * \`${dupFilePath}\` (${getTypeMessage(dupFileType)})\n`
)
.sort()
.join("")
);
this.hasteName = name;
this.platform = platform;
this.supportsNativePlatform = supportsNativePlatform;
this.duplicatesSet = duplicatesSet;
}
}
function getPlatformMessage(platform) {
if (platform === _constants.default.GENERIC_PLATFORM) {
return "The platform is generic (no extension).";
}
return `The platform extension is \`${platform}\`.`;
}
function getTypeMessage(type) {
switch (type) {
case _constants.default.MODULE:
return "module";
case _constants.default.PACKAGE:
return "package";
}
return "unknown";
}
ModuleMap.DuplicateHasteCandidatesError = DuplicateHasteCandidatesError;

@@ -28,2 +28,4 @@ "use strict";

var _events = _interopRequireDefault(require("events"));
var _perf_hooks = require("perf_hooks");

@@ -94,3 +96,3 @@

class Watcher {
class Watcher extends _events.default {
_backends = [];

@@ -101,2 +103,3 @@ _nextHealthCheckId = 0;

constructor(options) {
super();
this._options = options;

@@ -120,6 +123,6 @@ this._instanceId = nextInstanceId++;

const crawl = options.useWatchman ? _watchman.default : _node.default;
let crawler = crawl === _watchman.default ? "watchman" : "node";
const crawlerOptions = {
abortSignal: options.abortSignal,
computeSha1: options.computeSha1,
data: options.initialData,
enableSymlinks: options.enableSymlinks,

@@ -129,3 +132,7 @@ extensions: options.extensions,

ignore,
onStatus: (status) => {
this.emit("status", status);
},
perfLogger: options.perfLogger,
previousState: options.previousState,
rootDir: options.rootDir,

@@ -137,2 +144,3 @@ roots: options.roots,

if (crawl === _watchman.default) {
crawler = "node";
options.console.warn(

@@ -159,5 +167,17 @@ "metro-file-map: Watchman crawl failed. Retrying once with node " +

const logEnd = (result) => {
var _this$_options$perfLo2;
const logEnd = (delta) => {
var _delta$clocks$size, _delta$clocks, _this$_options$perfLo2;
debug(
'Crawler "%s" returned %d added/modified, %d removed, %d clock(s).',
crawler,
delta.changedFiles.size,
delta.removedFiles.size,
(_delta$clocks$size =
(_delta$clocks = delta.clocks) === null || _delta$clocks === void 0
? void 0
: _delta$clocks.size) !== null && _delta$clocks$size !== void 0
? _delta$clocks$size
: 0
);
(_this$_options$perfLo2 = this._options.perfLogger) === null ||

@@ -167,5 +187,7 @@ _this$_options$perfLo2 === void 0

: _this$_options$perfLo2.point("crawl_end");
return result;
return delta;
};
debug('Beginning crawl with "%s".', crawler);
try {

@@ -172,0 +194,0 @@ return crawl(crawlerOptions).catch(retry).then(logEnd);

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