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

Prevent asbolute webpack:/// paths from being relatively resolved #49

Merged
merged 1 commit into from
Nov 1, 2019
Merged
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
3 changes: 3 additions & 0 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ function transformSourcesMap (options) {
readFileJSON(options.sourceMap)
.then(sourceMap => (
mapSources(sourceMap, p => {
// don't transform any webpack paths
if (/^webpack:\/\//.test(p)) return p

// resolve a relative path in the sources array
const resolvedPath = path.resolve(path.dirname(options.sourceMap), p)

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/webpack/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/webpack/main.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,36 @@ test('multiple uploads (resolving relative source paths inside map)', () => {
])
})
})

test('webpack paths', () => {
let mockCalled = 0
let mockCalledWith = []
const mockConcat = concat
jest.mock('../lib/request', () => {
return (endpoint, makePayload, onSuccess, onError) => {
mockCalled++
const payload = makePayload()
payload.sourceMap.pipe(mockConcat(data => {
payload.sourceMapData = JSON.parse(data)
mockCalledWith.push(payload)
onSuccess()
}))
}
})

const upload = require('../').upload
return upload({
apiKey: 'API_KEY',
projectRoot: `${__dirname}/fixtures/webpack`,
sourceMap: `${__dirname}/fixtures/webpack/main.js.map`,
minifiedFile: `${__dirname}/fixtures/webpack/main.js`,
minifiedUrl: 'http://yeah.no/bundle.js'
}).then(() => {
expect(mockCalled).toBe(1)

expect(mockCalledWith[0].sourceMapData.sources).toEqual([
'webpack:///webpack/bootstrap',
'webpack:///./src/index.js'
])
})
})