ããã«ã¡ã¯ãåç° (@t_wada) ã§ããæ¬æ¥ã¯ Node.js Advent Calendar ã® 7 æ¥ç®ã¨ãã¦ã Node.js ã§éçºããéã®è¨å®ãã¡ã¤ã« package.json
ã«ã¾ã¤ãã Tips ã«ã¤ãã¦æ¸ãããã¨æãã¾ãã
ã¯ããã«
ç§ã¯ããã¾ã§ power-assert ãçé ã«ãããã¤ã npm ã¢ã¸ã¥ã¼ã«ããªãªã¼ã¹ãã¦ãã¾ããã
Node.js ã使ã£ãéçºã«ã¯ãè¨å®ãã¡ã¤ã« package.json
ã®è¨è¿°ãå¿
è¦ã§ããç¹ã« npm ã¢ã¸ã¥ã¼ã«ãå
¬éããå ´åã«ã¯ãè¨å®ãã¹ãäºãèããã¹ãäºãããããå¢ãã¦ãã¾ããä»åã¯ã npm ã¢ã¸ã¥ã¼ã«ãä½ã£ã¦ããéç¨ã§å¦ãã package.json ã«é¢ãã Tips ã®ä¸ã§ããã¾ãç¥ããã¦ããªããã¤ãã¼æ°å³ãªãã®ãæãã¦ããããã¨æãã¾ãã
Tips1: package.json ã® files ãã£ã¼ã«ãã§ãã¯ã¤ããªã¹ã
éçºã«ã¯å¿
è¦ãªãã®ã®ãé
å¸ãã npm ã«ã¯å«ããããªããã£ã¬ã¯ããªããã¡ã¤ã«ãããã¨æãã¾ããä¾ãã° .idea
ãã£ã¬ã¯ããªã .vimrc.project
ã®ãããªã®ãããªéçºç°å¢åºæã®è¨å®ãã¡ã¤ã«ç¾¤ãæããããã§ãããããã®ãããªãã¡ã¤ã«éãé
å¸ã¢ã¸ã¥ã¼ã«ã«æ··å
¥ãã¦ãã¾ãã®ãé¿ãããããå¾æ¥ã§ã¯ .npmignore
ã¨ãããã¡ã¤ã«ã« npm ããé¤å¤ããããã¡ã¤ã«ãã¿ã¼ã³ãè¨è¿°ãã¦ãã¾ãããä¾ãã°ã次ã®ããã«æ¸ããã¾ãã
.git* .idea* /bower_components
ãã® .npmignore
ã¯ãè¨ããªãã°ãã©ãã¯ãªã¹ãã§ãããã©ãã¯ãªã¹ãã§ããã¨ãããã¨ã¯ãæªç¥ã®ãã¡ã¤ã«ã«å¯¾ãã¦ç¡é²åã«ãªããã¡ã§ãããã¨ãããã¨ãæå³ãã¦ãã¾ããä¾ãã°ä¸è¨ .npmignore
㯠IDEA æ´¾ã®äººã®ãã¡ã¤ã«ã®ããã§ããããã®äººã vim æ´¾ã«ä¹ãæã㦠.vimrc.project
ã .gitignore
ã«è¿½å ãããã®ã®ã .npmignore
ã«ã¯è¿½å ãå¿ããã¾ã¾ãªãªã¼ã¹ããã¨ã .vimrc.project
ã®å
¥ã£ã npm ã¢ã¸ã¥ã¼ã«ã®ã§ããããã§ããã¨ãã£ã¿ã®è¨å®ããããªãè¯ãããããã¾ãããããã£ã¨ãã©ã¤ãã¼ããªå
容ãæ¸ããã¦ãããã¡ã¤ã«ã ã£ããã©ãã§ãããã
ãã¯ããã©ãã¯ãªã¹ãã ãã§ã¯å±ããã®ã§ãã足ããªãã®ã¯ãã¯ã¤ããªã¹ããã¤ã¾ãé
å¸ãããã¡ã¤ã«ã ããè¨è¿°ã§ããæ¹æ³ã§ããããã§ç»å ´ããã®ã package.json
ã«è¨è¿°ãã files
ãã£ã¼ã«ãã§ãã
package.json ã® files
ãã£ã¼ã«ãã¯ãé
å¸ãã npm ã¢ã¸ã¥ã¼ã«ã«å«ããã¹ããã¡ã¤ã«ããã£ã¬ã¯ããªãè¨è¿°ãããã£ã¼ã«ãã§ãã¾ãã«ãã¯ã¤ããªã¹ãã¨ãã¦æ©è½ãã¾ããå
·ä½çã«ã¯ npm ã¢ã¸ã¥ã¼ã«ã«å«ãããã¡ã¤ã«åããã£ã¬ã¯ããªåãè¨è¿°ãã¾ãã
"files": [ "README.md", "index.js", "package.json", "lib", "test" ],
ä¸è¨ã®ããã«æ¸ãã¨ã README.md
, index.js
, package.json
ãã¡ã¤ã«ãåã³ lib
,test
ãã£ã¬ã¯ããªé
ä¸ãé
å¸ npm ã«å«ã¾ããããã«ãªããä»ã®ãã¡ã¤ã«ã¯é¤å¤ããã¾ãã
package.json ã® files
ãã£ã¼ã«ã㯠.npmignore
ãã¡ã¤ã«ã¨çµã¿åããããã¨ãã§ãã¾ããä¾ãã°ä¸è¨è¨å®ã§ test
ãã£ã¬ã¯ããªå
ã«é
å¸ç©ããã¯é¤å¤ããããã¡ã¤ã«ãããã¤ãããå ´åã¯ããã®ãã¡ã¤ã«éãé¤å¤ãããã¿ã¼ã³ã .npmignore
ã«æ¸ãã°ããã¯ã¤ããªã¹ãã¨ãã©ãã¯ãªã¹ãã®ã³ã³ãå®æã§ããåºæ¬çã« files
ãã£ã¼ã«ãã«ãã¯ã¤ããªã¹ããæ¸ãããã®ä¸ããåå¥ã«é¤å¤ããããã¿ã¼ã³ãããã° .npmignore
ã«æ¸ããã¨ããçµã¿åãããè¯ãã®ã§ã¯ãªããã¨æãã¾ãã
(追è¨: package.json ã® files
ã¯ãã¯ã¤ããªã¹ãã§ãã®ã§ã npm ã«å«ã¾ããã¹ãæ°è¦ãã¡ã¤ã«ãä½æããéã« files
ã«è¿½å ãå¿ããã¨ããã®ãã¡ã¤ã«ã¯é
å¸ãã npm ããæ¼ãããã¨ã«ãªã£ã¦ãã¾ãã¾ããã注æãã ãã)
Tips2: package.json ã®ãã£ã¼ã«ã並ã³é ã«æ©ãããããªã fixpack
npm ã¢ã¸ã¥ã¼ã«ã®éçºãé²ãã§ããã¨ã package.json
ãã¡ã¤ã«ã®ä¸èº«ãã ãã ã大ãããªã£ã¦ãã¾ãã
éçºåæ㯠name
, version
, description
, keywords
, main
, scripts
, author
, license
ãªã©ã®ãã£ã¼ã«ãã ãã ã£ã package.json ã«ã dependencies
, devDependencies
ã®ãããªä¾åã¢ã¸ã¥ã¼ã«å®ç¾©ãã bugs
, homepage
, repository
ã¨ãã£ã URL ã®å®ç¾©ãããã¦ãã¡ãã files
ãã£ã¼ã«ããå ãã£ã¦ããã¾ããããã« package.json ã«ã¯ browserify é¢ä¿ã®ãã£ã¼ã«ããããã³ãã¨ã³ãé¢ä¿ã®ãã£ã¼ã«ããªã©ããããç¨åº¦èªç±ã«å®ç¾©ãã¦è¿½å ã§ããã¨ãã(è¯ãæå³ã§ã®)èªç±ããããã¾ãã
è¤æ°ã®ããã¸ã§ã¯ããéçºãã¦ããã¨ãããããã£ã¼ã«ãã®ä¸¦ã³é ãªã©ãããã¸ã§ã¯ãã«ãã£ã¦ãã©ãã©ã«ãªã£ã¦ãã¦æ´çãé£ãããªã£ãããç°¡åã«ã³ãã¼ã§ããªããªã£ã¦ãã¾ããã ãã ãã¨æ··æ²ç¶æ ã«ãªã£ã¦ãã¾ãã package.json ã®è¦ç´ãããã£ã¼ã«ãã®ä¸¦ã³ã®åºæºã欲ãããªã£ã¦ããã¨ããã§ãã
ããã§ç»å ´ããã®ã fixpack ã§ãããã®ãã¼ã«ã¯ package.json ã®ä¸èº«ã
name
ãä¸çªæådescription
ãäºçªç®version
ãä¸çªç®author
ã åçªç®- æ®ãã®ãã£ã¼ã«ããã¢ã«ãã¡ãããé
ã«ä¸¦ã¹æ¿ãã¦ããã¾ããããã« dependencies
ã devDependencies
ã®ä¸èº«ãã¢ã«ãã¡ãããé ã«ä¸¦ã³æ¿ãã¦ããã¾ã(ãã㯠npm install --save
çã§ãã§ãã¾ãã)ã
fixpack ã使ãã° package.json å
ã®ä¸¦ã³ãæ©ã¾ãªãã¨ãè¯ããªãã¾ãã fixpack
ã³ãã³ãã使ãã ãã§ãã
ã¡ãªã¿ã« bower.json ã«å¯¾ãã¦åæ§ã®ãã¨ãè¡ã fixbow ãããã¾ãã(ç§ã® PR ã¯æ¾ç½®ããã¦ãã¾ã£ã¦ãã¾ããâ¦â¦)
Tips3: ã©ã¤ã»ã³ã¹ã MIT ã§è¯ããªã mit-license.org
OSS éçºã«ããã¦ã©ã¤ã»ã³ã¹ã大äºãªãã¨ã¯è¨ãã¾ã§ãããã¾ããã npm ã®ä¸çã§ã¯ Permissive 㪠MIT ã©ã¤ã»ã³ã¹ãä¸è¬çã§ããç§ã MIT 以å¤ã«ããå¼·ãçç±ã¯ç¡ãã®ã§ã npm ã¢ã¸ã¥ã¼ã«ã«é¢ãã¦ã¯ MIT ã©ã¤ã»ã³ã¹ã§å ¬éãã¦ãã¾ãã
ä»ã®ã©ã¤ã»ã³ã¹ã¨åæ§ã MIT ã©ã¤ã»ã³ã¹ãã©ã¤ã»ã³ã¹ã®æè¨ãå¿ è¦ã§ãã opensource.org ã® The MIT License ã®å ¨æãã³ããã㦠"year" 㨠"copyright holders" ãç½®ãæãã¦â¦â¦å°ãã®æéãªã®ã§ãããæéã¯æéã§ããæ¯åã»ã¼åããªã®ã«â¦â¦ã¨ãããã¨ã§ä¸åº¦ä½ã£ãã©ã¤ã»ã³ã¹ãã¡ã¤ã«ãã³ãã¼ãã¦ä½¿ãåãã®ã§ãããããããã¨å 容ãã»ã¼åããã¡ã¤ã«ãããã¸ã§ã¯ãæ¯ã«ä½ããããã¨ã«ãªãã¾ããããã¡ãã£ã¨ææ°ãæ¸ãããªãããªãã¨ããã¨ããã§è¦ã¤ããã®ã mit-license.org ã§ãã
mit-license.org ã¯ç»é²å¶ã® Web ãµã¼ãã¹ã§ãç»é²ããã¨æ°ããªãµããã¡ã¤ã³ãä½æãããèªåã権å©è ã¨ãã MIT ã©ã¤ã»ã³ã¹æ¡é æ¬æã示ããã¼ããªã³ã¯ãã§ããããã¾ãã詳ãã㯠remy/mit-license ã mit-license.org - Weblog - Hail2u.net ãèªãã§ã¿ã¦ãã ããã
ç»é²ã®ä»æ¹ã¯ããã¤ãããã¾ãããç§ã¯ãããªæã㧠curl ã§ç»é²ãã¾ããã
$ curl -d'{ "copyright": "Takuto Wada", "url": "https://github.com/twada" }' http://twada.mit-license.org >>> MIT license page created: http://twada.mit-license.org $
ããã§ã http://twada.mit-license.org/ ã¨ãã URL ã§èªåã® MIT ã©ã¤ã»ã³ã¹æ¡é
æ¬æã«ã¢ã¯ã»ã¹ã§ããããã«ãªãã¾ãããã¨ã¯ package.json ã® license
ãã£ã¼ã«ãã« URL ãæ¸ãã° OK ã§ããã¢ã¸ã¥ã¼ã«éçºãæ´ã«ä¸ææ¸ãã¾ããã
"license": { "type": "MIT", "url": "http://twada.mit-license.org/" },
ã¡ãªã¿ã« URL ã«å¹´ãæéãä¸ãããã¨ãã§ãã¾ãã RESTful 㪠URL è¨è¨ã§ã¨ã¦ãè¯ãã§ããã
ãããã«
ããã¾ã§ package.json ã«é¢ãã Tips ãä¸ã¤æ¸ãã¦ãã¾ããã npm ã¯ã¢ã¸ã¥ã¼ã«å©ç¨è ã«ãä½æè ã«ã使ãããããè¯ãã§ããããã±ã¼ã¸ç®¡çã·ã¹ãã ã§ããã¨æãã¾ããç¹ã«ã¢ã¸ã¥ã¼ã«å ¬éã®å®¹æãã¯ç¹çãã¹ãç¹ã§ããã¨è¨ããã§ãããã Node.js ã®ã¨ã³ã·ã¹ãã ã®è±ç©£ãã¯ãã¢ã¸ã¥ã¼ã«å©ç¨è ããã¢ã¸ã¥ã¼ã«ä½æè ã«é²ãããã®ãã¼ãã«ãä½ããã¨ã§æãç«ã£ã¦ãã¾ãããã®ã¨ã³ããªãèªãã çãããããã² npm author ã«ãªã£ã¦ã¿ã¦ãã ããããã®ãã¼ãã«ãè¶ããã®ã¯ãæå¤ã¨é£ããããã¾ããã
Node.js Advent Calendarã ææ¥ã¯ @kjirou ããã§ãã