flow-upgrade 1.0.4 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -2
- package/dist/Styled.js +12 -14
- package/dist/Types.js +21 -1
- package/dist/bin/runSpecificCodemod.js +117 -0
- package/dist/bin/upgrade.js +75 -0
- package/dist/codemodUtils/getClassMemberName.js +27 -0
- package/dist/codemodUtils/replaceMethodWithArrowProp.js +60 -0
- package/dist/codemods/collapseObjectInitialization.js +250 -0
- package/dist/codemods/convertImplicitInexactObjectTypes.js +35 -0
- package/dist/codemods/removeAnnotationsInDestructuring.js +40 -0
- package/dist/codemods/removeDuplicateClassProperties.js +268 -0
- package/dist/findFlowFiles.js +136 -156
- package/dist/runCodemods.js +36 -0
- package/dist/upgrade.js +127 -150
- package/dist/upgrades/0.170.0/index.js +25 -0
- package/dist/upgrades/0.176.0/index.js +25 -0
- package/dist/upgrades/0.84.0/index.js +25 -0
- package/dist/upgrades/index.js +29 -0
- package/dist/utils/redirectConsole.js +59 -0
- package/package.json +36 -20
- package/dist/codemods/ReactUtils.js +0 -140
- package/dist/codemods/createAggregateCodemod.js +0 -36
- package/dist/codemods/runCodemods.js +0 -53
- package/dist/index.js +0 -26
- package/dist/upgrades/0.53.0/ReactComponentExplicitTypeArgs/codemod.js +0 -154
- package/dist/upgrades/0.53.0/ReactComponentExplicitTypeArgs/index.js +0 -75
- package/dist/upgrades/0.53.0/ReactComponentSimplifyTypeArgs/codemod.js +0 -65
- package/dist/upgrades/0.53.0/ReactComponentSimplifyTypeArgs/index.js +0 -52
- package/dist/upgrades/0.53.0/ReactUtilityTypes/codemod.js +0 -200
- package/dist/upgrades/0.53.0/ReactUtilityTypes/index.js +0 -59
package/dist/upgrade.js
CHANGED
|
@@ -1,66 +1,72 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = upgrade;
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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"));
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 }; }
|
|
16
25
|
|
|
17
26
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
27
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
28
|
+
*
|
|
29
|
+
* This source code is licensed under the MIT license found in the
|
|
30
|
+
* LICENSE file in the root directory of this source tree.
|
|
31
|
+
*
|
|
32
|
+
* @format
|
|
33
|
+
*
|
|
20
34
|
*/
|
|
21
|
-
const VERSION_UPGRADES = [
|
|
22
|
-
// We started writing and distributing upgrades with `flow-upgrade` after Flow
|
|
23
|
-
// version 0.52.0. We assume that you have valid Flow 0.52.0 code and are not
|
|
24
|
-
// backporting any previous automated upgrades.
|
|
25
|
-
|
|
26
|
-
{
|
|
27
|
-
version: '0.53.0',
|
|
28
|
-
upgrades: [require('./upgrades/0.53.0/ReactComponentExplicitTypeArgs'), require('./upgrades/0.53.0/ReactComponentSimplifyTypeArgs'), require('./upgrades/0.53.0/ReactUtilityTypes')]
|
|
29
|
-
}];
|
|
30
35
|
|
|
31
36
|
/**
|
|
32
37
|
* Decides all of the upgrades that will need to be run when moving from one
|
|
33
38
|
* version to another and runs them asynchronously.
|
|
34
39
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
}
|
|
40
|
+
async function upgrade(directory, currentVersion, nextVersion, options) {
|
|
41
|
+
const log = options.silent ? () => {} : (...messages) => console.log(...messages);
|
|
42
|
+
const allUpgrades = []; // Collect all of the upgrades we will need to run.
|
|
43
|
+
|
|
44
|
+
for (let i = 0; i < _upgrades.VERSION_UPGRADES.length; i++) {
|
|
45
|
+
const {
|
|
46
|
+
version,
|
|
47
|
+
upgrades
|
|
48
|
+
} = _upgrades.VERSION_UPGRADES[i]; // If the version number is larger then the version we are upgrading to we
|
|
49
|
+
// are done! Do not add any more upgrades,
|
|
50
|
+
|
|
51
|
+
if (_semver.default.cmp(version, '>', nextVersion)) {
|
|
52
|
+
break;
|
|
53
|
+
} // If the version number is larget then the current version, but not larger
|
|
54
|
+
// then the next version then we want to run the upgrades for this version.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
if (_semver.default.cmp(version, '>', currentVersion)) {
|
|
58
|
+
upgrades.forEach(upgrade => allUpgrades.push(upgrade));
|
|
56
59
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
log();
|
|
63
|
+
log(_Styled.default.sectionHeader('flow-upgrade'));
|
|
64
|
+
log();
|
|
65
|
+
{
|
|
66
|
+
const titleStyled = _chalk.default.bold('flow-upgrade'); // Log the initial intro message for our user.
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
const message = `
|
|
64
70
|
Thank you for choosing to upgrade Flow. In every release the Flow community adds
|
|
65
71
|
new features and improves the performance of Flow to better serve you and your
|
|
66
72
|
team. Upgrading gives you the best that Flow has to offer.
|
|
@@ -77,115 +83,86 @@ using git make sure you've commit the changes in your working directory.) After
|
|
|
77
83
|
running ${titleStyled} review the changes that were made and manually tweak
|
|
78
84
|
your code until you are happy with the upgrade.
|
|
79
85
|
|
|
80
|
-
The Flow version you're upgrading from: ${
|
|
81
|
-
The Flow version you're upgrading to: ${
|
|
86
|
+
The Flow version you're upgrading from: ${_chalk.default.bold.magenta(currentVersion)}
|
|
87
|
+
The Flow version you're upgrading to: ${_chalk.default.bold.green(nextVersion)}
|
|
82
88
|
|
|
83
|
-
We will assume that your code is valid Flow ${
|
|
89
|
+
We will assume that your code is valid Flow ${_chalk.default.bold.magenta(currentVersion)} code.
|
|
84
90
|
|
|
85
91
|
We will be running the following steps to upgrade your codebase. Each step will
|
|
86
92
|
print a short message explaining what it does before it runs, but we won't stop
|
|
87
93
|
to ask you for reconfirmation once we begin upgrading.
|
|
88
94
|
|
|
89
|
-
${allUpgrades.map(
|
|
90
|
-
return Styled.upgradeTitle(u.title, i + 1);
|
|
91
|
-
}).join('\n')}
|
|
95
|
+
${allUpgrades.map((u, i) => _Styled.default.upgradeTitle(u.title, i + 1)).join('\n')}
|
|
92
96
|
|
|
93
|
-
Today we will be upgrading all JavaScript files using Flow in: ${
|
|
97
|
+
Today we will be upgrading all JavaScript files using Flow in: ${_chalk.default.bold.magenta(directory)}
|
|
94
98
|
|
|
95
99
|
Excluding any JavaScript files in node_modules directories, in flow-typed
|
|
96
100
|
directories, in __flowtests__ directories, or files ending in -flowtest.js.
|
|
97
101
|
`.slice(1);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
//
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
102
|
+
log(message);
|
|
103
|
+
} // Find all of the Flow files in the directory we are upgrading.
|
|
104
|
+
|
|
105
|
+
const filePaths = await (0, _findFlowFiles.findFlowFilesWithSpinner)(directory, options); // Make sure the user knows that they should review their information before
|
|
106
|
+
// proceeding.
|
|
107
|
+
|
|
108
|
+
log(_chalk.default.bold.red('Please review this information to make sure that it is correct before proceeding.'));
|
|
109
|
+
log(); // Ask the user for confirmation.
|
|
110
|
+
|
|
111
|
+
const answer = options.yes || (await new _promptConfirm.default('Are you ready to begin the upgrade?').run()); // If the user did not let us continue then log a new line and do not
|
|
112
|
+
// continue.
|
|
113
|
+
|
|
114
|
+
if (!answer) {
|
|
115
|
+
log();
|
|
116
|
+
return;
|
|
117
|
+
} // Run through all of our upgrades.
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
while (allUpgrades.length) {
|
|
121
|
+
// Put some space between us and the last upgrade.
|
|
122
|
+
log(); // Get the next upgrade.
|
|
123
|
+
|
|
124
|
+
const upgrade = allUpgrades.shift();
|
|
125
|
+
|
|
126
|
+
switch (upgrade.kind) {
|
|
127
|
+
// If this is a codemod, collect all codemods after it as well and execute
|
|
128
|
+
// those codemods together.
|
|
129
|
+
case 'codemod':
|
|
130
|
+
{
|
|
131
|
+
const codemods = [upgrade]; // While the next upgrade is a codemod, add it to our `codemods` array.
|
|
132
|
+
|
|
133
|
+
while (allUpgrades[0] && allUpgrades[0].kind === 'codemod') {
|
|
134
|
+
codemods.push(allUpgrades.shift());
|
|
135
|
+
} // Tell the user what we are about to do.
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
log(_Styled.default.sectionHeader('Codemods'));
|
|
139
|
+
log();
|
|
140
|
+
log('We are now going to run the following codemods:');
|
|
141
|
+
log();
|
|
142
|
+
log(codemods.map((u, i) => _Styled.default.upgradeTitle(u.title, i + 1)).join('\n'));
|
|
143
|
+
log();
|
|
144
|
+
log('Following is a short description of each codemod listed above so ' + 'that you know\nhow your code is being upgraded.');
|
|
145
|
+
log();
|
|
146
|
+
log(_Styled.default.divider());
|
|
147
|
+
log();
|
|
148
|
+
codemods.forEach((u, i) => {
|
|
149
|
+
log(_Styled.default.upgradeTitle(u.title, i + 1));
|
|
150
|
+
log();
|
|
151
|
+
log(u.description);
|
|
152
|
+
log();
|
|
153
|
+
log(_Styled.default.divider());
|
|
154
|
+
log();
|
|
155
|
+
});
|
|
156
|
+
log(`Running ${_chalk.default.bold.cyan(codemods.length)} codemods...`);
|
|
157
|
+
log(); // Run all of our codemods.
|
|
158
|
+
|
|
159
|
+
await (0, _runCodemods.default)(codemods, filePaths, options);
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
// Throw an error for all other kinds of upgrades.
|
|
163
|
+
|
|
164
|
+
default:
|
|
165
|
+
throw new Error(`Unexpected upgrade kind: '${upgrade.kind}'`);
|
|
132
166
|
}
|
|
133
|
-
// Run through all of our upgrades.
|
|
134
|
-
while (allUpgrades.length) {
|
|
135
|
-
// Put some space between us and the last upgrade.
|
|
136
|
-
console.log();
|
|
137
|
-
// Get the next upgrade.
|
|
138
|
-
const upgrade = allUpgrades.shift();
|
|
139
|
-
switch (upgrade.kind) {
|
|
140
|
-
// If this is a codemod, collect all codemods after it as well and execute
|
|
141
|
-
// those codemods together.
|
|
142
|
-
case 'codemod':
|
|
143
|
-
{
|
|
144
|
-
const codemods = [upgrade];
|
|
145
|
-
// While the next upgrade is a codemod, add it to our `codemods` array.
|
|
146
|
-
while (allUpgrades[0] && allUpgrades[0].kind === 'codemod') {
|
|
147
|
-
codemods.push(allUpgrades.shift());
|
|
148
|
-
}
|
|
149
|
-
// Tell the user what we are about to do.
|
|
150
|
-
console.log(Styled.sectionHeader('Codemods'));
|
|
151
|
-
console.log();
|
|
152
|
-
console.log('We are now going to run the following codemods:');
|
|
153
|
-
console.log();
|
|
154
|
-
console.log(codemods.map(function (u, i) {
|
|
155
|
-
return Styled.upgradeTitle(u.title, i + 1);
|
|
156
|
-
}).join('\n'));
|
|
157
|
-
console.log();
|
|
158
|
-
console.log('Following is a short description of each codemod listed above so ' + 'that you know\nhow your code is being upgraded.');
|
|
159
|
-
console.log();
|
|
160
|
-
console.log(Styled.divider());
|
|
161
|
-
console.log();
|
|
162
|
-
codemods.forEach(function (u, i) {
|
|
163
|
-
console.log(Styled.upgradeTitle(u.title, i + 1));
|
|
164
|
-
console.log();
|
|
165
|
-
console.log(u.description);
|
|
166
|
-
console.log();
|
|
167
|
-
console.log(Styled.divider());
|
|
168
|
-
console.log();
|
|
169
|
-
});
|
|
170
|
-
console.log(`Running ${chalk.bold.cyan(codemods.length)} codemods...`);
|
|
171
|
-
console.log();
|
|
172
|
-
// Run all of our codemods.
|
|
173
|
-
const runCodemods = require('./codemods/runCodemods');
|
|
174
|
-
yield runCodemods(codemods.map(function ({ transformPath }) {
|
|
175
|
-
return transformPath;
|
|
176
|
-
}), filePaths);
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
// Throw an error for all other kinds of upgrades.
|
|
180
|
-
default:
|
|
181
|
-
throw new Error(`Unexpected upgrade kind: '${upgrade.kind}'`);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
function upgrade(_x, _x2, _x3, _x4) {
|
|
187
|
-
return _ref.apply(this, arguments);
|
|
188
167
|
}
|
|
189
|
-
|
|
190
|
-
return upgrade;
|
|
191
|
-
})();
|
|
168
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _removeDuplicateClassProperties = _interopRequireDefault(require("../../codemods/removeDuplicateClassProperties"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*
|
|
18
|
+
* @format
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
var _default = {
|
|
22
|
+
version: '0.170.0',
|
|
23
|
+
upgrades: [_removeDuplicateClassProperties.default]
|
|
24
|
+
};
|
|
25
|
+
exports.default = _default;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _removeAnnotationsInDestructuring = _interopRequireDefault(require("../../codemods/removeAnnotationsInDestructuring"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*
|
|
18
|
+
* @format
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
var _default = {
|
|
22
|
+
version: '0.176.0',
|
|
23
|
+
upgrades: [_removeAnnotationsInDestructuring.default]
|
|
24
|
+
};
|
|
25
|
+
exports.default = _default;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _convertImplicitInexactObjectTypes = _interopRequireDefault(require("../../codemods/convertImplicitInexactObjectTypes"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*
|
|
18
|
+
* @format
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
var _default = {
|
|
22
|
+
version: '0.84.0',
|
|
23
|
+
upgrades: [_convertImplicitInexactObjectTypes.default]
|
|
24
|
+
};
|
|
25
|
+
exports.default = _default;
|
|
@@ -0,0 +1,29 @@
|
|
|
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.170.0"));
|
|
9
|
+
|
|
10
|
+
var _2 = _interopRequireDefault(require("./0.176.0"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
16
|
+
*
|
|
17
|
+
* This source code is licensed under the MIT license found in the
|
|
18
|
+
* LICENSE file in the root directory of this source tree.
|
|
19
|
+
*
|
|
20
|
+
* @format
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Holds all of the upgrades that need to be run to upgrade to each version from
|
|
26
|
+
* the last version of Flow.
|
|
27
|
+
*/
|
|
28
|
+
const VERSION_UPGRADES = [_.default, _2.default];
|
|
29
|
+
exports.VERSION_UPGRADES = VERSION_UPGRADES;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, "__esModule", {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
exports.redirectConsole = redirectConsole;
|
|
16
|
+
exports.restoreConsole = restoreConsole;
|
|
17
|
+
|
|
18
|
+
var util = _interopRequireWildcard(require("util"));
|
|
19
|
+
|
|
20
|
+
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); }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
const oldConsole = {
|
|
25
|
+
error: console.error,
|
|
26
|
+
info: console.info,
|
|
27
|
+
log: console.log,
|
|
28
|
+
warn: console.warn
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function redirectConsole(reporter_) {
|
|
32
|
+
const reporter = typeof reporter_ === 'function' ? reporter_(oldConsole) : reporter_; // $FlowExpectedError[cannot-write]
|
|
33
|
+
|
|
34
|
+
console.log = (...args) => {
|
|
35
|
+
reporter.onStdout(util.format(...args));
|
|
36
|
+
}; // $FlowExpectedError[cannot-write]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
console.info = (...args) => {
|
|
40
|
+
reporter.onStdout(util.format(...args));
|
|
41
|
+
}; // $FlowExpectedError[cannot-write]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
console.warn = (...args) => {
|
|
45
|
+
reporter.onStdout('[WARN]' + util.format(...args));
|
|
46
|
+
}; // $FlowExpectedError[cannot-write]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
console.error = (...args) => {
|
|
50
|
+
reporter.onStderr(util.format(...args));
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function restoreConsole() {
|
|
55
|
+
for (const [name, fn] of Object.entries(oldConsole)) {
|
|
56
|
+
// $FlowExpectedError
|
|
57
|
+
console[name] = fn;
|
|
58
|
+
}
|
|
59
|
+
}
|
package/package.json
CHANGED
|
@@ -1,40 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flow-upgrade",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A utility for upgrading your codebase to the latest version of Flow.",
|
|
5
5
|
"engines": {
|
|
6
|
-
"node": ">=
|
|
6
|
+
"node": ">=14"
|
|
7
7
|
},
|
|
8
|
+
"license": "MIT",
|
|
8
9
|
"files": [
|
|
9
10
|
"dist"
|
|
10
11
|
],
|
|
11
|
-
"bin":
|
|
12
|
+
"bin": {
|
|
13
|
+
"flow-upgrade": "./dist/bin/upgrade.js",
|
|
14
|
+
"flow-codemod": "./dist/bin/runSpecificCodemod.js"
|
|
15
|
+
},
|
|
12
16
|
"scripts": {
|
|
13
|
-
"build": "rm -rf dist && babel src --out-dir dist --ignore __tests__",
|
|
17
|
+
"build": "rm -rf dist && babel src --out-dir dist --ignore '**/__tests__'",
|
|
14
18
|
"test": "jest --watch",
|
|
15
|
-
"prepublish": "
|
|
19
|
+
"prepublish": "yarn run build",
|
|
16
20
|
"postpublish": "node ./scripts/postpublish.js"
|
|
17
21
|
},
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/facebook/flow.git"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/facebook/flow/issues"
|
|
23
28
|
},
|
|
29
|
+
"homepage": "https://github.com/facebook/flow/tree/master/packages/flow-upgrade#readme",
|
|
24
30
|
"dependencies": {
|
|
31
|
+
"@babel/highlight": "^7.18.6",
|
|
25
32
|
"chalk": "^2.0.1",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
33
|
+
"fs-extra": "10.1.0",
|
|
34
|
+
"hermes-estree": "0.9.0",
|
|
35
|
+
"hermes-parser": "0.9.0",
|
|
36
|
+
"hermes-transform": "0.9.0",
|
|
37
|
+
"klaw-sync": "^6.0.0",
|
|
38
|
+
"ora": "^5.4.1",
|
|
29
39
|
"prompt-confirm": "^1.2.0",
|
|
30
|
-
"semver": "^
|
|
31
|
-
"yargs": "^
|
|
40
|
+
"semver": "^7.3.7",
|
|
41
|
+
"yargs": "^17.0.1"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"prettier": "^2.4.1"
|
|
32
45
|
},
|
|
33
46
|
"devDependencies": {
|
|
34
|
-
"babel
|
|
35
|
-
"babel
|
|
36
|
-
"babel
|
|
37
|
-
"flow
|
|
38
|
-
"
|
|
47
|
+
"@babel/cli": "^7.14.8",
|
|
48
|
+
"@babel/core": "^7.14.8",
|
|
49
|
+
"@babel/preset-env": "^7.14.8",
|
|
50
|
+
"@babel/preset-flow": "^7.14.5",
|
|
51
|
+
"flow-bin": "^0.178.0",
|
|
52
|
+
"jest": "^27.5.1",
|
|
53
|
+
"memfs": "^3.4.3",
|
|
54
|
+
"prettier": "^2.4.1"
|
|
39
55
|
}
|
|
40
56
|
}
|