Skip to content

Commit

Permalink
fix: correct gptscript bin path behavior
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thedadams committed May 30, 2024
1 parent a83af5b commit ca2f708
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"url": "^0.11.3"
},
"jest": {
"preset": "ts-jest/presets/default-esm",
"transform": {
"^.+\\.ts?$": [
"ts-jest",
Expand Down
2 changes: 1 addition & 1 deletion scripts/install-binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const suffix = {

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

const outputDir = path.resolve('..', 'bin');
const outputDir = path.resolve('bin');

const fileExist = (path) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/gptscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ function getCmdPath(): string {
return process.env.GPTSCRIPT_BIN
}

return path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "bin", "gptscript")
return path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "bin", "gptscript")
}

function parseBlocksFromNodes(nodes: any[]): Block[] {
Expand Down
2 changes: 2 additions & 0 deletions tests/gptscript.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as gptscript from "../src/gptscript"
import path from "path"
import {fileURLToPath} from "url"

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

describe("gptscript module", () => {
beforeAll(async () => {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "bundler",
"moduleResolution": "node",
"rootDir": "./src",
"declaration": true,
"outDir": "./dist",
Expand Down

0 comments on commit ca2f708

Please sign in to comment.