diff --git a/README.md b/README.md index 78baf57f..55ffcd79 100644 --- a/README.md +++ b/README.md @@ -80,9 +80,9 @@ npx swagger-typescript-api -p ./swagger.json -o ./src -n myApi.ts You can use this package from nodejs: ```js -const { generateApi, generateTemplates } = require("swagger-typescript-api"); -const path = require("path"); -const fs = require("fs"); +import fs from "node:fs"; +import path from "node:path"; +import { generateApi, generateTemplates } from "swagger-typescript-api"; /* NOTE: all fields are optional expect one of `input`, `url`, `spec` */ generateApi({ diff --git a/index.d.ts b/index.d.ts index fccb5403..43a42e0e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -192,7 +192,7 @@ interface GenerateApiParamsBase { * * @example * ```ts - * const { Translator } = require("swagger-typescript-api/src/translators/translator"); + * import { Translator } from "swagger-typescript-api/src/translators/translator"; * * class MyTranslator extends Translator { * diff --git a/index.js b/index.js index 353d33d6..5f0172a8 100644 --- a/index.js +++ b/index.js @@ -301,7 +301,7 @@ const main = async () => { try { const customConfigPath = resolve(process.cwd(), options.customConfig); console.log(`✨ found custom config at: ${customConfigPath}`); - customConfig = require(customConfigPath); + customConfig = await import(customConfigPath); } catch (e) { /* empty */ } diff --git a/src/templates-worker.js b/src/templates-worker.js index 9b834f0a..0dc63823 100644 --- a/src/templates-worker.js +++ b/src/templates-worker.js @@ -76,21 +76,21 @@ class TemplatesWorker { ); }; - requireFnFromTemplate = (packageOrPath) => { + requireFnFromTemplate = async (packageOrPath) => { const isPath = _.startsWith(packageOrPath, "./") || _.startsWith(packageOrPath, "../"); if (isPath) { - return require( + return await import( path.resolve( this.config.templatePaths.custom || this.config.templatePaths.original, packageOrPath, - ), + ) ); } - return require(packageOrPath); + return await import(packageOrPath); }; getTemplate = ({ fileName, name, path }) => {