Repository: parcel-bundler/parcel
File: packages/runtimes/js/src/JSRuntime.js (JavaScript)

Code before:

    idToName.push([
      bundle.publicId,
      relativeBundlePath(entryBundle, nullthrows(bundle), {
        leadingDotSlash: false,
      }),
    ]);

    if (bundle !== entryBundle && isNewContext(bundle, bundleGraph)) {
      for (let referenced of bundleGraph.getReferencedBundles(bundle)) {
        idToName.push([
          referenced.publicId,
          relativeBundlePath(entryBundle, nullthrows(referenced), {
            leadingDotSlash: false,
          }),
        ]);
      }
      // New contexts have their own manifests, so there's no need to continue.
      actions.skipChildren();
    }
  }, entryBundle);

  let baseUrl =
    entryBundle.env.outputFormat === 'esmodule' &&
    entryBundle.env.supports('import-meta-url')
      ? 'new __parcel__URL__("").toString()' // <-- this isn't ideal. We should use `import.meta.url` directly but it get's replaced currently
      : `require('./helpers/bundle-url').getBundleURL('${entryBundle.publicId}')`;

  return `require('./helpers/bundle-manifest').register(${baseUrl},JSON.parse(${JSON.stringify(
    JSON.stringify(idToName),
  )}));`;
}

function getRelativePathExpr(
  from: NamedBundle,
  to: NamedBundle,
  options: PluginOptions,
): string {
  let relativePath = relativeBundlePath(from, to, {leadingDotSlash: false});
  let res = JSON.stringify(relativePath);
  if (options.hmrOptions) {
    res += ' + "?" + Date.now()';
  }

  return res;
}

function getAbsoluteUrlExpr(relativePathExpr: string, bundle: NamedBundle) {
  if (
    (bundle.env.outputFormat === 'esmodule' &&
      bundle.env.supports('import-meta-url')) ||

Review comment (suggestion):
```suggestion
      ? 'new __parcel__URL__("").toString()' // <-- this isn't ideal. We should use `import.meta.url` directly but it gets replaced currently
```

Code after:

    // To make the manifest as small as possible all bundle key/values are
    // serialised into a single array e.g. ['id', 'value', 'id2', 'value2'].
    // `./helpers/bundle-manifest` accounts for this by iterating index by 2
    mappings.push(
      bundle.publicId,
      relativeBundlePath(entryBundle, nullthrows(bundle), {
        leadingDotSlash: false,
      }),
    );

    if (bundle !== entryBundle && isNewContext(bundle, bundleGraph)) {
      for (let referenced of bundleGraph.getReferencedBundles(bundle)) {
        mappings.push(
          referenced.publicId,
          relativeBundlePath(entryBundle, nullthrows(referenced), {
            leadingDotSlash: false,
          }),
        );
      }
      // New contexts have their own manifests, so there's no need to continue.
      actions.skipChildren();
    }
  }, entryBundle);

  let baseUrl =
    entryBundle.env.outputFormat === 'esmodule' &&
    entryBundle.env.supports('import-meta-url')
      ? 'new __parcel__URL__("").toString()' // <-- this isn't ideal. We should use `import.meta.url` directly but it gets replaced currently
      : `require('./helpers/bundle-url').getBundleURL('${entryBundle.publicId}')`;

  return `require('./helpers/bundle-manifest').register(${baseUrl},JSON.parse(${JSON.stringify(
    JSON.stringify(mappings),
  )}));`;
}

function getRelativePathExpr(
  from: NamedBundle,
  to: NamedBundle,
  options: PluginOptions,
): string {
  let relativePath = relativeBundlePath(from, to, {leadingDotSlash: false});
  let res = JSON.stringify(relativePath);
  if (options.hmrOptions) {
    res += ' + "?" + Date.now()';
  }

  return res;
}

function getAbsoluteUrlExpr(relativePathExpr: string, bundle: NamedBundle) {