Skip to content

Commit

Permalink
Add @noflow @NOLINT @noformat and @generated directives to React Nati…
Browse files Browse the repository at this point in the history
…ve shims
  • Loading branch information
rubennorte committed Apr 13, 2023
1 parent 7b0642b commit ae56fe4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 21 additions & 1 deletion scripts/rollup/packaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ const {
readFileSync,
writeFileSync,
} = require('fs');
const path = require('path');
const Bundles = require('./bundles');
const {
asyncCopyTo,
asyncExecuteCommand,
asyncExtractTar,
asyncRimRaf,
} = require('./utils');
const {getSigningToken, signFile} = require('signedsource');

const {
NODE_ES2015,
Expand Down Expand Up @@ -133,7 +135,25 @@ async function copyRNShims() {
await asyncCopyTo(
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));

for (const file of files) {
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() {
Expand Down
39 changes: 20 additions & 19 deletions scripts/rollup/wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const {resolve} = require('path');
const {readFileSync} = require('fs');
const {signFile, getSigningToken} = require('signedsource');
const {bundleTypes, moduleTypes} = require('./bundles');

const {
Expand Down Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -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}`);
},
};

Expand Down Expand Up @@ -369,7 +370,7 @@ ${source}
${license}
*/
module.exports = function $$$reconciler($$$config) {
var exports = {};
${source}
return exports;
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ae56fe4

Please sign in to comment.