Skip to content

Commit

Permalink
Generate source map files with long extentions (e.g. .js.map) (#2472)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillrogovoy authored and DeMoorJasper committed Dec 27, 2018
1 parent 0fac29e commit 0c0563d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/core/integration-tests/test/css.js
Expand Up @@ -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',
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('css', function() {
childBundles: []
},
{
name: 'index.map',
name: 'index.js.map',
type: 'map'
}
]
Expand Down
20 changes: 10 additions & 10 deletions packages/core/integration-tests/test/sourcemaps.js
Expand Up @@ -14,7 +14,7 @@ describe('sourcemaps', function() {
assets: ['index.js'],
childBundles: [
{
name: 'index.map',
name: 'index.js.map',
type: 'map'
}
]
Expand All @@ -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);
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('sourcemaps', function() {
assets: ['index.ts'],
childBundles: [
{
name: 'index.map',
name: 'index.js.map',
type: 'map'
}
]
Expand All @@ -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);

Expand All @@ -88,7 +88,7 @@ describe('sourcemaps', function() {
assets: ['index.ts', 'local.ts'],
childBundles: [
{
name: 'index.map',
name: 'index.js.map',
type: 'map'
}
]
Expand All @@ -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);

Expand All @@ -117,7 +117,7 @@ describe('sourcemaps', function() {
assets: ['index.js', 'local.js', 'util.js'],
childBundles: [
{
name: 'index.map',
name: 'index.js.map',
type: 'map'
}
]
Expand All @@ -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);

Expand All @@ -149,7 +149,7 @@ describe('sourcemaps', function() {
assets: ['index.js', 'local.js', 'util.js'],
childBundles: [
{
name: 'index.map',
name: 'index.js.map',
type: 'map'
}
]
Expand All @@ -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);

Expand Down
15 changes: 13 additions & 2 deletions packages/core/parcel-bundler/src/Bundle.js
Expand Up @@ -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
);
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0c0563d

Please sign in to comment.