pnpm-link 1.0.1 → 1.0.2

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.
Files changed (2) hide show
  1. package/dist/index.js +60 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6,6 +6,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __commonJS = (cb, mod) => function __require() {
10
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
+ };
9
12
  var __copyProps = (to, from, except, desc) => {
10
13
  if (from && typeof from === "object" || typeof from === "function") {
11
14
  for (let key of __getOwnPropNames(from))
@@ -23,6 +26,49 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
26
  mod
24
27
  ));
25
28
 
29
+ // package.json
30
+ var require_package = __commonJS({
31
+ "package.json"(exports2, module2) {
32
+ module2.exports = {
33
+ name: "pnpm-link",
34
+ version: "1.0.2",
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
+ keywords: [
37
+ "pnpm",
38
+ "link",
39
+ "dependencies",
40
+ "devDependencies",
41
+ "package.json",
42
+ "workspace",
43
+ "cli"
44
+ ],
45
+ license: "ISC",
46
+ author: "zyrong",
47
+ type: "commonjs",
48
+ bin: {
49
+ "pnpm-link": "./dist/index.js"
50
+ },
51
+ files: [
52
+ "dist"
53
+ ],
54
+ scripts: {
55
+ build: "tsup",
56
+ typecheck: "tsc",
57
+ test: "pnpm build && vitest run",
58
+ "test:watch": "vitest"
59
+ },
60
+ packageManager: "pnpm@10.28.0",
61
+ devDependencies: {
62
+ "@types/node": "^22.19.15",
63
+ cac: "^7.0.0",
64
+ tsup: "^8.5.1",
65
+ typescript: "^7.0.2",
66
+ vitest: "^4.0.18"
67
+ }
68
+ };
69
+ }
70
+ });
71
+
26
72
  // src/cli.ts
27
73
  var import_node_path2 = __toESM(require("path"));
28
74
 
@@ -646,8 +692,16 @@ var cac = (name = "") => new CAC(name);
646
692
  var import_node_child_process = require("child_process");
647
693
  var import_node_fs = __toESM(require("fs"));
648
694
  var import_node_path = __toESM(require("path"));
695
+ var SCOPED_PACKAGE_RE = /^@[^/\\]+\/[^/\\]+$/;
649
696
  function isLocalPackageReference(value) {
650
- return value.startsWith("./") || value.startsWith("../") || value.startsWith("/") || value.startsWith("file:") || value.includes("/") || value.includes("\\");
697
+ return value.startsWith("./") || value.startsWith("../") || value.startsWith("/") || value.startsWith("file:") || value.includes("\\") || value.includes("/") && !SCOPED_PACKAGE_RE.test(value);
698
+ }
699
+ function assertValidPackageInput(value) {
700
+ if (value.startsWith("@") && !SCOPED_PACKAGE_RE.test(value)) {
701
+ throw new Error(
702
+ `"${value}" is not a valid scoped package name. Expected "@scope/name".`
703
+ );
704
+ }
651
705
  }
652
706
  function readPackageNameFromDir(dirPath) {
653
707
  const pkgJsonPath = import_node_path.default.join(dirPath, "package.json");
@@ -662,6 +716,7 @@ function readPackageNameFromDir(dirPath) {
662
716
  }
663
717
  }
664
718
  function resolvePackageLocation(packageName) {
719
+ assertValidPackageInput(packageName);
665
720
  if (isLocalPackageReference(packageName)) {
666
721
  const absolutePath = import_node_path.default.resolve(packageName);
667
722
  if (!import_node_fs.default.existsSync(absolutePath)) {
@@ -692,7 +747,7 @@ function linkPackageToProject(options) {
692
747
  packageName,
693
748
  targetPkgPath = "./package.json",
694
749
  depType = "dependencies",
695
- protocol = "file"
750
+ protocol = "link"
696
751
  } = options;
697
752
  const targetAbs = import_node_path.default.resolve(targetPkgPath);
698
753
  if (!import_node_fs.default.existsSync(targetAbs)) {
@@ -722,6 +777,7 @@ function linkPackageToProject(options) {
722
777
  }
723
778
 
724
779
  // src/cli.ts
780
+ var { version: cliVersion } = require_package();
725
781
  function resolveDepType(options) {
726
782
  if (options.saveDev) return "devDependencies";
727
783
  if (options.saveProd) return "dependencies";
@@ -747,12 +803,12 @@ function runLinkCommand(packageName, options) {
747
803
  }
748
804
  var cli = cac("pnpm-link");
749
805
  cli.command("<package-name>", "\u5C06\u5168\u5C40\u5DF2 link \u7684\u5305\u6216\u672C\u5730\u76F8\u5BF9\u8DEF\u5F84\u5305\u5199\u5165\u5F53\u524D\u9879\u76EE\u4F9D\u8D56").option("-D, --save-dev", "\u5199\u5165 devDependencies").option("-P, --save-prod", "\u5199\u5165 dependencies").option("-p, --protocol <protocol>", "\u534F\u8BAE\u7C7B\u578B (file|link)", {
750
- default: "file"
806
+ default: "link"
751
807
  }).example("pnpm-link my-package --save-dev").example("pnpm-link ./packages/my-lib --protocol file").action((packageName, options) => {
752
808
  runLinkCommand(packageName, options);
753
809
  });
754
810
  if (require.main === module) {
755
811
  cli.help();
756
- cli.version("1.0.0");
812
+ cli.version(cliVersion);
757
813
  cli.parse();
758
814
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pnpm-link",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "把全局已 link 的包或本地包写入当前项目依赖,适用于 pnpm 工作流",
5
5
  "keywords": [
6
6
  "pnpm",