flow-upgrade 2.0.2 → 2.1.0
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/README.md
CHANGED
|
@@ -2,30 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
A utility for upgrading your codebase to the latest version of Flow.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Install using `yarn add flow-upgrade`. We expect `prettier` to be installed as a [peer dependency](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#peerdependencies) wherever you are running `flow-upgrade`.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
You can then run:
|
|
8
8
|
|
|
9
9
|
```
|
|
10
|
-
yarn
|
|
10
|
+
yarn run flow-upgrade <current flow version> <target flow version>
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
You may also use [`npx`](https://www.npmjs.com/package/npx):
|
|
14
14
|
|
|
15
15
|
```
|
|
16
|
-
|
|
17
|
-
flow-upgrade
|
|
16
|
+
npx flow-upgrade <current flow version> <target flow version>
|
|
18
17
|
```
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
[`npx`]: https://www.npmjs.com/package/npx
|
|
19
|
+
We also supply the `flow-codemod` binary:
|
|
23
20
|
|
|
24
21
|
```
|
|
25
|
-
|
|
22
|
+
yarn run flow-codemod <codemod name>
|
|
26
23
|
```
|
|
27
24
|
|
|
28
|
-
|
|
25
|
+
If you just want to run a codemod without specifying Flow versions.
|
|
29
26
|
|
|
30
27
|
## Options
|
|
31
28
|
|
|
@@ -41,7 +38,41 @@ yarn create flow-upgrade --all
|
|
|
41
38
|
### `prettierrc`
|
|
42
39
|
|
|
43
40
|
Path to a `.prettierrc` file to use.
|
|
44
|
-
Upgrade codemods rely upon [`prettier`]
|
|
41
|
+
Upgrade codemods rely upon [`prettier`](https://www.npmjs.com/package/prettier) to print the resulting code after transformation.
|
|
45
42
|
If this is not provided, we will just use the defaults.
|
|
46
43
|
|
|
47
|
-
|
|
44
|
+
## Codemods available
|
|
45
|
+
|
|
46
|
+
### Collapse object initialization
|
|
47
|
+
Converts static object assignments (e.g. `const o = {}; o.a = 1;`) to inline properties (e.g. `const o = {a: 1};`).
|
|
48
|
+
|
|
49
|
+
Run with `yarn run flow-codemod collapseObjectInitialization`.
|
|
50
|
+
|
|
51
|
+
### Convert type parameter bound exact empty object to inexact
|
|
52
|
+
Replaces `T: {}` with `T: {...}` in type parameter bounds. The former is almost always wrong.
|
|
53
|
+
|
|
54
|
+
Run with `yarn run flow-codemod typeParameterBoundExactEmptyObjectToInexact`.
|
|
55
|
+
|
|
56
|
+
### Convert implicit inexact object types
|
|
57
|
+
Converts implicitly inexact object type syntax `{}` to explicitly inexact `{...}`.
|
|
58
|
+
|
|
59
|
+
Run with `yarn run flow-codemod convertImplicitInexactObjectTypes`.
|
|
60
|
+
|
|
61
|
+
### Remove explicitly exact object type syntax
|
|
62
|
+
Converts explicitly exact object type syntax `{| |}` to be just be `{ }`. To be done after you turn on `exact_by_default=true` in your `.flowconfig`.
|
|
63
|
+
|
|
64
|
+
Run with `yarn run flow-codemod removeExplicitlyExactObjectTypeSyntax`.
|
|
65
|
+
|
|
66
|
+
### Remove annotations in destructuring
|
|
67
|
+
Removes annotations nested inside of destructuring (e.g. `const [o: number] = foo;`). These are not valid Flow syntax.
|
|
68
|
+
|
|
69
|
+
Run with `yarn run flow-codemod removeAnnotationsInDestructuring`.
|
|
70
|
+
|
|
71
|
+
Part of upgrade to 0.176
|
|
72
|
+
|
|
73
|
+
### Remove duplicate class properties
|
|
74
|
+
Removes useless duplicate class properties and fixes bad constructor binding in those classes.
|
|
75
|
+
|
|
76
|
+
Run with `yarn run flow-codemod removeDuplicateClassProperties`.
|
|
77
|
+
|
|
78
|
+
Part of upgrade to 0.170
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _Types = require("../Types");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
12
|
+
*
|
|
13
|
+
* This source code is licensed under the MIT license found in the
|
|
14
|
+
* LICENSE file in the root directory of this source tree.
|
|
15
|
+
*
|
|
16
|
+
* @format
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
var _default = (0, _Types.codemod)({
|
|
20
|
+
title: 'Remove explicitly exact object type syntax',
|
|
21
|
+
description: 'Convert explicitly exact object type syntax `{| |}` to be just be `{ }`. To be done after you turn on `exact_by_default=true` in your `.flowconfig`.',
|
|
22
|
+
transform: context => {
|
|
23
|
+
return {
|
|
24
|
+
'ObjectTypeAnnotation[exact=true]'(node) {
|
|
25
|
+
context.modifyNodeInPlace(node, {
|
|
26
|
+
exact: false
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
exports.default = _default;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _Types = require("../Types");
|
|
9
|
+
|
|
10
|
+
var _hermesTransform = require("hermes-transform");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*
|
|
18
|
+
* @format
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
var _default = (0, _Types.codemod)({
|
|
22
|
+
title: 'Replace `T: {}` with `T: {...}` in type parameter bounds',
|
|
23
|
+
description: 'Replace `T: {}` with `T: {...}` in type parameter bounds',
|
|
24
|
+
transform: context => {
|
|
25
|
+
return {
|
|
26
|
+
TypeParameter(node) {
|
|
27
|
+
if (node.bound != null) {
|
|
28
|
+
const annotation = node.bound.typeAnnotation;
|
|
29
|
+
|
|
30
|
+
if (annotation.type === 'ObjectTypeAnnotation' && !annotation.inexact && annotation.properties.length === 0 && annotation.callProperties.length === 0 && annotation.indexers.length === 0 && annotation.internalSlots.length === 0) {
|
|
31
|
+
context.replaceNode(annotation, _hermesTransform.t.ObjectTypeAnnotation({
|
|
32
|
+
properties: [],
|
|
33
|
+
callProperties: [],
|
|
34
|
+
exact: false,
|
|
35
|
+
|
|
36
|
+
/* $FlowExpectedError[incompatible-call]
|
|
37
|
+
* TODO: hermes-transform mandates that inexact must be
|
|
38
|
+
* `false`, which is wrong. */
|
|
39
|
+
inexact: true,
|
|
40
|
+
indexers: [],
|
|
41
|
+
internalSlots: []
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
exports.default = _default;
|
package/dist/upgrades/index.js
CHANGED
|
@@ -5,9 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.VERSION_UPGRADES = void 0;
|
|
7
7
|
|
|
8
|
-
var _ = _interopRequireDefault(require("./0.
|
|
8
|
+
var _ = _interopRequireDefault(require("./0.84.0"));
|
|
9
9
|
|
|
10
|
-
var _2 = _interopRequireDefault(require("./0.
|
|
10
|
+
var _2 = _interopRequireDefault(require("./0.170.0"));
|
|
11
|
+
|
|
12
|
+
var _3 = _interopRequireDefault(require("./0.176.0"));
|
|
11
13
|
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
15
|
|
|
@@ -25,5 +27,5 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
25
27
|
* Holds all of the upgrades that need to be run to upgrade to each version from
|
|
26
28
|
* the last version of Flow.
|
|
27
29
|
*/
|
|
28
|
-
const VERSION_UPGRADES = [_.default, _2.default];
|
|
30
|
+
const VERSION_UPGRADES = [_.default, _2.default, _3.default];
|
|
29
31
|
exports.VERSION_UPGRADES = VERSION_UPGRADES;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flow-upgrade",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A utility for upgrading your codebase to the latest version of Flow.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=14"
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"yargs": "^17.0.1"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"prettier": "
|
|
44
|
+
"prettier": "2.7.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@babel/cli": "^7.14.8",
|
|
@@ -51,6 +51,6 @@
|
|
|
51
51
|
"flow-bin": "^0.178.0",
|
|
52
52
|
"jest": "^27.5.1",
|
|
53
53
|
"memfs": "^3.4.3",
|
|
54
|
-
"prettier": "
|
|
54
|
+
"prettier": "2.7.1"
|
|
55
55
|
}
|
|
56
56
|
}
|