Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate source map files with long extentions (e.g. .js.map) #2472

Merged
merged 1 commit into from Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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