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

Fix windows paths #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,14 @@ function uploadMany (options, logger) {

logger.info(`Found ${files.length} source map(s) to upload`)
const uploads = files.map(f => {
const minifiedUrl = path.relative(options.projectRoot, f.replace(/\.map$/, ''))
var minifiedUrl = path.relative(options.projectRoot, f.replace(/\.map$/, ''))
const minifiedFile = f.replace(/\.map$/, '')

// Fix paths on non-posix platforms
if (path.sep !== '/') {
minifiedUrl = minifiedUrl.split(path.sep).join('/')
}

return cb => {
const opts = Object.assign({}, options, { sourceMap: f, minifiedUrl: minifiedUrl, minifiedFile: minifiedFile, sources: {} })
uploadOne(opts, logger)
Expand Down
6 changes: 5 additions & 1 deletion lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ function transformSourcesMap (options) {
const resolvedPath = path.resolve(path.dirname(options.sourceMap), p)

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

if (path.sep !== '/') {
relativePath = relativePath.split(path.sep).join('/')
}

return doesFileExist(resolvedPath).then(exists => {
if (exists && options.uploadSources) {
Expand Down
25 changes: 13 additions & 12 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const path = require('path')
const concat = require('concat-stream')
const ROOT = __dirname.split(path.sep).join('/')

afterEach(() => jest.resetModules())

Expand All @@ -17,8 +18,8 @@ test('single uploads', () => {
const upload = require('../').upload
return upload({
apiKey: 'API_KEY',
sourceMap: `${__dirname}/fixtures/single/noop.min.js.map`,
projectRoot: `${__dirname}/fixtures/single`
sourceMap: `${ROOT}/fixtures/single/noop.min.js.map`,
projectRoot: `${ROOT}/fixtures/single`
}).then(() => {
expect(mockCalled).toBe(1)
})
Expand All @@ -38,7 +39,7 @@ test('multiple uploads', () => {
const upload = require('../').upload
return upload({
apiKey: 'API_KEY',
projectRoot: `${__dirname}/fixtures/multi`,
projectRoot: `${ROOT}/fixtures/multi`,
directory: true
}).then(() => {
expect(mockCalled).toBe(4)
Expand All @@ -54,22 +55,22 @@ test('multiple uploads', () => {
expect(uploads).toEqual([
{
minifiedUrl: 'app.js',
minifiedFile: `${__dirname}/fixtures/multi/app.js`,
minifiedFile: `${ROOT}/fixtures/multi/app.js`,
sourceMap: 'app.js.map'
},
{
minifiedUrl: 'services/bugsnag.js',
minifiedFile: `${__dirname}/fixtures/multi/services/bugsnag.js`,
minifiedFile: `${ROOT}/fixtures/multi/services/bugsnag.js`,
sourceMap: 'bugsnag.js.map'
},
{
minifiedUrl: 'services/logger.js',
minifiedFile: `${__dirname}/fixtures/multi/services/logger.js`,
minifiedFile: `${ROOT}/fixtures/multi/services/logger.js`,
sourceMap: 'logger.js.map'
},
{
minifiedUrl: 'services/widget.js',
minifiedFile: `${__dirname}/fixtures/multi/services/widget.js`,
minifiedFile: `${ROOT}/fixtures/multi/services/widget.js`,
sourceMap: 'widget.js.map'
}
])
Expand All @@ -95,7 +96,7 @@ test('multiple uploads (resolving relative source paths inside map)', () => {
const upload = require('../').upload
return upload({
apiKey: 'API_KEY',
projectRoot: `${__dirname}/fixtures/multi-relative`,
projectRoot: `${ROOT}/fixtures/multi-relative`,
directory: true
}).then(() => {
expect(mockCalled).toBe(4)
Expand All @@ -119,22 +120,22 @@ test('multiple uploads (resolving relative source paths inside map)', () => {
expect(uploads).toEqual([
{
minifiedUrl: 'lib/app.js',
minifiedFile: `${__dirname}/fixtures/multi-relative/lib/app.js`,
minifiedFile: `${ROOT}/fixtures/multi-relative/lib/app.js`,
sourceMap: 'app.js.map'
},
{
minifiedUrl: 'lib/services/bugsnag.js',
minifiedFile: `${__dirname}/fixtures/multi-relative/lib/services/bugsnag.js`,
minifiedFile: `${ROOT}/fixtures/multi-relative/lib/services/bugsnag.js`,
sourceMap: 'bugsnag.js.map'
},
{
minifiedUrl: 'lib/services/logger.js',
minifiedFile: `${__dirname}/fixtures/multi-relative/lib/services/logger.js`,
minifiedFile: `${ROOT}/fixtures/multi-relative/lib/services/logger.js`,
sourceMap: 'logger.js.map'
},
{
minifiedUrl: 'lib/services/widget.js',
minifiedFile: `${__dirname}/fixtures/multi-relative/lib/services/widget.js`,
minifiedFile: `${ROOT}/fixtures/multi-relative/lib/services/widget.js`,
sourceMap: 'widget.js.map'
}
])
Expand Down