mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 00:20:04 +01:00
In React 19 React will finally stop publishing UMD builds. This is motivated primarily by the lack of use of UMD format and the added complexity of maintaining build infra for these releases. Additionally with ESM becoming more prevalent in browsers and services like esm.sh which can host React as an ESM module there are other options for doing script tag based react loading. This PR removes all the UMD build configs and forks. There are some fixtures that still have references to UMD builds however many of them already do not work (for instance they are using legacy features like ReactDOM.render) and rather than block the removal on these fixtures being brought up to date we'll just move forward and fix or removes fixtures as necessary in the future.
91 lines
2.9 KiB
JavaScript
91 lines
2.9 KiB
JavaScript
'use strict';
|
|
|
|
const forks = require('./forks');
|
|
|
|
// 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({
|
|
fs: HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
|
'fs/promises': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
|
path: HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
|
stream: HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
|
'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,
|
|
react: HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
|
'react-dom/server': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
|
'react/jsx-dev-runtime': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
|
'react-dom': HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
|
url: HAS_NO_SIDE_EFFECTS_ON_IMPORT,
|
|
ReactNativeInternalFeatureFlags: 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/tap': 'ReactEventsTap',
|
|
scheduler: 'Scheduler',
|
|
'scheduler/unstable_mock': 'SchedulerMock',
|
|
ReactNativeInternalFeatureFlags: 'ReactNativeInternalFeatureFlags',
|
|
});
|
|
|
|
// Given ['react'] in bundle externals, returns { 'react': 'React' }.
|
|
function getPeerGlobals(externals, bundleType) {
|
|
const peerGlobals = {};
|
|
externals.forEach(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,
|
|
};
|