Skip to content

Commit 505eab2

Browse files
committed
chore(types): auto-generate types for metro-file-map
1 parent 37d74fc commit 505eab2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1999
-553
lines changed

packages/metro-config/src/defaults/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ const getDefaultValues = (projectRoot: ?string): ConfigT => ({
175175
async function getDefaultConfig(rootPath: ?string): Promise<ConfigT> {
176176
// We can add more logic here to get a sensible default configuration, for
177177
// now we just return a stub.
178-
179178
return getDefaultValues(rootPath);
180179
}
181180

packages/metro-file-map/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"walker": "^1.0.7"
3030
},
3131
"devDependencies": {
32-
"slash": "^3.0.0"
32+
"slash": "^3.0.0",
33+
"metro-babel-register": "0.83.3"
3334
},
3435
"engines": {
3536
"node": ">=20.19.4"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
* @noformat - Flow comment syntax
9+
*/
10+
11+
/* eslint-disable import/no-commonjs */
12+
13+
/*
14+
* This file exports a set of constants that are used for Jest's haste map
15+
* serialization. On very large repositories, the haste map cache becomes very
16+
* large to the point where it is the largest overhead in starting up Jest.
17+
*
18+
* This constant key map allows to keep the map smaller without having to build
19+
* a custom serialization library.
20+
*/
21+
22+
23+
import type {HType} from './flow-types';
24+
25+
26+
'use strict';
27+
28+
export const constants: HType = {
29+
/* dependency serialization */
30+
DEPENDENCY_DELIM: '\0',
31+
32+
/* file map attributes */
33+
MTIME: 0,
34+
SIZE: 1,
35+
VISITED: 2,
36+
DEPENDENCIES: 3,
37+
SHA1: 4,
38+
SYMLINK: 5,
39+
ID: 6,
40+
41+
/* module map attributes */
42+
PATH: 0,
43+
TYPE: 1,
44+
45+
/* module types */
46+
MODULE: 0,
47+
PACKAGE: 1,
48+
49+
/* platforms */
50+
GENERIC_PLATFORM: 'g',
51+
NATIVE_PLATFORM: 'native',
52+
};
53+
54+
export default constants as HType;

packages/metro-file-map/src/constants.js

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,20 @@
55
* LICENSE file in the root directory of this source tree.
66
*
77
* @flow strict-local
8-
* @noformat - Flow comment syntax
8+
* @format
9+
* @oncall react_native
910
*/
1011

1112
/* eslint-disable import/no-commonjs */
1213

13-
/*
14-
* This file exports a set of constants that are used for Jest's haste map
15-
* serialization. On very large repositories, the haste map cache becomes very
16-
* large to the point where it is the largest overhead in starting up Jest.
17-
*
18-
* This constant key map allows to keep the map smaller without having to build
19-
* a custom serialization library.
20-
*/
14+
'use strict';
2115

2216
/*::
23-
import type {HType} from './flow-types';
17+
export type * from './constants.flow';
2418
*/
2519

26-
'use strict';
27-
28-
const constants/*: HType */ = {
29-
/* dependency serialization */
30-
DEPENDENCY_DELIM: '\0',
31-
32-
/* file map attributes */
33-
MTIME: 0,
34-
SIZE: 1,
35-
VISITED: 2,
36-
DEPENDENCIES: 3,
37-
SHA1: 4,
38-
SYMLINK: 5,
39-
ID: 6,
40-
41-
/* module map attributes */
42-
PATH: 0,
43-
TYPE: 1,
44-
45-
/* module types */
46-
MODULE: 0,
47-
PACKAGE: 1,
48-
49-
/* platforms */
50-
GENERIC_PLATFORM: 'g',
51-
NATIVE_PLATFORM: 'native',
52-
};
20+
try {
21+
require('metro-babel-register').unstable_registerForMetroMonorepo();
22+
} catch {}
5323

54-
module.exports = constants;
24+
module.exports = require('./constants.flow');

packages/metro-file-map/src/flow-types.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ export type FileMapPluginInitOptions<SerializableState> = $ReadOnly<{
187187
pluginState: ?SerializableState,
188188
}>;
189189

190-
type V8Serializable = interface {};
190+
// While I could use `interface {}`, this does not translate nicely to TypeScript.
191+
// $FlowFixMe[unclear-type] - using Object type here to represent an arbitrary object
192+
type V8Serializable = Object;
191193

192194
export interface FileMapPlugin<SerializableState = V8Serializable> {
193195
+name: string;
@@ -472,4 +474,4 @@ export type WorkerMetadata = $ReadOnly<{
472474
content?: ?Buffer,
473475
}>;
474476

475-
export type WorkerSetupArgs = $ReadOnly<{}>;
477+
export type WorkerSetupArgs = $ReadOnly<Record<string, mixed>>;

packages/metro-file-map/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import type {
4040
} from './flow-types';
4141

4242
import {DiskCacheManager} from './cache/DiskCacheManager';
43-
import H from './constants';
43+
import H from './constants.flow';
4444
import checkWatchmanCapabilities from './lib/checkWatchmanCapabilities';
4545
import {FileProcessor} from './lib/FileProcessor';
4646
import normalizePathSeparatorsToPosix from './lib/normalizePathSeparatorsToPosix';

packages/metro-file-map/src/lib/FileProcessor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import type {
1717
WorkerSetupArgs,
1818
} from '../flow-types';
1919

20-
import H from '../constants';
21-
import {Worker} from '../worker';
20+
import H from '../constants.flow';
21+
import {Worker} from '../worker.flow';
2222
import {Worker as JestWorker} from 'jest-worker';
2323
import {sep} from 'path';
2424

packages/metro-file-map/src/lib/TreeFS.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type {
1919
ProcessFileFunction,
2020
} from '../flow-types';
2121

22-
import H from '../constants';
22+
import H from '../constants.flow';
2323
import {RootPathUtils} from './RootPathUtils';
2424
import invariant from 'invariant';
2525
import path from 'path';

packages/metro-file-map/src/lib/__tests__/FileProcessor-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {
1515
WorkerMetadata,
1616
} from '../../flow-types';
1717

18-
import H from '../../constants';
18+
import H from '../../constants.flow';
1919

2020
const MockJestWorker = jest.fn().mockImplementation(() => ({
2121
processFile: async () => ({}),

packages/metro-file-map/src/lib/__tests__/TreeFS-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import type {CanonicalPath, FileData, FileMetadata} from '../../flow-types';
1313
import type TreeFSType from '../TreeFS';
1414

15-
import H from '../../constants';
15+
import H from '../../constants.flow';
1616

1717
let mockPathModule;
1818
jest.mock('path', () => mockPathModule);

0 commit comments

Comments
 (0)