Skip to content

Commit 7563205

Browse files
fix base64 build issue (#4581)
* fix base64 build issue * remove leading whitespace * fix import * add explanation --------- Co-authored-by: Luke Taylor <service@lukebtaylor.com>
1 parent 0c378da commit 7563205

File tree

4 files changed

+45
-20
lines changed

4 files changed

+45
-20
lines changed

packages/local-mail-watcher/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:22.12 as builder
1+
FROM node:22.12 as builder
22

33
WORKDIR /app
44

packages/local-mail-watcher/src/lib/base64.js

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Utility functions for handling base64 encoding/decoding
3+
*/
4+
5+
// Node.js Buffer is globally available
6+
// Only import type information - no runtime import
7+
// This will be removed during compilation
8+
import type {} from '../types/node-buffer';
9+
10+
/**
11+
* Decodes a base64 string to UTF-8 text
12+
* Uses Node.js Buffer with type safety
13+
*/
14+
export function decodeBase64(base64String: string): string {
15+
try {
16+
return Buffer.from(base64String, 'base64').toString('utf-8');
17+
} catch (error) {
18+
console.error('Error decoding base64 string:', error);
19+
return base64String; // Return original string if decoding fails
20+
}
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
declare global {
2+
interface Buffer extends Uint8Array {
3+
write(string: string, encoding?: BufferEncoding): number;
4+
toString(encoding?: BufferEncoding, start?: number, end?: number): string;
5+
}
6+
7+
interface BufferConstructor {
8+
from(arrayBuffer: WithImplicitCoercion<ArrayBuffer | SharedArrayBuffer>, byteOffset?: number, length?: number): Buffer;
9+
from(data: WithImplicitCoercion<Uint8Array | readonly number[]>): Buffer;
10+
from(str: WithImplicitCoercion<string>, encoding?: BufferEncoding): Buffer;
11+
alloc(size: number): Buffer;
12+
alloc(size: number, fill: string | Buffer | number): Buffer;
13+
}
14+
15+
type WithImplicitCoercion<T> = T | { valueOf(): T };
16+
17+
type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'latin1' | 'binary' | 'hex';
18+
19+
const Buffer: BufferConstructor;
20+
}
21+
22+
// This empty export makes TypeScript treat this file as a module
23+
export {};

0 commit comments

Comments
 (0)