mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
* Split ReactNativeFiber into separate ReactNativeFiberRenderer module Hopefully this is sufficient to work around Rollup circular dependency problems. (To be seen in subsequent commits...) * Split findNodeHandle into findNodeHandleFiber + findNodeHandleStack This allowed me to remove the ReactNative -> findNodeHandle injections, which should in turn allow me to require a fully-functional findNodeHandle without going through ReactNative. This will hopefully allow ReactNativeBaseomponent to avoid a circular dependency. * Un-forked findNodeHandle in favor of just inlining the findNode function impl * takeSnapshot no longer requires/depends-on ReactNative for findNodeHandle Instead it uses the new, renderer-specific wrappers (eg findNodeHandleFiberWrapper and findNodeHandleStackWrapper) to ensure the returned value is numeric (or null). This avoids a circular dependency that would trip up Rollup. * NativeMethodsMixin requires findNodeHandler wrapper(s) directly rather than ReactNative This works around a potential circular dependency that would break the Rollup build * Add RN_* build targets to hash-finle-name check * Strip @providesModule annotations from headers for RN_* builds * Added process.env.REACT_NATIVE_USE_FIBER to ReactNativeFeatureFlags This is kind of a hacky solution, but it is temporary. It works around the fact that ReactNativeFeatureFlag values need to be set at build time in order to avoid a mismatch between runtime flag values. DOM avoids the need to do this by using injection but Native is not able to use this same approach due to circular dependency issues. * Moved a couple of SECRET exports to dev-only. Removed SyntheticEvent and PooledClass from SECRET exports. Converted Rollup helper function to use named params. * Split NativeMethodsMixins interface and object-type * Add @noflow header to flat-bundle template to avoid triggering Flow problems When Flow tries to infer such a large file, it consumes massive amounts of CPU/RAM and can often lead to programs crashing. It is better for such large files to use .flow.js types instead. * NativeMethodsMixin and ReactNativeFiberHostComponent now share the same Flow type * Collocated (externally exposed) ReactTypes and ReactNativeTypes into single files to be synced to fbsource. ReactNativeFiber and ReactNativeStack use ReactNativeType Flow type * Build script syncs RN types and PooledClass automatically * Added optional sync-RN step to Rollup build script * Added results.json for new RN bundles
171 lines
5.8 KiB
JavaScript
171 lines
5.8 KiB
JavaScript
'use strict';
|
|
|
|
const basename = require('path').basename;
|
|
const fs = require('fs');
|
|
const join = require('path').join;
|
|
const resolve = require('path').resolve;
|
|
const Bundles = require('./bundles');
|
|
const asyncCopyTo = require('./utils').asyncCopyTo;
|
|
|
|
const UMD_DEV = Bundles.bundleTypes.UMD_DEV;
|
|
const UMD_PROD = Bundles.bundleTypes.UMD_PROD;
|
|
const NODE_DEV = Bundles.bundleTypes.NODE_DEV;
|
|
const NODE_PROD = Bundles.bundleTypes.NODE_PROD;
|
|
const FB_DEV = Bundles.bundleTypes.FB_DEV;
|
|
const FB_PROD = Bundles.bundleTypes.FB_PROD;
|
|
const RN_DEV = Bundles.bundleTypes.RN_DEV;
|
|
const RN_PROD = Bundles.bundleTypes.RN_PROD;
|
|
|
|
const facebookWWW = 'facebook-www';
|
|
// these files need to be copied to the facebook-www build
|
|
const facebookWWWSrcDependencies = [
|
|
'src/test/reactComponentExpect.js',
|
|
'src/renderers/dom/shared/eventPlugins/TapEventPlugin.js',
|
|
];
|
|
|
|
// these files need to be copied to the react-native build
|
|
const reactNativeSrcDependencies = [
|
|
'src/shared/utils/PooledClass.js',
|
|
'src/renderers/shared/fiber/isomorphic/ReactTypes.js',
|
|
'src/renderers/native/ReactNativeTypes.js',
|
|
];
|
|
|
|
function getPackageName(name) {
|
|
if (name.indexOf('/') !== -1) {
|
|
return name.split('/')[0];
|
|
}
|
|
return name;
|
|
}
|
|
|
|
function createReactNativeBuild() {
|
|
// create the react-native folder for FB bundles
|
|
fs.mkdirSync(join('build', 'react-native'));
|
|
// create the react-native shims folder for FB shims
|
|
fs.mkdirSync(join('build', 'react-native', 'shims'));
|
|
// copy in all the shims from build/rollup/shims/react-native
|
|
const from = join('scripts', 'rollup', 'shims', 'react-native');
|
|
const to = join('build', 'react-native', 'shims');
|
|
|
|
return asyncCopyTo(from, to).then(() => {
|
|
let promises = [];
|
|
// we also need to copy over some specific files from src
|
|
// defined in reactNativeSrcDependencies
|
|
for (const srcDependency of reactNativeSrcDependencies) {
|
|
promises.push(
|
|
asyncCopyTo(resolve(srcDependency), join(to, basename(srcDependency)))
|
|
);
|
|
}
|
|
return Promise.all(promises);
|
|
});
|
|
}
|
|
|
|
function createFacebookWWWBuild() {
|
|
// create the facebookWWW folder for FB bundles
|
|
fs.mkdirSync(join('build', facebookWWW));
|
|
// create the facebookWWW shims folder for FB shims
|
|
fs.mkdirSync(join('build', facebookWWW, 'shims'));
|
|
// copy in all the shims from build/rollup/shims/facebook-www
|
|
const from = join('scripts', 'rollup', 'shims', facebookWWW);
|
|
const to = join('build', facebookWWW, 'shims');
|
|
|
|
return asyncCopyTo(from, to).then(() => {
|
|
let promises = [];
|
|
// we also need to copy over some specific files from src
|
|
// defined in facebookWWWSrcDependencies
|
|
for (const srcDependency of facebookWWWSrcDependencies) {
|
|
promises.push(
|
|
asyncCopyTo(resolve(srcDependency), join(to, basename(srcDependency)))
|
|
);
|
|
}
|
|
return Promise.all(promises);
|
|
});
|
|
}
|
|
|
|
function copyBundleIntoNodePackage(packageName, filename, bundleType) {
|
|
const packageDirectory = resolve(`./build/packages/${packageName}`);
|
|
|
|
if (fs.existsSync(packageDirectory)) {
|
|
let from = resolve(`./build/${filename}`);
|
|
let to = `${packageDirectory}/${filename}`;
|
|
// for UMD bundles we have to move the files into a umd directory
|
|
// within the package directory. we also need to set the from
|
|
// to be the root build from directory
|
|
if (bundleType === UMD_DEV || bundleType === UMD_PROD) {
|
|
const distDirectory = `${packageDirectory}/umd`;
|
|
// create a dist directory if not created
|
|
if (!fs.existsSync(distDirectory)) {
|
|
fs.mkdirSync(distDirectory);
|
|
}
|
|
from = resolve(`./build/dist/${filename}`);
|
|
to = `${packageDirectory}/umd/${filename}`;
|
|
}
|
|
// for NODE bundles we have to move the files into a cjs directory
|
|
// within the package directory. we also need to set the from
|
|
// to be the root build from directory
|
|
if (bundleType === NODE_DEV || bundleType === NODE_PROD) {
|
|
const distDirectory = `${packageDirectory}/cjs`;
|
|
// create a dist directory if not created
|
|
if (!fs.existsSync(distDirectory)) {
|
|
fs.mkdirSync(distDirectory);
|
|
}
|
|
to = `${packageDirectory}/cjs/${filename}`;
|
|
}
|
|
return asyncCopyTo(from, to).then(() => {
|
|
// delete the old file if this is a not a UMD bundle
|
|
if (bundleType !== UMD_DEV && bundleType !== UMD_PROD) {
|
|
fs.unlinkSync(from);
|
|
}
|
|
});
|
|
} else {
|
|
return Promise.resolve();
|
|
}
|
|
}
|
|
|
|
function copyNodePackageTemplate(packageName) {
|
|
const from = resolve(`./packages/${packageName}`);
|
|
const to = resolve(`./build/packages/${packageName}`);
|
|
|
|
// if the package directory already exists, we skip copying to it
|
|
if (!fs.existsSync(to) && fs.existsSync(from)) {
|
|
return asyncCopyTo(from, to).then(() =>
|
|
Promise.all([
|
|
asyncCopyTo(resolve('./LICENSE'), `${to}/LICENSE`),
|
|
asyncCopyTo(resolve('./PATENTS'), `${to}/PATENTS`),
|
|
])
|
|
);
|
|
} else {
|
|
return Promise.resolve();
|
|
}
|
|
}
|
|
|
|
function createNodePackage(bundleType, packageName, filename) {
|
|
// the only case where we don't want to copy the package is for FB bundles
|
|
if (bundleType !== FB_DEV && bundleType !== FB_PROD) {
|
|
return copyNodePackageTemplate(packageName).then(() =>
|
|
copyBundleIntoNodePackage(packageName, filename, bundleType)
|
|
);
|
|
}
|
|
return Promise.resolve();
|
|
}
|
|
|
|
function getPackageDestination(config, bundleType, filename) {
|
|
let dest = config.destDir + filename;
|
|
|
|
if (bundleType === FB_DEV || bundleType === FB_PROD) {
|
|
dest = `${config.destDir}${facebookWWW}/${filename}`;
|
|
} else if (bundleType === UMD_DEV || bundleType === UMD_PROD) {
|
|
dest = `${config.destDir}dist/${filename}`;
|
|
} else if (bundleType === RN_DEV || bundleType === RN_PROD) {
|
|
dest = `${config.destDir}react-native/${filename}`;
|
|
}
|
|
return dest;
|
|
}
|
|
|
|
module.exports = {
|
|
getPackageDestination,
|
|
createNodePackage,
|
|
getPackageName,
|
|
createFacebookWWWBuild,
|
|
createReactNativeBuild,
|
|
};
|