1/**
2 * Copyright © 2022 650 Industries.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7import { fetchAsync } from './fetchAsync';
8/**
9 * Load a bundle for a URL using fetch + eval on native and script tag injection on web.
10 *
11 * @param bundlePath Given a statement like `import('./Bacon')` `bundlePath` would be `Bacon`.
12 */
13export function fetchThenEvalAsync(url) {
14    return fetchAsync(url).then(({ body, headers }) => {
15        if (headers?.has?.('Content-Type') != null &&
16            headers.get('Content-Type').includes('application/json')) {
17            // Errors are returned as JSON.
18            throw new Error(JSON.parse(body).message || `Unknown error fetching '${url}'`);
19        }
20        // NOTE(EvanBacon): All of this code is ignored in development mode at the root.
21        // Some engines do not support `sourceURL` as a comment. We expose a
22        // `globalEvalWithSourceUrl` function to handle updates in that case.
23        if (global.globalEvalWithSourceUrl) {
24            global.globalEvalWithSourceUrl(body, url);
25        }
26        else {
27            // eslint-disable-next-line no-eval
28            eval(body);
29        }
30    });
31}
32//# sourceMappingURL=fetchThenEval.js.map