pgai 0.14.0-dev.43 → 0.14.0-dev.44
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/pgai.ts +68 -0
- package/dist/bin/pgai.js +55 -0
- package/package.json +12 -5
- package/bin/pgai.js +0 -48
package/bin/pgai.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { spawn } from "child_process";
|
|
4
|
+
import { resolve, dirname } from "path";
|
|
5
|
+
import { existsSync } from "fs";
|
|
6
|
+
import { createRequire } from "module";
|
|
7
|
+
import { fileURLToPath } from "url";
|
|
8
|
+
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = dirname(__filename);
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
|
|
13
|
+
function die(msg: string): never {
|
|
14
|
+
process.stderr.write(`${msg}\n`);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let target: string;
|
|
19
|
+
|
|
20
|
+
// Try to find the postgresai package
|
|
21
|
+
try {
|
|
22
|
+
// First try to resolve from node_modules - look for the compiled dist version
|
|
23
|
+
const postgresaiPkg = require.resolve("postgresai/package.json");
|
|
24
|
+
target = resolve(dirname(postgresaiPkg), "dist", "bin", "postgres-ai.js");
|
|
25
|
+
|
|
26
|
+
// Fallback to source TS if dist doesn't exist (development)
|
|
27
|
+
if (!existsSync(target)) {
|
|
28
|
+
target = resolve(dirname(postgresaiPkg), "bin", "postgres-ai.ts");
|
|
29
|
+
}
|
|
30
|
+
} catch {
|
|
31
|
+
// Dev-friendly fallback when running from the monorepo checkout (postgresai lives under ../cli).
|
|
32
|
+
const fallbackJs = resolve(__dirname, "..", "..", "cli", "dist", "bin", "postgres-ai.js");
|
|
33
|
+
const fallbackTs = resolve(__dirname, "..", "..", "cli", "bin", "postgres-ai.ts");
|
|
34
|
+
|
|
35
|
+
if (existsSync(fallbackJs)) {
|
|
36
|
+
target = fallbackJs;
|
|
37
|
+
} else if (existsSync(fallbackTs)) {
|
|
38
|
+
target = fallbackTs;
|
|
39
|
+
} else {
|
|
40
|
+
die(
|
|
41
|
+
[
|
|
42
|
+
"pgai: failed to locate postgresai package.",
|
|
43
|
+
"",
|
|
44
|
+
"This wrapper expects postgresai to be installed as a dependency.",
|
|
45
|
+
].join("\n")
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Determine if we should use node or bun based on the file extension
|
|
51
|
+
const isTsFile = target.endsWith(".ts");
|
|
52
|
+
const runtime = isTsFile ? "bun" : process.execPath;
|
|
53
|
+
|
|
54
|
+
const child = spawn(runtime, [target, ...process.argv.slice(2)], {
|
|
55
|
+
stdio: "inherit",
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
child.on("exit", (code, signal) => {
|
|
59
|
+
if (signal) {
|
|
60
|
+
process.kill(process.pid, signal);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
process.exit(code ?? 0);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
child.on("error", (err) => {
|
|
67
|
+
die(`pgai: failed to run postgresai: ${err instanceof Error ? err.message : String(err)}`);
|
|
68
|
+
});
|
package/dist/bin/pgai.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @bun
|
|
3
|
+
|
|
4
|
+
// bin/pgai.ts
|
|
5
|
+
import { spawn } from "child_process";
|
|
6
|
+
import { resolve, dirname } from "path";
|
|
7
|
+
import { existsSync } from "fs";
|
|
8
|
+
import { createRequire } from "module";
|
|
9
|
+
import { fileURLToPath } from "url";
|
|
10
|
+
var __filename2 = fileURLToPath(import.meta.url);
|
|
11
|
+
var __dirname2 = dirname(__filename2);
|
|
12
|
+
var require2 = createRequire(import.meta.url);
|
|
13
|
+
function die(msg) {
|
|
14
|
+
process.stderr.write(`${msg}
|
|
15
|
+
`);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
var target;
|
|
19
|
+
try {
|
|
20
|
+
const postgresaiPkg = require2.resolve("postgresai/package.json");
|
|
21
|
+
target = resolve(dirname(postgresaiPkg), "dist", "bin", "postgres-ai.js");
|
|
22
|
+
if (!existsSync(target)) {
|
|
23
|
+
target = resolve(dirname(postgresaiPkg), "bin", "postgres-ai.ts");
|
|
24
|
+
}
|
|
25
|
+
} catch {
|
|
26
|
+
const fallbackJs = resolve(__dirname2, "..", "..", "cli", "dist", "bin", "postgres-ai.js");
|
|
27
|
+
const fallbackTs = resolve(__dirname2, "..", "..", "cli", "bin", "postgres-ai.ts");
|
|
28
|
+
if (existsSync(fallbackJs)) {
|
|
29
|
+
target = fallbackJs;
|
|
30
|
+
} else if (existsSync(fallbackTs)) {
|
|
31
|
+
target = fallbackTs;
|
|
32
|
+
} else {
|
|
33
|
+
die([
|
|
34
|
+
"pgai: failed to locate postgresai package.",
|
|
35
|
+
"",
|
|
36
|
+
"This wrapper expects postgresai to be installed as a dependency."
|
|
37
|
+
].join(`
|
|
38
|
+
`));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
var isTsFile = target.endsWith(".ts");
|
|
42
|
+
var runtime = isTsFile ? "bun" : process.execPath;
|
|
43
|
+
var child = spawn(runtime, [target, ...process.argv.slice(2)], {
|
|
44
|
+
stdio: "inherit"
|
|
45
|
+
});
|
|
46
|
+
child.on("exit", (code, signal) => {
|
|
47
|
+
if (signal) {
|
|
48
|
+
process.kill(process.pid, signal);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
process.exit(code ?? 0);
|
|
52
|
+
});
|
|
53
|
+
child.on("error", (err) => {
|
|
54
|
+
die(`pgai: failed to run postgresai: ${err instanceof Error ? err.message : String(err)}`);
|
|
55
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pgai",
|
|
3
|
-
"version": "0.14.0-dev.
|
|
4
|
-
"description": "Thin wrapper for postgresai CLI (provides `npx pgai ...`)",
|
|
3
|
+
"version": "0.14.0-dev.44",
|
|
4
|
+
"description": "Thin wrapper for postgresai CLI (provides `npx pgai ...` or `bunx pgai ...`)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"private": false,
|
|
7
7
|
"repository": {
|
|
@@ -13,13 +13,20 @@
|
|
|
13
13
|
"url": "https://gitlab.com/postgres-ai/postgres_ai/-/issues"
|
|
14
14
|
},
|
|
15
15
|
"bin": {
|
|
16
|
-
"pgai": "./bin/pgai.js"
|
|
16
|
+
"pgai": "./dist/bin/pgai.js"
|
|
17
17
|
},
|
|
18
|
-
"type": "
|
|
18
|
+
"type": "module",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=18"
|
|
21
21
|
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "bun build ./bin/pgai.ts --outdir ./dist/bin --target node && node -e \"const fs=require('fs');const f='./dist/bin/pgai.js';fs.writeFileSync(f,fs.readFileSync(f,'utf8').replace('#!/usr/bin/env bun','#!/usr/bin/env node'))\"",
|
|
24
|
+
"prepublishOnly": "npm run build"
|
|
25
|
+
},
|
|
22
26
|
"dependencies": {
|
|
23
|
-
"postgresai": "0.14.0-dev.
|
|
27
|
+
"postgresai": "0.14.0-dev.44"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/bun": "^1.1.14"
|
|
24
31
|
}
|
|
25
32
|
}
|
package/bin/pgai.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
const { spawn } = require("node:child_process");
|
|
5
|
-
const path = require("node:path");
|
|
6
|
-
const fs = require("node:fs");
|
|
7
|
-
|
|
8
|
-
function die(msg) {
|
|
9
|
-
process.stderr.write(`${msg}\n`);
|
|
10
|
-
process.exit(1);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
let target;
|
|
14
|
-
try {
|
|
15
|
-
target = require.resolve("postgresai/dist/bin/postgres-ai.js");
|
|
16
|
-
} catch (e) {
|
|
17
|
-
// Dev-friendly fallback when running from the monorepo checkout (postgresai lives under ../cli).
|
|
18
|
-
const fallback = path.resolve(__dirname, "..", "..", "cli", "dist", "bin", "postgres-ai.js");
|
|
19
|
-
if (fs.existsSync(fallback)) {
|
|
20
|
-
target = fallback;
|
|
21
|
-
} else {
|
|
22
|
-
die(
|
|
23
|
-
[
|
|
24
|
-
"pgai: failed to locate postgresai package.",
|
|
25
|
-
"",
|
|
26
|
-
"This wrapper expects postgresai to be installed as a dependency.",
|
|
27
|
-
].join("\n")
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const child = spawn(process.execPath, [target, ...process.argv.slice(2)], {
|
|
33
|
-
stdio: "inherit",
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
child.on("exit", (code, signal) => {
|
|
37
|
-
if (signal) {
|
|
38
|
-
process.kill(process.pid, signal);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
process.exit(code ?? 0);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
child.on("error", (err) => {
|
|
45
|
-
die(`pgai: failed to run postgresai: ${err instanceof Error ? err.message : String(err)}`);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
|