pnpm-plugin-alex-857 1.0.26 → 1.0.27

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.
@@ -2,7 +2,6 @@
2
2
  const path = require("path");
3
3
  const fs = require("fs");
4
4
 
5
- // Resolve pnpm-workspace.json: plugin dir first, then cwd
6
5
  const possiblePaths = [
7
6
  path.join(__dirname, "pnpm-workspace.json"),
8
7
  path.join(process.cwd(), "pnpm-workspace.json"),
@@ -21,28 +20,49 @@ if (!Array.isArray(packagesFromJson) || packagesFromJson.length === 0) {
21
20
  }
22
21
 
23
22
  const yamlPath = path.join(process.cwd(), "pnpm-workspace.yaml");
24
- let existingPackages = [];
25
23
  let raw = "";
26
24
 
27
25
  if (fs.existsSync(yamlPath)) {
28
26
  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]);
27
+ }
28
+
29
+ // Extract existing package patterns from the packages section (avoid duplicates from malformed YAML)
30
+ function extractExistingPackages(text) {
31
+ const seen = new Set();
32
+ const list = [];
33
+ const sectionMatch = text.match(/^packages\s*:\s*\n([\s\S]*?)(?=\n[a-zA-Z][\w]*\s*:|\s*$)/m);
34
+ if (!sectionMatch) return list;
35
+ const section = sectionMatch[1];
36
+ for (const m of section.matchAll(/^\s+-\s+['"]([^'"]+)['"]\s*$/gm)) {
37
+ const p = m[1].trim();
38
+ if (p && !seen.has(p)) {
39
+ seen.add(p);
40
+ list.push(p);
41
+ }
33
42
  }
43
+ return list;
34
44
  }
35
45
 
46
+ const existingPackages = raw ? extractExistingPackages(raw) : [];
36
47
  const mergedPackages = [...new Set([...existingPackages, ...packagesFromJson])];
37
- const packagesBlock = "packages:\n" + mergedPackages.map((p) => ` - '${p}'`).join("\n") + "\n";
48
+ const packagesBlock =
49
+ "packages:\n" + mergedPackages.map((p) => ` - '${p}'`).join("\n") + "\n";
38
50
 
39
51
  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;
52
+ if (raw && /^packages\s*:/m.test(raw)) {
53
+ // Replace the entire packages section (from "packages:" to next top-level key or end) to avoid duplication/corruption
54
+ output = raw.replace(
55
+ /^packages\s*:\s*\n[\s\S]*?(?=\n[a-zA-Z][\w]*\s*:|\s*$)/m,
56
+ () => packagesBlock
57
+ );
58
+ if (output === raw) {
59
+ output = raw.replace(/^packages\s*:[\s\S]*?(?=\n(?:catalog|configDependencies)\s*:)/m, packagesBlock);
60
+ }
61
+ if (output === raw) {
62
+ output = raw.replace(/^packages\s*:[\s\S]*/m, packagesBlock);
45
63
  }
64
+ } else if (raw) {
65
+ output = raw.trimEnd() + "\n\n" + packagesBlock;
46
66
  } else {
47
67
  output = packagesBlock;
48
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pnpm-plugin-alex-857",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "A plugin for pnpm to use alex as a linter",
5
5
  "bin": {
6
6
  "install-catalog": "./install-catalog.js",