Skip to content

Fix 'flow-coverage-report' command. #13393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
},
"scripts": {
"build": "npm run version-check && node ./scripts/rollup/build.js",
"flow-coverage": "flow-coverage-report --config ./.flowcoverage",
"flow-coverage": "node ./scripts/tasks/flow-coverage.js",
"linc": "node ./scripts/tasks/linc.js",
"lint": "node ./scripts/tasks/eslint.js",
"lint-build": "node ./scripts/rollup/validate/index.js",
Expand Down
2 changes: 1 addition & 1 deletion .flowcoverage → scripts/flow/.flowcoverage
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"json",
"text"
]
}
}
14 changes: 6 additions & 8 deletions scripts/flow/config/flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
.*/__tests__/.*

[include]
../../../node_modules/
../../../packages/
../../../scripts/
# Substituted by flowConfig.js:
%FLOW_INCLUDE%

[libs]
../../../node_modules/fbjs/flow/lib/dev.js
../environment.js
../react-native-host-hooks.js
# Substituted by flowConfig.js:
%FLOW_LIBS%

[lints]
untyped-type-import=error
Expand All @@ -29,7 +27,7 @@ untyped-type-import=error
esproposal.class_static_fields=enable
esproposal.class_instance_fields=enable

# Substituted by createFlowConfig.js:
# Substituted by flowConfig.js:
%REACT_RENDERER_FLOW_OPTIONS%

munge_underscores=false
Expand All @@ -45,4 +43,4 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

[version]
^0.72.0
^0.72.0
47 changes: 1 addition & 46 deletions scripts/flow/createFlowConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,8 @@

'use strict';

const chalk = require('chalk');
const fs = require('fs');
const mkdirp = require('mkdirp');
const inlinedHostConfigs = require('../shared/inlinedHostConfigs');

const configTemplate = fs
.readFileSync(__dirname + '/config/flowconfig')
.toString();

function writeConfig(renderer) {
const folder = __dirname + '/' + renderer;
mkdirp.sync(folder);

const config = configTemplate.replace(
'%REACT_RENDERER_FLOW_OPTIONS%',
`
module.name_mapper='react-reconciler/inline.${renderer}$$' -> 'react-reconciler/inline-typed'
module.name_mapper='ReactFiberHostConfig$$' -> 'forks/ReactFiberHostConfig.${renderer}'
`.trim(),
);

const disclaimer = `
# ---------------------------------------------------------------#
# NOTE: this file is generated. #
# If you want to edit it, open ./scripts/flow/config/flowconfig. #
# Then run Yarn for changes to take effect. #
# ---------------------------------------------------------------#
`.trim();

const configFile = folder + '/.flowconfig';
let oldConfig;
try {
oldConfig = fs.readFileSync(configFile).toString();
} catch (err) {
oldConfig = null;
}
const newConfig = `
${disclaimer}
${config}
${disclaimer}
`.trim();

if (newConfig !== oldConfig) {
fs.writeFileSync(configFile, newConfig);
console.log(chalk.dim('Wrote a Flow config to ' + configFile));
}
}
const writeConfig = require('./flowConfig').writeConfig;

// Write multiple configs in different folders
// so that we can run those checks in parallel if we want.
Expand Down
48 changes: 48 additions & 0 deletions scripts/flow/createFlowCoverageReport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const chalk = require('chalk');
const path = require('path');
const spawn = require('child_process').spawn;
const rimraf = require('rimraf');
const writeConfig = require('./flowConfig').writeConfig;

function deleteFlowConfig() {
const file = path.join(__dirname, '../../.flowconfig');
rimraf.sync(file);
}

async function createFlowCoverage(renderer) {
return new Promise(resolve => {
console.log(
`Creating Flow coverage report for the ${chalk.yellow(
renderer,
)} renderer...`,
);
let cmd = path.join(
__dirname,
'../../node_modules/.bin/flow-coverage-report',
);
if (process.platform === 'win32') {
cmd = cmd + '.cmd';
}

writeConfig(renderer, true);

spawn(cmd, ['--config', 'scripts/flow/.flowcoverage'], {
// Allow colors to pass through:
stdio: 'inherit',
}).on('close', function() {
deleteFlowConfig();
resolve();
});
});
}

module.exports = createFlowCoverage;
103 changes: 103 additions & 0 deletions scripts/flow/flowConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

'use strict';

const chalk = require('chalk');
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');

const configTemplate = fs
.readFileSync(__dirname + '/config/flowconfig')
.toString();

function writeConfig(renderer, rootFolder = false) {
let folder;
if (rootFolder) {
folder = path.join(__dirname, '../../');
} else {
folder = path.join(__dirname, renderer);
}

mkdirp.sync(folder);

let config = configTemplate.replace(
'%REACT_RENDERER_FLOW_OPTIONS%',
`
module.name_mapper='react-reconciler/inline.${renderer}$$' -> 'react-reconciler/inline-typed'
module.name_mapper='ReactFiberHostConfig$$' -> 'forks/ReactFiberHostConfig.${renderer}'
`.trim(),
);

if (rootFolder) {
config = config.replace(
'%FLOW_INCLUDE%',
`
./node_modules/
./packages/
./scripts/
`.trim(),
);

config = config.replace(
'%FLOW_LIBS%',
`
./node_modules/fbjs/flow/lib/dev.js
./scripts/flow/environment.js
./scripts/flow/react-native-host-hooks.js
`.trim(),
);
} else {
config = config.replace(
'%FLOW_INCLUDE%',
`
../../../node_modules/
../../../packages/
../../../scripts/
`.trim(),
);

config = config.replace(
'%FLOW_LIBS%',
`
../../../node_modules/fbjs/flow/lib/dev.js
../environment.js
../react-native-host-hooks.js
`.trim(),
);
}

const disclaimer = `
# ---------------------------------------------------------------#
# NOTE: this file is generated. #
# If you want to edit it, open ./scripts/flow/config/flowconfig. #
# Then run Yarn for changes to take effect. #
# ---------------------------------------------------------------#
`.trim();

const configFile = path.join(folder, '.flowconfig');
let oldConfig;
try {
oldConfig = fs.readFileSync(configFile).toString();
} catch (err) {
oldConfig = null;
}
const newConfig = `
${disclaimer}
${config}
${disclaimer}
`.trim();

if (newConfig !== oldConfig) {
fs.writeFileSync(configFile, newConfig);
console.log(chalk.dim('Wrote a Flow config to ' + configFile));
}
}

exports.writeConfig = writeConfig;
43 changes: 43 additions & 0 deletions scripts/tasks/flow-coverage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

process.on('unhandledRejection', err => {
throw err;
});

const chalk = require('chalk');
const createFlowCoverageReport = require('../flow/createFlowCoverageReport');
const inlinedHostConfigs = require('../shared/inlinedHostConfigs');

const primaryRenderer = inlinedHostConfigs.find(
info => info.isFlowTyped && info.shortName === process.argv[2]
);
if (!primaryRenderer) {
console.log(
'The ' +
chalk.red('yarn flow-coverage') +
' command requires you to pick a primary renderer:'
);
console.log();
inlinedHostConfigs.forEach(rendererInfo => {
if (rendererInfo.isFlowTyped) {
console.log(
' * ' + chalk.cyan('yarn flow-coverage ' + rendererInfo.shortName)
);
}
});
console.log();
console.log(
'If you are not sure, run ' + chalk.green('yarn flow-coverage dom') + '.'
);
console.log();
process.exit(1);
}

createFlowCoverageReport(primaryRenderer.shortName);