Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UMD production+profiling entry points #13642

Merged
merged 5 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions packages/schedule/npm/umd/schedule.profiling.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @license React
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

(function(global, factory) {
typeof exports === 'object' && typeof module !== 'undefined'
? (module.exports = factory(require('react')))
: typeof define === 'function' && define.amd // eslint-disable-line no-undef
? define(['react'], factory) // eslint-disable-line no-undef
: (global.Schedule = factory(global));
})(this, function(global) {
function unstable_now() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Schedule.unstable_now.apply(
this,
arguments
);
}

function unstable_scheduleWork() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Schedule.unstable_scheduleWork.apply(
this,
arguments
);
}

function unstable_cancelScheduledWork() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Schedule.unstable_cancelScheduledWork.apply(
this,
arguments
);
}

return Object.freeze({
unstable_now: unstable_now,
unstable_scheduleWork: unstable_scheduleWork,
unstable_cancelScheduledWork: unstable_cancelScheduledWork,
});
});
17 changes: 15 additions & 2 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ process.on('unhandledRejection', err => {
const {
UMD_DEV,
UMD_PROD,
UMD_PROFILING,
NODE_DEV,
NODE_PROD,
NODE_PROFILING,
Expand Down Expand Up @@ -113,6 +114,7 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
});
case UMD_DEV:
case UMD_PROD:
case UMD_PROFILING:
case NODE_DEV:
case NODE_PROD:
case NODE_PROFILING:
Expand Down Expand Up @@ -158,6 +160,7 @@ function getFormat(bundleType) {
switch (bundleType) {
case UMD_DEV:
case UMD_PROD:
case UMD_PROFILING:
return `umd`;
case NODE_DEV:
case NODE_PROD:
Expand All @@ -183,6 +186,8 @@ function getFilename(name, globalName, bundleType) {
return `${name}.development.js`;
case UMD_PROD:
return `${name}.production.min.js`;
case UMD_PROFILING:
return `${name}.profiling.min.js`;
case NODE_DEV:
return `${name}.development.js`;
case NODE_PROD:
Expand Down Expand Up @@ -214,6 +219,7 @@ function isProductionBundleType(bundleType) {
return false;
case UMD_PROD:
case NODE_PROD:
case UMD_PROFILING:
case NODE_PROFILING:
case FB_WWW_PROD:
case FB_WWW_PROFILING:
Expand Down Expand Up @@ -244,6 +250,7 @@ function isProfilingBundleType(bundleType) {
case NODE_PROFILING:
case RN_FB_PROFILING:
case RN_OSS_PROFILING:
case UMD_PROFILING:
return true;
default:
throw new Error(`Unknown type: ${bundleType}`);
Expand Down Expand Up @@ -280,7 +287,10 @@ function getPlugins(
const forks = Modules.getForks(bundleType, entry, moduleType);
const isProduction = isProductionBundleType(bundleType);
const isProfiling = isProfilingBundleType(bundleType);
const isUMDBundle = bundleType === UMD_DEV || bundleType === UMD_PROD;
const isUMDBundle =
bundleType === UMD_DEV ||
bundleType === UMD_PROD ||
bundleType === UMD_PROFILING;
const isFBBundle =
bundleType === FB_WWW_DEV ||
bundleType === FB_WWW_PROD ||
Expand Down Expand Up @@ -430,7 +440,9 @@ async function createBundle(bundle, bundleType) {
}

const shouldBundleDependencies =
bundleType === UMD_DEV || bundleType === UMD_PROD;
bundleType === UMD_DEV ||
bundleType === UMD_PROD ||
bundleType === UMD_PROFILING;
const peerGlobals = Modules.getPeerGlobals(bundle.externals, bundleType);
let externals = Object.keys(peerGlobals);
if (!shouldBundleDependencies) {
Expand Down Expand Up @@ -580,6 +592,7 @@ async function buildEverything() {
for (const bundle of Bundles.bundles) {
await createBundle(bundle, UMD_DEV);
await createBundle(bundle, UMD_PROD);
await createBundle(bundle, UMD_PROFILING);
await createBundle(bundle, NODE_DEV);
await createBundle(bundle, NODE_PROD);
await createBundle(bundle, NODE_PROFILING);
Expand Down
5 changes: 4 additions & 1 deletion scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const bundleTypes = {
UMD_DEV: 'UMD_DEV',
UMD_PROD: 'UMD_PROD',
UMD_PROFILING: 'UMD_PROFILING',
NODE_DEV: 'NODE_DEV',
NODE_PROD: 'NODE_PROD',
NODE_PROFILING: 'NODE_PROFILING',
Expand All @@ -19,6 +20,7 @@ const bundleTypes = {

const UMD_DEV = bundleTypes.UMD_DEV;
const UMD_PROD = bundleTypes.UMD_PROD;
const UMD_PROFILING = bundleTypes.UMD_PROFILING;
const NODE_DEV = bundleTypes.NODE_DEV;
const NODE_PROD = bundleTypes.NODE_PROD;
const NODE_PROFILING = bundleTypes.NODE_PROFILING;
Expand Down Expand Up @@ -58,9 +60,9 @@ const bundles = [
bundleTypes: [
UMD_DEV,
UMD_PROD,
UMD_PROFILING,
NODE_DEV,
NODE_PROD,
NODE_PROFILING,
FB_WWW_DEV,
FB_WWW_PROD,
FB_WWW_PROFILING,
Expand All @@ -77,6 +79,7 @@ const bundles = [
bundleTypes: [
UMD_DEV,
UMD_PROD,
UMD_PROFILING,
NODE_DEV,
NODE_PROD,
NODE_PROFILING,
Expand Down
9 changes: 8 additions & 1 deletion scripts/rollup/forks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const inlinedHostConfigs = require('../shared/inlinedHostConfigs');

const UMD_DEV = bundleTypes.UMD_DEV;
const UMD_PROD = bundleTypes.UMD_PROD;
const UMD_PROFILING = bundleTypes.UMD_PROFILING;
const FB_WWW_DEV = bundleTypes.FB_WWW_DEV;
const FB_WWW_PROD = bundleTypes.FB_WWW_PROD;
const FB_WWW_PROFILING = bundleTypes.FB_WWW_PROFILING;
Expand All @@ -24,7 +25,11 @@ const forks = Object.freeze({
// Optimization: for UMDs, use object-assign polyfill that is already a part
// of the React package instead of bundling it again.
'object-assign': (bundleType, entry, dependencies) => {
if (bundleType !== UMD_DEV && bundleType !== UMD_PROD) {
if (
bundleType !== UMD_DEV &&
bundleType !== UMD_PROD &&
bundleType !== UMD_PROFILING
) {
// It's only relevant for UMD bundles since that's where the duplication
// happens. Other bundles just require('object-assign') anyway.
return null;
Expand Down Expand Up @@ -118,6 +123,7 @@ const forks = Object.freeze({
switch (bundleType) {
case UMD_DEV:
case UMD_PROD:
case UMD_PROFILING:
if (dependencies.indexOf('react') === -1) {
// It's only safe to use this fork for modules that depend on React,
// because they read the re-exported API from the SECRET_INTERNALS object.
Expand All @@ -136,6 +142,7 @@ const forks = Object.freeze({
switch (bundleType) {
case UMD_DEV:
case UMD_PROD:
case UMD_PROFILING:
if (dependencies.indexOf('react') === -1) {
// It's only safe to use this fork for modules that depend on React,
// because they read the re-exported API from the SECRET_INTERNALS object.
Expand Down
5 changes: 4 additions & 1 deletion scripts/rollup/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const bundleTypes = require('./bundles').bundleTypes;

const UMD_DEV = bundleTypes.UMD_DEV;
const UMD_PROD = bundleTypes.UMD_PROD;
const UMD_PROFILING = bundleTypes.UMD_PROFILING;

// For any external that is used in a DEV-only condition, explicitly
// specify whether it has side effects during import or not. This lets
Expand Down Expand Up @@ -32,7 +33,9 @@ function getPeerGlobals(externals, bundleType) {
externals.forEach(name => {
if (
!knownGlobals[name] &&
(bundleType === UMD_DEV || bundleType === UMD_PROD)
(bundleType === UMD_DEV ||
bundleType === UMD_PROD ||
bundleType === UMD_PROFILING)
) {
throw new Error('Cannot build UMD without a global name for: ' + name);
}
Expand Down
2 changes: 2 additions & 0 deletions scripts/rollup/packaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
const {
UMD_DEV,
UMD_PROD,
UMD_PROFILING,
NODE_DEV,
NODE_PROD,
NODE_PROFILING,
Expand Down Expand Up @@ -41,6 +42,7 @@ function getBundleOutputPaths(bundleType, filename, packageName) {
return [`build/node_modules/${packageName}/cjs/${filename}`];
case UMD_DEV:
case UMD_PROD:
case UMD_PROFILING:
return [
`build/node_modules/${packageName}/umd/${filename}`,
`build/dist/${filename}`,
Expand Down
11 changes: 11 additions & 0 deletions scripts/rollup/wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const reactVersion = require('../../package.json').version;

const UMD_DEV = Bundles.bundleTypes.UMD_DEV;
const UMD_PROD = Bundles.bundleTypes.UMD_PROD;
const UMD_PROFILING = Bundles.bundleTypes.UMD_PROFILING;
const NODE_DEV = Bundles.bundleTypes.NODE_DEV;
const NODE_PROD = Bundles.bundleTypes.NODE_PROD;
const NODE_PROFILING = Bundles.bundleTypes.NODE_PROFILING;
Expand Down Expand Up @@ -49,6 +50,16 @@ ${license}
${source}`;
},

/***************** UMD_PROFILING *****************/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems more '*' than others 😄

[UMD_PROFILING](source, globalName, filename, moduleType) {
return `/** @license React v${reactVersion}
* ${filename}
*
${license}
*/
${source}`;
},

/***************** NODE_DEV *****************/
[NODE_DEV](source, globalName, filename, moduleType) {
return `/** @license React v${reactVersion}
Expand Down