{"id":327088,"date":"2023-04-20T20:44:39","date_gmt":"2023-04-20T12:44:39","guid":{"rendered":"https:\/\/www.idc.net\/help\/327088\/"},"modified":"2023-04-20T20:44:39","modified_gmt":"2023-04-20T12:44:39","slug":"%e7%8e%b0%e4%bb%a3-monorepo-%e5%b7%a5%e7%a8%8b%e6%8a%80%e6%9c%af%e9%80%89%e5%9e%8b%ef%bc%8c%e8%81%8a%e8%81%8a%e6%88%91%e7%9a%84%e6%80%9d%e8%80%83","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/327088\/","title":{"rendered":"\u73b0\u4ee3 Monorepo \u5de5\u7a0b\u6280\u672f\u9009\u578b\uff0c\u804a\u804a\u6211\u7684\u601d\u8003"},"content":{"rendered":"<h4>\u524d\u8a00<br \/><\/h4>\n<p>\u76f8\u4fe1\u5f88\u591a\u5173\u6ce8 Monorepo \u751f\u6001\u7684\u540c\u5b66\uff0c\u5e94\u8be5\u5927\u90fd\u770b\u8fc7\u8fd9\u7bc7\u6587\u7ae0 monorepo.tools [1] \uff0c\u5176\u4e2d\u5217\u4e3e\u4e86\u73b0\u5b58\u7684\u51e0\u4e2a\u4e3b\u6d41\u7684 Monorepo \u76f8\u5173\u7684\u5de5\u5177\uff1a<\/p>\n<ul>\n<li>Bazel (by Google) [2]<\/li>\n<li>Lage (by Microsoft) [3]<\/li>\n<li>Lerna [4]<\/li>\n<li>Nx (by Nrwl) [5]<\/li>\n<li>Rush (by Microsoft) [6]<\/li>\n<li>Turborepo (by Vercel) [7]<\/li>\n<\/ul>\n<p>\u76f8\u5e94\u5730\uff0c\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\u4e5f\u5bf9\u5404\u7c7b\u5de5\u5177\u8fdb\u884c\u4e86\u4e00\u4e00\u4ecb\u7ecd\u3002\u5e76\u4e14\uff0c\u6211\u76f8\u4fe1\u6bcf\u4e2a\u770b\u8fc7\u8fd9\u7bc7\u6587\u7ae0\u7684\u540c\u5b66\uff0c\u90fd\u4f1a\u7559\u4e0b\u8fd9\u4e48\u4e2a\u7591\u95ee\uff1a \u8fd9\u4e48\u591a Monorepo Tool\uff0c\u6211\u8981\u5982\u4f55\u8fdb\u884c\u9009\u578b\uff1f<\/p>\n<p>\u8fd9\u91cc\uff0c\u6211\u7ed9\u51fa\u7684\u7b54\u6848\u662f PNPM + Turborepo + Changesets\u3002\u90a3\u4e48\uff0c\u53c8\u4e3a\u4ec0\u4e48\u662f\u8fd9 3 \u8005\u5462\uff1f\u4e0b\u9762\uff0c\u6211\u5c06\u4f1a\u5206\u522b\u56f4\u7ed5\u8fd9 3 \u4e2a\u6280\u672f\u5c55\u5f00\uff0c\u6765\u4e00\u4e00\u89e3\u7b54\u8fd9\u4e2a\u9009\u578b\u7684\u539f\u56e0\u4ee5\u53ca\u600e\u4e48\u505a\u3002<\/p>\n<h4>PNPM<br \/><\/h4>\n<p>PNPM \u7684\u52a8\u673a\uff08 Motivation [8] \uff09\uff0c\u5982\u5b83\u5728\u5b98\u65b9\u6587\u6863\u4ecb\u7ecd\u7684\u6240\u8bf4\uff1a \u201cSaving disk space and boosting installation speed\u201d\uff0c\u8282\u7701\u78c1\u76d8\u7a7a\u95f4\u548c\u63d0\u9ad8\u5b89\u88c5\u901f\u5ea6 \u3002\u9664\u5f00\u8fd9\u4e2a\u52a8\u673a\u63cf\u8ff0\u7684\u663e\u8457\u4f18\u70b9\u5916\uff0c PNPM \u5185\u7f6e\u4e86\u5bf9 Monorepo \u7684\u652f\u6301 [9] \uff0c\u5e76\u89e3\u51b3\u4e86\u5f88\u591a\u4ee4\u4eba\u8bdf\u75c5\u7684\u95ee\u9898\u3002<\/p>\n<p>\u5176\u4e2d\uff0c\u6bd4\u8f83\u7ecf\u5178\u7684\u5c31\u662f Phantom dependencies\uff08\u5e7b\u5f71\u4f9d\u8d56\uff09\u3002\u7531\u4e8e\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b yarn \u3001 npm \u5b89\u88c5\u7684\u4f9d\u8d56\u90fd\u662f\u4f1a\u88ab\u63d0\u5347\u3002\u6240\u4ee5\uff0c\u6709\u65f6\u5019\u4f60\u53ef\u80fd\u4f1a\u9047\u5230 Monorepo \u9879\u76ee\u4e2d\u7684\u67d0\u4e2a\u5305\u4e2d\u7684 package.json \u6ca1\u6709\u5b89\u88c5\u8fd9\u4e2a\u4f9d\u8d56\uff0c\u7ed3\u679c\u5b9e\u9645\u4ee3\u7801\u4e2d\u5374\u4f7f\u7528\u4e86\u8fd9\u4e2a\u4f9d\u8d56...<\/p>\n<p>\u867d\u8bf4\uff0cPNPM \u53ef\u4ee5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4f46\u662f\uff0c \u9ed8\u8ba4\u60c5\u51b5 \u4e0b PNPM \u5b89\u88c5\u7684\u4f9d\u8d56\u4e5f\u662f\u4f1a\u88ab\u63d0\u5347\u7684\u3002\u5982\u679c\uff0c\u9700\u8981 PNPM \u7981\u6b62\u4f9d\u8d56\u63d0\u5347\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5728 Monorepo \u9879\u76ee\u5de5\u4f5c\u533a\u4e0b\u7684 .npmrc \u6587\u4ef6\u4e2d \u914d\u7f6e [10] \uff0c\u4f8b\u5982\u53ea\u63d0\u5347 lodash \uff1a<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">hoist<\/span><span style=\"margin: 0px;padding: 0px\">-<\/span><span style=\"margin: 0px;padding: 0px\">pattern<\/span>[]<span style=\"margin: 0px;padding: 0px\">=<\/span><span style=\"margin: 0px;padding: 0px\">*<\/span><span style=\"margin: 0px;padding: 0px\">lodash<\/span><span style=\"margin: 0px;padding: 0px\">*<\/span><\/pre>\n<p>\u5f53\u7136\uff0c\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u7684\u95ee\u9898\uff0c\u6709\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u770b ELab \u56e2\u961f\u5199\u7684\u8fd9\u7bc7\u6587\u7ae0 \u300aMonorepo \u7684\u8fd9\u4e9b\u5751\uff0c\u6211\u4eec\u5e2e\u4f60\u8e29\u8fc7\u4e86\uff01\u300b [11] \u3002<\/p>\n<p>\u90a3\u4e48\uff0c\u5728\u7b80\u5355\u89e3\u7b54\u4e86\u4e3a\u4ec0\u4e48\u7528 PNPM \u540e\uff0c\u4e0b\u9762\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u8981\u600e\u4e48\u7528\uff1f<\/p>\n<h4>Workspace \u914d\u7f6e<br \/><\/h4>\n<p>\u8981\u4f7f\u7528 PNPM \u7684 Monorepo \u5f88\u7b80\u5355\uff0c\u53ea\u9700\u8981\u5728 Monorepo \u9879\u76ee\u7684\u5de5\u4f5c\u533a\u4e0b\u65b0\u5efa pnpm-workspace.yaml \u6587\u4ef6\u5e76\u914d\u7f6e\uff1a<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">packages<\/span>:<br> <span style=\"margin: 0px;padding: 0px\">-<\/span> <span style=\"margin: 0px;padding: 0px\">'packages\/**'<\/span><\/pre>\n<p>\u63a5\u4e0b\u6765\uff0c\u5219\u662f\u8bb0\u5fc6\u5e38\u7528\u4f9d\u8d56\u548c\u591a\u5305\u4efb\u52a1\u6267\u884c\u76f8\u5173\u7684\u547d\u4ee4\u3002\u7531\u4e8e\uff0c\u6211\u4eec\u7684\u6280\u672f\u9009\u578b\u4e2d\u6709 Turborepo\uff0c\u5b83\u4f1a\u8d1f\u8d23\u591a\u5305\u4efb\u52a1\u7684\u6267\u884c\u3002\u6240\u4ee5\uff0c\u8fd9\u91cc\u53ea\u9700\u8981\u8bb0\u5fc6 \u5e38\u7528\u4f9d\u8d56\u76f8\u5173\u7684\u547d\u4ee4 \u3002<\/p>\n<h4>\u5e38\u7528\u4f9d\u8d56\u76f8\u5173\u547d\u4ee4<br \/><\/h4>\n<p><strong>pnpm i<\/strong><\/p>\n<p>\u5728 PNPM \u4e2d\uff0c\u5b89\u88c5\u4f9d\u8d56\u53ef\u4ee5\u7528 pnpm i \u6765\u5b8c\u6210\u3002\u5728 Monorepo \u7684\u573a\u666f\u4e0b\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b pnpm i \u4f1a\u5b89\u88c5\u6240\u6709\u7684\u4f9d\u8d56\uff08\u5305\u62ec packages\/* \uff09\u3002\u6b64\u5916\uff0c pnpm i \u8fd8\u9700\u8981\u7528\u5230 3 \u4e2a\u9009\u9879\uff08Option\uff09\uff1a<\/p>\n<ul>\n<li>--filter &lt;package&gt;\uff0c\u5b89\u88c5\u4f9d\u8d56\u5230\u6307\u5b9a\u7684 package\uff0c\u4e0d\u58f0\u660e\u8981\u5b89\u88c5\u7684\u4f9d\u8d56\u5305\u5219\u9ed8\u8ba4\u5b89\u88c5 package.json \u4e2d\u7684\u6240\u6709\u4f9d\u8d56<\/li>\n<li>--prod, P\uff0c\u5b89\u88c5\u4f9d\u8d56\u5230 dependencies<\/li>\n<li>--dev, D\uff0c\u5b89\u88c5\u4f9d\u8d56\u5230 devDependencies<\/li>\n<\/ul>\n<p><strong>pnpm remove<\/strong><\/p>\n<p>\u5728 PNPM \u4e2d\uff0c\u5220\u9664\u5728 package.json \u4e2d\u7684\u67d0\u4e2a\u4f9d\u8d56\uff0c\u53ef\u4ee5\u7528 pnpm remove \u5b8c\u6210\u3002\u5b83\u7684\u9009\u9879\uff08Option\uff09\u4f7f\u7528\u548c pnpm i \u5927\u540c\u5c0f\u5f02\u3002\u5176\u4e2d\uff0c\u4e0d\u540c\u5730\u662f\u5f53\u6211\u4eec\u5728\u5de5\u4f5c\u533a\u60f3\u8981\u5220\u9664 packages \u4e2d\u6240\u6709\u5305\u7684 package.json \u4e2d\u7684\u67d0\u4e2a\u4f9d\u8d56\u7684\u65f6\u5019\uff0c\u9700\u8981\u4f7f\u7528 -r \uff0c\u4f8b\u5982\u79fb\u9664\u6240\u6709\u5305\u4e2d\u7684 lodash \uff1a<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">pnpm<\/span> <span style=\"margin: 0px;padding: 0px\">remove<\/span> <span style=\"margin: 0px;padding: 0px\">lodash<\/span> <span style=\"margin: 0px;padding: 0px\">-<\/span><span style=\"margin: 0px;padding: 0px\">r<\/span><\/pre>\n<p>\u5f53\u7136\uff0c\u53ef\u80fd\u8fd8\u6709\u540c\u5b66\u6709\u4e00\u4e9b\u5176\u4ed6\u7684\u8bc9\u6c42\uff0c\u6709\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u79fb\u6b65\u6587\u6863\u4e86\u89e3\uff0c\u8fd9\u91cc\u4e0d\u505a\u5c55\u5f00\u3002<\/p>\n<h4>Changesets<br \/><\/h4>\n<p>\u7ecf\u5e38\u7ef4\u62a4\u5f00\u6e90\u9879\u76ee\u7684\u540c\u5b66\u90fd\u77e5\u9053\u7684\u4e00\u70b9\uff0c\u6bcf\u6b21\u5305\uff08Package\uff09\u7684\u53d1\u5e03\uff0c\u9700\u8981\u4fee\u6539 package.json \u7684 version \u5b57\u6bb5\uff0c\u4ee5\u53ca\u540c\u6b65\u66f4\u65b0\u4e00\u4e0b\u672c\u6b21\u53d1\u5e03\u4fee\u6539\u7684 CHANGELOG.md\u3002<\/p>\n<p>\u8fd9\u4e48\u4e00\u6765\uff0c\u5c31\u4f1a\u51f8\u663e\u4e00\u4e2a\u95ee\u9898\uff0c\u6bcf\u6b21\u53d1\u5e03\u90fd\u9700\u8981\u624b\u52a8\u5730\u53bb\u66f4\u65b0 version \u3001\u66f4\u65b0 CHANGELOG.md\uff0c\u672a\u514d \u6709\u70b9\u7e41\u7410 \u3002\u5e76\u4e14\uff0c\u7528\u8fc7 Lerna \u7684\u540c\u5b66\uff0c\u5e94\u8be5\u90fd\u77e5\u9053 Lerna \u5185\u7f6e\u4e86\u5bf9\u8fd9\u5757\u7684\u652f\u6301\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u65e0\u8bba\u662f PNPM \u53c8\u6216\u8005\u662f\u4e0b\u9762\u8981\u8bf4\u7684 Turborepo \u90fd\u4e0d\u652f\u6301\u8fd9\u5757\uff0c\u6240\u4ee5 2 \u8005\u7684\u5b98\u65b9\u6587\u6863\u90fd\u7ed9\u5927\u5bb6\u63a8\u8350\u4e86\u7528\u4e8e\u652f\u6301\u8fd9\u5757\u80fd\u529b\u7684\u5de5\u5177\uff0c\u4f8b\u5982 Changesets [12] \u3001 Beachball [13] \u3001 Auto [14] \u7b49\u3002<\/p>\n<p>\u90a3\u4e48\uff0c\u8fd9\u91cc\u6211\u4eec\u8981\u4ecb\u7ecd\u7684\u5c31\u662f Changesets\u3002\u4e0b\u9762\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u5728\u524d\u9762\u5efa\u597d\u7684 PNPM \u7684 Monorepo \u9879\u76ee\u4e2d\u5982\u4f55\u4f7f\u7528 Changesets\u3002\u9996\u5148\uff0c\u9700\u8981\u6267\u884c\u5728 Monorepo \u9879\u76ee\u7684\u5de5\u4f5c\u533a\u4e0b\uff0c\u6267\u884c\u5982\u4e0b 2 \u4e2a\u547d\u4ee4\uff1a<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">pnpm<\/span> <span style=\"margin: 0px;padding: 0px\">i<\/span> <span style=\"margin: 0px;padding: 0px\">-<\/span><span style=\"margin: 0px;padding: 0px\">DW<\/span> <span style=\"margin: 0px;padding: 0px\">@<\/span><span style=\"margin: 0px;padding: 0px\">changesets<\/span><span style=\"margin: 0px;padding: 0px\">\/<\/span><span style=\"margin: 0px;padding: 0px\">cli<\/span><br><span style=\"margin: 0px;padding: 0px\">pnpm<\/span> <span style=\"margin: 0px;padding: 0px\">changeset<\/span> <span style=\"margin: 0px;padding: 0px\">init<\/span><\/pre>\n<p>\u524d\u8005\u662f\u5b89\u88c5 Changesets \u7684 CLI\uff0c\u540e\u8005\u662f\u521d\u59cb\u5316 .changeset \u6587\u4ef6\u5939\u4ee5\u53ca\u5bf9\u5e94\u7684\u6587\u4ef6\uff1a<\/p>\n<pre>.<span style=\"margin: 0px;padding: 0px\">changeset<\/span><br> <span style=\"margin: 0px;padding: 0px\">\uff5c<\/span><span style=\"margin: 0px;padding: 0px\">--<\/span> <span style=\"margin: 0px;padding: 0px\">config<\/span>.<span style=\"margin: 0px;padding: 0px\">json<\/span><br> <span style=\"margin: 0px;padding: 0px\">\uff5c__<\/span> <span style=\"margin: 0px;padding: 0px\">README<\/span>.<span style=\"margin: 0px;padding: 0px\">md<\/span><\/pre>\n<p>\u8fd9\u91cc\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e0b config.json [15] \u6587\u4ef6\uff1a<\/p>\n<pre>{<br> <span style=\"margin: 0px;padding: 0px\">\"$schema\"<\/span>: <span style=\"margin: 0px;padding: 0px\">\"https:\/\/unpkg.com\/@changesets\/config@1.6.4\/schema.json\"<\/span>,<br> <span style=\"margin: 0px;padding: 0px\">\"changelog\"<\/span>: <span style=\"margin: 0px;padding: 0px\">\"@changesets\/cli\/changelog\"<\/span>,<br> <span style=\"margin: 0px;padding: 0px\">\"commit\"<\/span>: <span style=\"margin: 0px;padding: 0px\">false<\/span>,<br> <span style=\"margin: 0px;padding: 0px\">\"linked\"<\/span>: [],<br> <span style=\"margin: 0px;padding: 0px\">\"access\"<\/span>: <span style=\"margin: 0px;padding: 0px\">\"restricted\"<\/span>,<br> <span style=\"margin: 0px;padding: 0px\">\"baseBranch\"<\/span>: <span style=\"margin: 0px;padding: 0px\">\"master\"<\/span>,<br> <span style=\"margin: 0px;padding: 0px\">\"updateInternalDependencies\"<\/span>: <span style=\"margin: 0px;padding: 0px\">\"patch\"<\/span>,<br> <span style=\"margin: 0px;padding: 0px\">\"ignore\"<\/span>: []<br>}<\/pre>\n<p>\u9664\u5f00 $schema \u8fd9\u4e2a\u4e0d\u9700\u8981\u4fee\u6539\u7684\u5b57\u6bb5\uff0c config.json \u6587\u4ef6\u4e2d\u5217\u4e86 7 \u4e2a\u5b57\u6bb5\uff0c\u5404\u4e2a\u5b57\u6bb5\u5206\u522b\u4ee3\u8868\u7684\u4f5c\u7528\u4e3a\uff1a<\/p>\n<ul>\n<li>changelog \u8bbe\u7f6e CHANGELOG.md \u751f\u6210\u65b9\u5f0f\uff0c\u53ef\u4ee5\u8bbe\u7f6e false \u4e0d\u751f\u6210\uff0c\u4e5f\u53ef\u4ee5\u8bbe\u7f6e\u4e3a\u5b9a\u4e49\u751f\u6210\u884c\u4e3a\u7684\u6587\u4ef6\u5730\u5740\u6216\u4f9d\u8d56\u540d\u79f0\uff0c\u4f8b\u5982 Changsets \u63d0\u4f9b\u7684 `changelog-git` [16] \u3002\u5176\u4e2d\uff0c\u5b9a\u4e49\u751f\u6210\u884c\u4e3a\u7684\u6587\u4ef6\u56fa\u5b9a\u4ee3\u7801\u6a21\u7248\u4e3a\uff1a<\/li>\n<\/ul>\n<pre><span style=\"margin: 0px;padding: 0px\">async<\/span> <span style=\"margin: 0px;padding: 0px\">function<\/span> <span style=\"margin: 0px;padding: 0px\">getReleaseLine<\/span>() {}<br><span style=\"margin: 0px;padding: 0px\">async<\/span> <span style=\"margin: 0px;padding: 0px\">function<\/span> <span style=\"margin: 0px;padding: 0px\">getDependencyReleaseLine<\/span>() {}<br><span style=\"margin: 0px;padding: 0px\">export<\/span> <span style=\"margin: 0px;padding: 0px\">default<\/span> {<br> <span style=\"margin: 0px;padding: 0px\">getReleaseLine<\/span>,<br> <span style=\"margin: 0px;padding: 0px\">getDependencyReleaseLine<\/span><br>}<\/pre>\n<ul>\n<li>commit \u8bbe\u7f6e\u662f\u5426\u628a\u6267\u884c changeset add \u6216 changeset publish \u64cd\u4f5c\u65f6\u5bf9\u4fee\u6539\u7528 Git \u63d0\u4ea4<\/li>\n<li>linked \u8bbe\u7f6e\u5171\u4eab\u7248\u672c\u7684\u5305\uff0c\u800c\u4e0d\u662f\u72ec\u7acb\u7248\u672c\u7684\u5305\uff0c\u4f8b\u5982\u4e00\u4e2a\u7ec4\u4ef6\u5e93\u4e2d\u4e3b\u9898\u548c\u5355\u72ec\u7684\u7ec4\u4ef6\u7684\u5173\u7cfb\uff0c\u4e5f\u5c31\u662f\u4fee\u6539 Version \u7684\u65f6\u5019\uff0c\u5171\u4eab\u7684\u5305\u9700\u8981\u540c\u6b65\u4e00\u8d77\u66f4\u65b0\u7248\u672c<\/li>\n<li>access \u8bbe\u7f6e\u6267\u884c npm publish \u7684 --access \u9009\u9879\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u6211\u4eec\u662f\u516c\u5171\u7684\u5305\uff0c\u6240\u4ee5\u8bbe\u7f6e public \u5373\u53ef\uff08\u6ce8\u610f\uff0c\u5b83\u4f1a\u88ab package.json \u4e2d\u7684 access \u5b57\u6bb5\u91cd\u5199\uff09<\/li>\n<li>baseBranch \u8bbe\u7f6e\u9ed8\u8ba4\u7684 Git \u5206\u652f\uff0c\u4f8b\u5982\u73b0\u5728 GitHub \u7684\u9ed8\u8ba4\u5206\u652f\u5e94\u8be5\u662f main<\/li>\n<li>updateInternalDependencies \u8bbe\u7f6e\u4e92\u76f8\u4f9d\u8d56\u7684\u5305\u7248\u672c\u66f4\u65b0\u673a\u5236\uff0c\u5b83\u662f\u4e00\u4e2a\u679a\u4e3e\uff08 major|minor|patch \uff09\uff0c\u4f8b\u5982\u8bbe\u7f6e\u4e3a minor \u65f6\uff0c\u53ea\u6709\u5f53\u4f9d\u8d56\u7684\u5305\u65b0\u4e86 minor \u7248\u672c\u6216\u8005\u624d\u4f1a\u5bf9\u5e94\u5730\u66f4\u65b0 package.json \u7684 dependencies \u6216 devDependencies \u4e2d\u5bf9\u5e94\u4f9d\u8d56\u7684\u7248\u672c<\/li>\n<li>ignore \u8bbe\u7f6e\u4e0d\u9700\u8981\u53d1\u5e03\u7684\u5305\uff0c\u8fd9\u4e9b\u4f1a\u88ab Changesets \u5ffd\u7565<\/li>\n<\/ul>\n<p>\u5728\u521d\u59cb\u5316 .changeset \u6587\u4ef6\u5939\u540e\uff0c\u5c31\u53ef\u4ee5\u6b63\u5e38\u4f7f\u7528 changeset \u76f8\u5173\u7684\u547d\u4ee4\uff0c\u4e3b\u8981\u662f\u8fd9 3 \u4e2a\u547d\u4ee4\uff1a<\/p>\n<ul>\n<li>pnpm chageset \u7528\u4e8e\u751f\u6210\u672c\u6b21\u4fee\u6539\u7684\u8981\u6dfb\u52a0\u5230 CHANGELOG.md \u4e2d\u7684\u63cf\u8ff0<\/li>\n<li>pnpm changeset version \u7528\u4e8e\u751f\u6210\u672c\u6b21\u4fee\u6539\u540e\u7684\u5305\u7684\u7248\u672c<\/li>\n<li>pnpm changeset publish \u7528\u4e8e\u53d1\u5e03\u5305<\/li>\n<\/ul>\n<p>\u6b64\u5916\uff0c\u5982\u679c\u662f\u5728\u4e1a\u52a1\u573a\u666f\u4e0b\uff0c\u6211\u4eec\u901a\u5e38\u9700\u8981\u628a\u5305\u53d1\u5230\u516c\u53f8 \u79c1\u6709\u7684 NPM Registry \uff0c\u800c\u8fd9\u6709\u5f88\u591a\u79cd\u914d\u7f6e\u65b9\u5f0f\u3002\u4f46\u662f\uff0c \u9700\u8981\u6ce8\u610f \u7684\u662f Changesets \u53ea\u652f\u6301\u5728\u6bcf\u4e2a\u5305\u4e2d\u58f0\u660e publicConfig.registry \u6216\u8005\u914d\u7f6e process.env.npm_config_registry \uff0c\u5bf9\u5e94\u7684\u4ee3\u7801\u4f1a\u662f\u8fd9\u6837\uff1a<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">\/\/ https:\/\/github.com\/changesets\/changesets\/blob\/main\/packages\/cli\/src\/commands\/publish\/npm-utils.ts<\/span><br><span style=\"margin: 0px;padding: 0px\">function<\/span> <span style=\"margin: 0px;padding: 0px\">getCorrectRegistry<\/span>(<span style=\"margin: 0px;padding: 0px\">packageJson<\/span><span style=\"margin: 0px;padding: 0px\">?<\/span>: <span style=\"margin: 0px;padding: 0px\">PackageJSON<\/span>): <span style=\"margin: 0px;padding: 0px\">string<\/span> {<br> <span style=\"margin: 0px;padding: 0px\">const<\/span> <span style=\"margin: 0px;padding: 0px\">registry<\/span> <span style=\"margin: 0px;padding: 0px\">=<\/span><br>   <span style=\"margin: 0px;padding: 0px\">packageJson<\/span>?.<span style=\"margin: 0px;padding: 0px\">publishConfig<\/span>?.<span style=\"margin: 0px;padding: 0px\">registry<\/span> <span style=\"margin: 0px;padding: 0px\">??<\/span> <span style=\"margin: 0px;padding: 0px\">process<\/span>.<span style=\"margin: 0px;padding: 0px\">env<\/span>.<span style=\"margin: 0px;padding: 0px\">npm_config_registry<\/span>;<br> <span style=\"margin: 0px;padding: 0px\">return<\/span> <span style=\"margin: 0px;padding: 0px\">!<\/span><span style=\"margin: 0px;padding: 0px\">registry<\/span> <span style=\"margin: 0px;padding: 0px\">||<\/span> <span style=\"margin: 0px;padding: 0px\">registry<\/span> <span style=\"margin: 0px;padding: 0px\">===<\/span> <span style=\"margin: 0px;padding: 0px\">\"https:\/\/registry.yarnpkg.com\"<\/span><br>   <span style=\"margin: 0px;padding: 0px\">?<\/span> <span style=\"margin: 0px;padding: 0px\">\"https:\/\/registry.npmjs.org\"<\/span><br>   : <span style=\"margin: 0px;padding: 0px\">registry<\/span>;<br>}<\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5982\u679c\u5728\u524d\u9762\u8bf4\u7684\u8fd9 2 \u79cd\u60c5\u51b5\u4e0b\u83b7\u53d6\u4e0d\u5230 registry \u7684\u8bdd\uff0cChangesets \u90fd\u662f\u6309\u516c\u5171\u7684 Registry \u53bb\u67e5\u627e\u6216\u8005\u53d1\u5e03\u5305\u7684\u3002<\/p>\n<h4>Turborepo<br \/><\/h4>\n<p>\u8bf4\u8d77 Turborepo\uff0c\u53ef\u80fd\u5927\u5bb6\u4f1a\u6709\u70b9\u964c\u751f\u3002\u4f46\u662f\uff0c\u5bf9\u4e8e Vercel [17] \u6211\u60f3\u5927\u5bb6\u90fd\u77e5\u9053\uff08\u6bd5\u7adf Rich Harris [18] \u3001Sebastian Markb\u00e5ge \u7b49\u90fd\u52a0\u5165\u4e86\uff09\uff0cTurbrepo \u5219\u662f Vercel \u65d7\u4e0b\u7684\u4e00\u4e2a\u5f00\u6e90\u9879\u76ee\u3002Turborepo \u662f\u7528\u4e8e\u4e3a JavaScript\/TypeScript \u7684 Monorepo \u63d0\u4f9b\u4e00\u4e2a\u6781\u5feb\u7684\u6784\u5efa\u7cfb\u7edf\uff0c\u7b80\u5355\u5730\u7406\u89e3\u5c31\u662f\u7528 Turborepo \u6765\u6267\u884c Monorepo \u9879\u76ee\u7684\u4e2d\u6784\u5efa\uff08\u6216\u8005\u5176\u4ed6\uff09\u4efb\u52a1\u4f1a \u975e\u5e38\u5feb \uff01<\/p>\n<p>\u5173\u4e8e Turborepo \u5176\u4ed6\u4f18\u52bf\uff0c\u5176 \u5b98\u65b9\u6587\u6863 [19] \u5199\u7684\u5f88\u8be6\u5c3d\uff0c\u6709\u5174\u8da3\u7684\u540c\u5b66\u53ef\u4ee5\u81ea\u884c\u4e86\u89e3~<\/p>\n<p>\u6240\u4ee5\uff0c\u4f60\u53ef\u4ee5\u7406\u89e3\u6210 \u5feb \u662f\u9009\u62e9 Turborepo \u8d1f\u8d23 Monorepo \u9879\u76ee\u591a\u5305\u4efb\u52a1\u6267\u884c\u7684\u539f\u56e0\u3002\u800c\u5728 Turborepo \u4e2d\u6267\u884c\u591a\u5305\u4efb\u52a1\u662f\u901a\u8fc7 turbo run &lt;script&gt; \u3002\u4e0d\u8fc7\uff0c turbo run \u548c lerna run \u76f4\u63a5\u4f7f\u7528\u6709\u6240\u4e0d\u540c\uff0c\u5b83\u9700\u8981\u914d\u7f6e turbo.json \u6587\u4ef6\uff0c\u6ce8\u518c\u6bcf\u4e2a\u9700\u8981\u6267\u884c\u7684 script \u547d\u4ee4\u3002<\/p>\n<p>\u5728 Turborepo \u4e2d\u6709\u4e2a Pipelines [20] \u7684\u6982\u5ff5\uff0c\u5b83\u662f\u7531 turbo.json \u6587\u4ef6\u4e2d\u7684 pipline \u5b57\u6bb5\u7684\u914d\u7f6e\u63cf\u8ff0\uff0c\u5b83\u4f1a\u5728\u6267\u884c turbo run \u547d\u4ee4\u7684\u65f6\u5019\uff0c\u6839\u636e\u5bf9\u5e94\u7684\u914d\u7f6e\u8fdb\u884c \u6709\u5e8f\u7684\u6267\u884c \u548c \u7f13\u5b58\u8f93\u51fa\u7684\u6587\u4ef6 \u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u6211\u4eec\u4e00\u4e2a Monorepo \u9879\u76ee\u4e2d\u7684\u6bcf\u4e2a\u5305\u53ef\u80fd\u4f1a\u6709 dev \u3001 build \u3001 test \u3001 clean \u7b49 4 \u4e2a\u547d\u4ee4\uff0c\u90a3\u4e48\u5bf9\u5e94\u7684 turbo.json \u7684\u914d\u7f6e\u4f1a\u662f\u8fd9\u6837\uff1a<\/p>\n<pre>{<br> <span style=\"margin: 0px;padding: 0px\">\"pipeline\"<\/span>: {<br>   <span style=\"margin: 0px;padding: 0px\">\"build\"<\/span>: {<br>     <span style=\"margin: 0px;padding: 0px\">\"dependsOn\"<\/span>: [<span style=\"margin: 0px;padding: 0px\">\"^build\"<\/span>],<br>     <span style=\"margin: 0px;padding: 0px\">\"outputs\"<\/span>: [<span style=\"margin: 0px;padding: 0px\">\"dist\/**\"<\/span>]<br>   },<br>   <span style=\"margin: 0px;padding: 0px\">\"clean\"<\/span>: {<br>     <span style=\"margin: 0px;padding: 0px\">\"dependsOn\"<\/span>: [<span style=\"margin: 0px;padding: 0px\">\"^clean\"<\/span>]<br>   },<br>   <span style=\"margin: 0px;padding: 0px\">\"test\"<\/span>: {<br>     <span style=\"margin: 0px;padding: 0px\">\"dependsOn\"<\/span>: [<span style=\"margin: 0px;padding: 0px\">\"build\"<\/span><span style=\"margin: 0px;padding: 0px\">\uff0c<\/span> <span style=\"margin: 0px;padding: 0px\">\"lint\"<\/span>]<br>   },<br>   <span style=\"margin: 0px;padding: 0px\">\"dev\"<\/span>: {<br>     <span style=\"margin: 0px;padding: 0px\">\"cache\"<\/span>: <span style=\"margin: 0px;padding: 0px\">false<\/span><br>   }<br> }<br>}<\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c pipeline \u4e2d\u7684\u6bcf\u4e2a key \u5219\u5bf9\u5e94\u7740\u6bcf\u4e2a\u9700\u8981\u6267\u884c\u7684 turbo run \u547d\u4ee4\u7684\u540d\u79f0\uff0c\u5176\u4e2d dependsOn \u3001 outputs \u3001 cache \u7b49 3 \u4e2a\u5b57\u6bb5\u5206\u522b\u4f5c\u7528\u4e3a\uff1a<\/p>\n<ul>\n<li>dependsOn \u8868\u793a\u5f53\u524d\u547d\u4ee4\u6240\u4f9d\u8d56\u7684\u547d\u4ee4\uff0c^ \u8868\u793a dependencies \u548c devDependencies \u7684\u6240\u6709\u4f9d\u8d56\u90fd\u6267\u884c\u5b8c build\uff0c\u624d\u6267\u884c build<\/li>\n<li>outputs \u8868\u793a\u547d\u4ee4\u6267\u884c\u8f93\u51fa\u7684\u6587\u4ef6\u7f13\u5b58\u76ee\u5f55\uff0c\u4f8b\u5982\u6211\u4eec\u5e38\u89c1\u7684 dist\u3001coverage \u7b49<\/li>\n<li>cache \u8868\u793a\u662f\u5426\u7f13\u5b58\uff0c\u901a\u5e38\u6211\u4eec\u6267\u884c dev \u547d\u4ee4\u7684\u65f6\u5019\u4f1a\u7ed3\u5408 watch \u6a21\u5f0f\uff0c\u6240\u4ee5\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5173\u95ed\u6389\u7f13\u5b58\u6bd4\u8f83\u5207\u5408\u5b9e\u9645\u9700\u6c42<\/li>\n<\/ul>\n<p>\u8fd9\u6837\u4e00\u6765\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528\u8bf8\u5982 turbo run build test \u7684\u547d\u4ee4\uff0c\u5b83\u5219\u4f1a\u6309 pipeline \u7684\u914d\u7f6e\u4f9d\u6b21\u6267\u884c\u5bf9\u5e94\u7684\u547d\u4ee4\u3002<\/p>\n<p>\u5f53\u7136\uff0c\u5982\u679c\u4f60\u60f3\u6bcf\u4e2a\u547d\u4ee4\u90fd\u652f\u6301\u5355\u72ec\u6267\u884c\uff0c\u53ef\u4ee5\u76f4\u63a5\u914d\u7f6e\u4e3a {} \u5373\u53ef\u3002\u6b64\u5916\uff0c\u5982\u679c\u8981\u4f7f\u7528 turbo run \u547d\u4ee4\uff0c\u8fd8\u9700\u8981\u5728 package.json \u4e2d\u58f0\u660e packageManage \u5b57\u6bb5\u4e3a\u6307\u5b9a\u7684\u5305\u7ba1\u7406\u5de5\u5177\u53ca\u7248\u672c\uff0c\u4f8b\u5982 \"packageManager\": \"pnpm@6.30.0\" \u3002<\/p>\n<h4>\u7ed3\u8bed<br \/><\/h4>\n<p>\u9605\u8bfb\u5230\u6b64\u5904\uff0c\u6211\u60f3\u5927\u5bb6\u5e94\u8be5\u7406\u89e3\u4e86 PNPM + Turborepo + Changesets \u8fd9\u4e2a\u6280\u672f\u9009\u578b\u7684\u539f\u56e0\u4ee5\u53ca\u8981\u600e\u4e48\u505a\u3002\u5f53\u7136\uff0c\u8fd9\u4e2a\u9009\u578b\u53ea\u662f\u6211\u4e2a\u4eba\u7684\u601d\u8003\u6240\u5f97\u51fa\u7684\u7b54\u6848\uff0c\u76f8\u4fe1\u4e5f\u6709\u540c\u5b66\u4ecd\u7136\u949f\u60c5\u4e8e Lerna\uff0c\u53c8\u6216\u8005\u559c\u6b22 Rush \u4e00\u628a\u68ad\uff0c\u8fd9\u4e9b\u89c2\u70b9\u5e76\u65e0\u5bf9\u9519\uff0c\u672c\u8d28\u4e0a\u8fd9\u4e5f\u662f\u7f16\u7a0b\u7684\u9b45\u529b\u6240\u5728\uff0c \u5404\u4e2a\u8f6e\u5b50\u90fd\u6709\u5176\u5b58\u5728\u7684\u4ef7\u503c \u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u76f8\u4fe1\u5f88\u591a\u5173\u6ce8 Monorepo \u751f\u6001\u7684\u540c\u5b66\uff0c\u5e94\u8be5\u5927\u90fd\u770b\u8fc7\u8fd9\u7bc7\u6587\u7ae0 monorepo.tools [1]  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-327088","post","type-post","status-publish","format-standard","hentry","category-website"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/327088","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=327088"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/327088\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=327088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=327088"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=327088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}