1*26ad19fcSEvan Bacon/**
2*26ad19fcSEvan Bacon * Copyright © 2022 650 Industries.
3*26ad19fcSEvan Bacon *
4*26ad19fcSEvan Bacon * This source code is licensed under the MIT license found in the
5*26ad19fcSEvan Bacon * LICENSE file in the root directory of this source tree.
6*26ad19fcSEvan Bacon */
7*26ad19fcSEvan Bacon
8*26ad19fcSEvan Baconexport function buildUrlForBundle(bundlePath: string): string {
9*26ad19fcSEvan Bacon  if (process.env.NODE_ENV === 'production') {
10*26ad19fcSEvan Bacon    if (typeof location !== 'undefined') {
11*26ad19fcSEvan Bacon      return joinComponents(location.origin, bundlePath);
12*26ad19fcSEvan Bacon    }
13*26ad19fcSEvan Bacon    throw new Error(
14*26ad19fcSEvan Bacon      'Unable to determine the production URL where additional JavaScript chunks are hosted because the global "location" variable is not defined.'
15*26ad19fcSEvan Bacon    );
16*26ad19fcSEvan Bacon  } else {
17*26ad19fcSEvan Bacon    const getDevServer = require('../getDevServer')
18*26ad19fcSEvan Bacon      .default as typeof import('../getDevServer').default;
19*26ad19fcSEvan Bacon
20*26ad19fcSEvan Bacon    const { url: serverUrl } = getDevServer();
21*26ad19fcSEvan Bacon
22*26ad19fcSEvan Bacon    return joinComponents(serverUrl, bundlePath);
23*26ad19fcSEvan Bacon  }
24*26ad19fcSEvan Bacon}
25*26ad19fcSEvan Bacon
26*26ad19fcSEvan Baconfunction joinComponents(prefix: string, suffix: string): string {
27*26ad19fcSEvan Bacon  return prefix.replace(/\/+$/, '') + '/' + suffix.replace(/^\/+/, '');
28*26ad19fcSEvan Bacon}
29