Skip to content

Commit

Permalink
Add IIFE bundle for SSR instruction streaming runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeiZ committed Oct 10, 2022
1 parent aa9988e commit 00e84f0
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/react-dom/external-streaming-runtime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// SSR instruction streaming runtime
// will be added by https://github.com/facebook/react/pull/25437
5 changes: 4 additions & 1 deletion packages/react-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"index.js",
"client.js",
"profiling.js",
"external-streaming-runtime.js",
"server.js",
"server.browser.js",
"server.node.js",
Expand All @@ -39,7 +40,8 @@
"test-utils.js",
"unstable_testing.js",
"cjs/",
"umd/"
"umd/",
"iife/"
],
"exports": {
".": "./index.js",
Expand All @@ -61,6 +63,7 @@
"./static.browser": "./static.browser.js",
"./static.node": "./static.node.js",
"./server-rendering-stub": "./server-rendering-stub.js",
"./external-streaming-runtime": "./external-streaming-runtime.js",
"./profiling": "./profiling.js",
"./test-utils": "./test-utils.js",
"./unstable_testing": "./unstable_testing.js",
Expand Down
32 changes: 29 additions & 3 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const {
RN_FB_DEV,
RN_FB_PROD,
RN_FB_PROFILING,
IIFE_DEV,
IIFE_PROD,
FB_IIFE_DEV,
FB_IIFE_PROD,
} = Bundles.bundleTypes;

const {getFilename} = Bundles;
Expand Down Expand Up @@ -224,6 +228,11 @@ function getFormat(bundleType) {
return `cjs`;
case NODE_ESM:
return `es`;
case IIFE_DEV:
case IIFE_PROD:
case FB_IIFE_DEV:
case FB_IIFE_PROD:
return 'iife';
}
}

Expand All @@ -236,6 +245,8 @@ function isProductionBundleType(bundleType) {
case FB_WWW_DEV:
case RN_OSS_DEV:
case RN_FB_DEV:
case IIFE_DEV:
case FB_IIFE_DEV:
return false;
case UMD_PROD:
case NODE_PROD:
Expand All @@ -247,6 +258,8 @@ function isProductionBundleType(bundleType) {
case RN_OSS_PROFILING:
case RN_FB_PROD:
case RN_FB_PROFILING:
case IIFE_PROD:
case FB_IIFE_PROD:
return true;
default:
throw new Error(`Unknown type: ${bundleType}`);
Expand All @@ -267,6 +280,10 @@ function isProfilingBundleType(bundleType) {
case RN_OSS_PROD:
case UMD_DEV:
case UMD_PROD:
case IIFE_DEV:
case IIFE_PROD:
case FB_IIFE_DEV:
case FB_IIFE_PROD:
return false;
case FB_WWW_PROFILING:
case NODE_PROFILING:
Expand Down Expand Up @@ -315,7 +332,9 @@ function getPlugins(
const isFBWWWBundle =
bundleType === FB_WWW_DEV ||
bundleType === FB_WWW_PROD ||
bundleType === FB_WWW_PROFILING;
bundleType === FB_WWW_PROFILING ||
bundleType === FB_IIFE_DEV ||
bundleType === FB_IIFE_PROD;
const isRNBundle =
bundleType === RN_OSS_DEV ||
bundleType === RN_OSS_PROD ||
Expand Down Expand Up @@ -509,7 +528,9 @@ async function createBundle(bundle, bundleType) {
const isFBWWWBundle =
bundleType === FB_WWW_DEV ||
bundleType === FB_WWW_PROD ||
bundleType === FB_WWW_PROFILING;
bundleType === FB_WWW_PROFILING ||
bundleType === FB_IIFE_DEV ||
bundleType === FB_IIFE_PROD;

const isFBRNBundle =
bundleType === RN_FB_DEV ||
Expand Down Expand Up @@ -593,6 +614,7 @@ async function createBundle(bundle, bundleType) {
bundle.global,
bundleType
);
console.log(rollupOutputOptions);

if (isWatchMode) {
rollupConfig.output = [rollupOutputOptions];
Expand Down Expand Up @@ -724,7 +746,11 @@ async function buildEverything() {
[bundle, RN_OSS_PROFILING],
[bundle, RN_FB_DEV],
[bundle, RN_FB_PROD],
[bundle, RN_FB_PROFILING]
[bundle, RN_FB_PROFILING],
[bundle, IIFE_DEV],
[bundle, IIFE_PROD],
[bundle, FB_IIFE_DEV],
[bundle, FB_IIFE_PROD]
);
}

Expand Down
27 changes: 27 additions & 0 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const bundleTypes = {
RN_FB_DEV: 'RN_FB_DEV',
RN_FB_PROD: 'RN_FB_PROD',
RN_FB_PROFILING: 'RN_FB_PROFILING',
IIFE_DEV: 'IIFE_DEV',
IIFE_PROD: 'IIFE_PROD',
FB_IIFE_DEV: 'FB_IIFE_DEV',
FB_IIFE_PROD: 'FB_IIFE_PROD',
};

const {
Expand All @@ -45,6 +49,10 @@ const {
RN_FB_DEV,
RN_FB_PROD,
RN_FB_PROFILING,
IIFE_DEV,
IIFE_PROD,
FB_IIFE_DEV,
FB_IIFE_PROD,
} = bundleTypes;

const moduleTypes = {
Expand Down Expand Up @@ -330,6 +338,19 @@ const bundles = [
externals: ['react', 'react-dom'],
},

{
bundleTypes: __EXPERIMENTAL__
? [IIFE_DEV, IIFE_PROD, FB_IIFE_DEV, FB_IIFE_PROD]
: [],
moduleType: RENDERER,
entry: 'react-dom/external-streaming-runtime',
name: 'external-streaming-runtime',
global: 'ReactDOMExternalStreamingRuntime',
minifyWithProdErrorCodes: true,
wrapWithModuleBoundaries: false,
externals: [],
},

/******* React DOM Fizz Static *******/
{
bundleTypes: __EXPERIMENTAL__ ? [NODE_DEV, NODE_PROD] : [],
Expand Down Expand Up @@ -1006,6 +1027,8 @@ function getOriginalFilename(bundle, bundleType) {
return `${name}.js`;
case NODE_ESM:
return `${name}.js`;
case IIFE_DEV:
return `${name}.development.js`;
case UMD_DEV:
return `${name}.development.js`;
case UMD_PROD:
Expand All @@ -1018,13 +1041,17 @@ function getOriginalFilename(bundle, bundleType) {
return `${name}.production.min.js`;
case NODE_PROFILING:
return `${name}.profiling.min.js`;
case IIFE_PROD:
return `${name}.production.min.js`;
case FB_WWW_DEV:
case RN_OSS_DEV:
case RN_FB_DEV:
case FB_IIFE_DEV:
return `${globalName}-dev.js`;
case FB_WWW_PROD:
case RN_OSS_PROD:
case RN_FB_PROD:
case FB_IIFE_PROD:
return `${globalName}-prod.js`;
case FB_WWW_PROFILING:
case RN_FB_PROFILING:
Expand Down
9 changes: 9 additions & 0 deletions scripts/rollup/packaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const {
RN_FB_DEV,
RN_FB_PROD,
RN_FB_PROFILING,
IIFE_DEV,
IIFE_PROD,
FB_IIFE_DEV,
FB_IIFE_PROD,
} = Bundles.bundleTypes;

function getPackageName(name) {
Expand All @@ -59,6 +63,8 @@ function getBundleOutputPath(bundleType, filename, packageName) {
case FB_WWW_DEV:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
case FB_IIFE_DEV:
case FB_IIFE_PROD:
return `build/facebook-www/${filename}`;
case RN_OSS_DEV:
case RN_OSS_PROD:
Expand Down Expand Up @@ -88,6 +94,9 @@ function getBundleOutputPath(bundleType, filename, packageName) {
default:
throw new Error('Unknown RN package.');
}
case IIFE_DEV:
case IIFE_PROD:
return `build/node_modules/${packageName}/iife/${filename}`;
default:
throw new Error('Unknown bundle type.');
}
Expand Down
53 changes: 53 additions & 0 deletions scripts/rollup/wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const {
RN_FB_DEV,
RN_FB_PROD,
RN_FB_PROFILING,
IIFE_DEV,
IIFE_PROD,
FB_IIFE_DEV,
FB_IIFE_PROD,
} = bundleTypes;

const {RECONCILER} = moduleTypes;
Expand Down Expand Up @@ -294,6 +298,55 @@ ${license}
* ${'@gen' + 'erated'}
*/
${source}`;
},

[IIFE_DEV](source, globalName, filename, moduleType) {
return `/**
* @license React
* ${filename}
*
${license}
*/
${source}`;
},
[IIFE_PROD](source, globalName, filename, moduleType) {
return `/**
* @license React
* ${filename}
*
${license}
*/
${source}`;
},
[FB_IIFE_DEV](source, globalName, filename, moduleType) {
return `/**
${license}
*
* @noflow
* @nolint
* @preventMunge
* @preserve-invariant-messages
*/
'use strict';
if (__DEV__) {
(function() {
${source}
})();
}`;
},
[FB_IIFE_PROD](source, globalName, filename, moduleType) {
return `/**
${license}
*
* @noflow
* @nolint
* @preventMunge
* @preserve-invariant-messages
*/
${source}`;
},
};
Expand Down
2 changes: 2 additions & 0 deletions scripts/shared/inlinedHostConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = [
'react-dom/src/server/ReactDOMFizzServerNode.js',
'react-dom/static.node',
'react-dom/server-rendering-stub',
'react-dom/external-streaming-runtime',
'react-server-dom-webpack/writer.node.server',
'react-server-dom-webpack',
],
Expand Down Expand Up @@ -51,6 +52,7 @@ module.exports = [
'react-dom/src/server/ReactDOMFizzServerBrowser.js',
'react-dom/static.browser',
'react-dom/server-rendering-stub',
'react-dom/external-streaming-runtime',
'react-server-dom-webpack/writer.browser.server',
'react-server-dom-webpack',
],
Expand Down

0 comments on commit 00e84f0

Please sign in to comment.