flow-upgrade 2.0.3 → 2.2.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 +48 -2
- package/dist/codemods/convertShapeToPartial.js +34 -0
- package/dist/codemods/removeExplicitlyExactObjectTypeSyntax.js +34 -0
- package/dist/codemods/renamePartial.js +34 -0
- package/dist/codemods/typeParameterBoundExactEmptyObjectToInexact.js +51 -0
- package/dist/upgrades/0.201.0/index.js +25 -0
- package/dist/upgrades/index.js +7 -3
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -38,7 +38,53 @@ yarn create flow-upgrade --all
|
|
|
38
38
|
### `prettierrc`
|
|
39
39
|
|
|
40
40
|
Path to a `.prettierrc` file to use.
|
|
41
|
-
Upgrade codemods rely upon [`prettier`]
|
|
41
|
+
Upgrade codemods rely upon [`prettier`](https://www.npmjs.com/package/prettier) to print the resulting code after transformation.
|
|
42
42
|
If this is not provided, we will just use the defaults.
|
|
43
43
|
|
|
44
|
-
|
|
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 the 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 the upgrade to 0.170
|
|
79
|
+
|
|
80
|
+
### Rename `$Partial` to `Partial`
|
|
81
|
+
Renames usages of the `$Partial` utility type to its new name, [`Partial`](https://flow.org/en/docs/types/utilities/#toc-partial).
|
|
82
|
+
|
|
83
|
+
Run with `yarn run flow-codemod renamePartial`.
|
|
84
|
+
|
|
85
|
+
Part of the upgrade to 0.201
|
|
86
|
+
|
|
87
|
+
### Convert `$Shape` to `Partial`
|
|
88
|
+
Converts usages of the deprecated and unsafe `$Shape` utility type to its replacement, [`Partial`](https://flow.org/en/docs/types/utilities/#toc-partial).
|
|
89
|
+
|
|
90
|
+
Run with `yarn run flow-codemod convertShapeToPartial`.
|
|
@@ -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: 'Convert `$Shape` to `Partial`',
|
|
21
|
+
description: 'Converts usage of the `$Shape` utility type to `Partial`. It is possible that this will create type errors that you will have to resolve.',
|
|
22
|
+
transform: context => {
|
|
23
|
+
return {
|
|
24
|
+
'GenericTypeAnnotation[id.name="$Shape"][typeParameters.params.length > 0]'(node) {
|
|
25
|
+
context.modifyNodeInPlace(node.id, {
|
|
26
|
+
name: 'Partial'
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
exports.default = _default;
|
|
@@ -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,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: 'Rename `$Partial` to `Partial`',
|
|
21
|
+
description: 'Renames the `$Partial` type utility to `Partial`.',
|
|
22
|
+
transform: context => {
|
|
23
|
+
return {
|
|
24
|
+
'GenericTypeAnnotation[id.name="$Partial"][typeParameters.params.length > 0]'(node) {
|
|
25
|
+
context.modifyNodeInPlace(node.id, {
|
|
26
|
+
name: 'Partial'
|
|
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;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _renamePartial = _interopRequireDefault(require("../../codemods/renamePartial"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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 = {
|
|
22
|
+
version: '0.201.0',
|
|
23
|
+
upgrades: [_renamePartial.default]
|
|
24
|
+
};
|
|
25
|
+
exports.default = _default;
|
package/dist/upgrades/index.js
CHANGED
|
@@ -5,9 +5,13 @@ 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"));
|
|
13
|
+
|
|
14
|
+
var _4 = _interopRequireDefault(require("./0.201.0"));
|
|
11
15
|
|
|
12
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
17
|
|
|
@@ -25,5 +29,5 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
25
29
|
* Holds all of the upgrades that need to be run to upgrade to each version from
|
|
26
30
|
* the last version of Flow.
|
|
27
31
|
*/
|
|
28
|
-
const VERSION_UPGRADES = [_.default, _2.default];
|
|
32
|
+
const VERSION_UPGRADES = [_.default, _2.default, _3.default, _4.default];
|
|
29
33
|
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.2.0",
|
|
4
4
|
"description": "A utility for upgrading your codebase to the latest version of Flow.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=14"
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"@babel/highlight": "^7.18.6",
|
|
32
32
|
"chalk": "^2.0.1",
|
|
33
33
|
"fs-extra": "10.1.0",
|
|
34
|
-
"hermes-estree": "0.
|
|
35
|
-
"hermes-parser": "0.
|
|
36
|
-
"hermes-transform": "0.
|
|
34
|
+
"hermes-estree": "0.10.0",
|
|
35
|
+
"hermes-parser": "0.10.0",
|
|
36
|
+
"hermes-transform": "0.10.0",
|
|
37
37
|
"klaw-sync": "^6.0.0",
|
|
38
38
|
"ora": "^5.4.1",
|
|
39
39
|
"prompt-confirm": "^1.2.0",
|
|
@@ -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
|
}
|