pnpm-plugin-alex-857 1.0.27 → 1.0.29
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/install-catalog.js +16 -2
- package/install-workspace.js +31 -13
- package/package.json +1 -1
package/install-catalog.js
CHANGED
|
@@ -21,8 +21,22 @@ if (specifiers.length === 0) {
|
|
|
21
21
|
process.exit(0);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
// In a workspace, catalog: is resolved by the plugin (configDependencies). If the workspace
|
|
25
|
+
// was just created or config was wiped, skip so postinstall does not fail.
|
|
26
|
+
const workspaceYamlPath = path.join(process.cwd(), "pnpm-workspace.yaml");
|
|
27
|
+
if (fs.existsSync(workspaceYamlPath)) {
|
|
28
|
+
const yaml = fs.readFileSync(workspaceYamlPath, "utf8");
|
|
29
|
+
const hasCatalog =
|
|
30
|
+
/\ncatalog\s*:/m.test(yaml) || /\nconfigDependencies\s*:/m.test(yaml);
|
|
31
|
+
if (!hasCatalog) {
|
|
32
|
+
console.warn(
|
|
33
|
+
"install-catalog: No catalog or configDependencies in pnpm-workspace.yaml; run 'pnpm add --config pnpm-plugin-alex-857@latest' first, then pnpm install."
|
|
34
|
+
);
|
|
35
|
+
process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const isWorkspaceRoot = fs.existsSync(workspaceYamlPath);
|
|
26
40
|
const addCmd = `pnpm add ${isWorkspaceRoot ? "-w " : ""}${specifiers.join(" ")}`;
|
|
27
41
|
|
|
28
42
|
console.log("Adding from catalog:", specifiers.join(", "));
|
package/install-workspace.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
|
|
5
|
+
// Resolve pnpm-workspace.json: plugin dir first, then cwd
|
|
5
6
|
const possiblePaths = [
|
|
6
7
|
path.join(__dirname, "pnpm-workspace.json"),
|
|
7
8
|
path.join(process.cwd(), "pnpm-workspace.json"),
|
|
@@ -26,12 +27,27 @@ if (fs.existsSync(yamlPath)) {
|
|
|
26
27
|
raw = fs.readFileSync(yamlPath, "utf8");
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
// Extract existing package patterns from the packages section (
|
|
30
|
+
// Extract existing package patterns from the packages section (no duplicates).
|
|
31
|
+
// Only matches lines like " - 'x'" or " - \"x\"".
|
|
30
32
|
function extractExistingPackages(text) {
|
|
31
33
|
const seen = new Set();
|
|
32
34
|
const list = [];
|
|
33
|
-
const sectionMatch = text.match(
|
|
34
|
-
|
|
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
|
+
}
|
|
35
51
|
const section = sectionMatch[1];
|
|
36
52
|
for (const m of section.matchAll(/^\s+-\s+['"]([^'"]+)['"]\s*$/gm)) {
|
|
37
53
|
const p = m[1].trim();
|
|
@@ -43,6 +59,7 @@ function extractExistingPackages(text) {
|
|
|
43
59
|
return list;
|
|
44
60
|
}
|
|
45
61
|
|
|
62
|
+
// Merge: keep all existing entries and add from plugin list; no duplicates.
|
|
46
63
|
const existingPackages = raw ? extractExistingPackages(raw) : [];
|
|
47
64
|
const mergedPackages = [...new Set([...existingPackages, ...packagesFromJson])];
|
|
48
65
|
const packagesBlock =
|
|
@@ -50,16 +67,17 @@ const packagesBlock =
|
|
|
50
67
|
|
|
51
68
|
let output;
|
|
52
69
|
if (raw && /^packages\s*:/m.test(raw)) {
|
|
53
|
-
// Replace the
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
);
|
|
58
|
-
if (output === raw) {
|
|
59
|
-
output = raw.replace(/^packages\s*:[\s\S]*?(?=\n(?:catalog|configDependencies)\s*:)/m, packagesBlock);
|
|
60
|
-
}
|
|
70
|
+
// Replace only the packages list: "packages:\n" + list lines. Never replace to end of file
|
|
71
|
+
// so we never wipe catalog / configDependencies (which would break install-catalog).
|
|
72
|
+
const nextKeyRegex = /^packages\s*:\s*\n[\s\S]*?(?=\n(?:catalog|configDependencies)\s*:)/m;
|
|
73
|
+
output = raw.replace(nextKeyRegex, () => packagesBlock);
|
|
61
74
|
if (output === raw) {
|
|
62
|
-
|
|
75
|
+
// No catalog/configDependencies after packages: replace only the list lines ( - '...')
|
|
76
|
+
// so any trailing content (catalog, configDependencies, blank lines) is preserved.
|
|
77
|
+
output = raw.replace(
|
|
78
|
+
/^(packages\s*:\s*\n)((?:\s+-\s+['"][^'"]+['"]\s*\n)*)/m,
|
|
79
|
+
() => packagesBlock
|
|
80
|
+
);
|
|
63
81
|
}
|
|
64
82
|
} else if (raw) {
|
|
65
83
|
output = raw.trimEnd() + "\n\n" + packagesBlock;
|
|
@@ -70,6 +88,6 @@ if (raw && /^packages\s*:/m.test(raw)) {
|
|
|
70
88
|
fs.writeFileSync(yamlPath, output, "utf8");
|
|
71
89
|
console.log(
|
|
72
90
|
raw ? "Updated" : "Created",
|
|
73
|
-
"pnpm-workspace.yaml with packages:",
|
|
91
|
+
"pnpm-workspace.yaml with packages (no duplicates):",
|
|
74
92
|
mergedPackages.join(", ")
|
|
75
93
|
);
|