@expo/metro-file-map 57.0.2 → 57.0.3

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.
@@ -161,9 +161,24 @@ class FallbackWatcher extends AbstractWatcher_1.AbstractWatcher {
161
161
  if (this.#watched[dir]) {
162
162
  return false;
163
163
  }
164
- const watcher = fs_1.default.watch(dir, { persistent: true }, (event, filename) => this.#normalizeChange(dir, event, filename));
164
+ let watcher;
165
+ try {
166
+ watcher = fs_1.default.watch(dir, { persistent: true }, (event, filename) => this.#normalizeChange(dir, event, filename));
167
+ }
168
+ catch (error) {
169
+ // Directory can vanish before watch; filterDir must not throw.
170
+ this.#checkedEmitError(error);
171
+ return false;
172
+ }
165
173
  this.#watched[dir] = watcher;
166
- watcher.on('error', this.#checkedEmitError);
174
+ watcher.on('error', (error) => {
175
+ // Node emits no `close` after `error`.
176
+ if (this.#watched[dir] === watcher) {
177
+ delete this.#watched[dir];
178
+ }
179
+ watcher.close();
180
+ this.#checkedEmitError(error);
181
+ });
167
182
  if (this.root !== dir) {
168
183
  this.#register(dir, 'd');
169
184
  }
@@ -174,13 +189,15 @@ class FallbackWatcher extends AbstractWatcher_1.AbstractWatcher {
174
189
  */
175
190
  async #stopWatching(dir) {
176
191
  const watcher = this.#watched[dir];
177
- if (watcher) {
178
- await new Promise((resolve) => {
179
- watcher.once('close', () => process.nextTick(resolve));
180
- watcher.close();
181
- delete this.#watched[dir];
182
- });
192
+ if (!watcher) {
193
+ return;
183
194
  }
195
+ delete this.#watched[dir];
196
+ await new Promise((resolve) => {
197
+ watcher.once('close', () => process.nextTick(resolve));
198
+ watcher.once('error', () => process.nextTick(resolve));
199
+ watcher.close();
200
+ });
184
201
  }
185
202
  /**
186
203
  * End watching.
@@ -232,6 +249,13 @@ class FallbackWatcher extends AbstractWatcher_1.AbstractWatcher {
232
249
  */
233
250
  #normalizeChange(dir, event, file) {
234
251
  if (!file) {
252
+ if (!this.#dirRegistry[dir]) {
253
+ // Windows may omit filename; list the new directory.
254
+ this.#processChange(dir, event === 'change' ? 'rename' : event, '').catch((error) => {
255
+ this.emitError(error);
256
+ });
257
+ return;
258
+ }
235
259
  this.#detectChangedFile(dir, event, (actualFile) => {
236
260
  if (actualFile) {
237
261
  this.#processChange(dir, event, actualFile).catch((error) => {
@@ -385,11 +409,15 @@ function isIgnorableFileError(error) {
385
409
  */
386
410
  function recReaddir(dir, dirCallback, fileCallback, symlinkCallback, endCallback, errorCallback, ignored) {
387
411
  const walk = walker(dir);
388
- if (ignored) {
389
- walk.filterDir((currentDir) => !common.posixPathMatchesPattern(ignored, currentDir));
390
- }
412
+ // Watch before readdir so a file written in between is not missed.
413
+ walk.filterDir((currentDir, stats) => {
414
+ if (ignored && common.posixPathMatchesPattern(ignored, currentDir)) {
415
+ return false;
416
+ }
417
+ normalizeProxy(dirCallback)(currentDir, stats);
418
+ return true;
419
+ });
391
420
  walk
392
- .on('dir', normalizeProxy(dirCallback))
393
421
  .on('file', normalizeProxy(fileCallback))
394
422
  .on('symlink', normalizeProxy(symlinkCallback))
395
423
  .on('error', errorCallback)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expo/metro-file-map",
3
- "version": "57.0.2",
3
+ "version": "57.0.3",
4
4
  "description": "A metro-file-map fork for Expo used with the Metro bundler",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -42,7 +42,7 @@
42
42
  "publishConfig": {
43
43
  "access": "public"
44
44
  },
45
- "gitHead": "52fc013ec8c75e89ba8f83c167e4b6b0416e6bf7",
45
+ "gitHead": "ee89f7c31877f111cb1705c8e5c2c8078fa80a03",
46
46
  "scripts": {
47
47
  "build": "expo-module tsc",
48
48
  "clean": "expo-module clean",