Repository: parcel-bundler/parcel
File: packages/reporters/sourcemap-visualiser/src/SourceMapVisualiser.js (JavaScript)

Code before:
// @flow
import path from 'path';
import {Reporter} from '@parcel/plugin';
import {relatifyPath} from '@parcel/utils';

export default new Reporter({
  async report({event, options, logger}) {
    if (event.type === 'buildSuccess') {
      let bundles = [];
      for (let bundle of event.bundleGraph.getBundles()) {
        let p = bundle.filePath;
        if (p) {
          let mapFilePath = p + '.map';
          let hasMap = await options.outputFS.exists(mapFilePath);
          if (hasMap) {
            let map = JSON.parse(
              await options.outputFS.readFile(mapFilePath, 'utf-8'),
            );

            let mappedSources = await Promise.all(
              map.sources.map(async s => {
                let sourceContent = '';
                try {
                  sourceContent = await options.inputFS.readFile(
                    path.join(options.projectRoot, s),
                    'utf-8',
                  );
                } catch (e) {
                  logger.warn({
                    message: `Error while loading content of ${s}, ${e.message}`,
                  });
                }

                return {
                  name: s,
                  content: sourceContent,
                };
              }),
            );

            let relativePath = relatifyPath(options.projectRoot, p);
            bundles.push({
              name: relativePath,
              mappings: map.mappings,
              names: map.names,
              sources: mappedSources,
              // $FlowFixMe
              content: await options.outputFS.readFile(
                bundle.filePath,
                'utf-8',

Review comment (refactor):
`@parcel/reporter-sourcemap-visualiser: Error while loading content of /Users/niklas/Documents/dev/_git/parcel/parcel/packages/shared/scope-hoisting/src/prelude.js, ENOENT: no such file or directory, open '/Users/niklas/Documents/_dev/_git/parcel/parcel/packages/examples/kitchen-sink/Users/niklas/Documents/_dev/git/parcel/parcel/packages/shared/scope-hoisting/src/prelude.js'`

So this should be 
```suggestion
                    path.resolve(options.projectRoot, s),
```

The locs in the `HELPERS` and `PRELUDE` asts in `scope-hoisting/src/concat.js` should really be relative to the project root as well.

Code after:
// @flow
import path from 'path';
import nullthrows from 'nullthrows';
import {Reporter} from '@parcel/plugin';
import {relatifyPath} from '@parcel/utils';

export default new Reporter({
  async report({event, options, logger}) {
    if (event.type === 'buildSuccess') {
      let bundles = [];
      for (let bundle of event.bundleGraph.getBundles()) {
        let p = bundle.filePath;
        if (p) {
          let mapFilePath = p + '.map';
          let hasMap = await options.outputFS.exists(mapFilePath);
          if (hasMap) {
            let map = JSON.parse(
              await options.outputFS.readFile(mapFilePath, 'utf-8'),
            );

            let mappedSources = await Promise.all(
              map.sources.map(async s => {
                let sourceContent = '';
                try {
                  sourceContent = await options.inputFS.readFile(
                    path.resolve(options.projectRoot, s),
                    'utf-8',
                  );
                } catch (e) {
                  logger.warn({
                    message: `Error while loading content of ${s}, ${e.message}`,
                  });
                }

                return {
                  name: s,
                  content: sourceContent,
                };
              }),
            );

            let relativePath = relatifyPath(options.projectRoot, p);
            bundles.push({
              name: relativePath,
              mappings: map.mappings,
              names: map.names,
              sources: mappedSources,
              content: await options.outputFS.readFile(
                nullthrows(bundle.filePath),
                'utf-8',