pnpm-plugin-alex-857 1.0.28 → 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 +8 -4
- 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
|
@@ -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;
|