Skip to content

Commit

Permalink
[expo-updates] Attempt fix for reported issue in 0.63 when bundling m…
Browse files Browse the repository at this point in the history
…anifest

- #9372 (comment)
- I was unable to reproduce it but if the reported cause is correct then this
  should resolve it.
  • Loading branch information
brentvatne committed Aug 1, 2020
1 parent ed8a7ec commit a566b2a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 46 deletions.
3 changes: 2 additions & 1 deletion packages/expo-updates/scripts/create-manifest-ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ RCT_METRO_PORT=${RCT_METRO_PORT:=8081}
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/..}
PROJECT_ROOT=${PROJECT_ROOT:-$PWD}
cd "$PROJECT_ROOT" || exit

if ! [ -x "$(command -v $NODE_BINARY)" ]; then
echo 'Error: cannot find the node binary. Try setting the NODE_BINARY variable in the ' \
Expand Down
58 changes: 52 additions & 6 deletions packages/expo-updates/scripts/createManifest.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
const { loadAsync } = require('@expo/metro-config');
const fs = require('fs');
const Server = require('metro/src/Server');
const path = require('path');
const uuid = require('uuid/v4');

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

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

(async function() {
const platform = process.argv[2];
const possibleProjectRoot = process.argv[3];
const destinationDir = process.argv[4];
const entryFile = process.env.ENTRY_FILE || 'index.js';

// Remove projectRoot validation when we no longer support React Native <= 62
let projectRoot;
if (fs.existsSync(path.join(possibleProjectRoot, entryFile))) {
projectRoot = possibleProjectRoot;
} else if (fs.existsSync(path.join(possibleProjectRoot, '..', entryFile))) {
projectRoot = path.resolve(possibleProjectRoot, '..');
}

let assets;
try {
assets = await fetchAssetManifestAsync(platform, projectRoot);
assets = await fetchAssetManifestAsync(platform, projectRoot, entryFile);
} catch (e) {
throw new Error(
"Error loading assets JSON from Metro. Ensure you've followed all expo-updates installation steps correctly. " +
Expand Down Expand Up @@ -89,3 +99,39 @@ function getBasePath(asset) {
}
return basePath;
}

// Spawn a Metro server to get the asset manifest
async function fetchAssetManifestAsync(platform, projectRoot, entryFile) {
// Project-level babel config does not load unless we change to the
// projectRoot before instantiating the server
process.chdir(projectRoot);

const config = await loadAsync(projectRoot);
const server = new Server(config);

const requestOpts = {
entryFile,
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;
}
39 changes: 0 additions & 39 deletions packages/expo-updates/scripts/fetchAssetManifestAsync.js

This file was deleted.

0 comments on commit a566b2a

Please sign in to comment.