Skip to content

Commit

Permalink
Add setup-nightly postinstall script for third party libraries to tes…
Browse files Browse the repository at this point in the history
…t nightly build
  • Loading branch information
Kudo committed Oct 2, 2022
1 parent 4363626 commit c4349b1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"scripts/react_native_pods.rb",
"scripts/cocoapods",
"scripts/react-native-xcode.sh",
"scripts/setup-nightly.js",
"sdks/.hermesversion",
"sdks/hermes-engine",
"sdks/hermesc",
Expand Down
8 changes: 8 additions & 0 deletions scripts/publish-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ if (isCommitly) {
}
}

// Add setup-nightly.js postinstall script for nightly build
if (nightlyBuild) {
const packageJsonPath = path.join(tmpPublishingFolder, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
packageJson.scripts.postinstall = './scripts/setup-nightly.js';
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
}

// -------- Generating Android Artifacts
env.REACT_NATIVE_SKIP_PREFAB = true;
if (exec('./gradlew :ReactAndroid:installArchives').code) {
Expand Down
44 changes: 44 additions & 0 deletions scripts/setup-nightly.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env node
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

'use strict';

const fs = require('fs');
const path = require('path');
const {exit} = require('process');

const ROOT_DIR = path.join(__dirname, '..');

// Version for nightly build. Since third party libraries used to check the minor version for feature detections.
// The nightly build version we published to npm is `0.0.0` which will break third party libraries assumption.
// This script will overwrite the nightly build version as `999.999.999`.
const NIGHTLY_VERSION = '999.999.999';

async function main() {
// Rewrite version in _package.json_
const packageJsonPath = path.join(ROOT_DIR, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
packageJson.version = NIGHTLY_VERSION;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));

// Rewrite version in _ReactAndroid/gradle.properties_
const gradlePropertiesPath = path.join(
ROOT_DIR,
'ReactAndroid',
'gradle.properties',
);
let content = fs.readFileSync(gradlePropertiesPath, 'utf-8');
content = content.replace(/^(VERSION_NAME)(.*)$/gm, `$1=${NIGHTLY_VERSION}`);
fs.writeFileSync(gradlePropertiesPath, content);
}

main().then(() => {
exit(0);
});
2 changes: 1 addition & 1 deletion sdks/hermes-engine/hermes-engine.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ git = "https://github.com/facebook/hermes.git"
if ENV.has_key?('HERMES_ENGINE_TARBALL_PATH')
Pod::UI.puts '[Hermes] Using pre-built Hermes binaries from local path.' if Object.const_defined?("Pod::UI")
source[:http] = "file://#{ENV['HERMES_ENGINE_TARBALL_PATH']}"
elsif version == '1000.0.0'
elsif version == '1000.0.0' || version == '999.999.999'
Pod::UI.puts '[Hermes] Installing hermes-engine may take a while, building Hermes from source...'.yellow if Object.const_defined?("Pod::UI")
source[:git] = git
source[:commit] = `git ls-remote https://github.com/facebook/hermes main | cut -f 1`.strip
Expand Down

0 comments on commit c4349b1

Please sign in to comment.