ecto 5.0.0 → 5.1.1

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.mts +12 -13
  2. package/dist/ecto.mjs +14 -17
  3. package/package.json +16 -16
package/dist/ecto.d.mts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Cacheable, CacheableMemory } from "cacheable";
2
2
  import { Hookified, HookifiedOptions } from "hookified";
3
-
4
3
  //#region src/engine-interface.d.ts
5
4
  type EngineInterface = {
6
5
  names: string[];
@@ -34,14 +33,14 @@ declare class BaseEngine {
34
33
  }
35
34
  //#endregion
36
35
  //#region src/engines/ejs.d.ts
37
- declare class EJS extends BaseEngine implements EngineInterface {
36
+ export declare class EJS extends BaseEngine implements EngineInterface {
38
37
  constructor(options?: Record<string, unknown>);
39
38
  render(source: string, data?: Record<string, unknown>): Promise<string>;
40
39
  renderSync(source: string, data?: Record<string, unknown>): string;
41
40
  }
42
41
  //#endregion
43
42
  //#region src/engines/handlebars.d.ts
44
- declare class Handlebars extends BaseEngine implements EngineInterface {
43
+ export declare class Handlebars extends BaseEngine implements EngineInterface {
45
44
  partialsPath: string[];
46
45
  constructor(options?: Record<string, unknown>);
47
46
  render(source: string, data?: Record<string, unknown>): Promise<string>;
@@ -51,35 +50,35 @@ declare class Handlebars extends BaseEngine implements EngineInterface {
51
50
  }
52
51
  //#endregion
53
52
  //#region src/engines/liquid.d.ts
54
- declare class Liquid extends BaseEngine implements EngineInterface {
53
+ export declare class Liquid extends BaseEngine implements EngineInterface {
55
54
  constructor(options?: Record<string, unknown>);
56
55
  render(source: string, data?: Record<string, unknown>): Promise<string>;
57
56
  renderSync(source: string, data?: Record<string, unknown>): string;
58
57
  }
59
58
  //#endregion
60
59
  //#region src/engines/markdown.d.ts
61
- declare class Markdown extends BaseEngine implements EngineInterface {
60
+ export declare class Markdown extends BaseEngine implements EngineInterface {
62
61
  constructor(options?: Record<string, unknown>);
63
62
  render(source: string, data?: Record<string, unknown>): Promise<string>;
64
63
  renderSync(source: string, data?: Record<string, unknown>): string;
65
64
  }
66
65
  //#endregion
67
66
  //#region src/engines/nunjucks.d.ts
68
- declare class Nunjucks extends BaseEngine implements EngineInterface {
67
+ export declare class Nunjucks extends BaseEngine implements EngineInterface {
69
68
  constructor(options?: Record<string, unknown>);
70
69
  render(source: string, data?: Record<string, unknown>): Promise<string>;
71
70
  renderSync(source: string, data?: Record<string, unknown>): string;
72
71
  }
73
72
  //#endregion
74
73
  //#region src/engines/pug.d.ts
75
- declare class Pug extends BaseEngine implements EngineInterface {
74
+ export declare class Pug extends BaseEngine implements EngineInterface {
76
75
  constructor(options?: Record<string, unknown>);
77
76
  render(source: string, data?: Record<string, unknown>): Promise<string>;
78
77
  renderSync(source: string, data?: Record<string, unknown>): string;
79
78
  }
80
79
  //#endregion
81
80
  //#region src/ecto.d.ts
82
- type EctoOptions = {
81
+ export type EctoOptions = {
83
82
  /**
84
83
  * The default engine to use. This can be 'ejs', 'markdown', 'pug', 'nunjucks', 'handlebars', 'liquid'
85
84
  * @default 'ejs'
@@ -119,7 +118,7 @@ type EctoOptions = {
119
118
  /**
120
119
  * Context passed to beforeRender and beforeRenderSync hooks
121
120
  */
122
- type RenderContext = {
121
+ export type RenderContext = {
123
122
  source: string;
124
123
  data?: Record<string, unknown>;
125
124
  engineName: string;
@@ -130,11 +129,11 @@ type RenderContext = {
130
129
  /**
131
130
  * Result passed to afterRender and afterRenderSync hooks
132
131
  */
133
- type RenderResult = {
132
+ export type RenderResult = {
134
133
  result: string;
135
134
  context: RenderContext;
136
135
  };
137
- declare enum EctoEvents {
136
+ export declare enum EctoEvents {
138
137
  cacheHit = "cacheHit",
139
138
  cacheMiss = "cacheMiss",
140
139
  warn = "warn",
@@ -144,7 +143,7 @@ declare enum EctoEvents {
144
143
  beforeRenderSync = "beforeRenderSync",
145
144
  afterRenderSync = "afterRenderSync"
146
145
  }
147
- declare class Ecto extends Hookified {
146
+ export declare class Ecto extends Hookified {
148
147
  private readonly _mapping;
149
148
  private readonly _engines;
150
149
  private _cache;
@@ -400,4 +399,4 @@ declare class Ecto extends Hookified {
400
399
  private writeFileSync;
401
400
  }
402
401
  //#endregion
403
- export { type BaseEngine, EJS, Ecto, EctoEvents, EctoOptions, type EngineInterface, Handlebars, Liquid, Markdown, Nunjucks, Pug, RenderContext, RenderResult };
402
+ export type { BaseEngine, EngineInterface };
package/dist/ecto.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import fs from "node:fs";
2
- import path from "node:path";
2
+ import nodePath from "node:path";
3
3
  import { Cacheable, CacheableMemory } from "cacheable";
4
4
  import { Hookified } from "hookified";
5
5
  import { Writr } from "writr";
@@ -526,7 +526,7 @@ var Ecto = class extends Hookified {
526
526
  async renderFromFile(filePath, data, rootTemplatePath, filePathOutput, engineName) {
527
527
  let result = "";
528
528
  engineName ??= this.getEngineByFilePath(filePath);
529
- const templateRootPath = rootTemplatePath ?? path.dirname(filePath);
529
+ const templateRootPath = rootTemplatePath ?? nodePath.dirname(filePath);
530
530
  const source = await fs.promises.readFile(filePath, "utf8");
531
531
  result = await this.render(source, data, engineName, templateRootPath, filePathOutput);
532
532
  return result;
@@ -545,7 +545,7 @@ var Ecto = class extends Hookified {
545
545
  renderFromFileSync(filePath, data, rootTemplatePath, filePathOutput, engineName) {
546
546
  let result = "";
547
547
  engineName ??= this.getEngineByFilePath(filePath);
548
- const templateRootPath = rootTemplatePath ?? path.dirname(filePath);
548
+ const templateRootPath = rootTemplatePath ?? nodePath.dirname(filePath);
549
549
  const source = fs.readFileSync(filePath, "utf8");
550
550
  result = this.renderSync(source, data, engineName, templateRootPath, filePathOutput);
551
551
  return result;
@@ -558,10 +558,9 @@ var Ecto = class extends Hookified {
558
558
  * await ecto.ensureFilePath('/path/to/file.txt');
559
559
  */
560
560
  async ensureFilePath(path) {
561
- const pathList = path.split("/");
562
- pathList.pop();
563
- const directory = pathList.join("/");
564
- if (!fs.existsSync(directory)) fs.mkdirSync(directory, { recursive: true });
561
+ const normalizedPath = nodePath.normalize(path);
562
+ const directory = nodePath.dirname(normalizedPath);
563
+ await fs.promises.mkdir(directory, { recursive: true });
565
564
  }
566
565
  /**
567
566
  * Synchronously ensure that the directory path for a file exists, creating it if necessary
@@ -571,10 +570,9 @@ var Ecto = class extends Hookified {
571
570
  * ecto.ensureFilePathSync('/path/to/file.txt');
572
571
  */
573
572
  ensureFilePathSync(path) {
574
- const pathList = path.split("/");
575
- pathList.pop();
576
- const directory = pathList.join("/");
577
- if (!fs.existsSync(directory)) fs.mkdirSync(directory, { recursive: true });
573
+ const normalizedPath = nodePath.normalize(path);
574
+ const directory = nodePath.dirname(normalizedPath);
575
+ fs.mkdirSync(directory, { recursive: true });
578
576
  }
579
577
  /**
580
578
  * Determine the appropriate template engine based on a file's extension
@@ -586,7 +584,8 @@ var Ecto = class extends Hookified {
586
584
  getEngineByFilePath(filePath) {
587
585
  let result = this._defaultEngine;
588
586
  if (filePath !== void 0) {
589
- const extension = filePath.includes(".") ? filePath.slice(filePath.lastIndexOf(".") + 1) : "";
587
+ const { ext } = nodePath.parse(filePath);
588
+ const extension = ext.startsWith(".") ? ext.slice(1) : ext;
590
589
  const engExtension = this._mapping.getName(extension);
591
590
  if (engExtension !== void 0) result = engExtension;
592
591
  }
@@ -604,7 +603,7 @@ var Ecto = class extends Hookified {
604
603
  let result = "";
605
604
  const files = await fs.promises.readdir(path);
606
605
  for (const file of files) if (file.startsWith(`${templateName}.`)) {
607
- result = `${path}/${file}`;
606
+ result = nodePath.join(path, file);
608
607
  break;
609
608
  }
610
609
  return result;
@@ -621,7 +620,7 @@ var Ecto = class extends Hookified {
621
620
  let result = "";
622
621
  const files = fs.readdirSync(path);
623
622
  for (const file of files) if (file.startsWith(`${templateName}.`)) {
624
- result = `${path}/${file}`;
623
+ result = nodePath.join(path, file);
625
624
  break;
626
625
  }
627
626
  return result;
@@ -777,9 +776,7 @@ var Ecto = class extends Hookified {
777
776
  case "liquid":
778
777
  result = this._liquid;
779
778
  break;
780
- default:
781
- result = this._ejs;
782
- break;
779
+ default: result = this._ejs;
783
780
  }
784
781
  return result;
785
782
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecto",
3
- "version": "5.0.0",
3
+ "version": "5.1.1",
4
4
  "description": "Modern Template Consolidation Engine for EJS, Markdown, Pug, Nunjucks, Liquid, and Handlebars",
5
5
  "type": "module",
6
6
  "main": "./dist/ecto.mjs",
@@ -42,30 +42,30 @@
42
42
  "liquidjs"
43
43
  ],
44
44
  "dependencies": {
45
- "@jaredwray/fumanchu": "^4.7.0",
46
- "cacheable": "^2.3.5",
45
+ "@jaredwray/fumanchu": "^4.7.3",
46
+ "cacheable": "^2.5.0",
47
47
  "ejs": "^6.0.1",
48
- "hookified": "^3.0.0",
49
- "liquidjs": "^10.27.0",
48
+ "hookified": "^3.0.3",
49
+ "liquidjs": "^10.29.0",
50
50
  "nunjucks": "^3.2.4",
51
51
  "pug": "^3.0.4",
52
- "writr": "^6.1.2"
52
+ "writr": "^6.1.6"
53
53
  },
54
54
  "devDependencies": {
55
- "@biomejs/biome": "^2.5.0",
56
- "@faker-js/faker": "^10.5.0",
55
+ "@biomejs/biome": "^2.5.14",
56
+ "@faker-js/faker": "^10.6.0",
57
57
  "@types/ejs": "^3.1.5",
58
- "@types/node": "^24.12.4",
58
+ "@types/node": "^24.13.6",
59
59
  "@types/nunjucks": "^3.2.6",
60
60
  "@types/pug": "^2.0.10",
61
- "@vitest/coverage-v8": "^4.1.9",
62
- "docula": "^2.0.0",
61
+ "@vitest/coverage-v8": "^5.0.1",
62
+ "docula": "^3.0.0",
63
63
  "rimraf": "^6.1.3",
64
- "tsdown": "^0.22.0",
65
- "typescript": "^6.0.3",
66
- "vite": "^8.0.16",
67
- "vitest": "^4.1.9",
68
- "wrangler": "^4.102.0"
64
+ "tsdown": "^0.23.0",
65
+ "typescript": "^7.0.2",
66
+ "vite": "^8.3.0",
67
+ "vitest": "^5.0.1",
68
+ "wrangler": "^4.135.0"
69
69
  },
70
70
  "files": [
71
71
  "dist",