@speedscale/proxymock 2.3.661 → 2.3.677
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/proxymock.js +52 -26
- package/lib/constants.js +7 -0
- package/lib/install.js +48 -24
- package/lib/log.js +35 -0
- package/lib/version.js +64 -0
- package/package.json +4 -1
package/bin/proxymock.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { spawn } from "child_process";
|
|
4
|
-
import { join, dirname } from "path";
|
|
5
4
|
import { existsSync } from "fs";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
import {
|
|
6
|
+
getPackageVersion,
|
|
7
|
+
getInstalledVersion,
|
|
8
|
+
} from "../lib/version.js";
|
|
9
|
+
import { binaryPath } from "../lib/constants.js";
|
|
10
|
+
import logger from "../lib/log.js";
|
|
11
|
+
import install from "../lib/install.js";
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Spawns the proxymock binary with the provided command line arguments
|
|
15
|
+
* Exits the process with the same code as proxymock
|
|
16
|
+
*/
|
|
13
17
|
function runProxyMock() {
|
|
14
18
|
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
15
19
|
stdio: "inherit",
|
|
@@ -17,7 +21,7 @@ function runProxyMock() {
|
|
|
17
21
|
});
|
|
18
22
|
|
|
19
23
|
child.on("error", (err) => {
|
|
20
|
-
|
|
24
|
+
logger.error(`Failed to start proxymock: ${err.message}`);
|
|
21
25
|
process.exit(1);
|
|
22
26
|
});
|
|
23
27
|
|
|
@@ -26,23 +30,45 @@ function runProxyMock() {
|
|
|
26
30
|
});
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
console.error("Installation failed");
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
// Run proxymock after successful installation
|
|
43
|
-
runProxyMock();
|
|
44
|
-
});
|
|
45
|
-
} else {
|
|
46
|
-
// Binary exists, run it directly
|
|
33
|
+
/**
|
|
34
|
+
* Installs proxymock and runs it, exiting on failure
|
|
35
|
+
*/
|
|
36
|
+
async function installAndRun() {
|
|
37
|
+
try {
|
|
38
|
+
await install();
|
|
39
|
+
} catch (error) {
|
|
40
|
+
logger.error(`Installation failed: ${error.message}`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
47
43
|
runProxyMock();
|
|
48
44
|
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Main entry point - ensures the correct version of proxymock is installed
|
|
48
|
+
* before executing it. Performs version checking and automatic reinstallation
|
|
49
|
+
* if the installed version doesn't match the npm package version.
|
|
50
|
+
*/
|
|
51
|
+
async function main() {
|
|
52
|
+
const npmVersion = getPackageVersion();
|
|
53
|
+
const expectedVersion = `v${npmVersion}`;
|
|
54
|
+
|
|
55
|
+
// Check if proxymock is installed
|
|
56
|
+
if (!existsSync(binaryPath)) {
|
|
57
|
+
await installAndRun();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Binary exists, check if version matches
|
|
62
|
+
const installedVersion = await getInstalledVersion();
|
|
63
|
+
|
|
64
|
+
if (installedVersion === null || installedVersion !== expectedVersion) {
|
|
65
|
+
// Version unknown or mismatch, reinstall version from package
|
|
66
|
+
await installAndRun();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Version matches, run directly
|
|
71
|
+
runProxyMock();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
main();
|
package/lib/constants.js
ADDED
package/lib/install.js
CHANGED
|
@@ -8,10 +8,12 @@ import {
|
|
|
8
8
|
mkdirSync,
|
|
9
9
|
chmodSync,
|
|
10
10
|
} from "fs";
|
|
11
|
-
import { join
|
|
12
|
-
import { tmpdir, platform, arch
|
|
11
|
+
import { join } from "path";
|
|
12
|
+
import { tmpdir, platform, arch } from "os";
|
|
13
13
|
import { createHash } from "crypto";
|
|
14
|
-
import
|
|
14
|
+
import logger from "./log.js";
|
|
15
|
+
import { getPackageVersion } from "./version.js";
|
|
16
|
+
import { INSTALLROOT } from "./constants.js";
|
|
15
17
|
|
|
16
18
|
async function downloadFile(url, destPath) {
|
|
17
19
|
return new Promise((resolve, reject) => {
|
|
@@ -85,15 +87,7 @@ async function validateChecksum(filePath, expectedChecksum) {
|
|
|
85
87
|
});
|
|
86
88
|
}
|
|
87
89
|
|
|
88
|
-
function
|
|
89
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
90
|
-
const packageJson = JSON.parse(
|
|
91
|
-
readFileSync(join(__dirname, "..", "package.json"), "utf8"),
|
|
92
|
-
);
|
|
93
|
-
return packageJson.version;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async function install() {
|
|
90
|
+
export default async function install() {
|
|
97
91
|
try {
|
|
98
92
|
// Read version from package.json
|
|
99
93
|
const npmVersion = getPackageVersion();
|
|
@@ -109,11 +103,14 @@ async function install() {
|
|
|
109
103
|
const srcUrl = `${baseUrl}/${srcfile}`;
|
|
110
104
|
const shaUrl = `${baseUrl}/${srcfile}.sha256`;
|
|
111
105
|
|
|
112
|
-
const INSTALLROOT =
|
|
113
|
-
process.env.INSTALLROOT || join(homedir(), ".speedscale");
|
|
114
|
-
|
|
115
106
|
// Ensure install directory exists
|
|
116
|
-
|
|
107
|
+
try {
|
|
108
|
+
mkdirSync(INSTALLROOT, { recursive: true });
|
|
109
|
+
} catch (error) {
|
|
110
|
+
throw new Error(
|
|
111
|
+
`Failed to create install directory ${INSTALLROOT}: ${error.message}`,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
117
114
|
|
|
118
115
|
// Download checksum first
|
|
119
116
|
const tempShaPath = join(tmpdir(), `${srcfile}.sha256`);
|
|
@@ -135,23 +132,50 @@ async function install() {
|
|
|
135
132
|
|
|
136
133
|
// Install - always as "proxymock" since npm version provides isolation
|
|
137
134
|
const dstPath = join(INSTALLROOT, "proxymock");
|
|
138
|
-
|
|
135
|
+
try {
|
|
136
|
+
copyFileSync(tempBinPath, dstPath);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
throw new Error(
|
|
139
|
+
`Failed to install binary to ${dstPath}: ${error.message}`,
|
|
140
|
+
);
|
|
141
|
+
}
|
|
139
142
|
|
|
140
143
|
// Make executable on Unix-like systems
|
|
141
144
|
if (platform() !== "win32") {
|
|
142
|
-
|
|
145
|
+
try {
|
|
146
|
+
chmodSync(dstPath, "755");
|
|
147
|
+
} catch (error) {
|
|
148
|
+
throw new Error(`Failed to make binary executable: ${error.message}`);
|
|
149
|
+
}
|
|
143
150
|
}
|
|
144
151
|
|
|
145
|
-
// Cleanup
|
|
146
|
-
|
|
147
|
-
|
|
152
|
+
// Cleanup temp files (non-fatal if it fails)
|
|
153
|
+
try {
|
|
154
|
+
unlinkSync(tempShaPath);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
logger.error(
|
|
157
|
+
`Failed to cleanup temp file ${tempShaPath}: ${error.message}`,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
unlinkSync(tempBinPath);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
logger.error(
|
|
164
|
+
`Failed to cleanup temp file ${tempBinPath}: ${error.message}`,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
logger.info(`installed proxymock ${proxymockVersion}`);
|
|
148
169
|
} catch (error) {
|
|
149
|
-
|
|
150
|
-
|
|
170
|
+
logger.error(`Installation failed: ${error.message}`);
|
|
171
|
+
throw error; // Let the caller handle the error
|
|
151
172
|
}
|
|
152
173
|
}
|
|
153
174
|
|
|
154
175
|
// Run installation if this script is executed directly
|
|
155
176
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
156
|
-
install()
|
|
177
|
+
install().catch((error) => {
|
|
178
|
+
logger.error(`Installation failed: ${error.message}`);
|
|
179
|
+
process.exit(1);
|
|
180
|
+
});
|
|
157
181
|
}
|
package/lib/log.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import winston from "winston";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { INSTALLROOT } from "./constants.js";
|
|
4
|
+
|
|
5
|
+
const LOG_FILE = join(INSTALLROOT, "npm.log");
|
|
6
|
+
|
|
7
|
+
// Create winston logger instance
|
|
8
|
+
const logger = winston.createLogger({
|
|
9
|
+
level: "info",
|
|
10
|
+
format: winston.format.combine(
|
|
11
|
+
winston.format.timestamp({
|
|
12
|
+
format: "YYYY-MM-DDTHH:mm:ss.SSSZ",
|
|
13
|
+
}),
|
|
14
|
+
winston.format.printf(
|
|
15
|
+
({ timestamp, level, message }) =>
|
|
16
|
+
`[${timestamp}] [${level.toUpperCase()}] ${message}`,
|
|
17
|
+
),
|
|
18
|
+
),
|
|
19
|
+
transports: [
|
|
20
|
+
new winston.transports.File({
|
|
21
|
+
filename: LOG_FILE,
|
|
22
|
+
handleExceptions: false,
|
|
23
|
+
handleRejections: false,
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
exitOnError: false,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Prevent winston from crashing on errors
|
|
30
|
+
logger.on("error", () => {
|
|
31
|
+
// Silently ignore errors from the winston logger itself
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export default logger;
|
|
35
|
+
|
package/lib/version.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
|
+
import { join, dirname } from "path";
|
|
3
|
+
import { readFileSync } from "fs";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import logger from "../lib/log.js";
|
|
6
|
+
import { INSTALLROOT, binaryPath } from "./constants.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Reads the npm package version from package.json
|
|
10
|
+
* @returns {string} The version string (e.g., "2.3.660")
|
|
11
|
+
*/
|
|
12
|
+
export function getPackageVersion() {
|
|
13
|
+
try {
|
|
14
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const packageJson = JSON.parse(
|
|
16
|
+
readFileSync(join(__dirname, "..", "package.json"), "utf8"),
|
|
17
|
+
);
|
|
18
|
+
if (!packageJson.version) {
|
|
19
|
+
throw new Error("No version found in package.json");
|
|
20
|
+
}
|
|
21
|
+
return packageJson.version;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
throw new Error(`Failed to read package version: ${error.message}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves the version of the installed proxymock binary
|
|
29
|
+
* @returns {Promise<string|null>} The installed version (e.g., "v2.3.660") or null if unable to determine
|
|
30
|
+
*/
|
|
31
|
+
export async function getInstalledVersion() {
|
|
32
|
+
return new Promise((resolve) => {
|
|
33
|
+
const child = spawn(binaryPath, [
|
|
34
|
+
"version",
|
|
35
|
+
"--client",
|
|
36
|
+
"--output",
|
|
37
|
+
"pretty",
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
let stdout = "";
|
|
41
|
+
child.stdout.on("data", (data) => {
|
|
42
|
+
stdout += data.toString();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
child.on("exit", (code) => {
|
|
46
|
+
if (code !== 0) {
|
|
47
|
+
logger.error(`Failed to get proxymock version - exit code: ${code}`);
|
|
48
|
+
resolve(null);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// With --output pretty, it just prints the version string directly
|
|
53
|
+
const version = stdout.trim();
|
|
54
|
+
resolve(version);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
child.on("error", (err) => {
|
|
58
|
+
logger.error(
|
|
59
|
+
`Error spawning proxymock for version check: ${err.message}`,
|
|
60
|
+
);
|
|
61
|
+
resolve(null);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@speedscale/proxymock",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.677",
|
|
4
4
|
"description": "A free desktop CLI that automatically creates mocks and tests from watching your app run.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -34,5 +34,8 @@
|
|
|
34
34
|
"scripts": {
|
|
35
35
|
"test": "node --test || echo 'No tests defined'",
|
|
36
36
|
"validate": "npm pack && echo 'Package validation complete'"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"winston": "^3.11.0"
|
|
37
40
|
}
|
|
38
41
|
}
|