import Foundation public struct ESMModules: Sendable { public let modules: [String: String] public let order: [String] public init(modules: [String: String], order: [String]) { self.modules = modules self.order = order } } public enum ESMBundleParser { public static func parse(_ bundle: String) throws -> ESMModules { let headerPrefix = "📦\n" let separator = "✄\n" guard bundle.hasPrefix(headerPrefix) else { throw ESMBundleError.invalidFormat } guard let separatorRange = bundle.range(of: "\n" + separator) else { throw ESMBundleError.headerNotFound } let headerString = String(bundle[..= desc.size else { throw ESMBundleError.sizeOutOfRange } let start = cursor let end = bodyBytes.index(start, offsetBy: desc.size) let fileData = bodyBytes[start..= separatorLength else { throw ESMBundleError.invalidSeparator } let sepEnd = bodyBytes.index(cursor, offsetBy: separatorLength) let sepSlice = bodyBytes[cursor..