@@ -4,14 +4,12 @@ const rollup = require('rollup').rollup;
44const babel = require ( 'rollup-plugin-babel' ) ;
55const closure = require ( 'rollup-plugin-closure-compiler-js' ) ;
66const commonjs = require ( 'rollup-plugin-commonjs' ) ;
7- const alias = require ( 'rollup-plugin-alias' ) ;
87const prettier = require ( 'rollup-plugin-prettier' ) ;
98const replace = require ( 'rollup-plugin-replace' ) ;
109const stripBanner = require ( 'rollup-plugin-strip-banner' ) ;
1110const chalk = require ( 'chalk' ) ;
12- const join = require ( 'path' ) . join ;
13- const resolve = require ( 'path' ) . resolve ;
14- const resolvePlugin = require ( 'rollup-plugin-node-resolve' ) ;
11+ const path = require ( 'path' ) ;
12+ const resolve = require ( 'rollup-plugin-node-resolve' ) ;
1513const fs = require ( 'fs' ) ;
1614const rimraf = require ( 'rimraf' ) ;
1715const argv = require ( 'minimist' ) ( process . argv . slice ( 2 ) ) ;
@@ -88,7 +86,7 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
8886 return Object . assign ( { } , options , {
8987 plugins : options . plugins . concat ( [
9088 // Use object-assign polyfill in open source
91- resolve ( './scripts/babel/transform-object-assign-require' ) ,
89+ path . resolve ( './scripts/babel/transform-object-assign-require' ) ,
9290 // Minify invariant messages
9391 require ( '../error-codes/replace-invariant-error-codes' ) ,
9492 // Wrap warning() calls in a __DEV__ check so they are stripped from production.
@@ -113,11 +111,11 @@ function handleRollupWarnings(warning) {
113111 ) ;
114112 }
115113 const importSideEffects = Modules . getImportSideEffects ( ) ;
116- const path = match [ 1 ] ;
117- if ( typeof importSideEffects [ path ] !== 'boolean' ) {
114+ const externalModule = match [ 1 ] ;
115+ if ( typeof importSideEffects [ externalModule ] !== 'boolean' ) {
118116 throw new Error (
119117 'An external module "' +
120- path +
118+ externalModule +
121119 '" is used in a DEV-only code path ' +
122120 'but we do not know if it is safe to omit an unused require() to it in production. ' +
123121 'Please add it to the `importSideEffects` list in `scripts/rollup/modules.js`.'
@@ -210,6 +208,44 @@ function isProductionBundleType(bundleType) {
210208 }
211209}
212210
211+ let resolveCache = new Map ( ) ;
212+ function useForks ( forks ) {
213+ let resolvedForks = { } ;
214+ Object . keys ( forks ) . forEach ( srcModule => {
215+ const targetModule = forks [ srcModule ] ;
216+ resolvedForks [ require . resolve ( srcModule ) ] = require . resolve ( targetModule ) ;
217+ } ) ;
218+ return {
219+ resolveId ( importee , importer ) {
220+ if ( ! importer || ! importee ) {
221+ return null ;
222+ }
223+ let resolvedImportee = null ;
224+ let cacheKey = `${ importer } :::${ importee } ` ;
225+ if ( resolveCache . has ( cacheKey ) ) {
226+ // Avoid hitting file system if possible.
227+ resolvedImportee = resolveCache . get ( cacheKey ) ;
228+ } else {
229+ try {
230+ resolvedImportee = require . resolve ( importee , {
231+ paths : [ path . dirname ( importer ) ] ,
232+ } ) ;
233+ } catch ( err ) {
234+ // Not our fault, let Rollup fail later.
235+ }
236+ if ( resolvedImportee ) {
237+ resolveCache . set ( cacheKey , resolvedImportee ) ;
238+ }
239+ }
240+ if ( resolvedImportee && resolvedForks . hasOwnProperty ( resolvedImportee ) ) {
241+ // We found a fork!
242+ return resolvedForks [ resolvedImportee ] ;
243+ }
244+ return null ;
245+ } ,
246+ } ;
247+ }
248+
213249function getPlugins (
214250 entry ,
215251 externals ,
@@ -236,9 +272,9 @@ function getPlugins(
236272 } ,
237273 } ,
238274 // Shim any modules that need forking in this environment.
239- alias ( forks ) ,
275+ useForks ( forks ) ,
240276 // Use Node resolution mechanism.
241- resolvePlugin ( {
277+ resolve ( {
242278 skip : externals ,
243279 } ) ,
244280 // Remove license headers from individual modules
@@ -437,9 +473,9 @@ rimraf('build', async () => {
437473 // create a new build directory
438474 fs . mkdirSync ( 'build' ) ;
439475 // create the packages folder for NODE+UMD bundles
440- fs . mkdirSync ( join ( 'build' , 'packages' ) ) ;
476+ fs . mkdirSync ( path . join ( 'build' , 'packages' ) ) ;
441477 // create the dist folder for UMD bundles
442- fs . mkdirSync ( join ( 'build' , 'dist' ) ) ;
478+ fs . mkdirSync ( path . join ( 'build' , 'dist' ) ) ;
443479
444480 await Packaging . createFacebookWWWBuild ( ) ;
445481 await Packaging . createReactNativeBuild ( ) ;
@@ -460,11 +496,11 @@ rimraf('build', async () => {
460496 }
461497
462498 if ( syncFbsource ) {
463- await syncReactNative ( join ( 'build' , 'react-native' ) , syncFbsource ) ;
464- await syncReactNativeRT ( join ( 'build' , 'react-rt' ) , syncFbsource ) ;
465- await syncReactNativeCS ( join ( 'build' , 'react-cs' ) , syncFbsource ) ;
499+ await syncReactNative ( path . join ( 'build' , 'react-native' ) , syncFbsource ) ;
500+ await syncReactNativeRT ( path . join ( 'build' , 'react-rt' ) , syncFbsource ) ;
501+ await syncReactNativeCS ( path . join ( 'build' , 'react-cs' ) , syncFbsource ) ;
466502 } else if ( syncWww ) {
467- await syncReactDom ( join ( 'build' , 'facebook-www' ) , syncWww ) ;
503+ await syncReactDom ( path . join ( 'build' , 'facebook-www' ) , syncWww ) ;
468504 }
469505
470506 console . log ( Stats . printResults ( ) ) ;
0 commit comments