Typescript+ESMã§npmããã±ã¼ã¸ãä½ãæ¹æ³ãæ¡å¤ã¾ã¨ã¾ã£ã¦ãªãã£ãã®ã§æ®ãã¦ãããããµã«ãªæè¿ãã»ã¼ç¢ºå®ã«ééã/éå¹çãªç¹ããããjestã§ãã¹ãããã£ã¦ããåºæ¬yarnã使ãã ã¢ã¸ã¥ã¼ã«åããã¨ãã«CommonJS(requireã®ãã¤)ã¨ESM(import/exportã®ãã¤)ã¨ããããã調ã¹ãã¨ããESMãæ¥çæ¨æºã§ãnodejs>13.2.0ã¨ã ã¢ãã³ãª ãã©ã¦ã¶ã§ã¯ãã§ã«å¯¾å¿ãã¦ããããã®ã§ãESMã§è¡ããTree Shakeãããããã£ãããããããã ããã¸ã§ã¯ãã®åæå YOUR_PACKAGE_NAME="<åå>" mkdir $YOUR_PACKAGE_NAME && cd $YOUR_PACKAGE_NAME yarn init -y
ã¯ããã« npmããã±ã¼ã¸ãéçºããã¨ããããã±ã¼ã¸å©ç¨è ã®å®è¡ç°å¢ã«åããã¦é©åãªã¢ã¸ã¥ã¼ã«å½¢å¼ã®ãã¡ã¤ã«ãããã±ã¼ã¸ã«å«ããæä¾ããå¿ è¦ãããã¾ãã å ·ä½çã«ã¯ããã¨ãã°ä»¥ä¸ã®ãããªããªã¨ã¼ã·ã§ã³ãèãããã¾ãã Node.jsç°å¢ã§ããã° CommonJS å½¢å¼ (module.exports / require() ) ãã©ã¦ã¶ç°å¢ã§ãwebpackãRollupãªã©ã®ã¢ã¸ã¥ã¼ã«ãã³ãã©ã¼ãåæã¨ãããªãã° CommonJS ã ES Modules å½¢å¼ (export / import ) ãã©ã¦ã¶ç°å¢ã§ãã¢ã¸ã¥ã¼ã«ãã³ãã©ã¼ãªã©ã¯ä½¿ãã<script>ã¿ã°ã§ãã¡ã¤ã«ãèªã¿è¾¼ãã§å©ç¨ãããªãã° UMD å½¢å¼ ãã®ã¨ããããã±ã¼ã¸æä¾å´ã¯ã©ããã£ããã¡ã¤ã«ãããã±ã¼ã¸ã«å«ããã¹ããªã®ããã¾ãããã TypeScript ã§ã©ã®ããã«å®ç¾ã§ããã®ãããã¾ãããããã£ã¦ããªãã£ãã®ã§
npm packã¨ãããµãã³ãã³ããããã®ã§ãããã使ãã¨ã¢ã¸ã¥ã¼ã«ãtgzã«ã¾ã¨ããäºãåºæ¥ããï¼ãã¤ã®éã«ãããªãµãã³ãã³ãåºæ¥ã¦ããã â¦â¦ï¼ $ npm pack grunt npm http GET https://registry.npmjs.org/grunt npm http 304 https://registry.npmjs.org/grunt grunt-0.4.4.tgz $ npm install ./grunt-0.4.4.tgz npm packã«é©å½ãªã¢ã¸ã¥ã¼ã«åã渡ãã¦ãããã¨ã ä¾åã¢ã¸ã¥ã¼ã«ã¨ä¸ç·ã«ãã¦ã³ãã¼ããã¦ãã¦ããã¦ããã®ã¾ã¾tgzã«åºãã¦ããããtgzå±éãããä¾åã¢ã¸ã¥ã¼ã«ä»ãã¦ããªãã£ãâ¦â¦ ãªã®ã§ãã¨ã¯npm installã§tgzãæå®ãã¦ãããã°ãæ°æ¥½ç°¡åã¤ã³ã¹ãã¼ã«ã ã©ããè¿ããµã¼ãã«ãããªæãã§tgzãè½ã¨ãã¦ããã¦ãpacka
node_moduleå ã®ãã¡ã¤ã«(主ã«androidã®build.gradleãªã©)ãç·¨éããéã«npm packã®ã³ãã³ãã使ç¨ãã¦å¤æ´ãå ããããã±ã¼ã¸ã.tgzãã¡ã¤ã«ã«ãã¦ãpackage.jsonã®èªã¿è¾¼ã¿å ã.tgzãã¡ã¤ã«ã«å¿ è¦ãããã æé ä¾ï¼react-native-mapsã®build.gradleãç·¨éããæ ç·¨éããããã±ã¼ã¸ã®ãã©ã«ãã«ç§»å(node_modules/react-native-maps/)ãã.tgzãã¡ã¤ã«ãçæ
npm ã«ã¯linkã¨ããã³ãã³ããç¨æããã¦ãããããã使ããã¨ã§ npm ããã±ã¼ã¸ã®éçºå¹çãä¸ããã æ¢åã®ããã±ã¼ã¸ã«æãå ããéã®åä½ç¢ºèªã«ã使ããã®ã§ãOSS æ´»åã®å¹çãä¸ããã ãã®è¨äºã§ã¯ãnpm linkã®ä»çµã¿ã¨ããããã©ã®ããã«å©ç¨ã§ããã®ãã«ã¤ãã¦èª¬æããã åä½ç¢ºèªã«ä½¿ã£ã npm ã®ãã¼ã¸ã§ã³ã¯6.14.5ã Node.js ã®ãã¼ã¸ã§ã³ã¯12.17.0ããã以åã®ãã¼ã¸ã§ã³ã ã¨ä»¥ä¸ã®åä½ç¢ºèªã§ã¨ã©ã¼ãåºãã®ã§æ³¨æã ãµã³ãã«ç¨ã®ããã±ã¼ã¸ã¨ã¢ããªãä½ã ã¾ãã¯ããã±ã¼ã¸ãä½æããã my-package-dirã¨ãããã£ã¬ã¯ããªãä½ããããã«ä»¥ä¸ã®å 容ã®package.jsonãä½æããã { "name": "my-package", "type": "module", "main": "main.js" } ããã¦ã以ä¸ã®å 容ã®main.jsãä½ãã
npm(nodejsã®ããã±ã¼ã¸ããã¼ã¸ã£ã¼)ã«ã¯ç°¡åã«èªä½ã®ã¢ã¸ã¥ã¼ã«ãuploadã§ãã¾ãã åãã¦ã®npm ããã±ã¼ã¸å ¬é - Qiita ãã¡ãã®è¨äºã§ååã¢ãããã¼ãã®æé ã¯è©³ç´°ã«æ¸ãã¦ããã¾ãã ååã¯ãã¡ããããã¼ã¸ã§ã³ã¢ãããã¦ï¼åç®ä»¥éã®npm publishãããæã®æ³¨æç¹ãè¨ãã¦ããã¾ãã æé test READMEã®ç¢ºèª TODOã®ç¢ºèª ã½ã¼ã¹ã³ã¼ãã®build GitHubã«pushãã¦CI(travisç)ã®test npm versionã®æ´æ° npm publish test ã¨ã«ããtestéã£ã¦ãªããã°è©±ã«ãªãã¾ãããnpm run test READMEã®ç¢ºèª ã³ã¼ããã¬ã·ã¬ã·æ¸ãã¦ãã¹ããéã£ããæºè¶³ãã¦ãã¾ããã¡ã§ãããå ¬éãããªãREADMEã«æ°æ©è½ã®èª¬æã追å ããã®ãå¿ãã¦ã¯ããã¾ããã TODOã®ç¢ºèª ç§ã¯éçºä¸ã«æãã¤ããæ©è½ãã¡ã½ããå
nodeã§ã¯npmã使ã£ã¦ã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã«ãã¦ããã°ã©ãã³ã°ãè¡ãã¾ããããã¦é å¸ããéã«ã¯node_modulesãé¤ããåèªãã¤ã³ã¹ãã¼ã«ãã¾ããããããããã¯ã¼ã¯ãå¿ è¦ã ã£ãããå ´åã«ãã£ã¦ã¯ã©ã¤ãã©ãªã®ã¤ã³ã¹ãã¼ã«ã«å¤±æããããç¥ãã¾ããã ããã§ä½¿ã£ã¦ã¿ããã®ãnccã§ããã³ã¼ããä¸ã¤ã«ã¾ã¨ãã¦ãã¼ã¿ãã«ã«ãã¦ãããã½ããã¦ã§ã¢ã§ãã nccã®ä½¿ãæ¹ ã³ã¼ãä¾ã§ãã const chalk = require("chalk"); console.log(chalk.blue.bgRed.bold("Hello world!")); ãã«ãã使ãã¨ã³ã¼ããçæããã¾ãã $ ncc build ncc: Version 0.20.4 ncc: Compiling file index.js 44kB dist/index.js 44kB [439ms] - ncc 0.20
ã¯ããã« npmããã±ã¼ã¸ãå©ç¨ããéããã¼ã¸ã§ã³ã®éããªã©ã§åããªãã£ãããå°ãã ãã«ã¹ã¿ãã¤ãºãããã¨ãã£ããããªå ´é¢ã«ééãããã¨ã¯ãªãã§ããããï¼ãããªã¨ãã«ä½¿ãã patch-package ã¨ãããã¼ã«ããç´¹ä»ãã¾ãã npmããã±ã¼ã¸ãä¿®æ£ããã«ã¯ npm install ã«ãã£ã¦è¿½å ãããããã±ã¼ã¸ã¯ããã¸ã§ã¯ãã®node_modulesã¨ãããã£ã¬ã¯ããªå ã«ä¿åããã¾ãã ãã®node_moduleså ã®ãã¡ã¤ã«ãå¤æ´ãã¦ãã¾ãã°npmããã±ã¼ã¸ãä¿®æ£ã§ããã®ã§ãããããã¤ãæ¹æ³ãããã¾ãã node_moduleså ãç´æ¥ä¿®æ£ããæ¹æ³ node_moduleså ã®ãã¡ã¤ã«ã¯ä¸è¬çã«ã¯JavaScriptã§ãã®ã§ããã®ãã¡ã¤ã«ãç´æ¥å¤æ´ãã¦ãã¾ããã¨ãå¯è½ã§ãã ããããnode_moduleså ã®ãã¡ã¤ã«ã¯ npm install æãªã©ã«ä¸æ¸ããããå¯è½æ§ãããã¾ãã
ã¯ããã« ä»äºã§npm linkæ©è½ããããã試ããªããå°å ¥ããã®ã§åå¿é²ãå ¼ãã¤ã¤ãã¾ã¨ãã¾ãã ãªã³ã¯ãè²¼ã åºæ¬çã«ã¯å ¬å¼ããã¥ã¡ã³ãã«ããã¨ããã§ãããå®éã«è©¦ããçµæã¨ãã¦ã¾ã¨ãã¾ãã æ³å®ã¨ãã¦ã¯ã ãuse-npm-link-Aãããã¾ã npmã«å ¬éãã¦ããªãuse-npm-link-Bã¨use-npm-link-Cã«ãªã³ã¯ãè²¼ã£ã¦åä½ã調ã¹ããã ã¨ãã£ãæãã§ããå®éã«ãªã³ã¯ãè²¼ã£ãç¶æ ã以ä¸ã®å³ã§ãã ãªã³ã¯ãããuse-npm-link-Bã¨use-npm-link-Cã¯ä»¥ä¸ã®å³ã®ããã«ãªã£ã¦ãã¾ãã ãã£ã¬ã¯ããªå -> use-npm-link-B package.jsonã®nameã§æå®ãããåå -> use-npm-link-B ãã£ã¬ã¯ããªå -> UseNpmLinkC package.jsonã®nameã§æå®ãããåå -> use-npm-link-
ããã«ã¡ã¯ã@yoheiMuneã§ãã npm linkã¨ããã³ãã³ãããããã§ãããåãã¦ç¥ãã¾ãããnpmã¢ã¸ã¥ã¼ã«éçºãå¹ççã«ã§ããã®ã§ãããã°ã«ãç¨éã使ãæ¹ãã¾ã¨ãã¦ããããã¨æãã¾ãã ç®æ¬¡ npm linkã¨ã¯ npm linkã¯ã·ã³ããªãã¯ãªã³ã¯ãè²¼ãä»çµã¿ã§ãéçºä¸ã®npmã¢ã¸ã¥ã¼ã«ã¨ããããçµã¿è¾¼ãã¢ããªã±ã¼ã·ã§ã³ã¨ãã¤ãªãåããããã¨ãã§ããä»çµã¿ã§ãã ããã§ã¯ãéçºä¸ã®ã¢ã¸ã¥ã¼ã«ãmymoduleããããçµã¿è¾¼ãã¢ããªãmyappã¨ãã¦ã以ä¸ã®ãã£ã¬ã¯ããªæ§æã ã¨ãã¾ãã + ~/git/ - mymodule/ <--- éçºä¸ã®ã¢ã¸ã¥ã¼ã« - myapp/ <--- éçºä¸ã®ã¢ã㪠- node_modules/ - mymodule/ (â»2) <--- éçºä¸ã®ã¢ã¸ã¥ã¼ã«ã«ä¾åãã¦ãã é常ã§ããã°myappããmymoduleã使ãå ´åã«ã¯ãnpm i
人é¡ã¯ããé«éã«CIãåãã¦ããã¹ãã ã¨æã£ã¦ãã ãããï¼@mstsskï¼ã§ãã å æ¥ã npm ã® v5.7ããªãªã¼ã¹ãã npm ci ã¨ãããµãã³ãã³ããæ°ãã«è¿½å ããã¾ããã The npm Blog â Introducing npm ci for faster, more reliable... http://blog.npmjs.org/post/171556855892/introducing-npm-ci-for-faster-more-reliable CI/CDãéçºããã»ã¹ã«çµã¿è¾¼ãã§ããå ´åã«ããæ´åæ§ãããé«éãªã¨ã¯ã¹ããªã¨ã³ã¹ãæä¾ãããã¨å ¬å¼ããã°ã§ã¯ç´¹ä»ãã¦ãã¾ãã npm ci ã¯ä½ãããã®ã npm ci ãå®è¡ããã¨å¸¸ã« package-lock.json ããä¾åé¢ä¿ãã¤ã³ã¹ãã¼ã«ãã¾ãã æ¢ã« node_modules ãã©ã«ãã®ä¸èº«ããã£ã¦ã
npm ãªãã¸ããªã verdaccio ã§æ§ç¯ãã ååânpmâããã±ã¼ã¸ãä½ã£ã¦ã¿ã¾ããããnpmâã§ããã±ã¼ã¸ãä½ã£ã¦ããã¨ããããªãã¸ããªã«å ¬éããããªã£ã¦ãã¾ããNodeJsâã«ã¯âhttps://www.npmjs.com/âã¨ããå ¬å¼ãªãã¸ããªãåå¨ãã¾ãããä¸è¬å ¬éããããªãânpmâã¢ã¸ã¥ã¼ã«ãç½®ãããã¨ããnpmâãªãã¸ããªèªä½ãèªåã§æ§ç¯ãããã¨ããè¦æãããã§ãããã èªåã®ânpmâãªãã¸ããªãµã¼ãã¼ã¯ããã¤ãåå¨ããã®ã§ãããä»åã¯æ§ç¯ã®ç°¡åãªâverdaccioâã使ã£ã¦ã¿ããã¨æãã¾ãã verdaccioâãã¤ã³ã¹ãã¼ã«ããnpmâãªãã¸ããªç¨ã®ãµã¼ãã¼ã«ãã°ã¤ã³ããverdaccioâãã¤ã³ã¹ãã¼ã«ãã¾ãã npmâã¢ã¸ã¥ã¼ã«ã¨ãã¦æä¾ããã¦ããã®ã§ãnpmâã³ãã³ãã§ã¤ã³ã¹ãã¼ã«ã§ãã¾ãã# npm install --global verdacci
ãã¼ã«ã«ã«npm registryãæ§ç¯ããæ¹æ³ã¯ããã¤ãããã¾ãããçµæ§æåãããVerdaccioã使ã£ã¦æ§ç¯ããããã®åå¿é² ããã°ã¨ãQiitaã«ãè¨äºã¯ãããã ãã©èå¿ãªè¨å®ãæãã¦ããããã¦ããã®ã§ãã®è¾ºãè¼ãã¦ããã¾ã ç®æ¬¡ æ§ç¯ç°å¢ å¿ è¦ãªããã±ã¼ã¸ã®ã¤ã³ã¹ãã¼ã« npmã®ã¤ã³ã¹ãã¼ã« verdaccioã®ã¤ã³ã¹ãã¼ã« verdaccioã®è¨å® æ¨æºã®ãµã¼ãã¹ãã¡ã¤ã«ãsystemdã«ã³ãã¼ãã ã³ãã¼ãããµã¼ãã¹ãã¡ã¤ã«ãä¿®æ£ãã ä¸æ¦verdaccioãèµ·åããã configãã¡ã¤ã«ãä¿®æ£ãã local registryã®proxyã追å npm packageåãåãããlocalåªå ã«ãã å¤é¨ã¢ã¯ã»ã¹ãåãä»ããã«ã¯ãããå¿ é verdaccioããµã¼ãã¹ã«ç»é²ãã èµ·åã¨èªåèµ·åã®è¨å® åä½ç¢ºèª registryã追å ãã ããã±ã¼ã¸æ¯ã«åãããå ´å ã°ãã¼
çºç«¯ npm@5 ã«ãªãã¨ãã«ã prepublish ã®æåã大ããå¤æ´ããã¾ããã Node.js ã® 8.x ã LTS ã«ãªã£ãå½æãNode.js@6 㯠npm@3 ã§ããããNode.js@8 ã§ã¯ npm@5 ã«ãªãããã ãã®å 容ãã¡ããã¨ææ¡ã§ãã¦ããªãã£ãã®ã§ã調ã¹ã¾ããã ä½æ¥ãã¦çµæãã¾ã¨ãããªãã¸ããªãããã®ã§ãããã®æ¥æ¬èªè¨³+ã¢ã«ãã¡ ãæ¸ãã¾ãã "ã¹ããã4" 㨠"ã¹ããã 5" ã¨ã¯ãªã«ã ã¾ã¨ããèªãã®ã«å¿ è¦ãªç¨èªï¼ï¼ï¼ãªã®ã§ãå ã«èª¬æãã¦ããã¾ãã https://github.com/npm/npm/issues/10074 ã§è¨ã£ã¦ããã¤ã§ãã ã¹ããã 4 ã¯ã In a year or so, make a semver-major bump to npm and make prepublish's behavior match prepu
ãã®è¨äºã§ã¯ãããããTypeScriptã§npmã©ã¤ãã©ãªéçºãããã¨ããèªè ã対象ã¨ãã¦ãã¾ãã ã¨ã¯ããä»ã©ãã¯VS Codeããã¨ããç´ æ´ãããã¨ãã£ã¿ã¼ã®ãããããã£ã¦ãåãæä¾ããã¦ããªãnpmã©ã¤ãã©ãªã¯ä½¿ãã¥ããç«å ´ã«ããã¾ãã ã§ã¯æ©éã§ãããTypeScriptã§"Hello ã ãã ã"ã¨ã³ã³ã½ã¼ã«ã«è¡¨ç¤ºãããnpmã©ã¤ãã©ãªãéçºãã¦ã¿ã¾ãããã åºæ¬çãªnpmã©ã¤ãã©ãªéçºã®ç¥è ãã®è¨äºã§ã¯ãTypeScriptã§ãnpmã©ã¤ãã©ãªéçºãããã¨ã«ä¸»ç¼ãç½®ããããããåºæ¬çãªnpmã©ã¤ãã©ãªéçºã®ç¥èã¯ãæ¬å½ã«ããããnpmã©ã¤ãã©ãªéçºå ¥éããããã¯ç¥ã£ã¦ããåæã§é²ãã¾ãã package.jsonã®ãããã ç§ã®è¶£å³ã¯äººã®æ¸ããpackage.jsonãè¦ããã¨ã§ããï¼è¶£å³æªãã§ãããï½ï¼ ã§ã¯ã¾ãã¯ä»åãé¡ã«ããpackage.jsonãè¦ã¦ããã ãã¾ããã
ã©ã³ãã³ã°
ã©ã³ãã³ã°
ã©ã³ãã³ã°
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}