pnpm-plugin-alex-857 1.0.28 → 1.0.30
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 +19 -2
- package/install-workspace.js +8 -4
- package/package.json +1 -1
package/install-catalog.js
CHANGED
|
@@ -21,8 +21,25 @@ if (specifiers.length === 0) {
|
|
|
21
21
|
process.exit(0);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
// Ensure pnpm-workspace.yaml has a catalog section so catalog: resolution works.
|
|
25
|
+
const workspaceYamlPath = path.join(process.cwd(), "pnpm-workspace.yaml");
|
|
26
|
+
if (fs.existsSync(workspaceYamlPath)) {
|
|
27
|
+
let yaml = fs.readFileSync(workspaceYamlPath, "utf8");
|
|
28
|
+
const hasCatalog = /\ncatalog\s*:/m.test(yaml);
|
|
29
|
+
if (!hasCatalog) {
|
|
30
|
+
const catalogBlock =
|
|
31
|
+
"\ncatalog:\n" +
|
|
32
|
+
Object.entries(catalog)
|
|
33
|
+
.map(([name, version]) => ` ${name}: ${version}`)
|
|
34
|
+
.join("\n") +
|
|
35
|
+
"\n";
|
|
36
|
+
yaml = yaml.trimEnd() + catalogBlock;
|
|
37
|
+
fs.writeFileSync(workspaceYamlPath, yaml, "utf8");
|
|
38
|
+
console.log("Added catalog to pnpm-workspace.yaml");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const isWorkspaceRoot = fs.existsSync(workspaceYamlPath);
|
|
26
43
|
const addCmd = `pnpm add ${isWorkspaceRoot ? "-w " : ""}${specifiers.join(" ")}`;
|
|
27
44
|
|
|
28
45
|
console.log("Adding from catalog:", specifiers.join(", "));
|
package/install-workspace.js
CHANGED
|
@@ -67,13 +67,17 @@ const packagesBlock =
|
|
|
67
67
|
|
|
68
68
|
let output;
|
|
69
69
|
if (raw && /^packages\s*:/m.test(raw)) {
|
|
70
|
-
// Replace only the packages
|
|
71
|
-
//
|
|
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
72
|
const nextKeyRegex = /^packages\s*:\s*\n[\s\S]*?(?=\n(?:catalog|configDependencies)\s*:)/m;
|
|
73
73
|
output = raw.replace(nextKeyRegex, () => packagesBlock);
|
|
74
74
|
if (output === raw) {
|
|
75
|
-
// No catalog/configDependencies after packages
|
|
76
|
-
|
|
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
|
+
);
|
|
77
81
|
}
|
|
78
82
|
} else if (raw) {
|
|
79
83
|
output = raw.trimEnd() + "\n\n" + packagesBlock;
|