Skip to content

Commit 40834a4

Browse files
authored
Merge pull request #807 from acacode/get-rid-of-require
Get rid of `require`
2 parents 537ebdd + 9f773c5 commit 40834a4

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ npx swagger-typescript-api -p ./swagger.json -o ./src -n myApi.ts
8080
You can use this package from nodejs:
8181

8282
```js
83-
const { generateApi, generateTemplates } = require("swagger-typescript-api");
84-
const path = require("path");
85-
const fs = require("fs");
83+
import fs from "node:fs";
84+
import path from "node:path";
85+
import { generateApi, generateTemplates } from "swagger-typescript-api";
8686

8787
/* NOTE: all fields are optional expect one of `input`, `url`, `spec` */
8888
generateApi({

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ interface GenerateApiParamsBase {
192192
*
193193
* @example
194194
* ```ts
195-
* const { Translator } = require("swagger-typescript-api/src/translators/translator");
195+
* import { Translator } from "swagger-typescript-api/src/translators/translator";
196196
*
197197
* class MyTranslator extends Translator {
198198
*

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ const main = async () => {
301301
try {
302302
const customConfigPath = resolve(process.cwd(), options.customConfig);
303303
console.log(`✨ found custom config at: ${customConfigPath}`);
304-
customConfig = require(customConfigPath);
304+
customConfig = await import(customConfigPath);
305305
} catch (e) {
306306
/* empty */
307307
}

src/templates-worker.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,21 @@ class TemplatesWorker {
7676
);
7777
};
7878

79-
requireFnFromTemplate = (packageOrPath) => {
79+
requireFnFromTemplate = async (packageOrPath) => {
8080
const isPath =
8181
_.startsWith(packageOrPath, "./") || _.startsWith(packageOrPath, "../");
8282

8383
if (isPath) {
84-
return require(
84+
return await import(
8585
path.resolve(
8686
this.config.templatePaths.custom ||
8787
this.config.templatePaths.original,
8888
packageOrPath,
89-
),
89+
)
9090
);
9191
}
9292

93-
return require(packageOrPath);
93+
return await import(packageOrPath);
9494
};
9595

9696
getTemplate = ({ fileName, name, path }) => {

0 commit comments

Comments
 (0)