Skip to content

Commit 8bc0bca

Browse files
authored
Add UMD production+profiling entry points (facebook#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
1 parent b488a5d commit 8bc0bca

File tree

9 files changed

+177
-6
lines changed

9 files changed

+177
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -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+
});
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,26 @@ describe('Scheduling UMD bundle', () => {
3737
const api = require('../../index');
3838
const umdAPIDev = require('../../npm/umd/schedule.development');
3939
const umdAPIProd = require('../../npm/umd/schedule.production.min');
40+
const umdAPIProfiling = require('../../npm/umd/schedule.profiling.min');
4041
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+
]);
4248
});
4349

4450
it('should define the same tracing API', () => {
4551
const api = require('../../tracing');
4652
const umdAPIDev = require('../../npm/umd/schedule-tracing.development');
4753
const umdAPIProd = require('../../npm/umd/schedule-tracing.production.min');
54+
const umdAPIProfiling = require('../../npm/umd/schedule-tracing.profiling.min');
4855
const secretAPI = require('react/src/ReactSharedInternals').default;
4956
validateForwardedAPIs(api, [
5057
umdAPIDev,
5158
umdAPIProd,
59+
umdAPIProfiling,
5260
secretAPI.ScheduleTracing,
5361
]);
5462
});

scripts/rollup/build.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ process.on('unhandledRejection', err => {
3838
const {
3939
UMD_DEV,
4040
UMD_PROD,
41+
UMD_PROFILING,
4142
NODE_DEV,
4243
NODE_PROD,
4344
NODE_PROFILING,
@@ -113,6 +114,7 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
113114
});
114115
case UMD_DEV:
115116
case UMD_PROD:
117+
case UMD_PROFILING:
116118
case NODE_DEV:
117119
case NODE_PROD:
118120
case NODE_PROFILING:
@@ -158,6 +160,7 @@ function getFormat(bundleType) {
158160
switch (bundleType) {
159161
case UMD_DEV:
160162
case UMD_PROD:
163+
case UMD_PROFILING:
161164
return `umd`;
162165
case NODE_DEV:
163166
case NODE_PROD:
@@ -183,6 +186,8 @@ function getFilename(name, globalName, bundleType) {
183186
return `${name}.development.js`;
184187
case UMD_PROD:
185188
return `${name}.production.min.js`;
189+
case UMD_PROFILING:
190+
return `${name}.profiling.min.js`;
186191
case NODE_DEV:
187192
return `${name}.development.js`;
188193
case NODE_PROD:
@@ -214,6 +219,7 @@ function isProductionBundleType(bundleType) {
214219
return false;
215220
case UMD_PROD:
216221
case NODE_PROD:
222+
case UMD_PROFILING:
217223
case NODE_PROFILING:
218224
case FB_WWW_PROD:
219225
case FB_WWW_PROFILING:
@@ -244,6 +250,7 @@ function isProfilingBundleType(bundleType) {
244250
case NODE_PROFILING:
245251
case RN_FB_PROFILING:
246252
case RN_OSS_PROFILING:
253+
case UMD_PROFILING:
247254
return true;
248255
default:
249256
throw new Error(`Unknown type: ${bundleType}`);
@@ -280,7 +287,10 @@ function getPlugins(
280287
const forks = Modules.getForks(bundleType, entry, moduleType);
281288
const isProduction = isProductionBundleType(bundleType);
282289
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;
284294
const isFBBundle =
285295
bundleType === FB_WWW_DEV ||
286296
bundleType === FB_WWW_PROD ||
@@ -430,7 +440,9 @@ async function createBundle(bundle, bundleType) {
430440
}
431441

432442
const shouldBundleDependencies =
433-
bundleType === UMD_DEV || bundleType === UMD_PROD;
443+
bundleType === UMD_DEV ||
444+
bundleType === UMD_PROD ||
445+
bundleType === UMD_PROFILING;
434446
const peerGlobals = Modules.getPeerGlobals(bundle.externals, bundleType);
435447
let externals = Object.keys(peerGlobals);
436448
if (!shouldBundleDependencies) {
@@ -580,6 +592,7 @@ async function buildEverything() {
580592
for (const bundle of Bundles.bundles) {
581593
await createBundle(bundle, UMD_DEV);
582594
await createBundle(bundle, UMD_PROD);
595+
await createBundle(bundle, UMD_PROFILING);
583596
await createBundle(bundle, NODE_DEV);
584597
await createBundle(bundle, NODE_PROD);
585598
await createBundle(bundle, NODE_PROFILING);

scripts/rollup/bundles.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const bundleTypes = {
44
UMD_DEV: 'UMD_DEV',
55
UMD_PROD: 'UMD_PROD',
6+
UMD_PROFILING: 'UMD_PROFILING',
67
NODE_DEV: 'NODE_DEV',
78
NODE_PROD: 'NODE_PROD',
89
NODE_PROFILING: 'NODE_PROFILING',
@@ -19,6 +20,7 @@ const bundleTypes = {
1920

2021
const UMD_DEV = bundleTypes.UMD_DEV;
2122
const UMD_PROD = bundleTypes.UMD_PROD;
23+
const UMD_PROFILING = bundleTypes.UMD_PROFILING;
2224
const NODE_DEV = bundleTypes.NODE_DEV;
2325
const NODE_PROD = bundleTypes.NODE_PROD;
2426
const NODE_PROFILING = bundleTypes.NODE_PROFILING;
@@ -58,9 +60,9 @@ const bundles = [
5860
bundleTypes: [
5961
UMD_DEV,
6062
UMD_PROD,
63+
UMD_PROFILING,
6164
NODE_DEV,
6265
NODE_PROD,
63-
NODE_PROFILING,
6466
FB_WWW_DEV,
6567
FB_WWW_PROD,
6668
FB_WWW_PROFILING,
@@ -77,6 +79,7 @@ const bundles = [
7779
bundleTypes: [
7880
UMD_DEV,
7981
UMD_PROD,
82+
UMD_PROFILING,
8083
NODE_DEV,
8184
NODE_PROD,
8285
NODE_PROFILING,

scripts/rollup/forks.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const inlinedHostConfigs = require('../shared/inlinedHostConfigs');
66

77
const UMD_DEV = bundleTypes.UMD_DEV;
88
const UMD_PROD = bundleTypes.UMD_PROD;
9+
const UMD_PROFILING = bundleTypes.UMD_PROFILING;
910
const FB_WWW_DEV = bundleTypes.FB_WWW_DEV;
1011
const FB_WWW_PROD = bundleTypes.FB_WWW_PROD;
1112
const FB_WWW_PROFILING = bundleTypes.FB_WWW_PROFILING;
@@ -24,7 +25,11 @@ const forks = Object.freeze({
2425
// Optimization: for UMDs, use object-assign polyfill that is already a part
2526
// of the React package instead of bundling it again.
2627
'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+
) {
2833
// It's only relevant for UMD bundles since that's where the duplication
2934
// happens. Other bundles just require('object-assign') anyway.
3035
return null;
@@ -118,6 +123,7 @@ const forks = Object.freeze({
118123
switch (bundleType) {
119124
case UMD_DEV:
120125
case UMD_PROD:
126+
case UMD_PROFILING:
121127
if (dependencies.indexOf('react') === -1) {
122128
// It's only safe to use this fork for modules that depend on React,
123129
// because they read the re-exported API from the SECRET_INTERNALS object.
@@ -136,6 +142,7 @@ const forks = Object.freeze({
136142
switch (bundleType) {
137143
case UMD_DEV:
138144
case UMD_PROD:
145+
case UMD_PROFILING:
139146
if (dependencies.indexOf('react') === -1) {
140147
// It's only safe to use this fork for modules that depend on React,
141148
// because they read the re-exported API from the SECRET_INTERNALS object.

scripts/rollup/modules.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const bundleTypes = require('./bundles').bundleTypes;
55

66
const UMD_DEV = bundleTypes.UMD_DEV;
77
const UMD_PROD = bundleTypes.UMD_PROD;
8+
const UMD_PROFILING = bundleTypes.UMD_PROFILING;
89

910
// For any external that is used in a DEV-only condition, explicitly
1011
// specify whether it has side effects during import or not. This lets
@@ -32,7 +33,9 @@ function getPeerGlobals(externals, bundleType) {
3233
externals.forEach(name => {
3334
if (
3435
!knownGlobals[name] &&
35-
(bundleType === UMD_DEV || bundleType === UMD_PROD)
36+
(bundleType === UMD_DEV ||
37+
bundleType === UMD_PROD ||
38+
bundleType === UMD_PROFILING)
3639
) {
3740
throw new Error('Cannot build UMD without a global name for: ' + name);
3841
}

scripts/rollup/packaging.js

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
const {
1313
UMD_DEV,
1414
UMD_PROD,
15+
UMD_PROFILING,
1516
NODE_DEV,
1617
NODE_PROD,
1718
NODE_PROFILING,
@@ -41,6 +42,7 @@ function getBundleOutputPaths(bundleType, filename, packageName) {
4142
return [`build/node_modules/${packageName}/cjs/${filename}`];
4243
case UMD_DEV:
4344
case UMD_PROD:
45+
case UMD_PROFILING:
4446
return [
4547
`build/node_modules/${packageName}/umd/${filename}`,
4648
`build/dist/${filename}`,

scripts/rollup/wrappers.js

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const reactVersion = require('../../package.json').version;
55

66
const UMD_DEV = Bundles.bundleTypes.UMD_DEV;
77
const UMD_PROD = Bundles.bundleTypes.UMD_PROD;
8+
const UMD_PROFILING = Bundles.bundleTypes.UMD_PROFILING;
89
const NODE_DEV = Bundles.bundleTypes.NODE_DEV;
910
const NODE_PROD = Bundles.bundleTypes.NODE_PROD;
1011
const NODE_PROFILING = Bundles.bundleTypes.NODE_PROFILING;
@@ -49,6 +50,16 @@ ${license}
4950
${source}`;
5051
},
5152

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+
5263
/***************** NODE_DEV *****************/
5364
[NODE_DEV](source, globalName, filename, moduleType) {
5465
return `/** @license React v${reactVersion}

0 commit comments

Comments
 (0)