pgplan 1.0.0 → 1.1.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.
Files changed (2) hide show
  1. package/bin/pgplan +31 -44
  2. package/package.json +11 -19
package/bin/pgplan CHANGED
@@ -1,58 +1,45 @@
1
1
  #!/usr/bin/env node
2
-
3
2
  "use strict";
4
3
 
5
4
  const { execFileSync } = require("child_process");
6
- const path = require("path");
7
- const os = require("os");
8
5
 
9
- const PLATFORMS = {
10
- "linux-x64": { pkg: "@pgplan/linux-x64", bin: "pgplan" },
11
- "linux-arm64": { pkg: "@pgplan/linux-arm64", bin: "pgplan" },
12
- "darwin-x64": { pkg: "@pgplan/darwin-x64", bin: "pgplan" },
13
- "darwin-arm64": { pkg: "@pgplan/darwin-arm64", bin: "pgplan" },
14
- "win32-x64": { pkg: "@pgplan/win32-x64", bin: "pgplan.exe" },
15
- };
6
+ const BIN_NAME = "pgplan";
7
+ const ORG_NAME = "pgplan";
16
8
 
17
- function getPlatformKey() {
18
- const platform = os.platform();
19
- const arch = os.arch();
20
- return `${platform}-${arch}`;
21
- }
9
+ const platforms = {
10
+ "linux-x64": `@${ORG_NAME}/${BIN_NAME}-linux-x64`,
11
+ "linux-arm64": `@${ORG_NAME}/${BIN_NAME}-linux-arm64`,
12
+ "darwin-x64": `@${ORG_NAME}/${BIN_NAME}-darwin-x64`,
13
+ "darwin-arm64": `@${ORG_NAME}/${BIN_NAME}-darwin-arm64`,
14
+ "win32-x64": `@${ORG_NAME}/${BIN_NAME}-win32-x64`,
15
+ "win32-arm64": `@${ORG_NAME}/${BIN_NAME}-win32-arm64`,
16
+ };
22
17
 
23
- function getBinaryPath() {
24
- const key = getPlatformKey();
25
- const entry = PLATFORMS[key];
26
- if (!entry) {
27
- const supported = Object.keys(PLATFORMS).join(", ");
28
- console.error(
29
- `pgplan: unsupported platform ${key}\nSupported: ${supported}`
30
- );
31
- process.exit(1);
32
- }
18
+ const key = `${process.platform}-${process.arch === "x64" ? "x64" : process.arch}`;
19
+ const pkg = platforms[key];
33
20
 
34
- try {
35
- const pkgPath = require.resolve(`${entry.pkg}/package.json`);
36
- return path.join(path.dirname(pkgPath), entry.bin);
37
- } catch {
38
- console.error(
39
- `pgplan: platform package ${entry.pkg} not installed.\n` +
40
- `Try reinstalling: npm install pgplan`
41
- );
42
- process.exit(1);
43
- }
21
+ if (!pkg) {
22
+ console.error(
23
+ `${BIN_NAME}: unsupported platform ${process.platform}/${process.arch}\n` +
24
+ `supported platforms: ${Object.keys(platforms).join(", ")}`
25
+ );
26
+ process.exit(1);
44
27
  }
45
28
 
46
- const binary = getBinaryPath();
29
+ let binPath;
30
+ try {
31
+ const binFile = process.platform === "win32" ? `${BIN_NAME}.exe` : BIN_NAME;
32
+ binPath = require.resolve(`${pkg}/bin/${binFile}`);
33
+ } catch (e) {
34
+ console.error(
35
+ `${BIN_NAME}: could not find platform package ${pkg}\n` +
36
+ `try reinstalling: npm install -g ${BIN_NAME}`
37
+ );
38
+ process.exit(1);
39
+ }
47
40
 
48
41
  try {
49
- const result = execFileSync(binary, process.argv.slice(2), {
50
- stdio: "inherit",
51
- env: process.env,
52
- });
42
+ execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
53
43
  } catch (e) {
54
- if (e.status !== null) {
55
- process.exit(e.status);
56
- }
57
- throw e;
44
+ process.exit(e.status ?? 1);
58
45
  }
package/package.json CHANGED
@@ -1,29 +1,21 @@
1
1
  {
2
2
  "name": "pgplan",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Analyze and compare PostgreSQL query plans",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/JacobArthurs/pgplan.git"
8
- },
9
- "author": "Jacob Arthurs",
10
5
  "license": "MIT",
11
- "bugs": {
12
- "url": "https://github.com/JacobArthurs/pgplan/issues"
13
- },
14
- "homepage": "https://github.com/JacobArthurs/pgplan",
6
+ "repository": "https://github.com/JacobArthurs/pgplan",
7
+ "files": [
8
+ "bin"
9
+ ],
15
10
  "bin": {
16
11
  "pgplan": "bin/pgplan"
17
12
  },
18
- "files": [
19
- "bin/**",
20
- "README.md"
21
- ],
22
13
  "optionalDependencies": {
23
- "@pgplan/linux-x64": "1.0.0",
24
- "@pgplan/linux-arm64": "1.0.0",
25
- "@pgplan/darwin-x64": "1.0.0",
26
- "@pgplan/darwin-arm64": "1.0.0",
27
- "@pgplan/win32-x64": "1.0.0"
14
+ "@pgplan/pgplan-darwin-arm64": "1.1.1",
15
+ "@pgplan/pgplan-darwin-x64": "1.1.1",
16
+ "@pgplan/pgplan-linux-arm64": "1.1.1",
17
+ "@pgplan/pgplan-linux-x64": "1.1.1",
18
+ "@pgplan/pgplan-win32-arm64": "1.1.1",
19
+ "@pgplan/pgplan-win32-x64": "1.1.1"
28
20
  }
29
21
  }