diff --git a/package.json b/package.json index fa6fa3b7..3f9732b0 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "c12": "^3.2.0", "citty": "^0.1.6", "consola": "^3.4.2", - "eta": "^2.2.0", + "eta": "^4.0.1", "js-yaml": "^4.1.0", "lodash": "^4.17.21", "nanoid": "^5.1.5", diff --git a/src/templates-worker.ts b/src/templates-worker.ts index 2d01c750..00807c6c 100644 --- a/src/templates-worker.ts +++ b/src/templates-worker.ts @@ -2,7 +2,7 @@ import * as module from "node:module"; import * as path from "node:path"; import * as url from "node:url"; import { consola } from "consola"; -import * as Eta from "eta"; +import { Eta } from "eta"; import lodash from "lodash"; import type { CodeGenProcess } from "./code-gen-process.js"; import type { CodeGenConfig } from "./configuration.js"; @@ -10,6 +10,10 @@ import type { FileSystem } from "./util/file-system.js"; const require = module.createRequire(import.meta.url); +const eta = new Eta({ + functionHeader: "const includeFile = options.includeFile;", +}); + export class TemplatesWorker { config: CodeGenConfig; fileSystem: FileSystem; @@ -214,31 +218,20 @@ export class TemplatesWorker { renderTemplate = ( template: string, - configuration: object, - options: object = {}, + configuration: Record, ) => { if (!template) return ""; - return Eta.render( - template, + return eta.render( + eta.compile(template, { async: false }), { ...this.getRenderTemplateData(), ...configuration, }, { - async: false, - ...options, - includeFile: ( - path: string, - configuration: object, - options: object = {}, - ) => { - return this.renderTemplate( - this.getTemplateContent(path), - configuration, - options, - ); - }, + // @ts-expect-error eta's meta options lack includeFile despite runtime support + includeFile: (path: string, configuration: Record) => + this.renderTemplate(this.getTemplateContent(path), configuration), }, ); }; diff --git a/yarn.lock b/yarn.lock index eaad7bb8..f7194ab7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2060,10 +2060,10 @@ __metadata: languageName: node linkType: hard -"eta@npm:^2.2.0": - version: 2.2.0 - resolution: "eta@npm:2.2.0" - checksum: 10c0/643b54d9539d2761bf6c5f4f48df1a5ea2d46c7f5a5fdc47a7d4802a8aa2b6262d4d61f724452e226c18cf82db02d48e65293fcc548f26a3f9d75a5ba7c3b859 +"eta@npm:^4.0.1": + version: 4.0.1 + resolution: "eta@npm:4.0.1" + checksum: 10c0/a7dc8641705a01373393aba6d0998f7571735c4f5444aa9c3375b2574a93ef3be80cfd5c7d1f8d6f0e56a83a14a7db451195ed3ceeab145f23492bb5b41d1ece languageName: node linkType: hard @@ -3777,7 +3777,7 @@ __metadata: c12: "npm:^3.2.0" citty: "npm:^0.1.6" consola: "npm:^3.4.2" - eta: "npm:^2.2.0" + eta: "npm:^4.0.1" js-yaml: "npm:^4.1.0" lodash: "npm:^4.17.21" nanoid: "npm:^5.1.5"