metro-file-map 0.84.3 → 0.85.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 (41) hide show
  1. package/package.json +3 -3
  2. package/src/Watcher.d.ts +1 -2
  3. package/src/Watcher.js +0 -1
  4. package/src/Watcher.js.flow +6 -6
  5. package/src/cache/DiskCacheManager.js.flow +2 -2
  6. package/src/crawlers/node/index.js +9 -92
  7. package/src/crawlers/node/index.js.flow +9 -98
  8. package/src/flow-types.d.ts +3 -5
  9. package/src/flow-types.js.flow +13 -15
  10. package/src/index.d.ts +1 -2
  11. package/src/index.js +0 -3
  12. package/src/index.js.flow +8 -12
  13. package/src/lib/FileProcessor.js.flow +2 -2
  14. package/src/lib/FileSystemChangeAggregator.js.flow +6 -6
  15. package/src/lib/RootPathUtils.js +8 -2
  16. package/src/lib/RootPathUtils.js.flow +16 -4
  17. package/src/lib/TreeFS.js +13 -5
  18. package/src/lib/TreeFS.js.flow +25 -10
  19. package/src/lib/rootRelativeCacheKeys.js +0 -1
  20. package/src/lib/rootRelativeCacheKeys.js.flow +0 -1
  21. package/src/plugins/DependencyPlugin.d.ts +5 -25
  22. package/src/plugins/DependencyPlugin.js +29 -45
  23. package/src/plugins/DependencyPlugin.js.flow +27 -85
  24. package/src/plugins/FileDataPlugin.d.ts +55 -0
  25. package/src/plugins/FileDataPlugin.js +41 -0
  26. package/src/plugins/FileDataPlugin.js.flow +76 -0
  27. package/src/plugins/HastePlugin.js.flow +11 -11
  28. package/src/plugins/MockPlugin.js.flow +5 -5
  29. package/src/plugins/dependencies/worker.js +7 -2
  30. package/src/plugins/dependencies/worker.js.flow +8 -3
  31. package/src/plugins/haste/worker.js +3 -1
  32. package/src/plugins/haste/worker.js.flow +4 -2
  33. package/src/watchers/AbstractWatcher.js.flow +5 -5
  34. package/src/watchers/FallbackWatcher.js.flow +4 -3
  35. package/src/watchers/NativeWatcher.d.ts +1 -2
  36. package/src/watchers/WatchmanWatcher.js.flow +2 -2
  37. package/src/worker.js +3 -1
  38. package/src/worker.js.flow +3 -1
  39. package/src/crawlers/node/hasNativeFindSupport.d.ts +0 -19
  40. package/src/crawlers/node/hasNativeFindSupport.js +0 -36
  41. package/src/crawlers/node/hasNativeFindSupport.js.flow +0 -41
@@ -55,19 +55,19 @@ export type HasteMapOptions = Readonly<{
55
55
  export default class HastePlugin
56
56
  implements HasteMap, FileMapPlugin<null, string | null>
57
57
  {
58
- +name: 'haste' = 'haste';
58
+ readonly name: 'haste' = 'haste';
59
59
 
60
- +#console: ?Console;
61
- +#duplicates: DuplicatesIndex = new Map();
62
- +#enableHastePackages: boolean;
63
- +#failValidationOnConflicts: boolean;
60
+ readonly #console: ?Console;
61
+ readonly #duplicates: DuplicatesIndex = new Map();
62
+ readonly #enableHastePackages: boolean;
63
+ readonly #failValidationOnConflicts: boolean;
64
64
  #getModuleNameByPath: string => ?string;
65
- +#hasteImplModulePath: ?string;
66
- +#map: Map<string, HasteMapItem> = new Map();
67
- +#pathUtils: RootPathUtils;
68
- +#perfLogger: ?PerfLogger;
69
- +#platforms: ReadonlySet<string>;
70
- +#rootDir: Path;
65
+ readonly #hasteImplModulePath: ?string;
66
+ readonly #map: Map<string, HasteMapItem> = new Map();
67
+ readonly #pathUtils: RootPathUtils;
68
+ readonly #perfLogger: ?PerfLogger;
69
+ readonly #platforms: ReadonlySet<string>;
70
+ readonly #rootDir: Path;
71
71
 
72
72
  constructor(options: HasteMapOptions) {
73
73
  this.#console = options.console ?? global.console;
@@ -39,13 +39,13 @@ export type MockMapOptions = Readonly<{
39
39
  export default class MockPlugin
40
40
  implements FileMapPlugin<RawMockMap, void>, IMockMap
41
41
  {
42
- +name: 'mocks' = 'mocks';
42
+ readonly name: 'mocks' = 'mocks';
43
43
 
44
- +#mocksPattern: RegExp;
44
+ readonly #mocksPattern: RegExp;
45
45
  #raw: RawMockMap;
46
- +#rootDir: Path;
47
- +#pathUtils: RootPathUtils;
48
- +#console: typeof console;
46
+ readonly #rootDir: Path;
47
+ readonly #pathUtils: RootPathUtils;
48
+ readonly #console: typeof console;
49
49
  #throwOnModuleCollision: boolean;
50
50
 
51
51
  constructor({
@@ -5,7 +5,12 @@ module.exports = class DependencyExtractorWorker {
5
5
  #dependencyExtractor;
6
6
  constructor({ dependencyExtractor }) {
7
7
  if (dependencyExtractor != null) {
8
- this.#dependencyExtractor = require(dependencyExtractor);
8
+ const mod = require(dependencyExtractor);
9
+ let extract = mod?.extract;
10
+ if (extract == null && mod?.__esModule === true) {
11
+ extract = mod.default?.extract;
12
+ }
13
+ this.#dependencyExtractor = extract;
9
14
  }
10
15
  }
11
16
  processFile(data, utils) {
@@ -13,7 +18,7 @@ module.exports = class DependencyExtractorWorker {
13
18
  const { filePath } = data;
14
19
  const dependencies =
15
20
  this.#dependencyExtractor != null
16
- ? this.#dependencyExtractor.extract(
21
+ ? this.#dependencyExtractor(
17
22
  content,
18
23
  filePath,
19
24
  defaultDependencyExtractor.extract,
@@ -20,14 +20,19 @@ import type {MetadataWorker, WorkerMessage, V8Serializable, DependencyExtractor}
20
20
  */
21
21
 
22
22
  module.exports = class DependencyExtractorWorker /*:: implements MetadataWorker */ {
23
- /*:: + */ #dependencyExtractor /*: ?DependencyExtractor */;
23
+ /*:: readonly */ #dependencyExtractor /*: ?DependencyExtractor['extract'] */;
24
24
 
25
25
  constructor(
26
26
  {dependencyExtractor} /*: Readonly<{dependencyExtractor: ?string}> */,
27
27
  ) {
28
28
  if (dependencyExtractor != null) {
29
29
  // $FlowFixMe[unsupported-syntax] - dynamic require
30
- this.#dependencyExtractor = require(dependencyExtractor);
30
+ const mod = require(dependencyExtractor);
31
+ let extract = mod?.extract; // CJS export or ESM named export
32
+ if (extract == null && mod?.__esModule === true) {
33
+ extract = mod.default?.extract;
34
+ }
35
+ this.#dependencyExtractor = extract;
31
36
  }
32
37
  }
33
38
 
@@ -40,7 +45,7 @@ module.exports = class DependencyExtractorWorker /*:: implements MetadataWorker
40
45
 
41
46
  const dependencies =
42
47
  this.#dependencyExtractor != null
43
- ? this.#dependencyExtractor.extract(
48
+ ? this.#dependencyExtractor(
44
49
  content,
45
50
  filePath,
46
51
  defaultDependencyExtractor.extract,
@@ -7,7 +7,9 @@ module.exports = class Worker {
7
7
  #hasteImpl = null;
8
8
  constructor({ hasteImplModulePath }) {
9
9
  if (hasteImplModulePath != null) {
10
- this.#hasteImpl = require(hasteImplModulePath);
10
+ const mod = require(hasteImplModulePath);
11
+ this.#hasteImpl =
12
+ mod.__esModule === true && "default" in mod ? mod.default : mod;
11
13
  }
12
14
  }
13
15
  processFile(data, utils) {
@@ -22,7 +22,7 @@ import type {MetadataWorker, WorkerMessage, V8Serializable} from '../../flow-typ
22
22
  const PACKAGE_JSON = path.sep + 'package.json';
23
23
 
24
24
  module.exports = class Worker /*:: implements MetadataWorker */ {
25
- /*:: + */ #hasteImpl /*: ?Readonly<{getHasteName: string => ?string}> */ =
25
+ /*:: readonly */ #hasteImpl /*: ?Readonly<{getHasteName: string => ?string}> */ =
26
26
  null;
27
27
 
28
28
  constructor(
@@ -30,7 +30,9 @@ module.exports = class Worker /*:: implements MetadataWorker */ {
30
30
  ) {
31
31
  if (hasteImplModulePath != null) {
32
32
  // $FlowFixMe[unsupported-syntax] - dynamic require
33
- this.#hasteImpl = require(hasteImplModulePath);
33
+ const mod = require(hasteImplModulePath);
34
+ this.#hasteImpl =
35
+ mod.__esModule === true && 'default' in mod ? mod.default : mod;
34
36
  }
35
37
  }
36
38
 
@@ -24,11 +24,11 @@ export type Listeners = Readonly<{
24
24
  }>;
25
25
 
26
26
  export class AbstractWatcher implements WatcherBackend {
27
- +root: string;
28
- +ignored: ?RegExp;
29
- +globs: ReadonlyArray<string>;
30
- +dot: boolean;
31
- +doIgnore: (path: string) => boolean;
27
+ readonly root: string;
28
+ readonly ignored: ?RegExp;
29
+ readonly globs: ReadonlyArray<string>;
30
+ readonly dot: boolean;
31
+ readonly doIgnore: (path: string) => boolean;
32
32
 
33
33
  #emitter: EventEmitter = new EventEmitter();
34
34
 
@@ -42,12 +42,13 @@ const DELETE_EVENT = common.DELETE_EVENT;
42
42
  const DEBOUNCE_MS = 100;
43
43
 
44
44
  export default class FallbackWatcher extends AbstractWatcher {
45
- +#changeTimers: Map<string, TimeoutID> = new Map();
46
- +#dirRegistry: {
45
+ readonly #changeTimers: Map<string, TimeoutID> = new Map();
46
+ readonly #dirRegistry: {
47
47
  [directory: string]: {[file: string]: true, __proto__: null},
48
48
  __proto__: null,
49
49
  } = Object.create(null);
50
- +#watched: {[key: string]: FSWatcher, __proto__: null} = Object.create(null);
50
+ readonly #watched: {[key: string]: FSWatcher, __proto__: null} =
51
+ Object.create(null);
51
52
 
52
53
  async startWatching(): Promise<void> {
53
54
  this.#watchdir(this.root);
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  * @noformat
8
- * @generated SignedSource<<b68c5620efd3f5bec83279059d0d1b4e>>
8
+ * @generated SignedSource<<6297e6ebfbeb2920f00b15cba9acbce2>>
9
9
  *
10
10
  * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
11
11
  * Original file: packages/metro-file-map/src/watchers/NativeWatcher.js
@@ -50,6 +50,5 @@ declare class NativeWatcher extends AbstractWatcher {
50
50
  * End watching.
51
51
  */
52
52
  stopWatching(): Promise<void>;
53
- _handleEvent(event: string, relativePath: string): void;
54
53
  }
55
54
  export default NativeWatcher;
@@ -41,12 +41,12 @@ const SUB_PREFIX = 'metro-file-map';
41
41
  */
42
42
  export default class WatchmanWatcher extends AbstractWatcher {
43
43
  #client: Client;
44
- +subscriptionName: string;
44
+ readonly subscriptionName: string;
45
45
  #watchProjectInfo: ?Readonly<{
46
46
  relativePath: string,
47
47
  root: string,
48
48
  }>;
49
- +#watchmanDeferStates: ReadonlyArray<string>;
49
+ readonly #watchmanDeferStates: ReadonlyArray<string>;
50
50
  #deferringStates: ?Set<string> = null;
51
51
 
52
52
  constructor(dir: string, opts: WatcherOptions) {
package/src/worker.js CHANGED
@@ -9,7 +9,9 @@ class Worker {
9
9
  #plugins;
10
10
  constructor({ plugins = [] }) {
11
11
  this.#plugins = plugins.map(({ modulePath, setupArgs }) => {
12
- const PluginWorker = require(modulePath);
12
+ const mod = require(modulePath);
13
+ const PluginWorker =
14
+ mod.__esModule === true && "default" in mod ? mod.default : mod;
13
15
  return new PluginWorker(setupArgs);
14
16
  });
15
17
  }
@@ -36,7 +36,9 @@ class Worker {
36
36
  constructor({plugins = []} /*: WorkerSetupArgs */) {
37
37
  this.#plugins = plugins.map(({modulePath, setupArgs}) => {
38
38
  // $FlowFixMe[unsupported-syntax] - dynamic require
39
- const PluginWorker = require(modulePath);
39
+ const mod = require(modulePath);
40
+ const PluginWorker =
41
+ mod.__esModule === true && 'default' in mod ? mod.default : mod;
40
42
  return new PluginWorker(setupArgs);
41
43
  });
42
44
  }
@@ -1,19 +0,0 @@
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<<8b6ff8a24f9156cd7991006c72edd296>>
10
- *
11
- * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
- * Original file: packages/metro-file-map/src/crawlers/node/hasNativeFindSupport.js
13
- * To regenerate, run:
14
- * js1 build metro-ts-defs (internal) OR
15
- * yarn run build-ts-defs (OSS)
16
- */
17
-
18
- declare function hasNativeFindSupport(): Promise<boolean>;
19
- export default hasNativeFindSupport;
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true,
5
- });
6
- exports.default = hasNativeFindSupport;
7
- var _child_process = require("child_process");
8
- async function hasNativeFindSupport() {
9
- try {
10
- return await new Promise((resolve) => {
11
- const args = [
12
- ".",
13
- "-type",
14
- "f",
15
- "(",
16
- "-iname",
17
- "*.ts",
18
- "-o",
19
- "-iname",
20
- "*.js",
21
- ")",
22
- ];
23
- const child = (0, _child_process.spawn)("find", args, {
24
- cwd: __dirname,
25
- });
26
- child.on("error", () => {
27
- resolve(false);
28
- });
29
- child.on("exit", (code) => {
30
- resolve(code === 0);
31
- });
32
- });
33
- } catch {
34
- return false;
35
- }
36
- }
@@ -1,41 +0,0 @@
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 {spawn} from 'child_process';
13
-
14
- export default async function hasNativeFindSupport(): Promise<boolean> {
15
- try {
16
- return await new Promise(resolve => {
17
- // Check the find binary supports the non-POSIX -iname parameter wrapped in parens.
18
- const args = [
19
- '.',
20
- '-type',
21
- 'f',
22
- '(',
23
- '-iname',
24
- '*.ts',
25
- '-o',
26
- '-iname',
27
- '*.js',
28
- ')',
29
- ];
30
- const child = spawn('find', args, {cwd: __dirname});
31
- child.on('error', () => {
32
- resolve(false);
33
- });
34
- child.on('exit', code => {
35
- resolve(code === 0);
36
- });
37
- });
38
- } catch {
39
- return false;
40
- }
41
- }