mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
Add UMD production+profiling entry points (#13642)
* 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
This commit is contained in:
79
packages/schedule/npm/umd/schedule-tracing.profiling.min.js
vendored
Normal file
79
packages/schedule/npm/umd/schedule-tracing.profiling.min.js
vendored
Normal file
@@ -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
packages/schedule/npm/umd/schedule.profiling.min.js
vendored
Normal file
45
packages/schedule/npm/umd/schedule.profiling.min.js
vendored
Normal file
@@ -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,
|
||||
});
|
||||
});
|
||||
@@ -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,
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -38,6 +38,7 @@ process.on('unhandledRejection', err => {
|
||||
const {
|
||||
UMD_DEV,
|
||||
UMD_PROD,
|
||||
UMD_PROFILING,
|
||||
NODE_DEV,
|
||||
NODE_PROD,
|
||||
NODE_PROFILING,
|
||||
@@ -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:
|
||||
@@ -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:
|
||||
@@ -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:
|
||||
@@ -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:
|
||||
@@ -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}`);
|
||||
@@ -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 ||
|
||||
@@ -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) {
|
||||
@@ -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);
|
||||
|
||||
@@ -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',
|
||||
@@ -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;
|
||||
@@ -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,
|
||||
@@ -77,6 +79,7 @@ const bundles = [
|
||||
bundleTypes: [
|
||||
UMD_DEV,
|
||||
UMD_PROD,
|
||||
UMD_PROFILING,
|
||||
NODE_DEV,
|
||||
NODE_PROD,
|
||||
NODE_PROFILING,
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ const {
|
||||
const {
|
||||
UMD_DEV,
|
||||
UMD_PROD,
|
||||
UMD_PROFILING,
|
||||
NODE_DEV,
|
||||
NODE_PROD,
|
||||
NODE_PROFILING,
|
||||
@@ -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}`,
|
||||
|
||||
@@ -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;
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user