metro-file-map 0.83.3 → 0.84.0

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 +4 -3
  2. package/src/Watcher.js +59 -52
  3. package/src/Watcher.js.flow +39 -39
  4. package/src/cache/DiskCacheManager.js.flow +3 -3
  5. package/src/constants.js +9 -8
  6. package/src/constants.js.flow +6 -18
  7. package/src/crawlers/node/index.js +27 -25
  8. package/src/crawlers/node/index.js.flow +6 -8
  9. package/src/crawlers/watchman/index.js +26 -22
  10. package/src/crawlers/watchman/index.js.flow +3 -4
  11. package/src/crawlers/watchman/planQuery.d.ts +24 -0
  12. package/src/crawlers/watchman/planQuery.js.flow +4 -4
  13. package/src/flow-types.js.flow +125 -87
  14. package/src/index.js +267 -235
  15. package/src/index.js.flow +269 -275
  16. package/src/lib/FileProcessor.js +76 -54
  17. package/src/lib/FileProcessor.js.flow +93 -72
  18. package/src/lib/RootPathUtils.js +25 -21
  19. package/src/lib/RootPathUtils.js.flow +4 -4
  20. package/src/lib/TreeFS.js +72 -77
  21. package/src/lib/TreeFS.js.flow +104 -124
  22. package/src/lib/checkWatchmanCapabilities.js.flow +4 -4
  23. package/src/lib/dependencyExtractor.d.ts +14 -0
  24. package/src/lib/normalizePathSeparatorsToPosix.js +25 -21
  25. package/src/lib/normalizePathSeparatorsToPosix.js.flow +3 -3
  26. package/src/lib/normalizePathSeparatorsToSystem.js +25 -21
  27. package/src/lib/normalizePathSeparatorsToSystem.js.flow +3 -3
  28. package/src/lib/rootRelativeCacheKeys.js +0 -20
  29. package/src/lib/rootRelativeCacheKeys.js.flow +1 -23
  30. package/src/plugins/DependencyPlugin.js +75 -0
  31. package/src/plugins/DependencyPlugin.js.flow +144 -0
  32. package/src/plugins/HastePlugin.js +83 -38
  33. package/src/plugins/HastePlugin.js.flow +105 -51
  34. package/src/plugins/MockPlugin.js +7 -4
  35. package/src/plugins/MockPlugin.js.flow +24 -15
  36. package/src/plugins/dependencies/dependencyExtractor.d.ts +14 -0
  37. package/src/{lib → plugins/dependencies}/dependencyExtractor.js.flow +3 -6
  38. package/src/plugins/dependencies/worker.d.ts +24 -0
  39. package/src/plugins/dependencies/worker.js +24 -0
  40. package/src/plugins/dependencies/worker.js.flow +53 -0
  41. package/src/plugins/haste/HasteConflictsError.js.flow +2 -2
  42. package/src/plugins/haste/computeConflicts.js +2 -1
  43. package/src/plugins/haste/computeConflicts.js.flow +11 -12
  44. package/src/plugins/haste/getPlatformExtension.js.flow +2 -2
  45. package/src/plugins/haste/worker.d.ts +24 -0
  46. package/src/plugins/haste/worker.js +35 -0
  47. package/src/plugins/haste/worker.js.flow +64 -0
  48. package/src/plugins/mocks/getMockName.js +27 -23
  49. package/src/plugins/mocks/getMockName.js.flow +2 -4
  50. package/src/watchers/AbstractWatcher.js +27 -22
  51. package/src/watchers/AbstractWatcher.js.flow +6 -5
  52. package/src/watchers/FallbackWatcher.js +88 -84
  53. package/src/watchers/FallbackWatcher.js.flow +65 -65
  54. package/src/watchers/NativeWatcher.js +25 -21
  55. package/src/watchers/NativeWatcher.js.flow +3 -3
  56. package/src/watchers/RecrawlWarning.js.flow +1 -1
  57. package/src/watchers/WatchmanWatcher.js +61 -53
  58. package/src/watchers/WatchmanWatcher.js.flow +39 -38
  59. package/src/watchers/common.js.flow +5 -5
  60. package/src/worker.d.ts +36 -0
  61. package/src/worker.js +16 -58
  62. package/src/worker.js.flow +19 -69
  63. package/src/workerExclusionList.d.ts +12 -0
  64. package/src/workerExclusionList.js.flow +1 -1
  65. package/src/Watcher.d.ts +0 -24
  66. package/src/cache/DiskCacheManager.d.ts +0 -38
  67. package/src/flow-types.d.ts +0 -353
  68. package/src/index.d.ts +0 -97
  69. package/src/lib/DuplicateHasteCandidatesError.d.ts +0 -24
  70. /package/src/{lib → plugins/dependencies}/dependencyExtractor.js +0 -0
@@ -5,28 +5,32 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var path = _interopRequireWildcard(require("path"));
8
- function _getRequireWildcardCache(e) {
9
- if ("function" != typeof WeakMap) return null;
10
- var r = new WeakMap(),
11
- t = new WeakMap();
12
- return (_getRequireWildcardCache = function (e) {
13
- return e ? t : r;
14
- })(e);
15
- }
16
- function _interopRequireWildcard(e, r) {
17
- if (!r && e && e.__esModule) return e;
18
- if (null === e || ("object" != typeof e && "function" != typeof e))
19
- return { default: e };
20
- var t = _getRequireWildcardCache(r);
21
- if (t && t.has(e)) return t.get(e);
22
- var n = { __proto__: null },
23
- a = Object.defineProperty && Object.getOwnPropertyDescriptor;
24
- for (var u in e)
25
- if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
26
- var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
27
- i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
8
+ function _interopRequireWildcard(e, t) {
9
+ if ("function" == typeof WeakMap)
10
+ var r = new WeakMap(),
11
+ n = new WeakMap();
12
+ return (_interopRequireWildcard = function (e, t) {
13
+ if (!t && e && e.__esModule) return e;
14
+ var o,
15
+ i,
16
+ f = { __proto__: null, default: e };
17
+ if (null === e || ("object" != typeof e && "function" != typeof e))
18
+ return f;
19
+ if ((o = t ? n : r)) {
20
+ if (o.has(e)) return o.get(e);
21
+ o.set(e, f);
28
22
  }
29
- return ((n.default = e), t && t.set(e, n), n);
23
+ for (const t in e)
24
+ "default" !== t &&
25
+ {}.hasOwnProperty.call(e, t) &&
26
+ ((i =
27
+ (o = Object.defineProperty) &&
28
+ Object.getOwnPropertyDescriptor(e, t)) &&
29
+ (i.get || i.set)
30
+ ? o(f, t, i)
31
+ : (f[t] = e[t]));
32
+ return f;
33
+ })(e, t);
30
34
  }
31
35
  let normalizePathSeparatorsToSystem;
32
36
  if (path.sep === "/") {
@@ -4,13 +4,13 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * @format
8
7
  * @flow strict
8
+ * @format
9
9
  */
10
10
 
11
11
  import * as path from 'path';
12
12
 
13
- let normalizePathSeparatorsToSystem: (string: string) => string;
13
+ let normalizePathSeparatorsToSystem;
14
14
  if (path.sep === '/') {
15
15
  normalizePathSeparatorsToSystem = (filePath: string): string => filePath;
16
16
  } else {
@@ -18,4 +18,4 @@ if (path.sep === '/') {
18
18
  filePath.replace(/\//g, path.sep);
19
19
  }
20
20
 
21
- export default normalizePathSeparatorsToSystem;
21
+ export default normalizePathSeparatorsToSystem as (filePath: string) => string;
@@ -12,20 +12,6 @@ var _crypto = require("crypto");
12
12
  function _interopRequireDefault(e) {
13
13
  return e && e.__esModule ? e : { default: e };
14
14
  }
15
- function moduleCacheKey(modulePath) {
16
- if (modulePath == null) {
17
- return null;
18
- }
19
- const moduleExports = require(modulePath);
20
- if (typeof moduleExports?.getCacheKey !== "function") {
21
- console.warn(
22
- `metro-file-map: Expected \`${modulePath}\` to export ` +
23
- "`getCacheKey: () => string`",
24
- );
25
- return null;
26
- }
27
- return moduleExports.getCacheKey();
28
- }
29
15
  function rootRelativeCacheKeys(buildParameters) {
30
16
  const { rootDir, plugins, ...otherParameters } = buildParameters;
31
17
  const rootDirHash = (0, _crypto.createHash)("md5")
@@ -44,19 +30,13 @@ function rootRelativeCacheKeys(buildParameters) {
44
30
  );
45
31
  case "cacheBreaker":
46
32
  case "extensions":
47
- case "computeDependencies":
48
33
  case "computeSha1":
49
- case "enableHastePackages":
50
34
  case "enableSymlinks":
51
35
  case "forceNodeFilesystemAPI":
52
36
  case "retainAllFiles":
53
- case "skipPackageJson":
54
37
  return buildParameters[key] ?? null;
55
38
  case "ignorePattern":
56
39
  return buildParameters[key].toString();
57
- case "hasteImplModulePath":
58
- case "dependencyExtractor":
59
- return moduleCacheKey(buildParameters[key]);
60
40
  default:
61
41
  key;
62
42
  throw new Error("Unrecognised key in build parameters: " + key);
@@ -15,22 +15,6 @@ import normalizePathSeparatorsToPosix from './normalizePathSeparatorsToPosix';
15
15
  import {RootPathUtils} from './RootPathUtils';
16
16
  import {createHash} from 'crypto';
17
17
 
18
- function moduleCacheKey(modulePath: ?string) {
19
- if (modulePath == null) {
20
- return null;
21
- }
22
- // $FlowFixMe[unsupported-syntax] - Dynamic require
23
- const moduleExports = require(modulePath);
24
- if (typeof moduleExports?.getCacheKey !== 'function') {
25
- console.warn(
26
- `metro-file-map: Expected \`${modulePath}\` to export ` +
27
- '`getCacheKey: () => string`',
28
- );
29
- return null;
30
- }
31
- return moduleExports.getCacheKey();
32
- }
33
-
34
18
  export default function rootRelativeCacheKeys(
35
19
  buildParameters: BuildParameters,
36
20
  ): {
@@ -53,21 +37,15 @@ export default function rootRelativeCacheKeys(
53
37
  );
54
38
  case 'cacheBreaker':
55
39
  case 'extensions':
56
- case 'computeDependencies':
57
40
  case 'computeSha1':
58
- case 'enableHastePackages':
59
41
  case 'enableSymlinks':
60
42
  case 'forceNodeFilesystemAPI':
61
43
  case 'retainAllFiles':
62
- case 'skipPackageJson':
63
44
  return buildParameters[key] ?? null;
64
45
  case 'ignorePattern':
65
46
  return buildParameters[key].toString();
66
- case 'hasteImplModulePath':
67
- case 'dependencyExtractor':
68
- return moduleCacheKey(buildParameters[key]);
69
47
  default:
70
- (key: empty);
48
+ key as empty;
71
49
  throw new Error('Unrecognised key in build parameters: ' + key);
72
50
  }
73
51
  });
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = void 0;
7
+ class DependencyPlugin {
8
+ name = "dependencies";
9
+ #dependencyExtractor;
10
+ #computeDependencies;
11
+ #getDependencies;
12
+ #rootDir;
13
+ constructor(options) {
14
+ this.#dependencyExtractor = options.dependencyExtractor;
15
+ this.#computeDependencies = options.computeDependencies;
16
+ this.#rootDir = options.rootDir;
17
+ }
18
+ async initialize(initOptions) {
19
+ const { files } = initOptions;
20
+ this.#getDependencies = (mixedPath) => {
21
+ const result = files.lookup(mixedPath);
22
+ if (result.exists && result.type === "f") {
23
+ return result.pluginData ?? [];
24
+ }
25
+ return null;
26
+ };
27
+ }
28
+ getSerializableSnapshot() {
29
+ return null;
30
+ }
31
+ async bulkUpdate(delta) {}
32
+ onNewOrModifiedFile(relativeFilePath, pluginData) {}
33
+ onRemovedFile(relativeFilePath, pluginData) {}
34
+ assertValid() {}
35
+ getCacheKey() {
36
+ if (this.#dependencyExtractor != null) {
37
+ const extractor = require(this.#dependencyExtractor);
38
+ return JSON.stringify({
39
+ extractorKey: extractor.getCacheKey?.() ?? null,
40
+ extractorPath: this.#dependencyExtractor,
41
+ });
42
+ }
43
+ return "default-dependency-extractor";
44
+ }
45
+ getWorker() {
46
+ const excludedExtensions = require("../workerExclusionList");
47
+ return {
48
+ worker: {
49
+ modulePath: require.resolve("./dependencies/worker.js"),
50
+ setupArgs: {
51
+ dependencyExtractor: this.#dependencyExtractor ?? null,
52
+ },
53
+ },
54
+ filter: ({ normalPath, isNodeModules }) => {
55
+ if (!this.#computeDependencies) {
56
+ return false;
57
+ }
58
+ if (isNodeModules) {
59
+ return false;
60
+ }
61
+ const ext = normalPath.substr(normalPath.lastIndexOf("."));
62
+ return !excludedExtensions.has(ext);
63
+ },
64
+ };
65
+ }
66
+ getDependencies(mixedPath) {
67
+ if (this.#getDependencies == null) {
68
+ throw new Error(
69
+ "DependencyPlugin has not been initialized before getDependencies",
70
+ );
71
+ }
72
+ return this.#getDependencies(mixedPath);
73
+ }
74
+ }
75
+ exports.default = DependencyPlugin;
@@ -0,0 +1,144 @@
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
+ * @flow strict-local
8
+ * @format
9
+ * @oncall react_native
10
+ */
11
+
12
+ import type {
13
+ FileMapDelta,
14
+ FileMapPlugin,
15
+ FileMapPluginInitOptions,
16
+ FileMapPluginWorker,
17
+ Path,
18
+ } from '../flow-types';
19
+
20
+ export type DependencyPluginOptions = Readonly<{
21
+ /** Path to custom dependency extractor module */
22
+ dependencyExtractor: ?string,
23
+ /** Whether to compute dependencies (performance optimization) */
24
+ computeDependencies: boolean,
25
+ rootDir: Path,
26
+ }>;
27
+
28
+ export default class DependencyPlugin
29
+ implements FileMapPlugin<null, ReadonlyArray<string> | null>
30
+ {
31
+ +name: 'dependencies' = 'dependencies';
32
+
33
+ #dependencyExtractor: ?string;
34
+ #computeDependencies: boolean;
35
+ #getDependencies: Path => ?ReadonlyArray<string>;
36
+ #rootDir: Path;
37
+
38
+ constructor(options: DependencyPluginOptions) {
39
+ this.#dependencyExtractor = options.dependencyExtractor;
40
+ this.#computeDependencies = options.computeDependencies;
41
+ this.#rootDir = options.rootDir;
42
+ }
43
+
44
+ async initialize(
45
+ initOptions: FileMapPluginInitOptions<null, ReadonlyArray<string> | null>,
46
+ ): Promise<void> {
47
+ const {files} = initOptions;
48
+ // Create closure to access dependencies from file metadata plugin data
49
+ this.#getDependencies = (mixedPath: Path) => {
50
+ const result = files.lookup(mixedPath);
51
+ if (result.exists && result.type === 'f') {
52
+ // Backwards compatibility: distinguish an extant file that we've not
53
+ // run the worker on (probably because it fails the extension filter)
54
+ // from a missing file. Non-source files are expected to have empty
55
+ // dependencies.
56
+ return result.pluginData ?? [];
57
+ }
58
+ return null;
59
+ };
60
+ }
61
+
62
+ getSerializableSnapshot(): null {
63
+ // Dependencies stored in plugin data, no separate serialization needed
64
+ return null;
65
+ }
66
+
67
+ async bulkUpdate(delta: FileMapDelta<?ReadonlyArray<string>>): Promise<void> {
68
+ // No-op: Worker already populated plugin data
69
+ // Plugin data is write-only from worker
70
+ }
71
+
72
+ onNewOrModifiedFile(
73
+ relativeFilePath: string,
74
+ pluginData: ?ReadonlyArray<string>,
75
+ ): void {
76
+ // No-op: Dependencies already in plugin data
77
+ }
78
+
79
+ onRemovedFile(
80
+ relativeFilePath: string,
81
+ pluginData: ?ReadonlyArray<string>,
82
+ ): void {
83
+ // No-op
84
+ }
85
+
86
+ assertValid(): void {
87
+ // No validation needed
88
+ }
89
+
90
+ getCacheKey(): string {
91
+ if (this.#dependencyExtractor != null) {
92
+ // Dynamic require to get extractor's cache key
93
+ // $FlowFixMe[unsupported-syntax] - dynamic require
94
+ const extractor = require(this.#dependencyExtractor);
95
+ return JSON.stringify({
96
+ extractorKey: extractor.getCacheKey?.() ?? null,
97
+ extractorPath: this.#dependencyExtractor,
98
+ });
99
+ }
100
+ return 'default-dependency-extractor';
101
+ }
102
+
103
+ getWorker(): FileMapPluginWorker {
104
+ const excludedExtensions = require('../workerExclusionList');
105
+
106
+ return {
107
+ worker: {
108
+ modulePath: require.resolve('./dependencies/worker.js'),
109
+ setupArgs: {
110
+ dependencyExtractor: this.#dependencyExtractor ?? null,
111
+ },
112
+ },
113
+ filter: ({normalPath, isNodeModules}) => {
114
+ // Respect computeDependencies flag
115
+ if (!this.#computeDependencies) {
116
+ return false;
117
+ }
118
+
119
+ // Never process node_modules
120
+ if (isNodeModules) {
121
+ return false;
122
+ }
123
+
124
+ // Skip excluded extensions
125
+ const ext = normalPath.substr(normalPath.lastIndexOf('.'));
126
+ return !excludedExtensions.has(ext);
127
+ },
128
+ };
129
+ }
130
+
131
+ /**
132
+ * Get the list of dependencies for a given file.
133
+ * @param mixedPath Absolute or project-relative path to the file
134
+ * @returns Array of dependency module names, or null if the file doesn't exist
135
+ */
136
+ getDependencies(mixedPath: Path): ?ReadonlyArray<string> {
137
+ if (this.#getDependencies == null) {
138
+ throw new Error(
139
+ 'DependencyPlugin has not been initialized before getDependencies',
140
+ );
141
+ }
142
+ return this.#getDependencies(mixedPath);
143
+ }
144
+ }
@@ -18,21 +18,25 @@ function _interopRequireDefault(e) {
18
18
  }
19
19
  const EMPTY_OBJ = {};
20
20
  const EMPTY_MAP = new Map();
21
+ const PACKAGE_JSON = /(?:[/\\]|^)package\.json$/;
21
22
  const YIELD_EVERY_NUM_HASTE_FILES = 10000;
22
23
  class HastePlugin {
23
24
  name = "haste";
24
- #rootDir;
25
- #map = new Map();
26
- #duplicates = new Map();
27
25
  #console;
26
+ #duplicates = new Map();
28
27
  #enableHastePackages;
29
- #perfLogger;
28
+ #failValidationOnConflicts;
29
+ #getModuleNameByPath;
30
+ #hasteImplModulePath;
31
+ #map = new Map();
30
32
  #pathUtils;
33
+ #perfLogger;
31
34
  #platforms;
32
- #failValidationOnConflicts;
35
+ #rootDir;
33
36
  constructor(options) {
34
- this.#console = options.console ?? null;
37
+ this.#console = options.console ?? global.console;
35
38
  this.#enableHastePackages = options.enableHastePackages;
39
+ this.#hasteImplModulePath = options.hasteImplModulePath;
36
40
  this.#perfLogger = options.perfLogger;
37
41
  this.#platforms = options.platforms;
38
42
  this.#rootDir = options.rootDir;
@@ -42,22 +46,35 @@ class HastePlugin {
42
46
  async initialize({ files }) {
43
47
  this.#perfLogger?.point("constructHasteMap_start");
44
48
  let hasteFiles = 0;
45
- for (const { baseName, canonicalPath, metadata } of files.metadataIterator({
49
+ for (const {
50
+ baseName,
51
+ canonicalPath,
52
+ pluginData: hasteId,
53
+ } of files.fileIterator({
46
54
  includeNodeModules: false,
47
55
  includeSymlinks: false,
48
56
  })) {
49
- if (metadata[_constants.default.ID]) {
50
- this.setModule(metadata[_constants.default.ID], [
51
- canonicalPath,
52
- this.#enableHastePackages && baseName === "package.json"
53
- ? _constants.default.PACKAGE
54
- : _constants.default.MODULE,
55
- ]);
56
- if (++hasteFiles % YIELD_EVERY_NUM_HASTE_FILES === 0) {
57
- await new Promise(setImmediate);
58
- }
57
+ if (hasteId == null) {
58
+ continue;
59
+ }
60
+ this.setModule(hasteId, [
61
+ canonicalPath,
62
+ this.#enableHastePackages && baseName === "package.json"
63
+ ? _constants.default.PACKAGE
64
+ : _constants.default.MODULE,
65
+ ]);
66
+ if (++hasteFiles % YIELD_EVERY_NUM_HASTE_FILES === 0) {
67
+ await new Promise(setImmediate);
59
68
  }
60
69
  }
70
+ this.#getModuleNameByPath = (mixedPath) => {
71
+ const result = files.lookup(mixedPath);
72
+ return result.exists &&
73
+ result.type === "f" &&
74
+ typeof result.pluginData === "string"
75
+ ? result.pluginData
76
+ : null;
77
+ };
61
78
  this.#perfLogger?.point("constructHasteMap_end");
62
79
  this.#perfLogger?.annotate({
63
80
  int: {
@@ -69,7 +86,7 @@ class HastePlugin {
69
86
  return null;
70
87
  }
71
88
  getModule(name, platform, supportsNativePlatform, type) {
72
- const module = this._getModuleMetadata(
89
+ const module = this.#getModuleMetadata(
73
90
  name,
74
91
  platform,
75
92
  !!supportsNativePlatform,
@@ -83,14 +100,22 @@ class HastePlugin {
83
100
  }
84
101
  return null;
85
102
  }
103
+ getModuleNameByPath(mixedPath) {
104
+ if (this.#getModuleNameByPath == null) {
105
+ throw new Error(
106
+ "HastePlugin has not been initialized before getModuleNameByPath",
107
+ );
108
+ }
109
+ return this.#getModuleNameByPath(mixedPath) ?? null;
110
+ }
86
111
  getPackage(name, platform, _supportsNativePlatform) {
87
112
  return this.getModule(name, platform, null, _constants.default.PACKAGE);
88
113
  }
89
- _getModuleMetadata(name, platform, supportsNativePlatform) {
114
+ #getModuleMetadata(name, platform, supportsNativePlatform) {
90
115
  const map = this.#map.get(name) || EMPTY_OBJ;
91
116
  const dupMap = this.#duplicates.get(name) || EMPTY_MAP;
92
117
  if (platform != null) {
93
- this._assertNoDuplicates(
118
+ this.#assertNoDuplicates(
94
119
  name,
95
120
  platform,
96
121
  supportsNativePlatform,
@@ -101,7 +126,7 @@ class HastePlugin {
101
126
  }
102
127
  }
103
128
  if (supportsNativePlatform) {
104
- this._assertNoDuplicates(
129
+ this.#assertNoDuplicates(
105
130
  name,
106
131
  _constants.default.NATIVE_PLATFORM,
107
132
  supportsNativePlatform,
@@ -111,7 +136,7 @@ class HastePlugin {
111
136
  return map[_constants.default.NATIVE_PLATFORM];
112
137
  }
113
138
  }
114
- this._assertNoDuplicates(
139
+ this.#assertNoDuplicates(
115
140
  name,
116
141
  _constants.default.GENERIC_PLATFORM,
117
142
  supportsNativePlatform,
@@ -122,7 +147,7 @@ class HastePlugin {
122
147
  }
123
148
  return null;
124
149
  }
125
- _assertNoDuplicates(name, platform, supportsNativePlatform, relativePathSet) {
150
+ #assertNoDuplicates(name, platform, supportsNativePlatform, relativePathSet) {
126
151
  if (relativePathSet == null) {
127
152
  return;
128
153
  }
@@ -139,15 +164,14 @@ class HastePlugin {
139
164
  );
140
165
  }
141
166
  async bulkUpdate(delta) {
142
- for (const [normalPath, metadata] of delta.removed) {
143
- this.onRemovedFile(normalPath, metadata);
167
+ for (const [normalPath, maybeHasteId] of delta.removed) {
168
+ this.onRemovedFile(normalPath, maybeHasteId);
144
169
  }
145
- for (const [normalPath, metadata] of delta.addedOrModified) {
146
- this.onNewOrModifiedFile(normalPath, metadata);
170
+ for (const [normalPath, maybeHasteId] of delta.addedOrModified) {
171
+ this.onNewOrModifiedFile(normalPath, maybeHasteId);
147
172
  }
148
173
  }
149
- onNewOrModifiedFile(relativeFilePath, fileMetadata) {
150
- const id = fileMetadata[_constants.default.ID] || null;
174
+ onNewOrModifiedFile(relativeFilePath, id) {
151
175
  if (id == null) {
152
176
  return;
153
177
  }
@@ -224,8 +248,7 @@ class HastePlugin {
224
248
  }
225
249
  hasteMapItem[platform] = module;
226
250
  }
227
- onRemovedFile(relativeFilePath, fileMetadata) {
228
- const moduleName = fileMetadata[_constants.default.ID] || null;
251
+ onRemovedFile(relativeFilePath, moduleName) {
229
252
  if (moduleName == null) {
230
253
  return;
231
254
  }
@@ -241,7 +264,7 @@ class HastePlugin {
241
264
  this.#map.set(moduleName, hasteMapItem);
242
265
  }
243
266
  }
244
- this._recoverDuplicates(moduleName, relativeFilePath);
267
+ this.#recoverDuplicates(moduleName, relativeFilePath);
245
268
  }
246
269
  assertValid() {
247
270
  if (!this.#failValidationOnConflicts) {
@@ -252,7 +275,7 @@ class HastePlugin {
252
275
  throw new _HasteConflictsError.HasteConflictsError(conflicts);
253
276
  }
254
277
  }
255
- _recoverDuplicates(moduleName, relativeFilePath) {
278
+ #recoverDuplicates(moduleName, relativeFilePath) {
256
279
  let dupsByPlatform = this.#duplicates.get(moduleName);
257
280
  if (dupsByPlatform == null) {
258
281
  return;
@@ -292,12 +315,12 @@ class HastePlugin {
292
315
  for (const [id, dupsByPlatform] of this.#duplicates.entries()) {
293
316
  for (const [platform, conflictingModules] of dupsByPlatform) {
294
317
  conflicts.push({
295
- id,
296
- platform:
297
- platform === _constants.default.GENERIC_PLATFORM ? null : platform,
298
318
  absolutePaths: [...conflictingModules.keys()]
299
319
  .map((modulePath) => this.#pathUtils.normalToAbsolute(modulePath))
300
320
  .sort(),
321
+ id,
322
+ platform:
323
+ platform === _constants.default.GENERIC_PLATFORM ? null : platform,
301
324
  type: "duplicate",
302
325
  });
303
326
  }
@@ -330,11 +353,11 @@ class HastePlugin {
330
353
  }
331
354
  if (conflictPaths.size) {
332
355
  conflicts.push({
333
- id,
334
- platform: null,
335
356
  absolutePaths: [...new Set([...conflictPaths, ...basePaths])]
336
357
  .map((modulePath) => this.#pathUtils.normalToAbsolute(modulePath))
337
358
  .sort(),
359
+ id,
360
+ platform: null,
338
361
  type: "shadowing",
339
362
  });
340
363
  }
@@ -351,8 +374,30 @@ class HastePlugin {
351
374
  getCacheKey() {
352
375
  return JSON.stringify([
353
376
  this.#enableHastePackages,
377
+ this.#hasteImplModulePath != null
378
+ ? require(this.#hasteImplModulePath).getCacheKey()
379
+ : null,
354
380
  [...this.#platforms].sort(),
355
381
  ]);
356
382
  }
383
+ getWorker() {
384
+ return {
385
+ worker: {
386
+ modulePath: require.resolve("./haste/worker.js"),
387
+ setupArgs: {
388
+ hasteImplModulePath: this.#hasteImplModulePath ?? null,
389
+ },
390
+ },
391
+ filter: ({ isNodeModules, normalPath }) => {
392
+ if (isNodeModules) {
393
+ return false;
394
+ }
395
+ if (PACKAGE_JSON.test(normalPath)) {
396
+ return this.#enableHastePackages;
397
+ }
398
+ return this.#hasteImplModulePath != null;
399
+ },
400
+ };
401
+ }
357
402
  }
358
403
  exports.default = HastePlugin;