@travetto/email-compiler 5.0.18 → 5.0.20

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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 ArcSine Technologies
3
+ Copyright (c) 2020 ArcSine Technologies
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/email-compiler",
3
- "version": "5.0.18",
3
+ "version": "5.0.20",
4
4
  "description": "Email compiling module",
5
5
  "keywords": [
6
6
  "email",
@@ -26,20 +26,20 @@
26
26
  "directory": "module/email-compiler"
27
27
  },
28
28
  "dependencies": {
29
- "@travetto/config": "^5.0.13",
30
- "@travetto/di": "^5.0.13",
31
- "@travetto/email": "^5.0.13",
32
- "@travetto/image": "^5.0.17",
33
- "@travetto/runtime": "^5.0.13",
34
- "@travetto/worker": "^5.0.15",
29
+ "@travetto/config": "^5.0.15",
30
+ "@travetto/di": "^5.0.15",
31
+ "@travetto/email": "^5.0.15",
32
+ "@travetto/image": "^5.0.19",
33
+ "@travetto/runtime": "^5.0.15",
34
+ "@travetto/worker": "^5.0.17",
35
35
  "@types/inline-css": "^3.0.3",
36
36
  "html-entities": "^2.5.2",
37
37
  "inline-css": "^4.0.2",
38
- "purgecss": "^6.0.0",
39
- "sass": "^1.80.4"
38
+ "purgecss": "^7.0.2",
39
+ "sass": "^1.83.0"
40
40
  },
41
41
  "peerDependencies": {
42
- "@travetto/cli": "^5.0.16"
42
+ "@travetto/cli": "^5.0.18"
43
43
  },
44
44
  "peerDependenciesMeta": {
45
45
  "@travetto/cli": {
package/src/compiler.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
 
4
- import { TypedObject, RuntimeIndex, watchCompiler, Runtime, BinaryUtil } from '@travetto/runtime';
4
+ import { TypedObject, RuntimeIndex, watchCompiler, Runtime, BinaryUtil, castTo } from '@travetto/runtime';
5
5
  import { EmailCompiled, MailUtil, EmailTemplateImport, EmailTemplateModule } from '@travetto/email';
6
6
 
7
7
  import { EmailCompileUtil } from './util';
@@ -15,7 +15,10 @@ export class EmailCompiler {
15
15
  * Load Template
16
16
  */
17
17
  static async loadTemplate(file: string): Promise<EmailTemplateModule> {
18
- const root = (await Runtime.importFrom<{ default: EmailTemplateImport }>(file)).default;
18
+ let root = (await Runtime.importFrom<{ default: EmailTemplateImport }>(file)).default;
19
+ if ('default' in root) {
20
+ root = castTo(root.default);
21
+ }
19
22
  const entry = RuntimeIndex.getEntry(file)!;
20
23
  return await root.prepare({ file, module: entry.module });
21
24
  }
package/src/util.ts CHANGED
@@ -11,13 +11,15 @@ type Tokenized = {
11
11
  finalize: (onToken: (token: string) => string) => string;
12
12
  };
13
13
 
14
+ const SUPPORT_SRC = /(?:support|src)\//;
15
+
14
16
  /**
15
17
  * Email compile tools
16
18
  */
17
19
  export class EmailCompileUtil {
18
20
  static #HTML_CSS_IMAGE_URLS = [
19
- /(?<pre><img[^>]src=\s*["'])(?<src>[^"{}]+)/g,
20
- /(?<pre>background(?:-image)?:\s*url[(]['"]?)(?<src>[^"'){}]+)/g
21
+ /(?<pre><img[^>]src=\s{0,10}["'])(?<src>[^"{}]{1,1000})/g,
22
+ /(?<pre>background(?:-image)?:\s{0,10}url[(]['"]?)(?<src>[^"'){}]{1,1000})/g
21
23
  ];
22
24
 
23
25
  static #EXT = /[.]email[.]tsx$/;
@@ -33,7 +35,7 @@ export class EmailCompileUtil {
33
35
  * Generate singular output path given a file
34
36
  */
35
37
  static buildOutputPath(file: string, suffix: string, prefix?: string): string {
36
- const res = file.replace(/.*(support|src)\//, '').replace(this.#EXT, suffix);
38
+ const res = (SUPPORT_SRC.test(file) ? file.split(SUPPORT_SRC)[1] : file).replace(this.#EXT, suffix);
37
39
  return prefix ? path.join(prefix, res) : res;
38
40
  }
39
41
 
@@ -68,7 +70,7 @@ export class EmailCompileUtil {
68
70
  text = text.replace(all, `${pre}${token}`);
69
71
  }
70
72
  }
71
- const finalize = (onToken: (token: string) => string): string => text.replace(/@@[^@]+@@/g, t => onToken(t));
73
+ const finalize = (onToken: (token: string) => string): string => text.replace(/@@[^@]{1,100}@@/g, t => onToken(t));
72
74
 
73
75
  return { text, tokens, finalize };
74
76
  }
@@ -161,7 +163,7 @@ export class EmailCompileUtil {
161
163
  static handleHtmlEdgeCases(html: string): string {
162
164
  return html
163
165
  .replace(/\n{3,100}/msg, '\n\n')
164
- .replace(/<(meta|img|link|hr|br)[^>]*>/g, a => a.replace('>', '/>')) // Fix self closing
166
+ .replace(/<(meta|img|link|hr|br)[^>]{0,200}>/g, a => a.replace(/>/g, '/>')) // Fix self closing
165
167
  .replace(/&apos;/g, '&#39;') // Fix apostrophes, as outlook hates them
166
168
  .replace(/(background(?:-color)?:\s*)([#0-9a-f]{6,8})([^>.#,]+)>/ig,
167
169
  (all, p, col, rest) => `${p}${col}${rest} bgcolor="${col}">`) // Inline bg-color
@@ -173,7 +175,6 @@ export class EmailCompileUtil {
173
175
  .concat('\n');
174
176
  }
175
177
 
176
-
177
178
  /**
178
179
  * Apply styles into a given html document
179
180
  */