Skip to content

Commit

Permalink
Update SourceMaps (#5106)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeMoorJasper authored Sep 7, 2020
1 parent 98d5368 commit ac21b52
Show file tree
Hide file tree
Showing 33 changed files with 65 additions and 67 deletions.
2 changes: 1 addition & 1 deletion packages/core/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@parcel/logger": "2.0.0-beta.1",
"@parcel/package-manager": "2.0.0-beta.1",
"@parcel/plugin": "2.0.0-beta.1",
"@parcel/source-map": "2.0.0-alpha.4.13",
"@parcel/source-map": "2.0.0-alpha.4.15",
"@parcel/types": "2.0.0-beta.1",
"@parcel/utils": "2.0.0-beta.1",
"@parcel/workers": "2.0.0-beta.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/src/CommittedAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default class CommittedAsset {
let mapBuffer = await this.getMapBuffer();
if (mapBuffer) {
// Get sourcemap from flatbuffer
let map = new SourceMap();
let map = new SourceMap(this.options.projectRoot);
map.addBufferMappings(mapBuffer);
return map;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/src/UncommittedAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export default class UncommittedAsset {
let mapBuffer = this.mapBuffer ?? (await this.getMapBuffer());
if (mapBuffer) {
// Get sourcemap from flatbuffer
let map = new SourceMap();
let map = new SourceMap(this.options.projectRoot);
map.addBufferMappings(mapBuffer);
this.map = map;
}
Expand Down
24 changes: 12 additions & 12 deletions packages/core/integration-tests/test/sourcemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('sourcemaps', function() {
}
let map = mapUrlData.map;

let sourceMap = new SourceMap();
let sourceMap = new SourceMap('/');
sourceMap.addRawMappings(map);
let input = await inputFS.readFile(
path.join(path.dirname(filename), map.sourceRoot, map.sources[0]),
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('sourcemaps', function() {
}
let map = mapUrlData.map;

let sourceMap = new SourceMap();
let sourceMap = new SourceMap('/');
sourceMap.addRawMappings(map);
assert.strictEqual(map.sourceRoot, '/__parcel_source_root/');
let input = await inputFS.readFile(
Expand Down Expand Up @@ -223,7 +223,7 @@ describe('sourcemaps', function() {
'sourceRoot should be the root of the source files, relative to the output directory.',
);

let sourceMap = new SourceMap();
let sourceMap = new SourceMap('/');
sourceMap.addRawMappings(map);
let input = await inputFS.readFile(sourceFilename, 'utf8');
let sourcePath = './index.js';
Expand Down Expand Up @@ -281,7 +281,7 @@ describe('sourcemaps', function() {
'sourceRoot should be the root of the source files, relative to the output directory.',
);

let sourceMap = new SourceMap();
let sourceMap = new SourceMap('/');
sourceMap.addRawMappings(map);
let mapData = sourceMap.getMap();
assert.equal(mapData.sources.length, 3);
Expand Down Expand Up @@ -370,7 +370,7 @@ describe('sourcemaps', function() {
'sourceRoot should be the root of the source files, relative to the output directory.',
);

let sourceMap = new SourceMap();
let sourceMap = new SourceMap('/');
sourceMap.addRawMappings(map);
let mapData = sourceMap.getMap();
assert.equal(mapData.sources.length, 3);
Expand Down Expand Up @@ -455,7 +455,7 @@ describe('sourcemaps', function() {
assert(raw.includes('//# sourceMappingURL=index.js.map'));
// assert.equal(map.sourceRoot, '/__parcel_source_root/');

let sourceMap = new SourceMap();
let sourceMap = new SourceMap('/');
sourceMap.addRawMappings(map);

let mapData = sourceMap.getMap();
Expand Down Expand Up @@ -494,7 +494,7 @@ describe('sourcemaps', function() {
assert.equal(map.file, 'index.js.map');
assert(raw.includes('//# sourceMappingURL=index.js.map'));

let sourceMap = new SourceMap();
let sourceMap = new SourceMap('/');
sourceMap.addRawMappings(map);

let mapData = sourceMap.getMap();
Expand Down Expand Up @@ -546,7 +546,7 @@ describe('sourcemaps', function() {
assert.equal(map.file, 'style.css.map');
assert(raw.includes('/*# sourceMappingURL=style.css.map */'));

let sourceMap = new SourceMap();
let sourceMap = new SourceMap('/');
sourceMap.addRawMappings(map);

let input = await inputFS.readFile(
Expand Down Expand Up @@ -601,7 +601,7 @@ describe('sourcemaps', function() {
assert.equal(map.file, 'style.css.map');
assert(raw.includes('/*# sourceMappingURL=style.css.map */'));

let sourceMap = new SourceMap();
let sourceMap = new SourceMap('/');
sourceMap.addRawMappings(map);

let mapData = sourceMap.getMap();
Expand Down Expand Up @@ -703,7 +703,7 @@ describe('sourcemaps', function() {
assert.equal(map.file, 'style.css.map');
assert(raw.includes('/*# sourceMappingURL=style.css.map */'));

let sourceMap = new SourceMap();
let sourceMap = new SourceMap('/');
sourceMap.addRawMappings(map);

let mapData = sourceMap.getMap();
Expand Down Expand Up @@ -758,7 +758,7 @@ describe('sourcemaps', function() {
assert.equal(map.file, 'style.css.map');
assert(raw.includes('/*# sourceMappingURL=style.css.map */'));

let sourceMap = new SourceMap();
let sourceMap = new SourceMap('/');
sourceMap.addRawMappings(map);

let mapData = sourceMap.getMap();
Expand Down Expand Up @@ -840,7 +840,7 @@ describe('sourcemaps', function() {
assert.equal(map.file, 'style.css.map');
assert(raw.includes('/*# sourceMappingURL=style.css.map */'));

let sourceMap = new SourceMap();
let sourceMap = new SourceMap('/');
sourceMap.addRawMappings(map);

let mapData = sourceMap.getMap();
Expand Down
4 changes: 2 additions & 2 deletions packages/core/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@parcel/diagnostic": "2.0.0-beta.1",
"@parcel/logger": "2.0.0-beta.1",
"@parcel/markdown-ansi": "2.0.0-beta.1",
"@parcel/source-map": "2.0.0-alpha.4.13",
"@parcel/source-map": "2.0.0-alpha.4.15",
"ansi-html": "^0.0.7",
"chalk": "^2.4.2",
"clone": "^2.1.1",
Expand All @@ -44,4 +44,4 @@
"@babel/plugin-transform-flow-strip-types": "^7.2.0",
"random-int": "^1.0.0"
}
}
}
2 changes: 1 addition & 1 deletion packages/core/utils/src/generateBuildMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function getSourcemapSizes(
}

let rawMap = mapUrlData.map;
let sourceMap = new SourceMap();
let sourceMap = new SourceMap(projectRoot);
sourceMap.addRawMappings(rawMap);
let parsedMapData = sourceMap.getMap();

Expand Down
4 changes: 2 additions & 2 deletions packages/core/utils/src/sourcemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ export async function loadSourceMap(
mapSourceRoot = path.join(mapSourceRoot, foundMap.map.sourceRoot);
}

let sourcemapInstance = new SourceMap();
let sourcemapInstance = new SourceMap(options.projectRoot);
sourcemapInstance.addRawMappings({
...foundMap.map,
sources: foundMap.map.sources.map(s => {
return path.relative(options.projectRoot, path.join(mapSourceRoot, s));
return path.join(mapSourceRoot, s);
}),
});
return sourcemapInstance;
Expand Down
10 changes: 3 additions & 7 deletions packages/core/utils/test/sourcemap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ describe('loadSourceMap', () => {
assert(!!map);

let parsedMap = map.getMap();
assert.deepEqual(parsedMap.sources, [
path.normalize('input/sourcemap/referenced.js'),
]);
assert.deepEqual(parsedMap.sources, ['./input/sourcemap/referenced.js']);
assert.deepEqual(parsedMap.names, ['hello', 'l', 'o', 'console', 'log']);
assert.deepEqual(parsedMap.mappings, [
{
Expand Down Expand Up @@ -189,9 +187,7 @@ describe('loadSourceMap', () => {
assert(!!map);

let parsedMap = map.getMap();
assert.deepEqual(parsedMap.sources, [
path.normalize('input/sourcemap/referenced.js'),
]);
assert.deepEqual(parsedMap.sources, ['./input/sourcemap/referenced.js']);
});

it('Should remap sources when using sourceRoot', async () => {
Expand All @@ -206,6 +202,6 @@ describe('loadSourceMap', () => {
assert(!!map);

let parsedMap = map.getMap();
assert.deepEqual(parsedMap.sources, [path.normalize('input/source.js')]);
assert.deepEqual(parsedMap.sources, ['./input/source.js']);
});
});
2 changes: 1 addition & 1 deletion packages/optimizers/cssnano/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"dependencies": {
"@parcel/plugin": "2.0.0-beta.1",
"@parcel/source-map": "2.0.0-alpha.4.13",
"@parcel/source-map": "2.0.0-alpha.4.15",
"cssnano": "^4.1.10",
"postcss": "^7.0.5"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/optimizers/cssnano/src/CSSNanoOptimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default (new Optimizer({

let map;
if (result.map != null) {
map = new SourceMap();
map = new SourceMap(options.projectRoot);
map.addRawMappings(result.map.toJSON());
}

Expand Down
4 changes: 2 additions & 2 deletions packages/optimizers/terser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"dependencies": {
"@parcel/diagnostic": "2.0.0-beta.1",
"@parcel/plugin": "2.0.0-beta.1",
"@parcel/source-map": "2.0.0-alpha.4.13",
"@parcel/source-map": "2.0.0-alpha.4.15",
"@parcel/utils": "2.0.0-beta.1",
"nullthrows": "^1.1.1",
"terser": "^5.2.0"
},
"peerDependencies": {
"@parcel/core": "^2.0.0-alpha.3.1"
}
}
}
2 changes: 1 addition & 1 deletion packages/optimizers/terser/src/TerserOptimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default (new Optimizer({
let sourceMap = null;
let minifiedContents: string = nullthrows(result.code);
if (result.map && typeof result.map !== 'string') {
sourceMap = new SourceMap();
sourceMap = new SourceMap(options.projectRoot);
sourceMap.addRawMappings(result.map);
let sourcemapReference = await getSourceMapReference(sourceMap);
if (sourcemapReference) {
Expand Down
2 changes: 1 addition & 1 deletion packages/packagers/css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"@parcel/plugin": "2.0.0-beta.1",
"@parcel/source-map": "2.0.0-alpha.4.13",
"@parcel/source-map": "2.0.0-alpha.4.15",
"@parcel/utils": "2.0.0-beta.1"
}
}
2 changes: 1 addition & 1 deletion packages/packagers/css/src/CSSPackager.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default (new Packager({

let outputs = await queue.run();
let contents = '';
let map = new SourceMap();
let map = new SourceMap(options.projectRoot);
let lineOffset = 0;
for (let [asset, code, mapBuffer] of outputs) {
contents += code + '\n';
Expand Down
2 changes: 1 addition & 1 deletion packages/packagers/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@babel/traverse": "^7.2.3",
"@parcel/plugin": "2.0.0-beta.1",
"@parcel/scope-hoisting": "2.0.0-beta.1",
"@parcel/source-map": "2.0.0-alpha.4.13",
"@parcel/source-map": "2.0.0-alpha.4.15",
"@parcel/utils": "2.0.0-beta.1",
"nullthrows": "^1.1.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/packagers/js/src/JSPackager.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default (new Packager({
let assets = '';
let i = 0;
let first = true;
let map = new SourceMap();
let map = new SourceMap(options.projectRoot);

let prefix = getPrefix(bundle, bundleGraph);
let lineOffset = countLines(prefix);
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/babel-ast-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@babel/generator": "^7.0.0",
"@babel/parser": "^7.0.0",
"@parcel/source-map": "2.0.0-alpha.4.13",
"@parcel/source-map": "2.0.0-alpha.4.15",
"@parcel/utils": "2.0.0-beta.1"
}
}
2 changes: 1 addition & 1 deletion packages/shared/babel-ast-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export async function generate({
let map = null;
let originalSourceMap = await asset.getMap();
if (generated.rawMappings) {
map = new SourceMap();
map = new SourceMap(options.projectRoot);
map.addIndexedMappings(generated.rawMappings);
if (originalSourceMap) {
map.extends(originalSourceMap.toBuffer());
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/scope-hoisting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@parcel/babel-ast-utils": "2.0.0-beta.1",
"@parcel/babylon-walk": "2.0.0-beta.1",
"@parcel/diagnostic": "2.0.0-beta.1",
"@parcel/source-map": "2.0.0-alpha.4.13",
"@parcel/source-map": "2.0.0-alpha.4.15",
"@parcel/utils": "2.0.0-beta.1",
"nullthrows": "^1.1.1"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/scope-hoisting/src/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function generate({

let map = null;
if (options.sourceMaps && rawMappings != null) {
map = new SourceMap();
map = new SourceMap(options.projectRoot);
map.addIndexedMappings(rawMappings);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/transformers/coffeescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"@parcel/plugin": "2.0.0-beta.1",
"@parcel/source-map": "2.0.0-alpha.4.13",
"@parcel/source-map": "2.0.0-alpha.4.15",
"@parcel/utils": "2.0.0-beta.1",
"coffeescript": "^2.0.3",
"nullthrows": "^1.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default (new Transformer({
if (options.sourceMaps) {
let map = null;
if (output.v3SourceMap) {
map = new SourceMap();
map = new SourceMap(options.projectRoot);
map.addRawMappings(JSON.parse(output.v3SourceMap));
}

Expand Down
2 changes: 1 addition & 1 deletion packages/transformers/css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"@parcel/plugin": "2.0.0-beta.1",
"@parcel/source-map": "2.0.0-alpha.4.13",
"@parcel/source-map": "2.0.0-alpha.4.15",
"@parcel/utils": "2.0.0-beta.1",
"postcss": "^7.0.5",
"postcss-value-parser": "^3.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/transformers/css/src/CSSTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export default (new Transformer({

let map;
if (result.map != null) {
map = new SourceMap();
map = new SourceMap(options.projectRoot);
map.addRawMappings(result.map.toJSON());
}

Expand Down
2 changes: 1 addition & 1 deletion packages/transformers/less/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"@parcel/plugin": "2.0.0-beta.1",
"@parcel/source-map": "2.0.0-alpha.4.13"
"@parcel/source-map": "2.0.0-alpha.4.15"
},
"devDependencies": {
"less": "^3.9.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/transformers/less/src/LessTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default (new Transformer({
}

if (result.map != null) {
let map = new SourceMap();
let map = new SourceMap(options.projectRoot);
let rawMap = JSON.parse(result.map);
map.addRawMappings({
...rawMap,
Expand Down
2 changes: 1 addition & 1 deletion packages/transformers/sass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@parcel/fs": "2.0.0-beta.1",
"@parcel/plugin": "2.0.0-beta.1",
"@parcel/source-map": "2.0.0-alpha.4.13",
"@parcel/source-map": "2.0.0-alpha.4.15",
"@parcel/utils": "2.0.0-beta.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/transformers/sass/src/SassTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default (new Transformer({
}

if (result.map != null) {
let map = new SourceMap();
let map = new SourceMap(options.projectRoot);
map.addRawMappings(JSON.parse(result.map));
asset.setMap(map);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/transformers/typescript-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"@parcel/plugin": "2.0.0-beta.1",
"@parcel/source-map": "2.0.0-alpha.4.13",
"@parcel/source-map": "2.0.0-alpha.4.15",
"@parcel/ts-utils": "2.0.0-beta.1",
"nullthrows": "^1.1.1"
},
Expand Down
Loading

0 comments on commit ac21b52

Please sign in to comment.