metro-file-map 0.84.2 → 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 +1 -1
- package/src/Watcher.d.ts +6 -9
- package/src/Watcher.js +66 -39
- package/src/Watcher.js.flow +84 -51
- package/src/crawlers/node/index.d.ts +3 -5
- package/src/crawlers/node/index.js +4 -1
- package/src/crawlers/node/index.js.flow +8 -6
- package/src/crawlers/watchman/index.d.ts +5 -12
- package/src/crawlers/watchman/index.js.flow +2 -6
- package/src/flow-types.d.ts +81 -32
- package/src/flow-types.js.flow +89 -29
- package/src/index.d.ts +4 -4
- package/src/index.js +145 -120
- package/src/index.js.flow +199 -149
- package/src/lib/FileSystemChangeAggregator.d.ts +40 -0
- package/src/lib/FileSystemChangeAggregator.js +89 -0
- package/src/lib/FileSystemChangeAggregator.js.flow +143 -0
- package/src/lib/TreeFS.d.ts +16 -8
- package/src/lib/TreeFS.js +67 -16
- package/src/lib/TreeFS.js.flow +89 -16
- package/src/plugins/DependencyPlugin.d.ts +5 -36
- package/src/plugins/DependencyPlugin.js +26 -48
- package/src/plugins/DependencyPlugin.js.flow +22 -100
- package/src/plugins/FileDataPlugin.d.ts +55 -0
- package/src/plugins/FileDataPlugin.js +41 -0
- package/src/plugins/FileDataPlugin.js.flow +76 -0
- package/src/plugins/HastePlugin.d.ts +3 -11
- package/src/plugins/HastePlugin.js +11 -11
- package/src/plugins/HastePlugin.js.flow +12 -12
- package/src/plugins/MockPlugin.d.ts +3 -5
- package/src/plugins/MockPlugin.js +17 -20
- package/src/plugins/MockPlugin.js.flow +18 -22
- package/src/watchers/FallbackWatcher.js +19 -3
- package/src/watchers/FallbackWatcher.js.flow +28 -5
- package/src/watchers/NativeWatcher.d.ts +2 -2
- package/src/watchers/NativeWatcher.js +27 -5
- package/src/watchers/NativeWatcher.js.flow +33 -6
- package/src/watchers/common.d.ts +3 -1
- package/src/watchers/common.js +6 -1
- package/src/watchers/common.js.flow +1 -0
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @noformat
|
|
8
8
|
* @oncall react_native
|
|
9
|
-
* @generated SignedSource<<
|
|
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,49 +15,18 @@
|
|
|
15
15
|
* yarn run build-ts-defs (OSS)
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import type {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
FileMapPluginInitOptions,
|
|
22
|
-
FileMapPluginWorker,
|
|
23
|
-
Path,
|
|
24
|
-
} from '../flow-types';
|
|
18
|
+
import type {Path} from '../flow-types';
|
|
19
|
+
|
|
20
|
+
import FileDataPlugin from './FileDataPlugin';
|
|
25
21
|
|
|
26
22
|
export type DependencyPluginOptions = Readonly<{
|
|
27
23
|
/** Path to custom dependency extractor module */
|
|
28
24
|
dependencyExtractor: null | undefined | string;
|
|
29
25
|
/** Whether to compute dependencies (performance optimization) */
|
|
30
26
|
computeDependencies: boolean;
|
|
31
|
-
rootDir: Path;
|
|
32
27
|
}>;
|
|
33
|
-
declare class DependencyPlugin
|
|
34
|
-
implements FileMapPlugin<null, ReadonlyArray<string> | null>
|
|
35
|
-
{
|
|
36
|
-
readonly name: 'dependencies';
|
|
28
|
+
declare class DependencyPlugin extends FileDataPlugin<ReadonlyArray<string> | null> {
|
|
37
29
|
constructor(options: DependencyPluginOptions);
|
|
38
|
-
initialize(
|
|
39
|
-
initOptions: FileMapPluginInitOptions<null, ReadonlyArray<string> | null>,
|
|
40
|
-
): Promise<void>;
|
|
41
|
-
getSerializableSnapshot(): null;
|
|
42
|
-
bulkUpdate(
|
|
43
|
-
delta: FileMapDelta<null | undefined | ReadonlyArray<string>>,
|
|
44
|
-
): void;
|
|
45
|
-
onNewOrModifiedFile(
|
|
46
|
-
relativeFilePath: string,
|
|
47
|
-
pluginData: null | undefined | ReadonlyArray<string>,
|
|
48
|
-
): void;
|
|
49
|
-
onRemovedFile(
|
|
50
|
-
relativeFilePath: string,
|
|
51
|
-
pluginData: null | undefined | ReadonlyArray<string>,
|
|
52
|
-
): void;
|
|
53
|
-
assertValid(): void;
|
|
54
|
-
getCacheKey(): string;
|
|
55
|
-
getWorker(): FileMapPluginWorker;
|
|
56
|
-
/**
|
|
57
|
-
* Get the list of dependencies for a given file.
|
|
58
|
-
* @param mixedPath Absolute or project-relative path to the file
|
|
59
|
-
* @returns Array of dependency module names, or null if the file doesn't exist
|
|
60
|
-
*/
|
|
61
30
|
getDependencies(mixedPath: Path): null | undefined | ReadonlyArray<string>;
|
|
62
31
|
}
|
|
63
32
|
export default DependencyPlugin;
|
|
@@ -4,72 +4,50 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true,
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
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
|
-
});
|
|
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";
|
|
42
23
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const excludedExtensions = require("../workerExclusionList");
|
|
47
|
-
return {
|
|
24
|
+
super({
|
|
25
|
+
name: "dependencies",
|
|
26
|
+
cacheKey,
|
|
48
27
|
worker: {
|
|
49
28
|
modulePath: require.resolve("./dependencies/worker.js"),
|
|
50
29
|
setupArgs: {
|
|
51
|
-
dependencyExtractor:
|
|
30
|
+
dependencyExtractor: dependencyExtractor ?? null,
|
|
52
31
|
},
|
|
53
32
|
},
|
|
54
33
|
filter: ({ normalPath, isNodeModules }) => {
|
|
55
|
-
if (!
|
|
34
|
+
if (!computeDependencies) {
|
|
56
35
|
return false;
|
|
57
36
|
}
|
|
58
37
|
if (isNodeModules) {
|
|
59
38
|
return false;
|
|
60
39
|
}
|
|
61
40
|
const ext = normalPath.substr(normalPath.lastIndexOf("."));
|
|
62
|
-
return !
|
|
41
|
+
return !_workerExclusionList.default.has(ext);
|
|
63
42
|
},
|
|
64
|
-
};
|
|
43
|
+
});
|
|
65
44
|
}
|
|
66
45
|
getDependencies(mixedPath) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
);
|
|
46
|
+
const result = this.getFileSystem().lookup(mixedPath);
|
|
47
|
+
if (result.exists && result.type === "f") {
|
|
48
|
+
return result.pluginData ?? [];
|
|
71
49
|
}
|
|
72
|
-
return
|
|
50
|
+
return null;
|
|
73
51
|
}
|
|
74
52
|
}
|
|
75
53
|
exports.default = DependencyPlugin;
|
|
@@ -9,136 +9,58 @@
|
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import type {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
FileMapPluginWorker,
|
|
17
|
-
Path,
|
|
18
|
-
} from '../flow-types';
|
|
12
|
+
import type {Path} from '../flow-types';
|
|
13
|
+
|
|
14
|
+
import excludedExtensions from '../workerExclusionList';
|
|
15
|
+
import FileDataPlugin from './FileDataPlugin';
|
|
19
16
|
|
|
20
17
|
export type DependencyPluginOptions = Readonly<{
|
|
21
18
|
/** Path to custom dependency extractor module */
|
|
22
19
|
dependencyExtractor: ?string,
|
|
23
20
|
/** Whether to compute dependencies (performance optimization) */
|
|
24
21
|
computeDependencies: boolean,
|
|
25
|
-
rootDir: Path,
|
|
26
22
|
}>;
|
|
27
23
|
|
|
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
|
-
|
|
24
|
+
export default class DependencyPlugin extends FileDataPlugin<ReadonlyArray<string> | null> {
|
|
38
25
|
constructor(options: DependencyPluginOptions) {
|
|
39
|
-
|
|
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
|
-
bulkUpdate(delta: FileMapDelta<?ReadonlyArray<string>>): void {
|
|
68
|
-
// No-op: Worker already populated plugin data
|
|
69
|
-
// Plugin data is write-only from worker
|
|
70
|
-
}
|
|
26
|
+
const {dependencyExtractor, computeDependencies} = options;
|
|
71
27
|
|
|
72
|
-
|
|
73
|
-
|
|
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
|
|
28
|
+
let cacheKey: string;
|
|
29
|
+
if (dependencyExtractor != null) {
|
|
93
30
|
// $FlowFixMe[unsupported-syntax] - dynamic require
|
|
94
|
-
const extractor = require(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
31
|
+
const extractor = require(dependencyExtractor);
|
|
32
|
+
cacheKey = extractor.getCacheKey?.() ?? dependencyExtractor;
|
|
33
|
+
} else {
|
|
34
|
+
cacheKey = 'default-dependency-extractor';
|
|
99
35
|
}
|
|
100
|
-
return 'default-dependency-extractor';
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
getWorker(): FileMapPluginWorker {
|
|
104
|
-
const excludedExtensions = require('../workerExclusionList');
|
|
105
36
|
|
|
106
|
-
|
|
37
|
+
super({
|
|
38
|
+
name: 'dependencies',
|
|
39
|
+
cacheKey,
|
|
107
40
|
worker: {
|
|
108
41
|
modulePath: require.resolve('./dependencies/worker.js'),
|
|
109
42
|
setupArgs: {
|
|
110
|
-
dependencyExtractor:
|
|
43
|
+
dependencyExtractor: dependencyExtractor ?? null,
|
|
111
44
|
},
|
|
112
45
|
},
|
|
113
46
|
filter: ({normalPath, isNodeModules}) => {
|
|
114
|
-
|
|
115
|
-
if (!this.#computeDependencies) {
|
|
47
|
+
if (!computeDependencies) {
|
|
116
48
|
return false;
|
|
117
49
|
}
|
|
118
|
-
|
|
119
|
-
// Never process node_modules
|
|
120
50
|
if (isNodeModules) {
|
|
121
51
|
return false;
|
|
122
52
|
}
|
|
123
|
-
|
|
124
|
-
// Skip excluded extensions
|
|
125
53
|
const ext = normalPath.substr(normalPath.lastIndexOf('.'));
|
|
126
54
|
return !excludedExtensions.has(ext);
|
|
127
55
|
},
|
|
128
|
-
};
|
|
56
|
+
});
|
|
129
57
|
}
|
|
130
58
|
|
|
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
59
|
getDependencies(mixedPath: Path): ?ReadonlyArray<string> {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
);
|
|
60
|
+
const result = this.getFileSystem().lookup(mixedPath);
|
|
61
|
+
if (result.exists && result.type === 'f') {
|
|
62
|
+
return result.pluginData ?? [];
|
|
141
63
|
}
|
|
142
|
-
return
|
|
64
|
+
return null;
|
|
143
65
|
}
|
|
144
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
|
+
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @noformat
|
|
8
8
|
* @oncall react_native
|
|
9
|
-
* @generated SignedSource<<
|
|
9
|
+
* @generated SignedSource<<3d1462ab2325a09553e02b69b5de84eb>>
|
|
10
10
|
*
|
|
11
11
|
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
12
|
* Original file: packages/metro-file-map/src/plugins/HastePlugin.js
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
|
|
18
18
|
import type {
|
|
19
19
|
Console,
|
|
20
|
-
FileMapDelta,
|
|
21
20
|
FileMapPlugin,
|
|
22
21
|
FileMapPluginInitOptions,
|
|
23
22
|
FileMapPluginWorker,
|
|
@@ -27,6 +26,7 @@ import type {
|
|
|
27
26
|
HTypeValue,
|
|
28
27
|
Path,
|
|
29
28
|
PerfLogger,
|
|
29
|
+
ReadonlyFileSystemChanges,
|
|
30
30
|
} from '../flow-types';
|
|
31
31
|
|
|
32
32
|
export type HasteMapOptions = Readonly<{
|
|
@@ -59,16 +59,8 @@ declare class HastePlugin
|
|
|
59
59
|
platform: null | undefined | string,
|
|
60
60
|
_supportsNativePlatform?: null | undefined | boolean,
|
|
61
61
|
): null | undefined | Path;
|
|
62
|
-
|
|
63
|
-
onNewOrModifiedFile(
|
|
64
|
-
relativeFilePath: string,
|
|
65
|
-
id: null | undefined | string,
|
|
66
|
-
): void;
|
|
62
|
+
onChanged(delta: ReadonlyFileSystemChanges<null | undefined | string>): void;
|
|
67
63
|
setModule(id: string, module: HasteMapItemMetadata): void;
|
|
68
|
-
onRemovedFile(
|
|
69
|
-
relativeFilePath: string,
|
|
70
|
-
moduleName: null | undefined | string,
|
|
71
|
-
): void;
|
|
72
64
|
assertValid(): void;
|
|
73
65
|
computeConflicts(): Array<HasteConflict>;
|
|
74
66
|
getCacheKey(): string;
|
|
@@ -163,22 +163,22 @@ class HastePlugin {
|
|
|
163
163
|
duplicates,
|
|
164
164
|
);
|
|
165
165
|
}
|
|
166
|
-
|
|
167
|
-
for (const [
|
|
168
|
-
this
|
|
166
|
+
onChanged(delta) {
|
|
167
|
+
for (const [canonicalPath, maybeHasteId] of delta.removedFiles) {
|
|
168
|
+
this.#onRemovedFile(canonicalPath, maybeHasteId);
|
|
169
169
|
}
|
|
170
|
-
for (const [
|
|
171
|
-
this
|
|
170
|
+
for (const [canonicalPath, maybeHasteId] of delta.addedFiles) {
|
|
171
|
+
this.#onNewFile(canonicalPath, maybeHasteId);
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
|
|
174
|
+
#onNewFile(canonicalPath, id) {
|
|
175
175
|
if (id == null) {
|
|
176
176
|
return;
|
|
177
177
|
}
|
|
178
178
|
const module = [
|
|
179
|
-
|
|
179
|
+
canonicalPath,
|
|
180
180
|
this.#enableHastePackages &&
|
|
181
|
-
_path.default.basename(
|
|
181
|
+
_path.default.basename(canonicalPath) === "package.json"
|
|
182
182
|
? _constants.default.PACKAGE
|
|
183
183
|
: _constants.default.MODULE,
|
|
184
184
|
];
|
|
@@ -248,12 +248,12 @@ class HastePlugin {
|
|
|
248
248
|
}
|
|
249
249
|
hasteMapItem[platform] = module;
|
|
250
250
|
}
|
|
251
|
-
onRemovedFile(
|
|
251
|
+
#onRemovedFile(canonicalPath, moduleName) {
|
|
252
252
|
if (moduleName == null) {
|
|
253
253
|
return;
|
|
254
254
|
}
|
|
255
255
|
const platform =
|
|
256
|
-
(0, _getPlatformExtension.default)(
|
|
256
|
+
(0, _getPlatformExtension.default)(canonicalPath, this.#platforms) ||
|
|
257
257
|
_constants.default.GENERIC_PLATFORM;
|
|
258
258
|
const hasteMapItem = this.#map.get(moduleName);
|
|
259
259
|
if (hasteMapItem != null) {
|
|
@@ -264,7 +264,7 @@ class HastePlugin {
|
|
|
264
264
|
this.#map.set(moduleName, hasteMapItem);
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
|
-
this.#recoverDuplicates(moduleName,
|
|
267
|
+
this.#recoverDuplicates(moduleName, canonicalPath);
|
|
268
268
|
}
|
|
269
269
|
assertValid() {
|
|
270
270
|
if (!this.#failValidationOnConflicts) {
|
|
@@ -13,7 +13,6 @@ import type {
|
|
|
13
13
|
Console,
|
|
14
14
|
DuplicatesIndex,
|
|
15
15
|
DuplicatesSet,
|
|
16
|
-
FileMapDelta,
|
|
17
16
|
FileMapPlugin,
|
|
18
17
|
FileMapPluginInitOptions,
|
|
19
18
|
FileMapPluginWorker,
|
|
@@ -24,6 +23,7 @@ import type {
|
|
|
24
23
|
HTypeValue,
|
|
25
24
|
Path,
|
|
26
25
|
PerfLogger,
|
|
26
|
+
ReadonlyFileSystemChanges,
|
|
27
27
|
} from '../flow-types';
|
|
28
28
|
|
|
29
29
|
import H from '../constants';
|
|
@@ -237,26 +237,26 @@ export default class HastePlugin
|
|
|
237
237
|
);
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
-
|
|
240
|
+
onChanged(delta: ReadonlyFileSystemChanges<?string>): void {
|
|
241
241
|
// Process removals first so that moves aren't treated as duplicates.
|
|
242
|
-
for (const [
|
|
243
|
-
this
|
|
242
|
+
for (const [canonicalPath, maybeHasteId] of delta.removedFiles) {
|
|
243
|
+
this.#onRemovedFile(canonicalPath, maybeHasteId);
|
|
244
244
|
}
|
|
245
|
-
for (const [
|
|
246
|
-
this
|
|
245
|
+
for (const [canonicalPath, maybeHasteId] of delta.addedFiles) {
|
|
246
|
+
this.#onNewFile(canonicalPath, maybeHasteId);
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
|
|
250
|
+
#onNewFile(canonicalPath: string, id: ?string) {
|
|
251
251
|
if (id == null) {
|
|
252
252
|
// Not a Haste module or package
|
|
253
253
|
return;
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
const module: HasteMapItemMetadata = [
|
|
257
|
-
|
|
257
|
+
canonicalPath,
|
|
258
258
|
this.#enableHastePackages &&
|
|
259
|
-
path.basename(
|
|
259
|
+
path.basename(canonicalPath) === 'package.json'
|
|
260
260
|
? H.PACKAGE
|
|
261
261
|
: H.MODULE,
|
|
262
262
|
];
|
|
@@ -324,14 +324,14 @@ export default class HastePlugin
|
|
|
324
324
|
hasteMapItem[platform] = module;
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
-
onRemovedFile(
|
|
327
|
+
#onRemovedFile(canonicalPath: string, moduleName: ?string) {
|
|
328
328
|
if (moduleName == null) {
|
|
329
329
|
// Not a Haste module or package
|
|
330
330
|
return;
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
const platform =
|
|
334
|
-
getPlatformExtension(
|
|
334
|
+
getPlatformExtension(canonicalPath, this.#platforms) ||
|
|
335
335
|
H.GENERIC_PLATFORM;
|
|
336
336
|
|
|
337
337
|
const hasteMapItem = this.#map.get(moduleName);
|
|
@@ -344,7 +344,7 @@ export default class HastePlugin
|
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
|
|
347
|
-
this.#recoverDuplicates(moduleName,
|
|
347
|
+
this.#recoverDuplicates(moduleName, canonicalPath);
|
|
348
348
|
}
|
|
349
349
|
|
|
350
350
|
assertValid(): void {
|