UNPKG

@bacons/expo-metro-runtime

Version:

Tools for making experimental Metro bundler features work

30 lines 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fetchThenEvalAsync = void 0; const fetchAsync_1 = require("./fetchAsync"); /** * Load a bundle for a URL using fetch + eval on native and script tag injection on web. * * @param bundlePath Given a statement like `import('./Bacon')` `bundlePath` would be `Bacon`. */ function fetchThenEvalAsync(url) { return (0, fetchAsync_1.fetchAsync)(url).then(({ body, headers }) => { if (headers["Content-Type"] != null && headers["Content-Type"].indexOf("application/json") >= 0) { // Errors are returned as JSON. throw new Error(JSON.parse(body).message || `Unknown error fetching '${url}'`); } // NOTE(EvanBacon): All of this code is ignored in development mode at the root. // Some engines do not support `sourceURL` as a comment. We expose a // `globalEvalWithSourceUrl` function to handle updates in that case. if (global.globalEvalWithSourceUrl) { global.globalEvalWithSourceUrl(body, url); } else { // eslint-disable-next-line no-eval eval(body); } }); } exports.fetchThenEvalAsync = fetchThenEvalAsync; //# sourceMappingURL=fetchThenEval.js.map