ゆず日記

戦う Vimmer 兼 Dvorakユーザ 兼 Kinesisユーザ 兼 おぺらー が戦わないブログ

jQueryを自前でbuildした話。

jQuery1.10.2にバージョンアップしたら、event.preventDefault()を使っている箇所がChrome

event.returnValue is deprecated. Please use the standard event.preventDefault() instead.

みたいなWarningが出るようになった。

調べてみた所、以下のチケットに書いてあるバグで既に修正済み。


とはいえ、修正後のコードが含まれたバージョンはまだ配布されてないので、自前で1.10.2 + change setをbuildした。


追記 (2013/11/23):
http://code.jquery.com/jquery/ に修正済みの2.1.0-beta1〜, 1.11.0-beta1〜 が公開されているので, 必ずしもbuildする必要はありません.

手順

何はともあれgithubからjQueryを持ってくる。

$ git clone git://github.com/jquery/jquery
$ cd jquery/

軽くtig (git log)した所、masterには2.x系しか入ってなさげなので、他ブランチを見てみる。

$ git branch -a
* master
  remotes/origin/#13388
  remotes/origin/1.8-stable
  remotes/origin/1.9-stable
  remotes/origin/1.x-master
  remotes/origin/HEAD -> origin/master
  remotes/origin/ajax-script-2.0
  remotes/origin/ajax-unit
  remotes/origin/master

あー、1.x-master がそれっぽいなーってことでこのリモートブランチも持ってくる。

$ git checkout -b 1.x-master origin/1.x-master

logみると以下のように [1.10.2]のタグも付いてるのでビンゴ。

...
2013-07-04 13:25 Timmy Willison     o Update sizzle to 1.10.3-pre
2013-07-03 09:49 Dave Methvin       o Updating the source version to 1.10.3-pre
2013-07-03 09:48 Dave Methvin       o [1.10.2] Tagging the 1.10.2 release.
2013-07-03 09:39 Timmy Willison     o Update Sizzle to version 1.10.2
2013-07-02 16:12 Dave Methvin       o Change the changelog header style
...

HEADを1.10.2タグの所まで戻す。

$ git checkout 1.10.2
Note: checking out '1.10.2'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 3b0b953... Tagging the 1.10.2 release.

https://github.com/jquery/jquery/commit/4671ef15c2d62962048fd4863911146fcc085f26 の差分だけcherry-pickする。

$ git cherry-pick 4671ef1 # commit idは途中まででもOK
error: could not apply 4671ef1... Fix #14282. Don't fondle getPreventDefault if preventDefault exists. Close gh-1365.
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

なんか怒られた。

$ git status
# HEAD detached at 1.10.2
# You are currently cherry-picking.
#   (fix conflicts and run "git cherry-pick --continue")
#   (use "git cherry-pick --abort" to cancel the cherry-pick operation)
#
# Unmerged paths:
#   (use "git add <file>..." to mark resolution)
#
#       both modified:      src/event.js
#
no changes added to commit (use "git add" and/or "git commit -a")


src/event.jsにconflictが起きているのでそれを修正する。

$ vi src/event.js

		// Events bubbling up the document may have been marked as prevented
		// by a handler lower down the tree; reflect the correct value.
<<<<<<< HEAD
		this.isDefaultPrevented = ( src.defaultPrevented || src.returnValue === false ||
			src.getPreventDefault && src.getPreventDefault() ) ? returnTrue : returnFalse;
=======
		this.isDefaultPrevented = src.defaultPrevented ||
				// Support: Android < 4.0
				src.defaultPrevented === undefined &&
				src.getPreventDefault && src.getPreventDefault() ?
			returnTrue :
			returnFalse;
>>>>>>> 4671ef1... Fix #14282. Don't fondle getPreventDefault if preventDefault exists. Close gh-1365.

<<<<<<< HEAD から ======= の箇所を削除して cherry-pickを続ける

$ git add -u
$ git cherry-pick --continue
[detached HEAD 7d7be73] Fix #14282. Don't fondle getPreventDefault if preventDefault exists. Close gh-1365.
 Author: Dave Methvin <dave.methvin@gmail.com>
 1 file changed, 6 insertions(+), 2 deletions(-)

出来た。お次にbuild

$ npm install # 要node.js
$ grunt # 要grunt-cli

npm installで、buildに必要なpackageのインストール。
grunt でbulid開始。「grunt?なんぞ?」って人はGrunt で livereload 環境を作ったお話。 - ゆず日記をどうぞ。

特に問題なければ、dist/以下にjquery.js, jquery.min.js, jquery.min.map が生成されている。
vimdiffでもchange setの差分の所だけ変更されているのを確認。

f:id:Yuzuemon:20131010025239p:plain

お疲れ様でした。