Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[expo-updates] Fetch asset manifest through programmatic CLI interface instead of depending on a running React Native CLI server #9372

Merged
merged 2 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/expo-updates/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

### 🐛 Bug fixes

- Fetch asset manifest through programmatic CLI interface instead of depending on a running React Native CLI server, so `./gradlew :app:assembleRelease` works as expected without needing to run `react-native start` beforehand. ([#9372](https://github.com/expo/expo/pull/9372)).

## 0.2.11 — 2020-06-29

### 🐛 Bug fixes
Expand Down
1 change: 1 addition & 0 deletions packages/expo-updates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"expo-file-system": "*"
},
"dependencies": {
"@expo/metro-config": "^0.1.16",
"fbemitter": "^2.1.1",
"uuid": "^3.4.0"
},
Expand Down
10 changes: 2 additions & 8 deletions packages/expo-updates/scripts/create-manifest-android.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ def nodeExecutableAndArgs = config.nodeExecutableAndArgs ?: ["node"]
def entryFile = config.entryFile ?: "index.js"
def assetsFile = entryFile.take(entryFile.lastIndexOf('.')) + ".assets"

def reactNativeDevServerPort() {
return project.getProperties().get("reactNativeDevServerPort") ?: "8081"
}

def reactNativePackagerHostname = System.getenv('REACT_NATIVE_PACKAGER_HOSTNAME') ?: "localhost:${reactNativeDevServerPort()}"

afterEvaluate {
def projectRoot = file("../../")
def inputExcludes = ["android/**", "ios/**"]
Expand Down Expand Up @@ -61,9 +55,9 @@ afterEvaluate {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
// in cmd, & must be escaped with ^
assetsFile = assetsFile.replace('&', '^&');
commandLine("cmd", "/c", *nodeExecutableAndArgs, "$expoUpdatesDir/scripts/createManifest.js", "android", "http://$reactNativePackagerHostname/$assetsFile?platform=android^&dev=false", assetsDir)
commandLine("cmd", "/c", *nodeExecutableAndArgs, "$expoUpdatesDir/scripts/createManifest.js", "android", projectRoot, assetsDir)
} else {
commandLine(*nodeExecutableAndArgs, "$expoUpdatesDir/scripts/createManifest.js", "android", "http://$reactNativePackagerHostname/$assetsFile?platform=android&dev=false", assetsDir)
commandLine(*nodeExecutableAndArgs, "$expoUpdatesDir/scripts/createManifest.js", "android", projectRoot, assetsDir)
}

enabled config."bundleIn${targetName}" || targetName.toLowerCase().contains("release")
Expand Down
7 changes: 4 additions & 3 deletions packages/expo-updates/scripts/create-manifest-ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ set -eo pipefail
DEST="$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH"
ENTRY_FILE=${ENTRY_FILE:-index.js}
RCT_METRO_PORT=${RCT_METRO_PORT:=8081}
REACT_NATIVE_PACKAGER_HOSTNAME=${REACT_NATIVE_PACKAGER_HOSTNAME:-"localhost:$RCT_METRO_PORT"}
ASSETS_URL="http://$REACT_NATIVE_PACKAGER_HOSTNAME/"${ENTRY_FILE%.js}".assets?platform=ios&dev=false"
NODE_BINARY=${NODE_BINARY:-node}

# Related to: https://github.com/facebook/react-native/blob/c9f869f9c7c8b035a669980382af4bbd4afecb89/scripts/react-native-xcode.sh#L59-L69
PROJECT_ROOT=${PROJECT_ROOT:-$PWD/..}

if ! [ -x "$(command -v $NODE_BINARY)" ]; then
echo 'Error: cannot find the node binary. Try setting the NODE_BINARY variable in the ' \
'"Bundle React Native code and images" Build Phase to the absolute path to your node binary. ' \
'You can find it by executing "which node" in a terminal window.' >&2
exit 1
fi

"$NODE_BINARY" "$(dirname "${BASH_SOURCE[0]}")/createManifest.js" ios "$ASSETS_URL" "$DEST"
"$NODE_BINARY" "$(dirname "${BASH_SOURCE[0]}")/createManifest.js" ios "$PROJECT_ROOT" "$DEST"
40 changes: 4 additions & 36 deletions packages/expo-updates/scripts/createManifest.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,21 @@
const fs = require('fs');
const http = require('http');
const path = require('path');
const uuid = require('uuid/v4');

const fetchAssetManifestAsync = require('./fetchAssetManifestAsync');
const filterPlatformAssetScales = require('./filterPlatformAssetScales');

const platform = process.argv[2];
const packagerUrl = process.argv[3];
const projectRoot = process.argv[3];
const destinationDir = process.argv[4];

(async function() {
let assetsJson;
try {
assetsJson = await new Promise(function(resolve, reject) {
const req = http.get(packagerUrl, function(res) {
if (res.statusCode !== 200) {
reject(new Error('Request to packager server failed: ' + res.statusCode));
res.resume();
return;
}

res.setEncoding('utf8');
let rawData = '';
res.on('data', function(chunk) {
rawData += chunk;
});
res.on('end', function() {
resolve(rawData);
});
});

req.on('error', function(error) {
reject(error);
});

req.end();
});
} catch (e) {
throw new Error(
`Failed to connect to the packager server. If you did not start this build by running 'react-native run-android', you can start the packager manually by running 'react-native start' in the project directory. (Error: ${e.message})`
);
}

let assets;
try {
assets = JSON.parse(assetsJson);
assets = await fetchAssetManifestAsync(platform, projectRoot);
} catch (e) {
throw new Error(
"Error parsing assets JSON from React Native packager. Ensure you've followed all expo-updates installation steps correctly. " +
"Error loading assets JSON from Metro. Ensure you've followed all expo-updates installation steps correctly. " +
e.message
);
}
Expand Down
35 changes: 35 additions & 0 deletions packages/expo-updates/scripts/fetchAssetManifestAsync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { loadAsync } = require('@expo/metro-config');
const Server = require('metro/src/Server');

async function fetchAssetManifestAsync(platform, projectRoot) {
const config = await loadAsync(projectRoot);
const server = new Server(config);

const requestOpts = {
entryFile: process.env.ENTRY_FILE || 'index.js',
dev: false,
minify: false,
platform,
};

let assetManifest;
let error;
try {
assetManifest = await server.getAssets({
...Server.DEFAULT_BUNDLE_OPTIONS,
...requestOpts,
});
} catch (e) {
error = e;
} finally {
server.end();
}

if (error) {
throw error;
}

return assetManifest;
}

module.exports = fetchAssetManifestAsync;
103 changes: 81 additions & 22 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,19 @@
"@babel/preset-env" "^7.4.4"
"@babel/preset-typescript" "^7.3.3"

"@expo/babel-preset-cli@0.2.16":
version "0.2.16"
resolved "https://registry.yarnpkg.com/@expo/babel-preset-cli/-/babel-preset-cli-0.2.16.tgz#64102032ae9b6cb931c80d8b6371dd08f2f5e748"
integrity sha512-CuBNFx8Vk6UAqhaCY9awIemdb2IppxLkrIk+OsmKIN4aoF21DEd++LUGgEGFz8jfFziF8JBdJU4OnyXMIb1KyQ==
dependencies:
"@babel/core" "^7.4.5"
"@babel/plugin-proposal-class-properties" "^7.4.4"
"@babel/plugin-proposal-nullish-coalescing-operator" "^7.7.4"
"@babel/plugin-proposal-optional-chaining" "^7.7.5"
"@babel/plugin-transform-modules-commonjs" "^7.5.0"
"@babel/preset-env" "^7.4.4"
"@babel/preset-typescript" "^7.3.3"

"@expo/browser-polyfill@^0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@expo/browser-polyfill/-/browser-polyfill-0.1.0.tgz#225dc667b22f8b247fa11aa961537f3a43c4fe48"
Expand All @@ -1118,6 +1131,24 @@
mv "~2"
safe-json-stringify "~1"

"@expo/config@3.2.15":
version "3.2.15"
resolved "https://registry.yarnpkg.com/@expo/config/-/config-3.2.15.tgz#20a23c3454a79bc32ee8942d99a6a0a46db50f52"
integrity sha512-Z6yszUuVeZlrD4NJEa0EAuYsluvDQ7ht81/WlCABjGfc4GGkOHQm2nyRLEkBDtmCyH2epE+1NjXpcyckCku+9Q==
dependencies:
"@babel/register" "^7.8.3"
"@expo/babel-preset-cli" "0.2.16"
"@expo/json-file" "8.2.21"
"@expo/plist" "0.0.8"
fs-extra "9.0.0"
glob "7.1.6"
invariant "^2.2.4"
resolve-from "^5.0.0"
semver "^7.1.3"
slugify "^1.3.4"
xcode "^2.1.0"
xml2js "^0.4.23"

"@expo/config@3.2.6", "@expo/config@^3.2.3":
version "3.2.6"
resolved "https://registry.yarnpkg.com/@expo/config/-/config-3.2.6.tgz#20b918db1543307f6a572906cf6821d627be6d32"
Expand Down Expand Up @@ -1192,6 +1223,17 @@
util.promisify "^1.0.0"
write-file-atomic "^2.3.0"

"@expo/json-file@8.2.21":
version "8.2.21"
resolved "https://registry.yarnpkg.com/@expo/json-file/-/json-file-8.2.21.tgz#b2e702d43262a03bea56ccfe60bdd6ee4d35bf6a"
integrity sha512-/WFk2s9Vjj4LObssu5lN7M4wW7MmRZL5+fG4SfhvPU0yE2nohwoyoKW0RJk0hfAmYdrzQmQ9gHhx+sSjnVuIng==
dependencies:
"@babel/code-frame" "^7.0.0-beta.44"
fs-extra "9.0.0"
json5 "^1.0.1"
lodash "^4.17.15"
write-file-atomic "^2.3.0"

"@expo/metro-config@0.1.7":
version "0.1.7"
resolved "https://registry.yarnpkg.com/@expo/metro-config/-/metro-config-0.1.7.tgz#f1940db8f31644964f5300031bd3bfa414dc846b"
Expand All @@ -1200,6 +1242,14 @@
"@expo/config" "3.2.6"
metro-react-native-babel-transformer "^0.58.0"

"@expo/metro-config@^0.1.16":
version "0.1.16"
resolved "https://registry.yarnpkg.com/@expo/metro-config/-/metro-config-0.1.16.tgz#79d58e267a8ff2b7230206e20fdd022ed50df085"
integrity sha512-Ej+5WxneZXfIRl8C7TfVSL0OPW+MVNpnXc7ZWHjZW9h3xASLFLLV5rpg6/tQjgIEVl3pxPluaFBVZRFb01bRNQ==
dependencies:
"@expo/config" "3.2.15"
metro-react-native-babel-transformer "^0.58.0"

"@expo/mux@^1.0.7":
version "1.0.7"
resolved "https://registry.yarnpkg.com/@expo/mux/-/mux-1.0.7.tgz#77a29dcf7bd02edf76cfc74631a64ea6b13b9c58"
Expand Down Expand Up @@ -1332,6 +1382,15 @@
xmlbuilder "^14.0.0"
xmldom "~0.1.31"

"@expo/plist@0.0.8":
version "0.0.8"
resolved "https://registry.yarnpkg.com/@expo/plist/-/plist-0.0.8.tgz#616fd2b9e511368aaa860759acf0d87228c3b228"
integrity sha512-sjWpUA3BPqyUu4cgRg3MkUiwjjVspCOcGo+lUpwU3lK1gQEmDQCJaS1Mjfj2JgM5BSnTcAPcenyLRrNXlfGFVQ==
dependencies:
base64-js "^1.2.3"
xmlbuilder "^14.0.0"
xmldom "~0.1.31"

"@expo/react-native-action-sheet@^2.0.1", "@expo/react-native-action-sheet@^2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@expo/react-native-action-sheet/-/react-native-action-sheet-2.1.0.tgz#7c3f6def52aee15ca7bd9e03cc0529e64618592c"
Expand Down Expand Up @@ -8180,6 +8239,16 @@ fs-extra@6.0.1:
jsonfile "^4.0.0"
universalify "^0.1.0"

fs-extra@9.0.0, fs-extra@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.0.tgz#b6afc31036e247b2466dc99c29ae797d5d4580a3"
integrity sha512-pmEYSk3vYsG/bF651KPUXZ+hvjpgWYw/Gc7W9NFUe3ZVLczKKWIij3IKpOrQcdw4TILtibFslZ0UmR8Vvzig4g==
dependencies:
at-least-node "^1.0.0"
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^1.0.0"

fs-extra@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-1.0.0.tgz#cd3ce5f7e7cb6145883fcae3191e9877f8587950"
Expand Down Expand Up @@ -8216,16 +8285,6 @@ fs-extra@^8.0.1, fs-extra@^8.1.0:
jsonfile "^4.0.0"
universalify "^0.1.0"

fs-extra@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.0.tgz#b6afc31036e247b2466dc99c29ae797d5d4580a3"
integrity sha512-pmEYSk3vYsG/bF651KPUXZ+hvjpgWYw/Gc7W9NFUe3ZVLczKKWIij3IKpOrQcdw4TILtibFslZ0UmR8Vvzig4g==
dependencies:
at-least-node "^1.0.0"
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^1.0.0"

fs-minipass@^1.2.5:
version "1.2.7"
resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.7.tgz#ccff8570841e7fe4265693da88936c55aed7f7c7"
Expand Down Expand Up @@ -8451,6 +8510,18 @@ glob@7.1.2:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@7.1.6, glob@^7.0.0, glob@^7.0.3, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6:
version "7.1.6"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^3.0.4"
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^5.0.14:
version "5.0.15"
resolved "https://registry.yarnpkg.com/glob/-/glob-5.0.15.tgz#1bc936b9e02f4a603fcc222ecf7633d30b8b93b1"
Expand All @@ -8473,18 +8544,6 @@ glob@^6.0.1:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^7.0.0, glob@^7.0.3, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6:
version "7.1.6"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^3.0.4"
once "^1.3.0"
path-is-absolute "^1.0.0"

global-modules@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/global-modules/-/global-modules-2.0.0.tgz#997605ad2345f27f51539bea26574421215c7780"
Expand Down