Skip to content

Commit 75fa88d

Browse files
committed
fix: remove reference to __dirname
The builtin __dirname is not available for ES modules.
1 parent 4f8b66d commit 75fa88d

File tree

4 files changed

+100
-13
lines changed

4 files changed

+100
-13
lines changed

babel.config.cjs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const test = process.env.NODE_ENV === 'test';
2+
3+
module.exports = {
4+
"presets": [
5+
"@babel/preset-typescript",
6+
[
7+
"@babel/preset-env",
8+
{
9+
"useBuiltIns": "entry",
10+
"corejs": 3,
11+
"targets": {
12+
"node": "current"
13+
}
14+
}
15+
]
16+
],
17+
"plugins": [
18+
function () {
19+
return {
20+
visitor: {
21+
MetaProperty(path) {
22+
path.replaceWithSourceString("__filename")
23+
}
24+
}
25+
}
26+
}
27+
]
28+
};

package-lock.json

+61-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@
3939
"devDependencies": {
4040
"@babel/core": "^7.24.5",
4141
"@babel/preset-env": "^7.24.5",
42+
"@babel/preset-typescript": "^7.24.1",
4243
"@rollup/plugin-typescript": "^11.1.6",
4344
"@swc/cli": "^0.3.9",
4445
"@swc/core": "^1.4.2",
4546
"@types/jest": "^29.5.12",
4647
"@types/node": "^20.12.8",
4748
"babel-loader": "^9.1.3",
49+
"babel-plugin-transform-import-meta": "^2.2.1",
4850
"copyfiles": "^2.4.1",
4951
"jest": "^29.7.0",
5052
"npm-run-all": "^4.1.5",
@@ -58,7 +60,13 @@
5860
},
5961
"jest": {
6062
"transform": {
61-
"^.+\\.ts?$": "ts-jest"
63+
"^.+\\.ts?$": [
64+
"ts-jest",
65+
{
66+
"babelConfig": true,
67+
"useESM": true
68+
}
69+
]
6270
},
6371
"testEnvironment": "node",
6472
"testRegex": "/tests/.*\\.(test|spec)?\\.(ts|tsx)$",

src/gptscript.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,8 @@ async function getCmdPath(): Promise<string> {
773773
}
774774

775775
const path = await import("path")
776-
return path.join(__dirname, "..", "bin", "gptscript")
776+
const url = await import("url")
777+
return path.join(path.dirname(url.fileURLToPath(import.meta.url)), "..", "bin", "gptscript")
777778
}
778779

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

0 commit comments

Comments
 (0)