1
0
wiki/Professional/Work/full-stack/工具/包管理工具.html

418 lines
470 KiB
HTML
Raw Normal View History

2024-09-06 10:58:26 +08:00
<!DOCTYPE html>
<html lang="zh"><head><title>包管理器</title><meta charset="utf-8"/><link rel="preconnect" href="https://fonts.googleapis.com"/><link rel="preconnect" href="https://fonts.gstatic.com"/><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=IBM Plex Mono&amp;family=Noto Serif Simplified Chinese:wght@400;700&amp;family=Source Sans Pro:ital,wght@0,400;0,600;1,400;1,600&amp;display=swap"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><meta property="og:title" content="包管理器"/><meta property="og:description" content="JavaScript 包管理工具."/><meta property="og:image" content="https://wiki.7wate.com/static/og-image.png"/><meta property="og:width" content="1200"/><meta property="og:height" content="675"/><link rel="icon" href="../../../../static/icon.png"/><meta name="description" content="JavaScript 包管理工具."/><meta name="generator" content="Quartz"/><link href="../../../../index.css" rel="stylesheet" type="text/css" spa-preserve/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/katex.min.css" rel="stylesheet" type="text/css" spa-preserve/><script src="../../../../prescript.js" type="application/javascript" spa-preserve></script><script type="application/javascript" spa-preserve>const fetchData = fetch("../../../../static/contentIndex.json").then(data => data.json())</script></head><body data-slug="Professional/Work/full-stack/工具/包管理工具"><div id="quartz-root" class="page"><div id="quartz-body"><div class="left sidebar"><h2 class="page-title"><a href="../../../..">🪴 X·Eden</a></h2><div class="spacer mobile-only"></div><div class="search"><button class="search-button" id="search-button"><p>搜索</p><svg role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19.9 19.7"><title>Search</title><g class="search-path" fill="none"><path stroke-linecap="square" d="M18.5 18.3l-5.4-5.4"></path><circle cx="8" cy="8" r="7"></circle></g></svg></button><div id="search-container"><div id="search-space"><input autocomplete="off" id="search-bar" name="search" type="text" aria-label="搜索些什么" placeholder="搜索些什么"/><div id="search-layout" data-preview="true"></div></div></div></div><button class="darkmode" id="darkmode"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="dayIcon" x="0px" y="0px" viewBox="0 0 35 35" style="enable-background:new 0 0 35 35" xml:space="preserve" aria-label="暗色模式"><title>暗色模式</title><path d="M6,17.5C6,16.672,5.328,16,4.5,16h-3C0.672,16,0,16.672,0,17.5 S0.672,19,1.5,19h3C5.328,19,6,18.328,6,17.5z M7.5,26c-0.414,0-0.789,0.168-1.061,0.439l-2,2C4.168,28.711,4,29.086,4,29.5 C4,30.328,4.671,31,5.5,31c0.414,0,0.789-0.168,1.06-0.44l2-2C8.832,28.289,9,27.914,9,27.5C9,26.672,8.329,26,7.5,26z M17.5,6 C18.329,6,19,5.328,19,4.5v-3C19,0.672,18.329,0,17.5,0S16,0.672,16,1.5v3C16,5.328,16.671,6,17.5,6z M27.5,9 c0.414,0,0.789-0.168,1.06-0.439l2-2C30.832,6.289,31,5.914,31,5.5C31,4.672,30.329,4,29.5,4c-0.414,0-0.789,0.168-1.061,0.44 l-2,2C26.168,6.711,26,7.086,26,7.5C26,8.328,26.671,9,27.5,9z M6.439,8.561C6.711,8.832,7.086,9,7.5,9C8.328,9,9,8.328,9,7.5 c0-0.414-0.168-0.789-0.439-1.061l-2-2C6.289,4.168,5.914,4,5.5,4C4.672,4,4,4.672,4,5.5c0,0.414,0.168,0.789,0.439,1.06 L6.439,8.561z M33.5,16h-3c-0.828,0-1.5,0.672-1.5,1.5s0.672,1.5,1.5,1.5h3c0.828,0,1.5-0.672,1.5-1.5S34.328,16,33.5,16z M28.561,26.439C28.289,26.168,27.914,26,27.5,26c-0.828,0-1.5,0.672-1.5,1.5c0,0.414,0.168,0.789,0.439,1.06l2,2 C28.711,30.832,29.086,31,29.5,31c0.828,0,1.5-0.672,1.5-1.5c0-0.414-0.168-0.789-0.439-1.061L28.561,26.439z M17.5,29 c-0.829,0-1.5,0.672-1.5,1.5v3c0,0.828,0.671,1.5,1.5,1.5s1.5-0.672,1.5-1.5v-3C19,29.672,18.329,29,17.5,29z M17.5,7 C11.71,7,7,11.71,7,17.5S11.71,28,17.5,28S28,23.29,28,17.5S23.29,7,17.5,7z M17.5,25c-4.136,0-7.5-3.364-7.5-7.5 c0-4.136,3.364-7.5,7.5-7.5c4.136,0,7.5,3.364,7.5,7.5C25,21.636,21.636,25,17.5,25z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="nightIc
<p><strong><a href="https://www.npmjs.com/" class="external">npm<svg aria-hidden="true" class="external-icon" viewBox="0 0 512 512"><path d="M320 0H288V64h32 82.7L201.4 265.4 178.7 288 224 333.3l22.6-22.6L448 109.3V192v32h64V192 32 0H480 320zM32 32H0V64 480v32H32 456h32V480 352 320H424v32 96H64V96h96 32V32H160 32z"></path></svg></a> 是 JavaScript 编写的软件包管理工具,同时也是 node.js 的默认包管理工具。</strong></p>
<h3 id="早期版本">早期版本<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#早期版本" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<p>因为早期 npm 版本采用<strong>嵌套结构</strong>,所以存在依赖地狱和存储空间占用过大问题;同时 Windows 环境下路径限制 256 字符,可能会导致运行出错。</p>
<p><img src="https://static.7wate.com/img/2022/09/06/e22a7d7484ab5.png" alt="node_modules"/></p>
<h3 id="v3-版本">V3 版本<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#v3-版本" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<p>V3 版本采用<strong>扁平结构</strong>来避免过深的依赖树和包冗余,子依赖会<strong>尽量平铺在主依赖所在的目录</strong>中(同一包但版本号不同还是会放至子目录中)。</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="markdown" data-theme="github-light github-dark"><code data-language="markdown" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">node_modules</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">├── A@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">├── B@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">└── C@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> └── node_modules</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> └── B@2.0.0</span></span></code></pre></figure>
<p>虽然解决了依赖地狱的问题,但是又形成了新的问题。</p>
<h4 id="幽灵依赖">幽灵依赖<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#幽灵依赖" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<p>幽灵依赖是指在 package.json 中未定义的依赖,但项目中依然可以正确地被引用到。</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="markdown" data-theme="github-light github-dark"><code data-language="markdown" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">{</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &quot;dependencies&quot;: {</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &quot;A&quot;: &quot;^1.0.0&quot;,</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &quot;C&quot;: &quot;^1.0.0&quot;</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></figure>
<p>例如我们只安装了 A 和 C虽然 A 引用了 B但是因为平铺在同一目录所以在项目中引用 B 还是可以正常工作的。将来如果某个版本的 A 依赖不再依赖 B 或者 B 的版本发生了变化,那么就会造成<strong>依赖缺失</strong>或兼容性问题。</p>
<h4 id="不确定性">不确定性<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#不确定性" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="markdown" data-theme="github-light github-dark"><code data-language="markdown" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">node_modules</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">├── A@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">├── B@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">└── C@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> └── node_modules</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> └── B@2.0.0</span></span></code></pre></figure>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="markdown" data-theme="github-light github-dark"><code data-language="markdown" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">node_modules</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">├── A@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ └── node_modules</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ └── B@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">├── B@2.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">└── C@1.0.0</span></span></code></pre></figure>
<p>不确定性是指同样的 package.json 文件install 依赖后可能不会得到同样的 node_modules 目录结构。如果 A 依赖 B@1.0C 依赖 B@2.0;依赖安装后究竟该提升 B 为 1.0 还是 2.0 取决于用户的安装顺序。</p>
<h4 id="依赖分身">依赖分身<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#依赖分身" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<p>假设继续再安装依赖 B@1.0 的 D 模块和依赖 @B2.0 的 E 模块此时A 和 D 依赖 B@1.0C 和 E 依赖 B@2.0。</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="markdown" data-theme="github-light github-dark"><code data-language="markdown" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">node_modules</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">├── A@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">├── B@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">├── D@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">├── C@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ └── node_modules</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ └── B@2.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">└── E@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> └── node_modules</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> └── B@2.0.0</span></span></code></pre></figure>
<p>可以看到 B@2.0 会被安装两次,实际上无论提升 B@1.0 还是 B@2.0,都会存在重复版本的 B 被安装,这两个重复安装的 B 就叫依赖分身。</p>
<h3 id="安装方式">安装方式<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#安装方式" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<p>可以通过 <a href="https://nodejs.org/zh-cn/" class="external">node.js 官网<svg aria-hidden="true" class="external-icon" viewBox="0 0 512 512"><path d="M320 0H288V64h32 82.7L201.4 265.4 178.7 288 224 333.3l22.6-22.6L448 109.3V192v32h64V192 32 0H480 320zM32 32H0V64 480v32H32 456h32V480 352 320H424v32 96H64V96h96 32V32H160 32z"></path></svg></a> 下载安装,或者直接使用如下脚本。</p>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">curl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -qL</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://www.npmjs.com/install.sh</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> sh</span></span></code></pre></figure>
<h3 id="常用命令">常用命令<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#常用命令" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<div class="table-container"><table><thead><tr><th>命令</th><th>功能</th></tr></thead><tbody><tr><td>npm help</td><td>帮助文档</td></tr><tr><td>npm -v</td><td>npm 版本</td></tr><tr><td>npm config list -l</td><td>npm 配置</td></tr><tr><td>npm init</td><td>初始化引导创建 package.json 文件</td></tr><tr><td>npm set &lt;变量名> &lt;值></td><td>设置环境变量</td></tr><tr><td>npm search &lt;关键词> [-g]</td><td>检索模块</td></tr><tr><td>npm list</td><td>局部查看模块</td></tr><tr><td>npm list -g —depth 0</td><td>全局安装的模块,目录深度为 0。</td></tr><tr><td>npm install</td><td>读取 package.json 安装模块</td></tr><tr><td>npm uninstall &lt;模块> [-g]</td><td>卸载局部模块或全局模块</td></tr><tr><td>npm update &lt;模块> [-g]</td><td>升级局部模块或全局的指定模块</td></tr><tr><td>npm run &lt;脚本></td><td>运行 package.json 脚本</td></tr></tbody></table></div>
<h2 id="yarn">Yarn<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#yarn" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h2>
<p><strong><a href="https://yarnpkg.com/" class="external">yarn<svg aria-hidden="true" class="external-icon" viewBox="0 0 512 512"><path d="M320 0H288V64h32 82.7L201.4 265.4 178.7 288 224 333.3l22.6-22.6L448 109.3V192v32h64V192 32 0H480 320zM32 32H0V64 480v32H32 456h32V480 352 320H424v32 96H64V96h96 32V32H160 32z"></path></svg></a> 同样采用扁平结构,它的出现是为了解决 npm V3 依赖安装速度慢和不确定性。</strong></p>
<h3 id="提升安装速度">提升安装速度<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#提升安装速度" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<p>yarn 采用<strong>并行模式</strong>替代 npm <strong>串行模式</strong>安装包,并且利用全局缓存可以提升较大安装速度。</p>
<h3 id="lockfile-解决不确定性">Lockfile 解决不确定性<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#lockfile-解决不确定性" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<p>安装依赖时,根据 package.josn 生成一份 yarn.lock 文件。因为 lockfile 里记录了依赖,以及依赖的子依赖、依赖的版本、获取地址、验证模块完整性的 hash所以即使是不同的安装顺序相同的依赖关系在任何的环境和容器中都能得到统一的 node_modules 目录结构,保证了依赖安装的确定性。</p>
<p><em><strong>npm v5 才发布 package-lock.json。</strong></em></p>
<h3 id="存在的问题">存在的问题<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#存在的问题" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<p>因为 yarn 和 npm 一样是扁平结构的 node_modules ,所以并没有解决<strong>幽灵依赖</strong><strong>依赖分身</strong>问题。</p>
<h3 id="安装方式-1">安装方式<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#安装方式-1" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">npm</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --global</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> yarn</span></span></code></pre></figure>
<h3 id="常用命令-1">常用命令<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#常用命令-1" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<div class="table-container"><table><thead><tr><th>命令</th><th>功能</th></tr></thead><tbody><tr><td>yarn help</td><td>帮助文档</td></tr><tr><td>yarn init</td><td>初始化项目</td></tr><tr><td>yarn install</td><td>安装所有依赖项</td></tr><tr><td>yarn add [package]</td><td>安装指定依赖项</td></tr><tr><td>yarn add [package]@[version | tag]</td><td>安装指定版本依赖</td></tr><tr><td>yarn up [package]</td><td>升级指定依赖</td></tr><tr><td>yarn up [package]@[version | tag]</td><td>升级指定版本依赖</td></tr><tr><td>yarn remove [package]</td><td>删除指定依赖</td></tr></tbody></table></div>
<h2 id="pnpm">Pnpm<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#pnpm" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h2>
<p><img src="https://static.7wate.com/img/2022/09/06/962148e0d436e.jpg" alt="img"/></p>
<p><a href="https://pnpm.io/zh/" class="external">pnpm<svg aria-hidden="true" class="external-icon" viewBox="0 0 512 512"><path d="M320 0H288V64h32 82.7L201.4 265.4 178.7 288 224 333.3l22.6-22.6L448 109.3V192v32h64V192 32 0H480 320zM32 32H0V64 480v32H32 456h32V480 352 320H424v32 96H64V96h96 32V32H160 32z"></path></svg></a> 不同于 npm 和 yarn 使用的扁平结构,而是采用了<strong>内容寻址存储</strong>。pnpm 通过设置<strong>全局 store</strong>,然后在项目中通过使用<strong>硬链接与符号链接</strong>引用依赖。为了实现此功能node_modules 目录下会多出 .pnpm 目录,而且是非扁平结构。</p>
<ul>
<li><strong>硬链接 Hard link</strong>:硬链接可以理解为<strong>源文件的副本</strong></li>
<li><strong>符号链接 Symbolic link</strong>:符号链接(软连接)可以理解为<strong>快捷方式</strong></li>
</ul>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="markdown" data-theme="github-light github-dark"><code data-language="markdown" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;store>/xxx 开头的路径是硬链接,指向全局 store 中安装的依赖。其余的是符号链接,指向依赖的快捷方式。</span></span>
<span data-line> </span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">node_modules</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">├── .pnpm</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ ├── A@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ │ └── node_modules</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ │ ├── A => &lt;store>/A@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ │ └── B => ../../B@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ ├── B@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ │ └── node_modules</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ │ └── B => &lt;store>/B@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ ├── B@2.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ │ └── node_modules</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ │ └── B => &lt;store>/B@2.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ └── C@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ └── node_modules</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ ├── C => &lt;store>/C@1.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">│ └── B => ../../B@2.0.0</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"></span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">├── A => .pnpm/A@1.0.0/node_modules/A</span></span>
<span data-line><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">└── C => .pnpm/C@1.0.0/node_modules/C</span></span></code></pre></figure>
<h3 id="未来可期">未来可期<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#未来可期" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<p>pnpm 这套全新的机制设计地十分巧妙,不仅兼容 node 的依赖解析,同时也解决了如下问题:</p>
<ul>
<li>
<p>幽灵依赖:只有直接依赖会平铺在 node_modules 下,子依赖不会被提升,不会产生幽灵依赖。</p>
</li>
<li>
<p>依赖分身:相同的依赖只会在全局 store 中安装一次。项目中的都是源文件的副本,几乎不占用任何空间,没有了依赖分身。</p>
</li>
</ul>
<p>同时由于链接的优势pnpm 的安装速度在大多数场景比 npm 和 yarn 快 2 倍,同时也节省更多的磁盘空间。但也存在一些弊端:</p>
<ul>
<li>
<p>因为 pnpm 创建的 node_modules 依赖软链接,所以在不支持软链接的环境中无法使用 pnpm比如 Electron 应用。</p>
</li>
<li>
<p>因为依赖源文件是安装在 store 中,调试依赖或 patch-package 给依赖打补丁也不太方便,可能会影响其他项目。</p>
</li>
</ul>
<h3 id="安装方式-2">安装方式<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#安装方式-2" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<h4 id="npm-1">Npm<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#npm-1" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">npm</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -g</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pnpm</span></span></code></pre></figure>
<h4 id="curl">Curl<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#curl" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h4>
<figure data-rehype-pretty-code-figure><pre tabindex="0" data-language="shell" data-theme="github-light github-dark"><code data-language="shell" data-theme="github-light github-dark" style="display:grid;"><span data-line><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">curl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -fsSL</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://get.pnpm.io/install.sh</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> sh</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> -</span></span></code></pre></figure>
<h3 id="常用命令-2">常用命令<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#常用命令-2" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h3>
<div class="table-container"><table><thead><tr><th>命令</th><th>功能</th></tr></thead><tbody><tr><td><code>pnpm install</code></td><td>安装 package.json 文件中的所有依赖项</td></tr><tr><td><code>pnpm add &lt;pkg></code></td><td>安装指定的依赖项</td></tr><tr><td><code>pnpm update</code></td><td>更新所有的依赖项</td></tr><tr><td><code>pnpm uninstall</code></td><td>移除指定的依赖项</td></tr><tr><td><code>pnpm list</code></td><td>列出已安装的所有依赖项</td></tr><tr><td><code>pnpm run</code></td><td>运行在 package.json 文件中定义的脚本</td></tr><tr><td><code>pnpm test</code></td><td>运行测试</td></tr><tr><td><code>pnpm link</code></td><td>创建或者删除一个软链接到全局安装的依赖项</td></tr><tr><td><code>pnpm prune</code></td><td>移除无用的依赖项</td></tr><tr><td><code>pnpm publish</code></td><td>将你的包发布到 npm 注册表</td></tr><tr><td><code>pnpm root</code></td><td>打印全局安装的依赖项的位置</td></tr><tr><td><code>pnpm store</code></td><td>控制共享的包存储</td></tr><tr><td><code>pnpm outdated</code></td><td>检查哪些依赖项有新版本可以更新</td></tr><tr><td><code>pnpm rebuild</code></td><td>重新编译包</td></tr><tr><td><code>pnpm import</code></td><td>从 npm 转换一个项目</td></tr><tr><td><code>pnpm fetch</code></td><td>预下载所有从注册表下载的依赖项到本地的存储库</td></tr><tr><td><code>pnpm audit</code></td><td>检查项目依赖项中的已知的漏洞</td></tr></tbody></table></div>
<h2 id="npmyarnpnpm-功能比较">npmyarnpnpm 功能比较<a role="anchor" aria-hidden="true" tabindex="-1" data-no-popover="true" href="#npmyarnpnpm-功能比较" class="internal"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg></a></h2>
<div class="table-container"><table><thead><tr><th>功能</th><th>pnpm</th><th>Yarn</th><th>npm</th></tr></thead><tbody><tr><td>工作空间支持monorepo</td><td>✔️</td><td>✔️</td><td>✔️</td></tr><tr><td>隔离的 <code>node_modules</code></td><td>✔️ - 默认</td><td>✔️</td><td></td></tr><tr><td>提升的 <code>node_modules</code></td><td>✔️</td><td>✔️</td><td>✔️ - 默认</td></tr><tr><td>自动安装 peers</td><td>✔️ - 通过 <a href="https://pnpm.io/zh/npmrc#auto-install-peers" class="external">auto-install-peers=true<svg aria-hidden="true" class="external-icon" viewBox="0 0 512 512"><path d="M320 0H288V64h32 82.7L201.4 265.4 178.7 288 224 333.3l22.6-22.6L448 109.3V192v32h64V192 32 0H480 320zM32 32H0V64 480v32H32 456h32V480 352 320H424v32 96H64V96h96 32V32H160 32z"></path></svg></a></td><td></td><td>✔️</td></tr><tr><td>PlugnPlay</td><td>✔️</td><td>✔️ - 默认</td><td></td></tr><tr><td>零安装</td><td></td><td>✔️</td><td></td></tr><tr><td>修补依赖项</td><td>✔️</td><td>✔️</td><td></td></tr><tr><td>管理 Node.js 版本</td><td>✔️</td><td></td><td></td></tr><tr><td>有锁文件</td><td>✔️ - <code>pnpm-lock.yaml</code></td><td>✔️ - <code>yarn.lock</code></td><td>✔️ - <code>package-lock.json</code></td></tr><tr><td>支持覆盖</td><td>✔️</td><td>✔️ - 通过 resolutions</td><td>✔️</td></tr><tr><td>内容可寻址存储</td><td>✔️</td><td></td><td></td></tr><tr><td>动态包执行</td><td>✔️ - 通过 <code>pnpm dlx</code></td><td>✔️ - 通过 <code>yarn dlx</code></td><td>✔️ - 通过 <code>npx</code></td></tr><tr><td>Side-effects cache</td><td>✔️</td><td></td><td></td></tr></tbody></table></div></article><hr/><div class="page-footer"></div></div><div class="right sidebar"><div class="graph"><h3>关系图谱</h3><div class="graph-outer"><div id="graph-container" data-cfg="{&quot;drag&quot;:true,&quot;zoom&quot;:true,&quot;depth&quot;:1,&quot;scale&quot;:1.1,&quot;repelForce&quot;:0.5,&quot;centerForce&quot;:0.3,&quot;linkDistance&quot;:30,&quot;fontSize&quot;:0.6,&quot;opacityScale&quot;:1,&quot;showTags&quot;:true,&quot;removeTags&quot;:[],&quot;focusOnHover&quot;:false}"></div><button id="global-graph-icon" aria-label="Global Graph"><svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 55 55" fill="currentColor" xml:space="preserve"><path d="M49,0c-3.309,0-6,2.691-6,6c0,1.035,0.263,2.009,0.726,2.86l-9.829,9.829C32.542,17.634,30.846,17,29,17
s-3.542,0.634-4.898,1.688l-7.669-7.669C16.785,10.424,17,9.74,17,9c0-2.206-1.794-4-4-4S9,6.794,9,9s1.794,4,4,4
c0.74,0,1.424-0.215,2.019-0.567l7.669,7.669C21.634,21.458,21,23.154,21,25s0.634,3.542,1.688,4.897L10.024,42.562
C8.958,41.595,7.549,41,6,41c-3.309,0-6,2.691-6,6s2.691,6,6,6s6-2.691,6-6c0-1.035-0.263-2.009-0.726-2.86l12.829-12.829
c1.106,0.86,2.44,1.436,3.898,1.619v10.16c-2.833,0.478-5,2.942-5,5.91c0,3.309,2.691,6,6,6s6-2.691,6-6c0-2.967-2.167-5.431-5-5.91
v-10.16c1.458-0.183,2.792-0.759,3.898-1.619l7.669,7.669C41.215,39.576,41,40.26,41,41c0,2.206,1.794,4,4,4s4-1.794,4-4
s-1.794-4-4-4c-0.74,0-1.424,0.215-2.019,0.567l-7.669-7.669C36.366,28.542,37,26.846,37,25s-0.634-3.542-1.688-4.897l9.665-9.665
C46.042,11.405,47.451,12,49,12c3.309,0,6-2.691,6-6S52.309,0,49,0z M11,9c0-1.103,0.897-2,2-2s2,0.897,2,2s-0.897,2-2,2
S11,10.103,11,9z M6,51c-2.206,0-4-1.794-4-4s1.794-4,4-4s4,1.794,4,4S8.206,51,6,51z M33,49c0,2.206-1.794,4-4,4s-4-1.794-4-4
s1.794-4,4-4S33,46.794,33,49z M29,31c-3.309,0-6-2.691-6-6s2.691-6,6-6s6,2.691,6,6S32.309,31,29,31z M47,41c0,1.103-0.897,2-2,2
s-2-0.897-2-2s0.897-2,2-2S47,39.897,47,41z M49,10c-2.206,0-4-1.794-4-4s1.794-4,4-4s4,1.794,4,4S51.206,10,49,10z"></path></svg></button></div><div id="global-graph-outer"><div id="global-graph-container" data-cfg="{&quot;drag&quot;:true,&quot;zoom&quot;:true,&quot;depth&quot;:-1,&quot;scale&quot;:0.9,&quot;repelForce&quot;:0.5,&quot;centerForce&quot;:0.3,&quot;linkDistance&quot;:30,&quot;fontSize&quot;:0.6,&quot;opacityScale&quot;:1,&quot;showTags&quot;:true,&quot;removeTags&quot;:[],&quot;focusOnHover&quot;:true}"></div></div></div><div class="toc desktop-only"><button type="button" id="toc" class aria-controls="toc-content" aria-expanded="true"><h3>目录</h3><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="fold"><polyline points="6 9 12 15 18 9"></polyline></svg></button><div id="toc-content" class><ul class="overflow"><li class="depth-0"><a href="#npm" data-for="npm">Npm</a></li><li class="depth-1"><a href="#早期版本" data-for="早期版本">早期版本</a></li><li class="depth-1"><a href="#v3-版本" data-for="v3-版本">V3 版本</a></li><li class="depth-1"><a href="#安装方式" data-for="安装方式">安装方式</a></li><li class="depth-1"><a href="#常用命令" data-for="常用命令">常用命令</a></li><li class="depth-0"><a href="#yarn" data-for="yarn">Yarn</a></li><li class="depth-1"><a href="#提升安装速度" data-for="提升安装速度">提升安装速度</a></li><li class="depth-1"><a href="#lockfile-解决不确定性" data-for="lockfile-解决不确定性">Lockfile 解决不确定性</a></li><li class="depth-1"><a href="#存在的问题" data-for="存在的问题">存在的问题</a></li><li class="depth-1"><a href="#安装方式-1" data-for="安装方式-1">安装方式</a></li><li class="depth-1"><a href="#常用命令-1" data-for="常用命令-1">常用命令</a></li><li class="depth-0"><a href="#pnpm" data-for="pnpm">Pnpm</a></li><li class="depth-1"><a href="#未来可期" data-for="未来可期">未来可期</a></li><li class="depth-1"><a href="#安装方式-2" data-for="安装方式-2">安装方式</a></li><li class="depth-1"><a href="#常用命令-2" data-for="常用命令-2">常用命令</a></li><li class="depth-0"><a href="#npmyarnpnpm-功能比较" data-for="npmyarnpnpm-功能比较">npmyarnpnpm 功能比较</a></li></ul></div></div><div class="explorer mobile-only"><button type="button" id="explorer" data-behavior="collapse" data-collapsed="collapsed" data-savestate="true" data-tree="[{&quot;path&quot;:&quot;Personal&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2018&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2020&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2021&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2022&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2023&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Blog/2024&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/个人成长&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/医学健康&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/历史&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/哲学宗教&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/心理&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/政治军事&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/教育学习&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/文学&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/生活百科&quot;,&quot;collapsed&quot;:true},{&quot;path&quot;:&quot;Personal/Book/社会
</script><script type="module">
let mermaidImport = undefined
document.addEventListener('nav', async () => {
if (document.querySelector("code.mermaid")) {
mermaidImport ||= await import('https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.7.0/mermaid.esm.min.mjs')
const mermaid = mermaidImport.default
const darkMode = document.documentElement.getAttribute('saved-theme') === 'dark'
mermaid.initialize({
startOnLoad: false,
securityLevel: 'loose',
theme: darkMode ? 'dark' : 'default'
})
await mermaid.run({
querySelector: '.mermaid'
})
}
});
</script><script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/contrib/copy-tex.min.js" type="application/javascript"></script><script src="../../../../postscript.js" type="module"></script></html>