metro-file-map 0.75.0 → 0.75.1

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.75.0",
3
+ "version": "0.75.1",
4
4
  "description": "[Experimental] - 🚇 File crawling, watching and mapping for Metro",
5
5
  "main": "src/index.js",
6
6
  "repository": {
package/src/HasteFS.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _constants = _interopRequireDefault(require("./constants"));
8
8
  var fastPath = _interopRequireWildcard(require("./lib/fast_path"));
9
+ var _invariant = _interopRequireDefault(require("invariant"));
9
10
  var path = _interopRequireWildcard(require("path"));
10
11
  var _jestUtil = require("jest-util");
11
12
  function _getRequireWildcardCache(nodeInterop) {
@@ -84,25 +85,6 @@ class HasteFS {
84
85
  addOrModify(filePath, metadata) {
85
86
  this.#files.set(this._normalizePath(filePath), metadata);
86
87
  }
87
- setVisitMetadata(filePath, visitResult) {
88
- const metadata = this._getFileData(filePath);
89
- if (!metadata) {
90
- throw new Error("Visited file not found in file map: " + filePath);
91
- }
92
- metadata[_constants.default.VISITED] = 1;
93
- if (visitResult.hasteId != null) {
94
- metadata[_constants.default.ID] = visitResult.hasteId;
95
- }
96
- if ("sha1" in visitResult) {
97
- metadata[_constants.default.SHA1] = visitResult.sha1;
98
- }
99
- if (visitResult.dependencies != null) {
100
- metadata[_constants.default.DEPENDENCIES] = visitResult.dependencies;
101
- }
102
- if (visitResult.symlinkTarget != null) {
103
- metadata[_constants.default.SYMLINK] = visitResult.symlinkTarget;
104
- }
105
- }
106
88
  getSerializableSnapshot() {
107
89
  return new Map(Array.from(this.#files.entries(), ([k, v]) => [k, [...v]]));
108
90
  }
@@ -122,22 +104,6 @@ class HasteFS {
122
104
  ? _ref2
123
105
  : null;
124
106
  }
125
- getSymlinkTarget(file) {
126
- const fileMetadata = this._getFileData(file);
127
- if (fileMetadata == null) {
128
- return null;
129
- }
130
- return typeof fileMetadata[_constants.default.SYMLINK] === "string"
131
- ? fileMetadata[_constants.default.SYMLINK]
132
- : null;
133
- }
134
- getType(file) {
135
- const fileMetadata = this._getFileData(file);
136
- if (fileMetadata == null) {
137
- return null;
138
- }
139
- return fileMetadata[_constants.default.SYMLINK] === 0 ? "f" : "l";
140
- }
141
107
  getDependencies(file) {
142
108
  const fileMetadata = this._getFileData(file);
143
109
  if (fileMetadata) {
@@ -158,14 +124,6 @@ class HasteFS {
158
124
  ? _ref3
159
125
  : null;
160
126
  }
161
- getModifiedTime(file) {
162
- var _ref4;
163
- const fileMetadata = this._getFileData(file);
164
- return (_ref4 = fileMetadata && fileMetadata[_constants.default.MTIME]) !==
165
- null && _ref4 !== void 0
166
- ? _ref4
167
- : null;
168
- }
169
127
  exists(file) {
170
128
  return this._getFileData(file) != null;
171
129
  }
@@ -180,6 +138,22 @@ class HasteFS {
180
138
  yield fastPath.resolve(this.#rootDir, file);
181
139
  }
182
140
  }
141
+ linkStats(file) {
142
+ const fileMetadata = this._getFileData(file);
143
+ if (fileMetadata == null) {
144
+ return null;
145
+ }
146
+ const fileType = fileMetadata[_constants.default.SYMLINK] === 0 ? "f" : "l";
147
+ const modifiedTime = fileMetadata[_constants.default.MTIME];
148
+ (0, _invariant.default)(
149
+ typeof modifiedTime === "number",
150
+ "File in HasteFS missing modified time"
151
+ );
152
+ return {
153
+ fileType,
154
+ modifiedTime,
155
+ };
156
+ }
183
157
  matchFiles(pattern) {
184
158
  const regexpPattern =
185
159
  pattern instanceof RegExp ? pattern : new RegExp(pattern);
@@ -245,5 +219,8 @@ class HasteFS {
245
219
  }
246
220
  return this.#files.get(this._normalizePath(filePath));
247
221
  }
222
+ getRealPath(filePath) {
223
+ throw new Error("HasteFS.getRealPath() is not implemented.");
224
+ }
248
225
  }
249
226
  exports.default = HasteFS;
@@ -11,14 +11,15 @@
11
11
  import type {
12
12
  FileData,
13
13
  FileMetaData,
14
+ FileStats,
14
15
  Glob,
15
16
  MutableFileSystem,
16
17
  Path,
17
- VisitMetadata,
18
18
  } from './flow-types';
19
19
 
20
20
  import H from './constants';
21
21
  import * as fastPath from './lib/fast_path';
22
+ import invariant from 'invariant';
22
23
  import * as path from 'path';
23
24
  import {globsToMatcher, replacePathSepForGlob} from 'jest-util';
24
25
 
@@ -51,33 +52,6 @@ export default class HasteFS implements MutableFileSystem {
51
52
  this.#files.set(this._normalizePath(filePath), metadata);
52
53
  }
53
54
 
54
- setVisitMetadata(
55
- filePath: Path,
56
- visitResult: $ReadOnly<VisitMetadata>,
57
- ): void {
58
- const metadata = this._getFileData(filePath);
59
- if (!metadata) {
60
- throw new Error('Visited file not found in file map: ' + filePath);
61
- }
62
- metadata[H.VISITED] = 1;
63
-
64
- if (visitResult.hasteId != null) {
65
- metadata[H.ID] = visitResult.hasteId;
66
- }
67
-
68
- if ('sha1' in visitResult) {
69
- metadata[H.SHA1] = visitResult.sha1;
70
- }
71
-
72
- if (visitResult.dependencies != null) {
73
- metadata[H.DEPENDENCIES] = visitResult.dependencies;
74
- }
75
-
76
- if (visitResult.symlinkTarget != null) {
77
- metadata[H.SYMLINK] = visitResult.symlinkTarget;
78
- }
79
- }
80
-
81
55
  getSerializableSnapshot(): FileData {
82
56
  return new Map(
83
57
  Array.from(this.#files.entries(), ([k, v]: [Path, FileMetaData]) => [
@@ -97,24 +71,6 @@ export default class HasteFS implements MutableFileSystem {
97
71
  return (fileMetadata && fileMetadata[H.SIZE]) ?? null;
98
72
  }
99
73
 
100
- getSymlinkTarget(file: Path): ?string {
101
- const fileMetadata = this._getFileData(file);
102
- if (fileMetadata == null) {
103
- return null;
104
- }
105
- return typeof fileMetadata[H.SYMLINK] === 'string'
106
- ? fileMetadata[H.SYMLINK]
107
- : null;
108
- }
109
-
110
- getType(file: Path): ?('f' | 'l') {
111
- const fileMetadata = this._getFileData(file);
112
- if (fileMetadata == null) {
113
- return null;
114
- }
115
- return fileMetadata[H.SYMLINK] === 0 ? 'f' : 'l';
116
- }
117
-
118
74
  getDependencies(file: Path): ?Array<string> {
119
75
  const fileMetadata = this._getFileData(file);
120
76
 
@@ -132,11 +88,6 @@ export default class HasteFS implements MutableFileSystem {
132
88
  return (fileMetadata && fileMetadata[H.SHA1]) ?? null;
133
89
  }
134
90
 
135
- getModifiedTime(file: Path): ?number {
136
- const fileMetadata = this._getFileData(file);
137
- return (fileMetadata && fileMetadata[H.MTIME]) ?? null;
138
- }
139
-
140
91
  exists(file: Path): boolean {
141
92
  return this._getFileData(file) != null;
142
93
  }
@@ -155,6 +106,23 @@ export default class HasteFS implements MutableFileSystem {
155
106
  }
156
107
  }
157
108
 
109
+ linkStats(file: Path): ?FileStats {
110
+ const fileMetadata = this._getFileData(file);
111
+ if (fileMetadata == null) {
112
+ return null;
113
+ }
114
+ const fileType = fileMetadata[H.SYMLINK] === 0 ? 'f' : 'l';
115
+ const modifiedTime = fileMetadata[H.MTIME];
116
+ invariant(
117
+ typeof modifiedTime === 'number',
118
+ 'File in HasteFS missing modified time',
119
+ );
120
+ return {
121
+ fileType,
122
+ modifiedTime,
123
+ };
124
+ }
125
+
158
126
  matchFiles(pattern: RegExp | string): Array<Path> {
159
127
  const regexpPattern =
160
128
  pattern instanceof RegExp ? pattern : new RegExp(pattern);
@@ -235,4 +203,8 @@ export default class HasteFS implements MutableFileSystem {
235
203
  }
236
204
  return this.#files.get(this._normalizePath(filePath));
237
205
  }
206
+
207
+ getRealPath(filePath: Path): Path {
208
+ throw new Error('HasteFS.getRealPath() is not implemented.');
209
+ }
238
210
  }
@@ -153,16 +153,25 @@ export type FileMetaData = [
153
153
  /* symlink */ 0 | 1 | string, // string specifies target, if known
154
154
  ];
155
155
 
156
+ export type FileStats = $ReadOnly<{
157
+ fileType: 'f' | 'l',
158
+ modifiedTime: number,
159
+ }>;
160
+
156
161
  export interface FileSystem {
157
162
  exists(file: Path): boolean;
158
163
  getAllFiles(): Array<Path>;
159
164
  getDependencies(file: Path): ?Array<string>;
160
- getModifiedTime(file: Path): ?number;
161
165
  getModuleName(file: Path): ?string;
166
+ getRealPath(file: Path): ?string;
162
167
  getSerializableSnapshot(): FileData;
163
168
  getSha1(file: Path): ?string;
164
- getSymlinkTarget(file: Path): ?string;
165
- getType(file: Path): ?('f' | 'l');
169
+
170
+ /**
171
+ * Analogous to posix lstat. If the file at `file` is a symlink, return
172
+ * information about the symlink without following it.
173
+ */
174
+ linkStats(file: Path): ?FileStats;
166
175
 
167
176
  matchFiles(pattern: RegExp | string): Array<Path>;
168
177
 
@@ -216,7 +225,6 @@ export interface MutableFileSystem extends FileSystem {
216
225
  remove(filePath: Path): void;
217
226
  addOrModify(filePath: Path, fileMetadata: FileMetaData): void;
218
227
  bulkAddOrModify(addedOrModifiedFiles: FileData): void;
219
- setVisitMetadata(filePath: Path, metadata: $ReadOnly<VisitMetadata>): void;
220
228
  }
221
229
 
222
230
  export type Path = string;
@@ -238,13 +246,6 @@ export type ReadOnlyRawModuleMap = $ReadOnly<{
238
246
  mocks: $ReadOnlyMap<string, Path>,
239
247
  }>;
240
248
 
241
- export type VisitMetadata = {
242
- hasteId?: string,
243
- sha1?: ?string,
244
- dependencies?: string,
245
- symlinkTarget?: string,
246
- };
247
-
248
249
  export type WatchmanClockSpec =
249
250
  | string
250
251
  | $ReadOnly<{scm: $ReadOnly<{'mergebase-with': string}>}>;