Commit c575c4e
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: 68c2a17b50c8fe579e856dbca24ea60f7c8bd8a71 parent 3690729 commit c575c4e
84 files changed
Lines changed: 155 additions & 112 deletions
File tree
- docs
- packages
- metro-cache/src
- metro-config
- src
- defaults
- types
- metro-core/src
- metro-resolver/src
- metro-runtime/src/modules
- __tests__
- metro-source-map/src
- Consumer
- metro-transform-worker/src
- metro/src
- Bundler
- DeltaBundler
- Serializers
- __tests__
- helpers
- __tests__
- __tests__
- ModuleGraph/worker
- Server/__tests__
- __tests__
- lib
- node-haste
- DependencyGraph
- scripts/__tests__
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
File renamed without changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
0 commit comments