Skip to content

Commit adf1b62

Browse files
motiz88facebook-github-bot
authored andcommitted
Normalise shell name/version strings, add commit hash when prebuilt (#53480)
Summary: Pull Request resolved: #53480 Changelog: [Internal] Improves the way `--version` and the User-Agent header work in `debugger-shell`. * The same app name and version string format will be used across the `dev` and `prebuilt` flavours. Previously, `dev` would report itself as being `Electron v37.2.6` while `prebuilt` would report `react-native/debugger-shell v0.82.0-main`. * `prebuilt` now also reports the original Meta-internal commit hash as a suffix `-rFBS..........` added to the semver string taken from `package.json`, while `dev` will have a `-dev` suffix in the same place. * We do **not** modify the version in `package.json` during the build, nor do we pass the commit hash to `electron/packager`, because this would impose inconvenient platform-specific restrictions on the version string's format. Reviewed By: huntie Differential Revision: D81120181 fbshipit-source-id: e730dd35da78dfbb8de326f9a3ab76b747fdb0b3
1 parent 7eb3536 commit adf1b62

4 files changed

Lines changed: 78 additions & 4 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
export default {
12+
revision: 'dev',
13+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* %s
8+
* @flow strict-local
9+
* @format
10+
*/
11+
12+
'use strict';
13+
14+
module.exports = {
15+
default: {
16+
revision: %s,
17+
},
18+
__esModule: true,
19+
};

packages/debugger-shell/src/electron/index.flow.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@
88
* @format
99
*/
1010

11+
import buildInfo from './BuildInfo';
12+
13+
// $FlowFixMe[untyped-import] Flow doesn't infer JSON types
14+
const pkg = require('../../package.json');
15+
const util = require('util');
1116
// $FlowFixMe[unclear-type] We have no Flow types for the Electron API.
1217
const {app} = require('electron') as any;
13-
const util = require('util');
18+
19+
// Set the app name and version early - these are used in --version as well as
20+
// in the User-Agent string.
21+
app.setName(pkg.name);
22+
app.setVersion(pkg.version + '-' + buildInfo.revision);
1423

1524
// Handle global command line arguments which don't require a window
1625
// or the single instance lock to be held.

scripts/debugger-shell/build-binary.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,23 @@ try {
1515
} catch {
1616
isMetaInternal = false;
1717
}
18+
19+
let additionalConfig /*: $ReadOnly<{
20+
appVersionHash: ?string,
21+
}> */ = {
22+
appVersionHash: null,
23+
};
24+
1825
if (isMetaInternal) {
1926
// $FlowFixMe[cannot-resolve-module] - not resolvable in OSS
20-
require('./metainternal/build-binary-setup');
27+
({additionalConfig} = require('./metainternal/build-binary-setup'));
2128
}
2229

2330
const {packager} = require('@electron/packager');
2431
const fs = require('fs');
2532
const path = require('path');
33+
const signedsource = require('signedsource');
34+
const util = require('util');
2635

2736
const APP_NAME = 'React Native DevTools';
2837
const COMPANY_NAME = 'Meta Platforms Technologies LLC';
@@ -50,15 +59,20 @@ async function main() {
5059
'dist/node',
5160
'metainternal/build-mac',
5261
'__tests__',
53-
'README.md',
5462
].map(
5563
dirRelativeToPackageRoot =>
5664
path.join(PACKAGE_ROOT, dirRelativeToPackageRoot) + path.sep,
5765
);
58-
const IGNORE_FILES = ['BUCK'].map(fileRelativeToPackageRoot =>
66+
const IGNORE_FILES = [
67+
'BUCK',
68+
'README.md',
69+
'dist/electron/BuildInfo.js.tpl',
70+
].map(fileRelativeToPackageRoot =>
5971
path.join(PACKAGE_ROOT, fileRelativeToPackageRoot),
6072
);
6173

74+
await writeBuildInfo();
75+
6276
await packager({
6377
dir: PACKAGE_ROOT,
6478
icon: path.join(PACKAGE_ROOT, 'src/electron/resources/icon'),
@@ -86,6 +100,25 @@ async function main() {
86100
});
87101
}
88102

103+
async function writeBuildInfo() {
104+
const template = await fs.promises.readFile(
105+
path.join(PACKAGE_ROOT, 'src/electron/BuildInfo.js.tpl'),
106+
'utf8',
107+
);
108+
const buildInfo = signedsource.signFile(
109+
util.format(
110+
template,
111+
signedsource.getSigningToken(),
112+
// revision
113+
JSON.stringify(additionalConfig.appVersionHash),
114+
),
115+
);
116+
await fs.promises.writeFile(
117+
path.join(PACKAGE_ROOT, 'dist/electron/BuildInfo.js'),
118+
buildInfo,
119+
);
120+
}
121+
89122
if (require.main === module) {
90123
main().catch(err => {
91124
console.error(err);

0 commit comments

Comments
 (0)