mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
The bindings upstream in Relay has been removed so we don't need these builds anymore. The idea is to revisit an FB integration of Flight but it wouldn't use the Relay specific bindings. It's a bit unclear how it would look but likely more like the OSS version so not worth keeping these around. The `dom-relay` name also included the FB specific Fizz implementation of the streaming config so I renamed that to `dom-fb`. There's no Fizz implementation for Native yet so I just removed `native-relay`. We created a configurable fork for how to encode the output of Flight and the Relay implementation encoded it as JSON objects instead of strings/streams. The new implementation would likely be more stream-like and just encode it directly as string/binary chunks. So I removed those indirections so that this can just be declared inline in ReactFlightServer/Client.
116 lines
3.4 KiB
JavaScript
116 lines
3.4 KiB
JavaScript
/**
|
|
* 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.
|
|
*/
|
|
|
|
'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,
|
|
isFlightSupported,
|
|
) {
|
|
const folder = __dirname + '/' + renderer;
|
|
mkdirp.sync(folder);
|
|
|
|
isFlightSupported =
|
|
isFlightSupported === true ||
|
|
(isServerSupported && isFlightSupported !== false);
|
|
|
|
const serverRenderer = isServerSupported ? renderer : 'custom';
|
|
const flightRenderer = isFlightSupported ? renderer : 'custom';
|
|
|
|
const 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 &&
|
|
otherRenderer.shortName !== flightRenderer
|
|
) {
|
|
ignoredPaths.push(
|
|
`.*/packages/.*/forks/.*\\.${otherRenderer.shortName}.js`,
|
|
);
|
|
}
|
|
});
|
|
|
|
const config = configTemplate
|
|
.replace(
|
|
'%CI_MAX_WORKERS%\n',
|
|
// On CI, we seem to need to limit workers.
|
|
process.env.CI ? 'server.max_workers=4\n' : '',
|
|
)
|
|
.replace(
|
|
'%REACT_RENDERER_FLOW_OPTIONS%',
|
|
`
|
|
module.name_mapper='ReactFiberConfig$$' -> 'forks/ReactFiberConfig.${renderer}'
|
|
module.name_mapper='ReactServerStreamConfig$$' -> 'forks/ReactServerStreamConfig.${serverRenderer}'
|
|
module.name_mapper='ReactFizzConfig$$' -> 'forks/ReactFizzConfig.${serverRenderer}'
|
|
module.name_mapper='ReactFlightServerConfig$$' -> 'forks/ReactFlightServerConfig.${flightRenderer}'
|
|
module.name_mapper='ReactFlightClientConfig$$' -> 'forks/ReactFlightClientConfig.${flightRenderer}'
|
|
module.name_mapper='react-devtools-feature-flags' -> 'react-devtools-shared/src/config/DevToolsFeatureFlags.default'
|
|
`.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,
|
|
rendererInfo.isFlightSupported,
|
|
);
|
|
}
|
|
});
|