mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
* ReactFiberReconciler -> ReactFiberReconciler.old * Set up infra for react-reconciler fork We're planning to land some significant refactors of the reconciler. We want to be able to gradually roll out the new implementation side-by- side with the existing one. So we'll create a short lived fork of the react-reconciler package. Once the new implementation has stabilized, we'll delete the old implementation and promote the new one. This means, for as long as the fork exists, we'll need to maintain two separate implementations. This sounds painful, but since the forks will still be largely the same, most changes will not require two separate implementations. In practice, you'll implement the change in the old fork and then copy paste it to the new one. This commit only sets up the build and testing infrastructure. It does not actually fork any modules. I'll do that in subsequent PRs. The forked version of the reconciler will be used to build a special version of React DOM. I've called this build ReactDOMForked. It's only built for www; there's no open source version. The new reconciler is disabled by default. It's enabled in the `yarn test-www-variant` command. The reconciler fork isn't really related to the "variant" feature of the www builds, but I'm piggy backing on that concept to avoid having to add yet another testing dimension.
92 lines
2.9 KiB
JavaScript
92 lines
2.9 KiB
JavaScript
'use strict';
|
|
|
|
const forks = require('./forks');
|
|
const {UMD_DEV, UMD_PROD, UMD_PROFILING} = require('./bundles').bundleTypes;
|
|
|
|
// For any external that is used in a DEV-only condition, explicitly
|
|
// specify whether it has side effects during import or not. This lets
|
|
// us know whether we can safely omit them when they are unused.
|
|
const HAS_NO_SIDE_EFFECTS_ON_IMPORT = false;
|
|
// const HAS_SIDE_EFFECTS_ON_IMPORT = true;
|
|
const importSideEffects = Object.freeze({
|
|
'prop-types/checkPropTypes': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
|
'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
|
scheduler: HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
|
'scheduler/tracing': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
|
'react-dom/server': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
|
});
|
|
|
|
// Bundles exporting globals that other modules rely on.
|
|
const knownGlobals = Object.freeze({
|
|
react: 'React',
|
|
'react-dom': 'ReactDOM',
|
|
'react-dom/server': 'ReactDOMServer',
|
|
'react-interactions/events/keyboard': 'ReactEventsKeyboard',
|
|
'react-interactions/events/tap': 'ReactEventsTap',
|
|
scheduler: 'Scheduler',
|
|
'scheduler/tracing': 'SchedulerTracing',
|
|
'scheduler/unstable_mock': 'SchedulerMock',
|
|
});
|
|
|
|
// Given ['react'] in bundle externals, returns { 'react': 'React' }.
|
|
function getPeerGlobals(externals, bundleType) {
|
|
const peerGlobals = {};
|
|
externals.forEach(name => {
|
|
if (
|
|
!knownGlobals[name] &&
|
|
(bundleType === UMD_DEV ||
|
|
bundleType === UMD_PROD ||
|
|
bundleType === UMD_PROFILING)
|
|
) {
|
|
throw new Error('Cannot build UMD without a global name for: ' + name);
|
|
}
|
|
peerGlobals[name] = knownGlobals[name];
|
|
});
|
|
return peerGlobals;
|
|
}
|
|
|
|
// Determines node_modules packages that are safe to assume will exist.
|
|
function getDependencies(bundleType, entry) {
|
|
// Replaces any part of the entry that follow the package name (like
|
|
// "/server" in "react-dom/server") by the path to the package settings
|
|
const packageJson = require(entry.replace(/(\/.*)?$/, '/package.json'));
|
|
// Both deps and peerDeps are assumed as accessible.
|
|
return Array.from(
|
|
new Set([
|
|
...Object.keys(packageJson.dependencies || {}),
|
|
...Object.keys(packageJson.peerDependencies || {}),
|
|
])
|
|
);
|
|
}
|
|
|
|
// Hijacks some modules for optimization and integration reasons.
|
|
function getForks(bundleType, entry, moduleType, bundle) {
|
|
const forksForBundle = {};
|
|
Object.keys(forks).forEach(srcModule => {
|
|
const dependencies = getDependencies(bundleType, entry);
|
|
const targetModule = forks[srcModule](
|
|
bundleType,
|
|
entry,
|
|
dependencies,
|
|
moduleType,
|
|
bundle
|
|
);
|
|
if (targetModule === null) {
|
|
return;
|
|
}
|
|
forksForBundle[srcModule] = targetModule;
|
|
});
|
|
return forksForBundle;
|
|
}
|
|
|
|
function getImportSideEffects() {
|
|
return importSideEffects;
|
|
}
|
|
|
|
module.exports = {
|
|
getImportSideEffects,
|
|
getPeerGlobals,
|
|
getDependencies,
|
|
getForks,
|
|
};
|