@travetto/email-compiler 7.1.3 → 8.0.0-alpha.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/email-compiler",
3
- "version": "7.1.3",
3
+ "version": "8.0.0-alpha.0",
4
4
  "type": "module",
5
5
  "description": "Email compiling module",
6
6
  "keywords": [
@@ -27,20 +27,20 @@
27
27
  "directory": "module/email-compiler"
28
28
  },
29
29
  "dependencies": {
30
- "@travetto/config": "^7.1.3",
31
- "@travetto/di": "^7.1.3",
32
- "@travetto/email": "^7.1.3",
33
- "@travetto/image": "^7.1.3",
34
- "@travetto/runtime": "^7.1.3",
35
- "@travetto/worker": "^7.1.3",
30
+ "@travetto/config": "^8.0.0-alpha.0",
31
+ "@travetto/di": "^8.0.0-alpha.0",
32
+ "@travetto/email": "^8.0.0-alpha.0",
33
+ "@travetto/image": "^8.0.0-alpha.0",
34
+ "@travetto/runtime": "^8.0.0-alpha.0",
35
+ "@travetto/worker": "^8.0.0-alpha.0",
36
36
  "@types/inline-css": "^3.0.4",
37
37
  "html-entities": "^2.6.0",
38
38
  "inline-css": "^4.0.3",
39
- "purgecss": "^7.0.2",
40
- "sass": "^1.97.2"
39
+ "purgecss": "^8.0.0",
40
+ "sass": "^1.97.3"
41
41
  },
42
42
  "peerDependencies": {
43
- "@travetto/cli": "^7.1.3"
43
+ "@travetto/cli": "^8.0.0-alpha.0"
44
44
  },
45
45
  "peerDependenciesMeta": {
46
46
  "@travetto/cli": {
package/src/compiler.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
 
4
- import { TypedObject, RuntimeIndex, Runtime, BinaryUtil, ExecUtil } from '@travetto/runtime';
4
+ import { TypedObject, RuntimeIndex, Runtime, ExecUtil } from '@travetto/runtime';
5
5
  import { type EmailCompiled, MailUtil, type EmailTemplateImport, type EmailTemplateModule } from '@travetto/email';
6
+ import { ManifestFileUtil } from '@travetto/manifest';
6
7
 
7
8
  import { EmailCompileUtil } from './util.ts';
8
9
 
@@ -57,7 +58,7 @@ export class EmailCompiler {
57
58
  await Promise.all(TypedObject.keys(outs).map(async key => {
58
59
  if (message[key]) {
59
60
  const content = MailUtil.buildBrand(file, message[key], 'trv email:compile');
60
- await BinaryUtil.bufferedFileWrite(outs[key], content);
61
+ await ManifestFileUtil.bufferedFileWrite(outs[key], content);
61
62
  } else {
62
63
  await fs.rm(outs[key], { force: true }); // Remove file if data not provided
63
64
  }
package/src/util.ts CHANGED
@@ -1,10 +1,9 @@
1
- import { buffer as toBuffer } from 'node:stream/consumers';
2
1
  import path from 'node:path';
3
2
  import type { CompileResult, Options } from 'sass';
4
3
 
5
4
  import type { EmailCompiled, EmailTemplateModule, EmailTemplateResource } from '@travetto/email';
6
5
  import { ImageUtil } from '@travetto/image';
7
- import { RuntimeIndex } from '@travetto/runtime';
6
+ import { BinaryUtil, CodecUtil, RuntimeIndex, type BinaryArray } from '@travetto/runtime';
8
7
 
9
8
  type Tokenized = {
10
9
  text: string;
@@ -144,26 +143,21 @@ export class EmailCompileUtil {
144
143
  */
145
144
  static async inlineImages(html: string, options: EmailTemplateResource): Promise<string> {
146
145
  const { tokens, finalize } = await this.tokenizeResources(html, HTML_CSS_IMAGE_URLS);
147
- const pendingImages: [token: string, ext: string, stream: Buffer | Promise<Buffer>][] = [];
148
-
149
- for (const [token, source] of tokens) {
150
- const ext = path.extname(source);
151
- if (/^[.](jpe?g|png)$/.test(ext)) {
152
- const output = await ImageUtil.convert(
153
- await options.loader.readStream(source),
154
- { format: ext === '.png' ? 'png' : 'jpeg' }
155
- );
156
- const buffer = await toBuffer(output);
157
- pendingImages.push([token, ext, buffer]);
146
+ const pendingImages = [...tokens.entries()].map(async ([token, source]) => {
147
+ const format = path.extname(source).substring(1);
148
+
149
+ let bytes: BinaryArray;
150
+ if (ImageUtil.isKnownExtension(format)) {
151
+ const stream = await options.loader.readBinaryStream(source);
152
+ const converted = await ImageUtil.convert(stream, { optimize: true, format });
153
+ bytes = await BinaryUtil.toBinaryArray(converted);
158
154
  } else {
159
- pendingImages.push([token, ext, options.loader.read(source, true)]);
155
+ bytes = await options.loader.readBinaryArray(source);
160
156
  }
161
- }
162
-
163
- const imageMap = new Map(await Promise.all(pendingImages.map(async ([token, ext, data]) =>
164
- [token, `data:image/${ext.replace('.', '')};base64,${data.toString('base64')}`] as const
165
- )));
157
+ return [token, `data:image/${format};base64,${CodecUtil.toBase64String(bytes)}`] as const;
158
+ });
166
159
 
160
+ const imageMap = new Map(await Promise.all(pendingImages));
167
161
  return finalize(token => imageMap.get(token)!);
168
162
  }
169
163
 
@@ -191,7 +185,7 @@ export class EmailCompileUtil {
191
185
  static async applyStyles(html: string, options: EmailTemplateResource): Promise<string> {
192
186
  const styles = [
193
187
  options.globalStyles ?? '',
194
- await options.loader.read('/email/main.scss').catch(() => '')
188
+ await options.loader.readText('/email/main.scss').catch(() => '')
195
189
  ]
196
190
  .filter(line => !!line)
197
191
  .join('\n');
@@ -1,7 +1,8 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import { parse, stringify } from 'yaml';
3
3
 
4
- import { Runtime, BinaryUtil } from '@travetto/runtime';
4
+ import { Runtime } from '@travetto/runtime';
5
+ import { ManifestFileUtil } from '@travetto/manifest';
5
6
 
6
7
  import type { EditorConfigType } from './types.ts';
7
8
 
@@ -51,7 +52,7 @@ export class EditorConfig {
51
52
  static async ensureConfig(): Promise<string> {
52
53
  const resolved = Runtime.workspaceRelative(CONFIG_FILE);
53
54
  if (!(await fs.stat(resolved).catch(() => { }))) {
54
- await BinaryUtil.bufferedFileWrite(resolved, this.getDefaultConfig());
55
+ await ManifestFileUtil.bufferedFileWrite(resolved, this.getDefaultConfig());
55
56
  }
56
57
  return resolved;
57
58
  }
@@ -1,6 +1,6 @@
1
1
  import { Inject, Injectable } from '@travetto/di';
2
2
  import { MailUtil, type EmailCompiled, type MailInterpolator } from '@travetto/email';
3
- import { AppError, TypedObject, WatchUtil } from '@travetto/runtime';
3
+ import { RuntimeError, TypedObject, WatchUtil } from '@travetto/runtime';
4
4
 
5
5
  import type { EditorSendService } from './send.ts';
6
6
  import { EditorConfig } from './config.ts';
@@ -63,7 +63,7 @@ export class EditorService {
63
63
  */
64
64
  async listen(): Promise<void> {
65
65
  if (!process.connected || !process.send) {
66
- throw new AppError('Unable to run email editor, missing ipc channel');
66
+ throw new RuntimeError('Unable to run email editor, missing ipc channel');
67
67
  }
68
68
  process.on('message', async (request: EditorRequest) => {
69
69
  switch (request.type) {