@pizzapi/pizza 0.1.34-dev.0 → 0.1.34-dev.1
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/bin/pizza.mjs +62 -18
- package/package.json +6 -6
package/bin/pizza.mjs
CHANGED
|
@@ -10,12 +10,13 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { execFileSync, execSync } from "node:child_process";
|
|
13
|
-
import { existsSync } from "node:fs";
|
|
13
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
14
14
|
import { join, dirname, resolve } from "node:path";
|
|
15
15
|
import { createRequire } from "node:module";
|
|
16
16
|
import { fileURLToPath } from "node:url";
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
19
|
+
const __dirname = dirname(__filename);
|
|
19
20
|
|
|
20
21
|
// Map of `${process.platform}-${process.arch}` to npm package name
|
|
21
22
|
const PLATFORM_PACKAGES = {
|
|
@@ -38,7 +39,17 @@ if (!pkgName) {
|
|
|
38
39
|
process.exit(1);
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
/** Read our own package.json version. */
|
|
43
|
+
function getOwnVersion() {
|
|
44
|
+
try {
|
|
45
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"));
|
|
46
|
+
return pkg.version;
|
|
47
|
+
} catch {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Try to find the platform binary via multiple strategies. */
|
|
42
53
|
function findBinary() {
|
|
43
54
|
const binName = process.platform === "win32" ? "pizza.exe" : "pizza";
|
|
44
55
|
const parts = pkgName.split("/");
|
|
@@ -56,8 +67,6 @@ function findBinary() {
|
|
|
56
67
|
|
|
57
68
|
// Strategy 2: Sibling scoped package — both packages live under
|
|
58
69
|
// node_modules/@pizzapi/, so the platform package is a sibling of ours.
|
|
59
|
-
// __dirname = .../node_modules/@pizzapi/pizza/bin
|
|
60
|
-
// sibling = .../node_modules/@pizzapi/cli-win32-x64/bin/pizza.exe
|
|
61
70
|
{
|
|
62
71
|
const siblingPath = join(__dirname, "..", "..", parts[1], "bin", binName);
|
|
63
72
|
if (existsSync(siblingPath)) return siblingPath;
|
|
@@ -88,9 +97,9 @@ function findBinary() {
|
|
|
88
97
|
}
|
|
89
98
|
}
|
|
90
99
|
|
|
91
|
-
// Strategy 5: Use npm root -g to find global node_modules
|
|
100
|
+
// Strategy 5: Use npm root -g to find global node_modules
|
|
92
101
|
try {
|
|
93
|
-
const globalRoot = execSync("npm root -g", { encoding: "utf-8" }).trim();
|
|
102
|
+
const globalRoot = execSync("npm root -g", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
|
|
94
103
|
if (globalRoot) {
|
|
95
104
|
const binPath = join(globalRoot, parts[0], parts[1], "bin", binName);
|
|
96
105
|
if (existsSync(binPath)) return binPath;
|
|
@@ -102,21 +111,58 @@ function findBinary() {
|
|
|
102
111
|
return null;
|
|
103
112
|
}
|
|
104
113
|
|
|
105
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Attempt to install the missing platform package alongside our package.
|
|
116
|
+
* Returns true if the install succeeded.
|
|
117
|
+
*/
|
|
118
|
+
function tryAutoInstall(version) {
|
|
119
|
+
const versionSpec = version ? `${pkgName}@${version}` : pkgName;
|
|
120
|
+
|
|
121
|
+
// Determine whether we're in a global install by checking if our path
|
|
122
|
+
// is inside a global-looking node_modules (not inside a project).
|
|
123
|
+
const isGlobal = __dirname.includes("node_modules");
|
|
124
|
+
|
|
125
|
+
const globalFlag = isGlobal ? " -g" : "";
|
|
126
|
+
console.error(
|
|
127
|
+
`\nThe platform package "${pkgName}" was not installed automatically.\n` +
|
|
128
|
+
`Attempting to install it now...\n`,
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
execSync(`npm install${globalFlag} ${versionSpec}`, {
|
|
133
|
+
stdio: "inherit",
|
|
134
|
+
env: process.env,
|
|
135
|
+
});
|
|
136
|
+
return true;
|
|
137
|
+
} catch {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// --- Main ---
|
|
143
|
+
|
|
144
|
+
let binaryPath = findBinary();
|
|
145
|
+
|
|
146
|
+
// If not found, try to auto-install the platform package and retry
|
|
147
|
+
if (!binaryPath) {
|
|
148
|
+
const version = getOwnVersion();
|
|
149
|
+
if (tryAutoInstall(version)) {
|
|
150
|
+
binaryPath = findBinary();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
106
153
|
|
|
107
154
|
if (!binaryPath) {
|
|
108
155
|
// Collect diagnostic info for troubleshooting
|
|
156
|
+
const parts = pkgName.split("/");
|
|
109
157
|
const diag = [
|
|
110
|
-
` launcher: ${
|
|
158
|
+
` launcher: ${__filename}`,
|
|
111
159
|
` __dirname: ${__dirname}`,
|
|
112
160
|
` platform: ${platformKey}`,
|
|
113
161
|
];
|
|
114
|
-
// Check if the platform package directory exists at all
|
|
115
|
-
const parts = pkgName.split("/");
|
|
116
162
|
const siblingDir = join(__dirname, "..", "..", parts[1]);
|
|
117
163
|
diag.push(` sibling dir exists: ${existsSync(siblingDir)} (${siblingDir})`);
|
|
118
164
|
try {
|
|
119
|
-
const globalRoot = execSync("npm root -g", { encoding: "utf-8" }).trim();
|
|
165
|
+
const globalRoot = execSync("npm root -g", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
|
|
120
166
|
const globalPkg = join(globalRoot, parts[0], parts[1]);
|
|
121
167
|
diag.push(` global root: ${globalRoot}`);
|
|
122
168
|
diag.push(` global pkg exists: ${existsSync(globalPkg)} (${globalPkg})`);
|
|
@@ -124,12 +170,10 @@ if (!binaryPath) {
|
|
|
124
170
|
|
|
125
171
|
console.error(
|
|
126
172
|
`Error: Could not find the PizzaPi binary for your platform (${platformKey}).\n\n` +
|
|
127
|
-
`The platform-specific package "${pkgName}"
|
|
128
|
-
`automatically
|
|
129
|
-
`Try
|
|
130
|
-
` npm install
|
|
131
|
-
`If the problem persists, install the platform package directly:\n` +
|
|
132
|
-
` npm install ${pkgName}\n\n` +
|
|
173
|
+
`The platform-specific package "${pkgName}" could not be installed\n` +
|
|
174
|
+
`automatically.\n\n` +
|
|
175
|
+
`Try installing it manually:\n` +
|
|
176
|
+
` npm install -g ${pkgName}@${getOwnVersion() || "latest"}\n\n` +
|
|
133
177
|
`Or build from source: https://github.com/Pizzaface/PizzaPi\n\n` +
|
|
134
178
|
`Diagnostics:\n${diag.join("\n")}`,
|
|
135
179
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pizzapi/pizza",
|
|
3
|
-
"version": "0.1.34-dev.
|
|
3
|
+
"version": "0.1.34-dev.1",
|
|
4
4
|
"description": "PizzaPi — a self-hosted web interface and relay server for the pi coding agent. Stream live AI coding sessions to any browser.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
"LICENSE"
|
|
14
14
|
],
|
|
15
15
|
"optionalDependencies": {
|
|
16
|
-
"@pizzapi/cli-linux-x64": "0.1.34-dev.
|
|
17
|
-
"@pizzapi/cli-linux-arm64": "0.1.34-dev.
|
|
18
|
-
"@pizzapi/cli-darwin-x64": "0.1.34-dev.
|
|
19
|
-
"@pizzapi/cli-darwin-arm64": "0.1.34-dev.
|
|
20
|
-
"@pizzapi/cli-win32-x64": "0.1.34-dev.
|
|
16
|
+
"@pizzapi/cli-linux-x64": "0.1.34-dev.1",
|
|
17
|
+
"@pizzapi/cli-linux-arm64": "0.1.34-dev.1",
|
|
18
|
+
"@pizzapi/cli-darwin-x64": "0.1.34-dev.1",
|
|
19
|
+
"@pizzapi/cli-darwin-arm64": "0.1.34-dev.1",
|
|
20
|
+
"@pizzapi/cli-win32-x64": "0.1.34-dev.1"
|
|
21
21
|
},
|
|
22
22
|
"engines": {
|
|
23
23
|
"node": ">=18"
|