Skip to content

Commit ca2f708

Browse files
committed
fix: correct gptscript bin path behavior
There is a big difference between running the tests and importing this as a module, specifically when not setting GPTSCRIPT_BIN. This change addresses these differences to allow both contexts to work.
1 parent a83af5b commit ca2f708

File tree

5 files changed

+6
-3
lines changed

5 files changed

+6
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"url": "^0.11.3"
5454
},
5555
"jest": {
56+
"preset": "ts-jest/presets/default-esm",
5657
"transform": {
5758
"^.+\\.ts?$": [
5859
"ts-jest",

scripts/install-binary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const suffix = {
8585

8686
const url = `${gptscript_info.url}${gptscript_info.version}/gptscript-${gptscript_info.version}-${pltfm}-${arch}.${suffix}`;
8787

88-
const outputDir = path.resolve('..', 'bin');
88+
const outputDir = path.resolve('bin');
8989

9090
const fileExist = (path) => {
9191
try {

src/gptscript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ function getCmdPath(): string {
668668
return process.env.GPTSCRIPT_BIN
669669
}
670670

671-
return path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "bin", "gptscript")
671+
return path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "bin", "gptscript")
672672
}
673673

674674
function parseBlocksFromNodes(nodes: any[]): Block[] {

tests/gptscript.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import * as gptscript from "../src/gptscript"
22
import path from "path"
3+
import {fileURLToPath} from "url"
34

45
let client: gptscript.Client
6+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
57

68
describe("gptscript module", () => {
79
beforeAll(async () => {

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"target": "esnext",
44
"module": "esnext",
5-
"moduleResolution": "bundler",
5+
"moduleResolution": "node",
66
"rootDir": "./src",
77
"declaration": true,
88
"outDir": "./dist",

0 commit comments

Comments
 (0)