From 0bd6d20c553ce211f8de7c80c8dfadff145b3683 Mon Sep 17 00:00:00 2001 From: Guillaume FORTAINE Date: Wed, 4 Jan 2023 18:20:39 +0100 Subject: [PATCH] chore(esm): enable ESM --- .../typescript-axios/configuration.mustache | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sdk-template-overrides/typescript-axios/configuration.mustache b/sdk-template-overrides/typescript-axios/configuration.mustache index 1020f66b..ecd34354 100644 --- a/sdk-template-overrides/typescript-axios/configuration.mustache +++ b/sdk-template-overrides/typescript-axios/configuration.mustache @@ -3,7 +3,15 @@ {{>licenseInfo}} {{! Edited by OpenAI, line 6 }} -const packageJson = require("../package.json"); +import FormData from "form-data"; +import filedirname from "filedirname"; +import fs from "fs"; +import path from "path"; + +const [, dirname] = filedirname(); +const filePath = path.join(dirname, '../package.json'); +const contents = fs.readFileSync(filePath, { encoding: 'utf8' }); +const packageJson = JSON.parse(contents); export interface ConfigurationParameters { apiKey?: string | Promise | ((name: string) => string) | ((name: string) => Promise); @@ -100,7 +108,7 @@ export class Configuration { this.baseOptions.headers['OpenAI-Organization'] = this.organization; } if (!this.formDataCtor) { - this.formDataCtor = require("form-data"); + this.formDataCtor = FormData; } }