Resolve host configs at build time (#12792)

* Extract base Jest config

This makes it easier to change the source config without affecting the build test config.

* Statically import the host config

This changes react-reconciler to import HostConfig instead of getting it through a function argument.

Rather than start with packages like ReactDOM that want to inline it, I started with React Noop and ensured that *custom* renderers using react-reconciler package still work. To do this, I'm making HostConfig module in the reconciler look at a global variable by default (which, in case of the react-reconciler npm package, ends up being the host config argument in the top-level scope).

This is still very broken.

* Add scaffolding for importing an inlined renderer

* Fix the build

* ES exports for renderer methods

* ES modules for host configs

* Remove closures from the reconciler

* Check each renderer's config with Flow

* Fix uncovered Flow issue

We know nextHydratableInstance doesn't get mutated inside this function, but Flow doesn't so it thinks it may be null.
Help Flow.

* Prettier

* Get rid of enable*Reconciler flags

They are not as useful anymore because for almost all cases (except third party renderers) we *know* whether it supports mutation or persistence.

This refactoring means react-reconciler and react-reconciler/persistent third-party packages now ship the same thing.
Not ideal, but this seems worth how simpler the code becomes. We can later look into addressing it by having a single toggle instead.

* Prettier again

* Fix Flow config creation issue

* Fix imprecise Flow typing

* Revert accidental changes
This commit is contained in:
Dan Abramov
2018-05-19 11:29:11 +01:00
committed by GitHub
parent c0fe8d6f69
commit 47b003a828
76 changed files with 8241 additions and 8226 deletions

View File

@@ -1,15 +1,35 @@
/**
* 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.
*
* @flow
*/
'use strict';
const chalk = require('chalk');
const fs = require('fs');
const mkdirp = require('mkdirp');
const {typedRenderers} = require('./typedRenderers');
const inlinedHostConfigs = require('../shared/inlinedHostConfigs');
const config = fs.readFileSync(__dirname + '/config/flowconfig');
const configTemplate = fs
.readFileSync(__dirname + '/config/flowconfig')
.toString();
function writeConfig(folder) {
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. #
@@ -39,6 +59,8 @@ ${disclaimer}
// Write multiple configs in different folders
// so that we can run those checks in parallel if we want.
typedRenderers.forEach(renderer => {
writeConfig(__dirname + '/' + renderer);
inlinedHostConfigs.forEach(rendererInfo => {
if (rendererInfo.isFlowTyped) {
writeConfig(rendererInfo.shortName);
}
});