metro-file-map 0.83.4 → 0.83.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/package.json +3 -2
  2. package/src/Watcher.d.ts +74 -0
  3. package/src/Watcher.js +68 -48
  4. package/src/Watcher.js.flow +84 -51
  5. package/src/cache/DiskCacheManager.d.ts +49 -0
  6. package/src/cache/DiskCacheManager.js +1 -5
  7. package/src/constants.d.ts +22 -0
  8. package/src/crawlers/node/hasNativeFindSupport.d.ts +19 -0
  9. package/src/crawlers/node/index.d.ts +21 -0
  10. package/src/crawlers/node/index.js +6 -10
  11. package/src/crawlers/node/index.js.flow +8 -6
  12. package/src/crawlers/watchman/index.d.ts +23 -0
  13. package/src/crawlers/watchman/index.js +2 -9
  14. package/src/crawlers/watchman/index.js.flow +2 -6
  15. package/src/flow-types.d.ts +460 -0
  16. package/src/flow-types.js.flow +89 -29
  17. package/src/index.d.ts +182 -0
  18. package/src/index.js +148 -132
  19. package/src/index.js.flow +200 -155
  20. package/src/lib/FileProcessor.d.ts +60 -0
  21. package/src/lib/FileProcessor.js +1 -5
  22. package/src/lib/FileSystemChangeAggregator.d.ts +40 -0
  23. package/src/lib/FileSystemChangeAggregator.js +89 -0
  24. package/src/lib/FileSystemChangeAggregator.js.flow +143 -0
  25. package/src/lib/RootPathUtils.d.ts +30 -0
  26. package/src/lib/RootPathUtils.js +2 -9
  27. package/src/lib/TreeFS.d.ts +174 -0
  28. package/src/lib/TreeFS.js +68 -21
  29. package/src/lib/TreeFS.js.flow +89 -16
  30. package/src/lib/checkWatchmanCapabilities.d.ts +20 -0
  31. package/src/lib/normalizePathSeparatorsToPosix.d.ts +20 -0
  32. package/src/lib/normalizePathSeparatorsToPosix.js +1 -4
  33. package/src/lib/normalizePathSeparatorsToSystem.d.ts +20 -0
  34. package/src/lib/normalizePathSeparatorsToSystem.js +1 -4
  35. package/src/lib/rootRelativeCacheKeys.d.ts +24 -0
  36. package/src/lib/rootRelativeCacheKeys.js +1 -5
  37. package/src/lib/sorting.d.ts +23 -0
  38. package/src/plugins/DependencyPlugin.d.ts +52 -0
  39. package/src/plugins/DependencyPlugin.js +1 -3
  40. package/src/plugins/DependencyPlugin.js.flow +1 -16
  41. package/src/plugins/HastePlugin.d.ts +69 -0
  42. package/src/plugins/HastePlugin.js +12 -16
  43. package/src/plugins/HastePlugin.js.flow +12 -12
  44. package/src/plugins/MockPlugin.d.ts +48 -0
  45. package/src/plugins/MockPlugin.js +18 -25
  46. package/src/plugins/MockPlugin.js.flow +18 -22
  47. package/src/plugins/dependencies/dependencyExtractor.d.ts +1 -1
  48. package/src/plugins/haste/DuplicateHasteCandidatesError.d.ts +31 -0
  49. package/src/plugins/haste/DuplicateHasteCandidatesError.js +1 -5
  50. package/src/plugins/haste/HasteConflictsError.d.ts +23 -0
  51. package/src/plugins/haste/HasteConflictsError.js +1 -5
  52. package/src/plugins/haste/computeConflicts.d.ts +34 -0
  53. package/src/plugins/haste/computeConflicts.js +1 -5
  54. package/src/plugins/haste/getPlatformExtension.d.ts +21 -0
  55. package/src/plugins/mocks/getMockName.d.ts +20 -0
  56. package/src/plugins/mocks/getMockName.js +1 -4
  57. package/src/watchers/AbstractWatcher.d.ts +41 -0
  58. package/src/watchers/AbstractWatcher.js +2 -9
  59. package/src/watchers/FallbackWatcher.d.ts +28 -0
  60. package/src/watchers/FallbackWatcher.js +21 -12
  61. package/src/watchers/FallbackWatcher.js.flow +28 -5
  62. package/src/watchers/NativeWatcher.d.ts +55 -0
  63. package/src/watchers/NativeWatcher.js +28 -9
  64. package/src/watchers/NativeWatcher.js.flow +33 -6
  65. package/src/watchers/RecrawlWarning.d.ts +32 -0
  66. package/src/watchers/WatchmanWatcher.d.ts +34 -0
  67. package/src/watchers/WatchmanWatcher.js +2 -9
  68. package/src/watchers/common.d.ts +70 -0
  69. package/src/watchers/common.js +7 -6
  70. package/src/watchers/common.js.flow +1 -0
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @noformat
8
+ * @generated SignedSource<<b68c5620efd3f5bec83279059d0d1b4e>>
9
+ *
10
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
11
+ * Original file: packages/metro-file-map/src/watchers/NativeWatcher.js
12
+ * To regenerate, run:
13
+ * js1 build metro-ts-defs (internal) OR
14
+ * yarn run build-ts-defs (OSS)
15
+ */
16
+
17
+ import {AbstractWatcher} from './AbstractWatcher';
18
+ /**
19
+ * NativeWatcher uses Node's native fs.watch API with recursive: true.
20
+ *
21
+ * Supported on macOS (and potentially Windows), because both natively have a
22
+ * concept of recurisve watching, via FSEvents and ReadDirectoryChangesW
23
+ * respectively. Notably Linux lacks this capability at the OS level.
24
+ *
25
+ * Node.js has at times supported the `recursive` option to fs.watch on Linux
26
+ * by walking the directory tree and creating a watcher on each directory, but
27
+ * this fits poorly with the synchronous `watch` API - either it must block for
28
+ * arbitrarily large IO, or it may drop changes after `watch` returns. See:
29
+ * https://github.com/nodejs/node/issues/48437
30
+ *
31
+ * Therefore, we retain a fallback to our own application-level recursive
32
+ * FallbackWatcher for Linux, which has async `startWatching`.
33
+ *
34
+ * On Windows, this watcher could be used in principle, but needs work around
35
+ * some Windows-specific edge cases handled in FallbackWatcher, like
36
+ * deduping file change events, ignoring directory changes, and handling EPERM.
37
+ */
38
+ declare class NativeWatcher extends AbstractWatcher {
39
+ static isSupported(): boolean;
40
+ constructor(
41
+ dir: string,
42
+ opts: Readonly<{
43
+ ignored: null | undefined | RegExp;
44
+ globs: ReadonlyArray<string>;
45
+ dot: boolean;
46
+ }>,
47
+ );
48
+ startWatching(): Promise<void>;
49
+ /**
50
+ * End watching.
51
+ */
52
+ stopWatching(): Promise<void>;
53
+ _handleEvent(event: string, relativePath: string): void;
54
+ }
55
+ export default NativeWatcher;
@@ -17,10 +17,7 @@ function _interopRequireWildcard(e, t) {
17
17
  if (!t && e && e.__esModule) return e;
18
18
  var o,
19
19
  i,
20
- f = {
21
- __proto__: null,
22
- default: e,
23
- };
20
+ f = { __proto__: null, default: e };
24
21
  if (null === e || ("object" != typeof e && "function" != typeof e))
25
22
  return f;
26
23
  if ((o = t ? n : r)) {
@@ -42,6 +39,7 @@ function _interopRequireWildcard(e, t) {
42
39
  const debug = require("debug")("Metro:NativeWatcher");
43
40
  const TOUCH_EVENT = "touch";
44
41
  const DELETE_EVENT = "delete";
42
+ const RECRAWL_EVENT = "recrawl";
45
43
  class NativeWatcher extends _AbstractWatcher.AbstractWatcher {
46
44
  #fsWatcher;
47
45
  static isSupported() {
@@ -60,8 +58,8 @@ class NativeWatcher extends _AbstractWatcher.AbstractWatcher {
60
58
  persistent: false,
61
59
  recursive: true,
62
60
  },
63
- (_event, relativePath) => {
64
- this._handleEvent(relativePath).catch((error) => {
61
+ (event, relativePath) => {
62
+ this._handleEvent(event, relativePath).catch((error) => {
65
63
  this.emitError(error);
66
64
  });
67
65
  },
@@ -74,13 +72,23 @@ class NativeWatcher extends _AbstractWatcher.AbstractWatcher {
74
72
  this.#fsWatcher.close();
75
73
  }
76
74
  }
77
- async _handleEvent(relativePath) {
75
+ async _handleEvent(event, relativePath) {
78
76
  const absolutePath = path.resolve(this.root, relativePath);
79
77
  if (this.doIgnore(relativePath)) {
80
- debug("Ignoring event on %s (root: %s)", relativePath, this.root);
78
+ debug(
79
+ 'Ignoring event "%s" on %s (root: %s)',
80
+ event,
81
+ relativePath,
82
+ this.root,
83
+ );
81
84
  return;
82
85
  }
83
- debug("Handling event on %s (root: %s)", relativePath, this.root);
86
+ debug(
87
+ 'Handling event "%s" on %s (root: %s)',
88
+ event,
89
+ relativePath,
90
+ this.root,
91
+ );
84
92
  try {
85
93
  const stat = await _fs.promises.lstat(absolutePath);
86
94
  const type = (0, _common.typeFromStat)(stat);
@@ -92,6 +100,17 @@ class NativeWatcher extends _AbstractWatcher.AbstractWatcher {
92
100
  ) {
93
101
  return;
94
102
  }
103
+ if (type === "d" && event === "rename") {
104
+ debug(
105
+ "Directory rename detected on %s, requesting recrawl",
106
+ relativePath,
107
+ );
108
+ this.emitFileEvent({
109
+ event: RECRAWL_EVENT,
110
+ relativePath,
111
+ });
112
+ return;
113
+ }
95
114
  this.emitFileEvent({
96
115
  event: TOUCH_EVENT,
97
116
  relativePath,
@@ -21,6 +21,7 @@ const debug = require('debug')('Metro:NativeWatcher');
21
21
 
22
22
  const TOUCH_EVENT = 'touch';
23
23
  const DELETE_EVENT = 'delete';
24
+ const RECRAWL_EVENT = 'recrawl';
24
25
 
25
26
  /**
26
27
  * NativeWatcher uses Node's native fs.watch API with recursive: true.
@@ -74,9 +75,8 @@ export default class NativeWatcher extends AbstractWatcher {
74
75
  // ~instant on macOS or Windows.
75
76
  recursive: true,
76
77
  },
77
- (_event, relativePath) => {
78
- // _event is always 'rename' on macOS, so we don't use it.
79
- this._handleEvent(relativePath).catch(error => {
78
+ (event, relativePath) => {
79
+ this._handleEvent(event, relativePath).catch(error => {
80
80
  this.emitError(error);
81
81
  });
82
82
  },
@@ -95,13 +95,23 @@ export default class NativeWatcher extends AbstractWatcher {
95
95
  }
96
96
  }
97
97
 
98
- async _handleEvent(relativePath: string) {
98
+ async _handleEvent(event: string, relativePath: string) {
99
99
  const absolutePath = path.resolve(this.root, relativePath);
100
100
  if (this.doIgnore(relativePath)) {
101
- debug('Ignoring event on %s (root: %s)', relativePath, this.root);
101
+ debug(
102
+ 'Ignoring event "%s" on %s (root: %s)',
103
+ event,
104
+ relativePath,
105
+ this.root,
106
+ );
102
107
  return;
103
108
  }
104
- debug('Handling event on %s (root: %s)', relativePath, this.root);
109
+ debug(
110
+ 'Handling event "%s" on %s (root: %s)',
111
+ event,
112
+ relativePath,
113
+ this.root,
114
+ );
105
115
 
106
116
  try {
107
117
  const stat = await fsPromises.lstat(absolutePath);
@@ -116,6 +126,23 @@ export default class NativeWatcher extends AbstractWatcher {
116
126
  return;
117
127
  }
118
128
 
129
+ // For directory "rename" events, notify that we need a recrawl since we
130
+ // wont' receive events for unmodified files underneath a moved (or
131
+ // cloned) directory. Renames are fired by the OS on moves, clones, and
132
+ // creations. We ignore "change" events because they indiciate a change
133
+ // to directory metadata, rather than its path or existence.
134
+ if (type === 'd' && event === 'rename') {
135
+ debug(
136
+ 'Directory rename detected on %s, requesting recrawl',
137
+ relativePath,
138
+ );
139
+ this.emitFileEvent({
140
+ event: RECRAWL_EVENT,
141
+ relativePath,
142
+ });
143
+ return;
144
+ }
145
+
119
146
  this.emitFileEvent({
120
147
  event: TOUCH_EVENT,
121
148
  relativePath,
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<dc063c7e351d5c09a5ad65d09b5b6b2a>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro-file-map/src/watchers/RecrawlWarning.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ /**
19
+ * Originally vendored from
20
+ * https://github.com/amasad/sane/blob/64ff3a870c42e84f744086884bf55a4f9c22d376/src/utils/recrawl-warning-dedupe.js
21
+ */
22
+
23
+ declare class RecrawlWarning {
24
+ static RECRAWL_WARNINGS: Array<RecrawlWarning>;
25
+ static REGEXP: RegExp;
26
+ root: string;
27
+ count: number;
28
+ constructor(root: string, count: number);
29
+ static findByRoot(root: string): null | undefined | RecrawlWarning;
30
+ static isRecrawlWarningDupe(warningMessage: unknown): boolean;
31
+ }
32
+ export default RecrawlWarning;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<b8358b8822835bcef505207f90b02c66>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro-file-map/src/watchers/WatchmanWatcher.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ import type {WatcherOptions} from './common';
19
+
20
+ import {AbstractWatcher} from './AbstractWatcher';
21
+ /**
22
+ * Watches `dir`.
23
+ */
24
+ declare class WatchmanWatcher extends AbstractWatcher {
25
+ readonly subscriptionName: string;
26
+ constructor(dir: string, opts: WatcherOptions);
27
+ startWatching(): Promise<void>;
28
+ /**
29
+ * Closes the watcher.
30
+ */
31
+ stopWatching(): Promise<void>;
32
+ getPauseReason(): null | undefined | string;
33
+ }
34
+ export default WatchmanWatcher;
@@ -22,10 +22,7 @@ function _interopRequireWildcard(e, t) {
22
22
  if (!t && e && e.__esModule) return e;
23
23
  var o,
24
24
  i,
25
- f = {
26
- __proto__: null,
27
- default: e,
28
- };
25
+ f = { __proto__: null, default: e };
29
26
  if (null === e || ("object" != typeof e && "function" != typeof e))
30
27
  return f;
31
28
  if ((o = t ? n : r)) {
@@ -45,11 +42,7 @@ function _interopRequireWildcard(e, t) {
45
42
  })(e, t);
46
43
  }
47
44
  function _interopRequireDefault(e) {
48
- return e && e.__esModule
49
- ? e
50
- : {
51
- default: e,
52
- };
45
+ return e && e.__esModule ? e : { default: e };
53
46
  }
54
47
  const debug = require("debug")("Metro:WatchmanWatcher");
55
48
  const DELETE_EVENT = common.DELETE_EVENT;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<ebebfbca9d43e034fde8489e1d9f2dbb>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro-file-map/src/watchers/common.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ /**
19
+ * Originally vendored from
20
+ * https://github.com/amasad/sane/blob/64ff3a870c42e84f744086884bf55a4f9c22d376/src/common.js
21
+ */
22
+
23
+ import type {ChangeEventMetadata} from '../flow-types';
24
+ import type {Stats} from 'fs';
25
+ /**
26
+ * Constants
27
+ */
28
+ export declare const DELETE_EVENT: 'delete';
29
+ export declare type DELETE_EVENT = typeof DELETE_EVENT;
30
+ export declare const TOUCH_EVENT: 'touch';
31
+ export declare type TOUCH_EVENT = typeof TOUCH_EVENT;
32
+ export declare const RECRAWL_EVENT: 'recrawl';
33
+ export declare type RECRAWL_EVENT = typeof RECRAWL_EVENT;
34
+ export declare const ALL_EVENT: 'all';
35
+ export declare type ALL_EVENT = typeof ALL_EVENT;
36
+ export type WatcherOptions = Readonly<{
37
+ globs: ReadonlyArray<string>;
38
+ dot: boolean;
39
+ ignored: null | undefined | RegExp;
40
+ watchmanDeferStates: ReadonlyArray<string>;
41
+ watchman?: unknown;
42
+ watchmanPath?: string;
43
+ }>;
44
+ /**
45
+ * Checks a file relative path against the globs array.
46
+ */
47
+ export declare function includedByGlob(
48
+ type: null | undefined | ('f' | 'l' | 'd'),
49
+ globs: ReadonlyArray<string>,
50
+ dot: boolean,
51
+ relativePath: string,
52
+ ): boolean;
53
+ /**
54
+ * Whether the given filePath matches the given RegExp, after converting
55
+ * (on Windows only) system separators to posix separators.
56
+ *
57
+ * Conversion to posix is for backwards compatibility with the previous
58
+ * anymatch matcher, which normlises all inputs[1]. This may not be consistent
59
+ * with other parts of metro-file-map.
60
+ *
61
+ * [1]: https://github.com/micromatch/anymatch/blob/3.1.1/index.js#L50
62
+ */
63
+ export declare const posixPathMatchesPattern: (
64
+ pattern: RegExp,
65
+ filePath: string,
66
+ ) => boolean;
67
+ export declare type posixPathMatchesPattern = typeof posixPathMatchesPattern;
68
+ export declare function typeFromStat(
69
+ stat: Stats,
70
+ ): null | undefined | ChangeEventMetadata['type'];
@@ -3,21 +3,22 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true,
5
5
  });
6
- exports.TOUCH_EVENT = exports.DELETE_EVENT = exports.ALL_EVENT = void 0;
6
+ exports.TOUCH_EVENT =
7
+ exports.RECRAWL_EVENT =
8
+ exports.DELETE_EVENT =
9
+ exports.ALL_EVENT =
10
+ void 0;
7
11
  exports.includedByGlob = includedByGlob;
8
12
  exports.posixPathMatchesPattern = void 0;
9
13
  exports.typeFromStat = typeFromStat;
10
14
  var _micromatch = _interopRequireDefault(require("micromatch"));
11
15
  var _path = _interopRequireDefault(require("path"));
12
16
  function _interopRequireDefault(e) {
13
- return e && e.__esModule
14
- ? e
15
- : {
16
- default: e,
17
- };
17
+ return e && e.__esModule ? e : { default: e };
18
18
  }
19
19
  const DELETE_EVENT = (exports.DELETE_EVENT = "delete");
20
20
  const TOUCH_EVENT = (exports.TOUCH_EVENT = "touch");
21
+ const RECRAWL_EVENT = (exports.RECRAWL_EVENT = "recrawl");
21
22
  const ALL_EVENT = (exports.ALL_EVENT = "all");
22
23
  function includedByGlob(type, globs, dot, relativePath) {
23
24
  if (globs.length === 0 || type !== "f") {
@@ -26,6 +26,7 @@ import path from 'path';
26
26
  */
27
27
  export const DELETE_EVENT = 'delete';
28
28
  export const TOUCH_EVENT = 'touch';
29
+ export const RECRAWL_EVENT = 'recrawl';
29
30
  export const ALL_EVENT = 'all';
30
31
 
31
32
  export type WatcherOptions = Readonly<{