From 30627a1ce3c915c76fb950605c9e65232912cd40 Mon Sep 17 00:00:00 2001 From: lustoykov Date: Thu, 14 Feb 2019 14:47:20 +0100 Subject: [PATCH] Fix sourceMappingURL for bundles with multiple entry points --- .../a/index.js | 1 + .../b/index.js | 1 + .../sourcemap-sourcemappingurl/index.js | 1 + .../core/integration-tests/test/sourcemaps.js | 30 +++++++++++++++++++ .../src/packagers/JSPackager.js | 2 +- 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 packages/core/integration-tests/test/integration/sourcemap-sourcemappingurl-multiple-entrypoints/a/index.js create mode 100644 packages/core/integration-tests/test/integration/sourcemap-sourcemappingurl-multiple-entrypoints/b/index.js create mode 100644 packages/core/integration-tests/test/integration/sourcemap-sourcemappingurl/index.js diff --git a/packages/core/integration-tests/test/integration/sourcemap-sourcemappingurl-multiple-entrypoints/a/index.js b/packages/core/integration-tests/test/integration/sourcemap-sourcemappingurl-multiple-entrypoints/a/index.js new file mode 100644 index 00000000000..d6357c10e58 --- /dev/null +++ b/packages/core/integration-tests/test/integration/sourcemap-sourcemappingurl-multiple-entrypoints/a/index.js @@ -0,0 +1 @@ +console.log('hello1'); \ No newline at end of file diff --git a/packages/core/integration-tests/test/integration/sourcemap-sourcemappingurl-multiple-entrypoints/b/index.js b/packages/core/integration-tests/test/integration/sourcemap-sourcemappingurl-multiple-entrypoints/b/index.js new file mode 100644 index 00000000000..a023d214778 --- /dev/null +++ b/packages/core/integration-tests/test/integration/sourcemap-sourcemappingurl-multiple-entrypoints/b/index.js @@ -0,0 +1 @@ +console.log('hello2'); \ No newline at end of file diff --git a/packages/core/integration-tests/test/integration/sourcemap-sourcemappingurl/index.js b/packages/core/integration-tests/test/integration/sourcemap-sourcemappingurl/index.js new file mode 100644 index 00000000000..ea17b22ee52 --- /dev/null +++ b/packages/core/integration-tests/test/integration/sourcemap-sourcemappingurl/index.js @@ -0,0 +1 @@ +console.log('hello'); \ No newline at end of file diff --git a/packages/core/integration-tests/test/sourcemaps.js b/packages/core/integration-tests/test/sourcemaps.js index 233915d50ab..4ccd418ab33 100644 --- a/packages/core/integration-tests/test/sourcemaps.js +++ b/packages/core/integration-tests/test/sourcemaps.js @@ -314,4 +314,34 @@ describe('sourcemaps', function() { ); mapValidator(jsOutput, map); }); + + it('should create correct sourceMappingURL', async function() { + const b = await bundle( + path.join(__dirname, '/integration/sourcemap-sourcemappingurl/index.js') + ); + + const jsOutput = await fs.readFile(b.name, 'utf8'); + assert(jsOutput.includes('//# sourceMappingURL=/index.js.map')); + }); + + it('should create correct sourceMappingURL with multiple entrypoints', async function() { + const b = await bundle([ + path.join( + __dirname, + '/integration/sourcemap-sourcemappingurl-multiple-entrypoints/a/index.js' + ), + path.join( + __dirname, + '/integration/sourcemap-sourcemappingurl-multiple-entrypoints/b/index.js' + ) + ]); + + const bundle1 = [...b.childBundles][0]; + const bundle2 = [...b.childBundles][1]; + const jsOutput1 = await fs.readFile(bundle1.name, 'utf8'); + const jsOutput2 = await fs.readFile(bundle2.name, 'utf8'); + + assert(jsOutput1.includes('//# sourceMappingURL=/a/index.js.map')); + assert(jsOutput2.includes('//# sourceMappingURL=/b/index.js.map')); + }); }); diff --git a/packages/core/parcel-bundler/src/packagers/JSPackager.js b/packages/core/parcel-bundler/src/packagers/JSPackager.js index c7abdbc9970..a07ff3baf7e 100644 --- a/packages/core/parcel-bundler/src/packagers/JSPackager.js +++ b/packages/core/parcel-bundler/src/packagers/JSPackager.js @@ -239,7 +239,7 @@ class JSPackager extends Packager { if (mapBundle) { let mapUrl = urlJoin( this.options.publicURL, - path.basename(mapBundle.name) + path.relative(this.options.outDir, mapBundle.name) ); await this.write(`\n//# sourceMappingURL=${mapUrl}`); }