Skip to content

Commit 39a3b72

Browse files
authored
Post-process build files for React Native to add generated signature and @NOLINT (#26616)
## Summary We're enabling a new mechanism to synchronize build files from `react` to `react-native`. That new mechanism doesn't post-process files, so we need to add that post-processing somewhere. This PR does that when generating the files in the first place, so the generated files in the `build` directory are ready to be committed in the `react-native` repository directly. This makes use of `signedsource` to avoid direct modifications of these files in the `react-native` repository, as well as `@noformat` and `@nolint` to prevent unactionable CI failures in that repository. ## How did you test this change? Generated build files for `react-native` before and after this change: ``` node ./scripts/rollup/build-all-release-channels.js react-native ``` Checked new contents. Relevant changes: ```diff diff --color -r build-before/react-native/implementations/ReactFabric-dev.fb.js build-after/react-native/implementations/ReactFabric-dev.fb.js 10c10 < * @generated --- > * @generated SignedSource<<03cef14e77b8250b567dfdf3b066085e>> diff --color -r build-before/react-native/implementations/ReactFabric-dev.js build-after/react-native/implementations/ReactFabric-dev.js 11c11 < * @generated --- > * @generated SignedSource<<e39eed38a363846ca9ee9b59a225683c>> diff --color -r build-before/react-native/implementations/ReactFabric-prod.fb.js build-after/react-native/implementations/ReactFabric-prod.fb.js 10c10 < * @generated --- > * @generated SignedSource<<f65efcd6a469d5f6fef1ce647e5ec09a>> diff --color -r build-before/react-native/implementations/ReactFabric-prod.js build-after/react-native/implementations/ReactFabric-prod.js 11c11 < * @generated --- > * @generated SignedSource<<cdd582aa889b1054b2c5faf412622b18>> diff --color -r build-before/react-native/implementations/ReactFabric-profiling.fb.js build-after/react-native/implementations/ReactFabric-profiling.fb.js 10c10 < * @generated --- > * @generated SignedSource<<81e74849b24f104882bd298f062be0fa>> diff --color -r build-before/react-native/implementations/ReactFabric-profiling.js build-after/react-native/implementations/ReactFabric-profiling.js 11c11 < * @generated --- > * @generated SignedSource<<c050b7fa1453dc21ac1c5b98146210a8>> diff --color -r build-before/react-native/implementations/ReactNativeRenderer-dev.fb.js build-after/react-native/implementations/ReactNativeRenderer-dev.fb.js 10c10 < * @generated --- > * @generated SignedSource<<9c03464b489b41c06a065aeba8619263>> diff --color -r build-before/react-native/implementations/ReactNativeRenderer-dev.js build-after/react-native/implementations/ReactNativeRenderer-dev.js 11c11 < * @generated --- > * @generated SignedSource<<18b34c037544949dcf9b28f945921ba8>> diff --color -r build-before/react-native/implementations/ReactNativeRenderer-prod.fb.js build-after/react-native/implementations/ReactNativeRenderer-prod.fb.js 10c10 < * @generated --- > * @generated SignedSource<<592e9654c584d1da523378b119bd8bd7>> diff --color -r build-before/react-native/implementations/ReactNativeRenderer-prod.js build-after/react-native/implementations/ReactNativeRenderer-prod.js 11c11 < * @generated --- > * @generated SignedSource<<91c894db99e2d76f8a32708ad6ad1bde>> diff --color -r build-before/react-native/implementations/ReactNativeRenderer-profiling.fb.js build-after/react-native/implementations/ReactNativeRenderer-profiling.fb.js 10c10 < * @generated --- > * @generated SignedSource<<5ce378a9216ea747d91b208b9fd1ebd5>> diff --color -r build-before/react-native/implementations/ReactNativeRenderer-profiling.js build-after/react-native/implementations/ReactNativeRenderer-profiling.js 11c11 < * @generated --- > * @generated SignedSource<<1c7564f446ee83142976035b2884dcfd>> diff --color -r build-before/react-native/shims/ReactFabric.js build-after/react-native/shims/ReactFabric.js 7c7 < * @Format --- > * @noformat 8a9,10 > * @NOLINT > * @generated SignedSource<<cece19ddbec9f287c995721f49c68977>> diff --color -r build-before/react-native/shims/ReactFeatureFlags.js build-after/react-native/shims/ReactFeatureFlags.js 7c7 < * @Format --- > * @noformat 8a9,10 > * @NOLINT > * @generated SignedSource<<2881c8e89ef0f73f4cf6612cb518b197>> diff --color -r build-before/react-native/shims/ReactNative.js build-after/react-native/shims/ReactNative.js 7c7 < * @Format --- > * @noformat 8a9,10 > * @NOLINT > * @generated SignedSource<<0debd6e5a17dc037cb4661315a886de6>> diff --color -r build-before/react-native/shims/ReactNativeTypes.js build-after/react-native/shims/ReactNativeTypes.js 7c7 < * @Format --- > * @noformat 8a9,10 > * @NOLINT > * @generated SignedSource<<652b117c94307244bcf5e4af18928903>> diff --color -r build-before/react-native/shims/ReactNativeViewConfigRegistry.js build-after/react-native/shims/ReactNativeViewConfigRegistry.js 7c7 < * @Format --- > * @noformat 8a9,10 > * @NOLINT > * @generated SignedSource<<ce82e8957367bee7d11379ab88e3f7c5>> diff --color -r build-before/react-native/shims/createReactNativeComponentClass.js build-after/react-native/shims/createReactNativeComponentClass.js 7c7 < * @Format --- > * @noformat 8a9,10 > * @NOLINT > * @generated SignedSource<<ede54ac2fa1b9a09e234cdf098048989>> ```
1 parent d121c67 commit 39a3b72

File tree

4 files changed

+46
-19
lines changed

4 files changed

+46
-19
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"rollup-plugin-prettier": "^3.0.0",
9494
"rollup-plugin-strip-banner": "^3.0.0",
9595
"semver": "^7.1.1",
96+
"signedsource": "^2.0.0",
9697
"targz": "^1.0.1",
9798
"through2": "^3.0.1",
9899
"tmp": "^0.1.0",

scripts/rollup/packaging.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ const {
77
readFileSync,
88
writeFileSync,
99
} = require('fs');
10+
const path = require('path');
1011
const Bundles = require('./bundles');
1112
const {
1213
asyncCopyTo,
1314
asyncExecuteCommand,
1415
asyncExtractTar,
1516
asyncRimRaf,
1617
} = require('./utils');
18+
const {getSigningToken, signFile} = require('signedsource');
1719

1820
const {
1921
NODE_ES2015,
@@ -134,6 +136,24 @@ async function copyRNShims() {
134136
require.resolve('react-native-renderer/src/ReactNativeTypes.js'),
135137
'build/react-native/shims/ReactNativeTypes.js'
136138
);
139+
processGenerated('build/react-native/shims');
140+
}
141+
142+
function processGenerated(directory) {
143+
const files = readdirSync(directory)
144+
.filter(dir => dir.endsWith('.js'))
145+
.map(file => path.join(directory, file));
146+
147+
files.forEach(file => {
148+
const originalContents = readFileSync(file, 'utf8');
149+
const contents = originalContents
150+
// Replace {@}format with {@}noformat
151+
.replace(/(\n\s*\*\s*)@format\b.*(\n)/, '$1@noformat$2')
152+
// Add {@}nolint and {@}generated
153+
.replace(' */\n', ` * @nolint\n * ${getSigningToken()}\n */\n`);
154+
const signedContents = signFile(contents);
155+
writeFileSync(file, signedContents, 'utf8');
156+
});
137157
}
138158

139159
async function copyAllShims() {

scripts/rollup/wrappers.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const {resolve} = require('path');
44
const {readFileSync} = require('fs');
5+
const {signFile, getSigningToken} = require('signedsource');
56
const {bundleTypes, moduleTypes} = require('./bundles');
67

78
const {
@@ -238,14 +239,14 @@ ${source}`;
238239

239240
/****************** RN_OSS_DEV ******************/
240241
[RN_OSS_DEV](source, globalName, filename, moduleType) {
241-
return `/**
242+
return signFile(`/**
242243
${license}
243244
*
244245
* @noflow
245246
* @nolint
246247
* @providesModule ${globalName}-dev
247248
* @preventMunge
248-
* ${'@gen' + 'erated'}
249+
* ${getSigningToken()}
249250
*/
250251
251252
'use strict';
@@ -254,48 +255,48 @@ if (__DEV__) {
254255
(function() {
255256
${source}
256257
})();
257-
}`;
258+
}`);
258259
},
259260

260261
/****************** RN_OSS_PROD ******************/
261262
[RN_OSS_PROD](source, globalName, filename, moduleType) {
262-
return `/**
263+
return signFile(`/**
263264
${license}
264265
*
265266
* @noflow
266267
* @nolint
267268
* @providesModule ${globalName}-prod
268269
* @preventMunge
269-
* ${'@gen' + 'erated'}
270+
* ${getSigningToken()}
270271
*/
271272
272-
${source}`;
273+
${source}`);
273274
},
274275

275276
/****************** RN_OSS_PROFILING ******************/
276277
[RN_OSS_PROFILING](source, globalName, filename, moduleType) {
277-
return `/**
278+
return signFile(`/**
278279
${license}
279280
*
280281
* @noflow
281282
* @nolint
282283
* @providesModule ${globalName}-profiling
283284
* @preventMunge
284-
* ${'@gen' + 'erated'}
285+
* ${getSigningToken()}
285286
*/
286287
287-
${source}`;
288+
${source}`);
288289
},
289290

290291
/****************** RN_FB_DEV ******************/
291292
[RN_FB_DEV](source, globalName, filename, moduleType) {
292-
return `/**
293+
return signFile(`/**
293294
${license}
294295
*
295296
* @noflow
296297
* @nolint
297298
* @preventMunge
298-
* ${'@gen' + 'erated'}
299+
* ${getSigningToken()}
299300
*/
300301
301302
'use strict';
@@ -304,35 +305,35 @@ if (__DEV__) {
304305
(function() {
305306
${source}
306307
})();
307-
}`;
308+
}`);
308309
},
309310

310311
/****************** RN_FB_PROD ******************/
311312
[RN_FB_PROD](source, globalName, filename, moduleType) {
312-
return `/**
313+
return signFile(`/**
313314
${license}
314315
*
315316
* @noflow
316317
* @nolint
317318
* @preventMunge
318-
* ${'@gen' + 'erated'}
319+
* ${getSigningToken()}
319320
*/
320321
321-
${source}`;
322+
${source}`);
322323
},
323324

324325
/****************** RN_FB_PROFILING ******************/
325326
[RN_FB_PROFILING](source, globalName, filename, moduleType) {
326-
return `/**
327+
return signFile(`/**
327328
${license}
328329
*
329330
* @noflow
330331
* @nolint
331332
* @preventMunge
332-
* ${'@gen' + 'erated'}
333+
* ${getSigningToken()}
333334
*/
334335
335-
${source}`;
336+
${source}`);
336337
},
337338
};
338339

@@ -369,7 +370,7 @@ ${source}
369370
${license}
370371
*/
371372
module.exports = function $$$reconciler($$$config) {
372-
373+
373374
var exports = {};
374375
${source}
375376
return exports;

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14872,6 +14872,11 @@ signal-exit@^3.0.7:
1487214872
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9"
1487314873
integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==
1487414874

14875+
signedsource@^2.0.0:
14876+
version "2.0.0"
14877+
resolved "https://registry.yarnpkg.com/signedsource/-/signedsource-2.0.0.tgz#f72dc0f98f5bca2763b464a555511a84a4da8eee"
14878+
integrity sha512-MscTxXbMij5JVgrW1xDiMIc+vFa0+H0+HP+rRrFjwa7ef2VAxIP/4L/E75I5H4xvyb4l1X+a9ch+6Zy5uFu7Fg==
14879+
1487514880
sisteransi@^1.0.5:
1487614881
version "1.0.5"
1487714882
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"

0 commit comments

Comments
 (0)