From b9a869346293316ed40d8515dfdeb0fd98b13030 Mon Sep 17 00:00:00 2001 From: Kirill Rogovoy Date: Thu, 27 Dec 2018 16:05:48 +0200 Subject: [PATCH] Generate source map files with long extentions (e.g. .js.map) --- packages/core/integration-tests/test/css.js | 4 ++-- .../core/integration-tests/test/sourcemaps.js | 20 +++++++++---------- packages/core/parcel-bundler/src/Bundle.js | 15 ++++++++++++-- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/packages/core/integration-tests/test/css.js b/packages/core/integration-tests/test/css.js index 44be2354224..ac8db41d712 100644 --- a/packages/core/integration-tests/test/css.js +++ b/packages/core/integration-tests/test/css.js @@ -12,7 +12,7 @@ describe('css', function() { assets: ['index.js', 'index.css', 'local.js', 'local.css'], childBundles: [ { - name: 'index.map' + name: 'index.js.map' }, { name: 'index.css', @@ -88,7 +88,7 @@ describe('css', function() { childBundles: [] }, { - name: 'index.map', + name: 'index.js.map', type: 'map' } ] diff --git a/packages/core/integration-tests/test/sourcemaps.js b/packages/core/integration-tests/test/sourcemaps.js index 4eafe6b6e05..dad3d802d18 100644 --- a/packages/core/integration-tests/test/sourcemaps.js +++ b/packages/core/integration-tests/test/sourcemaps.js @@ -14,7 +14,7 @@ describe('sourcemaps', function() { assets: ['index.js'], childBundles: [ { - name: 'index.map', + name: 'index.js.map', type: 'map' } ] @@ -24,7 +24,7 @@ describe('sourcemaps', function() { path.join(__dirname, '/dist/index.js') )).toString(); let map = (await fs.readFile( - path.join(__dirname, '/dist/index.map') + path.join(__dirname, '/dist/index.js.map') )).toString(); mapValidator(raw, map); let mapObject = JSON.parse(map); @@ -59,7 +59,7 @@ describe('sourcemaps', function() { assets: ['index.ts'], childBundles: [ { - name: 'index.map', + name: 'index.js.map', type: 'map' } ] @@ -69,7 +69,7 @@ describe('sourcemaps', function() { path.join(__dirname, '/dist/index.js') )).toString(); let map = (await fs.readFile( - path.join(__dirname, '/dist/index.map') + path.join(__dirname, '/dist/index.js.map') )).toString(); mapValidator(raw, map); @@ -88,7 +88,7 @@ describe('sourcemaps', function() { assets: ['index.ts', 'local.ts'], childBundles: [ { - name: 'index.map', + name: 'index.js.map', type: 'map' } ] @@ -98,7 +98,7 @@ describe('sourcemaps', function() { path.join(__dirname, '/dist/index.js') )).toString(); let map = (await fs.readFile( - path.join(__dirname, '/dist/index.map') + path.join(__dirname, '/dist/index.js.map') )).toString(); mapValidator(raw, map); @@ -117,7 +117,7 @@ describe('sourcemaps', function() { assets: ['index.js', 'local.js', 'util.js'], childBundles: [ { - name: 'index.map', + name: 'index.js.map', type: 'map' } ] @@ -127,7 +127,7 @@ describe('sourcemaps', function() { path.join(__dirname, '/dist/index.js') )).toString(); let map = (await fs.readFile( - path.join(__dirname, '/dist/index.map') + path.join(__dirname, '/dist/index.js.map') )).toString(); mapValidator(raw, map); @@ -149,7 +149,7 @@ describe('sourcemaps', function() { assets: ['index.js', 'local.js', 'util.js'], childBundles: [ { - name: 'index.map', + name: 'index.js.map', type: 'map' } ] @@ -159,7 +159,7 @@ describe('sourcemaps', function() { path.join(__dirname, '/dist/index.js') )).toString(); let map = (await fs.readFile( - path.join(__dirname, '/dist/index.map') + path.join(__dirname, '/dist/index.js.map') )).toString(); mapValidator(raw, map); diff --git a/packages/core/parcel-bundler/src/Bundle.js b/packages/core/parcel-bundler/src/Bundle.js index e4dbf718776..1847eb3eaec 100644 --- a/packages/core/parcel-bundler/src/Bundle.js +++ b/packages/core/parcel-bundler/src/Bundle.js @@ -64,7 +64,11 @@ class Bundle { type, Path.join( Path.dirname(this.name), - Path.basename(this.name, Path.extname(this.name)) + '.' + type + // keep the original extension for source map files, so we have + // .js.map instead of just .map + type === 'map' + ? Path.basename(this.name) + '.' + type + : Path.basename(this.name, Path.extname(this.name)) + '.' + type ), this ); @@ -110,7 +114,14 @@ class Bundle { getHashedBundleName(contentHash) { // If content hashing is enabled, generate a hash from all assets in the bundle. // Otherwise, use a hash of the filename so it remains consistent across builds. - let ext = Path.extname(this.name); + let basename = Path.basename(this.name); + + let ext = Path.extname(basename); + if (this.type === 'map') { + // Using this instead of Path.extname because the source map files have long + // extensions like '.js.map' but extname only return the last piece (.map). + ext = basename.substring(basename.indexOf('.')); + } let hash = (contentHash ? this.getHash() : Path.basename(this.name, ext)