periderm-cli 0.1.49 → 0.1.54

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/dist/config.js CHANGED
@@ -3,13 +3,21 @@ import path from "node:path";
3
3
  import os from "node:os";
4
4
  const CONFIG_DIR = path.join(os.homedir(), ".periderm");
5
5
  const CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
6
+ const DEFAULT_API_URL = "https://periderm-cli.vercel.app";
6
7
  export function resolveApiUrl(stored) {
7
- return (process.env.PERIDERM_API_URL || stored || "").replace(/\/$/, "");
8
+ return (process.env.PERIDERM_API_URL || stored || DEFAULT_API_URL).replace(/\/$/, "");
8
9
  }
9
10
  export function readConfig() {
10
11
  try {
11
12
  if (fs.existsSync(CONFIG_FILE)) {
12
13
  const raw = JSON.parse(fs.readFileSync(CONFIG_FILE, "utf8"));
14
+ // Auto-fix corrupted config by clearing out localhost URLs
15
+ // (forces the CLI to use the production default or the explicitly set PERIDERM_API_URL)
16
+ if (raw.apiUrl && !process.env.PERIDERM_API_URL && (raw.apiUrl.includes("localhost") || raw.apiUrl.includes("127.0.0.1"))) {
17
+ console.warn("[periderm] Detected local dev URL in config. Clearing corrupted config...");
18
+ fs.unlinkSync(CONFIG_FILE); // Purge the corrupted file
19
+ return { apiUrl: resolveApiUrl() };
20
+ }
13
21
  return { apiUrl: resolveApiUrl(raw.apiUrl), token: raw.token };
14
22
  }
15
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "periderm-cli",
3
- "version": "0.1.49",
3
+ "version": "0.1.54",
4
4
  "description": "Periderm CLI: The Local-First Security & Performance Code Scanner",
5
5
  "type": "module",
6
6
  "preferGlobal": true,
@@ -9,7 +9,8 @@
9
9
  },
10
10
  "files": [
11
11
  "dist",
12
- "README.md"
12
+ "README.md",
13
+ "scripts"
13
14
  ],
14
15
  "keywords": [
15
16
  "cli",
@@ -47,6 +48,7 @@
47
48
  "license": "MIT",
48
49
  "scripts": {
49
50
  "build": "tsc -p tsconfig.json && chmod +x dist/bin.js",
51
+ "postinstall": "node scripts/postinstall.js",
50
52
  "postpublish": "cd ../../ && tsx --env-file=.env scripts/broadcast-update.ts",
51
53
  "dev": "tsx src/index.ts",
52
54
  "start": "node dist/index.js"
@@ -0,0 +1,36 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import os from "node:os";
4
+
5
+ // If this is running inside the curl install.sh script, skip cleanup!
6
+ // We want curl installations to KEEP their ~/.periderm/bin folders.
7
+ if (process.env.PERIDERM_CURL_INSTALL === "1") {
8
+ process.exit(0);
9
+ }
10
+
11
+ // Find actual home directory, even if running via sudo npm install -g
12
+ const isRoot = process.getuid && process.getuid() === 0;
13
+ const sudoUser = process.env.SUDO_USER;
14
+
15
+ let homeDir = os.homedir();
16
+ if (isRoot && sudoUser) {
17
+ // Basic fallback for Linux/macOS sudo users
18
+ if (fs.existsSync(`/home/${sudoUser}`)) {
19
+ homeDir = `/home/${sudoUser}`;
20
+ } else if (fs.existsSync(`/Users/${sudoUser}`)) {
21
+ homeDir = `/Users/${sudoUser}`;
22
+ }
23
+ }
24
+
25
+ const peridermDir = path.join(homeDir, ".periderm");
26
+ const binDir = path.join(peridermDir, "bin");
27
+ const nodeModulesDir = path.join(peridermDir, "node_modules");
28
+
29
+ try {
30
+ // If the user installs globally via NPM, delete the legacy curl folders
31
+ // so that ~/.periderm/bin/periderm doesn't shadow /usr/local/bin/periderm.
32
+ fs.rmSync(binDir, { recursive: true, force: true });
33
+ fs.rmSync(nodeModulesDir, { recursive: true, force: true });
34
+ } catch (e) {
35
+ // Silent fail
36
+ }