@expo/metro-file-map 57.0.3 → 57.0.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/build/Watcher.js CHANGED
@@ -146,15 +146,16 @@ class Watcher extends events_1.default {
146
146
  this.#activeWatcher = watcher;
147
147
  const createWatcherBackend = (root) => {
148
148
  const watcherOptions = {
149
- dot: true,
150
- globs: [
149
+ included: {
150
+ extensions: new Set(extensions),
151
151
  // Ensure we always include package.json files, which are crucial for
152
- /// module resolution.
153
- '**/package.json',
152
+ // module resolution.
153
+ basenames: new Set(['package.json']),
154
154
  // Ensure we always watch any health check files
155
- '**/' + this.#options.healthCheckFilePrefix + '*',
156
- ...extensions.map((extension) => '**/*.' + extension),
157
- ],
155
+ basenamePrefixes: this.#options.healthCheckFilePrefix != null
156
+ ? [this.#options.healthCheckFilePrefix]
157
+ : [],
158
+ },
158
159
  ignored: ignorePatternForWatch,
159
160
  watchmanDeferStates: this.#options.watchmanDeferStates,
160
161
  };
package/build/types.d.ts CHANGED
@@ -270,7 +270,6 @@ export interface FileSystem {
270
270
  rootDir?: Path | null | undefined;
271
271
  }): Iterable<Path>;
272
272
  }
273
- export type Glob = string;
274
273
  export type JsonData = string | number | boolean | null | JsonData[] | {
275
274
  [key: string]: JsonData;
276
275
  };
@@ -379,8 +378,16 @@ export type WatcherBackendChangeEvent = {
379
378
  };
380
379
  export interface WatcherBackendOptions {
381
380
  readonly ignored: RegExp | undefined | null;
382
- readonly globs: readonly string[];
383
- readonly dot: boolean;
381
+ readonly included: WatcherIncludedFiles | null | undefined;
382
+ }
383
+ /**
384
+ * Regular files a watcher reports changes to: those matching any of the
385
+ * extensions (without a leading dot), basenames, or basename prefixes.
386
+ */
387
+ export interface WatcherIncludedFiles {
388
+ readonly extensions: ReadonlySet<string>;
389
+ readonly basenames: ReadonlySet<string>;
390
+ readonly basenamePrefixes: readonly string[];
384
391
  }
385
392
  export type WatchmanClockSpec = string | {
386
393
  readonly scm: {
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import type { WatcherBackend, WatcherBackendChangeEvent, WatcherBackendOptions } from '../types';
7
+ import type { WatcherBackend, WatcherBackendChangeEvent, WatcherBackendOptions, WatcherIncludedFiles } from '../types';
8
8
  type EachOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
9
9
  export type WatcherBackendChangeEventWithoutRoot = EachOmit<WatcherBackendChangeEvent, 'root'>;
10
10
  export interface Listeners {
@@ -15,8 +15,7 @@ export declare class AbstractWatcher implements WatcherBackend {
15
15
  #private;
16
16
  readonly root: string;
17
17
  readonly ignored: RegExp | undefined | null;
18
- readonly globs: readonly string[];
19
- readonly dot: boolean;
18
+ readonly included: WatcherIncludedFiles | null | undefined;
20
19
  readonly doIgnore: (path: string) => boolean;
21
20
  constructor(dir: string, opts: WatcherBackendOptions);
22
21
  onFileEvent(listener: (event: WatcherBackendChangeEvent) => void): () => void;
@@ -50,15 +50,13 @@ const common_1 = require("./common");
50
50
  class AbstractWatcher {
51
51
  root;
52
52
  ignored;
53
- globs;
54
- dot;
53
+ included;
55
54
  doIgnore;
56
55
  #emitter = new events_1.default();
57
56
  constructor(dir, opts) {
58
- const { ignored, globs, dot } = opts;
59
- this.dot = dot || false;
57
+ const { ignored, included } = opts;
60
58
  this.ignored = ignored;
61
- this.globs = globs;
59
+ this.included = included;
62
60
  this.doIgnore = ignored
63
61
  ? (filePath) => (0, isWatcherExcluded_1.default)(filePath) || (0, common_1.posixPathMatchesPattern)(ignored, filePath)
64
62
  : isWatcherExcluded_1.default;
@@ -101,7 +101,7 @@ class FallbackWatcher extends AbstractWatcher_1.AbstractWatcher {
101
101
  }
102
102
  const relativePath = path_1.default.relative(this.root, filepath);
103
103
  if (this.doIgnore(relativePath) ||
104
- (type === 'f' && !common.includedByGlob('f', this.globs, this.dot, relativePath))) {
104
+ (type === 'f' && !common.isIncluded('f', this.included, relativePath))) {
105
105
  return false;
106
106
  }
107
107
  if (!this.#dirRegistry[dir]) {
@@ -284,8 +284,7 @@ class FallbackWatcher extends AbstractWatcher_1.AbstractWatcher {
284
284
  if (event === 'change') {
285
285
  return;
286
286
  }
287
- if (this.doIgnore(relativePath) ||
288
- !common.includedByGlob('d', this.globs, this.dot, relativePath)) {
287
+ if (this.doIgnore(relativePath) || !common.isIncluded('d', this.included, relativePath)) {
289
288
  return;
290
289
  }
291
290
  recReaddir(path_1.default.resolve(this.root, relativePath), (dir, stats) => {
@@ -118,7 +118,7 @@ class NativeWatcher extends AbstractWatcher_1.AbstractWatcher {
118
118
  if (!type) {
119
119
  return;
120
120
  }
121
- if (!(0, common_1.includedByGlob)(type, this.globs, this.dot, relativePath)) {
121
+ if (!(0, common_1.isIncluded)(type, this.included, relativePath)) {
122
122
  return;
123
123
  }
124
124
  // For directory "rename" events, notify that we need a recrawl since we
@@ -128,17 +128,6 @@ class WatchmanWatcher extends AbstractWatcher_1.AbstractWatcher {
128
128
  defer: self.#watchmanDeferStates,
129
129
  relative_root: watchProjectInfo.relativePath,
130
130
  };
131
- // Make sure we honor the dot option if even we're not using globs.
132
- if (self.globs.length === 0 && !self.dot) {
133
- options.expression = [
134
- 'match',
135
- '**',
136
- 'wholename',
137
- {
138
- includedotfiles: false,
139
- },
140
- ];
141
- }
142
131
  self.#client.command(['subscribe', getWatchRoot(), self.subscriptionName, options], onSubscribe);
143
132
  }
144
133
  const onSubscribe = (error, resp) => {
@@ -190,8 +179,7 @@ class WatchmanWatcher extends AbstractWatcher_1.AbstractWatcher {
190
179
  if (type != null && !(type === 'f' || type === 'd' || type === 'l')) {
191
180
  return;
192
181
  }
193
- if (this.doIgnore(relativePath) ||
194
- !common.includedByGlob(type, this.globs, this.dot, relativePath)) {
182
+ if (this.doIgnore(relativePath) || !common.isIncluded(type, this.included, relativePath)) {
195
183
  return;
196
184
  }
197
185
  const clock = typeof rawClock === 'string' && this.#watchProjectInfo != null
@@ -8,23 +8,27 @@
8
8
  * https://github.com/amasad/sane/blob/64ff3a870c42e84f744086884bf55a4f9c22d376/src/common.js
9
9
  */
10
10
  import type { Stats } from 'fs';
11
- import type { ChangeEventMetadata } from '../types';
11
+ import type { ChangeEventMetadata, WatcherIncludedFiles } from '../types';
12
12
  export declare const DELETE_EVENT = "delete";
13
13
  export declare const TOUCH_EVENT = "touch";
14
14
  export declare const RECRAWL_EVENT = "recrawl";
15
15
  export declare const ALL_EVENT = "all";
16
16
  export interface WatcherOptions {
17
- readonly globs: readonly string[];
18
- readonly dot: boolean;
17
+ readonly included: WatcherIncludedFiles | null | undefined;
19
18
  readonly ignored: RegExp | null | undefined;
20
19
  readonly watchmanDeferStates: readonly string[];
21
20
  readonly watchman?: unknown;
22
21
  readonly watchmanPath?: string;
23
22
  }
24
23
  /**
25
- * Checks a file relative path against the globs array.
24
+ * Whether a watcher should report a change at the given relative path. Only
25
+ * regular files are checked against `included`, and every file is included
26
+ * when it is null.
27
+ *
28
+ * A file matches an extension when its basename ends with `.` followed by
29
+ * that extension, so `.env` matches `env` and `foo.d.ts` matches `d.ts`.
26
30
  */
27
- export declare function includedByGlob(type: 'f' | 'l' | 'd' | null | undefined, globs: readonly string[], dot: boolean, relativePath: string): boolean;
31
+ export declare function isIncluded(type: 'f' | 'l' | 'd' | null | undefined, included: WatcherIncludedFiles | null | undefined, relativePath: string): boolean;
28
32
  /**
29
33
  * Whether the given filePath matches the given RegExp, after converting
30
34
  * (on Windows only) system separators to posix separators.
@@ -13,24 +13,37 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.posixPathMatchesPattern = exports.ALL_EVENT = exports.RECRAWL_EVENT = exports.TOUCH_EVENT = exports.DELETE_EVENT = void 0;
16
- exports.includedByGlob = includedByGlob;
16
+ exports.isIncluded = isIncluded;
17
17
  exports.typeFromStat = typeFromStat;
18
- const micromatch_1 = __importDefault(require("micromatch"));
19
18
  const path_1 = __importDefault(require("path"));
20
19
  exports.DELETE_EVENT = 'delete';
21
20
  exports.TOUCH_EVENT = 'touch';
22
21
  exports.RECRAWL_EVENT = 'recrawl';
23
22
  exports.ALL_EVENT = 'all';
24
23
  /**
25
- * Checks a file relative path against the globs array.
24
+ * Whether a watcher should report a change at the given relative path. Only
25
+ * regular files are checked against `included`, and every file is included
26
+ * when it is null.
27
+ *
28
+ * A file matches an extension when its basename ends with `.` followed by
29
+ * that extension, so `.env` matches `env` and `foo.d.ts` matches `d.ts`.
26
30
  */
27
- function includedByGlob(type, globs, dot, relativePath) {
28
- // For non-regular files or if there are no glob matchers, just respect the
29
- // `dot` option to filter dotfiles if dot === false.
30
- if (globs.length === 0 || type !== 'f') {
31
- return dot || micromatch_1.default.some(relativePath, '**/*');
31
+ function isIncluded(type, included, relativePath) {
32
+ if (included == null || type !== 'f') {
33
+ return true;
34
+ }
35
+ const basename = path_1.default.basename(relativePath);
36
+ return (hasIncludedExtension(included.extensions, basename) ||
37
+ included.basenames.has(basename) ||
38
+ included.basenamePrefixes.some((prefix) => basename.startsWith(prefix)));
39
+ }
40
+ function hasIncludedExtension(extensions, basename) {
41
+ for (let i = basename.indexOf('.'); i !== -1; i = basename.indexOf('.', i + 1)) {
42
+ if (extensions.has(basename.slice(i + 1))) {
43
+ return true;
44
+ }
32
45
  }
33
- return micromatch_1.default.some(relativePath, globs, { dot });
46
+ return false;
34
47
  }
35
48
  /**
36
49
  * Whether the given filePath matches the given RegExp, after converting
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expo/metro-file-map",
3
- "version": "57.0.3",
3
+ "version": "57.0.4",
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",
@@ -26,7 +26,6 @@
26
26
  "fb-watchman": "^2.0.2",
27
27
  "invariant": "^2.2.4",
28
28
  "jest-worker": "^29.7.0",
29
- "micromatch": "^4.0.4",
30
29
  "walker": "^1.0.8"
31
30
  },
32
31
  "devDependencies": {
@@ -34,7 +33,6 @@
34
33
  "@types/debug": "^4.1.7",
35
34
  "@types/fb-watchman": "^2.0.6",
36
35
  "@types/invariant": "^2.2.37",
37
- "@types/micromatch": "^4.0.10",
38
36
  "@types/node": "^22.14.0",
39
37
  "memfs": "^3.6.0",
40
38
  "expo-module-scripts": "56.0.3"
@@ -42,7 +40,7 @@
42
40
  "publishConfig": {
43
41
  "access": "public"
44
42
  },
45
- "gitHead": "ee89f7c31877f111cb1705c8e5c2c8078fa80a03",
43
+ "gitHead": "50ac74f1ab5682c8e32b24da6e5e97dd4dbbb80f",
46
44
  "scripts": {
47
45
  "build": "expo-module tsc",
48
46
  "clean": "expo-module clean",