Skip to content

Commit c575c4e

Browse files
robhoganfacebook-github-bot
authored andcommitted
Only use .flow.js extensions when there is an adjacent plain JS that registers Babel (#1546)
Summary: Currently, we have a smattering of `*.flow.js` files in Metro. These mean either of two things: 1) Modules that only export Flow types 2) Modules that are written in Flow, to distinguish them from a colocated plain JS file. Type 1) doesn't really have any significance and isn't enforced - we still build and publish (usually empty) `foo.flow.js` files and even accompanying `foo.flow.js.flow` files, and there's nothing to stop them containing runtime code (indeed, with enums, they do). This diff: - Renames all files of type 1) to drop the `.flow`. - Adds a test to ensure all `.flow.js` files have an adjacent `.js` file with the expected content. This is a prerequisite for auto-generating TS types for Metro - by establishing and enforcing a convention that `foo.js` and `foo.flow.js` are a Babel-registering entry point and an implementation file respectively, we can teach the API generator that `foo.flow.js` should generate `foo.d.ts`, and `foo.js` should be ignored. Changelog: Internal Pull Request resolved: #1546 Test Plan: - Flow/CI - Test verifies when JS has unexpected content: ``` $ echo "module.exports = 'illegal';" >> xplat/js/tools/metro/packages/metro/src/index.js $ js1 jest subpackages Determining test suites to run... FAIL xplat/js/tools/metro/scripts/__tests__/subpackages-test.js <...> ● packages/metro › all .flow.js files have an adjacent babel-registering entry point expect(received).toEqual(expected) // deep equality - Expected - 1 + Received + 2 @@ -7,7 +7,8 @@ try { require('metro-babel-register').unstable_registerForMetroMonorepo(); } catch {} - module.exports = require('./index.flow'); + module.exports = require('./index.flow'); + module.exports = 'illegal'; ↵ 152 | const endOfHeader = content.indexOf('*/\n') + 3; 153 | expect(endOfHeader).toBeGreaterThan(3); > 154 | expect(content.slice(endOfHeader)).toEqual(` | ^ 155 | 'use strict'; 156 | 157 | /*:: at Object.toEqual (scripts/__tests__/subpackages-test.js:154:42) Test Suites: 1 failed, 1 total Tests: 1 failed, 180 passed, 181 total Snapshots: 0 total Time: 0.599 s, estimated 1 s ``` Reviewed By: huntie Differential Revision: D79566838 Pulled By: robhogan fbshipit-source-id: 68c2a17b50c8fe579e856dbca24ea60f7c8bd8a7
1 parent 3690729 commit c575c4e

84 files changed

Lines changed: 155 additions & 112 deletions

File tree

Some content is hidden

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

docs/Configuration.md

Lines changed: 2 additions & 2 deletions

packages/metro-cache/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const HttpStore = require('./stores/HttpStore');
2020

2121
export type {Options as FileOptions} from './stores/FileStore';
2222
export type {Options as HttpOptions} from './stores/HttpStore';
23-
export type {CacheStore} from './types.flow';
23+
export type {CacheStore} from './types';
2424

2525
module.exports.AutoCleanFileStore = AutoCleanFileStore;
2626
module.exports.Cache = Cache;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
'use strict';
1313

14-
import type {PerfLogger, RootPerfLogger} from '../configTypes.flow';
14+
import type {PerfLogger, RootPerfLogger} from '../types';
1515

1616
const defaultCreateModuleIdFactory = require('metro/private/lib/createModuleIdFactory');
1717

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
'use strict';
1313

14-
import type {ConfigT} from '../configTypes.flow';
14+
import type {ConfigT} from '../types';
1515

1616
const {
1717
DEFAULT_METRO_MINIFIER_PATH,

packages/metro-config/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'use strict';
1313

1414
/*::
15-
export type * from './configTypes.flow';
15+
export type * from './types';
1616
*/
1717

1818
try {

packages/metro-config/src/loadConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
'use strict';
1313

14-
import type {ConfigT, InputConfigT, YargArguments} from './configTypes.flow';
14+
import type {ConfigT, InputConfigT, YargArguments} from './types';
1515

1616
const getDefaultConfig = require('./defaults');
1717
const validConfig = require('./defaults/validConfig');

packages/metro-config/src/configTypes.flow.js renamed to packages/metro-config/src/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import type {
2323
Module,
2424
ReadOnlyGraph,
2525
SerializerOptions,
26-
} from 'metro/private/DeltaBundler/types.flow';
26+
} from 'metro/private/DeltaBundler/types';
2727
import type {Reporter} from 'metro/private/lib/reporting';
2828
import type MetroServer from 'metro/private/Server';
2929

packages/metro-config/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
import getDefaultConfig from './defaults';
1212
import {loadConfig, mergeConfig, resolveConfig} from './loadConfig';
1313

14-
export * from './configTypes';
14+
export * from './types';
1515
export {loadConfig, mergeConfig, resolveConfig, getDefaultConfig};

packages/metro-config/types/loadConfig.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @oncall react_native
99
*/
1010

11-
import type {ConfigT, InputConfigT, YargArguments} from './configTypes';
11+
import type {ConfigT, InputConfigT, YargArguments} from './types';
1212

1313
export interface CosmiConfigResult {
1414
filepath: string;

0 commit comments

Comments
 (0)