metro-file-map 0.84.3 → 0.84.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metro-file-map",
3
- "version": "0.84.3",
3
+ "version": "0.84.4",
4
4
  "description": "[Experimental] - 🚇 File crawling, watching and mapping for Metro",
5
5
  "main": "src/index.js",
6
6
  "exports": {
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @noformat
8
8
  * @oncall react_native
9
- * @generated SignedSource<<e07a9c061b0224fc44191d956461bd6f>>
9
+ * @generated SignedSource<<344b340710d6da24bcb609058e7ce8d6>>
10
10
  *
11
11
  * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
12
  * Original file: packages/metro-file-map/src/plugins/DependencyPlugin.js
@@ -15,38 +15,18 @@
15
15
  * yarn run build-ts-defs (OSS)
16
16
  */
17
17
 
18
- import type {
19
- FileMapPlugin,
20
- FileMapPluginInitOptions,
21
- FileMapPluginWorker,
22
- Path,
23
- } from '../flow-types';
18
+ import type {Path} from '../flow-types';
19
+
20
+ import FileDataPlugin from './FileDataPlugin';
24
21
 
25
22
  export type DependencyPluginOptions = Readonly<{
26
23
  /** Path to custom dependency extractor module */
27
24
  dependencyExtractor: null | undefined | string;
28
25
  /** Whether to compute dependencies (performance optimization) */
29
26
  computeDependencies: boolean;
30
- rootDir: Path;
31
27
  }>;
32
- declare class DependencyPlugin
33
- implements FileMapPlugin<null, ReadonlyArray<string> | null>
34
- {
35
- readonly name: 'dependencies';
28
+ declare class DependencyPlugin extends FileDataPlugin<ReadonlyArray<string> | null> {
36
29
  constructor(options: DependencyPluginOptions);
37
- initialize(
38
- initOptions: FileMapPluginInitOptions<null, ReadonlyArray<string> | null>,
39
- ): Promise<void>;
40
- getSerializableSnapshot(): null;
41
- onChanged(): void;
42
- assertValid(): void;
43
- getCacheKey(): string;
44
- getWorker(): FileMapPluginWorker;
45
- /**
46
- * Get the list of dependencies for a given file.
47
- * @param mixedPath Absolute or project-relative path to the file
48
- * @returns Array of dependency module names, or null if the file doesn't exist
49
- */
50
30
  getDependencies(mixedPath: Path): null | undefined | ReadonlyArray<string>;
51
31
  }
52
32
  export default DependencyPlugin;
@@ -4,70 +4,50 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true,
5
5
  });
6
6
  exports.default = void 0;
7
- class DependencyPlugin {
8
- name = "dependencies";
9
- #dependencyExtractor;
10
- #computeDependencies;
11
- #getDependencies;
12
- #rootDir;
7
+ var _workerExclusionList = _interopRequireDefault(
8
+ require("../workerExclusionList"),
9
+ );
10
+ var _FileDataPlugin = _interopRequireDefault(require("./FileDataPlugin"));
11
+ function _interopRequireDefault(e) {
12
+ return e && e.__esModule ? e : { default: e };
13
+ }
14
+ class DependencyPlugin extends _FileDataPlugin.default {
13
15
  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
- onChanged() {}
32
- assertValid() {}
33
- getCacheKey() {
34
- if (this.#dependencyExtractor != null) {
35
- const extractor = require(this.#dependencyExtractor);
36
- return JSON.stringify({
37
- extractorKey: extractor.getCacheKey?.() ?? null,
38
- extractorPath: this.#dependencyExtractor,
39
- });
16
+ const { dependencyExtractor, computeDependencies } = options;
17
+ let cacheKey;
18
+ if (dependencyExtractor != null) {
19
+ const extractor = require(dependencyExtractor);
20
+ cacheKey = extractor.getCacheKey?.() ?? dependencyExtractor;
21
+ } else {
22
+ cacheKey = "default-dependency-extractor";
40
23
  }
41
- return "default-dependency-extractor";
42
- }
43
- getWorker() {
44
- const excludedExtensions = require("../workerExclusionList");
45
- return {
24
+ super({
25
+ name: "dependencies",
26
+ cacheKey,
46
27
  worker: {
47
28
  modulePath: require.resolve("./dependencies/worker.js"),
48
29
  setupArgs: {
49
- dependencyExtractor: this.#dependencyExtractor ?? null,
30
+ dependencyExtractor: dependencyExtractor ?? null,
50
31
  },
51
32
  },
52
33
  filter: ({ normalPath, isNodeModules }) => {
53
- if (!this.#computeDependencies) {
34
+ if (!computeDependencies) {
54
35
  return false;
55
36
  }
56
37
  if (isNodeModules) {
57
38
  return false;
58
39
  }
59
40
  const ext = normalPath.substr(normalPath.lastIndexOf("."));
60
- return !excludedExtensions.has(ext);
41
+ return !_workerExclusionList.default.has(ext);
61
42
  },
62
- };
43
+ });
63
44
  }
64
45
  getDependencies(mixedPath) {
65
- if (this.#getDependencies == null) {
66
- throw new Error(
67
- "DependencyPlugin has not been initialized before getDependencies",
68
- );
46
+ const result = this.getFileSystem().lookup(mixedPath);
47
+ if (result.exists && result.type === "f") {
48
+ return result.pluginData ?? [];
69
49
  }
70
- return this.#getDependencies(mixedPath);
50
+ return null;
71
51
  }
72
52
  }
73
53
  exports.default = DependencyPlugin;
@@ -9,121 +9,58 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- import type {
13
- FileMapPlugin,
14
- FileMapPluginInitOptions,
15
- FileMapPluginWorker,
16
- Path,
17
- } from '../flow-types';
12
+ import type {Path} from '../flow-types';
13
+
14
+ import excludedExtensions from '../workerExclusionList';
15
+ import FileDataPlugin from './FileDataPlugin';
18
16
 
19
17
  export type DependencyPluginOptions = Readonly<{
20
18
  /** Path to custom dependency extractor module */
21
19
  dependencyExtractor: ?string,
22
20
  /** Whether to compute dependencies (performance optimization) */
23
21
  computeDependencies: boolean,
24
- rootDir: Path,
25
22
  }>;
26
23
 
27
- export default class DependencyPlugin
28
- implements FileMapPlugin<null, ReadonlyArray<string> | null>
29
- {
30
- +name: 'dependencies' = 'dependencies';
31
-
32
- #dependencyExtractor: ?string;
33
- #computeDependencies: boolean;
34
- #getDependencies: Path => ?ReadonlyArray<string>;
35
- #rootDir: Path;
36
-
24
+ export default class DependencyPlugin extends FileDataPlugin<ReadonlyArray<string> | null> {
37
25
  constructor(options: DependencyPluginOptions) {
38
- this.#dependencyExtractor = options.dependencyExtractor;
39
- this.#computeDependencies = options.computeDependencies;
40
- this.#rootDir = options.rootDir;
41
- }
42
-
43
- async initialize(
44
- initOptions: FileMapPluginInitOptions<null, ReadonlyArray<string> | null>,
45
- ): Promise<void> {
46
- const {files} = initOptions;
47
- // Create closure to access dependencies from file metadata plugin data
48
- this.#getDependencies = (mixedPath: Path) => {
49
- const result = files.lookup(mixedPath);
50
- if (result.exists && result.type === 'f') {
51
- // Backwards compatibility: distinguish an extant file that we've not
52
- // run the worker on (probably because it fails the extension filter)
53
- // from a missing file. Non-source files are expected to have empty
54
- // dependencies.
55
- return result.pluginData ?? [];
56
- }
57
- return null;
58
- };
59
- }
60
-
61
- getSerializableSnapshot(): null {
62
- // Dependencies stored in plugin data, no separate serialization needed
63
- return null;
64
- }
26
+ const {dependencyExtractor, computeDependencies} = options;
65
27
 
66
- onChanged(): void {
67
- // No-op: Worker already populated plugin data
68
- // Plugin data is write-only from worker
69
- }
70
-
71
- assertValid(): void {
72
- // No validation needed
73
- }
74
-
75
- getCacheKey(): string {
76
- if (this.#dependencyExtractor != null) {
77
- // Dynamic require to get extractor's cache key
28
+ let cacheKey: string;
29
+ if (dependencyExtractor != null) {
78
30
  // $FlowFixMe[unsupported-syntax] - dynamic require
79
- const extractor = require(this.#dependencyExtractor);
80
- return JSON.stringify({
81
- extractorKey: extractor.getCacheKey?.() ?? null,
82
- extractorPath: this.#dependencyExtractor,
83
- });
31
+ const extractor = require(dependencyExtractor);
32
+ cacheKey = extractor.getCacheKey?.() ?? dependencyExtractor;
33
+ } else {
34
+ cacheKey = 'default-dependency-extractor';
84
35
  }
85
- return 'default-dependency-extractor';
86
- }
87
36
 
88
- getWorker(): FileMapPluginWorker {
89
- const excludedExtensions = require('../workerExclusionList');
90
-
91
- return {
37
+ super({
38
+ name: 'dependencies',
39
+ cacheKey,
92
40
  worker: {
93
41
  modulePath: require.resolve('./dependencies/worker.js'),
94
42
  setupArgs: {
95
- dependencyExtractor: this.#dependencyExtractor ?? null,
43
+ dependencyExtractor: dependencyExtractor ?? null,
96
44
  },
97
45
  },
98
46
  filter: ({normalPath, isNodeModules}) => {
99
- // Respect computeDependencies flag
100
- if (!this.#computeDependencies) {
47
+ if (!computeDependencies) {
101
48
  return false;
102
49
  }
103
-
104
- // Never process node_modules
105
50
  if (isNodeModules) {
106
51
  return false;
107
52
  }
108
-
109
- // Skip excluded extensions
110
53
  const ext = normalPath.substr(normalPath.lastIndexOf('.'));
111
54
  return !excludedExtensions.has(ext);
112
55
  },
113
- };
56
+ });
114
57
  }
115
58
 
116
- /**
117
- * Get the list of dependencies for a given file.
118
- * @param mixedPath Absolute or project-relative path to the file
119
- * @returns Array of dependency module names, or null if the file doesn't exist
120
- */
121
59
  getDependencies(mixedPath: Path): ?ReadonlyArray<string> {
122
- if (this.#getDependencies == null) {
123
- throw new Error(
124
- 'DependencyPlugin has not been initialized before getDependencies',
125
- );
60
+ const result = this.getFileSystem().lookup(mixedPath);
61
+ if (result.exists && result.type === 'f') {
62
+ return result.pluginData ?? [];
126
63
  }
127
- return this.#getDependencies(mixedPath);
64
+ return null;
128
65
  }
129
66
  }
@@ -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
+ * @oncall react_native
9
+ * @generated SignedSource<<8833f226ec9fa3a4c96370862ca4d59f>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro-file-map/src/plugins/FileDataPlugin.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 {
19
+ FileMapPlugin,
20
+ FileMapPluginInitOptions,
21
+ FileMapPluginWorker,
22
+ ReadonlyFileSystemChanges,
23
+ V8Serializable,
24
+ } from '../flow-types';
25
+
26
+ export type FileDataPluginOptions = Readonly<
27
+ Omit<FileMapPluginWorker, keyof {name: string; cacheKey: string}> & {
28
+ name: string;
29
+ cacheKey: string;
30
+ }
31
+ >;
32
+ /**
33
+ * Base class for FileMap plugins that store per-file data via a worker and
34
+ * have no separate serializable state. Provides default no-op implementations
35
+ * of lifecycle methods that subclasses can override as needed.
36
+ */
37
+ declare class FileDataPlugin<
38
+ PerFileData extends void | V8Serializable = void | V8Serializable,
39
+ > implements FileMapPlugin<null, PerFileData>
40
+ {
41
+ readonly name: string;
42
+ constructor($$PARAM_0$$: FileDataPluginOptions);
43
+ initialize(
44
+ initOptions: FileMapPluginInitOptions<null, PerFileData>,
45
+ ): Promise<void>;
46
+ getFileSystem(): FileMapPluginInitOptions<null, PerFileData>['files'];
47
+ onChanged(
48
+ _changes: ReadonlyFileSystemChanges<null | undefined | PerFileData>,
49
+ ): void;
50
+ assertValid(): void;
51
+ getSerializableSnapshot(): null;
52
+ getCacheKey(): string;
53
+ getWorker(): FileMapPluginWorker;
54
+ }
55
+ export default FileDataPlugin;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = void 0;
7
+ class FileDataPlugin {
8
+ #worker;
9
+ #cacheKey;
10
+ #files;
11
+ constructor({ name, worker, filter, cacheKey }) {
12
+ this.name = name;
13
+ this.#worker = {
14
+ worker,
15
+ filter,
16
+ };
17
+ this.#cacheKey = cacheKey;
18
+ }
19
+ async initialize(initOptions) {
20
+ this.#files = initOptions.files;
21
+ }
22
+ getFileSystem() {
23
+ const files = this.#files;
24
+ if (files == null) {
25
+ throw new Error(`${this.name} plugin has not been initialized`);
26
+ }
27
+ return files;
28
+ }
29
+ onChanged(_changes) {}
30
+ assertValid() {}
31
+ getSerializableSnapshot() {
32
+ return null;
33
+ }
34
+ getCacheKey() {
35
+ return this.#cacheKey;
36
+ }
37
+ getWorker() {
38
+ return this.#worker;
39
+ }
40
+ }
41
+ exports.default = FileDataPlugin;
@@ -0,0 +1,76 @@
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
+ FileMapPlugin,
14
+ FileMapPluginInitOptions,
15
+ FileMapPluginWorker,
16
+ ReadonlyFileSystemChanges,
17
+ V8Serializable,
18
+ } from '../flow-types';
19
+
20
+ export type FileDataPluginOptions = Readonly<{
21
+ ...FileMapPluginWorker,
22
+ name: string,
23
+ cacheKey: string,
24
+ }>;
25
+
26
+ /**
27
+ * Base class for FileMap plugins that store per-file data via a worker and
28
+ * have no separate serializable state. Provides default no-op implementations
29
+ * of lifecycle methods that subclasses can override as needed.
30
+ */
31
+ export default class FileDataPlugin<
32
+ -PerFileData extends void | V8Serializable = void | V8Serializable,
33
+ > implements FileMapPlugin<null, PerFileData>
34
+ {
35
+ +name: string;
36
+
37
+ #worker: FileMapPluginWorker;
38
+ #cacheKey: string;
39
+ #files: ?FileMapPluginInitOptions<null, PerFileData>['files'];
40
+
41
+ constructor({name, worker, filter, cacheKey}: FileDataPluginOptions) {
42
+ this.name = name;
43
+ this.#worker = {worker, filter};
44
+ this.#cacheKey = cacheKey;
45
+ }
46
+
47
+ async initialize(
48
+ initOptions: FileMapPluginInitOptions<null, PerFileData>,
49
+ ): Promise<void> {
50
+ this.#files = initOptions.files;
51
+ }
52
+
53
+ getFileSystem(): FileMapPluginInitOptions<null, PerFileData>['files'] {
54
+ const files = this.#files;
55
+ if (files == null) {
56
+ throw new Error(`${this.name} plugin has not been initialized`);
57
+ }
58
+ return files;
59
+ }
60
+
61
+ onChanged(_changes: ReadonlyFileSystemChanges<?PerFileData>): void {}
62
+
63
+ assertValid(): void {}
64
+
65
+ getSerializableSnapshot(): null {
66
+ return null;
67
+ }
68
+
69
+ getCacheKey(): string {
70
+ return this.#cacheKey;
71
+ }
72
+
73
+ getWorker(): FileMapPluginWorker {
74
+ return this.#worker;
75
+ }
76
+ }