diff --git a/babel.config.cjs b/babel.config.cjs new file mode 100644 index 0000000..786a88b --- /dev/null +++ b/babel.config.cjs @@ -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") + } + } + } + } + ] +}; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 07b25c2..8b234f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,12 +20,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", @@ -795,12 +797,12 @@ } }, "node_modules/@babel/plugin-syntax-jsx": { - "version": "7.23.3", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.23.3.tgz", - "integrity": "sha512-EB2MELswq55OHUoRZLGg/zC7QWUKfNLpE57m/S2yr1uEneIgsTgrSzXP3NXEsMkVn76OlaVVnzN+ugObuYGwhg==", + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.24.1.tgz", + "integrity": "sha512-2eCtxZXf+kbkMIsXS4poTvT4Yu5rXiRa+9xGVT56raghjmBTKMpFNc9R4IDiB4emao9eO22Ox7CxuJG7BgExqA==", "dev": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.22.5" + "@babel/helper-plugin-utils": "^7.24.0" }, "engines": { "node": ">=6.9.0" @@ -912,12 +914,12 @@ } }, "node_modules/@babel/plugin-syntax-typescript": { - "version": "7.23.3", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.23.3.tgz", - "integrity": "sha512-9EiNjVJOMwCO+43TqoTrgQ8jMwcAd0sWyXi9RPfIsLTj4R2MADDDQXELhffaUx/uJv2AYcxBgPwH6j4TIA4ytQ==", + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.24.1.tgz", + "integrity": "sha512-Yhnmvy5HZEnHUty6i++gcfH1/l68AHnItFHnaCv6hn9dNh0hQvvQJsxpi4BMBFN5DLeHBuucT/0DgzXif/OyRw==", "dev": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.22.5" + "@babel/helper-plugin-utils": "^7.24.0" }, "engines": { "node": ">=6.9.0" @@ -1650,6 +1652,24 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/plugin-transform-typescript": { + "version": "7.24.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.24.5.tgz", + "integrity": "sha512-E0VWu/hk83BIFUWnsKZ4D81KXjN5L3MobvevOHErASk9IPwKHOkTgvqzvNo1yP/ePJWqqK2SpUR5z+KQbl6NVw==", + "dev": true, + "dependencies": { + "@babel/helper-annotate-as-pure": "^7.22.5", + "@babel/helper-create-class-features-plugin": "^7.24.5", + "@babel/helper-plugin-utils": "^7.24.5", + "@babel/plugin-syntax-typescript": "^7.24.1" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/plugin-transform-unicode-escapes": { "version": "7.24.1", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-escapes/-/plugin-transform-unicode-escapes-7.24.1.tgz", @@ -1831,6 +1851,25 @@ "@babel/core": "^7.0.0-0 || ^8.0.0-0 <8.0.0" } }, + "node_modules/@babel/preset-typescript": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.24.1.tgz", + "integrity": "sha512-1DBaMmRDpuYQBPWD8Pf/WEwCrtgRHxsZnP4mIy9G/X+hFfbI47Q2G4t1Paakld84+qsk2fSsUPMKg71jkoOOaQ==", + "dev": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/helper-validator-option": "^7.23.5", + "@babel/plugin-syntax-jsx": "^7.24.1", + "@babel/plugin-transform-modules-commonjs": "^7.24.1", + "@babel/plugin-transform-typescript": "^7.24.1" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/regjsgen": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/@babel/regjsgen/-/regjsgen-0.8.0.tgz", @@ -3272,6 +3311,19 @@ "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" } }, + "node_modules/babel-plugin-transform-import-meta": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-import-meta/-/babel-plugin-transform-import-meta-2.2.1.tgz", + "integrity": "sha512-AxNh27Pcg8Kt112RGa3Vod2QS2YXKKJ6+nSvRtv7qQTJAdx0MZa4UHZ4lnxHUWA2MNbLuZQv5FVab4P1CoLOWw==", + "dev": true, + "dependencies": { + "@babel/template": "^7.4.4", + "tslib": "^2.4.0" + }, + "peerDependencies": { + "@babel/core": "^7.10.0" + } + }, "node_modules/babel-preset-current-node-syntax": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.0.1.tgz", @@ -8819,9 +8871,7 @@ "version": "2.6.2", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", - "dev": true, - "optional": true, - "peer": true + "dev": true }, "node_modules/type-detect": { "version": "4.0.8", diff --git a/package.json b/package.json index 6fd0592..73a309e 100644 --- a/package.json +++ b/package.json @@ -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", @@ -58,7 +60,13 @@ }, "jest": { "transform": { - "^.+\\.ts?$": "ts-jest" + "^.+\\.ts?$": [ + "ts-jest", + { + "babelConfig": true, + "useESM": true + } + ] }, "testEnvironment": "node", "testRegex": "/tests/.*\\.(test|spec)?\\.(ts|tsx)$", diff --git a/src/gptscript.ts b/src/gptscript.ts index 6aae7f9..4b9f244 100644 --- a/src/gptscript.ts +++ b/src/gptscript.ts @@ -773,7 +773,8 @@ async function getCmdPath(): Promise { } 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 {