@samitouri / QOS-React-2 / commits / 8bc0bcabe7

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

Brian Vaughn committed Sep 13, 2018 at 17:44 UTC 8bc0bcabe7505a991e9e40a4b8ad1d3eb9b5723f
9 files changed +177 -6
packages/schedule/npm/umd/schedule-tracing.profiling.min.js new
+79
@@ -0,0 +1,79 @@
1 +/**
2 + * @license React
3 + *
4 + * Copyright (c) Facebook, Inc. and its affiliates.
5 + *
6 + * This source code is licensed under the MIT license found in the
7 + * LICENSE file in the root directory of this source tree.
8 + */
9 +
10 +'use strict';
11 +
12 +(function(global, factory) {
13 + typeof exports === 'object' && typeof module !== 'undefined'
14 + ? (module.exports = factory(require('react')))
15 + : typeof define === 'function' && define.amd // eslint-disable-line no-undef
16 + ? define(['react'], factory) // eslint-disable-line no-undef
17 + : (global.ScheduleTracing = factory(global));
18 +})(this, function(global) {
19 + function unstable_clear() {
20 + return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_clear.apply(
21 + this,
22 + arguments
23 + );
24 + }
25 +
26 + function unstable_getCurrent() {
27 + return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_getCurrent.apply(
28 + this,
29 + arguments
30 + );
31 + }
32 +
33 + function unstable_getThreadID() {
34 + return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_getThreadID.apply(
35 + this,
36 + arguments
37 + );
38 + }
39 +
40 + function unstable_subscribe() {
41 + // eslint-disable-next-line max-len
42 + return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_subscribe.apply(
43 + this,
44 + arguments
45 + );
46 + }
47 +
48 + function unstable_trace() {
49 + return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_trace.apply(
50 + this,
51 + arguments
52 + );
53 + }
54 +
55 + function unstable_unsubscribe() {
56 + // eslint-disable-next-line max-len
57 + return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_unsubscribe.apply(
58 + this,
59 + arguments
60 + );
61 + }
62 +
63 + function unstable_wrap() {
64 + return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracing.unstable_wrap.apply(
65 + this,
66 + arguments
67 + );
68 + }
69 +
70 + return Object.freeze({
71 + unstable_clear: unstable_clear,
72 + unstable_getCurrent: unstable_getCurrent,
73 + unstable_getThreadID: unstable_getThreadID,
74 + unstable_subscribe: unstable_subscribe,
75 + unstable_trace: unstable_trace,
76 + unstable_unsubscribe: unstable_unsubscribe,
77 + unstable_wrap: unstable_wrap,
78 + });
79 +});
packages/schedule/npm/umd/schedule.profiling.min.js new
+45
@@ -0,0 +1,45 @@
1 +/**
2 + * @license React
3 + *
4 + * Copyright (c) Facebook, Inc. and its affiliates.
5 + *
6 + * This source code is licensed under the MIT license found in the
7 + * LICENSE file in the root directory of this source tree.
8 + */
9 +
10 +'use strict';
11 +
12 +(function(global, factory) {
13 + typeof exports === 'object' && typeof module !== 'undefined'
14 + ? (module.exports = factory(require('react')))
15 + : typeof define === 'function' && define.amd // eslint-disable-line no-undef
16 + ? define(['react'], factory) // eslint-disable-line no-undef
17 + : (global.Schedule = factory(global));
18 +})(this, function(global) {
19 + function unstable_now() {
20 + return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Schedule.unstable_now.apply(
21 + this,
22 + arguments
23 + );
24 + }
25 +
26 + function unstable_scheduleWork() {
27 + return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Schedule.unstable_scheduleWork.apply(
28 + this,
29 + arguments
30 + );
31 + }
32 +
33 + function unstable_cancelScheduledWork() {
34 + return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Schedule.unstable_cancelScheduledWork.apply(
35 + this,
36 + arguments
37 + );
38 + }
39 +
40 + return Object.freeze({
41 + unstable_now: unstable_now,
42 + unstable_scheduleWork: unstable_scheduleWork,
43 + unstable_cancelScheduledWork: unstable_cancelScheduledWork,
44 + });
45 +});
packages/schedule/src/__tests__/ScheduleUMDBundle-test.internal.js
+9 -1
@@ -37,18 +37,26 @@ describe('Scheduling UMD bundle', () => {
37 const api = require('../../index');
38 const umdAPIDev = require('../../npm/umd/schedule.development');
39 const umdAPIProd = require('../../npm/umd/schedule.production.min');
40 + const umdAPIProfiling = require('../../npm/umd/schedule.profiling.min');
41 const secretAPI = require('react/src/ReactSharedInternals').default;
41 - validateForwardedAPIs(api, [umdAPIDev, umdAPIProd, secretAPI.Schedule]);
42 + validateForwardedAPIs(api, [
43 + umdAPIDev,
44 + umdAPIProd,
45 + umdAPIProfiling,
46 + secretAPI.Schedule,
47 + ]);
48 });
49
50 it('should define the same tracing API', () => {
51 const api = require('../../tracing');
52 const umdAPIDev = require('../../npm/umd/schedule-tracing.development');
53 const umdAPIProd = require('../../npm/umd/schedule-tracing.production.min');
54 + const umdAPIProfiling = require('../../npm/umd/schedule-tracing.profiling.min');
55 const secretAPI = require('react/src/ReactSharedInternals').default;
56 validateForwardedAPIs(api, [
57 umdAPIDev,
58 umdAPIProd,
59 + umdAPIProfiling,
60 secretAPI.ScheduleTracing,
61 ]);
62 });
scripts/rollup/build.js
+15 -2
@@ -38,6 +38,7 @@ process.on('unhandledRejection', err => {
38 const {
39 UMD_DEV,
40 UMD_PROD,
41 + UMD_PROFILING,
42 NODE_DEV,
43 NODE_PROD,
44 NODE_PROFILING,
@@ -113,6 +114,7 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
114 });
115 case UMD_DEV:
116 case UMD_PROD:
117 + case UMD_PROFILING:
118 case NODE_DEV:
119 case NODE_PROD:
120 case NODE_PROFILING:
@@ -158,6 +160,7 @@ function getFormat(bundleType) {
160 switch (bundleType) {
161 case UMD_DEV:
162 case UMD_PROD:
163 + case UMD_PROFILING:
164 return `umd`;
165 case NODE_DEV:
166 case NODE_PROD:
@@ -183,6 +186,8 @@ function getFilename(name, globalName, bundleType) {
186 return `${name}.development.js`;
187 case UMD_PROD:
188 return `${name}.production.min.js`;
189 + case UMD_PROFILING:
190 + return `${name}.profiling.min.js`;
191 case NODE_DEV:
192 return `${name}.development.js`;
193 case NODE_PROD:
@@ -214,6 +219,7 @@ function isProductionBundleType(bundleType) {
219 return false;
220 case UMD_PROD:
221 case NODE_PROD:
222 + case UMD_PROFILING:
223 case NODE_PROFILING:
224 case FB_WWW_PROD:
225 case FB_WWW_PROFILING:
@@ -244,6 +250,7 @@ function isProfilingBundleType(bundleType) {
250 case NODE_PROFILING:
251 case RN_FB_PROFILING:
252 case RN_OSS_PROFILING:
253 + case UMD_PROFILING:
254 return true;
255 default:
256 throw new Error(`Unknown type: ${bundleType}`);
@@ -280,7 +287,10 @@ function getPlugins(
287 const forks = Modules.getForks(bundleType, entry, moduleType);
288 const isProduction = isProductionBundleType(bundleType);
289 const isProfiling = isProfilingBundleType(bundleType);
283 - const isUMDBundle = bundleType === UMD_DEV || bundleType === UMD_PROD;
290 + const isUMDBundle =
291 + bundleType === UMD_DEV ||
292 + bundleType === UMD_PROD ||
293 + bundleType === UMD_PROFILING;
294 const isFBBundle =
295 bundleType === FB_WWW_DEV ||
296 bundleType === FB_WWW_PROD ||
@@ -430,7 +440,9 @@ async function createBundle(bundle, bundleType) {
440 }
441
442 const shouldBundleDependencies =
433 - bundleType === UMD_DEV || bundleType === UMD_PROD;
443 + bundleType === UMD_DEV ||
444 + bundleType === UMD_PROD ||
445 + bundleType === UMD_PROFILING;
446 const peerGlobals = Modules.getPeerGlobals(bundle.externals, bundleType);
447 let externals = Object.keys(peerGlobals);
448 if (!shouldBundleDependencies) {
@@ -580,6 +592,7 @@ async function buildEverything() {
592 for (const bundle of Bundles.bundles) {
593 await createBundle(bundle, UMD_DEV);
594 await createBundle(bundle, UMD_PROD);
595 + await createBundle(bundle, UMD_PROFILING);
596 await createBundle(bundle, NODE_DEV);
597 await createBundle(bundle, NODE_PROD);
598 await createBundle(bundle, NODE_PROFILING);
scripts/rollup/bundles.js
+4 -1
@@ -3,6 +3,7 @@
3 const bundleTypes = {
4 UMD_DEV: 'UMD_DEV',
5 UMD_PROD: 'UMD_PROD',
6 + UMD_PROFILING: 'UMD_PROFILING',
7 NODE_DEV: 'NODE_DEV',
8 NODE_PROD: 'NODE_PROD',
9 NODE_PROFILING: 'NODE_PROFILING',
@@ -19,6 +20,7 @@ const bundleTypes = {
20
21 const UMD_DEV = bundleTypes.UMD_DEV;
22 const UMD_PROD = bundleTypes.UMD_PROD;
23 +const UMD_PROFILING = bundleTypes.UMD_PROFILING;
24 const NODE_DEV = bundleTypes.NODE_DEV;
25 const NODE_PROD = bundleTypes.NODE_PROD;
26 const NODE_PROFILING = bundleTypes.NODE_PROFILING;
@@ -58,9 +60,9 @@ const bundles = [
60 bundleTypes: [
61 UMD_DEV,
62 UMD_PROD,
63 + UMD_PROFILING,
64 NODE_DEV,
65 NODE_PROD,
63 - NODE_PROFILING,
66 FB_WWW_DEV,
67 FB_WWW_PROD,
68 FB_WWW_PROFILING,
@@ -77,6 +79,7 @@ const bundles = [
79 bundleTypes: [
80 UMD_DEV,
81 UMD_PROD,
82 + UMD_PROFILING,
83 NODE_DEV,
84 NODE_PROD,
85 NODE_PROFILING,
scripts/rollup/forks.js
+8 -1
@@ -6,6 +6,7 @@ const inlinedHostConfigs = require('../shared/inlinedHostConfigs');
6
7 const UMD_DEV = bundleTypes.UMD_DEV;
8 const UMD_PROD = bundleTypes.UMD_PROD;
9 +const UMD_PROFILING = bundleTypes.UMD_PROFILING;
10 const FB_WWW_DEV = bundleTypes.FB_WWW_DEV;
11 const FB_WWW_PROD = bundleTypes.FB_WWW_PROD;
12 const FB_WWW_PROFILING = bundleTypes.FB_WWW_PROFILING;
@@ -24,7 +25,11 @@ const forks = Object.freeze({
25 // Optimization: for UMDs, use object-assign polyfill that is already a part
26 // of the React package instead of bundling it again.
27 'object-assign': (bundleType, entry, dependencies) => {
27 - if (bundleType !== UMD_DEV && bundleType !== UMD_PROD) {
28 + if (
29 + bundleType !== UMD_DEV &&
30 + bundleType !== UMD_PROD &&
31 + bundleType !== UMD_PROFILING
32 + ) {
33 // It's only relevant for UMD bundles since that's where the duplication
34 // happens. Other bundles just require('object-assign') anyway.
35 return null;
@@ -118,6 +123,7 @@ const forks = Object.freeze({
123 switch (bundleType) {
124 case UMD_DEV:
125 case UMD_PROD:
126 + case UMD_PROFILING:
127 if (dependencies.indexOf('react') === -1) {
128 // It's only safe to use this fork for modules that depend on React,
129 // because they read the re-exported API from the SECRET_INTERNALS object.
@@ -136,6 +142,7 @@ const forks = Object.freeze({
142 switch (bundleType) {
143 case UMD_DEV:
144 case UMD_PROD:
145 + case UMD_PROFILING:
146 if (dependencies.indexOf('react') === -1) {
147 // It's only safe to use this fork for modules that depend on React,
148 // because they read the re-exported API from the SECRET_INTERNALS object.
scripts/rollup/modules.js
+4 -1
@@ -5,6 +5,7 @@ const bundleTypes = require('./bundles').bundleTypes;
5
6 const UMD_DEV = bundleTypes.UMD_DEV;
7 const UMD_PROD = bundleTypes.UMD_PROD;
8 +const UMD_PROFILING = bundleTypes.UMD_PROFILING;
9
10 // For any external that is used in a DEV-only condition, explicitly
11 // specify whether it has side effects during import or not. This lets
@@ -32,7 +33,9 @@ function getPeerGlobals(externals, bundleType) {
33 externals.forEach(name => {
34 if (
35 !knownGlobals[name] &&
35 - (bundleType === UMD_DEV || bundleType === UMD_PROD)
36 + (bundleType === UMD_DEV ||
37 + bundleType === UMD_PROD ||
38 + bundleType === UMD_PROFILING)
39 ) {
40 throw new Error('Cannot build UMD without a global name for: ' + name);
41 }
scripts/rollup/packaging.js
+2
@@ -12,6 +12,7 @@ const {
12 const {
13 UMD_DEV,
14 UMD_PROD,
15 + UMD_PROFILING,
16 NODE_DEV,
17 NODE_PROD,
18 NODE_PROFILING,
@@ -41,6 +42,7 @@ function getBundleOutputPaths(bundleType, filename, packageName) {
42 return [`build/node_modules/${packageName}/cjs/${filename}`];
43 case UMD_DEV:
44 case UMD_PROD:
45 + case UMD_PROFILING:
46 return [
47 `build/node_modules/${packageName}/umd/${filename}`,
48 `build/dist/${filename}`,
scripts/rollup/wrappers.js
+11
@@ -5,6 +5,7 @@ const reactVersion = require('../../package.json').version;
5
6 const UMD_DEV = Bundles.bundleTypes.UMD_DEV;
7 const UMD_PROD = Bundles.bundleTypes.UMD_PROD;
8 +const UMD_PROFILING = Bundles.bundleTypes.UMD_PROFILING;
9 const NODE_DEV = Bundles.bundleTypes.NODE_DEV;
10 const NODE_PROD = Bundles.bundleTypes.NODE_PROD;
11 const NODE_PROFILING = Bundles.bundleTypes.NODE_PROFILING;
@@ -49,6 +50,16 @@ ${license}
50 ${source}`;
51 },
52
53 + /***************** UMD_PROFILING *****************/
54 + [UMD_PROFILING](source, globalName, filename, moduleType) {
55 + return `/** @license React v${reactVersion}
56 + * ${filename}
57 + *
58 +${license}
59 + */
60 +${source}`;
61 + },
62 +
63 /***************** NODE_DEV *****************/
64 [NODE_DEV](source, globalName, filename, moduleType) {
65 return `/** @license React v${reactVersion}