pnpm-plugin-alex-857 1.0.26 → 1.0.28

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,28 +21,62 @@ if (!Array.isArray(packagesFromJson) || packagesFromJson.length === 0) {
21
21
  }
22
22
 
23
23
  const yamlPath = path.join(process.cwd(), "pnpm-workspace.yaml");
24
- let existingPackages = [];
25
24
  let raw = "";
26
25
 
27
26
  if (fs.existsSync(yamlPath)) {
28
27
  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]);
28
+ }
29
+
30
+ // Extract existing package patterns from the packages section (no duplicates).
31
+ // Only matches lines like " - 'x'" or " - \"x\"".
32
+ function extractExistingPackages(text) {
33
+ const seen = new Set();
34
+ const list = [];
35
+ const sectionMatch = text.match(
36
+ /^packages\s*:\s*\n([\s\S]*?)(?=\n(?:catalog|configDependencies)\s*:)/m
37
+ );
38
+ if (!sectionMatch) {
39
+ const toEnd = text.match(/^packages\s*:\s*\n([\s\S]*)/m);
40
+ if (toEnd) {
41
+ for (const m of toEnd[1].matchAll(/^\s+-\s+['"]([^'"]+)['"]\s*$/gm)) {
42
+ const p = m[1].trim();
43
+ if (p && !seen.has(p)) {
44
+ seen.add(p);
45
+ list.push(p);
46
+ }
47
+ }
48
+ }
49
+ return list;
50
+ }
51
+ const section = sectionMatch[1];
52
+ for (const m of section.matchAll(/^\s+-\s+['"]([^'"]+)['"]\s*$/gm)) {
53
+ const p = m[1].trim();
54
+ if (p && !seen.has(p)) {
55
+ seen.add(p);
56
+ list.push(p);
57
+ }
33
58
  }
59
+ return list;
34
60
  }
35
61
 
62
+ // Merge: keep all existing entries and add from plugin list; no duplicates.
63
+ const existingPackages = raw ? extractExistingPackages(raw) : [];
36
64
  const mergedPackages = [...new Set([...existingPackages, ...packagesFromJson])];
37
- const packagesBlock = "packages:\n" + mergedPackages.map((p) => ` - '${p}'`).join("\n") + "\n";
65
+ const packagesBlock =
66
+ "packages:\n" + mergedPackages.map((p) => ` - '${p}'`).join("\n") + "\n";
38
67
 
39
68
  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;
69
+ if (raw && /^packages\s*:/m.test(raw)) {
70
+ // Replace only the packages section: from "packages:" to next top-level key (catalog/configDependencies) or end of file.
71
+ // Do not use $ with /m (it matches end of line) or we stop at a blank line and leave duplicates.
72
+ const nextKeyRegex = /^packages\s*:\s*\n[\s\S]*?(?=\n(?:catalog|configDependencies)\s*:)/m;
73
+ output = raw.replace(nextKeyRegex, () => packagesBlock);
74
+ if (output === raw) {
75
+ // No catalog/configDependencies after packages; replace to end of string
76
+ output = raw.replace(/^packages\s*:\s*\n[\s\S]*/m, packagesBlock);
45
77
  }
78
+ } else if (raw) {
79
+ output = raw.trimEnd() + "\n\n" + packagesBlock;
46
80
  } else {
47
81
  output = packagesBlock;
48
82
  }
@@ -50,6 +84,6 @@ if (raw) {
50
84
  fs.writeFileSync(yamlPath, output, "utf8");
51
85
  console.log(
52
86
  raw ? "Updated" : "Created",
53
- "pnpm-workspace.yaml with packages:",
87
+ "pnpm-workspace.yaml with packages (no duplicates):",
54
88
  mergedPackages.join(", ")
55
89
  );
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.28",
4
4
  "description": "A plugin for pnpm to use alex as a linter",
5
5
  "bin": {
6
6
  "install-catalog": "./install-catalog.js",