index.js
function transformSourcesMap (options) {
  return (
    readFileJSON(options.sourceMap)
      .then(sourceMap => (
        mapSources(sourceMap, path => {
          const relativePath = stripProjectRoot(options.projectRoot, path)
          return doesFileExist(path).then(exists => {
            if (exists && options.uploadSources) {
              if (path.indexOf('node_modules') !== -1) {
                if (options.uploadNodeModules) {
                  options.sources[relativePath] = path
                }
              } else {
                options.sources[relativePath] = path
              }
            }
            return relativePath
          })
        })
      ))
      .then(sourceMap => {
        // Replace the sourceMap option with a buffer of the modified sourcemap.
        const tempMap = path.join(options.tempDir, path.basename(options.sourceMap))
        fs.writeFileSync(tempMap, JSON.stringify(sourceMap)) // FIXME find out why passing a Buffer instead of a fs.ReadStream throws "maxFieldsSize 2097152 exceeded"
        options.sourceMap = tempMap
        return options
      })
      .catch(err => {
        if (err.name === 'SyntaxError') {
          throw new Error(`Source map file was not valid JSON (${options.sourceMap})`)
        }
        if (err.code === 'ENOENT') {
          throw new Error(`Source map file does not exist (${options.sourceMap})`)
        }
        throw new Error(`Source map file could not be read (doesn't exist or isn't valid JSON).`)
      })
  )
}
function transformSourcesMap (options) {
  return (
    readFileJSON(options.sourceMap)
      .then(sourceMap => (
        mapSources(sourceMap, path => {
          const relativePath = stripProjectRoot(options.projectRoot, path)
          return doesFileExist(path).then(exists => {
            if (exists && options.uploadSources) {
              if (path.indexOf('node_modules') !== -1) {
                if (options.uploadNodeModules) {
                  options.sources[relativePath] = path
                }
              } else {
                options.sources[relativePath] = path
              }
            }
            return relativePath
          })
        })
      ))
      .then(sourceMap => {
        // Replace the sourceMap option with a buffer of the modified sourcemap.
        const tempMap = path.join(options.tempDir, path.basename(options.sourceMap))
        fs.writeFileSync(tempMap, JSON.stringify(sourceMap)) // FIXME find out why passing a Buffer instead of a fs.ReadStream throws "maxFieldsSize 2097152 exceeded"
        options.sourceMap = tempMap
        return options
      })
      .catch(err => {
        if (err.name === 'SyntaxError') {
          throw new Error(`Source map file was not valid JSON (${options.sourceMap})`)
        }
        if (err.code === 'ENOENT') {
          throw new Error(`Source map file does not exist (${options.sourceMap})`)
        }
        throw new Error(`Source map file could not be read (doesn't exist or isn't valid JSON).`)
      })
  )
}
function transformSourcesMap ( options ) { return ( readFileJSON ( options . sourceMap ) . then ( sourceMap => ( mapSources ( sourceMap , path => { const relativePath = stripProjectRoot ( options . projectRoot , path ) return doesFileExist ( path ) . then ( exists => { if ( exists && options . uploadSources ) { if ( path . indexOf ( 'node_modules' ) !== - 1 ) { if ( options . uploadNodeModules ) { options . sources [ relativePath ] = path } } else { options . sources [ relativePath ] = path } } return relativePath } ) } ) ) ) . then ( sourceMap => { // Replace the sourceMap option with a buffer of the modified sourcemap. const tempMap = path . join ( options . tempDir , path . basename ( options . sourceMap ) ) fs . writeFileSync ( tempMap , JSON . stringify ( sourceMap ) ) // FIXME find out why passing a Buffer instead of a fs.ReadStream throws "maxFieldsSize 2097152 exceeded" options . sourceMap = tempMap return options } ) . catch ( err => { if ( err . name === 'SyntaxError' ) { throw new Error ( ` ${ options . sourceMap } ` ) } if ( err . code === 'ENOENT' ) { throw new Error ( ` ${ options . sourceMap } ` ) } throw new Error ( ` ` ) } ) ) }
Extracts the source file paths from the specified source map file, and adds them to
the "sources" option, so they are uploaded too.

Note: The "projectRoot" option is used to create relative paths to the sources.

@param {object} options The options
@returns {Promise<object>}
Extracts the source file paths from the specified source map file and adds them to the sources option so they are uploaded too .