pnpm-plugin-alex-857 1.0.20 → 1.0.22

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.
@@ -21,8 +21,12 @@ if (specifiers.length === 0) {
21
21
  process.exit(0);
22
22
  }
23
23
 
24
+ const isWorkspaceRoot =
25
+ fs.existsSync(path.join(process.cwd(), "pnpm-workspace.yaml"));
26
+ const addCmd = `pnpm add ${isWorkspaceRoot ? "-w " : ""}${specifiers.join(" ")}`;
27
+
24
28
  console.log("Adding from catalog:", specifiers.join(", "));
25
- execSync(`pnpm add ${specifiers.join(" ")}`, {
29
+ execSync(addCmd, {
26
30
  stdio: "inherit",
27
31
  cwd: process.cwd(),
28
32
  });
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  const path = require("path");
3
3
  const fs = require("fs");
4
- const yaml = require("js-yaml");
5
4
 
6
5
  // Resolve pnpm-workspace.json: plugin dir first, then cwd
7
6
  const possiblePaths = [
@@ -22,17 +21,35 @@ if (!Array.isArray(packagesFromJson) || packagesFromJson.length === 0) {
22
21
  }
23
22
 
24
23
  const yamlPath = path.join(process.cwd(), "pnpm-workspace.yaml");
25
- let yamlContent = {};
26
- let exists = false;
24
+ let existingPackages = [];
25
+ let raw = "";
27
26
 
28
27
  if (fs.existsSync(yamlPath)) {
29
- exists = true;
30
- yamlContent = yaml.load(fs.readFileSync(yamlPath, "utf8")) || {};
28
+ raw = fs.readFileSync(yamlPath, "utf8");
29
+ const match = raw.match(/^packages\s*:\s*\n((?:\s+-\s+[^\n]+\n?)*)/m);
30
+ if (match) {
31
+ const items = match[1].matchAll(/^\s+-\s+['"]?([^'"]+)['"]?/gm);
32
+ for (const m of items) existingPackages.push(m[1]);
33
+ }
31
34
  }
32
35
 
33
- const existingPackages = Array.isArray(yamlContent.packages) ? yamlContent.packages : [];
34
36
  const mergedPackages = [...new Set([...existingPackages, ...packagesFromJson])];
35
- yamlContent.packages = mergedPackages;
37
+ const packagesBlock = "packages:\n" + mergedPackages.map((p) => ` - '${p}'`).join("\n") + "\n";
36
38
 
37
- fs.writeFileSync(yamlPath, yaml.dump(yamlContent), "utf8");
38
- console.log(exists ? "Updated" : "Created", "pnpm-workspace.yaml with packages:", mergedPackages.join(", "));
39
+ let output;
40
+ if (raw) {
41
+ if (/^packages\s*:/m.test(raw)) {
42
+ output = raw.replace(/^packages\s*:\s*\n(?:\s+-\s+[^\n]+\n?)*/m, packagesBlock);
43
+ } else {
44
+ output = raw.trimEnd() + "\n\n" + packagesBlock;
45
+ }
46
+ } else {
47
+ output = packagesBlock;
48
+ }
49
+
50
+ fs.writeFileSync(yamlPath, output, "utf8");
51
+ console.log(
52
+ raw ? "Updated" : "Created",
53
+ "pnpm-workspace.yaml with packages:",
54
+ mergedPackages.join(", ")
55
+ );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pnpm-plugin-alex-857",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "A plugin for pnpm to use alex as a linter",
5
5
  "bin": {
6
6
  "install-catalog": "./install-catalog.js",
@@ -14,9 +14,6 @@
14
14
  "install-workspace.js"
15
15
  ],
16
16
  "keywords": ["pnpm", "plugin"],
17
- "dependencies": {
18
- "js-yaml": "^4.1.0"
19
- },
20
17
  "author": "aboungnaseng857",
21
18
  "license": "ISC",
22
19
  "scripts": {