Skip to content

Commit b848766

Browse files
committed
Post-process map file so it has the right path.
1 parent 3e1589d commit b848766

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

Gruntfile.js

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module.exports = function( grunt ) {
44

55
var distpaths = [
66
"dist/jquery.js",
7-
"dist/jquery.min.js"
7+
"dist/jquery.min.js",
8+
"dist/jquery.min.map"
89
],
910
readOptionalJSON = function( filepath ) {
1011
var data = {};
@@ -96,7 +97,7 @@ module.exports = function( grunt ) {
9697
},
9798
options: {
9899
banner: "/*! jQuery v<%= pkg.version %> jquery.com | jquery.org/license */",
99-
sourceMap: "dist/jquery.source-map.js",
100+
sourceMap: "jquery.min.map",
100101
beautify: {
101102
ascii_only: true
102103
}
@@ -220,7 +221,7 @@ module.exports = function( grunt ) {
220221

221222
grunt.util.spawn({
222223
cmd: process.platform === "win32" ? "grunt.cmd" : "grunt",
223-
args: [ "build:*:*:" + modules, "uglify" ]
224+
args: [ "build:*:*:" + modules, "uglify", "dist" ]
224225
}, function( err, result ) {
225226
if ( err ) {
226227
grunt.verbose.error();
@@ -387,7 +388,7 @@ module.exports = function( grunt ) {
387388
grunt.log.writeln( "File '" + name + "' created." );
388389
});
389390

390-
// Allow custom dist file locations
391+
// Process files for distribution
391392
grunt.registerTask( "dist", function() {
392393
var flags, paths, stored;
393394

@@ -408,47 +409,43 @@ module.exports = function( grunt ) {
408409
nonascii = false;
409410

410411
distpaths.forEach(function( filename ) {
411-
var buf = fs.readFileSync( filename, "utf8" ),
412+
var text = fs.readFileSync( filename, "utf8" ),
412413
i, c;
413-
if ( buf.length !== Buffer.byteLength( buf, "utf8" ) ) {
414+
if ( text.length !== Buffer.byteLength( text, "utf8" ) ) {
414415
grunt.log.writeln( filename + ": Non-ASCII characters detected:" );
415-
for ( i = 0; i < buf.length; i++ ) {
416-
c = buf.charCodeAt( i );
416+
for ( i = 0; i < text.length; i++ ) {
417+
c = text.charCodeAt( i );
417418
if ( c > 127 ) {
418419
grunt.log.writeln( "- position " + i + ": " + c );
419-
grunt.log.writeln( "-- " + buf.substring( i - 20, i + 20 ) );
420+
grunt.log.writeln( "-- " + text.substring( i - 20, i + 20 ) );
420421
nonascii = true;
422+
break;
421423
}
422424
}
423425
}
424-
});
425-
if ( nonascii ) {
426-
return false;
427-
}
428426

429-
// Proceed only if there are actual
430-
// paths to write to
431-
if ( paths.length ) {
432-
433-
// 'distpaths' is declared at the top of the
434-
// module.exports function scope. It is an array
435-
// of default files that jQuery creates
436-
distpaths.forEach(function( filename ) {
437-
paths.forEach(function( path ) {
438-
var created;
439-
440-
if ( !/\/$/.test( path ) ) {
441-
path += "/";
442-
}
427+
// Modify map so that it points to files in the same folder;
428+
// see https://github.com/mishoo/UglifyJS2/issues/47
429+
if ( /\.map$/.test( filename ) ) {
430+
text = text.replace( /"dist\//g, "\"" );
431+
fs.writeFileSync( filename, text, "utf-8" );
432+
}
443433

444-
created = path + filename.replace( "dist/", "" );
434+
// Optionally copy dist files to other locations
435+
paths.forEach(function( path ) {
436+
var created;
445437

446-
grunt.file.write( created, grunt.file.read(filename) );
438+
if ( !/\/$/.test( path ) ) {
439+
path += "/";
440+
}
447441

448-
grunt.log.writeln( "File '" + created + "' created." );
449-
});
442+
created = path + filename.replace( "dist/", "" );
443+
grunt.file.write( created, text );
444+
grunt.log.writeln( "File '" + created + "' created." );
450445
});
451-
}
446+
});
447+
448+
return !nonascii;
452449
});
453450

454451
// Load grunt tasks from NPM packages

0 commit comments

Comments
 (0)