Skip to content

Commit 95ffd40

Browse files
committed
(squashed) last set of changes
1 parent d0d3f5a commit 95ffd40

File tree

4 files changed

+110
-99
lines changed

4 files changed

+110
-99
lines changed

scripts/publish-npm.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ const {
3737
exitIfNotOnGit,
3838
getCurrentCommit,
3939
isTaggedLatest,
40-
saveFiles,
4140
} = require('./scm-utils');
42-
const {generateAndroidArtifacts} = require('./release-utils');
41+
const {
42+
generateAndroidArtifacts,
43+
saveFilesToRestore,
44+
} = require('./release-utils');
4345
const fs = require('fs');
4446
const os = require('os');
4547
const path = require('path');
@@ -73,22 +75,7 @@ const dryRunBuild = argv.dryRun;
7375
const includeHermes = argv.includeHermes;
7476
const isCommitly = nightlyBuild || dryRunBuild;
7577

76-
const filesToSaveAndRestore = [
77-
'template/Gemfile',
78-
'template/_ruby-version',
79-
'template/package.json',
80-
'.ruby-version',
81-
'Gemfile.lock',
82-
'Gemfile',
83-
'package.json',
84-
'ReactAndroid/gradle.properties',
85-
'Libraries/Core/ReactNativeVersion.js',
86-
'React/Base/RCTVersion.m',
87-
'ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java',
88-
'ReactCommon/cxxreact/ReactNativeVersion.h',
89-
];
90-
91-
saveFiles(filesToSaveAndRestore, tmpPublishingFolder);
78+
saveFilesToRestore(tmpPublishingFolder);
9279

9380
if (includeHermes) {
9481
const HERMES_INSTALL_LOCATION = 'sdks';

scripts/release-utils.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,26 @@
1010
'use strict';
1111

1212
const {exec, echo, exit, test, env} = require('shelljs');
13-
const {revertFiles} = require('./scm-utils');
13+
const {revertFiles, saveFiles} = require('./scm-utils');
14+
15+
function saveFilesToRestore(tmpPublishingFolder) {
16+
const filesToSaveAndRestore = [
17+
'template/Gemfile',
18+
'template/_ruby-version',
19+
'template/package.json',
20+
'.ruby-version',
21+
'Gemfile.lock',
22+
'Gemfile',
23+
'package.json',
24+
'ReactAndroid/gradle.properties',
25+
'Libraries/Core/ReactNativeVersion.js',
26+
'React/Base/RCTVersion.m',
27+
'ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java',
28+
'ReactCommon/cxxreact/ReactNativeVersion.h',
29+
];
30+
31+
saveFiles(filesToSaveAndRestore, tmpPublishingFolder);
32+
}
1433

1534
function generateAndroidArtifacts(releaseVersion, tmpPublishingFolder) {
1635
// -------- Generating Android Artifacts
@@ -61,4 +80,5 @@ function generateAndroidArtifacts(releaseVersion, tmpPublishingFolder) {
6180

6281
module.exports = {
6382
generateAndroidArtifacts,
83+
saveFilesToRestore,
6484
};

scripts/test-e2e-local.js

Lines changed: 82 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,13 @@ const os = require('os');
2525
const {
2626
launchAndroidEmulator,
2727
isPackagerRunning,
28-
launchPackagesInSeparateWindow,
28+
launchPackagerInSeparateWindow,
2929
} = require('./testing-utils');
3030

31-
const {generateAndroidArtifacts} = require('./release-utils');
32-
33-
// setting this just 'cause this https://github.com/facebook/react-native/commit/0a3ca80af401654896cbc73e235711eef0f9b3c5
34-
// breaks a bunch of stuff. This should be enough.
35-
// TODO: follow up with Nicola in understanding the impact of the commit, and if we can remove this
36-
// also, remove the folder
37-
process.env.TMP_PUBLISH_DIR = fs.mkdtempSync(
38-
path.join(os.tmpdir(), 'rn-publish-'),
39-
);
40-
console.info(`The temp folder is ${process.env.TMP_PUBLISH_DIR}`);
31+
const {
32+
generateAndroidArtifacts,
33+
saveFilesToRestore,
34+
} = require('./release-utils');
4135

4236
const argv = yargs
4337
.option('t', {
@@ -72,12 +66,16 @@ if (isPackagerRunning() === 'running') {
7266
}
7367

7468
if (argv.target === 'RNTester') {
75-
//FIXME: make sure that the commands retains colors
69+
// FIXME: make sure that the commands retains colors
7670
// (--ansi) doesn't always work
7771
// see also https://github.com/shelljs/shelljs/issues/86
7872

7973
if (argv.platform === 'iOS') {
80-
console.info("We're going to test the Hermes version of RNTester iOS");
74+
console.info(
75+
`We're going to test the ${
76+
argv.hermes ? 'Hermes' : 'JSC'
77+
} version of RNTester iOS`,
78+
);
8179
exec(
8280
`cd packages/rn-tester && USE_HERMES=${
8381
argv.hermes ? 1 : 0
@@ -86,7 +84,7 @@ if (argv.target === 'RNTester') {
8684

8785
// if everything succeeded so far, we can launch Metro and the app
8886
// start the Metro server in a separate window
89-
launchPackagesInSeparateWindow();
87+
launchPackagerInSeparateWindow();
9088

9189
// launch the app on iOS simulator
9290
pushd('packages/rn-tester');
@@ -97,21 +95,24 @@ if (argv.target === 'RNTester') {
9795

9896
launchAndroidEmulator();
9997

100-
if (argv.hermes) {
101-
console.info(
102-
"We're going to test the Hermes version of RNTester Android",
103-
);
104-
exec(
105-
'./gradlew :packages:rn-tester:android:app:installHermesDebug --quiet',
106-
);
107-
} else {
108-
console.info("We're going to test the JSC version of RNTester Android");
109-
exec('./gradlew :packages:rn-tester:android:app:installJscDebug --quiet');
110-
}
98+
console.info(
99+
`We're going to test the ${
100+
argv.hermes ? 'Hermes' : 'JSC'
101+
} version of RNTester Android`,
102+
);
103+
exec(
104+
`./gradlew :packages:rn-tester:android:app:${
105+
argv.hermes ? 'installHermesDebug' : 'installJscDebug'
106+
} --quiet`,
107+
);
108+
109+
// launch the app on Android simulator
110+
// TODO: we should find a way to make it work like for iOS, via npx react-native run-android
111+
// currently, that fails with an error.
111112

112113
// if everything succeeded so far, we can launch Metro and the app
113114
// start the Metro server in a separate window
114-
launchPackagesInSeparateWindow();
115+
launchPackagerInSeparateWindow();
115116
// just to make sure that the Android up won't have troubles finding the Metro server
116117
exec('adb reverse tcp:8081 tcp:8081');
117118
// launch the app
@@ -124,6 +125,14 @@ if (argv.target === 'RNTester') {
124125

125126
// create the local npm package to feed the CLI
126127

128+
// base setup required (specular to publish-npm.js)
129+
const tmpPublishingFolder = fs.mkdtempSync(
130+
path.join(os.tmpdir(), 'rn-publish-'),
131+
);
132+
console.info(`The temp publishing folder is ${tmpPublishingFolder}`);
133+
134+
saveFilesToRestore(tmpPublishingFolder);
135+
127136
// we need to add the unique timestamp to avoid npm/yarn to use some local caches
128137
const baseVersion = require('../package.json').version;
129138

@@ -135,67 +144,62 @@ if (argv.target === 'RNTester') {
135144

136145
const releaseVersion = `${baseVersion}-${dateIdentifier}`;
137146

138-
// need to put it into into a try finally to ensure that we clean up the state
139-
try {
140-
// this is needed to generate the Android artifacts correctly
141-
exec(`node scripts/set-rn-version.js --to-version ${releaseVersion}`).code;
147+
// this is needed to generate the Android artifacts correctly
148+
exec(`node scripts/set-rn-version.js --to-version ${releaseVersion}`).code;
142149

143-
// Generate native files (Android only for now)
144-
generateAndroidArtifacts(releaseVersion);
150+
// Generate native files (Android only for now)
151+
generateAndroidArtifacts(releaseVersion, tmpPublishingFolder);
145152

146-
// create locally the node module
147-
exec('npm pack');
153+
// create locally the node module
154+
exec('npm pack');
148155

149-
const localNodeTGZPath = `${pwd()}/react-native-${releaseVersion}.tgz`;
150-
exec(`node scripts/set-rn-template-version.js "file:${localNodeTGZPath}"`);
156+
const localNodeTGZPath = `${pwd()}/react-native-${releaseVersion}.tgz`;
157+
exec(`node scripts/set-rn-template-version.js "file:${localNodeTGZPath}"`);
151158

152-
const repoRoot = pwd();
159+
const repoRoot = pwd();
153160

154-
pushd('/tmp/');
155-
// need to avoid the pod install step because it will fail! (see above)
156-
exec(
157-
`node ${repoRoot}/cli.js init RNTestProject --template ${repoRoot} --skip-install`,
158-
);
161+
pushd('/tmp/');
162+
// need to avoid the pod install step because it will fail! (see above)
163+
exec(
164+
`node ${repoRoot}/cli.js init RNTestProject --template ${repoRoot} --skip-install`,
165+
);
166+
167+
cd('RNTestProject');
168+
exec('yarn install');
169+
170+
if (argv.platform === 'iOS') {
171+
// if we want iOS, we need to do pod install - but with a trick
172+
cd('ios');
173+
exec('bundle install');
159174

160-
cd('RNTestProject');
161-
exec('yarn install');
162-
163-
if (argv.platform === 'iOS') {
164-
// if we want iOS, we need to do pod install - but with a trick
165-
cd('ios');
166-
exec('bundle install');
167-
168-
// TODO: we should be able to also use HERMES_ENGINE_TARBALL_PATH
169-
// if we can make RNTester step generate it already so that it gets reused
170-
171-
// need to discern if it's main branch or release branch
172-
if (baseVersion === '1000.0.0') {
173-
// main branch
174-
exec(
175-
`USE_HERMES=${argv.hermes ? 1 : 0} bundle exec pod install --ansi`,
176-
);
177-
} else {
178-
// a release branch
179-
// copy over the .hermesversion file from react-native core into the RNTestProject
180-
exec(`cp -f ${repoRoot}/sdks/.hermesversion .`);
181-
exec(
182-
`CI=true USE_HERMES=${
183-
argv.hermes ? 1 : 0
184-
} bundle exec pod install --ansi`,
185-
);
186-
}
187-
cd('..');
188-
exec('yarn ios');
175+
// TODO: we should be able to also use HERMES_ENGINE_TARBALL_PATH
176+
// if we can make RNTester step generate it already so that it gets reused
177+
178+
// need to discern if it's main branch or release branch
179+
if (baseVersion === '1000.0.0') {
180+
// main branch
181+
exec(`USE_HERMES=${argv.hermes ? 1 : 0} bundle exec pod install --ansi`);
189182
} else {
190-
// android
191-
exec('yarn android');
183+
// TODO: to test this, I need to apply changes on top of a release branch
184+
// a release branch
185+
// copy over the .hermesversion file from react-native core into the RNTestProject
186+
exec(`cp -f ${repoRoot}/sdks/.hermesversion .`);
187+
exec(
188+
`CI=true USE_HERMES=${
189+
argv.hermes ? 1 : 0
190+
} bundle exec pod install --ansi`,
191+
);
192192
}
193-
popd();
194-
} finally {
195-
// at the end here I most likely want to set back the rn version to baseVersion!
196-
// for git "cleanness" reasons
197-
exec(`node scripts/set-rn-template-version.js ${baseVersion}`);
193+
cd('..');
194+
exec('yarn ios');
195+
} else {
196+
// android
197+
exec('yarn android');
198198
}
199+
popd();
200+
201+
// just cleaning up the temp folder, the rest is done by the test clean script
202+
exec(`rm -rf ${tmpPublishingFolder}`);
199203
}
200204

201205
exit(0);

scripts/testing-utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ function isPackagerRunning(
100100
// literally, this is macos only
101101
// a more robust implementation can be found here:
102102
// https://github.com/react-native-community/cli/blob/7c003f2b1d9d80ec5c167614ba533a004272c685/packages/cli-platform-android/src/commands/runAndroid/index.ts#L195
103-
function launchPackagesInSeparateWindow() {
103+
function launchPackagerInSeparateWindow() {
104104
exec("open -a 'Terminal' ./scripts/packager.sh");
105105
}
106106

107107
module.exports = {
108108
launchAndroidEmulator,
109109
isPackagerRunning,
110-
launchPackagesInSeparateWindow,
110+
launchPackagerInSeparateWindow,
111111
};

0 commit comments

Comments
 (0)