Skip to content

Commit 21fa6d0

Browse files
committed
remove base64
1 parent 07a24c9 commit 21fa6d0

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Behavioural changes in TerserJS are listed [here](https://github.com/terser/ters
33
## Unreleased
44
## 1.2.6 (19 June 2025)
55
- update TerserJS to [5.43.1]
6+
- remove base64 for compatibility with Ruby 3.4
67

78
## 1.2.5 (20 January 2025)
89
- update TerserJS to [5.37.0]

lib/terser.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# frozen_string_literal: true
33

44
require "json"
5-
require "base64"
65
require "execjs"
76
require "terser/railtie" if defined?(Rails::Railtie)
87
require "terser/version"
@@ -163,7 +162,7 @@ def initialize(options = {})
163162
def compile(source, source_map_options = @options)
164163
if source_map_options[:source_map]
165164
compiled, source_map = run_terserjs(source, true, source_map_options)
166-
source_map_uri = Base64.strict_encode64(source_map)
165+
source_map_uri = [source_map].pack("m0")
167166
source_map_mime = "application/json;charset=utf-8;base64"
168167
compiled + "\n//# sourceMappingURL=data:#{source_map_mime},#{source_map_uri}"
169168
else
@@ -506,9 +505,19 @@ def input_source_map(source, generate_map, options)
506505
source_map_options = options[:source_map].is_a?(Hash) ? options[:source_map] : {}
507506
sanitize_map_root(source_map_options.fetch(:input_source_map) do
508507
url = extract_source_mapping_url(source)
509-
Base64.strict_decode64(url.split(",", 2)[-1]) if url && url.start_with?("data:")
508+
base64_strict_decode64(url.split(",", 2)[-1]) if url && url.start_with?("data:")
510509
end)
511510
rescue ArgumentError, JSON::ParserError
512511
nil
513512
end
513+
514+
if "".respond_to?(:unpack1)
515+
def base64_strict_decode64(str)
516+
str.unpack1("m0")
517+
end
518+
else
519+
def base64_strict_decode64(str)
520+
str.unpack("m0")[0]
521+
end
522+
end
514523
end

0 commit comments

Comments
 (0)