ecto 4.4.1 → 4.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/ecto.d.ts +16 -16
  2. package/dist/ecto.js +116 -87
  3. package/package.json +12 -9
package/dist/ecto.d.ts CHANGED
@@ -1,5 +1,14 @@
1
- import { HookifiedOptions, Hookified } from 'hookified';
2
1
  import { Cacheable, CacheableMemory } from 'cacheable';
2
+ import { HookifiedOptions, Hookified } from 'hookified';
3
+
4
+ type EngineInterface = {
5
+ names: string[];
6
+ engine: any;
7
+ opts?: Record<string, unknown>;
8
+ rootTemplatePath?: string;
9
+ render(source: string, data?: Record<string, unknown>): Promise<string>;
10
+ renderSync(source: string, data?: Record<string, unknown>): string;
11
+ };
3
12
 
4
13
  declare class EngineMap {
5
14
  private readonly _mappings;
@@ -12,7 +21,7 @@ declare class EngineMap {
12
21
 
13
22
  declare class BaseEngine {
14
23
  names: string[];
15
- opts?: any;
24
+ opts?: Record<string, unknown>;
16
25
  engine: any;
17
26
  rootTemplatePath?: string;
18
27
  private _extensions;
@@ -21,17 +30,8 @@ declare class BaseEngine {
21
30
  deleteExtension(name: string): void;
22
31
  }
23
32
 
24
- type EngineInterface = {
25
- names: string[];
26
- engine: any;
27
- opts?: any;
28
- rootTemplatePath?: string;
29
- render(source: string, data?: Record<string, unknown>): Promise<string>;
30
- renderSync(source: string, data?: Record<string, unknown>): string;
31
- };
32
-
33
- declare class Markdown extends BaseEngine implements EngineInterface {
34
- constructor(options?: any);
33
+ declare class EJS extends BaseEngine implements EngineInterface {
34
+ constructor(options?: Record<string, unknown>);
35
35
  render(source: string, data?: Record<string, unknown>): Promise<string>;
36
36
  renderSync(source: string, data?: Record<string, unknown>): string;
37
37
  }
@@ -45,13 +45,13 @@ declare class Handlebars extends BaseEngine implements EngineInterface {
45
45
  registerPartials(partialsPath: string): boolean;
46
46
  }
47
47
 
48
- declare class EJS extends BaseEngine implements EngineInterface {
48
+ declare class Liquid extends BaseEngine implements EngineInterface {
49
49
  constructor(options?: Record<string, unknown>);
50
50
  render(source: string, data?: Record<string, unknown>): Promise<string>;
51
51
  renderSync(source: string, data?: Record<string, unknown>): string;
52
52
  }
53
53
 
54
- declare class Pug extends BaseEngine implements EngineInterface {
54
+ declare class Markdown extends BaseEngine implements EngineInterface {
55
55
  constructor(options?: Record<string, unknown>);
56
56
  render(source: string, data?: Record<string, unknown>): Promise<string>;
57
57
  renderSync(source: string, data?: Record<string, unknown>): string;
@@ -63,7 +63,7 @@ declare class Nunjucks extends BaseEngine implements EngineInterface {
63
63
  renderSync(source: string, data?: Record<string, unknown>): string;
64
64
  }
65
65
 
66
- declare class Liquid extends BaseEngine implements EngineInterface {
66
+ declare class Pug extends BaseEngine implements EngineInterface {
67
67
  constructor(options?: Record<string, unknown>);
68
68
  render(source: string, data?: Record<string, unknown>): Promise<string>;
69
69
  renderSync(source: string, data?: Record<string, unknown>): string;
package/dist/ecto.js CHANGED
@@ -1,15 +1,15 @@
1
1
  // src/ecto.ts
2
2
  import fs2 from "fs";
3
+ import { Cacheable, CacheableMemory } from "cacheable";
3
4
  import { Hookified } from "hookified";
4
5
  import { Writr as Writr2 } from "writr";
5
- import { Cacheable, CacheableMemory } from "cacheable";
6
6
 
7
7
  // src/engine-map.ts
8
8
  var EngineMap = class {
9
9
  _mappings = /* @__PURE__ */ new Map();
10
10
  set(name, extensions) {
11
11
  const engineName = name.trim().toLowerCase();
12
- const engineExtensions = new Array();
12
+ const engineExtensions = [];
13
13
  if (extensions.length > 0 && name !== "") {
14
14
  for (let extension of extensions) {
15
15
  extension = extension.trim().toLowerCase();
@@ -27,7 +27,7 @@ var EngineMap = class {
27
27
  const engineName = name.trim().toLowerCase();
28
28
  const extensions = this._mappings.get(engineName);
29
29
  if (extensions) {
30
- const engineExtensions = new Array();
30
+ const engineExtensions = [];
31
31
  for (const extension_ of extensions) {
32
32
  if (extension_ !== extension.trim().toLowerCase()) {
33
33
  engineExtensions.push(extension_);
@@ -50,21 +50,22 @@ var EngineMap = class {
50
50
  }
51
51
  };
52
52
 
53
- // src/engines/markdown.ts
54
- import { Writr } from "writr";
53
+ // src/engines/ejs.ts
54
+ import * as ejs from "ejs";
55
55
 
56
56
  // src/base-engine.ts
57
57
  var BaseEngine = class {
58
- names = new Array();
58
+ names = [];
59
59
  opts = void 0;
60
+ // biome-ignore lint/suspicious/noExplicitAny: Different engines use different types, any is required for flexibility
60
61
  engine;
61
62
  rootTemplatePath = void 0;
62
- _extensions = new Array();
63
+ _extensions = [];
63
64
  getExtensions() {
64
65
  return this._extensions;
65
66
  }
66
67
  setExtensions(extensions) {
67
- this._extensions = new Array();
68
+ this._extensions = [];
68
69
  for (const extension of extensions) {
69
70
  const newExtension = extension.trim().toLowerCase();
70
71
  if (!this._extensions.includes(newExtension)) {
@@ -81,39 +82,45 @@ var BaseEngine = class {
81
82
  }
82
83
  };
83
84
 
84
- // src/engines/markdown.ts
85
- var Markdown = class extends BaseEngine {
85
+ // src/engines/ejs.ts
86
+ var EJS = class extends BaseEngine {
86
87
  constructor(options) {
87
88
  super();
88
- this.names = ["markdown"];
89
+ this.names = ["ejs"];
89
90
  if (options) {
90
91
  this.opts = options;
91
92
  }
92
- this.engine = new Writr(options);
93
- this.setExtensions(["md", "markdown"]);
93
+ this.setExtensions(["ejs"]);
94
94
  }
95
95
  async render(source, data) {
96
- this.engine.content = source;
97
- return this.engine.render(data);
96
+ this.engine ??= ejs;
97
+ this.opts ??= {};
98
+ if (this.rootTemplatePath) {
99
+ this.opts.root = this.rootTemplatePath;
100
+ }
101
+ return ejs.render(source, data, this.opts);
98
102
  }
99
103
  renderSync(source, data) {
100
- this.engine.content = source;
101
- return this.engine.renderSync(data);
104
+ this.engine ??= ejs;
105
+ this.opts ??= {};
106
+ if (this.rootTemplatePath) {
107
+ this.opts.root = this.rootTemplatePath;
108
+ }
109
+ return ejs.render(source, data, this.opts);
102
110
  }
103
111
  };
104
112
 
105
113
  // src/engines/handlebars.ts
106
114
  import fs from "fs";
115
+ import { fumanchu } from "@jaredwray/fumanchu";
107
116
  import * as _ from "underscore";
108
- import { helpers, handlebars } from "@jaredwray/fumanchu";
109
117
  var Handlebars = class extends BaseEngine {
110
118
  partialsPath = ["partials", "includes", "templates"];
111
119
  constructor(options) {
112
120
  super();
113
121
  this.names = ["handlebars", "mustache"];
114
122
  this.opts = options;
115
- this.engine = handlebars;
116
- helpers({ handlebars }, this.opts);
123
+ this.engine = fumanchu();
117
124
  this.setExtensions(["hbs", "hjs", "handlebars", "mustache"]);
118
125
  }
119
126
  async render(source, data) {
@@ -143,17 +150,23 @@ var Handlebars = class extends BaseEngine {
143
150
  registerPartials(partialsPath) {
144
151
  let result = false;
145
152
  if (fs.existsSync(partialsPath)) {
146
- const partials = fs.readdirSync(partialsPath, { recursive: true, encoding: "utf8" });
153
+ const partials = fs.readdirSync(partialsPath, {
154
+ recursive: true,
155
+ encoding: "utf8"
156
+ });
147
157
  for (const p of partials) {
148
- if (fs.statSync(partialsPath + "/" + p).isDirectory()) {
149
- const directoryPartials = fs.readdirSync(partialsPath + "/" + p, { recursive: true, encoding: "utf8" });
158
+ if (fs.statSync(`${partialsPath}/${p}`).isDirectory()) {
159
+ const directoryPartials = fs.readdirSync(`${partialsPath}/${p}`, {
160
+ recursive: true,
161
+ encoding: "utf8"
162
+ });
150
163
  for (const dp of directoryPartials) {
151
- const source = fs.readFileSync(partialsPath + "/" + p + "/" + dp).toString();
152
- const name = p + "/" + dp.split(".")[0];
164
+ const source = fs.readFileSync(`${partialsPath}/${p}/${dp}`).toString();
165
+ const name = `${p}/${dp.split(".")[0]}`;
153
166
  this.engine.registerPartial(name, this.engine.compile(source));
154
167
  }
155
168
  } else {
156
- const source = fs.readFileSync(partialsPath + "/" + p, "utf8");
169
+ const source = fs.readFileSync(`${partialsPath}/${p}`, "utf8");
157
170
  const name = p.split(".")[0];
158
171
  this.engine.registerPartial(name, this.engine.compile(source));
159
172
  }
@@ -164,62 +177,58 @@ var Handlebars = class extends BaseEngine {
164
177
  }
165
178
  };
166
179
 
167
- // src/engines/ejs.ts
168
- import * as ejs from "ejs";
169
- var EJS = class extends BaseEngine {
180
+ // src/engines/liquid.ts
181
+ import { Liquid as LiquidEngine } from "liquidjs";
182
+ var Liquid = class extends BaseEngine {
170
183
  constructor(options) {
171
184
  super();
172
- this.names = ["ejs"];
185
+ this.names = ["liquid"];
173
186
  if (options) {
174
187
  this.opts = options;
175
188
  }
176
- this.setExtensions(["ejs"]);
189
+ this.setExtensions(["liquid"]);
177
190
  }
178
191
  async render(source, data) {
179
- this.engine ??= ejs;
180
- this.opts ??= {};
181
192
  if (this.rootTemplatePath) {
193
+ this.opts ??= {};
182
194
  this.opts.root = this.rootTemplatePath;
183
195
  }
184
- return ejs.render(source, data, this.opts);
196
+ if (!this.engine) {
197
+ this.engine = new LiquidEngine(this.opts);
198
+ }
199
+ return this.engine.parseAndRender(source, data);
185
200
  }
186
201
  renderSync(source, data) {
187
- this.engine ??= ejs;
188
- this.opts ??= {};
189
202
  if (this.rootTemplatePath) {
203
+ this.opts ??= {};
190
204
  this.opts.root = this.rootTemplatePath;
191
205
  }
192
- return ejs.render(source, data, this.opts);
206
+ if (!this.engine) {
207
+ this.engine = new LiquidEngine(this.opts);
208
+ }
209
+ return this.engine.parseAndRenderSync(source, data);
193
210
  }
194
211
  };
195
212
 
196
- // src/engines/pug.ts
197
- import * as pug from "pug";
198
- var Pug = class extends BaseEngine {
213
+ // src/engines/markdown.ts
214
+ import { Writr } from "writr";
215
+ var Markdown = class extends BaseEngine {
199
216
  constructor(options) {
200
217
  super();
201
- this.names = ["pug"];
202
- this.engine = pug;
218
+ this.names = ["markdown"];
203
219
  if (options) {
204
220
  this.opts = options;
205
221
  }
206
- this.setExtensions(["pug", "jade"]);
222
+ this.engine = new Writr(options);
223
+ this.setExtensions(["md", "markdown"]);
207
224
  }
208
225
  async render(source, data) {
209
- if (this.rootTemplatePath) {
210
- this.opts ??= {};
211
- this.opts.basedir = this.rootTemplatePath;
212
- }
213
- const template = pug.compile(source, this.opts);
214
- return template(data);
226
+ this.engine.content = source;
227
+ return this.engine.render(data);
215
228
  }
216
229
  renderSync(source, data) {
217
- if (this.rootTemplatePath) {
218
- this.opts ??= {};
219
- this.opts.basedir = this.rootTemplatePath;
220
- }
221
- const template = pug.compile(source, this.opts);
222
- return template(data);
230
+ this.engine.content = source;
231
+ return this.engine.renderSync(data);
223
232
  }
224
233
  };
225
234
 
@@ -238,7 +247,10 @@ var Nunjucks = class extends BaseEngine {
238
247
  }
239
248
  async render(source, data) {
240
249
  if (this.rootTemplatePath) {
241
- nunjucks.configure(this.rootTemplatePath, this.opts);
250
+ nunjucks.configure(
251
+ this.rootTemplatePath,
252
+ this.opts
253
+ );
242
254
  } else {
243
255
  nunjucks.configure(this.opts);
244
256
  }
@@ -247,7 +259,10 @@ var Nunjucks = class extends BaseEngine {
247
259
  }
248
260
  renderSync(source, data) {
249
261
  if (this.rootTemplatePath) {
250
- nunjucks.configure(this.rootTemplatePath, this.opts);
262
+ nunjucks.configure(
263
+ this.rootTemplatePath,
264
+ this.opts
265
+ );
251
266
  } else {
252
267
  nunjucks.configure(this.opts);
253
268
  }
@@ -256,36 +271,33 @@ var Nunjucks = class extends BaseEngine {
256
271
  }
257
272
  };
258
273
 
259
- // src/engines/liquid.ts
260
- import { Liquid as LiquidEngine } from "liquidjs";
261
- var Liquid = class extends BaseEngine {
274
+ // src/engines/pug.ts
275
+ import * as pug from "pug";
276
+ var Pug = class extends BaseEngine {
262
277
  constructor(options) {
263
278
  super();
264
- this.names = ["liquid"];
279
+ this.names = ["pug"];
280
+ this.engine = pug;
265
281
  if (options) {
266
282
  this.opts = options;
267
283
  }
268
- this.setExtensions(["liquid"]);
284
+ this.setExtensions(["pug", "jade"]);
269
285
  }
270
286
  async render(source, data) {
271
287
  if (this.rootTemplatePath) {
272
288
  this.opts ??= {};
273
- this.opts.root = this.rootTemplatePath;
274
- }
275
- if (!this.engine) {
276
- this.engine = new LiquidEngine(this.opts);
289
+ this.opts.basedir = this.rootTemplatePath;
277
290
  }
278
- return this.engine.parseAndRender(source, data);
291
+ const template = pug.compile(source, this.opts);
292
+ return template(data);
279
293
  }
280
294
  renderSync(source, data) {
281
295
  if (this.rootTemplatePath) {
282
296
  this.opts ??= {};
283
- this.opts.root = this.rootTemplatePath;
284
- }
285
- if (!this.engine) {
286
- this.engine = new LiquidEngine(this.opts);
297
+ this.opts.basedir = this.rootTemplatePath;
287
298
  }
288
- return this.engine.parseAndRenderSync(source, data);
299
+ const template = pug.compile(source, this.opts);
300
+ return template(data);
289
301
  }
290
302
  };
291
303
 
@@ -299,7 +311,7 @@ var EctoEvents = /* @__PURE__ */ ((EctoEvents2) => {
299
311
  })(EctoEvents || {});
300
312
  var Ecto = class extends Hookified {
301
313
  _mapping = new EngineMap();
302
- _engines = new Array();
314
+ _engines = [];
303
315
  // Cacheable instance for caching rendered templates
304
316
  _cache;
305
317
  _cacheSync;
@@ -315,7 +327,6 @@ var Ecto = class extends Hookified {
315
327
  * Ecto constructor
316
328
  * @param {EctoOptions} [options] - The options for the ecto engine
317
329
  */
318
- // eslint-disable-next-line complexity
319
330
  constructor(options) {
320
331
  super();
321
332
  this._ejs = new EJS(options?.engineOptions?.ejs);
@@ -324,7 +335,14 @@ var Ecto = class extends Hookified {
324
335
  this._nunjucks = new Nunjucks(options?.engineOptions?.nunjucks);
325
336
  this._handlebars = new Handlebars(options?.engineOptions?.handlebars);
326
337
  this._liquid = new Liquid(options?.engineOptions?.liquid);
327
- this._engines.push(this._ejs, this._markdown, this._pug, this._nunjucks, this._handlebars, this._liquid);
338
+ this._engines.push(
339
+ this._ejs,
340
+ this._markdown,
341
+ this._pug,
342
+ this._nunjucks,
343
+ this._handlebars,
344
+ this._liquid
345
+ );
328
346
  this.registerEngineMappings();
329
347
  if (options?.cache === true) {
330
348
  this._cache = new Cacheable();
@@ -336,7 +354,7 @@ var Ecto = class extends Hookified {
336
354
  } else if (options?.cacheSync instanceof CacheableMemory) {
337
355
  this._cacheSync = options.cacheSync;
338
356
  }
339
- if (options !== void 0 && this.isValidEngine(options.defaultEngine)) {
357
+ if (options?.defaultEngine && this.isValidEngine(options.defaultEngine)) {
340
358
  this._defaultEngine = options.defaultEngine;
341
359
  }
342
360
  }
@@ -356,7 +374,10 @@ var Ecto = class extends Hookified {
356
374
  if (this.isValidEngine(value)) {
357
375
  this._defaultEngine = value;
358
376
  } else {
359
- this.emit("warn" /* warn */, `Invalid engine name: ${value}. Defaulting to ${this._defaultEngine}.`);
377
+ this.emit(
378
+ "warn" /* warn */,
379
+ `Invalid engine name: ${value}. Defaulting to ${this._defaultEngine}.`
380
+ );
360
381
  }
361
382
  }
362
383
  /**
@@ -445,7 +466,6 @@ var Ecto = class extends Hookified {
445
466
  * @param {string} [filePathOutput] - The file path to write the output
446
467
  * @returns {Promise<string>}
447
468
  */
448
- // eslint-disable-next-line max-params
449
469
  async render(source, data, engineName, rootTemplatePath, filePathOutput) {
450
470
  try {
451
471
  const cacheKey = `${engineName ?? this._defaultEngine}-${source}-${JSON.stringify(data)}`;
@@ -485,7 +505,6 @@ var Ecto = class extends Hookified {
485
505
  * @param {string} [filePathOutput] - The file path to write the output
486
506
  * @returns {string}
487
507
  */
488
- // eslint-disable-next-line max-params
489
508
  renderSync(source, data, engineName, rootTemplatePath, filePathOutput) {
490
509
  try {
491
510
  const cacheKey = `${engineName ?? this._defaultEngine}-${source}-${JSON.stringify(data)}`;
@@ -525,12 +544,17 @@ var Ecto = class extends Hookified {
525
544
  * @param {string} [engineName] - The engine to use for rendering
526
545
  * @returns
527
546
  */
528
- // eslint-disable-next-line max-params
529
547
  async renderFromFile(filePath, data, rootTemplatePath, filePathOutput, engineName) {
530
548
  let result = "";
531
549
  engineName ??= this.getEngineByFilePath(filePath);
532
550
  const source = await fs2.promises.readFile(filePath, "utf8");
533
- result = await this.render(source, data, engineName, rootTemplatePath, filePathOutput);
551
+ result = await this.render(
552
+ source,
553
+ data,
554
+ engineName,
555
+ rootTemplatePath,
556
+ filePathOutput
557
+ );
534
558
  return result;
535
559
  }
536
560
  /**
@@ -542,12 +566,17 @@ var Ecto = class extends Hookified {
542
566
  * @param {string} [engineName] - The engine to use for rendering
543
567
  * @returns {string}
544
568
  */
545
- // eslint-disable-next-line max-params
546
569
  renderFromFileSync(filePath, data, rootTemplatePath, filePathOutput, engineName) {
547
570
  let result = "";
548
571
  engineName ??= this.getEngineByFilePath(filePath);
549
572
  const source = fs2.readFileSync(filePath, "utf8");
550
- result = this.renderSync(source, data, engineName, rootTemplatePath, filePathOutput);
573
+ result = this.renderSync(
574
+ source,
575
+ data,
576
+ engineName,
577
+ rootTemplatePath,
578
+ filePathOutput
579
+ );
551
580
  return result;
552
581
  }
553
582
  /**
@@ -602,8 +631,8 @@ var Ecto = class extends Hookified {
602
631
  let result = "";
603
632
  const files = await fs2.promises.readdir(path);
604
633
  for (const file of files) {
605
- if (file.startsWith(templateName + ".")) {
606
- result = path + "/" + file;
634
+ if (file.startsWith(`${templateName}.`)) {
635
+ result = `${path}/${file}`;
607
636
  break;
608
637
  }
609
638
  }
@@ -619,8 +648,8 @@ var Ecto = class extends Hookified {
619
648
  let result = "";
620
649
  const files = fs2.readdirSync(path);
621
650
  for (const file of files) {
622
- if (file.startsWith(templateName + ".")) {
623
- result = path + "/" + file;
651
+ if (file.startsWith(`${templateName}.`)) {
652
+ result = `${path}/${file}`;
624
653
  break;
625
654
  }
626
655
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecto",
3
- "version": "4.4.1",
3
+ "version": "4.4.3",
4
4
  "description": "Modern Template Consolidation Engine for EJS, Markdown, Pug, Nunjucks, Liquid, and Handlebars",
5
5
  "type": "module",
6
6
  "main": "./dist/ecto.js",
@@ -18,8 +18,11 @@
18
18
  "author": "Jared Wray <me@jaredwray.com>",
19
19
  "license": "MIT",
20
20
  "scripts": {
21
+ "lint": "biome check --write --error-on-warnings",
22
+ "lint:ci": "biome check --error-on-warnings",
21
23
  "clean": "rimraf ./dist yarn.lock package-lock.json pnpm-lock.yaml ./coverage ./node_modules ./site/readme.md ./dist-site",
22
- "test": "xo --fix && vitest run --coverage",
24
+ "test": "pnpm lint && vitest run --coverage",
25
+ "test:ci": "pnpm lint:ci && vitest run --coverage",
23
26
  "build": "rimraf ./dist && tsup src/ecto.ts --format esm --dts --clean",
24
27
  "prepare": "pnpm build",
25
28
  "website:build": "rimraf ./site/readme.md && npx -y docula build -s ./site -o ./dist-site",
@@ -46,19 +49,20 @@
46
49
  "liquidjs"
47
50
  ],
48
51
  "dependencies": {
49
- "@jaredwray/fumanchu": "^3.1.2",
50
- "cacheable": "^1.10.4",
52
+ "@jaredwray/fumanchu": "^4.0.3",
53
+ "cacheable": "^2.0.1",
51
54
  "ejs": "^3.1.10",
52
- "hookified": "^1.11.0",
55
+ "hookified": "^1.12.1",
53
56
  "liquidjs": "^10.21.1",
54
57
  "nunjucks": "^3.2.4",
55
58
  "pug": "^3.0.3",
56
59
  "underscore": "^1.13.7",
57
- "writr": "^4.4.6"
60
+ "writr": "^4.5.0"
58
61
  },
59
62
  "devDependencies": {
63
+ "@biomejs/biome": "^2.2.4",
60
64
  "@types/ejs": "^3.1.5",
61
- "@types/node": "^24.3.0",
65
+ "@types/node": "^24.5.2",
62
66
  "@types/nunjucks": "^3.2.6",
63
67
  "@types/pug": "^2.0.10",
64
68
  "@types/underscore": "^1.13.0",
@@ -68,8 +72,7 @@
68
72
  "tsup": "^8.5.0",
69
73
  "typescript": "^5.9.2",
70
74
  "vitest": "^3.2.4",
71
- "webpack": "^5.101.3",
72
- "xo": "^1.2.0"
75
+ "webpack": "^5.101.3"
73
76
  },
74
77
  "files": [
75
78
  "dist",