flow-upgrade 2.6.0 → 2.7.1
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
|
@@ -113,3 +113,16 @@ Converts:
|
|
|
113
113
|
- `React.ElementConfig<React.AbstractComponent<Props, Instance>>` to `Props`
|
|
114
114
|
- `React.ElementRef<React.AbstractComponent<Props, Instance>>` to `Instance`
|
|
115
115
|
- `React.ElementRef<React.AbstractComponent<Props>` to `mixed`
|
|
116
|
+
|
|
117
|
+
### Convert legacy Flow utility types to modern equivalents
|
|
118
|
+
Converts legacy Flow utility types to TypeScript-compatible equivalents:
|
|
119
|
+
- `$NonMaybeType<T>` to `NonNullable<T>`
|
|
120
|
+
- `$ReadOnly<T>` to `Readonly<T>`
|
|
121
|
+
- `$ReadOnlyArray<T>` to `ReadonlyArray<T>`
|
|
122
|
+
- `$ReadOnlyMap<K, V>` to `ReadonlyMap<K, V>`
|
|
123
|
+
- `$ReadOnlySet<T>` to `ReadonlySet<T>`
|
|
124
|
+
- `$Keys<T>` to `keyof T`
|
|
125
|
+
- `$Values<T>` to `Values<T>`
|
|
126
|
+
- `mixed` to `unknown`
|
|
127
|
+
|
|
128
|
+
Run with `yarn run flow-codemod convertLegacyUtilityTypes`.
|
|
@@ -7,8 +7,6 @@ var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
|
7
7
|
|
|
8
8
|
var _yargs = _interopRequireDefault(require("yargs/yargs"));
|
|
9
9
|
|
|
10
|
-
var _upgrade = _interopRequireDefault(require("../upgrade"));
|
|
11
|
-
|
|
12
10
|
var _path = _interopRequireDefault(require("path"));
|
|
13
11
|
|
|
14
12
|
var _findFlowFiles = require("../findFlowFiles");
|
|
@@ -19,9 +17,7 @@ var _Styled = _interopRequireDefault(require("../Styled"));
|
|
|
19
17
|
|
|
20
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
|
+
require('../upgrade');
|
|
25
21
|
|
|
26
22
|
const CODEMOD_DIR = _path.default.resolve(__dirname, '..', 'codemods');
|
|
27
23
|
|
|
@@ -72,7 +68,7 @@ async function main(args) {
|
|
|
72
68
|
const filePaths = await (0, _findFlowFiles.findFlowFilesWithSpinner)(directory, options);
|
|
73
69
|
const {
|
|
74
70
|
default: upgrade
|
|
75
|
-
} = await
|
|
71
|
+
} = await import(`${CODEMOD_DIR}/${codemodName}.js`);
|
|
76
72
|
|
|
77
73
|
if (!options.silent) {
|
|
78
74
|
console.log(_Styled.default.sectionHeader('Codemods'));
|
package/dist/bin/upgrade.js
CHANGED
|
@@ -7,10 +7,10 @@ var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
|
7
7
|
|
|
8
8
|
var _yargs = _interopRequireDefault(require("yargs/yargs"));
|
|
9
9
|
|
|
10
|
-
var _upgrade = _interopRequireDefault(require("../upgrade"));
|
|
11
|
-
|
|
12
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
11
|
|
|
12
|
+
require('../upgrade');
|
|
13
|
+
|
|
14
14
|
async function main(args) {
|
|
15
15
|
const yargs = (0, _yargs.default)(args).usage('Usage: flow-upgrade <current version> <target version>').positional('current version', {
|
|
16
16
|
describe: 'Your current flow version'
|
|
@@ -52,7 +52,7 @@ async function main(args) {
|
|
|
52
52
|
const toVersion = yargs._[1];
|
|
53
53
|
|
|
54
54
|
try {
|
|
55
|
-
await (
|
|
55
|
+
await upgrade(process.cwd(), fromVersion, toVersion, options);
|
|
56
56
|
} catch (error) {
|
|
57
57
|
console.error(_chalk.default.red(error ? error.stack || error : error));
|
|
58
58
|
}
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
var _default = (0, _Types.codemod)({
|
|
13
|
+
title: 'Convert legacy Flow utility types to modern equivalents',
|
|
14
|
+
describe: `
|
|
15
|
+
Transforms legacy Flow utility types to TypeScript-compatible types:
|
|
16
|
+
- \`$NonMaybeType<T>\` -> \`NonNullable<T>\`
|
|
17
|
+
- \`$ReadOnly<T>\` -> \`Readonly<T>\`
|
|
18
|
+
- \`$ReadOnlyArray<T>\` -> \`ReadonlyArray<T>\`
|
|
19
|
+
- \`$ReadOnlyMap<K, V>\` -> \`ReadonlyMap<K, V>\`
|
|
20
|
+
- \`$ReadOnlySet<T>\` -> \`ReadonlySet<T>\`
|
|
21
|
+
- \`$Keys<T>\` -> \`keyof T\`
|
|
22
|
+
- \`$Values<T>\` -> \`Values<T>\`
|
|
23
|
+
- \`mixed\` -> \`unknown\``,
|
|
24
|
+
transform: context => {
|
|
25
|
+
return {
|
|
26
|
+
MixedTypeAnnotation(node) {
|
|
27
|
+
const newNode = _hermesTransform.t.GenericTypeAnnotation({
|
|
28
|
+
id: _hermesTransform.t.Identifier({
|
|
29
|
+
name: 'unknown'
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
context.replaceNode(node, newNode, {
|
|
34
|
+
keepComments: true
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
GenericTypeAnnotation(node) {
|
|
39
|
+
const id = node.id;
|
|
40
|
+
|
|
41
|
+
if (id.type !== 'Identifier') {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const typeName = id.name;
|
|
46
|
+
|
|
47
|
+
if (typeName === '$Keys') {
|
|
48
|
+
if (node.typeParameters && node.typeParameters.params && node.typeParameters.params.length === 1) {
|
|
49
|
+
const newNode = _hermesTransform.t.KeyofTypeAnnotation({
|
|
50
|
+
argument: node.typeParameters.params[0]
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
context.replaceNode(node, newNode, {
|
|
54
|
+
keepComments: true
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const typeMap = {
|
|
62
|
+
$NonMaybeType: 'NonNullable',
|
|
63
|
+
$ReadOnly: 'Readonly',
|
|
64
|
+
$ReadOnlyArray: 'ReadonlyArray',
|
|
65
|
+
$ReadOnlyMap: 'ReadonlyMap',
|
|
66
|
+
$ReadOnlySet: 'ReadonlySet',
|
|
67
|
+
$Values: 'Values'
|
|
68
|
+
};
|
|
69
|
+
const modernType = typeMap[typeName];
|
|
70
|
+
|
|
71
|
+
if (modernType) {
|
|
72
|
+
context.modifyNodeInPlace(node.id, {
|
|
73
|
+
name: modernType
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
exports.default = _default;
|
|
@@ -148,9 +148,7 @@ var _default = (0, _Types.codemod)({
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
for (const memberToDelete of toDelete) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (memberToDelete.type === 'PropertyDefinition' && ((_memberToDelete$value = memberToDelete.value) === null || _memberToDelete$value === void 0 ? void 0 : _memberToDelete$value.type) === 'CallExpression') {
|
|
151
|
+
if (memberToDelete.type === 'PropertyDefinition' && memberToDelete.value?.type === 'CallExpression') {
|
|
154
152
|
console.log(context.buildCodeFrame(memberToDelete.value, 'Deleted a property with a CallExpression value. You should double check this was safe.'));
|
|
155
153
|
}
|
|
156
154
|
|
|
@@ -202,7 +200,7 @@ var _default = (0, _Types.codemod)({
|
|
|
202
200
|
const subjectName = node.property.name;
|
|
203
201
|
const member = instanceMembers.get(subjectName);
|
|
204
202
|
|
|
205
|
-
if (
|
|
203
|
+
if (member?.kind !== 'Method') {
|
|
206
204
|
return;
|
|
207
205
|
}
|
|
208
206
|
|
|
@@ -231,12 +229,8 @@ var _default = (0, _Types.codemod)({
|
|
|
231
229
|
},
|
|
232
230
|
|
|
233
231
|
'ClassDeclaration, ClassExpression:exit'(node) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if (classStack && ((_classStack = classStack) === null || _classStack === void 0 ? void 0 : _classStack.current) === node) {
|
|
237
|
-
var _classStack2;
|
|
238
|
-
|
|
239
|
-
classStack = (_classStack2 = classStack) === null || _classStack2 === void 0 ? void 0 : _classStack2.parent;
|
|
232
|
+
if (classStack && classStack?.current === node) {
|
|
233
|
+
classStack = classStack?.parent;
|
|
240
234
|
}
|
|
241
235
|
}
|
|
242
236
|
|
package/dist/runCodemods.js
CHANGED
|
@@ -13,6 +13,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
13
13
|
|
|
14
14
|
async function runCodemods(codemods, filePaths, options) {
|
|
15
15
|
const results = await Promise.allSettled(filePaths.map(async filePath => {
|
|
16
|
+
if (typeof require !== 'undefined' && require.cache) {
|
|
17
|
+
Object.keys(require.cache).forEach(key => {
|
|
18
|
+
if (key.includes('hermes-transform') || key.includes('prettier')) {
|
|
19
|
+
delete require.cache[key];
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
16
24
|
const originalContents = await _fsExtra.default.readFile(filePath, 'utf8');
|
|
17
25
|
let contents = originalContents;
|
|
18
26
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flow-upgrade",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.1",
|
|
4
4
|
"description": "A utility for upgrading your codebase to the latest version of Flow.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=14"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"flow-codemod": "./dist/bin/runSpecificCodemod.js"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
|
-
"build": "rm -rf dist && babel src --out-dir dist --ignore '**/__tests__'",
|
|
17
|
+
"build": "rm -rf dist && babel src --out-dir dist --ignore '**/__tests__' --plugins=@babel/plugin-transform-modules-commonjs",
|
|
18
18
|
"test": "jest",
|
|
19
19
|
"flow": "flow",
|
|
20
20
|
"prepublish": "yarn run build",
|
|
@@ -30,15 +30,15 @@
|
|
|
30
30
|
"homepage": "https://github.com/facebook/flow/tree/master/packages/flow-upgrade#readme",
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/highlight": "^7.18.6",
|
|
33
|
-
"babel-plugin-syntax-hermes-parser": "0.
|
|
33
|
+
"babel-plugin-syntax-hermes-parser": "0.33.3",
|
|
34
34
|
"chalk": "^2.0.1",
|
|
35
35
|
"fs-extra": "10.1.0",
|
|
36
|
-
"hermes-estree": "0.
|
|
37
|
-
"hermes-parser": "0.
|
|
38
|
-
"hermes-transform": "0.
|
|
36
|
+
"hermes-estree": "0.33.3",
|
|
37
|
+
"hermes-parser": "0.33.3",
|
|
38
|
+
"hermes-transform": "0.33.3",
|
|
39
39
|
"klaw-sync": "^6.0.0",
|
|
40
40
|
"ora": "^5.4.1",
|
|
41
|
-
"prettier-plugin-hermes-parser": "0.
|
|
41
|
+
"prettier-plugin-hermes-parser": "0.29.1",
|
|
42
42
|
"prompt-confirm": "^1.2.0",
|
|
43
43
|
"semver": "^7.3.7",
|
|
44
44
|
"yargs": "^17.0.1"
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"flow-bin": "^0.227.0",
|
|
55
55
|
"jest": "^27.5.1",
|
|
56
56
|
"memfs": "^3.4.3",
|
|
57
|
-
"prettier": "2.8.8"
|
|
57
|
+
"prettier": "2.8.8",
|
|
58
|
+
"@babel/plugin-transform-modules-commonjs": "^7.24.0"
|
|
58
59
|
}
|
|
59
60
|
}
|