Skip to content

Commit 803954e

Browse files
committed
fix: remove sourceMappingUrl from prepends and appends
1 parent 742ae22 commit 803954e

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

spec/shared.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ test('contentOrFile rejects wrong remote url', t => {
7878
test('contentOrFile reads local js file', t => {
7979
const path = 'a.js';
8080

81-
contentOrFile(path, {readFile: buildReadFile({'a.js': 'var a;'})})
81+
contentOrFile(path, {readFile: buildReadFile({'a.js': 'var a;\n//# sourceMappingURL=abc'})})
8282
.then(
83-
result => t.equal(result.contents, 'var a;'),
83+
result => t.equal(result.contents, 'var a;\n'),
8484
err => t.fail(err.message)
8585
)
8686
.then(t.end);

src/shared.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,31 @@ export function contentOrFile(pathOrContent, mock) {
5353
return Promise.reject(new Error('No content or file provided'));
5454
}
5555

56+
let p;
5657
// pathOrContent is a path
5758
if (pathOrContent.match(/^https?:\/\//)) {
5859
// remote url
59-
return fetch(pathOrContent)
60+
p = fetch(pathOrContent)
6061
.then(response => {
6162
if (response.ok) return response.text();
6263
else throw new Error(response.statusText)
6364
})
6465
.then(text => {
6566
ensureParsed(text);
6667
// pathOrContent is code
67-
return Promise.resolve({contents: text});
68+
return text;
6869
});
6970
} else if (pathOrContent.endsWith('.js')) {
70-
return _readFile(pathOrContent)
71-
.then(buffer => ({contents: buffer.toString()}));
71+
p = _readFile(pathOrContent)
72+
.then(buffer => buffer.toString());
7273
} else {
73-
return new Promise(resolve => {
74+
p = new Promise(resolve => {
7475
ensureParsed(pathOrContent);
75-
resolve({contents: pathOrContent});
76+
resolve(pathOrContent);
7677
});
7778
}
79+
80+
return p.then(text => ({contents: stripSourceMappingUrl(text)}));
7881
}
7982

8083
export function generateHash(bufOrStr) {

0 commit comments

Comments
 (0)