2017-11-09 06:37:11 +08:00
|
|
|
'use strict';
|
|
|
|
|
2021-10-22 02:40:41 +08:00
|
|
|
const {resolve} = require('path');
|
|
|
|
const {readFileSync} = require('fs');
|
2020-02-04 07:31:31 +08:00
|
|
|
const {bundleTypes, moduleTypes} = require('./bundles');
|
2017-11-09 06:37:11 +08:00
|
|
|
const reactVersion = require('../../package.json').version;
|
|
|
|
|
2020-02-04 07:31:31 +08:00
|
|
|
const {
|
2020-05-29 06:56:34 +08:00
|
|
|
NODE_ES2015,
|
2020-11-13 21:57:45 +08:00
|
|
|
NODE_ESM,
|
2020-02-04 07:31:31 +08:00
|
|
|
UMD_DEV,
|
|
|
|
UMD_PROD,
|
|
|
|
UMD_PROFILING,
|
|
|
|
NODE_DEV,
|
|
|
|
NODE_PROD,
|
|
|
|
NODE_PROFILING,
|
|
|
|
FB_WWW_DEV,
|
|
|
|
FB_WWW_PROD,
|
|
|
|
FB_WWW_PROFILING,
|
|
|
|
RN_OSS_DEV,
|
|
|
|
RN_OSS_PROD,
|
|
|
|
RN_OSS_PROFILING,
|
|
|
|
RN_FB_DEV,
|
|
|
|
RN_FB_PROD,
|
|
|
|
RN_FB_PROFILING,
|
|
|
|
} = bundleTypes;
|
2017-11-09 06:37:11 +08:00
|
|
|
|
2020-02-04 07:31:31 +08:00
|
|
|
const {RECONCILER} = moduleTypes;
|
2017-11-09 06:37:11 +08:00
|
|
|
|
2021-11-04 22:40:35 +08:00
|
|
|
const USE_STRICT_HEADER_REGEX = /'use strict';\n+/;
|
|
|
|
|
2021-10-22 02:40:41 +08:00
|
|
|
function registerInternalModuleStart(globalName) {
|
2021-11-04 22:40:35 +08:00
|
|
|
const path = resolve(__dirname, 'wrappers', 'registerInternalModuleBegin.js');
|
|
|
|
const file = readFileSync(path);
|
|
|
|
return String(file).trim();
|
2021-10-22 02:40:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function registerInternalModuleStop(globalName) {
|
2021-11-04 22:40:35 +08:00
|
|
|
const path = resolve(__dirname, 'wrappers', 'registerInternalModuleEnd.js');
|
|
|
|
const file = readFileSync(path);
|
|
|
|
|
|
|
|
// Remove the 'use strict' directive from the footer.
|
|
|
|
// This directive is only meaningful when it is the first statement in a file or function.
|
|
|
|
return String(file)
|
|
|
|
.replace(USE_STRICT_HEADER_REGEX, '')
|
|
|
|
.trim();
|
2021-10-22 02:40:41 +08:00
|
|
|
}
|
|
|
|
|
2018-09-08 06:11:23 +08:00
|
|
|
const license = ` * Copyright (c) Facebook, Inc. and its affiliates.
|
2017-11-09 06:37:11 +08:00
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.`;
|
|
|
|
|
|
|
|
const wrappers = {
|
2020-05-29 06:56:34 +08:00
|
|
|
/***************** NODE_ES2015 *****************/
|
|
|
|
[NODE_ES2015](source, globalName, filename, moduleType) {
|
|
|
|
return `/** @license React v${reactVersion}
|
|
|
|
* ${filename}
|
|
|
|
*
|
|
|
|
${license}
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2020-11-13 21:57:45 +08:00
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/***************** NODE_ESM *****************/
|
|
|
|
[NODE_ESM](source, globalName, filename, moduleType) {
|
|
|
|
return `/** @license React v${reactVersion}
|
|
|
|
* ${filename}
|
|
|
|
*
|
|
|
|
${license}
|
|
|
|
*/
|
|
|
|
|
2020-05-29 06:56:34 +08:00
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
2017-11-09 06:37:11 +08:00
|
|
|
/***************** UMD_DEV *****************/
|
|
|
|
[UMD_DEV](source, globalName, filename, moduleType) {
|
|
|
|
return `/** @license React v${reactVersion}
|
|
|
|
* ${filename}
|
|
|
|
*
|
|
|
|
${license}
|
|
|
|
*/
|
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/***************** UMD_PROD *****************/
|
|
|
|
[UMD_PROD](source, globalName, filename, moduleType) {
|
|
|
|
return `/** @license React v${reactVersion}
|
|
|
|
* ${filename}
|
|
|
|
*
|
|
|
|
${license}
|
|
|
|
*/
|
2020-08-15 21:42:49 +08:00
|
|
|
(function(){${source}})();`;
|
2017-11-09 06:37:11 +08:00
|
|
|
},
|
|
|
|
|
2018-09-14 08:44:08 +08:00
|
|
|
/***************** UMD_PROFILING *****************/
|
|
|
|
[UMD_PROFILING](source, globalName, filename, moduleType) {
|
|
|
|
return `/** @license React v${reactVersion}
|
|
|
|
* ${filename}
|
|
|
|
*
|
|
|
|
${license}
|
|
|
|
*/
|
2020-08-15 21:42:49 +08:00
|
|
|
(function(){${source}})();`;
|
2018-09-14 08:44:08 +08:00
|
|
|
},
|
|
|
|
|
2017-11-09 06:37:11 +08:00
|
|
|
/***************** NODE_DEV *****************/
|
|
|
|
[NODE_DEV](source, globalName, filename, moduleType) {
|
|
|
|
return `/** @license React v${reactVersion}
|
|
|
|
* ${filename}
|
|
|
|
*
|
|
|
|
${license}
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== "production") {
|
|
|
|
(function() {
|
|
|
|
${source}
|
|
|
|
})();
|
|
|
|
}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/***************** NODE_PROD *****************/
|
|
|
|
[NODE_PROD](source, globalName, filename, moduleType) {
|
|
|
|
return `/** @license React v${reactVersion}
|
|
|
|
* ${filename}
|
|
|
|
*
|
|
|
|
${license}
|
|
|
|
*/
|
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
2018-06-12 04:16:27 +08:00
|
|
|
/***************** NODE_PROFILING *****************/
|
|
|
|
[NODE_PROFILING](source, globalName, filename, moduleType) {
|
|
|
|
return `/** @license React v${reactVersion}
|
|
|
|
* ${filename}
|
|
|
|
*
|
|
|
|
${license}
|
|
|
|
*/
|
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
2018-04-19 04:16:50 +08:00
|
|
|
/****************** FB_WWW_DEV ******************/
|
|
|
|
[FB_WWW_DEV](source, globalName, filename, moduleType) {
|
2017-11-09 06:37:11 +08:00
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2017-11-09 06:37:11 +08:00
|
|
|
* @preventMunge
|
2018-04-10 01:57:52 +08:00
|
|
|
* @preserve-invariant-messages
|
2017-11-09 06:37:11 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
if (__DEV__) {
|
|
|
|
(function() {
|
|
|
|
${source}
|
|
|
|
})();
|
|
|
|
}`;
|
|
|
|
},
|
|
|
|
|
2018-04-19 04:16:50 +08:00
|
|
|
/****************** FB_WWW_PROD ******************/
|
|
|
|
[FB_WWW_PROD](source, globalName, filename, moduleType) {
|
2017-11-09 06:37:11 +08:00
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2017-11-09 06:37:11 +08:00
|
|
|
* @preventMunge
|
2018-04-10 01:57:52 +08:00
|
|
|
* @preserve-invariant-messages
|
2017-11-09 06:37:11 +08:00
|
|
|
*/
|
|
|
|
|
2018-06-27 04:28:41 +08:00
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/****************** FB_WWW_PROFILING ******************/
|
|
|
|
[FB_WWW_PROFILING](source, globalName, filename, moduleType) {
|
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2018-06-27 04:28:41 +08:00
|
|
|
* @preventMunge
|
|
|
|
* @preserve-invariant-messages
|
|
|
|
*/
|
|
|
|
|
2017-11-09 06:37:11 +08:00
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
2018-04-19 04:16:50 +08:00
|
|
|
/****************** RN_OSS_DEV ******************/
|
|
|
|
[RN_OSS_DEV](source, globalName, filename, moduleType) {
|
2017-11-09 06:37:11 +08:00
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2017-11-09 06:37:11 +08:00
|
|
|
* @providesModule ${globalName}-dev
|
|
|
|
* @preventMunge
|
2018-05-15 01:39:30 +08:00
|
|
|
* ${'@gen' + 'erated'}
|
2017-11-09 06:37:11 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
if (__DEV__) {
|
|
|
|
(function() {
|
|
|
|
${source}
|
|
|
|
})();
|
|
|
|
}`;
|
|
|
|
},
|
|
|
|
|
2018-04-19 04:16:50 +08:00
|
|
|
/****************** RN_OSS_PROD ******************/
|
|
|
|
[RN_OSS_PROD](source, globalName, filename, moduleType) {
|
2017-11-09 06:37:11 +08:00
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2017-11-09 06:37:11 +08:00
|
|
|
* @providesModule ${globalName}-prod
|
|
|
|
* @preventMunge
|
2018-05-15 01:39:30 +08:00
|
|
|
* ${'@gen' + 'erated'}
|
2017-11-09 06:37:11 +08:00
|
|
|
*/
|
|
|
|
|
2018-06-12 04:16:27 +08:00
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/****************** RN_OSS_PROFILING ******************/
|
|
|
|
[RN_OSS_PROFILING](source, globalName, filename, moduleType) {
|
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2018-06-12 04:16:27 +08:00
|
|
|
* @providesModule ${globalName}-profiling
|
|
|
|
* @preventMunge
|
|
|
|
* ${'@gen' + 'erated'}
|
|
|
|
*/
|
|
|
|
|
2018-04-19 04:16:50 +08:00
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/****************** RN_FB_DEV ******************/
|
|
|
|
[RN_FB_DEV](source, globalName, filename, moduleType) {
|
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2018-04-19 04:16:50 +08:00
|
|
|
* @preventMunge
|
2018-05-15 01:39:30 +08:00
|
|
|
* ${'@gen' + 'erated'}
|
2018-04-19 04:16:50 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
if (__DEV__) {
|
|
|
|
(function() {
|
|
|
|
${source}
|
|
|
|
})();
|
|
|
|
}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/****************** RN_FB_PROD ******************/
|
|
|
|
[RN_FB_PROD](source, globalName, filename, moduleType) {
|
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2018-04-19 04:16:50 +08:00
|
|
|
* @preventMunge
|
2018-05-15 01:39:30 +08:00
|
|
|
* ${'@gen' + 'erated'}
|
2018-04-19 04:16:50 +08:00
|
|
|
*/
|
|
|
|
|
2018-06-27 04:28:41 +08:00
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/****************** RN_FB_PROFILING ******************/
|
|
|
|
[RN_FB_PROFILING](source, globalName, filename, moduleType) {
|
|
|
|
return `/**
|
|
|
|
${license}
|
|
|
|
*
|
|
|
|
* @noflow
|
2020-02-25 22:45:31 +08:00
|
|
|
* @nolint
|
2018-06-27 04:28:41 +08:00
|
|
|
* @preventMunge
|
|
|
|
* ${'@gen' + 'erated'}
|
|
|
|
*/
|
|
|
|
|
2017-11-09 06:37:11 +08:00
|
|
|
${source}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const reconcilerWrappers = {
|
|
|
|
/***************** NODE_DEV (reconciler only) *****************/
|
|
|
|
[NODE_DEV](source, globalName, filename, moduleType) {
|
|
|
|
return `/** @license React v${reactVersion}
|
|
|
|
* ${filename}
|
|
|
|
*
|
|
|
|
${license}
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== "production") {
|
2018-05-19 18:29:11 +08:00
|
|
|
module.exports = function $$$reconciler($$$hostConfig) {
|
2020-02-28 09:18:55 +08:00
|
|
|
var exports = {};
|
2017-11-09 06:37:11 +08:00
|
|
|
${source}
|
2020-02-28 09:18:55 +08:00
|
|
|
return exports;
|
2017-11-09 06:37:11 +08:00
|
|
|
};
|
|
|
|
}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/***************** NODE_PROD (reconciler only) *****************/
|
|
|
|
[NODE_PROD](source, globalName, filename, moduleType) {
|
|
|
|
return `/** @license React v${reactVersion}
|
|
|
|
* ${filename}
|
|
|
|
*
|
|
|
|
${license}
|
|
|
|
*/
|
2018-05-19 18:29:11 +08:00
|
|
|
module.exports = function $$$reconciler($$$hostConfig) {
|
2020-02-28 09:18:55 +08:00
|
|
|
var exports = {};
|
2017-11-09 06:37:11 +08:00
|
|
|
${source}
|
2020-02-28 09:18:55 +08:00
|
|
|
return exports;
|
2020-08-19 21:11:27 +08:00
|
|
|
};`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/***************** NODE_PROFILING (reconciler only) *****************/
|
|
|
|
[NODE_PROFILING](source, globalName, filename, moduleType) {
|
|
|
|
return `/** @license React v${reactVersion}
|
|
|
|
* ${filename}
|
|
|
|
*
|
|
|
|
${license}
|
|
|
|
*/
|
|
|
|
module.exports = function $$$reconciler($$$hostConfig) {
|
|
|
|
var exports = {};
|
|
|
|
${source}
|
|
|
|
return exports;
|
2017-11-09 06:37:11 +08:00
|
|
|
};`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-10-22 02:40:41 +08:00
|
|
|
function wrapBundle(
|
|
|
|
source,
|
|
|
|
bundleType,
|
|
|
|
globalName,
|
|
|
|
filename,
|
|
|
|
moduleType,
|
|
|
|
wrapWithModuleBoundaries
|
|
|
|
) {
|
|
|
|
if (wrapWithModuleBoundaries) {
|
|
|
|
switch (bundleType) {
|
|
|
|
case NODE_DEV:
|
|
|
|
case NODE_PROFILING:
|
|
|
|
case FB_WWW_DEV:
|
|
|
|
case FB_WWW_PROFILING:
|
|
|
|
case RN_OSS_DEV:
|
|
|
|
case RN_OSS_PROFILING:
|
|
|
|
case RN_FB_DEV:
|
|
|
|
case RN_FB_PROFILING:
|
2021-11-04 22:40:35 +08:00
|
|
|
// Remove the 'use strict' directive from source.
|
|
|
|
// The module start wrapper will add its own.
|
|
|
|
// This directive is only meaningful when it is the first statement in a file or function.
|
|
|
|
source = source.replace(USE_STRICT_HEADER_REGEX, '');
|
|
|
|
|
2021-10-22 02:40:41 +08:00
|
|
|
// Certain DEV and Profiling bundles should self-register their own module boundaries with DevTools.
|
2021-11-04 03:10:29 +08:00
|
|
|
// This allows the Timeline to de-emphasize (dim) internal stack frames.
|
2021-10-22 02:40:41 +08:00
|
|
|
source = `
|
|
|
|
${registerInternalModuleStart(globalName)}
|
|
|
|
${source}
|
|
|
|
${registerInternalModuleStop(globalName)}
|
|
|
|
`;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-09 06:37:11 +08:00
|
|
|
if (moduleType === RECONCILER) {
|
|
|
|
// Standalone reconciler is only used by third-party renderers.
|
|
|
|
// It is handled separately.
|
|
|
|
const wrapper = reconcilerWrappers[bundleType];
|
|
|
|
if (typeof wrapper !== 'function') {
|
|
|
|
throw new Error(
|
|
|
|
`Unsupported build type for the reconciler package: ${bundleType}.`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return wrapper(source, globalName, filename, moduleType);
|
|
|
|
}
|
|
|
|
// All the other packages.
|
|
|
|
const wrapper = wrappers[bundleType];
|
|
|
|
if (typeof wrapper !== 'function') {
|
|
|
|
throw new Error(`Unsupported build type: ${bundleType}.`);
|
|
|
|
}
|
|
|
|
return wrapper(source, globalName, filename, moduleType);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
wrapBundle,
|
|
|
|
};
|