pnpm-link 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -51
- package/dist/index.js +186 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# pnpm-link
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
跨项目本地包链接工具,提供 `link` / `unlink` 子命令,适用于 pnpm 11 及更新版本移除 `pnpm link --global` 后的本地开发工作流。
|
|
4
4
|
|
|
5
5
|
## 功能
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
7
|
+
- 将当前包注册到 pnpm 全局包目录,并链接其命令行 bin
|
|
8
|
+
- 将全局已注册的包或本地路径包写入当前项目依赖
|
|
9
|
+
- 从项目中移除本地链接依赖,或注销当前包的全局链接
|
|
10
10
|
- 默认在当前执行目录下查找 `package.json`
|
|
11
|
-
- 支持 `file:` 与 `link:`
|
|
12
|
-
- 支持 `--save-dev` / `--save-prod
|
|
11
|
+
- 支持 `file:` 与 `link:` 两种依赖协议,默认使用 `link:`
|
|
12
|
+
- 支持 `--save-dev` / `--save-prod`
|
|
13
13
|
|
|
14
14
|
## 安装
|
|
15
15
|
|
|
@@ -19,70 +19,58 @@ npm i -g pnpm-link
|
|
|
19
19
|
pnpm add -g pnpm-link
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
##
|
|
22
|
+
## 跨项目链接
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
pnpm-link --global
|
|
26
|
-
pnpm-link <package-name>
|
|
27
|
-
pnpm-link <package-name> --save-dev
|
|
28
|
-
pnpm-link <package-name> --save-prod
|
|
29
|
-
pnpm-link ./packages/my-lib --protocol file
|
|
30
|
-
pnpm-link ./packages/my-lib --protocol link
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## 跨项目链接(替代 `pnpm link --global`)
|
|
34
|
-
|
|
35
|
-
pnpm 11 及更新版本已移除 `pnpm link --global`。`pnpm-link` 提供相同的“先在 A 注册、再从 B 按包名引用”工作流:
|
|
24
|
+
在项目 A 中注册包,再在项目 B 中按包名链接:
|
|
36
25
|
|
|
37
26
|
```bash
|
|
38
27
|
# 项目 A:进入要共享的包目录,package.json 必须有 name
|
|
39
28
|
cd /path/to/project-a/packages/my-lib
|
|
40
|
-
pnpm-link --global
|
|
29
|
+
pnpm-link link --global
|
|
41
30
|
|
|
42
|
-
# 项目 B
|
|
31
|
+
# 项目 B:按 A 包 package.json 中的 name 引用
|
|
43
32
|
cd /path/to/project-b
|
|
44
|
-
pnpm-link @my-scope/my-lib --save-dev
|
|
33
|
+
pnpm-link link @my-scope/my-lib --save-dev
|
|
45
34
|
```
|
|
46
35
|
|
|
47
36
|
第一条命令会把 A 包注册到 pnpm 全局包目录;如果包声明了 `bin`,也会在全局 bin 目录创建对应链接。第二条命令会把指向 A 源码目录的 `link:` 依赖写入 B 的 `devDependencies`,并自动运行 `pnpm install`。A 中源码的修改会直接反映在 B 使用的链接包中。
|
|
48
37
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
## 参数说明
|
|
38
|
+
不传 `--save-dev` 时,依赖默认写入 `dependencies`。也可以直接链接本地路径:
|
|
52
39
|
|
|
53
|
-
|
|
54
|
-
-
|
|
55
|
-
-
|
|
56
|
-
|
|
57
|
-
- `-h, --help`:显示帮助
|
|
58
|
-
- `-v, --version`:显示版本
|
|
40
|
+
```bash
|
|
41
|
+
pnpm-link link ./packages/my-lib
|
|
42
|
+
pnpm-link link ./packages/my-lib --protocol file
|
|
43
|
+
```
|
|
59
44
|
|
|
60
|
-
##
|
|
45
|
+
## 解除链接
|
|
61
46
|
|
|
62
47
|
```bash
|
|
63
|
-
#
|
|
64
|
-
|
|
65
|
-
pnpm-link --global
|
|
48
|
+
# 项目 B:移除 link: 或 file: 依赖并更新安装
|
|
49
|
+
pnpm-link unlink @my-scope/my-lib
|
|
66
50
|
|
|
67
|
-
#
|
|
68
|
-
|
|
69
|
-
|
|
51
|
+
# 项目 A:注销全局包及其命令行 bin 链接
|
|
52
|
+
pnpm-link unlink --global
|
|
53
|
+
```
|
|
70
54
|
|
|
71
|
-
|
|
72
|
-
pnpm-link package-a --save-dev
|
|
55
|
+
`unlink <package-name>` 只移除当前项目中 `link:` 或 `file:` 协议的依赖,不会删除普通 registry 依赖。`unlink --global` 只删除指向当前包目录及其 bin 文件的符号链接;如果目标位置已被其他内容占用,命令会报错而不会删除它。
|
|
73
56
|
|
|
74
|
-
|
|
75
|
-
pnpm-link /path/to/package-a
|
|
57
|
+
## 命令参数
|
|
76
58
|
|
|
77
|
-
|
|
78
|
-
pnpm-link
|
|
79
|
-
|
|
59
|
+
- `pnpm-link link <package-name|path>`:将全局包或本地路径包链接到当前项目
|
|
60
|
+
- `pnpm-link link --global`:将当前包注册到 pnpm 全局目录
|
|
61
|
+
- `pnpm-link unlink <package-name>`:从当前项目移除链接依赖
|
|
62
|
+
- `pnpm-link unlink --global`:从 pnpm 全局目录注销当前包
|
|
63
|
+
- `-D, --save-dev`:写入 `devDependencies`
|
|
64
|
+
- `-P, --save-prod`:写入 `dependencies`
|
|
65
|
+
- `-p, --protocol <protocol>`:依赖协议,可选 `file` 或 `link`,默认 `link`
|
|
66
|
+
- `-h, --help`:显示帮助
|
|
67
|
+
- `-v, --version`:显示版本
|
|
80
68
|
|
|
81
|
-
|
|
69
|
+
`--global` 必须与 `link` 或 `unlink` 子命令一起使用;旧的顶层 `pnpm-link --global` 语法不再支持。
|
|
82
70
|
|
|
83
|
-
|
|
71
|
+
## 实现原理
|
|
84
72
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
73
|
+
- `link --global` 根据当前 `package.json` 的包名,将包目录符号链接到 `pnpm root -g`;声明的 `bin` 命令也会链接到 `pnpm bin -g`
|
|
74
|
+
- `link <package-name>` 从全局包目录查找包;`link <path>` 解析本地路径。随后将 `file:` 或 `link:` 依赖写入当前项目的 `package.json`,并运行 `pnpm install`
|
|
75
|
+
- `unlink <package-name>` 从项目的依赖字段移除对应的 `link:` / `file:` 依赖,并运行 `pnpm install`
|
|
76
|
+
- `unlink --global` 只移除指向当前包及其 bin 文件的全局符号链接
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var require_package = __commonJS({
|
|
|
31
31
|
"package.json"(exports2, module2) {
|
|
32
32
|
module2.exports = {
|
|
33
33
|
name: "pnpm-link",
|
|
34
|
-
version: "1.0
|
|
34
|
+
version: "1.1.0",
|
|
35
35
|
description: "\u628A\u5168\u5C40\u5DF2 link \u7684\u5305\u6216\u672C\u5730\u5305\u5199\u5165\u5F53\u524D\u9879\u76EE\u4F9D\u8D56\uFF0C\u9002\u7528\u4E8E pnpm \u5DE5\u4F5C\u6D41",
|
|
36
36
|
keywords: [
|
|
37
37
|
"pnpm",
|
|
@@ -696,6 +696,12 @@ var import_node_child_process = require("child_process");
|
|
|
696
696
|
var import_node_fs = __toESM(require("fs"));
|
|
697
697
|
var import_node_path = __toESM(require("path"));
|
|
698
698
|
var SCOPED_PACKAGE_RE = /^@[^/\\]+\/[^/\\]+$/;
|
|
699
|
+
var DEPENDENCY_FIELDS = [
|
|
700
|
+
"dependencies",
|
|
701
|
+
"devDependencies",
|
|
702
|
+
"optionalDependencies",
|
|
703
|
+
"peerDependencies"
|
|
704
|
+
];
|
|
699
705
|
function packagePathFromName(globalRoot, packageName) {
|
|
700
706
|
const isScopedName = SCOPED_PACKAGE_RE.test(packageName);
|
|
701
707
|
const segments = packageName.split("/");
|
|
@@ -726,8 +732,22 @@ function linkPath(targetPath, destinationPath) {
|
|
|
726
732
|
import_node_fs.default.mkdirSync(import_node_path.default.dirname(destinationPath), { recursive: true });
|
|
727
733
|
import_node_fs.default.symlinkSync(targetPath, destinationPath, "junction");
|
|
728
734
|
}
|
|
729
|
-
function
|
|
730
|
-
|
|
735
|
+
function unlinkPath(targetPath, destinationPath) {
|
|
736
|
+
if (!import_node_fs.default.existsSync(destinationPath)) return;
|
|
737
|
+
const stat = import_node_fs.default.lstatSync(destinationPath);
|
|
738
|
+
if (!stat.isSymbolicLink()) {
|
|
739
|
+
throw new Error(
|
|
740
|
+
`Cannot remove link; path is not a symbolic link: ${destinationPath}`
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
if (import_node_fs.default.realpathSync(destinationPath) !== targetPath) {
|
|
744
|
+
throw new Error(
|
|
745
|
+
`Cannot remove link; it points to a different target: ${destinationPath}`
|
|
746
|
+
);
|
|
747
|
+
}
|
|
748
|
+
import_node_fs.default.unlinkSync(destinationPath);
|
|
749
|
+
}
|
|
750
|
+
function readCurrentPackage(targetPkgPath) {
|
|
731
751
|
if (!import_node_fs.default.existsSync(targetPkgPath)) {
|
|
732
752
|
throw new Error(
|
|
733
753
|
"No package.json found in current directory. Run this command in the package root."
|
|
@@ -738,17 +758,20 @@ function linkCurrentPackageGlobally(options = {}) {
|
|
|
738
758
|
if (typeof pkg.name !== "string" || !pkg.name) {
|
|
739
759
|
throw new Error("The current package.json must define a package name.");
|
|
740
760
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
const bins = resolveBins(pkg.bin, pkg.name);
|
|
745
|
-
const binEntries = Object.entries(bins);
|
|
761
|
+
return { packageDir, name: pkg.name, bin: pkg.bin };
|
|
762
|
+
}
|
|
763
|
+
function getGlobalLinkPaths(packageDir, packageName, bin, globalRoot, globalBinDir) {
|
|
746
764
|
const links = [
|
|
747
|
-
{
|
|
765
|
+
{
|
|
766
|
+
targetPath: packageDir,
|
|
767
|
+
destinationPath: packagePathFromName(globalRoot, packageName)
|
|
768
|
+
}
|
|
748
769
|
];
|
|
770
|
+
const binEntries = Object.entries(resolveBins(bin, packageName));
|
|
749
771
|
if (binEntries.length > 0) {
|
|
750
|
-
|
|
751
|
-
|
|
772
|
+
if (!globalBinDir) {
|
|
773
|
+
throw new Error("pnpm bin -g returned an empty path.");
|
|
774
|
+
}
|
|
752
775
|
for (const [commandName, binPath] of binEntries) {
|
|
753
776
|
if (!commandName || commandName === "." || commandName === ".." || commandName.includes("/") || commandName.includes("\\")) {
|
|
754
777
|
throw new Error(
|
|
@@ -758,10 +781,9 @@ function linkCurrentPackageGlobally(options = {}) {
|
|
|
758
781
|
const targetPath = import_node_path.default.resolve(packageDir, binPath);
|
|
759
782
|
const relativePath = import_node_path.default.relative(packageDir, targetPath);
|
|
760
783
|
if (relativePath === ".." || relativePath.startsWith(`..${import_node_path.default.sep}`)) {
|
|
761
|
-
throw new Error(
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
throw new Error(`Executable does not exist: ${targetPath}`);
|
|
784
|
+
throw new Error(
|
|
785
|
+
`Executable path must be inside the package: "${binPath}"`
|
|
786
|
+
);
|
|
765
787
|
}
|
|
766
788
|
links.push({
|
|
767
789
|
targetPath,
|
|
@@ -769,13 +791,72 @@ function linkCurrentPackageGlobally(options = {}) {
|
|
|
769
791
|
});
|
|
770
792
|
}
|
|
771
793
|
}
|
|
794
|
+
return links;
|
|
795
|
+
}
|
|
796
|
+
function linkCurrentPackageGlobally(options = {}) {
|
|
797
|
+
const targetPkgPath = import_node_path.default.resolve(options.targetPkgPath ?? "./package.json");
|
|
798
|
+
const pkg = readCurrentPackage(targetPkgPath);
|
|
799
|
+
const globalRoot = (0, import_node_child_process.execSync)("pnpm root -g", { encoding: "utf-8" }).trim();
|
|
800
|
+
if (!globalRoot) throw new Error("pnpm root -g returned an empty path.");
|
|
801
|
+
const binEntries = Object.entries(resolveBins(pkg.bin, pkg.name));
|
|
802
|
+
const globalBinDir = binEntries.length > 0 ? (0, import_node_child_process.execSync)("pnpm bin -g", { encoding: "utf-8" }).trim() : void 0;
|
|
803
|
+
if (binEntries.length > 0 && !globalBinDir) {
|
|
804
|
+
throw new Error("pnpm bin -g returned an empty path.");
|
|
805
|
+
}
|
|
806
|
+
const links = getGlobalLinkPaths(
|
|
807
|
+
pkg.packageDir,
|
|
808
|
+
pkg.name,
|
|
809
|
+
pkg.bin,
|
|
810
|
+
globalRoot,
|
|
811
|
+
globalBinDir
|
|
812
|
+
);
|
|
772
813
|
for (const link of links) {
|
|
814
|
+
if (!import_node_fs.default.existsSync(link.targetPath)) {
|
|
815
|
+
throw new Error(`Link target does not exist: ${link.targetPath}`);
|
|
816
|
+
}
|
|
773
817
|
assertLinkAvailable(link.targetPath, link.destinationPath);
|
|
774
818
|
}
|
|
775
819
|
for (const link of links) {
|
|
776
820
|
linkPath(link.targetPath, link.destinationPath);
|
|
777
821
|
}
|
|
778
|
-
console.log(`\u2705 Linked "${pkg.name}" globally from "${packageDir}"`);
|
|
822
|
+
console.log(`\u2705 Linked "${pkg.name}" globally from "${pkg.packageDir}"`);
|
|
823
|
+
}
|
|
824
|
+
function unlinkCurrentPackageGlobally(options = {}) {
|
|
825
|
+
const targetPkgPath = import_node_path.default.resolve(options.targetPkgPath ?? "./package.json");
|
|
826
|
+
const pkg = readCurrentPackage(targetPkgPath);
|
|
827
|
+
const globalRoot = (0, import_node_child_process.execSync)("pnpm root -g", { encoding: "utf-8" }).trim();
|
|
828
|
+
if (!globalRoot) throw new Error("pnpm root -g returned an empty path.");
|
|
829
|
+
const binEntries = Object.entries(resolveBins(pkg.bin, pkg.name));
|
|
830
|
+
const globalBinDir = binEntries.length > 0 ? (0, import_node_child_process.execSync)("pnpm bin -g", { encoding: "utf-8" }).trim() : void 0;
|
|
831
|
+
if (binEntries.length > 0 && !globalBinDir) {
|
|
832
|
+
throw new Error("pnpm bin -g returned an empty path.");
|
|
833
|
+
}
|
|
834
|
+
const links = getGlobalLinkPaths(
|
|
835
|
+
pkg.packageDir,
|
|
836
|
+
pkg.name,
|
|
837
|
+
pkg.bin,
|
|
838
|
+
globalRoot,
|
|
839
|
+
globalBinDir
|
|
840
|
+
);
|
|
841
|
+
for (const link of links) {
|
|
842
|
+
if (import_node_fs.default.existsSync(link.destinationPath)) {
|
|
843
|
+
const stat = import_node_fs.default.lstatSync(link.destinationPath);
|
|
844
|
+
if (!stat.isSymbolicLink()) {
|
|
845
|
+
throw new Error(
|
|
846
|
+
`Cannot remove link; path is not a symbolic link: ${link.destinationPath}`
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
if (import_node_fs.default.realpathSync(link.destinationPath) !== link.targetPath) {
|
|
850
|
+
throw new Error(
|
|
851
|
+
`Cannot remove link; it points to a different target: ${link.destinationPath}`
|
|
852
|
+
);
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
for (const link of links) {
|
|
857
|
+
unlinkPath(link.targetPath, link.destinationPath);
|
|
858
|
+
}
|
|
859
|
+
console.log(`\u2705 Unlinked "${pkg.name}" from the global directory`);
|
|
779
860
|
}
|
|
780
861
|
function isLocalPackageReference(value) {
|
|
781
862
|
return value.startsWith("./") || value.startsWith("../") || value.startsWith("/") || value.startsWith("file:") || value.includes("\\") || value.includes("/") && !SCOPED_PACKAGE_RE.test(value);
|
|
@@ -859,6 +940,43 @@ function linkPackageToProject(options) {
|
|
|
859
940
|
});
|
|
860
941
|
console.log(`\u2705 Updated ${depType}["${depKey}"] = "${depValue}"`);
|
|
861
942
|
}
|
|
943
|
+
function unlinkPackageFromProject(options) {
|
|
944
|
+
const { packageName, targetPkgPath = "./package.json" } = options;
|
|
945
|
+
assertValidPackageInput(packageName);
|
|
946
|
+
const targetAbs = import_node_path.default.resolve(targetPkgPath);
|
|
947
|
+
if (!import_node_fs.default.existsSync(targetAbs)) {
|
|
948
|
+
throw new Error(
|
|
949
|
+
"No package.json found in current directory. Run this command in your project root."
|
|
950
|
+
);
|
|
951
|
+
}
|
|
952
|
+
const projectDir = import_node_path.default.dirname(targetAbs);
|
|
953
|
+
const pkg = JSON.parse(import_node_fs.default.readFileSync(targetAbs, "utf-8"));
|
|
954
|
+
const linkedFields = [];
|
|
955
|
+
for (const field of DEPENDENCY_FIELDS) {
|
|
956
|
+
const dependencies = pkg[field];
|
|
957
|
+
if (dependencies && typeof dependencies === "object" && !Array.isArray(dependencies)) {
|
|
958
|
+
const specifier = dependencies[packageName];
|
|
959
|
+
if (typeof specifier === "string" && /^(?:link|file):/.test(specifier)) {
|
|
960
|
+
linkedFields.push(field);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
if (linkedFields.length === 0) {
|
|
965
|
+
throw new Error(
|
|
966
|
+
`No linked dependency "${packageName}" found in the current project.`
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
for (const field of linkedFields) {
|
|
970
|
+
const dependencies = pkg[field];
|
|
971
|
+
delete dependencies[packageName];
|
|
972
|
+
}
|
|
973
|
+
import_node_fs.default.writeFileSync(targetAbs, JSON.stringify(pkg, null, 2) + "\n");
|
|
974
|
+
(0, import_node_child_process.execSync)("pnpm install", {
|
|
975
|
+
cwd: projectDir,
|
|
976
|
+
stdio: "inherit"
|
|
977
|
+
});
|
|
978
|
+
console.log(`\u2705 Removed linked dependency "${packageName}" from the project`);
|
|
979
|
+
}
|
|
862
980
|
|
|
863
981
|
// src/cli.ts
|
|
864
982
|
var { version: cliVersion } = require_package();
|
|
@@ -869,23 +987,26 @@ function resolveDepType(options) {
|
|
|
869
987
|
return normalized === "devDependencies" ? "devDependencies" : "dependencies";
|
|
870
988
|
}
|
|
871
989
|
function runLinkCommand(packageName, options) {
|
|
872
|
-
|
|
990
|
+
try {
|
|
873
991
|
if (options.global) {
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
targetPkgPath: import_node_path2.default.resolve(process.cwd(), "package.json")
|
|
877
|
-
});
|
|
878
|
-
return;
|
|
879
|
-
} catch (err) {
|
|
880
|
-
console.error(err.message);
|
|
881
|
-
process.exit(1);
|
|
992
|
+
if (packageName) {
|
|
993
|
+
throw new Error('Do not specify a package name with "link --global".');
|
|
882
994
|
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
995
|
+
linkCurrentPackageGlobally({
|
|
996
|
+
targetPkgPath: import_node_path2.default.resolve(process.cwd(), "package.json")
|
|
997
|
+
});
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
if (!packageName) {
|
|
1001
|
+
throw new Error(
|
|
1002
|
+
'Please specify a package name or local path, or use "link --global".'
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
1005
|
+
if (options.protocol && !["file", "link"].includes(options.protocol)) {
|
|
1006
|
+
throw new Error(
|
|
1007
|
+
`Unsupported protocol "${options.protocol}". Use file or link.`
|
|
1008
|
+
);
|
|
886
1009
|
}
|
|
887
|
-
}
|
|
888
|
-
try {
|
|
889
1010
|
linkPackageToProject({
|
|
890
1011
|
packageName,
|
|
891
1012
|
targetPkgPath: import_node_path2.default.resolve(process.cwd(), "package.json"),
|
|
@@ -897,13 +1018,46 @@ function runLinkCommand(packageName, options) {
|
|
|
897
1018
|
process.exit(1);
|
|
898
1019
|
}
|
|
899
1020
|
}
|
|
1021
|
+
function runUnlinkCommand(packageName, options) {
|
|
1022
|
+
try {
|
|
1023
|
+
if (options.global) {
|
|
1024
|
+
if (packageName) {
|
|
1025
|
+
throw new Error('Do not specify a package name with "unlink --global".');
|
|
1026
|
+
}
|
|
1027
|
+
unlinkCurrentPackageGlobally({
|
|
1028
|
+
targetPkgPath: import_node_path2.default.resolve(process.cwd(), "package.json")
|
|
1029
|
+
});
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
1032
|
+
if (!packageName) {
|
|
1033
|
+
throw new Error(
|
|
1034
|
+
'Please specify a linked package name, or use "unlink --global".'
|
|
1035
|
+
);
|
|
1036
|
+
}
|
|
1037
|
+
unlinkPackageFromProject({
|
|
1038
|
+
packageName,
|
|
1039
|
+
targetPkgPath: import_node_path2.default.resolve(process.cwd(), "package.json")
|
|
1040
|
+
});
|
|
1041
|
+
} catch (err) {
|
|
1042
|
+
console.error(err.message);
|
|
1043
|
+
process.exit(1);
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
900
1046
|
var cli = cac("pnpm-link");
|
|
901
|
-
cli.command("[package-name]", "\
|
|
1047
|
+
cli.command("link [package-name]", "\u94FE\u63A5\u672C\u5730\u5305\u5230\u5F53\u524D\u9879\u76EE\uFF0C\u6216\u6CE8\u518C\u5F53\u524D\u5305\u5230\u5168\u5C40").option("-g, --global", "\u5C06\u5F53\u524D\u5305\u6CE8\u518C\u5230 pnpm \u5168\u5C40\u5305\u76EE\u5F55").option("-D, --save-dev", "\u5199\u5165 devDependencies").option("-P, --save-prod", "\u5199\u5165 dependencies").option("-p, --protocol <protocol>", "\u534F\u8BAE\u7C7B\u578B (file|link)", {
|
|
902
1048
|
default: "link"
|
|
903
|
-
}).example("pnpm-link
|
|
1049
|
+
}).example("pnpm-link link --global").example("pnpm-link link @scope/my-lib --save-dev").example("pnpm-link link ./packages/my-lib --protocol file").action((packageName, options) => {
|
|
904
1050
|
runLinkCommand(packageName, options);
|
|
905
1051
|
});
|
|
1052
|
+
cli.command("unlink [package-name]", "\u89E3\u9664\u9879\u76EE\u4F9D\u8D56\u94FE\u63A5\uFF0C\u6216\u6CE8\u9500\u5F53\u524D\u5305\u7684\u5168\u5C40\u94FE\u63A5").option("-g, --global", "\u4ECE pnpm \u5168\u5C40\u76EE\u5F55\u6CE8\u9500\u5F53\u524D\u5305").example("pnpm-link unlink @scope/my-lib").example("pnpm-link unlink --global").action((packageName, options) => {
|
|
1053
|
+
runUnlinkCommand(packageName, options);
|
|
1054
|
+
});
|
|
906
1055
|
if (require.main === module) {
|
|
1056
|
+
const firstArg = process.argv[2];
|
|
1057
|
+
if (firstArg && !["link", "unlink", "--help", "-h", "--version", "-v"].includes(firstArg)) {
|
|
1058
|
+
console.error(`Unknown command "${firstArg}". Use "link" or "unlink".`);
|
|
1059
|
+
process.exit(1);
|
|
1060
|
+
}
|
|
907
1061
|
cli.help();
|
|
908
1062
|
cli.version(cliVersion);
|
|
909
1063
|
cli.parse();
|