Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #43 from bugsnag/bengourley/upload-sources-fix
Browse files Browse the repository at this point in the history
Fix --upload-sources stream/buffer logic
  • Loading branch information
bengourley committed May 23, 2019
2 parents 9131a99 + 0fd7543 commit 6d306d5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
4 changes: 3 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ for (const key in conf) {
}

upload(conf, logger).catch(err => {
logger.error(`Error uploading source maps: ${err.message}`)
const stack = (err && err.stack) ? err.stack : err
const apiResponse = (err && err.errors) ? `\n\n API response:\n ${err.errors.join(', ')}\n` : ''
logger.error(`Error uploading source maps: ${stack}${apiResponse}`)
process.exitCode = 1
})
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function uploadMany (options, logger) {
const minifiedUrl = path.relative(options.projectRoot, f.replace(/\.map$/, ''))
const minifiedFile = f.replace(/\.map$/, '')
return cb => {
const opts = Object.assign({}, options, { sourceMap: f, minifiedUrl: minifiedUrl, minifiedFile: minifiedFile })
const opts = Object.assign({}, options, { sourceMap: f, minifiedUrl: minifiedUrl, minifiedFile: minifiedFile, sources: {} })
uploadOne(opts, logger)
.then(() => {
logger.info(`Upload successful (${path.basename(f)})`)
Expand Down
14 changes: 6 additions & 8 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,20 @@ function transformSourcesMap (options) {
readFileJSON(options.sourceMap)
.then(sourceMap => (
mapSources(sourceMap, p => {
// resolve a relative path in the sources array if it begins with a ".." e.g. "../../src/index.js"
const resolvedPath = /^\.\./.test(p)
? path.resolve(path.dirname(options.sourceMap), p)
: p
// resolve a relative path in the sources array
const resolvedPath = path.resolve(path.dirname(options.sourceMap), p)

// then make it relative to the project root
const relativePath = stripProjectRoot(options.projectRoot, resolvedPath)

return doesFileExist(p).then(exists => {
return doesFileExist(resolvedPath).then(exists => {
if (exists && options.uploadSources) {
if (p.indexOf('node_modules') !== -1) {
if (resolvedPath.indexOf('node_modules') !== -1) {
if (options.uploadNodeModules) {
options.sources[relativePath] = p
options.sources[relativePath] = resolvedPath
}
} else {
options.sources[relativePath] = p
options.sources[relativePath] = resolvedPath
}
}
return relativePath
Expand Down
4 changes: 2 additions & 2 deletions lib/prepare-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ module.exports = function prepareRequest (options) {
* valid file path or whether it's a Buffer object (used for sourceMap when uploadSources
* is set to `true`, because the sourcemap is modified).
*
* @param {string|Buffer} path The path of the file, or the file Buffer
* @param {string|Buffer} pathOrBuffer The path of the file, or the file Buffer
* @returns {fs.ReadStream|Buffer}
*/
function getSendableSource (pathOrBuffer) {
if (typeof path === 'string') {
if (typeof pathOrBuffer === 'string') {
return createReadStream(pathOrBuffer)
} else if (Buffer.isBuffer(pathOrBuffer)) {
return pathOrBuffer
Expand Down
1 change: 1 addition & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const send = (endpoint, data, onSuccess, onError) => {
return onError(err)
} catch (_) {
const e = new Error(`HTTP status ${res.statusCode} received from upload API`)
e.errors = [ body.toString() ]
e.isRetryable = false
return onError(e)
}
Expand Down

0 comments on commit 6d306d5

Please sign in to comment.