Skip to content

Commit

Permalink
fix: remove reference to __dirname
Browse files Browse the repository at this point in the history
The builtin __dirname is not available for ES modules.
  • Loading branch information
thedadams committed May 7, 2024
1 parent 4f8b66d commit 75fa88d
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 13 deletions.
28 changes: 28 additions & 0 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const test = process.env.NODE_ENV === 'test';

module.exports = {
"presets": [
"@babel/preset-typescript",
[
"@babel/preset-env",
{
"useBuiltIns": "entry",
"corejs": 3,
"targets": {
"node": "current"
}
}
]
],
"plugins": [
function () {
return {
visitor: {
MetaProperty(path) {
path.replaceWithSourceString("__filename")
}
}
}
}
]
};
72 changes: 61 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@
"devDependencies": {
"@babel/core": "^7.24.5",
"@babel/preset-env": "^7.24.5",
"@babel/preset-typescript": "^7.24.1",
"@rollup/plugin-typescript": "^11.1.6",
"@swc/cli": "^0.3.9",
"@swc/core": "^1.4.2",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.8",
"babel-loader": "^9.1.3",
"babel-plugin-transform-import-meta": "^2.2.1",
"copyfiles": "^2.4.1",
"jest": "^29.7.0",
"npm-run-all": "^4.1.5",
Expand All @@ -58,7 +60,13 @@
},
"jest": {
"transform": {
"^.+\\.ts?$": "ts-jest"
"^.+\\.ts?$": [
"ts-jest",
{
"babelConfig": true,
"useESM": true
}
]
},
"testEnvironment": "node",
"testRegex": "/tests/.*\\.(test|spec)?\\.(ts|tsx)$",
Expand Down
3 changes: 2 additions & 1 deletion src/gptscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,8 @@ async function getCmdPath(): Promise<string> {
}

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

export function listTools(gptscriptURL?: string): Promise<string> {
Expand Down

0 comments on commit 75fa88d

Please sign in to comment.