flow-upgrade 2.6.0 → 2.7.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 +13 -0
- package/dist/Styled.js +0 -2
- package/dist/Types.js +1 -8
- package/dist/bin/runSpecificCodemod.js +21 -38
- package/dist/bin/upgrade.js +8 -15
- package/dist/codemodUtils/getClassMemberName.js +1 -8
- package/dist/codemodUtils/replaceMethodWithArrowProp.js +6 -14
- package/dist/codemods/collapseObjectInitialization.js +6 -19
- package/dist/codemods/convertImplicitInexactObjectTypes.js +3 -13
- package/dist/codemods/convertLegacyUtilityTypes.js +69 -0
- package/dist/codemods/convertShapeToPartial.js +3 -13
- package/dist/codemods/eliminateAbstractComponent.js +10 -20
- package/dist/codemods/removeAnnotationsInDestructuring.js +3 -13
- package/dist/codemods/removeDuplicateClassProperties.js +12 -29
- package/dist/codemods/removeExplicitlyExactObjectTypeSyntax.js +3 -13
- package/dist/codemods/renamePartial.js +3 -13
- package/dist/codemods/replaceReactDollarUtilityTypes.js +8 -21
- package/dist/codemods/replaceTemporaryTypes.js +8 -21
- package/dist/codemods/typeCastToAsExpression.js +5 -15
- package/dist/codemods/typeParameterBoundExactEmptyObjectToInexact.js +5 -16
- package/dist/findFlowFiles.js +15 -32
- package/dist/runCodemods.js +14 -17
- package/dist/upgrade.js +30 -48
- package/dist/upgrades/0.170.0/index.js +4 -15
- package/dist/upgrades/0.176.0/index.js +4 -15
- package/dist/upgrades/0.201.0/index.js +4 -15
- package/dist/upgrades/0.84.0/index.js +4 -15
- package/dist/upgrades/index.js +5 -19
- package/dist/utils/redirectConsole.js +3 -16
- package/package.json +6 -6
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`.
|
package/dist/Styled.js
CHANGED
package/dist/Types.js
CHANGED
|
@@ -1,36 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var _path = _interopRequireDefault(require("path"));
|
|
13
|
-
|
|
14
|
-
var _findFlowFiles = require("../findFlowFiles");
|
|
15
|
-
|
|
16
|
-
var _runCodemods = _interopRequireDefault(require("../runCodemods"));
|
|
17
|
-
|
|
18
|
-
var _Styled = _interopRequireDefault(require("../Styled"));
|
|
19
|
-
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
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; }
|
|
25
|
-
|
|
26
|
-
const CODEMOD_DIR = _path.default.resolve(__dirname, '..', 'codemods');
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import yargsImport from 'yargs/yargs';
|
|
5
|
+
import upgrade from '../upgrade';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { findFlowFilesWithSpinner } from '../findFlowFiles';
|
|
8
|
+
import runCodemods from '../runCodemods';
|
|
9
|
+
import Styled from '../Styled';
|
|
10
|
+
const CODEMOD_DIR = path.resolve(__dirname, '..', 'codemods');
|
|
27
11
|
|
|
28
12
|
async function main(args) {
|
|
29
|
-
const codemodNames =
|
|
13
|
+
const codemodNames = fs.readdirSync(CODEMOD_DIR, {
|
|
30
14
|
withFileTypes: false
|
|
31
|
-
}).map(f =>
|
|
32
|
-
|
|
33
|
-
const yargs = (0, _yargs.default)(args).usage('Usage: flow-upgrade-codemod <codemod name>').positional('codemod name', {
|
|
15
|
+
}).map(f => path.parse(f).name);
|
|
16
|
+
const yargs = yargsImport(args).usage('Usage: flow-upgrade-codemod <codemod name>').positional('codemod name', {
|
|
34
17
|
describe: 'Your current flow version',
|
|
35
18
|
choices: codemodNames
|
|
36
19
|
}).options({
|
|
@@ -57,7 +40,7 @@ async function main(args) {
|
|
|
57
40
|
return {};
|
|
58
41
|
}
|
|
59
42
|
|
|
60
|
-
return
|
|
43
|
+
return fs.readJSON(yargs.prettierrc);
|
|
61
44
|
})();
|
|
62
45
|
const options = {
|
|
63
46
|
all: !!yargs.all,
|
|
@@ -69,36 +52,36 @@ async function main(args) {
|
|
|
69
52
|
const directory = process.cwd();
|
|
70
53
|
|
|
71
54
|
try {
|
|
72
|
-
const filePaths = await
|
|
55
|
+
const filePaths = await findFlowFilesWithSpinner(directory, options);
|
|
73
56
|
const {
|
|
74
57
|
default: upgrade
|
|
75
|
-
} = await
|
|
58
|
+
} = await import(`${CODEMOD_DIR}/${codemodName}.js`);
|
|
76
59
|
|
|
77
60
|
if (!options.silent) {
|
|
78
|
-
console.log(
|
|
61
|
+
console.log(Styled.sectionHeader('Codemods'));
|
|
79
62
|
console.log();
|
|
80
63
|
console.log('We are now going to run the following codemods:');
|
|
81
64
|
console.log();
|
|
82
|
-
console.log(
|
|
65
|
+
console.log(Styled.upgradeTitle(upgrade.title, 1));
|
|
83
66
|
console.log();
|
|
84
67
|
console.log(upgrade.describe);
|
|
85
68
|
console.log();
|
|
86
|
-
console.log(
|
|
69
|
+
console.log(Styled.divider());
|
|
87
70
|
console.log();
|
|
88
|
-
console.log(`Running ${
|
|
71
|
+
console.log(`Running ${chalk.bold.cyan(1)} codemod...`);
|
|
89
72
|
console.log();
|
|
90
73
|
}
|
|
91
74
|
|
|
92
75
|
switch (upgrade.kind) {
|
|
93
76
|
case 'codemod':
|
|
94
|
-
await (
|
|
77
|
+
await runCodemods([upgrade], filePaths, options);
|
|
95
78
|
break;
|
|
96
79
|
|
|
97
80
|
default:
|
|
98
81
|
throw new Error(`Unexpected upgrade kind: '${upgrade.kind}'`);
|
|
99
82
|
}
|
|
100
83
|
} catch (error) {
|
|
101
|
-
console.error(
|
|
84
|
+
console.error(chalk.red(error ? error.stack || error : error));
|
|
102
85
|
}
|
|
103
86
|
}
|
|
104
87
|
|
package/dist/bin/upgrade.js
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
7
|
-
|
|
8
|
-
var _yargs = _interopRequireDefault(require("yargs/yargs"));
|
|
9
|
-
|
|
10
|
-
var _upgrade = _interopRequireDefault(require("../upgrade"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import yargsImport from 'yargs/yargs';
|
|
5
|
+
import upgrade from '../upgrade';
|
|
13
6
|
|
|
14
7
|
async function main(args) {
|
|
15
|
-
const yargs = (
|
|
8
|
+
const yargs = yargsImport(args).usage('Usage: flow-upgrade <current version> <target version>').positional('current version', {
|
|
16
9
|
describe: 'Your current flow version'
|
|
17
10
|
}).positional('target version', {
|
|
18
11
|
describe: 'The flow version you are upgrading to'
|
|
@@ -40,7 +33,7 @@ async function main(args) {
|
|
|
40
33
|
return {};
|
|
41
34
|
}
|
|
42
35
|
|
|
43
|
-
return
|
|
36
|
+
return fs.readJSON(yargs.prettierrc);
|
|
44
37
|
})();
|
|
45
38
|
const options = {
|
|
46
39
|
all: !!yargs.all,
|
|
@@ -52,9 +45,9 @@ async function main(args) {
|
|
|
52
45
|
const toVersion = yargs._[1];
|
|
53
46
|
|
|
54
47
|
try {
|
|
55
|
-
await (
|
|
48
|
+
await upgrade(process.cwd(), fromVersion, toVersion, options);
|
|
56
49
|
} catch (error) {
|
|
57
|
-
console.error(
|
|
50
|
+
console.error(chalk.red(error ? error.stack || error : error));
|
|
58
51
|
}
|
|
59
52
|
}
|
|
60
53
|
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getClassMemberName = getClassMemberName;
|
|
7
|
-
|
|
8
|
-
function getClassMemberName(member) {
|
|
1
|
+
export function getClassMemberName(member) {
|
|
9
2
|
if (member.key.type === 'PrivateIdentifier') {
|
|
10
3
|
return `#${member.key.name}`;
|
|
11
4
|
}
|
|
@@ -1,23 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.replaceMethodWithArrowProp = replaceMethodWithArrowProp;
|
|
7
|
-
|
|
8
|
-
var _hermesTransform = require("hermes-transform");
|
|
9
|
-
|
|
10
|
-
function replaceMethodWithArrowProp(context, method, name) {
|
|
11
|
-
context.replaceNode(method, _hermesTransform.t.PropertyDefinition({
|
|
1
|
+
import { t } from 'hermes-transform';
|
|
2
|
+
export function replaceMethodWithArrowProp(context, method, name) {
|
|
3
|
+
context.replaceNode(method, t.PropertyDefinition({
|
|
12
4
|
computed: false,
|
|
13
5
|
declare: false,
|
|
14
|
-
key:
|
|
6
|
+
key: t.Identifier({
|
|
15
7
|
name,
|
|
16
8
|
typeAnnotation: null
|
|
17
9
|
}),
|
|
18
10
|
optional: false,
|
|
19
11
|
static: false,
|
|
20
|
-
value:
|
|
12
|
+
value: t.ArrowFunctionExpression({
|
|
21
13
|
async: method.value.async,
|
|
22
14
|
body: method.value.body,
|
|
23
15
|
params: method.value.params,
|
|
@@ -25,7 +17,7 @@ function replaceMethodWithArrowProp(context, method, name) {
|
|
|
25
17
|
typeParameters: method.value.typeParameters,
|
|
26
18
|
returnType: method.value.returnType
|
|
27
19
|
}),
|
|
28
|
-
variance:
|
|
20
|
+
variance: t.Variance({
|
|
29
21
|
kind: 'plus'
|
|
30
22
|
})
|
|
31
23
|
}));
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _hermesTransform = require("hermes-transform");
|
|
9
|
-
|
|
10
|
-
var _Types = require("../Types");
|
|
11
|
-
|
|
12
|
-
var _default = (0, _Types.codemod)({
|
|
1
|
+
import { t } from 'hermes-transform';
|
|
2
|
+
import { codemod } from '../Types';
|
|
3
|
+
export default codemod({
|
|
13
4
|
title: 'Collapse Object Initialization',
|
|
14
5
|
describe: 'Converts static object assignments to inline properties',
|
|
15
6
|
transform: context => {
|
|
@@ -100,8 +91,7 @@ var _default = (0, _Types.codemod)({
|
|
|
100
91
|
|
|
101
92
|
if (memberObjectNode.type === 'Identifier' && memberObjectNode.name === idNode.name && memberPropertyNode.type === 'Identifier') {
|
|
102
93
|
const shorthand = !leftNode.computed && exprRightNode.type === 'Identifier' && exprRightNode.name === memberPropertyNode.name;
|
|
103
|
-
|
|
104
|
-
const property = _hermesTransform.t.Property({
|
|
94
|
+
const property = t.Property({
|
|
105
95
|
key: memberPropertyNode,
|
|
106
96
|
value: exprRightNode,
|
|
107
97
|
computed: leftNode.computed,
|
|
@@ -109,7 +99,6 @@ var _default = (0, _Types.codemod)({
|
|
|
109
99
|
method: false,
|
|
110
100
|
shorthand
|
|
111
101
|
});
|
|
112
|
-
|
|
113
102
|
return {
|
|
114
103
|
type: 'property',
|
|
115
104
|
keyName: memberPropertyNode.name,
|
|
@@ -222,7 +211,7 @@ var _default = (0, _Types.codemod)({
|
|
|
222
211
|
const newProperties = objectProperties.map(([{
|
|
223
212
|
property
|
|
224
213
|
}, _]) => property);
|
|
225
|
-
context.replaceNode(initNode,
|
|
214
|
+
context.replaceNode(initNode, t.ObjectExpression({
|
|
226
215
|
properties: newProperties
|
|
227
216
|
}));
|
|
228
217
|
objectProperties.forEach(([_, stmtToRemove]) => {
|
|
@@ -233,6 +222,4 @@ var _default = (0, _Types.codemod)({
|
|
|
233
222
|
|
|
234
223
|
};
|
|
235
224
|
}
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
exports.default = _default;
|
|
225
|
+
});
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _Types = require("../Types");
|
|
9
|
-
|
|
10
|
-
var _default = (0, _Types.codemod)({
|
|
1
|
+
import { codemod } from '../Types';
|
|
2
|
+
export default codemod({
|
|
11
3
|
title: 'Make implicitly inexact object types explicitly inexact',
|
|
12
4
|
describe: 'Convert implicitly inexact object type syntax `{}` to explicitly inexact `{...}`',
|
|
13
5
|
transform: context => {
|
|
@@ -20,6 +12,4 @@ var _default = (0, _Types.codemod)({
|
|
|
20
12
|
|
|
21
13
|
};
|
|
22
14
|
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
exports.default = _default;
|
|
15
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { codemod } from '../Types';
|
|
2
|
+
import { t } from 'hermes-transform';
|
|
3
|
+
export default codemod({
|
|
4
|
+
title: 'Convert legacy Flow utility types to modern equivalents',
|
|
5
|
+
describe: `
|
|
6
|
+
Transforms legacy Flow utility types to TypeScript-compatible types:
|
|
7
|
+
- \`$NonMaybeType<T>\` -> \`NonNullable<T>\`
|
|
8
|
+
- \`$ReadOnly<T>\` -> \`Readonly<T>\`
|
|
9
|
+
- \`$ReadOnlyArray<T>\` -> \`ReadonlyArray<T>\`
|
|
10
|
+
- \`$ReadOnlyMap<K, V>\` -> \`ReadonlyMap<K, V>\`
|
|
11
|
+
- \`$ReadOnlySet<T>\` -> \`ReadonlySet<T>\`
|
|
12
|
+
- \`$Keys<T>\` -> \`keyof T\`
|
|
13
|
+
- \`$Values<T>\` -> \`Values<T>\`
|
|
14
|
+
- \`mixed\` -> \`unknown\``,
|
|
15
|
+
transform: context => {
|
|
16
|
+
return {
|
|
17
|
+
MixedTypeAnnotation(node) {
|
|
18
|
+
const newNode = t.GenericTypeAnnotation({
|
|
19
|
+
id: t.Identifier({
|
|
20
|
+
name: 'unknown'
|
|
21
|
+
})
|
|
22
|
+
});
|
|
23
|
+
context.replaceNode(node, newNode, {
|
|
24
|
+
keepComments: true
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
GenericTypeAnnotation(node) {
|
|
29
|
+
const id = node.id;
|
|
30
|
+
|
|
31
|
+
if (id.type !== 'Identifier') {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const typeName = id.name;
|
|
36
|
+
|
|
37
|
+
if (typeName === '$Keys') {
|
|
38
|
+
if (node.typeParameters && node.typeParameters.params && node.typeParameters.params.length === 1) {
|
|
39
|
+
const newNode = t.KeyofTypeAnnotation({
|
|
40
|
+
argument: node.typeParameters.params[0]
|
|
41
|
+
});
|
|
42
|
+
context.replaceNode(node, newNode, {
|
|
43
|
+
keepComments: true
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const typeMap = {
|
|
51
|
+
$NonMaybeType: 'NonNullable',
|
|
52
|
+
$ReadOnly: 'Readonly',
|
|
53
|
+
$ReadOnlyArray: 'ReadonlyArray',
|
|
54
|
+
$ReadOnlyMap: 'ReadonlyMap',
|
|
55
|
+
$ReadOnlySet: 'ReadonlySet',
|
|
56
|
+
$Values: 'Values'
|
|
57
|
+
};
|
|
58
|
+
const modernType = typeMap[typeName];
|
|
59
|
+
|
|
60
|
+
if (modernType) {
|
|
61
|
+
context.modifyNodeInPlace(node.id, {
|
|
62
|
+
name: modernType
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
});
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _Types = require("../Types");
|
|
9
|
-
|
|
10
|
-
var _default = (0, _Types.codemod)({
|
|
1
|
+
import { codemod } from '../Types';
|
|
2
|
+
export default codemod({
|
|
11
3
|
title: 'Convert `$Shape` to `Partial`',
|
|
12
4
|
describe: 'Converts usage of the `$Shape` utility type to `Partial`. It is possible that this will create type errors that you will have to resolve.',
|
|
13
5
|
transform: context => {
|
|
@@ -20,6 +12,4 @@ var _default = (0, _Types.codemod)({
|
|
|
20
12
|
|
|
21
13
|
};
|
|
22
14
|
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
exports.default = _default;
|
|
15
|
+
});
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
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");
|
|
1
|
+
import { codemod } from '../Types';
|
|
2
|
+
import { t } from 'hermes-transform';
|
|
11
3
|
|
|
12
4
|
function eliminateAbstractComponent(node) {
|
|
13
5
|
const {
|
|
@@ -23,16 +15,16 @@ function eliminateAbstractComponent(node) {
|
|
|
23
15
|
}
|
|
24
16
|
|
|
25
17
|
if (instance == null || instance.type === 'MixedTypeAnnotation') {
|
|
26
|
-
return
|
|
27
|
-
id:
|
|
28
|
-
qualification:
|
|
18
|
+
return t.GenericTypeAnnotation({
|
|
19
|
+
id: t.QualifiedTypeIdentifier({
|
|
20
|
+
qualification: t.Identifier({
|
|
29
21
|
name: 'React'
|
|
30
22
|
}),
|
|
31
|
-
id:
|
|
23
|
+
id: t.Identifier({
|
|
32
24
|
name: 'ComponentType'
|
|
33
25
|
})
|
|
34
26
|
}),
|
|
35
|
-
typeParameters:
|
|
27
|
+
typeParameters: t.TypeParameterInstantiation({
|
|
36
28
|
params: [config]
|
|
37
29
|
})
|
|
38
30
|
});
|
|
@@ -50,13 +42,13 @@ function eliminateAbstractComponent(node) {
|
|
|
50
42
|
}
|
|
51
43
|
|
|
52
44
|
if (maybeQualifiedIdentifier.type === 'QualifiedTypeIdentifier' && maybeQualifiedIdentifier.qualification.name === 'React' && maybeQualifiedIdentifier.id.name === 'ElementRef' && typeParameters != null && typeParameters.params.length === 1 && typeParameters.params[0].type === 'GenericTypeAnnotation' && typeParameters.params[0].id.type === 'QualifiedTypeIdentifier' && typeParameters.params[0].id.qualification.name === 'React' && typeParameters.params[0].id.id.name === 'AbstractComponent' && typeParameters.params[0].typeParameters != null && typeParameters.params[0].typeParameters.params.length === 1) {
|
|
53
|
-
return
|
|
45
|
+
return t.MixedTypeAnnotation({});
|
|
54
46
|
}
|
|
55
47
|
|
|
56
48
|
return null;
|
|
57
49
|
}
|
|
58
50
|
|
|
59
|
-
|
|
51
|
+
export default codemod({
|
|
60
52
|
title: 'Eliminate `React.AbstractComponent<...>`',
|
|
61
53
|
describe: `
|
|
62
54
|
- \`React.AbstractComponent<Props>\` -> \`React.ComponentType<Props>\`
|
|
@@ -77,6 +69,4 @@ var _default = (0, _Types.codemod)({
|
|
|
77
69
|
|
|
78
70
|
};
|
|
79
71
|
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
exports.default = _default;
|
|
72
|
+
});
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _Types = require("../Types");
|
|
9
|
-
|
|
10
|
-
var _default = (0, _Types.codemod)({
|
|
1
|
+
import { codemod } from '../Types';
|
|
2
|
+
export default codemod({
|
|
11
3
|
title: 'Remove Annotations In Destructuring',
|
|
12
4
|
describe: 'Remove annotations nested inside of destructuring. These are not valid Flow syntax.',
|
|
13
5
|
transform: context => {
|
|
@@ -26,6 +18,4 @@ var _default = (0, _Types.codemod)({
|
|
|
26
18
|
|
|
27
19
|
};
|
|
28
20
|
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
exports.default = _default;
|
|
21
|
+
});
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _getClassMemberName = require("../codemodUtils/getClassMemberName");
|
|
9
|
-
|
|
10
|
-
var _replaceMethodWithArrowProp = require("../codemodUtils/replaceMethodWithArrowProp");
|
|
11
|
-
|
|
12
|
-
var _Types = require("../Types");
|
|
1
|
+
import { getClassMemberName } from '../codemodUtils/getClassMemberName';
|
|
2
|
+
import { replaceMethodWithArrowProp } from '../codemodUtils/replaceMethodWithArrowProp';
|
|
3
|
+
import { codemod } from '../Types';
|
|
13
4
|
|
|
14
5
|
function getKind(member) {
|
|
15
6
|
switch (member.type) {
|
|
@@ -114,7 +105,7 @@ function findDuplicates(membersMap) {
|
|
|
114
105
|
return toDelete;
|
|
115
106
|
}
|
|
116
107
|
|
|
117
|
-
|
|
108
|
+
export default codemod({
|
|
118
109
|
title: 'Remove Duplicate Class Properties',
|
|
119
110
|
describe: 'Removes useless duplicate class properties and fixes bad constructor binding in those classes',
|
|
120
111
|
transform: context => {
|
|
@@ -126,7 +117,7 @@ var _default = (0, _Types.codemod)({
|
|
|
126
117
|
|
|
127
118
|
for (const member of node.body.body) {
|
|
128
119
|
const membersMap = member.static ? staticMembers : instanceMembers;
|
|
129
|
-
const name =
|
|
120
|
+
const name = getClassMemberName(member);
|
|
130
121
|
|
|
131
122
|
if (name == null) {
|
|
132
123
|
continue;
|
|
@@ -148,9 +139,7 @@ var _default = (0, _Types.codemod)({
|
|
|
148
139
|
}
|
|
149
140
|
|
|
150
141
|
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') {
|
|
142
|
+
if (memberToDelete.type === 'PropertyDefinition' && memberToDelete.value?.type === 'CallExpression') {
|
|
154
143
|
console.log(context.buildCodeFrame(memberToDelete.value, 'Deleted a property with a CallExpression value. You should double check this was safe.'));
|
|
155
144
|
}
|
|
156
145
|
|
|
@@ -168,7 +157,7 @@ var _default = (0, _Types.codemod)({
|
|
|
168
157
|
continue;
|
|
169
158
|
}
|
|
170
159
|
|
|
171
|
-
const name =
|
|
160
|
+
const name = getClassMemberName(member);
|
|
172
161
|
|
|
173
162
|
if (name == null) {
|
|
174
163
|
continue;
|
|
@@ -202,7 +191,7 @@ var _default = (0, _Types.codemod)({
|
|
|
202
191
|
const subjectName = node.property.name;
|
|
203
192
|
const member = instanceMembers.get(subjectName);
|
|
204
193
|
|
|
205
|
-
if (
|
|
194
|
+
if (member?.kind !== 'Method') {
|
|
206
195
|
return;
|
|
207
196
|
}
|
|
208
197
|
|
|
@@ -227,21 +216,15 @@ var _default = (0, _Types.codemod)({
|
|
|
227
216
|
throw new Error('this cannot happen');
|
|
228
217
|
}
|
|
229
218
|
|
|
230
|
-
|
|
219
|
+
replaceMethodWithArrowProp(context, method, subjectName);
|
|
231
220
|
},
|
|
232
221
|
|
|
233
222
|
'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;
|
|
223
|
+
if (classStack && classStack?.current === node) {
|
|
224
|
+
classStack = classStack?.parent;
|
|
240
225
|
}
|
|
241
226
|
}
|
|
242
227
|
|
|
243
228
|
};
|
|
244
229
|
}
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
exports.default = _default;
|
|
230
|
+
});
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _Types = require("../Types");
|
|
9
|
-
|
|
10
|
-
var _default = (0, _Types.codemod)({
|
|
1
|
+
import { codemod } from '../Types';
|
|
2
|
+
export default codemod({
|
|
11
3
|
title: 'Remove explicitly exact object type syntax',
|
|
12
4
|
describe: 'Convert explicitly exact object type syntax `{| |}` to be just be `{ }`. To be done after you turn on `exact_by_default=true` in your `.flowconfig`.',
|
|
13
5
|
transform: context => {
|
|
@@ -20,6 +12,4 @@ var _default = (0, _Types.codemod)({
|
|
|
20
12
|
|
|
21
13
|
};
|
|
22
14
|
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
exports.default = _default;
|
|
15
|
+
});
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _Types = require("../Types");
|
|
9
|
-
|
|
10
|
-
var _default = (0, _Types.codemod)({
|
|
1
|
+
import { codemod } from '../Types';
|
|
2
|
+
export default codemod({
|
|
11
3
|
title: 'Rename `$Partial` to `Partial`',
|
|
12
4
|
describe: 'Renames the `$Partial` type utility to `Partial`.',
|
|
13
5
|
transform: context => {
|
|
@@ -20,6 +12,4 @@ var _default = (0, _Types.codemod)({
|
|
|
20
12
|
|
|
21
13
|
};
|
|
22
14
|
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
exports.default = _default;
|
|
15
|
+
});
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _hermesTransform = require("hermes-transform");
|
|
9
|
-
|
|
10
|
-
var _Types = require("../Types");
|
|
11
|
-
|
|
1
|
+
import { t } from 'hermes-transform';
|
|
2
|
+
import { codemod } from '../Types';
|
|
12
3
|
const UTILITY_TYPES = new Set(['React$ComponentType', 'React$AbstractComponent', 'React$Element', 'React$MixedElement', 'React$ElementType', 'React$Key', 'React$Ref', 'React$RefSetter', 'React$Node', 'React$Context', 'React$Portal', 'React$ElementProps', 'React$ElementConfig', 'React$ElementRef', 'React$Config', 'React$Config', 'React$RefObject']);
|
|
13
|
-
|
|
14
|
-
var _default = (0, _Types.codemod)({
|
|
4
|
+
export default codemod({
|
|
15
5
|
title: 'Replace React$SomeUtilityType with React.SomeUtilityType.',
|
|
16
6
|
transform: context => {
|
|
17
7
|
return {
|
|
@@ -26,23 +16,20 @@ var _default = (0, _Types.codemod)({
|
|
|
26
16
|
return;
|
|
27
17
|
}
|
|
28
18
|
|
|
29
|
-
const newNode =
|
|
30
|
-
id:
|
|
31
|
-
id:
|
|
19
|
+
const newNode = t.GenericTypeAnnotation({
|
|
20
|
+
id: t.QualifiedTypeIdentifier({
|
|
21
|
+
id: t.Identifier({
|
|
32
22
|
name: utilTypeName.substring('React$'.length)
|
|
33
23
|
}),
|
|
34
|
-
qualification:
|
|
24
|
+
qualification: t.Identifier({
|
|
35
25
|
name: 'React'
|
|
36
26
|
})
|
|
37
27
|
}),
|
|
38
28
|
typeParameters: node.typeParameters
|
|
39
29
|
});
|
|
40
|
-
|
|
41
30
|
context.replaceNode(node, newNode);
|
|
42
31
|
}
|
|
43
32
|
|
|
44
33
|
};
|
|
45
34
|
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
exports.default = _default;
|
|
35
|
+
});
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _hermesTransform = require("hermes-transform");
|
|
9
|
-
|
|
10
|
-
var _Types = require("../Types");
|
|
11
|
-
|
|
12
|
-
var _default = (0, _Types.codemod)({
|
|
1
|
+
import { t } from 'hermes-transform';
|
|
2
|
+
import { codemod } from '../Types';
|
|
3
|
+
export default codemod({
|
|
13
4
|
title: 'Replace $TEMPORARY$ types',
|
|
14
5
|
describe: ['Converts:', ' - `$TEMPORARY$object<{props}>` to `$ReadOnly<{props}>`', ' - `$TEMPORARY$array<T>` to `$ReadOnlyArray<T>`', ' - `$TEMPORARY$number<42>` annotations to `number`', ' - `$TEMPORARY$string<"foo">` annotations to `string`'].join('\n'),
|
|
15
6
|
transform: context => {
|
|
@@ -19,7 +10,7 @@ var _default = (0, _Types.codemod)({
|
|
|
19
10
|
|
|
20
11
|
if (id.type === 'Identifier' && id.name === '$TEMPORARY$object' && node.typeParameters != null) {
|
|
21
12
|
context.modifyNodeInPlace(node, {
|
|
22
|
-
id:
|
|
13
|
+
id: t.Identifier({
|
|
23
14
|
name: '$ReadOnly'
|
|
24
15
|
})
|
|
25
16
|
});
|
|
@@ -27,23 +18,21 @@ var _default = (0, _Types.codemod)({
|
|
|
27
18
|
|
|
28
19
|
if (id.type === 'Identifier' && id.name === '$TEMPORARY$array' && node.typeParameters != null) {
|
|
29
20
|
context.modifyNodeInPlace(node, {
|
|
30
|
-
id:
|
|
21
|
+
id: t.Identifier({
|
|
31
22
|
name: '$ReadOnlyArray'
|
|
32
23
|
})
|
|
33
24
|
});
|
|
34
25
|
}
|
|
35
26
|
|
|
36
27
|
if (id.type === 'Identifier' && id.name === '$TEMPORARY$number') {
|
|
37
|
-
const new_node =
|
|
38
|
-
|
|
28
|
+
const new_node = t.NumberTypeAnnotation();
|
|
39
29
|
context.replaceNode(node, new_node, {
|
|
40
30
|
keepComments: true
|
|
41
31
|
});
|
|
42
32
|
}
|
|
43
33
|
|
|
44
34
|
if (id.type === 'Identifier' && id.name === '$TEMPORARY$string') {
|
|
45
|
-
const new_node =
|
|
46
|
-
|
|
35
|
+
const new_node = t.StringTypeAnnotation();
|
|
47
36
|
context.replaceNode(node, new_node, {
|
|
48
37
|
keepComments: true
|
|
49
38
|
});
|
|
@@ -52,6 +41,4 @@ var _default = (0, _Types.codemod)({
|
|
|
52
41
|
|
|
53
42
|
};
|
|
54
43
|
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
exports.default = _default;
|
|
44
|
+
});
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
|
|
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");
|
|
1
|
+
import { codemod } from '../Types';
|
|
2
|
+
import { t } from 'hermes-transform';
|
|
11
3
|
|
|
12
4
|
function convertTypeCast(node) {
|
|
13
5
|
const {
|
|
@@ -16,13 +8,13 @@ function convertTypeCast(node) {
|
|
|
16
8
|
typeAnnotation
|
|
17
9
|
}
|
|
18
10
|
} = node;
|
|
19
|
-
return
|
|
11
|
+
return t.AsExpression({
|
|
20
12
|
expression: expression.type === 'TypeCastExpression' ? convertTypeCast(expression) : expression,
|
|
21
13
|
typeAnnotation
|
|
22
14
|
});
|
|
23
15
|
}
|
|
24
16
|
|
|
25
|
-
|
|
17
|
+
export default codemod({
|
|
26
18
|
title: 'Update type casting syntax',
|
|
27
19
|
describe: 'Convert type cast expressions `(<expr>: <type>)` to as expressions `<expr> as <type>`',
|
|
28
20
|
transform: context => {
|
|
@@ -36,6 +28,4 @@ var _default = (0, _Types.codemod)({
|
|
|
36
28
|
|
|
37
29
|
};
|
|
38
30
|
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
exports.default = _default;
|
|
31
|
+
});
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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)({
|
|
1
|
+
import { codemod } from '../Types';
|
|
2
|
+
import { t } from 'hermes-transform';
|
|
3
|
+
export default codemod({
|
|
13
4
|
title: 'Replace `T: {}` with `T: {...}` in type parameter bounds',
|
|
14
5
|
describe: 'Replace `T: {}` with `T: {...}` in type parameter bounds',
|
|
15
6
|
transform: context => {
|
|
@@ -19,7 +10,7 @@ var _default = (0, _Types.codemod)({
|
|
|
19
10
|
const annotation = node.bound.typeAnnotation;
|
|
20
11
|
|
|
21
12
|
if (annotation.type === 'ObjectTypeAnnotation' && !annotation.inexact && annotation.properties.length === 0 && annotation.callProperties.length === 0 && annotation.indexers.length === 0 && annotation.internalSlots.length === 0) {
|
|
22
|
-
context.replaceNode(annotation,
|
|
13
|
+
context.replaceNode(annotation, t.ObjectTypeAnnotation({
|
|
23
14
|
properties: [],
|
|
24
15
|
callProperties: [],
|
|
25
16
|
exact: false,
|
|
@@ -33,6 +24,4 @@ var _default = (0, _Types.codemod)({
|
|
|
33
24
|
|
|
34
25
|
};
|
|
35
26
|
}
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
exports.default = _default;
|
|
27
|
+
});
|
package/dist/findFlowFiles.js
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.findFlowFiles = findFlowFiles;
|
|
7
|
-
exports.findFlowFilesWithSpinner = findFlowFilesWithSpinner;
|
|
8
|
-
|
|
9
|
-
var _path = _interopRequireDefault(require("path"));
|
|
10
|
-
|
|
11
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
12
|
-
|
|
13
|
-
var _ora = _interopRequireDefault(require("ora"));
|
|
14
|
-
|
|
15
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
16
|
-
|
|
17
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
-
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import ora from 'ora';
|
|
4
|
+
import chalk from 'chalk';
|
|
19
5
|
const PRAGMA_BYTES = 5000;
|
|
20
|
-
|
|
21
|
-
async function findFlowFiles({
|
|
6
|
+
export async function findFlowFiles({
|
|
22
7
|
includeNonAtFlow,
|
|
23
8
|
rootDirectory
|
|
24
9
|
}) {
|
|
@@ -27,14 +12,13 @@ async function findFlowFiles({
|
|
|
27
12
|
return filePaths;
|
|
28
13
|
|
|
29
14
|
async function processDirectory(directory) {
|
|
30
|
-
const fileNames = await
|
|
15
|
+
const fileNames = await fs.readdir(directory);
|
|
31
16
|
await Promise.all(fileNames.map(fileName => processFilePath(directory, fileName)));
|
|
32
17
|
}
|
|
33
18
|
|
|
34
19
|
async function processFilePath(directory, fileName) {
|
|
35
|
-
const filePath =
|
|
36
|
-
|
|
37
|
-
const stats = await _fsExtra.default.lstat(filePath);
|
|
20
|
+
const filePath = path.join(directory, fileName);
|
|
21
|
+
const stats = await fs.lstat(filePath);
|
|
38
22
|
|
|
39
23
|
if (stats.isDirectory()) {
|
|
40
24
|
if (fileName !== 'node_modules' && fileName !== 'flow-typed' && fileName !== '__flowtests__') {
|
|
@@ -60,22 +44,21 @@ async function findFlowFiles({
|
|
|
60
44
|
return;
|
|
61
45
|
}
|
|
62
46
|
|
|
63
|
-
const file = await
|
|
47
|
+
const file = await fs.open(filePath, 'r');
|
|
64
48
|
const bytes = Math.min(PRAGMA_BYTES, fileByteSize);
|
|
65
49
|
const buffer = Buffer.alloc(bytes);
|
|
66
|
-
await
|
|
50
|
+
await fs.read(file, buffer, 0, bytes, 0);
|
|
67
51
|
|
|
68
52
|
if (buffer.includes('@flow')) {
|
|
69
53
|
filePaths.push(filePath);
|
|
70
54
|
}
|
|
71
55
|
|
|
72
|
-
await
|
|
56
|
+
await fs.close(file);
|
|
73
57
|
}
|
|
74
58
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
text: _chalk.default.italic.cyan('Finding all the Flow files to be upgraded...'),
|
|
59
|
+
export async function findFlowFilesWithSpinner(rootDirectory, options) {
|
|
60
|
+
const spinner = ora({
|
|
61
|
+
text: chalk.italic.cyan('Finding all the Flow files to be upgraded...'),
|
|
79
62
|
color: 'cyan',
|
|
80
63
|
isSilent: options.silent
|
|
81
64
|
});
|
|
@@ -94,7 +77,7 @@ async function findFlowFilesWithSpinner(rootDirectory, options) {
|
|
|
94
77
|
spinner.stop();
|
|
95
78
|
|
|
96
79
|
if (!options.silent) {
|
|
97
|
-
console.log(`Found ${
|
|
80
|
+
console.log(`Found ${chalk.bold.cyan(filePaths.length)} Flow files.`);
|
|
98
81
|
console.log();
|
|
99
82
|
}
|
|
100
83
|
|
package/dist/runCodemods.js
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = runCodemods;
|
|
7
|
-
|
|
8
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
9
|
-
|
|
10
|
-
var _hermesTransform = require("hermes-transform");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
async function runCodemods(codemods, filePaths, options) {
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import { transform } from 'hermes-transform';
|
|
3
|
+
export default async function runCodemods(codemods, filePaths, options) {
|
|
15
4
|
const results = await Promise.allSettled(filePaths.map(async filePath => {
|
|
16
|
-
|
|
5
|
+
if (typeof require !== 'undefined' && require.cache) {
|
|
6
|
+
Object.keys(require.cache).forEach(key => {
|
|
7
|
+
if (key.includes('hermes-transform') || key.includes('prettier')) {
|
|
8
|
+
delete require.cache[key];
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const originalContents = await fs.readFile(filePath, 'utf8');
|
|
17
14
|
let contents = originalContents;
|
|
18
15
|
|
|
19
16
|
for (const codemod of codemods) {
|
|
20
|
-
contents = await
|
|
17
|
+
contents = await transform(contents, codemod.transform, options.prettierOptions);
|
|
21
18
|
}
|
|
22
19
|
|
|
23
20
|
if (originalContents !== contents) {
|
|
24
|
-
await
|
|
21
|
+
await fs.writeFile(filePath, contents, 'utf8');
|
|
25
22
|
}
|
|
26
23
|
}));
|
|
27
24
|
}
|
package/dist/upgrade.js
CHANGED
|
@@ -1,53 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
11
|
-
|
|
12
|
-
var _ora = _interopRequireDefault(require("ora"));
|
|
13
|
-
|
|
14
|
-
var _promptConfirm = _interopRequireDefault(require("prompt-confirm"));
|
|
15
|
-
|
|
16
|
-
var _Styled = _interopRequireDefault(require("./Styled"));
|
|
17
|
-
|
|
18
|
-
var _findFlowFiles = require("./findFlowFiles");
|
|
19
|
-
|
|
20
|
-
var _runCodemods = _interopRequireDefault(require("./runCodemods"));
|
|
21
|
-
|
|
22
|
-
var _upgrades = require("./upgrades");
|
|
23
|
-
|
|
24
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
|
-
async function upgrade(directory, currentVersion, nextVersion, options) {
|
|
1
|
+
import semver from 'semver';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import ora from 'ora';
|
|
4
|
+
import Confirm from 'prompt-confirm';
|
|
5
|
+
import Styled from './Styled';
|
|
6
|
+
import { findFlowFilesWithSpinner } from './findFlowFiles';
|
|
7
|
+
import runCodemods from './runCodemods';
|
|
8
|
+
import { VERSION_UPGRADES } from './upgrades';
|
|
9
|
+
export default async function upgrade(directory, currentVersion, nextVersion, options) {
|
|
27
10
|
const log = options.silent ? () => {} : (...messages) => console.log(...messages);
|
|
28
11
|
const allUpgrades = [];
|
|
29
12
|
|
|
30
|
-
for (let i = 0; i <
|
|
13
|
+
for (let i = 0; i < VERSION_UPGRADES.length; i++) {
|
|
31
14
|
const {
|
|
32
15
|
version,
|
|
33
16
|
upgrades
|
|
34
|
-
} =
|
|
17
|
+
} = VERSION_UPGRADES[i];
|
|
35
18
|
|
|
36
|
-
if (
|
|
19
|
+
if (semver.cmp(version, '>', nextVersion)) {
|
|
37
20
|
break;
|
|
38
21
|
}
|
|
39
22
|
|
|
40
|
-
if (
|
|
23
|
+
if (semver.cmp(version, '>', currentVersion)) {
|
|
41
24
|
upgrades.forEach(upgrade => allUpgrades.push(upgrade));
|
|
42
25
|
}
|
|
43
26
|
}
|
|
44
27
|
|
|
45
28
|
log();
|
|
46
|
-
log(
|
|
29
|
+
log(Styled.sectionHeader('flow-upgrade'));
|
|
47
30
|
log();
|
|
48
31
|
{
|
|
49
|
-
const titleStyled =
|
|
50
|
-
|
|
32
|
+
const titleStyled = chalk.bold('flow-upgrade');
|
|
51
33
|
const message = `
|
|
52
34
|
Thank you for choosing to upgrade Flow. In every release the Flow community adds
|
|
53
35
|
new features and improves the performance of Flow to better serve you and your
|
|
@@ -65,28 +47,28 @@ using git make sure you've commit the changes in your working directory.) After
|
|
|
65
47
|
running ${titleStyled} review the changes that were made and manually tweak
|
|
66
48
|
your code until you are happy with the upgrade.
|
|
67
49
|
|
|
68
|
-
The Flow version you're upgrading from: ${
|
|
69
|
-
The Flow version you're upgrading to: ${
|
|
50
|
+
The Flow version you're upgrading from: ${chalk.bold.magenta(currentVersion)}
|
|
51
|
+
The Flow version you're upgrading to: ${chalk.bold.green(nextVersion)}
|
|
70
52
|
|
|
71
|
-
We will assume that your code is valid Flow ${
|
|
53
|
+
We will assume that your code is valid Flow ${chalk.bold.magenta(currentVersion)} code.
|
|
72
54
|
|
|
73
55
|
We will be running the following steps to upgrade your codebase. Each step will
|
|
74
56
|
print a short message explaining what it does before it runs, but we won't stop
|
|
75
57
|
to ask you for reconfirmation once we begin upgrading.
|
|
76
58
|
|
|
77
|
-
${allUpgrades.map((u, i) =>
|
|
59
|
+
${allUpgrades.map((u, i) => Styled.upgradeTitle(u.title, i + 1)).join('\n')}
|
|
78
60
|
|
|
79
|
-
Today we will be upgrading all JavaScript files using Flow in: ${
|
|
61
|
+
Today we will be upgrading all JavaScript files using Flow in: ${chalk.bold.magenta(directory)}
|
|
80
62
|
|
|
81
63
|
Excluding any JavaScript files in node_modules directories, in flow-typed
|
|
82
64
|
directories, in __flowtests__ directories, or files ending in -flowtest.js.
|
|
83
65
|
`.slice(1);
|
|
84
66
|
log(message);
|
|
85
67
|
}
|
|
86
|
-
const filePaths = await
|
|
87
|
-
log(
|
|
68
|
+
const filePaths = await findFlowFilesWithSpinner(directory, options);
|
|
69
|
+
log(chalk.bold.red('Please review this information to make sure that it is correct before proceeding.'));
|
|
88
70
|
log();
|
|
89
|
-
const answer = options.yes || (await new
|
|
71
|
+
const answer = options.yes || (await new Confirm('Are you ready to begin the upgrade?').run());
|
|
90
72
|
|
|
91
73
|
if (!answer) {
|
|
92
74
|
log();
|
|
@@ -106,27 +88,27 @@ directories, in __flowtests__ directories, or files ending in -flowtest.js.
|
|
|
106
88
|
codemods.push(allUpgrades.shift());
|
|
107
89
|
}
|
|
108
90
|
|
|
109
|
-
log(
|
|
91
|
+
log(Styled.sectionHeader('Codemods'));
|
|
110
92
|
log();
|
|
111
93
|
log('We are now going to run the following codemods:');
|
|
112
94
|
log();
|
|
113
|
-
log(codemods.map((u, i) =>
|
|
95
|
+
log(codemods.map((u, i) => Styled.upgradeTitle(u.title, i + 1)).join('\n'));
|
|
114
96
|
log();
|
|
115
97
|
log('Following is a short description of each codemod listed above so ' + 'that you know\nhow your code is being upgraded.');
|
|
116
98
|
log();
|
|
117
|
-
log(
|
|
99
|
+
log(Styled.divider());
|
|
118
100
|
log();
|
|
119
101
|
codemods.forEach((u, i) => {
|
|
120
|
-
log(
|
|
102
|
+
log(Styled.upgradeTitle(u.title, i + 1));
|
|
121
103
|
log();
|
|
122
104
|
log(u.describe);
|
|
123
105
|
log();
|
|
124
|
-
log(
|
|
106
|
+
log(Styled.divider());
|
|
125
107
|
log();
|
|
126
108
|
});
|
|
127
|
-
log(`Running ${
|
|
109
|
+
log(`Running ${chalk.bold.cyan(codemods.length)} codemods...`);
|
|
128
110
|
log();
|
|
129
|
-
await (
|
|
111
|
+
await runCodemods(codemods, filePaths, options);
|
|
130
112
|
break;
|
|
131
113
|
}
|
|
132
114
|
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _removeDuplicateClassProperties = _interopRequireDefault(require("../../codemods/removeDuplicateClassProperties"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
var _default = {
|
|
1
|
+
import removeDuplicateClassProperties from '../../codemods/removeDuplicateClassProperties';
|
|
2
|
+
export default {
|
|
13
3
|
version: '0.170.0',
|
|
14
|
-
upgrades: [
|
|
15
|
-
};
|
|
16
|
-
exports.default = _default;
|
|
4
|
+
upgrades: [removeDuplicateClassProperties]
|
|
5
|
+
};
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _removeAnnotationsInDestructuring = _interopRequireDefault(require("../../codemods/removeAnnotationsInDestructuring"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
var _default = {
|
|
1
|
+
import removeAnnotationsInDestructuring from '../../codemods/removeAnnotationsInDestructuring';
|
|
2
|
+
export default {
|
|
13
3
|
version: '0.176.0',
|
|
14
|
-
upgrades: [
|
|
15
|
-
};
|
|
16
|
-
exports.default = _default;
|
|
4
|
+
upgrades: [removeAnnotationsInDestructuring]
|
|
5
|
+
};
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
|
|
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
|
-
var _default = {
|
|
1
|
+
import renamePartial from '../../codemods/renamePartial';
|
|
2
|
+
export default {
|
|
13
3
|
version: '0.201.0',
|
|
14
|
-
upgrades: [
|
|
15
|
-
};
|
|
16
|
-
exports.default = _default;
|
|
4
|
+
upgrades: [renamePartial]
|
|
5
|
+
};
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _convertImplicitInexactObjectTypes = _interopRequireDefault(require("../../codemods/convertImplicitInexactObjectTypes"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
var _default = {
|
|
1
|
+
import convertImplicitInexactObjectTypes from '../../codemods/convertImplicitInexactObjectTypes';
|
|
2
|
+
export default {
|
|
13
3
|
version: '0.84.0',
|
|
14
|
-
upgrades: [
|
|
15
|
-
};
|
|
16
|
-
exports.default = _default;
|
|
4
|
+
upgrades: [convertImplicitInexactObjectTypes]
|
|
5
|
+
};
|
package/dist/upgrades/index.js
CHANGED
|
@@ -1,19 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.VERSION_UPGRADES = void 0;
|
|
7
|
-
|
|
8
|
-
var _ = _interopRequireDefault(require("./0.84.0"));
|
|
9
|
-
|
|
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"));
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
const VERSION_UPGRADES = [_.default, _2.default, _3.default, _4.default];
|
|
19
|
-
exports.VERSION_UPGRADES = VERSION_UPGRADES;
|
|
1
|
+
import v0_84_0 from './0.84.0';
|
|
2
|
+
import v0_170_0 from './0.170.0';
|
|
3
|
+
import v0_176_0 from './0.176.0';
|
|
4
|
+
import v0_201_0 from './0.201.0';
|
|
5
|
+
export const VERSION_UPGRADES = [v0_84_0, v0_170_0, v0_176_0, v0_201_0];
|
|
@@ -1,25 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.redirectConsole = redirectConsole;
|
|
7
|
-
exports.restoreConsole = restoreConsole;
|
|
8
|
-
|
|
9
|
-
var util = _interopRequireWildcard(require("util"));
|
|
10
|
-
|
|
11
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
-
|
|
13
|
-
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; }
|
|
14
|
-
|
|
3
|
+
import * as util from 'util';
|
|
15
4
|
const oldConsole = {
|
|
16
5
|
error: console.error,
|
|
17
6
|
info: console.info,
|
|
18
7
|
log: console.log,
|
|
19
8
|
warn: console.warn
|
|
20
9
|
};
|
|
21
|
-
|
|
22
|
-
function redirectConsole(reporter_) {
|
|
10
|
+
export function redirectConsole(reporter_) {
|
|
23
11
|
const reporter = typeof reporter_ === 'function' ? reporter_(oldConsole) : reporter_;
|
|
24
12
|
|
|
25
13
|
console.log = (...args) => {
|
|
@@ -38,8 +26,7 @@ function redirectConsole(reporter_) {
|
|
|
38
26
|
reporter.onStderr(util.format(...args));
|
|
39
27
|
};
|
|
40
28
|
}
|
|
41
|
-
|
|
42
|
-
function restoreConsole() {
|
|
29
|
+
export function restoreConsole() {
|
|
43
30
|
for (const [name, fn] of Object.entries(oldConsole)) {
|
|
44
31
|
console[name] = fn;
|
|
45
32
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flow-upgrade",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "A utility for upgrading your codebase to the latest version of Flow.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=14"
|
|
@@ -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"
|