Skip to content

Commit

Permalink
Add UMD production+profiling entry points (facebook#13642)
Browse files Browse the repository at this point in the history
* Added UMD_PROFILING type to react-dom and scheduling package. Added UMD shim to schedule package.
* Added new schedule umd prod+prof bundle to API test
  • Loading branch information
bvaughn authored and jetoneza committed Jan 23, 2019
1 parent 177dfd4 commit 4a98c98
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 6 deletions.
79 changes: 79 additions & 0 deletions packages/schedule/npm/umd/schedule-tracing.profiling.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* @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.ScheduleTracing = factory(global));
})(this, function(global) {
function unstable_clear() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_clear.apply(
this,
arguments
);
}

function unstable_getCurrent() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_getCurrent.apply(
this,
arguments
);
}

function unstable_getThreadID() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_getThreadID.apply(
this,
arguments
);
}

function unstable_subscribe() {
// eslint-disable-next-line max-len
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_subscribe.apply(
this,
arguments
);
}

function unstable_trace() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_trace.apply(
this,
arguments
);
}

function unstable_unsubscribe() {
// eslint-disable-next-line max-len
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_unsubscribe.apply(
this,
arguments
);
}

function unstable_wrap() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_wrap.apply(
this,
arguments
);
}

return Object.freeze({
unstable_clear: unstable_clear,
unstable_getCurrent: unstable_getCurrent,
unstable_getThreadID: unstable_getThreadID,
unstable_subscribe: unstable_subscribe,
unstable_trace: unstable_trace,
unstable_unsubscribe: unstable_unsubscribe,
unstable_wrap: unstable_wrap,
});
});
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,
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,26 @@ describe('Scheduling UMD bundle', () => {
const api = require('../../index');
const umdAPIDev = require('../../npm/umd/schedule.development');
const umdAPIProd = require('../../npm/umd/schedule.production.min');
const umdAPIProfiling = require('../../npm/umd/schedule.profiling.min');
const secretAPI = require('react/src/ReactSharedInternals').default;
validateForwardedAPIs(api, [umdAPIDev, umdAPIProd, secretAPI.Schedule]);
validateForwardedAPIs(api, [
umdAPIDev,
umdAPIProd,
umdAPIProfiling,
secretAPI.Schedule,
]);
});

it('should define the same tracing API', () => {
const api = require('../../tracing');
const umdAPIDev = require('../../npm/umd/schedule-tracing.development');
const umdAPIProd = require('../../npm/umd/schedule-tracing.production.min');
const umdAPIProfiling = require('../../npm/umd/schedule-tracing.profiling.min');
const secretAPI = require('react/src/ReactSharedInternals').default;
validateForwardedAPIs(api, [
umdAPIDev,
umdAPIProd,
umdAPIProfiling,
secretAPI.ScheduleTracing,
]);
});
Expand Down
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 *****************/
[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

0 comments on commit 4a98c98

Please sign in to comment.