flow-upgrade
Advanced tools
Comparing version 2.2.0 to 2.3.0
#!/usr/bin/env node | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
"use strict"; | ||
@@ -82,7 +72,6 @@ | ||
try { | ||
const filePaths = await (0, _findFlowFiles.findFlowFilesWithSpinner)(directory, options); // $FlowExpectedError[unsupported-syntax] | ||
const filePaths = await (0, _findFlowFiles.findFlowFilesWithSpinner)(directory, options); | ||
const { | ||
default: upgrade | ||
} = await Promise.resolve(`${CODEMOD_DIR}/${codemodName}.js`).then(s => _interopRequireWildcard(require(s))); // Tell the user what we are about to do. | ||
} = await Promise.resolve(`${CODEMOD_DIR}/${codemodName}.js`).then(s => _interopRequireWildcard(require(s))); | ||
@@ -96,3 +85,3 @@ if (!options.silent) { | ||
console.log(); | ||
console.log(upgrade.description); | ||
console.log(upgrade.describe); | ||
console.log(); | ||
@@ -109,3 +98,2 @@ console.log(_Styled.default.divider()); | ||
break; | ||
// Throw an error for all other kinds of upgrades. | ||
@@ -112,0 +100,0 @@ default: |
#!/usr/bin/env node | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
"use strict"; | ||
@@ -60,7 +50,3 @@ | ||
yes: !!yargs.yes | ||
}; // For now we are asking for the version numbers out of convenience. When we add | ||
// upgrades for future versions we will need to check `.flowconfig` or | ||
// `flow-bin` for the current version and allow the new version to be | ||
// configurable. (But still default to the latest version.) | ||
}; | ||
const fromVersion = yargs._[0]; | ||
@@ -67,0 +53,0 @@ const toVersion = yargs._[1]; |
@@ -12,14 +12,5 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
var _default = (0, _Types.codemod)({ | ||
title: 'Collapse Object Initialization', | ||
description: 'Converts static object assignments to inline properties', | ||
describe: 'Converts static object assignments to inline properties', | ||
transform: context => { | ||
@@ -42,3 +33,2 @@ function getStatementContainerArray(stmtNode) { | ||
{ | ||
// $FlowIgnore[incompatible-return] | ||
return parent.body; | ||
@@ -114,3 +104,3 @@ } | ||
if (memberObjectNode.type === 'Identifier' && memberObjectNode.name === idNode.name && memberPropertyNode.type === 'Identifier') { | ||
const shorthand = !leftNode.computed && exprRightNode.type === 'Identifier' && exprRightNode.name === memberPropertyNode.name; // $FlowIgnore[incompatible-type-arg] You gonna have to trust me | ||
const shorthand = !leftNode.computed && exprRightNode.type === 'Identifier' && exprRightNode.name === memberPropertyNode.name; | ||
@@ -123,3 +113,2 @@ const property = _hermesTransform.t.Property({ | ||
method: false, | ||
// $FlowIgnore[incompatible-call] | ||
shorthand | ||
@@ -218,4 +207,3 @@ }); | ||
if (assignmentRefsCount !== objectProperties.length) { | ||
console.error(context.buildCodeFrame(stmtNode, 'Object had non inlinable and inlineable properties')); // If you don't wish to codemod these mixed objects return here. | ||
// return; | ||
console.error(context.buildCodeFrame(stmtNode, 'Object had non inlinable and inlineable properties')); | ||
} | ||
@@ -222,0 +210,0 @@ |
@@ -10,18 +10,8 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
var _default = (0, _Types.codemod)({ | ||
title: 'Make implicitly inexact object types explicitly inexact', | ||
description: 'Convert implicitly inexact object type syntax `{}` to explicitly inexact `{...}`', | ||
describe: 'Convert implicitly inexact object type syntax `{}` to explicitly inexact `{...}`', | ||
transform: context => { | ||
return { | ||
':not(InterfaceDeclaration, InterfaceTypeAnnotation, DeclareInterface, DeclareClass) > ObjectTypeAnnotation[inexact=false][exact=false]'(node) { | ||
// $FlowFixMe[incompatible-call] `inexact` can be true, as is the case with `{...}` | ||
context.modifyNodeInPlace(node, { | ||
@@ -28,0 +18,0 @@ inexact: true |
@@ -10,14 +10,5 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
var _default = (0, _Types.codemod)({ | ||
title: 'Convert `$Shape` to `Partial`', | ||
description: 'Converts usage of the `$Shape` utility type to `Partial`. It is possible that this will create type errors that you will have to resolve.', | ||
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.', | ||
transform: context => { | ||
@@ -24,0 +15,0 @@ return { |
@@ -10,14 +10,5 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
var _default = (0, _Types.codemod)({ | ||
title: 'Remove Annotations In Destructuring', | ||
description: 'Remove annotations nested inside of destructuring. These are not valid Flow syntax.', | ||
describe: 'Remove annotations nested inside of destructuring. These are not valid Flow syntax.', | ||
transform: context => { | ||
@@ -24,0 +15,0 @@ return { |
@@ -14,11 +14,2 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
function getKind(member) { | ||
@@ -67,5 +58,4 @@ switch (member.type) { | ||
continue; | ||
} // handle the valid cases | ||
} | ||
switch (lastMember.kind) { | ||
@@ -110,5 +100,4 @@ case 'GetterSetter': | ||
break; | ||
} // overwrite and delete the old member as it's incompatible | ||
} | ||
if (lastMember.kind === 'GetterSetter') { | ||
@@ -133,7 +122,6 @@ toDelete.push(lastMember.getter); | ||
title: 'Remove Duplicate Class Properties', | ||
description: 'Removes useless duplicate class properties and fixes bad constructor binding in those classes', | ||
describe: 'Removes useless duplicate class properties and fixes bad constructor binding in those classes', | ||
transform: context => { | ||
let classStack = null; | ||
return { | ||
// find and delete duplicated members | ||
'ClassDeclaration, ClassExpression'(node) { | ||
@@ -148,3 +136,2 @@ const staticMembers = new Map(); | ||
if (name == null) { | ||
// unsupported computed member | ||
continue; | ||
@@ -166,5 +153,4 @@ } | ||
return; | ||
} // mark members for deletion | ||
} | ||
for (const memberToDelete of toDelete) { | ||
@@ -178,6 +164,4 @@ var _memberToDelete$value; | ||
context.removeNode(memberToDelete); | ||
} // we need the final list of instance members so we can | ||
// fix up rebinding later | ||
} | ||
const newInstanceMembers = new Map(); | ||
@@ -205,5 +189,4 @@ | ||
}); | ||
} // push the stack | ||
} | ||
classStack = { | ||
@@ -216,3 +199,2 @@ current: node, | ||
// remove unnecessary .bind in constructor | ||
'MethodDefinition[kind = "constructor"] ExpressionStatement > AssignmentExpression[operator = "="] > MemberExpression[object.type = "ThisExpression"].left'(node) { | ||
@@ -230,3 +212,3 @@ if (!classStack) { | ||
const subjectName = node.property.name; | ||
const member = instanceMembers.get(subjectName); // the subject member must be a method | ||
const member = instanceMembers.get(subjectName); | ||
@@ -244,3 +226,3 @@ if ((member === null || member === void 0 ? void 0 : member.kind) !== 'Method') { | ||
const right = assignmentExpr.right; // we're looking for `this.thing = this.thing.bind(this)` | ||
const right = assignmentExpr.right; | ||
@@ -250,5 +232,4 @@ if (right.type !== 'CallExpression' || right.arguments.length !== 1 || right.arguments[0].type !== 'ThisExpression' || right.callee.type !== 'MemberExpression' || right.callee.computed || right.callee.property.type !== 'Identifier' || right.callee.property.name !== 'bind' || right.callee.object.type !== 'MemberExpression' || right.callee.object.computed || right.callee.object.object.type !== 'ThisExpression' || right.callee.object.property.type !== 'Identifier' || right.callee.object.property.name !== subjectName) { | ||
return; | ||
} // remove the bind assignment and... | ||
} | ||
context.removeStatement(exprStatement); | ||
@@ -259,9 +240,7 @@ const method = member.member; | ||
throw new Error('this cannot happen'); | ||
} // convert the method to an arrow function | ||
} | ||
(0, _replaceMethodWithArrowProp.replaceMethodWithArrowProp)(context, method, subjectName); | ||
}, | ||
// pop the stack | ||
'ClassDeclaration, ClassExpression:exit'(node) { | ||
@@ -268,0 +247,0 @@ var _classStack; |
@@ -10,14 +10,5 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
var _default = (0, _Types.codemod)({ | ||
title: 'Remove explicitly exact object type syntax', | ||
description: 'Convert explicitly exact object type syntax `{| |}` to be just be `{ }`. To be done after you turn on `exact_by_default=true` in your `.flowconfig`.', | ||
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`.', | ||
transform: context => { | ||
@@ -24,0 +15,0 @@ return { |
@@ -10,14 +10,5 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
var _default = (0, _Types.codemod)({ | ||
title: 'Rename `$Partial` to `Partial`', | ||
description: 'Renames the `$Partial` type utility to `Partial`.', | ||
describe: 'Renames the `$Partial` type utility to `Partial`.', | ||
transform: context => { | ||
@@ -24,0 +15,0 @@ return { |
@@ -12,14 +12,5 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
var _default = (0, _Types.codemod)({ | ||
title: 'Replace `T: {}` with `T: {...}` in type parameter bounds', | ||
description: 'Replace `T: {}` with `T: {...}` in type parameter bounds', | ||
describe: 'Replace `T: {}` with `T: {...}` in type parameter bounds', | ||
transform: context => { | ||
@@ -36,6 +27,2 @@ return { | ||
exact: false, | ||
/* $FlowExpectedError[incompatible-call] | ||
* TODO: hermes-transform mandates that inexact must be | ||
* `false`, which is wrong. */ | ||
inexact: true, | ||
@@ -42,0 +29,0 @@ indexers: [], |
@@ -8,11 +8,2 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
function getClassMemberName(member) { | ||
@@ -19,0 +10,0 @@ if (member.key.type === 'PrivateIdentifier') { |
@@ -10,20 +10,2 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
/** | ||
* Converts method definition to an arrow function property | ||
* ``` | ||
* method<T>(arg) { ... } | ||
* // to | ||
* +method = <T>(arg) => { ... }; | ||
* ``` | ||
*/ | ||
function replaceMethodWithArrowProp(context, method, name) { | ||
@@ -35,11 +17,2 @@ context.replaceNode(method, _hermesTransform.t.PropertyDefinition({ | ||
name, | ||
// for types-first compliance, this should ideally be filled out for | ||
// non-private members. However it's *super* complicated to correctly | ||
// handle these cases statically (type parameters and default args make | ||
// it hard). | ||
// So instead we just ignore it and they can be filled later using a | ||
// type-aware codemod like | ||
// ``` | ||
// flow codemod annotate-exports --write --munge-underscore-members --max-type-size 25 | ||
// ``` | ||
typeAnnotation: null | ||
@@ -57,3 +30,2 @@ }), | ||
}), | ||
// methods are readonly, so we mark the property as readonly as well | ||
variance: _hermesTransform.t.Variance({ | ||
@@ -60,0 +32,0 @@ kind: 'plus' |
@@ -19,20 +19,3 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
/** | ||
* How many bytes we should look at for the Flow pragma. | ||
*/ | ||
const PRAGMA_BYTES = 5000; | ||
/** | ||
* Finds all of the Flow files in the provided directory as efficiently as | ||
* possible. | ||
*/ | ||
@@ -43,40 +26,21 @@ async function findFlowFiles({ | ||
}) { | ||
// All the valid file paths that we have found. | ||
const filePaths = []; // Begin the recursion! | ||
const filePaths = []; | ||
await processDirectory(rootDirectory); | ||
return filePaths; | ||
/** | ||
* Process a directory by looking at all of its entries and recursing | ||
* through child directories as is appropriate. | ||
*/ | ||
async function processDirectory(directory) { | ||
// Read the directory... | ||
const fileNames = await _fsExtra.default.readdir(directory); // Process every file name that we got from reading the directory. | ||
const fileNames = await _fsExtra.default.readdir(directory); | ||
await Promise.all(fileNames.map(fileName => processFilePath(directory, fileName))); | ||
} | ||
/** | ||
* Process a directory file path by seeing if it is a directory and either | ||
* recursing or adding it to filePaths. | ||
*/ | ||
async function processFilePath(directory, fileName) { | ||
// Get the file file path for this file. | ||
const filePath = _path.default.join(directory, fileName); // Get the stats for the file. | ||
const filePath = _path.default.join(directory, fileName); | ||
const stats = await _fsExtra.default.lstat(filePath); | ||
const stats = await _fsExtra.default.lstat(filePath); // If this is a directory... | ||
if (stats.isDirectory()) { | ||
// ...and it is not an ignored directory... | ||
if (fileName !== 'node_modules' && fileName !== 'flow-typed' && fileName !== '__flowtests__') { | ||
// ...then recursively process the directory. | ||
await processDirectory(filePath); | ||
} | ||
} else if (stats.isFile()) { | ||
// Otherwise if this is a JavaScript/JSX file and it is not an ignored | ||
// JavaScript file... | ||
const fileIsJsOrJsx = /\.jsx?$/.test(fileName); | ||
@@ -86,8 +50,5 @@ const fileIsIgnored = fileName.endsWith('-flowtest.js'); | ||
if (fileIsJsOrJsx && !fileIsIgnored) { | ||
// Then process the file path as JavaScript. | ||
await processJavaScriptFilePath(filePath, stats.size); | ||
} // If this is a Flow file then we don't need to check the file pragma | ||
// and can add the file to our paths immediately. | ||
} | ||
if (fileName.endsWith('.flow')) { | ||
@@ -98,31 +59,18 @@ filePaths.push(filePath); | ||
} | ||
/** | ||
* Check if a file path really is a Flow file by looking for the | ||
* header pragma. | ||
*/ | ||
async function processJavaScriptFilePath(filePath, fileByteSize) { | ||
// If `all` was configured then we don't need to check for the Flow | ||
// header pragma. | ||
if (includeNonAtFlow) { | ||
filePaths.push(filePath); | ||
return; | ||
} // Open the file path. | ||
} | ||
const file = await _fsExtra.default.open(filePath, 'r'); | ||
const bytes = Math.min(PRAGMA_BYTES, fileByteSize); | ||
const buffer = Buffer.alloc(bytes); | ||
await _fsExtra.default.read(file, buffer, 0, bytes, 0); | ||
const file = await _fsExtra.default.open(filePath, 'r'); // Get the smaller of our pragma chars constant and the file byte size. | ||
const bytes = Math.min(PRAGMA_BYTES, fileByteSize); // Create the buffer we will read to. | ||
const buffer = Buffer.alloc(bytes); // Read a set number of bytes from the file. | ||
await _fsExtra.default.read(file, buffer, 0, bytes, 0); // If the buffer has the pragma then add the file path to our | ||
// final file paths array. | ||
if (buffer.includes('@flow')) { | ||
filePaths.push(filePath); | ||
} // Close the file. | ||
} | ||
await _fsExtra.default.close(file); | ||
@@ -133,3 +81,2 @@ } | ||
async function findFlowFilesWithSpinner(rootDirectory, options) { | ||
// Create a new spinner. | ||
const spinner = (0, _ora.default)({ | ||
@@ -139,6 +86,4 @@ text: _chalk.default.italic.cyan('Finding all the Flow files to be upgraded...'), | ||
isSilent: options.silent | ||
}); // Start the spinner. | ||
spinner.start(); // Find all of the Flow files in the directory we are upgrading. | ||
}); | ||
spinner.start(); | ||
const filePaths = await (() => { | ||
@@ -151,10 +96,8 @@ try { | ||
} catch (error) { | ||
// Stop the spinner if we get an error. | ||
spinner.stop(); | ||
throw error; | ||
} | ||
})(); // Stop the spinner. | ||
})(); | ||
spinner.stop(); | ||
spinner.stop(); // Log the number of Flow files that we found. | ||
if (!options.silent) { | ||
@@ -161,0 +104,0 @@ console.log(`Found ${_chalk.default.bold.cyan(filePaths.length)} Flow files.`); |
@@ -14,11 +14,2 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
async function runCodemods(codemods, filePaths, options) { | ||
@@ -30,3 +21,3 @@ const results = await Promise.allSettled(filePaths.map(async filePath => { | ||
for (const codemod of codemods) { | ||
contents = (0, _hermesTransform.transform)(contents, codemod.transform, options.prettierOptions); | ||
contents = await (0, _hermesTransform.transform)(contents, codemod.transform, options.prettierOptions); | ||
} | ||
@@ -33,0 +24,0 @@ |
"use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
const chalk = require('chalk'); | ||
@@ -27,14 +18,7 @@ | ||
exports.codeblock = function codeblock(code) { | ||
return code // Add indentation to the beginning of every line of code. | ||
.split('\n').map(line => ` ${line}`).join('\n') // Add highlighting for puncuation. We need to do this first otherwise it | ||
// breaks the other colors. | ||
.replace(/([={}()\[\];<>,:.*/])/g, chalk.grey('$1')) // Add highlighting for reserved keywords. | ||
.replace(/(import|from|typeof|type|class|extends|static|return|function)/g, chalk.magenta('$1')) // Add highlighting for strings. | ||
.replace(/('[^\n]*')/g, chalk.green('$1')); | ||
return code.split('\n').map(line => ` ${line}`).join('\n').replace(/([={}()\[\];<>,:.*/])/g, chalk.grey('$1')).replace(/(import|from|typeof|type|class|extends|static|return|function)/g, chalk.magenta('$1')).replace(/('[^\n]*')/g, chalk.green('$1')); | ||
}; | ||
exports.list = function list(items) { | ||
return items.map(item => // Indent every item and add a `- ` to the beginning of each line. | ||
item.split('\n').map((line, i) => `${i === 0 ? chalk.grey('- ') : ' '}${line}`).join('\n')) // Combine all of our items into one list string. | ||
.join('\n'); | ||
return items.map(item => item.split('\n').map((line, i) => `${i === 0 ? chalk.grey('- ') : ' '}${line}`).join('\n')).join('\n'); | ||
}; |
@@ -8,11 +8,2 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
function codemod(config) { | ||
@@ -19,0 +10,0 @@ return { ...config, |
@@ -26,19 +26,5 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
/** | ||
* Decides all of the upgrades that will need to be run when moving from one | ||
* version to another and runs them asynchronously. | ||
*/ | ||
async function upgrade(directory, currentVersion, nextVersion, options) { | ||
const log = options.silent ? () => {} : (...messages) => console.log(...messages); | ||
const allUpgrades = []; // Collect all of the upgrades we will need to run. | ||
const allUpgrades = []; | ||
@@ -49,11 +35,8 @@ for (let i = 0; i < _upgrades.VERSION_UPGRADES.length; i++) { | ||
upgrades | ||
} = _upgrades.VERSION_UPGRADES[i]; // If the version number is larger then the version we are upgrading to we | ||
// are done! Do not add any more upgrades, | ||
} = _upgrades.VERSION_UPGRADES[i]; | ||
if (_semver.default.cmp(version, '>', nextVersion)) { | ||
break; | ||
} // If the version number is larget then the current version, but not larger | ||
// then the next version then we want to run the upgrades for this version. | ||
} | ||
if (_semver.default.cmp(version, '>', currentVersion)) { | ||
@@ -68,5 +51,4 @@ upgrades.forEach(upgrade => allUpgrades.push(upgrade)); | ||
{ | ||
const titleStyled = _chalk.default.bold('flow-upgrade'); // Log the initial intro message for our user. | ||
const titleStyled = _chalk.default.bold('flow-upgrade'); | ||
const message = ` | ||
@@ -106,37 +88,26 @@ Thank you for choosing to upgrade Flow. In every release the Flow community adds | ||
log(message); | ||
} // Find all of the Flow files in the directory we are upgrading. | ||
const filePaths = await (0, _findFlowFiles.findFlowFilesWithSpinner)(directory, options); // Make sure the user knows that they should review their information before | ||
// proceeding. | ||
} | ||
const filePaths = await (0, _findFlowFiles.findFlowFilesWithSpinner)(directory, options); | ||
log(_chalk.default.bold.red('Please review this information to make sure that it is correct before proceeding.')); | ||
log(); // Ask the user for confirmation. | ||
log(); | ||
const answer = options.yes || (await new _promptConfirm.default('Are you ready to begin the upgrade?').run()); | ||
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 | ||
// continue. | ||
if (!answer) { | ||
log(); | ||
return; | ||
} // Run through all of our upgrades. | ||
} | ||
while (allUpgrades.length) { | ||
// Put some space between us and the last upgrade. | ||
log(); // Get the next upgrade. | ||
log(); | ||
const upgrade = allUpgrades.shift(); | ||
switch (upgrade.kind) { | ||
// If this is a codemod, collect all codemods after it as well and execute | ||
// those codemods together. | ||
case 'codemod': | ||
{ | ||
const codemods = [upgrade]; // While the next upgrade is a codemod, add it to our `codemods` array. | ||
const codemods = [upgrade]; | ||
while (allUpgrades[0] && allUpgrades[0].kind === 'codemod') { | ||
codemods.push(allUpgrades.shift()); | ||
} // Tell the user what we are about to do. | ||
} | ||
log(_Styled.default.sectionHeader('Codemods')); | ||
@@ -155,3 +126,3 @@ log(); | ||
log(); | ||
log(u.description); | ||
log(u.describe); | ||
log(); | ||
@@ -162,8 +133,6 @@ log(_Styled.default.divider()); | ||
log(`Running ${_chalk.default.bold.cyan(codemods.length)} codemods...`); | ||
log(); // Run all of our codemods. | ||
log(); | ||
await (0, _runCodemods.default)(codemods, filePaths, options); | ||
break; | ||
} | ||
// Throw an error for all other kinds of upgrades. | ||
@@ -170,0 +139,0 @@ default: |
@@ -12,11 +12,2 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
var _default = { | ||
@@ -23,0 +14,0 @@ version: '0.170.0', |
@@ -12,11 +12,2 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
var _default = { | ||
@@ -23,0 +14,0 @@ version: '0.176.0', |
@@ -12,11 +12,2 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
var _default = { | ||
@@ -23,0 +14,0 @@ version: '0.201.0', |
@@ -12,11 +12,2 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
var _default = { | ||
@@ -23,0 +14,0 @@ version: '0.84.0', |
@@ -18,17 +18,3 @@ "use strict"; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
/** | ||
* Holds all of the upgrades that need to be run to upgrade to each version from | ||
* the last version of Flow. | ||
*/ | ||
const VERSION_UPGRADES = [_.default, _2.default, _3.default, _4.default]; | ||
exports.VERSION_UPGRADES = VERSION_UPGRADES; |
@@ -1,10 +0,1 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* | ||
*/ | ||
'use strict'; | ||
@@ -32,19 +23,16 @@ | ||
function redirectConsole(reporter_) { | ||
const reporter = typeof reporter_ === 'function' ? reporter_(oldConsole) : reporter_; // $FlowExpectedError[cannot-write] | ||
const reporter = typeof reporter_ === 'function' ? reporter_(oldConsole) : reporter_; | ||
console.log = (...args) => { | ||
reporter.onStdout(util.format(...args)); | ||
}; // $FlowExpectedError[cannot-write] | ||
}; | ||
console.info = (...args) => { | ||
reporter.onStdout(util.format(...args)); | ||
}; // $FlowExpectedError[cannot-write] | ||
}; | ||
console.warn = (...args) => { | ||
reporter.onStdout('[WARN]' + util.format(...args)); | ||
}; // $FlowExpectedError[cannot-write] | ||
}; | ||
console.error = (...args) => { | ||
@@ -57,5 +45,4 @@ reporter.onStderr(util.format(...args)); | ||
for (const [name, fn] of Object.entries(oldConsole)) { | ||
// $FlowExpectedError | ||
console[name] = fn; | ||
} | ||
} |
{ | ||
"name": "flow-upgrade", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "A utility for upgrading your codebase to the latest version of Flow.", | ||
@@ -18,3 +18,4 @@ "engines": { | ||
"build": "rm -rf dist && babel src --out-dir dist --ignore '**/__tests__'", | ||
"test": "jest --watch", | ||
"test": "jest", | ||
"flow": "flow", | ||
"prepublish": "yarn run build", | ||
@@ -33,9 +34,11 @@ "postpublish": "node ./scripts/postpublish.js" | ||
"@babel/highlight": "^7.18.6", | ||
"babel-plugin-syntax-hermes-parser": "0.19.0", | ||
"chalk": "^2.0.1", | ||
"fs-extra": "10.1.0", | ||
"hermes-estree": "0.10.0", | ||
"hermes-parser": "0.10.0", | ||
"hermes-transform": "0.10.0", | ||
"hermes-estree": "0.19.0", | ||
"hermes-parser": "0.19.0", | ||
"hermes-transform": "0.19.0", | ||
"klaw-sync": "^6.0.0", | ||
"ora": "^5.4.1", | ||
"prettier-plugin-hermes-parser": "0.19.0", | ||
"prompt-confirm": "^1.2.0", | ||
@@ -46,3 +49,3 @@ "semver": "^7.3.7", | ||
"peerDependencies": { | ||
"prettier": "2.7.1" | ||
"prettier": "2.8.8" | ||
}, | ||
@@ -54,7 +57,7 @@ "devDependencies": { | ||
"@babel/preset-flow": "^7.14.5", | ||
"flow-bin": "^0.178.0", | ||
"flow-bin": "^0.227.0", | ||
"jest": "^27.5.1", | ||
"memfs": "^3.4.3", | ||
"prettier": "2.7.1" | ||
"prettier": "2.8.8" | ||
} | ||
} |
@@ -91,1 +91,6 @@ # `flow-upgrade` | ||
Run with `yarn run flow-codemod convertShapeToPartial`. | ||
### Migrate type casts `(x: T)` to `as` expressions `x as T` | ||
Converts usages of the old casting syntax `(x: T)` to the new casting syntax `x as T`. | ||
Run with `yarn run flow-codemod typeCastToAsExpression`. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26
96
44430
14
1037
+ Addedbabel-plugin-syntax-hermes-parser@0.19.0(transitive)
+ Addedhermes-eslint@0.19.0(transitive)
+ Addedhermes-estree@0.19.0(transitive)
+ Addedhermes-parser@0.19.0(transitive)
+ Addedhermes-transform@0.19.0(transitive)
+ Addedprettier@2.8.8(transitive)
+ Addedprettier-plugin-hermes-parser@0.19.0(transitive)
- Removedhermes-eslint@0.10.0(transitive)
- Removedhermes-estree@0.10.0(transitive)
- Removedhermes-parser@0.10.0(transitive)
- Removedhermes-transform@0.10.0(transitive)
- Removedprettier@2.7.1(transitive)
Updatedhermes-estree@0.19.0
Updatedhermes-parser@0.19.0
Updatedhermes-transform@0.19.0