Skip to content

Commit

Permalink
[WIP] Move @generated signing from build to sync
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Jun 7, 2024
1 parent 142b2a8 commit 77e2b92
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 39 deletions.
20 changes: 0 additions & 20 deletions scripts/rollup/packaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ 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 @@ -127,24 +125,6 @@ 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(/(\r?\n\s*\*\s*)@format\b.*(\n)/, '$1@noformat$2')
// Add {@}nolint and {@}generated
.replace(/(\r?\n\s*\*)\//, `$1 @nolint$1 ${getSigningToken()}$1/`);
const signedContents = signFile(contents);
writeFileSync(file, signedContents, 'utf8');
});
}

async function copyAllShims() {
Expand Down
31 changes: 12 additions & 19 deletions scripts/rollup/wrappers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

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

const {
Expand Down Expand Up @@ -392,86 +391,80 @@ ${source}`;

/****************** RN_OSS_DEV ******************/
[RN_OSS_DEV](source, globalName, filename, moduleType) {
return signFile(`/**
return `/**
${license}
*
* @noflow
* @nolint
* @preventMunge
* ${getSigningToken()}
*/
${source}`);
${source}`;
},

/****************** RN_OSS_PROD ******************/
[RN_OSS_PROD](source, globalName, filename, moduleType) {
return signFile(`/**
return `/**
${license}
*
* @noflow
* @nolint
* @preventMunge
* ${getSigningToken()}
*/
${source}`);
${source}`;
},

/****************** RN_OSS_PROFILING ******************/
[RN_OSS_PROFILING](source, globalName, filename, moduleType) {
return signFile(`/**
return `/**
${license}
*
* @noflow
* @nolint
* @preventMunge
* ${getSigningToken()}
*/
${source}`);
${source}`;
},

/****************** RN_FB_DEV ******************/
[RN_FB_DEV](source, globalName, filename, moduleType) {
return signFile(`/**
return `/**
${license}
*
* @noflow
* @nolint
* @preventMunge
* ${getSigningToken()}
*/
${source}`);
${source}`;
},

/****************** RN_FB_PROD ******************/
[RN_FB_PROD](source, globalName, filename, moduleType) {
return signFile(`/**
return `/**
${license}
*
* @noflow
* @nolint
* @preventMunge
* ${getSigningToken()}
*/
${source}`);
${source}`;
},

/****************** RN_FB_PROFILING ******************/
[RN_FB_PROFILING](source, globalName, filename, moduleType) {
return signFile(`/**
return `/**
${license}
*
* @noflow
* @nolint
* @preventMunge
* ${getSigningToken()}
*/
${source}`);
${source}`;
},
};

Expand Down

0 comments on commit 77e2b92

Please sign in to comment.