Skip to content

Commit 03595fd

Browse files
committed
Update renderTemplate for eta v4
Signed-off-by: Sora Morimoto <[email protected]>
1 parent f0751e6 commit 03595fd

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

src/templates-worker.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ import * as module from "node:module";
22
import * as path from "node:path";
33
import * as url from "node:url";
44
import { consola } from "consola";
5-
import * as Eta from "eta";
5+
import { Eta } from "eta";
66
import lodash from "lodash";
77
import type { CodeGenProcess } from "./code-gen-process.js";
88
import type { CodeGenConfig } from "./configuration.js";
99
import type { FileSystem } from "./util/file-system.js";
1010

1111
const require = module.createRequire(import.meta.url);
1212

13+
const eta = new Eta({
14+
functionHeader: "const includeFile = options.includeFile;",
15+
});
16+
1317
export class TemplatesWorker {
1418
config: CodeGenConfig;
1519
fileSystem: FileSystem;
@@ -214,31 +218,20 @@ export class TemplatesWorker {
214218

215219
renderTemplate = (
216220
template: string,
217-
configuration: object,
218-
options: object = {},
221+
configuration: Record<string, unknown>,
219222
) => {
220223
if (!template) return "";
221224

222-
return Eta.render(
223-
template,
225+
return eta.render(
226+
eta.compile(template, { async: false }),
224227
{
225228
...this.getRenderTemplateData(),
226229
...configuration,
227230
},
228231
{
229-
async: false,
230-
...options,
231-
includeFile: (
232-
path: string,
233-
configuration: object,
234-
options: object = {},
235-
) => {
236-
return this.renderTemplate(
237-
this.getTemplateContent(path),
238-
configuration,
239-
options,
240-
);
241-
},
232+
// @ts-expect-error eta's meta options lack includeFile despite runtime support
233+
includeFile: (path: string, configuration: Record<string, string>) =>
234+
this.renderTemplate(this.getTemplateContent(path), configuration),
242235
},
243236
);
244237
};

0 commit comments

Comments
 (0)