Skip to content
Permalink
Browse files

Fix #13776: Add banner before generating source map. Close gh-1246.

  • Loading branch information...
gibson042 committed Apr 18, 2013
1 parent aae7abf commit 9d16fe6283667396094d49559a37fc672c06252c
Showing with 51 additions and 20 deletions.
  1. +50 −19 Gruntfile.js
  2. +1 −1 package.json
@@ -41,7 +41,7 @@ module.exports = function( grunt ) {
srcFile: "src/sizzle/dist/sizzle.js"
},
build: {
all:{
all: {
dest: "dist/jquery.js",
src: [
"src/intro.js",
@@ -105,14 +105,31 @@ module.exports = function( grunt ) {
tasks: "dev"
},

"pre-uglify": {
all: {
files: {
"dist/jquery.pre-min.js": [ "dist/jquery.js" ]
},
options: {
banner: "/*! jQuery v<%= pkg.version %> | " +
"(c) 2005, 2013 jQuery Foundation, Inc. | " +

This comment has been minimized.

Copy link
@jdalton

jdalton Sep 20, 2013

Member

The copyright dates seem off. jQuery wasn't released until 2006 and the foundation formed a bit later. I know in the foundation history page it mentions hints of a lib, but it didn't materialize until 2006.

This comment has been minimized.

Copy link
@scottgonzalez

scottgonzalez Sep 20, 2013

Member

The first release was 2006, but the first publicly available code that was copyright John Resig is 2005. While old releases of jQuery were released with John owning the copyright, he has since transferred the rights to the jQuery Foundation. This makes whatever code from 2005 that still exists here copyright jQuery Foundation.

This comment has been minimized.

Copy link
@jdalton

jdalton Sep 20, 2013

Member

Ah nice. Do you have a reference for the code available in 2005 (the reference in the blog post from 05 was pseudo code)?

This comment has been minimized.

Copy link
@scottgonzalez

scottgonzalez Sep 20, 2013

Member

Hmm...the earliest public sharing of code I can find is indeed from 2006. The 2005 date may just be a mistake from the discussion with our lawyer:

Because jQuery has multiple versions we should use the original date for jQuery (2005?) and then the current year for that version.

The rest of the discussion then uses 2005 as a definitive date, followed by this commit two months later.

@joelgkinney Can you confirm whether we should use the date of first implementation or date of first public availability?
@dmethvin Can you confirm that 2005 came from that discussion?

This comment has been minimized.

Copy link
@dmethvin

dmethvin Sep 20, 2013

Member

The first announcement was January 2006 but some of the code concepts at least were discussed on John's blog during 2005; there may have been some public discussion of the code that year: http://ejohn.org/blog/selectors-in-javascript/

This comment has been minimized.

Copy link
@jdalton

jdalton Sep 20, 2013

Member

@dmethvin The snippets from that blog post are referred to as "a syntactical mock-up for how [Resig though] ‘Behaviour’ could’ve been implemented". I don't see any real working code at that point, just mock ups.

This comment has been minimized.

Copy link
@dmethvin

dmethvin Sep 20, 2013

Member

I agree with that, I was just pointing out that John may have shown it publicly before December 31 2005. Is there any harm/issue with having the copyright encompass 2005 when the code was originally started, vs when it may have been publicly shown first in January 2006?

This comment has been minimized.

Copy link
@jdalton

jdalton Sep 20, 2013

Member

Is there any harm/issue with having the copyright encompass 2005 when the code was originally started, vs when it may have been publicly shown first in January 2006?

Beats me hehe :D
Was curious more than anything. Yay Fridays! 👯

This comment has been minimized.

Copy link
@scottgonzalez

scottgonzalez Sep 20, 2013

Member

Copyright law is a funny thing, and it seems like even lawyers tend to disagree on what's actually required in the copyright line. That's why I pinged @joelgkinney, because we're just going to do whatever he says 🐑

This comment has been minimized.

Copy link
@curiousdannii

curiousdannii Sep 21, 2013

You don't actually need to include the years in a copyright statement. For that matter you don't need a copyright statement. But even so, when he owned the copyrights they lasted until his death+70, so the years don't matter. Now that it's transferred to a corporation it's 95 years after publication, so only the last year is useful. Personally, I normally use a dash.

This comment has been minimized.

Copy link
@jdalton

jdalton Sep 21, 2013

Member

I love how all the weekend lawyers pop out of the woodwork lol.

This comment has been minimized.

Copy link
@curiousdannii

This comment has been minimized.

Copy link
@scottgonzalez

scottgonzalez Sep 22, 2013

Member

I love how all the weekend lawyers pop out of the woodwork

And without a single IANAL warning :-P

The comment from @joelgkinney closes this discussion though; there's no action that needs to be taken.

This comment has been minimized.

Copy link
@jdalton

jdalton Sep 22, 2013

Member

@scottgonzalez I guess it depends on what "first implementation" means. If it means released software & not just something equivalent to writings on a napkin then we're back to the same issue.

This comment has been minimized.

Copy link
@dmethvin

dmethvin Sep 22, 2013

Member

What problem are we trying to solve here? Do we lose all rights to the copyright if we're off by a few months?

This comment has been minimized.

Copy link
@jdalton

jdalton Sep 22, 2013

Member

What problem are we trying to solve here? Do we lose all rights to the copyright if we're off by a few months?

It's an entire year. It's common knowledge that Prototype and others were out in 2005 but not jQuery. By shifting the copyright year back 1 entire year it's an attempt to rewrite history. jQuery already has the lion's share of market I do not understand getting sloppy with the copyright. If jQuery didn't release in 2005 I don't think it should claim it, plain and simple.

This comment has been minimized.

Copy link
@dmethvin

dmethvin Sep 22, 2013

Member

@jdalton according to our lawyer @joelgkinney who weighed in above, the date we want is the date of the first implementation. I think we can be honest that at least some of the initial implementation existed on December 31 2005, since @jeresig announced it on January 14 2006. Heck, two the examples John uses in his August 2005 blog post still work to this day.

This comment has been minimized.

Copy link
@jdalton
"jquery.org/license\n" +
"//@ sourceMappingURL=jquery.min.map\n" +
"*/"
}
}
},
uglify: {
all: {
files: {
"dist/jquery.min.js": [ "dist/jquery.js" ]
"dist/jquery.min.js": [ "dist/jquery.pre-min.js" ]
},
options: {
banner: "/*! jQuery v<%= pkg.version %> | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license */",
// Keep our hard-coded banner
preserveComments: "some",
sourceMap: "dist/jquery.min.map",
sourceMappingURL: "jquery.min.map",
report: "min",
beautify: {
ascii_only: true
},
@@ -225,7 +242,6 @@ module.exports = function( grunt ) {
grunt.log.writeln( "File '" + name + "' created." );
});


// Special "alias" task to make custom build creation less grawlix-y
grunt.registerTask( "custom", function() {
var done = this.async(),
@@ -245,7 +261,7 @@ module.exports = function( grunt ) {

grunt.util.spawn({
cmd: process.platform === "win32" ? "grunt.cmd" : "grunt",
args: [ "build:*:*:" + modules, "uglify", "dist" ]
args: [ "build:*:*:" + modules, "pre-uglify", "uglify", "dist" ]
}, function( err, result ) {
if ( err ) {
grunt.verbose.error();
@@ -260,7 +276,6 @@ module.exports = function( grunt ) {
});

// Special concat/build task to handle various jQuery build requirements
//
grunt.registerMultiTask(
"build",
"Concatenate source (include/exclude modules with +/- flags), embed date/version",
@@ -438,7 +453,7 @@ module.exports = function( grunt ) {
nonascii = false;

distpaths.forEach(function( filename ) {
var i, c, map,
var i, c,
text = fs.readFileSync( filename, "utf8" );

// Ensure files use only \n for line endings, not \r\n
@@ -466,19 +481,17 @@ module.exports = function( grunt ) {
if ( /\.map$/.test( filename ) ) {
text = text.replace( /"dist\//g, "\"" );
fs.writeFileSync( filename, text, "utf-8" );

// Use our hard-coded sourceMap directive instead of the autogenerated one (#13274; #13776)
} else if ( /\.min\.js$/.test( filename ) ) {
// Wrap sourceMap directive in multiline comments (#13274)
text = text.replace( /\n?(\/\/@\s*sourceMappingURL=)(.*)/,
function( _, directive, path ) {
map = "\n" + directive + path.replace( /^dist\//, "" );
return "";
i = 0;
text = text.replace( /(?:\/\*|)\n?\/\/@\s*sourceMappingURL=.*(\n\*\/|)/g,
function( match ) {
if ( i++ ) {
return "";
}
return match;
});
if ( map ) {
text = text.replace( /(^\/\*[\w\W]*?)\s*\*\/|$/,
function( _, comment ) {
return ( comment || "\n/*" ) + map + "\n*/";
});
}
fs.writeFileSync( filename, text, "utf-8" );
}

@@ -499,6 +512,24 @@ module.exports = function( grunt ) {
return !nonascii;
});

// Work around grunt-contrib-uglify sourceMap issues (jQuery #13776)
grunt.registerMultiTask( "pre-uglify", function() {
var banner = this.options().banner;

this.files.forEach(function( mapping ) {
// Join src
var input = mapping.src.map(function( file ) {
var contents = grunt.file.read( file );

// Strip banners
return contents.replace( /^\/\*!(?:.|\n)*?\*\/\n?/gm, "" );
}).join("\n");

// Write temp file (with optional banner)
grunt.file.write( mapping.dest, ( banner || "" ) + input );
});
});

// Load grunt tasks from NPM packages
grunt.loadNpmTasks("grunt-compare-size");
grunt.loadNpmTasks("grunt-git-authors");
@@ -508,7 +539,7 @@ module.exports = function( grunt ) {
grunt.loadNpmTasks("grunt-contrib-uglify");

// Default grunt
grunt.registerTask( "default", [ "update_submodules", "selector", "build:*:*", "jshint", "uglify", "dist:*", "compare_size" ] );
grunt.registerTask( "default", [ "update_submodules", "selector", "build:*:*", "jshint", "pre-uglify", "uglify", "dist:*", "compare_size" ] );

// Short list as a high frequency watch task
grunt.registerTask( "dev", [ "selector", "build:*:*", "jshint" ] );
@@ -28,7 +28,7 @@
"grunt-update-submodules": "0.2.0",
"grunt-contrib-watch": "0.3.1",
"grunt-contrib-jshint": "0.3.0",
"grunt-contrib-uglify": "0.1.2",
"grunt-contrib-uglify": "0.2.0",
"grunt": "0.4.1",
"gzip-js": "0.3.1",
"testswarm": "0.2.2"

1 comment on commit 9d16fe6

@WebDevCA

This comment has been minimized.

Copy link

commented on 9d16fe6 Sep 20, 2013

In my understanding of copyright law it would be okay to record "2005" in the instance of jQuery.

Please sign in to comment.
You can’t perform that action at this time.