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