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;

const { loadAsync } = require('@expo/metro-config');
const Server = require('metro/src/Server');

async function fetchAssetManifestAsync(platform, projectRoot) {
  // 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: 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;

Change directory to project root before loading asset manifest
[expo-updates] Change directory to project root before loading asset manifest

- Fixes https://github.com/expo/expo/issues/8374#issuecomment-666640157
