Files
react/scripts/flow/createFlowConfigs.js
Sebastian Markbåge 99d7371863 [Flight] Split Streaming from Relay Implemenation (#18260)
* Add ReactFlightServerConfig intermediate

This just forwards to the stream version of Flight which is itself forked
between Node and W3C streams.

The dom-relay goes directly to the Relay config though which allows it to
avoid the stream part of Flight.

* Separate streaming protocol into the Stream config

* Split streaming parts into the ReactFlightServerConfigStream

This decouples it so that the Relay implementation doesn't have to encode
the JSON to strings. Instead it can be fed the values as JSON objects and
do its own encoding.

* Split FlightClient into a basic part and a stream part

Same split as the server.

* Expose lower level async hooks to Relay

This requires an external helper file that we'll wire up internally.
2020-03-10 14:55:04 -07:00

98 lines
2.8 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
'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, rendererInfo, isServerSupported) {
const folder = __dirname + '/' + renderer;
mkdirp.sync(folder);
const serverRenderer = isServerSupported ? renderer : 'custom';
let ignoredPaths = [];
inlinedHostConfigs.forEach(otherRenderer => {
if (otherRenderer === rendererInfo) {
return;
}
otherRenderer.paths.forEach(otherPath => {
if (rendererInfo.paths.indexOf(otherPath) !== -1) {
return;
}
ignoredPaths.push(`.*/packages/${otherPath}`);
});
if (otherRenderer.shortName !== serverRenderer) {
ignoredPaths.push(
`.*/packages/.*/forks/.*.${otherRenderer.shortName}.js`,
);
}
});
const config = configTemplate
.replace(
'%REACT_RENDERER_FLOW_OPTIONS%',
`
module.name_mapper='ReactFiberHostConfig$$' -> 'forks/ReactFiberHostConfig.${renderer}'
module.name_mapper='ReactServerStreamConfig$$' -> 'forks/ReactServerStreamConfig.${serverRenderer}'
module.name_mapper='ReactServerFormatConfig$$' -> 'forks/ReactServerFormatConfig.${serverRenderer}'
module.name_mapper='ReactFlightServerConfig$$' -> 'forks/ReactFlightServerConfig.${serverRenderer}'
module.name_mapper='ReactFlightClientHostConfig$$' -> 'forks/ReactFlightClientHostConfig.${serverRenderer}'
`.trim(),
)
.replace('%REACT_RENDERER_FLOW_IGNORES%', ignoredPaths.join('\n'));
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));
}
}
// Write multiple configs in different folders
// so that we can run those checks in parallel if we want.
inlinedHostConfigs.forEach(rendererInfo => {
if (rendererInfo.isFlowTyped) {
writeConfig(
rendererInfo.shortName,
rendererInfo,
rendererInfo.isServerSupported,
);
}
});