Skip to content

Commit f30e695

Browse files
committed
feat: inline sourcesContent for all npm package sourceMap
1 parent 16cefcb commit f30e695

11 files changed

Lines changed: 122 additions & 61 deletions

File tree

File renamed without changes.

spec/fixtures/map-file-comment.css

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/fixtures/missing.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/fixtures/src/x.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import _ from 'lodash';
2+
export default class X {
3+
constructor() {
4+
this.name = 'Hello';
5+
}
6+
7+
description() {
8+
return _.trim(this.name);
9+
}
10+
}

spec/fixtures/y.js

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/fixtures/y.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/package-locators/default.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ test('defaultNpmPackageLocator returns fileRead func rejects missing file for ex
236236

237237
test('defaultNpmPackageLocator can read .wasm file into base64 string', t => {
238238
const defaultLocator = mockLocator(buildReadFile({
239-
'node_modules/foo/fib.wasm': fs.readFileSync(path.join(__dirname, '..', 'fib.wasm'))
239+
'node_modules/foo/fib.wasm': fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'fib.wasm'))
240240
}));
241241

242242
defaultLocator({name: 'foo'})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
import test from 'tape';
4+
import {getSourceMap} from '../src/shared';
5+
6+
// no test in browser
7+
test('getSourceMap gets referenced sourceMap file content', t => {
8+
const filePath = path.resolve(__dirname, 'fixtures', 'y.js');
9+
const contents = fs.readFileSync(filePath, 'utf8');
10+
const sourceMap = getSourceMap(contents, filePath);
11+
t.ok(sourceMap);
12+
t.deepEqual(sourceMap.sources, ['src/x.js']);
13+
t.ok(sourceMap.sourcesContent);
14+
t.equal(sourceMap.sourcesContent.length, 1);
15+
t.ok(sourceMap.sourcesContent[0].includes('_.trim'));
16+
t.end();
17+
});
18+
19+
test('getSourceMap ignores missing sourceMap file', t => {
20+
const filePath = path.resolve(__dirname, 'fixtures', 'missing.js');
21+
const contents = fs.readFileSync(filePath, 'utf8');
22+
const sourceMap = getSourceMap(contents, filePath);
23+
t.notOk(sourceMap);
24+
t.end();
25+
});

spec/shared.spec.js

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ test('getSourceMap ignores file without sourceMap', t => {
148148

149149
test('getSourceMap gets inline sourceMap', t => {
150150
const contents = 'var a = 1;\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVpbGQvZm9vLm1pbi5qcyIsInNvdXJjZXMiOlsic3JjL2Zvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSIsInNvdXJjZVJvb3QiOiIvIn0=';
151-
const sourceMap = {"version":3,"file":"build/foo.min.js","sources":["src/foo.js"],"names":[],"mappings":"AAAA","sourceRoot":"/"};
151+
const sourceMap = {"version":3,"file":"build/foo.min.js","sources":["src/foo.js"],"names":[],"mappings":"AAAA"};
152152
t.deepEqual(getSourceMap(contents, 'foo.js'), sourceMap);
153153
t.end();
154154
});
@@ -158,55 +158,3 @@ test('getSourceMap ignores broken inline sourceMap', t => {
158158
t.notOk(getSourceMap(contents, 'foo.js'));
159159
t.end();
160160
});
161-
162-
if (typeof global.document === 'undefined') {
163-
// no test in browser
164-
test('getSourceMap gets referenced sourceMap file content', t => {
165-
let contents = `
166-
.header {
167-
background: #444;
168-
border: solid;
169-
padding: 10px;
170-
border-radius: 10px 5px 10px 5px;
171-
color: #b4b472; }
172-
173-
#main li {
174-
color: green;
175-
margin: 10px;
176-
padding: 10px;
177-
font-size: 18px; }
178-
179-
`;
180-
contents += '\n//# sourceMappingURL=map-file-comment.css.map\n';
181-
const sourceMap = {
182-
"version": "3",
183-
"mappings": "AAAA,wBAAyB;EACvB,UAAU,EAAE,IAAI;EAChB,MAAM,EAAE,KAAK;EACb,OAAO,EAAE,IAAI;EACb,aAAa,EAAE,iBAAiB;EAChC,KAAK,EAAE,OAAkB;;AAG3B,wBAAyB;EACvB,OAAO,EAAE,IAAI;;ACTf,gBAAiB;EACf,UAAU,EAAE,IAAI;EAChB,KAAK,EAAE,MAAM;;AAGf,kBAAmB;EACjB,MAAM,EAAE,IAAI;EACZ,OAAO,EAAE,IAAI;EACb,UAAU,EAAE,KAAK;EACjB,aAAa,EAAE,GAAG;EAClB,KAAK,EAAE,KAAK;;AAEd,kBAAmB;EACjB,KAAK,EAAE,KAAK;;AAGd,mBAAoB;EAClB,KAAK,EAAE,KAAK;EACZ,MAAM,EAAE,IAAI;EACZ,OAAO,EAAE,IAAI;EACb,SAAS,EAAE,IAAI",
184-
"sources": ["./client/sass/core.scss","./client/sass/main.scss"],
185-
"file": "map-file-comment.css"
186-
};
187-
188-
t.deepEqual(getSourceMap(contents, 'spec/map-file-comment.css'), sourceMap);
189-
t.end();
190-
});
191-
192-
test('getSourceMap ignores missing sourceMap file', t => {
193-
let contents = `
194-
.header {
195-
background: #444;
196-
border: solid;
197-
padding: 10px;
198-
border-radius: 10px 5px 10px 5px;
199-
color: #b4b472; }
200-
201-
#main li {
202-
color: green;
203-
margin: 10px;
204-
padding: 10px;
205-
font-size: 18px; }
206-
207-
`;
208-
contents += '\n//# sourceMappingURL=missing.css.map\n';
209-
t.notOk(getSourceMap(contents, 'spec/map-file-comment.css'));
210-
t.end();
211-
});
212-
}

0 commit comments

Comments
 (0)