diff --git a/package.json b/package.json index a23ea2c514..c805e34005 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,7 @@ "rollup-plugin-prettier": "^3.0.0", "rollup-plugin-strip-banner": "^3.0.0", "semver": "^7.1.1", + "signedsource": "^2.0.0", "targz": "^1.0.1", "through2": "^3.0.1", "tmp": "^0.1.0", diff --git a/scripts/rollup/packaging.js b/scripts/rollup/packaging.js index d9e7b42608..442ca962c7 100644 --- a/scripts/rollup/packaging.js +++ b/scripts/rollup/packaging.js @@ -7,6 +7,7 @@ const { readFileSync, writeFileSync, } = require('fs'); +const path = require('path'); const Bundles = require('./bundles'); const { asyncCopyTo, @@ -14,6 +15,7 @@ const { asyncExtractTar, asyncRimRaf, } = require('./utils'); +const {getSigningToken, signFile} = require('signedsource'); const { NODE_ES2015, @@ -134,6 +136,24 @@ async function copyRNShims() { require.resolve('react-native-renderer/src/ReactNativeTypes.js'), 'build/react-native/shims/ReactNativeTypes.js' ); + processGenerated('build/react-native/shims'); +} + +function processGenerated(directory) { + const files = readdirSync(directory) + .filter(dir => dir.endsWith('.js')) + .map(file => path.join(directory, file)); + + files.forEach(file => { + const originalContents = readFileSync(file, 'utf8'); + const contents = originalContents + // Replace {@}format with {@}noformat + .replace(/(\n\s*\*\s*)@format\b.*(\n)/, '$1@noformat$2') + // Add {@}nolint and {@}generated + .replace(' */\n', ` * @nolint\n * ${getSigningToken()}\n */\n`); + const signedContents = signFile(contents); + writeFileSync(file, signedContents, 'utf8'); + }); } async function copyAllShims() { diff --git a/scripts/rollup/wrappers.js b/scripts/rollup/wrappers.js index 237e49c912..aecb2bb139 100644 --- a/scripts/rollup/wrappers.js +++ b/scripts/rollup/wrappers.js @@ -2,6 +2,7 @@ const {resolve} = require('path'); const {readFileSync} = require('fs'); +const {signFile, getSigningToken} = require('signedsource'); const {bundleTypes, moduleTypes} = require('./bundles'); const { @@ -238,14 +239,14 @@ ${source}`; /****************** RN_OSS_DEV ******************/ [RN_OSS_DEV](source, globalName, filename, moduleType) { - return `/** + return signFile(`/** ${license} * * @noflow * @nolint * @providesModule ${globalName}-dev * @preventMunge - * ${'@gen' + 'erated'} + * ${getSigningToken()} */ 'use strict'; @@ -254,48 +255,48 @@ if (__DEV__) { (function() { ${source} })(); -}`; +}`); }, /****************** RN_OSS_PROD ******************/ [RN_OSS_PROD](source, globalName, filename, moduleType) { - return `/** + return signFile(`/** ${license} * * @noflow * @nolint * @providesModule ${globalName}-prod * @preventMunge - * ${'@gen' + 'erated'} + * ${getSigningToken()} */ -${source}`; +${source}`); }, /****************** RN_OSS_PROFILING ******************/ [RN_OSS_PROFILING](source, globalName, filename, moduleType) { - return `/** + return signFile(`/** ${license} * * @noflow * @nolint * @providesModule ${globalName}-profiling * @preventMunge - * ${'@gen' + 'erated'} + * ${getSigningToken()} */ -${source}`; +${source}`); }, /****************** RN_FB_DEV ******************/ [RN_FB_DEV](source, globalName, filename, moduleType) { - return `/** + return signFile(`/** ${license} * * @noflow * @nolint * @preventMunge - * ${'@gen' + 'erated'} + * ${getSigningToken()} */ 'use strict'; @@ -304,35 +305,35 @@ if (__DEV__) { (function() { ${source} })(); -}`; +}`); }, /****************** RN_FB_PROD ******************/ [RN_FB_PROD](source, globalName, filename, moduleType) { - return `/** + return signFile(`/** ${license} * * @noflow * @nolint * @preventMunge - * ${'@gen' + 'erated'} + * ${getSigningToken()} */ -${source}`; +${source}`); }, /****************** RN_FB_PROFILING ******************/ [RN_FB_PROFILING](source, globalName, filename, moduleType) { - return `/** + return signFile(`/** ${license} * * @noflow * @nolint * @preventMunge - * ${'@gen' + 'erated'} + * ${getSigningToken()} */ -${source}`; +${source}`); }, }; @@ -369,7 +370,7 @@ ${source} ${license} */ module.exports = function $$$reconciler($$$config) { - + var exports = {}; ${source} return exports; diff --git a/yarn.lock b/yarn.lock index 3c8628af7f..7b877e9139 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14872,6 +14872,11 @@ signal-exit@^3.0.7: resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9" integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ== +signedsource@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/signedsource/-/signedsource-2.0.0.tgz#f72dc0f98f5bca2763b464a555511a84a4da8eee" + integrity sha512-MscTxXbMij5JVgrW1xDiMIc+vFa0+H0+HP+rRrFjwa7ef2VAxIP/4L/E75I5H4xvyb4l1X+a9ch+6Zy5uFu7Fg== + sisteransi@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"